Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/app-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@ The App map shows how a team's app fits together across all its repositories. It
- `build`: writes the answers and builds, until the build passes and every file and endpoint is described (the workflow's own limits: 4 and 3 attempts).
- After a push to a default branch (a code graph update), a team that has a map gets an update queued two minutes later. Floorplan's refresh keeps every description whose file didn't change, so only new or changed files and endpoints are described again.
- The map (`floorplan/graph@1`) is kept in the bucket at `app-map/{team}/graph.json.gz`, Floorplan's own files at `state.tgz`, and the step's job at `job.json`; the build status is in the settings table (`AM#{team}`, `STATUS`).
- With each map the worker also writes the page's copy (`view.json.gz`: read-only, Floorplan's checks labelled, stored as JSON with `Content-Encoding: gzip`) and a small index (`index.json.gz`, `common::app_map::MapIndex`: the repositories' folders, every file path on the map, each repository's main part and Floorplan's checks with their places). A map written before these existed gets them from the gateway on its first read.

## How the page reads it

- `GET /api/app-map` never reads or sends the whole map. It answers with the build status, a signed GET for the page's copy (`graph_url`, 15 minutes; the browser reads it from the bucket and unzips it), the same bytes through the API for a browser that can't reach the bucket (`graph_fallback`, `GET /api/app-map/graph`, passed on unread), when the map was written (`graph_at`), and CoderHelm's overlays (`overlays`) placed with the index: Recent work (`recent`), and Health (`health.add`, the Floorplan checks to `drop` by id, and the `summary`). The page lays them over its copy (`dashboard/src/lib/app-map-load.ts`, the same as `common::app_map::apply_overlays`) and reads the map again only when `graph_at` changes.
- Recent work reads the plans' "why" eight at a time, for runs that are on the map only; Health reads its four sources at once.
- The data bucket's CORS allows `GET` and `HEAD` from the dashboard's origins (`infra/lib/storage-stack.ts`), next to the uploads' `PUT`.
- `cargo test -p common a_page_view` measures a page view on a made-up 4,000-file map (`APP_MAP_BENCH_GRAPH=<graph.json.gz>` measures a map on disk); `cargo test -p gateway a_page_view_of_a_large_map` does it through the handler.
- Chat and `/mcp` still read the whole map at their first lookup (`load_graph`): one read per question, and their lookups need the files, links and descriptions the index doesn't keep.

## What CoderHelm adds (`common/src/app_map.rs`)

- Recent work and Health, put into the map's own `recent` and `health.issues` fields when the gateway serves it, so Floorplan's viewer shows them natively. CoderHelm's findings are marked `source: "coderhelm"` and link to their pages; Floorplan's own checks are marked `Floorplan check`, and one at the same file and line as a CoderHelm finding is dropped.
- Recent work and Health in the map's own `recent` and `health.issues` fields, laid over the page's copy on the page, so Floorplan's viewer shows them natively. CoderHelm's findings are marked `source: "coderhelm"` and link to their pages; Floorplan's own checks are marked `Floorplan check`, and one at the same file and line as a CoderHelm finding is dropped.
- The page's copy: read-only (Floorplan's exported mode), with the sandbox's folder left out.
- Lookups for the read API (`/api/app-map/part`, `file`, `screen`, `search`).
- The map lookups Chat and `/mcp` share (`common::app_map::Lookups`: `map_overview`, `map_find`, `map_part`, `map_screen`, `map_file`). Chat offers them when the team has a built map and reads the map at the first lookup; a question about how the app fits together gets them first (`chat_understand`). Each lookup is a citable source linking to the App map page focused on its parts, and an answer that used them carries a mini map of those parts (`map` on the answer and its saved message). The App map page's Ask box asks Chat (origin `app_map`), so its questions are kept in the person's chats. On `/mcp` the same lookups are read-only tools under `code:read`.
Expand Down
10 changes: 6 additions & 4 deletions infra/lib/storage-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ export class StorageStack extends cdk.Stack {
autoDeleteObjects: !props.cfg.retainData,
// Knowledge base files and brain chat attachments are uploaded from
// the browser with short-lived signed PUT URLs (bound to the object's
// key, size and type by the gateway); nothing else is allowed. The
// dashboard's origins when known at synth; otherwise any origin, since
// the signed URL itself is the credential.
// key, size and type by the gateway), and the App map page reads the
// team's map with a short-lived signed GET URL (the gateway never
// passes the map itself); nothing else is allowed. The dashboard's
// origins when known at synth; otherwise any origin, since the signed
// URL itself is the credential.
cors: [
{
allowedMethods: [s3.HttpMethods.PUT],
allowedMethods: [s3.HttpMethods.PUT, s3.HttpMethods.GET, s3.HttpMethods.HEAD],
allowedOrigins:
props.cfg.split?.corsOrigins ??
(props.cfg.appUrl ? [props.cfg.appUrl] : ["*"]),
Expand Down
13 changes: 13 additions & 0 deletions infra/test/hybrid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ test("relay bodies held for retries are gone after two days", () => {
assert.equal(rule.ExpirationInDays, 2);
});

test("the dashboard may read signed GETs from the data bucket (the App map), and still only its own origins", () => {
const cors = (t: any) => {
const bucket = Object.values(t.findResources("AWS::S3::Bucket")).find((b: any) => JSON.stringify(b.Properties.BucketName).includes("-data")) as any;
return bucket.Properties.CorsConfiguration.CorsRules;
};
const hostedRules = cors(hosted()["coderhelm-prod-storage"]);
assert.equal(hostedRules.length, 1);
assert.deepEqual([...hostedRules[0].AllowedMethods].sort(), ["GET", "HEAD", "PUT"]);
assert.ok(!hostedRules[0].AllowedOrigins.includes("*"), "the hosted dashboard's own origins");
const self = synth(resolveConfig({ account: "111122223333", region: "us-west-2", stage: "prod", email: { from: "coderhelm@example.org" }, admins: ["owner@example.org"] }));
assert.deepEqual([...cors(self["coderhelm-prod-storage"])[0].AllowedMethods].sort(), ["GET", "HEAD", "PUT"]);
});

test("a self-hosted install: relay intake, its own 404, no hosted-side parts", () => {
const cfg = resolveConfig({ account: "111122223333", region: "us-west-2", stage: "prod", email: { from: "coderhelm@example.org" }, admins: ["owner@example.org"] });
const t = synth(cfg);
Expand Down
2 changes: 1 addition & 1 deletion selfhost/versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"about": "The dashboard commit each platform release ships: a full 40-character commit SHA of CoderHelm/coderhelm, never a branch or tag (scripts/check-dashboard-ref.mjs fails CI and the release otherwise). The release workflow builds exactly this commit (dashboard/) into dashboard.tar.gz. Move it with scripts/bump-dashboard.sh in a reviewed PR, in the same PR as any API change the dashboard needs.",
"dashboardRef": "3a39e0c8f6b66e3cf734a70292c6e7211afaa47d"
"dashboardRef": "e136e62e4ff4e7ab922c819a3714de2fdfab8936"
}
2 changes: 1 addition & 1 deletion services/common/contract/worker_messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"webhook_send": {"type":"webhook_send","team_id":"TEAM#team-a","endpoint_id":"ep_01jbendpt4a7b0c3d6e9f2g5h8","event_id":"evt_01JBEVNT8M1N4P7Q0R3S6T9V2W","delivery_id":"01hzzdelivery","due_at":1792416387},
"relay_retry": {"type":"relay_retry","install_id":"ins_abcdefghijklmnopqrstuvwx","delivery_id":"01hzzdelivery","relay_delivery_id":"72d3162e-cc78-11e3-81ab-4c9367dc0958","event":"pull_request","source":"github"},
"await_merge": {"type":"await_merge","team_id":"TEAM#team-a","installation_id":1,"repo_owner":"acme","repo_name":"widgets","pr_number":2,"head_sha":"abc","base_branch":"main","self_authored":true,"attempts":1,"chain_id":"c","error_retries":0},
"app_map": {"type":"app_map","team_id":"TEAM#team-a","repo":"","step":"build"},
"app_map": {"type":"app_map","team_id":"TEAM#team-a","repo":"","step":"build","build":"0f9c2d4e8a7b4c1d9e6f3a2b1c0d9e8f","turn":2},
"graph_index": {"type":"graph_index","team_id":"TEAM#team-a","installation_id":1,"repo_owner":"acme","repo_name":"widgets","branch":"main","changed_files":["a.rs"]},
"release_notes": {"type":"release_notes","team_id":"TEAM#team-a","installation_id":1,"repo_owner":"acme","repo_name":"widgets","tag":"v1.0.0","sha":"abc","resend":"","check_branch":true},
"restack": {"type":"restack","team_id":"TEAM#team-a","installation_id":1,"repo_owner":"acme","repo_name":"widgets","branch":"coderhelm/feature-a","before":"abc","after":"def"},
Expand Down
Loading
Loading