From 44fe4634eb99b470317fd58f164be90bbd12c837 Mon Sep 17 00:00:00 2001 From: qiansc Date: Mon, 26 Oct 2026 14:02:31 +0000 Subject: [PATCH 1/2] feat(site): per-article source map with a list view, on by default (site.sourceMap) Co-Authored-By: Claude Opus 5.5 --- bun.lock | 2 + .../manuals/guides/package-outputs.md | 13 +- .../manuals/reference/project-api.md | 3 +- packages/context-cli/package.json | 2 + .../src/__tests__/packageSite.test.ts | 26 +- .../__tests__/packageSiteSourceMap.test.ts | 88 +++++ .../context-cli/src/project/packageSite.ts | 53 ++- .../src/project/packageSiteSourceMap.ts | 326 ++++++++++++++++++ .../src/project/packageSiteSources.ts | 73 ++-- .../src/project/packageSiteTheme.ts | 244 ++++++++++++- .../context/docs/guides/package-outputs.md | 13 +- .../context/docs/reference/project-api.md | 3 +- .../context/src/__tests__/packageSite.test.ts | 3 + packages/context/src/packageSite.ts | 5 + 14 files changed, 813 insertions(+), 41 deletions(-) create mode 100644 packages/context-cli/src/__tests__/packageSiteSourceMap.test.ts create mode 100644 packages/context-cli/src/project/packageSiteSourceMap.ts diff --git a/bun.lock b/bun.lock index 6e0823f2..20cff8f3 100644 --- a/bun.lock +++ b/bun.lock @@ -45,6 +45,7 @@ "@c4a/extract-ts": "workspace:*", "@mermaid-js/layout-elk": "0.2.0", "commander": "^11.0.0", + "d3-force": "3.0.0", "fast-xml-parser": "^5.10.1", "handlebars": "^4.7.8", "ink": "^5.0.0", @@ -67,6 +68,7 @@ }, "devDependencies": { "@c4a/core": "workspace:*", + "@types/d3-force": "3.0.10", "esbuild": "0.27.3", "playwright": "1.58.2", "zod-to-json-schema": "^3.25.1", diff --git a/packages/context-cli/context-workflow/resources/manuals/guides/package-outputs.md b/packages/context-cli/context-workflow/resources/manuals/guides/package-outputs.md index baf62f9f..09cee90e 100644 --- a/packages/context-cli/context-workflow/resources/manuals/guides/package-outputs.md +++ b/packages/context-cli/context-workflow/resources/manuals/guides/package-outputs.md @@ -121,7 +121,18 @@ zoom, full-screen and source controls. Controls appear on hover or keyboard focu (and remain visible on touch devices). Layout and source/copy actions are on the left, sizing actions on the right. Source view replaces the diagram. Flowcharts default to ELK and can switch to Dagre without changing the article. Offline Review reports use the same viewer and include its resources only when a candidate contains Mermaid. -Article provenance initially shows ten sources; Show more reveals the full list. +Each article ends with its sources as a map: the article's sections in the +middle and the documents they cite around them, grouped by where each document +comes from (a repository directory, Lark documents or notes). Sections are purple; +sources are coloured by type: repository files green, Skills magenta, Lark +documents blue and notes orange. Hovering a section +or document highlights what it is linked to; clicking a document opens the cited +lines, and clicking a section scrolls to it. A List view shows the same documents +by group with their cited line ranges, and narrow screens show only the list. +Below the map, other articles citing the same documents are linked. The map is +computed while building from the recorded references, so it needs no agent +step; set `site.sourceMap: false` to show the plain source list instead, which +initially shows ten sources; Show more reveals the full list. Invalid diagrams and diagrams with embedded image/HTML resources retain their source with a rendering notice instead of blocking publication. Code samples and raw HTML are displayed as content, not executed as Vue components or scripts. diff --git a/packages/context-cli/context-workflow/resources/manuals/reference/project-api.md b/packages/context-cli/context-workflow/resources/manuals/reference/project-api.md index 4f4c22c8..8ba85d6e 100644 --- a/packages/context-cli/context-workflow/resources/manuals/reference/project-api.md +++ b/packages/context-cli/context-workflow/resources/manuals/reference/project-api.md @@ -191,7 +191,8 @@ the same build, beside the KB directory. `` removes one trailing `-kb` from the package name, if present. Omit it for KB-only output. It accepts `title`, `description`, `lang`, a deployment `base` path, an optional top-bar `titleLink`, and an optional `home` presentation. Navigation and language fields are `nav`, `more`, -`socialLinks`, `locales` and `localePreferenceKey`; see +`socialLinks`, `locales` and `localePreferenceKey`; `sourceMap: false` replaces +the per-article source map with a plain source list; see [Package Outputs](../guides/package-outputs.md) and [Site translation](../guides/site-translation.md). `home` accepts `title`, `slogan`, `description`, hero `actions`, and `resources` shown diff --git a/packages/context-cli/package.json b/packages/context-cli/package.json index db637563..05e301a5 100644 --- a/packages/context-cli/package.json +++ b/packages/context-cli/package.json @@ -67,6 +67,7 @@ "@c4a/extract-ts": "workspace:*", "@mermaid-js/layout-elk": "0.2.0", "commander": "^11.0.0", + "d3-force": "3.0.0", "fast-xml-parser": "^5.10.1", "handlebars": "^4.7.8", "ink": "^5.0.0", @@ -89,6 +90,7 @@ }, "devDependencies": { "@c4a/core": "workspace:*", + "@types/d3-force": "3.0.10", "esbuild": "0.27.3", "playwright": "1.58.2", "zod-to-json-schema": "^3.25.1" diff --git a/packages/context-cli/src/__tests__/packageSite.test.ts b/packages/context-cli/src/__tests__/packageSite.test.ts index c1de4460..2e99f28e 100644 --- a/packages/context-cli/src/__tests__/packageSite.test.ts +++ b/packages/context-cli/src/__tests__/packageSite.test.ts @@ -167,7 +167,12 @@ test("VitePress builds an independent site with search, safe prose, anchors and expect(article).not.toContain("