@jacebenson/jsn 5.5.1-dev.167.1 → 5.5.1-dev.169.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.169.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
@@ -10,7 +10,7 @@ import { App } from './app.js';
10
10
  import { resolveSession, applySession } from './session.js';
11
11
  import { renderHelp, renderTips } from './help.js';
12
12
  import { isMutationCommand, refreshMutationCommands } from './mutations.js';
13
- import { maybeShowWelcome } from './welcome.js';
13
+ import { maybeShowHome } from './welcome.js';
14
14
  import { skippedUpdatesCmd } from './commands/skipped-updates.js';
15
15
  import { isLocalPreview, noInstanceCommands, dailyCheckSkipCommands, contextHeaderSkipCommands } from './capabilities.js';
16
16
  import { guardExit, exitWithError, AppError, CodeUsage } from './errors.js';
@@ -601,12 +601,11 @@ export function buildCLI() {
601
601
  }
602
602
  process.exit(0);
603
603
  }
604
- // First-run orientation (issue #387) sits above the unchanged help.
605
- // maybeShowWelcome decides for itself: human terminal, no machine
606
- // format, no configured profile, and not shown before.
604
+ // Human terminals always get the compact local home. Machine and
605
+ // non-interactive discovery retain their existing reference output.
607
606
  const config = loadConfig(formatArgv);
608
- maybeShowWelcome({ argv: formatArgv, requestedFormat, cfg: config });
609
- process.stdout.write(renderHelp(config, visibleCommandRegistry(cliInstance.commandRegistry(), config, formatArgv)) + '\n');
607
+ const welcome = maybeShowHome({ argv: formatArgv, requestedFormat, cfg: config });
608
+ if (!welcome) process.stdout.write(renderHelp(config, visibleCommandRegistry(cliInstance.commandRegistry(), config, formatArgv)) + '\n');
610
609
  process.exit(0);
611
610
  }
612
611
  // Every other failure here (unknown command, missing required argument,
@@ -299,7 +299,7 @@ async function readBrowserSessionFile(file) {
299
299
  }
300
300
 
301
301
  /** Collect human answers, then call the same login operation as auth login. */
302
- export async function loginWizard(app, argv = {}) {
302
+ export async function loginWizard(app, argv = {}, { concise = false } = {}) {
303
303
  const { input, select, confirm, password } = await import('../prompts.js');
304
304
  const explicitInstance = resolveWizardInstance(app, argv);
305
305
  const instance = resolveInstanceArg(explicitInstance || await input({
@@ -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
- });
337
- const result = await loginProfile(request, app);
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 }));
336
+ const result = await loginProfile(request, app, { concise });
337
+ if (result.authenticated && !concise) {
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
 
@@ -550,7 +552,7 @@ function canLogoutBareProfile(app, instance, target, explicitlySelected) {
550
552
  return sameInstance.length <= 1;
551
553
  }
552
554
 
553
- export async function loginProfile(argv, app) {
555
+ export async function loginProfile(argv, app, { concise = false } = {}) {
554
556
  argv = profileSettingValues(argv);
555
557
  validateLoginSelectors(argv);
556
558
  if (argv.name !== undefined) {
@@ -808,7 +810,12 @@ Find your instance URL in your browser's address bar when logged into ServiceNow
808
810
  description: 'Set these at login; --skip-confirmations disables delete prompts',
809
811
  },
810
812
  ] : [];
811
- app.ok(result, { summary, breadcrumbs });
813
+ if (concise && canUsePicker(app, argv)) {
814
+ const next = setDefault ? 'jsn incidents list' : `jsn --profile ${quoteShellArg(profileName)} incidents list`;
815
+ app.ok(result, { summary: `${summary}\nNext: ${next}`, breadcrumbs: [] });
816
+ } else {
817
+ app.ok(result, { summary, breadcrumbs });
818
+ }
812
819
  return result;
813
820
  }
814
821
 
@@ -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. */
@@ -87,7 +89,7 @@ export async function authHubMenu({ promptFn = authHubPrompt, input, output, has
87
89
  */
88
90
  export async function dispatchSetupAction(app, argv, action) {
89
91
  if (action === 'add') {
90
- return loginWizard(app, argv);
92
+ return loginWizard(app, argv, { concise: true });
91
93
  } else if (action === 'login') {
92
94
  return loginProfile(argv, app);
93
95
  } else if (action === 'status') {
@@ -119,30 +121,39 @@ 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
- const result = await loginWizard(app, argv);
139
- await showAuthStatus({ ...argv, profile: result.profileName }, app);
150
+ await loginWizard(app, argv, { concise: true });
140
151
  return;
141
152
  }
142
153
  const action = await authHubMenu({ hasProfiles: profileNames.length > 0 });
143
154
  if (action === undefined) return;
144
155
  const result = await dispatchSetupAction(app, argv, action);
145
- if (!['status', 'advanced'].includes(action)) await showAuthStatus({ ...argv, profile: result?.profile || result?.profileName }, app);
156
+ if (!['add', 'status', 'advanced'].includes(action)) await showAuthStatus({ ...argv, profile: result?.profile || result?.profileName }, app);
146
157
  }),
147
158
  };
148
159
  }
