baselineos 0.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +198 -0
  3. package/dist/__evals__/runner.d.ts +2 -0
  4. package/dist/__evals__/runner.js +14687 -0
  5. package/dist/__evals__/runner.js.map +1 -0
  6. package/dist/api/server.d.ts +21 -0
  7. package/dist/api/server.js +1007 -0
  8. package/dist/api/server.js.map +1 -0
  9. package/dist/cli/bin.d.ts +1 -0
  10. package/dist/cli/bin.js +8427 -0
  11. package/dist/cli/bin.js.map +1 -0
  12. package/dist/core/agent-bus.d.ts +110 -0
  13. package/dist/core/agent-bus.js +242 -0
  14. package/dist/core/agent-bus.js.map +1 -0
  15. package/dist/core/cache.d.ts +66 -0
  16. package/dist/core/cache.js +160 -0
  17. package/dist/core/cache.js.map +1 -0
  18. package/dist/core/config.d.ts +1002 -0
  19. package/dist/core/config.js +429 -0
  20. package/dist/core/config.js.map +1 -0
  21. package/dist/core/indexer.d.ts +152 -0
  22. package/dist/core/indexer.js +481 -0
  23. package/dist/core/indexer.js.map +1 -0
  24. package/dist/core/llm-tracer.d.ts +2 -0
  25. package/dist/core/llm-tracer.js +241 -0
  26. package/dist/core/llm-tracer.js.map +1 -0
  27. package/dist/core/memory.d.ts +86 -0
  28. package/dist/core/memory.js +346 -0
  29. package/dist/core/memory.js.map +1 -0
  30. package/dist/core/opa-client.d.ts +51 -0
  31. package/dist/core/opa-client.js +157 -0
  32. package/dist/core/opa-client.js.map +1 -0
  33. package/dist/core/opa-policy-gate.d.ts +133 -0
  34. package/dist/core/opa-policy-gate.js +454 -0
  35. package/dist/core/opa-policy-gate.js.map +1 -0
  36. package/dist/core/orchestrator.d.ts +14 -0
  37. package/dist/core/orchestrator.js +1297 -0
  38. package/dist/core/orchestrator.js.map +1 -0
  39. package/dist/core/pii-detector.d.ts +82 -0
  40. package/dist/core/pii-detector.js +126 -0
  41. package/dist/core/pii-detector.js.map +1 -0
  42. package/dist/core/rag-engine.d.ts +121 -0
  43. package/dist/core/rag-engine.js +504 -0
  44. package/dist/core/rag-engine.js.map +1 -0
  45. package/dist/core/task-queue.d.ts +69 -0
  46. package/dist/core/task-queue.js +124 -0
  47. package/dist/core/task-queue.js.map +1 -0
  48. package/dist/core/telemetry.d.ts +56 -0
  49. package/dist/core/telemetry.js +94 -0
  50. package/dist/core/telemetry.js.map +1 -0
  51. package/dist/core/types.d.ts +328 -0
  52. package/dist/core/types.js +24 -0
  53. package/dist/core/types.js.map +1 -0
  54. package/dist/index.d.ts +21 -0
  55. package/dist/index.js +12444 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/llm-tracer-CIIujuO-.d.ts +493 -0
  58. package/dist/mcp/server.d.ts +2651 -0
  59. package/dist/mcp/server.js +676 -0
  60. package/dist/mcp/server.js.map +1 -0
  61. package/dist/orchestrator-DF89k_AK.d.ts +506 -0
  62. package/package.json +157 -0
  63. package/templates/README.md +7 -0
  64. package/templates/baseline.config.ts +207 -0
