From 1a1cb3d2cb093362a7d89590defaea5b77c70f98 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 02:58:42 +0000 Subject: [PATCH] feat(plugins): built-in map-views plugin renders a space to one HTML file The sctx-map-views package is imported when a space is rendered, so no other command pays for its size. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_019XphpeFwEYm8K11SoT9ewz --- README.md | 1 + bun.lock | 3 +++ package.json | 1 + src/plugins/builtin-names.ts | 1 + src/plugins/index.ts | 3 ++- src/plugins/map-views/index.ts | 15 +++++++++++++++ tests/plugins/loader.test.ts | 3 ++- tests/plugins/map-views.test.ts | 30 ++++++++++++++++++++++++++++++ 8 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/plugins/map-views/index.ts create mode 100644 tests/plugins/map-views.test.ts diff --git a/README.md b/README.md index ba319e49..0bf08d23 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ Renders a space in a plugin-provided format. Use `sctx render list [space]` to l - `markdown.bullets` — Indented bullet list tree (outputs to stdout or `--out `). - `markdown.directory` — Markdown space directory with one file per node. Writes to `--out ` (refuses to overwrite existing files unless `--force` is passed). Flat directory by default, or organized into per-type subfolders with `--data folders=type` or when configured with `typeInference.folderMap`. Without `--out`, prints a summary of files to be written. +- `map-views.html` — One self-contained interactive HTML file of the space and its map views, with `--out `. Options: [sctx-map-views](https://github.com/mindsocket/structured-context-map-views/tree/main/packages/sctx-map-views#readme). ### Show space tree diff --git a/bun.lock b/bun.lock index 343007fd..b20f945a 100644 --- a/bun.lock +++ b/bun.lock @@ -17,6 +17,7 @@ "mdast-util-to-string": "^4.0.0", "remark-gfm": "^4.0.1", "remark-parse": "^11.0.0", + "sctx-map-views": "^0.6.2", "unified": "^11.0.5", "unist-util-visit": "^5.1.0", }, @@ -511,6 +512,8 @@ "scheduler": ["scheduler@0.28.0", "", {}, "sha512-juorfCmIkIw8tT+p5BXSm6PJjQF/ycEYmKyzURCIt/RaZIhL+PulbQ9Yu2z1HdOJDdqDTlxA1+xKBmHXJsczAw=="], + "sctx-map-views": ["sctx-map-views@0.6.2", "", {}, "sha512-E7ZeoEjbvIXaabD6oc5ukZ767OUB/qfK+PV4DS6vm93+G6pg0v9RC7QLBdzS0sW82zZ86T+GJDLM3pdm9eUO2w=="], + "section-matter": ["section-matter@1.0.0", "", { "dependencies": { "extend-shallow": "^2.0.1", "kind-of": "^6.0.0" } }, "sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA=="], "send": ["send@1.2.1", "", { "dependencies": { "debug": "^4.4.3", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", "fresh": "^2.0.0", "http-errors": "^2.0.1", "mime-types": "^3.0.2", "ms": "^2.1.3", "on-finished": "^2.4.1", "range-parser": "^1.2.1", "statuses": "^2.0.2" } }, "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ=="], diff --git a/package.json b/package.json index 3a297146..535eced9 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "mdast-util-to-string": "^4.0.0", "remark-gfm": "^4.0.1", "remark-parse": "^11.0.0", + "sctx-map-views": "^0.6.2", "unified": "^11.0.5", "unist-util-visit": "^5.1.0" } diff --git a/src/plugins/builtin-names.ts b/src/plugins/builtin-names.ts index 62b9c671..bb4e37ee 100644 --- a/src/plugins/builtin-names.ts +++ b/src/plugins/builtin-names.ts @@ -5,6 +5,7 @@ import { normalizePluginName } from './util'; export const BUILTIN_PLUGIN_NAMES = { markdown: `${PLUGIN_PREFIX}markdown`, mermaid: `${PLUGIN_PREFIX}mermaid`, + mapViews: `${PLUGIN_PREFIX}map-views`, miro: `${PLUGIN_PREFIX}miro`, } as const; diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 283d7aa9..1f327e32 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -1,7 +1,8 @@ +import { mapViewsPlugin } from './map-views'; import { markdownPlugin } from './markdown'; import { mermaidPlugin } from './mermaid'; import { miroPlugin } from './miro'; import type { StructuredContextPlugin } from './util'; /** All built-in plugins, in default load order. */ -export const builtinPlugins: StructuredContextPlugin[] = [markdownPlugin, mermaidPlugin, miroPlugin]; +export const builtinPlugins: StructuredContextPlugin[] = [markdownPlugin, mermaidPlugin, miroPlugin, mapViewsPlugin]; diff --git a/src/plugins/map-views/index.ts b/src/plugins/map-views/index.ts new file mode 100644 index 00000000..198a6810 --- /dev/null +++ b/src/plugins/map-views/index.ts @@ -0,0 +1,15 @@ +import { BUILTIN_PLUGIN_NAMES } from '../builtin-names'; +import type { StructuredContextPlugin } from '../util'; + +/** Loads the `sctx-map-views` package only to render: it bundles the map view library, which would slow every command's start. */ +export const mapViewsPlugin: StructuredContextPlugin = { + name: BUILTIN_PLUGIN_NAMES.mapViews, + configSchema: { type: 'object', additionalProperties: false }, + render: { + formats: [{ name: 'html', description: 'Self-contained interactive HTML page of the space and its map views' }], + async render(context, graph, options) { + const { default: plugin } = (await import('sctx-map-views')) as { default: StructuredContextPlugin }; + return plugin.render!.render(context, graph, options); + }, + }, +}; diff --git a/tests/plugins/loader.test.ts b/tests/plugins/loader.test.ts index 3e8fb993..8f002d52 100644 --- a/tests/plugins/loader.test.ts +++ b/tests/plugins/loader.test.ts @@ -9,10 +9,11 @@ describe('loadPlugins', () => { describe('built-in plugins', () => { it('always includes built-in plugins when no map is given', async () => { const loaded = await loadPlugins({}, CONFIG_DIR); - expect(loaded).toHaveLength(3); + expect(loaded).toHaveLength(4); expect(loaded.map((l) => l.plugin.name)).toContain('sctx-markdown'); expect(loaded.map((l) => l.plugin.name)).toContain('sctx-mermaid'); expect(loaded.map((l) => l.plugin.name)).toContain('sctx-miro'); + expect(loaded.map((l) => l.plugin.name)).toContain('sctx-map-views'); expect(loaded.find((l) => l.plugin.name === 'sctx-markdown')!.pluginConfig).toEqual({}); expect(loaded.find((l) => l.plugin.name === 'sctx-mermaid')!.pluginConfig).toEqual({}); expect(loaded.find((l) => l.plugin.name === 'sctx-miro')!.pluginConfig).toEqual({}); diff --git a/tests/plugins/map-views.test.ts b/tests/plugins/map-views.test.ts new file mode 100644 index 00000000..7f267927 --- /dev/null +++ b/tests/plugins/map-views.test.ts @@ -0,0 +1,30 @@ +import { afterAll, beforeAll, describe, expect, it } from 'bun:test'; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import plugin from 'sctx-map-views'; +import { mapViewsPlugin } from '../../src/plugins/map-views'; +import { executeRender } from '../../src/render/render'; +import { makeSpaceContext } from '../helpers/context'; + +let dir: string; +beforeAll(() => { + dir = mkdtempSync(join(tmpdir(), 'sctx-map-views-')); + mkdirSync(join(dir, 'space')); + writeFileSync(join(dir, 'space', 'Vision.md'), '---\ntype: vision\n---\n# Vision\n'); +}); +afterAll(() => rmSync(dir, { recursive: true, force: true })); + +describe('built-in map-views plugin', () => { + it('offers the formats of the package it imports on render', () => { + expect(mapViewsPlugin.render!.formats).toEqual(plugin.render!.formats); + }); + + it('renders a space to one HTML page', async () => { + const page = (await executeRender('map-views.html', makeSpaceContext(join(dir, 'space')), {})) as string; + const snapshots = JSON.parse(/id="sctx-snapshots">(.*?)<\/script>/s.exec(page)![1]!); + expect(snapshots).toHaveLength(1); + expect(snapshots[0].graph.nodes).toHaveLength(1); + expect(snapshots[0].definitions.map((d: { id: string }) => d.id)).toContain('sctx-map-view://core/strategy-tree'); + }); +});