蓝色天空网mbsky.com · 知识 · 实践 · 创造Pi Agent · 本地阅读预览
教程 / AI / 智能开发 / Pi Agent

Pi Agent 配置参考手册

理解配置字段的默认行为、来源优先级和本地资源的加载方式。

本站独立整理的内容草稿。实例显示的是预期结果;浏览器、服务端运行与技术内容验收尚待完成,本页只用于阅读和图文核对。

学完这一章,你能够

一个用户设置,多套项目覆盖

Pi 1.5.0 先读用户配置目录的 settings.json,再读取已信任项目的 .pi/settings.json。标量通常由更具体的项目值覆盖,对象按子键合并。包与资源列表按资源规则合并,而模型范围列表和普通工具列表可以在项目中替换。

高级显示字段可以写入 JSON。tuiMode 切换 regular 与 fullscreen。fullscreenExitOutput 控制退出时输出对话还是继续提示。fullscreenScrollbar、fullscreenCopyOnSelect 和 fullscreenWheelScrollLines 分别控制滚动条、选区复制和滚轮步长。terminal.hyperlinks 管理 OSC 8 链接,markdown.mermaid 可选 off、final、streaming。

模型与推理档位

启动时把 defaultProvider 与 defaultModel 视为一对。若用户选择过模型,可为 provider/modelId 记录单独的推理档位。推理参数只有在模型和提供方支持时才会生效,调试时应看实际模型及传给客户端的参数。

界面设置和用户级信任策略

系统主题会尝试随终端明暗切换。编辑区、消息区和补全列表有各自的尺寸键。doubleEscapeAction 和 treeFilterMode 决定空编辑器双击 Escape 的行为及会话树打开时的选择范围。先查看自己安装版本的默认值。

代理设置的范围

用户级 httpProxy 应写在当前 Pi 用户配置目录。项目里的同名值不会作为 Pi 管理的 HTTP 客户端代理生效。若代理来自环境,也应根据所用客户端确认变量及作用范围。配套脚本只观察有效配置的读取层级。

为上下文压缩和分支摘要留出空间

自动压缩会在可用上下文接近预留值时尝试收缩早期历史,再保留近期消息。调试时用不同数字分别观察 reserveTokens 和 keepRecentTokens,避免把两者混成同一个预算。

离开一条历史分支时,分支摘要可帮助保留分支上的关键内容。reserveTokens 专用于摘要预算。skipPrompt 跳过是否摘要的询问,此时默认直接切换。

重试与消息传输

区分代理在一次运行中执行的重试和提供方网络客户端的重试。外层的次数及基础等待决定瞬时失败后何时重试。内层字段决定请求超时、重试次数和可接受的服务端延迟。两层的时间需要一起评估。

steeringMode 控制运行中的插话何时送达,followUpMode 控制当前工作完成后的跟进队列。网络客户端仍需自身支持所选 transport。HTTP 空闲超时和 WebSocket 握手超时处理的是不同阶段。

图片和终端是两条配置链

terminal 下的设置只管终端如何绘制内容。images 下的设置控制交给模型客户端的数据。关闭屏幕里的预览时,附件仍可能被发送。限制附件发送需设置 images.blockImages。

Shell、默认工具和本地资源

shellPath 与 shellCommandPrefix 决定内置命令使用的解释器及前置内容。npmCommand 的每一项是独立参数,需要启用替代运行器时应在自己的环境验证参数传递。

defaultTools 中列出普通名称会替换基础选择。Pi 1.5.0 支持用全是 +名称 或 -名称 的项目列表增减用户已有选择。这项设定主要建立内置工具启动名单,自定义工具的注册与生效按对应接口处理。

enabledModels 用模型模式决定启动及 Ctrl+P 范围。包和显式资源路径可以来自用户和可信项目两处,项目资源的相对路径以 .pi 为基准。使用资源加载器处理两层清单,不能只从合并后的单个 settings 字段推断资源是否实际装入。会话目录也可配置,命令行和对应环境变量可以覆盖。

用户配置和项目设置

位置加载范围与效果
用户配置目录/settings.json用户级默认,包含 httpProxy 等仅在此层生效的字段。可用 PI_CODING_AGENT_DIR 更换目录。
项目目录/.pi/settings.json只加载可信项目的配置。项目可覆盖允许字段,部分集合会合并。

模型、推理和提醒

