feat(remote): resolve backend URL from page origin instead of hardcod of hardcoded localhost#44
Conversation
Gracker
left a comment
There was a problem hiding this comment.
Requesting changes. The SmartPerfetto wrapper does not yet make the remote/public-host setup work reliably without configuration. Please update the CORS strategy before landing.
| for (const iface of Object.values(os.networkInterfaces())) { | ||
| for (const info of (iface ?? [])) { | ||
| if (info.family === 'IPv4' && !info.internal) { | ||
| origins.push(`http://${info.address}:10000`); |
There was a problem hiding this comment.
This only whitelists origins built from local non-loopback IPv4 addresses. It does not cover access through a hostname, public DNS name, or NAT/public IP, while the Perfetto-side change derives the backend URL from window.location.hostname. In those cases the browser origin can be http://my-host:10000 but serverConfig.corsOrigins will only include values like http://192.168.x.x:10000, so browser requests to http://my-host:3000 can still fail CORS. Please support the same hostname/public-host deployment path here, or document and require explicit CORS_ORIGINS instead of claiming it works without reconfiguration.
Replace the monolithic "any code change → trace regression" rule with an explicit four-tier policy that distinguishes work that genuinely exercises agent behavior from contract / type-only and CRUD-only changes that don't: - Contract / type-only (`backend/src/types/sparkContracts.ts` etc.) → `npx tsc --noEmit` + the sparkContracts.test.ts case for that contract. - CRUD-only service (file IO, no agent path touched) → that service's own `__tests__/<name>.test.ts`. - Touches mcp / memory / report / agent runtime → `npm run test:scene-trace-regression` (the existing 6-trace gate). - PR landing → `npm run verify:pr` (strict full gate, unchanged). The new policy is inlined consistently in all 7 rule documents — keeping fresh clones self-contained — and the wording is identical across files so future drift is easy to spot. Files touched: CLAUDE.md, AGENTS.md, docs/development/testing.md, README.md, README.zh-CN.md, CONTRIBUTING.md, docs/getting-started/quick-start.md. Motivation: subsequent Spark contract scaffold commits (Gracker#41 / Gracker#44 / Gracker#50 / Gracker#54 / Gracker#55) only add types to sparkContracts.ts and add unit tests. Running the full 6-trace regression on each adds minutes per commit without exercising any code path the contract touches. The tiered policy keeps the strict gate where it earns its keep (anything wired into the agent runtime, plus PR landing) while letting type-only work finish in seconds. The trace regression command itself is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Land Plan 44 (Spark Gracker#94, Gracker#95) — project / world memory plus the feedback → case → skill draft pipeline. Critical invariant: this contract does NOT modify the existing session-scope `analysisPatternMemory.ts`. Plan 44 introduces an independent project + world store at runtime (`backend/src/agentv3/projectMemory.ts`, landed in D-phase). The existing 200-entry session store, weighted Jaccard matching, and supersede integration stay untouched. Types added to `backend/src/types/sparkContracts.ts`: - `ProjectMemoryStatus` — 5-state status machine inlined to keep `backend/src/types/` independent of `backend/src/agentv3/`. Mirrors agentv3's PatternStatus including `disputed_late`. Doc note flags that the two unions must stay in sync; if agentv3 changes, mirror the change here. - `ProjectMemoryEntry` — one entry. Carries optional `promotionPolicy`; the Plan 44 service layer (`projectMemory.saveProjectMemoryEntry`) enforces that a `'world'`-scope entry MUST have a policy. Schema itself keeps it optional so older snapshots remain readable. - `FeedbackPipelineEntry` — feedback pipeline state. Uses the shared `CaseRef` from C0 base types so this contract does NOT depend on Plan 54's CaseNode shape, breaking the Gracker#44 ↔ Gracker#54 schema cycle that Codex flagged in round 1. - `MemoryRagSelfImprovementContract` — service surface bundling entries + pipeline + recent RAG retrievals. Storage location for project + world entries: `backend/logs/analysis_project_memory.json` with shape `{entries: ProjectMemoryEntry[], promotionAudit: ...}`. Audit log schema is finalized in §4.3 of the design doc. Five new test cases in `__tests__/sparkContracts.test.ts` cover: - ProjectMemoryStatus matches the 5-state machine, no `auto_inferred` - project entry can omit promotionPolicy - world entry carries promotionPolicy with reviewer for audit - FeedbackPipelineEntry uses CaseRef shape, not CaseNode - contract bundles entries + pipeline + recent retrievals Test count: 55 (was 50). Test tier: contract / type-only. `npx tsc --noEmit` clean, sparkContracts.test.ts passes 55/55. Trace regression intentionally not run per the tiered policy in commit d8529e1. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
c828e29 to
67479f6
Compare
- Backend: replace static whitelist with port 10000 check in CORS middleware - Perfetto: update submodule to feat/remote-backend-url (URL derivation) - Fixes remote/public-host deployment where hostname != local IP Change-Id: I9fba5e72236046df30ee2fe44b8c2179194da0cc
67479f6 to
2889dbd
Compare
|
@Gracker 已按反馈重新实现: 把 这样 localhost / LAN IP / hostname / 公网 DNS 都能覆盖, |
Gracker
left a comment
There was a problem hiding this comment.
Verified the updated CORS strategy and the submodule pointer. SmartPerfetto root verify:pr passed on the PR head with the updated perfetto submodule.
4-layer fix that derives the backend address dynamically from window.location.hostname so the same build works on localhost, LAN IP, or a public server without reconfiguration:
Change-Id: I1dc49a37a0966e1da2d444419a61471cc74c8a76
Summary
Change Type
Affected Areas
Done Conditions
Test Plan
Risk / Rollback
Low risk. Changes are additive (new helper function, IIFE, settings override) with no existing behavior modified. Rollback: revert the commit.
Notes for Reviewers
Perfetto submodule points to commit f8ff26c8a (branch feat/remote-backend-url). This commit needs to exist on Gracker/perfetto before the submodule pointer resolves. CSP layer (http://${location.hostname}:3000 in connect-src) was
already merged upstream — see ui/src/frontend/index.ts line 177.