@c4a/context 0.6.0-beta.8 → 0.6.1-beta.1
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.
- package/LICENSE +21 -0
- package/README.md +94 -54
- package/README.zh-CN.md +114 -0
- package/package.json +14 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 context4ai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Context SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[简体中文](./README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
`@c4a/context` is the declarative SDK for a Context workspace. It provides the
|
|
6
|
+
typed API used by `src/index.ts` to describe sources, processing phases, review
|
|
7
|
+
gates, and package outputs. It does not perform filesystem writes or run the
|
|
8
|
+
workflow; those operations belong to the
|
|
9
|
+
[Context CLI](../context-cli/README.md).
|
|
8
10
|
|
|
9
|
-
##
|
|
11
|
+
## Project Model
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
For local SDK development:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
./start.sh link
|
|
17
|
-
context init context --dev
|
|
18
|
-
cd context
|
|
19
|
-
bun install
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Tiny Example
|
|
13
|
+
A Context project follows a sources-to-phases-to-packages model:
|
|
23
14
|
|
|
24
15
|
```ts
|
|
25
16
|
import {
|
|
26
17
|
defineProject,
|
|
27
18
|
extractTs,
|
|
28
|
-
reviewValidity,
|
|
29
19
|
kbPackage,
|
|
20
|
+
reviewValidity,
|
|
30
21
|
source,
|
|
31
22
|
} from "@c4a/context";
|
|
32
23
|
|
|
@@ -51,50 +42,99 @@ export default defineProject({
|
|
|
51
42
|
});
|
|
52
43
|
```
|
|
53
44
|
|
|
54
|
-
|
|
45
|
+
`src/index.ts` is similar to a Webpack configuration for knowledge. It defines
|
|
46
|
+
what enters the project, which transformations and gates run, and what is built
|
|
47
|
+
at the end. The installed Agent plugin includes the skills and SDK manuals
|
|
48
|
+
needed to maintain this configuration from a user's requirements.
|
|
49
|
+
|
|
50
|
+
## Public Surface
|
|
51
|
+
|
|
52
|
+
| API | Purpose |
|
|
53
|
+
|---|---|
|
|
54
|
+
| `defineProject()` | Declares the complete project graph. |
|
|
55
|
+
| `source()` and `allSources()` | References registered repo, file, or Lark source boundaries. |
|
|
56
|
+
| `extractTs()` | Extracts TypeScript/TSX symbols and relationships into `codegraph` candidates. |
|
|
57
|
+
| `alignProse()` and `compileProse()` | Structures document evidence and compiles source-bound knowledge candidates. |
|
|
58
|
+
| `reviewValidity()` | Declares the review gate for one collection or the project. |
|
|
59
|
+
| `customPhase()` | Adds project-specific orchestration when built-in phase factories are not enough. |
|
|
60
|
+
| `kbPackage()` | Builds an Agent knowledge-base package from approved knowledge and templates. |
|
|
61
|
+
| `llmsPackage()` | Builds a single text bundle for model context or RAG import. |
|
|
62
|
+
|
|
63
|
+
Use the built-in phase factories first. `customPhase()` is an escape hatch for
|
|
64
|
+
project-specific orchestration, not a replacement for source, extraction,
|
|
65
|
+
review, and package lifecycle rules.
|
|
66
|
+
|
|
67
|
+
## Knowledge Collections
|
|
68
|
+
|
|
69
|
+
Approved Markdown is organized under `knowledge/<collection>/`:
|
|
70
|
+
|
|
71
|
+
| Collection | What it contains | Typical sources |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `codegraph` | Code symbols, modules, and relationships | Code repositories |
|
|
74
|
+
| `business` | Business concepts, roles, and relationships | Business and Lark documents |
|
|
75
|
+
| `product` | Product capabilities and behavior | Product and requirement documents |
|
|
76
|
+
| `architecture` | System structure and design explanations | Architecture and design documents |
|
|
77
|
+
| `sop` | Procedures, runbooks, and operational steps | Handbooks and operation documents |
|
|
78
|
+
| `faq` | Common questions and troubleshooting | FAQs, support documents, experience notes |
|
|
79
|
+
| `decision` | Decisions, alternatives, and trade-offs | Design reviews and decision records |
|
|
80
|
+
| `incident` | Incident timelines, response, and follow-up | Incident reports and retrospectives |
|
|
81
|
+
| `standards` | Normative rules and constraints | Engineering standards and business rules |
|
|
82
|
+
| `test` | Validation rules, scenarios, and acceptance criteria | Test plans and acceptance documents |
|
|
83
|
+
| `feats` | Capability records for a specific use case | Custom project workflows and approved knowledge |
|
|
84
|
+
|
|
85
|
+
Collections are semantic classifications, not final package directories.
|
|
86
|
+
Package build maps selected collections into OKF roots such as `wikis/`,
|
|
87
|
+
`guides/`, `rules/`, and `feats/`. One source may contribute to several
|
|
88
|
+
collections; classification should be based on evidence and user confirmation,
|
|
89
|
+
not filenames.
|
|
90
|
+
|
|
91
|
+
## Package Templates
|
|
92
|
+
|
|
93
|
+
Package declarations point at editable templates under
|
|
94
|
+
`src/package-templates/`. Installed examples are available at:
|
|
55
95
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
- [Getting Started](./docs/getting-started.md)
|
|
60
|
-
- [Agent Guide](./docs/guides/agent-guide.md)
|
|
61
|
-
- [Package Outputs](./docs/guides/package-outputs.md)
|
|
62
|
-
- [Project API](./docs/reference/project-api.md)
|
|
63
|
-
- [Package Templates](./docs/reference/package-templates.md)
|
|
96
|
+
```text
|
|
97
|
+
node_modules/@c4a/context/templates/package-templates/
|
|
98
|
+
```
|
|
64
99
|
|
|
65
|
-
|
|
100
|
+
The default KB template includes:
|
|
66
101
|
|
|
67
102
|
```text
|
|
68
|
-
|
|
103
|
+
kb/
|
|
104
|
+
|-- AGENTS.md
|
|
105
|
+
|-- skills/
|
|
106
|
+
| `-- knowledge-query/SKILL.md
|
|
107
|
+
`-- wikis/index.md
|
|
69
108
|
```
|
|
70
109
|
|
|
71
|
-
|
|
72
|
-
|
|
110
|
+
The `knowledge-query` Skill teaches consuming Agents how to navigate indexes,
|
|
111
|
+
inspect approved knowledge, and cite evidence. A project can add more Skills or
|
|
112
|
+
template files under `wikis/`, `guides/`, `rules/`, and other package paths.
|
|
73
113
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
`
|
|
78
|
-
at the top level. Do not nest `sources`, `visibility`, or `code_symbols` under
|
|
79
|
-
`context`, and do not add frontmatter `source_refs`. Section provenance lives in
|
|
80
|
-
`context:section` source-ref comments.
|
|
114
|
+
Templates use Handlebars variables in file contents and paths. Common variables
|
|
115
|
+
include `{{packageName}}`, `{{displayName}}`, `{{knowledgeCount}}`,
|
|
116
|
+
`{{knowledgeGroups}}`, `{{knowledgeItems}}`, `{{knowledgeTree}}`, and
|
|
117
|
+
`{{buildInventory}}`.
|
|
81
118
|
|
|
82
|
-
|
|
119
|
+
For advanced routing and retrieval, a template may carry a local script such as
|
|
120
|
+
`query.ts`, with a Skill describing when and how an Agent should call it. The
|
|
121
|
+
Skill can also route the Agent to MCP servers, CLI commands, or other tools to
|
|
122
|
+
form a package-specific Agentic Search workflow.
|
|
83
123
|
|
|
84
|
-
|
|
124
|
+
## State Boundary
|
|
85
125
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
126
|
+
The SDK stays declarative. It may describe reads, writes, phases, review, and
|
|
127
|
+
package selection, but the CLI owns source materialization, capture, extraction,
|
|
128
|
+
review application, approved Markdown materialization, verification, and build.
|
|
129
|
+
Do not replace CLI lifecycle operations with direct edits to `sources/`,
|
|
130
|
+
`unapproved/`, `knowledge/`, or `dist/`.
|
|
91
131
|
|
|
92
|
-
|
|
132
|
+
## Documentation
|
|
93
133
|
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
-
|
|
97
|
-
-
|
|
98
|
-
- package
|
|
99
|
-
-
|
|
100
|
-
-
|
|
134
|
+
- [Documentation index](./docs/README.md)
|
|
135
|
+
- [Getting Started](./docs/getting-started.md)
|
|
136
|
+
- [Agent Guide](./docs/guides/agent-guide.md)
|
|
137
|
+
- [Project API](./docs/reference/project-api.md)
|
|
138
|
+
- [Package Outputs](./docs/guides/package-outputs.md)
|
|
139
|
+
- [Package Templates](./docs/reference/package-templates.md)
|
|
140
|
+
- [Template Variables](./docs/reference/template-variables.md)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Context SDK
|
|
2
|
+
|
|
3
|
+
[English](./README.md)
|
|
4
|
+
|
|
5
|
+
`@c4a/context` 是 Context workspace 使用的声明式 SDK。它为 `src/index.ts` 提供类型化 API,用来描述知识来源、处理阶段、审核门禁和知识包输出。SDK 本身不写入工作区,也不执行流程;这些操作由 [Context CLI](../context-cli/README.zh-CN.md) 负责。
|
|
6
|
+
|
|
7
|
+
## 项目模型
|
|
8
|
+
|
|
9
|
+
Context 项目使用“来源 → 阶段 → 知识包”的声明模型:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import {
|
|
13
|
+
defineProject,
|
|
14
|
+
extractTs,
|
|
15
|
+
kbPackage,
|
|
16
|
+
reviewValidity,
|
|
17
|
+
source,
|
|
18
|
+
} from "@c4a/context";
|
|
19
|
+
|
|
20
|
+
const sampleLib = source("20260712", "sample-lib");
|
|
21
|
+
|
|
22
|
+
export default defineProject({
|
|
23
|
+
sources: [sampleLib],
|
|
24
|
+
phases: [
|
|
25
|
+
extractTs({ source: sampleLib, collection: "codegraph" }),
|
|
26
|
+
reviewValidity({ collection: "codegraph" }),
|
|
27
|
+
],
|
|
28
|
+
packages: [
|
|
29
|
+
kbPackage({
|
|
30
|
+
name: "sample-lib-kb",
|
|
31
|
+
template: {
|
|
32
|
+
path: "src/package-templates/kb",
|
|
33
|
+
vars: { displayName: "Sample Library KB" },
|
|
34
|
+
},
|
|
35
|
+
select: { collections: ["codegraph"], okfRoots: ["wikis"] },
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`src/index.ts` 有点像知识项目的 Webpack 配置:它定义哪些内容进入项目、经过哪些转换和门禁,以及最终构建什么产物。安装好的 Agent 插件带有编写技能和 SDK 说明文档,可以根据用户需求维护这份配置。
|
|
42
|
+
|
|
43
|
+
## 主要 API
|
|
44
|
+
|
|
45
|
+
| API | 用途 |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `defineProject()` | 声明完整的项目处理图。 |
|
|
48
|
+
| `source()` 和 `allSources()` | 引用已经登记的代码仓库、本地文件或飞书来源边界。 |
|
|
49
|
+
| `extractTs()` | 从 TypeScript/TSX 中提取符号和关系,生成 `codegraph` 候选。 |
|
|
50
|
+
| `alignProse()` 和 `compileProse()` | 整理文档证据,并生成与来源绑定的知识候选。 |
|
|
51
|
+
| `reviewValidity()` | 声明单个知识类型或整个项目的审核门禁。 |
|
|
52
|
+
| `customPhase()` | 在内置阶段无法覆盖时增加项目专用编排。 |
|
|
53
|
+
| `kbPackage()` | 使用审核通过的知识和模板构建 Agent 知识库。 |
|
|
54
|
+
| `llmsPackage()` | 构建供模型上下文或 RAG 导入使用的单文件文本包。 |
|
|
55
|
+
|
|
56
|
+
优先使用内置阶段。`customPhase()` 是项目专用编排的扩展口,不应该绕开来源、提取、审核和打包的生命周期规则。
|
|
57
|
+
|
|
58
|
+
## 知识分类
|
|
59
|
+
|
|
60
|
+
审核通过的 Markdown 会存放在 `knowledge/<collection>/`:
|
|
61
|
+
|
|
62
|
+
| 知识类型 | 主要内容 | 常见来源 |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `codegraph` | 代码符号、模块和调用关系 | 代码仓库 |
|
|
65
|
+
| `business` | 业务概念、角色和业务关系 | 业务文档、飞书文档 |
|
|
66
|
+
| `product` | 产品能力、功能行为和产品关系 | 产品文档、需求文档 |
|
|
67
|
+
| `architecture` | 系统结构、模块职责和设计说明 | 架构文档、设计文档 |
|
|
68
|
+
| `sop` | 操作流程、运行手册和处理步骤 | 操作手册、值班文档 |
|
|
69
|
+
| `faq` | 常见问题、解释和排障方法 | FAQ、支持文档、经验记录 |
|
|
70
|
+
| `decision` | 方案选择、取舍和决策背景 | 设计评审、决策记录 |
|
|
71
|
+
| `incident` | 故障过程、处置方式和后续行动 | 故障复盘、事故报告 |
|
|
72
|
+
| `standards` | 必须遵守的规范和约束 | 研发规范、业务规则 |
|
|
73
|
+
| `test` | 验证规则、测试场景和验收标准 | 测试文档、验收说明 |
|
|
74
|
+
| `feats` | 面向具体场景整理的能力记录 | 项目自定义处理和已确认知识 |
|
|
75
|
+
|
|
76
|
+
知识类型是语义分类,不是最终知识包目录。构建时会把选中的类型映射到 `wikis/`、`guides/`、`rules/`、`feats/` 等 OKF 目录。同一份来源可能贡献多种知识,分类应该依据证据和用户确认,而不是文件名。
|
|
77
|
+
|
|
78
|
+
## 知识包模板
|
|
79
|
+
|
|
80
|
+
知识包声明会引用 `src/package-templates/` 下的可编辑模板。安装后的示例位于:
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
node_modules/@c4a/context/templates/package-templates/
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
默认 KB 模板包含:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
kb/
|
|
90
|
+
|-- AGENTS.md
|
|
91
|
+
|-- skills/
|
|
92
|
+
| `-- knowledge-query/SKILL.md
|
|
93
|
+
`-- wikis/index.md
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`knowledge-query` Skill 会告诉消费知识包的 Agent 如何浏览索引、读取审核通过的知识并引用证据。项目还可以增加更多 Skills,或者在 `wikis/`、`guides/`、`rules/` 等目录中加入模板文件。
|
|
97
|
+
|
|
98
|
+
模板使用 Handlebars 变量,可以作用于文件内容和路径。常用变量包括 `{{packageName}}`、`{{displayName}}`、`{{knowledgeCount}}`、`{{knowledgeGroups}}`、`{{knowledgeItems}}`、`{{knowledgeTree}}` 和 `{{buildInventory}}`。
|
|
99
|
+
|
|
100
|
+
如果需要更强的路由和检索能力,模板可以携带 `query.ts` 一类本地脚本,再由 Skill 约定 Agent 何时、如何调用。Skill 也可以把 Agent 路由到 MCP、CLI 或其他工具,组成适合当前知识包的 Agentic Search 流程。
|
|
101
|
+
|
|
102
|
+
## 状态边界
|
|
103
|
+
|
|
104
|
+
SDK 只负责声明。它可以描述读取、写入、阶段、审核和知识包选择,但来源物化、内容读取、代码提取、审核应用、正式知识写入、质量验证和构建都由 CLI 负责。不要通过直接编辑 `sources/`、`unapproved/`、`knowledge/` 或 `dist/` 来替代 CLI 生命周期操作。
|
|
105
|
+
|
|
106
|
+
## 参考文档
|
|
107
|
+
|
|
108
|
+
- [文档索引](./docs/README.md)
|
|
109
|
+
- [快速开始](./docs/getting-started.md)
|
|
110
|
+
- [Agent 指南](./docs/guides/agent-guide.md)
|
|
111
|
+
- [项目 API](./docs/reference/project-api.md)
|
|
112
|
+
- [知识包输出](./docs/guides/package-outputs.md)
|
|
113
|
+
- [知识包模板](./docs/reference/package-templates.md)
|
|
114
|
+
- [模板变量](./docs/reference/template-variables.md)
|
package/package.json
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c4a/context",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"description": "Context SDK — project-local configuration and workspace primitives",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/context4ai/context.git",
|
|
10
|
+
"directory": "packages/context"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"context",
|
|
14
|
+
"sdk",
|
|
15
|
+
"knowledge",
|
|
16
|
+
"workspace"
|
|
17
|
+
],
|
|
5
18
|
"dependencies": {
|
|
6
19
|
"yaml": "^2.5.1",
|
|
7
20
|
"zod": "^3.23.8"
|