scanruler-mcp 0.3.0 → 0.4.0

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/src/config.js CHANGED
@@ -3,7 +3,10 @@
3
3
  // has to present, made on the first run and kept in the user's config
4
4
  // folder so it is pasted into ScanRuler's Settings once, not every time —
5
5
  // and the commands the last page that connected had, so an agent that lists
6
- // the tools once, before a page is back, still sees all of them.
6
+ // the tools once, before a page is back, still sees all of them — and the
7
+ // folders the scans were opened from, where its files go. The command list
8
+ // carries the page's version: a server shipped with a newer list of its own
9
+ // lists that one (mcp.js).
7
10
 
8
11
  import { randomBytes } from 'node:crypto'
9
12
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
@@ -22,20 +25,49 @@ export function configDir(env = process.env, platform = process.platform) {
22
25
  /** A new token: 24 random bytes, URL-safe — it travels in a link. */
23
26
  const newToken = () => randomBytes(24).toString('base64url')
24
27
 
25
- /** The command list the last connected page sent, or null. */
28
+ /** The command list the last connected page sent, with the page's version
29
+ * and plugins and when it was kept — `{ commands, version, plugins, saved }`
30
+ * — or null. A list kept by a server before 0.4.0 has no version. */
26
31
  export function loadRemembered(dir = configDir()) {
27
32
  try {
28
33
  const kept = JSON.parse(readFileSync(join(dir, 'tools.json'), 'utf8'))
29
- return Array.isArray(kept.commands) && kept.commands.length > 0 ? kept.commands : null
34
+ if (!Array.isArray(kept.commands) || kept.commands.length === 0) return null
35
+ return {
36
+ commands: kept.commands,
37
+ version: typeof kept.version === 'string' ? kept.version : null,
38
+ plugins: Array.isArray(kept.plugins) ? kept.plugins.map(String) : null,
39
+ saved: typeof kept.saved === 'string' ? kept.saved : null,
40
+ }
41
+ } catch {
42
+ return null
43
+ }
44
+ }
45
+
46
+ /** Keep a page's command list for the next run: `{ commands, version,
47
+ * plugins }` — the page's version, for the next run to tell whether the
48
+ * list it was shipped with is newer — or the list alone. */
49
+ export function saveRemembered(kept, dir = configDir()) {
50
+ const { commands, version = null, plugins = null } = Array.isArray(kept) ? { commands: kept } : kept
51
+ mkdirSync(dir, { recursive: true })
52
+ writeFileSync(join(dir, 'tools.json'), JSON.stringify({ saved: new Date().toISOString(), version, plugins, commands }) + '\n')
53
+ }
54
+
55
+ /** The folders scans and projects were opened from or saved into, the
56
+ * latest first, or null — kept beside the command list, so a copy started
57
+ * afresh still writes and lists where the last one did. */
58
+ export function loadFolders(dir = configDir()) {
59
+ try {
60
+ const kept = JSON.parse(readFileSync(join(dir, 'folders.json'), 'utf8'))
61
+ return Array.isArray(kept.folders) && kept.folders.every((f) => typeof f === 'string') ? kept.folders : null
30
62
  } catch {
31
63
  return null
32
64
  }
33
65
  }
34
66
 
35
- /** Keep a page's command list for the next run. */
36
- export function saveRemembered(commands, dir = configDir()) {
67
+ /** Keep the folders for the next run, and for the other copies. */
68
+ export function saveFolders(folders, dir = configDir()) {
37
69
  mkdirSync(dir, { recursive: true })
38
- writeFileSync(join(dir, 'tools.json'), JSON.stringify({ saved: new Date().toISOString(), commands }) + '\n')
70
+ writeFileSync(join(dir, 'folders.json'), JSON.stringify({ saved: new Date().toISOString(), folders }) + '\n')
39
71
  }
40
72
 
41
73
  /** The stored config, with a token made and saved if there was none. */