字段值类型初始行为与用途
defaultProvider字符串默认自动选择。指定启动时使用的模型提供方。
defaultModel字符串默认自动选择。填写所选提供方的模型 ID。
defaultThinkingLevel档位字符串缺省设置对象无此字段,程序启动的通常档位为 medium,并按模型能力限制。可写 off、minimal、low、medium、high、xhigh 或 max。
modelThinkingLevels对象默认空。用 provider/modelId 作为精确键设置特定模型的启动档位。
hideThinkingBlock布尔值默认 false。设为 true 隐藏终端对话中的推理块。
showCacheMissNotices布尔值默认 false。开启后报告达到条件的缓存未命中、缓存预热、压缩用量及恢复提示等。
thinkingBudgets对象缺省用运行时内置预算。可配置 minimal、low、medium 和 high 对应的 token 数,取决于提供方是否支持。
warnings.anthropicExtraUsage布尔值默认 true。订阅认证可能使用付费额外用量时打开提示。

界面、编辑和统计

字段值类型初始行为与用途
theme字符串Pi 1.5.0 默认按 system 选色。可配置内置或已加载的自定义主题。
externalEditor字符串未设置时取 VISUAL、EDITOR 或平台默认值。固定版 Windows 回退到 notepad,其他平台回退到 nano。
quietStartup布尔值或 header默认 false。true 隐藏启动头与资源列表,header 保留头部并隐藏模型范围与资源列表。
defaultProjectTrustask、always 或 never默认 ask,仅从用户配置读取。always 自动信任,never 默认拒绝。
collapseChangelog布尔值默认 false。开启后压缩显示程序更新记录。
enableInstallTelemetry布尔值默认 true,控制匿名安装、更新报告和指定归因头。版本检查另设控制。
enableAnalytics布尔值默认 false。固定版只在实验性首次设置中使用此选项。
doubleEscapeActiontree、fork 或 none默认 tree,在空编辑区连续按 Escape 时打开树。可改成分叉或无动作。
treeFilterMode字符串默认 default。可选 no-tools、user-only、labeled-only 或 all,控制 /tree 初始过滤。
editorPaddingX整数默认 0,编辑区横向留白按 0 到 3 个单元格配置。
outputPad0 或 1默认 1。控制会话消息、工具输出与摘要的横向留白。
autocompleteMaxVisible整数默认 5,补全列表可见条目建议在 3 到 20 范围设置。

网络代理

字段值类型初始行为与用途
httpProxy字符串默认不指定。用用户配置为 Pi 管理的 HTTP 客户端设置代理。

压缩

字段值类型初始行为与用途
compaction.enabled布尔值默认 true。允许在达到条件时自动压缩。
compaction.reserveTokens非负整数默认 16384 token。达到所设剩余空间阈值时准备压缩。
compaction.keepRecentTokens非负整数默认 20000 token。决定保留多少近期上下文原样进入后续轮次。

分支摘要

字段值类型初始行为与用途
branchSummary.reserveTokens数字默认 16384 token,为分支摘要保留空间。
branchSummary.skipPrompt布尔值默认 false。true 时不再询问,默认不生成摘要。

重试与延时

字段值类型初始行为与用途
retry.enabled布尔值默认 true。代理对可重试失败自动再尝试。
retry.maxRetries整数默认 3。限制代理级的重新尝试次数。
retry.baseDelayMs毫秒数默认 2000。作为指数退避的初始等待。
retry.provider.timeoutMs毫秒数省略时使用当前客户端的默认超时。1.5.0 文档将网络默认与 httpIdleTimeoutMs 关联。
retry.provider.maxRetries整数有效默认 0。单独控制提供方客户端重试,原始设置读取可能返回未设置。
retry.provider.maxRetryDelayMs毫秒数默认 60000。提供方所要求的重试延迟超过限制时停止。设 0 可去掉该上限。

消息队列与连接

字段值类型初始行为与用途
steeringModeall 或 one-at-a-time默认 one-at-a-time。决定运行中的导向消息集中送入或分次送入。
followUpModeall 或 one-at-a-time默认 one-at-a-time。决定当前运行结束后的跟进消息如何出队。
transportauto、sse、websocket 或 websocket-cached默认 auto。为具备多个传输选项的客户端设置偏好。
httpIdleTimeoutMs毫秒数或 disabled默认 300000。限制 HTTP 头部和响应体的空闲时间。设 0 或 disabled 禁用。
websocketConnectTimeoutMs毫秒数或 disabled网络层默认 15000。限制 WebSocket 连接时长,设 0 或 disabled 禁用。

