gsd-for-omp 0.0.0-stage → 1.1.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 (43) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/CONTRIBUTING.md +78 -0
  3. package/LICENSE +23 -0
  4. package/README.md +84 -2
  5. package/README.zh-CN.md +85 -0
  6. package/bin/gsd-for-omp.cjs +492 -0
  7. package/docs/ARCHITECTURE.md +188 -0
  8. package/docs/CONFIGURATION.md +239 -0
  9. package/docs/DEVELOPMENT.md +128 -0
  10. package/docs/GETTING-STARTED.md +211 -0
  11. package/docs/TESTING.md +143 -0
  12. package/package.json +66 -4
  13. package/src/eos.cjs +70 -0
  14. package/src/extension/cli-bridge.cjs +169 -0
  15. package/src/extension/commands.cjs +441 -0
  16. package/src/extension/continuation.cjs +416 -0
  17. package/src/extension/engine.cjs +130 -0
  18. package/src/extension/goal-mode.cjs +156 -0
  19. package/src/extension/graphify.cjs +185 -0
  20. package/src/extension/hooks.cjs +157 -0
  21. package/src/extension/lifecycle.cjs +218 -0
  22. package/src/extension/localize.cjs +56 -0
  23. package/src/extension/native-launchers.cjs +721 -0
  24. package/src/extension/native-prompts.cjs +769 -0
  25. package/src/extension/native-tasks.cjs +335 -0
  26. package/src/extension/native-ui.cjs +199 -0
  27. package/src/extension/onboarding.cjs +83 -0
  28. package/src/extension/phase-guard.cjs +81 -0
  29. package/src/extension/phases.cjs +263 -0
  30. package/src/extension/planning-store.cjs +161 -0
  31. package/src/extension/planning.cjs +164 -0
  32. package/src/extension/projected-skills.cjs +164 -0
  33. package/src/extension/session-controls.cjs +211 -0
  34. package/src/extension/state.cjs +59 -0
  35. package/src/extension/status.cjs +314 -0
  36. package/src/extension/task-results.cjs +212 -0
  37. package/src/extension/util.cjs +44 -0
  38. package/src/extension.cjs +111 -0
  39. package/src/gsd-graphify-worker.cjs +80 -0
  40. package/src/locale.cjs +72 -0
  41. package/src/locales/en.cjs +22 -0
  42. package/src/locales/zh-CN.cjs +22 -0
  43. package/src/projection.cjs +168 -0
