@baselineos/lang 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/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@baselineos/lang",
3
+ "version": "0.1.0",
4
+ "description": "Baseline Lang — Language & Expression Layer",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "dependencies": {
16
+ "@baselineos/protocol-core": "1.0.0"
17
+ },
18
+ "devDependencies": {
19
+ "tsup": "^8.0.0",
20
+ "typescript": "^5.7.0",
21
+ "vitest": "^2.1.0"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "scripts": {
27
+ "build": "tsup src/index.ts --format esm --dts",
28
+ "dev": "tsup src/index.ts --format esm --dts --watch",
29
+ "test": "vitest run",
30
+ "lint": "eslint src/",
31
+ "typecheck": "tsc --noEmit",
32
+ "clean": "rm -rf dist"
33
+ }
34
+ }
@@ -0,0 +1,14 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { BaselineLangSystem } from '../index.js';
3
+
4
+ describe('lang', () => {
5
+ it('should instantiate BaselineLangSystem', () => {
6
+ const lang = new BaselineLangSystem();
7
+ expect(lang).toBeDefined();
8
+ });
9
+
10
+ it('should have command registry with entries', () => {
11
+ const lang = new BaselineLangSystem();
12
+ expect(lang.getCommandRegistry().size).toBeGreaterThan(0);
13
+ });
14
+ });
@@ -0,0 +1,83 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { BaselineLangSystem } from '../index.js';
3
+
4
+ describe('lang validation', () => {
5
+ it('enforces required options and allowed values', () => {
6
+ const lang = new BaselineLangSystem();
7
+ lang.registerCommand('deploy', {
8
+ aliases: [],
9
+ description: 'Deploy a service',
10
+ usage: 'deploy --region <name>',
11
+ examples: ['deploy --region us'],
12
+ options: {
13
+ region: {
14
+ type: 'string',
15
+ required: true,
16
+ values: ['us', 'eu'],
17
+ },
18
+ },
19
+ });
20
+
21
+ const missing = lang.processInput('deploy');
22
+ expect(missing.success).toBe(false);
23
+ expect(missing.details).toContain('Missing required option: region');
24
+
25
+ const invalid = lang.processInput('deploy --region mars');
26
+ expect(invalid.success).toBe(false);
27
+ expect(invalid.details).toContain('Invalid value for option: region');
28
+
29
+ const ok = lang.processInput('deploy --region us');
30
+ expect(ok.success).toBe(true);
31
+ });
32
+
33
+ it('coerces number and boolean options', () => {
34
+ const lang = new BaselineLangSystem();
35
+ lang.registerCommand('scale', {
36
+ aliases: [],
37
+ description: 'Scale service',
38
+ usage: 'scale --count <n> [--force]',
39
+ examples: ['scale --count 3 --force'],
40
+ options: {
41
+ count: { type: 'number', required: true },
42
+ force: { type: 'boolean' },
43
+ },
44
+ });
45
+
46
+ const result = lang.processInput('scale --count 3 --force');
47
+ expect(result.success).toBe(true);
48
+ const options = result.result?.options as Map<string, unknown>;
49
+ expect(options.get('count')).toBe(3);
50
+ expect(options.get('force')).toBe(true);
51
+ });
52
+
53
+ it('merges project lexicon entries', () => {
54
+ const lang = new BaselineLangSystem({
55
+ projectLexicon: {
56
+ baseline: {
57
+ description: 'Project-specific term',
58
+ aliases: ['bl'],
59
+ tags: ['core'],
60
+ },
61
+ },
62
+ });
63
+
64
+ const lexicon = lang.getLexicon();
65
+ const entry = lexicon.get('baseline');
66
+ expect(entry?.description).toBe('Project-specific term');
67
+ expect(entry?.aliases).toContain('bl');
68
+ });
69
+
70
+ it('suggests similar commands on typos', () => {
71
+ const lang = new BaselineLangSystem();
72
+ const result = lang.processInput('hepl');
73
+ expect(result.success).toBe(false);
74
+ expect(result.suggestions?.join(' ')).toContain('help');
75
+ });
76
+
77
+ it('returns help output from registry metadata', () => {
78
+ const lang = new BaselineLangSystem();
79
+ const result = lang.processInput('help');
80
+ expect(result.success).toBe(true);
81
+ expect(result.result?.message).toContain('help');
82
+ });
83
+ });
@@ -0,0 +1,11 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { BaselineLangSystem } from '../index.js';
3
+
4
+ describe('lang workflow', () => {
5
+ it('processes a basic command', () => {
6
+ const lang = new BaselineLangSystem();
7
+ const result = lang.processInput('help');
8
+ expect(result.success).toBe(true);
9
+ expect(result.parsed?.command).toBe('help');
10
+ });
11
+ });
@@ -0,0 +1,346 @@
1
+ {
2
+ "system": {
3
+ "name": "Baseline Lang System",
4
+ "version": "1.0.0",
5
+ "description": "Natural language processing and command interpretation for Baseline Protocol",
6
+ "language": "en",
7
+ "encoding": "utf-8"
8
+ },
9
+ "syntax": {
10
+ "commandPrefix": "--",
11
+ "optionPrefix": "-",
12
+ "separator": " ",
13
+ "quoteChar": "\"",
14
+ "escapeChar": "\\",
15
+ "wildcard": "*",
16
+ "range": ".."
17
+ },
18
+ "patterns": {
19
+ "intent": {
20
+ "question": "^(what|how|when|where|why|who|which|can|should|will|do|does|is|are|was|were)",
21
+ "action": "^(create|make|build|generate|start|begin|init|initialize|launch|establish|found|set|put)",
22
+ "query": "^(show|display|list|find|search|get|fetch|retrieve|look|see|view|examine|inspect)",
23
+ "modification": "^(update|modify|edit|change|alter|adjust|transform|convert|adapt|revise|amend)",
24
+ "deletion": "^(delete|remove|destroy|eliminate|clear|wipe|erase|purge|drop|uninstall)",
25
+ "status": "^(status|info|details|state|condition|health|check|verify|validate|test)",
26
+ "navigation": "^(go|navigate|move|jump|switch|change|enter|exit|open|close)",
27
+ "configuration": "^(config|configure|setup|install|deploy|arrange|organize|structure)"
28
+ },
29
+ "command": {
30
+ "basic": "^[a-z][a-z0-9-]*$",
31
+ "compound": "^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$",
32
+ "nested": "^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$",
33
+ "namespaced": "^[a-z][a-z0-9-]*\\.[a-z][a-z0-9-]*$"
34
+ },
35
+ "option": {
36
+ "short": "^-[a-zA-Z]$",
37
+ "long": "^--[a-z][a-z0-9-]*$",
38
+ "withValue": "^--[a-z][a-z0-9-]*=",
39
+ "flag": "^--[a-z][a-z0-9-]*$"
40
+ },
41
+ "value": {
42
+ "text": "^[a-zA-Z0-9\\s\\-_\\.,/\\\\]+$",
43
+ "number": "^[0-9]+(\\.[0-9]+)?$",
44
+ "identifier": "^[a-zA-Z_][a-zA-Z0-9_]*$",
45
+ "path": "^[a-zA-Z0-9\\-_/\\\\\\.]+$",
46
+ "url": "^https?://[a-zA-Z0-9\\-_./]+$",
47
+ "email": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
48
+ }
49
+ },
50
+ "commands": {
51
+ "help": {
52
+ "aliases": ["h", "?", "--help", "help"],
53
+ "description": "Show help information and command reference",
54
+ "usage": "help [command] [options]",
55
+ "examples": [
56
+ "help",
57
+ "help create",
58
+ "help --verbose",
59
+ "help create project"
60
+ ],
61
+ "options": {
62
+ "verbose": {
63
+ "type": "boolean",
64
+ "description": "Show detailed help information",
65
+ "default": false
66
+ },
67
+ "format": {
68
+ "type": "string",
69
+ "description": "Output format (text, json, markdown)",
70
+ "default": "text",
71
+ "values": ["text", "json", "markdown"]
72
+ }
73
+ }
74
+ },
75
+ "create": {
76
+ "aliases": ["c", "new", "make", "build", "generate"],
77
+ "description": "Create a new resource or entity",
78
+ "usage": "create <type> [name] [options]",
79
+ "examples": [
80
+ "create project",
81
+ "create project myproject",
82
+ "create --type=project --name=myproject --description=\"A new project\"",
83
+ "create project myproject --template=web --framework=react"
84
+ ],
85
+ "options": {
86
+ "type": {
87
+ "type": "string",
88
+ "description": "Type of resource to create",
89
+ "required": true,
90
+ "values": ["project", "service", "component", "document", "user", "team"]
91
+ },
92
+ "name": {
93
+ "type": "string",
94
+ "description": "Name of the resource",
95
+ "required": false
96
+ },
97
+ "description": {
98
+ "type": "string",
99
+ "description": "Description of the resource",
100
+ "required": false
101
+ },
102
+ "template": {
103
+ "type": "string",
104
+ "description": "Template to use for creation",
105
+ "required": false
106
+ },
107
+ "framework": {
108
+ "type": "string",
109
+ "description": "Framework to use",
110
+ "required": false
111
+ },
112
+ "force": {
113
+ "type": "boolean",
114
+ "description": "Force creation even if resource exists",
115
+ "default": false
116
+ }
117
+ }
118
+ },
119
+ "list": {
120
+ "aliases": ["ls", "show", "display", "view"],
121
+ "description": "List resources or entities",
122
+ "usage": "list [type] [options]",
123
+ "examples": [
124
+ "list",
125
+ "list projects",
126
+ "list --type=project --format=json",
127
+ "list projects --filter=active --sort=name"
128
+ ],
129
+ "options": {
130
+ "type": {
131
+ "type": "string",
132
+ "description": "Type of resources to list",
133
+ "required": false
134
+ },
135
+ "format": {
136
+ "type": "string",
137
+ "description": "Output format (text, json, table, csv)",
138
+ "default": "text",
139
+ "values": ["text", "json", "table", "csv"]
140
+ },
141
+ "filter": {
142
+ "type": "string",
143
+ "description": "Filter criteria",
144
+ "required": false
145
+ },
146
+ "sort": {
147
+ "type": "string",
148
+ "description": "Sort field",
149
+ "required": false
150
+ },
151
+ "limit": {
152
+ "type": "number",
153
+ "description": "Maximum number of results",
154
+ "default": 50
155
+ }
156
+ }
157
+ },
158
+ "update": {
159
+ "aliases": ["u", "modify", "edit", "change", "alter"],
160
+ "description": "Update an existing resource or entity",
161
+ "usage": "update <type> <id> [options]",
162
+ "examples": [
163
+ "update project 123",
164
+ "update project 123 --name=newName",
165
+ "update --type=project --id=123 --description=\"Updated description\""
166
+ ],
167
+ "options": {
168
+ "type": {
169
+ "type": "string",
170
+ "description": "Type of resource to update",
171
+ "required": true
172
+ },
173
+ "id": {
174
+ "type": "string",
175
+ "description": "ID of the resource",
176
+ "required": true
177
+ },
178
+ "name": {
179
+ "type": "string",
180
+ "description": "New name for the resource",
181
+ "required": false
182
+ },
183
+ "description": {
184
+ "type": "string",
185
+ "description": "New description for the resource",
186
+ "required": false
187
+ },
188
+ "force": {
189
+ "type": "boolean",
190
+ "description": "Force update even if validation fails",
191
+ "default": false
192
+ }
193
+ }
194
+ },
195
+ "delete": {
196
+ "aliases": ["d", "remove", "rm", "del", "destroy"],
197
+ "description": "Delete a resource or entity",
198
+ "usage": "delete <type> <id> [options]",
199
+ "examples": [
200
+ "delete project 123",
201
+ "delete project 123 --force",
202
+ "delete --type=project --id=123 --confirm"
203
+ ],
204
+ "options": {
205
+ "type": {
206
+ "type": "string",
207
+ "description": "Type of resource to delete",
208
+ "required": true
209
+ },
210
+ "id": {
211
+ "type": "string",
212
+ "description": "ID of the resource",
213
+ "required": true
214
+ },
215
+ "force": {
216
+ "type": "boolean",
217
+ "description": "Force deletion without confirmation",
218
+ "default": false
219
+ },
220
+ "confirm": {
221
+ "type": "boolean",
222
+ "description": "Confirm deletion",
223
+ "default": false
224
+ }
225
+ }
226
+ },
227
+ "status": {
228
+ "aliases": ["s", "info", "details", "health"],
229
+ "description": "Show status information about resources or system",
230
+ "usage": "status [type] [id] [options]",
231
+ "examples": [
232
+ "status",
233
+ "status project 123",
234
+ "status system",
235
+ "status --type=project --id=123 --verbose"
236
+ ],
237
+ "options": {
238
+ "type": {
239
+ "type": "string",
240
+ "description": "Type of resource to check status",
241
+ "required": false
242
+ },
243
+ "id": {
244
+ "type": "string",
245
+ "description": "ID of the resource",
246
+ "required": false
247
+ },
248
+ "verbose": {
249
+ "type": "boolean",
250
+ "description": "Show detailed status information",
251
+ "default": false
252
+ },
253
+ "format": {
254
+ "type": "string",
255
+ "description": "Output format (text, json, table)",
256
+ "default": "text",
257
+ "values": ["text", "json", "table"]
258
+ }
259
+ }
260
+ },
261
+ "config": {
262
+ "aliases": ["cfg", "settings", "configure"],
263
+ "description": "Manage system configuration and settings",
264
+ "usage": "config [action] [key] [value] [options]",
265
+ "examples": [
266
+ "config show",
267
+ "config get database.url",
268
+ "config set database.url localhost:5432",
269
+ "config list --format=json"
270
+ ],
271
+ "options": {
272
+ "action": {
273
+ "type": "string",
274
+ "description": "Action to perform (show, get, set, list, reset)",
275
+ "required": false,
276
+ "values": ["show", "get", "set", "list", "reset", "export", "import"]
277
+ },
278
+ "key": {
279
+ "type": "string",
280
+ "description": "Configuration key",
281
+ "required": false
282
+ },
283
+ "value": {
284
+ "type": "string",
285
+ "description": "Configuration value",
286
+ "required": false
287
+ },
288
+ "format": {
289
+ "type": "string",
290
+ "description": "Output format (text, json, yaml)",
291
+ "default": "text",
292
+ "values": ["text", "json", "yaml"]
293
+ }
294
+ }
295
+ },
296
+ "test": {
297
+ "aliases": ["t", "validate", "check", "verify"],
298
+ "description": "Run tests or validation checks",
299
+ "usage": "test [type] [options]",
300
+ "examples": [
301
+ "test",
302
+ "test unit",
303
+ "test integration --verbose",
304
+ "test --type=system --format=json"
305
+ ],
306
+ "options": {
307
+ "type": {
308
+ "type": "string",
309
+ "description": "Type of tests to run",
310
+ "required": false,
311
+ "values": ["unit", "integration", "system", "all"]
312
+ },
313
+ "verbose": {
314
+ "type": "boolean",
315
+ "description": "Show detailed test output",
316
+ "default": false
317
+ },
318
+ "format": {
319
+ "type": "string",
320
+ "description": "Output format (text, json, junit)",
321
+ "default": "text",
322
+ "values": ["text", "json", "junit"]
323
+ }
324
+ }
325
+ }
326
+ },
327
+ "validation": {
328
+ "strict": false,
329
+ "allowUnknown": true,
330
+ "maxTokens": 100,
331
+ "maxOptions": 20,
332
+ "maxArguments": 10
333
+ },
334
+ "errorHandling": {
335
+ "suggestions": true,
336
+ "fuzzyMatching": true,
337
+ "maxSuggestions": 5,
338
+ "levenshteinThreshold": 2
339
+ },
340
+ "performance": {
341
+ "cacheSize": 1000,
342
+ "maxCacheAge": 300000,
343
+ "enableProfiling": false,
344
+ "logPerformance": false
345
+ }
346
+ }
package/src/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ export {
2
+ BaselineLangSystem,
3
+ IntentRecognizer,
4
+ CommandProcessor,
5
+ SyntaxValidator,
6
+ } from './system.js';
7
+
8
+ export type {
9
+ LangSystemConfig,
10
+ SyntaxConfig,
11
+ PatternConfig,
12
+ CommandConfig,
13
+ CommandOptionSpec,
14
+ CommandValidationSpec,
15
+ RegisteredCommand,
16
+ CommandHandler,
17
+ CommandResult,
18
+ ParsedInput,
19
+ IntentResult,
20
+ ProcessResult,
21
+ ParsedOption,
22
+ LexiconEntry,
23
+ LangValidationConfig,
24
+ BaselineLangOptions,
25
+ } from './system.js';