@kindgi/sdk 0.0.0-bootstrap.0 → 0.1.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 (51) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +187 -1
  3. package/dist/build.d.ts +10 -0
  4. package/dist/build.d.ts.map +1 -0
  5. package/dist/build.js +11 -0
  6. package/dist/build.js.map +1 -0
  7. package/dist/client.d.ts +33 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +55 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/define.d.ts +25 -0
  12. package/dist/define.d.ts.map +1 -0
  13. package/dist/define.js +37 -0
  14. package/dist/define.js.map +1 -0
  15. package/dist/index.d.ts +17 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +19 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/runtime-config.d.ts +53 -0
  20. package/dist/runtime-config.d.ts.map +1 -0
  21. package/dist/runtime-config.js +114 -0
  22. package/dist/runtime-config.js.map +1 -0
  23. package/dist/types.d.ts +16 -0
  24. package/dist/types.d.ts.map +1 -0
  25. package/dist/types.js +4 -0
  26. package/dist/types.js.map +1 -0
  27. package/dist/webhooks.d.ts +15 -0
  28. package/dist/webhooks.d.ts.map +1 -0
  29. package/dist/webhooks.js +16 -0
  30. package/dist/webhooks.js.map +1 -0
  31. package/package.json +88 -4
  32. package/skills/kindgi-authoring-agents/SKILL.md +252 -0
  33. package/skills/kindgi-authoring-flows/SKILL.md +302 -0
  34. package/skills/kindgi-authoring-guardrails/SKILL.md +297 -0
  35. package/skills/kindgi-authoring-mcp-servers/SKILL.md +289 -0
  36. package/skills/kindgi-authoring-providers/SKILL.md +705 -0
  37. package/skills/kindgi-authoring-tools/SKILL.md +298 -0
  38. package/skills/kindgi-framework-feedback/SKILL.md +211 -0
  39. package/skills/kindgi-getting-started/SKILL.md +189 -0
  40. package/skills/kindgi-python-authoring-agents/SKILL.md +205 -0
  41. package/skills/kindgi-python-authoring-flows/SKILL.md +325 -0
  42. package/skills/kindgi-python-authoring-guardrails/SKILL.md +176 -0
  43. package/skills/kindgi-python-authoring-tools/SKILL.md +305 -0
  44. package/skills/kindgi-python-getting-started/SKILL.md +242 -0
  45. package/src/build.ts +18 -0
  46. package/src/client.ts +177 -0
  47. package/src/define.ts +75 -0
  48. package/src/index.ts +20 -0
  49. package/src/runtime-config.ts +180 -0
  50. package/src/types.ts +86 -0
  51. package/src/webhooks.ts +34 -0
