khotan-data 0.0.1 → 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.
Files changed (51) hide show
  1. package/AGENTS.md +54 -0
  2. package/README.md +62 -0
  3. package/dist/cli.js +2585 -0
  4. package/dist/factory.cjs +2319 -0
  5. package/dist/factory.cjs.map +1 -0
  6. package/dist/factory.d.cts +475 -0
  7. package/dist/factory.d.ts +475 -0
  8. package/dist/factory.js +2311 -0
  9. package/dist/factory.js.map +1 -0
  10. package/dist/plug-client.cjs +99 -0
  11. package/dist/plug-client.cjs.map +1 -0
  12. package/dist/plug-client.d.cts +71 -0
  13. package/dist/plug-client.d.ts +71 -0
  14. package/dist/plug-client.js +96 -0
  15. package/dist/plug-client.js.map +1 -0
  16. package/dist/templates/agent-skill.md +73 -0
  17. package/dist/templates/agents.md +41 -0
  18. package/dist/templates/catch.example.ts +36 -0
  19. package/dist/templates/catch.ts +107 -0
  20. package/dist/templates/config-page.tsx +20 -0
  21. package/dist/templates/debug-index-page.tsx +101 -0
  22. package/dist/templates/debug-page.tsx +48 -0
  23. package/dist/templates/graph-page.tsx +11 -0
  24. package/dist/templates/hub.tsx +450 -0
  25. package/dist/templates/inflow.example.ts +61 -0
  26. package/dist/templates/inflow.ts +99 -0
  27. package/dist/templates/khotan-config.ts +40 -0
  28. package/dist/templates/khotan-route.ts +13 -0
  29. package/dist/templates/logs-page.tsx +9 -0
  30. package/dist/templates/logs.tsx +20 -0
  31. package/dist/templates/outflow.example.ts +52 -0
  32. package/dist/templates/outflow.ts +90 -0
  33. package/dist/templates/pass.example.ts +51 -0
  34. package/dist/templates/pass.ts +124 -0
  35. package/dist/templates/plug-debugger.tsx +1185 -0
  36. package/dist/templates/plug.example.ts +93 -0
  37. package/dist/templates/plug.ts +806 -0
  38. package/dist/templates/relay.example.ts +61 -0
  39. package/dist/templates/relay.ts +95 -0
  40. package/dist/templates/runs-table.tsx +592 -0
  41. package/dist/templates/schema.ts +424 -0
  42. package/dist/templates/skill-dashboard.md +144 -0
  43. package/dist/templates/skill-plug.md +193 -0
  44. package/dist/templates/skill-setup.md +119 -0
  45. package/dist/templates/skill-webhook.md +196 -0
  46. package/dist/templates/topology-canvas.tsx +1406 -0
  47. package/dist/templates/var-panel.tsx +276 -0
  48. package/dist/templates/webhook-events-table.tsx +241 -0
  49. package/dist/templates/wire-panel.tsx +216 -0
  50. package/dist/templates/wire.ts +155 -0
  51. package/package.json +46 -5
