@jacebenson/jsn 5.5.7 → 5.5.8

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 (63) hide show
  1. package/README.md +16 -1
  2. package/package.json +5 -6
  3. package/skills/servicenow/SKILL.md +9 -1
  4. package/src/app.js +4 -79
  5. package/src/bounded-reads.js +13 -0
  6. package/src/capabilities.js +8 -3
  7. package/src/cli-adapter.js +26 -3
  8. package/src/cli.js +13 -14
  9. package/src/command-families.js +68 -0
  10. package/src/commands/_generic.js +1 -0
  11. package/src/commands/_ticket.js +1 -1
  12. package/src/commands/actions.js +9 -4
  13. package/src/commands/approvals.js +1 -1
  14. package/src/commands/atf.js +1 -1
  15. package/src/commands/attachments.js +1 -1
  16. package/src/commands/auth.js +21 -2
  17. package/src/commands/codesearch.js +11 -2
  18. package/src/commands/compare.js +22 -0
  19. package/src/commands/customizations.js +3 -4
  20. package/src/commands/decisiontables.js +4 -0
  21. package/src/commands/docs/docs.js +5 -5
  22. package/src/commands/domains.js +1 -1
  23. package/src/commands/eval.js +11 -5
  24. package/src/commands/flows.js +24 -7
  25. package/src/commands/groupmembers.js +1 -1
  26. package/src/commands/grouproles.js +1 -1
  27. package/src/commands/groups.js +1 -1
  28. package/src/commands/midservers.js +4 -11
  29. package/src/commands/perf.js +2 -3
  30. package/src/commands/plugins.js +9 -0
  31. package/src/commands/records.js +12 -2
  32. package/src/commands/scopes.js +1 -1
  33. package/src/commands/scrapi.js +2 -2
  34. package/src/commands/setup.js +4 -34
  35. package/src/commands/skipped-updates.js +2 -3
  36. package/src/commands/store.js +4 -1
  37. package/src/commands/subscriptions.js +47 -0
  38. package/src/commands/tickets.js +1 -1
  39. package/src/commands/users.js +1 -1
  40. package/src/commands/workflows.js +3 -5
  41. package/src/config.js +1 -0
  42. package/src/context.js +8 -56
  43. package/src/docs-links.js +28 -0
  44. package/src/flow-create.js +9 -0
  45. package/src/help.js +4 -0
  46. package/src/helpers.js +17 -24
  47. package/src/instance-inventory.js +184 -0
  48. package/src/intended-context.js +68 -0
  49. package/src/mutation-context.js +69 -46
  50. package/src/output.js +1 -1
  51. package/src/paginated-search.js +146 -178
  52. package/src/picker-ui.js +20 -0
  53. package/src/prompt-engine.js +176 -0
  54. package/src/prompts.js +293 -43
  55. package/src/records/inspect.js +30 -16
  56. package/src/records-engine.js +2 -2
  57. package/src/schedule-cache.js +96 -0
  58. package/src/schedules/itom-2026-04-09.json +121 -0
  59. package/src/schedules/public-inventory.json +6224 -0
  60. package/src/sdk-batch.js +2 -1
  61. package/src/sdk.js +42 -16
  62. package/src/setup-preferences.js +2 -2
  63. package/src/subscriptions.js +176 -0
