@sentinelconnector/cli 0.0.0-stage → 0.1.1

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.
Files changed (77) hide show
  1. package/LICENSE +11 -0
  2. package/README.md +218 -2
  3. package/dist/api/client.d.ts +63 -0
  4. package/dist/api/client.js +115 -0
  5. package/dist/api/client.js.map +1 -0
  6. package/dist/api/config.d.ts +21 -0
  7. package/dist/api/config.js +62 -0
  8. package/dist/api/config.js.map +1 -0
  9. package/dist/api/errors.d.ts +34 -0
  10. package/dist/api/errors.js +92 -0
  11. package/dist/api/errors.js.map +1 -0
  12. package/dist/api/http.d.ts +24 -0
  13. package/dist/api/http.js +60 -0
  14. package/dist/api/http.js.map +1 -0
  15. package/dist/auth/credentials.d.ts +48 -0
  16. package/dist/auth/credentials.js +144 -0
  17. package/dist/auth/credentials.js.map +1 -0
  18. package/dist/auth/deviceFlow.d.ts +52 -0
  19. package/dist/auth/deviceFlow.js +106 -0
  20. package/dist/auth/deviceFlow.js.map +1 -0
  21. package/dist/auth/lock.d.ts +2 -0
  22. package/dist/auth/lock.js +86 -0
  23. package/dist/auth/lock.js.map +1 -0
  24. package/dist/auth/store.d.ts +87 -0
  25. package/dist/auth/store.js +281 -0
  26. package/dist/auth/store.js.map +1 -0
  27. package/dist/bin.d.ts +2 -0
  28. package/dist/bin.js +8 -0
  29. package/dist/bin.js.map +1 -0
  30. package/dist/cli.d.ts +11 -0
  31. package/dist/cli.js +111 -0
  32. package/dist/cli.js.map +1 -0
  33. package/dist/commands/mergeChecks.d.ts +9 -0
  34. package/dist/commands/mergeChecks.js +57 -0
  35. package/dist/commands/mergeChecks.js.map +1 -0
  36. package/dist/commands/routes.d.ts +21 -0
  37. package/dist/commands/routes.js +306 -0
  38. package/dist/commands/routes.js.map +1 -0
  39. package/dist/commands/session.d.ts +44 -0
  40. package/dist/commands/session.js +137 -0
  41. package/dist/commands/session.js.map +1 -0
  42. package/dist/context.d.ts +31 -0
  43. package/dist/context.js +42 -0
  44. package/dist/context.js.map +1 -0
  45. package/dist/journeys/mergeChecks.d.ts +70 -0
  46. package/dist/journeys/mergeChecks.js +127 -0
  47. package/dist/journeys/mergeChecks.js.map +1 -0
  48. package/dist/mcp/main.d.ts +13 -0
  49. package/dist/mcp/main.js +39 -0
  50. package/dist/mcp/main.js.map +1 -0
  51. package/dist/mcp/server.d.ts +181 -0
  52. package/dist/mcp/server.js +282 -0
  53. package/dist/mcp/server.js.map +1 -0
  54. package/dist/mcp/untrusted.d.ts +38 -0
  55. package/dist/mcp/untrusted.js +125 -0
  56. package/dist/mcp/untrusted.js.map +1 -0
  57. package/dist/mcp.d.ts +2 -0
  58. package/dist/mcp.js +7 -0
  59. package/dist/mcp.js.map +1 -0
  60. package/dist/mfa.d.ts +12 -0
  61. package/dist/mfa.js +29 -0
  62. package/dist/mfa.js.map +1 -0
  63. package/dist/prompt.d.ts +4 -0
  64. package/dist/prompt.js +54 -0
  65. package/dist/prompt.js.map +1 -0
  66. package/dist/routes/call.d.ts +26 -0
  67. package/dist/routes/call.js +120 -0
  68. package/dist/routes/call.js.map +1 -0
  69. package/dist/routes/catalogue.d.ts +47 -0
  70. package/dist/routes/catalogue.js +69 -0
  71. package/dist/routes/catalogue.js.map +1 -0
  72. package/dist/routes/routes.json +11367 -0
  73. package/dist/skill.d.ts +13 -0
  74. package/dist/skill.js +61 -0
  75. package/dist/skill.js.map +1 -0
  76. package/package.json +40 -4
  77. package/skills/sentinel/SKILL.md +150 -0
