Add a package resource
§ 1Purpose
Declare a new resource in a package and implement its check/apply wscript script against the host API.
§ 2Prerequisites
- A playbook with a pkgs/<name>/package.wcl already exists.
§ 3Flowchart
§ 4Steps
§ 4.11
§ 4.2Declare the resource and its params
resource "file_present" {
description = "Ensure a file exists with the given content"
script = "resources/file_present.wscript"
concurrency = "parallel"
param "path" { description = "Absolute path" type = "string" required = true }
param "content" { description = "File content" type = "string" default = "" }
}
Add a resource block to package.wcl with script (a path relative to the package dir) and a param per input. Params are validated against playbook properties at validation time.
§ 4.32
§ 4.4Implement check() and apply()
use value
use fs
use path
let p = params.get?.as_string?
if !exists
if read? == params.get?.as_string? Ok
} else
}
let p = params.get?.as_string?
mkdir?
write?
Ok
}
The contract
check must never mutate; apply must converge so a re-check returns AlreadyConfigured — even in a fresh process.
Write the script under resources/. Export check(params) and apply(params); import host modules with use. Run config-weave wscripti next to the scripts so the wscript LSP type-checks against the exact host surface.
§ 4.53
§ 4.6Validate the script compiles
$ config-weave validate ./my-playbook
ok
Run config-weave validate — its final stage compiles every wscript script against the host API, so a bad signature or unknown host function is a hard error.
Verification
config-weave validate exits 0 with the new resource's script compiled.