feat: extract files from message logs

This commit is contained in:
zhaoyilun
2026-07-10 00:45:08 +08:00
parent 3d68a18097
commit fe242145bb
5 changed files with 249 additions and 7 deletions

View File

@@ -1277,7 +1277,7 @@ Evidence precheck result:
- Query supports `ConversationID`, `MessageID`, `FileID`, `NameContains`, and `Limit`; default/zero limit returns all candidates.
- This loop does not register the MCP tool yet. Registration/list-mode smoke becomes C14 after source behavior passes tests.
- [ ] **Step 1: Write failing file extraction test**
- [x] **Step 1: Write failing file extraction test**
Create `internal/isphere/files_test.go` and run:
@@ -1287,11 +1287,11 @@ go test ./internal/isphere -run TestListFilesFromMessagesExtractsFileTransferCan
Expected initial failure: file query/types/functions do not exist.
- [ ] **Step 2: Implement file metadata extraction/search**
- [x] **Step 2: Implement file metadata extraction/search**
Create `internal/isphere/files.go` with minimal pure Go logic over normalized messages and synthetic/redacted fixtures.
- [ ] **Step 3: Run full verification and rewrite Loop C14**
- [x] **Step 3: Run full verification and rewrite Loop C14**
Run:
@@ -1306,6 +1306,74 @@ Expected: all exit 0. Remove any generated root `isphere-mcp.exe` after build. R
---
## Loop C13 Result
Implemented and verified in this loop:
- `internal/isphere.ListFilesFromMessages(messages, query)` extracts read-only file metadata candidates from normalized messages when `Subject` contains `FILE_TRANSFER` or message text contains a supported file extension.
- File metadata currently includes stable local `FileID` (`message_id:file_name`), `MessageID`, `ConversationID`, `FileName`, inferred `MimeType`, `CreatedAt`, `Source` `local_readonly`, and `RawRef` `packetlog_file_transfer`.
- `SizeBytes`, `DownloadRef`, `SavedPath`, and `SHA256` remain empty/unknown because C12 did not prove a message-to-cache/download mapping.
- Query matching supports conversation, message, file id, file-name substring, and limit. Tests use only synthetic/redacted filenames.
- Verification completed for C13 with the loop-specific RED/GREEN test; full verification is run again before commit.
---
## Loop C14: Register `isphere_receive_files` MCP list mode
**Goal:** Register the `isphere_receive_files` MCP tool in list mode on top of C13 file metadata extraction, while making download mode explicitly deferred until cache/download mapping is validated.
**Planned files:**
- Create: `internal/tools/isphere_files.go`
- Create: `internal/tools/isphere_files_test.go`
- Modify: `internal/mcpserver/server.go`
- Modify: `internal/mcpserver/server_test.go`
- Modify: `scripts/verify-go-mcp.ps1`
- Modify: `docs/go-mcp-runbook.md`
- Modify: `docs/current-status-card.md`
- Modify: `docs/source-discovery/capability-source-matrix.md`
- Modify: `docs/superpowers/plans/2026-07-09-stage-c-log-backed-receive-messages-loop.md`
**Planned interface:**
- Tool name: `isphere_receive_files`.
- Input: `conversation_id`, `message_id`, `file_id`, `name_contains`, `mode`, `limit`.
- C14 supports `mode` empty or `list`; download mode is not implemented in this loop.
- Source: same env-configured receive-message source used by receive/contact/group tools.
- Output shape: `ok`, `mode`, `files`, `next_cursor`, and `audit`, aligned with `docs/mcp-core-tools-contract.md`.
- Default empty source returns `ok: true`, `mode: "list"`, `files: []`.
- [ ] **Step 1: Write failing MCP tool test**
Create `internal/tools/isphere_files_test.go` and run:
```powershell
go test ./internal/tools -run TestISphereReceiveFilesToolReturnsLogBackedFiles -v
```
Expected initial failure: file receive tool registration does not exist.
- [ ] **Step 2: Implement file tool registration**
Register `isphere_receive_files` with source injection for tests. Use `ListFilesFromMessages` and return a contract-shaped map with minimal audit metadata.
- [ ] **Step 3: Wire server and verification**
Register file receive in server construction. Update server tool-count tests and `scripts/verify-go-mcp.ps1` to expect eight tools and call `isphere_receive_files` against default empty source and synthetic configured file-transfer fixture.
- [ ] **Step 4: Run full verification and commit**
Run:
```powershell
git diff --check
go test ./...
go build ./cmd/isphere-mcp
powershell -NoProfile -ExecutionPolicy Bypass -File scripts/verify-go-mcp.ps1
```
Expected: all exit 0. Remove any generated root `isphere-mcp.exe` after build. Commit exact C14 paths only and rewrite the next loop from actual results.
---
## Self-Review
- Spec coverage: the plan follows the user's cyclic requirement: plan first, implement one loop at a time, update the next loop after each result, and ask only on blockers.