feat: add send file preview tool

This commit is contained in:
zhaoyilun
2026-07-10 21:22:39 +08:00
parent 6781c75f84
commit 1fd10b5df7
9 changed files with 673 additions and 26 deletions

View File

@@ -535,23 +535,23 @@ git push gitea main
- Env: `ISPHERE_SEND_FILE_ALLOWED_DIR` required for previewing real local file paths.
- Response fields: `ok`, `send_status`, `file_sha256`, `file_size_bytes`, `target_ref`, `production_send_enabled`, `side_effect_flags`.
- [ ] **Step 1: Write file-preview test**
- [x] **Step 1: Write file-preview test**
Add `TestISphereSendFilePreviewComputesHashAndSize`, creating a temp allowed directory and `hello.txt`, then asserting preview returns `ok=true`, `send_status="planned"`, `file_size_bytes=5`, and `real_send_attempted=false`.
- [ ] **Step 2: Write path rejection test**
- [x] **Step 2: Write path rejection test**
Add `TestISphereSendFileRejectsPathOutsideAllowedDir` asserting paths outside `ISPHERE_SEND_FILE_ALLOWED_DIR` return `ok=false` and `send_status="blocked"`.
- [ ] **Step 3: Implement tool and registration**
- [x] **Step 3: Implement tool and registration**
Register the tenth MCP tool. Production execution returns blocked with `production_send_enabled=false`.
- [ ] **Step 4: Update smoke scripts**
- [x] **Step 4: Update smoke scripts**
`verify-go-mcp.ps1` and `isphere-capability-smoke` must assert tool count includes `isphere_send_file`, preview works with a temp fixture file, and production remains blocked.
- [ ] **Step 5: Verify and commit**
- [x] **Step 5: Verify and commit**
```powershell
git diff --check
@@ -566,6 +566,15 @@ git push gitea main
**Acceptance gate:** 数字员工能看到“发文件”工具,但默认路径只做 preview不上传。
**R7 Result:**
- Added `internal/tools/isphere_send_file.go` and `internal/tools/isphere_send_file_test.go`.
- Registered `isphere_send_file` as the tenth MCP tool.
- Preview requires `ISPHERE_SEND_FILE_ALLOWED_DIR`, validates target/idempotency/file existence/path boundary/SHA256/size, and returns `send_status="planned"` with `real_send_attempted=false`.
- Production `execution_mode="production"` remains structured blocked with `production_send_enabled=false` and all send/upload/UI/network side-effect flags false.
- Updated `scripts/verify-go-mcp.ps1` and `cmd/isphere-capability-smoke` to assert 10 tools, send-file preview readiness, and send-file production disabled.
- Verification passed: `git diff --check`, focused send-file tests, 10-tool registration test, `go test ./...`, `go build ./cmd/isphere-mcp`, `scripts\verify-go-mcp.ps1`, and `go run ./cmd/isphere-capability-smoke`.
---
### R8: Send-file idempotency and audit hardening