@miphamai/cli 0.16.2 → 0.16.3
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/bin/mipham.ts +61 -0
- package/package.json +1 -1
package/bin/mipham.ts
CHANGED
|
@@ -331,6 +331,32 @@ async function main() {
|
|
|
331
331
|
process.exit(0)
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
+
// ── Help flag ─────────────────────────────────────────────────────────────
|
|
335
|
+
if (
|
|
336
|
+
process.argv.includes('--help') ||
|
|
337
|
+
process.argv.includes('-h') ||
|
|
338
|
+
process.argv.slice(2).some((a) => a === 'help')
|
|
339
|
+
) {
|
|
340
|
+
console.log(`Mipham Code — AI-powered coding terminal
|
|
341
|
+
|
|
342
|
+
Usage:
|
|
343
|
+
mipham Launch interactive CLI
|
|
344
|
+
mipham update Update to the latest version
|
|
345
|
+
mipham upgrade Same as 'mipham update'
|
|
346
|
+
mipham plugin <cmd> Plugin management (install, list, remove, etc.)
|
|
347
|
+
mipham workflow <cmd> Workflow orchestration (run, list, resume, etc.)
|
|
348
|
+
mipham --version Print version and exit
|
|
349
|
+
mipham --help Show this help
|
|
350
|
+
|
|
351
|
+
Flags:
|
|
352
|
+
--safe-mode Skip custom agents, skills, hooks, plugins
|
|
353
|
+
--version, -v, -V Print version
|
|
354
|
+
|
|
355
|
+
Docs: https://mipham.ai/code
|
|
356
|
+
npm: https://www.npmjs.com/package/@miphamai/cli`)
|
|
357
|
+
process.exit(0)
|
|
358
|
+
}
|
|
359
|
+
|
|
334
360
|
// ── Update / upgrade ──────────────────────────────────────────────────────
|
|
335
361
|
const handledUpdate = await runUpdate()
|
|
336
362
|
if (handledUpdate) return
|
|
@@ -343,6 +369,41 @@ async function main() {
|
|
|
343
369
|
const handled = await runWorkflowCLI()
|
|
344
370
|
if (handled) return
|
|
345
371
|
|
|
372
|
+
// ── Unknown command detection ──────────────────────────────────────────────
|
|
373
|
+
// After all known subcommands are checked, any remaining positional argument
|
|
374
|
+
// is probably a typo. Show error + suggestions instead of silently launching CLI.
|
|
375
|
+
const KNOWN_COMMANDS = ['update', 'upgrade', 'plugin', 'workflow', 'help']
|
|
376
|
+
const firstArg = process.argv.slice(2).find((a) => !a.startsWith('-'))
|
|
377
|
+
if (firstArg) {
|
|
378
|
+
// Levenshtein distance to find closest match
|
|
379
|
+
const distance = (a: string, b: string): number => {
|
|
380
|
+
const m = a.length
|
|
381
|
+
const n = b.length
|
|
382
|
+
const dp: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0))
|
|
383
|
+
for (let i = 0; i <= m; i++) dp[i]![0] = i
|
|
384
|
+
for (let j = 0; j <= n; j++) dp[0]![j] = j
|
|
385
|
+
for (let i = 1; i <= m; i++)
|
|
386
|
+
for (let j = 1; j <= n; j++)
|
|
387
|
+
dp[i]![j] =
|
|
388
|
+
a[i - 1] === b[j - 1]
|
|
389
|
+
? dp[i - 1]![j - 1]!
|
|
390
|
+
: 1 + Math.min(dp[i - 1]![j]!, dp[i]![j - 1]!, dp[i - 1]![j - 1]!)
|
|
391
|
+
return dp[m]![n]!
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const best = KNOWN_COMMANDS.map((cmd) => ({ cmd, dist: distance(firstArg, cmd) }))
|
|
395
|
+
.filter((c) => c.dist <= 3)
|
|
396
|
+
.sort((a, b) => a.dist - b.dist)
|
|
397
|
+
const suggestions = best.map((c) => `'mipham ${c.cmd}'`).join(', ')
|
|
398
|
+
|
|
399
|
+
console.error(`Unknown command: mipham ${firstArg}`)
|
|
400
|
+
if (suggestions) {
|
|
401
|
+
console.error(`Did you mean: ${suggestions}?`)
|
|
402
|
+
}
|
|
403
|
+
console.error(`Run 'mipham --help' for usage.`)
|
|
404
|
+
process.exit(1)
|
|
405
|
+
}
|
|
406
|
+
|
|
346
407
|
// Parse --safe-mode flag: skip custom agents, skills, hooks, plugins
|
|
347
408
|
const safeModeFlag = process.argv.includes('--safe-mode')
|
|
348
409
|
if (safeModeFlag) {
|