hostctl 0.1.42 → 0.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,11 +3,13 @@
3
3
  `hostctl` is a modern task runner for managing fleets of hosts. It executes TypeScript or JavaScript automations locally or over SSH while keeping inventories, tags, and secrets in one place.
4
4
 
5
5
  ## Why hostctl
6
+
6
7
  - Treat remote automation like regular code: tasks are modules with strong typing and structured logging.
7
8
  - First-class inventory and secrets management built around [AGE](https://age-encryption.org/).
8
9
  - Layered runtime cleanly separates CLI parsing, orchestration, and execution for easy extension.
9
10
 
10
11
  ## System Requirements
12
+
11
13
  - Node.js **24+** (CLI runs through `tsx`).
12
14
  - [`age`](https://age-encryption.org) for encrypting secrets.
13
15
  - Git (recommended) for cloning packages and publishing tasks.
@@ -23,26 +25,32 @@ age --version
23
25
  ## Install hostctl
24
26
 
25
27
  ### Clone & Develop
28
+
26
29
  ```bash
27
30
  git clone https://github.com/monopod/hostctl.git
28
31
  cd hostctl
29
32
  npm install
30
33
  ```
34
+
31
35
  Use `./hostctl` during development or `npm run build && ./dist/bin/hostctl.js ...` to test the bundled CLI.
32
36
 
33
37
  ### Global CLI
38
+
34
39
  ```bash
35
40
  npm install -g hostctl
36
41
  hostctl --help
37
42
  ```
38
43
 
39
44
  ### One-off Execution
45
+
40
46
  Run straight from npm without installing globally:
47
+
41
48
  ```bash
42
49
  npx hostctl run core.echo message:hello
43
50
  ```
44
51
 
45
52
  ## Bootstrap identities, inventory, and secrets
53
+
46
54
  1. **Generate AGE identities**
47
55
  ```bash
48
56
  mkdir -p ~/.hostctl/age
@@ -73,6 +81,7 @@ npx hostctl run core.echo message:hello
73
81
  Set `AGE_IDS="~/.hostctl/age/*.priv"` before running commands if the file is encrypted.
74
82
 
75
83
  ## Running tasks
84
+
76
85
  - **Local script**
77
86
  ```bash
78
87
  npm run build
@@ -82,10 +91,12 @@ npx hostctl run core.echo message:hello
82
91
  ```bash
83
92
  hostctl run ./my-package hello name:Sam
84
93
  ```
94
+ Local directories are executed directly and are not installable via `hostctl pkg install`.
85
95
  - **Remote orchestration**
86
96
  ```bash
87
97
  hostctl run -r -t ubuntu core.net.interfaces --json
88
98
  ```
99
+
89
100
  - `-r/--remote` targets hosts selected by tags via SSH.
90
101
  - `-t/--tag` is greedy; use `--` before positional args when needed.
91
102
  - **From npm or git**
@@ -106,28 +117,38 @@ npx hostctl run core.echo message:hello
106
117
  The first task streams container output back to the CLI; the detached variant returns the created container ID/name so you can manage it later.
107
118
 
108
119
  **Passing parameters**
120
+
109
121
  - `key:value` pairs after the task name.
110
122
  - `--params '{"key":"value"}'` for JSON blobs.
111
123
  - `--file params.json` to load structured arguments.
112
124
 
113
125
  ## Managing task packages
126
+
114
127
  `hostctl pkg` commands wrap the npm-only package manager:
128
+
115
129
  ```bash
116
130
  hostctl pkg create my-task --lang typescript
117
131
  hostctl pkg install hostctl-hello
118
132
  hostctl pkg list
119
133
  hostctl pkg remove hostctl-hello
120
134
  ```
135
+
121
136
  Installed packages live under `~/.hostctl/packages` and can be run offline once cached.
137
+ Use `pkg install` for npm registry names (scoped + versioned) or git URLs. Local directories should be run directly without installing (`hostctl run ./path/to/pkg task args`); this avoids polluting the manifest with workstation paths and keeps the install story aligned with reproducible npm/git sources.
122
138
 
123
139
  ## Designing tasks
140
+
124
141
  Define tasks with the `task` helper and a typed `TaskContext`:
125
142
 
126
143
  ```ts
127
144
  import { task, type TaskContext } from 'hostctl';
128
145
 
129
- interface EchoParams { message: string }
130
- interface EchoResult { repeated: string }
146
+ interface EchoParams {
147
+ message: string;
148
+ }
149
+ interface EchoResult {
150
+ repeated: string;
151
+ }
131
152
 
132
153
  async function run(context: TaskContext<EchoParams>): Promise<EchoResult> {
133
154
  const { params, info } = context;
@@ -135,10 +156,13 @@ async function run(context: TaskContext<EchoParams>): Promise<EchoResult> {
135
156
  return { repeated: params.message };
136
157
  }
137
158
 
138
- export default task(run, { name: 'example.echo', description: 'Prints a message' });
159
+ export default task(run, { name: 'echo', description: 'Prints a message' });
139
160
  ```
140
161
 
162
+ Export one default task per file. Qualified task names come from a registry when present; otherwise they are derived from the task file path relative to the package root.
163
+
141
164
  Key `TaskContext` capabilities (see [`docs/task-api.md`](docs/task-api.md) for details):
165
+
142
166
  - Structured logging via `info`, `warn`, `error`, `debug`, or `log(level, ...)`.
143
167
  - Command execution with `exec(command, { sudo, env, cwd, stdin, pty })`.
144
168
  - Remote fan-out using `ssh(tags, remoteFn)`.
@@ -148,6 +172,7 @@ Key `TaskContext` capabilities (see [`docs/task-api.md`](docs/task-api.md) for d
148
172
  - File helpers: `file.read`, `file.write`, `file.exists`, `file.mkdir`, `file.rm` that respect local vs. remote runtime.
149
173
 
150
174
  ## Building & testing task packages
175
+
151
176
  1. Scaffold: `hostctl pkg create awesome-firewall --lang typescript`.
152
177
  2. Install deps: `cd awesome-firewall && npm install`.
153
178
  3. Build: `npm run build` (defaults to `tsc`).
@@ -155,6 +180,7 @@ Key `TaskContext` capabilities (see [`docs/task-api.md`](docs/task-api.md) for d
155
180
  5. Add unit tests with Vitest if needed, or invoke tasks directly in scripts.
156
181
 
157
182
  ## Publishing task packages
183
+
158
184
  1. Update `package.json` metadata (`name`, `version`, `description`, `files`).
159
185
  2. Build artifacts (`npm run build` or rely on `prepublishOnly`).
160
186
  3. Authenticate with npm (`npm login` or `NPM_TOKEN`).
@@ -167,11 +193,13 @@ Key `TaskContext` capabilities (see [`docs/task-api.md`](docs/task-api.md) for d
167
193
  6. Verify: `npm info your-package version`.
168
194
 
169
195
  ## Consuming published packages
196
+
170
197
  - One-off: `npx hostctl run your-package taskName param:value`.
171
198
  - Cache locally: `hostctl pkg install your-package@1.2.3` then run offline.
172
199
  - Compose in other codebases by adding the package to `dependencies` and importing its exported tasks.
173
200
 
174
201
  ## Troubleshooting
202
+
175
203
  - **Task not found**: confirm the package exports the task name and that `exports` exposes it.
176
204
  - **Version mismatch**: keep `package.json`, `src/version.ts`, and `jsr.json` in sync before releasing.
177
205
  - **SSH failures**: verify inventory entries (hostname, user, auth) and only pass `-r` when you intend remote execution.
@@ -179,6 +207,7 @@ Key `TaskContext` capabilities (see [`docs/task-api.md`](docs/task-api.md) for d
179
207
  - **Environment drift**: run `hostctl runtime` to inspect prerequisites or `hostctl runtime install` to bootstrap them.
180
208
 
181
209
  ## Developer workflow
210
+
182
211
  - Format & typing: `npm run format` (Prettier) and `npm run lint` (`tsc --noEmit`).
183
212
  - Build artifacts: `npm run build` (tsup) produces `dist/` bundles for the CLI and published package.
184
213
  - Tests:
@@ -188,7 +217,9 @@ Key `TaskContext` capabilities (see [`docs/task-api.md`](docs/task-api.md) for d
188
217
  - Releases rely on `npm run release` + `release-it`; see `NPM_MIGRATION_PLAN.md` for npm-only context.
189
218
 
190
219
  ## Documentation map
220
+
191
221
  - **Task API reference**: [`docs/task-api.md`](docs/task-api.md).
222
+ - **Task package authoring**: [`docs/task-package-authoring.md`](docs/task-package-authoring.md).
192
223
  - **Operational guides**: `docs/*.md` (process, package, system management, etc.).
193
224
  - **Architecture & design**: [`ARCHITECTURE.md`](ARCHITECTURE.md) and supporting design docs.
194
225
  - **Contributor guide**: [`CONTRIBUTING.md`](CONTRIBUTING.md) and [`AGENTS.md`](AGENTS.md).