Skip to content

Create a module

This is the shortest path from nothing to a module a host can install. Each step links to the reference page that goes deeper. A coding agent opened in a new module repo gets the same walkthrough as the knetik-create-module skill.

Terminal window
npx knetik init weekly-report
cd weekly-report
npm install
npm run check && npm test

knetik init <id> writes a small complete module that already passes check and test: an agent stage that drafts two options, a pick gate, and a code stage that writes a Markdown file. It also writes the tests, scripted-model fixtures, AGENTS.md, the module skills and CI and release workflows.

Option Meaning
--title "Weekly report" The display name (default: the id, capitalised)
--dir <path> Where to create it (default: ./<id>)
--link <path to a knetik clone> Link that clone’s packages (file:) instead of taking them from npm. Use it while the packages are not published, or when you work on the host too

The id is lowercase letters, digits and single dashes, starting with a letter. The command refuses a folder that is not empty.

Write one sentence for each before you change the code:

  • Input: what a person gives it to start. Each field becomes a form field.
  • Stages, in order: which use a model (agent stages), which are plain work (code stages), and where a person must decide (gates).
  • Outputs: the files a run produces.
  • Connectors: Slack, Google or an MCP server, with the scopes you need, and whether the module works without them.
  • Configuration or input: choices made per run are input; values an admin sets once (config) are configuration.
Terminal window
npm run check # manifest, stage graph, agents, schemas, connectors, fixtures
npm test # headless: real executor, scripted model, mock connectors
npm run dev # the whole host with mocks and hot reload (needs a knetik clone next to the module)

Change one stage, then check and test. Tests drive the whole process with runModule (see Testing): script what the model says, answer each gate by option id, mock connectors, and assert on the artifacts and the recorded events.

Three rules catch most mistakes: a code stage runs at least once, so it must be safe to run twice; a run’s outputs are stored in one database row (about 1.5 MB), so put large content in an artifact; and module code must not use Node-only APIs, because it also runs on Cloudflare Workers.

  1. Raise version in knetik.module.ts.
  2. Run npm run check && npm test, then merge to main.
  3. git tag v0.2.0 && git push --tags. The tag must equal the manifest version; the Release workflow checks that and creates the GitHub release.

A host never loads a module while it runs. It vendors a reviewed copy pinned to a commit. The owner runs npx knetik add github:<org>/<repo>@<sha>, which shows what the module asks for and waits for approval, or the host’s bump workflow opens a pull request when it sees a new release tag.

The @knetikdotdev packages a module imports (sdk, testing, cli, core) are Apache-2.0, which puts no condition on the license of your module. A new module starts with "license": "UNLICENSED" in package.json, which grants nobody else any rights; set a real license and add a LICENSE file before you share it. Apache-2.0 suits a module well: it is compatible with the AGPL-3.0 host that vendors modules, and with the packages. Put the copyright holder in a NOTICE file. The host itself is AGPL-3.0, which matters only to someone who modifies the host and runs it for other people.

Command Needs
npx knetik init, check, test The Knetik packages only (from npm, or linked with --link)
npm run dev A clone of the knetik repo next to the module, installed, as the host it runs in