终端绘制与模型图片输入

字段值类型初始行为与用途
terminal.showImages布尔值默认 true,在终端支持对应协议时绘制图片。
terminal.imageWidthCells数字默认 60 个单元格,设置图片的首选终端宽度。
terminal.clearOnShrink布尔值默认 false,可在内容缩小时清理空行。字段省略时也可由 PI_CLEAR_ON_SHRINK=1 启用。
images.autoResize布尔值默认 true。发给模型前将较大图片缩到最长边不超过 2000 像素。
images.blockImages布尔值默认 false,开启时阻止图片内容发送给模型。

本地命令与包管理

字段值类型初始行为与用途
shellPath字符串省略使用平台默认的 Shell,支持用 ~ 指向用户目录。
shellCommandPrefix字符串默认没有。将同一段前置内容加入 Shell 命令。
npmCommand字符串数组默认使用 npm。可依次提供程序和独立参数用于 npm 查询及安装。

默认工具

字段值类型初始行为与用途
defaultTools字符串数组缺省启用 read、bash、edit、write。可显式选择 grep、find、ls 或 Windows 的 powershell。普通名称直接选择工具。只用增减项时按原选择增减。

模型轮换、资源和会话目录

字段值类型初始行为与用途
enabledModels字符串数组默认所有可用模型。可按模式限定启动与 Ctrl+P 循环。
packages字符串与对象组成的数组没有额外包时为空。字符串给一个包来源,对象可追加 skills、extensions 等资源筛选。
extensions字符串数组显式扩展路径,缺省没有用户路径,也有单独管理的内置扩展。
skills字符串数组显式 Skill 文件或目录,默认无额外路径。
prompts字符串数组显式提示模板文件或目录,默认无额外路径。
themes字符串数组显式主题文件或目录,默认无额外路径。
enableSkillCommands布尔值默认 true,将可用 Skill 注册为 /skill:名称。
sessionDir字符串默认使用用户配置目录下的会话存储。相对目录按工作目录解释。环境变量 PI_CODING_AGENT_SESSION_DIR 或命令行 --session-dir 可以覆盖。

改变项目设置并观察两层配置和模板

javascript · 阅读源码
import assert from "node:assert/strict";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { basename, dirname, join, resolve } from "node:path";
import { pathToFileURL } from "node:url";

if (!process.argv[2]) throw new Error("Pass the directory containing the fixed node_modules.");
const api = resolve(process.argv[2], "@earendil-works", "pi-coding-agent");
const { SettingsManager } = await import(pathToFileURL(join(api, "dist/core/settings-manager.js")).href);
const { DefaultResourceLoader } = await import(pathToFileURL(join(api, "dist/core/resource-loader.js")).href);
const { SETTINGS_DEFAULTS } = await import(pathToFileURL(join(api, "dist/core/settings-defaults.js")).href);
const { version } = JSON.parse(await readFile(join(api, "package.json"), "utf8"));
const tmp = resolve(tmpdir());
const root = await mkdtemp(join(tmp, "mbsky-pi-settings-reference-"));
const cases = [];
function check(name, input, expected, actual) {
    assert.deepEqual(actual, expected, name);
    cases.push({ name, input, expected, actual, passed: true });
}
const save = (path, value) => writeFile(path, JSON.stringify(value, null, 2), "utf8");

