Skip to content

Commit 95fd5cb

Browse files
authored
chore: update docs (#151)
1 parent 7ce00c6 commit 95fd5cb

4 files changed

Lines changed: 40 additions & 28 deletions

File tree

docs/reference/how-it-works.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,23 @@ Notes:
9494

9595
- Built-in command candidates cover common cloud tools even before PATH discovery runs.
9696
- Built-in tree-shaped subcommands cover common `git`, `docker`, and `kubectl` nested commands even before dynamic discovery runs.
97-
- Typo caches discovered subcommands in `~/.typo/subcommands.json` using `schema_version: 2`.
97+
- Typo caches discovered subcommands in `~/.typo/subcommands.json` using `schema_version: 3`.
9898
- Hierarchical subcommand discovery is supported for `git`, `docker`, `aws`, `gcloud`, and `az`; `kubectl` resource correction uses a conservative built-in resource tree.
99-
- Older subcommand cache files without `schema_version: 2` are moved aside automatically and regenerated.
99+
- Older subcommand cache files without `schema_version: 3` are moved aside automatically and regenerated.
100100

101-
### Subcommand cache version 2
101+
### Subcommand cache version 3
102102

103103
`subcommands.json` uses a versioned tree format:
104104

105105
```json
106106
{
107-
"schema_version": 2,
107+
"schema_version": 3,
108108
"tools": [
109109
{
110110
"tool": "git",
111111
"tree": {
112+
"long_options": ["--help", "--version"],
113+
"long_options_with_values": ["--git-dir", "--work-tree"],
112114
"children": {
113115
"stash": {
114116
"children": {
@@ -123,22 +125,26 @@ Notes:
123125
}
124126
```
125127

126-
Version 2 stores nested subcommands directly instead of keeping a flat root list
127-
plus path-specific child lists. This lets typo correct each command level
128-
independently, for example `gcloud container clusers lisr` to
129-
`gcloud container clusters list`.
128+
Version 3 keeps the nested command tree format and adds long-option metadata to
129+
tree nodes. This lets typo correct each command level independently, for example
130+
`gcloud container clusers lisr` to `gcloud container clusters list`, while also
131+
keeping the option candidates used by experimental `--long-option` correction in
132+
the same cache.
130133

131134
Node fields have these meanings:
132135

133136
- `children`: valid child tokens below the current level
134137
- `terminal`: the token can end a command path
135138
- `passthrough`: arguments after this token are treated as user input, not subcommands
136139
- `alias`: canonical token to output when a short alias is used
137-
138-
If typo finds an older cache format, it renames that file to
139-
`subcommands.json.corrupt-<timestamp>` and rebuilds a fresh version 2 cache on
140-
next use. The file only contains discovered command metadata, so no user rules,
141-
history, or configuration are lost.
140+
- `long_options`: known `--long-option` tokens visible at this node
141+
- `long_options_with_values`: known `--long-option` tokens that consume the next argument
142+
143+
If typo finds an older cache format, including version 2 or files without a
144+
schema version, it renames that file to
145+
`subcommands.json.corrupt-<timestamp>` and rebuilds a fresh version 3 cache on
146+
next use. The file only contains discovered command metadata and option
147+
metadata, so no user rules, history, or configuration are lost.
142148

143149
## Local files
144150

docs/reference/how-it-works_CN.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,23 @@ Typo 不仅能修正顶层命令,也能修正常见工具的子命令。
8787

8888
- 常用云工具会作为内置命令候选加入,即使 PATH 发现还没执行,也能先修正顶层命令。
8989
- `git``docker``kubectl` 内置了树形子命令结构,即使动态发现还没执行,也能修正常见多层子命令。
90-
- 动态发现到的子命令会以 `schema_version: 2` 的树形结构缓存到 `~/.typo/subcommands.json`
90+
- 动态发现到的子命令会以 `schema_version: 3` 的树形结构缓存到 `~/.typo/subcommands.json`
9191
- `git``docker``aws``gcloud``az` 支持层级化子命令发现;`kubectl` 资源修正使用保守的内置资源树。
92-
- 不符合 `schema_version: 2` 的旧子命令缓存会被自动隔离,并在后续使用时重新生成。
92+
- 不符合 `schema_version: 3` 的旧子命令缓存会被自动隔离,并在后续使用时重新生成。
9393

94-
### 子命令缓存 v2
94+
### 子命令缓存 v3
9595

9696
`subcommands.json` 使用带版本号的树形格式:
9797

9898
```json
9999
{
100-
"schema_version": 2,
100+
"schema_version": 3,
101101
"tools": [
102102
{
103103
"tool": "git",
104104
"tree": {
105+
"long_options": ["--help", "--version"],
106+
"long_options_with_values": ["--git-dir", "--work-tree"],
105107
"children": {
106108
"stash": {
107109
"children": {
@@ -116,16 +118,18 @@ Typo 不仅能修正顶层命令,也能修正常见工具的子命令。
116118
}
117119
```
118120

119-
v2 会直接保存嵌套子命令,不再使用“根级扁平列表 + 路径子列表”的旧格式。这样 Typo 可以逐层修正命令,例如把 `gcloud container clusers lisr` 修正为 `gcloud container clusters list`
121+
v3 保留嵌套命令树格式,并在树节点上增加长选项元数据。这样 Typo 既可以逐层修正命令,例如把 `gcloud container clusers lisr` 修正为 `gcloud container clusters list`,也可以把实验性 `--long-option` 修正所需的候选保存在同一份缓存里
120122

121123
节点字段含义如下:
122124

123125
- `children`:当前层级下的有效子命令。
124126
- `terminal`:该 token 可以作为命令路径的结束。
125127
- `passthrough`:该 token 后面的内容按用户参数处理,不再继续当作子命令修正。
126128
- `alias`:短别名对应的规范输出名称。
129+
- `long_options`:当前节点可见的已知 `--long-option` token。
130+
- `long_options_with_values`:当前节点可见、且会消费下一个参数的已知 `--long-option` token。
127131

128-
如果 Typo 发现旧格式缓存,会把该文件重命名为 `subcommands.json.corrupt-<时间戳>`,并在下次使用时重新生成 v2 缓存。该文件只包含动态发现到的命令元数据,不包含用户规则、历史记录或配置,因此隔离旧缓存不会丢失用户数据。
132+
如果 Typo 发现旧格式缓存,包括 v2 或没有 schema 版本的文件,会把该文件重命名为 `subcommands.json.corrupt-<时间戳>`,并在下次使用时重新生成 v3 缓存。该文件只包含动态发现到的命令元数据和选项元数据,不包含用户规则、历史记录或配置,因此隔离旧缓存不会丢失用户数据。
129133

130134
## 本地文件
131135

docs/troubleshooting/upgrade-from-0x.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ The `~/.typo/` directory layout has expanded:
101101

102102
### Subcommand cache format
103103

104-
Current v1 builds write `subcommands.json` with `schema_version: 2`. This format
105-
stores a tree of subcommands so typo can correct nested command paths such as
106-
`aws cloudformation wait stack-create-complete` and
107-
`gcloud container clusters list`.
108-
109-
Older cache files from previous builds may not have a `schema_version` field or
110-
may use a flat list format. On first load, typo moves those files aside as
104+
Current v1 builds write `subcommands.json` with `schema_version: 3`. This format
105+
stores a tree of subcommands plus long-option metadata so typo can correct nested
106+
command paths such as `aws cloudformation wait stack-create-complete` and
107+
`gcloud container clusters list`, and can reuse cached option candidates for
108+
experimental `--long-option` correction.
109+
110+
Older cache files from previous builds may not have a `schema_version` field,
111+
may use a flat list format, or may use the previous tree-only version 2 format.
112+
On first load, typo moves those files aside as
111113
`subcommands.json.corrupt-<timestamp>` and creates a fresh cache when
112114
subcommand discovery runs again.
113115

docs/troubleshooting/upgrade-from-0x_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ Invoke-Expression (& typo init powershell | Out-String)
101101

102102
### 子命令缓存格式
103103

104-
当前 v1 版本写入的 `subcommands.json` 使用 `schema_version: 2`。该格式保存树形子命令,因此 Typo 可以修正 `aws cloudformation wait stack-create-complete``gcloud container clusters list` 这类多层命令路径。
104+
当前 v1 版本写入的 `subcommands.json` 使用 `schema_version: 3`。该格式保存树形子命令和长选项元数据,因此 Typo 可以修正 `aws cloudformation wait stack-create-complete``gcloud container clusters list` 这类多层命令路径,也可以复用缓存中的选项候选来支持实验性 `--long-option` 修正
105105

106-
旧版本生成的缓存可能没有 `schema_version` 字段,也可能使用扁平列表格式。Typo 首次加载时会把这些旧缓存隔离为 `subcommands.json.corrupt-<时间戳>`,并在下一次执行子命令发现时重新生成缓存。
106+
旧版本生成的缓存可能没有 `schema_version` 字段,也可能使用扁平列表格式,或使用上一版仅包含树形子命令的 v2 格式。Typo 首次加载时会把这些旧缓存隔离为 `subcommands.json.corrupt-<时间戳>`,并在下一次执行子命令发现时重新生成缓存。
107107

108108
不需要手动迁移。该缓存不保存用户规则、历史记录或配置。如果需要强制刷新,可以删除 `~/.typo/subcommands.json`,然后运行会触发子命令修正的命令。
109109

0 commit comments

Comments
 (0)