@mdvp/cli 1.3.2 → 1.5.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.
Files changed (2) hide show
  1. package/cli.mjs +29 -17
  2. package/package.json +3 -3
package/cli.mjs CHANGED
@@ -221,13 +221,15 @@ ${BOLD}Docs${R} https://mdvp.tixo-digital.workers.dev/docs
221
221
  `
222
222
 
223
223
  async function cmdHire(opts) {
224
- const { daemon, tabs, local } = opts
225
- const { execSync, spawn } = await import("child_process")
224
+ const { daemon, tabs, local, _url, _once } = opts
225
+ const { spawn } = await import("child_process")
226
226
  const { existsSync } = await import("fs")
227
227
  const dir = `${homedir()}/.mdvp/crawler`
228
228
 
229
- console.log(`${DIM}${ASCII}${R}\n`)
230
- console.log(`${BOLD}Hiring as crawler node...${R}`)
229
+ if (!_once) {
230
+ console.log(`${DIM}${ASCII}${R}\n`)
231
+ console.log(`${BOLD}Hiring as crawler node...${R}`)
232
+ }
231
233
 
232
234
  process.stderr.write(`${DIM}Downloading worker from ${API}...${R}\n`)
233
235
  mkdirSync(dir, { recursive: true })
@@ -264,15 +266,21 @@ async function cmdHire(opts) {
264
266
 
265
267
  const apiUrl = local ? "http://localhost:7227" : API
266
268
  const nodeId = `mdvp-${Math.random().toString(36).slice(2, 8)}`
267
- const env = { ...process.env, NODE_ID: nodeId, TABS: String(tabs || 2), API_URL: apiUrl }
269
+ const env = { ...process.env, NODE_ID: nodeId, TABS: String(tabs || 2), API_URL: apiUrl, ...(_url ? { CRAWL_ONCE: _url } : {}) }
270
+
271
+ if (_once && _url) {
272
+ process.stderr.write(`${DIM}running local crawl for ${_url}...${R}\n`)
273
+ const child = spawn("node", [`${dir}/crawler-worker.mjs`], { env, cwd: dir, stdio: "inherit" })
274
+ await new Promise((res) => child.on("exit", res))
275
+ console.log(`\n ${BOLD}Done!${R} Check: npx @mdvp/cli audit ${_url.replace(/^https?:\/\//, "")}`)
276
+ return
277
+ }
268
278
 
269
279
  if (daemon) {
270
280
  const { openSync } = await import("fs")
271
281
  const log = `${dir}/worker-${process.pid}.log`
272
282
  const out = openSync(log, "a")
273
- const child = spawn("node", [`${dir}/crawler-worker.mjs`], {
274
- env, cwd: dir, detached: true, stdio: ["ignore", out, out],
275
- })
283
+ const child = spawn("node", [`${dir}/crawler-worker.mjs`], { env, cwd: dir, detached: true, stdio: ["ignore", out, out] })
276
284
  child.unref()
277
285
  console.log(`${GREEN}Worker started in background${R}`)
278
286
  console.log(` PID: ${child.pid}`)
@@ -281,23 +289,27 @@ async function cmdHire(opts) {
281
289
  console.log(` Node: ${nodeId}`)
282
290
  } else {
283
291
  console.log(`${GREEN}Starting crawler node ${nodeId}${R} (Ctrl+C to stop)\n`)
284
- const child = spawn("node", [`${dir}/crawler-worker.mjs`], {
285
- env, cwd: dir, stdio: "inherit",
286
- })
292
+ const child = spawn("node", [`${dir}/crawler-worker.mjs`], { env, cwd: dir, stdio: "inherit" })
287
293
  await new Promise((res) => child.on("exit", res))
288
294
  }
289
295
  }
290
296
 
291
297
  async function cmdSubmit(domain, opts) {
292
298
  const { apiKey, local } = opts
293
- if (!apiKey) { console.error(`${RED}No API key. Run: npx mdvp login${R}`); process.exit(1) }
294
299
  domain = parseDomain(domain)
295
- const targetApi = local ? "http://localhost:7227" : API
296
- process.stderr.write(`${DIM}submitting ${domain} → ${local ? "local" : "global"} crawler...${R}\n`)
297
- const d = await apiPost("/crawl/submit", { domain, url: `https://${domain}` }, apiKey, targetApi)
300
+
301
+ if (local) {
302
+ process.stderr.write(`${DIM}crawling ${domain} locally...${R}\n`)
303
+ await cmdHire({ ...opts, domain, daemon: false, _url: `https://${domain}`, _once: true })
304
+ return
305
+ }
306
+
307
+ if (!apiKey) { console.error(`${RED}No API key. Run: npx @mdvp/cli login${R}`); process.exit(1) }
308
+ process.stderr.write(`${DIM}submitting ${domain} → global crawler queue...${R}\n`)
309
+ const d = await apiPost("/crawl/submit", { domain, url: `https://${domain}` }, apiKey)
298
310
  if (d.error) { console.error(`${RED}Error: ${d.error}${R}`); process.exit(1) }
299
- console.log(`\n ${BOLD}Submitted!${R} ${domain} added to crawl queue.`)
300
- console.log(` ${DIM}Results in ~60s. Check: npx mdvp audit ${domain}${R}\n`)
311
+ console.log(`\n ${BOLD}Submitted!${R} ${domain} queued for crawl.`)
312
+ console.log(` ${DIM}Results in ~60s. Check: npx @mdvp/cli audit ${domain}${R}\n`)
301
313
  }
302
314
 
303
315
  async function main() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mdvp/cli",
3
- "version": "1.3.2",
4
- "description": "Machine Design Vision Protocol gives agents eyes to understand design quality",
3
+ "version": "1.5.0",
4
+ "description": "Machine Design Vision Protocol \u2014 gives agents eyes to understand design quality",
5
5
  "bin": {
6
6
  "mdvp": "./cli.mjs"
7
7
  },
@@ -23,4 +23,4 @@
23
23
  },
24
24
  "homepage": "https://mdvp.tixo-digital.workers.dev",
25
25
  "license": "MIT"
26
- }
26
+ }