Build the Apple Container extension

Turns the empty scaffold into a working Nova extension for Apple Container
and container-compose, in the shape of the Docker Suite extension.

Sidebar (Scripts/Sidebar):
- System, Containers, Images, Volumes and Networks sections
- Containers grouped into compose projects via the com.docker.compose.project
  label container-compose stamps; project rows drive compose up/down/build
  against the matching workspace file
- Lifecycle, shell, logs, inspect, browse and copy commands per resource
- Apple Container publishes no event stream, so the sidebar polls while
  visible and only reloads a section when a fingerprint of its data changes,
  which keeps selection and expansion intact

Hostnames (Scripts/Hostnames.js):
- A container's hostname is <name>.<domain> and the domain lives in Apple
  Container's config.toml, which has no CLI setter, so the Hostname Domain
  preference reads and writes that file directly
- Changing it offers to register the domain with macOS and restart the
  services; the write preserves the file's other tables and its mode

Language support:
- Dockerfile and Compose syntaxes backed by tree-sitter grammars built by
  Tools/build-syntaxes.sh, pinned to revisions that generate ABI 14
- The Compose syntax is named dockercompose because that is the languageId
  docker-language-server recognises compose files by
- docker-language-server is downloaded on first use rather than bundled, at
  roughly 40 MB

