@instruktlabs/kiln 1.0.0 → 1.1.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +48 -3
- package/CONTRIBUTING.md +16 -7
- package/README.md +95 -381
- package/dist/agent-run.mjs +1 -1
- package/dist/build.json +40 -28
- package/dist/cli.mjs +18 -14
- package/dist/mcp-engine.mjs +15 -11
- package/dist/mcp-server.mjs +1 -1
- package/docs/architecture.md +6 -3
- package/docs/chatgpt.md +20 -5
- package/docs/examples.md +40 -170
- package/docs/install.md +100 -35
- package/docs/migration.md +20 -0
- package/docs/sdk.md +26 -5
- package/lib/asset-widget-uri.d.ts +9 -0
- package/lib/asset-widget-uri.js +9 -0
- package/lib/cli-render-mode.js +10 -3
- package/lib/discovery/portable.d.ts +9 -0
- package/lib/discovery/portable.js +6 -0
- package/lib/engine-identity.d.ts +1 -1
- package/lib/engine-identity.js +1 -1
- package/lib/evaluator/isolation.js +19 -5
- package/lib/evaluator/probe-invariants.d.ts +11 -0
- package/lib/evaluator/probe-invariants.js +36 -0
- package/lib/evaluator/probe-worker.js +16 -4
- package/lib/loopback.d.ts +6 -0
- package/lib/loopback.js +6 -0
- package/lib/mcp-core.d.ts +209 -0
- package/lib/mcp-core.js +278 -0
- package/lib/mcp-engine.d.ts +57 -0
- package/lib/mcp-engine.js +284 -0
- package/lib/mcp-manifest.d.ts +15 -0
- package/lib/mcp-manifest.js +65 -0
- package/lib/mcp.d.ts +5 -0
- package/lib/mcp.js +2 -0
- package/lib/render-service-host.js +1 -1
- package/package.json +22 -1
- package/plugin.json +1 -1
- package/plugins/kiln-engine/.claude-plugin/icon.png +0 -0
- package/plugins/kiln-engine/.claude-plugin/plugin.json +9 -3
- package/plugins/kiln-engine/PRIVACY.md +100 -0
- package/plugins/kiln-engine/README.md +103 -18
- package/plugins/kiln-engine/{scripts/setup-workspace.mjs → bin/kiln-setup-workspace.mjs} +37 -9
- package/plugins/kiln-engine/package-provenance.json +15 -8
- package/plugins/kiln-engine/plugin.json +10 -4
- package/plugins/kiln-engine/runtime.json +10 -1
- package/plugins/kiln-engine/skills/kiln-setup-workspace/SKILL.md +17 -18
- package/plugins/kiln-engine/skills/kiln-setup-workspace/references/plugin-install.md +28 -8
- package/plugins/kiln-engine/skills/kiln-setup-workspace/references/renderer-setup.md +11 -0
- package/scripts/create-workspace.mjs +71 -13
- package/scripts/workspace-config.mjs +239 -0
- package/scripts/workspace-project.mjs +384 -0
- package/scripts/workspace-transaction.mjs +504 -0
- package/skills/kiln-setup-workspace/SKILL.md +17 -18
- package/skills/kiln-setup-workspace/references/plugin-install.md +28 -8
- package/skills/kiln-setup-workspace/references/renderer-setup.md +11 -0
- package/src/cli-render-mode.ts +9 -9
- package/src/cli.ts +3 -3
- package/src/discovery/portable.ts +9 -0
- package/src/engine-identity.ts +1 -1
- package/src/evaluator/isolation.ts +27 -6
- package/src/evaluator/probe-invariants.ts +50 -0
- package/src/evaluator/probe-worker.ts +22 -4
- package/src/mcp.ts +5 -0
- package/src/render-service-host.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: kiln-setup-workspace
|
|
3
|
-
description:
|
|
3
|
+
description: Configure and verify Kiln in an existing project or a new asset workspace for the selected coding agent. Use before authoring when the project has no working kiln_workspace server or needs another agent integration; engine development stays in the engine checkout.
|
|
4
4
|
license: MIT
|
|
5
5
|
metadata:
|
|
6
6
|
kiln-workflow: workspace
|
|
@@ -18,15 +18,18 @@ Do not author assets inside the engine checkout. The authoring skills assume a w
|
|
|
18
18
|
|
|
19
19
|
## Create the workspace
|
|
20
20
|
|
|
21
|
-
When this skill comes from the **Kiln
|
|
21
|
+
When this skill comes from the **Kiln local plugin**, its plugin root contains `runtime.json` and `bin/kiln-setup-workspace.mjs` (plugin 1.0.0 used `scripts/setup-workspace.mjs`). Follow [plugin installation and upgrades](references/plugin-install.md) to install the pinned engine and configure a separate workspace. Do not run the checkout command below from a plugin cache. The plugin registers setup only; the workspace supplies its authoring skills and `kiln_workspace` server.
|
|
22
22
|
|
|
23
|
-
Choose an absolute path
|
|
23
|
+
Choose the user's existing project or an absolute path for a new workspace outside the engine installation. Check the installed initializer's `--help`: this setup version supports `--adopt`; older engines support only empty destinations. Upgrade an older installation explicitly before adopting a populated project.
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
node scripts/create-workspace.mjs /absolute/
|
|
26
|
+
node scripts/create-workspace.mjs /absolute/project --adopt --harness claude --check
|
|
27
|
+
node scripts/create-workspace.mjs /absolute/project --adopt --harness claude
|
|
27
28
|
```
|
|
28
29
|
|
|
29
|
-
From an installed package,
|
|
30
|
+
From an installed package, use `kiln-init` with the same arguments. Check reports planned changes and exits 1 when changes are needed; it writes nothing. Adoption preserves existing instruction files, unrelated settings, assets and skills. Read the returned `instructions` file (`.kiln/AGENTS.md`) and `.kiln/START.md`, alongside the project's existing instructions. Conflicts stop setup before writes; do not delete or replace owner configuration to make the command pass.
|
|
31
|
+
|
|
32
|
+
Author, refine and QA skills are installed by default; `--skills compose,batch` adds the optional workflows. Use the agent selected by the user or current host; ask only when it is unknown. Repeat `--adopt --harness codex` (or another supported adapter) to add that integration around the same program store. It explicitly migrates a legacy managed workspace while preserving assets. A combination whose config formats conflict is reported before changes; do not force one client's configuration into another. The plain empty-directory setup command remains compatible with older workflows.
|
|
30
33
|
|
|
31
34
|
CLI/MCP workspaces use the shared skills under `skills/`. Kiln's optional built-in Strands agent adds its workflow internally, outside that directory. Do not copy its system prompt, native workflow skill or completion protocol into another harness's skills or instructions. This applies to manual setup and plugin installs too; the engine's `src/agent/` directory is not a skill source.
|
|
32
35
|
|
|
@@ -37,24 +40,18 @@ CLI/MCP workspaces use the shared skills under `skills/`. Kiln's optional built-
|
|
|
37
40
|
| `cursor-agent` | `cursor-agent` |
|
|
38
41
|
| `opencode` | `opencode` |
|
|
39
42
|
| `agy` | `node agy.mjs` |
|
|
40
|
-
| `codex` | `node codex.mjs` |
|
|
43
|
+
| `codex` | `codex` after project trust; `node codex.mjs "TASK"` for a headless run |
|
|
41
44
|
| `hermes` | `node hermes.mjs` |
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
Read `.kiln/START.md` for an adopted project, or `START.md` in a legacy workspace. Codex reads trusted project configuration from `.codex/config.toml`; its optional headless launcher supplies the same settings per invocation without relocating authentication. Antigravity and Hermes use their generated launchers for the measured workspace flow. Setup does not grant project trust or edit global credentials. Skill registration is client-specific: Claude uses `.claude/skills`, Codex uses `.agents/skills`, and OpenCode uses its configured skills path, all copied from the same maintained Kiln skills.
|
|
44
47
|
|
|
45
48
|
Hermes needs one user-level registration for the MCP server, because it has no project-scoped equivalent and no per-invocation flag for one. Its START.md prints the exact `hermes mcp add` command; offer to run it, and verify with `hermes mcp list`. Never redirect `HERMES_HOME` at the workspace: that one variable resolves the configuration path and the credential path together, so pointing it at a workspace leaves the run with no provider.
|
|
46
49
|
|
|
47
|
-
##
|
|
48
|
-
|
|
49
|
-
Setup asks for render mode `auto`: textured or metallic scenes use a compatible GPU service, starting one lazily when available. Ordinary untextured scenes with zero metalness and no advanced material extensions use CPU views, even with a GPU available. CPU views support silhouette, proportion and contact review, but cannot confirm PBR appearance. Use CLI `--render gpu` when material review is required, including roughness on nonmetallic surfaces.
|
|
50
|
-
|
|
51
|
-
The renderer code is included with Kiln; its native GPU dependency is optional at the Kiln package root. For material-dependent tasks, check `node kiln.mjs service status` before starting the authoring session. If dependencies are missing or incompatible, reinstall the official Kiln package with optional dependencies enabled. npm 11 may print an `install-scripts` warning for the optional `webgpu` package; its postinstall only clears the macOS download quarantine from the prebuilt Dawn binary the package ships, so Windows and Linux need nothing and the warning is not an install failure. Read `runtime` from `.kiln/workspace.json` to identify the installation. A source checkout uses `bun install --frozen-lockfile` at that root. Setup checks dependency resolution without loading native code; ready dependencies alone do not prove the device can render.
|
|
50
|
+
## Check rendering readiness
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
Setup selects render mode `auto`. Textured or metallic scenes use a compatible render service; plain scenes use CPU geometry views. CPU views cannot confirm PBR appearance. Check `node kiln.mjs service status` before material-dependent work and require a real `viewFidelity` result before claiming material evidence.
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
A `KILN_RENDER_PORT_URL` whose origin is exactly the shared local socket (`http://127.0.0.1:8000` by default) takes the local route: it starts on demand and restarts after an idle exit. For rendering on another device, configure the MCP server process's `KILN_RENDER_PORT_URL` and, when needed, `KILN_RENDER_TOKEN` through the chosen harness. CLI accepts `--render-port URL` and reads `KILN_RENDER_TOKEN`. Start a compatible Kiln renderer on that device; its wider bind requires `RENDER_SERVICE_TOKEN` unless an authenticated proxy is explicitly configured. Manage the remote service on its own device. Verify the selected route with capabilities and require an actual `viewFidelity` receipt for material evidence.
|
|
54
|
+
Read [local renderer setup](references/renderer-setup.md) when dependencies are missing, a service is unavailable, or the task uses a renderer on another device. It covers dependency repair, shared-service lifetime, reprobe and authenticated remote rendering. Do not replace an unknown listener or install dependencies merely to clear a diagnostic.
|
|
58
55
|
|
|
59
56
|
## Verify the loadout before authoring
|
|
60
57
|
|
|
@@ -97,7 +94,9 @@ node /current/kiln/scripts/create-workspace.mjs /absolute/empty-workspace --repa
|
|
|
97
94
|
|
|
98
95
|
Repair rewrites generated runtime paths only. It preserves copied skills, saved revisions and assets, refuses configuration that was edited by hand, and does not upgrade the skills.
|
|
99
96
|
|
|
100
|
-
For an existing workspace, stop its harness/MCP session and run setup from the desired installation with `--check`, then `--upgrade`. Check returns JSON and exits 1 when an update is required. Upgrade refreshes unchanged configuration, instructions and
|
|
97
|
+
For an existing workspace, stop its harness/MCP session and run setup from the desired installation with `--check`, then `--upgrade`. Check returns JSON and exits 1 when an update is required. Upgrade refreshes unchanged owned configuration, instructions and registered skill copies while preserving assets and source stores. Conflicting local edits stop the whole upgrade before writing. Adopted projects preserve unrelated configuration changes and leave pre-existing instruction files alone. Legacy instruction files without ownership hashes can require explicit resolution; preserve them before resolving the named conflict. Do not overwrite an edited file merely to clear a diagnostic.
|
|
98
|
+
|
|
99
|
+
If adopted-project setup stops partway through writing, it attempts rollback. When it reports recovery required, preserve the project and run `kiln-init /absolute/project --recover` after confirming setup has stopped. Recovery refuses conflicting edits and retains its private snapshots outside the project. Resolve named conflicts explicitly; do not delete a lock or journal to force another setup. Recovery is for interrupted setup, not a general asset backup.
|
|
101
100
|
|
|
102
101
|
New managed launchers reject runtime/skill mismatches before serving tools; older workspaces need this explicit check first. Restart the harness/MCP session after upgrading so cached tool schemas and instructions match. `--repair` alone does not refresh copied skills or a running session. For independent model evaluations, create a fresh workspace from the candidate.
|
|
103
102
|
|
|
@@ -105,4 +104,4 @@ Discovery replaces the removed `kiln_list_primitives` tool; its old `name`, `nam
|
|
|
105
104
|
|
|
106
105
|
## What isolation means
|
|
107
106
|
|
|
108
|
-
A separate workspace limits task context
|
|
107
|
+
A separate workspace limits task context; an adopted project retains its existing application context and Git repository. Neither is an operating-system sandbox. User-level instructions, memory, authentication and filesystem permissions still apply. For comparing harnesses or models, use a fresh workspace and read `skills/kiln-batch-dispatch/references/clean-room-evaluation.md`, which covers inherited context and reporting trials.
|
|
@@ -4,19 +4,27 @@ The local `kiln-engine` plugin installs Kiln's exact pinned npm version and crea
|
|
|
4
4
|
an asset workspace. It carries setup guidance and a small installer; the engine,
|
|
5
5
|
source stores and authored assets live outside the plugin cache. It needs a
|
|
6
6
|
supported Node.js installation with npm, network access for first installation,
|
|
7
|
-
and no separate model API key.
|
|
7
|
+
and no separate model API key. Use it in Claude Code or Codex; it requires a local
|
|
8
|
+
shell and persistent filesystem and is not a Claude chat or Cowork plugin.
|
|
8
9
|
|
|
9
10
|
Resolve the plugin root from this installed skill's absolute path: it is two
|
|
10
11
|
directories above `skills/kiln-setup-workspace`. Confirm `runtime.json` and
|
|
11
|
-
`
|
|
12
|
+
`bin/kiln-setup-workspace.mjs` exist there. Do not assume plugin path variables are
|
|
12
13
|
available in an ordinary shell, and do not substitute an engine checkout.
|
|
13
14
|
|
|
15
|
+
Plugin version 1.0.0 used `scripts/setup-workspace.mjs`; if using that older
|
|
16
|
+
installation, confirm and use that file instead. Plugin and engine versions are
|
|
17
|
+
independent. `runtime.json` always names the exact engine to install.
|
|
18
|
+
|
|
14
19
|
For a fresh workspace, use an absolute empty destination outside both the plugin
|
|
15
|
-
and its runtime data directory. Select
|
|
16
|
-
|
|
20
|
+
and its runtime data directory. Select the current host or the user's stated
|
|
21
|
+
adapter. New bundles list the engine's supported adapters in `runtime.json`;
|
|
22
|
+
older bundles without that list accept `claude` or `codex` only. The plugin itself
|
|
23
|
+
is installed in Claude Code or Codex, but its helper can configure another adapter
|
|
24
|
+
supported by the pinned engine:
|
|
17
25
|
|
|
18
26
|
```sh
|
|
19
|
-
node "/absolute/plugin/
|
|
27
|
+
node "/absolute/plugin/bin/kiln-setup-workspace.mjs" "/absolute/my-assets" --harness codex
|
|
20
28
|
```
|
|
21
29
|
|
|
22
30
|
The installer verifies the package name and exact version from `runtime.json`.
|
|
@@ -27,11 +35,23 @@ or `$XDG_DATA_HOME/instruktlabs/kiln` on other systems, falling back to
|
|
|
27
35
|
Do not place it or the asset workspace inside a removable plugin version directory.
|
|
28
36
|
|
|
29
37
|
Read the returned workspace's `START.md`. Open Claude Code in that workspace, or
|
|
30
|
-
launch Codex there with `node codex.mjs
|
|
38
|
+
launch Codex there with `codex`. The `node codex.mjs "TASK"` launcher is for
|
|
39
|
+
headless execution with an explicit prompt. Accept the host's ordinary project/MCP
|
|
31
40
|
trust prompts, then call `kiln_discover({capabilities:true})` on `kiln_workspace`.
|
|
32
41
|
Compare its installation identity to `.kiln/workspace.json`; a config file alone
|
|
33
42
|
does not prove the server loaded. The plugin itself starts no global MCP server.
|
|
34
43
|
|
|
44
|
+
For an existing project, use a plugin whose helper advertises `--adopt` and whose
|
|
45
|
+
pinned engine supports project adoption. The published engine 1.0.0 predates this
|
|
46
|
+
feature. The helper checks the engine capability and refuses unsupported adoption
|
|
47
|
+
instead of silently falling back to empty-folder setup. Preview with
|
|
48
|
+
`--adopt --check --harness codex`, then apply with `--adopt --harness codex`.
|
|
49
|
+
Use the same path with another `--harness` to add an integration around the same
|
|
50
|
+
assets. Read the returned `instructions` path and `.kiln/START.md`; existing project
|
|
51
|
+
instruction files remain intact. The helper still leaves normal client trust
|
|
52
|
+
prompts to the host. No manual changes to a plugin's runtime pin are needed or
|
|
53
|
+
appropriate.
|
|
54
|
+
|
|
35
55
|
If the current workspace already has a working `kiln_workspace`, keep it. Do not
|
|
36
56
|
create a second server. Use its installed authoring skills, which come from its
|
|
37
57
|
engine version. The plugin supplies only setup, so authoring instructions are not
|
|
@@ -43,8 +63,8 @@ For an existing managed workspace, stop its harness session and run the new
|
|
|
43
63
|
plugin's helper with `--check`, then `--upgrade` when an update is intended:
|
|
44
64
|
|
|
45
65
|
```sh
|
|
46
|
-
node "/absolute/plugin/
|
|
47
|
-
node "/absolute/plugin/
|
|
66
|
+
node "/absolute/plugin/bin/kiln-setup-workspace.mjs" "/absolute/my-assets" --check
|
|
67
|
+
node "/absolute/plugin/bin/kiln-setup-workspace.mjs" "/absolute/my-assets" --upgrade
|
|
48
68
|
```
|
|
49
69
|
|
|
50
70
|
Check is read-only and reports a missing pinned engine without installing it.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Local renderer setup
|
|
2
|
+
|
|
3
|
+
Setup asks for render mode `auto`: textured or metallic scenes use a compatible GPU service, starting one lazily when available. Ordinary untextured scenes with zero metalness and no advanced material extensions use CPU views, even with a GPU available. CPU views support silhouette, proportion and contact review, but cannot confirm PBR appearance. Use CLI `--render gpu` when material review is required, including roughness on nonmetallic surfaces.
|
|
4
|
+
|
|
5
|
+
The renderer code is included with Kiln; its native GPU dependency is optional at the Kiln package root. For material-dependent tasks, check `node kiln.mjs service status` before starting the authoring session. If dependencies are missing or incompatible, reinstall the official Kiln package with optional dependencies enabled. npm 11 may print an `install-scripts` warning for the optional `webgpu` package; its postinstall only clears the macOS download quarantine from the prebuilt Dawn binary the package ships, so Windows and Linux need nothing and the warning is not an install failure. Read `runtime` from `.kiln/workspace.json` to identify the installation. A source checkout uses `bun install --frozen-lockfile` at that root. Setup checks dependency resolution without loading native code; ready dependencies alone do not prove the device can render.
|
|
6
|
+
|
|
7
|
+
Once dependencies are available, local CLI/MCP auto mode starts a managed service lazily for a view that needs PBR shading. Compatible clients share it; it survives the initiating session and exits after five minutes without admitted uploads, queued jobs or active renders. From the installation root, `node --import ./render-service/src/register-hooks.mjs render-service/src/server.mjs` starts a manual service that remains running while idle. It binds loopback; widening `HOST` requires `RENDER_SERVICE_TOKEN`.
|
|
8
|
+
|
|
9
|
+
`node kiln.mjs service status` reports installation, verified health and lifetime. `node kiln.mjs service start` joins a compatible service or starts a managed one the way an on-demand view does, and prints its port, renderer, pid, lifetime and build; it starts nothing when a stale, foreign or unknown listener holds the socket. After dependency repair or a cached startup failure, call `kiln_renderer({action:"reprobe"})` inside the MCP session to refresh its existing route. It neither installs dependencies nor starts a renderer; the next view starts one if needed. CLI `service reprobe` checks only its own process. Restart the session after changing Kiln, environment variables or credentials. Unknown or incompatible listeners are reported and left alone. `service stop` explicitly stops a verified local service. If no usable GPU is available, report the material-review limitation and continue on CPU views when that fits the task.
|
|
10
|
+
|
|
11
|
+
A `KILN_RENDER_PORT_URL` whose origin is exactly the shared local socket (`http://127.0.0.1:8000` by default) takes the local route: it starts on demand and restarts after an idle exit. For rendering on another device, configure the MCP server process's `KILN_RENDER_PORT_URL` and, when needed, `KILN_RENDER_TOKEN` through the chosen harness. CLI accepts `--render-port URL` and reads `KILN_RENDER_TOKEN`. Start a compatible Kiln renderer on that device; its wider bind requires `RENDER_SERVICE_TOKEN` unless an authenticated proxy is explicitly configured. Manage the remote service on its own device. Verify the selected route with capabilities and require an actual `viewFidelity` receipt for material evidence.
|
|
@@ -22,11 +22,24 @@ import { assertNodeRuntime } from '../src/runtime-support.mjs';
|
|
|
22
22
|
const installation = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
23
23
|
const quote = JSON.stringify;
|
|
24
24
|
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
25
|
-
const harnesses = [
|
|
25
|
+
const harnesses = Object.freeze([
|
|
26
|
+
'claude',
|
|
27
|
+
'codex',
|
|
28
|
+
'opencode',
|
|
29
|
+
'hermes',
|
|
30
|
+
'agy',
|
|
31
|
+
'copilot',
|
|
32
|
+
'cursor-agent',
|
|
33
|
+
]);
|
|
34
|
+
export const workspaceSetupCapabilities = Object.freeze({
|
|
35
|
+
projectAdoption: 1,
|
|
36
|
+
recovery: 1,
|
|
37
|
+
harnesses,
|
|
38
|
+
});
|
|
26
39
|
/**
|
|
27
40
|
* Where the chosen harness looks for project skills, relative to the workspace, as
|
|
28
|
-
* measured on the installed CLIs (docs/harnesses.md).
|
|
29
|
-
*
|
|
41
|
+
* measured on the installed CLIs (docs/harnesses.md). Fresh-profile probes on
|
|
42
|
+
* 2026-10-07 load Claude skills from `.claude/skills`, not `.agents/skills`;
|
|
30
43
|
* codex, hermes, agy, copilot and cursor-agent name `.agents/skills`; opencode reads only
|
|
31
44
|
* the `skills.paths` its generated config names, which is `skills/` itself. One registry
|
|
32
45
|
* per harness: every copy is bytes an upgrade must track and a reader may edit.
|
|
@@ -304,7 +317,7 @@ try {
|
|
|
304
317
|
}
|
|
305
318
|
|
|
306
319
|
function startGuide(root, runtime, harness, nodeExecutable, server) {
|
|
307
|
-
const launchers = { agy: 'node agy.mjs',
|
|
320
|
+
const launchers = { agy: 'node agy.mjs', hermes: 'node hermes.mjs' };
|
|
308
321
|
const command = launchers[harness] ?? harness;
|
|
309
322
|
const launch =
|
|
310
323
|
harness === 'hermes'
|
|
@@ -573,13 +586,30 @@ export async function renderServiceNotice(runtime) {
|
|
|
573
586
|
/** Preflight first; create a complete project in a staging directory before installing it. */
|
|
574
587
|
export async function createWorkspace(directory, harness = 'claude', options = {}) {
|
|
575
588
|
let root = resolve(directory);
|
|
589
|
+
if (options.recover) {
|
|
590
|
+
if (options.repair || options.upgrade || options.check || options.adopt || options.skills)
|
|
591
|
+
throw new Error('Use --recover alone before retrying setup.');
|
|
592
|
+
const { recoverProjectEdits } = await import('./workspace-transaction.mjs');
|
|
593
|
+
return recoverProjectEdits(root, { stateDirectory: options.stateDirectory });
|
|
594
|
+
}
|
|
576
595
|
const runtime = await realpath(resolve(options.installation ?? installation));
|
|
577
596
|
if ([options.repair, options.upgrade, options.check].filter(Boolean).length > 1)
|
|
578
597
|
throw new Error('Choose only one of --repair, --upgrade or --check.');
|
|
579
|
-
if ((options.repair || options.upgrade || options.check) && options.skills)
|
|
598
|
+
if ((options.repair || options.upgrade || (options.check && !options.adopt)) && options.skills)
|
|
580
599
|
throw new Error('Maintenance does not change the installed skill selection.');
|
|
581
|
-
|
|
582
|
-
|
|
600
|
+
let previous;
|
|
601
|
+
if (options.adopt) {
|
|
602
|
+
const bytes = await workspaceFile(root, '.kiln/workspace.json');
|
|
603
|
+
if (bytes !== undefined) {
|
|
604
|
+
try {
|
|
605
|
+
previous = JSON.parse(bytes.toString('utf8'));
|
|
606
|
+
if (!previous || typeof previous !== 'object' || Array.isArray(previous)) throw new Error();
|
|
607
|
+
} catch {
|
|
608
|
+
throw new Error('Invalid Kiln workspace manifest; no files were changed.');
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
} else if (options.repair || options.upgrade || options.check)
|
|
612
|
+
previous = await readManifest(root);
|
|
583
613
|
// A read-only check validates the configured interpreter, not whichever supported
|
|
584
614
|
// Node the caller's shell selected. Setup/repair/upgrade deliberately repin it.
|
|
585
615
|
// A missing recorded executable remains drift; do not silently accept that case.
|
|
@@ -588,17 +618,20 @@ export async function createWorkspace(directory, harness = 'claude', options = {
|
|
|
588
618
|
options.check && typeof previous?.node === 'string' && existsSync(previous.node)
|
|
589
619
|
? previous.node
|
|
590
620
|
: realpathSync(process.execPath);
|
|
591
|
-
if (previous) harness = previous.harness;
|
|
621
|
+
if (previous && !options.adopt) harness = previous.harness;
|
|
592
622
|
if (!harnesses.includes(harness)) throw new Error(`Choose ${harnesses.join(', ')}.`);
|
|
593
623
|
const extras = options.skills ?? [];
|
|
594
624
|
if (extras.some((name) => !Object.hasOwn(optional, name)))
|
|
595
625
|
throw new Error('Optional skills: compose,batch.');
|
|
596
|
-
const
|
|
626
|
+
const previousSkills = previous?.skills ?? core;
|
|
597
627
|
if (
|
|
598
|
-
!Array.isArray(
|
|
599
|
-
|
|
628
|
+
!Array.isArray(previousSkills) ||
|
|
629
|
+
!core.every((name) => previousSkills.includes(name)) ||
|
|
630
|
+
new Set(previousSkills).size !== previousSkills.length ||
|
|
631
|
+
previousSkills.some((name) => ![...core, ...Object.values(optional)].includes(name))
|
|
600
632
|
)
|
|
601
633
|
throw new Error('Invalid workspace skill manifest.');
|
|
634
|
+
const skills = [...new Set([...previousSkills, ...extras.map((name) => optional[name])])];
|
|
602
635
|
const pkg = await preflightRuntime(runtime, skills, !options.check);
|
|
603
636
|
let exists = false;
|
|
604
637
|
try {
|
|
@@ -631,7 +664,7 @@ export async function createWorkspace(directory, harness = 'claude', options = {
|
|
|
631
664
|
}
|
|
632
665
|
if (inside(runtime, root) || inside(runtime, ancestor))
|
|
633
666
|
throw new Error('Choose a directory outside the Kiln installation.');
|
|
634
|
-
if (!previous && exists && (await readdir(root)).length)
|
|
667
|
+
if (!options.adopt && !previous && exists && (await readdir(root)).length)
|
|
635
668
|
throw new Error('The destination must be empty; no existing files were changed.');
|
|
636
669
|
const { files, store, server } = managedFiles(root, runtime, harness, nodeExecutable);
|
|
637
670
|
const manifest = {
|
|
@@ -660,6 +693,29 @@ export async function createWorkspace(directory, harness = 'claude', options = {
|
|
|
660
693
|
: undefined,
|
|
661
694
|
generated: Object.fromEntries(Object.entries(files).map(([name, body]) => [name, hash(body)])),
|
|
662
695
|
};
|
|
696
|
+
if (options.adopt || previous?.schemaVersion === 2) {
|
|
697
|
+
const { setupProject } = await import('./workspace-project.mjs');
|
|
698
|
+
return setupProject({
|
|
699
|
+
root,
|
|
700
|
+
runtime,
|
|
701
|
+
harness,
|
|
702
|
+
previous,
|
|
703
|
+
metadata: manifest,
|
|
704
|
+
exists,
|
|
705
|
+
options,
|
|
706
|
+
guide,
|
|
707
|
+
allowedHarnesses: harnesses,
|
|
708
|
+
projectFiles: (selected) => managedFiles(root, runtime, selected, nodeExecutable).files,
|
|
709
|
+
startGuide: (selected) => startGuide(root, runtime, selected, nodeExecutable, server),
|
|
710
|
+
skillFiles: async () => {
|
|
711
|
+
const result = {};
|
|
712
|
+
for (const skill of skills)
|
|
713
|
+
for (const name of Object.keys(await fileHashes(join(runtime, 'skills', skill))).sort())
|
|
714
|
+
result[`${skill}/${name}`] = await readFile(join(runtime, 'skills', skill, name));
|
|
715
|
+
return result;
|
|
716
|
+
},
|
|
717
|
+
});
|
|
718
|
+
}
|
|
663
719
|
if (previous && (options.upgrade || options.check))
|
|
664
720
|
return upgradeWorkspace(root, runtime, previous, manifest, files, options.check);
|
|
665
721
|
if (previous) {
|
|
@@ -773,7 +829,7 @@ if (isDirectSetupEntry()) {
|
|
|
773
829
|
const args = process.argv.slice(2);
|
|
774
830
|
if (args.includes('--help') || args.includes('-h')) {
|
|
775
831
|
console.log(
|
|
776
|
-
`Usage: kiln-init <empty-directory> [--harness ${harnesses.join('|')}] [--skills compose,batch]\n kiln-init <managed-workspace> --repair|--check|--upgrade`,
|
|
832
|
+
`Usage: kiln-init <empty-directory> [--harness ${harnesses.join('|')}] [--skills compose,batch]\n kiln-init <project-or-new-workspace> --adopt [--harness NAME] [--check]\n kiln-init <managed-workspace> --repair|--check|--upgrade\n kiln-init <project> --recover`,
|
|
777
833
|
);
|
|
778
834
|
} else {
|
|
779
835
|
const directory = args.shift();
|
|
@@ -786,6 +842,8 @@ if (isDirectSetupEntry()) {
|
|
|
786
842
|
if (flag === '--repair') options.repair = true;
|
|
787
843
|
else if (flag === '--upgrade') options.upgrade = true;
|
|
788
844
|
else if (flag === '--check') options.check = true;
|
|
845
|
+
else if (flag === '--adopt') options.adopt = true;
|
|
846
|
+
else if (flag === '--recover') options.recover = true;
|
|
789
847
|
else if (flag === '--harness' || flag === '--skills') {
|
|
790
848
|
const value = args.shift();
|
|
791
849
|
if (!value || value.startsWith('--')) throw new Error(`${flag} requires a value.`);
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/** Shared configuration edits for local project integrations. Never writes files. */
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { applyEdits, getNodeValue, modify, parseTree } from 'jsonc-parser';
|
|
4
|
+
import { parse as parseToml } from 'smol-toml';
|
|
5
|
+
|
|
6
|
+
const maxLength = 2 * 1024 * 1024;
|
|
7
|
+
const forbidden = new Set(['__proto__', 'prototype', 'constructor']);
|
|
8
|
+
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
9
|
+
const conflict = (path) =>
|
|
10
|
+
new Error(`Configuration conflict at ${path.join('.')}; no files were changed.`);
|
|
11
|
+
|
|
12
|
+
function checkPath(path) {
|
|
13
|
+
if (
|
|
14
|
+
!Array.isArray(path) ||
|
|
15
|
+
!path.length ||
|
|
16
|
+
path.length > 16 ||
|
|
17
|
+
path.some(
|
|
18
|
+
(part) => typeof part !== 'string' || !/^[a-zA-Z0-9_-]+$/.test(part) || forbidden.has(part),
|
|
19
|
+
)
|
|
20
|
+
)
|
|
21
|
+
throw new Error('Invalid configuration path.');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function checkText(text, kind) {
|
|
25
|
+
if (typeof text !== 'string' || text.length > maxLength)
|
|
26
|
+
throw new Error(`Invalid ${kind} configuration.`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function jsonTree(text, comments) {
|
|
30
|
+
checkText(text, 'JSON');
|
|
31
|
+
try {
|
|
32
|
+
const errors = [];
|
|
33
|
+
const root = parseTree(text, errors, {
|
|
34
|
+
disallowComments: !comments,
|
|
35
|
+
allowTrailingComma: comments,
|
|
36
|
+
});
|
|
37
|
+
if (errors.length || root?.type !== 'object') throw new Error();
|
|
38
|
+
let count = 0;
|
|
39
|
+
const visit = (node, depth = 0) => {
|
|
40
|
+
if (++count > 100000 || depth > 64) throw new Error();
|
|
41
|
+
if (node.type === 'object') {
|
|
42
|
+
const keys = new Set();
|
|
43
|
+
for (const property of node.children ?? []) {
|
|
44
|
+
const key = property.children[0].value;
|
|
45
|
+
if (keys.has(key)) throw new Error();
|
|
46
|
+
keys.add(key);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const child of node.children ?? []) visit(child, depth + 1);
|
|
50
|
+
};
|
|
51
|
+
visit(root);
|
|
52
|
+
return root;
|
|
53
|
+
} catch {
|
|
54
|
+
// Parser messages can include source lines containing user credentials.
|
|
55
|
+
throw new Error('Invalid JSON configuration.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function jsonEntry(root, path) {
|
|
60
|
+
let node = root;
|
|
61
|
+
for (const part of path) {
|
|
62
|
+
if (node === undefined) return undefined;
|
|
63
|
+
if (node.type !== 'object') throw conflict(path);
|
|
64
|
+
node = node.children?.find((property) => property.children[0].value === part)?.children[1];
|
|
65
|
+
}
|
|
66
|
+
return node;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function jsonValue(value) {
|
|
70
|
+
try {
|
|
71
|
+
const serialized = JSON.stringify(value);
|
|
72
|
+
if (serialized === undefined || !isDeepStrictEqual(JSON.parse(serialized), value))
|
|
73
|
+
throw new Error();
|
|
74
|
+
jsonTree(`{"value":${serialized}}`, false);
|
|
75
|
+
return value;
|
|
76
|
+
} catch {
|
|
77
|
+
throw new Error('Invalid configuration value.');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function equalJson(a, b) {
|
|
82
|
+
if (Object.is(a, b)) return true;
|
|
83
|
+
if (
|
|
84
|
+
!a ||
|
|
85
|
+
!b ||
|
|
86
|
+
typeof a !== 'object' ||
|
|
87
|
+
typeof b !== 'object' ||
|
|
88
|
+
Array.isArray(a) !== Array.isArray(b)
|
|
89
|
+
)
|
|
90
|
+
return false;
|
|
91
|
+
const keys = Object.keys(a);
|
|
92
|
+
return (
|
|
93
|
+
keys.length === Object.keys(b).length &&
|
|
94
|
+
keys.every((key) => Object.hasOwn(b, key) && equalJson(a[key], b[key]))
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function checkOwnedNumbers(node, path) {
|
|
99
|
+
if (
|
|
100
|
+
node.type === 'number' &&
|
|
101
|
+
(!Number.isFinite(node.value) ||
|
|
102
|
+
(Number.isInteger(node.value) && !Number.isSafeInteger(node.value)))
|
|
103
|
+
)
|
|
104
|
+
throw conflict(path);
|
|
105
|
+
for (const child of node.children ?? []) checkOwnedNumbers(child, path);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Apply non-overlapping owned entries; unrelated JSON bytes are not reserialized. */
|
|
109
|
+
export function mergeJsonConfig(text, changes, { comments = false } = {}) {
|
|
110
|
+
checkText(text, 'JSON');
|
|
111
|
+
if (!Array.isArray(changes) || changes.length > 64)
|
|
112
|
+
throw new Error('Invalid configuration edits.');
|
|
113
|
+
for (const change of changes) {
|
|
114
|
+
checkPath(change?.path);
|
|
115
|
+
jsonValue(change.value);
|
|
116
|
+
if (Object.hasOwn(change, 'previous')) jsonValue(change.previous);
|
|
117
|
+
}
|
|
118
|
+
for (let i = 0; i < changes.length; i++)
|
|
119
|
+
for (let j = i + 1; j < changes.length; j++) {
|
|
120
|
+
const a = changes[i].path,
|
|
121
|
+
b = changes[j].path;
|
|
122
|
+
if (a.slice(0, Math.min(a.length, b.length)).every((part, k) => part === b[k]))
|
|
123
|
+
throw new Error('Overlapping configuration edits.');
|
|
124
|
+
}
|
|
125
|
+
let result = text.trim() ? text : `${text}{}\n`;
|
|
126
|
+
let root = jsonTree(result, comments);
|
|
127
|
+
for (const change of changes) {
|
|
128
|
+
const node = jsonEntry(root, change.path);
|
|
129
|
+
if (node !== undefined) {
|
|
130
|
+
checkOwnedNumbers(node, change.path);
|
|
131
|
+
const current = getNodeValue(node);
|
|
132
|
+
if (equalJson(current, change.value)) continue;
|
|
133
|
+
if (!Object.hasOwn(change, 'previous') || !equalJson(current, change.previous))
|
|
134
|
+
throw conflict(change.path);
|
|
135
|
+
}
|
|
136
|
+
// No whole-document formatter: preserve comments, large numbers and unrelated bytes.
|
|
137
|
+
result = applyEdits(result, modify(result, change.path, change.value, {}));
|
|
138
|
+
root = jsonTree(result, comments);
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function toml(text) {
|
|
144
|
+
checkText(text, 'TOML');
|
|
145
|
+
try {
|
|
146
|
+
return parseToml(text, { integersAsBigInt: true });
|
|
147
|
+
} catch {
|
|
148
|
+
throw new Error('Invalid TOML configuration.');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function entry(root, path) {
|
|
153
|
+
let value = root;
|
|
154
|
+
for (const part of path) {
|
|
155
|
+
if (!object(value)) throw conflict(path);
|
|
156
|
+
if (!Object.hasOwn(value, part)) return undefined;
|
|
157
|
+
value = value[part];
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function withoutEntry(root, path) {
|
|
163
|
+
const result = { ...root };
|
|
164
|
+
const [key, ...rest] = path;
|
|
165
|
+
if (Object.hasOwn(result, key)) {
|
|
166
|
+
if (!rest.length) delete result[key];
|
|
167
|
+
else {
|
|
168
|
+
result[key] = withoutEntry(result[key], rest);
|
|
169
|
+
if (!Object.keys(result[key]).length) delete result[key];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function fragmentValue(fragment, path) {
|
|
176
|
+
const parsed = toml(fragment);
|
|
177
|
+
const value = entry(parsed, path);
|
|
178
|
+
if (
|
|
179
|
+
!object(value) ||
|
|
180
|
+
!Object.keys(value).length ||
|
|
181
|
+
Object.keys(withoutEntry(parsed, path)).length
|
|
182
|
+
)
|
|
183
|
+
throw new Error('Invalid managed TOML fragment.');
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function markerLines(text, marker) {
|
|
188
|
+
const offsets = [];
|
|
189
|
+
let offset = 0;
|
|
190
|
+
for (const line of text.split('\n')) {
|
|
191
|
+
if (line.replace(/\r$/, '') === marker) offsets.push(offset);
|
|
192
|
+
offset += line.length + 1;
|
|
193
|
+
}
|
|
194
|
+
return offsets;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** TOML is preserved verbatim outside a validated, exclusively owned table block. */
|
|
198
|
+
export function mergeTomlConfig(text, { path, fragment, previous } = {}) {
|
|
199
|
+
checkPath(path);
|
|
200
|
+
const original = toml(text);
|
|
201
|
+
const desired = fragmentValue(fragment, path);
|
|
202
|
+
if (previous !== undefined) fragmentValue(previous, path);
|
|
203
|
+
const start = `# BEGIN KILN ${JSON.stringify(path)}`;
|
|
204
|
+
const end = `# END KILN ${JSON.stringify(path)}`;
|
|
205
|
+
const starts = markerLines(text, start),
|
|
206
|
+
ends = markerLines(text, end);
|
|
207
|
+
const newline = text.includes('\r\n') ? '\r\n' : '\n';
|
|
208
|
+
const block = (value) =>
|
|
209
|
+
`${start}${newline}${value.replace(/\r\n/g, '\n').trim().replace(/\n/g, newline)}${newline}${end}${newline}`;
|
|
210
|
+
let prefix = text,
|
|
211
|
+
suffix = '',
|
|
212
|
+
base = original;
|
|
213
|
+
if (starts.length || ends.length) {
|
|
214
|
+
if (starts.length !== 1 || ends.length !== 1 || starts[0] >= ends[0]) throw conflict(path);
|
|
215
|
+
const afterLine = text.indexOf('\n', ends[0]);
|
|
216
|
+
const after = afterLine < 0 ? text.length : afterLine + 1;
|
|
217
|
+
if (text.slice(starts[0], after) !== block(previous ?? fragment)) throw conflict(path);
|
|
218
|
+
prefix = text.slice(0, starts[0]);
|
|
219
|
+
suffix = text.slice(after);
|
|
220
|
+
base = toml(prefix + suffix);
|
|
221
|
+
if (
|
|
222
|
+
entry(base, path) !== undefined ||
|
|
223
|
+
!isDeepStrictEqual(entry(original, path), fragmentValue(previous ?? fragment, path)) ||
|
|
224
|
+
!isDeepStrictEqual(withoutEntry(original, path), withoutEntry(base, path))
|
|
225
|
+
)
|
|
226
|
+
throw conflict(path);
|
|
227
|
+
} else {
|
|
228
|
+
if (entry(original, path) !== undefined) throw conflict(path);
|
|
229
|
+
if (prefix && !prefix.endsWith('\n')) prefix += newline;
|
|
230
|
+
}
|
|
231
|
+
const result = prefix + block(fragment) + suffix;
|
|
232
|
+
const parsed = toml(result);
|
|
233
|
+
if (
|
|
234
|
+
!isDeepStrictEqual(entry(parsed, path), desired) ||
|
|
235
|
+
!isDeepStrictEqual(withoutEntry(parsed, path), withoutEntry(base, path))
|
|
236
|
+
)
|
|
237
|
+
throw conflict(path);
|
|
238
|
+
return result;
|
|
239
|
+
}
|