@jacebenson/jsn 5.5.10-dev.235.1 → 5.5.10-dev.236.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 +1 -1
- package/src/cli-adapter.js +45 -2
- package/src/cli.js +1 -1
- package/src/command-audience.js +3 -1
- package/src/commands/auth.js +6 -0
- package/src/commands/discover.js +108 -8
- package/src/commands/records.js +4 -0
- package/src/commands/table-behavior.js +5 -0
- package/src/commands/tickets.js +5 -0
package/package.json
CHANGED
package/src/cli-adapter.js
CHANGED
|
@@ -312,7 +312,7 @@ export class LocalCLI {
|
|
|
312
312
|
* help page. Machine discovery leaves it out, so the JSON schema and bytes
|
|
313
313
|
* stay unchanged.
|
|
314
314
|
*/
|
|
315
|
-
commandRegistry({ summaries = false, shallow = false } = {}) {
|
|
315
|
+
commandRegistry({ summaries = false, shallow = false, details = false } = {}) {
|
|
316
316
|
const visible = (node) => !node.definition.hidden;
|
|
317
317
|
const serialize = (node) => {
|
|
318
318
|
if (!shallow) node.build();
|
|
@@ -333,7 +333,7 @@ export class LocalCLI {
|
|
|
333
333
|
if (summaries) entry.summary = node.definition.summary || '';
|
|
334
334
|
return entry;
|
|
335
335
|
};
|
|
336
|
-
|
|
336
|
+
const registry = {
|
|
337
337
|
commands: this.root.children.filter(visible).map(serialize),
|
|
338
338
|
options: [...this.root.options.values()].map((spec) => ({
|
|
339
339
|
name: spec.name,
|
|
@@ -343,6 +343,49 @@ export class LocalCLI {
|
|
|
343
343
|
type: spec.type || 'boolean',
|
|
344
344
|
})),
|
|
345
345
|
};
|
|
346
|
+
// Opt-in action detail leaves the legacy command/group projection intact.
|
|
347
|
+
// Build every visible descendant, using the same option inheritance and
|
|
348
|
+
// signatures as dispatch. Hidden subtrees are never indexed.
|
|
349
|
+
if (details) {
|
|
350
|
+
registry.entries = [];
|
|
351
|
+
const visit = (node, ancestors = [], aliases = []) => {
|
|
352
|
+
if (!visible(node)) return;
|
|
353
|
+
// Dispatch resolves names as literal tokens, not positional patterns.
|
|
354
|
+
// A positional-headed declaration cannot yield a fixed canonical path
|
|
355
|
+
// after placeholder substitution. Keep it only in the legacy projection.
|
|
356
|
+
if (positionSpec(node.name).length) return;
|
|
357
|
+
node.build();
|
|
358
|
+
const nodes = [...ancestors, node];
|
|
359
|
+
const path = nodes.map(value => value.name);
|
|
360
|
+
const bindings = this._optionConfig(nodes);
|
|
361
|
+
const allOptions = [...new Set(bindings.values())];
|
|
362
|
+
const options = allOptions.filter(spec => !spec.hidden).map(spec => {
|
|
363
|
+
// An inherited alias can now belong to a different, hidden option.
|
|
364
|
+
// Advertise only tokens that still resolve to this visible spec.
|
|
365
|
+
const tokens = [...bindings].filter(([_name, bound]) => bound === spec).map(([name]) => name);
|
|
366
|
+
return { ...spec, token: tokens.includes(spec.name) ? spec.name : tokens[0],
|
|
367
|
+
alias: tokens.filter(name => name !== spec.name) };
|
|
368
|
+
});
|
|
369
|
+
const positions = positionSpec(node.definition.command || '').map(position => ({
|
|
370
|
+
...position, ...node.positionals.get(position.name), name: position.name,
|
|
371
|
+
}));
|
|
372
|
+
registry.entries.push({
|
|
373
|
+
path, aliases: [...aliases, ...node.aliases],
|
|
374
|
+
description: node.definition.describe || '',
|
|
375
|
+
group: nodes[0].definition.describe || '',
|
|
376
|
+
table: nodes[0].definition.discovery?.table || '',
|
|
377
|
+
help: `jsn ${path.join(' ')} --help`,
|
|
378
|
+
parent: node.children.some(visible),
|
|
379
|
+
options, positions,
|
|
380
|
+
hiddenRequired: allOptions.some(spec => spec.hidden && spec.demandOption),
|
|
381
|
+
tasks: node.definition.discoveryTasks || [],
|
|
382
|
+
examples: node.definition.examples || [],
|
|
383
|
+
});
|
|
384
|
+
for (const child of node.children) visit(child, nodes, [...aliases, ...node.aliases]);
|
|
385
|
+
};
|
|
386
|
+
for (const node of this.root.children) visit(node);
|
|
387
|
+
}
|
|
388
|
+
return registry;
|
|
346
389
|
}
|
|
347
390
|
|
|
348
391
|
/** Structured child signatures for a parent node, built on demand. */
|
package/src/cli.js
CHANGED
|
@@ -458,7 +458,7 @@ export function buildCLI() {
|
|
|
458
458
|
.command(versionCmd(wrap))
|
|
459
459
|
.command(upgradeCmd(wrap))
|
|
460
460
|
.command(documentCmd(wrap))
|
|
461
|
-
.command(discoverCmd(wrap, (argv) => visibleCommandRegistry(cliInstance.commandRegistry(), app.config, argv)))
|
|
461
|
+
.command(discoverCmd(wrap, (argv) => visibleCommandRegistry(cliInstance.commandRegistry({ details: true }), app.config, argv)))
|
|
462
462
|
.demandCommand(1, 'You must specify a command')
|
|
463
463
|
.onParentDiscovery((argv, { path, subcommands }) => {
|
|
464
464
|
// Reached only for a parent command that declares no default handler of
|
package/src/command-audience.js
CHANGED
|
@@ -34,5 +34,7 @@ export function commandAudience(config, { instance, allCommands = false } = {})
|
|
|
34
34
|
|
|
35
35
|
export function visibleCommandRegistry(registry, config, options = {}) {
|
|
36
36
|
if (commandAudience(config, options) !== 'basic') return registry;
|
|
37
|
-
return { ...registry, commands: registry.commands.filter(command => BASIC_COMMANDS.has(command.name))
|
|
37
|
+
return { ...registry, commands: registry.commands.filter(command => BASIC_COMMANDS.has(command.name)),
|
|
38
|
+
...(registry.entries ? { entries: registry.entries.filter(entry => BASIC_COMMANDS.has(entry.path[0])) } : {}),
|
|
39
|
+
};
|
|
38
40
|
}
|
package/src/commands/auth.js
CHANGED
|
@@ -1277,6 +1277,12 @@ export function authCmd(wrap) {
|
|
|
1277
1277
|
.command({
|
|
1278
1278
|
command: 'status',
|
|
1279
1279
|
describe: 'Show authentication status (use --details for users and instance URLs)',
|
|
1280
|
+
discoveryTasks: [{
|
|
1281
|
+
phrases: ['current update set', 'selected scope', 'capture context', 'current capture context', 'current scope', 'current application scope', 'active scope', 'selected application scope', 'active update set', 'selected update set', 'capture set', 'which scope am I in'],
|
|
1282
|
+
args: ['--context', '--json'],
|
|
1283
|
+
description: 'Read the selected profile context, including scope and current capture update set; does not select or change them',
|
|
1284
|
+
}],
|
|
1285
|
+
examples: [{ args: ['--context', '--json'], description: 'Inspect the selected scope and capture update set' }],
|
|
1280
1286
|
builder: sub => sub.option('local', {
|
|
1281
1287
|
type: 'boolean', describe: 'Show saved credential state without contacting any instance',
|
|
1282
1288
|
}).option('context', {
|
package/src/commands/discover.js
CHANGED
|
@@ -16,6 +16,95 @@ export function discoverCommands(registry, { query = '', table = '' } = {}) {
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
const normalize = text => String(text).toLowerCase().replace(/[^a-z0-9_]+/g, ' ').trim();
|
|
20
|
+
const filler = new Set(['a', 'an', 'the', 'my', 'is', 'are', 'what', 'which', 'show', 'me', 'please', 'for', 'of', 'to']);
|
|
21
|
+
const quote = value => /^[a-zA-Z0-9_./:<>=-]+$/.test(value) && !value.includes('=<') ? value : `'${value.replaceAll("'", "'\\''")}'`;
|
|
22
|
+
|
|
23
|
+
// Task/example args are argv tokens owned by that action, never shell code.
|
|
24
|
+
// Fill only parser-declared required inputs, and reject stale/hidden flags.
|
|
25
|
+
function invocationArgs(entry, suffix) {
|
|
26
|
+
if (entry.parent) return suffix.length ? null : [...entry.path, '--help'];
|
|
27
|
+
if (entry.hiddenRequired) return null;
|
|
28
|
+
const options = new Map(entry.options.flatMap(spec => [spec.token || spec.name, ...(Array.isArray(spec.alias) ? spec.alias : spec.alias ? [spec.alias] : [])].map(name => [name, spec])));
|
|
29
|
+
const positional = [], flags = [], supplied = new Set();
|
|
30
|
+
for (let i = 0; i < suffix.length; i++) {
|
|
31
|
+
const token = suffix[i];
|
|
32
|
+
if (!token.startsWith('-')) { positional.push(token); continue; }
|
|
33
|
+
// Long options require --; the parser treats -mode as short bundles.
|
|
34
|
+
if (!token.startsWith('--') && !/^-[^-](?:=|$)/.test(token)) return null;
|
|
35
|
+
const name = token.replace(/^-+/, '').split('=')[0];
|
|
36
|
+
const spec = options.get(name) || (name.startsWith('no-') && options.get(name.slice(3))?.type === 'boolean' ? options.get(name.slice(3)) : null);
|
|
37
|
+
if (!spec) return null;
|
|
38
|
+
supplied.add(spec.name);
|
|
39
|
+
flags.push(token);
|
|
40
|
+
let value = token.includes('=') ? token.slice(token.indexOf('=') + 1) : undefined;
|
|
41
|
+
if (spec.type && spec.type !== 'boolean' && value === undefined) {
|
|
42
|
+
value = suffix[++i];
|
|
43
|
+
if (value === undefined || value.startsWith('--')) return null;
|
|
44
|
+
flags.push(value);
|
|
45
|
+
}
|
|
46
|
+
if (value !== undefined && !value.includes('<')) {
|
|
47
|
+
if (spec.choices && !spec.choices.includes(value)) return null;
|
|
48
|
+
if (spec.type === 'number' && (value === '' || !Number.isFinite(Number(value)))) return null;
|
|
49
|
+
if (spec.type === 'boolean' && !['true', 'false'].includes(value)) return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const position of entry.positions.slice(positional.length)) {
|
|
53
|
+
if (position.required) positional.push(`<${position.name}>`);
|
|
54
|
+
}
|
|
55
|
+
for (const spec of entry.options) {
|
|
56
|
+
if (spec.demandOption && !supplied.has(spec.name)) {
|
|
57
|
+
flags.push(`--${spec.token || spec.name}`);
|
|
58
|
+
if (spec.type !== 'boolean') flags.push(`<${spec.name}>`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [...entry.path, ...positional, ...flags];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function rankedDiscoveries(registry, { query = '', table = '', limit = 5 } = {}) {
|
|
65
|
+
const normalized = normalize(query);
|
|
66
|
+
const words = normalized.split(' ').filter(word => word && !filler.has(word));
|
|
67
|
+
const matches = text => words.length > 0 && words.every(word => normalize(text).includes(word));
|
|
68
|
+
const candidates = [];
|
|
69
|
+
for (const entry of registry.entries || []) {
|
|
70
|
+
if (table && entry.table !== table) continue;
|
|
71
|
+
const add = (score, suffix, description, match) => {
|
|
72
|
+
const args = invocationArgs(entry, suffix);
|
|
73
|
+
if (!args) return;
|
|
74
|
+
const invocation = `jsn ${args.map(quote).join(' ')}`;
|
|
75
|
+
candidates.push({ score, invocation, args, description, help: entry.help, match,
|
|
76
|
+
required: [...new Set(args.flatMap(arg => arg.match(/<[^>]+>/g) || []))],
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
if (!normalized) {
|
|
80
|
+
if (entry.path.length === 1) add(1, [], entry.description, 'group');
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
for (const task of entry.tasks) {
|
|
84
|
+
const exact = task.phrases.some(phrase => normalize(phrase) === normalized);
|
|
85
|
+
if (!task.hidden && (exact || task.phrases.some(matches))) add(exact ? 400 : 350, task.args || [], task.description, 'task');
|
|
86
|
+
}
|
|
87
|
+
for (const example of entry.examples) {
|
|
88
|
+
if (!example.hidden && matches(`${example.description} ${(example.args || []).join(' ')}`)) {
|
|
89
|
+
add(275, example.args || [], example.description, 'example');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!entry.parent) for (const option of entry.options) {
|
|
93
|
+
if (matches(`${option.name} ${[].concat(option.alias || []).join(' ')} ${option.describe || option.description || ''}`)) {
|
|
94
|
+
add(250, [`--${option.token || option.name}`, ...(option.type && option.type !== 'boolean' ? [`<${option.name}>`] : [])],
|
|
95
|
+
option.describe || option.description || entry.description, 'option');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (matches(`${entry.path.join(' ')} ${entry.aliases.join(' ')} ${entry.description}`)) {
|
|
99
|
+
add(entry.parent ? 100 : 200, [], entry.description, entry.parent ? 'group' : 'action');
|
|
100
|
+
} else if (matches(`${entry.group} ${entry.table}`)) add(50, [], entry.description, 'group');
|
|
101
|
+
}
|
|
102
|
+
candidates.sort((a, b) => b.score - a.score || (a.invocation < b.invocation ? -1 : a.invocation > b.invocation ? 1 : 0));
|
|
103
|
+
const seen = new Set();
|
|
104
|
+
return candidates.filter(result => !seen.has(result.invocation) && seen.add(result.invocation))
|
|
105
|
+
.slice(0, limit).map(({ score: _score, ...result }) => result);
|
|
106
|
+
}
|
|
107
|
+
|
|
19
108
|
export function discoverCmd(wrap, getRegistry) {
|
|
20
109
|
return {
|
|
21
110
|
command: 'discover [query]',
|
|
@@ -32,12 +121,23 @@ export function discoverCmd(wrap, getRegistry) {
|
|
|
32
121
|
' Rich request views (attachments and variables): jsn requests show --help',
|
|
33
122
|
' Raw endpoints when needed: jsn rest --help',
|
|
34
123
|
'Generic records supports any accessible table; specialized commands provide configured defaults and table-specific behavior.',
|
|
35
|
-
'
|
|
36
|
-
'
|
|
124
|
+
'Ranked suggestions use local task phrases, action/option help and registered examples; exact task phrases rank first, with stable ties and at most 5 results.',
|
|
125
|
+
'Suggestions never run commands. Replace every <placeholder> before use; discovery does not infer record IDs or authorize writes.',
|
|
126
|
+
'Compatibility: data.commands retains legacy unranked group matching unchanged. Additive data.results contains ranked action suggestions.',
|
|
127
|
+
'Use --json --get data.results for ranked suggestions, or --json --get data.commands for legacy matches.',
|
|
37
128
|
].join('\n')),
|
|
38
129
|
handler: wrap(async (argv, app) => {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
130
|
+
const registry = getRegistry(argv);
|
|
131
|
+
const search = { query: argv.query, table: argv.table };
|
|
132
|
+
const commands = discoverCommands(registry, search);
|
|
133
|
+
const results = rankedDiscoveries(registry, search);
|
|
134
|
+
const lines = results.flatMap(result => [
|
|
135
|
+
result.invocation,
|
|
136
|
+
` ${result.description}`,
|
|
137
|
+
` Help: ${result.help}${result.required.length ? `; required: ${result.required.join(', ')}` : ''}`,
|
|
138
|
+
]);
|
|
139
|
+
// Exact-table discovery keeps its existing configured-view details.
|
|
140
|
+
if (argv.table) lines.push(...commands.flatMap(command => [
|
|
41
141
|
`${command.name}: ${command.description}`,
|
|
42
142
|
...(command.discovery ? [
|
|
43
143
|
` Table: ${command.discovery.table}; default columns: ${command.discovery.defaultColumns.join(', ')}`,
|
|
@@ -45,10 +145,10 @@ export function discoverCmd(wrap, getRegistry) {
|
|
|
45
145
|
] : []),
|
|
46
146
|
` ${command.help}`,
|
|
47
147
|
...(command.actions || []).map(action => ` ${action.help} — ${action.description}`),
|
|
48
|
-
]);
|
|
49
|
-
if (!
|
|
50
|
-
app.ok({ commands, _formatted: lines.join('\n') }, {
|
|
51
|
-
summary: `${commands.length} matching command(s). Use jsn discover --help for guidance by intent.`,
|
|
148
|
+
]));
|
|
149
|
+
if (!lines.length) lines.push('No registered matches. Try fewer words or use generic records for any accessible table: jsn records list --help');
|
|
150
|
+
app.ok({ commands, results, _formatted: lines.join('\n') }, {
|
|
151
|
+
summary: `${results.length} ranked suggestion(s); ${commands.length} legacy matching command(s). Use jsn discover --help for guidance by intent.`,
|
|
52
152
|
});
|
|
53
153
|
}),
|
|
54
154
|
};
|
package/src/commands/records.js
CHANGED
|
@@ -638,6 +638,10 @@ export function recordsCmd(wrap) {
|
|
|
638
638
|
command: 'inspect <table> <identifier>',
|
|
639
639
|
aliases: ['debug', 'diag'],
|
|
640
640
|
describe: 'Inspect a record: show audit history, business rules, and running flows',
|
|
641
|
+
discoveryTasks: [{
|
|
642
|
+
phrases: ['record history', 'audit history', 'record changes', 'show record history', 'who changed a record'],
|
|
643
|
+
args: ['--json'], description: 'Inspect audit history for the specified table and record',
|
|
644
|
+
}],
|
|
641
645
|
builder: (y) => y
|
|
642
646
|
.positional('table', { describe: 'Table name (e.g. incident)', type: 'string' })
|
|
643
647
|
.positional('identifier', { describe: 'Record sys_id or number', type: 'string' }),
|
|
@@ -26,6 +26,11 @@ export function withTableBehavior(command, wrap) {
|
|
|
26
26
|
command: 'behavior <table>',
|
|
27
27
|
aliases: ['behaviour'],
|
|
28
28
|
describe: 'Read-only inventory of tables behavior: rules, scripts, actions, policies, dictionary, notifications, ACLs, styles, views and flow triggers (inherited included)',
|
|
29
|
+
discoveryTasks: [{
|
|
30
|
+
phrases: ['inherited business rules', 'inherited rules', 'parent table business rules', 'business rules from ancestors'],
|
|
31
|
+
args: ['--category', 'business_rules', '--json'],
|
|
32
|
+
description: 'List business rules for the specified table, including inherited rules by default',
|
|
33
|
+
}],
|
|
29
34
|
builder: (y) => y
|
|
30
35
|
.positional('table', { type: 'string', describe: 'Table name (e.g. incident)' })
|
|
31
36
|
.option('category', {
|
package/src/commands/tickets.js
CHANGED
|
@@ -92,6 +92,11 @@ export function ticketsCmd(wrap) {
|
|
|
92
92
|
.command({
|
|
93
93
|
command: 'update <number>',
|
|
94
94
|
describe: 'Update a ticket',
|
|
95
|
+
discoveryTasks: [{
|
|
96
|
+
phrases: ['write work note', 'write work notes', 'add work note', 'add work notes', 'append work notes', 'write a work note', 'add internal note'],
|
|
97
|
+
args: ['--field', 'work_notes=<text>', '--json'],
|
|
98
|
+
description: 'Write a work note to the specified ticket; replace the required number and text placeholders',
|
|
99
|
+
}],
|
|
95
100
|
builder: (y) => recordOptions(y, false)
|
|
96
101
|
.option('data', { type: 'string', describe: 'JSON fields' })
|
|
97
102
|
.option('data-file', { type: 'string', describe: 'Read JSON payload from file' })
|