Icons are generated by Tools/make-icons.py so they can be regenerated rather
than hand-maintained.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UnSBcR5Lywz5Fbj5FmVbfc
This commit is contained in:
2026-08-18 22:45:14 -03:00
co-authored by Claude Opus 5
parent 0879e5a163
commit 0506f44db3
80 changed files with 5201 additions and 3 deletions
+137
View File
@@ -0,0 +1,137 @@
//
// Wrapper around `container-compose`.
//
// container-compose has no `ls`, so projects are discovered from the
// com.docker.compose.project labels it stamps on containers, and compose files
// are discovered from the workspace.
//
const { exec } = require("../Utilities/Process");
const SEARCH_PATHS = [
"/opt/homebrew/bin/container-compose",
"/usr/local/bin/container-compose"
];
const FILE_NAMES = [
"compose.yaml",
"compose.yml",
"docker-compose.yaml",
"docker-compose.yml",
"container-compose.yaml",
"container-compose.yml"
];
class ComposeCLI {
static resolve() {
let configured = nova.config.get("apple_container.cli.compose", "string");
if (configured && configured.trim().length > 0) {
return [configured.trim(), []];
}
for (let path of SEARCH_PATHS) {
if (nova.fs.access(path, nova.fs.X_OK)) {
return [path, []];
}
}
return ["/usr/bin/env", ["container-compose"]];
}
static path() {
let [path, leading] = this.resolve();
return leading.length > 0 ? "container-compose" : path;
}
// Compose files in the workspace root, in the order compose itself would
// prefer them.
static workspaceFiles() {
if (!nova.workspace.path) {
return [];
}
let found = [];
for (let name of FILE_NAMES) {
let path = nova.path.join(nova.workspace.path, name);
if (nova.fs.access(path, nova.fs.R_OK)) {
found.push(path);
}
}
return found;
}
// The compose file commands act on: the workspace setting when present,
// otherwise the first file found in the workspace.
static defaultFile() {
let configured = nova.workspace.config.get("apple_container.compose.file", "string");
if (configured && configured.trim().length > 0) {
return configured.trim();
}
return this.workspaceFiles()[0] || null;
}
// Mirrors container-compose: the compose file's `name:` when set, otherwise
// the containing directory with dots replaced, since dots are not valid in
// container names.
static projectName(file) {
if (!file) {
return null;
}
try {
let contents = nova.fs.open(file, "r").read();
let match = contents.match(/^name:\s*["']?([^"'\s#]+)["']?\s*$/m);
if (match) {
return match[1];
}
} catch (error) {
// Fall through to the directory name.
}
return nova.path.basename(nova.path.dirname(file)).replace(/\./g, "_");
}
static profiles() {
let configured = nova.workspace.config.get("apple_container.compose.profiles", "string");
if (!configured) {
return [];
}
return configured
.split(/\s+/)
.filter((profile) => profile.length > 0)
.reduce((args, profile) => args.concat(["--profile", profile]), []);
}
static upArgs(file, services = []) {
let args = ["up", "--file", file];
if (nova.config.get("apple_container.compose.detach", "boolean") !== false) {
args.push("--detach");
}
return args.concat(this.profiles(), services);
}
static downArgs(file, services = []) {
return ["down", "--file", file].concat(this.profiles(), services);
}
static buildArgs(file, services = []) {
return ["build", "--file", file].concat(this.profiles(), services);
}
static run(args, options = {}) {
let [path, leading] = this.resolve();
return exec(path, leading.concat(args), options);
}
}
module.exports = { ComposeCLI };
+251
View File
@@ -0,0 +1,251 @@
//
// Wrapper around the `container` command line tool.
//
// Every list command is asked for JSON; Apple Container's JSON is a single
// document rather than the line delimited JSON Docker emits, so output is
// buffered and parsed once the process exits.
//
const { exec, execJSON } = require("../Utilities/Process");
const SEARCH_PATHS = [
"/usr/local/bin/container",
"/opt/homebrew/bin/container",
"/usr/bin/container"
];
class ContainerCLI {
// Resolves the tool as a [path, leadingArgs] pair. Nova does not inherit a
// login shell's PATH reliably, so a configured or well known absolute path
// is preferred and `/usr/bin/env` is only the last resort.
static resolve() {
let configured = nova.config.get("apple_container.cli.container", "string");
if (configured && configured.trim().length > 0) {
return [configured.trim(), []];
}
for (let path of SEARCH_PATHS) {
if (nova.fs.access(path, nova.fs.X_OK)) {
return [path, []];
}
}
return ["/usr/bin/env", ["container"]];
}
// Absolute path to the tool, or null when it could not be found. Used to
// build shell commands for the terminal.
static path() {
let [path, leading] = this.resolve();
return leading.length > 0 ? "container" : path;
}
static run(args, options = {}) {
let [path, leading] = this.resolve();
return exec(path, leading.concat(args), options);
}
static runJSON(args, options = {}) {
let [path, leading] = this.resolve();
return execJSON(path, leading.concat(args), options);
}
// System ---------------------------------------------------------------
// Resolves to a status object even when the services are down, so the
// sidebar can render the stopped state rather than an empty section.
static async systemStatus() {
try {
let status = await this.runJSON(["system", "status", "--format", "json"]);
return status && typeof status === "object" ? status : { status: "unknown" };
} catch (error) {
return { status: "stopped", error: error.message };
}
}
static systemStart() {
return this.run(["system", "start"]);
}
static systemStop() {
return this.run(["system", "stop"]);
}
static async systemDiskUsage() {
try {
return await this.runJSON(["system", "df", "--format", "json"]);
} catch (error) {
return null;
}
}
static async dnsDomains() {
try {
let result = await this.run(["system", "dns", "ls"]);
return result.stdout
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0)
.slice(1);
} catch (error) {
return [];
}
}
static version() {
return this.run(["--version"]);
}
// Builder --------------------------------------------------------------
// `container builder status` reports through its message rather than a
// machine readable field, so the text is matched.
static async builderRunning() {
try {
let result = await this.run(["builder", "status"], { ignoreStatus: true });
let output = `${result.stdout} ${result.stderr}`.toLowerCase();
if (output.includes("not running") || output.includes("does not exist")) {
return false;
}
return result.status === 0;
} catch (error) {
return false;
}
}
static builderStart() {
return this.run(["builder", "start"]);
}
static builderStop() {
return this.run(["builder", "stop"]);
}
static builderDelete() {
return this.run(["builder", "delete"]);
}
// Containers -----------------------------------------------------------
static listContainers() {
return this.runJSON(["list", "--all", "--format", "json"]);
}
static startContainers(ids) {
// `container start` takes a single container, so fan out.
return Promise.all(ids.map((id) => this.run(["start", id])));
}
static stopContainers(ids) {
return this.run(["stop"].concat(ids));
}
static killContainers(ids) {
return this.run(["kill"].concat(ids));
}
static async restartContainers(ids) {
await this.stopContainers(ids);
return this.startContainers(ids);
}
static deleteContainers(ids, force = false) {
let args = force ? ["delete", "--force"] : ["delete"];
return this.run(args.concat(ids));
}
static pruneContainers() {
return this.run(["prune"]);
}
static async inspectContainer(id) {
let result = await this.run(["inspect", id]);
return result.stdout;
}
// Images ---------------------------------------------------------------
static listImages() {
return this.runJSON(["image", "list", "--format", "json"]);
}
static pullImage(reference) {
return this.run(["image", "pull", reference]);
}
static pushImage(reference) {
return this.run(["image", "push", reference]);
}
static tagImage(reference, target) {
return this.run(["image", "tag", reference, target]);
}
static deleteImages(references) {
return this.run(["image", "delete"].concat(references));
}
static pruneImages() {
return this.run(["image", "prune"]);
}
static async inspectImage(reference) {
let result = await this.run(["image", "inspect", reference]);
return result.stdout;
}
// Volumes --------------------------------------------------------------
static listVolumes() {
return this.runJSON(["volume", "list", "--format", "json"]);
}
static createVolume(nameOrArgs) {
let args = Array.isArray(nameOrArgs) ? nameOrArgs : [nameOrArgs];
return this.run(["volume", "create"].concat(args));
}
static deleteVolumes(names) {
return this.run(["volume", "delete"].concat(names));
}
static pruneVolumes() {
return this.run(["volume", "prune"]);
}
static async inspectVolume(name) {
let result = await this.run(["volume", "inspect", name]);
return result.stdout;
}
// Networks -------------------------------------------------------------
static listNetworks() {
return this.runJSON(["network", "list", "--format", "json"]);
}
// Accepts a bare name or a full argument list such as
// ["backend", "--subnet", "192.168.70.0/24"].
static createNetwork(nameOrArgs) {
let args = Array.isArray(nameOrArgs) ? nameOrArgs : [nameOrArgs];
return this.run(["network", "create"].concat(args));
}
static deleteNetworks(names) {
return this.run(["network", "delete"].concat(names));
}
static pruneNetworks() {
return this.run(["network", "prune"]);
}
static async inspectNetwork(name) {
let result = await this.run(["network", "inspect", name]);
return result.stdout;
}
}
module.exports = { ContainerCLI };
+61
View File
@@ -0,0 +1,61 @@
//
// Runs commands in the user's terminal application.
//
// Nova has no terminal of its own, so anything interactive or long running --
// shells, followed logs, compose output -- is handed to Terminal or iTerm2
// through AppleScript.
//
const { exec } = require("../Utilities/Process");
class Terminal {
// Quotes a single argument for /bin/sh.
static quote(argument) {
return `'${String(argument).replace(/'/g, `'\\''`)}'`;
}
// Joins an argument vector into a shell command.
static command(parts) {
return parts.map((part) => this.quote(part)).join(" ");
}
static escapeAppleScript(text) {
return text.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
}
// Opens a new terminal window running the given shell command.
static async run(command, cwd) {
let full = cwd ? `cd ${this.quote(cwd)} && ${command}` : command;
let script =
nova.config.get("apple_container.cli.terminal", "string") === "iTerm2"
? this.iTermScript(full)
: this.terminalScript(full);
return exec("/usr/bin/osascript", ["-e", script]);
}
static terminalScript(command) {
let escaped = this.escapeAppleScript(command);
return [
'tell application "Terminal"',
` do script "${escaped}"`,
" activate",
"end tell"
].join("\n");
}
static iTermScript(command) {
let escaped = this.escapeAppleScript(command);
return [
'tell application "iTerm"',
" activate",
" set newWindow to (create window with default profile)",
" tell current session of newWindow",
` write text "${escaped}"`,
" end tell",
"end tell"
].join("\n");
}
}
module.exports = { Terminal };