@@ -0,0 +1,281 @@
1
+ /**
2
+ * Where a CLI session is kept: the OS keychain (macOS Keychain, Windows
3
+ * Credential Manager, libsecret) through @napi-rs/keyring, or, where none
4
+ * works, an AES-256-GCM encrypted file whose key comes from a passphrase.
5
+ * Never a plain config file. Entries are keyed by API URL, so a UAT session
6
+ * is never sent to production.
7
+ *
8
+ * SENTINEL_CREDENTIAL_STORE picks one: `keychain`, `file` or `memory` (tests).
9
+ */
10
+ import { createCipheriv, createDecipheriv, randomBytes, scrypt } from 'node:crypto';
11
+ import { chmod, mkdir, open, readFile, rename, rm, stat } from 'node:fs/promises';
12
+ import { join } from 'node:path';
13
+ import { configDir } from '../api/config.js';
14
+ import { SentinelError } from '../api/errors.js';
15
+ import { askHidden, isInteractive } from '../prompt.js';
16
+ import { withLock } from './lock.js';
17
+ export const STORE_ENV = 'SENTINEL_CREDENTIAL_STORE';
18
+ export const PASSPHRASE_ENV = 'SENTINEL_CREDENTIALS_PASSPHRASE';
19
+ // Not the admin CLI's service name: the two never read each other's sign-ins.
20
+ const SERVICE = 'sentinel';
21
+ /**
22
+ * Only a customer sign-in counts: an admin CLI session (`snt_cli_`) that
23
+ * shares a configured folder or passphrase is never read as one.
24
+ */
25
+ function customerSession(value) {
26
+ return value &&
27
+ value.version === 1 &&
28
+ typeof value.refreshToken === 'string' &&
29
+ value.refreshToken.startsWith('snt_cur_') &&
30
+ typeof value.accessToken === 'string' &&
31
+ value.accessToken.startsWith('snt_cua_')
32
+ ? value
33
+ : undefined;
34
+ }
35
+ function parse(text) {
36
+ if (!text)
37
+ return undefined;
38
+ try {
39
+ const value = JSON.parse(text);
40
+ return customerSession(value);
41
+ }
42
+ catch {
43
+ return undefined;
44
+ }
45
+ }
46
+ export class MemoryStore {
47
+ kind = 'memory';
48
+ entries = new Map();
49
+ async get(apiUrl) {
50
+ return this.entries.get(apiUrl);
51
+ }
52
+ async set(session) {
53
+ this.entries.set(session.apiUrl, session);
54
+ }
55
+ async delete(apiUrl) {
56
+ this.entries.delete(apiUrl);
57
+ }
58
+ }
59
+ // On Linux only the Secret Service persists: the kernel keyring, the
60
+ // library's own fallback, loses everything at reboot.
61
+ const ENTRY_OPTIONS = { linux: { store: 'secret-service' } };
62
+ export class KeychainStore {
63
+ Entry;
64
+ kind = 'keychain';
65
+ constructor(Entry) {
66
+ this.Entry = Entry;
67
+ }
68
+ entry(apiUrl) {
69
+ return new this.Entry(SERVICE, apiUrl, ENTRY_OPTIONS);
70
+ }
71
+ async get(apiUrl) {
72
+ return parse(this.entry(apiUrl).getPassword());
73
+ }
74
+ async set(session) {
75
+ try {
76
+ this.entry(session.apiUrl).setPassword(JSON.stringify(session));
77
+ }
78
+ catch {
79
+ throw new SentinelError('Could not save the session in the OS keychain. Is it locked?', 4);
80
+ }
81
+ }
82
+ async delete(apiUrl) {
83
+ try {
84
+ this.entry(apiUrl).deletePassword();
85
+ }
86
+ catch {
87
+ // Nothing stored.
88
+ }
89
+ }
90
+ }
91
+ /** Load the keychain and prove it can store and read a value, or undefined. */
92
+ export async function loadKeychain() {
93
+ try {
94
+ const { Entry } = (await import('@napi-rs/keyring'));
95
+ const probe = new Entry(SERVICE, '__probe__', ENTRY_OPTIONS);
96
+ const value = randomBytes(8).toString('hex');
97
+ probe.setPassword(value);
98
+ const read = probe.getPassword();
99
+ probe.deletePassword();
100
+ return read === value ? new KeychainStore(Entry) : undefined;
101
+ }
102
+ catch {
103
+ return undefined;
104
+ }
105
+ }
106
+ // OWASP's scrypt minimum: N=2^17, r=8, p=1 (128 MiB).
107
+ const SCRYPT = { N: 1 << 17, r: 8, p: 1, maxmem: 256 * 1024 * 1024 };
108
+ const TAG_LENGTH = 16;
109
+ const keys = new Map();
110
+ /** The file key; derived off the event loop and kept per passphrase and salt. */
111
+ async function deriveKey(passphrase, salt) {
112
+ const id = `${salt.toString('base64')}:${passphrase}`;
113
+ const known = keys.get(id);
114
+ if (known)
115
+ return known;
116
+ const key = await new Promise((resolve, reject) => scrypt(passphrase.normalize('NFKC'), salt, 32, SCRYPT, (error, derived) => error ? reject(error) : resolve(derived)));
117
+ keys.set(id, key);
118
+ return key;
119
+ }
120
+ export async function seal(entries, passphrase, salt = randomBytes(16)) {
121
+ const iv = randomBytes(12);
122
+ const cipher = createCipheriv('aes-256-gcm', await deriveKey(passphrase, salt), iv, {
123
+ authTagLength: TAG_LENGTH,
124
+ });
125
+ const data = Buffer.concat([cipher.update(JSON.stringify(entries), 'utf8'), cipher.final()]);
126
+ return {
127
+ version: 1,
128
+ kdf: 'scrypt',
129
+ salt: salt.toString('base64'),
130
+ iv: iv.toString('base64'),
131
+ tag: cipher.getAuthTag().toString('base64'),
132
+ data: data.toString('base64'),
133
+ };
134
+ }
135
+ export async function unseal(sealed, passphrase) {
136
+ if (![sealed?.salt, sealed?.iv, sealed?.tag, sealed?.data].every((field) => typeof field === 'string')) {
137
+ throw new SentinelError('The credentials file is damaged; delete it and sign in again.', 4);
138
+ }
139
+ const key = await deriveKey(passphrase, Buffer.from(sealed.salt, 'base64'));
140
+ try {
141
+ const tag = Buffer.from(sealed.tag, 'base64');
142
+ if (tag.length !== TAG_LENGTH)
143
+ throw new Error('bad tag');
144
+ const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(sealed.iv, 'base64'), {
145
+ authTagLength: TAG_LENGTH,
146
+ });
147
+ decipher.setAuthTag(tag);
148
+ const text = Buffer.concat([
149
+ decipher.update(Buffer.from(sealed.data, 'base64')),
150
+ decipher.final(),
151
+ ]).toString('utf8');
152
+ return JSON.parse(text);
153
+ }
154
+ catch {
155
+ throw new SentinelError('Could not decrypt the credentials file: wrong passphrase?', 4);
156
+ }
157
+ }
158
+ export function defaultPassphrase(env = process.env) {
159
+ let cached;
160
+ return async (options = {}) => {
161
+ if (cached)
162
+ return cached;
163
+ const value = env[PASSPHRASE_ENV];
164
+ if (value)
165
+ return (cached = value);
166
+ if (!isInteractive()) {
167
+ throw new SentinelError(`No OS keychain is available. Set ${PASSPHRASE_ENV} for the encrypted credentials file, ` +
168
+ 'or use SENTINEL_TOKEN.', 4);
169
+ }
170
+ const typed = await askHidden('Passphrase for the Sentinel credentials file: ');
171
+ if (!typed)
172
+ throw new SentinelError('A passphrase is needed.', 4);
173
+ if (options.creating && (await askHidden('Type it again: ')) !== typed) {
174
+ throw new SentinelError('The passphrases did not match.', 4);
175
+ }
176
+ return (cached = typed);
177
+ };
178
+ }
179
+ /** An encrypted file, mode 0600 in a 0700 directory. */
180
+ export class EncryptedFileStore {
181
+ dir;
182
+ passphrase;
183
+ kind = 'file';
184
+ path;
185
+ constructor(dir, passphrase) {
186
+ this.dir = dir;
187
+ this.passphrase = passphrase;
188
+ // Not the admin CLI's file name, should both be pointed at one folder.
189
+ this.path = join(dir, 'customer-credentials.enc.json');
190
+ }
191
+ async readAll() {
192
+ let text;
193
+ try {
194
+ text = await readFile(this.path, 'utf8');
195
+ }
196
+ catch (error) {
197
+ if (error.code === 'ENOENT')
198
+ return {};
199
+ throw new SentinelError(`Cannot read ${this.path}.`, 4);
200
+ }
201
+ const info = await stat(this.path);
202
+ if (process.platform !== 'win32' && (info.mode & 0o077) !== 0) {
203
+ throw new SentinelError(`${this.path} is readable by other users; fix with chmod 600.`, 4);
204
+ }
205
+ let sealed;
206
+ try {
207
+ sealed = JSON.parse(text);
208
+ }
209
+ catch {
210
+ throw new SentinelError(`${this.path} is damaged; delete it and sign in again.`, 4);
211
+ }
212
+ return unseal(sealed, await this.passphrase());
213
+ }
214
+ async writeAll(entries) {
215
+ if (Object.keys(entries).length === 0) {
216
+ await rm(this.path, { force: true });
217
+ return;
218
+ }
219
+ await mkdir(this.dir, { recursive: true, mode: 0o700 });
220
+ const creating = !(await stat(this.path).catch(() => undefined));
221
+ const sealed = await seal(entries, await this.passphrase({ creating }));
222
+ const temp = `${this.path}.${randomBytes(6).toString('hex')}.tmp`;
223
+ try {
224
+ const handle = await open(temp, 'wx', 0o600);
225
+ try {
226
+ await handle.writeFile(JSON.stringify(sealed));
227
+ }
228
+ finally {
229
+ await handle.close();
230
+ }
231
+ await chmod(temp, 0o600);
232
+ await rename(temp, this.path);
233
+ }
234
+ catch (error) {
235
+ await rm(temp, { force: true });
236
+ throw error;
237
+ }
238
+ }
239
+ /** Read, change and write the whole file under one lock for all commands. */
240
+ change(update) {
241
+ return withLock(this.dir, 'customer-credentials-file', async () => {
242
+ const entries = await this.readAll();
243
+ if (update(entries))
244
+ await this.writeAll(entries);
245
+ });
246
+ }
247
+ async get(apiUrl) {
248
+ return customerSession((await this.readAll())[apiUrl]);
249
+ }
250
+ async set(session) {
251
+ await this.change((entries) => {
252
+ entries[session.apiUrl] = session;
253
+ return true;
254
+ });
255
+ }
256
+ async delete(apiUrl) {
257
+ await this.change((entries) => {
258
+ if (!(apiUrl in entries))
259
+ return false;
260
+ delete entries[apiUrl];
261
+ return true;
262
+ });
263
+ }
264
+ }
265
+ let shared;
266
+ /** The store this process uses: the keychain when it works, else the file. */
267
+ export async function openStore(env = process.env) {
268
+ const choice = env[STORE_ENV]?.toLowerCase();
269
+ if (choice === 'memory')
270
+ return (shared ??= new MemoryStore());
271
+ const file = () => new EncryptedFileStore(configDir(env), defaultPassphrase(env));
272
+ if (choice === 'file')
273
+ return file();
274
+ const keychain = await loadKeychain();
275
+ if (keychain)
276
+ return keychain;
277
+ if (choice === 'keychain')
278
+ throw new SentinelError('The OS keychain is not available here.', 4);
279
+ return file();
280
+ }
281
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/auth/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,MAAM,SAAS,GAAG,2BAA2B,CAAC;AACrD,MAAM,CAAC,MAAM,cAAc,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cli.js';
4
+ import { defaultIo } from './context.js';
5
+ import { askHidden } from './prompt.js';
6
+ const io = defaultIo();
7
+ process.exitCode = await main(process.argv.slice(2), { env: process.env, io: io.ask ? { ...io, askHidden } : io });
8
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,8BAA8B;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;AACvB,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * sentinel: Sentinel from the terminal, for customers (epic
3
+ * truecms/sentinel#1618). Secrets never come from arguments: sign in with
4
+ * `login`, or set SENTINEL_TOKEN to a personal API token. SENTINEL_API_URL
5
+ * picks another environment than production.
6
+ */
7
+ import { Command } from 'commander';
8
+ import { type Context } from './context.js';
9
+ export declare function buildProgram(context: Context): Command;
10
+ export declare function exitCodeFor(error: unknown): number;
11
+ export declare function main(argv: string[], context?: Context): Promise<number>;
package/dist/cli.js ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * sentinel: Sentinel from the terminal, for customers (epic
3
+ * truecms/sentinel#1618). Secrets never come from arguments: sign in with
4
+ * `login`, or set SENTINEL_TOKEN to a personal API token. SENTINEL_API_URL
5
+ * picks another environment than production.
6
+ */
7
+ import { Command, CommanderError, Option } from 'commander';
8
+ import open from 'open';
9
+ import { printable, redact, SentinelError } from './api/errors.js';
10
+ import { NetworkError } from './api/http.js';
11
+ import { openStore } from './auth/store.js';
12
+ import { addMergeChecksCommands } from './commands/mergeChecks.js';
13
+ import { addApiCommand, addRouteCommands, addRoutesCommand } from './commands/routes.js';
14
+ import { canOpenBrowser, login, logout, rememberEmail } from './commands/session.js';
15
+ import { apiUrlOf, clientOf, defaultIo } from './context.js';
16
+ import { addSkillCommands } from './skill.js';
17
+ const EXIT_HELP = `
18
+ Exit codes: 0 done, 1 error, 2 usage, 3 network, 4 not signed in or the
19
+ sign-in stopped working, 5 wrong environment, 10 refused (by the server or a
20
+ declined prompt), 13 a change got no answer and may have been made.`;
21
+ export function buildProgram(context) {
22
+ const program = new Command()
23
+ .name('sentinel')
24
+ .description('Sentinel from the terminal: your organisations, sites, findings, reports and Patching.')
25
+ // SENTINEL_API_URL is read through the context when the option is absent.
26
+ .addOption(new Option('--api-url <url>', 'Sentinel API URL (default production, or SENTINEL_API_URL)'))
27
+ .addHelpText('after', EXIT_HELP)
28
+ .showHelpAfterError()
29
+ .exitOverride();
30
+ const apiUrl = () => apiUrlOf(context, program.opts().apiUrl);
31
+ program
32
+ .command('login')
33
+ .description('Sign in through the browser (works over SSH: open the link anywhere)')
34
+ .option('--write', 'Ask to allow changes, not only reads')
35
+ .option('--no-browser', 'Only print the link and code')
36
+ .action(async (options) => {
37
+ const url = apiUrl();
38
+ const store = await openStore(context.env);
39
+ const controller = new AbortController();
40
+ process.once('SIGINT', () => controller.abort());
41
+ const session = await login({
42
+ apiUrl: url,
43
+ store,
44
+ write: Boolean(options.write),
45
+ browser: options.browser && canOpenBrowser(context.env),
46
+ openUrl: (link) => open(link),
47
+ signal: controller.signal,
48
+ env: context.env,
49
+ log: context.io.err,
50
+ fetch: context.fetch,
51
+ });
52
+ const { me } = await rememberEmail(url, store, { fetch: context.fetch });
53
+ context.io.err(`Signed in to ${printable(session.environment).toUpperCase()} as ${printable(me.user.email)} ` +
54
+ `(${session.scope === 'read write' ? 'reads and changes' : 'reads only'}, kept in the ` +
55
+ `${store.kind === 'keychain' ? 'OS keychain' : 'encrypted credentials file'}). Ends by ${session.sessionExpiresAt}.`);
56
+ });
57
+ program
58
+ .command('logout')
59
+ .description('Sign this CLI out: the server ends the sign-in')
60
+ .action(async () => {
61
+ await logout({ apiUrl: apiUrl(), store: await openStore(context.env), env: context.env, log: context.io.err, fetch: context.fetch });
62
+ });
63
+ program
64
+ .command('whoami')
65
+ .description('Show who you are signed in as, the environment, the credential and its scopes')
66
+ .option('--json', 'As JSON')
67
+ .action(async (options) => {
68
+ const me = await (await clientOf(context, program.opts().apiUrl)).whoami();
69
+ if (options.json)
70
+ return context.io.out(JSON.stringify(me, null, 2));
71
+ const credential = me.credential;
72
+ context.io.out(`${printable(me.user.full_name ?? me.user.email)} <${printable(me.user.email)}>`);
73
+ context.io.out(`Environment: ${printable(me.environment)}`);
74
+ if (credential) {
75
+ const kind = credential.kind === 'cli_session' ? 'CLI sign-in' : 'personal API token';
76
+ context.io.out(`Credential: ${kind} #${credential.id}, scopes ${credential.scopes.join(' ')}, until ${credential.expires_at}`);
77
+ }
78
+ });
79
+ addRoutesCommand(program, context);
80
+ addApiCommand(program, context);
81
+ addSkillCommands(program, context);
82
+ addRouteCommands(program, context);
83
+ const patching = program.commands.find((command) => command.name() === 'patching');
84
+ if (patching)
85
+ addMergeChecksCommands(patching, context);
86
+ return program;
87
+ }
88
+ export function exitCodeFor(error) {
89
+ if (error instanceof CommanderError) {
90
+ return error.code === 'commander.helpDisplayed' || error.code === 'commander.version' ? 0 : 2;
91
+ }
92
+ if (error instanceof SentinelError)
93
+ return error.exitCode;
94
+ return 1;
95
+ }
96
+ export async function main(argv, context = { env: process.env, io: defaultIo() }) {
97
+ const program = buildProgram(context);
98
+ try {
99
+ await program.parseAsync(argv, { from: 'user' });
100
+ return 0;
101
+ }
102
+ catch (error) {
103
+ if (error instanceof CommanderError)
104
+ return exitCodeFor(error);
105
+ const message = error instanceof Error ? error.message : String(error);
106
+ const network = error instanceof NetworkError ? ' Check your connection and SENTINEL_API_URL.' : '';
107
+ context.io.err(`sentinel: ${printable(redact(message))}${network}`);
108
+ return exitCodeFor(error);
109
+ }
110
+ }
111
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAgB,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,SAAS,GAAG;;;oEAGkD,CAAC;AAErE,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE;SAC1B,IAAI,CAAC,UAAU,CAAC;SAChB,WAAW,CAAC,wFAAwF,CAAC;QACtG,0EAA0E;SACzE,SAAS,CAAC,IAAI,MAAM,CAAC,iBAAiB,EAAE,4DAA4D,CAAC,CAAC;SACtG,WAAW,CAAC,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/sentinel#1930).
3
+ * Acknowledging is an organisation administrator's standing authorisation for
4
+ * Autopilot, so it needs a CLI sign-in, the person's typed confirmation and a
5
+ * fresh authenticator code (route policy `mfa`).
6
+ */
7
+ import type { Command } from 'commander';
8
+ import { type Context } from '../context.js';
9
+ export declare function addMergeChecksCommands(patching: Command, context: Context): void;
@@ -0,0 +1,57 @@
1
+ import { SentinelError } from '../api/errors.js';
2
+ import { announceChange, clientOf, dashboardLink } from '../context.js';
3
+ import { acknowledgeMergeChecks, agreementText, describeMergeChecks, readMergeChecks, refusalBeforeAcknowledging, } from '../journeys/mergeChecks.js';
4
+ import { stepUpHeaders } from '../mfa.js';
5
+ export function addMergeChecksCommands(patching, context) {
6
+ const group = patching
7
+ .command('merge-checks')
8
+ .description("The repository's required checks, and the acknowledgement Autopilot needs to follow them");
9
+ group
10
+ .command('show')
11
+ .description('Read the required checks from the Git host now, and whether the acknowledgement is current')
12
+ .argument('<site>', 'The site UUID')
13
+ .option('--json', 'As JSON')
14
+ .action(async (site, options, command) => {
15
+ const client = await clientOf(context, command.optsWithGlobals().apiUrl);
16
+ const answer = await readMergeChecks(client, site);
17
+ if (options.json)
18
+ context.io.out(JSON.stringify(answer, null, 2));
19
+ else
20
+ for (const line of describeMergeChecks(answer))
21
+ context.io.out(line);
22
+ });
23
+ group
24
+ .command('acknowledge')
25
+ .description('Acknowledge what the required checks mean for Autopilot (organisation administrators, authenticator code)')
26
+ .argument('<site>', 'The site UUID')
27
+ .action(async (site, _options, command) => {
28
+ const { io } = context;
29
+ const client = await clientOf(context, command.optsWithGlobals().apiUrl);
30
+ const link = dashboardLink(client, context.env, `/app/sites/${encodeURIComponent(site)}?tab=patching`);
31
+ if (client.credential.kind !== 'cli_session') {
32
+ throw new SentinelError(`Acknowledging needs a person: sign in with \`sentinel login --write\`, or use ${link}.`, 10);
33
+ }
34
+ if (!io.ask)
35
+ throw new SentinelError(`Acknowledging needs a terminal. Or use ${link}.`, 2);
36
+ const seen = await readMergeChecks(client, site);
37
+ for (const line of describeMergeChecks(seen))
38
+ io.err(line);
39
+ const refusal = refusalBeforeAcknowledging(seen);
40
+ if (refusal)
41
+ throw new SentinelError(refusal, 10);
42
+ await announceChange(client, io);
43
+ io.err('');
44
+ io.err(agreementText(seen));
45
+ io.err('If a required check is later removed on the host, or the repository or branch changes, the acknowledgement ' +
46
+ 'stops counting and Autopilot holds until it is given again. A check added later is followed without one.');
47
+ const typed = (await io.ask('Type "acknowledge" to agree: ')).trim().toLowerCase();
48
+ if (typed !== 'acknowledge')
49
+ throw new SentinelError('Nothing was changed.', 10);
50
+ const headers = await stepUpHeaders(client, io.askHidden);
51
+ const answer = await acknowledgeMergeChecks(client, site, seen, headers);
52
+ for (const line of describeMergeChecks(answer))
53
+ io.out(line);
54
+ io.err('An Autopilot run that is paused does not resume by itself: press Resume, or run its resume command.');
55
+ });
56
+ }
57
+ //# sourceMappingURL=mergeChecks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeChecks.js","sourceRoot":"","sources":["../../src/commands/mergeChecks.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAgB,MAAM,eAAe,CAAC;AACtF,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,0BAA0B,GAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,UAAU,sBAAsB,CAAC,QAAiB,EAAE,OAAgB;IACxE,MAAM,KAAK,GAAG,QAAQ;SACnB,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,0FAA0F,CAAC,CAAC;IAE3G,KAAK;SACF,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,4FAA4F,CAAC;SACzG,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;SACnC,MAAM,CAAC,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+ import { Command } from 'commander';
2
+ import { type Context } from '../context.js';
3
+ import { type PlannedCall } from '../routes/call.js';
4
+ export declare function journeyOnly(method: string, path: string): string | undefined;
5
+ /** A body from an argument: refused when it holds a secret, which belongs in a file. */
6
+ export declare function inlineBody(text: string): unknown;
7
+ export declare function output(context: Context, result: unknown, out?: string): Promise<void> | void;
8
+ /** Text safe for a terminal: lines and tabs kept, other control and invisible characters removed. */
9
+ export declare function terminalText(text: string): string;
10
+ /** Run one planned call with the confirmations its policy needs. */
11
+ export declare function runCall(context: Context, call: PlannedCall, options: {
12
+ yes?: boolean;
13
+ out?: string;
14
+ apiUrl?: string;
15
+ }): Promise<void>;
16
+ /** Groups of route commands, added to `program` (an existing group is extended). */
17
+ export declare function addRouteCommands(program: Command, context: Context): void;
18
+ /** `sentinel routes [words…]`: find the command for a job. */
19
+ export declare function addRoutesCommand(program: Command, context: Context): void;
20
+ /** `sentinel api <method> <path>`: any customer route, by its path. */
21
+ export declare function addApiCommand(program: Command, context: Context): void;