@@ -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
  /**
@@ -128,12 +116,12 @@ function configLabels(env, configDir) {
128
116
  * @param {number} width
129
117
  * @returns {string[]}
130
118
  */
131
- function renderSteps(width) {
132
- const commandWidth = Math.max(...STEPS.map((step) => step.command.length));
119
+ function renderSteps(width, steps = STEPS) {
120
+ const commandWidth = Math.max(...steps.map((step) => step.command.length));
133
121
  const alignedColumn = 4 + commandWidth + 2;
134
- const oneLine = STEPS.every((step) => alignedColumn + step.detail.length <= width);
122
+ const oneLine = steps.every((step) => alignedColumn + step.detail.length <= width);
135
123
  const lines = [];
136
- for (const step of STEPS) {
124
+ for (const step of steps) {
137
125
  if (oneLine) {
138
126
  lines.push(` ${step.command.padEnd(commandWidth)} ${step.detail}`);
139
127
  continue;
@@ -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,16 +289,29 @@ 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
308
- * run, then record it. Returns the text that was shown, or '' when nothing was.
309
- *
310
- * The marker is claimed before anything is printed, so an interrupted run
311
- * (Ctrl-C) can leave the note unshown but never printed twice.
312
- *
313
- * @param {object} [opts] — same inputs as shouldShowWelcome, plus the
314
- * welcomeText inputs (columns, version)
315
- * @returns {string}
292
+ * Every human bare invocation gets a local-only home. The legacy welcome
293
+ * marker controls only the greeting, never whether the catalog is selected.
316
294
  */
295
+ export function maybeShowHome({ argv = {}, requestedFormat = '', cfg = {}, env = process.env,
296
+ configDir = globalConfigDir(), interactive = canPrompt(), columns = process.stdout?.columns } = {}) {
297
+ if (env.JSN_NO_WELCOME === '1' || !interactive || argv.get || !HUMAN_FORMATS.has(requestedFormat || '')) return '';
298
+ const width = layoutWidth(columns);
299
+ const selected = cfg.activeProfile || cfg.defaultProfile;
300
+ const profile = selected && cfg.profiles?.[selected] ? selected : undefined;
301
+ const steps = profile ? [
302
+ { command: 'jsn incidents list', detail: 'browse incidents' },
303
+ { command: 'jsn setup', detail: 'manage connections' },
304
+ { command: 'jsn --help', detail: 'every command and flag' },
305
+ ] : STEPS;
306
+ const greeting = shouldShowWelcome({ argv, requestedFormat, cfg, env, configDir, interactive })
307
+ && claimWelcome(configDir) !== 'taken';
308
+ const heading = profile ? `Profile: ${profile}` : greeting ? 'Welcome to jsn' : 'Get started';
309
+ const text = [...wrapText(heading, width), '', ...renderSteps(width, steps)].join('\n');
310
+ process.stdout.write(`${text}\n\n`);
311
+ return text;
312
+ }
313
+
314
+ /** Legacy once-only note API; bare CLI discovery uses maybeShowHome. */
317
315
  export function maybeShowWelcome(opts = {}) {
318
316
  if (!shouldShowWelcome(opts)) return '';
319
317
  const configDir = opts.configDir || globalConfigDir();