@kairos-sdk/core 0.5.1 → 0.6.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.
Files changed (42) hide show
  1. package/README.md +121 -15
  2. package/dist/{chunk-VPPWTMRJ.js → chunk-2ZHNO37N.js} +48 -4
  3. package/dist/chunk-2ZHNO37N.js.map +1 -0
  4. package/dist/chunk-GG4B4TYG.js +153 -0
  5. package/dist/chunk-GG4B4TYG.js.map +1 -0
  6. package/dist/{chunk-MYAGTDQ2.js → chunk-PCNW5ZUD.js} +2 -2
  7. package/dist/chunk-SC6CLQZB.js +144 -0
  8. package/dist/chunk-SC6CLQZB.js.map +1 -0
  9. package/dist/chunk-SQS4QHDH.js +44 -0
  10. package/dist/chunk-SQS4QHDH.js.map +1 -0
  11. package/dist/{chunk-V2IZBZGB.js → chunk-STG7Z2SS.js} +2 -2
  12. package/dist/{chunk-GVZKMS53.js → chunk-YOQTEVDB.js} +4 -4
  13. package/dist/cli.cjs +647 -3
  14. package/dist/cli.cjs.map +1 -1
  15. package/dist/cli.js +239 -4
  16. package/dist/cli.js.map +1 -1
  17. package/dist/index.cjs +385 -5
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +86 -3
  20. package/dist/index.d.ts +86 -3
  21. package/dist/index.js +19 -5
  22. package/dist/mcp-server.cjs +47 -3
  23. package/dist/mcp-server.cjs.map +1 -1
  24. package/dist/mcp-server.js +2 -2
  25. package/dist/pack-builder-RTQWXGIS.js +9 -0
  26. package/dist/pack-builder-RTQWXGIS.js.map +1 -0
  27. package/dist/pack-exporter-KFNLSP5V.js +7 -0
  28. package/dist/pack-exporter-KFNLSP5V.js.map +1 -0
  29. package/dist/pack-validator-HZPB2XJ3.js +7 -0
  30. package/dist/pack-validator-HZPB2XJ3.js.map +1 -0
  31. package/dist/{reader-B5mV20H6.d.ts → reader-CfWGpL4V.d.cts} +2 -1
  32. package/dist/{reader-B5mV20H6.d.cts → reader-CfWGpL4V.d.ts} +2 -1
  33. package/dist/standalone.cjs +43 -3
  34. package/dist/standalone.cjs.map +1 -1
  35. package/dist/standalone.d.cts +1 -1
  36. package/dist/standalone.d.ts +1 -1
  37. package/dist/standalone.js +2 -2
  38. package/package.json +1 -1
  39. package/dist/chunk-VPPWTMRJ.js.map +0 -1
  40. /package/dist/{chunk-MYAGTDQ2.js.map → chunk-PCNW5ZUD.js.map} +0 -0
  41. /package/dist/{chunk-V2IZBZGB.js.map → chunk-STG7Z2SS.js.map} +0 -0
  42. /package/dist/{chunk-GVZKMS53.js.map → chunk-YOQTEVDB.js.map} +0 -0