@@ -0,0 +1,492 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const crypto = require('node:crypto');
5
+ const fs = require('node:fs');
6
+ const os = require('node:os');
7
+ const path = require('node:path');
8
+ const { spawnSync } = require('node:child_process');
9
+ const Eos = require('../src/eos.cjs');
10
+ const { buildProjectedArtifacts } = require('../src/projection.cjs');
11
+ const packageJson = require('../package.json');
12
+ const { t } = require('../src/locale.cjs');
13
+
14
+ const MANIFEST_NAME = '.gsd-for-omp-manifest.json';
15
+ const LEGACY_EXTENSION_PATHS = Object.freeze([
16
+ path.join('extensions', 'gsd-omp.cjs'),
17
+ path.join('extensions', 'gsd-omp.cjs.bak-mutable-default'),
18
+ ]);
19
+ const LEGACY_EXTENSION_MARKER = 'GSD extension for Pi-compatible hosts';
20
+ const PACKAGE_NAME = 'gsd-for-omp';
21
+ const MIN_GSD_CORE = packageJson.engines.gsd.replace(/^>=/, '');
22
+
23
+ function sha256(content) {
24
+ return crypto.createHash('sha256').update(content).digest('hex');
25
+ }
26
+ const SHA256_PATTERN = /^[a-f0-9]{64}$/i;
27
+
28
+ function normalizedVersion(value) {
29
+ const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(String(value ?? '').trim());
30
+ return match ? `${Number(match[1])}.${Number(match[2])}.${Number(match[3])}` : null;
31
+ }
32
+
33
+ function manifestError(root, message) {
34
+ const error = new Error(t('cli.error.invalidManifest', { path: manifestPath(root), message }));
35
+ error.code = 'ERR_GSD_FOR_OMP_MANIFEST';
36
+ return error;
37
+ }
38
+
39
+ function normalizedManifestPath(root, value) {
40
+ if (typeof value !== 'string') return null;
41
+ const candidate = value.trim();
42
+ if (!candidate || candidate.includes('\0') || path.isAbsolute(candidate)) return null;
43
+ if (candidate.split(/[\\/]+/).includes('..')) return null;
44
+ const resolved = path.resolve(root, candidate);
45
+ const relative = path.relative(path.resolve(root), resolved);
46
+ if (!relative || relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return null;
47
+ return relative;
48
+ }
49
+
50
+ function safeTarget(root, filePath, errorFactory) {
51
+ const normalized = normalizedManifestPath(root, filePath);
52
+ if (!normalized) throw errorFactory(String(filePath));
53
+ let current = path.resolve(root);
54
+ for (const segment of normalized.split(path.sep).slice(0, -1)) {
55
+ current = path.join(current, segment);
56
+ try {
57
+ const stat = fs.lstatSync(current);
58
+ if (stat.isSymbolicLink() || !stat.isDirectory()) throw errorFactory(current);
59
+ } catch (error) {
60
+ if (error?.code === 'ENOENT') break;
61
+ throw error;
62
+ }
63
+ }
64
+ return path.join(root, normalized);
65
+ }
66
+
67
+ function safeArtifactTarget(root, filePath) {
68
+ return safeTarget(root, filePath, (target) => new Error(t('cli.error.refusingOverwrite', { path: target })));
69
+ }
70
+ function legacyArtifactFiles(root) {
71
+ return LEGACY_EXTENSION_PATHS.flatMap((relativePath) => {
72
+ const target = safeArtifactTarget(root, relativePath);
73
+ let stat;
74
+ try {
75
+ stat = fs.lstatSync(target);
76
+ } catch (error) {
77
+ if (error?.code === 'ENOENT') return [];
78
+ throw error;
79
+ }
80
+ if (!stat.isFile() || stat.isSymbolicLink()) return [];
81
+ let content;
82
+ try {
83
+ content = fs.readFileSync(target, 'utf8');
84
+ } catch {
85
+ return [];
86
+ }
87
+ if (!content.includes(LEGACY_EXTENSION_MARKER)) return [];
88
+ return [{ path: relativePath, sha256: sha256(content) }];
89
+ });
90
+ }
91
+
92
+ function validateManifest(root, manifest) {
93
+ if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest) || !Array.isArray(manifest.files)) {
94
+ throw manifestError(root, 'files must be an array');
95
+ }
96
+ if (manifest.schemaVersion !== 1 || manifest.plugin !== packageJson.name) {
97
+ throw manifestError(root, 'unsupported manifest schema or plugin');
98
+ }
99
+ const seen = new Set();
100
+ const files = manifest.files.map((entry) => {
101
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) throw manifestError(root, 'each file entry must be an object');
102
+ const filePath = normalizedManifestPath(root, entry.path);
103
+ const hash = typeof entry.sha256 === 'string' ? entry.sha256.toLowerCase() : '';
104
+ if (!filePath || filePath === MANIFEST_NAME || seen.has(filePath)) throw manifestError(root, `invalid or duplicate file path: ${String(entry.path)}`);
105
+ if (!SHA256_PATTERN.test(hash)) throw manifestError(root, `invalid SHA-256 for ${filePath}`);
106
+ seen.add(filePath);
107
+ return { ...entry, path: filePath, sha256: hash };
108
+ });
109
+ return { ...manifest, files };
110
+ }
111
+
112
+ function manifestTarget(root, filePath) {
113
+ return safeTarget(root, filePath, (target) => manifestError(root, `unsafe parent path: ${target}`));
114
+ }
115
+
116
+ function fileHash(target) {
117
+ try {
118
+ if (!fs.statSync(target).isFile()) throw new Error('not a regular file');
119
+ return sha256(fs.readFileSync(target));
120
+ } catch (error) {
121
+ if (error?.code === 'ENOENT') return null;
122
+ throw error;
123
+ }
124
+ }
125
+
126
+
127
+ function parseArgs(argv) {
128
+ const args = [...argv];
129
+ let command = 'install';
130
+ if (args[0] === '--help' || args[0] === '-h') {
131
+ args.shift();
132
+ command = '--help';
133
+ } else if (args[0] && !args[0].startsWith('-')) {
134
+ command = args.shift();
135
+ }
136
+ let root;
137
+ let force = false;
138
+ let json = false;
139
+ while (args.length) {
140
+ const arg = args.shift();
141
+ if (arg === '--force') force = true;
142
+ else if (arg === '--json') json = true;
143
+ else if (arg === '--root') {
144
+ const value = args.shift();
145
+ if (!value || value.startsWith('-')) throw new Error(t('cli.error.rootRequiresPath'));
146
+ root = path.resolve(value);
147
+ } else throw new Error(t('cli.error.unknownArgument', { arg }));
148
+ }
149
+ return { command, root, force, json };
150
+ }
151
+
152
+ function npmLatestVersion() {
153
+ const res = spawnSync('npm', ['view', PACKAGE_NAME, 'version', '--json'], {
154
+ encoding: 'utf8',
155
+ stdio: ['ignore', 'pipe', 'ignore'],
156
+ timeout: 30000,
157
+ });
158
+ if (res.error || res.status !== 0) throw new Error(t('cli.error.updateCheckFailed'));
159
+ try {
160
+ return JSON.parse(res.stdout);
161
+ } catch {
162
+ throw new Error(t('cli.error.updateCheckFailed'));
163
+ }
164
+ }
165
+
166
+ function update({ root: rootOverride, force = false, latestVersion, json = false } = {}) {
167
+ const provider = latestVersion === undefined ? npmLatestVersion : latestVersion;
168
+ const latest = normalizedVersion(typeof provider === 'function' ? provider() : null);
169
+ if (!latest) throw new Error(t('cli.error.updateCheckFailed'));
170
+ const root = runtimeRoot(rootOverride);
171
+ const manifest = readManifest(root);
172
+ const projectionStale = manifest?.version !== packageJson.version;
173
+ const comparison = compareVersions(latest, packageJson.version);
174
+ if (comparison <= 0 && !projectionStale) {
175
+ return { upToDate: comparison === 0, current: packageJson.version, latest, root };
176
+ }
177
+ if (comparison <= 0 && projectionStale) {
178
+ install({ root: rootOverride, force });
179
+ return { updated: true, from: manifest?.version || null, to: packageJson.version, root };
180
+ }
181
+ const npmArgs = ['install', '--global', `${PACKAGE_NAME}@${latest}`];
182
+ const res = spawnSync('npm', npmArgs, { encoding: 'utf8', stdio: json ? ['ignore', 'ignore', 'inherit'] : 'inherit', timeout: 300000 });
183
+ if (res.status !== 0) throw new Error(t('cli.error.updateFailed'));
184
+
185
+ // The current process still contains the old package. Invoke the freshly
186
+ // installed CLI so projection uses the new extension, agents, skills, and
187
+ // bundled gsd-core rather than the old process's module graph.
188
+ const prefix = globalPrefix();
189
+ if (!prefix) throw new Error(t('cli.error.updateProjectionFailed'));
190
+ const cli = process.platform === 'win32'
191
+ ? path.join(prefix, 'gsd-for-omp.cmd')
192
+ : path.join(prefix, 'bin', 'gsd-for-omp');
193
+ const installArgs = ['install'];
194
+ if (rootOverride) installArgs.push('--root', rootOverride);
195
+ if (force) installArgs.push('--force');
196
+ const projection = spawnSync(cli, installArgs, { encoding: 'utf8', stdio: json ? ['ignore', 'ignore', 'inherit'] : 'inherit', timeout: 120000 });
197
+ if (projection.status !== 0) throw new Error(t('cli.error.updateProjectionFailed'));
198
+ return { updated: true, from: packageJson.version, to: latest, root };
199
+ }
200
+
201
+ function compareVersions(left, right) {
202
+ const parse = (value) => String(value || '').match(/^(\d+)\.(\d+)\.(\d+)/)?.slice(1).map(Number) || null;
203
+ const a = parse(left);
204
+ const b = parse(right);
205
+ if (!a || !b) return 0;
206
+ return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
207
+ }
208
+
209
+ function globalPrefix() {
210
+ const res = spawnSync('npm', ['prefix', '--global'], { encoding: 'utf8' });
211
+ if (res.error || res.status !== 0) return undefined;
212
+ return (res.stdout || '').trim() || undefined;
213
+ }
214
+
215
+ function runtimeRoot(override) {
216
+ return override ? path.resolve(override) : path.resolve(process.env.PI_CODING_AGENT_DIR || path.join(os.homedir(), '.omp', 'agent'));
217
+ }
218
+
219
+ function manifestPath(root) {
220
+ return path.join(root, MANIFEST_NAME);
221
+ }
222
+
223
+ function readManifest(root) {
224
+ const location = manifestPath(root);
225
+ try {
226
+ const stat = fs.lstatSync(location);
227
+ if (!stat.isFile() || stat.isSymbolicLink()) throw manifestError(root, 'manifest must be a regular file');
228
+ return validateManifest(root, JSON.parse(fs.readFileSync(location, 'utf8')));
229
+ } catch (error) {
230
+ if (error.code === 'ENOENT') return null;
231
+ if (error.code === 'ERR_GSD_FOR_OMP_MANIFEST') throw error;
232
+ throw new Error(t('cli.error.cannotReadManifest', { path: location, message: error.message }));
233
+ }
234
+ }
235
+
236
+ function pathExists(target) {
237
+ try {
238
+ fs.lstatSync(target);
239
+ return true;
240
+ } catch (error) {
241
+ if (error?.code === 'ENOENT') return false;
242
+ throw error;
243
+ }
244
+ }
245
+
246
+ function writeStagedFile(target, content) {
247
+ fs.mkdirSync(path.dirname(target), { recursive: true });
248
+ fs.writeFileSync(target, content, { encoding: 'utf8', flag: 'wx' });
249
+ }
250
+
251
+ function installTransaction(root, artifacts, staleFiles, manifestContent) {
252
+ fs.mkdirSync(root, { recursive: true });
253
+ const transactionRoot = fs.mkdtempSync(path.join(root, '.gsd-for-omp-install-'));
254
+ const stagedRoot = path.join(transactionRoot, 'staged');
255
+ const backupRoot = path.join(transactionRoot, 'backup');
256
+ const records = [];
257
+ const entries = [
258
+ ...artifacts.map((artifact) => ({ relativePath: artifact.relativePath, content: artifact.content })),
259
+ { relativePath: MANIFEST_NAME, content: manifestContent },
260
+ ...staleFiles.map((file) => ({ relativePath: file.path, content: null })),
261
+ ];
262
+ try {
263
+ for (const entry of entries) {
264
+ if (entry.content !== null) writeStagedFile(path.join(stagedRoot, entry.relativePath), entry.content);
265
+ }
266
+ for (const entry of entries) {
267
+ let target = safeArtifactTarget(root, entry.relativePath);
268
+ fs.mkdirSync(path.dirname(target), { recursive: true });
269
+ target = safeArtifactTarget(root, entry.relativePath);
270
+ const backup = path.join(backupRoot, entry.relativePath);
271
+ const record = { target, backup, hadPrevious: false, installed: false };
272
+ records.push(record);
273
+ if (pathExists(target)) {
274
+ fs.mkdirSync(path.dirname(backup), { recursive: true });
275
+ fs.renameSync(target, backup);
276
+ record.hadPrevious = true;
277
+ }
278
+ if (entry.content !== null) {
279
+ fs.renameSync(path.join(stagedRoot, entry.relativePath), target);
280
+ record.installed = true;
281
+ }
282
+ }
283
+ } catch (error) {
284
+ for (const record of records.reverse()) {
285
+ try {
286
+ if (record.installed && pathExists(record.target)) fs.unlinkSync(record.target);
287
+ } catch { /* preserve the original transaction error */ }
288
+ try {
289
+ if (record.hadPrevious && pathExists(record.backup)) {
290
+ fs.mkdirSync(path.dirname(record.target), { recursive: true });
291
+ fs.renameSync(record.backup, record.target);
292
+ }
293
+ } catch { /* preserve the original transaction error */ }
294
+ }
295
+ throw error;
296
+ } finally {
297
+ fs.rmSync(transactionRoot, { recursive: true, force: true });
298
+ }
299
+ }
300
+
301
+ function removeEmptyParents(start, stop) {
302
+ let current = path.dirname(start);
303
+ const boundary = path.resolve(stop);
304
+ while (current.startsWith(`${boundary}${path.sep}`)) {
305
+ try {
306
+ fs.rmdirSync(current);
307
+ } catch {
308
+ return;
309
+ }
310
+ current = path.dirname(current);
311
+ }
312
+ }
313
+
314
+ function assertSupportedCore(coreRoot) {
315
+ const corePackage = JSON.parse(fs.readFileSync(path.join(coreRoot, 'package.json'), 'utf8'));
316
+ const match = String(corePackage.version || '').match(/^(\d+)\.(\d+)\.(\d+)/);
317
+ if (!match || compareVersions(corePackage.version, MIN_GSD_CORE) < 0) {
318
+ throw new Error(t('cli.error.unsupportedCore', { minimum: MIN_GSD_CORE, version: corePackage.version || 'unknown' }));
319
+ }
320
+ return corePackage.version;
321
+ }
322
+
323
+ function extensionWrapper(root) {
324
+ const extensionPath = path.join(__dirname, '..', 'src', 'extension.cjs');
325
+ return `import { createRequire } from "node:module";\n\nconst require = createRequire(import.meta.url);\nconst extension = require(${JSON.stringify(extensionPath)});\n\nexport default (pi: unknown) => extension(pi, { runtime: "omp", runtimeRoot: ${JSON.stringify(root)} });\n`;
326
+ }
327
+
328
+ function desiredArtifacts(root, coreRoot) {
329
+ return [
330
+ {
331
+ relativePath: path.join('extensions', 'gsd-for-omp.ts'),
332
+ content: extensionWrapper(root),
333
+ },
334
+ ...buildProjectedArtifacts({ coreRoot, runtimeRoot: root }),
335
+ ];
336
+ }
337
+
338
+ function install({ root: rootOverride, force = false } = {}) {
339
+ const root = runtimeRoot(rootOverride);
340
+ const eos = Eos.initialize();
341
+ const coreVersion = assertSupportedCore(eos.coreRoot);
342
+ const previous = readManifest(root);
343
+ const artifacts = desiredArtifacts(root, eos.coreRoot);
344
+ const artifactPaths = new Set(artifacts.map((artifact) => artifact.relativePath));
345
+ const staleFiles = [...new Map([
346
+ ...(previous?.files || []).filter((file) => !artifactPaths.has(file.path)),
347
+ ...legacyArtifactFiles(root),
348
+ ].map((file) => [file.path, file])).values()];
349
+ const previousFiles = new Map((previous?.files || []).map((file) => [file.path, file.sha256]));
350
+ const checkOwnership = (filePath, expectedHash) => {
351
+ const target = safeArtifactTarget(root, filePath);
352
+ if (!pathExists(target)) return;
353
+ let currentHash;
354
+ try {
355
+ currentHash = fileHash(target);
356
+ } catch {
357
+ throw new Error(t('cli.error.refusingOverwrite', { path: target }));
358
+ }
359
+ if (!force && currentHash !== expectedHash) {
360
+ throw new Error(t('cli.error.refusingOverwrite', { path: target }));
361
+ }
362
+ };
363
+ for (const artifact of artifacts) checkOwnership(artifact.relativePath, previousFiles.get(artifact.relativePath));
364
+ for (const file of staleFiles) checkOwnership(file.path, file.sha256);
365
+
366
+ const files = artifacts.map((artifact) => ({ path: artifact.relativePath, sha256: sha256(artifact.content) }));
367
+ const manifest = {
368
+ schemaVersion: 1,
369
+ plugin: packageJson.name,
370
+ version: packageJson.version,
371
+ enginesGsd: packageJson.engines.gsd,
372
+ protocolVersion: eos.negotiation.protocolVersion,
373
+ coreVersion,
374
+ profile: eos.profile,
375
+ installedAt: new Date().toISOString(),
376
+ files,
377
+ };
378
+ installTransaction(root, artifacts, staleFiles, `${JSON.stringify(manifest, null, 2)}\n`);
379
+ for (const file of staleFiles) {
380
+ try { removeEmptyParents(safeArtifactTarget(root, file.path), root); } catch { /* cleanup is best effort */ }
381
+ }
382
+ return { root, manifestPath: manifestPath(root), installed: files.length, coreVersion, protocolVersion: manifest.protocolVersion };
383
+ }
384
+
385
+ function uninstall({ root: rootOverride, force = false } = {}) {
386
+ const root = runtimeRoot(rootOverride);
387
+ const manifest = readManifest(root);
388
+ if (!manifest) return { root, removed: 0, skipped: [], absent: true };
389
+ const skipped = [];
390
+ let removed = 0;
391
+ for (const file of [...manifest.files].reverse()) {
392
+ const target = manifestTarget(root, file.path);
393
+ if (!pathExists(target)) continue;
394
+ let currentHash;
395
+ try {
396
+ if (fs.statSync(target).isDirectory()) {
397
+ skipped.push(file.path);
398
+ continue;
399
+ }
400
+ currentHash = fileHash(target);
401
+ } catch {
402
+ skipped.push(file.path);
403
+ continue;
404
+ }
405
+ if (!force && currentHash !== file.sha256) {
406
+ skipped.push(file.path);
407
+ continue;
408
+ }
409
+ fs.unlinkSync(target);
410
+ removeEmptyParents(target, root);
411
+ removed += 1;
412
+ }
413
+ if (!skipped.length) fs.unlinkSync(manifestPath(root));
414
+ return { root, removed, skipped, absent: false };
415
+ }
416
+
417
+ function doctor({ root: rootOverride } = {}) {
418
+ const root = runtimeRoot(rootOverride);
419
+ const manifest = readManifest(root);
420
+ const eos = Eos.initialize();
421
+ const missing = [];
422
+ const modified = [];
423
+ for (const file of manifest?.files || []) {
424
+ const target = manifestTarget(root, file.path);
425
+ if (!pathExists(target)) missing.push(file.path);
426
+ else {
427
+ try {
428
+ if (fileHash(target) !== file.sha256) modified.push(file.path);
429
+ } catch {
430
+ modified.push(file.path);
431
+ }
432
+ }
433
+ }
434
+ return {
435
+ ok: Boolean(manifest) && missing.length === 0 && modified.length === 0 && eos.profile === 'programmatic-cli',
436
+ root,
437
+ installed: Boolean(manifest),
438
+ version: manifest?.version || null,
439
+ coreVersion: manifest?.coreVersion || null,
440
+ protocolVersion: eos.negotiation.protocolVersion,
441
+ profile: eos.profile,
442
+ missing,
443
+ modified,
444
+ };
445
+ }
446
+
447
+ function descriptor() {
448
+ const eos = Eos.initialize();
449
+ return {
450
+ id: 'gsd-for-omp',
451
+ protocolVersion: eos.negotiation.protocolVersion,
452
+ enginesGsd: packageJson.engines.gsd,
453
+ profile: eos.profile,
454
+ interfacePoints: ['command', 'dispatch', 'model', 'hooks', 'state', 'artifact'],
455
+ axes: Eos.OMP_AXES,
456
+ };
457
+ }
458
+
459
+ function print(value, json) {
460
+ if (json || typeof value !== 'string') process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
461
+ else process.stdout.write(`${value}\n`);
462
+ }
463
+
464
+ function main(argv = process.argv.slice(2)) {
465
+ const options = parseArgs(argv);
466
+ let result;
467
+ if (options.command === 'install') result = install(options);
468
+ else if (options.command === 'uninstall') result = uninstall(options);
469
+ else if (options.command === 'doctor') result = doctor(options);
470
+ else if (options.command === 'descriptor') result = descriptor();
471
+ else if (options.command === 'update') result = update(options);
472
+ else if (options.command === 'help' || options.command === '--help') {
473
+ print(t('cli.usage'), false);
474
+ return 0;
475
+ } else throw new Error(t('cli.error.unknownCommand', { command: options.command }));
476
+ print(result, options.json);
477
+ const unhealthy = options.command === 'doctor' && !result.ok;
478
+ const incompleteUninstall = options.command === 'uninstall' && result.skipped?.length > 0;
479
+ return unhealthy || incompleteUninstall ? 1 : 0;
480
+ }
481
+
482
+ if (require.main === module) {
483
+ try {
484
+ process.exitCode = main();
485
+ } catch (error) {
486
+ const message = String(error.message);
487
+ process.stderr.write(`${message.startsWith('gsd-for-omp') ? message : `gsd-for-omp: ${message}`}\n`);
488
+ process.exitCode = 1;
489
+ }
490
+ }
491
+
492
+ module.exports = { descriptor, doctor, install, main, parseArgs, runtimeRoot, uninstall, update, compareVersions };