feat: load packet logs from configured source

This commit is contained in:
zhaoyilun
2026-07-09 23:23:06 +08:00
parent 220f3f68c1
commit 28bcb94b41
10 changed files with 337 additions and 28 deletions

View File

@@ -795,7 +795,7 @@ Implemented and verified in this loop:
- Configured behavior: env var set to a local text file means the server reads non-empty encrypted Base64 lines from that file into `isphere.EncryptedPacketLogSource{Lines: lines}`.
- Evidence rule: the configured file should live under ignored `runs/` or another operator-local path; the loader must not require or commit raw evidence.
- [ ] **Step 1: Write failing file loader test**
- [x] **Step 1: Write failing file loader test**
Create `internal/isphere/file_source_test.go` first and run:
@@ -805,23 +805,23 @@ go test ./internal/isphere -run TestLoadEncryptedPacketLogSourceFromFileReadsNon
Expected initial failure: loader function/type does not exist.
- [ ] **Step 2: Implement file loader**
- [x] **Step 2: Implement file loader**
Implement a small loader that reads a UTF-8 text file, trims whitespace, skips blank lines, and returns `EncryptedPacketLogSource{Lines: lines}`. It should return clear path/context errors for missing or unreadable files.
- [ ] **Step 3: Write failing env-wired server test**
- [x] **Step 3: Write failing env-wired server test**
Update `internal/mcpserver/server_test.go` with a temp encrypted fixture file and a test that sets `ISPHERE_PACKET_LOG_FILE`, constructs the env-wired server, calls `isphere_receive_messages`, and expects one redacted message. Run the specific test before implementation.
- [ ] **Step 4: Implement env-wired server construction**
- [x] **Step 4: Implement env-wired server construction**
Add `NewServerFromEnv()` or equivalent env-aware construction. Keep `NewServer()` as the empty default for existing tests. Update `cmd/isphere-mcp/main.go` to use the env-aware server.
- [ ] **Step 5: Update operator verification/docs**
- [x] **Step 5: Update operator verification/docs**
Extend `scripts/verify-go-mcp.ps1` so default verification still asserts zero messages when no env var is set. Document optional `ISPHERE_PACKET_LOG_FILE` usage in `docs/go-mcp-runbook.md` and update the status card.
- [ ] **Step 6: Run full verification and commit**
- [x] **Step 6: Run full verification and commit**
Run:
@@ -836,6 +836,67 @@ Expected: all exit 0. Remove any generated root `isphere-mcp.exe` after build. C
---
## Loop C5 Result
Implemented and verified in this loop:
- `internal/isphere.LoadEncryptedPacketLogSourceFromFile(path)` reads non-empty encrypted Base64 PacketReader log lines from an operator-local text file and returns `EncryptedPacketLogSource{Lines: lines}`.
- `internal/mcpserver.NewServerFromEnv()` reads `ISPHERE_PACKET_LOG_FILE` when set, otherwise preserves the empty default receive source.
- `cmd/isphere-mcp/main.go` now uses the env-aware server constructor and fails fast on invalid configuration.
- `scripts/verify-go-mcp.ps1` now exercises `NewServerFromEnv()` with `ISPHERE_PACKET_LOG_FILE` cleared and confirms the deterministic empty-source behavior.
- Docs now explain optional `ISPHERE_PACKET_LOG_FILE` usage and reinforce that raw evidence must remain under ignored/operator-local paths.
- Verification completed for C5 with `git diff --check`, `go test ./...`, `go build ./cmd/isphere-mcp`, and `powershell -NoProfile -ExecutionPolicy Bypass -File scripts/verify-go-mcp.ps1`; the generated root `isphere-mcp.exe` build artifact was removed.
---
## Loop C6: Fixture-backed operator smoke for configured receive source
**Goal:** Extend repeatable operator verification so a synthetic encrypted PacketReader fixture file proves `ISPHERE_PACKET_LOG_FILE` can drive `isphere_receive_messages` end-to-end without committing raw evidence.
**Planned files:**
- Modify: `scripts/verify-go-mcp.ps1`
- Modify: `docs/go-mcp-runbook.md`
- Modify: `docs/current-status-card.md`
- Modify: `docs/superpowers/plans/2026-07-09-stage-c-log-backed-receive-messages-loop.md`
**Planned behavior:**
- Existing default smoke remains: unset `ISPHERE_PACKET_LOG_FILE` returns `messages: []`.
- New fixture smoke creates a temporary synthetic/redacted PacketReader plaintext, encrypts it with the known log policy inside the temporary Go harness, writes one encrypted line to a temp file, sets `ISPHERE_PACKET_LOG_FILE` to that temp file, starts `mcpserver.NewServerFromEnv()`, calls `isphere_receive_messages`, and asserts one normalized message.
- No raw N12-pre evidence or decrypted user content is written to the repo.
- [ ] **Step 1: Capture current fixture-smoke gap**
Run the current verification script and note that it only proves the default empty source, not configured fixture ingestion:
```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File scripts/verify-go-mcp.ps1
```
Expected: PASS with `receive_message_count: 0`, but no configured-source proof yet.
- [ ] **Step 2: Update the temporary Go harness**
Extend the generated harness with a second server session that sets `ISPHERE_PACKET_LOG_FILE` to a temp synthetic encrypted log-line file and asserts one returned message with redacted content.
- [ ] **Step 3: Update docs**
Update the runbook/status card to say verification covers both default empty source and synthetic configured-source smoke.
- [ ] **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 C6 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.