diff --git a/.gitignore b/.gitignore index 4d4d34a..8dc4d19 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,7 @@ !docs/** !examples/ !examples/** +!contrib/ +!contrib/** !.github/ !.github/** diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 7c2eb59..5f51084 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -2,6 +2,9 @@ == v0.1.0 (unreleased) +* Unity Install Layout (UIL) v1.0: JSON schema, Antora reference, `installcoordinator.uil` library (parse, validate, classic-path plan, journal dry-run). +* CLI: `uil validate`, `uil plan`, `uil emit-coordinator`; examples `uil-classic-demo.uil.json` and `thin-stub-msi.job.json`. +* Linux/Posix: Unix socket client/server fixes for current Phobos (`Socket`, `getpid`). * Initial daemon, job state machine, MSI serialization lane, named-pipe IPC, HTTP API + web UI. * Two surfaces: local user app window (`/ui/user`) and admin remote control (`/ui/admin` + JSON API with Bearer auth when non-local). * Thin stub submit flow, session elevation lock, batch scope/terms, install history catalog. diff --git a/README.adoc b/README.adoc index 83c583d..9c67937 100644 --- a/README.adoc +++ b/README.adoc @@ -1,11 +1,13 @@ = Install Coordinator -D daemon with **two surfaces**: a local lay-user app window and an admin remote-control HTTP API. +D daemon with **two surfaces**: a local lay-user app window and an admin remote-control HTTP API. It is also a **installer framework option** for DevCentr: the queue plane serializes MSI work while **Unity Install Layout (UIL)** describes package roles, shell claims, and transaction journals for Ibex and other emitters. ## Why Windows blocks parallel MSI sessions via `_MSIExecute`. GUI users double-click installers and get error 1618. Install Coordinator collects jobs, explains waits, and runs MSI steps one at a time while allowing disjoint work in parallel when claims permit. +UIL adds a layout contract so installs refresh PATH, shortcuts, and environment—not only copy files—on classic Windows/macOS/Linux/BSD paths today, with a forward mapping to connectome-fs. + ## Surfaces * **User (local)** — `install-coordinator gui` opens a framed app window at `/ui/user`. Plain language, no admin jargon. Localhost only. @@ -21,11 +23,14 @@ install-coordinator gui # local user app window install-coordinator list active install-coordinator session --lock-elevation --batch-terms --scope=perMachine install-coordinator shortcut --desktop +install-coordinator uil validate examples/uil-classic-demo.uil.json +install-coordinator uil plan examples/uil-classic-demo.uil.json --dry-run +install-coordinator uil emit-coordinator examples/uil-classic-demo.uil.json ``` Environment: `INSTALL_COORD_BIND`, `INSTALL_COORD_AUTH_TOKEN`, `INSTALL_COORD_REMOTE=1`, `INSTALL_COORD_HTTP_PORT`. -## Manifest (minimal) +## Manifest (queue plane, minimal) ```json { @@ -40,12 +45,39 @@ Environment: `INSTALL_COORD_BIND`, `INSTALL_COORD_AUTH_TOKEN`, `INSTALL_COORD_RE } ``` +See `examples/thin-stub-msi.job.json` for a documented MSI stub sample. + +## UIL (layout contract) + +Ibex and other authors emit `*.uil.json` manifests (schema: `docs/schema/uil-manifest.schema.json`). The CLI validates, plans classic path mapping, and prints a transaction journal (dry-run MVP). + +```json +{ + "uilVersion": "1.0", + "package": { "id": "dev-centr.myapp", "name": "My App", "version": "1.0.0" }, + "layout": { "adapter": "classic-paths", "scope": "perUser" }, + "payload": { + "entries": [{ "source": "staging/bin/myapp", "role": "bin", "relativePath": "myapp" }] + }, + "claims": [{ "type": "path_entry", "directories": ["${role:bin}"] }] +} +``` + +Full reference: Antora pages under `docs/modules/ROOT/pages/` (`framework.adoc`, `uil-reference.adoc`). + +## Ibex integration + +Author installer projects with link:https://github.com/dev-centr/ibex-install-builder[ibex-install-builder]. Select plugin `uil` or `install-coordinator` to emit UIL manifests and coordinator job JSON into `dist/`. If your Ibex revision predates the plugin, copy the patch from `contrib/ibex-uil-option/`. + ## Build ```powershell dub build --config=application +dub test --config=library ``` +Library configuration exposes `installcoordinator.uil` for parse, validate, plan, and journal helpers. + ## Docs https://docs.devcentr.org/install-coordinator/latest/index.html (after hub wire) diff --git a/contrib/ibex-uil-option/README.adoc b/contrib/ibex-uil-option/README.adoc new file mode 100644 index 0000000..f71fbcb --- /dev/null +++ b/contrib/ibex-uil-option/README.adoc @@ -0,0 +1,35 @@ += Ibex UIL / Install Coordinator option (contrib patch) + +Apply these files to link:https://github.com/dev-centr/ibex-install-builder[ibex-install-builder] when the upstream PR is not yet merged. + +== Files + +* `plugins/install_coordinator.d` — builtin plugins `uil` and `install-coordinator` +* `docs/modules/ibex/pages/install-coordinator-uil.adoc` — how-to page + +== Manual steps + +1. Copy `plugins/install_coordinator.d` into the Ibex repo `plugins/` directory. +2. Add to `source/app.d`: `import easyinstaller.plugins.install_coordinator;` +3. Merge nav entry and plugins table row from the install-coordinator PR (or copy from `patches/` below). +4. `dub build --config=application` + +== Patches + +[source,diff] +---- +--- a/docs/modules/ibex/nav.adoc ++++ b/docs/modules/ibex/nav.adoc +@@ + * xref:plugins.adoc[Plugins] ++* xref:install-coordinator-uil.adoc[Install Coordinator / UIL] +---- + +[source,diff] +---- +--- a/source/app.d ++++ b/source/app.d +@@ + import easyinstaller.plugins.appimage; ++import easyinstaller.plugins.install_coordinator; +---- diff --git a/contrib/ibex-uil-option/docs/modules/ibex/pages/install-coordinator-uil.adoc b/contrib/ibex-uil-option/docs/modules/ibex/pages/install-coordinator-uil.adoc new file mode 100644 index 0000000..3415286 --- /dev/null +++ b/contrib/ibex-uil-option/docs/modules/ibex/pages/install-coordinator-uil.adoc @@ -0,0 +1,51 @@ += Install Coordinator and UIL emit +:description: Emit Unity Install Layout manifests and coordinator job JSON from Ibex projects. +:navtitle: Install Coordinator / UIL + +Ibex can target link:https://github.com/dev-centr/install-coordinator[Install Coordinator] as the delivery runtime: **UIL** describes layout and shell claims; the **coordinator job** hands work to the daemon queue plane. + +== Select the plugin + +In `installer.kdl`: + +[source,kdl] +---- +installer { + name "MyApp" + version "1.0.0" + id "com.example.myapp" + plugin "uil" + add-to-path true + extras { + uilScope "perUser" + sideBySide "true" + emitCoordinatorJob "true" + } +} +---- + +Plugin ids: `uil` (alias) or `install-coordinator`. + +== Build outputs + +[source,bash] +---- +ibex build . +---- + +Writes under `dist/`: + +* `MyApp.uil.json` — UIL v1.0 manifest (`classic-paths` adapter) +* `MyApp.coordinator.json` — thin-stub job referencing the UIL path (MVP: `uil plan --dry-run` exec step) + +Validate on a machine with Install Coordinator: + +[source,bash] +---- +install-coordinator uil validate dist/MyApp.uil.json +install-coordinator submit dist/MyApp.coordinator.json +---- + +== Contract reference + +UIL schema and Antora reference live in the Install Coordinator repo (`docs/schema/uil-manifest.schema.json`, `uil-reference.adoc`). diff --git a/contrib/ibex-uil-option/plugins/install_coordinator.d b/contrib/ibex-uil-option/plugins/install_coordinator.d new file mode 100644 index 0000000..c4e200d --- /dev/null +++ b/contrib/ibex-uil-option/plugins/install_coordinator.d @@ -0,0 +1,173 @@ +module easyinstaller.plugins.install_coordinator; + +import easyinstaller.plugin; +import easyinstaller.project : InstallerProject, extra, extraFlag; +import std.file : exists, mkdirRecurse, write; +import std.json; +import std.path : buildPath; +import std.string : format; + +/// Emit UIL manifests and Install Coordinator job JSON (queue plane handoff). +final class InstallCoordinatorPlugin : InstallerPlugin +{ + string id() { return "install-coordinator"; } + string displayName() { return "Install Coordinator (UIL)"; } + string[] targets() { return ["all"]; } + bool canBuild() { return true; } + string detectTool() { return "install-coordinator"; } + string guiName() { return "Install Coordinator"; } + string guiInstallUrl() { return "https://github.com/dev-centr/install-coordinator"; } + string guiDetectHint() { return "install-coordinator on PATH"; } + string detectGui() { return ""; } + string installPlaybook() { return ""; } + + ExtraField[] extrasSchema() + { + return [ + ExtraField("uilScope", "string", "perUser", "perUser or perMachine layout.scope"), + ExtraField("sideBySide", "bool", "false", "Enable UIL side-by-side slot directory"), + ExtraField("emitCoordinatorJob", "bool", "true", "Also write dist/.coordinator.json"), + ]; + } + + string designerSource(const ref InstallerProject project, string outDir) + { + return buildPath(outDir, project.name ~ ".uil.json"); + } + + string emitSources(const ref InstallerProject project, string outDir) + { + if (!exists(outDir)) + mkdirRecurse(outDir); + auto uilPath = buildPath(outDir, project.name ~ ".uil.json"); + write(uilPath, emitUilJson(project)); + return "Wrote " ~ uilPath; + } + + string build(const ref InstallerProject project, string outDir) + { + if (!exists(outDir)) + mkdirRecurse(outDir); + auto uilPath = buildPath(outDir, project.name ~ ".uil.json"); + write(uilPath, emitUilJson(project)); + string[] notes = ["Wrote " ~ uilPath]; + if (extraFlag(project, "emitCoordinatorJob", true)) + { + auto jobPath = buildPath(outDir, project.name ~ ".coordinator.json"); + write(jobPath, emitCoordinatorJob(project, uilPath)); + notes ~= "Wrote " ~ jobPath; + } + return notes.join("\n"); + } + + private string emitUilJson(const ref InstallerProject project) + { + string installScope = extra(project, "uilScope", "perUser"); + bool sxs = extraFlag(project, "sideBySide", false); + JSONValue root = JSONValue.emptyObject; + root["uilVersion"] = JSONValue("1.0"); + JSONValue pkg = JSONValue.emptyObject; + pkg["id"] = JSONValue(project.id); + pkg["name"] = JSONValue(project.name); + pkg["publisher"] = JSONValue(project.publisher); + pkg["version"] = JSONValue(project.version_); + root["package"] = pkg; + JSONValue layout = JSONValue.emptyObject; + layout["adapter"] = JSONValue("classic-paths"); + layout.object["scope"] = JSONValue(installScope); + if (sxs) + { + JSONValue s = JSONValue.emptyObject; + s["enabled"] = JSONValue(true); + s["slot"] = JSONValue(project.version_); + layout["sideBySide"] = s; + } + root["layout"] = layout; + JSONValue entries = JSONValue.emptyArray; + JSONValue bin = JSONValue.emptyObject; + bin["source"] = JSONValue(project.exe.length ? project.exe : "dist/"); + bin["role"] = JSONValue("bin"); + if (project.exe.length) + bin["relativePath"] = JSONValue(project.exe); + entries.array ~= bin; + JSONValue payload = JSONValue.emptyObject; + payload["entries"] = entries; + root["payload"] = payload; + if (project.addToPath) + { + JSONValue claims = JSONValue.emptyArray; + JSONValue pe = JSONValue.emptyObject; + pe["type"] = JSONValue("path_entry"); + JSONValue dirs = JSONValue.emptyArray; + dirs.array ~= JSONValue("${role:bin}"); + pe["directories"] = dirs; + claims.array ~= pe; + root["claims"] = claims; + } + JSONValue coord = JSONValue.emptyObject; + coord["presentation"] = JSONValue("thinStub"); + coord["termsAccepted"] = JSONValue(true); + root["coordinator"] = coord; + return root.toPrettyString(); + } + + private string emitCoordinatorJob(const ref InstallerProject project, string uilPath) + { + JSONValue root = JSONValue.emptyObject; + root["displayName"] = JSONValue(project.name); + root["publisher"] = JSONValue(project.publisher); + root["version"] = JSONValue(project.version_); + root["presentation"] = JSONValue("thinStub"); + root["termsAccepted"] = JSONValue(true); + root.object["scope"] = JSONValue(extra(project, "uilScope", "perUser")); + JSONValue claims = JSONValue.emptyObject; + claims["msi"] = JSONValue(false); + root["claims"] = claims; + JSONValue steps = JSONValue.emptyArray; + JSONValue step = JSONValue.emptyObject; + step["kind"] = JSONValue("exec"); + step["path"] = JSONValue("install-coordinator"); + JSONValue args = JSONValue.emptyArray; + args.array ~= JSONValue("uil"); + args.array ~= JSONValue("plan"); + args.array ~= JSONValue(uilPath); + args.array ~= JSONValue("--dry-run"); + step["args"] = args; + steps.array ~= step; + root["steps"] = steps; + JSONValue opts = JSONValue.emptyObject; + opts["uilManifest"] = JSONValue(uilPath); + opts["uilPackageId"] = JSONValue(project.id); + root["options"] = opts; + return root.toPrettyString(); + } +} + +/// Alias plugin id `uil` for documentation and installer.kdl ergonomics. +final class UilPlugin : InstallerPlugin +{ + private InstallCoordinatorPlugin inner; + this() { inner = new InstallCoordinatorPlugin(); } + string id() { return "uil"; } + string displayName() { return "Unity Install Layout (UIL)"; } + string[] targets() { return inner.targets(); } + bool canBuild() { return inner.canBuild(); } + string detectTool() { return inner.detectTool(); } + string guiName() { return inner.guiName(); } + string guiInstallUrl() { return inner.guiInstallUrl(); } + string guiDetectHint() { return inner.guiDetectHint(); } + string detectGui() { return inner.detectGui(); } + string installPlaybook() { return inner.installPlaybook(); } + ExtraField[] extrasSchema() { return inner.extrasSchema(); } + string designerSource(const ref InstallerProject project, string outDir) { return inner.designerSource(project, outDir); } + string emitSources(const ref InstallerProject project, string outDir) { return inner.emitSources(project, outDir); } + string build(const ref InstallerProject project, string outDir) { return inner.build(project, outDir); } +} + +shared static this() +{ + registerBuiltin(new InstallCoordinatorPlugin()); + registerBuiltin(new UilPlugin()); +} + +private import std.array : join; diff --git a/docs/modules/ROOT/attachments/uil-manifest.schema.json b/docs/modules/ROOT/attachments/uil-manifest.schema.json new file mode 100644 index 0000000..8d29c3b --- /dev/null +++ b/docs/modules/ROOT/attachments/uil-manifest.schema.json @@ -0,0 +1,278 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://docs.devcentr.org/install-coordinator/latest/uil-manifest.schema.json", + "title": "Unity Install Layout (UIL) manifest", + "description": "DevCentr layout contract for Install Coordinator and Ibex emit targets. Works with classic path adapters today; maps to connectome-fs node kinds later.", + "type": "object", + "required": ["uilVersion", "package", "layout", "payload"], + "additionalProperties": false, + "properties": { + "uilVersion": { + "type": "string", + "const": "1.0", + "description": "UIL contract revision." + }, + "package": { "$ref": "#/$defs/packageIdentity" }, + "layout": { "$ref": "#/$defs/layout" }, + "payload": { "$ref": "#/$defs/payload" }, + "claims": { + "type": "array", + "items": { "$ref": "#/$defs/claim" }, + "default": [] + }, + "lifecycle": { "$ref": "#/$defs/lifecycle" }, + "journal": { "$ref": "#/$defs/journalSpec" }, + "coordinator": { "$ref": "#/$defs/coordinatorBridge" } + }, + "$defs": { + "packageIdentity": { + "type": "object", + "required": ["id", "name", "version"], + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "minLength": 1, + "description": "Stable package id (reverse-DNS or GUID-backed id in connectome-fs)." + }, + "name": { "type": "string", "minLength": 1 }, + "publisher": { "type": "string" }, + "version": { + "type": "string", + "minLength": 1, + "description": "Semantic or product version string." + }, + "edition": { + "type": "string", + "default": "default", + "description": "Edition slot for side-by-side (e.g. default, pro, lts)." + } + } + }, + "layout": { + "type": "object", + "required": ["adapter"], + "additionalProperties": false, + "properties": { + "adapter": { + "type": "string", + "enum": ["classic-paths", "connectome-fs"], + "description": "classic-paths resolves FHS / Windows / macOS roots; connectome-fs is reserved for graph-native storage." + }, + "scope": { + "type": "string", + "enum": ["perUser", "perMachine"], + "default": "perUser" + }, + "platformFamily": { + "type": "string", + "enum": ["windows", "macos", "linux", "bsd", "auto"], + "default": "auto", + "description": "When auto, the runtime picks the host OS family." + }, + "sideBySide": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { "type": "boolean", "default": false }, + "slot": { + "type": "string", + "description": "Version or edition slot directory name when side-by-side is enabled." + } + } + }, + "installRoot": { + "type": "string", + "description": "Optional explicit install root override (classic-paths only)." + } + } + }, + "payloadRole": { + "type": "string", + "enum": ["bin", "lib", "share", "state", "cache", "config", "logs"] + }, + "payloadEntry": { + "type": "object", + "required": ["source", "role"], + "additionalProperties": false, + "properties": { + "source": { + "type": "string", + "minLength": 1, + "description": "Staging path relative to manifest directory or absolute path." + }, + "role": { "$ref": "#/$defs/payloadRole" }, + "relativePath": { + "type": "string", + "description": "Path under the role root inside the install prefix." + } + } + }, + "payload": { + "type": "object", + "required": ["entries"], + "additionalProperties": false, + "properties": { + "entries": { + "type": "array", + "minItems": 1, + "items": { "$ref": "#/$defs/payloadEntry" } + } + } + }, + "claim": { + "type": "object", + "required": ["type"], + "additionalProperties": true, + "properties": { + "type": { + "type": "string", + "enum": ["path_entry", "start_menu", "file_assoc", "service", "driver", "env"] + }, + "id": { "type": "string" }, + "description": { "type": "string" } + }, + "allOf": [ + { + "if": { "properties": { "type": { "const": "path_entry" } } }, + "then": { + "required": ["directories"], + "properties": { + "directories": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "prepend": { "type": "boolean", "default": true } + } + } + }, + { + "if": { "properties": { "type": { "const": "start_menu" } } }, + "then": { + "required": ["shortcut"], + "properties": { + "shortcut": { + "type": "object", + "required": ["name", "targetRole", "targetRelative"], + "properties": { + "name": { "type": "string" }, + "targetRole": { "$ref": "#/$defs/payloadRole" }, + "targetRelative": { "type": "string" }, + "arguments": { "type": "string" }, + "iconRole": { "$ref": "#/$defs/payloadRole" }, + "iconRelative": { "type": "string" } + } + } + } + } + }, + { + "if": { "properties": { "type": { "const": "file_assoc" } } }, + "then": { + "required": ["extension", "progid"], + "properties": { + "extension": { "type": "string" }, + "progid": { "type": "string" }, + "openCommandRole": { "$ref": "#/$defs/payloadRole" }, + "openCommandRelative": { "type": "string" } + } + } + }, + { + "if": { "properties": { "type": { "const": "service" } } }, + "then": { + "required": ["serviceName"], + "properties": { + "serviceName": { "type": "string" }, + "displayName": { "type": "string" }, + "executableRole": { "$ref": "#/$defs/payloadRole" }, + "executableRelative": { "type": "string" } + } + } + }, + { + "if": { "properties": { "type": { "const": "driver" } } }, + "then": { + "required": ["infRole", "infRelative"], + "properties": { + "infRole": { "$ref": "#/$defs/payloadRole" }, + "infRelative": { "type": "string" } + } + } + }, + { + "if": { "properties": { "type": { "const": "env" } } }, + "then": { + "required": ["variables"], + "properties": { + "scope": { "type": "string", "enum": ["user", "machine", "process"] }, + "variables": { + "type": "object", + "additionalProperties": { "type": "string" } + } + } + } + } + ] + }, + "lifecycle": { + "type": "object", + "additionalProperties": false, + "properties": { + "repair": { + "type": "object", + "properties": { + "strategy": { + "type": "string", + "enum": ["reconcile-payload", "msi-repair", "custom"], + "default": "reconcile-payload" + }, + "notes": { "type": "string" } + } + }, + "uninstall": { + "type": "object", + "properties": { + "strategy": { + "type": "string", + "enum": ["remove-payload-and-claims", "msi-uninstall", "custom"], + "default": "remove-payload-and-claims" + }, + "removeState": { "type": "boolean", "default": false }, + "removeCache": { "type": "boolean", "default": true } + } + } + } + }, + "journalSpec": { + "type": "object", + "additionalProperties": false, + "properties": { + "format": { + "type": "string", + "const": "uil-journal-v1" + }, + "persistPath": { + "type": "string", + "description": "Where the apply journal is written under the state role." + } + } + }, + "coordinatorBridge": { + "type": "object", + "description": "Optional handoff to Install Coordinator queue plane.", + "additionalProperties": false, + "properties": { + "presentation": { + "type": "string", + "enum": ["thinStub", "detachedCollect", "embeddedQueue"] + }, + "termsAccepted": { "type": "boolean" }, + "options": { + "type": "object", + "additionalProperties": { "type": "string" } + } + } + } + } +} diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index 27f6f89..8182480 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -1 +1,4 @@ * xref:index.adoc[Overview] +* xref:framework.adoc[Framework + UIL] +* xref:uil-reference.adoc[UIL reference] +* xref:connectome-fs.adoc[Connectome-fs mapping] diff --git a/docs/modules/ROOT/pages/connectome-fs.adoc b/docs/modules/ROOT/pages/connectome-fs.adoc new file mode 100644 index 0000000..6d4afd9 --- /dev/null +++ b/docs/modules/ROOT/pages/connectome-fs.adoc @@ -0,0 +1,30 @@ += UIL on connectome-fs (adapter notes) +:description: How UIL package identity, roles, and claims map to graph-native storage. +:navtitle: Connectome-fs mapping + +Connectome-fs treats paths as views over GUID nodes with multi-names and association edges. UIL's `layout.adapter: connectome-fs` reserves the same JSON document shape as `classic-paths`; only resolution changes. + +== Node kinds (planned) + +[cols="1,2"] +|=== +| UIL concept | Connectome node kind + +| `package.id` | `Package` node (stable GUID; human id as alias) +| `package.edition` | `Edition` child of package +| `layout.sideBySide.slot` | `VersionSlot` or edge label on `Edition` +| Payload `source` | `PayloadBlob` (content-addressed) or `StagingRef` +| Payload `role` | `RoleMount` edge to `Namespace` (`bin`, `lib`, …) +| `claims[]` | `ClaimBinding` edges (`PathEntry`, `StartMenu`, …) +| `journal` | `TransactionLog` node under state namespace +|=== + +== Associations + +* **Hierarchy view** — classic paths appear as one naming view; another view may expose the same `bin` executable under a Start Menu alias node. +* **Claims** — `path_entry` binds a `Directory` node to the shell orientation graph (PATH refresh), matching OpenShell's discoverability goals. +* **Repair** — `reconcile-payload` compares `PayloadBlob` hashes on associations; journal replay uses edge insert/delete instead of `copy`/`remove` file ops. + +== Runtime status + +Install Coordinator validates `connectome-fs` manifests but planning requires `classic-paths` until the connectome adapter ships. Ibex should still emit `classic-paths` for production targets. diff --git a/docs/modules/ROOT/pages/framework.adoc b/docs/modules/ROOT/pages/framework.adoc new file mode 100644 index 0000000..0f93c30 --- /dev/null +++ b/docs/modules/ROOT/pages/framework.adoc @@ -0,0 +1,43 @@ += Install Coordinator as installer framework +:description: Queue plane plus Unity Install Layout (UIL) — how DevCentr packages install without fighting MSI global mutex. +:navtitle: Framework + +Install Coordinator is two cooperating layers: + +* **Queue plane** — daemon, job state machine, MSI lane (`Global\_MSIExecute`), path-claim scheduling, user/admin surfaces. +* **Layout contract (UIL)** — declarative package identity, payload roles, shell/discoverability claims, transaction journal, repair/uninstall semantics. + +Ibex (link:https://github.com/dev-centr/ibex-install-builder[ibex-install-builder]) authors projects; emit targets can produce UIL manifests and thin-stub coordinator jobs that hand work to the daemon. + +== Queue plane recap + +[source,shell] +---- +install-coordinator daemon +install-coordinator submit examples/thin-stub-msi.job.json +install-coordinator gui +---- + +Jobs move `collecting` → `ready` → `queued` → `executing` → terminal states. MSI steps share one lane; disjoint path claims may run in parallel. + +== UIL layout plane + +UIL answers *where* payload lands on classic OS layouts today, and *what orientation claims* (PATH, Start Menu, associations, services, drivers, environment) must be refreshed so OpenShell-style discovery stays accurate. + +[source,shell] +---- +install-coordinator uil validate examples/uil-classic-demo.uil.json +install-coordinator uil plan examples/uil-classic-demo.uil.json --dry-run +install-coordinator uil emit-coordinator examples/uil-classic-demo.uil.json dist/demo.job.json +---- + +The MVP apply engine validates, plans classic paths, and prints a forward/rollback journal (dry-run). File copy and claim application will wrap the same journal records used by MSI/exec steps on the queue plane. + +== Authoring flow (Ibex → Coordinator) + +. Ibex project selects plugin `install-coordinator` or `uil`. +. Build emits `dist/.uil.json` and optional `dist/.coordinator.json`. +. End user runs the stub (`install-coordinator submit …`) or an Ibex-produced launcher. +. Coordinator queues work; UIL plan/journal runs inside exec steps as apply matures. + +See xref:uil-reference.adoc[UIL reference] for field-level detail and xref:connectome-fs.adoc[Connectome-fs mapping notes]. diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 1c2d6b6..329bce1 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -38,7 +38,17 @@ curl -H "Authorization: Bearer YOUR_SECRET" http://HOST:17420/jobs Package managers like UniGetUI can still install many apps; Install Coordinator helps when users double-click several EXE/MSI installers and hit error 1618. Desktop / Start Menu shortcuts work from the user UI or CLI. +== Installer framework (UIL) + +Install Coordinator is documented as a **queue plane** plus the **Unity Install Layout (UIL)** contract for package roles, shell claims, and transaction journals. Start with xref:framework.adoc[Framework + UIL] and xref:uil-reference.adoc[UIL reference]. + +[source,shell] +---- +install-coordinator uil validate examples/uil-classic-demo.uil.json +install-coordinator uil plan examples/uil-classic-demo.uil.json --dry-run +---- + == Related -* link:https://github.com/dev-centr/easy-installer[Ibex / Easy Installer] — project authoring and plugin emit +* link:https://github.com/dev-centr/ibex-install-builder[Ibex install builder] — authoring; emit `uil` / `install-coordinator` targets * link:https://devcentr.org/news/2026-08-29-when-unrelated-installers-still-queue[Essay: When unrelated installers still queue] diff --git a/docs/modules/ROOT/pages/uil-reference.adoc b/docs/modules/ROOT/pages/uil-reference.adoc new file mode 100644 index 0000000..35d236b --- /dev/null +++ b/docs/modules/ROOT/pages/uil-reference.adoc @@ -0,0 +1,101 @@ += Unity Install Layout (UIL) reference +:description: JSON manifest contract for package layout, claims, journal, repair, and uninstall. +:navtitle: UIL reference + +UIL version `1.0` is the first stable contract between Ibex emitters and Install Coordinator. + +Machine-readable schema: xref:attachment$uil-manifest.schema.json[uil-manifest.schema.json] (source in the repo at `docs/schema/`). + +== Top-level document + +[cols="1,3"] +|=== +| Field | Purpose + +| `uilVersion` +| Must be `"1.0"`. + +| `package` +| Identity: `id`, `name`, `version`, optional `publisher`, `edition`. + +| `layout` +| `adapter` (`classic-paths` \| `connectome-fs`), `scope`, `platformFamily`, optional `sideBySide`, `installRoot`. + +| `payload.entries[]` +| Staged `source` files mapped into role roots with optional `relativePath`. + +| `claims[]` +| Orientation / integration: `path_entry`, `start_menu`, `file_assoc`, `service`, `driver`, `env`. + +| `lifecycle` +| `repair` and `uninstall` strategies. + +| `journal` +| Transaction log format (`uil-journal-v1`) and optional persist path under the state role. + +| `coordinator` +| Bridge fields for thin-stub jobs (`presentation`, `termsAccepted`, `options`). +|=== + +== Payload roles + +Classic adapters map roles to install-prefix subtrees (FHS-like on Unix, `Program Files` / `%LOCALAPPDATA%\Programs` on Windows, `~/Applications` or `/Library` on macOS): + +* `bin` — executables (PATH claims usually target this root) +* `lib` — private libraries +* `share` — read-only assets, documentation +* `state` — mutable application state, journals +* `cache` — regenerable cache +* `config` — configuration files +* `logs` — log output + +== Claims and shell refresh + +Installs must update discoverability, not only copy bytes: + +* `path_entry` — directories prepended or appended to PATH (or platform equivalent). +* `start_menu` — shortcut metadata pointing at a `bin` payload relative path. +* `file_assoc` — extension ↔ handler binding. +* `service` / `driver` — OS service or driver registration (planned apply). +* `env` — user/machine/process environment variables (often referencing `${prefix}`). + +Token expansion in claim paths: + +* `${prefix}` / `${installRoot}` — resolved install prefix for the plan. +* `${role:bin}` (and other roles) — resolved role root from the classic adapter. + +== Side-by-side and editions + +`package.edition` names a product edition (default, pro, lts). When `layout.sideBySide.enabled` is true, `layout.sideBySide.slot` (often the version string) becomes an extra directory under the prefix so multiple versions coexist. + +== Lifecycle + +[cols="1,2"] +|=== +| Strategy | Meaning + +| `reconcile-payload` (repair) +| Re-apply payload entries and refresh claims from the journal. + +| `remove-payload-and-claims` (uninstall) +| Reverse journal operations; optional retention of `state` vs `cache` via flags. +|=== + +MSI-specific `msi-repair` / `msi-uninstall` strategies exist for hybrid packages that still route through `msiexec` on the queue plane. + +== Transaction journal + +Journal records are ordered `mkdir`, `copy`, claim operations, with rollback counterparts (`remove`, claim undo). The D library builds this journal during `uil plan` and prints it in dry-run mode until the apply engine lands. + +== Classic path adapters + +| OS family | per-user prefix (default) | per-machine prefix (default) +| Windows | `%LOCALAPPDATA%\Programs\\` | `%ProgramFiles%\\` +| macOS | `~/Applications//` | `/Library/Application Support//` +| Linux / BSD | `~/.local/opt//` | `/opt//` + +Override any prefix with `layout.installRoot`. + +== Connectome-fs (forward) + +See xref:connectome-fs.adoc[Connectome-fs adapter notes]. Author manifests with `classic-paths` today; the same logical roles and claims map to GUID nodes without changing Ibex emit shape. diff --git a/docs/schema/uil-manifest.schema.json b/docs/schema/uil-manifest.schema.json new file mode 100644 index 0000000..8d29c3b --- /dev/null +++ b/docs/schema/uil-manifest.schema.json @@ -0,0 +1,278 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://docs.devcentr.org/install-coordinator/latest/uil-manifest.schema.json", + "title": "Unity Install Layout (UIL) manifest", + "description": "DevCentr layout contract for Install Coordinator and Ibex emit targets. Works with classic path adapters today; maps to connectome-fs node kinds later.", + "type": "object", + "required": ["uilVersion", "package", "layout", "payload"], + "additionalProperties": false, + "properties": { + "uilVersion": { + "type": "string", + "const": "1.0", + "description": "UIL contract revision." + }, + "package": { "$ref": "#/$defs/packageIdentity" }, + "layout": { "$ref": "#/$defs/layout" }, + "payload": { "$ref": "#/$defs/payload" }, + "claims": { + "type": "array", + "items": { "$ref": "#/$defs/claim" }, + "default": [] + }, + "lifecycle": { "$ref": "#/$defs/lifecycle" }, + "journal": { "$ref": "#/$defs/journalSpec" }, + "coordinator": { "$ref": "#/$defs/coordinatorBridge" } + }, + "$defs": { + "packageIdentity": { + "type": "object", + "required": ["id", "name", "version"], + "additionalProperties": false, + "properties": { + "id": { + "type": "string", + "minLength": 1, + "description": "Stable package id (reverse-DNS or GUID-backed id in connectome-fs)." + }, + "name": { "type": "string", "minLength": 1 }, + "publisher": { "type": "string" }, + "version": { + "type": "string", + "minLength": 1, + "description": "Semantic or product version string." + }, + "edition": { + "type": "string", + "default": "default", + "description": "Edition slot for side-by-side (e.g. default, pro, lts)." + } + } + }, + "layout": { + "type": "object", + "required": ["adapter"], + "additionalProperties": false, + "properties": { + "adapter": { + "type": "string", + "enum": ["classic-paths", "connectome-fs"], + "description": "classic-paths resolves FHS / Windows / macOS roots; connectome-fs is reserved for graph-native storage." + }, + "scope": { + "type": "string", + "enum": ["perUser", "perMachine"], + "default": "perUser" + }, + "platformFamily": { + "type": "string", + "enum": ["windows", "macos", "linux", "bsd", "auto"], + "default": "auto", + "description": "When auto, the runtime picks the host OS family." + }, + "sideBySide": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { "type": "boolean", "default": false }, + "slot": { + "type": "string", + "description": "Version or edition slot directory name when side-by-side is enabled." + } + } + }, + "installRoot": { + "type": "string", + "description": "Optional explicit install root override (classic-paths only)." + } + } + }, + "payloadRole": { + "type": "string", + "enum": ["bin", "lib", "share", "state", "cache", "config", "logs"] + }, + "payloadEntry": { + "type": "object", + "required": ["source", "role"], + "additionalProperties": false, + "properties": { + "source": { + "type": "string", + "minLength": 1, + "description": "Staging path relative to manifest directory or absolute path." + }, + "role": { "$ref": "#/$defs/payloadRole" }, + "relativePath": { + "type": "string", + "description": "Path under the role root inside the install prefix." + } + } + }, + "payload": { + "type": "object", + "required": ["entries"], + "additionalProperties": false, + "properties": { + "entries": { + "type": "array", + "minItems": 1, + "items": { "$ref": "#/$defs/payloadEntry" } + } + } + }, + "claim": { + "type": "object", + "required": ["type"], + "additionalProperties": true, + "properties": { + "type": { + "type": "string", + "enum": ["path_entry", "start_menu", "file_assoc", "service", "driver", "env"] + }, + "id": { "type": "string" }, + "description": { "type": "string" } + }, + "allOf": [ + { + "if": { "properties": { "type": { "const": "path_entry" } } }, + "then": { + "required": ["directories"], + "properties": { + "directories": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "prepend": { "type": "boolean", "default": true } + } + } + }, + { + "if": { "properties": { "type": { "const": "start_menu" } } }, + "then": { + "required": ["shortcut"], + "properties": { + "shortcut": { + "type": "object", + "required": ["name", "targetRole", "targetRelative"], + "properties": { + "name": { "type": "string" }, + "targetRole": { "$ref": "#/$defs/payloadRole" }, + "targetRelative": { "type": "string" }, + "arguments": { "type": "string" }, + "iconRole": { "$ref": "#/$defs/payloadRole" }, + "iconRelative": { "type": "string" } + } + } + } + } + }, + { + "if": { "properties": { "type": { "const": "file_assoc" } } }, + "then": { + "required": ["extension", "progid"], + "properties": { + "extension": { "type": "string" }, + "progid": { "type": "string" }, + "openCommandRole": { "$ref": "#/$defs/payloadRole" }, + "openCommandRelative": { "type": "string" } + } + } + }, + { + "if": { "properties": { "type": { "const": "service" } } }, + "then": { + "required": ["serviceName"], + "properties": { + "serviceName": { "type": "string" }, + "displayName": { "type": "string" }, + "executableRole": { "$ref": "#/$defs/payloadRole" }, + "executableRelative": { "type": "string" } + } + } + }, + { + "if": { "properties": { "type": { "const": "driver" } } }, + "then": { + "required": ["infRole", "infRelative"], + "properties": { + "infRole": { "$ref": "#/$defs/payloadRole" }, + "infRelative": { "type": "string" } + } + } + }, + { + "if": { "properties": { "type": { "const": "env" } } }, + "then": { + "required": ["variables"], + "properties": { + "scope": { "type": "string", "enum": ["user", "machine", "process"] }, + "variables": { + "type": "object", + "additionalProperties": { "type": "string" } + } + } + } + } + ] + }, + "lifecycle": { + "type": "object", + "additionalProperties": false, + "properties": { + "repair": { + "type": "object", + "properties": { + "strategy": { + "type": "string", + "enum": ["reconcile-payload", "msi-repair", "custom"], + "default": "reconcile-payload" + }, + "notes": { "type": "string" } + } + }, + "uninstall": { + "type": "object", + "properties": { + "strategy": { + "type": "string", + "enum": ["remove-payload-and-claims", "msi-uninstall", "custom"], + "default": "remove-payload-and-claims" + }, + "removeState": { "type": "boolean", "default": false }, + "removeCache": { "type": "boolean", "default": true } + } + } + } + }, + "journalSpec": { + "type": "object", + "additionalProperties": false, + "properties": { + "format": { + "type": "string", + "const": "uil-journal-v1" + }, + "persistPath": { + "type": "string", + "description": "Where the apply journal is written under the state role." + } + } + }, + "coordinatorBridge": { + "type": "object", + "description": "Optional handoff to Install Coordinator queue plane.", + "additionalProperties": false, + "properties": { + "presentation": { + "type": "string", + "enum": ["thinStub", "detachedCollect", "embeddedQueue"] + }, + "termsAccepted": { "type": "boolean" }, + "options": { + "type": "object", + "additionalProperties": { "type": "string" } + } + } + } + } +} diff --git a/examples/thin-stub-msi.job.json b/examples/thin-stub-msi.job.json new file mode 100644 index 0000000..5f4699e --- /dev/null +++ b/examples/thin-stub-msi.job.json @@ -0,0 +1,23 @@ +{ + "displayName": "Sample MSI (thin stub)", + "publisher": "Example Corp", + "version": "1.0.0", + "presentation": "thinStub", + "termsAccepted": true, + "scope": "perUser", + "claims": { + "msi": true, + "paths": ["${ProgramFiles}/SampleApp/**"] + }, + "steps": [ + { + "kind": "msiexec", + "path": "C:/path/to/sample.msi", + "args": ["/passive", "/norestart"] + } + ], + "options": { + "installDir": "C:/Program Files/SampleApp", + "notes": "Queue-plane job only — serialized through the MSI lane. Pair with a UIL manifest when Ibex emits layout + coordinator together." + } +} diff --git a/examples/uil-classic-demo.uil.json b/examples/uil-classic-demo.uil.json new file mode 100644 index 0000000..a3a3cd7 --- /dev/null +++ b/examples/uil-classic-demo.uil.json @@ -0,0 +1,81 @@ +{ + "uilVersion": "1.0", + "package": { + "id": "dev-centr.uil-demo", + "name": "UIL Classic Demo", + "publisher": "DevCentr", + "version": "1.2.0", + "edition": "default" + }, + "layout": { + "adapter": "classic-paths", + "scope": "perUser", + "platformFamily": "auto", + "sideBySide": { + "enabled": true, + "slot": "1.2.0" + } + }, + "payload": { + "entries": [ + { + "source": "staging/bin/uil-demo", + "role": "bin", + "relativePath": "uil-demo" + }, + { + "source": "staging/share/doc/README.txt", + "role": "share", + "relativePath": "doc/README.txt" + }, + { + "source": "staging/state/installed.json", + "role": "state", + "relativePath": "installed.json" + } + ] + }, + "claims": [ + { + "type": "path_entry", + "id": "demo-bin", + "directories": ["${role:bin}"], + "prepend": true + }, + { + "type": "start_menu", + "shortcut": { + "name": "UIL Demo", + "targetRole": "bin", + "targetRelative": "uil-demo" + } + }, + { + "type": "env", + "id": "demo-home", + "scope": "user", + "variables": { + "UIL_DEMO_HOME": "${prefix}" + } + } + ], + "lifecycle": { + "repair": { "strategy": "reconcile-payload" }, + "uninstall": { + "strategy": "remove-payload-and-claims", + "removeState": false, + "removeCache": true + } + }, + "journal": { + "format": "uil-journal-v1", + "persistPath": "state/transactions/latest.json" + }, + "coordinator": { + "presentation": "thinStub", + "termsAccepted": true, + "options": { + "ibexProject": "uil-classic-demo" + } + } +} diff --git a/source/app.d b/source/app.d index faf53b2..333b7e1 100644 --- a/source/app.d +++ b/source/app.d @@ -8,6 +8,7 @@ import installcoordinator.store; import installcoordinator.stub; import installcoordinator.types; import installcoordinator.versioninfo; +import installcoordinator.uil_cli; import std.conv : to; import std.file : exists, readText, write; import std.json; @@ -56,6 +57,8 @@ int main(string[] args) return cmdShortcut(args[2 .. $]); case "new-manifest": return cmdNewManifest(args[2 .. $]); + case "uil": + return cmdUil(args[2 .. $]); case "help": case "--help": case "-h": @@ -87,6 +90,7 @@ Commands: session [--lock-elevation] [--scope=perMachine] [--batch-terms] shortcut --desktop|--start-menu new-manifest [out.json] + uil validate|plan|emit-coordinator ping Daemon health check Presentation modes (manifest field presentation): diff --git a/source/installcoordinator/client.d b/source/installcoordinator/client.d index efe3e6c..14be147 100644 --- a/source/installcoordinator/client.d +++ b/source/installcoordinator/client.d @@ -76,14 +76,15 @@ private string pipeRoundTripUnix(string line) if (!exists(sockPath)) throw new Exception("daemon socket missing — run install-coordinator daemon"); auto addr = new UnixAddress(sockPath); - auto sock = socket(PF_LOCAL, SocketType.STREAM, 0); + auto sock = new Socket(AddressFamily.UNIX, SocketType.STREAM); scope (exit) sock.close(); sock.connect(addr); line ~= "\n"; sock.send(line); char[65536] buf; auto n = sock.receive(buf); - return cast(string) buf[0 .. n].strip(); + string s = cast(string) buf[0 .. n].idup; + return s.strip(); } bool daemonRunning() diff --git a/source/installcoordinator/daemon.d b/source/installcoordinator/daemon.d index 2edebe9..ed398b7 100644 --- a/source/installcoordinator/daemon.d +++ b/source/installcoordinator/daemon.d @@ -64,7 +64,7 @@ final class CoordinatorDaemon } else { - import std.process : getpid; + import core.sys.posix.unistd : getpid; write(daemonPidFile(), to!string(getpid())); } } @@ -127,7 +127,7 @@ private int runUnixSocketServer() if (exists(sockPath)) remove(sockPath); auto addr = new UnixAddress(sockPath); - auto listener = socket(PF_LOCAL, SocketType.STREAM, 0); + auto listener = new Socket(AddressFamily.UNIX, SocketType.STREAM); scope (exit) listener.close(); listener.bind(addr); listener.listen(8); diff --git a/source/installcoordinator/uil/classic_paths.d b/source/installcoordinator/uil/classic_paths.d new file mode 100644 index 0000000..6d1cf75 --- /dev/null +++ b/source/installcoordinator/uil/classic_paths.d @@ -0,0 +1,205 @@ +module installcoordinator.uil.classic_paths; + +import installcoordinator.types : InstallScope; +import installcoordinator.uil.types; +import std.algorithm.searching : startsWith; +import std.string : indexOf; +import std.path : buildPath, dirName, baseName; +import std.process : environment; + +struct RoleRoots +{ + string[PayloadRole.max + 1] roots; +} + +struct ResolvedPayload +{ + PayloadRole role; + string source; + string destination; +} + +struct ClassicInstallPlan +{ + PlatformFamily platform; + InstallScope installScope; + string installPrefix; + RoleRoots roles; + ResolvedPayload[] files; + string[] claimNotes; +} + +PlatformFamily hostPlatformFamily() +{ + version (Windows) + return PlatformFamily.windows; + else version (OSX) + return PlatformFamily.macos; + else version (linux) + return PlatformFamily.linux; + else version (BSD) + return PlatformFamily.bsd; + else + return PlatformFamily.linux; +} + +PlatformFamily effectivePlatform(const ref UilLayout layout) +{ + if (layout.platformFamily != PlatformFamily.host) + return layout.platformFamily; + return hostPlatformFamily(); +} + +string defaultInstallPrefix(const ref UilManifest m, PlatformFamily pf) +{ + if (m.layout.installRoot.length) + return m.layout.installRoot; + + string slot = m.layout.sideBySide.enabled ? m.layout.sideBySide.slot : m.package_.version_; + if (!slot.length) + slot = m.package_.edition; + + auto idTail = sanitizePackageId(m.package_.id); + + final switch (pf) + { + case PlatformFamily.windows: + if (m.layout.installScope == InstallScope.perMachine) + return buildPath(environment.get("ProgramFiles", "C:/Program Files"), idTail, slot); + return buildPath(environment.get("LOCALAPPDATA", ""), "Programs", idTail, slot); + case PlatformFamily.macos: + if (m.layout.installScope == InstallScope.perMachine) + return buildPath("/Library/Application Support", idTail, slot); + return buildPath(environment.get("HOME", ""), "Applications", idTail, slot); + case PlatformFamily.linux, PlatformFamily.bsd, PlatformFamily.host: + if (m.layout.installScope == InstallScope.perMachine) + return buildPath("/opt", idTail, slot); + return buildPath(environment.get("HOME", ""), ".local", "opt", idTail, slot); + } +} + +RoleRoots roleRootsFor(string prefix, PlatformFamily pf) +{ + RoleRoots r; + final switch (pf) + { + case PlatformFamily.windows: + r.roots[PayloadRole.bin] = buildPath(prefix, "bin"); + r.roots[PayloadRole.lib] = buildPath(prefix, "lib"); + r.roots[PayloadRole.share] = buildPath(prefix, "share"); + r.roots[PayloadRole.state] = buildPath(prefix, "state"); + r.roots[PayloadRole.cache] = buildPath(prefix, "cache"); + r.roots[PayloadRole.config] = buildPath(prefix, "config"); + r.roots[PayloadRole.logs] = buildPath(prefix, "logs"); + break; + case PlatformFamily.macos: + r.roots[PayloadRole.bin] = buildPath(prefix, "bin"); + r.roots[PayloadRole.lib] = buildPath(prefix, "lib"); + r.roots[PayloadRole.share] = buildPath(prefix, "share"); + r.roots[PayloadRole.state] = buildPath(prefix, "Library", "Application Support", "state"); + r.roots[PayloadRole.cache] = buildPath(prefix, "Library", "Caches"); + r.roots[PayloadRole.config] = buildPath(prefix, "Library", "Preferences"); + r.roots[PayloadRole.logs] = buildPath(prefix, "Library", "Logs"); + break; + case PlatformFamily.linux, PlatformFamily.bsd, PlatformFamily.host: + r.roots[PayloadRole.bin] = buildPath(prefix, "bin"); + r.roots[PayloadRole.lib] = buildPath(prefix, "lib"); + r.roots[PayloadRole.share] = buildPath(prefix, "share"); + r.roots[PayloadRole.state] = buildPath(prefix, "var", "state"); + r.roots[PayloadRole.cache] = buildPath(prefix, "var", "cache"); + r.roots[PayloadRole.config] = buildPath(prefix, "etc"); + r.roots[PayloadRole.logs] = buildPath(prefix, "var", "log"); + break; + } + return r; +} + +ClassicInstallPlan planClassicPaths(const ref UilManifest m, string manifestDir = "") +{ + ClassicInstallPlan plan; + plan.platform = effectivePlatform(m.layout); + plan.installScope = m.layout.installScope; + plan.installPrefix = defaultInstallPrefix(m, plan.platform); + plan.roles = roleRootsFor(plan.installPrefix, plan.platform); + + foreach (e; m.entries) + { + ResolvedPayload rp; + rp.role = e.role; + rp.source = resolveSourcePath(e.source, manifestDir, m.sourcePath); + auto rel = e.relativePath.length ? e.relativePath : baseName(e.source); + rp.destination = buildPath(plan.roles.roots[e.role], rel); + plan.files ~= rp; + } + + foreach (c; m.claims) + { + final switch (c.kind) + { + case ClaimKind.pathEntry: + foreach (d; c.pathEntryDirectories) + plan.claimNotes ~= "path_entry: " ~ expandClaimPath(d, plan) ~ (c.pathEntryPrepend ? " (prepend)" : ""); + break; + case ClaimKind.startMenu: + auto target = buildPath(plan.roles.roots[c.startMenu.targetRole], c.startMenu.targetRelative); + plan.claimNotes ~= "start_menu: " ~ c.startMenu.name ~ " -> " ~ target; + break; + case ClaimKind.fileAssoc: + plan.claimNotes ~= "file_assoc: ." ~ c.fileExtension ~ " (" ~ c.progid ~ ")"; + break; + case ClaimKind.service: + plan.claimNotes ~= "service: " ~ c.serviceName; + break; + case ClaimKind.driver: + plan.claimNotes ~= "driver: " ~ buildPath(plan.roles.roots[c.driverInfRole], c.driverInfRelative); + break; + case ClaimKind.env: + foreach (k, v; c.envVariables) + plan.claimNotes ~= "env[" ~ c.envScope ~ "]: " ~ k ~ "=" ~ v; + break; + } + } + return plan; +} + +string sanitizePackageId(string id) +{ + char[] buf = id.dup; + foreach (ref c; buf) + { + if (c == '.' || c == '/' || c == '\\') + c = '-'; + } + return cast(string) buf; +} + +string resolveSourcePath(string source, string manifestDir, string manifestPath) +{ + import std.path : isAbsolute; + if (isAbsolute(source)) + return source; + if (manifestDir.length) + return buildPath(manifestDir, source); + if (manifestPath.length) + return buildPath(dirName(manifestPath), source); + return source; +} + +string expandClaimPath(string token, const ref ClassicInstallPlan plan) +{ + if (token == "${prefix}" || token == "${installRoot}") + return plan.installPrefix; + if (token.startsWith("${role:")) + { + auto end = indexOf(token, '}'); + if (end > 6) + { + auto roleName = token[7 .. end]; + auto role = parsePayloadRole(roleName); + return plan.roles.roots[role]; + } + } + if (token.startsWith("${bin}")) + return plan.roles.roots[PayloadRole.bin]; + return token; +} diff --git a/source/installcoordinator/uil/coordinator_emit.d b/source/installcoordinator/uil/coordinator_emit.d new file mode 100644 index 0000000..df7bf64 --- /dev/null +++ b/source/installcoordinator/uil/coordinator_emit.d @@ -0,0 +1,56 @@ +module installcoordinator.uil.coordinator_emit; + +import installcoordinator.manifest : manifestTemplate; +import installcoordinator.uil.types; +import std.json; +import std.path : absolutePath; + +/// Build a thin-stub Install Coordinator job that references a UIL manifest for planning/apply. +string coordinatorJobJson(const ref UilManifest m, string uilPath) +{ + JSONValue root = JSONValue.emptyObject; + root["displayName"] = JSONValue(m.package_.name); + root["publisher"] = JSONValue(m.package_.publisher); + root["version"] = JSONValue(m.package_.version_); + root["presentation"] = JSONValue(m.coordinator.presentation.length ? m.coordinator.presentation : "thinStub"); + root["termsAccepted"] = JSONValue(m.coordinator.termsAccepted); + root["scope"] = JSONValue(m.layout.installScope == InstallScope.perMachine ? "perMachine" : "perUser"); + + JSONValue claims = JSONValue.emptyObject; + claims["msi"] = JSONValue(false); + JSONValue paths = JSONValue.emptyArray; + paths.array ~= JSONValue("${installRoot}/**"); + claims["paths"] = paths; + root["claims"] = claims; + + JSONValue steps = JSONValue.emptyArray; + JSONValue step = JSONValue.emptyObject; + step["kind"] = JSONValue("exec"); + step["path"] = JSONValue("install-coordinator"); + JSONValue args = JSONValue.emptyArray; + args.array ~= JSONValue("uil"); + args.array ~= JSONValue("plan"); + args.array ~= JSONValue(absolutePath(uilPath)); + args.array ~= JSONValue("--dry-run"); + step["args"] = args; + steps.array ~= step; + root["steps"] = steps; + + JSONValue opts = JSONValue.emptyObject; + opts["uilManifest"] = JSONValue(absolutePath(uilPath)); + opts["uilPackageId"] = JSONValue(m.package_.id); + opts["uilEdition"] = JSONValue(m.package_.edition); + foreach (k, v; m.coordinator.options) + opts[k] = JSONValue(v); + root["options"] = opts; + + return root.toPrettyString(); +} + +/// MSI thin-stub job (queue plane only). +string msiThinStubJobJson(string displayName, string msiPath, string publisher = "", string version_ = "") +{ + return manifestTemplate(displayName, msiPath); +} + +private import installcoordinator.types : InstallScope; diff --git a/source/installcoordinator/uil/journal.d b/source/installcoordinator/uil/journal.d new file mode 100644 index 0000000..0de2303 --- /dev/null +++ b/source/installcoordinator/uil/journal.d @@ -0,0 +1,179 @@ +module installcoordinator.uil.journal; + +import installcoordinator.uil.classic_paths; +import installcoordinator.uil.types; +import std.datetime.systime; +import std.json; +import std.stdio : writeln; + +enum JournalOpKind +{ + mkdir, + copyFile, + claimPathEntry, + claimStartMenu, + claimFileAssoc, + claimService, + claimDriver, + claimEnv, + removeFile, +} + +struct JournalOperation +{ + JournalOpKind kind; + string source; + string destination; + string detail; +} + +struct InstallJournal +{ + string format = "uil-journal-v1"; + string packageId; + string packageVersion; + SysTime startedAt; + JournalOperation[] forward; + JournalOperation[] rollback; +} + +InstallJournal buildJournal(const ref UilManifest m, const ref ClassicInstallPlan plan) +{ + InstallJournal j; + j.format = m.journal.format.length ? m.journal.format : "uil-journal-v1"; + j.packageId = m.package_.id; + j.packageVersion = m.package_.version_; + j.startedAt = Clock.currTime(); + + foreach (f; plan.files) + { + JournalOperation mk; + mk.kind = JournalOpKind.mkdir; + mk.destination = dirNameOnly(f.destination); + j.forward ~= mk; + + JournalOperation cp; + cp.kind = JournalOpKind.copyFile; + cp.source = f.source; + cp.destination = f.destination; + j.forward ~= cp; + + JournalOperation rm; + rm.kind = JournalOpKind.removeFile; + rm.destination = f.destination; + j.rollback ~= rm; + } + + foreach (note; plan.claimNotes) + { + JournalOperation claim; + claim.detail = note; + if (note.startsWith("path_entry:")) + claim.kind = JournalOpKind.claimPathEntry; + else if (note.startsWith("start_menu:")) + claim.kind = JournalOpKind.claimStartMenu; + else if (note.startsWith("file_assoc:")) + claim.kind = JournalOpKind.claimFileAssoc; + else if (note.startsWith("service:")) + claim.kind = JournalOpKind.claimService; + else if (note.startsWith("driver:")) + claim.kind = JournalOpKind.claimDriver; + else if (note.startsWith("env[")) + claim.kind = JournalOpKind.claimEnv; + else + continue; + claim.detail = note; + j.forward ~= claim; + j.rollback ~= claim; // MVP: claims reversed in a future apply engine + } + + return j; +} + +void printJournalDryRun(const ref InstallJournal j) +{ + writeln("UIL journal (dry-run) format=", j.format, " package=", j.packageId, "@", j.packageVersion); + foreach (op; j.forward) + writeln(" + ", journalOpLabel(op)); +} + +void printRollbackDryRun(const ref InstallJournal j) +{ + writeln("UIL rollback (dry-run) operations=", j.rollback.length); + foreach (op; j.rollback) + writeln(" - ", journalOpLabel(op)); +} + +ApplyResult applyJournalDryRun(const ref InstallJournal j) +{ + printJournalDryRun(j); + ApplyResult r; + r.dryRun = true; + r.operationsPlanned = j.forward.length; + return r; +} + +struct ApplyResult +{ + bool dryRun; + size_t operationsPlanned; + string error; +} + +JSONValue journalToJson(const ref InstallJournal j) +{ + JSONValue ops = JSONValue.emptyArray; + foreach (op; j.forward) + { + JSONValue o = JSONValue.emptyObject; + o["kind"] = JSONValue(journalOpKindLabel(op.kind)); + if (op.source.length) + o["source"] = JSONValue(op.source); + if (op.destination.length) + o["destination"] = JSONValue(op.destination); + if (op.detail.length) + o["detail"] = JSONValue(op.detail); + ops.array ~= o; + } + JSONValue root = JSONValue.emptyObject; + root["format"] = JSONValue(j.format); + root["packageId"] = JSONValue(j.packageId); + root["packageVersion"] = JSONValue(j.packageVersion); + root["startedAt"] = JSONValue(j.startedAt.toISOExtString()); + root["operations"] = ops; + return root; +} + +private string dirNameOnly(string path) +{ + import std.path : dirName; + return dirName(path); +} + +private string journalOpLabel(const ref JournalOperation op) +{ + auto k = journalOpKindLabel(op.kind); + if (op.kind == JournalOpKind.copyFile) + return k ~ " " ~ op.source ~ " -> " ~ op.destination; + if (op.destination.length) + return k ~ " " ~ op.destination; + return k ~ " " ~ op.detail; +} + +private string journalOpKindLabel(JournalOpKind k) @safe +{ + final switch (k) + { + case JournalOpKind.mkdir: return "mkdir"; + case JournalOpKind.copyFile: return "copy"; + case JournalOpKind.claimPathEntry: return "claim.path_entry"; + case JournalOpKind.claimStartMenu: return "claim.start_menu"; + case JournalOpKind.claimFileAssoc: return "claim.file_assoc"; + case JournalOpKind.claimService: return "claim.service"; + case JournalOpKind.claimDriver: return "claim.driver"; + case JournalOpKind.claimEnv: return "claim.env"; + case JournalOpKind.removeFile: return "remove"; + } +} + +private import std.algorithm : startsWith; diff --git a/source/installcoordinator/uil/package.d b/source/installcoordinator/uil/package.d new file mode 100644 index 0000000..05e7d0b --- /dev/null +++ b/source/installcoordinator/uil/package.d @@ -0,0 +1,43 @@ +module installcoordinator.uil; + +public import installcoordinator.uil.types; +public import installcoordinator.uil.parse; +public import installcoordinator.uil.validate; +public import installcoordinator.uil.classic_paths; +public import installcoordinator.uil.journal; +public import installcoordinator.uil.plan; +public import installcoordinator.uil.coordinator_emit; + +unittest +{ + import std.path : buildPath; + immutable sample = `{ + "uilVersion": "1.0", + "package": { + "id": "dev-centr.demo", + "name": "Demo", + "version": "1.0.0" + }, + "layout": { + "adapter": "classic-paths", + "scope": "perUser" + }, + "payload": { + "entries": [ + { "source": "bin/demo", "role": "bin", "relativePath": "demo" } + ] + }, + "claims": [ + { + "type": "path_entry", + "directories": ["${role:bin}"] + } + ] +}`; + auto m = parseUilManifest(sample, buildPath("examples", "uil-classic-demo.uil.json")); + auto vr = validateUil(m); + assert(vr.ok); + auto pr = planUil(m); + assert(pr.ok); + assert(pr.classic.files.length == 1); +} diff --git a/source/installcoordinator/uil/parse.d b/source/installcoordinator/uil/parse.d new file mode 100644 index 0000000..4b9f494 --- /dev/null +++ b/source/installcoordinator/uil/parse.d @@ -0,0 +1,270 @@ +module installcoordinator.uil.parse; + +import installcoordinator.types : InstallScope, parseInstallScope; +import installcoordinator.uil.types; +import std.file : readText; +import std.json; + +UilManifest parseUilManifest(string text, string sourcePath = "") +{ + auto root = parseJSON(text); + UilManifest m; + m.sourcePath = sourcePath; + + if ("uilVersion" !in root) + throw new Exception("missing uilVersion"); + if (root["uilVersion"].str != "1.0") + throw new Exception("unsupported uilVersion: " ~ root["uilVersion"].str); + m.contract = UilVersion.v1_0; + + if ("package" !in root) + throw new Exception("missing package"); + parsePackage(root["package"], m.package_); + + if ("layout" !in root) + throw new Exception("missing layout"); + parseLayout(root["layout"], m.layout); + + if ("payload" !in root || "entries" !in root["payload"]) + throw new Exception("missing payload.entries"); + foreach (e; root["payload"]["entries"].array) + m.entries ~= parsePayloadEntry(e); + + if ("claims" in root) + foreach (c; root["claims"].array) + m.claims ~= parseClaim(c); + + if ("lifecycle" in root) + parseLifecycle(root["lifecycle"], m.lifecycle); + + if ("journal" in root) + parseJournal(root["journal"], m.journal); + + if ("coordinator" in root) + parseCoordinator(root["coordinator"], m.coordinator); + + return m; +} + +UilManifest loadUilFile(string path) +{ + return parseUilManifest(readText(path), path); +} + +private void parsePackage(JSONValue v, ref UilPackage p) +{ + if ("id" !in v) + throw new Exception("package.id required"); + p.id = v["id"].str; + if ("name" !in v) + throw new Exception("package.name required"); + p.name = v["name"].str; + if ("version" !in v) + throw new Exception("package.version required"); + p.version_ = v["version"].str; + if ("publisher" in v) + p.publisher = v["publisher"].str; + if ("edition" in v) + p.edition = v["edition"].str; +} + +private void parseLayout(JSONValue v, ref UilLayout l) +{ + if ("adapter" !in v) + throw new Exception("layout.adapter required"); + switch (v["adapter"].str) + { + case "classic-paths": + l.adapter = LayoutAdapter.classicPaths; + break; + case "connectome-fs": + l.adapter = LayoutAdapter.connectomeFs; + break; + default: + throw new Exception("unknown layout.adapter: " ~ v["adapter"].str); + } + if ("scope" in v) + l.installScope = parseInstallScope(v["scope"].str); + if ("platformFamily" in v) + l.platformFamily = parsePlatformFamily(v["platformFamily"].str); + if ("sideBySide" in v) + { + auto s = v["sideBySide"]; + if ("enabled" in s) + l.sideBySide.enabled = s["enabled"].type == JSONType.true_; + if ("slot" in s) + l.sideBySide.slot = s["slot"].str; + } + if ("installRoot" in v) + l.installRoot = v["installRoot"].str; +} + +private PlatformFamily parsePlatformFamily(string s) +{ + switch (s) + { + case "auto": return PlatformFamily.host; + case "windows": return PlatformFamily.windows; + case "macos": return PlatformFamily.macos; + case "linux": return PlatformFamily.linux; + case "bsd": return PlatformFamily.bsd; + default: throw new Exception("unknown platformFamily: " ~ s); + } +} + +private PayloadEntry parsePayloadEntry(JSONValue v) +{ + PayloadEntry e; + if ("source" !in v) + throw new Exception("payload entry missing source"); + if ("role" !in v) + throw new Exception("payload entry missing role"); + e.source = v["source"].str; + e.role = parsePayloadRole(v["role"].str); + if ("relativePath" in v) + e.relativePath = v["relativePath"].str; + return e; +} + +private UilClaim parseClaim(JSONValue v) +{ + if ("type" !in v) + throw new Exception("claim missing type"); + UilClaim c; + c.kind = parseClaimKind(v["type"].str); + if ("id" in v) + c.id = v["id"].str; + if ("description" in v) + c.description = v["description"].str; + + final switch (c.kind) + { + case ClaimKind.pathEntry: + if ("directories" !in v) + throw new Exception("path_entry claim requires directories"); + foreach (d; v["directories"].array) + c.pathEntryDirectories ~= d.str; + if ("prepend" in v) + c.pathEntryPrepend = v["prepend"].type == JSONType.true_; + break; + case ClaimKind.startMenu: + if ("shortcut" !in v) + throw new Exception("start_menu claim requires shortcut"); + parseShortcut(v["shortcut"], c.startMenu); + break; + case ClaimKind.fileAssoc: + if ("extension" !in v || "progid" !in v) + throw new Exception("file_assoc requires extension and progid"); + c.fileExtension = v["extension"].str; + c.progid = v["progid"].str; + if ("openCommandRole" in v) + c.openCommandRole = parsePayloadRole(v["openCommandRole"].str); + if ("openCommandRelative" in v) + c.openCommandRelative = v["openCommandRelative"].str; + break; + case ClaimKind.service: + if ("serviceName" !in v) + throw new Exception("service claim requires serviceName"); + c.serviceName = v["serviceName"].str; + if ("displayName" in v) + c.serviceDisplayName = v["displayName"].str; + if ("executableRole" in v) + c.serviceExecutableRole = parsePayloadRole(v["executableRole"].str); + if ("executableRelative" in v) + c.serviceExecutableRelative = v["executableRelative"].str; + break; + case ClaimKind.driver: + if ("infRole" !in v || "infRelative" !in v) + throw new Exception("driver claim requires infRole and infRelative"); + c.driverInfRole = parsePayloadRole(v["infRole"].str); + c.driverInfRelative = v["infRelative"].str; + break; + case ClaimKind.env: + if ("variables" !in v) + throw new Exception("env claim requires variables"); + if ("scope" in v) + c.envScope = v["scope"].str; + foreach (string k, ref val; v["variables"].object) + c.envVariables[k] = val.str; + break; + } + return c; +} + +private void parseShortcut(JSONValue v, ref StartMenuShortcut s) +{ + if ("name" !in v || "targetRole" !in v || "targetRelative" !in v) + throw new Exception("shortcut requires name, targetRole, targetRelative"); + s.name = v["name"].str; + s.targetRole = parsePayloadRole(v["targetRole"].str); + s.targetRelative = v["targetRelative"].str; + if ("arguments" in v) + s.arguments = v["arguments"].str; + if ("iconRole" in v) + s.iconRole = parsePayloadRole(v["iconRole"].str); + if ("iconRelative" in v) + s.iconRelative = v["iconRelative"].str; +} + +private void parseLifecycle(JSONValue v, ref UilLifecycle l) +{ + if ("repair" in v) + { + auto r = v["repair"]; + if ("strategy" in r) + l.repair.strategy = parseRepairStrategy(r["strategy"].str); + if ("notes" in r) + l.repair.notes = r["notes"].str; + } + if ("uninstall" in v) + { + auto u = v["uninstall"]; + if ("strategy" in u) + l.uninstall.strategy = parseUninstallStrategy(u["strategy"].str); + if ("removeState" in u) + l.uninstall.removeState = u["removeState"].type == JSONType.true_; + if ("removeCache" in u) + l.uninstall.removeCache = u["removeCache"].type == JSONType.true_; + } +} + +private RepairStrategy parseRepairStrategy(string s) +{ + switch (s) + { + case "reconcile-payload": return RepairStrategy.reconcilePayload; + case "msi-repair": return RepairStrategy.msiRepair; + case "custom": return RepairStrategy.custom; + default: throw new Exception("unknown repair strategy: " ~ s); + } +} + +private UninstallStrategy parseUninstallStrategy(string s) +{ + switch (s) + { + case "remove-payload-and-claims": return UninstallStrategy.removePayloadAndClaims; + case "msi-uninstall": return UninstallStrategy.msiUninstall; + case "custom": return UninstallStrategy.custom; + default: throw new Exception("unknown uninstall strategy: " ~ s); + } +} + +private void parseJournal(JSONValue v, ref JournalSpec j) +{ + if ("format" in v) + j.format = v["format"].str; + if ("persistPath" in v) + j.persistPath = v["persistPath"].str; +} + +private void parseCoordinator(JSONValue v, ref CoordinatorBridge c) +{ + if ("presentation" in v) + c.presentation = v["presentation"].str; + if ("termsAccepted" in v) + c.termsAccepted = v["termsAccepted"].type == JSONType.true_; + if ("options" in v) + foreach (string k, ref val; v["options"].object) + c.options[k] = val.str; +} diff --git a/source/installcoordinator/uil/plan.d b/source/installcoordinator/uil/plan.d new file mode 100644 index 0000000..5feb240 --- /dev/null +++ b/source/installcoordinator/uil/plan.d @@ -0,0 +1,73 @@ +module installcoordinator.uil.plan; + +import installcoordinator.uil.classic_paths; +import installcoordinator.uil.journal; +import installcoordinator.uil.types; +import installcoordinator.uil.validate; +import std.path : dirName; +import std.stdio : writeln; + +struct UilPlanResult +{ + ValidationResult validation; + ClassicInstallPlan classic; + InstallJournal journal; + bool ok; +} + +UilPlanResult planUil(const ref UilManifest m) +{ + UilPlanResult r; + r.validation = validateUil(m); + if (!r.validation.ok) + { + r.ok = false; + return r; + } + if (m.layout.adapter != LayoutAdapter.classicPaths) + { + r.validation.add("layout.adapter", "only classic-paths planning is implemented"); + r.ok = false; + return r; + } + auto manifestDir = m.sourcePath.length ? dirName(m.sourcePath) : ""; + r.classic = planClassicPaths(m, manifestDir); + r.journal = buildJournal(m, r.classic); + r.ok = true; + return r; +} + +void printClassicPlan(const ref ClassicInstallPlan plan) +{ + writeln("UIL classic-path plan"); + writeln(" platform: ", platformLabel(plan.platform)); + writeln(" scope: ", plan.installScope == InstallScope.perMachine ? "perMachine" : "perUser"); + writeln(" installPrefix: ", plan.installPrefix); + writeln(" role roots:"); + foreach (r; [PayloadRole.bin, PayloadRole.lib, PayloadRole.share, PayloadRole.state, + PayloadRole.cache, PayloadRole.config, PayloadRole.logs]) + writeln(" ", payloadRoleLabel(r), ": ", plan.roles.roots[r]); + writeln(" payload:"); + foreach (f; plan.files) + writeln(" ", payloadRoleLabel(f.role), ": ", f.source, " -> ", f.destination); + if (plan.claimNotes.length) + { + writeln(" claims (orientation / shell refresh):"); + foreach (n; plan.claimNotes) + writeln(" ", n); + } +} + +private string platformLabel(PlatformFamily pf) @safe +{ + final switch (pf) + { + case PlatformFamily.host: return "auto"; + case PlatformFamily.windows: return "windows"; + case PlatformFamily.macos: return "macos"; + case PlatformFamily.linux: return "linux"; + case PlatformFamily.bsd: return "bsd"; + } +} + +private import installcoordinator.types : InstallScope; diff --git a/source/installcoordinator/uil/types.d b/source/installcoordinator/uil/types.d new file mode 100644 index 0000000..f8deb90 --- /dev/null +++ b/source/installcoordinator/uil/types.d @@ -0,0 +1,210 @@ +module installcoordinator.uil.types; + +import installcoordinator.types : InstallScope; + +/// UIL contract revision supported by this library. +enum UilVersion +{ + v1_0, +} + +enum LayoutAdapter +{ + classicPaths, + connectomeFs, +} + +enum PlatformFamily +{ + host, + windows, + macos, + linux, + bsd, +} + +enum PayloadRole +{ + bin, + lib, + share, + state, + cache, + config, + logs, +} + +enum ClaimKind +{ + pathEntry, + startMenu, + fileAssoc, + service, + driver, + env, +} + +enum RepairStrategy +{ + reconcilePayload, + msiRepair, + custom, +} + +enum UninstallStrategy +{ + removePayloadAndClaims, + msiUninstall, + custom, +} + +struct UilPackage +{ + string id; + string name; + string publisher; + string version_; + string edition = "default"; +} + +struct SideBySideLayout +{ + bool enabled; + string slot; +} + +struct UilLayout +{ + LayoutAdapter adapter = LayoutAdapter.classicPaths; + InstallScope installScope = InstallScope.perUser; + PlatformFamily platformFamily = PlatformFamily.host; + SideBySideLayout sideBySide; + string installRoot; +} + +struct PayloadEntry +{ + string source; + PayloadRole role; + string relativePath; +} + +struct StartMenuShortcut +{ + string name; + PayloadRole targetRole; + string targetRelative; + string arguments; + PayloadRole iconRole; + string iconRelative; +} + +struct UilClaim +{ + ClaimKind kind; + string id; + string description; + string[] pathEntryDirectories; + bool pathEntryPrepend = true; + StartMenuShortcut startMenu; + string fileExtension; + string progid; + PayloadRole openCommandRole; + string openCommandRelative; + string serviceName; + string serviceDisplayName; + PayloadRole serviceExecutableRole; + string serviceExecutableRelative; + PayloadRole driverInfRole; + string driverInfRelative; + string envScope = "user"; + string[string] envVariables; +} + +struct LifecycleRepair +{ + RepairStrategy strategy = RepairStrategy.reconcilePayload; + string notes; +} + +struct LifecycleUninstall +{ + UninstallStrategy strategy = UninstallStrategy.removePayloadAndClaims; + bool removeState; + bool removeCache = true; +} + +struct UilLifecycle +{ + LifecycleRepair repair; + LifecycleUninstall uninstall; +} + +struct JournalSpec +{ + string format = "uil-journal-v1"; + string persistPath; +} + +struct CoordinatorBridge +{ + string presentation = "thinStub"; + bool termsAccepted; + string[string] options; +} + +struct UilManifest +{ + UilVersion contract = UilVersion.v1_0; + UilPackage package_; + UilLayout layout; + PayloadEntry[] entries; + UilClaim[] claims; + UilLifecycle lifecycle; + JournalSpec journal; + CoordinatorBridge coordinator; + string sourcePath; +} + +string payloadRoleLabel(PayloadRole r) @safe +{ + final switch (r) + { + case PayloadRole.bin: return "bin"; + case PayloadRole.lib: return "lib"; + case PayloadRole.share: return "share"; + case PayloadRole.state: return "state"; + case PayloadRole.cache: return "cache"; + case PayloadRole.config: return "config"; + case PayloadRole.logs: return "logs"; + } +} + +PayloadRole parsePayloadRole(string s) +{ + switch (s) + { + case "bin": return PayloadRole.bin; + case "lib": return PayloadRole.lib; + case "share": return PayloadRole.share; + case "state": return PayloadRole.state; + case "cache": return PayloadRole.cache; + case "config": return PayloadRole.config; + case "logs": return PayloadRole.logs; + default: throw new Exception("unknown payload role: " ~ s); + } +} + +ClaimKind parseClaimKind(string s) +{ + switch (s) + { + case "path_entry": return ClaimKind.pathEntry; + case "start_menu": return ClaimKind.startMenu; + case "file_assoc": return ClaimKind.fileAssoc; + case "service": return ClaimKind.service; + case "driver": return ClaimKind.driver; + case "env": return ClaimKind.env; + default: throw new Exception("unknown claim type: " ~ s); + } +} diff --git a/source/installcoordinator/uil/validate.d b/source/installcoordinator/uil/validate.d new file mode 100644 index 0000000..97e41f7 --- /dev/null +++ b/source/installcoordinator/uil/validate.d @@ -0,0 +1,107 @@ +module installcoordinator.uil.validate; + +import installcoordinator.uil.types; +import std.algorithm : canFind; +import std.conv : to; + +struct ValidationIssue +{ + string path; + string message; +} + +struct ValidationResult +{ + ValidationIssue[] issues; + + bool ok() const @safe + { + return issues.length == 0; + } + + void add(string path, string message) + { + ValidationIssue i; + i.path = path; + i.message = message; + issues ~= i; + } +} + +ValidationResult validateUil(const ref UilManifest m) +{ + ValidationResult r; + if (!m.package_.id.length) + r.add("package.id", "required"); + if (!m.package_.name.length) + r.add("package.name", "required"); + if (!m.package_.version_.length) + r.add("package.version", "required"); + + if (m.layout.adapter == LayoutAdapter.connectomeFs) + r.add("layout.adapter", "connectome-fs is documented but not yet implemented in this runtime; use classic-paths"); + + if (m.layout.sideBySide.enabled && !m.layout.sideBySide.slot.length) + r.add("layout.sideBySide.slot", "required when sideBySide.enabled is true"); + + if (!m.entries.length) + r.add("payload.entries", "at least one entry required"); + + foreach (i, e; m.entries) + { + auto prefix = "payload.entries[" ~ i.to!string ~ "]"; + if (!e.source.length) + r.add(prefix ~ ".source", "required"); + if (!e.relativePath.length && e.role != PayloadRole.bin) + r.add(prefix ~ ".relativePath", "recommended for non-bin roles"); + } + + foreach (i, c; m.claims) + { + auto prefix = "claims[" ~ i.to!string ~ "]"; + final switch (c.kind) + { + case ClaimKind.pathEntry: + if (!c.pathEntryDirectories.length) + r.add(prefix, "path_entry requires directories"); + break; + case ClaimKind.startMenu: + if (!c.startMenu.name.length || !c.startMenu.targetRelative.length) + r.add(prefix, "start_menu shortcut incomplete"); + break; + case ClaimKind.fileAssoc: + if (!c.fileExtension.length || !c.progid.length) + r.add(prefix, "file_assoc requires extension and progid"); + break; + case ClaimKind.service: + if (!c.serviceName.length) + r.add(prefix, "service requires serviceName"); + break; + case ClaimKind.driver: + if (!c.driverInfRelative.length) + r.add(prefix, "driver requires infRelative"); + break; + case ClaimKind.env: + if (!c.envVariables.length) + r.add(prefix, "env requires variables"); + break; + } + } + + if (m.journal.format.length && m.journal.format != "uil-journal-v1") + r.add("journal.format", "must be uil-journal-v1 when set"); + + // path_entry directories should reference role roots when using relative tokens + foreach (c; m.claims) + { + if (c.kind != ClaimKind.pathEntry) + continue; + foreach (d; c.pathEntryDirectories) + { + if (d.canFind("..")) + r.add("claims.path_entry", "directory paths must not contain .."); + } + } + + return r; +} diff --git a/source/installcoordinator/uil_cli.d b/source/installcoordinator/uil_cli.d new file mode 100644 index 0000000..d5e02b8 --- /dev/null +++ b/source/installcoordinator/uil_cli.d @@ -0,0 +1,120 @@ +module installcoordinator.uil_cli; + +import installcoordinator.uil.coordinator_emit; +import installcoordinator.uil.journal; +import installcoordinator.uil.parse; +import installcoordinator.uil.plan; +import installcoordinator.uil.validate; +import std.file : write; +import std.path : absolutePath, dirName; +import std.stdio : writeln, stderr; +import std.string : toLower; + +int cmdUil(string[] args) +{ + if (!args.length) + return uilUsage(); + auto sub = args[0].toLower; + auto rest = args[1 .. $]; + switch (sub) + { + case "validate": + return uilValidate(rest); + case "plan": + return uilPlan(rest); + case "emit-coordinator": + return uilEmitCoordinator(rest); + case "help": + return uilUsage(); + default: + stderr.writeln("Unknown uil subcommand: ", args[0]); + return uilUsage(); + } +} + +int uilUsage() +{ + writeln(`UIL (Unity Install Layout) commands: + uil validate + uil plan [--dry-run] [--json-journal] + uil emit-coordinator [out.job.json] +`); + return 0; +} + +int uilValidate(string[] args) +{ + if (!args.length) + { + stderr.writeln("manifest path required"); + return 1; + } + auto m = loadUilFile(absolutePath(args[0])); + auto vr = validateUil(m); + if (!vr.ok) + { + foreach (i; vr.issues) + stderr.writeln(i.path, ": ", i.message); + return 1; + } + writeln("OK ", m.package_.id, " ", m.package_.version_, " (", m.entries.length, " payload entries, ", + m.claims.length, " claims)"); + return 0; +} + +int uilPlan(string[] args) +{ + if (!args.length) + { + stderr.writeln("manifest path required"); + return 1; + } + bool dryRun; + bool jsonJournal; + string path = args[0]; + foreach (a; args[1 .. $]) + { + if (a == "--dry-run") + dryRun = true; + else if (a == "--json-journal") + jsonJournal = true; + } + auto m = loadUilFile(absolutePath(path)); + auto pr = planUil(m); + if (!pr.ok) + { + foreach (i; pr.validation.issues) + stderr.writeln(i.path, ": ", i.message); + return 1; + } + printClassicPlan(pr.classic); + if (jsonJournal) + writeln(journalToJson(pr.journal).toPrettyString()); + else if (dryRun) + applyJournalDryRun(pr.journal); + else + applyJournalDryRun(pr.journal); // MVP: apply engine not wired; journal preview only + return 0; +} + +int uilEmitCoordinator(string[] args) +{ + if (!args.length) + { + stderr.writeln("manifest path required"); + return 1; + } + auto abs = absolutePath(args[0]); + auto m = loadUilFile(abs); + auto vr = validateUil(m); + if (!vr.ok) + { + foreach (i; vr.issues) + stderr.writeln(i.path, ": ", i.message); + return 1; + } + auto jobPath = args.length >= 2 ? args[1] : dirName(abs) ~ "/coordinator.job.json"; + write(jobPath, coordinatorJobJson(m, abs)); + writeln("Wrote ", jobPath); + return 0; +}