Files
marqdo-app-harness/scripts/mqdh.mjs
cflmy fd1d129e00
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful
feat: add a read-only mqdh status ecosystem view
Start the app-harness#16 version-visibility slice with `mqdh status [--json]`:
one read-only report of the application version/home/workspace, platform and
Node, ecosystem candidate/version, Bundle version/modules/digest, installed tool
versions, market/knowledge counts and the privacy constants. JSON uses the
stable schema marqdo.mqdh.status.

The launcher product-command set and HELP include status; ARCHITECTURE records
the command. The CLI test covers JSON and text output for an empty install and
asserts the honest "not installed"/false values. This is not the full latest
version/release-notes/download view from #16; that remains UNVERIFIED.

Verified locally: all downstream node tests 77 pass/3 skipped; typecheck gates
5/5 pass.
2026-11-30 20:21:33 +08:00

147 lines
5.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Marqdo Harness product launcher (`mqdh`).
*
* Creates the application home, materialises the single `mqdh` DSH profile with
* its bundle row, and starts the forked `dsh` launcher. It never rewrites a
* user's existing DSH home and never resolves a floating Marqdo runtime: the
* active environment is whatever the ecosystem manager activated.
*
* @module marqdo-app-harness/launcher
*/
import { access, chmod, mkdir, readFile, symlink, unlink, writeFile } from 'node:fs/promises'
import { constants } from 'node:fs'
import { homedir } from 'node:os'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
import { spawn } from 'node:child_process'
const here = dirname(fileURLToPath(import.meta.url))
const root = resolve(here, '..')
const productCommands = new Set(['bootstrap', 'status', 'doctor', 'repair', 'report', 'update', 'network', 'uninstall', 'help'])
/** Resolve the application home without touching the user's `~/.dsh`. */
function resolveHome() {
const configured = process.env.MQDH_HOME?.trim()
if (configured) return resolve(configured)
const xdg = process.env.XDG_DATA_HOME?.trim()
return xdg ? join(xdg, 'marqdo-harness') : join(homedir(), '.local', 'share', 'marqdo-harness')
}
/** Whether a path exists. */
async function exists(path) {
try {
await access(path, constants.F_OK)
return true
} catch {
return false
}
}
/** Find the built `dsh` launcher, or fall back to the installed dependency. */
async function findDsh() {
const override = process.env.MQDH_DSH_BIN?.trim()
const candidates = [
override,
join(root, 'apps', 'cli', 'lib', 'bin.js'),
join(root, 'node_modules', '@deepseek-ai', 'dsh', 'lib', 'bin.js'),
].filter(Boolean)
for (const candidate of candidates) {
if (await exists(candidate)) return candidate
}
throw new Error(
'dsh launcher not found; run `pnpm install && pnpm run build` in the application checkout or set MQDH_DSH_BIN',
)
}
/** Ensure the single product profile and its local bundle links. */
async function ensureProfile(dshHome) {
const profileDir = join(dshHome, 'profiles', 'mqdh')
const nodeModules = join(profileDir, 'node_modules', '@marqdo')
await mkdir(nodeModules, { recursive: true, mode: 0o700 })
await chmod(profileDir, 0o700)
const manifest = {
name: 'mqdh-profile',
private: true,
dsh: {
profile: {
bundles: ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', '@marqdo/mqdh-bundle'],
},
},
}
const manifestPath = join(profileDir, 'package.json')
const current = await readFile(manifestPath, 'utf8').catch(() => '')
if (current !== `${JSON.stringify(manifest, null, 2)}\n`) {
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o600 })
}
// Bundle packages are resolved from the profile's own node_modules. Removing
// a stale link first keeps a moved checkout from loading old code.
for (const [name, target] of [
['mqdh-bundle', join(root, 'packages', 'marqdo', 'bundle')],
['mqdh-harness', join(root, 'packages', 'marqdo', 'harness')],
]) {
const link = join(nodeModules, name)
await unlink(link).catch(() => undefined)
await symlink(target, link, 'dir')
}
return profileDir
}
/** Start the forked launcher with the application home. */
async function main() {
const home = resolveHome()
await mkdir(home, { recursive: true, mode: 0o700 })
await chmod(home, 0o700)
const dshHome = join(home, 'harness')
await mkdir(dshHome, { recursive: true, mode: 0o700 })
await ensureProfile(dshHome)
const dsh = await findDsh()
const args = [dsh, '--profile', 'mqdh', ...process.argv.slice(2)]
const child = spawn(process.execPath, args, {
stdio: 'inherit',
env: {
...process.env,
DSH_HOME: dshHome,
MQDH_HOME: home,
MQDH_WORKSPACE: process.env.MQDH_WORKSPACE?.trim() || join(home, 'workspaces', 'default'),
},
})
const forward = (signal) => {
if (child.exitCode === null && child.signalCode === null) child.kill(signal)
}
process.on('SIGINT', () => forward('SIGINT'))
process.on('SIGTERM', () => forward('SIGTERM'))
child.on('exit', (code, signal) => {
if (signal) process.kill(process.pid, signal)
else process.exit(code ?? 1)
})
}
/** Product commands run without booting the DSH profile. */
async function productMain(args) {
// The packaged tree carries the source identity used by diagnostic reports.
const sourceSha = await readFile(join(root, 'SOURCE_SHA'), 'utf8').catch(() => '')
if (sourceSha.trim() !== '') process.env.MQDH_SOURCE_SHA ??= sourceSha.trim()
if (args[0] === '--version' || args[0] === '-V') {
const { APP_VERSION } = await import(pathToFileURL(join(root, 'packages', 'marqdo', 'harness', 'src', 'version.ts')).href)
process.stdout.write(`mqdh ${APP_VERSION}\n`)
return 0
}
const { runProductCli } = await import(pathToFileURL(join(root, 'packages', 'marqdo', 'harness', 'src', 'cli', 'main.ts')).href)
return await runProductCli(args)
}
const args = process.argv.slice(2)
if (args[0] !== undefined && (productCommands.has(args[0]) || args[0] === '--version' || args[0] === '-V')) {
productMain(args).then(code => process.exit(code)).catch((error) => {
process.stderr.write(`mqdh: ${error instanceof Error ? error.message : String(error)}\n`)
process.exit(1)
})
} else {
main().catch((error) => {
process.stderr.write(`mqdh: ${error instanceof Error ? error.message : String(error)}\n`)
process.exit(1)
})
}