@flowmark/core-cli 0.1.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 centimani
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 ADDED
@@ -0,0 +1,72 @@
1
+ # FlowMark-core
2
+
3
+ Core CLI for FlowMark v0.1.
4
+
5
+ ## Install (npm)
6
+
7
+ ```bash
8
+ npm install @flowmark/core-cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ flowmark validate path/to/file.md
15
+ cat path/to/file.md | flowmark validate
16
+ flowmark parse path/to/file.md
17
+ flowmark lint path/to/file.md
18
+ ```
19
+
20
+ ## Options
21
+
22
+ - `--strict` : strict mode
23
+ - `--lenient` : lenient mode (default)
24
+ - `--stdin` : read from STDIN even if file is provided
25
+ - `--version`
26
+ - `--help`
27
+
28
+ ## Docker
29
+
30
+ Image: `ghcr.io/centimani/flowmark-core-cli`
31
+
32
+ ```bash
33
+ docker run --rm -v "$(pwd)":/work -w /work ghcr.io/centimani/flowmark-core-cli validate path/to/file.md
34
+ cat path/to/file.md | docker run --rm -i -v "$(pwd)":/work -w /work ghcr.io/centimani/flowmark-core-cli validate --stdin
35
+ ```
36
+
37
+ ## Test Samples (MVP)
38
+
39
+ ```bash
40
+ node bin/flowmark.js validate docs/dev/v0.1/samples/minimal.md
41
+ node bin/flowmark.js validate docs/dev/v0.1/samples/invalid-duplicate-header.md
42
+ node bin/flowmark.js validate docs/dev/v0.1/samples/invalid-no-item.md
43
+ node bin/flowmark.js validate docs/dev/v0.1/samples/invalid-status.md
44
+ node bin/flowmark.js validate docs/dev/v0.1/samples/invalid-coverage.md
45
+ node bin/flowmark.js validate docs/dev/v0.1/samples/invalid-yaml.md
46
+ node bin/flowmark.js validate docs/dev/v0.1/samples/lenient-unexpected.md
47
+ ```
48
+
49
+ Note: If `E_YAML_PARSE` occurs, derived errors/warnings (e.g. `E_ITEM_NONE`, `W_REGISTRY_MISSING`) are suppressed.
50
+
51
+ ## Strict vs Lenient (Example)
52
+
53
+ ```bash
54
+ node bin/flowmark.js validate docs/dev/v0.1/samples/lenient-unexpected.md
55
+ node bin/flowmark.js validate --strict docs/dev/v0.1/samples/lenient-unexpected.md
56
+ ```
57
+
58
+ In `lenient`, unexpected items are warnings (`W_UNEXPECTED_ITEM`).
59
+ In `strict`, they become errors (`E_UNEXPECTED_ITEM`).
60
+
61
+ ## Unknown Keys Warning
62
+
63
+ Unknown keys are allowed but produce `W_UNKNOWN_KEYS` warnings.
64
+
65
+ ## npm pack (Publish Check)
66
+
67
+ ```bash
68
+ npm pack
69
+ tar -tf flowmark-core-cli-0.1.0.tgz
70
+ ```
71
+
72
+ Check that `bin/`, `src/`, `README.md`, and `LICENSE` are included.
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { parseFlowmark, toDocument } = require('../src/parser/flowmark');
6
+ const { validateDocument, lintDocument } = require('../src/validator/validate');
7
+
8
+ function printHelp() {
9
+ const msg = `FlowMark CLI (v0.1)
10
+
11
+ Usage:
12
+ flowmark validate <file>
13
+ flowmark parse <file>
14
+ flowmark lint <file>
15
+ cat file.md | flowmark validate
16
+
17
+ Options:
18
+ --strict Use strict mode
19
+ --lenient Use lenient mode (default)
20
+ --stdin Read from STDIN even if a file is provided
21
+ --version Print version
22
+ --help Show help
23
+ `;
24
+ process.stdout.write(msg);
25
+ }
26
+
27
+ function readVersion() {
28
+ const pkgPath = path.resolve(__dirname, '..', 'package.json');
29
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
30
+ return pkg.version || '0.0.0';
31
+ }
32
+
33
+ function parseArgs(argv) {
34
+ const opts = {
35
+ mode: 'lenient',
36
+ stdin: false,
37
+ help: false,
38
+ version: false
39
+ };
40
+ let command = null;
41
+ let file = null;
42
+
43
+ for (const arg of argv) {
44
+ if (arg === '--help' || arg === '-h') {
45
+ opts.help = true;
46
+ } else if (arg === '--version') {
47
+ opts.version = true;
48
+ } else if (arg === '--strict') {
49
+ opts.mode = 'strict';
50
+ } else if (arg === '--lenient') {
51
+ opts.mode = 'lenient';
52
+ } else if (arg === '--stdin') {
53
+ opts.stdin = true;
54
+ } else if (!command) {
55
+ command = arg;
56
+ } else if (!file) {
57
+ file = arg;
58
+ } else {
59
+ // ignore extra args for now
60
+ }
61
+ }
62
+
63
+ return { command, file, opts };
64
+ }
65
+
66
+ function readInput({ file, stdin }) {
67
+ if (stdin) {
68
+ return fs.readFileSync(0, 'utf8');
69
+ }
70
+ if (file) {
71
+ return fs.readFileSync(file, 'utf8');
72
+ }
73
+ if (process.stdin.isTTY) {
74
+ throw new Error('No input provided. Pass a file or pipe STDIN.');
75
+ }
76
+ return fs.readFileSync(0, 'utf8');
77
+ }
78
+
79
+ function run() {
80
+ const { command, file, opts } = parseArgs(process.argv.slice(2));
81
+
82
+ if (opts.version) {
83
+ process.stdout.write(readVersion() + '\n');
84
+ return process.exit(0);
85
+ }
86
+
87
+ if (opts.help || !command) {
88
+ printHelp();
89
+ return process.exit(opts.help ? 0 : 2);
90
+ }
91
+
92
+ if (command !== 'validate') {
93
+ if (command !== 'parse' && command !== 'lint') {
94
+ process.stderr.write(`Unknown command: ${command}\n`);
95
+ printHelp();
96
+ return process.exit(2);
97
+ }
98
+ }
99
+
100
+ let input;
101
+ try {
102
+ input = readInput({ file, stdin: opts.stdin });
103
+ } catch (err) {
104
+ process.stderr.write(String(err.message || err) + '\n');
105
+ return process.exit(2);
106
+ }
107
+
108
+ const parsed = parseFlowmark(input);
109
+
110
+ if (command === 'parse') {
111
+ const output = {
112
+ document: toDocument(parsed),
113
+ errors: parsed.errors || []
114
+ };
115
+ process.stdout.write(JSON.stringify(output, null, 2) + '\n');
116
+ return process.exit(output.errors.length > 0 ? 2 : 0);
117
+ }
118
+
119
+ if (command === 'lint') {
120
+ const result = lintDocument(parsed, { mode: opts.mode });
121
+ const output = {
122
+ mode: opts.mode,
123
+ errors: result.errors,
124
+ warnings: result.warnings
125
+ };
126
+ process.stdout.write(JSON.stringify(output, null, 2) + '\n');
127
+ if (output.errors.length > 0) return process.exit(2);
128
+ if (output.warnings.length > 0) return process.exit(1);
129
+ return process.exit(0);
130
+ }
131
+
132
+ const result = validateDocument(parsed, { mode: opts.mode });
133
+ const output = {
134
+ mode: opts.mode,
135
+ errors: result.errors,
136
+ warnings: result.warnings
137
+ };
138
+ process.stdout.write(JSON.stringify(output, null, 2) + '\n');
139
+
140
+ if (output.errors.length > 0) {
141
+ return process.exit(2);
142
+ }
143
+ if (output.warnings.length > 0) {
144
+ return process.exit(1);
145
+ }
146
+ return process.exit(0);
147
+ }
148
+
149
+ run();
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@flowmark/core-cli",
3
+ "version": "0.1.0",
4
+ "description": "FlowMark core CLI",
5
+ "private": false,
6
+ "keywords": [
7
+ "flowmark",
8
+ "cli",
9
+ "validator"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/centimani/flowmark-core.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/centimani/flowmark-core/issues"
17
+ },
18
+ "homepage": "https://github.com/centimani/flowmark-core#readme",
19
+ "license": "MIT",
20
+ "type": "commonjs",
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "files": [
25
+ "bin/",
26
+ "src/",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "bin": {
31
+ "flowmark": "bin/flowmark.js"
32
+ },
33
+ "dependencies": {
34
+ "yaml": "^2.4.5"
35
+ }
36
+ }
@@ -0,0 +1,88 @@
1
+ const YAML = require('yaml');
2
+ const { scanFencedBlocks } = require('./scan');
3
+
4
+ const INFO_MAP = {
5
+ 'yaml flowmark': 'header',
6
+ 'yaml flowmark-section': 'section',
7
+ 'yaml flowmark-item': 'item',
8
+ 'yaml flowmark-registry': 'registry'
9
+ };
10
+
11
+ function parseYamlBlock(block) {
12
+ const doc = YAML.parseDocument(block.content, { prettyErrors: false });
13
+ if (doc.errors && doc.errors.length > 0) {
14
+ const err = doc.errors[0];
15
+ let location = null;
16
+ if (err.linePos && err.linePos.start && typeof err.linePos.start.line === 'number') {
17
+ const base = block.startLine + 1;
18
+ const start = err.linePos.start.line;
19
+ const end = err.linePos.end && typeof err.linePos.end.line === 'number'
20
+ ? err.linePos.end.line
21
+ : start;
22
+ location = {
23
+ start_line: base + start - 1,
24
+ end_line: base + end - 1
25
+ };
26
+ }
27
+ return {
28
+ error: {
29
+ code: 'E_YAML_PARSE',
30
+ message: `YAML parse error: ${err.message}`,
31
+ location
32
+ }
33
+ };
34
+ }
35
+
36
+ return { data: doc.toJSON() };
37
+ }
38
+
39
+ function parseFlowmark(text) {
40
+ const blocks = scanFencedBlocks(text);
41
+ const result = {
42
+ headers: [],
43
+ sections: [],
44
+ items: [],
45
+ registries: [],
46
+ errors: []
47
+ };
48
+
49
+ for (const block of blocks) {
50
+ const type = INFO_MAP[block.info];
51
+ if (!type) {
52
+ continue;
53
+ }
54
+
55
+ const parsed = parseYamlBlock(block);
56
+ if (parsed.error) {
57
+ result.errors.push(parsed.error);
58
+ continue;
59
+ }
60
+
61
+ const entry = {
62
+ data: parsed.data,
63
+ location: { start_line: block.startLine, end_line: block.endLine }
64
+ };
65
+
66
+ if (type === 'header') result.headers.push(entry);
67
+ if (type === 'section') result.sections.push(entry);
68
+ if (type === 'item') result.items.push(entry);
69
+ if (type === 'registry') result.registries.push(entry);
70
+ }
71
+
72
+ return result;
73
+ }
74
+
75
+ function toDocument(parsed) {
76
+ const header = parsed.headers[0]
77
+ ? { ...parsed.headers[0].data, location: parsed.headers[0].location }
78
+ : null;
79
+ const sections = parsed.sections.map((s) => ({ ...s.data, location: s.location }));
80
+ const items = parsed.items.map((i) => ({ ...i.data, location: i.location }));
81
+ const registry = parsed.registries[0]
82
+ ? { ...parsed.registries[0].data, location: parsed.registries[0].location }
83
+ : null;
84
+
85
+ return { header, sections, items, registry };
86
+ }
87
+
88
+ module.exports = { parseFlowmark, toDocument };
@@ -0,0 +1,45 @@
1
+ function scanFencedBlocks(text) {
2
+ const lines = text.split(/\r?\n/);
3
+ const blocks = [];
4
+
5
+ let inFence = false;
6
+ let info = '';
7
+ let startLine = 0;
8
+ let contentLines = [];
9
+
10
+ for (let i = 0; i < lines.length; i++) {
11
+ const line = lines[i];
12
+
13
+ if (!inFence) {
14
+ const startMatch = line.match(/^(\s*)```(.*)$/);
15
+ if (startMatch) {
16
+ inFence = true;
17
+ info = (startMatch[2] || '').trim();
18
+ startLine = i + 1;
19
+ contentLines = [];
20
+ }
21
+ continue;
22
+ }
23
+
24
+ const endMatch = line.match(/^(\s*)```\s*$/);
25
+ if (endMatch) {
26
+ const endLine = i + 1;
27
+ blocks.push({
28
+ info,
29
+ content: contentLines.join('\n'),
30
+ startLine,
31
+ endLine
32
+ });
33
+ inFence = false;
34
+ info = '';
35
+ startLine = 0;
36
+ contentLines = [];
37
+ } else {
38
+ contentLines.push(line);
39
+ }
40
+ }
41
+
42
+ return blocks;
43
+ }
44
+
45
+ module.exports = { scanFencedBlocks };
@@ -0,0 +1,301 @@
1
+ const ALLOWED_STATUS = new Set(['todo', 'done', 'skipped', 'blocked']);
2
+
3
+ const ALLOWED_KEYS = {
4
+ header: new Set(['id', 'title', 'version', 'status', 'created_at', 'inputs']),
5
+ section: new Set(['id', 'scope', 'notes']),
6
+ item: new Set(['id', 'status', 'refs', 'batch']),
7
+ registry: new Set(['expected_items'])
8
+ };
9
+
10
+ function isNonEmptyString(value) {
11
+ return typeof value === 'string' && value.trim() !== '';
12
+ }
13
+
14
+ function addSchemaError(errors, message, location) {
15
+ errors.push({
16
+ code: 'E_SCHEMA_INVALID',
17
+ message,
18
+ location: location || null
19
+ });
20
+ }
21
+
22
+ function addUnknownKeyWarnings(kind, entry, warnings) {
23
+ if (!entry || !entry.data || typeof entry.data !== 'object' || Array.isArray(entry.data)) {
24
+ return;
25
+ }
26
+ const allowed = ALLOWED_KEYS[kind];
27
+ if (!allowed) return;
28
+ const unknown = Object.keys(entry.data).filter((k) => !allowed.has(k));
29
+ if (unknown.length === 0) return;
30
+ warnings.push({
31
+ code: 'W_UNKNOWN_KEYS',
32
+ message: `Unknown keys in ${kind}: ${unknown.join(', ')}`,
33
+ location: entry.location || null
34
+ });
35
+ }
36
+
37
+ function validateDocument(parsed, { mode }) {
38
+ const errors = [...(parsed.errors || [])];
39
+ const warnings = [];
40
+ const hasParseError = errors.some((e) => e && e.code === 'E_YAML_PARSE');
41
+
42
+ if (parsed.headers.length === 0) {
43
+ errors.push({
44
+ code: 'E_HEADER_MISSING',
45
+ message: 'Header block is missing.',
46
+ location: null
47
+ });
48
+ } else if (parsed.headers.length > 1) {
49
+ for (let i = 1; i < parsed.headers.length; i++) {
50
+ errors.push({
51
+ code: 'E_HEADER_DUPLICATE',
52
+ message: 'Header block is duplicated.',
53
+ location: parsed.headers[i].location || null
54
+ });
55
+ }
56
+ }
57
+
58
+ if (parsed.headers.length > 0) {
59
+ const header = parsed.headers[0];
60
+ const data = header.data;
61
+ if (!data || typeof data !== 'object' || Array.isArray(data)) {
62
+ addSchemaError(errors, 'Header block must be a mapping.', header.location);
63
+ } else {
64
+ if (!isNonEmptyString(data.id)) {
65
+ addSchemaError(errors, 'Header id is required.', header.location);
66
+ }
67
+ if (!isNonEmptyString(data.title)) {
68
+ addSchemaError(errors, 'Header title is required.', header.location);
69
+ }
70
+ if (!isNonEmptyString(data.version)) {
71
+ addSchemaError(errors, 'Header version must be a non-empty string.', header.location);
72
+ }
73
+ }
74
+ }
75
+
76
+ if (!hasParseError && parsed.items.length === 0) {
77
+ errors.push({
78
+ code: 'E_ITEM_NONE',
79
+ message: 'No item blocks found.',
80
+ location: null
81
+ });
82
+ }
83
+
84
+ const itemIds = new Set();
85
+ for (const item of parsed.items) {
86
+ if (hasParseError) break;
87
+ const data = item.data;
88
+ if (!data || typeof data !== 'object' || Array.isArray(data)) {
89
+ addSchemaError(errors, 'Item block must be a mapping.', item.location);
90
+ continue;
91
+ }
92
+ const id = data.id;
93
+ const status = data.status;
94
+
95
+ if (isNonEmptyString(id)) {
96
+ if (itemIds.has(id)) {
97
+ errors.push({
98
+ code: 'E_ITEM_ID_DUPLICATE',
99
+ message: `Duplicate item id: ${id}`,
100
+ location: item.location || null
101
+ });
102
+ } else {
103
+ itemIds.add(id);
104
+ }
105
+ } else {
106
+ addSchemaError(errors, 'Item id is required.', item.location);
107
+ }
108
+
109
+ if (!isNonEmptyString(status)) {
110
+ addSchemaError(errors, 'Item status is required.', item.location);
111
+ } else if (!ALLOWED_STATUS.has(status)) {
112
+ errors.push({
113
+ code: 'E_ITEM_STATUS_INVALID',
114
+ message: `Invalid item status: ${status}`,
115
+ location: item.location || null
116
+ });
117
+ }
118
+
119
+ addUnknownKeyWarnings('item', item, warnings);
120
+ }
121
+
122
+ for (const section of parsed.sections) {
123
+ addUnknownKeyWarnings('section', section, warnings);
124
+ }
125
+ for (const header of parsed.headers) {
126
+ addUnknownKeyWarnings('header', header, warnings);
127
+ }
128
+
129
+ if (!hasParseError && parsed.registries.length === 0) {
130
+ warnings.push({
131
+ code: 'W_REGISTRY_MISSING',
132
+ message: 'Registry block is missing.',
133
+ location: null
134
+ });
135
+ } else if (parsed.registries.length > 1) {
136
+ for (let i = 1; i < parsed.registries.length; i++) {
137
+ errors.push({
138
+ code: 'E_REGISTRY_DUPLICATE',
139
+ message: 'Registry block is duplicated.',
140
+ location: parsed.registries[i].location || null
141
+ });
142
+ }
143
+ }
144
+
145
+ if (!hasParseError && parsed.registries.length > 0) {
146
+ const registry = parsed.registries[0];
147
+ addUnknownKeyWarnings('registry', registry, warnings);
148
+
149
+ const expected = registry.data && typeof registry.data === 'object' && !Array.isArray(registry.data)
150
+ ? registry.data.expected_items
151
+ : null;
152
+
153
+ if (!Array.isArray(expected)) {
154
+ addSchemaError(errors, 'Registry expected_items must be an array.', registry.location);
155
+ } else {
156
+ const expectedSet = new Set();
157
+ const duplicates = new Set();
158
+ for (const id of expected) {
159
+ if (expectedSet.has(id)) duplicates.add(id);
160
+ expectedSet.add(id);
161
+ }
162
+ if (duplicates.size > 0) {
163
+ errors.push({
164
+ code: 'E_REGISTRY_DUPLICATE',
165
+ message: `Duplicate registry ids: ${Array.from(duplicates).join(', ')}`,
166
+ location: registry.location || null
167
+ });
168
+ }
169
+
170
+ const missing = Array.from(expectedSet).filter((id) => !itemIds.has(id));
171
+ const unexpected = Array.from(itemIds).filter((id) => !expectedSet.has(id));
172
+
173
+ if (missing.length > 0) {
174
+ errors.push({
175
+ code: 'E_COVERAGE_MISSING',
176
+ message: `Missing items: ${missing.join(', ')}`,
177
+ location: registry.location || null
178
+ });
179
+ }
180
+
181
+ if (unexpected.length > 0) {
182
+ if (mode === 'strict') {
183
+ errors.push({
184
+ code: 'E_UNEXPECTED_ITEM',
185
+ message: `Unexpected items: ${unexpected.join(', ')}`,
186
+ location: registry.location || null
187
+ });
188
+ } else {
189
+ warnings.push({
190
+ code: 'W_UNEXPECTED_ITEM',
191
+ message: `Unexpected items: ${unexpected.join(', ')}`,
192
+ location: registry.location || null
193
+ });
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
+ const sectionIds = new Set();
200
+ for (const section of parsed.sections) {
201
+ const data = section.data;
202
+ const id = data && typeof data === 'object' && !Array.isArray(data) ? data.id : null;
203
+ if (typeof id === 'string' && id.trim() !== '') {
204
+ if (sectionIds.has(id)) {
205
+ warnings.push({
206
+ code: 'W_SECTION_ID_DUPLICATE',
207
+ message: `Duplicate section id: ${id}`,
208
+ location: section.location || null
209
+ });
210
+ } else {
211
+ sectionIds.add(id);
212
+ }
213
+ }
214
+ }
215
+
216
+ return { errors, warnings };
217
+ }
218
+
219
+ function lintDocument(parsed, { mode }) {
220
+ const errors = [...(parsed.errors || [])];
221
+ const warnings = [];
222
+ const hasParseError = errors.some((e) => e && e.code === 'E_YAML_PARSE');
223
+ if (hasParseError) {
224
+ return { errors, warnings };
225
+ }
226
+
227
+ const itemIds = new Set();
228
+ for (const item of parsed.items) {
229
+ const data = item.data;
230
+ if (data && typeof data === 'object' && !Array.isArray(data) && isNonEmptyString(data.id)) {
231
+ itemIds.add(data.id);
232
+ }
233
+ addUnknownKeyWarnings('item', item, warnings);
234
+ }
235
+ for (const section of parsed.sections) {
236
+ addUnknownKeyWarnings('section', section, warnings);
237
+ }
238
+ for (const header of parsed.headers) {
239
+ addUnknownKeyWarnings('header', header, warnings);
240
+ }
241
+
242
+ if (parsed.registries.length === 0) {
243
+ warnings.push({
244
+ code: 'W_REGISTRY_MISSING',
245
+ message: 'Registry block is missing.',
246
+ location: null
247
+ });
248
+ }
249
+
250
+ if (parsed.registries.length > 0) {
251
+ const registry = parsed.registries[0];
252
+ addUnknownKeyWarnings('registry', registry, warnings);
253
+ const expected = registry.data && typeof registry.data === 'object' && !Array.isArray(registry.data)
254
+ ? registry.data.expected_items
255
+ : null;
256
+ if (Array.isArray(expected)) {
257
+ const expectedSet = new Set();
258
+ const duplicates = new Set();
259
+ for (const id of expected) {
260
+ if (expectedSet.has(id)) duplicates.add(id);
261
+ expectedSet.add(id);
262
+ }
263
+ if (duplicates.size > 0) {
264
+ warnings.push({
265
+ code: 'W_REGISTRY_DUPLICATE',
266
+ message: `Duplicate registry ids: ${Array.from(duplicates).join(', ')}`,
267
+ location: registry.location || null
268
+ });
269
+ }
270
+ const unexpected = Array.from(itemIds).filter((id) => !expectedSet.has(id));
271
+ if (unexpected.length > 0) {
272
+ warnings.push({
273
+ code: 'W_UNEXPECTED_ITEM',
274
+ message: `Unexpected items: ${unexpected.join(', ')}`,
275
+ location: registry.location || null
276
+ });
277
+ }
278
+ }
279
+ }
280
+
281
+ const sectionIds = new Set();
282
+ for (const section of parsed.sections) {
283
+ const data = section.data;
284
+ const id = data && typeof data === 'object' && !Array.isArray(data) ? data.id : null;
285
+ if (isNonEmptyString(id)) {
286
+ if (sectionIds.has(id)) {
287
+ warnings.push({
288
+ code: 'W_SECTION_ID_DUPLICATE',
289
+ message: `Duplicate section id: ${id}`,
290
+ location: section.location || null
291
+ });
292
+ } else {
293
+ sectionIds.add(id);
294
+ }
295
+ }
296
+ }
297
+
298
+ return { errors, warnings };
299
+ }
300
+
301
+ module.exports = { validateDocument, lintDocument };