@kb-labs/scaffold 2.29.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 (59) hide show
  1. package/dist/commands/doctor.d.ts +15 -0
  2. package/dist/commands/doctor.js +63 -0
  3. package/dist/commands/doctor.js.map +1 -0
  4. package/dist/commands/scaffold.d.ts +18 -0
  5. package/dist/commands/scaffold.js +196 -0
  6. package/dist/commands/scaffold.js.map +1 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +114 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/manifest.d.ts +75 -0
  11. package/dist/manifest.js +114 -0
  12. package/dist/manifest.js.map +1 -0
  13. package/package.json +55 -0
  14. package/templates/adapter/blocks/base/block.yaml +4 -0
  15. package/templates/adapter/blocks/base/files/README.md.eta +28 -0
  16. package/templates/adapter/blocks/base/files/package.json.eta +37 -0
  17. package/templates/adapter/blocks/base/files/src/manifest.ts.eta +24 -0
  18. package/templates/adapter/blocks/base/files/tsconfig.json +8 -0
  19. package/templates/adapter/blocks/base/files/tsup.config.ts +10 -0
  20. package/templates/adapter/blocks/base/files/vitest.config.ts +12 -0
  21. package/templates/adapter/blocks/provider-example/block.yaml +6 -0
  22. package/templates/adapter/blocks/provider-example/files/src/index.ts.eta +6 -0
  23. package/templates/adapter/blocks/provider-example/files/src/llm.ts.eta +46 -0
  24. package/templates/adapter/entity.yaml +37 -0
  25. package/templates/plugin/blocks/base/block.yaml +5 -0
  26. package/templates/plugin/blocks/base/files/README.md.eta +54 -0
  27. package/templates/plugin/blocks/base/files/package.json.eta +14 -0
  28. package/templates/plugin/blocks/base/files/packages/__name__-contracts/package.json.eta +29 -0
  29. package/templates/plugin/blocks/base/files/packages/__name__-contracts/src/index.ts.eta +14 -0
  30. package/templates/plugin/blocks/base/files/packages/__name__-contracts/tsconfig.json +8 -0
  31. package/templates/plugin/blocks/base/files/packages/__name__-contracts/tsup.config.ts +10 -0
  32. package/templates/plugin/blocks/base/files/packages/__name__-contracts/vitest.config.ts +12 -0
  33. package/templates/plugin/blocks/base/files/packages/__name__-core/package.json.eta +33 -0
  34. package/templates/plugin/blocks/base/files/packages/__name__-core/src/hello.ts.eta +59 -0
  35. package/templates/plugin/blocks/base/files/packages/__name__-core/src/index.ts.eta +1 -0
  36. package/templates/plugin/blocks/base/files/packages/__name__-core/tests/hello.test.ts.eta +16 -0
  37. package/templates/plugin/blocks/base/files/packages/__name__-core/tsconfig.json +8 -0
  38. package/templates/plugin/blocks/base/files/packages/__name__-core/tsup.config.ts +10 -0
  39. package/templates/plugin/blocks/base/files/packages/__name__-core/vitest.config.ts +12 -0
  40. package/templates/plugin/blocks/base/files/packages/__name__-entry/eslint.config.js +3 -0
  41. package/templates/plugin/blocks/base/files/packages/__name__-entry/package.json.eta +41 -0
  42. package/templates/plugin/blocks/base/files/packages/__name__-entry/src/commands/hello.ts.eta +39 -0
  43. package/templates/plugin/blocks/base/files/packages/__name__-entry/src/index.ts.eta +4 -0
  44. package/templates/plugin/blocks/base/files/packages/__name__-entry/tsconfig.json +8 -0
  45. package/templates/plugin/blocks/base/files/packages/__name__-entry/tsup.config.ts +10 -0
  46. package/templates/plugin/blocks/base/files/packages/__name__-entry/vitest.config.ts +12 -0
  47. package/templates/plugin/blocks/base/files/pnpm-workspace.yaml.eta +3 -0
  48. package/templates/plugin/blocks/base/files/tsconfig.base.json +3 -0
  49. package/templates/plugin/blocks/base/manifest.patch.yaml +28 -0
  50. package/templates/plugin/blocks/base/manifest.snippets.yaml +4 -0
  51. package/templates/plugin/blocks/cli/block.yaml +5 -0
  52. package/templates/plugin/blocks/cli/files/packages/__name__-entry/src/commands/ping.ts.eta +25 -0
  53. package/templates/plugin/blocks/cli/manifest.patch.yaml +14 -0
  54. package/templates/plugin/blocks/contracts/block.yaml +5 -0
  55. package/templates/plugin/blocks/contracts/files/packages/__name__-contracts/src/events.ts.eta +13 -0
  56. package/templates/plugin/blocks/rest/block.yaml +6 -0
  57. package/templates/plugin/blocks/rest/files/packages/__name__-entry/src/rest/hello.ts.eta +22 -0
  58. package/templates/plugin/blocks/rest/manifest.patch.yaml +9 -0
  59. package/templates/plugin/entity.yaml +39 -0
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "<%= it.scope ? it.scope + '/' : '' %><%= it.name %>-entry",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "V3 manifest + CLI handlers for <%= it.name %>",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./plugin-manifest": {
14
+ "import": "./dist/manifest.js",
15
+ "types": "./dist/manifest.d.ts"
16
+ }
17
+ },
18
+ "kb": {
19
+ "manifest": "./dist/manifest.js"
20
+ },
21
+ "files": ["dist"],
22
+ "sideEffects": false,
23
+ "scripts": {
24
+ "clean": "rimraf dist",
25
+ "build": "tsup",
26
+ "type-check": "tsc --noEmit",
27
+ "test": "vitest run --passWithNoTests"
28
+ },
29
+ "dependencies": {
30
+ "<%= it.scope ? it.scope + '/' : '' %><%= it.name %>-core": "<%= it.mode === 'in-workspace' ? 'workspace:*' : '^0.1.0' %>",
31
+ "<%= it.scope ? it.scope + '/' : '' %><%= it.name %>-contracts": "<%= it.mode === 'in-workspace' ? 'workspace:*' : '^0.1.0' %>",
32
+ "@kb-labs/sdk": "<%= it.mode === 'in-workspace' ? 'workspace:*' : '^' + it.versions.sdk %>"
33
+ },
34
+ "devDependencies": {
35
+ "@kb-labs/devkit": "<%= it.mode === 'in-workspace' ? 'workspace:*' : '^' + it.versions.devkit %>",
36
+ "rimraf": "^6.0.1",
37
+ "tsup": "^8.5.0",
38
+ "typescript": "^5.6.3",
39
+ "vitest": "^3.2.4"
40
+ }
41
+ }
@@ -0,0 +1,39 @@
1
+ import { defineCommand, type PluginContextV3 } from '@kb-labs/sdk';
2
+ import { hello } from '<%= it.scope ? it.scope + '/' : '' %><%= it.name %>-core';
3
+
4
+ type HelloFlags = {
5
+ who?: string;
6
+ json?: boolean;
7
+ };
8
+
9
+ type HelloResult = {
10
+ exitCode: number;
11
+ result?: { greeting: string };
12
+ };
13
+
14
+ /**
15
+ * `kb <%= it.name %> hello` — prints a friendly greeting.
16
+ *
17
+ * This handler demonstrates the bare minimum: receive flags, call into
18
+ * `-core`, write output via `ctx.ui`. As you grow, reach for the patterns
19
+ * sketched inside `<%= it.name %>-core/src/hello.ts` — LLM calls, caching,
20
+ * structured logging — ALL through `@kb-labs/sdk`.
21
+ */
22
+ export default defineCommand({
23
+ id: '<%= it.name %>:hello',
24
+ description: 'Say hello from <%= it.name %>',
25
+
26
+ handler: {
27
+ async execute(ctx: PluginContextV3, input: HelloFlags): Promise<HelloResult> {
28
+ const { greeting } = hello({ who: input.who ?? 'World' });
29
+
30
+ if (input.json) {
31
+ ctx.ui?.json?.({ greeting });
32
+ } else {
33
+ ctx.ui?.info?.(greeting);
34
+ }
35
+
36
+ return { exitCode: 0, result: { greeting } };
37
+ },
38
+ },
39
+ });
@@ -0,0 +1,4 @@
1
+ // Re-export the manifest as a side-channel for tooling that imports the
2
+ // package directly (e.g. the marketplace linker). The primary entry point
3
+ // is the "kb.manifest" field in package.json pointing at ./dist/manifest.js.
4
+ export { default as manifest } from './manifest.js';
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@kb-labs/devkit/tsconfig/node.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src"]
8
+ }
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'tsup';
2
+ import nodePreset from '@kb-labs/devkit/tsup/node';
3
+
4
+ export default defineConfig({
5
+ ...nodePreset,
6
+ entry: ['src/index.ts', 'src/manifest.ts', 'src/commands/*.ts'],
7
+ dts: { resolve: true, skipLibCheck: true },
8
+ clean: true,
9
+ sourcemap: true,
10
+ });
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import baseConfig from '@kb-labs/devkit/vitest/node';
3
+
4
+ export default defineConfig({
5
+ ...baseConfig,
6
+ test: {
7
+ ...baseConfig.test,
8
+ globals: true,
9
+ include: ['tests/**/*.test.ts', 'src/**/*.test.ts'],
10
+ environment: 'node',
11
+ },
12
+ });
@@ -0,0 +1,3 @@
1
+ <% if (it.vars.mode === 'standalone') { %>packages:
2
+ - packages/*
3
+ <% } else { %><!--@@scaffold:skip@@--><% } %>
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "@kb-labs/devkit/tsconfig/base.json"
3
+ }
@@ -0,0 +1,28 @@
1
+ schema: kb.plugin/3
2
+ id: "<%= it.scope ? it.scope + '/' : '' %><%= it.name %>"
3
+ version: "0.1.0"
4
+ display:
5
+ name: "<%= it.name %>"
6
+ description: "<%= it.vars.description %>"
7
+ cli:
8
+ groupMeta:
9
+ - name: "<%= it.name %>"
10
+ description: "<%= it.vars.description %>"
11
+ commands:
12
+ - id: hello
13
+ group: "<%= it.name %>"
14
+ describe: "Say hello from <%= it.name %>"
15
+ handler: "./commands/hello.js#default"
16
+ handlerPath: "./commands/hello.js"
17
+ flags:
18
+ - name: who
19
+ type: string
20
+ description: "Who to greet"
21
+ default: World
22
+ - name: json
23
+ type: boolean
24
+ description: "Emit JSON instead of text"
25
+ examples:
26
+ - "kb <%= it.name %> hello"
27
+ - "kb <%= it.name %> hello --who=Developer"
28
+ - "kb <%= it.name %> hello --json"
@@ -0,0 +1,4 @@
1
+ imports:
2
+ - "import { combinePermissions, kbPlatformPreset } from '@kb-labs/sdk';"
3
+ permissions:
4
+ - "with(kbPlatformPreset)"
@@ -0,0 +1,5 @@
1
+ id: cli
2
+ describe: |
3
+ Adds a second CLI command (`ping`) as an example of how to register
4
+ additional commands. Requires `base`.
5
+ requires: [base]
@@ -0,0 +1,25 @@
1
+ import { defineCommand, type PluginContextV3 } from '@kb-labs/sdk';
2
+
3
+ type PingFlags = { json?: boolean };
4
+
5
+ /**
6
+ * `kb <%= it.name %> ping` — a second command to show how to add more.
7
+ * Duplicate this file, add an entry in `manifest.ts` under `cli.commands[]`,
8
+ * and you have a new command.
9
+ */
10
+ export default defineCommand({
11
+ id: '<%= it.name %>:ping',
12
+ description: 'Health ping for <%= it.name %>',
13
+
14
+ handler: {
15
+ async execute(ctx: PluginContextV3, input: PingFlags) {
16
+ const payload = { ok: true, at: new Date().toISOString() };
17
+ if (input.json) {
18
+ ctx.ui?.json?.(payload);
19
+ } else {
20
+ ctx.ui?.info?.(`pong @ ${payload.at}`);
21
+ }
22
+ return { exitCode: 0, result: payload };
23
+ },
24
+ },
25
+ });
@@ -0,0 +1,14 @@
1
+ cli:
2
+ commands:
3
+ - id: ping
4
+ group: "<%= it.name %>"
5
+ describe: "Health ping for <%= it.name %>"
6
+ handler: "./commands/ping.js#default"
7
+ handlerPath: "./commands/ping.js"
8
+ flags:
9
+ - name: json
10
+ type: boolean
11
+ description: "Emit JSON instead of text"
12
+ examples:
13
+ - "kb <%= it.name %> ping"
14
+ - "kb <%= it.name %> ping --json"
@@ -0,0 +1,5 @@
1
+ id: contracts
2
+ describe: |
3
+ Seeds the contracts package with a second types file (`events.ts`) to
4
+ demonstrate how to organise multiple type modules. Requires `base`.
5
+ requires: [base]
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Example event shapes — expand as the plugin grows.
3
+ *
4
+ * Contracts are deliberately small: put ONLY the types that both `-core`
5
+ * and `-entry` need to agree on here. Internal types belong in their
6
+ * respective packages.
7
+ */
8
+
9
+ export interface GreetingEmitted {
10
+ kind: '<%= it.name %>.greeting.emitted';
11
+ who: string;
12
+ at: string;
13
+ }
@@ -0,0 +1,6 @@
1
+ id: rest
2
+ describe: |
3
+ Adds a REST route (`GET /<name>/hello`) backed by the same `-core` logic.
4
+ Routes are handled through the gateway when the host plugin runs.
5
+ Requires `base`.
6
+ requires: [base]
@@ -0,0 +1,22 @@
1
+ import { defineRoute, type PluginContextV3 } from '@kb-labs/sdk';
2
+ import { hello } from '<%= it.scope ? it.scope + '/' : '' %><%= it.name %>-core';
3
+
4
+ type HelloQuery = { who?: string };
5
+
6
+ /**
7
+ * `GET /<%= it.name %>/hello?who=World` — the REST twin of the CLI command.
8
+ *
9
+ * Route handlers receive the parsed query/body through the second argument.
10
+ * Keep them thin: call into `-core`, return the response shape.
11
+ */
12
+ export default defineRoute({
13
+ id: '<%= it.name %>:rest:hello',
14
+ description: 'Say hello over HTTP',
15
+
16
+ handler: {
17
+ async execute(_ctx: PluginContextV3, input: HelloQuery) {
18
+ const { greeting } = hello({ who: input.who ?? 'World' });
19
+ return { status: 200, body: { greeting } };
20
+ },
21
+ },
22
+ });
@@ -0,0 +1,9 @@
1
+ rest:
2
+ basePath: "/<%= it.name %>"
3
+ routes:
4
+ - id: hello
5
+ method: GET
6
+ path: "/hello"
7
+ handler: "./rest/hello.js#default"
8
+ handlerPath: "./rest/hello.js"
9
+ describe: "Say hello over HTTP"
@@ -0,0 +1,39 @@
1
+ id: plugin
2
+ displayName: KB Labs Plugin
3
+ description: |
4
+ A KB Labs plugin: three workspace packages (entry, core, contracts) that
5
+ register CLI commands, REST routes, Studio pages, or daemons via a V3
6
+ manifest. Everything extends @kb-labs/devkit configs and talks to the
7
+ platform exclusively through @kb-labs/sdk.
8
+
9
+ output: .kb/plugins/<%= it.name %>
10
+ manifestTarget: packages/<%= it.name %>-entry/src/manifest.ts
11
+
12
+ variables:
13
+ - name: scope
14
+ type: string
15
+ describe: npm scope (e.g. @kb-labs, @acme). Leave blank for unscoped.
16
+ default: "@kb-labs"
17
+ validate: npmScope
18
+ - name: description
19
+ type: string
20
+ describe: Short description of the plugin
21
+ default: A KB Labs plugin
22
+ - name: license
23
+ type: string
24
+ describe: License identifier
25
+ default: MIT
26
+ - name: mode
27
+ type: select
28
+ describe: Where will this plugin live?
29
+ default: in-workspace
30
+ choices:
31
+ - value: in-workspace
32
+ label: Inside an existing KB Labs workspace (use workspace:* deps)
33
+ - value: standalone
34
+ label: Standalone repo (semver-pinned deps, own pnpm-workspace.yaml)
35
+
36
+ defaults:
37
+ blocks:
38
+ - base
39
+ - cli