@vinsonw2/asset-compound 0.0.0-stage → 0.1.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.
@@ -0,0 +1,88 @@
1
+ export type SourceType = "requirement" | "design" | "ai-artifact" | "git";
2
+ export type ChangeKind = "新增" | "增量" | "未变";
3
+ export interface SourceSet {
4
+ type: SourceType;
5
+ include?: string[];
6
+ maxCommits?: number;
7
+ }
8
+ export interface RunConfig {
9
+ outputRoot: "docs/可读化";
10
+ baseBranch?: string;
11
+ sourceSets: SourceSet[];
12
+ exclude?: string[];
13
+ }
14
+ export interface DimensionFinding {
15
+ level: "ready" | "partial" | "missing" | "conflict" | "high" | "medium" | "low";
16
+ evidence: string[];
17
+ gaps: string[];
18
+ recommendations: string[];
19
+ }
20
+ export interface AssetRecord {
21
+ assetId: string;
22
+ sourceType: SourceType;
23
+ sourceRef: string;
24
+ sourceRevision: string;
25
+ contentHash: string;
26
+ title: string;
27
+ summary: string;
28
+ facts: string[];
29
+ decisions: string[];
30
+ actions: string[];
31
+ relations: string[];
32
+ analysis: {
33
+ completeness: DimensionFinding;
34
+ executability: DimensionFinding;
35
+ consistency: DimensionFinding;
36
+ reuseValue: DimensionFinding;
37
+ };
38
+ writebackKind: ChangeKind;
39
+ }
40
+ export interface SourceState {
41
+ contentHash: string;
42
+ sourceRevision: string;
43
+ assetIds: string[];
44
+ status: "active" | "stale";
45
+ }
46
+ export interface AssetState {
47
+ canonicalContentHash: string;
48
+ outputPath: string;
49
+ lastGeneratedHash: string;
50
+ }
51
+ export interface ReadState {
52
+ schemaVersion: 1;
53
+ selfHash: string;
54
+ baseBranch: string;
55
+ baseCommit: string;
56
+ lastReadCommit: string;
57
+ sources: Record<string, SourceState>;
58
+ assets: Record<string, AssetState>;
59
+ managedFiles: Record<string, string>;
60
+ }
61
+ export interface ScanRecord {
62
+ sourceType: SourceType;
63
+ sourceRef: string;
64
+ sourceRevision: string;
65
+ contentHash: string;
66
+ content: string;
67
+ }
68
+ export interface Conflict {
69
+ assetId: string;
70
+ path: string;
71
+ reason: string;
72
+ expectedHash?: string;
73
+ actualHash?: string;
74
+ }
75
+ export interface PipelineResult {
76
+ runId: string;
77
+ counts: {
78
+ new: number;
79
+ updated: number;
80
+ unchanged: number;
81
+ conflicts: number;
82
+ };
83
+ assets: AssetRecord[];
84
+ conflicts: Conflict[];
85
+ changedFiles: string[];
86
+ noOp: boolean;
87
+ secondRunZeroDiff?: boolean;
88
+ }
package/package.json CHANGED
@@ -1,6 +1,83 @@
1
1
  {
2
2
  "name": "@vinsonw2/asset-compound",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Editor-neutral CLI and protocol for incremental, traceable documentation assets",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/types/index.d.ts",
8
+ "engines": {
9
+ "node": ">=20"
10
+ },
11
+ "bin": {
12
+ "asset-compound": "./dist/cli.js"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "schemas",
17
+ "templates",
18
+ "prompts",
19
+ "protocol",
20
+ "skill",
21
+ "artifacts"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/types/index.d.ts",
26
+ "import": "./dist/index.js"
27
+ },
28
+ "./schemas/*": "./schemas/*",
29
+ "./templates/*": "./templates/*",
30
+ "./prompts/*": "./prompts/*",
31
+ "./protocol/*": "./protocol/*",
32
+ "./cursor-skill": "./skill/asset-compounding/SKILL.md",
33
+ "./package.json": "./package.json"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup && tsc -p tsconfig.build.json",
37
+ "dev": "tsx src/cli.ts",
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "vitest run",
40
+ "test:watch": "vitest",
41
+ "smoke": "node scripts/smoke.mjs",
42
+ "smoke:packed": "node scripts/packed-smoke.mjs",
43
+ "check": "npm run typecheck && npm run test && npm run build",
44
+ "prepack": "npm run check"
45
+ },
46
+ "keywords": [
47
+ "ai-editor",
48
+ "documentation",
49
+ "incremental",
50
+ "knowledge-management",
51
+ "cli"
52
+ ],
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/vinsonw/ai.git"
56
+ },
57
+ "homepage": "https://github.com/vinsonw/ai#readme",
58
+ "bugs": {
59
+ "url": "https://github.com/vinsonw/ai/issues"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public",
63
+ "registry": "https://registry.npmjs.org/"
64
+ },
65
+ "license": "MIT",
66
+ "packageManager": "pnpm@10.33.4",
67
+ "dependencies": {
68
+ "ajv": "^8.20.0",
69
+ "ajv-formats": "^3.0.1",
70
+ "commander": "^15.1.0",
71
+ "fast-glob": "^3.3.3",
72
+ "write-file-atomic": "^8.0.0",
73
+ "yaml": "^2.9.1"
74
+ },
75
+ "devDependencies": {
76
+ "@types/node": "^26.6.6",
77
+ "@types/write-file-atomic": "^4.0.3",
78
+ "tsup": "^9.0.0",
79
+ "tsx": "^4.23.15",
80
+ "typescript": "^7.0.2",
81
+ "vitest": "^5.1.0"
82
+ }
83
+ }
@@ -0,0 +1,59 @@
1
+ # 资产复利四维分析提示协议
2
+
3
+ 你正在分析真实项目材料。输入文件是 `asset-compound prepare` 生成的 JSON 数组,输出必须仍是 JSON 数组,并通过随包提供的 `schemas/analysis-output.schema.json`。
4
+
5
+ ## 不可修改字段
6
+
7
+ 每条记录的以下字段是确定性来源契约,禁止修改:
8
+
9
+ - `assetId`
10
+ - `sourceType`
11
+ - `sourceRef`
12
+ - `sourceRevision`
13
+ - `contentHash`
14
+ - `writebackKind`
15
+
16
+ 禁止增加、删除或复制数组元素。每个来源必须恰好对应一条资产。
17
+
18
+ ## 可以增强的字段
19
+
20
+ - `title`
21
+ - `summary`
22
+ - `facts`
23
+ - `decisions`
24
+ - `actions`
25
+ - `relations`
26
+ - `analysis`
27
+
28
+ ## 四维分析
29
+
30
+ 对每条资产分别填写:
31
+
32
+ 1. `analysis.completeness`:完整性。材料是否覆盖目标、范围、约束、边界、异常和验收条件。
33
+ 2. `analysis.executability`:可执行性。是否有明确行动、负责人、前置条件、完成定义和验证办法。
34
+ 3. `analysis.consistency`:一致性。与其他需求、设计、AI 产物和 Git 决策是否相容。
35
+ 4. `analysis.reuseValue`:复用价值。是否可沉淀为检查表、模板、规则、ADR 或后续任务输入。
36
+
37
+ 每个维度必须包含:
38
+
39
+ - `level`
40
+ - `evidence`
41
+ - `gaps`
42
+ - `recommendations`
43
+
44
+ `level` 的稳定枚举是:
45
+
46
+ - `ready`
47
+ - `partial`
48
+ - `missing`
49
+ - `conflict`
50
+ - `high`
51
+ - `medium`
52
+ - `low`
53
+
54
+ ## 安全要求
55
+
56
+ - 不得写入密钥、令牌、邮箱或未经授权的私有标识。
57
+ - 不得编造来源中不存在的事实。
58
+ - 不确定内容必须放入 `gaps` 或 `recommendations`,不能伪装为已确认结论。
59
+ - 最终只输出 JSON,不添加 Markdown 代码围栏或解释文字。
@@ -0,0 +1,49 @@
1
+ # 编辑器无关资产复利协议
2
+
3
+ 本协议不假设存在统一的 AI 编辑器 Skill 标准。任何能够读取和编辑文件的 AI 工具,都可以按下列文件契约参与。
4
+
5
+ ## 角色分工
6
+
7
+ - `asset-compound`:确定性扫描、hash、增量 state、schema 校验、安全回写。
8
+ - AI 编辑器:在禁止修改来源契约字段的前提下,补充语义资产和四维分析。
9
+ - 人工验收者:确认真实来源范围、结论质量、冲突、分支和证据。
10
+
11
+ ## 文件流
12
+
13
+ 1. 用户在目标仓库之外保存 `run.yaml`。
14
+ 2. `asset-compound prepare ... > prepared.json` 生成 AI 输入。
15
+ 3. AI 按 `asset-analysis.zh-CN.md` 将结果写为 `enriched.json`。
16
+ 4. `asset-compound validate --input enriched.json` 做独立 schema 校验。
17
+ 5. `asset-compound finalize ... --assets enriched.json` 再核对当前扫描的 provenance,并只写 `docs/可读化/**`。
18
+ 6. `asset-compound verify --repo ... --config ...` 证明无变化二次运行。
19
+
20
+ ## 初始化目录
21
+
22
+ `npx @vinsonw2/asset-compound init --output <目录>` 会生成:
23
+
24
+ ```text
25
+ <目录>/
26
+ ├── README.md
27
+ ├── run.yaml
28
+ ├── prompts/
29
+ │ └── asset-analysis.zh-CN.md
30
+ ├── protocol/
31
+ │ └── README.zh-CN.md
32
+ └── schemas/
33
+ ├── analysis-input.schema.json
34
+ └── analysis-output.schema.json
35
+ ```
36
+
37
+ 该目录应位于目标仓库之外。若必须放入目标仓库,应先提交为受控配置;否则 CLI 的工作树边界检查会拒绝写入。
38
+
39
+ ## 稳定契约
40
+
41
+ 命令名、JSON 字段和枚举保持英文。中文提示只负责解释,不得改名。完整字段以 `schemas/*.json` 为准。
42
+
43
+ ## 验收边界
44
+
45
+ - 至少两种不同、真实、非空的来源类型。
46
+ - 示例和 fixture 不能作为真实验收数据。
47
+ - AI 输出必须经过 `validate`。
48
+ - CLI 输出仅允许位于 `docs/可读化/**`。
49
+ - 二次运行必须输出 `secondRunZeroDiff: true`。
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://asset-compound.dev/schemas/analysis-input.schema.json",
4
+ "title": "Four-dimension analysis input",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "sourceType",
9
+ "sourceRef",
10
+ "sourceRevision",
11
+ "contentHash",
12
+ "content"
13
+ ],
14
+ "properties": {
15
+ "sourceType": {
16
+ "enum": ["requirement", "design", "ai-artifact", "git"]
17
+ },
18
+ "sourceRef": {
19
+ "type": "string",
20
+ "minLength": 1
21
+ },
22
+ "sourceRevision": {
23
+ "type": "string",
24
+ "minLength": 1
25
+ },
26
+ "contentHash": {
27
+ "type": "string",
28
+ "pattern": "^sha256:[a-f0-9]{64}$"
29
+ },
30
+ "content": {
31
+ "type": "string"
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,117 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://asset-compound.dev/schemas/analysis-output.schema.json",
4
+ "title": "Structured asset with four-dimension analysis",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": [
8
+ "assetId",
9
+ "sourceType",
10
+ "sourceRef",
11
+ "sourceRevision",
12
+ "contentHash",
13
+ "title",
14
+ "summary",
15
+ "facts",
16
+ "decisions",
17
+ "actions",
18
+ "relations",
19
+ "analysis",
20
+ "writebackKind"
21
+ ],
22
+ "properties": {
23
+ "assetId": {
24
+ "type": "string",
25
+ "pattern": "^sha256:[a-f0-9]{64}$"
26
+ },
27
+ "sourceType": {
28
+ "enum": ["requirement", "design", "ai-artifact", "git"]
29
+ },
30
+ "sourceRef": {
31
+ "type": "string",
32
+ "minLength": 1
33
+ },
34
+ "sourceRevision": {
35
+ "type": "string",
36
+ "minLength": 1
37
+ },
38
+ "contentHash": {
39
+ "type": "string",
40
+ "pattern": "^sha256:[a-f0-9]{64}$"
41
+ },
42
+ "title": {
43
+ "type": "string",
44
+ "minLength": 1
45
+ },
46
+ "summary": {
47
+ "type": "string"
48
+ },
49
+ "facts": {
50
+ "type": "array",
51
+ "items": {"type": "string"}
52
+ },
53
+ "decisions": {
54
+ "type": "array",
55
+ "items": {"type": "string"}
56
+ },
57
+ "actions": {
58
+ "type": "array",
59
+ "items": {"type": "string"}
60
+ },
61
+ "relations": {
62
+ "type": "array",
63
+ "items": {"type": "string"}
64
+ },
65
+ "analysis": {
66
+ "type": "object",
67
+ "additionalProperties": false,
68
+ "required": [
69
+ "completeness",
70
+ "executability",
71
+ "consistency",
72
+ "reuseValue"
73
+ ],
74
+ "properties": {
75
+ "completeness": {"$ref": "#/$defs/dimension"},
76
+ "executability": {"$ref": "#/$defs/dimension"},
77
+ "consistency": {"$ref": "#/$defs/dimension"},
78
+ "reuseValue": {"$ref": "#/$defs/dimension"}
79
+ }
80
+ },
81
+ "writebackKind": {
82
+ "enum": ["新增", "增量", "未变"]
83
+ }
84
+ },
85
+ "$defs": {
86
+ "dimension": {
87
+ "type": "object",
88
+ "additionalProperties": false,
89
+ "required": ["level", "evidence", "gaps", "recommendations"],
90
+ "properties": {
91
+ "level": {
92
+ "enum": [
93
+ "ready",
94
+ "partial",
95
+ "missing",
96
+ "conflict",
97
+ "high",
98
+ "medium",
99
+ "low"
100
+ ]
101
+ },
102
+ "evidence": {
103
+ "type": "array",
104
+ "items": {"type": "string"}
105
+ },
106
+ "gaps": {
107
+ "type": "array",
108
+ "items": {"type": "string"}
109
+ },
110
+ "recommendations": {
111
+ "type": "array",
112
+ "items": {"type": "string"}
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
@@ -0,0 +1,90 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://asset-compound.dev/schemas/read-state.schema.json",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": [
7
+ "schemaVersion",
8
+ "selfHash",
9
+ "baseBranch",
10
+ "baseCommit",
11
+ "lastReadCommit",
12
+ "sources",
13
+ "assets",
14
+ "managedFiles"
15
+ ],
16
+ "properties": {
17
+ "schemaVersion": {"const": 1},
18
+ "selfHash": {
19
+ "type": "string",
20
+ "pattern": "^sha256:[a-f0-9]{64}$"
21
+ },
22
+ "baseBranch": {"type": "string"},
23
+ "baseCommit": {"type": "string"},
24
+ "lastReadCommit": {"type": "string"},
25
+ "sources": {
26
+ "type": "object",
27
+ "additionalProperties": {
28
+ "type": "object",
29
+ "additionalProperties": false,
30
+ "required": [
31
+ "contentHash",
32
+ "sourceRevision",
33
+ "assetIds",
34
+ "status"
35
+ ],
36
+ "properties": {
37
+ "contentHash": {
38
+ "type": "string",
39
+ "pattern": "^sha256:[a-f0-9]{64}$"
40
+ },
41
+ "sourceRevision": {"type": "string"},
42
+ "assetIds": {
43
+ "type": "array",
44
+ "items": {
45
+ "type": "string",
46
+ "pattern": "^sha256:[a-f0-9]{64}$"
47
+ }
48
+ },
49
+ "status": {"enum": ["active", "stale"]}
50
+ }
51
+ }
52
+ },
53
+ "assets": {
54
+ "type": "object",
55
+ "additionalProperties": {
56
+ "type": "object",
57
+ "additionalProperties": false,
58
+ "required": [
59
+ "canonicalContentHash",
60
+ "outputPath",
61
+ "lastGeneratedHash"
62
+ ],
63
+ "properties": {
64
+ "canonicalContentHash": {
65
+ "type": "string",
66
+ "pattern": "^sha256:[a-f0-9]{64}$"
67
+ },
68
+ "outputPath": {
69
+ "type": "string",
70
+ "pattern": "^(?!.*(?:^|/)\\.\\.(?:/|$))docs/可读化/.+$"
71
+ },
72
+ "lastGeneratedHash": {
73
+ "type": "string",
74
+ "pattern": "^sha256:[a-f0-9]{64}$"
75
+ }
76
+ }
77
+ }
78
+ },
79
+ "managedFiles": {
80
+ "type": "object",
81
+ "propertyNames": {
82
+ "pattern": "^(?!.*(?:^|/)\\.\\.(?:/|$))docs/可读化/.+$"
83
+ },
84
+ "additionalProperties": {
85
+ "type": "string",
86
+ "pattern": "^sha256:[a-f0-9]{64}$"
87
+ }
88
+ }
89
+ }
90
+ }
@@ -0,0 +1,65 @@
1
+ ---
2
+ name: asset-compounding
3
+ description: 读取至少两类真实来源,提取可追溯资产,执行四维分析,并仅向 docs/可读化 增量回写。
4
+ ---
5
+
6
+ # 资产复利
7
+
8
+ 这是 `@vinsonw2/asset-compound` npm 包的**可选 Cursor 适配器**。核心 CLI、schema、templates、prompts 和通用 protocol 不依赖 Cursor。任意 AI 编辑器应使用 `npx @vinsonw2/asset-compound init` 生成的编辑器无关文件协议;本项目不假装存在跨编辑器统一 Skill 标准。
9
+
10
+ 当 Cursor 中的真实项目需要把需求、设计、AI 产物和 Git 历史沉淀为可复用、可增量、可审计的文档资产时,使用此适配器。
11
+
12
+ ## 前置条件
13
+
14
+ 1. 确认目标仓库、基线分支和允许读取的来源 glob。
15
+ 2. 至少提供两种不同类型、真实、非空且有业务意义的来源;fixture 和空 API 不能作为验收数据。
16
+ 3. CLI 工具包必须放在目标仓库之外。
17
+ 4. 任何写入前,必须从当前基线创建独立分支。
18
+
19
+ ## 执行流程
20
+
21
+ 1. 运行 `npx @vinsonw2/asset-compound plan --repo <仓库> --config <run.yaml>`。
22
+ 2. 运行 `npx @vinsonw2/asset-compound scan`,检查每个来源路径和 revision。
23
+ 3. 运行 `npx @vinsonw2/asset-compound prepare ... > prepared.json`。需要业务判断时补充严格 JSON;不得修改 ID、hash 和来源追踪字段。
24
+ 4. 确保每条资产分别包含完整性、可执行性、一致性、复用价值四项结论,每项均有证据、缺口和建议。
25
+ 5. 运行 `npx @vinsonw2/asset-compound validate --input enriched.json`。预览写入集合;只有全部路径都位于 `docs/可读化/**` 时,才运行 `npx @vinsonw2/asset-compound render ... --assets enriched.json`。
26
+ 6. 运行 `npx @vinsonw2/asset-compound verify --repo <仓库> --config <run.yaml>`,保存其中的 `secondRunZeroDiff` JSON 作为 V6 证据。
27
+ 7. 运行 `npx @vinsonw2/asset-compound finalize`,保存验收报告。
28
+ 8. 在独立分支提交;禁止直接推送基线分支。
29
+ 9. 使用完全相同的输入执行第二次运行,要求业务产物零 diff,且 `new=0 updated=0`。
30
+ 10. 如需证明受控增量,只能使用一份已批准的真实来源变更,并证明仅对应资产发生增量。
31
+
32
+ ## 安全规则
33
+
34
+ - 禁止修改应用源码、包清单、原始需求/设计/AI 材料,以及 `docs/可读化/**` 之外的路径。
35
+ - 当前文件 hash 与 state 不一致时,禁止静默覆盖;必须保留原文件并生成冲突报告。
36
+ - schema 校验失败或检测到越界写入后,禁止推进 state。
37
+ - 模型输出属于不可信输入,只有通过随包提供的 JSON Schema 后才能渲染。
38
+ - 增量身份必须使用来源内容 hash,禁止使用模型摘要。
39
+ - Markdown 和截图必须移除密钥、令牌、邮箱等隐私标识。
40
+
41
+ ## 稳定契约中英映射
42
+
43
+ 代码标识符、命令名和 JSON/schema 字段保持英文,以保障自动化兼容:
44
+
45
+ | 稳定字段 | 中文含义 |
46
+ |---|---|
47
+ | `sourceType` / `sourceRef` / `sourceRevision` | 来源类型 / 来源定位 / 来源版本 |
48
+ | `contentHash` / `assetId` | 内容指纹 / 稳定资产 ID |
49
+ | `analysis.completeness` | 完整性 |
50
+ | `analysis.executability` | 可执行性 |
51
+ | `analysis.consistency` | 一致性 |
52
+ | `analysis.reuseValue` | 复用价值 |
53
+ | `writebackKind` | 回写标记 |
54
+ | `new` / `updated` / `unchanged` / `conflicts` | 新增 / 增量 / 未变 / 冲突 |
55
+ | `secondRunZeroDiff` | 第二次运行业务产物零差异 |
56
+
57
+ ## 必备证据
58
+
59
+ - 至少两类真实非空来源的来源清单。
60
+ - 结构化资产与完整的四维分析。
61
+ - 独立分支、提交记录和路径边界验证。
62
+ - state 前后版本、稳定 ID、hash 和 Git revision。
63
+ - 冲突报告;无冲突时也必须明确记录“0 个冲突”。
64
+ - 首次运行结果与无变化二次运行结果。
65
+ - 覆盖 R1–R6 和 V1–V8 的验收报告。
@@ -0,0 +1,23 @@
1
+ # 资产复利验收报告
2
+
3
+ - 运行 ID:`{{run_id}}`
4
+ - 分支:`{{branch}}`
5
+ - 基线提交 / 当前提交:`{{base_sha}}` / `{{head_sha}}`
6
+ - 来源:{{source_type_summary}}
7
+ - 统计:新增 {{new_count}},增量 {{updated_count}},未变 {{unchanged_count}},冲突 {{conflict_count}}
8
+
9
+ ## R1–R6
10
+
11
+ {{requirements_matrix}}
12
+
13
+ ## V1–V8
14
+
15
+ {{verification_matrix}}
16
+
17
+ ## 四维结论摘要
18
+
19
+ {{four_dimension_summary}}
20
+
21
+ ## 冲突与证据
22
+
23
+ {{conflict_and_evidence_links}}
@@ -0,0 +1,8 @@
1
+ # 冲突报告
2
+
3
+ - 运行 ID:`{{run_id}}`
4
+ - 冲突数:{{conflict_count}}
5
+
6
+ {{conflicts}}
7
+
8
+ > 冲突必须透明记录;禁止静默覆盖人工编辑或来源歧义。