@consilium108/mcp-module-devops 1.4.0 → 1.5.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/CHANGELOG.md +12 -0
- package/README.md +16 -2
- package/bin/consilium-devops-runner.js +16 -0
- package/package.json +1 -1
- package/src/runner/config.js +1 -1
- package/src/runner/index.js +1 -0
- package/src/runner/recipes.js +3 -1
- package/src/runner/record.js +140 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.5.0 — 2026-11-25 (OPS-AUDIT-435)
|
|
4
|
+
|
|
5
|
+
<!-- generated by Claude (Opus 5.5), 2026-11-24; Konsilium OPS-AUDIT-435 (deploy audit #435 recommendations 7, 8). -->
|
|
6
|
+
|
|
7
|
+
- **`consilium-devops-runner record`** — a deploy made from the terminal goes into the Konsilium deploy journal
|
|
8
|
+
(`POST /api/deploy/runner/record` with the target's runner token; `requested_via = 'terminal'`; nothing runs, nothing is
|
|
9
|
+
approved; idempotent by summary + start time; `--dry-run` prints the body without the token). Needs a core / DevOps
|
|
10
|
+
module with that route (older → `not_supported`). Exported as `runRecord`, `recordDeploy`, `buildRecordBody`, … from
|
|
11
|
+
`./runner`; the monorepo wrapper is `scripts/record-deploy.mjs`.
|
|
12
|
+
- Recipe `konsilium-linux`: the first check is `GET /api/health?deep=1` (DB, migrations = newest file, remote modules;
|
|
13
|
+
`deepHealth: false` → the plain `/api/health`); the example config's watchdog health URL uses `?deep=1` too.
|
|
14
|
+
|
|
3
15
|
## 1.4.0 — 2026-11-24
|
|
4
16
|
|
|
5
17
|
<!-- generated by Claude (Opus 5.5), 2026-11-24; Konsilium TASK-P37-486 v2, SDD-P37-160 IT-160-1 … IT-160-7 — owner
|
package/README.md
CHANGED
|
@@ -192,7 +192,7 @@ consilium-devops-runner once # один цикл
|
|
|
192
192
|
"mcpUrl": "http://127.0.0.1:8091"
|
|
193
193
|
}
|
|
194
194
|
},
|
|
195
|
-
"watch": { "diskPath": "/", "minFreeGb": 30, "health": "http://127.0.0.1:8090/api/health", "chatIds": [], "envFile": "~/.config/consilium-devops-runner/runner.env" }
|
|
195
|
+
"watch": { "diskPath": "/", "minFreeGb": 30, "health": "http://127.0.0.1:8090/api/health?deep=1", "chatIds": [], "envFile": "~/.config/consilium-devops-runner/runner.env" }
|
|
196
196
|
}
|
|
197
197
|
```
|
|
198
198
|
|
|
@@ -204,7 +204,7 @@ consilium-devops-runner once # один цикл
|
|
|
204
204
|
`docker compose exec -T app node --no-deprecation scripts/db-backup.js`;
|
|
205
205
|
2. **выкатка**: образ запущенного контейнера каждого сервиса → `konsilium-<svc>:prev`; `user_version` до;
|
|
206
206
|
`GIT_SHA=$(git rev-parse HEAD) docker compose up -d --build app mcp`; ожидание healthy (`healthyTimeoutMs`, 5 мин);
|
|
207
|
-
3. **проверки**: `GET /api/health` 200, `POST /mcp` 401 без ключа, `POST /line/webhook` и `/max/webhook` 401,
|
|
207
|
+
3. **проверки**: `GET /api/health?deep=1` 200 (БД, миграции, модули; `deepHealth: false` — простой `/api/health`), `POST /mcp` 401 без ключа, `POST /line/webhook` и `/max/webhook` 401,
|
|
208
208
|
`user_version` через node + better-sqlite3 внутри контейнера app (не меньше, чем до), ошибок в логах app/mcp с
|
|
209
209
|
начала выкатки 0 (`logErrorPattern`);
|
|
210
210
|
4. **откат** при сбое шага 2–3 (и по кнопке «↩ Откатить»): `docker tag konsilium-<svc>:prev konsilium-<svc>:latest`,
|
|
@@ -219,6 +219,20 @@ consilium-devops-runner once # один цикл
|
|
|
219
219
|
своими `deploy` / `rollback` / `health` (формат старого `deploy-runner/config.json`) работает как раньше. `git pull`
|
|
220
220
|
runner не делает: выкатывается то, что лежит в рабочей копии (HEAD).
|
|
221
221
|
|
|
222
|
+
### Запись терминальной выкатки (`record`, OPS-AUDIT-435)
|
|
223
|
+
|
|
224
|
+
Если выкатка сделана из терминала, а не кнопкой, ведущий сразу после неё записывает её в тот же журнал:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
consilium-devops-runner record --summary "app + mcp: …, миграции …" --exit-code 0 --health ok \
|
|
228
|
+
--started-at 2026-11-24T10:00:00Z --approval "Антон: «выкатывай» в терминале" [--log-file deploy.log] [--dry-run]
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
`POST /api/deploy/runner/record` с токеном цели (`CONSILIUM_RUNNER_TOKEN` или `tokenFile` конфига; не печатается):
|
|
232
|
+
запись `requested_via = 'terminal'`, `approved_by` пустой, текст одобрения — в сводке; повтор не дублирует; событие
|
|
233
|
+
`deploy.done` / `deploy.failed` в журнал проекта, людям сообщений нет. Ничего не выполняет. В монорепо то же —
|
|
234
|
+
`node scripts/record-deploy.mjs …`.
|
|
235
|
+
|
|
222
236
|
### Установка на сервере (делает человек)
|
|
223
237
|
|
|
224
238
|
`consilium-devops-runner install --print` (или MCP `runner_setup`) печатает точные команды: токен цели через
|
|
@@ -17,6 +17,9 @@ import {
|
|
|
17
17
|
formatDoctor,
|
|
18
18
|
installSteps,
|
|
19
19
|
loadConfig,
|
|
20
|
+
RECORD_USAGE,
|
|
21
|
+
formatRecorded,
|
|
22
|
+
runRecord,
|
|
20
23
|
tick,
|
|
21
24
|
unitText,
|
|
22
25
|
} from '../src/runner/index.js';
|
|
@@ -32,6 +35,8 @@ const USAGE = `consilium-devops-runner — Konsilium deploy runner (${PKG.name}
|
|
|
32
35
|
consilium-devops-runner install --print [--user] [--repo <dir>] [--target <key>] PRINT the systemd unit and steps
|
|
33
36
|
consilium-devops-runner unit --print [--user] [--repo <dir>] PRINT only the unit
|
|
34
37
|
consilium-devops-runner config --print [--repo <dir>] [--target <key>] PRINT an example config (no secret)
|
|
38
|
+
consilium-devops-runner record --summary "…" [--exit-code N] [--approval "…"] [--dry-run] put a TERMINAL deploy into
|
|
39
|
+
the Konsilium deploy journal (after the fact; nothing runs; record --help)
|
|
35
40
|
consilium-devops-runner --version | --help
|
|
36
41
|
|
|
37
42
|
Options: --config <file>
|
|
@@ -59,6 +64,17 @@ const repoGuess = () => resolve(dirname(BIN), '..', '..', '..');
|
|
|
59
64
|
|
|
60
65
|
async function main() {
|
|
61
66
|
if (has('--version') || cmd === 'version') return out(PKG.version);
|
|
67
|
+
if (cmd === 'record') {
|
|
68
|
+
// OPS-AUDIT-435: its own flags (--summary "…" has free text) — parsed by runRecord, not by the generic parser above
|
|
69
|
+
if (has('--help') || has('-h')) return out(RECORD_USAGE);
|
|
70
|
+
try {
|
|
71
|
+
const r = await runRecord(argv.slice(argv.indexOf('record') + 1));
|
|
72
|
+
if (r.dryRun) return out(JSON.stringify({ server: r.server, token: r.tokenPresent ? 'present (not shown)' : 'missing', body: r.body }, null, 2));
|
|
73
|
+
return out(formatRecorded(r.row));
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return fail(e, e.code === 'bad_argument' || e.code === 'summary_required' ? 2 : 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
62
78
|
if (has('--help') || has('-h') || cmd === 'help') return out(USAGE);
|
|
63
79
|
const configFile = opt('--config');
|
|
64
80
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@consilium108/mcp-module-devops",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "DevOps module of the Konsilium MCP (#442): Deploy requests by button and their status; debug reports of apps. Loaded by the host @consilium108/mcp; also runs on its own (bin consilium-devops-mcp, #482) — with the DevOps Orchestrator inside that process (#486 v2: Konsilium events → jobs of the workspace's job inbox, claimed by the session's own subagents); the deploy runner service (bin consilium-devops-runner).",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "NativeMind",
|
package/src/runner/config.js
CHANGED
|
@@ -134,7 +134,7 @@ export function exampleConfig({ repoDir = '/path/to/consilium.nativemind.net', t
|
|
|
134
134
|
intervalMs: 60000,
|
|
135
135
|
diskPath: '/',
|
|
136
136
|
minFreeGb: 30,
|
|
137
|
-
health: 'http://127.0.0.1:8090/api/health',
|
|
137
|
+
health: 'http://127.0.0.1:8090/api/health?deep=1', // OPS-AUDIT-435: DB + migrations + modules, 503 when broken
|
|
138
138
|
failAfter: 3,
|
|
139
139
|
chatIds: [],
|
|
140
140
|
envFile: '~/.config/consilium-devops-runner/runner.env',
|
package/src/runner/index.js
CHANGED
|
@@ -10,3 +10,4 @@ export { tick, resolveTarget, createRunner } from './daemon.js';
|
|
|
10
10
|
export { SERVICE_NAME, unitText, installSteps } from './install.js';
|
|
11
11
|
export { doctor, formatDoctor } from './doctor.js';
|
|
12
12
|
export { createLogger, redact } from './log.js';
|
|
13
|
+
export { RECORD_USAGE, parseRecordArgs, buildRecordBody, gitHead, logTailOf, recordDeploy, formatRecorded, runRecord } from './record.js'; // OPS-AUDIT-435
|
package/src/runner/recipes.js
CHANGED
|
@@ -24,6 +24,7 @@ const KONSILIUM_DEFAULTS = {
|
|
|
24
24
|
healthyTimeoutMs: 300_000,
|
|
25
25
|
userVersion: true,
|
|
26
26
|
logErrors: true,
|
|
27
|
+
deepHealth: true, // OPS-AUDIT-435: the first check is GET /api/health?deep=1
|
|
27
28
|
logErrorPattern: '"level":(50|60)\\b|UnhandledPromiseRejection|Uncaught(Exception)?\\b|FATAL',
|
|
28
29
|
stepTimeoutMs: 20 * 60_000,
|
|
29
30
|
};
|
|
@@ -50,7 +51,8 @@ export function httpCheck({ method = 'GET', url, expect = 200, headers = {}, bod
|
|
|
50
51
|
export function konsiliumChecks(o, deps) {
|
|
51
52
|
const json = { 'content-type': 'application/json', accept: 'application/json, text/event-stream' };
|
|
52
53
|
return [
|
|
53
|
-
|
|
54
|
+
// OPS-AUDIT-435: deep=1 — DB, migrations = newest file, remote modules (an older core ignores the query and answers 200)
|
|
55
|
+
{ method: 'GET', url: `${o.appUrl}/api/health${o.deepHealth === false ? '' : '?deep=1'}`, expect: 200 },
|
|
54
56
|
{ method: 'POST', url: `${o.mcpUrl}/mcp`, expect: 401, headers: json, body: '{}' },
|
|
55
57
|
{ method: 'POST', url: `${o.appUrl}/line/webhook`, expect: 401, headers: json, body: '{}' },
|
|
56
58
|
{ method: 'POST', url: `${o.appUrl}/max/webhook`, expect: 401, headers: json, body: '{}' },
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// generated by Claude (Opus 5.5), 2026-11-24 — OPS-AUDIT-435 (аудит выкаток #435, рекомендация 8): a deploy made from
|
|
2
|
+
// the TERMINAL goes into the same journal as the button ones (deploy_requests, requested_via 'terminal'). The lead calls
|
|
3
|
+
// `consilium-devops-runner record …` (or scripts/record-deploy.mjs in the Konsilium checkout) right after a terminal
|
|
4
|
+
// deploy. It POSTs /api/deploy/runner/record with the target's runner token through the Konsilium API (the core proxies it
|
|
5
|
+
// to the DevOps module with MODULE_DEVOPS=remote) — it never opens a database, never runs a step, never approves anything.
|
|
6
|
+
// The token comes from CONSILIUM_RUNNER_TOKEN or the runner config's tokenFile and is never printed.
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
import { DevopsMcpError } from '../errors.js';
|
|
10
|
+
import { DEFAULT_SERVER, findConfig, loadConfig } from './config.js';
|
|
11
|
+
import { LOG_MAX } from './steps.js';
|
|
12
|
+
|
|
13
|
+
export const RECORD_USAGE = `record — put a terminal deploy into the Konsilium deploy journal (after the fact; nothing runs)
|
|
14
|
+
|
|
15
|
+
record --summary "<what changed>" [--exit-code N | --status done|failed] [--health ok|fail|<text>]
|
|
16
|
+
[--started-at <ISO>] [--finished-at <ISO>] [--approval "<who approved, where, when>"]
|
|
17
|
+
[--git-sha <sha> | --repo <dir>] [--log-file <file>] [--kind deploy|rollback]
|
|
18
|
+
[--server <url>] [--config <file>] [--dry-run]
|
|
19
|
+
|
|
20
|
+
The token: CONSILIUM_RUNNER_TOKEN, else "tokenFile" of the runner config (never printed).
|
|
21
|
+
The server: --server, else KONSILIUM_API_URL, else the runner config's "server" (e.g. http://127.0.0.1:8090 on the prod host).
|
|
22
|
+
--dry-run prints the request body (without the token) and sends nothing.`;
|
|
23
|
+
|
|
24
|
+
const VALUED = ['--summary', '--exit-code', '--status', '--health', '--started-at', '--finished-at', '--approval', '--git-sha', '--repo', '--log-file', '--kind', '--server', '--config'];
|
|
25
|
+
|
|
26
|
+
/** argv (after the command) → options; unknown flags are an error. */
|
|
27
|
+
export function parseRecordArgs(argv) {
|
|
28
|
+
const o = { dryRun: false };
|
|
29
|
+
for (let i = 0; i < argv.length; i++) {
|
|
30
|
+
const a = argv[i];
|
|
31
|
+
if (a === 'record') continue;
|
|
32
|
+
if (a === '--dry-run') {
|
|
33
|
+
o.dryRun = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!VALUED.includes(a)) throw new DevopsMcpError('bad_argument', `unknown argument ${a} (record --help)`);
|
|
37
|
+
const v = argv[i + 1];
|
|
38
|
+
if (v == null || (v.startsWith('--') && VALUED.includes(v))) throw new DevopsMcpError('bad_argument', `${a} needs a value`);
|
|
39
|
+
o[a.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase())] = v;
|
|
40
|
+
i++;
|
|
41
|
+
}
|
|
42
|
+
return o;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Options → the request body. Pure (gitSha / logTail are passed in). */
|
|
46
|
+
export function buildRecordBody(o, { gitSha = null, logTail = '' } = {}) {
|
|
47
|
+
const summary = String(o.summary ?? '').trim();
|
|
48
|
+
if (!summary) throw new DevopsMcpError('summary_required', '--summary is required (what was deployed: services, migrations, commits)');
|
|
49
|
+
let exitCode = null;
|
|
50
|
+
if (o.exitCode != null) {
|
|
51
|
+
exitCode = Number(o.exitCode);
|
|
52
|
+
if (!Number.isInteger(exitCode)) throw new DevopsMcpError('bad_argument', '--exit-code must be an integer');
|
|
53
|
+
}
|
|
54
|
+
if (o.status != null && !['done', 'failed'].includes(o.status)) throw new DevopsMcpError('bad_argument', '--status: done | failed');
|
|
55
|
+
if (o.kind != null && !['deploy', 'rollback'].includes(o.kind)) throw new DevopsMcpError('bad_argument', '--kind: deploy | rollback');
|
|
56
|
+
for (const k of ['startedAt', 'finishedAt']) if (o[k] != null && Number.isNaN(new Date(o[k]).getTime())) throw new DevopsMcpError('bad_argument', `--${k === 'startedAt' ? 'started-at' : 'finished-at'}: not a date/time`);
|
|
57
|
+
const body = { summary: summary.slice(0, 2000) };
|
|
58
|
+
if (o.status) body.status = o.status;
|
|
59
|
+
if (o.kind) body.kind = o.kind;
|
|
60
|
+
if (exitCode != null) body.exitCode = exitCode;
|
|
61
|
+
if (o.health) body.health = String(o.health).slice(0, 200);
|
|
62
|
+
if (o.startedAt) body.startedAt = new Date(o.startedAt).toISOString();
|
|
63
|
+
if (o.finishedAt) body.finishedAt = new Date(o.finishedAt).toISOString();
|
|
64
|
+
if (o.approval) body.approval = String(o.approval).slice(0, 300);
|
|
65
|
+
const sha = o.gitSha ?? gitSha;
|
|
66
|
+
if (sha) {
|
|
67
|
+
if (!/^[0-9a-f]{7,40}$/i.test(sha)) throw new DevopsMcpError('bad_argument', '--git-sha: 7–40 hex characters');
|
|
68
|
+
body.gitSha = sha;
|
|
69
|
+
}
|
|
70
|
+
if (logTail) body.logTail = String(logTail).slice(-LOG_MAX);
|
|
71
|
+
return body;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** HEAD of a checkout, or null. */
|
|
75
|
+
export function gitHead(repo) {
|
|
76
|
+
try {
|
|
77
|
+
return execFileSync('git', ['-C', repo, 'rev-parse', 'HEAD'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || null;
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The last LOG_MAX bytes of a log file. */
|
|
84
|
+
export function logTailOf(file) {
|
|
85
|
+
return readFileSync(file, 'utf8').slice(-LOG_MAX);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** POST /api/deploy/runner/record → the journal row ({ id, status, via: 'terminal', … , already? }). */
|
|
89
|
+
export async function recordDeploy({ server, token, body, fetchImpl = fetch, userAgent = 'consilium-devops-runner record', timeoutMs = 30_000 }) {
|
|
90
|
+
if (!token) throw new DevopsMcpError('token_missing', 'no runner token (CONSILIUM_RUNNER_TOKEN or "tokenFile" in the runner config)');
|
|
91
|
+
const base = String(server ?? '').replace(/\/+$/, '');
|
|
92
|
+
if (!/^https?:\/\//.test(base)) throw new DevopsMcpError('bad_argument', 'no server URL (--server, KONSILIUM_API_URL or "server" in the runner config)');
|
|
93
|
+
let r;
|
|
94
|
+
try {
|
|
95
|
+
r = await fetchImpl(`${base}/api/deploy/runner/record`, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json', 'user-agent': userAgent },
|
|
98
|
+
body: JSON.stringify(body),
|
|
99
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
100
|
+
});
|
|
101
|
+
} catch (e) {
|
|
102
|
+
throw new DevopsMcpError('network_unavailable', `record: ${e?.cause?.code ?? e?.name ?? 'network error'}`, 0);
|
|
103
|
+
}
|
|
104
|
+
const text = await r.text();
|
|
105
|
+
let json = null;
|
|
106
|
+
try {
|
|
107
|
+
json = JSON.parse(text);
|
|
108
|
+
} catch {
|
|
109
|
+
/* not JSON */
|
|
110
|
+
}
|
|
111
|
+
if (!r.ok) {
|
|
112
|
+
const code = r.status === 401 ? 'bad_runner_token' : r.status === 404 ? 'not_supported' : json?.error?.code ?? `http_${r.status}`;
|
|
113
|
+
const hint = r.status === 404 ? ' (the server is older than OPS-AUDIT-435 — deploy it first, then record)' : '';
|
|
114
|
+
throw new DevopsMcpError(code, `record: HTTP ${r.status}${json?.error?.message ? ` — ${json.error.message}` : ''}${hint}`, r.status);
|
|
115
|
+
}
|
|
116
|
+
return json;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** One line for people: «#D97 done (terminal) …». */
|
|
120
|
+
export function formatRecorded(r) {
|
|
121
|
+
return `${r.already ? 'already recorded' : 'recorded'}: #D${r.id} ${r.status} (via ${r.via}) → ${r.target ?? '?'}${r.startedAt ? ` · ${r.startedAt}–${r.finishedAt ?? ''}` : ''}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The whole command: argv → body → POST. Config is optional when CONSILIUM_RUNNER_TOKEN is set.
|
|
126
|
+
* @returns {Promise<{ dryRun: true, server: string, body: object } | { dryRun: false, server: string, row: object }>}
|
|
127
|
+
*/
|
|
128
|
+
export async function runRecord(argv, { env = process.env, fetchImpl = fetch, cwd = process.cwd(), load = loadConfig, find = findConfig } = {}) {
|
|
129
|
+
const o = parseRecordArgs(argv);
|
|
130
|
+
let cfg = null;
|
|
131
|
+
const file = o.config ?? env.CONSILIUM_DEVOPS_RUNNER_CONFIG ?? find(env);
|
|
132
|
+
if (file || !env.CONSILIUM_RUNNER_TOKEN) cfg = load({ file: o.config ?? null, env, strictToken: !o.dryRun });
|
|
133
|
+
const token = env.CONSILIUM_RUNNER_TOKEN?.trim() || cfg?.token || null;
|
|
134
|
+
const server = String(o.server ?? env.KONSILIUM_API_URL ?? cfg?.server ?? DEFAULT_SERVER).replace(/\/+$/, '');
|
|
135
|
+
const repo = o.repo ?? cwd;
|
|
136
|
+
const body = buildRecordBody(o, { gitSha: o.gitSha ? null : gitHead(repo), logTail: o.logFile ? logTailOf(o.logFile) : '' });
|
|
137
|
+
if (o.dryRun) return { dryRun: true, server, tokenPresent: !!token, body };
|
|
138
|
+
const row = await recordDeploy({ server, token, body, fetchImpl });
|
|
139
|
+
return { dryRun: false, server, row };
|
|
140
|
+
}
|