@jacebenson/jsn 5.5.1-dev.167.1 → 5.5.1-dev.168.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacebenson/jsn",
3
- "version": "5.5.1-dev.167.1",
3
+ "version": "5.5.1-dev.168.1",
4
4
  "description": "A command-line interface for ServiceNow that follows the Unix philosophy: simple, composable, and scriptable.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -601,12 +601,12 @@ export function buildCLI() {
601
601
  }
602
602
  process.exit(0);
603
603
  }
604
- // First-run orientation (issue #387) sits above the unchanged help.
604
+ // First-run orientation replaces the catalog only for a fresh human terminal.
605
605
  // maybeShowWelcome decides for itself: human terminal, no machine
606
606
  // format, no configured profile, and not shown before.
607
607
  const config = loadConfig(formatArgv);
608
- maybeShowWelcome({ argv: formatArgv, requestedFormat, cfg: config });
609
- process.stdout.write(renderHelp(config, visibleCommandRegistry(cliInstance.commandRegistry(), config, formatArgv)) + '\n');
608
+ const welcome = maybeShowWelcome({ argv: formatArgv, requestedFormat, cfg: config });
609
+ if (!welcome) process.stdout.write(renderHelp(config, visibleCommandRegistry(cliInstance.commandRegistry(), config, formatArgv)) + '\n');
610
610
  process.exit(0);
611
611
  }
612
612
  // Every other failure here (unknown command, missing required argument,
@@ -322,19 +322,21 @@ export async function loginWizard(app, argv = {}) {
322
322
  const request = { ...argv, profile: undefined, instance, name: name.trim() };
323
323
  if (method === 'browser') request.browser = true;
324
324
  if (method === 'oauth') request.oauth = true;
325
+ const settings = await chooseConnectionPreferences(app.config, profileSettingValues(argv), { confirm });
325
326
  if (method === 'basic') {
326
327
  request.basic = true;
327
328
  const username = await input({ message: 'Username:', validate: value => value.trim() ? true : 'A username is required' });
328
329
  request._basicCredentials = { username: username.trim(), password: await password({ message: 'Password:' }) };
329
330
  }
330
- const settings = await chooseConnectionPreferences(app.config, profileSettingValues(argv), { confirm });
331
331
  request['read-only'] = settings.read_only;
332
332
  request['skip-confirmations'] = settings.skip_confirmations;
333
333
  request['include-counts'] = settings.include_counts;
334
- request.makeDefault = argv.makeDefault ?? await confirm({
335
- message: 'Use this profile by default?', default: !app.config.defaultProfile,
336
- });
334
+ request.makeDefault = argv.makeDefault ?? (Object.keys(app.config.profiles || {}).length === 0 && !app.config.defaultProfile
335
+ ? true : await confirm({ message: 'Use this profile by default?', default: !app.config.defaultProfile }));
337
336
  const result = await loginProfile(request, app);
337
+ if (result.authenticated) {
338
+ process.stdout.write(`Connection preset: ${settings.read_only ? 'read-only' : 'writes allowed'} · deletes ${settings.skip_confirmations ? 'without confirmation' : 'ask first'} · totals ${settings.include_counts ? 'on' : 'off'}\nChange with: jsn auth modify ${result.profile} --read-only\n`);
339
+ }
338
340
  return { instanceURL: instance, profileName: result.profile, loggedIn: result.authenticated };
339
341
  }
340
342
 
@@ -1,4 +1,5 @@
1
- import { configureGlobalDefaults, configureDocumentation } from '../setup-preferences.js';
1
+ import { configureGlobalDefaults, configureDocumentation, connectionPreferences } from '../setup-preferences.js';
2
+ import { saveConfig } from '../config.js';
2
3
  import { select } from '../prompts.js';
3
4
  import { loginWizard, loginProfile, showAuthStatus, switchProfile, modifyProfile, logoutProfile, removeConnection } from './auth.js';
4
5
  import { errUsageHint } from '../errors.js';