@@ -0,0 +1,676 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
+ import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema } from '@modelcontextprotocol/sdk/types.js';
4
+
5
+ // src/mcp/server.ts
6
+ var TOOL_RISKS = {
7
+ search_knowledge: { level: "low", requiresEscalation: false, reason: "Read-only retrieval" },
8
+ get_context: { level: "low", requiresEscalation: false, reason: "Read-only retrieval" },
9
+ get_context_delta: { level: "low", requiresEscalation: false, reason: "Read-only retrieval" },
10
+ remember: { level: "medium", requiresEscalation: false, reason: "Writes to memory store" },
11
+ recall: { level: "low", requiresEscalation: false, reason: "Read-only memory access" },
12
+ run_task: { level: "high", requiresEscalation: true, reason: "Triggers autonomous execution" },
13
+ list_tasks: { level: "low", requiresEscalation: false, reason: "Read-only task listing" },
14
+ list_workflows: { level: "low", requiresEscalation: false, reason: "Read-only workflow listing" },
15
+ run_workflow: { level: "high", requiresEscalation: true, reason: "Triggers autonomous execution" },
16
+ get_checkpoint: { level: "medium", requiresEscalation: false, reason: "Reads checkpoint state" },
17
+ recover_checkpoint: { level: "high", requiresEscalation: true, reason: "Recovers task state" },
18
+ get_task_audit: { level: "medium", requiresEscalation: false, reason: "Reads audit trail" },
19
+ get_evidence_bundle: { level: "medium", requiresEscalation: false, reason: "Reads evidence bundle" },
20
+ get_task: { level: "low", requiresEscalation: false, reason: "Read-only task access" },
21
+ stats: { level: "low", requiresEscalation: false, reason: "Read-only stats" },
22
+ get_tool_risks: { level: "low", requiresEscalation: false, reason: "Read-only tool metadata" }
23
+ };
24
+ var CONTEXT_LEVELS = ["oneliner", "summary", "working", "full", "expanded"];
25
+ var TASK_PRIORITIES = ["critical", "high", "medium", "low"];
26
+ var TASK_STATUSES = [
27
+ "pending",
28
+ "planning",
29
+ "executing",
30
+ "verifying",
31
+ "reviewing",
32
+ "correcting",
33
+ "completed",
34
+ "failed",
35
+ "blocked"
36
+ ];
37
+ var MEMORY_SCOPES = ["working", "session", "long-term", "shared"];
38
+ var RETRIEVE_SCOPES = [...MEMORY_SCOPES, "all"];
39
+ function parsePolicy(value) {
40
+ if (!value || typeof value !== "object") return void 0;
41
+ return value;
42
+ }
43
+ function parseBudget(value) {
44
+ if (!value || typeof value !== "object") return void 0;
45
+ return value;
46
+ }
47
+ function parseLevel(value) {
48
+ if (typeof value === "string" && CONTEXT_LEVELS.includes(value)) {
49
+ return value;
50
+ }
51
+ return "working";
52
+ }
53
+ function parseOverlayOrder(value) {
54
+ if (!Array.isArray(value)) return void 0;
55
+ const overlays = value.map((entry) => String(entry)).filter((entry) => entry === "org" || entry === "repo" || entry === "public");
56
+ return overlays.length > 0 ? overlays : void 0;
57
+ }
58
+ function parseMemoryScope(value) {
59
+ if (typeof value === "string" && MEMORY_SCOPES.includes(value)) {
60
+ return value;
61
+ }
62
+ return "session";
63
+ }
64
+ function parseRetrieveScope(value) {
65
+ if (typeof value === "string" && RETRIEVE_SCOPES.includes(value)) {
66
+ return value;
67
+ }
68
+ return "all";
69
+ }
70
+ function parseTaskPriority(value) {
71
+ if (typeof value === "string" && TASK_PRIORITIES.includes(value)) {
72
+ return value;
73
+ }
74
+ return "medium";
75
+ }
76
+ function parseTaskStatus(value) {
77
+ if (typeof value === "string" && TASK_STATUSES.includes(value)) {
78
+ return value;
79
+ }
80
+ return void 0;
81
+ }
82
+ function parseAcceptanceCriteria(value) {
83
+ if (!Array.isArray(value)) return [];
84
+ return value.filter((entry) => {
85
+ return Boolean(entry && typeof entry === "object" && typeof entry.description === "string");
86
+ }).map((entry) => ({
87
+ description: entry.description,
88
+ type: entry.type ?? "automated",
89
+ weight: typeof entry.weight === "number" ? entry.weight : 1
90
+ }));
91
+ }
92
+ var MCPServer = class {
93
+ baseline;
94
+ server;
95
+ transport;
96
+ running = false;
97
+ constructor(baseline) {
98
+ this.baseline = baseline;
99
+ }
100
+ async start() {
101
+ if (this.running) return;
102
+ this.server = new Server(
103
+ { name: "baselineos", version: "0.2.0-beta.1" },
104
+ { capabilities: { tools: {}, resources: {} } }
105
+ );
106
+ this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
107
+ tools: this.getTools()
108
+ }));
109
+ this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
110
+ const name = request.params.name;
111
+ const args = request.params.arguments || {};
112
+ try {
113
+ const result = await this.handleToolCall(name, args);
114
+ return {
115
+ content: [
116
+ {
117
+ type: "text",
118
+ text: JSON.stringify(result, null, 2)
119
+ }
120
+ ]
121
+ };
122
+ } catch (error) {
123
+ return {
124
+ content: [
125
+ {
126
+ type: "text",
127
+ text: JSON.stringify(
128
+ { error: error.message || "Unknown error" },
129
+ null,
130
+ 2
131
+ )
132
+ }
133
+ ]
134
+ };
135
+ }
136
+ });
137
+ this.server.setRequestHandler(ListResourcesRequestSchema, async () => ({
138
+ resources: this.getResources()
139
+ }));
140
+ this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
141
+ const uri = request.params.uri;
142
+ const resource = await this.readResource(uri);
143
+ return {
144
+ contents: [
145
+ {
146
+ uri,
147
+ mimeType: "application/json",
148
+ text: JSON.stringify(resource, null, 2)
149
+ }
150
+ ]
151
+ };
152
+ });
153
+ this.transport = new StdioServerTransport();
154
+ await this.server.connect(this.transport);
155
+ this.running = true;
156
+ console.error("[MCP] Server started (stdio)");
157
+ }
158
+ async stop() {
159
+ this.running = false;
160
+ console.error("[MCP] Server stopped");
161
+ }
162
+ isRunning() {
163
+ return this.running;
164
+ }
165
+ getTools() {
166
+ return [
167
+ {
168
+ name: "search_knowledge",
169
+ description: "Search the BaselineOS knowledge index",
170
+ inputSchema: {
171
+ type: "object",
172
+ properties: {
173
+ query: { type: "string" },
174
+ limit: { type: "number", default: 5 },
175
+ policy: {
176
+ type: "object",
177
+ properties: {
178
+ repo: { type: "array", items: { type: "string" } },
179
+ overlays: { type: "array", items: { type: "string", enum: ["org", "repo", "public"] } },
180
+ sensitivity: { type: "string", enum: ["public", "internal", "restricted"] },
181
+ scopes: { type: "array", items: { type: "string" } },
182
+ roles: { type: "array", items: { type: "string" } }
183
+ },
184
+ additionalProperties: false
185
+ }
186
+ },
187
+ required: ["query"]
188
+ }
189
+ },
190
+ {
191
+ name: "get_context",
192
+ description: "Get context for a subject at a specified compression level",
193
+ inputSchema: {
194
+ type: "object",
195
+ properties: {
196
+ subject: { type: "string" },
197
+ level: {
198
+ type: "string",
199
+ enum: ["oneliner", "summary", "working", "full", "expanded"],
200
+ default: "working"
201
+ },
202
+ policy: {
203
+ type: "object",
204
+ properties: {
205
+ repo: { type: "array", items: { type: "string" } },
206
+ overlays: { type: "array", items: { type: "string", enum: ["org", "repo", "public"] } },
207
+ sensitivity: { type: "string", enum: ["public", "internal", "restricted"] },
208
+ scopes: { type: "array", items: { type: "string" } },
209
+ roles: { type: "array", items: { type: "string" } }
210
+ },
211
+ additionalProperties: false
212
+ },
213
+ overlayOrder: { type: "array", items: { type: "string", enum: ["org", "repo", "public"] } },
214
+ budget: {
215
+ type: "object",
216
+ properties: {
217
+ maxTokens: { type: "number" },
218
+ maxCostUsd: { type: "number" },
219
+ costPer1kTokensUsd: { type: "number" }
220
+ },
221
+ additionalProperties: false
222
+ }
223
+ },
224
+ required: ["subject"]
225
+ }
226
+ },
227
+ {
228
+ name: "get_context_delta",
229
+ description: "Get only changed/unknown context for a subject (delta compression)",
230
+ inputSchema: {
231
+ type: "object",
232
+ properties: {
233
+ subject: { type: "string" },
234
+ level: {
235
+ type: "string",
236
+ enum: ["oneliner", "summary", "working", "full", "expanded"],
237
+ default: "working"
238
+ },
239
+ known: {
240
+ type: "array",
241
+ items: {
242
+ type: "object",
243
+ properties: {
244
+ id: { type: "string" },
245
+ hash: { type: "string" }
246
+ },
247
+ required: ["id"],
248
+ additionalProperties: false
249
+ }
250
+ },
251
+ policy: {
252
+ type: "object",
253
+ properties: {
254
+ repo: { type: "array", items: { type: "string" } },
255
+ overlays: { type: "array", items: { type: "string", enum: ["org", "repo", "public"] } },
256
+ sensitivity: { type: "string", enum: ["public", "internal", "restricted"] },
257
+ scopes: { type: "array", items: { type: "string" } },
258
+ roles: { type: "array", items: { type: "string" } }
259
+ },
260
+ additionalProperties: false
261
+ },
262
+ overlayOrder: { type: "array", items: { type: "string", enum: ["org", "repo", "public"] } },
263
+ budget: {
264
+ type: "object",
265
+ properties: {
266
+ maxTokens: { type: "number" },
267
+ maxCostUsd: { type: "number" },
268
+ costPer1kTokensUsd: { type: "number" }
269
+ },
270
+ additionalProperties: false
271
+ }
272
+ },
273
+ required: ["subject"]
274
+ }
275
+ },
276
+ {
277
+ name: "remember",
278
+ description: "Store a value in memory",
279
+ inputSchema: {
280
+ type: "object",
281
+ properties: {
282
+ key: { type: "string" },
283
+ value: {},
284
+ scope: {
285
+ type: "string",
286
+ enum: ["working", "session", "long-term", "shared"],
287
+ default: "session"
288
+ },
289
+ sessionId: { type: "string" },
290
+ taskId: { type: "string" },
291
+ repo: { type: "string" },
292
+ persona: { type: "string" },
293
+ ttl: { type: "number" },
294
+ tags: { type: "array", items: { type: "string" } }
295
+ },
296
+ required: ["key", "value"]
297
+ }
298
+ },
299
+ {
300
+ name: "recall",
301
+ description: "Retrieve a value from memory",
302
+ inputSchema: {
303
+ type: "object",
304
+ properties: {
305
+ key: { type: "string" },
306
+ scope: {
307
+ type: "string",
308
+ enum: ["working", "session", "long-term", "shared", "all"],
309
+ default: "all"
310
+ },
311
+ sessionId: { type: "string" },
312
+ taskId: { type: "string" },
313
+ repo: { type: "string" },
314
+ persona: { type: "string" }
315
+ },
316
+ required: ["key"]
317
+ }
318
+ },
319
+ {
320
+ name: "run_task",
321
+ description: "Execute a task in BaselineOS",
322
+ inputSchema: {
323
+ type: "object",
324
+ properties: {
325
+ title: { type: "string" },
326
+ description: { type: "string" },
327
+ priority: {
328
+ type: "string",
329
+ enum: ["critical", "high", "medium", "low"],
330
+ default: "medium"
331
+ },
332
+ requiredCapabilities: { type: "array", items: { type: "string" } },
333
+ acceptanceCriteria: { type: "array" },
334
+ context: { type: "object" },
335
+ blocking: { type: "boolean", default: false },
336
+ timeout: { type: "number", default: 3e5 },
337
+ allowHighRisk: { type: "boolean", default: false },
338
+ reason: { type: "string" }
339
+ },
340
+ required: ["title", "description"]
341
+ }
342
+ },
343
+ {
344
+ name: "list_tasks",
345
+ description: "List tasks by status",
346
+ inputSchema: {
347
+ type: "object",
348
+ properties: {
349
+ status: {
350
+ type: "string",
351
+ enum: [
352
+ "pending",
353
+ "planning",
354
+ "executing",
355
+ "verifying",
356
+ "reviewing",
357
+ "correcting",
358
+ "completed",
359
+ "failed",
360
+ "blocked"
361
+ ]
362
+ }
363
+ }
364
+ }
365
+ },
366
+ {
367
+ name: "list_workflows",
368
+ description: "List registered workflows",
369
+ inputSchema: {
370
+ type: "object",
371
+ properties: {}
372
+ }
373
+ },
374
+ {
375
+ name: "run_workflow",
376
+ description: "Execute a workflow by ID",
377
+ inputSchema: {
378
+ type: "object",
379
+ properties: {
380
+ workflowId: { type: "string" },
381
+ title: { type: "string" },
382
+ description: { type: "string" },
383
+ priority: {
384
+ type: "string",
385
+ enum: ["critical", "high", "medium", "low"],
386
+ default: "medium"
387
+ },
388
+ requiredCapabilities: { type: "array", items: { type: "string" } },
389
+ acceptanceCriteria: { type: "array" },
390
+ context: { type: "object" },
391
+ blocking: { type: "boolean", default: false },
392
+ timeout: { type: "number", default: 3e5 },
393
+ allowHighRisk: { type: "boolean", default: false },
394
+ reason: { type: "string" }
395
+ },
396
+ required: ["workflowId"]
397
+ }
398
+ },
399
+ {
400
+ name: "get_checkpoint",
401
+ description: "Get checkpoint by ID",
402
+ inputSchema: {
403
+ type: "object",
404
+ properties: {
405
+ checkpointId: { type: "string" },
406
+ allowHighRisk: { type: "boolean", default: false },
407
+ reason: { type: "string" }
408
+ },
409
+ required: ["checkpointId"]
410
+ }
411
+ },
412
+ {
413
+ name: "recover_checkpoint",
414
+ description: "Recover a task from checkpoint",
415
+ inputSchema: {
416
+ type: "object",
417
+ properties: {
418
+ checkpointId: { type: "string" }
419
+ },
420
+ required: ["checkpointId"]
421
+ }
422
+ },
423
+ {
424
+ name: "get_task_audit",
425
+ description: "Get audit trail for a task",
426
+ inputSchema: {
427
+ type: "object",
428
+ properties: {
429
+ taskId: { type: "string" }
430
+ },
431
+ required: ["taskId"]
432
+ }
433
+ },
434
+ {
435
+ name: "get_evidence_bundle",
436
+ description: "Get evidence bundle for a task",
437
+ inputSchema: {
438
+ type: "object",
439
+ properties: {
440
+ taskId: { type: "string" }
441
+ },
442
+ required: ["taskId"]
443
+ }
444
+ },
445
+ {
446
+ name: "get_task",
447
+ description: "Get a specific task by ID",
448
+ inputSchema: {
449
+ type: "object",
450
+ properties: {
451
+ taskId: { type: "string" }
452
+ },
453
+ required: ["taskId"]
454
+ }
455
+ },
456
+ {
457
+ name: "stats",
458
+ description: "Get BaselineOS system stats",
459
+ inputSchema: {
460
+ type: "object",
461
+ properties: {}
462
+ }
463
+ },
464
+ {
465
+ name: "get_tool_risks",
466
+ description: "Get risk scoring for MCP tools",
467
+ inputSchema: {
468
+ type: "object",
469
+ properties: {}
470
+ }
471
+ }
472
+ ];
473
+ }
474
+ getResources() {
475
+ return [
476
+ {
477
+ uri: "baseline://tasks",
478
+ name: "Tasks",
479
+ description: "Task list and status",
480
+ mimeType: "application/json"
481
+ },
482
+ {
483
+ uri: "baseline://agents",
484
+ name: "Agents",
485
+ description: "Agent registry",
486
+ mimeType: "application/json"
487
+ },
488
+ {
489
+ uri: "baseline://stats",
490
+ name: "Stats",
491
+ description: "System statistics",
492
+ mimeType: "application/json"
493
+ }
494
+ ];
495
+ }
496
+ async handleToolCall(name, args) {
497
+ const riskDecision = this.enforceToolRisk(name, args);
498
+ if (!riskDecision.allowed) {
499
+ return riskDecision.response ?? {
500
+ error: "escalation_required",
501
+ tool: name,
502
+ risk: { level: "high", requiresEscalation: true, reason: "Escalation required" },
503
+ next: "retry_with_escalation=true"
504
+ };
505
+ }
506
+ switch (name) {
507
+ case "search_knowledge": {
508
+ const query = String(args.query ?? "");
509
+ const limit = typeof args.limit === "number" ? args.limit : 5;
510
+ const policy = parsePolicy(args.policy);
511
+ return this.baseline.search(query, { limit, policy });
512
+ }
513
+ case "get_context": {
514
+ const subject = String(args.subject ?? "");
515
+ const level = parseLevel(args.level);
516
+ const policy = parsePolicy(args.policy);
517
+ const overlayOrder = parseOverlayOrder(args.overlayOrder);
518
+ const budget = parseBudget(args.budget);
519
+ return this.baseline.getContext(subject, level, { policy, overlayOrder, budget });
520
+ }
521
+ case "get_context_delta": {
522
+ const subject = String(args.subject ?? "");
523
+ const level = parseLevel(args.level);
524
+ const policy = parsePolicy(args.policy);
525
+ const overlayOrder = parseOverlayOrder(args.overlayOrder);
526
+ const known = Array.isArray(args.known) ? args.known : void 0;
527
+ const budget = parseBudget(args.budget);
528
+ return this.baseline.getContextDelta(subject, level, { policy, overlayOrder, known, budget });
529
+ }
530
+ case "remember": {
531
+ const key = String(args.key ?? "");
532
+ const value = args.value;
533
+ const scope = parseMemoryScope(args.scope);
534
+ await this.baseline.remember(key, value, {
535
+ scope,
536
+ sessionId: typeof args.sessionId === "string" ? args.sessionId : void 0,
537
+ taskId: typeof args.taskId === "string" ? args.taskId : void 0,
538
+ repo: typeof args.repo === "string" ? args.repo : void 0,
539
+ persona: typeof args.persona === "string" ? args.persona : void 0,
540
+ ttl: typeof args.ttl === "number" ? args.ttl : void 0,
541
+ tags: Array.isArray(args.tags) ? args.tags : void 0
542
+ });
543
+ return { status: "ok" };
544
+ }
545
+ case "recall": {
546
+ const key = String(args.key ?? "");
547
+ const scope = parseRetrieveScope(args.scope);
548
+ return { value: await this.baseline.recall(key, {
549
+ scope,
550
+ sessionId: typeof args.sessionId === "string" ? args.sessionId : void 0,
551
+ taskId: typeof args.taskId === "string" ? args.taskId : void 0,
552
+ repo: typeof args.repo === "string" ? args.repo : void 0,
553
+ persona: typeof args.persona === "string" ? args.persona : void 0
554
+ }) };
555
+ }
556
+ case "run_task": {
557
+ const input = {
558
+ title: String(args.title ?? ""),
559
+ description: String(args.description ?? ""),
560
+ priority: parseTaskPriority(args.priority),
561
+ requiredCapabilities: Array.isArray(args.requiredCapabilities) ? args.requiredCapabilities : [],
562
+ acceptanceCriteria: parseAcceptanceCriteria(args.acceptanceCriteria),
563
+ context: args.context && typeof args.context === "object" ? args.context : {}
564
+ };
565
+ const handle = await this.baseline.run(input);
566
+ const blocking = Boolean(args.blocking);
567
+ if (blocking) {
568
+ const task = await handle.wait(typeof args.timeout === "number" ? args.timeout : 3e5);
569
+ return { task };
570
+ }
571
+ return { taskId: handle.id, status: handle.status };
572
+ }
573
+ case "list_tasks": {
574
+ const status = parseTaskStatus(args.status);
575
+ return this.baseline.listTasks(status ? { status } : void 0);
576
+ }
577
+ case "list_workflows": {
578
+ return this.baseline.listWorkflows();
579
+ }
580
+ case "run_workflow": {
581
+ const workflowId = String(args.workflowId ?? "");
582
+ const handle = await this.baseline.runWorkflow(workflowId, {
583
+ title: typeof args.title === "string" ? args.title : void 0,
584
+ description: typeof args.description === "string" ? args.description : void 0,
585
+ priority: parseTaskPriority(args.priority),
586
+ requiredCapabilities: Array.isArray(args.requiredCapabilities) ? args.requiredCapabilities : void 0,
587
+ acceptanceCriteria: parseAcceptanceCriteria(args.acceptanceCriteria),
588
+ context: args.context && typeof args.context === "object" ? args.context : void 0
589
+ });
590
+ const blocking = Boolean(args.blocking);
591
+ if (blocking) {
592
+ const task = await handle.wait(typeof args.timeout === "number" ? args.timeout : 3e5);
593
+ return { task };
594
+ }
595
+ return { taskId: handle.id, status: handle.status };
596
+ }
597
+ case "get_checkpoint": {
598
+ const checkpointId = String(args.checkpointId ?? "");
599
+ const checkpoint = this.baseline.loadCheckpoint(checkpointId);
600
+ if (!checkpoint) return { error: "not_found" };
601
+ return { checkpoint };
602
+ }
603
+ case "recover_checkpoint": {
604
+ const checkpointId = String(args.checkpointId ?? "");
605
+ const task = this.baseline.recoverTaskFromCheckpoint(checkpointId);
606
+ if (!task) return { error: "not_found" };
607
+ return { task };
608
+ }
609
+ case "get_task_audit": {
610
+ const taskId = String(args.taskId ?? "");
611
+ return { taskId, audit: this.baseline.getAuditTrail(taskId) };
612
+ }
613
+ case "get_evidence_bundle": {
614
+ const taskId = String(args.taskId ?? "");
615
+ return { taskId, bundle: this.baseline.getEvidenceBundle(taskId) };
616
+ }
617
+ case "get_task": {
618
+ const taskId = String(args.taskId ?? "");
619
+ const task = this.baseline.getTask(taskId);
620
+ if (!task) return { error: "not_found" };
621
+ return task;
622
+ }
623
+ case "stats": {
624
+ return this.baseline.getStats();
625
+ }
626
+ case "get_tool_risks": {
627
+ return { tools: TOOL_RISKS };
628
+ }
629
+ default:
630
+ throw new Error(`Unknown tool: ${name}`);
631
+ }
632
+ }
633
+ enforceToolRisk(name, args) {
634
+ const risk = TOOL_RISKS[name];
635
+ if (!risk || !risk.requiresEscalation) {
636
+ return { allowed: true };
637
+ }
638
+ const allowHighRisk = args.allowHighRisk === true;
639
+ const reason = typeof args.reason === "string" ? args.reason.trim() : "";
640
+ if (!allowHighRisk || reason.length === 0) {
641
+ return {
642
+ allowed: false,
643
+ response: {
644
+ error: "escalation_required",
645
+ tool: name,
646
+ risk,
647
+ next: "Retry with { allowHighRisk: true, reason: '...' } after supervisor approval."
648
+ }
649
+ };
650
+ }
651
+ return { allowed: true };
652
+ }
653
+ async readResource(uri) {
654
+ switch (uri) {
655
+ case "baseline://tasks":
656
+ return this.baseline.listTasks();
657
+ case "baseline://agents":
658
+ return this.baseline.listAgents();
659
+ case "baseline://stats":
660
+ return this.baseline.getStats();
661
+ default:
662
+ return { error: "not_found" };
663
+ }
664
+ }
665
+ };
666
+ /**
667
+ * BaselineOS MCP Server
668
+ *
669
+ * Model Context Protocol server for Claude Desktop and other MCP clients.
670
+ *
671
+ * @license Apache-2.0
672
+ */
673
+
674
+ export { MCPServer };
675
+ //# sourceMappingURL=server.js.map
676
+ //# sourceMappingURL=server.js.map