KScript docs
EN

Projects and kscript.json

Installing source libraries

kscript lib add installs KScript source files from public GitHub repositories. For a bare name, KScript searches the default branches of its own kylepantall/kscript catalog, the trusted public repositories matching orimovo/* and waggr-gb/*, and repositories registered in your project. In each repository it checks libraries/<name>/ first. If that folder is absent, the root kscript.json can declare a library with the requested name or point to the folder that declares it.

A single match installs immediately. If several distinct packages share the name, the CLI prints the number of matches and each qualified owner/repo@library name. Choose one and rerun kscript lib add with that name to install it. Each owner/repo@library appears once, even if its repository is both trusted and registered locally. A separate catalog that pins the library as a Git submodule has its own qualified name and can pin a different revision.

Official library What it provides Runtime package it uses
integer-math Greatest common divisor, least common multiple and factorial Core only
app-cache Caches computed values using the project's cache store and expiry settings KScript.Cache
request-id HTTP middleware that passes through a caller's request ID or generates one for the response KScript.Http
isolink-connect Opens an Isolink desktop session and works with spaces and records KScript.Net

Core is available in every script. The other runtime packages in the table ship with KScript, and each library imports the one it uses. For example, install Isolink Connect by name.

Shell
kscript lib add isolink-connect

You can select a public repository under either trusted owner explicitly in a fresh project. For example, the Isolink SDK lives in waggr-gb/isolink-connect.

Shell
kscript lib add waggr-gb/isolink-connect@isolink-connect

A qualified install skips discovery across other publishers. Use it if discovery cannot finish or you are close to GitHub’s API limit. It still needs API quota to resolve the selected revision. If GitHub has exhausted the quota, retry after it resets.

The installer prints the import to use from the site root. SDK 0.3 uses the manifest entry client.kscript and the generic @with_loopback_json transport from KScript.Net.

<import path="lib/isolink-connect/client.kscript" as="connect" />
import "lib/isolink-connect/client.kscript" as connect

For a publisher outside the built-in catalog and trusted owners, register its specific repository in your project. You can then install by bare name or select that publisher directly. For example, if your team publishes a slugs library in acme/kscript-libraries, run both commands from the project.

CommandWhat it does
kscript repo add acme/kscript-librariesAdd a repository that publishes libraries.
kscript lib add acme/kscript-libraries@slugsInstall its slugs library.

The first command also accepts the repository's HTTPS URL. It records the registration in .kscript/repos/ beside the nearest kscript.json, or in the current folder for standalone scripts. Commit the registration to share it with teammates. The second command downloads libraries/slugs/ from the registered repository's default branch. A script in the site root can then use import "lib/slugs/index.kscript" as slugs with the default layout.

For a direct install, kscript lib add owner/repo or kscript lib add https://github.com/owner/repo starts at the repository root. If its kscript.json points to a library folder, the installer copies just that folder. Otherwise it installs the entire repository. A GitHub tree URL selects a branch, tag, commit, or folder within it, such as kscript lib add https://github.com/owner/repo/tree/v1.0.0/libraries/slugs. Direct installs work without registering a repository.

Named libraries install into lib/<library-name>/. Direct installs use lib/<repository-name>/ when you select a repository or lib/<folder-name>/ when you select a folder. Set paths.lib in the nearest kscript.json to choose another folder relative to serve.root. Outside a project, the command installs into lib/ in the current folder. Imports are relative to the script containing them, so a script one level down would use ../lib/isolink-connect/client.kscript.

The installer reads the selected folder's kscript.json, validates its library metadata, and prints an import for library.entry. Without library.entry, the entry is the library's top-level main.kscript, main.ks.xml, index.kscript or index.ks.xml, in that order (the same main script rule as kscript run). For older libraries without a library section, it uses that rule too, then the shallowest script. The generated .kscript-lib.json receipt inside the installed folder records the source, exact commit and entry path, plus the name, version and runtime packages when declared.

In VS Code, completions inside the project's packages array show which runtime packages the installed, pinned libraries require. Add a package there when you also want it available throughout your project. Completions under types use the running KScript version's built-in types and accepted options, such as types.password.min and types.uuid.v.

Restoring a project's libraries

kscript lib add records the source URL and full commit under libraries in the consuming project's kscript.json. If there is no project yet, a successful add creates this file in the current directory. Commit it so teammates and CI can restore the same revisions after cloning.

A named Isolink install records the selected publisher folder and commit. For example, a project pinned to one revision looks like this.

JSON
{
  "libraries": {
    "isolink-connect": {
      "source": "https://github.com/waggr-gb/isolink-connect/tree/HEAD/libraries/isolink-connect",
      "commit": "d12745f9989a9523fcb33922f75625f0c1a96766"
    }
  }
}

On a fresh checkout, run the following command from the project or one of its subdirectories.

Shell
kscript lib restore

Restore reads the pins from the nearest project and fetches each library directly from its recorded publisher at the exact commit. For the example above, it fetches libraries/isolink-connect/ from waggr-gb/isolink-connect. A direct repository install records the repository URL and commit. Restore follows the library folder reference from that commit. If a team catalog publishes a Git submodule, the recorded catalog commit also fixes the upstream commit. An existing copy at the recorded revision keeps its local edits. To share those edits, commit the modified library files or publish the changes upstream. The installer uses the empty .kscript/libraries.lock file to coordinate simultaneous adds. You can ignore it in Git.

Publishing a named library

On the default branch of your public repository, put each library in an ordinary folder under libraries/ or pin a separate public GitHub repository there as a Git submodule. Both layouts publish source directly. For an ordinary folder, include the entry script, any scripts it imports by path, and any data it reads. The acme/kscript-libraries@slugs example could contain these files.

Text
libraries/
  slugs/
    kscript.json
    index.kscript
    README.md

Put the manifest beside the public source. For example, libraries/slugs/kscript.json can declare a Core-only library.

JSON
{
  "name": "slugs",
  "library": { "version": "1.0.0", "entry": "index.kscript" },
  "packages": []
}

library.version is a semantic version. library.entry is a .kscript or .ks.xml path relative to this file and can point to a nested module. Leave it out when the entry is main.kscript or index.kscript beside the manifest: "library": { "version": "1.0.0" } is enough. List required native runtime packages such as KScript.Net under packages, and import them in the source modules that use them. Declare public functions in the entry module. Users can then install your published library by its qualified name.

A repository that publishes a single library can place the same manifest and entry script at its root. Set name to the library name users should install. For example, a root manifest named slugs in the registered repository acme/slug-tools can be installed as kscript lib add acme/slug-tools@slugs.

A repository with tests or examples alongside the SDK can point its root kscript.json to the package folder. For example, Connect can keep its test settings in the following root manifest.

JSON
{
  "library": "libraries/isolink-connect",
  "test": { "include": ["tests/**/*.test.kscript"] }
}

The path is relative to this manifest. The target folder must contain its own kscript.json declaring a library name, library.version and library.entry. Declare any runtime packages there, too. Both kscript lib add waggr-gb/isolink-connect and kscript lib add waggr-gb/isolink-connect@isolink-connect then install that folder and print the same import. The repository's tests and examples stay in the checkout.

To publish slugs from a separate repository, run this in your library catalog and commit both .gitmodules and libraries/slugs.

Shell
git submodule add https://github.com/acme/slug-tools.git libraries/slugs

kscript lib add acme/kscript-libraries@slugs downloads the upstream commit pinned by the catalog. If the upstream contains libraries/slugs/, only that folder is installed, so other SDKs can share the repository. Otherwise the installer uses the upstream root. Keep all scripts and assets in the selected folder. The installer follows one submodule level, and records both repositories' commits in .kscript-lib.json. To publish an update, commit the new submodule pin in the catalog.

Edit this page on GitHub