@snutils/snu 0.1.4 → 0.1.6
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/LICENSE.md +7 -0
- package/README.md +91 -7
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +17 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/updateCheck.d.ts +23 -0
- package/dist/cli/updateCheck.d.ts.map +1 -0
- package/dist/cli/updateCheck.js +133 -0
- package/dist/cli/updateCheck.js.map +1 -0
- package/package.json +4 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# SN Utils Service Terms
|
|
2
|
+
|
|
3
|
+
Copyright © 2020–2026 SN Utils B.V. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Use of `@snutils/snu`, sn-scriptsync, and associated SN Utils components is governed by the [SN Utils Service Terms](https://snutils.com/legal/service-terms).
|
|
6
|
+
|
|
7
|
+
Third-party software included in or referenced by this package remains subject to its own license terms.
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Unified CLI and Model Context Protocol (MCP) server for ServiceNow development,
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- **Zero Manual Credentials:** Connects to your live browser session via SN Utils, automatically inheriting authenticated SSO/MFA sessions, cookies, update set, and application scope.
|
|
10
|
-
- **Dual Mode (CLI + MCP):** Use it as a terminal command tool (`snu query`, `snu search`, `snu schema`) or as
|
|
10
|
+
- **Dual Mode (CLI + MCP):** Use it as a terminal command tool (`snu query`, `snu search`, `snu schema`) or as a local stdio MCP server (`snu --mcp`) in any compatible AI client.
|
|
11
11
|
- **Works Attached & Standalone:** Operates seamlessly when VS Code is open (Attached Mode), or completely standalone without VS Code (Standalone Mode with in-process bridge and auto-handover).
|
|
12
12
|
- **14 Strictly-Typed Tools:** Fast GraphQL code search, schema dictionary inspection, record queries, CRUD operations, background script execution, and live form automation.
|
|
13
13
|
|
|
@@ -48,22 +48,29 @@ snu run "gs.print('Hello from ' + gs.getUserName());"
|
|
|
48
48
|
|
|
49
49
|
---
|
|
50
50
|
|
|
51
|
-
## 2.
|
|
51
|
+
## 2. Use as an MCP Server
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
`@snutils/snu` exposes the same ServiceNow capabilities as 14 MCP tools. The MCP client starts `snu --mcp` as a local stdio process; no remote MCP endpoint or API key is required.
|
|
54
|
+
|
|
55
|
+
### Configure your MCP client
|
|
56
|
+
|
|
57
|
+
Add this server to your client's MCP configuration. Depending on the client, this may be an `mcp.json`, `claude_desktop_config.json`, project setting, or an **Add MCP server** screen.
|
|
58
|
+
|
|
59
|
+
Using `npx` is the easiest option because it does not require a global installation:
|
|
54
60
|
|
|
55
61
|
```json
|
|
56
62
|
{
|
|
57
63
|
"mcpServers": {
|
|
58
64
|
"sn-utils": {
|
|
59
65
|
"command": "npx",
|
|
60
|
-
"args": ["-
|
|
66
|
+
"args": ["--yes", "--prefer-online", "@snutils/snu@latest", "--mcp"]
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
```
|
|
65
71
|
|
|
66
|
-
|
|
72
|
+
If the package is installed globally, use the shorter command:
|
|
73
|
+
|
|
67
74
|
```json
|
|
68
75
|
{
|
|
69
76
|
"mcpServers": {
|
|
@@ -75,7 +82,84 @@ Or if installed globally:
|
|
|
75
82
|
}
|
|
76
83
|
```
|
|
77
84
|
|
|
78
|
-
|
|
85
|
+
Restart or refresh the MCP client after changing its configuration. The server should appear as `sn-utils` with 14 tools. `@latest` with `--prefer-online` checks npm for a newer release each time the MCP process starts; a running MCP process is never replaced underneath an active session.
|
|
86
|
+
|
|
87
|
+
### Connect a ServiceNow instance
|
|
88
|
+
|
|
89
|
+
1. Start or enable the `sn-utils` server in your MCP client.
|
|
90
|
+
2. Open the ServiceNow instance in a browser where you are already signed in.
|
|
91
|
+
3. Run `/token` from the SN Utils slash command box. This opens the ScriptSync and AI Agent Helper tab.
|
|
92
|
+
4. Keep the helper tab open while the agent is working.
|
|
93
|
+
5. Ask the agent to call `snu_get_context` before doing other work. It reports the connected instance, helper status, license tier, and effective permission gates.
|
|
94
|
+
|
|
95
|
+
You normally do **not** need to run `snu serve` separately. `snu --mcp` first looks for the ScriptSync bridge supplied by VS Code or an existing standalone daemon. If neither is available, it starts an in-process standalone bridge automatically. Run `snu serve` only when you also want a persistent bridge for separate terminal commands.
|
|
96
|
+
|
|
97
|
+
The `/token` connection must be made after a bridge is running. If the MCP client or standalone bridge is restarted, run `/token` again. Session credentials remain in memory and are cleared when the helper disconnects.
|
|
98
|
+
|
|
99
|
+
### Try it from your agent
|
|
100
|
+
|
|
101
|
+
Example prompts:
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
Use snu_get_context and summarize the connected ServiceNow instance and permission gates.
|
|
105
|
+
|
|
106
|
+
Inspect the incident table schema, then query five active priority 1 incidents.
|
|
107
|
+
|
|
108
|
+
Find active Script Includes containing "GlideRecordSecure" and summarize what they do.
|
|
109
|
+
|
|
110
|
+
Read the current incident form and explain which fields are populated. Do not change anything.
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
When more than one instance is connected, tell the agent which instance to use or pass the optional `instance` argument to a tool.
|
|
114
|
+
|
|
115
|
+
### Available MCP tools
|
|
116
|
+
|
|
117
|
+
| Category | Tools | Purpose |
|
|
118
|
+
| --- | --- | --- |
|
|
119
|
+
| Connection | `snu_get_context` | Inspect the bridge, helper, instances, license, and permission gates. |
|
|
120
|
+
| Schema and search | `snu_get_schema`, `snu_code_search` | Inspect table metadata and search server-side code. Code Search requires SN Utils Pro. |
|
|
121
|
+
| Record reads | `snu_query_records`, `snu_get_record` | Query tables or fetch a record by `sys_id`. |
|
|
122
|
+
| Record writes | `snu_create_artifact`, `snu_update_record`, `snu_delete_record` | Create scriptable artifacts, update fields, or delete a record. |
|
|
123
|
+
| Server execution | `snu_run_background_script` | Run server-side JavaScript and return its captured output. |
|
|
124
|
+
| Browser and forms | `snu_get_form_state`, `snu_set_form_field`, `snu_run_ui_action`, `snu_navigate`, `snu_take_screenshot` | Inspect and operate the connected ServiceNow browser tab. |
|
|
125
|
+
|
|
126
|
+
### Permissions and human review
|
|
127
|
+
|
|
128
|
+
The helper tab applies permissions per ServiceNow instance:
|
|
129
|
+
|
|
130
|
+
- **Off** blocks that class of operation.
|
|
131
|
+
- **Approve** sends high-risk operations to the helper's Review Queue for one-time approval.
|
|
132
|
+
- **Auto** allows that operation without a review prompt.
|
|
133
|
+
|
|
134
|
+
Standalone mode also has fail-closed host gates. Background Scripts, record deletion, REST writes, and browser debugger access are disabled by default; artifact creation is enabled by default. Both the host gate and the instance gate must allow an operation.
|
|
135
|
+
|
|
136
|
+
For an MCP process, host gates can be enabled through environment variables in clients that support an `env` block. Only enable the capabilities you intend to give the agent:
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"mcpServers": {
|
|
141
|
+
"sn-utils": {
|
|
142
|
+
"command": "npx",
|
|
143
|
+
"args": ["--yes", "--prefer-online", "@snutils/snu@latest", "--mcp"],
|
|
144
|
+
"env": {
|
|
145
|
+
"SNU_ALLOW_BACKGROUND_SCRIPTS": "1"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Supported host settings are `SNU_ALLOW_BACKGROUND_SCRIPTS`, `SNU_ALLOW_DELETE_RECORDS`, `SNU_ALLOW_CREATE_ARTIFACTS`, `SNU_ALLOW_BROWSER_DEBUGGER`, and `SNU_ALLOW_REST_REQUEST`. Global defaults can alternatively be stored in `~/.sn-scriptsync/settings.json`.
|
|
153
|
+
|
|
154
|
+
Interactive CLI commands check for a newer release at most once every 24 hours and print an update hint when one is available. MCP, JSON output, CI, and npm offline mode never perform this check. Set `SNU_DISABLE_UPDATE_CHECK=1` to opt out explicitly.
|
|
155
|
+
|
|
156
|
+
### MCP troubleshooting
|
|
157
|
+
|
|
158
|
+
- **`Missing instance URL or authentication token`:** make sure the MCP server is running, then run `/token` again from the intended ServiceNow instance.
|
|
159
|
+
- **`E_BROWSER_DISCONNECTED`:** reopen the helper with `/token` and leave that tab open.
|
|
160
|
+
- **An operation is disabled:** check both the host setting and the matching per-instance permission in the helper's Agent Access tab.
|
|
161
|
+
- **The MCP server is not listed:** refresh or restart the MCP client after editing its configuration. With a global install, verify that the client can resolve `snu`; otherwise use the `npx` configuration.
|
|
162
|
+
- **Multiple instances are connected:** pass the tool's `instance` argument or name the target instance in the prompt.
|
|
79
163
|
|
|
80
164
|
---
|
|
81
165
|
|
|
@@ -162,4 +246,4 @@ Session credentials stay on your machine. The standalone bridge keeps the `/toke
|
|
|
162
246
|
|
|
163
247
|
## License
|
|
164
248
|
|
|
165
|
-
|
|
249
|
+
Copyright © 2020–2026 SN Utils B.V. All rights reserved. Use of this package is governed by the [SN Utils Service Terms](https://snutils.com/legal/service-terms).
|
package/dist/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,OAAO,QAA0B,CAAC;AAY/C,wBAAgB,SAAS,IAAI,IAAI,CAoChC;AAED,wBAAsB,MAAM,CAAC,IAAI,WAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+QxE"}
|
package/dist/cli/index.js
CHANGED
|
@@ -45,8 +45,19 @@ const stdin_js_1 = require("./stdin.js");
|
|
|
45
45
|
const format_js_1 = require("./format.js");
|
|
46
46
|
const index_js_1 = require("../mcp/index.js");
|
|
47
47
|
const standalone_js_1 = require("../server/standalone.js");
|
|
48
|
+
const updateCheck_js_1 = require("./updateCheck.js");
|
|
48
49
|
const packageMetadata = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../package.json'), 'utf8'));
|
|
49
50
|
exports.VERSION = packageMetadata.version;
|
|
51
|
+
function startUpdateCheck(enabled) {
|
|
52
|
+
if (!enabled || !(0, updateCheck_js_1.shouldCheckForUpdates)())
|
|
53
|
+
return Promise.resolve(undefined);
|
|
54
|
+
return (0, updateCheck_js_1.getUpdateNotice)({ currentVersion: exports.VERSION });
|
|
55
|
+
}
|
|
56
|
+
async function printUpdateNotice(noticePromise) {
|
|
57
|
+
const notice = await noticePromise;
|
|
58
|
+
if (notice)
|
|
59
|
+
process.stderr.write(notice);
|
|
60
|
+
}
|
|
50
61
|
function printHelp() {
|
|
51
62
|
console.log(`
|
|
52
63
|
\x1b[1mSN Utils CLI (snu)\x1b[0m — Unified CLI and MCP Bridge for ServiceNow
|
|
@@ -92,10 +103,12 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
92
103
|
}
|
|
93
104
|
if (argv.includes('-h') || argv.includes('--help') || argv.length === 0) {
|
|
94
105
|
printHelp();
|
|
106
|
+
await printUpdateNotice(startUpdateCheck(true));
|
|
95
107
|
return;
|
|
96
108
|
}
|
|
97
109
|
if (argv.includes('-v') || argv.includes('--version')) {
|
|
98
110
|
console.log(`snu v${exports.VERSION}`);
|
|
111
|
+
await printUpdateNotice(startUpdateCheck(true));
|
|
99
112
|
return;
|
|
100
113
|
}
|
|
101
114
|
let isJsonMode = argv.includes('-j') || argv.includes('--json');
|
|
@@ -126,8 +139,10 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
126
139
|
}
|
|
127
140
|
if (nonGlobalTokens.length === 0) {
|
|
128
141
|
printHelp();
|
|
142
|
+
await printUpdateNotice(startUpdateCheck(!isJsonMode));
|
|
129
143
|
return;
|
|
130
144
|
}
|
|
145
|
+
const updateNotice = startUpdateCheck(!isJsonMode);
|
|
131
146
|
// Handle standalone daemon command: snu serve
|
|
132
147
|
if (nonGlobalTokens[0] === 'serve') {
|
|
133
148
|
const standalone = new standalone_js_1.StandaloneBridge({
|
|
@@ -143,6 +158,7 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
143
158
|
console.log(` • HTTP API: http://127.0.0.1:${httpPort}/api`);
|
|
144
159
|
console.log(` • WebSocket: ws://127.0.0.1:${wsPort} (connect via SN Utils helper tab)`);
|
|
145
160
|
console.log(`\n\x1b[90mRunning standalone. Press Ctrl+C to stop.\x1b[0m\n`);
|
|
161
|
+
await printUpdateNotice(updateNotice);
|
|
146
162
|
}
|
|
147
163
|
catch (err) {
|
|
148
164
|
(0, format_js_1.outputError)(err, false);
|
|
@@ -323,6 +339,7 @@ async function runCli(argv = process.argv.slice(2)) {
|
|
|
323
339
|
else {
|
|
324
340
|
process.stdout.write((0, format_js_1.formatHumanOutput)(tool.agentCommand, result));
|
|
325
341
|
}
|
|
342
|
+
await printUpdateNotice(updateNotice);
|
|
326
343
|
}
|
|
327
344
|
catch (err) {
|
|
328
345
|
(0, format_js_1.outputError)(err, isJsonMode);
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,8BAoCC;AAED,wBA+QC;AAhVD,+BAAiC;AACjC,uCAAyB;AACzB,2CAA6B;AAC7B,gDAA4D;AAC5D,4CAAuE;AACvE,yCAAiD;AACjD,2CAAyE;AACzE,8CAAiD;AACjD,2DAA2D;AAC3D,qDAA0E;AAE1E,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAChC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC,CAChD,CAAC;AAEZ,QAAA,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC;AAE/C,SAAS,gB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AG,EAAE,UAAU,CAAC,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface UpdateResponse {
|
|
2
|
+
ok: boolean;
|
|
3
|
+
json(): Promise<{
|
|
4
|
+
version?: unknown;
|
|
5
|
+
}>;
|
|
6
|
+
}
|
|
7
|
+
type UpdateFetch = (url: string, init: {
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
}) => Promise<UpdateResponse>;
|
|
10
|
+
export interface UpdateCheckOptions {
|
|
11
|
+
currentVersion: string;
|
|
12
|
+
cacheFile?: string;
|
|
13
|
+
now?: number;
|
|
14
|
+
intervalMs?: number;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
fetchImpl?: UpdateFetch;
|
|
17
|
+
}
|
|
18
|
+
export declare function getUpdateCacheFile(): string;
|
|
19
|
+
export declare function shouldCheckForUpdates(env?: NodeJS.ProcessEnv, stderrIsTty?: boolean): boolean;
|
|
20
|
+
export declare function isNewerVersion(candidate: string, current: string): boolean;
|
|
21
|
+
export declare function getUpdateNotice(options: UpdateCheckOptions): Promise<string | undefined>;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=updateCheck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateCheck.d.ts","sourceRoot":"","sources":["../../src/cli/updateCheck.ts"],"names":[],"mappings":"AAaA,UAAU,cAAc;IACtB,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,IAAI,OAAO,CAAC;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACxC;AAED,KAAK,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAE3F,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,WAAW,CAAC;CACzB;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAgB,qBAAqB,CACnC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,WAAW,GAAE,OAAuC,GACnD,OAAO,CAKT;AAWD,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAY1E;AAwBD,wBAAsB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA+B9F"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getUpdateCacheFile = getUpdateCacheFile;
|
|
37
|
+
exports.shouldCheckForUpdates = shouldCheckForUpdates;
|
|
38
|
+
exports.isNewerVersion = isNewerVersion;
|
|
39
|
+
exports.getUpdateNotice = getUpdateNotice;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const os = __importStar(require("os"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const REGISTRY_URL = 'https://registry.npmjs.org/@snutils%2Fsnu/latest';
|
|
44
|
+
const DEFAULT_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
45
|
+
const DEFAULT_TIMEOUT_MS = 800;
|
|
46
|
+
function getUpdateCacheFile() {
|
|
47
|
+
return path.join(os.homedir(), '.sn-scriptsync', 'snu-update-check.json');
|
|
48
|
+
}
|
|
49
|
+
function shouldCheckForUpdates(env = process.env, stderrIsTty = process.stderr.isTTY === true) {
|
|
50
|
+
if (!stderrIsTty)
|
|
51
|
+
return false;
|
|
52
|
+
if (env.CI || env.NO_UPDATE_NOTIFIER || env.SNU_DISABLE_UPDATE_CHECK)
|
|
53
|
+
return false;
|
|
54
|
+
if (env.npm_config_offline === 'true' || env.npm_config_offline === '1')
|
|
55
|
+
return false;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
function parseVersion(version) {
|
|
59
|
+
const match = version.trim().replace(/^v/, '').match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/);
|
|
60
|
+
if (!match)
|
|
61
|
+
return undefined;
|
|
62
|
+
return {
|
|
63
|
+
numbers: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
64
|
+
prerelease: match[4] || null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function isNewerVersion(candidate, current) {
|
|
68
|
+
const next = parseVersion(candidate);
|
|
69
|
+
const installed = parseVersion(current);
|
|
70
|
+
if (!next || !installed)
|
|
71
|
+
return false;
|
|
72
|
+
for (let i = 0; i < next.numbers.length; i++) {
|
|
73
|
+
if (next.numbers[i] !== installed.numbers[i]) {
|
|
74
|
+
return next.numbers[i] > installed.numbers[i];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return installed.prerelease !== null && next.prerelease === null;
|
|
78
|
+
}
|
|
79
|
+
function readCache(cacheFile) {
|
|
80
|
+
try {
|
|
81
|
+
const parsed = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
|
|
82
|
+
if (typeof parsed.checkedAt !== 'number')
|
|
83
|
+
return undefined;
|
|
84
|
+
return {
|
|
85
|
+
checkedAt: parsed.checkedAt,
|
|
86
|
+
latestVersion: typeof parsed.latestVersion === 'string' ? parsed.latestVersion : undefined,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function writeCache(cacheFile, cache) {
|
|
94
|
+
try {
|
|
95
|
+
fs.mkdirSync(path.dirname(cacheFile), { recursive: true });
|
|
96
|
+
fs.writeFileSync(cacheFile, JSON.stringify(cache), { encoding: 'utf8', mode: 0o600 });
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Update checks must never interfere with the requested CLI command.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function getUpdateNotice(options) {
|
|
103
|
+
const now = options.now ?? Date.now();
|
|
104
|
+
const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
105
|
+
const cacheFile = options.cacheFile ?? getUpdateCacheFile();
|
|
106
|
+
const cached = readCache(cacheFile);
|
|
107
|
+
if (cached && now - cached.checkedAt < intervalMs)
|
|
108
|
+
return undefined;
|
|
109
|
+
const controller = new AbortController();
|
|
110
|
+
const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
111
|
+
let latestVersion;
|
|
112
|
+
try {
|
|
113
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
114
|
+
const response = await fetchImpl(REGISTRY_URL, { signal: controller.signal });
|
|
115
|
+
if (response.ok) {
|
|
116
|
+
const payload = await response.json();
|
|
117
|
+
if (typeof payload.version === 'string')
|
|
118
|
+
latestVersion = payload.version;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Network availability must not affect CLI behavior.
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
writeCache(cacheFile, { checkedAt: now, latestVersion });
|
|
127
|
+
}
|
|
128
|
+
if (!latestVersion || !isNewerVersion(latestVersion, options.currentVersion))
|
|
129
|
+
return undefined;
|
|
130
|
+
return (`\nUpdate available: snu v${options.currentVersion} -> v${latestVersion}\n` +
|
|
131
|
+
'Run: npm install -g @snutils/snu@latest\n');
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=updateCheck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateCheck.js","sourceRoot":"","sources":["../../src/cli/updateCheck.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,gDAEC;AAED,sDAQC;AAWD,wCAYC;AAwBD,0CA+BC;AAvHD,uCAAyB;AACzB,uCAAyB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C;QAC3E,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,qDAAqD;IACvD,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,UAAU,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,CAAC,aAAa,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,OAAO,CAAC,cAAc,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/F,OAAO,CACL,4BAA4B,OAAO,CAAC,cAAc,QAAQ,aAAa,IAAI;QAC3E,2CAA2C,CAC5C,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snutils/snu",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Unified CLI and Model Context Protocol (MCP) server for SN Utils and ScriptSync",
|
|
5
5
|
"author": "Arnoud Kooi <arnoud@snutils.com>",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"dist",
|
|
17
17
|
"!dist/test",
|
|
18
18
|
"bin",
|
|
19
|
-
"README.md"
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE.md"
|
|
20
21
|
],
|
|
21
22
|
"engines": {
|
|
22
23
|
"node": ">=20.0.0"
|