@c4a/context 0.6.0-beta.7 → 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/docs/getting-started.md +9 -1
- package/docs/guides/agent-dialogue.md +11 -0
- package/docs/guides/agent-guide.md +46 -2
- package/docs/guides/package-outputs.md +20 -0
- package/docs/reference/package-templates.md +6 -3
- package/docs/reference/project-api.md +77 -18
- package/package.json +14 -1
- package/templates/package-templates/kb/AGENTS.md +5 -3
- package/templates/package-templates/kb/skills/knowledge-query/SKILL.md +10 -6
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/docs/getting-started.md
CHANGED
|
@@ -13,7 +13,10 @@ bun install
|
|
|
13
13
|
context status
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Use `--dev`
|
|
16
|
+
Use `--dev` when testing a local link or prepared pack before the matching SDK
|
|
17
|
+
version is published. It writes a `file:` dependency to the SDK resolved beside
|
|
18
|
+
the active CLI. Published users can omit it and install the versioned SDK from
|
|
19
|
+
the registry.
|
|
17
20
|
When operating through an Agent plugin, use the installed Context continuation entry from the project root after initialization; it reads `context status` and then calls the lower-level CLI primitives as needed. The exact slash command or skill name is host-specific.
|
|
18
21
|
|
|
19
22
|
## 2. Choose And Register A Source Boundary
|
|
@@ -101,6 +104,11 @@ pausing for another date name or collection choice between modules. If any
|
|
|
101
104
|
module lacks a declaration, status returns `needs-capture-phase` and a precise
|
|
102
105
|
`routing.configuration` action instead of an unexecutable command.
|
|
103
106
|
|
|
107
|
+
After capture, status returns `captured-ready-to-classify` for document modules
|
|
108
|
+
without an align declaration. Run the returned collection-neutral evidence
|
|
109
|
+
views first; only then propose a mainline collection and ask for confirmation.
|
|
110
|
+
The batch read permission does not itself choose a collection.
|
|
111
|
+
|
|
104
112
|
When the workspace also contains repo sources, Context prioritizes untouched
|
|
105
113
|
code after all document captures finish: status returns `ready-to-extract`
|
|
106
114
|
until the code extraction round is current, then returns to document
|
|
@@ -19,6 +19,17 @@ CLI commands, source names, phase ids, status values, payload keys, and
|
|
|
19
19
|
`source_ref` values are protocol text. Keep those exact when needed, but do not
|
|
20
20
|
make them the main explanation.
|
|
21
21
|
|
|
22
|
+
## Fully Managed Conversation
|
|
23
|
+
|
|
24
|
+
If the user explicitly says the current conversation is fully managed, briefly
|
|
25
|
+
confirm that eligible workflow decisions will proceed automatically, then use
|
|
26
|
+
the CLI's `--managed` status loop. Do not ask the ordinary classification,
|
|
27
|
+
extraction-scope, structure-confirmation, Review, or package-output questions.
|
|
28
|
+
Continue to surface source/read permission, external operation requests, and
|
|
29
|
+
validation or verification failures because managed mode does not authorize or
|
|
30
|
+
hide them. The authorization ends with the conversation and must not be written
|
|
31
|
+
to project configuration.
|
|
32
|
+
|
|
22
33
|
## Human Gate Question Form
|
|
23
34
|
|
|
24
35
|
When the decision has a small fixed option set, use the host's native
|
|
@@ -14,6 +14,24 @@ This guide is for Coding Agents operating a Context workspace.
|
|
|
14
14
|
and [Package Templates](../reference/package-templates.md).
|
|
15
15
|
6. Before asking a human gate question, read [Agent Dialogue](./agent-dialogue.md).
|
|
16
16
|
|
|
17
|
+
## Current-conversation fully managed mode
|
|
18
|
+
|
|
19
|
+
When the user explicitly requests fully managed operation in the current
|
|
20
|
+
conversation, use `context status --managed --format json` and keep `--managed`
|
|
21
|
+
on the commands returned by that loop. Eligible classification, extraction
|
|
22
|
+
scope, structure confirmation, Review, and package-output gates may proceed
|
|
23
|
+
without another question. Review uses the CLI's atomic `context review
|
|
24
|
+
approve-all ... --managed` route; valid structure staging records
|
|
25
|
+
`confirmed_by: managed-session`.
|
|
26
|
+
|
|
27
|
+
This is execution authority, not project configuration. Do not add it to
|
|
28
|
+
`defineProject`, environment files, or committed workspace state, and do not
|
|
29
|
+
carry it into a new conversation. It never grants a new source boundary or
|
|
30
|
+
source-body read permission, authorizes clone/checkout/fetch/install/build/test
|
|
31
|
+
operations outside the Context workspace, or suppresses validation, close, or
|
|
32
|
+
verify failures. Without an explicit request, use ordinary status and all
|
|
33
|
+
existing human gates.
|
|
34
|
+
|
|
17
35
|
If the installed docs are unavailable, run `bun install` in the Context workspace.
|
|
18
36
|
|
|
19
37
|
## Dialogue Language
|
|
@@ -131,8 +149,9 @@ captured through the Lark capture phase, and written as committed snapshots
|
|
|
131
149
|
as a sibling file under `sources/lark/<date>/`, tracked by the date-level `manifest.json`;
|
|
132
150
|
do not fetch or import Lark content with ad hoc scripts.
|
|
133
151
|
If the user requests multiple documents together, register and declare all of
|
|
134
|
-
them before capture. The user's explicit batch request supplies one read scope
|
|
135
|
-
|
|
152
|
+
them before capture. The user's explicit batch request supplies one read scope,
|
|
153
|
+
but it does not imply a mainline collection unless the user explicitly chose
|
|
154
|
+
one. Follow `routing.command_plan`: run
|
|
136
155
|
`immediate` items directly and run `after-human-confirmation` items only after
|
|
137
156
|
the current conversation contains that confirmation. Do not ask for another
|
|
138
157
|
date name or repeat the collection gate per document.
|
|
@@ -160,6 +179,31 @@ by the structure must have an exact compile route for the same source. Do not
|
|
|
160
179
|
run a compile command from another collection as a fallback. A
|
|
161
180
|
`reviewValidity({ scope: "all" })` declaration covers every collection.
|
|
162
181
|
|
|
182
|
+
When status is `captured-ready-to-classify`, execute its immediate capture-phase
|
|
183
|
+
evidence commands before adding align/compile declarations. Inspect every
|
|
184
|
+
unclassified target, explain the evidence behind the proposed mainline
|
|
185
|
+
collection, and wait for user confirmation. Filenames, URLs, source titles, and
|
|
186
|
+
collection names are hints, not sufficient classification evidence by
|
|
187
|
+
themselves.
|
|
188
|
+
|
|
189
|
+
Also inspect `pendingStructureTargets`. A non-empty list means captured document
|
|
190
|
+
work remains outside the active structure snapshots, even if the current package
|
|
191
|
+
is already built. Follow `needs-prose-configuration` first when declarations are
|
|
192
|
+
missing, then run the exact returned align command. Continue in the same
|
|
193
|
+
workspace; do not replace a valid earlier structure round or create a second
|
|
194
|
+
workspace merely to add the next document.
|
|
195
|
+
|
|
196
|
+
Use `structureBatch` for the complete multi-source slot overview. Evidence View
|
|
197
|
+
commands are workspace-read-only and parallel-safe; structure stage/confirm,
|
|
198
|
+
compile stage, Review apply, and close mutate workspace state and must run
|
|
199
|
+
serially.
|
|
200
|
+
|
|
201
|
+
The confirmation and Review scopes are different: confirm each canonical source
|
|
202
|
+
plus collection structure slot independently, but do not open Review while
|
|
203
|
+
another declared slot remains pending in the same round. Compile every View from
|
|
204
|
+
all slots first, open one collection-level Review, and let deterministic close
|
|
205
|
+
merge the active slots into `knowledge/structure.yaml`.
|
|
206
|
+
|
|
163
207
|
Do not infer permission from the presence of a command. Do not infer a command
|
|
164
208
|
from prose when `commands_available=false`; complete the returned configuration
|
|
165
209
|
action and rerun status instead.
|
|
@@ -66,6 +66,26 @@ package; the OKF-compatible interchange surface is the selected OKF root
|
|
|
66
66
|
subtrees under `dist/<package-name>/`, with `wikis/index.md` as the required
|
|
67
67
|
default KB entry.
|
|
68
68
|
|
|
69
|
+
Current collection mapping:
|
|
70
|
+
|
|
71
|
+
| Internal collection | Package path | Role |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `codegraph` | `wikis/codegraph/` | Structured code entities and relationships. |
|
|
74
|
+
| `business` | `wikis/business/` | Structured business entities and relationships. |
|
|
75
|
+
| `product` | `wikis/product/` | Structured product entities, behavior, and relationships. |
|
|
76
|
+
| `architecture` | `guides/architecture/` | Architecture explanations and design narratives. |
|
|
77
|
+
| `sop` | `guides/sop/` | Procedures and runbooks. |
|
|
78
|
+
| `faq` | `guides/faq/` | Question-oriented explanations and troubleshooting. |
|
|
79
|
+
| `decision` | `guides/decision/` | Decision records and trade-off narratives. |
|
|
80
|
+
| `incident` | `guides/incident/` | Incident timelines, response, and follow-up. |
|
|
81
|
+
| `standards` | `rules/standards/` | Normative standards and constraints. |
|
|
82
|
+
| `test` | `rules/test/` | Validation rules, scenarios, and acceptance checks. |
|
|
83
|
+
| `feats` | `feats/` | Feature capability records. |
|
|
84
|
+
|
|
85
|
+
`wikis/` is the structured entity-and-relationship layer. `guides/` and
|
|
86
|
+
`rules/` may explain, operationalize, or constrain that knowledge; their
|
|
87
|
+
placement does not create a relationship unless Context includes a typed edge.
|
|
88
|
+
|
|
69
89
|
`index.md` is reserved for OKF bundle and directory indexes. Source documents
|
|
70
90
|
may be named `index.md`, but generated concept pages must use a non-reserved
|
|
71
91
|
name such as `index-page.md`; `context build` rejects copied knowledge that
|
|
@@ -132,9 +132,12 @@ child indexes expose their own subdirectories and pages.
|
|
|
132
132
|
|
|
133
133
|
The generated `dist/<package-name>/wikis/` tree is the required default KB
|
|
134
134
|
entry surface. Internal collections are mapped into OKF roots during build:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
`feats/`.
|
|
135
|
+
`codegraph`, `business`, and `product` go to `wikis/`; `architecture`, `sop`,
|
|
136
|
+
`faq`, `decision`, and `incident` go to `guides/`; `standards` and `test` go to
|
|
137
|
+
`rules/`; and `feats` goes to `feats/`. Treat `wikis/` as the structured
|
|
138
|
+
entity-and-relationship layer. Guides and rules may explain, operationalize,
|
|
139
|
+
or constrain that knowledge, but directory placement alone does not establish
|
|
140
|
+
a relationship.
|
|
138
141
|
|
|
139
142
|
Default navigation rules:
|
|
140
143
|
|
|
@@ -210,10 +210,39 @@ compile routing is exact: phase selection uses canonical source plus collection,
|
|
|
210
210
|
and candidate progress remains bound to the current `structure_digest`. A
|
|
211
211
|
compile phase from another collection is never used as fallback.
|
|
212
212
|
|
|
213
|
+
Captured align targets that do not yet have an active confirmed structure are
|
|
214
|
+
reported in `pendingStructureTargets`. They remain unfinished even when the
|
|
215
|
+
currently active structures have been closed, verified, and built. Missing
|
|
216
|
+
compile or Review declarations route to `needs-prose-configuration`; once the
|
|
217
|
+
declarations are complete, status returns the exact align investigation command
|
|
218
|
+
for the next target. A built package does not freeze the workspace or require a
|
|
219
|
+
new workspace for later sources.
|
|
220
|
+
|
|
213
221
|
Use `context status --format json --view summary` when only the current state,
|
|
214
222
|
target, counts, diagnostics, and recommended command are needed. The full view
|
|
215
223
|
retains source, phase, package, and lifecycle inventories.
|
|
216
224
|
|
|
225
|
+
### Current-conversation managed execution
|
|
226
|
+
|
|
227
|
+
`context status --managed --format json` exposes
|
|
228
|
+
`executionMode: { mode: "managed", scope: "current-conversation" }` and resolves
|
|
229
|
+
eligible human gates into immediate commands. The flag is deliberately absent
|
|
230
|
+
from `defineProject`: callers must pass it on each status/run/review command in
|
|
231
|
+
the authorized conversation. A later process or conversation gets ordinary
|
|
232
|
+
human-gated behavior by default.
|
|
233
|
+
|
|
234
|
+
Managed Review is atomic and scope-validated:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
context review approve-all <collection> --managed --format json
|
|
238
|
+
context review approve-all --all --managed --format json
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Managed structure staging uses `context run <align-phase> --stage --managed
|
|
242
|
+
--input <structure.yaml> --format json`. Source boundaries and unread source
|
|
243
|
+
bodies, external operations, payload validation, deterministic close, and
|
|
244
|
+
verification errors are never bypassed.
|
|
245
|
+
|
|
217
246
|
### `captureFile`
|
|
218
247
|
|
|
219
248
|
Capture a registered file source into a committed normalized document snapshot.
|
|
@@ -299,6 +328,12 @@ alignProse({
|
|
|
299
328
|
});
|
|
300
329
|
```
|
|
301
330
|
|
|
331
|
+
`collection` is an internal knowledge classification, not a package directory.
|
|
332
|
+
Package build maps `codegraph`/`business`/`product` to `wikis/`,
|
|
333
|
+
`architecture`/`sop`/`faq`/`decision`/`incident` to `guides/`,
|
|
334
|
+
`standards`/`test` to `rules/`, and `feats` to `feats/`. The complete output
|
|
335
|
+
contract is documented in [Package Outputs](../guides/package-outputs.md).
|
|
336
|
+
|
|
302
337
|
When `source("name")` is type-neutral, the SDK may declare
|
|
303
338
|
`align:source:<source-name>:architecture`; the CLI resolves it to
|
|
304
339
|
`align:file:<source-name>:architecture` or `align:lark:<source-name>:architecture` after
|
|
@@ -313,7 +348,9 @@ context run align:file:<source-name>:architecture --view source-index --compact
|
|
|
313
348
|
context run align:file:<source-name>:architecture --view span-detail --span <source-ref> --format json
|
|
314
349
|
context run align:file:<source-name>:architecture --view span-text --span <source-ref> --format json
|
|
315
350
|
context run align:file:<source-name>:architecture --view schema --format json
|
|
351
|
+
context run align:file:<source-name>:architecture --view semantic-rules --format json
|
|
316
352
|
context run align:file:<source-name>:architecture --validate --input <structure.yaml> --format json
|
|
353
|
+
context run align:file:<source-name>:architecture --view diagnostics --input <structure.yaml> --format json
|
|
317
354
|
context run align:file:<source-name>:architecture --view structure-summary --input <structure.yaml> --format json
|
|
318
355
|
context run align:file:<source-name>:architecture --stage --input <structure.yaml> --format json
|
|
319
356
|
```
|
|
@@ -321,17 +358,19 @@ context run align:file:<source-name>:architecture --stage --input <structure.yam
|
|
|
321
358
|
`--validate`, `--stage`, `--confirm`, and `--repair` are mutually exclusive
|
|
322
359
|
operations. An `--input` without an operation is rejected unless the selected
|
|
323
360
|
view explicitly consumes that input. Successful validation returns a stage
|
|
324
|
-
command with the same file path. JSON run output keeps `next_action` first
|
|
325
|
-
|
|
326
|
-
full phase
|
|
361
|
+
command with the same file path. JSON run output keeps `next_action` first;
|
|
362
|
+
schema and full reports stay behind explicit Views, while `--verbose` restores
|
|
363
|
+
the full phase result and repeated contracts. Long diagnostics return a compact
|
|
364
|
+
first page plus an exact diagnostics continuation command.
|
|
327
365
|
|
|
328
366
|
Align and compile evidence results include `semantic_rules`. Its `required`
|
|
329
367
|
array is the rule subset selected for the current judgment, with a selection
|
|
330
368
|
reason and content digest for each rule. `handle`, `digest`, and
|
|
331
369
|
`rules_version` are stable cache checks: reuse a loaded ruleset only while its
|
|
332
370
|
content remains in the active context and both handle and digest still match.
|
|
333
|
-
After context compaction,
|
|
334
|
-
does not imply that the rule text is
|
|
371
|
+
After context compaction, resume the paginated `semantic-rules` View for the
|
|
372
|
+
returned required subset; a handle alone does not imply that the rule text is
|
|
373
|
+
still available.
|
|
335
374
|
|
|
336
375
|
Document evidence boundaries are deterministic rather than semantic.
|
|
337
376
|
`source-index` and `chunks` mark Markdown AST blocks with
|
|
@@ -342,15 +381,24 @@ ranges are never structure boundaries. Structure validation blocks repeated
|
|
|
342
381
|
fixed-width line grids that cut through AST blocks and reports sections that
|
|
343
382
|
cross multiple heading paths, without classifying document topics.
|
|
344
383
|
|
|
345
|
-
|
|
346
|
-
`span-
|
|
347
|
-
|
|
348
|
-
|
|
384
|
+
After capture, the capture phase itself exposes collection-neutral `read-plan`,
|
|
385
|
+
`source-index`, `span-detail`, `span-text`, and other read-only evidence views.
|
|
386
|
+
Status reports `captured-ready-to-classify` until every captured target has an
|
|
387
|
+
evidence-backed, user-confirmed align declaration. Align then adds `schema` and
|
|
388
|
+
`structure-summary` for structure work. Agents should not inspect `sources/` or
|
|
389
|
+
`.tmp` directly.
|
|
390
|
+
|
|
391
|
+
Compile `read-plan`, `blockers`, `node-context`, and `schema` Views are also
|
|
392
|
+
workspace-read-only and may run concurrently. `--validate`, `--stage`,
|
|
393
|
+
structure confirmation, Review apply, and close are serial mutations.
|
|
349
394
|
|
|
350
395
|
Structure payloads use `schema_version: "context.structure.v1"` and canonical
|
|
351
396
|
`file:` / `lark:` `#span` source refs. A one-file-to-one-page plan is represented
|
|
352
397
|
as ordinary `nodes[]` and `views[]` in the structure. It does not bypass
|
|
353
|
-
structure confirmation or compile.
|
|
398
|
+
structure confirmation or compile. Continuity applies to each Section, while one View/Page may
|
|
399
|
+
contain multiple independently retrievable continuous Sections. The optional
|
|
400
|
+
`suggested-splits` repair can expand a broad cross-heading Section into Markdown
|
|
401
|
+
structural groups without creating child Views.
|
|
354
402
|
|
|
355
403
|
### `compileProse`
|
|
356
404
|
|
|
@@ -390,10 +438,11 @@ context run compile:file:<source-name>:architecture --stage --input <compile-act
|
|
|
390
438
|
```
|
|
391
439
|
|
|
392
440
|
Compile remains one View per write for evidence isolation. After staging, follow
|
|
393
|
-
`continue_compile_batch` to prepare the next View.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
441
|
+
`continue_compile_batch` to prepare the next View. Each canonical source plus
|
|
442
|
+
collection is confirmed as an independent structure slot. When other captured
|
|
443
|
+
align targets remain pending, status routes to those slots before opening one
|
|
444
|
+
collection-level Review payload. `context close` is blocked while a planned
|
|
445
|
+
View is unprepared, still draft, or rejected without a structure revision.
|
|
397
446
|
|
|
398
447
|
Compile action payloads use `schema_version: "context.compile-actions.v1"`.
|
|
399
448
|
By default, actions should omit body content and let the CLI mirror cited source
|
|
@@ -544,10 +593,20 @@ review html --all --open --format json`, confirm the returned `opened` field,
|
|
|
544
593
|
and wait for the user-copied payload. They should not run the phase as an
|
|
545
594
|
automatic approval step or synthesize a payload themselves.
|
|
546
595
|
|
|
547
|
-
The
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
596
|
+
The only batch-wide exception is explicit current-conversation fully managed
|
|
597
|
+
authority. In that mode, follow the `context status --managed` route to
|
|
598
|
+
`context review approve-all ... --managed`; the CLI validates the exact current
|
|
599
|
+
scope before applying one default-approved decision.
|
|
600
|
+
|
|
601
|
+
The gate is batch-scoped: prose waits for every planned View across all active
|
|
602
|
+
structure slots and every declared `pendingStructureTargets` item in the round;
|
|
603
|
+
codegraph waits for every pending extract phase in the confirmed module round.
|
|
604
|
+
Candidate count/hash therefore describes the complete current batch rather than
|
|
605
|
+
one page, source slot, or module. Deterministic close later merges all active
|
|
606
|
+
slots into `knowledge/structure.yaml`.
|
|
607
|
+
|
|
608
|
+
`status.structureBatch` lists unclassified, configuration-required, pending,
|
|
609
|
+
and active structure slots together with the execution policy for the round.
|
|
551
610
|
|
|
552
611
|
If the user explicitly asks for an automated or quick approval/rejection path,
|
|
553
612
|
use the scoped quick commands instead of hand-writing a payload:
|
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"
|
|
@@ -19,9 +19,11 @@ product-specific skills or routing rules.
|
|
|
19
19
|
Selected OKF root directories such as `wikis/`, `guides/`, `rules/`, and
|
|
20
20
|
`feats/` follow the C4A OKF Profile: OKF fields and C4A extension fields stay
|
|
21
21
|
at the top level, and no `context` or `schema` field is emitted. Root mapping:
|
|
22
|
-
`wikis/` maps from
|
|
23
|
-
`
|
|
24
|
-
`
|
|
22
|
+
`wikis/` maps from structured `codegraph`, `business`, and `product` knowledge;
|
|
23
|
+
`guides/` maps from `architecture`, `sop`, `faq`, `decision`, and `incident`;
|
|
24
|
+
`rules/` maps from `standards` and `test`; `feats/` maps from `feats`. Treat
|
|
25
|
+
`wikis/` as the entity-and-relationship layer; guides and rules may explain or
|
|
26
|
+
constrain that layer. Customize
|
|
25
27
|
`wikis/index.md` before build to describe the package scope and query guidance;
|
|
26
28
|
other selected OKF root indexes are generated unless this template supplies
|
|
27
29
|
them.
|
|
@@ -49,8 +49,9 @@ beyond the packaged content.
|
|
|
49
49
|
| User intent | First move | Evidence move |
|
|
50
50
|
|---|---|---|
|
|
51
51
|
| Vague topic or unknown name | Open the package's OKF root index, usually `wikis/index.md`, then child indexes such as `wikis/<group>/index.md`. If the package includes other selected OKF roots such as `guides/` or `rules/`, use their indexes too. | Choose candidate pages by title, path, frontmatter, and index grouping. |
|
|
52
|
-
|
|
|
53
|
-
|
|
|
52
|
+
| Architecture, procedure, FAQ, decision, incident, or troubleshooting question | Start from `guides/index.md` when present. These pages are mapped from internal `architecture`, `sop`, `faq`, `decision`, and `incident` collections. | Use guide pages for explanations, design narratives, decisions, steps, operational context, and troubleshooting; cite the relevant sections. |
|
|
53
|
+
| Structured product or business question | Start from `wikis/index.md`, then the `product` or `business` group index. | Use entity pages and typed relationships to establish scope before reading supporting narratives. |
|
|
54
|
+
| Standard, constraint, acceptance, or test scenario question | Start from `rules/index.md` when present. These pages are mapped from internal `standards` and `test` collections. | Use rule pages for normative constraints, acceptance criteria, and validation scenarios. |
|
|
54
55
|
| Specific entity/domain/action named | Open the matching page or nearest group index. | Read the page sections and source metadata. |
|
|
55
56
|
| Relationship or impact question | Check `context-build-inventory.json` `structure.edge_records`, then related endpoint pages. | Cite typed edge evidence if available; otherwise cite page sections and mark relation gaps. |
|
|
56
57
|
| Detail within a known page | Read that page's relevant `context:section` block. | Cite the section id/source_ref and quote or summarize only supported text. |
|
|
@@ -185,10 +186,13 @@ the user it is false; distinguish "not evidenced here" from "not true."
|
|
|
185
186
|
|
|
186
187
|
- The bundled OKF root directories, usually including `wikis/`, are the source
|
|
187
188
|
of truth for this skill.
|
|
188
|
-
- OKF root mapping: `wikis/` maps from
|
|
189
|
-
|
|
190
|
-
`incident`; `rules/` maps from `
|
|
191
|
-
maps from `feats`.
|
|
189
|
+
- OKF root mapping: `wikis/` maps from the structured `codegraph`, `business`,
|
|
190
|
+
and `product` collections; `guides/` maps from `architecture`, `sop`, `faq`,
|
|
191
|
+
`decision`, and `incident`; `rules/` maps from `standards` and `test`;
|
|
192
|
+
`feats/` maps from `feats`.
|
|
193
|
+
- Treat `wikis/` as the primary entity-and-relationship layer. Guides and rules
|
|
194
|
+
may explain, operationalize, or constrain that structured knowledge, but
|
|
195
|
+
directory co-location alone is not relationship evidence.
|
|
192
196
|
- Bundled OKF root directories follow the C4A OKF Profile.
|
|
193
197
|
- Prefer OKF indexes, `context-build-inventory.json`, package manifests when
|
|
194
198
|
present, build inventory, and page source span metadata over raw text search.
|