@@ -0,0 +1,96 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { createHash, randomUUID } from 'node:crypto';
4
+ import { cacheDir } from './config.js';
5
+ import { AppError } from './errors.js';
6
+
7
+ const MAX = 4 * 1024 * 1024;
8
+ const digest = bytes => createHash('sha256').update(bytes).digest('hex');
9
+ const fail = message => { throw new AppError('invalid_catalog', message); };
10
+ const file = () => path.join(cacheDir(), 'subscription-schedules-v1.json');
11
+ const hash = value => typeof value === 'string' && /^[a-f0-9]{64}$/.test(value);
12
+ export function validateCatalog(catalog) {
13
+ const checkDepth = (value, depth = 0) => {
14
+ if (depth > 32) fail('Catalog nesting exceeds schema limit.');
15
+ if (value && typeof value === 'object') for (const child of Object.values(value)) checkDepth(child, depth + 1);
16
+ };
17
+ checkDepth(catalog);
18
+ if (catalog?.schema_version !== 1 || !hash(catalog.revision) || !Array.isArray(catalog.schedules) || !catalog.schedules.length) fail('Invalid catalog schema.');
19
+ const ids = new Set();
20
+ for (const r of catalog.schedules) {
21
+ if (!r || typeof r.id !== 'string' || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(r.id) || ids.has(r.id) || typeof r.product !== 'string' || !r.product.trim()) fail('Invalid or duplicate schedule ID/product.');
22
+ ids.add(r.id);
23
+ for (const key of ['title', 'source_version', 'effective_date', 'applicability', 'measurement', 'normalization_status']) {
24
+ if (r[key] !== undefined && r[key] !== null && typeof r[key] !== 'string') fail(`Invalid record ${key}.`);
25
+ }
26
+ for (const key of ['source_sections', 'skus', 'unknowns', 'exceptions', 'limitations']) {
27
+ if (r[key] !== undefined && (!Array.isArray(r[key]) || r[key].some(v => typeof v !== 'string'))) fail(`Invalid record ${key}.`);
28
+ }
29
+ if (r.definitions !== undefined && (!r.definitions || typeof r.definitions !== 'object')) fail('Invalid definitions.');
30
+ if (Array.isArray(r.definitions) && r.definitions.some(d => !d || typeof d.term !== 'string' || typeof d.definition !== 'string' || !Array.isArray(d.source_sections) || d.source_sections.some(v => typeof v !== 'string'))) fail('Invalid definition provenance.');
31
+ if (r.meter !== undefined && (!r.meter || typeof r.meter !== 'object' || Array.isArray(r.meter))) fail('Invalid meter.');
32
+ if (r.meter?.rules !== undefined && (!Array.isArray(r.meter.rules) || r.meter.rules.some(v => !v || typeof v !== 'object' || Array.isArray(v)))) fail('Invalid meter rules.');
33
+ for (const key of ['packages', 'entitlements', 'section_coverage', 'capability_lists']) {
34
+ if (r[key] !== undefined && (!r[key] || typeof r[key] !== 'object')) fail(`Invalid record ${key}.`);
35
+ }
36
+ let source;
37
+ try { source = new URL(r.source_url); } catch { fail('Missing source provenance.'); }
38
+ if (source.protocol !== 'https:' || source.hostname !== 'www.servicenow.com' || source.username || source.password || !source.pathname.endsWith('.pdf') || !Number.isFinite(Date.parse(r.retrieved_at || r.fetched_at))) fail('Unsafe or missing source provenance.');
39
+ if (r.id !== 'itom-2026-04-09' && (!Array.isArray(r.source_sections) || !r.source_sections.length || !Array.isArray(r.skus) || !['normalized', 'partial'].includes(r.normalization_status))) fail('Invalid normalized record schema.');
40
+ }
41
+ return catalog;
42
+ }
43
+ function safeURL(value, origin) {
44
+ let u;
45
+ try { u = new URL(value); } catch { fail('Invalid catalog URL.'); }
46
+ if (u.username || u.password || u.hash || (u.protocol !== 'https:' && !(u.protocol === 'http:' && ['127.0.0.1', '[::1]', 'localhost'].includes(u.hostname))) || (origin && u.origin !== origin)) fail('Catalog URL must use HTTPS and the approved manifest origin (explicit loopback HTTP is allowed).');
47
+ return u;
48
+ }
49
+ async function download(url, cap) {
50
+ const response = await fetch(url, { redirect: 'error', signal: AbortSignal.timeout(10000), credentials: 'omit' });
51
+ if (!response.ok) fail(`Catalog HTTP ${response.status}.`);
52
+ if (Number(response.headers.get('content-length')) > cap) fail('Catalog exceeds size cap.');
53
+ const chunks = []; let size = 0;
54
+ for await (const chunk of response.body) {
55
+ size += chunk.length;
56
+ if (size > cap) { fail('Catalog exceeds size cap.'); }
57
+ chunks.push(chunk);
58
+ }
59
+ return Buffer.concat(chunks);
60
+ }
61
+ export async function refreshSchedules(manifestURL) {
62
+ if (!manifestURL) fail('Specify --manifest-url or configure JSN_DOCS_URL / global docs.url.');
63
+ const url = safeURL(manifestURL);
64
+ const manifest = JSON.parse(await download(url, 16384));
65
+ if (manifest.schema_version !== 1 || !hash(manifest.revision) || !hash(manifest.sha256) || !Number.isSafeInteger(manifest.bytes) || manifest.bytes < 1 || manifest.bytes > MAX || !Number.isFinite(Date.parse(manifest.published_at))) fail('Invalid manifest schema or size.');
66
+ const artifactURL = safeURL(manifest.catalog_url, url.origin);
67
+ const bytes = await download(artifactURL, MAX);
68
+ if (bytes.length !== manifest.bytes || digest(bytes) !== manifest.sha256) fail('Catalog byte length or SHA256 mismatch.');
69
+ const text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
70
+ const catalog = validateCatalog(JSON.parse(text));
71
+ if (catalog.revision !== manifest.revision) fail('Catalog revision mismatch.');
72
+ const entry = { manifest, manifest_url: url.href, retrieved_at: new Date().toISOString(), artifact: text };
73
+ const serialized = JSON.stringify(entry);
74
+ if (Buffer.byteLength(serialized) > MAX * 2) fail('Serialized cache exceeds size cap.');
75
+ fs.mkdirSync(path.dirname(file()), { recursive: true, mode: 0o700 });
76
+ const temp = `${file()}.${randomUUID()}.tmp`;
77
+ try { fs.writeFileSync(temp, serialized, { mode: 0o600, flag: 'wx' }); fs.renameSync(temp, file()); }
78
+ finally { fs.rmSync(temp, { force: true }); }
79
+ return cachedSchedules().provenance;
80
+ }
81
+ export function cachedSchedules() {
82
+ try {
83
+ if (fs.statSync(file()).size > MAX * 2) return null;
84
+ const entry = JSON.parse(fs.readFileSync(file(), 'utf8'));
85
+ const m = entry.manifest;
86
+ if (m?.schema_version !== 1 || !hash(m.revision) || !hash(m.sha256) || !Number.isSafeInteger(m.bytes) || m.bytes < 1 || m.bytes > MAX || !Number.isFinite(Date.parse(m.published_at))) return null;
87
+ const approved = safeURL(entry.manifest_url);
88
+ safeURL(m.catalog_url, approved.origin);
89
+ if (typeof entry.artifact !== 'string') return null;
90
+ const bytes = Buffer.from(entry.artifact);
91
+ if (bytes.length > MAX || bytes.length !== entry.manifest.bytes || digest(bytes) !== entry.manifest.sha256) return null;
92
+ const catalog = validateCatalog(JSON.parse(bytes));
93
+ if (catalog.revision !== entry.manifest.revision || !Number.isFinite(Date.parse(entry.retrieved_at))) return null;
94
+ return { schedules: catalog.schedules, provenance: { source: 'validated-cache', revision: catalog.revision, sha256: entry.manifest.sha256, retrieved_at: entry.retrieved_at, manifest_url: entry.manifest_url, stale: Date.now() - Date.parse(entry.retrieved_at) > 86400000, freshness: 'last-good snapshot; no network freshness check' } };
95
+ } catch { return null; }
96
+ }
@@ -0,0 +1,121 @@
1
+ {
2
+ "id": "itom-2026-04-09",
3
+ "product": "ITOM",
4
+ "effective_for_skus_introduced": "2026-04-09",
5
+ "source_url": "https://www.servicenow.com/content/dam/servicenow-assets/public/en-us/doc-type/legal/it-operations-management-itom-servicenow-subscription-unit-overview.pdf",
6
+ "source_version": "Effective for SKUs introduced on April 9, 2026; sections 1.1 and 1.2",
7
+ "fetched_at": "2026-11-19T07:47:54.276651+00:00",
8
+ "retrieval": "Independent web_extract PDF text retrieval; direct download returned 403. Binary hash unavailable.",
9
+ "categories": [
10
+ {
11
+ "id": "server",
12
+ "resources_per_su": 1,
13
+ "classes": [
14
+ "cmdb_ci_server",
15
+ "cmdb_ci_vm_instance",
16
+ "cmdb_ci_ucs_rack_unit",
17
+ "cmdb_ci_ucs_blade",
18
+ "cmdb_ci_mainframe_hardware"
19
+ ]
20
+ },
21
+ {
22
+ "id": "paas",
23
+ "resources_per_su": 3,
24
+ "classes": [
25
+ "cmdb_ci_cloud_appserver",
26
+ "cmdb_ci_could_database",
27
+ "cmdb_ci_dynamodb_table",
28
+ "cmdb_ci_cloud_directory",
29
+ "cmdb_ci_cloud_gateway",
30
+ "cmdb_ci_cloud_messaging_service",
31
+ "cmdb_ci_cloud_webserver"
32
+ ]
33
+ },
34
+ {
35
+ "id": "container",
36
+ "resources_per_su": 10,
37
+ "classes": [
38
+ "cmdb_ci_oslv_container"
39
+ ]
40
+ },
41
+ {
42
+ "id": "image",
43
+ "resources_per_su": 3,
44
+ "classes": [
45
+ "cmdb_ci_oslv_image",
46
+ "cmdb_ci_oslv_local_image",
47
+ "cmdb_ci_openshift_images"
48
+ ]
49
+ },
50
+ {
51
+ "id": "end_user_device",
52
+ "resources_per_su": 4,
53
+ "classes": [
54
+ "cmdb_ci_computer"
55
+ ]
56
+ },
57
+ {
58
+ "id": "faas",
59
+ "resources_per_su": 20,
60
+ "classes": [
61
+ "cmdb_ci_cloud_function"
62
+ ]
63
+ },
64
+ {
65
+ "id": "gpu",
66
+ "resources_per_su": 1,
67
+ "classes": [
68
+ "cmdb_ci_gpu"
69
+ ]
70
+ },
71
+ {
72
+ "id": "api",
73
+ "resources_per_su": 1,
74
+ "classes": [
75
+ "cmdb_ci_api"
76
+ ]
77
+ },
78
+ {
79
+ "id": "ai_agent",
80
+ "resources_per_su": 3,
81
+ "classes": [
82
+ "cmdb_ci_function_ai"
83
+ ]
84
+ },
85
+ {
86
+ "id": "service_instance",
87
+ "resources_per_su": 1,
88
+ "classes": [
89
+ "cmdb_ci_service_auto"
90
+ ]
91
+ },
92
+ {
93
+ "id": "unresolved_object",
94
+ "resources_per_su": 4,
95
+ "classes": []
96
+ }
97
+ ],
98
+ "definitions": {
99
+ "provenance": "Paraphrases of section 1.1, not independent eligibility rules. All CI resource types must be represented in the listed classes or descendants and managed by an ITOM application.",
100
+ "server": "Physical or virtual server.",
101
+ "paas": "Cloud-based platform service.",
102
+ "container": "Operating system-level virtualization.",
103
+ "image": "Operating system-level virtualization image.",
104
+ "end_user_device": "Physical or virtual computing device not defined as another Managed IT Resource Type, with an ITOM component such as Agent Client Collector installed.",
105
+ "faas": "Serverless compute function-as-a-service instance.",
106
+ "gpu": "Graphics Processing Unit.",
107
+ "api": "Application programming interface.",
108
+ "ai_agent": "Service for machine learning, data processing and AI-driven tasks.",
109
+ "service_instance": "Interconnected applications and IT resources configured to offer a digital service.",
110
+ "unresolved_object": "IT resource receiving an ITOM event, performance metric or log, not represented as a CMDB CI; recorded in em_unique_nodes with type=unknown. Counting this source is unsupported in this slice."
111
+ },
112
+ "unresolved_mapping": "cmdb_ci_could_database is literal source text; no corrected mapping is assumed.",
113
+ "limitations": [
114
+ "CMDB populations are not managed or billable counts, nor a ceiling.",
115
+ "Managed-by-ITOM eligibility and product scope are unverified.",
116
+ "End-user devices require an installed ITOM component and exclusion of other resource types.",
117
+ "Container/image relationship exclusions are not evaluated.",
118
+ "Rounding and contract applicability are unknown.",
119
+ "Observed 90-day usage and purchased entitlements are not implemented."
120
+ ]
121
+ }