squad_state_list fails for root on adapter-backed backends: StateBackendStorageAdapter.toRelative() returns "." for squadDir
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 63/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
研究方向
Start in packages/squad-sdk/src/state-backend.ts and inspect StateBackendStorageAdapter.toRelative() alongside its list and directory methods. Then read packages/squad-sdk/src/tools/index.ts for normalizeStateToolDir() and the existing key validation. Add regression coverage for root listing while preserving traversal and file-operation rejection; done means the listed root entries are returned and the specified invalid paths still fail.
由索引模型根據 Issue 內容生成。
描述
Summary
squad_state_list with dir omitted (or "", or ".squad") fails on any backend routed through StateBackendStorageAdapter (observed with stateBackend: "two-layer"):
Failed to list state: State key must not contain . or .. path segments
squad_state_list {dir: "decisions"} works.
Environment
- squad CLI v1.0.1 (WinGet
bradygaster.Squad), Windows .squad/config.json→stateBackend: "two-layer";squad_state_health→State backend storage: StateBackendStorageAdapter- Source references below are from
main@ 89d6302576ce03b87fe0519235854c9e8638737f (bug still present)
Minimal repro
- Repo with
stateBackend: "two-layer"(ororphan/git-notes). - Run
squad state-mcp, callsquad_state_list {}. - Observe the error above.
Unit-level repro:
const adapter = new StateBackendStorageAdapter(new OrphanBranchBackend(repo), squadDir);
adapter.listSync(squadDir); // throws: State key must not contain . or .. path segments
Root cause
packages/squad-sdk/src/tools/index.tsnormalizeStateToolDir()correctly maps an omitted dir to"", then callsthis.storage.listSync(path.join(this.squadRoot, "")), i.e.listSync(squadRoot).packages/squad-sdk/src/state-backend.tsStateBackendStorageAdapter.toRelative()has:if (fileCmp === squadCmp) { return '.'; }- Every backend
list()runsnormalizeKey(relativeDir).normalizeKeyexplicitly allows""as root ("Empty string after normalization means root — valid for list() operations"), but"."is non-empty, sovalidateStateKey('.')throws.
The adapter emits a root sentinel the backends do not accept.
Suggested fix (keeps traversal rejection)
Do not relax validateStateKey. Map squadDir to "" only for list-shaped reads:
list/listSync/isDirectory/isDirectorySync: when the path resolves to squadDir, pass"".- Keep
"."(and therefore rejection) for file operations and especiallydeleteDir/deleteDirSync. Returning""there would turndeleteDir(squadDir)into a wipe of all state, andread("")on git backends could resolve to a tree object.
For example, add private toRelativeDir(p) { const r = this.toRelative(p); return r === '.' ? '' : r; } and use it in the four list methods.
Regression tests
adapter.listSync(squadDir)returns root entries for the orphan, git-notes, and two-layer backends.squad_state_list {}and{dir: ""}succeed.{dir: ".."},{dir: "a/../b"}, and{dir: "."}still fail with the. or ..error.adapter.deleteDirSync(squadDir)andadapter.readSync(squadDir)still throw.
Downstream report: OlyForge3D/PrintFarmer#3372
- 主要語言
- TypeScript
- 星號
- 3.4k
- 分支
- 516
- 平均合併
- 1 天 15 小時
- 30 天內合併 PR
- 116
環境準備
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/squad 的其他 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 77/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
相似的 Issue
-
bot:ai-assisted component:platform-js status:untriaged
難度 1/5 1 小時以內 新手友好度 74/100
midnightntwrk/platform-js#38 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
ranxianglei/billion-context#7068 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
mybigday/whisper.rn#348 ·
-
enhancement severity:low
難度 2/5 1-3 小時 新手友好度 82/100
Battle-Cattle/BCUK-Bot-4#1075 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 67/100
ilan-pinto/roaring-lions#1552 ·
維護者通常 1 天內回覆