@baselineos/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/dist/cli.d.cts ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Baseline Protocol CLI
4
+ * Entry point for the `baseline` command.
5
+ */
6
+ declare function buildCommandLine(args: string[]): string;
7
+
8
+ export { buildCommandLine };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Baseline Protocol CLI
4
+ * Entry point for the `baseline` command.
5
+ */
6
+ declare function buildCommandLine(args: string[]): string;
7
+
8
+ export { buildCommandLine };
package/dist/cli.js ADDED
@@ -0,0 +1,470 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ BaselineCommandSystem
4
+ } from "./chunk-CCIHFLKI.js";
5
+
6
+ // src/cli.ts
7
+ import { BaselineLangSystem } from "@baselineos/lang";
8
+ import { BaselineFrameSystem } from "@baselineos/frame";
9
+ import { BaselineStudioSystem } from "@baselineos/studio";
10
+ import { BaselineGovernSystem } from "@baselineos/govern";
11
+ import { BaselineExperienceSystem } from "@baselineos/experience";
12
+ import { BaselineAutonomySystem } from "@baselineos/autonomy";
13
+ import { BaselinePersonaEngine } from "@baselineos/persona";
14
+
15
+ // src/verify.ts
16
+ import { readFile } from "fs/promises";
17
+ import { existsSync } from "fs";
18
+ import { createHash } from "crypto";
19
+ async function runVerify(options) {
20
+ const checks = [];
21
+ if (options.evidencePath) {
22
+ const evidenceChecks = await verifyEvidenceBundle(options.evidencePath);
23
+ checks.push(...evidenceChecks);
24
+ }
25
+ if (options.policyPath) {
26
+ const policyChecks = await verifyPolicy(options.policyPath);
27
+ checks.push(...policyChecks);
28
+ }
29
+ if (options.auditTrailPath) {
30
+ const auditChecks = await verifyAuditTrail(options.auditTrailPath);
31
+ checks.push(...auditChecks);
32
+ }
33
+ if (checks.length === 0) {
34
+ checks.push({
35
+ name: "input",
36
+ status: "fail",
37
+ message: "No files provided. Use --policy, --evidence, or --audit-trail."
38
+ });
39
+ }
40
+ const passed = checks.filter((c) => c.status === "pass").length;
41
+ const failed = checks.filter((c) => c.status === "fail").length;
42
+ const warnings = checks.filter((c) => c.status === "warn").length;
43
+ const skipped = checks.filter((c) => c.status === "skip").length;
44
+ const hashInput = checks.map((c) => `${c.name}:${c.status}:${c.message}`).join("|");
45
+ const hash = createHash("sha256").update(hashInput).digest("hex").slice(0, 16);
46
+ return {
47
+ success: failed === 0,
48
+ passed,
49
+ failed,
50
+ warnings,
51
+ skipped,
52
+ checks,
53
+ hash,
54
+ verifiedAt: (/* @__PURE__ */ new Date()).toISOString()
55
+ };
56
+ }
57
+ async function verifyEvidenceBundle(filePath) {
58
+ const checks = [];
59
+ if (!existsSync(filePath)) {
60
+ checks.push({ name: "evidence.exists", status: "fail", message: `Evidence file not found: ${filePath}` });
61
+ return checks;
62
+ }
63
+ checks.push({ name: "evidence.exists", status: "pass", message: "Evidence file found" });
64
+ try {
65
+ const raw = await readFile(filePath, "utf-8");
66
+ const bundle = JSON.parse(raw);
67
+ if (bundle.policy) {
68
+ checks.push({ name: "evidence.policy", status: "pass", message: `Policy: ${bundle.policy.name ?? bundle.policy.id}` });
69
+ } else {
70
+ checks.push({ name: "evidence.policy", status: "warn", message: "Evidence bundle has no policy reference" });
71
+ }
72
+ if (Array.isArray(bundle.auditTrail)) {
73
+ checks.push({
74
+ name: "evidence.auditTrail",
75
+ status: bundle.auditTrail.length > 0 ? "pass" : "warn",
76
+ message: `Audit trail: ${bundle.auditTrail.length} events`
77
+ });
78
+ } else {
79
+ checks.push({ name: "evidence.auditTrail", status: "fail", message: "Evidence bundle missing audit trail" });
80
+ }
81
+ if (bundle.latestEvaluation) {
82
+ const eval_ = bundle.latestEvaluation;
83
+ checks.push({
84
+ name: "evidence.evaluation",
85
+ status: eval_.passed ? "pass" : "fail",
86
+ message: `Evaluation: ${eval_.passed ? "passed" : "failed"} (score: ${eval_.score ?? "N/A"})`
87
+ });
88
+ } else {
89
+ checks.push({ name: "evidence.evaluation", status: "skip", message: "No evaluation in evidence bundle" });
90
+ }
91
+ if (Array.isArray(bundle.approvals)) {
92
+ const approved = bundle.approvals.filter((a) => a.status === "approved");
93
+ checks.push({
94
+ name: "evidence.approvals",
95
+ status: "pass",
96
+ message: `Approvals: ${approved.length}/${bundle.approvals.length} approved`
97
+ });
98
+ }
99
+ const contentHash = createHash("sha256").update(raw).digest("hex");
100
+ checks.push({ name: "evidence.integrity", status: "pass", message: `SHA-256: ${contentHash.slice(0, 16)}...` });
101
+ } catch (error) {
102
+ checks.push({
103
+ name: "evidence.parse",
104
+ status: "fail",
105
+ message: `Failed to parse evidence: ${error instanceof Error ? error.message : String(error)}`
106
+ });
107
+ }
108
+ return checks;
109
+ }
110
+ async function verifyPolicy(filePath) {
111
+ const checks = [];
112
+ if (!existsSync(filePath)) {
113
+ checks.push({ name: "policy.exists", status: "fail", message: `Policy file not found: ${filePath}` });
114
+ return checks;
115
+ }
116
+ checks.push({ name: "policy.exists", status: "pass", message: "Policy file found" });
117
+ try {
118
+ const raw = await readFile(filePath, "utf-8");
119
+ const policy = JSON.parse(raw);
120
+ if (policy.id && policy.name) {
121
+ checks.push({ name: "policy.identity", status: "pass", message: `Policy: ${policy.name} (${policy.id})` });
122
+ } else {
123
+ checks.push({ name: "policy.identity", status: "fail", message: "Policy missing id or name" });
124
+ }
125
+ if (policy.status === "approved" || policy.status === "enforced") {
126
+ checks.push({ name: "policy.status", status: "pass", message: `Status: ${policy.status}` });
127
+ } else {
128
+ checks.push({ name: "policy.status", status: "warn", message: `Policy status is ${policy.status ?? "unknown"}, not approved/enforced` });
129
+ }
130
+ if (policy.version) {
131
+ checks.push({ name: "policy.version", status: "pass", message: `Version: ${policy.version}` });
132
+ } else {
133
+ checks.push({ name: "policy.version", status: "warn", message: "Policy has no version" });
134
+ }
135
+ if (Array.isArray(policy.rules) && policy.rules.length > 0) {
136
+ checks.push({ name: "policy.rules", status: "pass", message: `${policy.rules.length} rules defined` });
137
+ } else {
138
+ checks.push({ name: "policy.rules", status: "warn", message: "Policy has no rules defined" });
139
+ }
140
+ } catch (error) {
141
+ checks.push({
142
+ name: "policy.parse",
143
+ status: "fail",
144
+ message: `Failed to parse policy: ${error instanceof Error ? error.message : String(error)}`
145
+ });
146
+ }
147
+ return checks;
148
+ }
149
+ async function verifyAuditTrail(filePath) {
150
+ const checks = [];
151
+ if (!existsSync(filePath)) {
152
+ checks.push({ name: "audit.exists", status: "fail", message: `Audit trail not found: ${filePath}` });
153
+ return checks;
154
+ }
155
+ checks.push({ name: "audit.exists", status: "pass", message: "Audit trail found" });
156
+ try {
157
+ const raw = await readFile(filePath, "utf-8");
158
+ const events = JSON.parse(raw);
159
+ if (!Array.isArray(events)) {
160
+ checks.push({ name: "audit.format", status: "fail", message: "Audit trail is not an array" });
161
+ return checks;
162
+ }
163
+ checks.push({ name: "audit.count", status: "pass", message: `${events.length} audit events` });
164
+ let ordered = true;
165
+ for (let i = 1; i < events.length; i++) {
166
+ if (events[i].timestamp < events[i - 1].timestamp) {
167
+ ordered = false;
168
+ break;
169
+ }
170
+ }
171
+ checks.push({
172
+ name: "audit.order",
173
+ status: ordered ? "pass" : "warn",
174
+ message: ordered ? "Events are chronologically ordered" : "Events are NOT chronologically ordered"
175
+ });
176
+ const types = new Set(events.map((e) => e.type));
177
+ checks.push({ name: "audit.types", status: "pass", message: `Event types: ${Array.from(types).join(", ")}` });
178
+ const contentHash = createHash("sha256").update(raw).digest("hex");
179
+ checks.push({ name: "audit.integrity", status: "pass", message: `SHA-256: ${contentHash.slice(0, 16)}...` });
180
+ } catch (error) {
181
+ checks.push({
182
+ name: "audit.parse",
183
+ status: "fail",
184
+ message: `Failed to parse audit trail: ${error instanceof Error ? error.message : String(error)}`
185
+ });
186
+ }
187
+ return checks;
188
+ }
189
+
190
+ // src/cli.ts
191
+ import { createInterface } from "readline/promises";
192
+ import { stdin as input, stdout as output } from "process";
193
+ var VERSION = "0.1.0";
194
+ function buildCommandLine(args) {
195
+ const raw = args.join(" ").trim();
196
+ if (!raw) return "";
197
+ return raw.startsWith("--") ? raw : `--${raw}`;
198
+ }
199
+ async function main() {
200
+ const args = process.argv.slice(2);
201
+ const command = args[0];
202
+ switch (command) {
203
+ case "--help":
204
+ case "-h":
205
+ case "help":
206
+ case void 0:
207
+ showStartScreen();
208
+ showHelp();
209
+ break;
210
+ case "status":
211
+ case "--status":
212
+ showStatus();
213
+ break;
214
+ case "init": {
215
+ const cmdSystem = new BaselineCommandSystem();
216
+ const commandLine = buildCommandLine(["--init", ...args.slice(1), "--write-config"]);
217
+ const result = await cmdSystem.executeCommand(commandLine);
218
+ if (!result.success) {
219
+ console.error(`Error: ${result.error ?? "Unknown error"}`);
220
+ process.exit(1);
221
+ }
222
+ console.log(JSON.stringify(result, null, 2));
223
+ break;
224
+ }
225
+ case "version":
226
+ case "--version":
227
+ case "-v":
228
+ console.log(`baseline v${VERSION}`);
229
+ break;
230
+ case "onboard":
231
+ case "onboarding": {
232
+ const cmdSystem = new BaselineCommandSystem();
233
+ const rawArgs = args.slice(1).filter((arg) => arg !== "--interactive");
234
+ const interactive = args.length <= 1 || args.includes("--interactive");
235
+ let result;
236
+ if (interactive) {
237
+ showStartScreen();
238
+ const options = await promptOnboardingOptions();
239
+ result = await cmdSystem.executeOnboarding(options);
240
+ } else {
241
+ const commandLine = buildCommandLine(["--onboard", ...rawArgs]);
242
+ result = await cmdSystem.executeCommand(commandLine);
243
+ }
244
+ if (!result.success) {
245
+ console.error(`Error: ${result.error ?? "Unknown error"}`);
246
+ process.exit(1);
247
+ }
248
+ console.log(JSON.stringify(result, null, 2));
249
+ break;
250
+ }
251
+ case "experience": {
252
+ const cmdSystem = new BaselineCommandSystem();
253
+ const rawArgs = args.slice(1);
254
+ const commandLine = buildCommandLine(["--experience", ...rawArgs]);
255
+ const result = await cmdSystem.executeCommand(commandLine);
256
+ if (!result.success) {
257
+ console.error(`Error: ${result.error ?? "Unknown error"}`);
258
+ process.exit(1);
259
+ }
260
+ console.log(JSON.stringify(result, null, 2));
261
+ break;
262
+ }
263
+ case "serve": {
264
+ const cmdSystem = new BaselineCommandSystem();
265
+ const commandLine = buildCommandLine(["--serve", ...args.slice(1)]);
266
+ const result = await cmdSystem.executeCommand(commandLine);
267
+ if (!result.success) {
268
+ console.error(`Error: ${result.error ?? "Unknown error"}`);
269
+ process.exit(1);
270
+ }
271
+ break;
272
+ }
273
+ case "verify": {
274
+ const verifyOpts = {};
275
+ for (let i = 1; i < args.length; i++) {
276
+ if (args[i] === "--policy" && args[i + 1]) {
277
+ verifyOpts.policyPath = args[++i];
278
+ } else if (args[i] === "--evidence" && args[i + 1]) {
279
+ verifyOpts.evidencePath = args[++i];
280
+ } else if (args[i] === "--audit-trail" && args[i + 1]) {
281
+ verifyOpts.auditTrailPath = args[++i];
282
+ }
283
+ }
284
+ const verifyResult = await runVerify(verifyOpts);
285
+ console.log(JSON.stringify(verifyResult, null, 2));
286
+ if (!verifyResult.success) process.exit(1);
287
+ break;
288
+ }
289
+ case "doctor": {
290
+ const cmdSystem = new BaselineCommandSystem();
291
+ const commandLine = buildCommandLine(["--doctor", ...args.slice(1)]);
292
+ const result = await cmdSystem.executeCommand(commandLine);
293
+ if (!result.success) {
294
+ console.error(`Error: ${result.error ?? "Unknown error"}`);
295
+ process.exit(1);
296
+ }
297
+ console.log(JSON.stringify(result, null, 2));
298
+ break;
299
+ }
300
+ default: {
301
+ const cmdSystem = new BaselineCommandSystem();
302
+ const commandLine = buildCommandLine(args);
303
+ if (!commandLine) {
304
+ showHelp();
305
+ return;
306
+ }
307
+ const result = await cmdSystem.executeCommand(commandLine);
308
+ if (!result.success) {
309
+ console.error(`Error: ${result.error ?? "Unknown error"}`);
310
+ process.exit(1);
311
+ }
312
+ console.log(JSON.stringify(result, null, 2));
313
+ break;
314
+ }
315
+ }
316
+ }
317
+ function showHelp() {
318
+ console.log(`
319
+ Baseline Protocol CLI v${VERSION}
320
+
321
+ Usage: baseline <command> [options]
322
+
323
+ Commands:
324
+ help Show this help message
325
+ status Show status of all protocol layers
326
+ onboard Run the guided onboarding flow
327
+ experience Run immersive onboarding experiences
328
+ init Initialize Baseline and write config
329
+ run Run the full Baseline workflow
330
+ index Index docs or context for retrieval
331
+ verify Verify policy compliance and evidence integrity
332
+ serve Start the Baseline MCP server
333
+ agents Show agent registry status
334
+ config Configure Baseline preferences
335
+ doctor Run diagnostics for Baseline readiness
336
+ version Show version information
337
+
338
+ Layer Commands:
339
+ --baseline Run full Baseline Protocol workflow
340
+ --baseline-lang Run Language layer only
341
+ --baseline-frame Run Frame layer only
342
+ --baseline-studio Run Studio layer only
343
+ --baseline-govern Run Governance layer only
344
+ --init Initialize a new Baseline project
345
+ --run Run the full workflow
346
+ --status Show system status
347
+ --help Show help information
348
+ `);
349
+ }
350
+ function showStartScreen() {
351
+ console.log(`
352
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
353
+ \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D
354
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557
355
+ \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D
356
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
357
+ \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D
358
+
359
+ Baseline Protocol \u2022 Guided Onboarding
360
+ `);
361
+ }
362
+ async function promptOnboardingOptions() {
363
+ const rl = createInterface({ input, output });
364
+ try {
365
+ const nameInput = (await rl.question("Your name (default: User): ")).trim();
366
+ const roleInput = (await rl.question("Role (default: Operator): ")).trim();
367
+ const emailInput = (await rl.question("Email (optional): ")).trim();
368
+ const companyInput = (await rl.question("Company name (default: Acme Corp): ")).trim();
369
+ const languageInput = (await rl.question(
370
+ "Preferred language (en/es/fr/de/ja/zh/ko/ar/hi/pt, default: en): "
371
+ )).trim();
372
+ const learningStyleInput = (await rl.question(
373
+ "Learning style (visual/auditory/kinesthetic/reading, default: visual): "
374
+ )).trim();
375
+ const paceInput = (await rl.question(
376
+ "Learning pace (slow/moderate/fast/lightning, default: moderate): "
377
+ )).trim();
378
+ const focusInput = (await rl.question(
379
+ "Learning focus (practical/theoretical/mixed, default: practical): "
380
+ )).trim();
381
+ const learningPathInput = (await rl.question(
382
+ "Learning path (standard/accelerated/hands-on/theoretical, default: standard): "
383
+ )).trim();
384
+ const teamInput = (await rl.question("Team name (optional, press enter to skip): ")).trim();
385
+ const projectInput = (await rl.question("Project name (optional, press enter to skip): ")).trim();
386
+ const contextInput = (await rl.question(`Context path (default: ${process.cwd()}): `)).trim();
387
+ const modeInput = (await rl.question(
388
+ "Mode (development/staging/production, default: development): "
389
+ )).trim().toLowerCase();
390
+ const runWorkflow = (await rl.question("Run full workflow now? (Y/n): ")).trim().toLowerCase();
391
+ const skipWorkflow = runWorkflow === "n" || runWorkflow === "no";
392
+ return {
393
+ name: nameInput || void 0,
394
+ role: roleInput || void 0,
395
+ email: emailInput || void 0,
396
+ company: companyInput || void 0,
397
+ language: languageInput || void 0,
398
+ "learning-style": learningStyleInput || void 0,
399
+ pace: paceInput || void 0,
400
+ focus: focusInput || void 0,
401
+ "learning-path": learningPathInput || void 0,
402
+ team: teamInput || void 0,
403
+ project: projectInput || void 0,
404
+ context: contextInput || void 0,
405
+ mode: modeInput || void 0,
406
+ "skip-workflow": skipWorkflow
407
+ };
408
+ } finally {
409
+ rl.close();
410
+ }
411
+ }
412
+ function showStatus() {
413
+ console.log(`
414
+ Baseline Protocol v${VERSION}
415
+ `);
416
+ console.log("Layer Status:");
417
+ console.log("-".repeat(60));
418
+ const safeLine = (label, fn) => {
419
+ try {
420
+ console.log(` ${label.padEnd(10)}: ${fn()}`);
421
+ } catch (err) {
422
+ const msg = err instanceof Error ? err.message : String(err);
423
+ console.log(` ${label.padEnd(10)}: error (${msg})`);
424
+ }
425
+ };
426
+ safeLine("Lang", () => {
427
+ const lang = new BaselineLangSystem();
428
+ const langCommands = lang.getCommandRegistry().size;
429
+ return `initialized (${langCommands} commands registered)`;
430
+ });
431
+ safeLine("Frame", () => {
432
+ const frame = new BaselineFrameSystem();
433
+ const frameStatus = frame.getStatus();
434
+ return `${frameStatus.initialized ? "initialized" : "not initialized"} (mode: ${frameStatus.currentMode?.name ?? "default"})`;
435
+ });
436
+ safeLine("Studio", () => {
437
+ const studio = new BaselineStudioSystem();
438
+ const studioStatus = studio.getStatus();
439
+ return `initialized (${studioStatus.system})`;
440
+ });
441
+ safeLine("Govern", () => {
442
+ const govern = new BaselineGovernSystem();
443
+ const governStatus = govern.getStatus();
444
+ return `${governStatus.initialized ? "initialized" : "not initialized"} (${governStatus.policies} policies)`;
445
+ });
446
+ safeLine("Experience", () => {
447
+ const experience = new BaselineExperienceSystem();
448
+ const expStatus = experience.getStatus();
449
+ return `${expStatus.initialized ? "initialized" : "not initialized"}`;
450
+ });
451
+ safeLine("Autonomy", () => {
452
+ const autonomy = new BaselineAutonomySystem();
453
+ const autoStatus = autonomy.getSystemStatus();
454
+ return `${autoStatus.status} (${autoStatus.agentCount} agents)`;
455
+ });
456
+ safeLine("Persona", () => {
457
+ const persona = new BaselinePersonaEngine();
458
+ const personaStatus = persona.getStatus();
459
+ return `${personaStatus.initialized ? "initialized" : "not initialized"} (${personaStatus.totalPersonas} personas)`;
460
+ });
461
+ console.log("");
462
+ console.log("All systems operational.");
463
+ }
464
+ main().catch((err) => {
465
+ console.error("Fatal error:", err instanceof Error ? err.message : String(err));
466
+ process.exit(1);
467
+ });
468
+ export {
469
+ buildCommandLine
470
+ };