How nicepkg/ctxport works
Purpose and Topology
CtxPort is a pnpm/Turborepo monorepo for a Manifest V3 browser extension that locally exports supported AI conversations and GitHub discussions as structured Markdown “Context Bundles.” A separate Next.js documentation/marketing site publishes product and usage content. Workspace boundaries are declared through pnpm-workspace.yaml and orchestrated by turbo.json.
Runtime Entry Points
The extension is the primary product runtime, built with WXT, React, and TypeScript. Its background entry point supports extension lifecycle/runtime integration; the content script mounts UI into supported pages; the popup provides extension UI.
• apps/browser-extension/src/entrypoints/background.ts
• apps/browser-extension/src/entrypoints/content.tsx
• apps/browser-extension/src/entrypoints/popup/main.tsx
• apps/browser-extension/wxt.config.ts
The website is a Next.js locale-routed documentation application, with middleware and OpenNext/Cloudflare-oriented deployment configuration.
• apps/web/src/app/[locale]/page.tsx
• apps/web/src/app/[locale]/docs/[[...mdxPath]]/page.tsx
• apps/web/middleware.ts
• apps/web/open-next.config.ts
Platform Plugin Boundary
core-plugins isolates each source platform behind a plugin contract and central registry. The extension selects a plugin based on the active page; plugins parse platform-specific DOM/API representations into shared conversation data rather than leaking source markup into export logic.
• packages/core-plugins/src/types.ts
• packages/core-plugins/src/registry.ts
• packages/core-plugins/src/plugins/index.ts
Platform implementations cover ChatGPT, Claude, Gemini, DeepSeek, Doubao, Grok, and GitHub. ChatGPT has the richest extraction pipeline, including content flatteners and tree linearization; GitHub includes GraphQL integration.
• packages/core-plugins/src/plugins/chatgpt/plugin.ts
• packages/core-plugins/src/plugins/chatgpt/tree-linearizer.ts
• packages/core-plugins/src/plugins/github/graphql.ts
Canonical Data and Serialization Pipeline
The cross-package contract is the Context Bundle schema: source metadata, URL/title/date, conversation nodes, and selected output format. Plugins produce this canonical representation; the Markdown package applies format selection and serializes it into clipboard-ready Markdown with frontmatter.
• packages/core-schema/src/content-bundle.ts
• packages/core-schema/src/errors.ts
• packages/core-markdown/src/formats.ts
• packages/core-markdown/src/serializer.ts
This creates a deliberate boundary: platform adapters handle acquisition/normalization, while core-markdown owns Full, User Only, Code Only, and Compact presentation. Token estimation is colocated with export serialization concerns.
• packages/core-markdown/src/token-estimator.ts
• packages/core-markdown/src/index.ts
Extension Interaction and Copy Flow
On a supported site, the content entrypoint injects the React application and contextual copy controls. User actions from in-chat controls, sidebar/list copy, context menu, or keyboard-oriented extension behavior invoke conversation extraction, serialize the selected bundle, and write it to the local clipboard. No backend, account, or upload pipeline is represented.
• apps/browser-extension/src/components/app.tsx
• apps/browser-extension/src/components/copy-button.tsx
• apps/browser-extension/src/components/list-copy-icon.tsx
• apps/browser-extension/src/hooks/use-copy-conversation.ts
Shared Presentation Layer
shared-ui is a reusable React component, rendering, localization, and styling package consumed by application surfaces. It is separate from extraction and serialization, keeping UI changes from affecting bundle semantics.
• packages/shared-ui/src/index.ts
• packages/shared-ui/src/components/renderer/markdown-renderer.tsx
• packages/shared-ui/src/i18n/react.tsx
Website Content and Delivery
The website renders English and Chinese MDX content through locale-aware App Router layouts and documentation routes. It is informational rather than part of the browser extension’s copy path. CI, website deployment, and extension release are automated through GitHub Actions.
• apps/web/content/en/_meta.ts
• apps/web/content/zh/_meta.ts
• .github/workflows/deploy-website.yml
• .github/workflows/release-extension.yml
Main entry points: index.ts Platform adapters · wxt.config.ts WXT build config · use-copy-conversation.ts Copy conversation flow · app.tsx Injected React app
Components 20
Browser Extension
- WXT build config
apps/browser-extension/wxt.config.ts - Background runtime · Handles extension lifecycle and runtime integration.
apps/browser-extension/src/entrypoints/background.ts - Content runtime · Injects contextual controls into supported pages.
apps/browser-extension/src/entrypoints/content.tsx - Popup UI
apps/browser-extension/src/entrypoints/popup/main.tsx - Injected React app
apps/browser-extension/src/components/app.tsx - Copy conversation flow · Extracts, serializes, and copies the selected conversation locally.
apps/browser-extension/src/hooks/use-copy-conversation.ts
Extraction & Export
- Plugin contract · Defines platform adapters and canonical conversation output.
packages/core-plugins/src/types.ts - Plugin registry · Selects the adapter for the active page.
packages/core-plugins/src/registry.ts - Platform adapters · ChatGPT, Claude, Gemini, DeepSeek, Doubao, Grok, and GitHub acquisition.
packages/core-plugins/src/plugins/index.ts - ChatGPT tree extraction · Flattens and linearizes ChatGPT conversation trees.
packages/core-plugins/src/plugins/chatgpt/tree-linearizer.ts - GitHub GraphQL adapter
packages/core-plugins/src/plugins/github/graphql.ts - Context Bundle schema · Carries source metadata, conversation nodes, and output format.
packages/core-schema/src/content-bundle.ts - Export formats · Full, User Only, Code Only, and Compact presentations.
packages/core-markdown/src/formats.ts - Markdown serializer · Produces clipboard-ready Markdown with frontmatter and token estimation.
packages/core-markdown/src/serializer.ts - Shared UI · Reusable rendering, localization, and styling.
packages/shared-ui/src/index.ts
Documentation Site
- Locale docs routes · Renders localized landing and MDX documentation pages.
apps/web/src/app/[locale]/docs/[[...mdxPath]]/page.tsx - Locale middleware
apps/web/middleware.ts - English & Chinese MDX
apps/web/content/en/_meta.ts
Automation
- Website deployment
.github/workflows/deploy-website.yml - Extension release
.github/workflows/release-extension.yml
Connections 22
- WXT build config → Background runtime: builds
- WXT build config → Content runtime: builds
- WXT build config → Popup UI: builds
- Content runtime → Injected React app: mounts
- Injected React app → Copy conversation flow: copy actions
- Popup UI → Shared UI: uses
- Injected React app → Shared UI: uses
- Copy conversation flow → Plugin registry: selects adapter
- Plugin registry → Plugin contract: uses
- Plugin registry → Platform adapters: resolves
- Platform adapters → ChatGPT tree extraction: includes
- Platform adapters → GitHub GraphQL adapter: includes
- Platform adapters → Context Bundle schema: normalizes to
- Plugin contract → Context Bundle schema: defines output
- Copy conversation flow → Export formats: selects format
- Context Bundle schema → Markdown serializer: serializes
- Export formats → Markdown serializer: configures
- Markdown serializer → Copy conversation flow: Markdown to clipboard
- Locale middleware → Locale docs routes: routes locale
- English & Chinese MDX → Locale docs routes: renders in
- Website deployment → Locale docs routes: deploys
- Extension release → WXT build config: releases build