Repository navigation
写设置、存删 API Key、列要 key 的服务,都能从命令做:settings set、settings mirror --no-chrome --json、settings keys、keys save、keys clear;settings --json 多了 exports - #268
Merged
Conversation
…orts - settings set <名> <值>|--unset [--json]:Studio 的三项设置,--json 打出写完以后 settings --json 的记录 - settings mirror … [--no-chrome] [--json]:--no-chrome 只改设置,不接着下 HyperFrames 的 Chrome;--json 时 stdout 只有记录 - settings --json 的 exports:bin/vh 为镜像设置导出或去掉的每个变量在这次运行里的值 - settings keys [--json]、keys save <名>(key 从标准输入读)、keys clear <名>:经 tools/keys.py,从不输出 key 的值 - 失败一律是 tools/jsonerr.py 的记录;schema、contract_checks、smoke_checks 两项新检查、文档和变更记录
… typed word is said back only when it is a word; checks: security's arguments on macOS, root, clear with no store
…n unknown word is said back only when it is a word
…h settings --json is the one to follow (a variable of the person's own at a mirror's address)
…no store is refused before); the line without a store reads plainly
…that goes up with each command, subcommand, option or --json field a client may use
ZLHad
marked this pull request as ready for review
December 1, 2026 17:59
ZLHad
enabled auto-merge (squash)
December 1, 2026 17:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
仓库外的客户端改这台机器的设置、存删服务的 API Key 时,还要 import
tools/settings.py、tools/keys.py。docs/project-format.md写明接口是片子的文件夹和bin/vh … --json,模块不是接口;这个 PR 把写的这一半补成bin/vh settings的子命令,没有加顶层命令(还是 74 条)。全是加法:不带新开关时,原有命令的输出一个字没变(-h和用法错误里的 usage 行多了新开关)。studio_lang、studio_theme、agent_default)bin/vh settings set <名> <值> [--json],set <名> --unset [--json]settings.set_studiobin/vh settings mirror cn|off|auto [--why TEXT] [--no-chrome] [--json]settings.set_mirrorbin/vh settings --json的新字段exportsin_effect()加上OVH_MIRRORbin/vh settings keys [--json]keys.store_kind、source、stored,tools/modules.jsonbin/vh settings keys save <名> [--json](key 从标准输入读一行,终端里输入时不显示),keys clear <名> [--json]keys.save、keys.clearbin/vh version --json的新字段interface(文字那一行末尾多 " · interface 1")tools/commands.json的interface带
--json时:set、mirror打出写完以后bin/vh settings --json的那份记录,keys save、keys clear打出改完以后的bin/vh settings keys --json;stdout 只有这一条,给人看的字走 stderr。settings keys --json的形状:{"version": 1, "tool", "store": "keychain"|"secret-service"|"none", "keys": [{"name", "source": "env"|"studio"|null, "saved"}], "services": [{"module", "keys", "cost", "key_url", "probe"}]},services是tools/modules.json里kind为 service、带needs.keys的行,按表里的顺序;从不输出 key 的值。出错码,都经
tools/jsonerr.py:名字或值不对、keys save名字后面还有东西是usage(退出码 2);设置文件是更新的版本写的是refused(1);设置写不进、存储没收下是failed(1);标准输入来的不像 key 或什么也没来是invalid(2);这台电脑没有密码存储时keys save是missing_tool(1)。几处取舍,为什么
exports给最终值,不给差值。bin/vh开头已经按设置改过一次环境,在命令里算"还差多少"是对着改过的环境算的:比如 cn 再选 cn,差值是空的,调用方就拿不到要设的变量。最终值没有这个问题,重复设也不出错。值就是这次运行里的样子:in_effect()加上OVH_MIRROR,没有的是null。settings mirror <模式> --json的记录按新设置算exports。 这条命令开头是按旧设置改的环境;写完以后先照新设置再走一遍bin/vh开头那一步(settings.follow()),再打记录,所以它和紧接着跑一次bin/vh settings --json打出的相同(CI 查了 cn、从 cn 回 auto、带着一个人自己设的变量这几种)。只有一种情况两者不一样:人自己设的某个镜像变量恰好等于镜像的地址、又不是从bin/vh继承来的,原来是 cn、改成别的;这时mirror --json的记录里它是null,接着跑的settings --json里它留着。要的是精确的最终值,改完再读一次bin/vh settings --json,-h写了这一句。settings keys的三条由tools/keys.py执行。static_checks的 keyreads 把"跟 key 有关的文件"里按变量名读环境的每一处都当成可能在读 key,只有tools/keys.py是例外;tools/settings.py一旦 importkeys,它读镜像变量的五处就都会被拦。所以bin/vh把settings keys …交给python3 tools/keys.py settings …(keys.cli()),settings.py不 importkeys,直接跑python3 tools/settings.py keys …时它转交过去。bin/vh settings keys -h照旧打印bin/vh settings -h,字段和出错码都写在那里。services[].keys是 key 名的列表,每个 key 的source、saved在外层的keys里,不在每家服务下面再抄一遍。记录里另有tool,和别的命令的记录一样。keys clear退出码 0:没有东西可删,keys.clear本来也不报错。keys save在那里是missing_tool,在读标准输入之前就拒绝,终端里不会先让人输一遍。keys save名字后面多出来的东西、set不认识的名字和值、settings不认识的子命令(只在它像一个词时照说),都不在报错里重复:那可能是贴错地方的 key。jsonerr 的记录本来就过activity.scrub,这里连 stderr 也不说。NotAKey那句在命令里换了说法("what came for NAME is not an API key"):原话 "NAME: that is …" 会被 scrub 当成"秘密的名字: 值",把 "that" 遮掉。bin/vh version --json多了interface。 握手时客户端拿format、commands和自己要的比;可commands是tools/commands.json的版本,也就是bin/vh commands --json的形状,加命令、加子命令、加--json字段时它都不动,客户端换成这些命令以后,遇到旧的 Core 只会在某个请求上失败,说不出该更新了。interface是表里的一个整数:每加一条客户端可能用到的命令、子命令、开关或--json字段它加一,只加不减(删掉什么、改了意思,是format或commands的版本的事);客户端要几就要求至少是几,没有这个字段的 Core 比 1 旧。1 是 读一支片子要的数据,都能从命令拿到:artifacts read、status --light、projects <项目>、review --body、--stage、--words#266 读一支片子数据的那几条,加上这个 PR 的这些,表的note写着。tools/version.py照读format、commands的办法读它,不是整数就是null(version.schema.json里和那两个一样允许null);tools/commands.py check查它是 1 以上的整数。bin/vh commands --json不带出表的顶层键,commands.schema.json不用动。--why吃掉它后面的一个词,不管是什么:mirror cn --why --no-chrome记下的理由就是 "--no-chrome",照样下 Chrome。bin/vh里判断--no-chrome的那一行照同一个规矩;几个开关在模式后面不分先后。其他:
bin/vh settings的失败以前带--json时 stdout 是空的,现在是 jsonerr 的记录(settings.py和keys.py的入口套了jsonerr.guard;python3 tools/settings.py env照旧,bin/vh开头和install.sheval 的输出不变);set、mirror、keys后两个词里有-h时打印帮助;tools/commands.json的settings写上三组用法和四个子命令,version的用法写上interface;CONTRIBUTING.md讲新命令的几条里加一句:加了客户端会用的命令、子命令、开关或--json字段,interface跟着加一;tools/schemas/output/新的settings-keys.schema.json,settings.schema.json加exports;docs/project-format.md:客户端握手那句补上interface和它什么时候加一,要数据找哪条命令的表加四行,新的一节"这台机器的设置和 API Key";changes/settings-writes.md。怎么验证的
tools/ci.sh --committed,照 GitHub 的 macOS 跑(/bin/bash3.2、LC_ALL=en_US.UTF-8、uv 的 shellcheck、pyflakes)。头783edb1:19 分 28 秒,677 ✓(连汇总行)、0 ✗、1 项跳过(HyperFrames 合成上取帧:临时检出没装styles/_swatch的依赖,和以前一样)。和 读一支片子要的数据,都能从命令拿到:artifacts read、status --light、projects <项目>、review --body、--stage、--words#266 最后一次整跑的检查名单逐行比:多了两条新检查(smoke_checks里写设置的那条和settings keys那条),studio_checks的 version 那条多查interface;contract_checks的数见下;keys、modules 两项搜的文件各多两个(两个新的 CI 文件),变更记录的条数跟着多了,白名单那一行的数来自 过渡期的 import 白名单只剩四行:activity、jsonerr、keys、settings #267;其余只有一处量出来的毫秒数。smoke_checks的settings_commands.py:从一份bin/vh的副本跑(styles/_swatch里放一个替身 HyperFrames,它的browsers只记下每次调用,什么也不下),临时的 HOME、设置文件和工作目录,环境里没有本机的镜像变量。set、--unset、mirror的--json记录和紧接着的settings --json相同、和tools/settings.py的函数在同一环境下给的相同;cn 时exports是每个镜像变量和OVH_MIRROR=cn;带着这些继承来的变量改回 auto,每个都是null,人自己设的那个留着;给人看的字在 stderr;--no-chrome什么也不下,不带它时下一次、它的字在 stderr,--why --no-chrome记下理由、照样下;版本更新的设置文件refused、写不进的目录failed,不出 traceback。smoke_checks的keys_store.py:在检查自己的密码存储上做,macOS 是临时目录里的一个钥匙串文件(HOME 也设在那里,每次调用都点名它),Linux 是一个替身secret-tool(存在一个文件里,记下每次的参数),服务名也是自己的。OVH_KEYSTORE=none时save是missing_tool、clear没东西可删;存进去以后source是 studio、saved为真,bin/vh doctor --json的key_source也说 studio;环境里还有同名变量时source是 env;删掉以后都没了;不像 key 的值、什么也没来、不认识的名字、key 放在命令参数里,都被拒绝;终端里(pty)提示出现、输入的 key 不回显;tools/keys.py自己的存、找、环境优先、删;假装成 Linux 时keys.local_way那两句"没有不用 key 的办法"的说法。用过的假 key 从不出现在 stdout、stderr 里,也不在存储程序的参数里(macOS 上给security套了一层只记参数的外壳)。studio_checks的 version 那一项:interface和表里的一样,是整数,文字那一行也带着它。contract_checks:新 schemasettings-keys,version.schema.json要求interface,settings set、settings mirror auto --no-chrome、settings keys的--json输出对着 schema 查,6 种新的失败对着错误的形状、code和退出码查。数:44 → 47 份输出、33 → 34 条命令、349 → 356 个字段、112 → 118 种失败、34 → 35 份 schema。exports少了OVH_MIRROR、mirror --json不按新设置算、给人看的字进了 stdout、不认--no-chrome、把--why的词当开关、set --json不打记录、更新版本的文件说成failed、source不看环境、saved恒假、存的时候把 key 说出来、不像 key 说成failed、收下命令参数里的 key、终端里回显、doctor的key_source、Linux 那两句、把 key 当security的参数);没抓到的是把services[].probe改成恒真:表里要 key 的四家服务现在都有 probe,看不出来。settings、settings --json、mirror cn|off|auto [--why]、mirror --get、用法错误、settings chrome、python3 tools/settings.py env [--mode],在同一个临时环境里和 main 的版本逐字比,只差exports和 usage 行里的新开关。sys.platform),keys_store.py走替身secret-tool整个跑通;GitHub 的 Linux 那一项会真跑一遍。settings不认识的子命令以前整行照说(打错一个字的settings key save NAME <key>会把 key 打到 stderr),现在只说像词的那一个;写不进目录的那一项在 root 下跳过;没有存储时clear的结果也查;macOS 上给security加了记参数的外壳。