@@ -37,6 +38,7 @@ const setupHelp = () => [
37
38
  'Use --no-read-only, --no-confirm-deletes, --no-include-counts or --no-make-default for the opposite value.',
38
39
  'Use --json for structured output. Explicit flags avoid implicit pickers; ambiguous targets return an error.',
39
40
  'Discover all options with jsn auth <command> --help.',
41
+ 'Configure settings directly: jsn setup --configure-defaults or jsn setup --configure-docs.',
40
42
  ].join('\n');
41
43
 
42
44
  /** The setup hub prompt; q and Escape resolve with no selected action. */
@@ -119,21 +121,31 @@ export function setupCmd(wrap) {
119
121
  return {
120
122
  command: 'setup',
121
123
  describe: 'Set up JSN defaults and manage ServiceNow connections (interactive)',
122
- builder: y => y.option('docs-source', { type: 'string', choices: ['snapshot', 'github', 'skip'], describe: 'Install optional documentation directly without the authentication wizard' }).epilogue(setupHelp()),
124
+ builder: y => y.option('docs-source', { type: 'string', choices: ['snapshot', 'github', 'skip'], describe: 'Install optional documentation directly without the authentication wizard' })
125
+ .option('configure-defaults', { type: 'boolean', describe: 'Configure defaults for future connections without the hub' })
126
+ .option('configure-docs', { type: 'boolean', describe: 'Configure documentation without the hub' }).epilogue(setupHelp()),
123
127
  handler: wrap(async (argv, app) => {
124
128
  if (argv['docs-source']) {
125
129
  const { installDocumentation } = await import('./docs/install.js');
126
130
  app.ok(await installDocumentation(argv['docs-source']));
127
131
  return;
128
132
  }
133
+ if (argv['configure-defaults'] || argv['configure-docs']) {
134
+ if (argv['configure-defaults']) await configureGlobalDefaults(app.config, { documentation: false });
135
+ if (argv['configure-docs']) await configureDocumentation(app.config);
136
+ app.ok({ settings: true }, { summary: 'Settings saved; existing connections unchanged' });
137
+ return;
138
+ }
129
139
  const { canUsePicker } = await import('../helpers.js');
130
140
  if (!app.isInteractive() || !canUsePicker(app, argv)) {
131
141
  throw errUsageHint('"jsn setup" is interactive. Use explicit auth commands instead.', setupHelp());
132
142
  }
133
143
  const profileNames = Object.keys(app.config.profiles || {});
134
144
  const firstSetup = !app.config.connectionDefaults;
135
- if (firstSetup) await configureGlobalDefaults(app.config);
136
- else if (!app.config.docs) await configureDocumentation(app.config);
145
+ if (firstSetup) {
146
+ app.config.connectionDefaults = connectionPreferences(app.config);
147
+ await saveConfig(app.config);
148
+ }
137
149
  if (profileNames.length === 0 && firstSetup) {
138
150
  const result = await loginWizard(app, argv);
139
151
  await showAuthStatus({ ...argv, profile: result.profileName }, app);
@@ -26,9 +26,9 @@ export async function askConnectionPreferences(defaults, prompts = { confirm })
26
26
 
27
27
  export async function chooseConnectionPreferences(config, flags = {}, prompts = { confirm }) {
28
28
  const defaults = connectionPreferences(config, {}, flags);
29
- const summary = `Read-only: ${defaults.read_only ? 'yes' : 'no'} · Delete confirmations: ${defaults.skip_confirmations ? 'off' : 'on'} · Result totals: ${defaults.include_counts ? 'on' : 'off'}`;
30
- if (await prompts.confirm({ message: `${summary}\nUse these defaults for this connection?`, default: true })) return defaults;
31
- return askConnectionPreferences(defaults, prompts);
29
+ const summary = `${defaults.read_only ? 'read-only' : 'writes allowed'} · delete confirmations ${defaults.skip_confirmations ? 'off' : 'on'} · result totals ${defaults.include_counts ? 'on' : 'off'}`;
30
+ if (await prompts.confirm({ message: `Accept defaults? ${summary}`, default: true })) return defaults;
31
+ return connectionPreferences(config, await askConnectionPreferences(defaults, prompts), flags);
32
32
  }
33
33
 
34
34
  export async function configureDocumentation(config, prompts = { input, confirm }) {
package/src/welcome.js CHANGED
@@ -1,8 +1,7 @@
1
1
  // First-run welcome (issue #387).
2
2
  //
3
- // A brand-new install that runs bare `jsn` gets grouped help, which assumes
4
- // the reader already knows what to do with it. This adds a short orientation
5
- // above that help, exactly once, only when a human is reading it.
3
+ // A brand-new install gets a compact front door instead of the command catalog,
4
+ // exactly once, only when a human is reading it.
6
5
  //
7
6
  // Invariants (see docs/DECISIONS.md):
8
7
  // - at most once: a marker file in the XDG config dir records that the note
@@ -10,7 +9,7 @@
10
9
  // both print it;
11
10
  // - human terminal only: no --json/--quiet/--csv/--markdown/--get, no piped
12
11
  // output, no agent/CI environments;
13
- // - never instead of help: the grouped help below it is unchanged;
12
+ // - explicit help stays comprehensive; the first-run front door stands alone;
14
13
  // - never an instance or auth operation: the note only points at local and
15
14
  // interactive commands, so it cannot block setup or require credentials;
16
15
  // - nothing on this path reaches the network, prompts, or reads an instance;
@@ -39,21 +38,10 @@ const MIN_WIDTH = 24;
39
38
 
40
39
  const HUMAN_FORMATS = new Set(['', 'auto', 'styled']);
41
40
 
42
- /**
43
- * What a first run actually needs next. Every command here exists, is visible
44
- * to a profile-less install, and works without an instance:
45
- * - `jsn setup` opens the interactive add-connection wizard (and defaults);
46
- * - `jsn auth login <instance>` adds one connection without the wizard;
47
- * - `jsn --help` is the grouped command list this note sits above;
48
- * - `jsn docs search` queries ServiceNow documentation, not an instance;
49
- * - `jsn skill install` writes the bundled agent skill from local files.
50
- */
41
+ /** One obvious next action, plus secondary discovery; no command catalog. */
51
42
  const STEPS = [
52
- { command: 'jsn setup', detail: 'first connection + defaults, interactive' },
53
- { command: 'jsn auth login <instance>', detail: 'one connection, scriptable, no wizard' },
43
+ { command: 'jsn setup', detail: 'connect to ServiceNow' },
54
44
  { command: 'jsn --help', detail: 'every command and flag' },
55
- { command: 'jsn docs search <query>', detail: 'search ServiceNow documentation' },
56
- { command: 'jsn skill install', detail: 'install the jsn skill for your AI agent' },
57
45
  ];
58
46
 
59
47
  /**
@@ -145,8 +133,8 @@ function renderSteps(width) {
145
133
  }
146
134
 
147
135
  /**
148
- * The orientation text. Kept short: it must fit above the grouped help without
149
- * pushing it off the first screen, and it must stay inside 12 lines at 80
136
+ * The orientation text. Kept short: it stands alone on the first screen
137
+ * instead of the command catalog, and stays inside 12 lines at 80
150
138
  * columns.
151
139
  *
152
140
  * Everything shown is derived from local state: the version comes from the
@@ -177,11 +165,8 @@ export function welcomeLines({
177
165
  ...wrapText(title, width),
178
166
  ...wrapText(configLabel, width),
179
167
  '',
180
- ' Next steps',
168
+ ' Get started',
181
169
  ...renderSteps(width),
182
- '',
183
- ...wrapText('Nothing above needs an instance. jsn asks for credentials only when needed.', width),
184
- ...wrapText('Prints once. Hide it with JSN_NO_WELCOME=1. Update with jsn upgrade.', width),
185
170
  ];
186
171
  }
187
172
 
@@ -304,7 +289,7 @@ export function markWelcomeSeen(configDir = globalConfigDir()) {
304
289
  }
305
290
 
306
291
  /**
307
- * Show the welcome (above the caller's own help output) when this is a first
292
+ * Show the standalone welcome instead of the catalog when this is a first
308
293
  * run, then record it. Returns the text that was shown, or '' when nothing was.
309
294
  *
310
295
  * The marker is claimed before anything is printed, so an interrupted run