try {
    const profile = join(root, "profile");
    const cwd = join(root, "work");
    const local = join(cwd, ".pi");
    await mkdir(profile);
    await mkdir(local, { recursive: true });
    const userConfig = join(profile, "settings.json");
    const projectConfig = join(local, "settings.json");
    const common = {
        defaultProvider: "catalog",
        defaultModel: "desk",
        modelThinkingLevels: { "catalog/desk": "medium", "catalog/archive": "low" },
        defaultProjectTrust: "never",
        httpProxy: "http://127.0.0.1:39999",
        compaction: { reserveTokens: 4000, keepRecentTokens: 12000 },
        branchSummary: { reserveTokens: 8000 },
        terminal: { showImages: false, imageWidthCells: 42 },
        images: { blockImages: false },
        enabledModels: ["catalog/*"],
        defaultTools: ["read"],
        extensions: ["./global-extension.ts"],
        skills: ["./global-skill"],
        prompts: ["./global-prompt.md"],
        themes: ["./global-theme.json"],
        packages: ["./global-package"],
    };
    const project = {
        defaultModel: "archive",
        modelThinkingLevels: { "catalog/archive": "high" },
        defaultProjectTrust: "always",
        httpProxy: "http://127.0.0.1:39998",
        compaction: { reserveTokens: 6000 },
        branchSummary: { skipPrompt: true },
        httpIdleTimeoutMs: "disabled",
        websocketConnectTimeoutMs: 2100,
        terminal: { clearOnShrink: true },
        images: { blockImages: true },
        enabledModels: ["catalog/archive"],
        defaultTools: ["+grep", "-read"],
        extensions: ["./work-extension.ts"],
        skills: ["./work-skill"],
        prompts: ["./work-prompt.md"],
        themes: ["./work-theme.json"],
        packages: [{ source: "./work-package", skills: ["work-skill"] }],
        enableSkillCommands: false,
        sessionDir: "./stage-sessions",
    };
    await save(userConfig, common);
    await save(projectConfig, project);
    const trusted = SettingsManager.create(cwd, profile, { projectTrusted: true });
    const ignored = SettingsManager.create(cwd, profile, { projectTrusted: false });
    const stock = SettingsManager.inMemory();
    check("project_value_requires_trust", ["defaultModel", "project trust"], ["archive", "desk", "catalog", "never"],
        [trusted.getDefaultModel(), ignored.getDefaultModel(), trusted.getDefaultProvider(), trusted.getDefaultProjectTrust()]);
    check("thinking_map_merges_exact_keys", ["catalog/archive", "catalog/desk", "other/desk"],
        ["high", "medium", null],
        [trusted.getModelThinkingLevel("catalog", "archive"), trusted.getModelThinkingLevel("catalog", "desk"),
         trusted.getModelThinkingLevel("other", "desk") ?? null]);
    check("nested_compaction_and_branch_values", ["compaction", "branchSummary"],
        [{ enabled: true, reserveTokens: 6000, keepRecentTokens: 12000 }, { reserveTokens: 8000, skipPrompt: true }],
        [trusted.getCompactionSettings(), trusted.getBranchSummarySettings()]);
    check("optional_default_model_and_thinking_keys_are_absent", {}, [null, null, null, false, false, null, true],
        [stock.getDefaultProvider() ?? null, stock.getDefaultModel() ?? null, stock.getDefaultThinkingLevel() ?? null,
         stock.getHideThinkingBlock(), stock.getShowCacheMissNotices(), stock.getThinkingBudgets() ?? null, stock.getWarnings().anthropicExtraUsage ?? SETTINGS_DEFAULTS.warnings.anthropicExtraUsage]);
    check("ui_accessor_defaults", {}, [null, false, "ask", false, true, false, "tree", "default", 0, 1, 5],
        [stock.getThemeSetting() ?? null, stock.getQuietStartup(), stock.getDefaultProjectTrust(),
         stock.getCollapseChangelog(), stock.getEnableInstallTelemetry(), stock.getEnableAnalytics(),
         stock.getDoubleEscapeAction(), stock.getTreeFilterMode(), stock.getEditorPaddingX(),
         stock.getOutputPad(), stock.getAutocompleteMaxVisible()]);
    check("global_proxy_value_comes_from_profile_layer", "configured URL lookup without client requests", common.httpProxy,
        trusted.getGlobalSettings().httpProxy);
    const retry = stock.getRetrySettings();
    const providerRetry = stock.getProviderRetrySettings();
    check("stock_retry_settings_and_transport_inputs",
        ["retry", "provider retry", "transport", "timeout accessors"],
        [true, 3, 2000, null, null, 60000, "one-at-a-time", "one-at-a-time", "auto", 300000, null, 0, 2100],
        [retry.enabled, retry.maxRetries, retry.baseDelayMs, providerRetry.timeoutMs ?? null,
         providerRetry.maxRetries ?? null, providerRetry.maxRetryDelayMs,
         stock.getSteeringMode(), stock.getFollowUpMode(), stock.getTransport(), stock.getHttpIdleTimeoutMs(),
         stock.getWebSocketConnectTimeoutMs() ?? null, trusted.getHttpIdleTimeoutMs(), trusted.getWebSocketConnectTimeoutMs()]);
    check("image_display_is_independent_of_image_submission", ["terminal", "images"],
        [[true, 60, false, true, false], [false, 42, true, true, true]],
        [stock, trusted].map(view => [view.getShowImages(), view.getImageWidthCells(), view.getClearOnShrink(),
         view.getImageAutoResize(), view.getBlockImages()]));
    check("advanced_display_default_values", {},
        ["fullscreen", "transcript", "auto", true, "auto", {}, "streaming"],
        [stock.getTuiMode(), stock.getFullscreenExitOutput(), stock.getFullscreenScrollbar(),
         stock.getFullscreenCopyOnSelect(), stock.getFullscreenWheelScrollLines(), stock.getTerminalCapabilityOverrides(),
         stock.getMermaidRenderingMode()]);
    check("tool_modifiers_and_model_arrays_resolve_separately", ["+grep", "-read", "catalog/archive"], [["grep"], ["catalog/archive"]],
        [trusted.getDefaultTools(), trusted.getEnabledModels()]);
    const keys = ["extensions", "skills", "prompts", "themes", "packages"];
    const readLayers = (key) => [trusted.getGlobalSettings()[key], trusted.getProjectSettings()[key]];
    check("resource_settings_keep_both_layers", keys, keys.map(key => [common[key], project[key]]), keys.map(readLayers));
    check("skill_command_registration_setting_can_be_disabled", "enableSkillCommands", [true, false],
        [stock.getEnableSkillCommands(), trusted.getEnableSkillCommands()]);
    const separate = join(root, "prompts-profile");
    const promptsCwd = join(root, "prompts-work");
    const promptsLocal = join(promptsCwd, ".pi");
    await mkdir(separate);
    await mkdir(promptsLocal, { recursive: true });
    await save(join(separate, "settings.json"), { prompts: ["./global-note.md"] });
    await save(join(promptsLocal, "settings.json"), { prompts: ["./project-note.md"] });
    await writeFile(join(separate, "global-note.md"), "Global example paragraph.", "utf8");
    await writeFile(join(promptsLocal, "project-note.md"), "Project example paragraph.", "utf8");
    const combined = new DefaultResourceLoader({ cwd: promptsCwd, agentDir: separate,
        settingsManager: SettingsManager.create(promptsCwd, separate, { projectTrusted: true }),
        noExtensions: true, noSkills: true, noThemes: true, noContextFiles: true });
    await combined.reload();
    check("prompt_loader_combines_resolved_user_and_project_files", ["./global-note.md", "./project-note.md"],
        [["global-note", "Global example paragraph."], ["project-note", "Project example paragraph."]],
        combined.getPrompts().prompts.map(prompt => [prompt.name, prompt.content.trim()]).sort());
    check("session_dir_is_configurable", "sessionDir", ["stage-sessions", null],
        [basename(trusted.getSessionDir()), ignored.getSessionDir() ?? null]);
    await save(projectConfig, { ...project, defaultTools: ["find"], compaction: { reserveTokens: 7200 } });
    await trusted.reload();
    check("reload_replaces_plain_tool_array_and_preserves_nested_fields", ["find", 7200], [["find"], 7200, 12000],
        [trusted.getDefaultTools(), trusted.getCompactionReserveTokens(), trusted.getCompactionKeepRecentTokens()]);
    assert.equal(JSON.stringify(JSON.parse(await readFile(userConfig, "utf8"))), JSON.stringify(common));
    process.stdout.write(JSON.stringify({ nodeVersion: process.version, packageVersion: version, cases }) + "\n");
} finally {
    assert.equal(dirname(root), tmp);
    assert.ok(basename(root).startsWith("mbsky-pi-settings-reference-"));
    await rm(root, { recursive: true, force: true });
}
预期结果 · 待实际运行核验
  • 可信项目覆盖允许的字段。嵌套字段保留未覆盖的默认值,资源加载器读取用户及项目两个本地提示模板。
改变项目设置并观察两层配置和模板

所需环境:Windows,Pi 1.5.0,Node.js 24.22.3,本地临时配置文件。

当前源码 SHA256:4788f8e474aa99b3d9727edc2d0831a6feaf1985d64b8ac023f2535ad4f4fa36

下载本站示例源码

在临时目录复跑

解压并按 README 运行,查看有效值和提示模板内容。

下载 Pi 配置本地实验

所需环境:Windows,Pi 1.5.0,Node.js 24.22.3,本地临时配置文件。

ZIP SHA256:948298659b852f688d979ad563c0a21d6f0287b11c9359578bb6f06c96fe97f0

常见错误与边界

  • 只有信任后才允许项目设置覆盖。
  • 识别有效默认行为与未设置的原始字段。

练习与解答

将项目工具数组改为普通工具名会怎样?

展开参考解答

重新加载后读取启用列表,看它是否替换用户级选择。

规范与官方依据