@c4a/extract-ts
v0.5.41-beta.7
Published
TypeScript/TSX extraction plugin for C4A. It implements the `ExtractionPlugin` protocol from `@c4a/extract` and is the default plugin used by `context capture --code` for npm-style packages.
Downloads
2,379
Readme
@c4a/extract-ts
TypeScript/TSX extraction plugin for C4A. It implements the ExtractionPlugin protocol from @c4a/extract and is the default plugin used by context capture --code for npm-style packages.
Role in the Monorepo
@c4a/extract-ts handles TypeScript package entry detection and AST extraction. It does not write .context files directly; @c4a/extract runs the plugin and @c4a/context-cli persists the resulting raw code snapshot.
Depends on: @c4a/extract, web-tree-sitter
Used by: @c4a/context-cli, @c4a/daemon, E2E tests
Current Extraction Coverage
Entry Detection
detectEntries() reads package.json and supports:
exportsmaps, including conditionalimport,default, andmaintargetsmainbinworkspacesglobs ending in/*dist/tosrc/source-path fallback throughresolveEntrySourcePath()- package kind classification:
lib,cli, orservice - package version propagation into
ExtractionResult.package.version
Entry files are returned as module-relative paths. The repository runner later prefixes them to repo-relative paths in raw snapshots.
Symbol Extraction
extractSymbols() starts from detected entry files, traces exports, and marks reachable declarations as exported.
It currently extracts:
- functions
- classes
- interfaces
- type aliases
- enums
- variables
- TSX component-like variables
- hook-like functions by name in downstream projection
- class/interface/type members as nested symbols
- JSDoc on declarations and members
- function params and return types
- type annotations
- interface/type object members, including object types nested in union/intersection/parenthesized types
- string-literal union values
- component
propsTypebyFC<Props>style annotations or{ComponentName}Propsconvention
It emits relations for:
importsimports_typeextendsimplementsparam_typereturn_typeof_type
All emitted relations are code-grounded AST relations with confidence 1.
Export Tracing
exportTracer.ts follows:
- local exported declarations
export default <identifier>when the identifier is locally declaredexport * from "./module"export { A } from "./module"- aliased export specifiers
- circular re-export chains through an in-flight guard
Only declarations reachable through entries are marked exported; other declarations in traced files remain internal.
Contract with Code Projection
The plugin returns ExtractionResult v2. The @c4a/extract runner turns that into raw snapshot rows:
packages.jsonlreceives package name/kind/language/version and package description when present.symbols.jsonlreceives flattened symbol rows withsymbol_id,package_name, andmodule_path.edges.jsonlreceives relation rows with package/module/version/hash metadata.digests.jsonlreceives versioned module digest rows.
context compile --code consumes those rows to build package/category/symbol Nodes. The important projection inputs are:
- stable package names and versions
- stable exported symbol names
- useful
kindvalues (component,function,type,interface, etc.) - accurate visibility
- source file and line ranges
- relation
from/tovalues - JSDoc and type/member metadata
Obsidian Render reads compiled Markdown and graph YAML after projection; it does not read @c4a/extract-ts output directly.
Usage
Manual registry usage:
import { ExtractionPluginRegistry } from "@c4a/extract";
import { TypeScriptPlugin } from "@c4a/extract-ts";
const registry = new ExtractionPluginRegistry();
registry.register(new TypeScriptPlugin());Runner usage normally goes through context capture --code; agents should not hand-build runner input or raw snapshots.
Internal Modules
| File | Purpose |
|---|---|
| plugin.ts | Plugin class; stores package info from detectEntries() for extractSymbols() |
| entryDetector.ts | package.json parsing, entry target collection, workspace package detection |
| symbolExtractor.ts | Tree-sitter AST extraction, symbol/member/relation collection |
| exportTracer.ts | Re-export tracing and exported/internal split |
| pathUtils.ts | Source-path and relative import resolution |
Development
bun run --filter @c4a/extract-ts build
bun run --filter @c4a/extract-ts typecheck
bun run --filter @c4a/extract-ts test
bun run --filter @c4a/extract-ts lint