@jacebenson/jsn 5.5.6 → 5.5.7-dev.212.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/README.md +16 -1
- package/package.json +9 -8
- package/src/amb.js +15 -0
- package/src/app.js +4 -15
- package/src/auth/credential-store.js +131 -32
- package/src/auth/oauth.js +4 -28
- package/src/auth/transport.js +22 -0
- package/src/auth.js +23 -2
- package/src/cli-adapter.js +18 -1
- package/src/cli.js +0 -3
- package/src/commands/auth.js +21 -5
- package/src/commands/codesearch.js +11 -2
- package/src/commands/docs/community.js +1 -1
- package/src/commands/docs/db.js +38 -4
- package/src/commands/docs/docs.js +14 -13
- package/src/commands/docs/index.js +2 -1
- package/src/commands/docs/refresh.js +2 -1
- package/src/commands/docs/releases.js +1 -1
- package/src/commands/docs/replace.js +1 -1
- package/src/commands/docs/service-snapshot.js +1 -1
- package/src/commands/docs/snapshot.js +2 -1
- package/src/commands/docs/sync-service.js +5 -3
- package/src/commands/flows.js +7 -2
- package/src/commands/setup.js +28 -31
- package/src/commands/skill.js +3 -8
- package/src/commands/version.js +5 -1
- package/src/config.js +93 -18
- package/src/docs-links.js +28 -0
- package/src/help.js +4 -0
- package/src/midserver-install.js +3 -0
- package/src/paginated-search.js +146 -178
- package/src/perf.js +1 -1
- package/src/prompt-engine.js +169 -0
- package/src/prompts.js +304 -42
- package/src/sdk.js +10 -44
- package/src/session.js +6 -1
- package/src/sqlite.js +94 -0
- package/src/commands/docs/public/index.html +0 -178
- package/src/commands/docs/public/vendor/marked.min.js +0 -69
- package/src/commands/docs/public/vendor/purify.min.js +0 -3
- package/src/commands/docs/serve.js +0 -287
- package/src/commands/history.js +0 -57
- package/src/mutation-history.js +0 -75
package/src/commands/auth.js
CHANGED
|
@@ -608,6 +608,18 @@ Find your instance URL in your browser's address bar when logged into ServiceNow
|
|
|
608
608
|
}
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
+
// A profile name selects an account; it does not approve a project-supplied
|
|
612
|
+
// replacement origin. Only a literal destination (also supplied by setup's
|
|
613
|
+
// destination prompt) may authorize a new global trust binding.
|
|
614
|
+
const literalDestination = !argv.profile && argv.instance && !app.config.profiles?.[argv.instance];
|
|
615
|
+
const trustedProfiles = app.config.credentialTrust?.profiles;
|
|
616
|
+
if (trustedProfiles && !literalDestination) {
|
|
617
|
+
const trustedOrigin = selectedProfileName ? trustedProfiles[selectedProfileName]?.instance_url : app.config.credentialTrust.origin;
|
|
618
|
+
if (!trustedOrigin || normalizeInstanceURL(trustedOrigin) !== normalizeInstanceURL(instanceURL)) {
|
|
619
|
+
throw errUsage('Project login destination is not globally trusted. Approve it explicitly with auth login <URL>.');
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
611
623
|
const matchingProfiles = Object.entries(app.config.profiles || {})
|
|
612
624
|
.filter(([, profile]) => normalizeInstanceURL(profile.instance_url) === instanceURL);
|
|
613
625
|
if (!selectedProfileName && !argv.name && matchingProfiles.length > 1) {
|
|
@@ -615,10 +627,13 @@ Find your instance URL in your browser's address bar when logged into ServiceNow
|
|
|
615
627
|
}
|
|
616
628
|
const target = argv.name ? { name: argv.name, profile: null }
|
|
617
629
|
: resolveTargetProfile({ ...argv, profile: selectedProfileName }, app.config, instanceURL);
|
|
618
|
-
const
|
|
630
|
+
const savedTarget = trustedProfiles?.[target.name];
|
|
631
|
+
const targetProfile = trustedProfiles
|
|
632
|
+
? savedTarget && normalizeInstanceURL(savedTarget.instance_url) === normalizeInstanceURL(instanceURL) ? savedTarget : null
|
|
633
|
+
: target.profile;
|
|
619
634
|
validateLoginSelectors(argv, targetProfile);
|
|
620
635
|
let targetUsername = targetProfile?.username || '';
|
|
621
|
-
const methodConfig = argv.name ? {
|
|
636
|
+
const methodConfig = { profiles: argv.name ? {} : trustedProfiles || app.config.profiles };
|
|
622
637
|
const useBasic = shouldUseBasicAuth(argv, methodConfig, instanceURL, targetProfile);
|
|
623
638
|
const useGck = shouldUseGckAuth(argv, methodConfig, instanceURL, targetProfile);
|
|
624
639
|
const interactive = canUsePicker(app, argv);
|
|
@@ -631,9 +646,10 @@ Find your instance URL in your browser's address bar when logged into ServiceNow
|
|
|
631
646
|
}
|
|
632
647
|
const preliminary = argv.printUrl && !argv.waitFile;
|
|
633
648
|
const explicitPreferences = ['read-only', 'skip-confirmations', 'include-counts'].every(flag => typeof argv[flag] === 'boolean');
|
|
649
|
+
const preferenceProfile = trustedProfiles ? trustedProfiles[target.name] || {} : targetProfile || {};
|
|
634
650
|
const preferences = !targetProfile && interactive && !preliminary && !explicitPreferences
|
|
635
651
|
? await chooseConnectionPreferences(app.config, argv, { confirm: (await import('../prompts.js')).confirm })
|
|
636
|
-
: await configureProfileOptions({ ...
|
|
652
|
+
: await configureProfileOptions({ ...preferenceProfile, ...connectionPreferences(app.config, preferenceProfile, argv) }, argv);
|
|
637
653
|
let setDefault = argv.makeDefault === true;
|
|
638
654
|
if (!targetProfile && argv.makeDefault === undefined && interactive && !preliminary) {
|
|
639
655
|
const { confirm } = await import('../prompts.js');
|
|
@@ -747,7 +763,7 @@ Find your instance URL in your browser's address bar when logged into ServiceNow
|
|
|
747
763
|
}
|
|
748
764
|
|
|
749
765
|
app.config.profiles[profileName] = {
|
|
750
|
-
...(app.config.profiles[profileName] || {}),
|
|
766
|
+
...(trustedProfiles ? trustedProfiles[profileName] || {} : app.config.profiles[profileName] || {}),
|
|
751
767
|
instance_url: instanceURL,
|
|
752
768
|
auth_method: useGck ? 'gck' : useBasic ? 'basic' : 'oauth',
|
|
753
769
|
username: username || undefined,
|
|
@@ -789,7 +805,7 @@ Find your instance URL in your browser's address bar when logged into ServiceNow
|
|
|
789
805
|
}
|
|
790
806
|
|
|
791
807
|
const { saveConfig } = await import('../config.js');
|
|
792
|
-
saveConfig(app.config);
|
|
808
|
+
saveConfig(app.config, { approvedProfile: profileName, approveDefault: setDefault });
|
|
793
809
|
syncSession(app);
|
|
794
810
|
|
|
795
811
|
const result = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// GraphQL read-only queries; no sn_codesearch engine or Flow downloads.
|
|
2
2
|
import { searchGraphQL } from '../codesearch-graphql.js';
|
|
3
|
+
import { docLink } from '../docs-links.js';
|
|
3
4
|
|
|
4
5
|
export function renderCodeSearch(data) {
|
|
5
6
|
const out = [`${data.recordCount} record(s), ${data.fieldCount} field(s), ${data.matchCount} match(es) — ${data.status}`];
|
|
@@ -35,13 +36,21 @@ export function codesearchCmd(wrap) {
|
|
|
35
36
|
.option('all-scopes', { type: 'boolean', default: true, describe: 'Search all scopes; false requires --scope' })
|
|
36
37
|
.option('page-size', { type: 'number', default: 250, describe: 'GraphQL page window size (max 1000)' })
|
|
37
38
|
.option('max-pages', { type: 'number', default: 20, describe: 'Maximum pages per table (max 1000)' })
|
|
38
|
-
.option('max-requests', { type: 'number', default: 1000, describe: 'Data-call budget including configuration, excluding SDK auth/bootstrap (max 10000)' })
|
|
39
|
+
.option('max-requests', { type: 'number', default: 1000, describe: 'Data-call budget including configuration, excluding SDK auth/bootstrap (max 10000)' })
|
|
40
|
+
.epilogue(`Code search is literal and read-only. Flow internals use "jsn flows search <term>".
|
|
41
|
+
Examples:
|
|
42
|
+
jsn codesearch search GlideAjax --limit 5
|
|
43
|
+
jsn codesearch search approval --scope x_my_app --limit 5
|
|
44
|
+
|
|
45
|
+
Full reference and coverage limits: ${docLink('codesearch')}`),
|
|
39
46
|
handler: wrap(async (argv, app) => {
|
|
40
47
|
const data = await searchGraphQL(app, argv);
|
|
41
48
|
Object.defineProperty(data, '_formatted', { value: renderCodeSearch(data), enumerable: false });
|
|
42
49
|
app.ok(data, { summary: `${data.recordCount} record(s), ${data.fieldCount} field(s), ${data.matchCount} match(es) — ${data.status}` });
|
|
43
50
|
}),
|
|
44
|
-
}).demandCommand(1, 'Specify a subcommand: search')
|
|
51
|
+
}).demandCommand(1, 'Specify a subcommand: search')
|
|
52
|
+
.epilogue(`Code search is literal and read-only. Flow internals use "jsn flows search <term>".
|
|
53
|
+
Documentation: ${docLink('codesearch')}`),
|
|
45
54
|
handler: () => {},
|
|
46
55
|
};
|
|
47
56
|
}
|
|
@@ -9,7 +9,7 @@ import path from 'node:path';
|
|
|
9
9
|
import process from 'node:process';
|
|
10
10
|
import TurndownService from 'turndown';
|
|
11
11
|
import { parseFrontmatter, stringifyFrontmatter } from '../../frontmatter.js';
|
|
12
|
-
import Database from '
|
|
12
|
+
import Database from '../../sqlite.js';
|
|
13
13
|
import { getDocsCommunityDir, resolveDocsDbPath, docsDbExists } from './db.js';
|
|
14
14
|
import { refreshDocs } from './refresh.js';
|
|
15
15
|
import { ingestDocs } from './ingest.js';
|
package/src/commands/docs/db.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import os from 'node:os';
|
|
6
|
-
import Database from '
|
|
6
|
+
import Database, { requireFts5 } from '../../sqlite.js';
|
|
7
7
|
import { docsReaderLease } from './locks.js';
|
|
8
8
|
import { AppError } from '../../errors.js';
|
|
9
9
|
|
|
@@ -118,20 +118,52 @@ export function ensureDocsCacheDir() {
|
|
|
118
118
|
* { dir, prefix } so community content can live under a `community/` prefix
|
|
119
119
|
* without colliding with the ServiceNowDocs markdown tree.
|
|
120
120
|
*/
|
|
121
|
+
// The caller-selected lexical root is the authorization boundary, not whatever
|
|
122
|
+
// realpath happens to point at. Reject aliases in *every* component (including
|
|
123
|
+
// junctions on Windows), before using realpath to pin that boundary. Missing
|
|
124
|
+
// optional roots remain optional; dangling links are not missing directories.
|
|
125
|
+
export function resolveDocsRoot(dir) {
|
|
126
|
+
const absolute = path.resolve(dir);
|
|
127
|
+
const anchor = path.parse(absolute).root;
|
|
128
|
+
let current = anchor;
|
|
129
|
+
for (const component of absolute.slice(anchor.length).split(path.sep).filter(Boolean)) {
|
|
130
|
+
current = path.join(current, component);
|
|
131
|
+
let stat;
|
|
132
|
+
try { stat = fs.lstatSync(current); }
|
|
133
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
134
|
+
if (stat.isSymbolicLink()) throw new Error(`Documentation source contains a symbolic link or junction alias: ${current}`);
|
|
135
|
+
if (!stat.isDirectory()) throw new Error(`Documentation source is not a directory: ${current}`);
|
|
136
|
+
}
|
|
137
|
+
const canonical = fs.realpathSync(absolute);
|
|
138
|
+
if (path.relative(absolute, canonical) !== '') throw new Error(`Documentation source resolves through an alias: ${absolute}`);
|
|
139
|
+
return canonical;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function containedDocsPath(root, file) {
|
|
143
|
+
const relative = path.relative(root, fs.realpathSync(file));
|
|
144
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
145
|
+
throw new Error(`Documentation source escapes its root: ${file}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
121
149
|
export function* walkDocs(roots) {
|
|
122
150
|
function* walk(dir, root, prefix) {
|
|
151
|
+
containedDocsPath(root, dir);
|
|
123
152
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
124
153
|
const full = path.join(dir, entry.name);
|
|
125
154
|
if (entry.isDirectory()) {
|
|
126
155
|
yield* walk(full, root, prefix);
|
|
127
156
|
} else if (entry.isFile() && entry.name.toLowerCase().endsWith('.md')) {
|
|
157
|
+
containedDocsPath(root, full);
|
|
128
158
|
const rel = prefix + path.relative(root, full).split(path.sep).join('/');
|
|
129
159
|
yield { file: full, rel };
|
|
130
160
|
}
|
|
131
161
|
}
|
|
132
162
|
}
|
|
133
|
-
|
|
134
|
-
|
|
163
|
+
// Validate every root before yielding any document from any root.
|
|
164
|
+
const validated = roots.map(root => ({ ...root, dir: resolveDocsRoot(root.dir) }));
|
|
165
|
+
for (const root of validated) {
|
|
166
|
+
if (!root.dir) continue;
|
|
135
167
|
yield* walk(root.dir, root.dir, root.prefix || '');
|
|
136
168
|
}
|
|
137
169
|
}
|
|
@@ -151,7 +183,8 @@ export function openDocsDb(opts = {}) {
|
|
|
151
183
|
let db;
|
|
152
184
|
try {
|
|
153
185
|
db = new Database(dbPath);
|
|
154
|
-
|
|
186
|
+
requireFts5(db);
|
|
187
|
+
} catch (error) { if (db) db.close(); release(); throw error; }
|
|
155
188
|
const close = db.close.bind(db);
|
|
156
189
|
db.close = () => { try { return close(); } finally { release(); } };
|
|
157
190
|
try {
|
|
@@ -190,6 +223,7 @@ export function setSchemaVersion(db, version) {
|
|
|
190
223
|
}
|
|
191
224
|
|
|
192
225
|
export function initDocsSchema(db) {
|
|
226
|
+
requireFts5(db);
|
|
193
227
|
db.exec(`
|
|
194
228
|
CREATE TABLE IF NOT EXISTS docs (
|
|
195
229
|
id INTEGER PRIMARY KEY,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Documentation search always uses the same API, hosted or self-hosted.
|
|
2
2
|
import { searchHostedDocs, getHostedDoc, getHostedDocsStatus, configuredDocsService } from './client.js';
|
|
3
3
|
import { documentationService } from './local.js';
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
import { declareCapabilities } from '../../capabilities.js';
|
|
6
|
+
import { docLink } from '../../docs-links.js';
|
|
6
7
|
import { AppError } from '../../errors.js';
|
|
7
8
|
import { resolveDocsRelease } from './db.js';
|
|
8
9
|
import { listDocsReleases } from './releases.js';
|
|
@@ -47,18 +48,25 @@ async function read(argv, app) {
|
|
|
47
48
|
app.ok(presented(row, `Doc ${row.id}: ${title} in ${row.release}\n${provenance}${context}\n${content}\n`), { summary: `Doc ${row.id}: ${title} in ${row.release}` });
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
export function docsCmd(
|
|
51
|
+
export function docsCmd(wrapHandler) {
|
|
52
|
+
// The adapter tolerates unknown options; retired server flags must fail closed
|
|
53
|
+
// on every docs spelling rather than becoming an accidental search request.
|
|
54
|
+
const wrap = handler => wrapHandler(async (argv, app) => {
|
|
55
|
+
for (const name of ['serve', 'no-serve', 'host', 'no-host', 'port', 'no-port']) {
|
|
56
|
+
if (Object.hasOwn(argv, name)) throw new AppError('usage_error', `Unknown option --${name}: the CLI documentation server flags have been removed. Use terminal search or configure a documentation service in jsn setup.`);
|
|
57
|
+
}
|
|
58
|
+
return handler(argv, app);
|
|
59
|
+
});
|
|
51
60
|
return {
|
|
52
61
|
command: 'docs [query..]',
|
|
53
62
|
defaultPositionals: true,
|
|
54
63
|
describe: 'Search ServiceNow documentation (hosted by default; configure your service in setup)',
|
|
55
64
|
builder: y => y
|
|
56
65
|
.usage('Usage: jsn docs "search terms" [options]')
|
|
66
|
+
.epilogue(`Documentation for this command: ${docLink('docs')}`)
|
|
57
67
|
.positional('query', { type: 'string', describe: 'Search words (up to 200 characters)' })
|
|
58
68
|
.option('release', { type: 'string', describe: 'Documentation family (docs.release config, otherwise australia)' })
|
|
59
|
-
|
|
60
|
-
.option('host', { type: 'string', default: '127.0.0.1', describe: 'Server bind address with --serve' })
|
|
61
|
-
.option('port', { type: 'number', default: 3000, describe: 'Server port with --serve' })
|
|
69
|
+
|
|
62
70
|
.option('limit', { type: 'number', default: 20, describe: 'Results per page (1–50)' })
|
|
63
71
|
.option('offset', { type: 'number', default: 0, describe: 'Result offset (0–10000)' })
|
|
64
72
|
.option('bundle', { type: 'string', describe: 'Filter by documentation bundle' })
|
|
@@ -95,14 +103,7 @@ export function docsCmd(wrap) {
|
|
|
95
103
|
app.ok(data, { summary: `Documentation service: ${data.state} in ${data.release}` });
|
|
96
104
|
}) }),
|
|
97
105
|
handler: wrap(async (argv, app) => {
|
|
98
|
-
|
|
99
|
-
if (!Number.isInteger(argv.port) || argv.port < 0 || argv.port > 65535) throw new AppError('usage_error', 'Use a port between 0 and 65535.');
|
|
100
|
-
const release = resolveDocsRelease(argv.release, app.config);
|
|
101
|
-
const { server, url } = await startDocumentationServer({ host: argv.host, port: argv.port, release });
|
|
102
|
-
app.ok({ url, release, state: 'listening' }, { summary: `Documentation server started for ${release}; the index updates automatically.` });
|
|
103
|
-
for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => server.close());
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
+
|
|
106
107
|
if ((argv.outline || argv.section !== undefined) && !argv.path) throw new AppError('usage_error', 'Use --path with --outline or --section.');
|
|
107
108
|
if (argv.path) return read(argv, app);
|
|
108
109
|
if (argv.query?.length) return search(argv, app);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import { selectDocument } from './sections.js';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import Database from '
|
|
5
|
+
import Database, { requireFts5 } from '../../sqlite.js';
|
|
6
6
|
import { resolveDocsDbPath } from './db.js';
|
|
7
7
|
|
|
8
8
|
export class DocumentationError extends Error {
|
|
@@ -56,6 +56,7 @@ export class DocumentationIndex {
|
|
|
56
56
|
close() { this.db.close(); }
|
|
57
57
|
revision() { return this.db.prepare("SELECT value FROM meta WHERE key = 'source_revision'").get()?.value || this.db.prepare("SELECT value FROM meta WHERE key = 'snapshot_revision'").get()?.value || ''; }
|
|
58
58
|
search({ query, limit = 20, offset = 0, bundle } = {}) {
|
|
59
|
+
requireFts5(this.db);
|
|
59
60
|
const text = String(query || '').trim();
|
|
60
61
|
if (!text || text.length > 200) throw new DocumentationError('Enter a search of 1 to 200 characters.', 400);
|
|
61
62
|
const tokens = text.match(/[\p{L}\p{N}_]+/gu)?.slice(0, 20);
|
|
@@ -7,7 +7,7 @@ import { docsReaderLease } from './locks.js';
|
|
|
7
7
|
import { errUsageHint } from '../../errors.js';
|
|
8
8
|
import { createHash } from 'node:crypto';
|
|
9
9
|
import { parseFrontmatter } from '../../frontmatter.js';
|
|
10
|
-
import { withDocsDb, resolveDocsDbPath, walkDocs, defaultDocsRoots, getDocsSourceDir } from './db.js';
|
|
10
|
+
import { withDocsDb, resolveDocsDbPath, resolveDocsRoot, walkDocs, defaultDocsRoots, getDocsSourceDir } from './db.js';
|
|
11
11
|
import { encodeText, phasesToBytes, docSurface, DEFAULT_DIM } from './hrr.js';
|
|
12
12
|
|
|
13
13
|
export function refreshDocs(opts = {}) {
|
|
@@ -20,6 +20,7 @@ function refreshDocsLocked(opts = {}) {
|
|
|
20
20
|
const dbPath = opts.dbPath || resolveDocsDbPath(opts.release);
|
|
21
21
|
const roots = opts.roots || defaultDocsRoots(opts);
|
|
22
22
|
|
|
23
|
+
for (const root of roots) resolveDocsRoot(root.dir);
|
|
23
24
|
if (roots.some(root => (!root.prefix || opts.roots) && (!fs.existsSync(root.dir) || !fs.statSync(root.dir).isDirectory()))) {
|
|
24
25
|
throw errUsageHint('Raw documentation source is missing; existing index retained.', 'Use jsn docs install --source snapshot to update a prebuilt index, or --source github to install raw source before refreshing.');
|
|
25
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import Database from '
|
|
3
|
+
import Database from '../../sqlite.js';
|
|
4
4
|
import { DEFAULT_DOCS_RELEASE, resolveDocsDbPath, getMeta } from './db.js';
|
|
5
5
|
import { docsReaderLease } from './locks.js';
|
|
6
6
|
|
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createHash } from 'node:crypto';
|
|
5
5
|
import { gzipSync } from 'node:zlib';
|
|
6
|
-
import Database from '
|
|
6
|
+
import Database from '../../sqlite.js';
|
|
7
7
|
import { validateDatabase, validateManifest } from './snapshot.js';
|
|
8
8
|
|
|
9
9
|
export async function publishServiceSnapshot(storage, { dbPath = path.join(storage, 'docs.sqlite3'), release } = {}) {
|
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createHash, randomUUID } from 'node:crypto';
|
|
5
5
|
import { gzipSync, gunzipSync } from 'node:zlib';
|
|
6
|
-
import Database from '
|
|
6
|
+
import Database, { requireFts5 } from '../../sqlite.js';
|
|
7
7
|
import { resolveDocsDbPath, resolveDocsRelease, DEFAULT_DOCS_RELEASE } from './db.js';
|
|
8
8
|
import { docsServiceUrl } from './client.js';
|
|
9
9
|
import { docsReaderLease } from './locks.js';
|
|
@@ -29,6 +29,7 @@ export function validateManifest(manifest) {
|
|
|
29
29
|
export function validateDatabase(filename) {
|
|
30
30
|
const db = new Database(filename, { readonly: true, fileMustExist: true });
|
|
31
31
|
try {
|
|
32
|
+
requireFts5(db);
|
|
32
33
|
if (db.pragma('integrity_check', { simple: true }) !== 'ok') throw new Error('Snapshot SQLite integrity check failed');
|
|
33
34
|
if (db.prepare("SELECT value FROM meta WHERE key='schema_version'").get()?.value !== String(SNAPSHOT_SCHEMA)) throw new Error('Incompatible snapshot database schema');
|
|
34
35
|
const count = db.prepare('SELECT count(*) AS n FROM docs').get().n;
|
|
@@ -5,12 +5,12 @@ import { fileURLToPath } from 'node:url';
|
|
|
5
5
|
import { randomUUID } from 'node:crypto';
|
|
6
6
|
import os from 'node:os';
|
|
7
7
|
import { spawnSync } from 'node:child_process';
|
|
8
|
-
import Database from '
|
|
8
|
+
import Database from '../../sqlite.js';
|
|
9
9
|
import { ingestDocs } from './ingest.js';
|
|
10
10
|
import { refreshDocs } from './refresh.js';
|
|
11
11
|
import { installSnapshot } from './snapshot.js';
|
|
12
12
|
import { publishServiceSnapshot } from './service-snapshot.js';
|
|
13
|
-
import { DEFAULT_DOCS_RELEASE, resolveDocsDbPath, resolveDocsRelease } from './db.js';
|
|
13
|
+
import { DEFAULT_DOCS_RELEASE, resolveDocsDbPath, resolveDocsRelease, resolveDocsRoot } from './db.js';
|
|
14
14
|
|
|
15
15
|
const defaultStorage = path.join(process.env.JSN_DATA_HOME || path.join(os.homedir(), '.jsn'), 'docs-service');
|
|
16
16
|
function git(args) {
|
|
@@ -30,6 +30,8 @@ async function performSync(options = {}) {
|
|
|
30
30
|
const branch = family ? resolveDocsRelease(family) : options.branch || process.env.DOCS_SOURCE_BRANCH || DEFAULT_DOCS_RELEASE;
|
|
31
31
|
fs.mkdirSync(storage, { recursive: true });
|
|
32
32
|
const repo = path.join(storage, 'source');
|
|
33
|
+
resolveDocsRoot(repo);
|
|
34
|
+
resolveDocsRoot(path.join(repo, 'markdown'));
|
|
33
35
|
const live = family ? resolveDocsDbPath(family) : path.join(storage, 'docs.sqlite3');
|
|
34
36
|
const staging = path.join(storage, `build-${randomUUID()}.sqlite3`);
|
|
35
37
|
let previous = {};
|
|
@@ -89,7 +91,7 @@ async function performSync(options = {}) {
|
|
|
89
91
|
}
|
|
90
92
|
const revision = git(['-C', repo, 'rev-parse', 'HEAD']);
|
|
91
93
|
const markdown = path.join(repo, 'markdown');
|
|
92
|
-
if (!
|
|
94
|
+
if (!resolveDocsRoot(markdown)) throw new Error('Source has no markdown directory');
|
|
93
95
|
let oldRevision;
|
|
94
96
|
if (fs.existsSync(live)) {
|
|
95
97
|
const db = new Database(live, { readonly: true });
|
package/src/commands/flows.js
CHANGED
|
@@ -5,6 +5,7 @@ import { canUsePicker } from '../helpers.js';
|
|
|
5
5
|
import { formatRecordForDisplay, formatCommandList, getStringField, interactiveList } from '../helpers.js';
|
|
6
6
|
import { discoverFlowContextFields, normalizeFlowContext, summarizeFlowContexts, formatFlowContextSummary, aggregateFlowContextMappings, mergeFlowContextStats, buildFlowContextQuery } from '../flow-context.js';
|
|
7
7
|
import { declareCapabilities } from '../capabilities.js';
|
|
8
|
+
import { docLink } from '../docs-links.js';
|
|
8
9
|
import { inspectFlow } from '../flow-inspection.js';
|
|
9
10
|
import { publishFlows, publishFlowLifecycle, publishDoctor, flowStatus } from '../flow-publish.js';
|
|
10
11
|
import { resolveRecord, unwrapSysId } from '../resolve-record.js';
|
|
@@ -96,7 +97,11 @@ export function flowsCmd(wrap) {
|
|
|
96
97
|
describe: 'Download/decode visible flows into a private cache and search literal text (first use can be slow)',
|
|
97
98
|
builder: y => y
|
|
98
99
|
.positional('term', { type: 'string', describe: 'Case-insensitive literal text to find in readable definitions' })
|
|
99
|
-
.option('refresh', { type: 'boolean', default: false, describe: 'Rebuild the decoded cache; warm searches still revalidate source access' })
|
|
100
|
+
.option('refresh', { type: 'boolean', default: false, describe: 'Rebuild the decoded cache; warm searches still revalidate source access' })
|
|
101
|
+
.epilogue(`Example:
|
|
102
|
+
jsn flows search approval
|
|
103
|
+
Interactive use can pick a flow; scripts pass the term.
|
|
104
|
+
Documentation: ${docLink('flows')}`),
|
|
100
105
|
handler: wrap(async (argv, app) => {
|
|
101
106
|
app.requireInstance();
|
|
102
107
|
const session = app.session || {};
|
|
@@ -575,7 +580,7 @@ export function flowsCmd(wrap) {
|
|
|
575
580
|
}),
|
|
576
581
|
})
|
|
577
582
|
.epilogue('Run "jsn flows <command> --help" for details. In a terminal you can omit the target and pick\n'
|
|
578
|
-
+
|
|
583
|
+
+ `one; scripts use explicit identifiers and manifests.\nDocumentation: ${docLink('flows')}`);
|
|
579
584
|
},
|
|
580
585
|
handler: wrap(async (_argv, app) => {
|
|
581
586
|
const summary = 'Manage Flow Designer flows from the sys_hub_flow table. Flow structure comes from the ProcessFlow API, so V1, V2 and subflow definitions all render in full.';
|
package/src/commands/setup.js
CHANGED
|
@@ -42,39 +42,36 @@ const setupHelp = () => [
|
|
|
42
42
|
].join('\n');
|
|
43
43
|
|
|
44
44
|
/** The setup hub prompt; q and Escape resolve with no selected action. */
|
|
45
|
-
export const authHubPrompt = async (
|
|
46
|
-
const {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
done(choices[active].value);
|
|
45
|
+
export const authHubPrompt = async (config = {}, context = {}) => {
|
|
46
|
+
const { runPrompt, escapeResult } = await import('../prompt-engine.js');
|
|
47
|
+
const choices = config.choices || [];
|
|
48
|
+
const state = { active: 0 };
|
|
49
|
+
return runPrompt(config, context, {
|
|
50
|
+
escapeValue: escapeResult(undefined),
|
|
51
|
+
init: () => state,
|
|
52
|
+
key(_state, key, api) {
|
|
53
|
+
if (key.name === 'q') return { done: undefined };
|
|
54
|
+
if (key.name === 'return' || key.name === 'enter') {
|
|
55
|
+
const choice = choices[state.active];
|
|
56
|
+
if (choice) return { done: choice.value };
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return `${config.message}\n${page}\n\n↑↓ navigate • ⏎ select • q/Esc exit`;
|
|
77
|
-
})(...args);
|
|
59
|
+
if (key.name === 'up' && state.active > 0) { state.active -= 1; api.redraw(); return; }
|
|
60
|
+
if (key.name === 'down' && state.active < choices.length - 1) { state.active += 1; api.redraw(); }
|
|
61
|
+
},
|
|
62
|
+
render() {
|
|
63
|
+
// Section headings are rendered inline; the pagination budget the
|
|
64
|
+
// Inquirer version needed no longer applies to a local renderer.
|
|
65
|
+
const lines = [config.message];
|
|
66
|
+
choices.forEach((choice, index) => {
|
|
67
|
+
const heading = choices[index - 1]?.section !== choice.section ? `${index ? '\n' : ''} ${choice.section}` : null;
|
|
68
|
+
if (heading) lines.push(heading);
|
|
69
|
+
lines.push(`${index === state.active ? '❯' : ' '} ${choice.name}`);
|
|
70
|
+
});
|
|
71
|
+
lines.push('', '↑↓ navigate • ⏎ select • q/Esc exit');
|
|
72
|
+
return lines;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
78
75
|
};
|
|
79
76
|
|
|
80
77
|
/** Interactive hub: what do you want to do? Returns an action or undefined on exit. */
|
package/src/commands/skill.js
CHANGED
|
@@ -4,8 +4,6 @@ import os from 'node:os';
|
|
|
4
4
|
import process from 'node:process';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
|
|
7
|
-
import { execSync } from 'node:child_process';
|
|
8
|
-
|
|
9
7
|
import { globalConfigPath } from '../config.js';
|
|
10
8
|
import { declareCapabilities } from '../capabilities.js';
|
|
11
9
|
import { canUsePicker } from '../helpers.js';
|
|
@@ -22,15 +20,12 @@ const SKILL_REPO_PATH = path.join(
|
|
|
22
20
|
* Resolve the user's real home directory, even when Hermes overrides $HOME.
|
|
23
21
|
*/
|
|
24
22
|
function realHomeDir() {
|
|
25
|
-
// getent doesn't exist on Windows; os.homedir() is reliable there.
|
|
26
|
-
if (process.platform === 'win32') return os.homedir();
|
|
27
|
-
|
|
28
23
|
try {
|
|
29
|
-
|
|
30
|
-
const home =
|
|
24
|
+
// OS account data is independent of inherited USER/HOME and needs no shell.
|
|
25
|
+
const home = os.userInfo().homedir;
|
|
31
26
|
if (home) return home;
|
|
32
27
|
} catch {
|
|
33
|
-
//
|
|
28
|
+
// Account lookup may be unavailable in minimal/container environments.
|
|
34
29
|
}
|
|
35
30
|
return os.homedir();
|
|
36
31
|
}
|
package/src/commands/version.js
CHANGED
|
@@ -59,7 +59,11 @@ export function versionCmd(wrap) {
|
|
|
59
59
|
alias: 'c',
|
|
60
60
|
type: 'boolean',
|
|
61
61
|
describe: 'Check npm registry for newer version',
|
|
62
|
-
})
|
|
62
|
+
})
|
|
63
|
+
.epilogue('Update jsn with the upgrade command:\n'
|
|
64
|
+
+ ' jsn upgrade Update within the current channel\n'
|
|
65
|
+
+ ' jsn upgrade --channel latest Switch to stable\n'
|
|
66
|
+
+ ' jsn upgrade --channel dev Switch to dev'),
|
|
63
67
|
handler: wrap(async (argv, app) => {
|
|
64
68
|
const version = getVersion();
|
|
65
69
|
|