@c4a/extract-ts 0.6.8 → 0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +17 -1
  2. package/README.zh-CN.md +148 -11
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,16 +1,32 @@
1
1
  # @c4a/extract-ts
2
2
 
3
- TypeScript/TSX extraction plugin for Context. It implements the
3
+ [简体中文](./README.zh-CN.md)
4
+
5
+ `@c4a/extract-ts` turns TypeScript and TSX structure into deterministic code
6
+ evidence for Context knowledge production. It implements the
4
7
  `ExtractionPlugin` protocol from `@c4a/extract` and is the default plugin used
5
8
  by the SDK `extractTs({ source, collection: "codegraph" })` phase for npm-style
6
9
  packages.
7
10
 
11
+ It extracts code facts; it does not decide product meaning, write approved
12
+ Markdown, or choose the user's source boundary. Knowledge-workspace users reach
13
+ it through the Context Agent entry and a confirmed extraction phase. The direct
14
+ APIs below are for reusable structural analysis and project-owned adapters.
15
+
8
16
  ## Package Role
9
17
 
10
18
  `@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.
11
19
 
12
20
  **Depends on:** `@c4a/extract`, `web-tree-sitter`
13
21
 
22
+ ```text
23
+ confirmed TypeScript boundary
24
+
25
+ entry detection + export tracing + AST facts
26
+
27
+ raw code snapshot → review candidates → approved knowledge
28
+ ```
29
+
14
30
  ## React Router structural facts
15
31
 
16
32
  Projects that use `extractCustom()` can reuse `extractReactRouterRoutes()` to
package/README.zh-CN.md CHANGED
@@ -1,11 +1,36 @@
1
1
  # @c4a/extract-ts
2
2
 
3
- Context 的 TypeScript/TSX 结构提取包。它实现 `@c4a/extract` 的插件协议,
4
- 也是 SDK `extractTs({ source, collection: "codegraph" })` 阶段使用的默认
5
- 提取器。
3
+ [English](./README.md)
6
4
 
7
- TypeScript 符号、导出和 AST 关系外,包还提供可独立使用的 React Router
8
- 结构提取:
5
+ `@c4a/extract-ts` TypeScript TSX 结构转化为 Context 知识生产可使用的确定性
6
+ 代码证据。它实现 `@c4a/extract` 的 `ExtractionPlugin` 协议,也是 npm-style
7
+ package 使用 `extractTs({ source, collection: "codegraph" })` 阶段时的默认插件。
8
+
9
+ 它只提取代码事实,不判断产品含义、不写正式 Markdown,也不替用户选择来源边界。
10
+ 知识工作区用户通过 Context Agent 入口和已确认的提取阶段使用它;直接 API 面向
11
+ 可复用结构分析和项目自有 Adapter。
12
+
13
+ ## 在知识生产链中的职责
14
+
15
+ ```text
16
+ 已确认的 TypeScript 边界
17
+
18
+ 入口检测 + 导出追踪 + AST 事实
19
+
20
+ 原始代码快照 → 审核候选 → 正式知识
21
+ ```
22
+
23
+ `@c4a/extract-ts` 负责 TypeScript package 入口检测和 AST 提取。它不直接写工作区;
24
+ `@c4a/extract` 运行插件,Context runtime 保存并校验原始代码快照。
25
+
26
+ **依赖:** `@c4a/extract`、`web-tree-sitter`
27
+
28
+ ## 可复用结构 API
29
+
30
+ ### React Router 结构事实
31
+
32
+ 使用 `extractCustom()` 的项目可以复用 `extractReactRouterRoutes()`,索引 JSX
33
+ `<Route>` 声明和 route-object 数组:
9
34
 
10
35
  ```ts
11
36
  import { extractReactRouterRoutes } from "@c4a/extract-ts";
@@ -16,11 +41,13 @@ const routes = extractReactRouterRoutes(source, "src/router.tsx", {
16
41
  });
17
42
  ```
18
43
 
19
- 该函数读取 JSX `<Route>` 和 route object 数组,返回路径、组件、重定向、
20
- 条件、导入来源、注释及源码位置,不判断业务含义。项目可以在
21
- `extractCustom()` 中将这些结构事实映射为自己的候选。
44
+ 结果包含路径、组件、重定向、条件、导入来源、注释和源码位置,但不会把路由分类为
45
+ 产品能力或业务页面。
22
46
 
23
- 包还提供单文件导出面读取:
47
+ ### TypeScript 模块导出面
48
+
49
+ `extractTypeScriptModuleExports()` 读取单个 TypeScript/TSX 模块,返回确定性的具名
50
+ 导出、通配导出目标和全部 re-export 目标:
24
51
 
25
52
  ```ts
26
53
  import { extractTypeScriptModuleExports } from "@c4a/extract-ts";
@@ -28,5 +55,115 @@ import { extractTypeScriptModuleExports } from "@c4a/extract-ts";
28
55
  const exports = extractTypeScriptModuleExports(source, "src/index.ts");