@@ -0,0 +1,189 @@
1
+ ---
2
+ name: kindgi-getting-started
3
+ description: >
4
+ Bootstrap a Kindgi pack from scratch: scaffold with
5
+ kindgi init, understand the pack layout (tools / agents /
6
+ guardrails / flows), boot the dev harness with kindgi dev, and hit
7
+ the first end-to-end run with kindgi runs start. Load this when a
8
+ project has no kindgi.config.ts yet and the user asks to "add
9
+ Kindgi", "create a pack", "scaffold a Kindgi pack", "start a
10
+ new pack", or when the user needs the mental model for what a Kindgi
11
+ pack IS. Once the pack is scaffolded and you are authoring code,
12
+ switch to kindgi-authoring-tools / kindgi-authoring-agents /
13
+ kindgi-authoring-guardrails / kindgi-authoring-flows for the specific
14
+ primitive.
15
+ type: core
16
+ library: "@kindgi/sdk"
17
+ version: "0.3.4"
18
+ sdk_version: "0.0.0"
19
+ pack_languages: [node]
20
+ ---
21
+
22
+ # Getting started with Kindgi
23
+
24
+ > **Running `kindgi`:** the CLI is a devDependency of the project (`@kindgi/cli`),
25
+ > not a global command. Run it through the project's package manager —
26
+ > `pnpm exec kindgi …`, `npx --no kindgi …` (npm), `yarn kindgi …` or
27
+ > `bun run kindgi …`. Commands below are written `kindgi …` for brevity.
28
+
29
+ Scaffold a Kindgi pack — a versioned, deployable bundle
30
+ of tools, agents, guardrails, and flows — and run it end-to-end
31
+ locally.
32
+
33
+ ## What a pack IS
34
+
35
+ A pack is one directory containing four primitive kinds authored via
36
+ `@kindgi/sdk`:
37
+
38
+ - **Tools** (`tools/<name>/index.ts`) — callable units of work.
39
+ - **Agents** (`agents/<name>/index.ts`) — LLM orchestrators that call
40
+ tools.
41
+ - **Guardrails** (`guardrails/<name>/index.ts`) — safety checks that
42
+ gate agent turns.
43
+ - **Flows** (`flows/<name>/index.ts`) — declarative workflows
44
+ composing multiple nodes.
45
+
46
+ Each primitive is a single TypeScript file whose default export is the
47
+ definition: `defineTool` / `defineAgent` / `defineFlow` build tools,
48
+ agents and flows; a guardrail file default-exports its declaration and
49
+ builds its check with `defineCheck` (see
50
+ `kindgi-authoring-guardrails`). The pack indexer discovers them by
51
+ folder convention.
52
+
53
+ ## Scaffold
54
+
55
+ **A new pack:**
56
+
57
+ ```bash
58
+ npx @kindgi/cli init my-pack
59
+ cd my-pack
60
+ pnpm install
61
+ ```
62
+
63
+ **Kindgi inside an existing app** (Next.js, NestJS, …) — in the app's
64
+ root, no pack name:
65
+
66
+ ```bash
67
+ npx @kindgi/cli init
68
+ pnpm install # or the app's own package manager
69
+ ```
70
+
71
+ This adds `kindgi.config.ts` and a `kindgi/` folder beside the app's code,
72
+ and never creates env files: `kindgi dev` reads the app's own `.env` /
73
+ `.env.local`. A package a tool imports must be in the app's `dependencies`,
74
+ not `devDependencies`: the deployed pack installs production dependencies
75
+ only (see `kindgi-authoring-tools`).
76
+
77
+ Either way, `init` adds `@kindgi/sdk` and `@kindgi/cli` to the project's
78
+ `package.json`, so the project runs the `kindgi` it pins — never a global
79
+ one. (`npx @kindgi/cli` is the scoped package; a bare `npx kindgi` would
80
+ fetch an unrelated package.)
81
+
82
+ Two templates:
83
+
84
+ - `--template=minimal` (default) — folder structure only, no example
85
+ primitives. Right when you know what you want to build.
86
+ - `--template=sample` — worked kitchen-sink example (echo tool + agent
87
+ + guardrail + flow). Right for exploring the primitive kinds.
88
+
89
+ ## Boot the dev harness
90
+
91
+ ```bash
92
+ pnpm exec kindgi dev
93
+ ```
94
+
95
+ `kindgi dev` boots a local Kindgi runtime (starting the services it
96
+ needs on first run), indexes the pack, registers every primitive, and
97
+ re-registers on every save. The banner prints the API URL, the seeded
98
+ bearer token, and (if the console is bundled) the `/console/` URL.
99
+
100
+ Until a model provider is registered, agents answer with `dev-echo`, a
101
+ stand-in that calls the agent's first tool with `{"message": <userMessage>}`
102
+ and replies with what the tool returned. It checks the wiring only: it can't
103
+ fill in any other tool input or produce a typed `output` (that turn fails
104
+ with `output-schema-violation`). Register a provider
105
+ (`kindgi-authoring-providers`) before building a real agent.
106
+
107
+ ## First run
108
+
109
+ From a second terminal, with `cd my-pack`:
110
+
111
+ ```bash
112
+ pnpm exec kindgi runs start --agent=my-pack.echo-agent --input='{"userMessage":"hi"}'
113
+ ```
114
+
115
+ `my-pack.echo-agent` is the agent the `sample` template ships (`<pack-id>.echo-agent`);
116
+ a `minimal` pack has no agent until you write one.
117
+
118
+ The CLI reads `.kindgirc.json` (auto-written by `kindgi dev`) for the
119
+ API URL + token, so second-terminal commands work without flags.
120
+
121
+ Once you author your own agent, run it by its own id.
122
+
123
+ ## Layout
124
+
125
+ ```
126
+ my-pack/
127
+ ├── kindgi.config.ts # pack id + version + discovery patterns
128
+ ├── package.json # @kindgi/sdk + zod; devDependency @kindgi/cli
129
+ ├── tsconfig.json
130
+ ├── .claude/
131
+ │ └── skills/ # auto-copied from @kindgi/sdk on init
132
+ ├── tools/ # place `<name>/index.ts` per tool
133
+ ├── agents/ # place `<name>/index.ts` per agent
134
+ ├── guardrails/ # place `<name>/index.ts` per guardrail
135
+ └── flows/ # place `<name>/index.ts` per flow
136
+ ```
137
+
138
+ ## Next steps
139
+
140
+ When authoring a primitive, switch to the specific skill:
141
+
142
+ - **Adding a tool** → `kindgi-authoring-tools`
143
+ - **Adding an agent** → `kindgi-authoring-agents`
144
+ - **Adding a guardrail** → `kindgi-authoring-guardrails`
145
+ - **Adding a flow** → `kindgi-authoring-flows`
146
+
147
+ Each of those skills is auto-loaded when working in the corresponding
148
+ folder or when the user's request mentions the primitive kind.
149
+
150
+ ## Two things need the human
151
+
152
+ Most of the setup is automatable, but two require your knowledge:
153
+
154
+ - **The pack id + version** in `kindgi.config.ts` — the pack id
155
+ becomes the namespace prefix (`<pack-id>.<primitive-name>`) for
156
+ every primitive. Pick a stable kebab-case name; changing it later
157
+ breaks all published references.
158
+ - **Real LLM provider credentials** — the built-in dev-echo provider
159
+ returns canned responses (great for the loop test, useless for real
160
+ agents). It is a fallback, so it steps aside once a real provider is
161
+ registered — `kindgi providers register --preset=anthropic` with the
162
+ key in `.env`; see `kindgi-authoring-providers`.
163
+
164
+ ## References
165
+
166
+ - Full CLI surface: `kindgi --help`.
167
+ - SDK hover docs: every `@kindgi/sdk/define` + `@kindgi/sdk/types`
168
+ export ships with JSDoc — hover in your editor.
169
+ - Companion API docs: `pnpm --filter @kindgi/sdk exec typedoc`
170
+ regenerates markdown at `packages/sdk/docs/`.
171
+
172
+ ## Keeping skills up to date
173
+
174
+ Skills in `.claude/skills/` are copied at `kindgi init` time. When the
175
+ framework SDK ships a new version of a skill (better docs, corrected
176
+ example, new capabilities), the pack's local copy stays stale until
177
+ you resync. `kindgi dev` boot prints a warning when it detects drift;
178
+ run `kindgi skills sync` to pull the latest framework skills.
179
+ Local edits are preserved by default (marked `skipped-modified`);
180
+ pass `--force` to overwrite them.
181
+
182
+ ## When the framework itself is the problem
183
+
184
+ Kindgi is early. You will hit rough edges — SDK type drift, wire
185
+ schemas that silently drop a field, misleading error messages, CLI
186
+ friction. When you diagnose that the bug is in the framework (not in
187
+ your pack), load the `kindgi-framework-feedback` skill and file a
188
+ structured report with `kindgi feedback write`. Your diagnostic is
189
+ exactly what the maintainers need.
@@ -0,0 +1,205 @@
1
+ ---
2
+ name: kindgi-python-authoring-agents
3
+ description: >
4
+ Covers writing agents for a Kindgi pack in Python (the `kindgi`
5
+ package): declaring an `Agent(...)` at module level, wiring tools
6
+ (Tool objects or {id, version} refs) and guardrails, capabilities and
7
+ model choice (preferred_provider / preferred_model), conversation
8
+ policy, turn budgets, prompt template parameters, typed output from a
9
+ pydantic model, and tool-error retries. Load this whenever you are
10
+ authoring or editing code inside a Python pack's agents/ directory
11
+ (a pack whose config is `[tool.kindgi]` in pyproject.toml), defining
12
+ an agent, or when the user asks to add, modify or refactor one.
13
+ Python tools are covered by kindgi-python-authoring-tools, Python
14
+ guardrails by kindgi-python-authoring-guardrails, connecting a real
15
+ model by kindgi-authoring-providers.
16
+ type: core
17
+ library: "kindgi (Python)"
18
+ version: "0.1.0"
19
+ sdk_version: "0.0.0"
20
+ pack_languages: [python]
21
+ sources:
22
+ - sdks/python/src/kindgi/pack/define.py
23
+ - sdks/python/src/kindgi/pack/index.py
24
+ ---
25
+
26
+ # Authoring Kindgi agents in Python
27
+
28
+ > **Running `kindgi`:** a Python pack has no Node project, so the
29
+ > `kindgi` CLI is the one on `PATH`. Python commands run in the pack's
30
+ > environment: `uv run …` (or `.venv/bin/python …`).
31
+
32
+ An **agent** is a versioned, model-driven orchestrator: instructions (a
33
+ prompt template), the tools it may call, the capabilities its model
34
+ needs, guardrails that gate its answer, and an optional conversation
35
+ policy. In a Python pack it is **data**: an `Agent(...)` assigned at
36
+ module level in a file under `agents/`. The model runs in the Kindgi
37
+ runtime, not in your Python process; your Python code runs only inside
38
+ the agent's tools and guardrail checks.
39
+
40
+ ## Ask before building
41
+
42
+ "Add an agent" is a conversation opener, not a ticket. Before writing a
43
+ file, ask:
44
+
45
+ - **What should the agent do?** The purpose drives everything else.
46
+ - **Which tools does it need?** New ones, or existing ones?
47
+ - **Multi-turn or one-shot?** History changes the shape.
48
+ - **Any rules it must respect?** Those become guardrails.
49
+
50
+ The pack's sample agent proves the runtime works end to end. It is not
51
+ the shape to imitate unless the user asks for that.
52
+
53
+ ## An agent
54
+
55
+ ```python
56
+ # agents/brief_writer.py
57
+ from pydantic import BaseModel
58
+
59
+ from kindgi import Agent
60
+
61
+ from ..guardrails.citations import no_fabricated_quotes
62
+ from ..tools.citations import fetch_precedent, verify_citation
63
+
64
+
65
+ class Brief(BaseModel):
66
+ argument: str
67
+ citations: list[str]
68
+
69
+
70
+ brief_writer = Agent(
71
+ id="acme.brief-writer",
72
+ version="0.1.0",
73
+ name="Brief Writer",
74
+ description="Drafts appellate briefs from a case file; cites precedents.",
75
+ instructions=(
76
+ "You are drafting a brief in {{ jurisdiction }}. The user provides the case "
77
+ "facts; you produce a Section IV argument citing at least two precedents. "
78
+ "Call acme.verify-citation on every cite before using it. Never invent one."
79
+ ),
80
+ capabilities=[{"needs": [{"feature": "tool-use"}]}],
81
+ tools=[verify_citation, fetch_precedent], # Tool objects — or {"id", "version"} refs
82
+ guardrails=[no_fabricated_quotes], # Guardrail objects — or ids
83
+ parameters=[{"name": "jurisdiction", "type": "string", "required": True}],
84
+ conversation_policy={"historyLimit": 20},
85
+ budget={"maxSteps": 8, "maxCostUsd": 0.5, "maxWallMs": 60_000},
86
+ output=Brief, # typed answer (optional)
87
+ )
88
+ ```
89
+
90
+ - Import tools and guardrails with **relative imports** — every file in
91
+ the pack is imported as part of one package rooted at the pack.
92
+ - **Dict-valued fields keep the wire's camelCase keys**: `maxSteps`,
93
+ `maxCostUsd`, `maxWallMs`, `historyLimit`, `maxRetries`, `retryOn`.
94
+ Only the `Agent` keyword arguments themselves are snake_case.
95
+ - A file may define several agents; each must be assigned at module
96
+ level (an agent built inside a function is invisible to the indexer).
97
+ - `Agent(...)` checks the id (non-empty) and the version (an exact
98
+ semver) where it is written. Everything else is checked when Kindgi
99
+ reads the pack: `uv run python -m kindgi.pack index --pack-dir .`
100
+ shows what it sees, and `kindgi dev` reports a problem with its file.
101
+
102
+ ## Field by field
103
+
104
+ - **`id`** — `<pack-id>.<agent-name>`, kebab-case, dot-namespaced.
105
+ - **`version`** — exact semver. Conversations pin the version they
106
+ started on.
107
+ - **`name`**, **`description`**, **`tags`** — for people and listings.
108
+ - **`instructions`** — a LiquidJS template. `{{ variable }}` comes from
109
+ `parameters` or the runtime's own variables (`today`, `now`,
110
+ `agent.*`, `conversation.*`), rendered strictly: an unknown variable
111
+ fails the turn. Write it as a brief for a capable colleague: what to
112
+ do, which tools to prefer, what to refuse, the quality bar.
113
+ - **`capabilities`** — what the model must support, e.g.
114
+ `[{"needs": [{"feature": "tool-use"}]}]`. The turn routes its first
115
+ capability to pick a provider and model; none declared fails the turn.
116
+ - **`tools`** — `Tool` objects (pinned to that tool's version, or the
117
+ pack's) or `{"id": "acme.x", "version": "^0.1.0"}` refs, where
118
+ `version` is a semver **range**; the highest active matching version
119
+ is picked at turn start. A bare string is rejected. Empty = a
120
+ chat-only agent.
121
+ - **`guardrails`** — `Guardrail` objects or ids. Evaluated once per
122
+ turn on the final answer, before it is stored. An id with no
123
+ registered guardrail fails the turn (`unresolved-guardrail`).
124
+ - **`parameters`** — inputs the caller supplies per run
125
+ (`{"name", "type", "required"}`); they fill `{{ … }}` in the
126
+ instructions.
127
+ - **`preferred_provider`** / **`preferred_model`** — soft hints: the
128
+ router prefers that provider id (e.g. `"anthropic"`) and/or model name
129
+ (e.g. `"claude-haiku-4-5"`) when they satisfy the capabilities. To
130
+ *require* a model, put it in the capability:
131
+ `{"needs": [{"feature": "tool-use"}, {"models": {"allow": ["claude-haiku-4-5"]}}]}`.
132
+ - **`conversation_policy`** — `{"historyLimit": n}` caps the prior
133
+ messages loaded; `hitl` configures approval gates. Absent = the full
134
+ history, no gates. A tenant's `hitl` policy can tighten the gates
135
+ (shorter timeout, higher reviewer role, stricter per tool), never
136
+ loosen them.
137
+ - **`budget`** — per turn: `maxSteps` (model calls, default 8),
138
+ `maxCostUsd`, `maxWallMs` (default 120 000). Steps or cost exceeded
139
+ fails the turn (`budget-exceeded`); out of wall time aborts it. Leave
140
+ room for real models: a turn with tool calls can take tens of seconds.
141
+ - **`output`** — a typed answer: a pydantic model class (or any type
142
+ pydantic understands, or a JSON Schema dict), or the full
143
+ `{"schema", "name", "maxRepairs"}` object. The final answer must be
144
+ JSON matching it; a wrong one goes back to the model with the problems
145
+ (`maxRepairs`, default 1), then the turn fails
146
+ (`output-schema-violation`). The parsed answer is the turn result's
147
+ `output` — a dict on the wire (with `kindgi.client`:
148
+ `Brief.model_validate(run.output["output"])`), and in a flow
149
+ `nodeOutputs.<step>.output.<field>`.
150
+ - **`tool_errors`** — `{"maxRetries": 1, "retryOn": [...]}`: a failed
151
+ tool call goes back to the model as the call's result so it can fix
152
+ the call. Default kinds are `invalid-arguments` and `unknown-tool`
153
+ (nothing ran); add `tool-error` only when retrying the tool is safe.
154
+ Each retry costs a step.
155
+ - **`retrieval`** — memory retrieval declarations; usually `[]`.
156
+
157
+ ## Which model answers
158
+
159
+ Agents run on a registered model provider; the router picks one whose
160
+ models satisfy `capabilities`. `kindgi dev` gives a new pack `dev-echo`,
161
+ a **fallback** that answers only while no other provider fits — it
162
+ calls the first tool and replies "Tool responded: …", and the turn
163
+ carries a `fallback-provider` warning. Register a real model and it
164
+ takes over: see `kindgi-authoring-providers`
165
+ (`kindgi providers register --preset=anthropic`).
166
+
167
+ ## Iterating
168
+
169
+ Save the file; `kindgi dev` re-indexes and the next run uses it. No
170
+ version bump, no restart. Bump `version` when you break what callers
171
+ rely on (a removed parameter, an incompatible output), not on every
172
+ save.
173
+
174
+ Run an agent from another terminal in the pack directory:
175
+
176
+ ```sh
177
+ kindgi runs start --agent=acme.brief-writer --input='{"userMessage":"…"}'
178
+ ```
179
+
180
+ or from Python with `kindgi.client` (`Kindgi().runs.start(agent=…, input=…)`).
181
+
182
+ ## Common mistakes
183
+
184
+ 1. **Building an agent without asking what it should do.** Copying the
185
+ sample's shape answers the wrong question.
186
+ 2. **`tools=["acme.x"]`.** A tool is a `Tool` object or an
187
+ `{"id", "version"}` ref; a bare string fails the index.
188
+ 3. **snake_case inside the dicts.** `budget={"max_steps": 4}` is not a
189
+ budget; the keys are `maxSteps`, `historyLimit`, `maxRetries`, ….
190
+ 4. **An unregistered guardrail id.** Pass the `Guardrail` object you
191
+ import, or make sure the id is one the tenant has.
192
+ 5. **`{{ variable }}` not in `parameters`.** The turn fails when the
193
+ instructions render.
194
+ 6. **No `capabilities`.** The turn can't pick a model.
195
+ 7. **Defining the agent inside a function or under `if __name__`.** Only
196
+ module-level primitives are collected.
197
+ 8. **A tight `maxWallMs` with a real model.** 15 s aborts real turns
198
+ under load; 60 s is a safer start.
199
+
200
+ ## When the framework itself is the problem
201
+
202
+ If the bug is in Kindgi or the `kindgi` package itself (the index
203
+ dropping a field, a misleading error, the router picking the wrong
204
+ model) and not in the pack's code, load `kindgi-framework-feedback` and
205
+ file it with `kindgi feedback write`.