@getvda/governance-schema 0.2.0

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 ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,30 @@
1
+ Verified Digital Agents (VDA) — Agent Control Plane
2
+ Copyright 2026 getvda.ai
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use these files except in compliance with the License. A copy of the
6
+ License is in the LICENSE file at the repository root and at:
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software distributed
11
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
+ CONDITIONS OF ANY KIND, either express or implied.
13
+
14
+ ---
15
+
16
+ What these packages do and do NOT carry
17
+ ----------------------------------------
18
+
19
+ The @getvda/* packages VERIFY and ENFORCE governance. They do not carry the
20
+ trust anchors that governance rests on:
21
+
22
+ - Bundle-signing keys (#key-3) live only in getvda's Secret Manager. These
23
+ packages VERIFY a bundle's signature against the public key resolved from
24
+ did:web:acp.getvda.ai; they cannot mint a bundle that verifies.
25
+ - Witness account credentials are the customer's own (customer-managed
26
+ custody). These packages SEAL to a Witness account the caller supplies;
27
+ they carry no standing credential.
28
+
29
+ The code is open. The trust anchors are not in the code — and giving away the
30
+ verifier does not give away the ability to forge what it verifies.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # @getvda/governance-schema
2
+
3
+ > **Status: pre-1.0 (0.x).** Public API may change between minor versions —
4
+ > pin an exact version if you need stability. Part of the [getvda.ai](https://getvda.ai)
5
+ > governance suite. Honesty discipline: nothing documented here is live unless it
6
+ > says so, boundaries (fail-static, condition-assertion) are stated where they apply,
7
+ > and a stub is labelled a stub.
8
+
9
+ > **What this carries — and what it does not.** This package *verifies and
10
+ > enforces* governance. The trust anchors are not in it: bundle-signing keys
11
+ > (`#key-3`) live only in getvda's Secret Manager, and Witness account
12
+ > credentials are the caller's own (customer-managed custody). It verifies a
13
+ > signature against the public key resolved from `did:web:acp.getvda.ai` and
14
+ > seals to a Witness account you supply — it cannot mint a bundle that verifies,
15
+ > and carries no standing credential. Open code, trust anchors elsewhere.
16
+
17
+ The **shared governance-file schema contract** — the C2MD ⇄ ACP interface
18
+ (Phase 1a). C2MD generates governance v1 (genesis); ACP owns the lifecycle from
19
+ there. This package is the versioned, first-class artifact both agree on
20
+ (design brief §7).
21
+
22
+ ## VDA-MD governance files
23
+
24
+ C2MD emits markdown + YAML-frontmatter files in the **VDA-MD v4.1** format:
25
+
26
+ | File | Contains | Required |
27
+ | -------------- | ------------------------------------------------------------------- | ----------- |
28
+ | `AGENTS.md` | identity, scope, **RACI** | yes |
29
+ | `SOP.md` | **MUST / MUST NOT / MAY** clauses + clause-level citations | yes |
30
+ | `SKILL.md` | permitted **capabilities with conditions** (the brief's "ceilings") | yes |
31
+ | `EXCEPTION.md` | exceptions, **where warranted** | conditional |
32
+
33
+ Citations reference NIST SP 800-53 Rev 5 · ISO/IEC 42001:2023 · EU AI Act
34
+ (EU) 2024/1689 · GDPR (EU) 2016/679 · APQC PCF v7.4.
35
+
36
+ ## Confidence tiers — nothing invented is presented as confirmed
37
+
38
+ Everything in this contract is one of:
39
+
40
+ - **CONFIRMED** — read directly from C2MD's live agent card, 2026-07-18. The
41
+ validator enforces these strictly (taxonomy, RACI on AGENTS.md, SOP carries
42
+ normative clauses, well-formed frontmatter).
43
+ - **PROVISIONAL** — a proposed shape for parts not publicly observable (exact
44
+ frontmatter fields, capability-condition serialization, literal citation
45
+ syntax). Validated leniently (warnings, never failures) so a real C2MD file is
46
+ never wrongly rejected.
47
+
48
+ The provisional parts and the **C2MD change request** to lock them are in
49
+ [`docs/OPEN-QUESTIONS.md`](docs/OPEN-QUESTIONS.md). This honours the brief's rule:
50
+ _design to what C2MD already emits; document genuine mismatches as change
51
+ requests rather than silently diverging._
52
+
53
+ ## API
54
+
55
+ ```ts
56
+ import {
57
+ validateFile,
58
+ validateSet,
59
+ parseGovernanceFile,
60
+ complianceFingerprint,
61
+ } from '@getvda/governance-schema';
62
+
63
+ validateSet({ 'AGENTS.md': a, 'SOP.md': s, 'SKILL.md': k }); // → { valid, errors, warnings }
64
+ complianceFingerprint(parseGovernanceFile('SOP.md', s)); // → MUST/MUST NOT/MAY counts + citation refs
65
+ ```
66
+
67
+ `complianceFingerprint` is the **seed of the Phase-1 Compliance Guard**: diff a
68
+ file's fingerprint across a change to prove a MUST-clause count wasn't weakened
69
+ and a citation wasn't stripped.
70
+
71
+ ## Artifacts
72
+
73
+ - [`schema/vda-md-frontmatter-0.1.schema.json`](schema/vda-md-frontmatter-0.1.schema.json) — machine-readable frontmatter schema (provisional).
74
+ - [`examples/`](examples) — a valid org-agnostic reference set.
75
+ - [`docs/OPEN-QUESTIONS.md`](docs/OPEN-QUESTIONS.md) — provisional items + C2MD change request.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @getvda/governance-schema — the shared governance-file schema contract (C2MD ⇄ ACP).
3
+ *
4
+ * The versioned, first-class interface between C2MD (genesis) and ACP
5
+ * (lifecycle). RECONCILED against a real v4.1 bundle (2026-07-18): the parser +
6
+ * validator model the actual `## MODALITY`-block clause format with structured
7
+ * `framework_reference` citations and the real frontmatter. Generation-aware
8
+ * (v4.1 taxonomy + legacy inline). See docs/OPEN-QUESTIONS.md.
9
+ */
10
+ export { CONTRACT_VERSION, VDA_MD_VERSION, C2MD_SCHEMA_VERSION, GOVERNANCE_FILE_NAMES, REQUIRED_FILE_NAMES, CONDITIONAL_FILE_NAMES, SOURCE_STANDARDS, FRAMEWORK_KEYS, type FrameworkKey, type GovernanceFileName, } from './version.js';
11
+ export type { Citation, ClauseModality, CommonFrontmatter, ConditionedCapability, NormativeClause, ParsedGovernanceFile, } from './types.js';
12
+ export { parseGovernanceFile, splitFrontmatter, extractCitations, parseFrameworkReference, extractClauses, extractCapabilities, } from './parse.js';
13
+ export { validateFile, validateSet, complianceFingerprint, isGovernanceFileName, type Severity, type ValidationIssue, type ValidationResult, type ComplianceFingerprint, } from './validate.js';
14
+ export { buildGovernanceSet, presentFiles, type GovernanceSet, type GovernanceSetEntry, } from './set.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,kBAAkB,GACxB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC3B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @getvda/governance-schema — the shared governance-file schema contract (C2MD ⇄ ACP).
3
+ *
4
+ * The versioned, first-class interface between C2MD (genesis) and ACP
5
+ * (lifecycle). RECONCILED against a real v4.1 bundle (2026-07-18): the parser +
6
+ * validator model the actual `## MODALITY`-block clause format with structured
7
+ * `framework_reference` citations and the real frontmatter. Generation-aware
8
+ * (v4.1 taxonomy + legacy inline). See docs/OPEN-QUESTIONS.md.
9
+ */
10
+ export { CONTRACT_VERSION, VDA_MD_VERSION, C2MD_SCHEMA_VERSION, GOVERNANCE_FILE_NAMES, REQUIRED_FILE_NAMES, CONDITIONAL_FILE_NAMES, SOURCE_STANDARDS, FRAMEWORK_KEYS, } from './version.js';
11
+ export { parseGovernanceFile, splitFrontmatter, extractCitations, parseFrameworkReference, extractClauses, extractCapabilities, } from './parse.js';
12
+ export { validateFile, validateSet, complianceFingerprint, isGovernanceFileName, } from './validate.js';
13
+ export { buildGovernanceSet, presentFiles, } from './set.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,GAGf,MAAM,cAAc,CAAC;AAWtB,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACd,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,oBAAoB,GAKrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,kBAAkB,EAClB,YAAY,GAGb,MAAM,UAAU,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Parse a VDA-MD governance file into the structured model.
3
+ *
4
+ * Tolerant by design: the parts of the format that are NOT publicly observable
5
+ * (exact frontmatter keys, capability-condition serialization, literal citation
6
+ * syntax) are parsed leniently so a real C2MD file is never rejected for a shape
7
+ * we could not confirm. The CONFIRMED parts (clause modality grammar, RACI
8
+ * presence) are parsed precisely.
9
+ */
10
+ import type { GovernanceFileName } from './version.js';
11
+ import { FRAMEWORK_KEYS } from './version.js';
12
+ import type { Citation, CommonFrontmatter, ConditionedCapability, NormativeClause, ParsedGovernanceFile } from './types.js';
13
+ export declare function splitFrontmatter(source: string): {
14
+ frontmatter: CommonFrontmatter;
15
+ body: string;
16
+ };
17
+ /** Legacy inline extraction (parenthetical / free-text citations). */
18
+ export declare function extractCitations(text: string): Citation[];
19
+ /**
20
+ * Parse a v4.1 structured `framework_reference` into citations. Handles a single
21
+ * framework ("EU AI Act Article 52"), a scoped clause ("GDPR: Art. 5(1)(c)"),
22
+ * a versioned control ("NIST SP 800-53 Rev 5: AU-2"), and MULTIPLE frameworks in
23
+ * one reference joined by ";" ("GDPR: Art. 32; NIST SP 800-53 Rev 5: AU-2").
24
+ */
25
+ export declare function parseFrameworkReference(ref: string): Citation[];
26
+ /**
27
+ * Extract normative clauses — GENERATION-AWARE.
28
+ *
29
+ * v4.1 (C2MD `generate_compliance_bundle`) writes each clause as a `## MUST|MUST
30
+ * NOT|MAY` heading followed by a ```yaml metadata block (`clause_type`,
31
+ * `framework_reference`, `confidence`, …) and prose. That is the primary format.
32
+ * Older / hand-authored files use inline `MODALITY … (citation)` sentences. This
33
+ * detects which convention a file uses and parses it correctly — critically,
34
+ * counting each clause ONCE (the v4.1 format repeats the modality in the heading,
35
+ * the YAML, and the prose, which a naive line scan would triple-count).
36
+ */
37
+ export declare function extractClauses(body: string): NormativeClause[];
38
+ /**
39
+ * Parse conditioned capabilities (SKILL.md). PROVISIONAL: prefers a structured
40
+ * `capabilities` array in frontmatter if present; otherwise reads bullet items
41
+ * under a capabilities-ish heading, treating nested bullets as conditions.
42
+ */
43
+ export declare function extractCapabilities(frontmatter: CommonFrontmatter, body: string): ConditionedCapability[];
44
+ export declare function parseGovernanceFile(name: GovernanceFileName, source: string): ParsedGovernanceFile;
45
+ export { FRAMEWORK_KEYS };
46
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,cAAc,EAAqB,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EACV,QAAQ,EAER,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAIpB,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAejG;AA0BD,sEAAsE;AACtE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAWzD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,EAAE,CAiB/D;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,CAI9D;AAyED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,iBAAiB,EAC9B,IAAI,EAAE,MAAM,GACX,qBAAqB,EAAE,CAiDzB;AAWD,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,MAAM,GACb,oBAAoB,CAUtB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
package/dist/parse.js ADDED
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Parse a VDA-MD governance file into the structured model.
3
+ *
4
+ * Tolerant by design: the parts of the format that are NOT publicly observable
5
+ * (exact frontmatter keys, capability-condition serialization, literal citation
6
+ * syntax) are parsed leniently so a real C2MD file is never rejected for a shape
7
+ * we could not confirm. The CONFIRMED parts (clause modality grammar, RACI
8
+ * presence) are parsed precisely.
9
+ */
10
+ import { parse as parseYaml } from 'yaml';
11
+ import { FRAMEWORK_KEYS } from './version.js';
12
+ const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
13
+ export function splitFrontmatter(source) {
14
+ const match = FRONTMATTER_RE.exec(source);
15
+ if (!match)
16
+ return { frontmatter: {}, body: source };
17
+ let fm = {};
18
+ try {
19
+ const parsed = parseYaml(match[1] ?? '');
20
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
21
+ fm = parsed;
22
+ }
23
+ }
24
+ catch {
25
+ // Malformed YAML is a validation error, surfaced by validate(); here we just
26
+ // return empty frontmatter and let the body parse continue.
27
+ fm = {};
28
+ }
29
+ return { frontmatter: fm, body: source.slice(match[0].length) };
30
+ }
31
+ /**
32
+ * Framework detection patterns. The LITERAL citation syntax is PROVISIONAL, so
33
+ * this recognises the framework by name/id in a few plausible forms and captures
34
+ * the trailing clause id. Tolerant, documented as such.
35
+ */
36
+ const FRAMEWORK_PATTERNS = [
37
+ { key: 'nist', re: /\bNIST(?:\s+SP)?\s*800-53\b[:\s]*([A-Z]{2}-\d+(?:\(\d+\))?)?/gi },
38
+ { key: 'iso', re: /\b(?:ISO(?:\/IEC)?\s*)?42001\b[:\s]*(\d+(?:\.\d+)*)?/gi },
39
+ { key: 'euAiAct', re: /\bEU\s*AI\s*Act\b[:\s]*(Art\.?\s*\d+[a-z]?)?/gi },
40
+ { key: 'gdpr', re: /\bGDPR\b[:\s]*(Art\.?\s*\d+[a-z]?)?/gi },
41
+ { key: 'apqc', re: /\bAPQC(?:\s*PCF)?\b[:\s]*([\d.]+)?/gi },
42
+ ];
43
+ /** Framework name → key, ordered most-specific first. Matches the real v4.1
44
+ * `framework_reference` strings ("EU AI Act Article 52", "NIST SP 800-53 Rev 5:
45
+ * AU-2", "GDPR: Art. 5(1)(c)") AND the legacy inline forms. */
46
+ const FRAMEWORK_NAME_PATTERNS = [
47
+ { key: 'euAiAct', re: /EU\s*AI\s*Act/i },
48
+ { key: 'iso', re: /ISO(?:\/IEC)?\s*42001/i },
49
+ { key: 'nist', re: /NIST(?:\s*SP)?\s*800-53/i },
50
+ { key: 'gdpr', re: /GDPR/i },
51
+ { key: 'apqc', re: /APQC(?:\s*PCF)?/i },
52
+ ];
53
+ /** Legacy inline extraction (parenthetical / free-text citations). */
54
+ export function extractCitations(text) {
55
+ const citations = [];
56
+ for (const { key, re } of FRAMEWORK_PATTERNS) {
57
+ re.lastIndex = 0;
58
+ let m;
59
+ while ((m = re.exec(text)) !== null) {
60
+ citations.push({ framework: key, clause: (m[1] ?? '').trim(), raw: m[0].trim() });
61
+ if (m.index === re.lastIndex)
62
+ re.lastIndex++; // guard against zero-width
63
+ }
64
+ }
65
+ return citations;
66
+ }
67
+ /**
68
+ * Parse a v4.1 structured `framework_reference` into citations. Handles a single
69
+ * framework ("EU AI Act Article 52"), a scoped clause ("GDPR: Art. 5(1)(c)"),
70
+ * a versioned control ("NIST SP 800-53 Rev 5: AU-2"), and MULTIPLE frameworks in
71
+ * one reference joined by ";" ("GDPR: Art. 32; NIST SP 800-53 Rev 5: AU-2").
72
+ */
73
+ export function parseFrameworkReference(ref) {
74
+ const out = [];
75
+ for (const partRaw of ref.split(';')) {
76
+ const part = partRaw.trim();
77
+ if (!part)
78
+ continue;
79
+ const hit = FRAMEWORK_NAME_PATTERNS.find(({ re }) => re.test(part));
80
+ if (!hit)
81
+ continue;
82
+ // clause id = text after the framework name, minus a leading separator and a
83
+ // trailing "Rev N" qualifier.
84
+ const clause = part
85
+ .replace(hit.re, '')
86
+ .replace(/\bRev\s*\d+\b/i, '')
87
+ .replace(/^[\s:.\-—]+/, '')
88
+ .trim();
89
+ out.push({ framework: hit.key, clause, raw: part });
90
+ }
91
+ return out;
92
+ }
93
+ const MODALITIES = ['MUST NOT', 'MUST', 'MAY']; // MUST NOT before MUST
94
+ const CLAUSE_HEADING_RE = /^#{2,3}\s+(MUST NOT|MUST|MAY)\s*$/;
95
+ /**
96
+ * Extract normative clauses — GENERATION-AWARE.
97
+ *
98
+ * v4.1 (C2MD `generate_compliance_bundle`) writes each clause as a `## MUST|MUST
99
+ * NOT|MAY` heading followed by a ```yaml metadata block (`clause_type`,
100
+ * `framework_reference`, `confidence`, …) and prose. That is the primary format.
101
+ * Older / hand-authored files use inline `MODALITY … (citation)` sentences. This
102
+ * detects which convention a file uses and parses it correctly — critically,
103
+ * counting each clause ONCE (the v4.1 format repeats the modality in the heading,
104
+ * the YAML, and the prose, which a naive line scan would triple-count).
105
+ */
106
+ export function extractClauses(body) {
107
+ const lines = body.split(/\r?\n/);
108
+ const isV41 = lines.some((l) => CLAUSE_HEADING_RE.test(l.trim()));
109
+ return isV41 ? extractClauseBlocks(lines) : extractInlineClauses(lines);
110
+ }
111
+ function extractClauseBlocks(lines) {
112
+ const clauses = [];
113
+ let i = 0;
114
+ while (i < lines.length) {
115
+ const h = CLAUSE_HEADING_RE.exec((lines[i] ?? '').trim());
116
+ if (!h) {
117
+ i++;
118
+ continue;
119
+ }
120
+ const modality = h[1];
121
+ const headingLine = i + 1;
122
+ i++;
123
+ // Skip blank lines between the heading and the (optional) YAML block.
124
+ while (i < lines.length && (lines[i] ?? '').trim() === '')
125
+ i++;
126
+ // Optional fenced YAML metadata block.
127
+ let frameworkReference;
128
+ let confidence;
129
+ if ((lines[i] ?? '').trim().startsWith('```')) {
130
+ const yamlLines = [];
131
+ i++;
132
+ while (i < lines.length && !(lines[i] ?? '').trim().startsWith('```')) {
133
+ yamlLines.push(lines[i] ?? '');
134
+ i++;
135
+ }
136
+ i++; // closing fence
137
+ try {
138
+ const meta = parseYaml(yamlLines.join('\n'));
139
+ if (meta && typeof meta === 'object') {
140
+ if (typeof meta['framework_reference'] === 'string')
141
+ frameworkReference = meta['framework_reference'];
142
+ if (typeof meta['confidence'] === 'number')
143
+ confidence = meta['confidence'];
144
+ }
145
+ }
146
+ catch {
147
+ /* malformed clause metadata — surfaced by validate() */
148
+ }
149
+ }
150
+ // Prose until the next heading.
151
+ const prose = [];
152
+ while (i < lines.length && !/^#{2,3}\s+/.test(lines[i] ?? '')) {
153
+ const t = (lines[i] ?? '').trim();
154
+ if (t)
155
+ prose.push(t);
156
+ i++;
157
+ }
158
+ clauses.push({
159
+ modality,
160
+ text: prose.join(' ') || modality,
161
+ citations: frameworkReference ? parseFrameworkReference(frameworkReference) : [],
162
+ line: headingLine,
163
+ ...(confidence !== undefined ? { confidence } : {}),
164
+ ...(frameworkReference !== undefined ? { frameworkReference } : {}),
165
+ });
166
+ }
167
+ return clauses;
168
+ }
169
+ function extractInlineClauses(lines) {
170
+ const clauses = [];
171
+ lines.forEach((rawLine, i) => {
172
+ const line = rawLine.trim();
173
+ if (line === '' || CLAUSE_HEADING_RE.test(line))
174
+ return;
175
+ for (const modality of MODALITIES) {
176
+ const re = new RegExp(`(^|[^A-Za-z])${modality.replace(' ', '\\s+')}([^A-Za-z]|$)`);
177
+ if (re.test(rawLine)) {
178
+ clauses.push({ modality, text: line, citations: extractCitations(rawLine), line: i + 1 });
179
+ break; // one clause per line; MUST NOT wins via ordering
180
+ }
181
+ }
182
+ });
183
+ return clauses;
184
+ }
185
+ /**
186
+ * Parse conditioned capabilities (SKILL.md). PROVISIONAL: prefers a structured
187
+ * `capabilities` array in frontmatter if present; otherwise reads bullet items
188
+ * under a capabilities-ish heading, treating nested bullets as conditions.
189
+ */
190
+ export function extractCapabilities(frontmatter, body) {
191
+ // v4.1: permitted_tools[] enumerate the granted capabilities; the conditions
192
+ // live in the MAY clauses + invocation_conditions.
193
+ const tools = frontmatter['permitted_tools'];
194
+ if (Array.isArray(tools) && tools.length > 0) {
195
+ const conditions = Array.isArray(frontmatter['invocation_conditions'])
196
+ ? frontmatter['invocation_conditions'].filter((x) => typeof x === 'string')
197
+ : [];
198
+ return tools
199
+ .filter((t) => typeof t === 'string')
200
+ .map((capability) => ({ capability, conditions }));
201
+ }
202
+ const fromFm = frontmatter['capabilities'];
203
+ if (Array.isArray(fromFm)) {
204
+ return fromFm
205
+ .map((c) => {
206
+ if (c && typeof c === 'object') {
207
+ const obj = c;
208
+ const capability = typeof obj['capability'] === 'string' ? obj['capability'] : undefined;
209
+ if (!capability)
210
+ return null;
211
+ const conditions = Array.isArray(obj['conditions'])
212
+ ? obj['conditions'].filter((x) => typeof x === 'string')
213
+ : [];
214
+ return { capability, conditions };
215
+ }
216
+ return null;
217
+ })
218
+ .filter((c) => c !== null);
219
+ }
220
+ // Body fallback: top-level bullets = capabilities, indented bullets = conditions.
221
+ const caps = [];
222
+ const lines = body.split(/\r?\n/);
223
+ let current = null;
224
+ for (const raw of lines) {
225
+ const top = /^[-*]\s+(.*)$/.exec(raw);
226
+ const nested = /^\s+[-*]\s+(.*)$/.exec(raw);
227
+ if (top) {
228
+ if (current)
229
+ caps.push(current);
230
+ current = { capability: top[1].trim(), conditions: [] };
231
+ }
232
+ else if (nested && current) {
233
+ current.conditions.push(nested[1].trim());
234
+ }
235
+ }
236
+ if (current)
237
+ caps.push(current);
238
+ return caps;
239
+ }
240
+ /** RACI detection — the real v4.1 AGENTS.md expresses RACI as a multi-row table
241
+ * (one role per row), so require the four role terms anywhere, or the literal
242
+ * "RACI". */
243
+ const RACI_ROLES = ['responsible', 'accountable', 'consulted', 'informed'];
244
+ function hasRaciSection(body) {
245
+ if (/\bRACI\b/i.test(body))
246
+ return true;
247
+ return RACI_ROLES.every((r) => new RegExp(`\\b${r}\\b`, 'i').test(body));
248
+ }
249
+ export function parseGovernanceFile(name, source) {
250
+ const { frontmatter, body } = splitFrontmatter(source);
251
+ return {
252
+ name,
253
+ frontmatter,
254
+ body,
255
+ clauses: extractClauses(body),
256
+ capabilities: name === 'SKILL.md' ? extractCapabilities(frontmatter, body) : [],
257
+ hasRaci: hasRaciSection(body),
258
+ };
259
+ }
260
+ export { FRAMEWORK_KEYS };
261
+ //# sourceMappingURL=parse.js.map