@rcpooley/concord 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +318 -0
- package/bin/concord.service +69 -0
- package/dist/age.d.ts +20 -0
- package/dist/age.d.ts.map +1 -0
- package/dist/age.js +58 -0
- package/dist/age.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +301 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/daemon.d.ts +4 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +394 -0
- package/dist/daemon.js.map +1 -0
- package/dist/eval-config.d.ts +2 -0
- package/dist/eval-config.d.ts.map +1 -0
- package/dist/eval-config.js +45 -0
- package/dist/eval-config.js.map +1 -0
- package/dist/exec.d.ts +168 -0
- package/dist/exec.d.ts.map +1 -0
- package/dist/exec.js +313 -0
- package/dist/exec.js.map +1 -0
- package/dist/git.d.ts +59 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +265 -0
- package/dist/git.js.map +1 -0
- package/dist/hook.d.ts +37 -0
- package/dist/hook.d.ts.map +1 -0
- package/dist/hook.js +89 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +76 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +236 -0
- package/dist/init.js.map +1 -0
- package/dist/loader.d.ts +35 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +230 -0
- package/dist/loader.js.map +1 -0
- package/dist/module.d.ts +116 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +100 -0
- package/dist/module.js.map +1 -0
- package/dist/modules/apt/index.d.ts +45 -0
- package/dist/modules/apt/index.d.ts.map +1 -0
- package/dist/modules/apt/index.js +249 -0
- package/dist/modules/apt/index.js.map +1 -0
- package/dist/modules/apt/schema.d.ts +63 -0
- package/dist/modules/apt/schema.d.ts.map +1 -0
- package/dist/modules/apt/schema.js +75 -0
- package/dist/modules/apt/schema.js.map +1 -0
- package/dist/modules/checkout/index.d.ts +88 -0
- package/dist/modules/checkout/index.d.ts.map +1 -0
- package/dist/modules/checkout/index.js +382 -0
- package/dist/modules/checkout/index.js.map +1 -0
- package/dist/modules/checkout/schema.d.ts +52 -0
- package/dist/modules/checkout/schema.d.ts.map +1 -0
- package/dist/modules/checkout/schema.js +132 -0
- package/dist/modules/checkout/schema.js.map +1 -0
- package/dist/modules/cloudflare/api.d.ts +64 -0
- package/dist/modules/cloudflare/api.d.ts.map +1 -0
- package/dist/modules/cloudflare/api.js +98 -0
- package/dist/modules/cloudflare/api.js.map +1 -0
- package/dist/modules/cloudflare/index.d.ts +74 -0
- package/dist/modules/cloudflare/index.d.ts.map +1 -0
- package/dist/modules/cloudflare/index.js +374 -0
- package/dist/modules/cloudflare/index.js.map +1 -0
- package/dist/modules/cloudflare/schema.d.ts +62 -0
- package/dist/modules/cloudflare/schema.d.ts.map +1 -0
- package/dist/modules/cloudflare/schema.js +85 -0
- package/dist/modules/cloudflare/schema.js.map +1 -0
- package/dist/modules/docker/index.d.ts +83 -0
- package/dist/modules/docker/index.d.ts.map +1 -0
- package/dist/modules/docker/index.js +470 -0
- package/dist/modules/docker/index.js.map +1 -0
- package/dist/modules/docker/registry.d.ts +35 -0
- package/dist/modules/docker/registry.d.ts.map +1 -0
- package/dist/modules/docker/registry.js +95 -0
- package/dist/modules/docker/registry.js.map +1 -0
- package/dist/modules/docker/render.d.ts +45 -0
- package/dist/modules/docker/render.d.ts.map +1 -0
- package/dist/modules/docker/render.js +162 -0
- package/dist/modules/docker/render.js.map +1 -0
- package/dist/modules/docker/schema.d.ts +231 -0
- package/dist/modules/docker/schema.d.ts.map +1 -0
- package/dist/modules/docker/schema.js +335 -0
- package/dist/modules/docker/schema.js.map +1 -0
- package/dist/modules/docker/sweeper.d.ts +64 -0
- package/dist/modules/docker/sweeper.d.ts.map +1 -0
- package/dist/modules/docker/sweeper.js +94 -0
- package/dist/modules/docker/sweeper.js.map +1 -0
- package/dist/modules/file/index.d.ts +79 -0
- package/dist/modules/file/index.d.ts.map +1 -0
- package/dist/modules/file/index.js +305 -0
- package/dist/modules/file/index.js.map +1 -0
- package/dist/modules/file/schema.d.ts +45 -0
- package/dist/modules/file/schema.d.ts.map +1 -0
- package/dist/modules/file/schema.js +114 -0
- package/dist/modules/file/schema.js.map +1 -0
- package/dist/modules/index.d.ts +20 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +11 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/porkbun/api.d.ts +36 -0
- package/dist/modules/porkbun/api.d.ts.map +1 -0
- package/dist/modules/porkbun/api.js +62 -0
- package/dist/modules/porkbun/api.js.map +1 -0
- package/dist/modules/porkbun/index.d.ts +50 -0
- package/dist/modules/porkbun/index.d.ts.map +1 -0
- package/dist/modules/porkbun/index.js +236 -0
- package/dist/modules/porkbun/index.js.map +1 -0
- package/dist/modules/porkbun/schema.d.ts +38 -0
- package/dist/modules/porkbun/schema.d.ts.map +1 -0
- package/dist/modules/porkbun/schema.js +39 -0
- package/dist/modules/porkbun/schema.js.map +1 -0
- package/dist/modules/script/index.d.ts +43 -0
- package/dist/modules/script/index.d.ts.map +1 -0
- package/dist/modules/script/index.js +116 -0
- package/dist/modules/script/index.js.map +1 -0
- package/dist/modules/script/schema.d.ts +25 -0
- package/dist/modules/script/schema.d.ts.map +1 -0
- package/dist/modules/script/schema.js +63 -0
- package/dist/modules/script/schema.js.map +1 -0
- package/dist/modules/systemd/index.d.ts +93 -0
- package/dist/modules/systemd/index.d.ts.map +1 -0
- package/dist/modules/systemd/index.js +394 -0
- package/dist/modules/systemd/index.js.map +1 -0
- package/dist/modules/systemd/render.d.ts +41 -0
- package/dist/modules/systemd/render.d.ts.map +1 -0
- package/dist/modules/systemd/render.js +252 -0
- package/dist/modules/systemd/render.js.map +1 -0
- package/dist/modules/systemd/schema.d.ts +293 -0
- package/dist/modules/systemd/schema.d.ts.map +1 -0
- package/dist/modules/systemd/schema.js +302 -0
- package/dist/modules/systemd/schema.js.map +1 -0
- package/dist/modules/systemd/sweeper.d.ts +31 -0
- package/dist/modules/systemd/sweeper.d.ts.map +1 -0
- package/dist/modules/systemd/sweeper.js +77 -0
- package/dist/modules/systemd/sweeper.js.map +1 -0
- package/dist/plans.d.ts +132 -0
- package/dist/plans.d.ts.map +1 -0
- package/dist/plans.js +315 -0
- package/dist/plans.js.map +1 -0
- package/dist/records.d.ts +37 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +100 -0
- package/dist/records.js.map +1 -0
- package/dist/registry.d.ts +38 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +31 -0
- package/dist/registry.js.map +1 -0
- package/dist/runner.d.ts +48 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +150 -0
- package/dist/runner.js.map +1 -0
- package/dist/scheduler.d.ts +36 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +77 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/schema.d.ts +762 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +185 -0
- package/dist/schema.js.map +1 -0
- package/dist/secret.d.ts +24 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +3 -0
- package/dist/secret.js.map +1 -0
- package/dist/ui.d.ts +62 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +288 -0
- package/dist/ui.js.map +1 -0
- package/package.json +57 -0
package/dist/plans.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { appendCapped, newRecordId, RecordStore } from './records.js';
|
|
7
|
+
export function summarize(p) {
|
|
8
|
+
const { log: _log, result, ...rest } = p;
|
|
9
|
+
return result ? { ...rest, totalOps: result.totalOps } : rest;
|
|
10
|
+
}
|
|
11
|
+
export class PlanError extends Error {
|
|
12
|
+
status;
|
|
13
|
+
constructor(message, status) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const execFileAsync = promisify(execFile);
|
|
19
|
+
/**
|
|
20
|
+
* Whether `name` is acceptable as a branch to plan.
|
|
21
|
+
*
|
|
22
|
+
* The name reaches git as an argument, never through a shell, so this is not
|
|
23
|
+
* the injection barrier — it is the barrier against option injection (a
|
|
24
|
+
* leading `-`) and against names git would reject anyway, with a message a
|
|
25
|
+
* caller can act on.
|
|
26
|
+
*/
|
|
27
|
+
export function validBranch(name) {
|
|
28
|
+
if (typeof name !== 'string')
|
|
29
|
+
return false;
|
|
30
|
+
if (name.length === 0 || name.length > 200)
|
|
31
|
+
return false;
|
|
32
|
+
if (!/^[A-Za-z0-9._/-]+$/.test(name))
|
|
33
|
+
return false;
|
|
34
|
+
if (name.startsWith('-') || name.startsWith('/') || name.endsWith('/'))
|
|
35
|
+
return false;
|
|
36
|
+
if (name.endsWith('.lock') || name.endsWith('.') || name.includes('..') || name.includes('//'))
|
|
37
|
+
return false;
|
|
38
|
+
if (name.split('/').some((part) => part.startsWith('.')))
|
|
39
|
+
return false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
export function validSha(sha) {
|
|
43
|
+
return typeof sha === 'string' && /^[0-9a-f]{7,40}$/.test(sha);
|
|
44
|
+
}
|
|
45
|
+
export class PlanService {
|
|
46
|
+
#opts;
|
|
47
|
+
#store;
|
|
48
|
+
#events = new EventEmitter();
|
|
49
|
+
/** Plans not yet finished, by id. Live copies — the store lags them. */
|
|
50
|
+
#live = new Map();
|
|
51
|
+
#queue = [];
|
|
52
|
+
#working = false;
|
|
53
|
+
constructor(opts) {
|
|
54
|
+
this.#opts = {
|
|
55
|
+
mainBranch: 'main',
|
|
56
|
+
maxQueued: 10,
|
|
57
|
+
timeoutMs: 20 * 60_000,
|
|
58
|
+
keep: 100,
|
|
59
|
+
...opts,
|
|
60
|
+
};
|
|
61
|
+
this.#events.setMaxListeners(0);
|
|
62
|
+
this.#store = new RecordStore(join(opts.root, 'records'), this.#opts.keep);
|
|
63
|
+
this.#recoverInterrupted();
|
|
64
|
+
}
|
|
65
|
+
get #checkout() {
|
|
66
|
+
return join(this.#opts.root, 'config');
|
|
67
|
+
}
|
|
68
|
+
get #home() {
|
|
69
|
+
return join(this.#opts.root, 'home');
|
|
70
|
+
}
|
|
71
|
+
/** Queue a plan. Throws PlanError for a request that can never succeed. */
|
|
72
|
+
request(branch, expectedSha) {
|
|
73
|
+
if (!validBranch(branch)) {
|
|
74
|
+
throw new PlanError(`not a valid branch name: ${JSON.stringify(branch)}`, 400);
|
|
75
|
+
}
|
|
76
|
+
if (expectedSha !== undefined && expectedSha !== null && expectedSha !== '' && !validSha(expectedSha)) {
|
|
77
|
+
throw new PlanError(`sha must be 7-40 lowercase hex characters`, 400);
|
|
78
|
+
}
|
|
79
|
+
if (this.#queue.length >= this.#opts.maxQueued) {
|
|
80
|
+
throw new PlanError(`${this.#queue.length} plans already queued — try again shortly`, 429);
|
|
81
|
+
}
|
|
82
|
+
const record = {
|
|
83
|
+
id: newRecordId('plan'),
|
|
84
|
+
branch,
|
|
85
|
+
...(validSha(expectedSha) ? { expectedSha } : {}),
|
|
86
|
+
status: 'queued',
|
|
87
|
+
requestedAt: new Date().toISOString(),
|
|
88
|
+
log: [],
|
|
89
|
+
};
|
|
90
|
+
this.#live.set(record.id, record);
|
|
91
|
+
this.#store.save(record);
|
|
92
|
+
this.#queue.push(record.id);
|
|
93
|
+
this.#log(`plan ${record.id} queued for ${branch}`);
|
|
94
|
+
void this.#drain();
|
|
95
|
+
return record;
|
|
96
|
+
}
|
|
97
|
+
get(id) {
|
|
98
|
+
return this.#live.get(id) ?? this.#store.get(id);
|
|
99
|
+
}
|
|
100
|
+
list(limit = 50) {
|
|
101
|
+
return this.#store.list(limit).map((r) => summarize(this.#live.get(r.id) ?? r));
|
|
102
|
+
}
|
|
103
|
+
/** Resolves with the record once it is finished, or after `ms`, whichever is first. */
|
|
104
|
+
wait(id, ms) {
|
|
105
|
+
const now = this.get(id);
|
|
106
|
+
if (!now || isFinished(now.status) || ms <= 0)
|
|
107
|
+
return Promise.resolve(now);
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
const done = () => {
|
|
110
|
+
clearTimeout(timer);
|
|
111
|
+
this.#events.off(id, done);
|
|
112
|
+
resolve(this.get(id));
|
|
113
|
+
};
|
|
114
|
+
const timer = setTimeout(done, ms);
|
|
115
|
+
this.#events.on(id, done);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// ---------------------------------------------------------------- worker ---
|
|
119
|
+
async #drain() {
|
|
120
|
+
if (this.#working)
|
|
121
|
+
return;
|
|
122
|
+
this.#working = true;
|
|
123
|
+
try {
|
|
124
|
+
for (let id = this.#queue.shift(); id; id = this.#queue.shift()) {
|
|
125
|
+
const record = this.#live.get(id);
|
|
126
|
+
if (!record)
|
|
127
|
+
continue;
|
|
128
|
+
try {
|
|
129
|
+
await this.#execute(record);
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
finish(record, 'failed', err instanceof Error ? err.message : String(err));
|
|
133
|
+
}
|
|
134
|
+
this.#store.save(record);
|
|
135
|
+
this.#live.delete(id);
|
|
136
|
+
this.#store.prune();
|
|
137
|
+
this.#log(`plan ${id} ${record.status}${record.error ? ` — ${record.error}` : ''}`);
|
|
138
|
+
this.#events.emit(id);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
this.#working = false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async #execute(record) {
|
|
146
|
+
record.status = 'running';
|
|
147
|
+
record.startedAt = new Date().toISOString();
|
|
148
|
+
record.overlappedRun = this.#opts.reconcileRunning?.() ?? false;
|
|
149
|
+
this.#store.save(record);
|
|
150
|
+
const note = (line) => appendCapped(record.log, line);
|
|
151
|
+
const refusal = await this.#prepare(record, note);
|
|
152
|
+
if (refusal)
|
|
153
|
+
return finish(record, 'refused', refusal);
|
|
154
|
+
const resultPath = join(this.#home, `${record.id}.result.json`);
|
|
155
|
+
rmSync(resultPath, { force: true });
|
|
156
|
+
const { command, args, env } = this.#opts.command({
|
|
157
|
+
configDir: this.#checkout,
|
|
158
|
+
home: this.#home,
|
|
159
|
+
resultPath,
|
|
160
|
+
});
|
|
161
|
+
const code = await runChild(command, args, env, this.#home, this.#opts.timeoutMs, note, () => {
|
|
162
|
+
if (this.#opts.reconcileRunning?.())
|
|
163
|
+
record.overlappedRun = true;
|
|
164
|
+
});
|
|
165
|
+
let result;
|
|
166
|
+
try {
|
|
167
|
+
result = JSON.parse(readFileSync(resultPath, 'utf8'));
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
/* reported below */
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
rmSync(resultPath, { force: true });
|
|
174
|
+
}
|
|
175
|
+
if (this.#opts.reconcileRunning?.())
|
|
176
|
+
record.overlappedRun = true;
|
|
177
|
+
if (result)
|
|
178
|
+
record.result = result;
|
|
179
|
+
if (code === 'timeout')
|
|
180
|
+
return finish(record, 'failed', `plan timed out after ${this.#opts.timeoutMs / 1000}s`);
|
|
181
|
+
if (!result)
|
|
182
|
+
return finish(record, 'failed', `plan exited ${code} without a result — see the log`);
|
|
183
|
+
if (result.sha !== record.sha) {
|
|
184
|
+
return finish(record, 'failed', `planned ${result.sha} but the checkout was at ${record.sha}`);
|
|
185
|
+
}
|
|
186
|
+
if (result.failed) {
|
|
187
|
+
const broken = result.modules.find((m) => m.error);
|
|
188
|
+
return finish(record, 'failed', broken ? `aborted at ${broken.scope}: ${broken.error}` : 'plan aborted');
|
|
189
|
+
}
|
|
190
|
+
finish(record, 'planned');
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Bring the plan clone to the branch tip. Returns a refusal message, or
|
|
194
|
+
* undefined when the checkout is ready to plan.
|
|
195
|
+
*/
|
|
196
|
+
async #prepare(record, note) {
|
|
197
|
+
const dir = this.#checkout;
|
|
198
|
+
const main = this.#opts.mainBranch;
|
|
199
|
+
mkdirSync(this.#home, { recursive: true });
|
|
200
|
+
if (!existsSync(join(dir, '.git'))) {
|
|
201
|
+
rmSync(dir, { recursive: true, force: true });
|
|
202
|
+
note(`cloning ${this.#opts.repoUrl}`);
|
|
203
|
+
// Full history, not --depth: "is main an ancestor of this branch" is only
|
|
204
|
+
// answerable when both histories are present back to where they meet.
|
|
205
|
+
await git(this.#opts.root, 'clone', '--no-checkout', '--', this.#opts.repoUrl, dir);
|
|
206
|
+
}
|
|
207
|
+
await git(dir, 'fetch', '--quiet', '--prune', 'origin', `+refs/heads/${main}:refs/remotes/origin/${main}`);
|
|
208
|
+
try {
|
|
209
|
+
await git(dir, 'fetch', '--quiet', 'origin', `+refs/heads/${record.branch}:refs/remotes/origin/${record.branch}`);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return `no branch "${record.branch}" on the config repo — push it first`;
|
|
213
|
+
}
|
|
214
|
+
const sha = (await git(dir, 'rev-parse', '--verify', `refs/remotes/origin/${record.branch}^{commit}`)).trim();
|
|
215
|
+
const mainSha = (await git(dir, 'rev-parse', '--verify', `refs/remotes/origin/${main}^{commit}`)).trim();
|
|
216
|
+
record.sha = sha;
|
|
217
|
+
record.mainSha = mainSha;
|
|
218
|
+
note(`${record.branch} is at ${sha.slice(0, 12)}, ${main} at ${mainSha.slice(0, 12)}`);
|
|
219
|
+
if (record.expectedSha && !sha.startsWith(record.expectedSha)) {
|
|
220
|
+
return `${record.branch} is at ${sha.slice(0, 12)}, not ${record.expectedSha} — push, or plan without a sha`;
|
|
221
|
+
}
|
|
222
|
+
const isAncestor = await git(dir, 'merge-base', '--is-ancestor', mainSha, sha).then(() => true, () => false);
|
|
223
|
+
if (!isAncestor) {
|
|
224
|
+
const behind = (await git(dir, 'rev-list', '--count', `${sha}..${mainSha}`)).trim();
|
|
225
|
+
return (`${record.branch} is ${behind} commit(s) behind ${main} — a plan would show those commits ` +
|
|
226
|
+
`being undone. Rebase onto origin/${main}, push, and plan again.`);
|
|
227
|
+
}
|
|
228
|
+
const log = await git(dir, 'log', '--max-count=50', '--format=%H%x09%s', `${mainSha}..${sha}`);
|
|
229
|
+
record.ahead = log
|
|
230
|
+
.split('\n')
|
|
231
|
+
.filter(Boolean)
|
|
232
|
+
.map((l) => {
|
|
233
|
+
const [s, ...subject] = l.split('\t');
|
|
234
|
+
return { sha: s ?? '', subject: subject.join('\t') };
|
|
235
|
+
});
|
|
236
|
+
await git(dir, 'checkout', '--quiet', '--force', '--detach', sha);
|
|
237
|
+
await git(dir, 'clean', '-ffdxq');
|
|
238
|
+
this.#store.save(record);
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* A plan that was queued or running when the daemon stopped will never
|
|
243
|
+
* finish. Say so, rather than leaving it "running" forever.
|
|
244
|
+
*/
|
|
245
|
+
#recoverInterrupted() {
|
|
246
|
+
for (const r of this.#store.list()) {
|
|
247
|
+
if (isFinished(r.status))
|
|
248
|
+
continue;
|
|
249
|
+
finish(r, 'failed', 'interrupted — the daemon restarted before this plan finished');
|
|
250
|
+
this.#store.save(r);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
#log(message) {
|
|
254
|
+
this.#opts.log?.('plan', message);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function isFinished(status) {
|
|
258
|
+
return status === 'refused' || status === 'failed' || status === 'planned';
|
|
259
|
+
}
|
|
260
|
+
function finish(record, status, error) {
|
|
261
|
+
record.status = status;
|
|
262
|
+
record.finishedAt = new Date().toISOString();
|
|
263
|
+
if (error) {
|
|
264
|
+
record.error = error;
|
|
265
|
+
appendCapped(record.log, `${status}: ${error}`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async function git(cwd, ...args) {
|
|
269
|
+
const { stdout } = await execFileAsync('git', args, {
|
|
270
|
+
cwd,
|
|
271
|
+
encoding: 'utf8',
|
|
272
|
+
timeout: 120_000,
|
|
273
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
274
|
+
// Never prompt: a credential prompt would hang the plan worker forever.
|
|
275
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
276
|
+
});
|
|
277
|
+
return stdout;
|
|
278
|
+
}
|
|
279
|
+
/** Run the plan child, streaming its output into the record. */
|
|
280
|
+
function runChild(command, args, env, cwd, timeoutMs, note, tick) {
|
|
281
|
+
return new Promise((resolve) => {
|
|
282
|
+
const child = spawn(command, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
283
|
+
let timedOut = false;
|
|
284
|
+
const timer = setTimeout(() => {
|
|
285
|
+
timedOut = true;
|
|
286
|
+
child.kill('SIGKILL');
|
|
287
|
+
}, timeoutMs);
|
|
288
|
+
const ticker = setInterval(tick, 5_000);
|
|
289
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
290
|
+
let partial = '';
|
|
291
|
+
stream.setEncoding('utf8');
|
|
292
|
+
stream.on('data', (chunk) => {
|
|
293
|
+
const lines = (partial + chunk).split('\n');
|
|
294
|
+
partial = lines.pop() ?? '';
|
|
295
|
+
for (const l of lines)
|
|
296
|
+
note(l);
|
|
297
|
+
});
|
|
298
|
+
stream.on('end', () => {
|
|
299
|
+
if (partial)
|
|
300
|
+
note(partial);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
const done = (code) => {
|
|
304
|
+
clearTimeout(timer);
|
|
305
|
+
clearInterval(ticker);
|
|
306
|
+
resolve(code);
|
|
307
|
+
};
|
|
308
|
+
child.on('error', (err) => {
|
|
309
|
+
note(`could not start the plan: ${err.message}`);
|
|
310
|
+
done(-1);
|
|
311
|
+
});
|
|
312
|
+
child.on('close', (code) => done(timedOut ? 'timeout' : (code ?? -1)));
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=plans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.js","sourceRoot":"","sources":["../src/plans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AA4ErE,MAAM,UAAU,SAAS,CAAC,CAAa;IACrC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,CAAA;IACxC,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AAC/D,CAAC;AA0BD,MAAM,OAAO,SAAU,SAAQ,KAAK;IAGvB;IAFX,YACE,OAAe,EACN,MAAc;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAA;QAFL,WAAM,GAAN,MAAM,CAAQ;IAGzB,CAAC;CACF;AAED,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAa;IACvC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,C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KAAK,EAAE,GAAG,EAAE;gBACpB,IAAI,OAAO;oBAAE,IAAI,CAAC,OAAO,CAAC,CAAA;YAC5B,CAAC,CAAC,CAAA;QACJ,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,IAAwB,EAAE,EAAE;YACxC,YAAY,CAAC,KAAK,CAAC,CAAA;YACnB,aAAa,CAAC,MAAM,CAAC,CAAA;YACrB,OAAO,CAAC,IAAI,CAAC,CAAA;QACf,CAAC,CAAA;QACD,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACxB,IAAI,CAAC,6BAA6B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;YAChD,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;QACF,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACxE,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small on-disk history: one JSON file per record, newest kept, oldest pruned.
|
|
3
|
+
*
|
|
4
|
+
* It backs the reconcile and plan history the UI shows. Nothing here is state
|
|
5
|
+
* Concord depends on: losing the directory loses history, never control.
|
|
6
|
+
* Every failure is swallowed for that reason — a full disk must not become a
|
|
7
|
+
* failed reconcile (daemon rule 2).
|
|
8
|
+
*/
|
|
9
|
+
export declare class RecordStore<T extends {
|
|
10
|
+
id: string;
|
|
11
|
+
}> {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(dir: string, keep?: number);
|
|
14
|
+
/** Atomically write a record: temp file, then rename. */
|
|
15
|
+
save(record: T): void;
|
|
16
|
+
get(id: string): T | undefined;
|
|
17
|
+
/** Newest first. Ids sort chronologically, so the file names are the index. */
|
|
18
|
+
ids(): string[];
|
|
19
|
+
list(limit?: number): T[];
|
|
20
|
+
/** Drop everything past the newest `keep`. */
|
|
21
|
+
prune(): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `<prefix>-YYYYMMDD-HHMMSSmmm-<hex>`, in UTC. Lexical order is chronological,
|
|
25
|
+
* which is what lets the directory listing be the index — so ids minted in
|
|
26
|
+
* the same millisecond are pushed a millisecond apart rather than left to the
|
|
27
|
+
* random suffix to order.
|
|
28
|
+
*/
|
|
29
|
+
export declare function newRecordId(prefix: string, now?: Date): string;
|
|
30
|
+
/** Ids reach the filesystem from URLs, so only the exact shape is accepted. */
|
|
31
|
+
export declare function isRecordId(id: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Append a line to a capped log. Past the cap the middle is dropped and the
|
|
34
|
+
* tail kept: the end of a log is where a failure is explained.
|
|
35
|
+
*/
|
|
36
|
+
export declare function appendCapped(lines: string[], line: string, cap?: number): void;
|
|
37
|
+
//# sourceMappingURL=records.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE;;gBAInC,GAAG,EAAE,MAAM,EAAE,IAAI,SAAM;IAMnC,yDAAyD;IACzD,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI;IAWrB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAS9B,+EAA+E;IAC/E,GAAG,IAAI,MAAM,EAAE;IAaf,IAAI,CAAC,KAAK,SAAa,GAAG,CAAC,EAAE;IAO7B,8CAA8C;IAC9C,KAAK,IAAI,IAAI;CASd;AAID;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAa,GAAG,MAAM,CAKpE;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAE9C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,SAAO,GAAG,IAAI,CAG5E"}
|
package/dist/records.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
/**
|
|
5
|
+
* A small on-disk history: one JSON file per record, newest kept, oldest pruned.
|
|
6
|
+
*
|
|
7
|
+
* It backs the reconcile and plan history the UI shows. Nothing here is state
|
|
8
|
+
* Concord depends on: losing the directory loses history, never control.
|
|
9
|
+
* Every failure is swallowed for that reason — a full disk must not become a
|
|
10
|
+
* failed reconcile (daemon rule 2).
|
|
11
|
+
*/
|
|
12
|
+
export class RecordStore {
|
|
13
|
+
#dir;
|
|
14
|
+
#keep;
|
|
15
|
+
constructor(dir, keep = 100) {
|
|
16
|
+
this.#dir = dir;
|
|
17
|
+
this.#keep = keep;
|
|
18
|
+
mkdirSync(dir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
/** Atomically write a record: temp file, then rename. */
|
|
21
|
+
save(record) {
|
|
22
|
+
try {
|
|
23
|
+
const path = join(this.#dir, `${record.id}.json`);
|
|
24
|
+
const tmp = `${path}.tmp`;
|
|
25
|
+
writeFileSync(tmp, JSON.stringify(record));
|
|
26
|
+
renameSync(tmp, path);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* history is a nicety; see the class comment */
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
get(id) {
|
|
33
|
+
if (!isRecordId(id))
|
|
34
|
+
return undefined;
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(readFileSync(join(this.#dir, `${id}.json`), 'utf8'));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Newest first. Ids sort chronologically, so the file names are the index. */
|
|
43
|
+
ids() {
|
|
44
|
+
try {
|
|
45
|
+
return readdirSync(this.#dir)
|
|
46
|
+
.filter((f) => f.endsWith('.json'))
|
|
47
|
+
.map((f) => f.slice(0, -'.json'.length))
|
|
48
|
+
.filter(isRecordId)
|
|
49
|
+
.sort()
|
|
50
|
+
.reverse();
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
list(limit = this.#keep) {
|
|
57
|
+
return this.ids()
|
|
58
|
+
.slice(0, limit)
|
|
59
|
+
.map((id) => this.get(id))
|
|
60
|
+
.filter((r) => r !== undefined);
|
|
61
|
+
}
|
|
62
|
+
/** Drop everything past the newest `keep`. */
|
|
63
|
+
prune() {
|
|
64
|
+
for (const id of this.ids().slice(this.#keep)) {
|
|
65
|
+
try {
|
|
66
|
+
rmSync(join(this.#dir, `${id}.json`), { force: true });
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
/* next prune gets it */
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
let lastMs = 0;
|
|
75
|
+
/**
|
|
76
|
+
* `<prefix>-YYYYMMDD-HHMMSSmmm-<hex>`, in UTC. Lexical order is chronological,
|
|
77
|
+
* which is what lets the directory listing be the index — so ids minted in
|
|
78
|
+
* the same millisecond are pushed a millisecond apart rather than left to the
|
|
79
|
+
* random suffix to order.
|
|
80
|
+
*/
|
|
81
|
+
export function newRecordId(prefix, now = new Date()) {
|
|
82
|
+
const ms = Math.max(now.getTime(), lastMs + 1);
|
|
83
|
+
lastMs = ms;
|
|
84
|
+
const stamp = new Date(ms).toISOString().replace(/[-:.]/g, '').replace('T', '-').slice(0, 18);
|
|
85
|
+
return `${prefix}-${stamp}-${randomBytes(3).toString('hex')}`;
|
|
86
|
+
}
|
|
87
|
+
/** Ids reach the filesystem from URLs, so only the exact shape is accepted. */
|
|
88
|
+
export function isRecordId(id) {
|
|
89
|
+
return /^[a-z]+-\d{8}-\d{9}-[0-9a-f]{6}$/.test(id);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Append a line to a capped log. Past the cap the middle is dropped and the
|
|
93
|
+
* tail kept: the end of a log is where a failure is explained.
|
|
94
|
+
*/
|
|
95
|
+
export function appendCapped(lines, line, cap = 5000) {
|
|
96
|
+
lines.push(line);
|
|
97
|
+
if (lines.length > cap)
|
|
98
|
+
lines.splice(200, lines.length - cap, '… (log truncated) …');
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=records.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../src/records.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;;;;;GAOG;AACH,MAAM,OAAO,WAAW;IACb,IAAI,CAAQ;IACZ,KAAK,CAAQ;IAEtB,YAAY,GAAW,EAAE,IAAI,GAAG,GAAG;QACjC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;QACf,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;QACjB,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACrC,CAAC;IAED,yDAAyD;IACzD,IAAI,CAAC,MAAS;QACZ,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,EAAE,OAAO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AAY,EAAE,GAAG,GAAG,IAAI;IACpE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAChB,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG;QAAE,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,qBAAqB,CAAC,CAAA;AACtF,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BaseOp, Module } from './module.js';
|
|
2
|
+
import type { HostConfig, ModuleConfig } from './schema.js';
|
|
3
|
+
/**
|
|
4
|
+
* The only place module classes are instantiated.
|
|
5
|
+
*
|
|
6
|
+
* The config repo hands over plain data; the reconciler builds instances from
|
|
7
|
+
* ITS OWN classes. That is what lets the config be genuinely independent of the
|
|
8
|
+
* running reconciler — no shared object graph, so no need to force the config's
|
|
9
|
+
* package import to resolve here.
|
|
10
|
+
*
|
|
11
|
+
* Adding a module = a schema in the union (schema.ts) + an entry here. The
|
|
12
|
+
* mapped type over ModuleConfig['type'] makes that exhaustive: forget one and
|
|
13
|
+
* this file fails to compile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* What a module TYPE contributes, beyond instances of declared config.
|
|
17
|
+
*
|
|
18
|
+
* `sweeper` is the host-truth lifecycle: a kind that defines it gets one
|
|
19
|
+
* synthesized enforcer per registry host, appended by the loader after every
|
|
20
|
+
* declared module. The keep-set is the union of `owned()` across the kind's
|
|
21
|
+
* instances on that host — injected at construction, so a sweeper without one
|
|
22
|
+
* cannot exist. Sweeping is a property of the kind, not something config
|
|
23
|
+
* declares: the config declares what SHOULD exist, and anything the kind
|
|
24
|
+
* tagged that is no longer declared is withdrawn.
|
|
25
|
+
*/
|
|
26
|
+
interface ModuleKind<T extends ModuleConfig> {
|
|
27
|
+
create(config: T): Module<any, BaseOp>;
|
|
28
|
+
sweeper?(host: string, keep: ReadonlySet<string>, config: HostConfig): Module<any, BaseOp>;
|
|
29
|
+
}
|
|
30
|
+
type Registry = {
|
|
31
|
+
[K in ModuleConfig['type']]: ModuleKind<Extract<ModuleConfig, {
|
|
32
|
+
type: K;
|
|
33
|
+
}>>;
|
|
34
|
+
};
|
|
35
|
+
export declare const REGISTRY: Registry;
|
|
36
|
+
export declare function instantiate(config: ModuleConfig): Module<any, BaseOp>;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAY3D;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;GAUG;AACH,UAAU,UAAU,CAAC,CAAC,SAAS,YAAY;IACzC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IACtC,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;CAC3F;AAED,KAAK,QAAQ,GAAG;KACb,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;CAC5E,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,QAetB,CAAA;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAGrE"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AptModule } from './modules/apt/index.js';
|
|
2
|
+
import { FileModule } from './modules/file/index.js';
|
|
3
|
+
import { SystemdModule } from './modules/systemd/index.js';
|
|
4
|
+
import { SystemdSweeper } from './modules/systemd/sweeper.js';
|
|
5
|
+
import { ScriptModule } from './modules/script/index.js';
|
|
6
|
+
import { DockerModule } from './modules/docker/index.js';
|
|
7
|
+
import { DockerSweeper } from './modules/docker/sweeper.js';
|
|
8
|
+
import { PorkbunModule } from './modules/porkbun/index.js';
|
|
9
|
+
import { CloudflareModule } from './modules/cloudflare/index.js';
|
|
10
|
+
import { CheckoutModule } from './modules/checkout/index.js';
|
|
11
|
+
export const REGISTRY = {
|
|
12
|
+
porkbun: { create: (config) => new PorkbunModule(config) },
|
|
13
|
+
cloudflare: { create: (config) => new CloudflareModule(config) },
|
|
14
|
+
apt: { create: (config) => new AptModule(config) },
|
|
15
|
+
file: { create: (config) => new FileModule(config) },
|
|
16
|
+
systemd: {
|
|
17
|
+
create: (config) => new SystemdModule(config),
|
|
18
|
+
sweeper: (host, keep) => new SystemdSweeper(host, keep),
|
|
19
|
+
},
|
|
20
|
+
script: { create: (config) => new ScriptModule(config) },
|
|
21
|
+
checkout: { create: (config) => new CheckoutModule(config) },
|
|
22
|
+
docker: {
|
|
23
|
+
create: (config) => new DockerModule(config),
|
|
24
|
+
sweeper: (host, keep, config) => new DockerSweeper(host, keep, config.containerSweep),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export function instantiate(config) {
|
|
28
|
+
const kind = REGISTRY[config.type];
|
|
29
|
+
return kind.create(config);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE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M,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC;QAC5C,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,cAAc,CAAC;KACtF;CACF,CAAA;AAED,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC9C,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAA6B,CAAA;IAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC5B,CAAC"}
|
package/dist/runner.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { BaseOp, Module } from './module.js';
|
|
2
|
+
import type { HostConfig, Settings } from './schema.js';
|
|
3
|
+
export interface RunOptions {
|
|
4
|
+
modules: Module<unknown, BaseOp>[];
|
|
5
|
+
ageKey: string;
|
|
6
|
+
stateRoot: string;
|
|
7
|
+
/** Config repo checkout — modules resolve `source` paths against it. */
|
|
8
|
+
configDir: string;
|
|
9
|
+
/** When false, plans are computed and printed but never applied. */
|
|
10
|
+
apply: boolean;
|
|
11
|
+
hosts: Record<string, HostConfig>;
|
|
12
|
+
settings: Settings;
|
|
13
|
+
log: (scope: string, message: string) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface ModuleResult {
|
|
16
|
+
id: string;
|
|
17
|
+
kind: string;
|
|
18
|
+
/** The host it targets; absent for API-driving modules (porkbun). */
|
|
19
|
+
host?: string;
|
|
20
|
+
ops: BaseOp[];
|
|
21
|
+
applied: boolean;
|
|
22
|
+
error?: string;
|
|
23
|
+
/** Host was unreachable and optional — this module's state is UNKNOWN. */
|
|
24
|
+
unreachable?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface RunResult {
|
|
27
|
+
/** Only the modules that actually ran. A run aborts at the first failure. */
|
|
28
|
+
modules: ModuleResult[];
|
|
29
|
+
totalOps: number;
|
|
30
|
+
failed: boolean;
|
|
31
|
+
/** Declared but never evaluated, because an earlier module failed. */
|
|
32
|
+
skipped: string[];
|
|
33
|
+
/** Skipped because their host was unreachable and declared optional. */
|
|
34
|
+
unreachable: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Things that did not converge but were declared non-blocking.
|
|
37
|
+
*
|
|
38
|
+
* A run carrying warnings is NOT "converged — no changes". The state of a
|
|
39
|
+
* warned target is known (it is still on its previous version), which is what
|
|
40
|
+
* separates this from `unreachable`, where the state is unknown.
|
|
41
|
+
*/
|
|
42
|
+
warnings: {
|
|
43
|
+
scope: string;
|
|
44
|
+
message: string;
|
|
45
|
+
}[];
|
|
46
|
+
}
|
|
47
|
+
export declare function run(opts: RunOptions): Promise<RunResult>;
|
|
48
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAA;AAEhE,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEvD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAA;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAA;IACjB,oEAAoE;IACpE,KAAK,EAAE,OAAO,CAAA;IACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACjC,QAAQ,EAAE,QAAQ,CAAA;IAClB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAC9C;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,IA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