29
56
  ```
30
57
 
31
- 返回结果包含具名导出、通配导出目标和全部 re-export 目标。函数不解析文件、
32
- 不追踪依赖,也不判断业务含义,适合由定制提取流程继续映射为领域事实。
58
+ 它不解析文件依赖,也不判断业务含义,适合由项目自有提取器继续映射为领域事实。
59
+
60
+ ## 当前提取范围
61
+
62
+ ### 入口检测
63
+
64
+ `detectEntries()` 读取 `package.json` 并支持:
65
+
66
+ - `exports` map,包括 conditional `import`、`default` 和 `main`;
67
+ - `main` 和 `bin`;
68
+ - 以 `/*` 结尾的 `workspaces` glob;
69
+ - 通过 `resolveEntrySourcePath()` 将 `dist/` 入口回退到 `src/`;
70
+ - `lib`、`cli`、`service` package 类型识别;
71
+ - 将 package version 写入 `ExtractionResult.package.version`。
72
+
73
+ Context 项目可以使用 source-relative `extractTs.entries` 覆盖自动检测,或用
74
+ `mode: "scan"` 把所有 `include` 命中的文件作为提取根。这些设置属于知识工作区,
75
+ 无需修改被分析 package。
76
+
77
+ 入口文件以 module-relative 路径返回,Repository Runner 再为原始快照补充
78
+ repo-relative 前缀。
79
+
80
+ ### 符号提取
81
+
82
+ `extractSymbols()` 从检测到的入口开始追踪导出,将可达声明标记为 `exported`。
83
+ 当前支持:
84
+
85
+ - function、class、interface、type alias、enum 和 variable;
86
+ - TSX component-like variable;
87
+ - 下游投影按名称识别的 hook-like function;
88
+ - class/interface/type 的嵌套成员;
89
+ - 声明和成员 JSDoc;
90
+ - function 参数和返回类型;
91
+ - type annotation、extends 和 implements;
92
+ - union/intersection/parenthesized type 中的 object member;
93
+ - string-literal union value;
94
+ - 通过 `FC<Props>` 或 `{ComponentName}Props` 约定识别的 `propsType`。
95
+
96
+ 输出关系包括 `imports`、`imports_type`、`extends`、`implements`、
97
+ `param_type`、`return_type` 和 `of_type`。这些关系均由 AST 直接支撑,confidence
98
+ 为 `1`。
99
+
100
+ ### 导出追踪
101
+
102
+ `exportTracer.ts` 支持:
103
+
104
+ - 本地导出声明;
105
+ - 本地标识符形式的 `export default`;
106
+ - `export * from "./module"`;
107
+ - `export { A } from "./module"`;
108
+ - 别名 export specifier;
109
+ - 通过 in-flight guard 处理循环 re-export。
110
+
111
+ 只有从入口导出面可达的声明会标记为 `exported`,同一已追踪文件中的其他声明保持
112
+ `internal`。
113
+
114
+ ## 与代码知识投影的契约
115
+
116
+ 插件返回 `ExtractionResult` v2,`@c4a/extract` Runner 将其转成原始快照:
117
+
118
+ - `packages.jsonl`:package 名、类型、语言、版本和可用描述;
119
+ - `symbols.jsonl`:带 `symbol_id`、`package_name` 和 `module_path` 的扁平符号;
120
+ - `edges.jsonl`:带 package、module、version 和 hash 元数据的关系;
121
+ - `digests.jsonl`:版本化模块 digest。
122
+
123
+ Context runtime 使用这些行生成 package/category/symbol 知识候选。重要输入是稳定
124
+ package 名和版本、稳定导出符号、准确 kind/visibility、文件与行范围、关系端点、
125
+ JSDoc 和类型成员信息。
126
+
127
+ 知识包构建读取 review apply 后的正式 Markdown 和项目元数据,不直接读取
128
+ `@c4a/extract-ts` 输出。
129
+
130
+ ## 使用方式
131
+
132
+ 手工注册插件:
133
+
134
+ ```ts
135
+ import { ExtractionPluginRegistry } from "@c4a/extract";
136
+ import { TypeScriptPlugin } from "@c4a/extract-ts";
137
+
138
+ const registry = new ExtractionPluginRegistry();
139
+ registry.register(new TypeScriptPlugin());
140
+ ```
141
+
142
+ 正常工作区在 `src/index.ts` 声明项目阶段:
143
+
144
+ ```ts
145
+ import { defineProject, extractTs, reviewValidity, source } from "@c4a/context";
146
+
147
+ const componentLib = source("component-lib");
148
+
149
+ export default defineProject({
150
+ sources: [componentLib],
151
+ phases: [
152
+ extractTs({ source: componentLib, collection: "codegraph" }),
153
+ reviewValidity({ collection: "codegraph" }),
154
+ ],
155
+ packages: [],
156
+ });
157
+ ```
158
+
159
+ 实际提取由当前 Context Route 驱动。Agent 不应在正常知识生产中手工构造 Runner
160
+ 输入或原始快照。
161
+
162
+ ## 开发
163
+
164
+ ```bash
165
+ bun run --filter @c4a/extract-ts build
166
+ bun run --filter @c4a/extract-ts typecheck
167
+ bun run --filter @c4a/extract-ts test
168
+ bun run --filter @c4a/extract-ts lint
169
+ ```
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@c4a/extract-ts",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "type": "module",
5
- "description": "TypeScript extraction plugin for C4A ExtractionResult v2",
5
+ "description": "TypeScript extraction plugin for the Context ExtractionResult v2 contract",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",