Repository navigation
fix(cli): getConfiguredPlatforms 增加磁盘存在校验 #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
wang93wei
wants to merge
5
commits into
mindfold-ai:main
from
wang93wei:fix/configured-platforms-disk-check
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7cba637
fix(cli): getConfiguredPlatforms 增加磁盘存在校验
wang93wei 7f428f5
docs(trellis): 归档 09-03-fix-configured-platforms-disk-check 任务
wang93wei 8756a57
chore: record journal
wang93wei 29801a4
fix(cli): 硬化 getConfiguredPlatforms 磁盘校验
wang93wei 077859e
docs(trellis): 同步归档任务文档与加固后的实现
wang93wei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
.trellis/tasks/archive/2026-09/09-03-fix-configured-platforms-disk-check/check.jsonl
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"file": ".trellis/spec/cli/unit-test/index.md", "reason": "verify test conventions and minimal mocking"} |
66 changes: 66 additions & 0 deletions
66
.trellis/tasks/archive/2026-09/09-03-fix-configured-platforms-disk-check/design.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Design: getConfiguredPlatforms 增加磁盘存在校验 | ||
|
|
||
| ## Problem | ||
|
|
||
| `getConfiguredPlatforms(cwd)`(`packages/cli/src/configurators/index.ts:138`)的判定条件: | ||
|
|
||
| ```ts | ||
| const hasTrackedTemplate = [...(templates?.keys() ?? [])].some( | ||
| (relativePath) => | ||
| (relativePath === configDir || | ||
| relativePath.startsWith(`${configDir}/`)) && | ||
| hashes[relativePath] !== undefined, // ← 只看 hash,不看磁盘 | ||
| ); | ||
| ``` | ||
|
|
||
| hash manifest 是"曾经写过"的记录,不是"现在存在"的事实。平台目录被删除(换机 clone 未提交、`.gitignore` 忽略如 `.cursor/`、手动清理)后,`init --<platform>` re-init 路径(`commands/init.ts:880`)误判 skipping,`platforms`(`commands/platforms` 经同一函数)虚报,`update`(`commands/update.ts:693,870`)对不存在的目录做收集。 | ||
|
|
||
| ## Decision | ||
|
|
||
| 在 `hasTrackedTemplate` 为真之外,叠加一个条件:**`configDir` 在磁盘上存在**。 | ||
|
|
||
| ```ts | ||
| if (hasTrackedTemplate && fs.existsSync(path.join(cwd, configDir))) { | ||
| platforms.add(id); | ||
| } | ||
| ``` | ||
|
|
||
| ### Why configDir existence (而不是逐文件校验) | ||
|
|
||
| 1. **便宜**:每平台一次 `stat`,O(platforms);逐文件是 O(files),hash 有 560 条。 | ||
| 2. **与检测键对齐**:现有检测只统计 `configDir` 前缀下的跟踪路径,`configDir` 就是判定锚点;目录缺失是最常见、最完整的"未配置"形态(本次复现即 7 个目录整体缺失)。 | ||
| 3. **有先例**:同一函数内的 legacy Windsurf→devin 分支就是"hash + 磁盘(readdir trellis-*)"双条件。 | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| 4. **部分缺失归 `update` 管**:单个文件被删属于内容漂移,应由 `update` 的 diff/修复逻辑处理,不在本函数职责内(Non-Goals)。 | ||
|
|
||
| ### Considered alternative: 要求 ≥1 个被跟踪文件存在于磁盘 | ||
|
|
||
| 更精确,能覆盖"目录在但文件被掏空"的部分缺失;但引入 O(files) 的 I/O,且"部分缺失算不算已配置"本身是产品语义问题(`init` 跳过 vs `update` 修复),不宜在这次顺手定。保持最小修复。 | ||
|
|
||
| ## Blast radius | ||
|
|
||
| `getConfiguredPlatforms` 的消费方(同函数语义自动跟随,无需逐个改): | ||
|
|
||
| | Caller | 修复后的行为变化 | | ||
| |---|---| | ||
| | `commands/init.ts:783` re-init / `:840,:870` 未配置列表 | 目录缺失的平台重新出现在可添加列表,`--<platform>` 不再误 skipping ✅ 目标修复 | | ||
| | `commands/platforms`(经 `configurators/index`)/ `cli/index.ts:364` | 不再虚报已删除的平台 | | ||
| | `commands/update.ts:693,870` | 不再对磁盘缺失的平台做模板收集(之前是对着不存在的目录算 diff,实际无输出) | | ||
| | `commands/uninstall.ts:207` | 已删除的平台不再出现在可卸载列表(删本来就不存在的东西无意义) | | ||
| | `commands/ablate.ts:381` | 同上跟随 | | ||
|
|
||
| 无反向风险:`configDir` 存在 + hash 命中的平台行为与之前完全一致;原生目录(无 hash)仍不算已配置,#501 语义保留。 | ||
|
|
||
| ## Edge cases | ||
|
|
||
| - 嵌套 `configDir`(kiro `.kiro/skills`、snow `.snow/skills`):`existsSync(join(cwd, configDir))` 对嵌套路径同样有效;父目录在但 `skills/` 被删 → 判未配置 → 重装,符合预期。 | ||
| - `extraManagedPaths` / 共享 `.agents/skills`:检测键本来就不含它们(#501 已排除),本次不碰。 | ||
| - manifest 缺失/损坏:`loadHashes` 返回空 → 本来就是空集,`existsSync` 短路在 `hasTrackedTemplate` 之后,无新增 I/O 失败面(`existsSync` 不抛异常)。 | ||
|
|
||
| ## Tests | ||
|
|
||
| 在 `packages/cli/test/configurators/platforms.test.ts` 的 `getConfiguredPlatforms` describe 内新增: | ||
|
|
||
| 1. `does not report a platform whose tracked directory was deleted` —— 为某平台生成 hash(复用现有 `configurePlatform` + `initializeHashes` 写法),然后 `rmSync(configDir)`,断言不再包含该平台(且其它平台不受影响可选)。 | ||
| 2. 现有用例即回归网:`detects every platform from the files Trellis tracked`(存在+hash → 检测到)、`does not treat native platform directories`(存在+无 hash → 不检测)保持全绿。 | ||
|
|
||
| 验证命令:`pnpm test test/configurators/platforms.test.ts`,另跑 `pnpm lint` + `pnpm typecheck`。 | ||
2 changes: 2 additions & 0 deletions
2
.trellis/tasks/archive/2026-09/09-03-fix-configured-platforms-disk-check/implement.jsonl
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {"file": ".trellis/spec/cli/backend/index.md", "reason": "CLI backend command/configurator conventions for init + platform detection"} | ||
| {"file": ".trellis/spec/cli/unit-test/index.md", "reason": "vitest conventions for the regression test in platforms.test.ts"} |
36 changes: 36 additions & 0 deletions
36
.trellis/tasks/archive/2026-09/09-03-fix-configured-platforms-disk-check/prd.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # 修复 getConfiguredPlatforms 误判:hash 有记录但磁盘文件缺失时 init --opencode 误报 skipping | ||
|
|
||
| ## Goal | ||
|
|
||
| `getConfiguredPlatforms()` 增加磁盘存在校验:当 `.trellis/.template-hashes.json` 有某平台的跟踪记录、但该平台配置目录在磁盘上已缺失时,不再将其判定为"已配置"。`init --<platform>`、`platforms`、`update` 等消费方行为保持一致。 | ||
|
|
||
| ## Background | ||
|
|
||
| 线上复现(WanLingBot 仓库):`.template-hashes.json` 跟踪 560 个文件(含 `.opencode` 57 条),但磁盘上 `.opencode/` 等 7 个平台目录全部缺失(仅 `.agent` 存在)。此时 `trellis init --opencode` 走 re-init 快捷路径,命中 `configuredPlatforms.has("opencode")`,直接输出 `○ OpenCode already configured, skipping`,什么文件都没写。`trellis platforms` 同样虚报 8 个已配置。 | ||
|
|
||
| 根因:`packages/cli/src/configurators/index.ts:getConfiguredPlatforms` 只检查 hash manifest,不检查磁盘。 | ||
|
|
||
| ## Requirements | ||
|
|
||
| - [ ] R1: `getConfiguredPlatforms(cwd)` 对每个平台,在 hash 命中之外,额外要求该平台 `configDir` 在磁盘上存在(`fs.existsSync(path.join(cwd, configDir))`),两者同时满足才算已配置。 | ||
| - [ ] R2: hash 有记录 + 目录缺失 → 判定为未配置,`init --opencode` 正常走配置流程重写文件;`platforms` 不再虚报。 | ||
| - [ ] R3: 现有语义不变:原生(非 Trellis 写入)的平台目录仍不算已配置(#501 的修复保持);hash 无记录仍不算已配置;legacy Windsurf→devin 分支逻辑不变。 | ||
| - [ ] R4: 回归测试覆盖:hash 有记录但目录被删除 → 未配置;正常配置 → 仍检测到。 | ||
|
|
||
| ## Acceptance Criteria | ||
|
|
||
| - [ ] A1: 复现场景验证通过:在 tmp 目录为某平台生成 hash 后删除其配置目录,`getConfiguredPlatforms` 不再包含该平台。 | ||
| - [ ] A2: `pnpm test test/configurators/platforms.test.ts` 全绿;`pnpm lint`、`pnpm typecheck` 通过。 | ||
| - [ ] A3: 手动验证:`trellis init --opencode` 在目录缺失+hash 残留的项目里会真实写文件(而非 skipping)。 | ||
| - [ ] A4: 独立分支 + PR 至远程。 | ||
|
|
||
| ## Non-Goals | ||
|
|
||
| - 不做缺失文件的"修复/补写"模式(`update` 的 drift 修复另议);本次只修"是否已配置"的判定。 | ||
| - 不清理残留的 stale hash 条目;重写配置时的 hash 合并逻辑保持现状。 | ||
| - 不改 `uninstall`/`ablate` 的删除逻辑(它们消费同一函数,语义自动跟随)。 | ||
|
|
||
| ## Notes | ||
|
|
||
| - Keep `prd.md` focused on requirements, constraints, and acceptance criteria. | ||
| - 设计见 `design.md`。 |
26 changes: 26 additions & 0 deletions
26
.trellis/tasks/archive/2026-09/09-03-fix-configured-platforms-disk-check/task.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "id": "fix-configured-platforms-disk-check", | ||
| "name": "fix-configured-platforms-disk-check", | ||
| "title": "修复 getConfiguredPlatforms 误判:hash 有记录但磁盘文件缺失时 init --opencode 误报 skipping", | ||
| "description": "getConfiguredPlatforms 增加磁盘存在校验,hash 有记录但平台目录缺失时不再误判为已配置,init/platforms/update 行为一致", | ||
| "status": "completed", | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| "dev_type": null, | ||
| "scope": null, | ||
| "package": "cli", | ||
| "priority": "P2", | ||
| "creator": "alan", | ||
| "assignee": "alan", | ||
| "createdAt": "2026-09-03", | ||
| "completedAt": "2026-09-03", | ||
| "branch": "feat/antigravity-hooks", | ||
| "base_branch": "main", | ||
| "worktree_path": null, | ||
| "commit": null, | ||
| "pr_url": null, | ||
| "subtasks": [], | ||
| "children": [], | ||
| "parent": null, | ||
| "relatedFiles": [], | ||
| "notes": "", | ||
| "meta": {} | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Workspace Index - alan | ||
|
|
||
| > Journal tracking for AI development sessions. | ||
|
|
||
| --- | ||
|
|
||
| ## Current Status | ||
|
|
||
| <!-- @@@auto:current-status --> | ||
| - **Active File**: `journal-1.md` | ||
| - **Total Sessions**: 2 | ||
| - **Last Active**: 2026-09-03 | ||
| <!-- @@@/auto:current-status --> | ||
|
|
||
| --- | ||
|
|
||
| ## Active Documents | ||
|
|
||
| <!-- @@@auto:active-documents --> | ||
| | File | Lines | Status | | ||
| |------|-------|--------| | ||
| | `journal-1.md` | ~70 | Active | | ||
| <!-- @@@/auto:active-documents --> | ||
|
|
||
| --- | ||
|
|
||
| ## Session History | ||
|
|
||
| <!-- @@@auto:session-history --> | ||
| | # | Date | Title | Commits | Branch | | ||
| |---|------|-------|---------|--------| | ||
| | 2 | 2026-09-03 | 修复 getConfiguredPlatforms 误判导致 init --opencode 空跳过 | `7cba6373` | `fix/configured-platforms-disk-check` | | ||
| | 1 | 2026-09-03 | feat(antigravity): 支持 hooks.json 生命周期钩子与会话状态注入 | `cf6663d3`, `d64de828` | `feat/antigravity-hooks` | | ||
| <!-- @@@/auto:session-history --> | ||
|
|
||
| --- | ||
|
|
||
| ## Notes | ||
|
|
||
| - Sessions are appended to journal files | ||
| - New journal file created when current exceeds 2000 lines | ||
| - Use `add_session.py` to record sessions |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Journal - alan (Part 1) | ||
|
|
||
| > AI development session journal | ||
| > Started: 2026-09-03 | ||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ## Session 1: feat(antigravity): 支持 hooks.json 生命周期钩子与会话状态注入 | ||
| <!-- trellis-session: v=2 fp=c6e3211153bb0cbe --> | ||
|
|
||
| **Date**: 2026-09-03 | ||
| **Task**: feat(antigravity): 支持 hooks.json 生命周期钩子与会话状态注入 | ||
| **Package**: cli | ||
| **Branch**: `feat/antigravity-hooks` | ||
|
|
||
| ### Summary | ||
|
|
||
| 为 Antigravity 平台添加 lifecycle hooks 支持,包含工作流状态注入和 shell 会话桥接 | ||
|
|
||
| ### Main Changes | ||
|
|
||
| - 在 packages/cli 中添加 Antigravity hooks.json 模板与配置器 | ||
| - 适配 inject-workflow-state.py 与 inject-shell-session-context.py 支持 Antigravity 契约 | ||
| - 修正 hooks.json 相对路径以适配 Antigravity 工作目录机制 | ||
|
|
||
| ### Git Commits | ||
|
|
||
| | Hash | Message | | ||
| |------|---------| | ||
| | `cf6663d3` | feat(antigravity): 支持 hooks.json 生命周期钩子与会话状态注入 (#599) | | ||
| | `d64de828` | fix(antigravity): 修正 hook 执行相对路径与宿主目录解析 (#599) | | ||
|
|
||
| ### Testing | ||
|
|
||
| - [OK] Core 测试全过 (372/372) | ||
| - [OK] CLI 全量测试通过 (1900/1900) | ||
| - [OK] 新增 Antigravity 集成测试通过 | ||
|
|
||
| ### Status | ||
|
|
||
| [OK] **Completed** | ||
|
|
||
| ### Next Steps | ||
|
|
||
| - 等待上游 PR #600 审核合并 | ||
|
|
||
|
|
||
| ## Session 2: 修复 getConfiguredPlatforms 误判导致 init --opencode 空跳过 | ||
| <!-- trellis-session: v=2 fp=b818a0ab242583af --> | ||
|
|
||
| **Date**: 2026-09-03 | ||
| **Task**: 修复 getConfiguredPlatforms 误判导致 init --opencode 空跳过 | ||
| **Package**: cli | ||
| **Branch**: `fix/configured-platforms-disk-check` | ||
|
|
||
| ### Summary | ||
|
|
||
| getConfiguredPlatforms 叠加 configDir 磁盘存在校验,hash 残留但目录缺失时不再误判已配置;回归测试+lint+typecheck+端到端验证通过,PR #601 | ||
|
|
||
| ### Git Commits | ||
|
|
||
| | Hash | Message | | ||
| |------|---------| | ||
| | `7cba6373` | fix(cli): getConfiguredPlatforms 增加磁盘存在校验 | | ||
|
|
||
| ### Status | ||
|
|
||
| [OK] **Completed** |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.