KScript docs
EN

kscript.json settings

Every setting a project's kscript.json can have. The editor checks the file against the same list, so it completes and explains each one as you type.

A dotted name is a setting inside another: serve.port is { "serve": { "port": 8080 } }. More in Projects and kscript.json.

Project

SettingTypeDefaultWhat it does
namestringThe project's name.
kscriptstringThe KScript release the project is written for: 0.51.0, or 0.51 for the newest 0.51.x. Editors that fetch KScript for you use this release; leave it out to use the latest.
timezonestring"Europe/London"The time zone the project's stored dates are in, by its IANA name: Europe/London (the default), America/New_York, UTC. A database column holds a date as a clock time with no zone; this says which zone that clock is in, so a row means the same moment on every computer.
librariesobjectInstalled source libraries by folder name. kscript lib add records the exact revision; kscript lib restore reinstalls it.
libraryobject or stringDeclares an installable library or points to its folder.
standardobject or array"kscript:recommended"The standard (or standards) whose lint rules and format settings this project starts from; kscript.json's own lint and format settings win over it. Built in: kscript:recommended (the default) and kscript:strict. Anything else is a path, relative to kscript.json, to a standard file or to a folder holding kscript-standard.json. [] uses no standard (style rules off).
packagesarrayPackages every script in the project uses without an <import>. KScript.Core is always imported.
extensionsarray["extensions"]Where the project's extension files are: folders (everything inside, subfolders too) or globs, relative to kscript.json. Their extend blocks (extend date { fn json() => ... }) apply to every script in the project. Default: ["extensions"].
nativesarray["natives"]Where the project's native types are: folders (everything inside, subfolders too) or globs, relative to kscript.json. The types and enums they declare (type Sku with [string] { ... }) work in every script in the project without an import. kscript make native writes to the first folder. Default: ["natives"].

types

SettingTypeDefaultWhat it does
typesobjectDefault validation rules for built-in types. Arguments at a type's use site can override these defaults.
types.passwordrules
types.stringrules
types.uuidRules for uuid values: the typeRules settings, plus v for the UUID version.

serve

SettingTypeDefaultWhat it does
serveobjectDefaults for kscript serve. Options on the command line win.
serve.rootstring"."The site folder, relative to kscript.json. Its files and folders are the site's URLs.
serve.portnumber8080The port to listen on.
serve.hoststring"localhost"localhost, an IP address to listen on, or * for every address.
serve.docsbooleanfalseAlso serve the KScript docs, with a page about this project's routes, functions and types, on localhost while you work (like kscript serve --with-docs). Never on for compiled programs or the production environment.
serve.docs_portnumber4180The port the docs are served on. Without it, 4180, or a free port if that is in use.
serve.dockerboolean or objectRun kscript serve through Docker Compose. True uses the default app service and mounts the working tree for development.
serve.docker.enabledbooleantrueLaunch Docker Compose by default.
serve.docker.compose_filestringCompose file relative to the project folder.
serve.docker.servicestring"app"The Compose service that runs the site.
serve.docker.buildbooleantrueBuild the service image before starting.
serve.docker.mountstring or null"/app"Container path for a read-only project bind mount. Null uses the image's files.

http