package/AGENTS.md ADDED
@@ -0,0 +1,54 @@
1
+ # khotan-data
2
+
3
+ Production-grade data sync, ETL, and webhook components for Next.js + Drizzle + Postgres.
4
+
5
+ ## Agent Skills
6
+
7
+ This package ships agent skills that teach coding agents how to use khotan-data.
8
+ Skills are installed into consumer projects via the CLI:
9
+
10
+ ```bash
11
+ npx khotan init --yes # Installs all skills during setup
12
+ npx khotan add skill-setup # Or install individually
13
+ ```
14
+
15
+ The installer auto-detects which coding agents are present (Cursor, Claude Code, Codex, Copilot, Kiro, Roo) and installs to all detected agent directories. It also places an `AGENTS.md` router at the project root.
16
+
17
+ ## Skill Templates
18
+
19
+ Source templates live in `src/cli/templates/`:
20
+
21
+ | Template | Skill name | Teaches |
22
+ |----------|-----------|---------|
23
+ | `skill-setup.md` | khotan-setup | Project initialization, factory config, database setup |
24
+ | `skill-plug.md` | khotan-plug | Plug authoring, auth strategies, typed endpoints |
25
+ | `skill-dashboard.md` | khotan-dashboard | Hub dashboard, plug debugger UI |
26
+ | `skill-webhook.md` | khotan-webhook | Wires, Catch, Pass, webhook flow |
27
+ | `agent-skill.md` | khotan-probe | Probe CLI for debugging plugs |
28
+
29
+ ## Agent Detection
30
+
31
+ `src/cli/agent-detect.ts` handles multi-agent installation:
32
+
33
+ | Agent | Marker directory | Skill path |
34
+ |-------|-----------------|------------|
35
+ | Cursor | `.cursor/` | `.cursor/skills/{name}/SKILL.md` |
36
+ | Claude Code | `.claude/` | `.claude/skills/{name}/SKILL.md` |
37
+ | Codex | `.agents/` | `.agents/skills/{name}/SKILL.md` |
38
+ | Copilot | `.github/` | `.github/skills/{name}/SKILL.md` |
39
+ | Kiro | `.kiro/` | `.kiro/skills/{name}/SKILL.md` |
40
+ | Roo | `.roo/` | `.roo/rules/{name}/SKILL.md` |
41
+
42
+ If no agent directories are detected, defaults to Cursor + Claude Code.
43
+
44
+ ## Package Architecture
45
+
46
+ See `openspec/` for full specifications. Key source files:
47
+
48
+ | File | Purpose |
49
+ |------|---------|
50
+ | `src/factory.ts` | Runtime core — plug registration, API routing, debug endpoints |
51
+ | `src/cli/` | CLI commands (init, add, generate, migrate, probe) |
52
+ | `src/cli/registry.ts` | Component/block registry |
53
+ | `src/cli/agent-detect.ts` | Agent detection + multi-path skill installer |
54
+ | `src/cli/compare.ts` | Schema inference + diff engine for probe --compare |
package/README.md CHANGED
@@ -4,6 +4,68 @@ Data primitives for TypeScript — ETL pipelines, transforms, and Drizzle Postgr
4
4
 
5
5
  Built for **Next.js + Drizzle + Postgres** projects. Think better-auth for data management.
6
6
 
7
+ ## CLI
8
+
9
+ Scaffold components into your Next.js + Drizzle project:
10
+
11
+ ```bash
12
+ # Initialize khotan config
13
+ npx khotan init
14
+
15
+ # Full setup (drizzle + shadcn + config in one go)
16
+ npx khotan init --full
17
+
18
+ # Add components (reusable building blocks — never create pages)
19
+ npx khotan add schema # Drizzle table definitions (plugs, flows, runs, resources, mappings)
20
+ npx khotan add plug # Fetch wrapper with auth, retry, pagination
21
+ npx khotan add inflow # Workflow-backed flow for pulling data in
22
+ npx khotan add outflow # Workflow-backed flow for pushing data out
23
+ npx khotan add relay # Workflow-backed flow for moving data between plugs
24
+ npx khotan add hub # Dashboard UI + API route + config (requires shadcn)
25
+
26
+ # Add blocks (sample pages composed from components)
27
+ npx khotan add config-page-1 # /config page that renders the KhotanHub dashboard
28
+
29
+ # Options
30
+ npx khotan add schema --force # Overwrite existing files
31
+ npx khotan add hub --yes # Auto-accept dependency install prompts
32
+ ```
33
+
34
+ ## Factory (Runtime Engine)
35
+
36
+ Register plugs, flows, and resources — the factory upserts them on boot and serves a REST API:
37
+
38
+ ```typescript
39
+ import { khotan, drizzleAdapter, toNextJsHandler } from "khotan-data/factory";
40
+ import { db } from "@/db";
41
+ import { shopifyPlug } from "@/lib/khotan/plugs/shopify";
42
+ import { shopifyProductsInflow } from "@/lib/khotan/flows/shopify-products";
43
+
44
+ const khotanData = khotan({
45
+ adapter: drizzleAdapter(db),
46
+ resources: [
47
+ { name: "products", connectField: "sku" },
48
+ ],
49
+ plugs: [
50
+ {
51
+ name: "shopify",
52
+ plug: shopifyPlug,
53
+ flows: [
54
+ shopifyProductsInflow,
55
+ ],
56
+ },
57
+ ],
58
+ });
59
+
60
+ // Next.js App Router: app/api/khotan/[...all]/route.ts
61
+ export const { GET, POST, PUT, DELETE } = toNextJsHandler(khotanData.handler);
62
+
63
+ // Start a flow through Khotan so run tracking + Workflow IDs are recorded
64
+ await khotanData.flow("products-inflow", { plugName: "shopify" }).start({
65
+ runType: "delta",
66
+ });
67
+ ```
68
+
7
69
  ## Install
8
70
 
9
71
  ```bash