package/README.md CHANGED
@@ -4,14 +4,14 @@
4
4
  [![npm version](https://img.shields.io/npm/v/@kairos-sdk/core)](https://www.npmjs.com/package/@kairos-sdk/core)
5
5
  [![npm downloads](https://img.shields.io/npm/dw/@kairos-sdk/core)](https://www.npmjs.com/package/@kairos-sdk/core)
6
6
 
7
- **Turn plain English into deployed n8n workflows validated, corrected, and deployed in one call.**
7
+ **Kairos is an AI workflow delivery engine for n8n. Give it a business context and it generates, validates, deploys, and documents a complete workflow pack — then learns from real executions and repairs over time.**
8
8
 
9
9
  ![Kairos SDK Demo](demo.gif)
10
10
 
11
- Kairos turns plain-English workflow descriptions into validated, deployable n8n workflow JSON. Use it as an **MCP server** (connect to Claude Code, Claude Desktop, or any MCP host your LLM generates, Kairos validates and deploys, no Anthropic API key needed) or as a **TypeScript SDK** for programmatic control (calls Claude internally with a specialized prompt). Either way, workflows pass through a **34-rule structural validator** with automatic correction, and a local workflow library with **hybrid retrieval** (TF-IDF + node fingerprinting + outcome history + cluster reranking) injects past failure patterns into future generations. With a seeded template library, Kairos achieves **100% first-try structural validation pass rate** across 20 benchmark prompts (meaning the generated JSON is structurally valid on the first attempt — runtime behavior depends on your credentials and node configuration).
11
+ Describe your business and Kairos builds a full suite of n8n automations: it plans the workflows, generates each one via Claude, validates every node and connection against **34 structural rules**, deploys to your n8n instance, and hands back a structured document covering credentials needed, data sources, assumptions made, open questions, and a test checklist. Use it as an **MCP server** (connect to Claude Code, Claude Desktop, or any MCP host no Anthropic API key needed), a **TypeScript SDK**, or a **CLI**. With a seeded template library, Kairos achieves **100% first-try structural validation pass rate** across 20 benchmark prompts.
12
12
 
13
13
  ```ts
14
- import { Kairos } from '@kairos-sdk/core'
14
+ import { Kairos, PackBuilder } from '@kairos-sdk/core'
15
15
 
16
16
  const kairos = new Kairos({
17
17
  anthropicApiKey: process.env.ANTHROPIC_API_KEY!,
@@ -19,12 +19,20 @@ const kairos = new Kairos({
19
19
  n8nApiKey: process.env.N8N_API_KEY!,
20
20
  })
21
21
 
22
+ // Build a single workflow
22
23
  const result = await kairos.build(
23
- 'Every morning at 9am, send a message to #daily-digest on Slack saying "Good morning team!"'
24
+ 'Every morning at 9am, send a message to #daily-digest on Slack'
24
25
  )
25
-
26
- console.log(result.workflowId) // deployed workflow ID
27
- console.log(result.credentialsNeeded) // what the user still needs to configure
26
+ console.log(result.workflowId) // deployed workflow ID
27
+ console.log(result.credentialsNeeded) // what still needs configuring
28
+
29
+ // Build a complete workflow pack from a business context
30
+ const builder = new PackBuilder({ anthropicApiKey: process.env.ANTHROPIC_API_KEY!, kairos })
31
+ const plan = await builder.plan('Homecare DME operations')
32
+ const pack = await builder.build(plan)
33
+ console.log(pack.workflows.map(w => w.name)) // all deployed workflow names
34
+ console.log(pack.openQuestions) // questions to answer before activating
35
+ console.log(pack.testChecklist) // how to verify each workflow
28
36
  ```
29
37
 
30
38
  ### What Kairos does and does not do
@@ -32,10 +40,12 @@ console.log(result.credentialsNeeded) // what the user still needs to configure
32
40
  | Kairos does | Kairos does not guarantee (yet) |
33
41
  |---|---|
34
42
  | Generates valid n8n workflow JSON | Perfect business logic |
35
- | Validates structure before deploy (34 rules) | Correct credentials |
36
- | Syncs node types from your live instance | Runtime success for every API |
37
- | Learns from prior successful builds | That every workflow matches intent perfectly |
38
- | Works through MCP, SDK, or CLI | Full replacement for human review |
43
+ | Builds complete workflow packs from business context | Correct credentials or API configs |
44
+ | Validates structure before deploy (34 rules) | Runtime success for every API |
45
+ | Documents assumptions, open questions, and test steps | That every workflow matches intent perfectly |
46
+ | Syncs node types from your live instance | Full replacement for human review |
47
+ | Learns from prior builds and failures | Monitoring after deployment (coming soon) |
48
+ | Works through MCP, SDK, or CLI | — |
39
49
 
40
50
  ---
41
51
 
@@ -323,6 +333,36 @@ const result = await kairos.build(description, {
323
333
 
324
334
  ---
325
335
 
336
+ ### `new PackBuilder(options)` + `builder.plan()` + `builder.build()`
337
+
338
+ Build a complete workflow pack from a plain-English business context.
339
+
340
+ ```ts
341
+ import { Kairos, PackBuilder } from '@kairos-sdk/core'
342
+
343
+ const kairos = new Kairos({ anthropicApiKey, n8nBaseUrl, n8nApiKey })
344
+ const builder = new PackBuilder({ anthropicApiKey, kairos })
345
+
346
+ // Step 1 — plan (LLM generates workflow list, assumptions, open questions)
347
+ const plan = await builder.plan('Homecare DME business operations')
348
+ console.log(plan.workflows) // array of { name, description, purpose }
349
+ console.log(plan.openQuestions) // questions needing human answers before go-live
350
+
351
+ // Step 2 — build (deploys each workflow, aggregates credentials and test steps)
352
+ const pack = await builder.build(plan, {
353
+ dryRun: false,
354
+ activate: false,
355
+ onProgress: (wf, i, total) => console.log(`[${i+1}/${total}] ${wf.name}`),
356
+ })
357
+
358
+ console.log(pack.workflows) // deployed results with workflowId and credentialsNeeded
359
+ console.log(pack.allCredentials) // deduped credential list across all workflows
360
+ console.log(pack.sheetsColumns) // Google Sheets required per sheet
361
+ console.log(pack.testChecklist) // per-workflow test steps
362
+ ```
363
+
364
+ ---
365
+
326
366
  ### Workflow management
327
367
 
328
368
  ```ts
@@ -421,11 +461,20 @@ try {
421
461
  Deploy workflows from the command line — no code required:
422
462
 
423
463
  ```bash
424
- # Generate and deploy
464
+ # First-time setup (prompts for credentials, seeds template library, prints Claude Desktop config)
465
+ kairos init
466
+
467
+ # Generate and deploy a single workflow
425
468
  kairos build "Every morning at 9am, send a Slack digest to #daily-updates"
426
469
 
427
- # Dry run only
428
- kairos build "Monitor a webhook and log payloads" --dry-run
470
+ # Generate a complete workflow pack from a business context
471
+ kairos build-pack "Homecare DME business patient onboarding, reorder reminders, social media"
472
+
473
+ # Dry run — plan and validate without deploying
474
+ kairos build-pack "E-commerce store operations" --dry-run
475
+
476
+ # Skip confirmation prompt and build immediately
477
+ kairos build-pack "Real estate agency operations" --yes
429
478
 
430
479
  # Seed library with n8n community templates
431
480
  kairos sync-templates --max 200
@@ -442,7 +491,64 @@ kairos deactivate <workflow-id>
442
491
  kairos delete <workflow-id> --confirm
443
492
  ```
444
493
 
445
- Set your credentials as environment variables:
494
+ ### What `build-pack` outputs
495
+
496
+ After building, Kairos prints a structured document and saves a JSON file to `~/.kairos/packs/<name>.json`:
497
+
498
+ ```
499
+ Homecare DME business — Workflow Pack
500
+ ══════════════════════════════════════
501
+
502
+ Workflows Built (6/6)
503
+ ──────────────────────────────────────────────────
504
+ ✓ Weekly Social Media Content [360Xba7BEQFQUw3v]
505
+ Generate and email 3 Facebook/Instagram posts for approval each Monday
506
+ ✓ Group Home Reorder Reminders [g1Dx5hjTpV4FrkwH]
507
+ Email facility contacts when supplies are due for reorder
508
+ ✓ Monthly Newsletter [lO8YxkDiaGkZiq76]
509
+ Send AI-generated newsletter to customer mailing list on the 1st
510
+ ✓ New Customer Welcome Sequence [PrMj2DwVGfAo6VXq]
511
+ 3-email onboarding sequence triggered by webhook on customer add
512
+ ✓ Annual Equipment Check-ins [LZCIedaEnGNsKNRp]
513
+ Daily check for customers whose equipment delivery was ~1 year ago
514
+ ✓ Weekly Google Business Post [IfxKaA1MYZ4Xs3eI]
515
+ Auto-post educational content to Google Business Profile each Monday
516
+
517
+ Credentials Needed (connect once in n8n)
518
+ ──────────────────────────────────────────────────
519
+ □ Gmail OAuth2
520
+ □ Google Sheets OAuth2
521
+ □ Anthropic Claude API (HTTP Header Auth)
522
+ □ Google My Business OAuth2
523
+
524
+ Google Sheets Required
525
+ ──────────────────────────────────────────────────
526
+ □ Facility Contacts: facility_name, contact_name, contact_email, product, reorder_frequency_weeks, last_order_date
527
+ □ Customer Mailing List: name, email
528
+
529
+ Assumptions Made
530
+ ──────────────────────────────────────────────────
531
+ - Customer data is maintained in Google Sheets
532
+ - Gmail is the outbound email platform
533
+ - Owner approves social posts before publishing
534
+
535
+ Open Questions (answer before activating)
536
+ ──────────────────────────────────────────────────
537
+ ? What email address should receive social media approval emails?
538
+ ? What is the brand voice / tone for posts and newsletters?
539
+ ? Should newsletters require approval before sending to the full list?
540
+
541
+ Test Checklist
542
+ ──────────────────────────────────────────────────
543
+ Weekly Social Media Content
544
+ □ Trigger manually — verify approval email arrives with 3 posts
545
+ Group Home Reorder Reminders
546
+ □ Add a test row with last_order_date 30 days ago — verify reminder email
547
+ New Customer Welcome Sequence
548
+ □ POST {"customer_name":"Test","customer_email":"you@test.com","equipment_type":"wheelchair"} to webhook
549
+ ```
550
+
551
+ Set your credentials as environment variables or run `kairos init`:
446
552
 
447
553
  ```bash
448
554
  export ANTHROPIC_API_KEY=sk-ant-...
@@ -489,6 +489,7 @@ var N8nValidator = class {
489
489
  this.checkRule32(workflow, issues);
490
490
  this.checkRule33(workflow, issues);
491
491
  this.checkRule34(workflow, issues);
492
+ this.checkRule35(workflow, issues);
492
493
  if (Array.isArray(workflow.nodes)) {
493
494
  const nodeById = new Map(workflow.nodes.map((n) => [n.id, n.type]));
494
495
  for (const issue of issues) {
@@ -1061,6 +1062,43 @@ var N8nValidator = class {
1061
1062
  }
1062
1063
  }
1063
1064
  }
1065
+ // Rule 35 (WARN): email-sending node with no duplicate-prevention signal
1066
+ checkRule35(w, issues) {
1067
+ if (!Array.isArray(w.nodes)) return;
1068
+ const sendNodes = w.nodes.filter((node) => {
1069
+ if (node.type === "n8n-nodes-base.gmail") {
1070
+ const op = node.parameters?.["operation"];
1071
+ return !op || op === "send" || op === "sendEmail" || op === "reply";
1072
+ }
1073
+ return node.type === "n8n-nodes-base.emailSend" || node.type === "n8n-nodes-base.sendEmail";
1074
+ });
1075
+ if (sendNodes.length === 0) return;
1076
+ const workflowText = JSON.stringify(w).toLowerCase();
1077
+ const IDEMPOTENCY_SIGNALS = [
1078
+ "sent_at",
1079
+ "last_sent",
1080
+ "last_reminder",
1081
+ "processed_at",
1082
+ "already_sent",
1083
+ "email_sent",
1084
+ "notified_at",
1085
+ "reminder_sent",
1086
+ "contacted_at",
1087
+ "dedupe",
1088
+ "idempotent"
1089
+ ];
1090
+ const hasIdempotencySignal = IDEMPOTENCY_SIGNALS.some((s) => workflowText.includes(s));
1091
+ if (!hasIdempotencySignal) {
1092
+ for (const node of sendNodes) {
1093
+ this.warn(
1094
+ issues,
1095
+ 35,
1096
+ `Node "${node.name}" sends email but no duplicate-prevention signal detected \u2014 add a sent_at timestamp field, a prior-send IF check, or a deduplication key to avoid repeat sends`,
1097
+ node.id
1098
+ );
1099
+ }
1100
+ }
1101
+ }
1064
1102
  // Rule 34 (WARN): webhook path contains spaces, starts with slash, or looks like a full URL
1065
1103
  checkRule34(w, issues) {
1066
1104
  if (!Array.isArray(w.nodes)) return;
@@ -1242,7 +1280,7 @@ import { join as join4 } from "path";
1242
1280
  import { homedir as homedir3 } from "os";
1243
1281
 
1244
1282
  // src/validation/rule-metadata.ts
1245
- var VALIDATOR_RULE_IDS = Array.from({ length: 34 }, (_, i) => i + 1);
1283
+ var VALIDATOR_RULE_IDS = Array.from({ length: 35 }, (_, i) => i + 1);
1246
1284
  var RULE_PIPELINE_STAGES = {
1247
1285
  1: "node_generation",
1248
1286
  2: "node_generation",
@@ -1277,7 +1315,8 @@ var RULE_PIPELINE_STAGES = {
1277
1315
  31: "node_generation",
1278
1316
  32: "node_generation",
1279
1317
  33: "node_generation",
1280
- 34: "node_generation"
1318
+ 34: "node_generation",
1319
+ 35: "node_generation"
1281
1320
  };
1282
1321
  var RULE_EXAMPLES = {
1283
1322
  17: {
@@ -1327,6 +1366,10 @@ var RULE_EXAMPLES = {
1327
1366
  34: {
1328
1367
  bad: '"path": "/my webhook"',
1329
1368
  good: '"path": "my-webhook"'
1369
+ },
1370
+ 35: {
1371
+ bad: '"type": "n8n-nodes-base.gmail", "parameters": { "operation": "send" } // no sent_at tracking',
1372
+ good: 'Add a Set node after send that writes "sent_at": "={{ $now }}" back to the sheet, or an IF node that checks sent_at before sending'
1330
1373
  }
1331
1374
  };
1332
1375
  var RULE_MITIGATIONS = {
@@ -1363,7 +1406,8 @@ var RULE_MITIGATIONS = {
1363
1406
  31: "Add at least one condition to the if node \u2014 conditions.conditions array must be non-empty",
1364
1407
  32: "Add field assignments to the set node \u2014 assignments.assignments array must be non-empty for typeVersion 3.x",
1365
1408
  33: "Add at least one schedule rule to scheduleTrigger \u2014 rule.interval array must have at least one entry",
1366
- 34: 'Webhook path must be a relative path without spaces, leading slashes, or protocol prefixes (e.g. "my-hook")'
1409
+ 34: 'Webhook path must be a relative path without spaces, leading slashes, or protocol prefixes (e.g. "my-hook")',
1410
+ 35: "Add duplicate-prevention to email-sending workflows: a sent_at timestamp field updated after each send, or an IF node that checks prior-send status before sending"
1367
1411
  };
1368
1412
 
1369
1413
  // src/telemetry/pattern-analyzer.ts
@@ -2579,4 +2623,4 @@ export {
2579
2623
  buildSearchCorpus,
2580
2624
  FileLibrary
2581
2625
  };
2582
- //# sourceMappingURL=chunk-VPPWTMRJ.js.map
2626
+ //# sourceMappingURL=chunk-2ZHNO37N.js.map