SettingTypeDefaultWhat it does
httpobjectKScript.Http: route files, middleware and their settings for kscript serve.
http.routesarrayThe route files, relative to the site folder. Without this, kscript serve loads routes.kscript and api.kscript (under /api), or their .ks.xml forms.
http.middlewarearrayMiddleware run for every route, such as ["log"]. Built-ins: log, cors, auth, guest, csrf, throttle, etag, cache_control, cache_response (throttle:30, auth:session, auth:token, auth:OTHER_TOKEN, cache_control:300, cache_response:5m).
http.groupsobjectNames for lists of middleware, used like a middleware name: { "admin": ["auth", "log"] }.
http.viewsstring"views"The folder @view() looks in first. It is never served as pages.
http.api_prefixstring"/api"The prefix of api.* route files.
http.write_filesbooleantruefalse makes controllers read-only, like pages. Writes never leave the site folder.
http.upload_limitinteger or string"8MB"The most bytes of files one request may upload ($request.files and live uploads): a number of bytes, or text such as "20MB".
http.corsobjectSettings for the cors middleware.
http.cors.originsarrayOrigins allowed to call the API, or ["*"] (the default) for any.
http.cors.methodsarrayMethods allowed in preflight requests.
http.cors.headersarrayRequest headers allowed in preflight requests.
http.cors.credentialsbooleantrue allows cookies and Authorization from other origins.
http.authobjectSign-in with KScript.Auth, and the auth middleware. Times are seconds, or text such as "15m", "2h" or "30d".
http.auth.token_envstring"API_TOKEN"The environment variable holding the shared bearer token the auth middleware also accepts.
http.auth.loginstring"/login"Where the auth middleware sends people who aren't signed in.
http.auth.homestring"/"Where the guest middleware sends people who are signed in, and @intended()'s default.
http.auth.sessionsfile or memory or database"file"Where sessions, API tokens, reset tokens and passkey challenges are kept: file (the app's state folder, so they last across restarts), memory, or database (the kscript_sessions table, shared by every server).
http.auth.auto_createbooleantrueWith sessions: database, false leaves making the kscript_sessions table to the project's migrations (kscript publish sessions sets it).
http.auth.folderstringA folder, relative to the site, for users, sessions and tokens. By default they go in the app's data and state folders.
http.auth.usersstringA KScript.Data model in the models folder, such as "User", that holds the users. By default they are JSON files in the app's data folder.
http.auth.lifetimenumber or string"2h"How long a session lasts after the last request.
http.auth.remembernumber or string"30d"How long a "remember me" sign-in lasts.
http.auth.securebooleanForces the cookie's Secure flag on or off. By default it is set for https requests.
http.auth.same_siteLax or Strict or None"Lax"The cookie's SameSite.
http.auth.csrfbooleantrueFalse turns off the CSRF check that web routes get when their file imports KScript.Auth.
http.auth.attemptsnumber5Failed sign-ins allowed per email and address before @attempt() makes them wait.
http.auth.lockoutnumber or string"1m"How long failed sign-ins are counted over, and how long @attempt() then waits.
http.auth.passkey_originstringThe public HTTPS origin for passkeys, or http://localhost with an optional development port. Setting this enables passkeys.
http.auth.passkey_signupbooleanfalseAllows new accounts to sign up with a passkey. Requires passkey_origin.
http.auth.passkey_rp_idstringAn optional relying party domain, such as example.com. Defaults to the passkey origin's hostname.
http.auth.reset_lifetimenumber or string"1h"How long a password reset token works.
http.auth.guest_lifetimenumber or string"365d"How long a browser keeps its @guest() id.
http.auth.adopt_guestbooleanfalseMoves a guest's rows of Ownable models to their account when they sign in.
http.throttleobjectSettings for the throttle middleware.
http.throttle.limitnumber60Requests allowed per window, per address and route.
http.throttle.secondsnumber60The length of the window.
http.throttle.storememory or file or database"memory"Where requests are counted: memory (this process), file (the app's cache folder) or database (shared by every server).
http.openapiboolean or objecttrueThe OpenAPI 3.1 document made from the routes. kscript serve answers /_openapi.json, /_openapi.yaml and the /_api page; kscript openapi writes it. false turns the served copies off.

lint

SettingTypeDefaultWhat it does
lintobjectUsed by kscript check and by the editor (language server).
lint.includearray["**/*.kscript","**/*.ks.xml","**/*.html","**/*.md"]Files kscript check looks at, as globs relative to kscript.json. .xml files that start with <kscript> are always included.
lint.excludearray["_templates","node_modules",".git"]Files and folders that are never checked, by kscript check or the editor. A name without / (such as _templates) matches anywhere; drafts/** matches a folder.
lint.rulesobjectSeverity per diagnostic code (KS3003) or code prefix (KS3*). The longest match wins.
lint.warnings_as_errorsbooleanfalseMake kscript check fail on warnings too (same as --warnings-as-errors).

paths

SettingTypeDefaultWhat it does
pathsobjectWhere kscript make puts each kind of file, relative to the site folder. Leave a folder out to use the recommended one.
paths.routesstring"routes"Route files: web.kscript (served at /) and api.kscript (under /api).
paths.controllersstring"controllers"Controllers (kscript make controller, kscript make route).
paths.middlewarestring"middleware"Middleware (kscript make middleware).
paths.requestsstring"requests"Typed request bodies (kscript make request).
paths.viewsstring"views"Views that controllers render with @view() (kscript make view). Also where @view() looks, unless http.views is set.
paths.componentsstring"_components"Page components (kscript make component).
paths.layoutsstring"_layouts"Page layouts (kscript make layout).
paths.partialsstring"_partials"HTML that pages <include> (kscript make partial).
paths.stylesstring"styles".ks.css stylesheets (kscript make css).
paths.libstring"lib"Shared functions and constants (kscript make module, kscript make const, kscript make cache).
paths.typesstring"types"Types and enums (kscript make type, kscript make enum).
paths.modelsstring"models"Database models (kscript make model).
paths.storagestring"lib"JSON file stores (kscript make storage).
paths.jobsstring"jobs"Jobs (kscript make job).
paths.policiesstring"policies"Policies, one per model, that @can and @authorize ask (kscript make policy).
paths.eventsstring"events"Events, dispatched with @dispatch_event() (kscript make event).
paths.listenersstring"listeners"Listeners, run the first time an event is dispatched (kscript make listener).
paths.windowsstring"."Desktop windows (kscript make window).
paths.documentsstring"documents"Document scripts that write PDF and Word files (kscript make document).
paths.localesstring"locales"Translations (kscript make locale).
paths.loggingstring"lib"Log providers (kscript make logger).
paths.datastring"data"JSON data that stores and caches write.
paths.scriptsstring"scripts"Scripts (kscript make script).
paths.testsstring"tests"Tests (kscript make test).

make

SettingTypeDefaultWhat it does
makeobjectSettings for kscript make.
make.syntaxkscript or xml"kscript"The syntax kscript make writes scripts, tests, routes and desktop apps in: kscript (.kscript files) or xml (.ks.xml). --syntax on the command line wins.

app

SettingTypeDefaultWhat it does
appobjectUsed by kscript compile, which builds a script, desktop app or site into a program for macOS, Windows and Linux.
app.mainstringThe script the app runs, relative to kscript.json. Usually one that imports KScript.UI and holds a Window { } (<KScript.Window> as the root of an XML file).
app.namestringThe app's name in the Dock, Start menu or launcher. Defaults to the project's name.
app.idstringA reverse-DNS id such as com.example.lifelab (the macOS bundle id).
app.versionstringThe app's version, such as 1.0.0.
app.iconstringAn icon file relative to kscript.json: .icns for macOS, .ico for Windows, .png for Linux.
app.user_configbooleanfalsetrue lays the person's own settings over $config: config.json in the app's config folder, such as ~/.config/<app> on Linux (see KScript.Storage).

test

SettingTypeDefaultWhat it does
testobjectUsed by kscript test.
test.includearray["**/*.test.kscript","**/*.test.ks.xml"]The test files kscript test runs, as globs relative to kscript.json.
test.excludearray["_templates","node_modules",".git"]Files and folders that are never run as tests.
test.timeoutnumber10Seconds one test may run before it fails (0 for no limit). timeout="..." on a <test> and --timeout win.
test.envstringThe environment the tests run in (KSCRIPT_ENV), so kscript.test.json can give tests their own database. kscript --env and a KSCRIPT_ENV already set win.
test.databasememory or config"memory"The database KScript.Data gives each test file: memory (a new SQLite database in memory, made from the migrations or the models) or config (the one the config names). Each test's changes are undone when it ends.
test.packagesarrayPackages every test file imports, on top of the project's packages. KScript.Test is always imported in test files.

config

SettingTypeDefaultWhat it does
configobjectThe app's own settings, read as $config: "config": { "app": { "name": "Shop" } } gives $config.app.name. kscript.<env>.json's config section is laid over this one for that environment (kscript --env or KSCRIPT_ENV), and then config.kscript's configure(environment), for settings that need @env() or other code.
config.appobjectSettings about the app, such as its name: $config.app.name.
config.databaseobjectKScript.Data's database connections.
config.database.defaultstringThe connection used when none is named (default: main).
config.database.connectionsobjectConnections by name, such as "main": { "url": "sqlite:data/app.sqlite" }.
config.cacheobjectKScript.Cache settings, such as "store": "memory" and "ttl": "5m".
config.mailobjectKScript.Mail: how @send_mail sends (see docs/mail.md).
config.mail.driversmtp or log or fake"log"smtp sends through a mail server, log writes each message to the log, and fake keeps them in memory.
config.mail.hoststring"localhost"The SMTP server.
config.mail.portnumber587The SMTP port: 587 for STARTTLS, 25 or a test server's port otherwise.
config.mail.usernamestringThe SMTP user. Defaults to the MAIL_USERNAME environment variable.
config.mail.passwordstringThe SMTP password. Leave it out to read the MAIL_PASSWORD environment variable.
config.mail.encryptiontls or none"tls"tls upgrades the connection with STARTTLS; none sends in the clear, for a local test server.
config.mail.fromstring or objectThe address mail comes from unless @send_mail names one: "hello@example.com", or { "address": "hello@example.com", "name": "Shop" }.
config.mail.queuestring"default"The queue mail sent with queue goes on.
config.loggingobjectLog level and providers, such as "level": "info".
config.i18nobjectTranslations: folder, default and locale, such as "default": "en-GB".
config.moneyobjectMoney settings, such as exchange_rates: { "EUR": { "GBP": 0.85 } }.

queue

SettingTypeDefaultWhat it does
queueobjectKScript.Queue: where dispatched jobs wait, and what kscript worker runs (see docs/queues.md).
queue.defaultstring"file"The connection jobs go to unless a job or dispatch names another: file, database, memory, sync, or one under queue.connections.
queue.connectionsobjectNamed connections. file, database, memory and sync are always there.
queue.queuesarrayThe only queues a worker checks, first to last, e.g. ["high", "default"]. Without it a worker checks default, then every other queue.
queue.failedobjectWhat happens to jobs that fail every try.
queue.failed.keepstring or number"7d"How long failed jobs are kept, such as "7d" or a number of seconds.
queue.workerobjectHow kscript worker runs jobs.
queue.worker.concurrencynumber1How many jobs a worker runs at once.
queue.worker.sleepstring or number"1s"How long a worker waits when the queues are empty.
queue.envobjectSettings per environment, e.g. { "test": { "default": "sync" } }. kscript test uses sync unless env.test says otherwise.

agents

SettingTypeDefaultWhat it does
agentsobjectSettings for generated AGENTS.md.
agents.mergearrayProject-relative Markdown files to include in AGENTS.md, in the listed order.

format

SettingTypeDefaultWhat it does
formatobjectUsed by kscript fmt and the editor's Format Document. Values set here win over the editor's tab settings.
format.enabledbooleantruefalse turns formatting off for the project: kscript fmt skips its files and Format Document makes no changes.
format.rulesobjectTurn individual formatting rules off, e.g. { "statement_per_line": false }. Every rule is on unless listed. To leave part of a file alone, use <!-- kscript-fmt: off --> ... <!-- kscript-fmt: on --> or <!-- kscript-fmt-ignore --> before an element.
format.rules.indenttrue or false or on or offtrueRe-indent elements by how deeply they are nested. Off: lines keep their indentation.
format.rules.statement_per_linetrue or false or on or offtruePut each statement and block-level element on its own line. Off: line breaks only change where there was already whitespace.
format.rules.tidy_tagstrue or false or on or offtrueOne space between attributes, and <x /> for self-closing tags. Off: start tags are kept exactly as written.
format.rules.wrap_attributestrue or false or on or offtrueOne attribute per line for long start tags and tags already written that way. Off: tags are never wrapped or joined.
format.rules.trim_trailing_whitespacetrue or false or on or offtrueRemove spaces at the ends of lines of text.
format.rules.collapse_blank_linestrue or false or on or offtrueShrink runs of blank lines to max_blank_lines.
format.rules.final_newlinetrue or false or on or offtrueEnd the file with exactly one newline. Off: the file ends as it did.
format.rules.spacingtrue or false or on or offtrue.kscript files: one space after commas and colons, around assignments and =>, and before a block's '{'. Off: spacing inside lines is kept.
format.rules.brace_styletrue or false or on or offtrue.kscript files: put else, elif, catch and finally on the line of the closing '}'. Off: they stay where they are.
format.rules.wrap_stringstrue or false or on or offtrue.kscript files: break a string that runs past print_width at a space, with a \ at the end of the line (the break isn't part of the string). Off: long strings stay on one line.
format.rules.wrap_chainstrue or false or on or offtrue.kscript files: a -> chain or |> pipe that runs past print_width puts each call on its own line, indented under where the chain starts. Off: chains stay on one line.
format.rules.wrap_bodiestrue or false or on or offtrue.kscript files: a one-line function (fn name() => body) that runs past print_width moves its body to the next line. Off: it stays on one line.
format.rules.wrap_commentstrue or false or on or offtrue.kscript files: a // or /// comment line that runs past print_width is broken between words onto a new comment line. Off: comments stay as written.
format.indentnumber2Spaces per indent level, or "tab" to indent with tabs.
format.tab_widthnumber2With "indent": "tab", how many columns a tab counts as when lining up existing text.
format.print_widthnumber80The longest a line should be (80 by default). Longer lines are wrapped: a start tag gets one attribute per line, and in .kscript files a long call, chain, one-line function, string or comment is broken onto more lines.
format.max_blank_linesnumber1Blank lines kept in a row; extra ones are removed.
format.end_of_lineauto or lf or crlf"auto"Line endings to write. auto keeps the ones each file already uses.
format.preservearray[]Elements whose content is kept exactly as written, on top of <pre>, <textarea>, <script>, <style> and CDATA sections.
format.includearray["**/*.kscript","**/*.ks.xml","**/*.html"]Files kscript fmt formats in a project folder, as globs relative to kscript.json. .xml files that start with <kscript> are always included; Markdown pages are never reformatted.
format.excludearray["_templates","node_modules",".git"]Files and folders kscript fmt leaves alone.