@cmdop/project-check 0.1.0 → 4.0.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/README.md +63 -13
- package/catalog/project-check.json +1 -1
- package/package.json +11 -2
- package/runtime/node/launcher.mjs +24 -2
package/README.md
CHANGED
|
@@ -1,25 +1,75 @@
|
|
|
1
1
|
# CMDOP Project Check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Check a Node.js project's CMDOP SDK configuration before running your first machine request. **@cmdop/project-check** is an offline CLI for inspecting project metadata and creating the official TypeScript SDK starter without executing it.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
*Illustration of the SDK workflow you can build after setup, not an execution by Project Check.*
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
[CMDOP](https://cmdop.ai) · [Documentation](https://docs.cmdop.ai) · [Official SDK quickstart](https://github.com/commandoperator/cmdop-sdk/blob/main/docs/quickstart.md)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Requirements
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
- Node.js 20 or newer, with npm.
|
|
14
|
+
- An npm-managed application directory. Linked SDK packages, pnpm, Yarn and workspaces are not supported by this utility.
|
|
15
|
+
- SDK 3.6.1 is the reviewed version for starter creation.
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
npx --no-install cmdop-project-check doctor --target /path/to/project --json
|
|
17
|
-
npx --no-install cmdop-project-check example --target /path/to/project
|
|
17
|
+
## Install and check your project
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Install the utility in a separate tools directory:
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
```sh
|
|
22
|
+
npm install --save-exact @cmdop/project-check@4.0.0
|
|
23
|
+
```
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
From that directory, point the CLI at your application:
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
```sh
|
|
28
|
+
npx --no-install cmdop-project-check doctor --target /path/to/project
|
|
29
|
+
npx --no-install cmdop-project-check doctor --target /path/to/project --json
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The check reads local runtime prerequisites, package-manager and lockfile compatibility, the declared SDK dependency, and the SDK manifest under your application's node_modules directory. It never runs SDK code or your application's lifecycle scripts.
|
|
33
|
+
|
|
34
|
+
## Interpret the SDK result
|
|
35
|
+
|
|
36
|
+
| SDK status | Meaning |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `matches_reviewed_version` | Local SDK metadata identifies the reviewed version. |
|
|
39
|
+
| `missing` | No project-local SDK manifest was found. |
|
|
40
|
+
| `different_version` | The installed manifest reports another version. |
|
|
41
|
+
| Other status or blocked diagnostic | Resolve the reported metadata or environment problem first. |
|
|
42
|
+
|
|
43
|
+
The CLI rejects unsuitable project metadata rather than trying to repair or install anything automatically. A successful diagnostic is not an SDK import, integrity, login or machine connection check.
|
|
44
|
+
|
|
45
|
+
If the SDK is missing, review the suggested install command and run it yourself in the application directory:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npm install --save-exact @cmdop/sdk@3.6.1
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Create the official starter example
|
|
52
|
+
|
|
53
|
+
After the diagnostic reports the reviewed SDK version, run this from your tools directory:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
npx --no-install cmdop-project-check example --target /path/to/project
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
This creates `cmdop-example.mjs` only if that file does not already exist. It does not run the example or connect to a machine. Review the generated code, [install the CMDOP machine program](https://cmdop.ai/download) separately, and follow the [SDK authentication guide](https://github.com/commandoperator/cmdop-sdk/blob/main/docs/authentication.md) before running it.
|
|
60
|
+
|
|
61
|
+
## CLI reference
|
|
62
|
+
|
|
63
|
+
| Command | Behavior |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `doctor [--target DIR] [--json]` | Inspect local project metadata; default target is the current directory. |
|
|
66
|
+
| `example --target DIR [--json]` | Create one starter file after a matching SDK metadata check. |
|
|
67
|
+
| `--help`, `--version` | Display usage or utility version. |
|
|
68
|
+
|
|
69
|
+
Exit code 0 indicates completion of the requested operation, 2 invalid usage, 3 a blocked operation, and 4 an unexpected inspection failure. A missing SDK can be reported by a successful inspection; consult the SDK status in the JSON result.
|
|
70
|
+
|
|
71
|
+
## Privacy and license
|
|
72
|
+
|
|
73
|
+
This first-party CMDOP utility includes readable JavaScript sources and the SDK-owned starter. It does not bundle the SDK, run install hooks, install dependencies at runtime, read credentials, make network requests, send analytics or connect to machines. Diagnostics stay local.
|
|
74
|
+
|
|
75
|
+
MIT. See LICENSE and LICENSE-SDK in the archive. The SDK source and technical documentation are available at [commandoperator/cmdop-sdk](https://github.com/commandoperator/cmdop-sdk).
|
package/package.json
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmdop/project-check",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"description": "Offline
|
|
6
|
+
"description": "Offline CLI to check Node.js CMDOP SDK metadata and create a TypeScript starter",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"cmdop",
|
|
9
|
+
"sdk",
|
|
10
|
+
"cli",
|
|
11
|
+
"nodejs",
|
|
12
|
+
"typescript",
|
|
13
|
+
"project-diagnostics",
|
|
14
|
+
"starter"
|
|
15
|
+
],
|
|
7
16
|
"type": "module",
|
|
8
17
|
"engines": {
|
|
9
18
|
"node": ">=20"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync, readdirSync, statSync, realpathSync, accessSync, constants } from "node:fs";
|
|
1
|
+
import { readFileSync, writeFileSync, readdirSync, statSync, lstatSync, fstatSync, openSync, closeSync, readSync, realpathSync, accessSync, constants } from "node:fs";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { dirname, resolve, join, delimiter } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
@@ -27,6 +27,28 @@ const directoryExists = (path) => { try { return statSync(path).isDirectory(); }
|
|
|
27
27
|
const fileExists = (path) => { try { return statSync(path).isFile(); } catch { return false; } };
|
|
28
28
|
const writable = (path) => { try { accessSync(path, constants.W_OK); return true; } catch { return false; } };
|
|
29
29
|
|
|
30
|
+
// Inspect only a bounded, ordinary project manifest. Do not follow a final symlink.
|
|
31
|
+
const MAX_MANIFEST_BYTES = 256 * 1024;
|
|
32
|
+
function readProjectManifest(path) {
|
|
33
|
+
const initial = lstatSync(path);
|
|
34
|
+
if (!initial.isFile() || initial.size > MAX_MANIFEST_BYTES) throw Error("Invalid manifest");
|
|
35
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
|
|
36
|
+
try {
|
|
37
|
+
const before = fstatSync(fd);
|
|
38
|
+
const stamp = s => [s.dev, s.ino, s.mode, s.size, s.mtimeMs, s.ctimeMs].join(":");
|
|
39
|
+
if (!before.isFile() || before.size > MAX_MANIFEST_BYTES || stamp(initial) !== stamp(before)) throw Error("Invalid manifest");
|
|
40
|
+
const bytes = Buffer.alloc(before.size + 1);
|
|
41
|
+
let count = 0;
|
|
42
|
+
while (count < bytes.length) {
|
|
43
|
+
const n = readSync(fd, bytes, count, bytes.length - count, null);
|
|
44
|
+
if (!n) break;
|
|
45
|
+
count += n;
|
|
46
|
+
}
|
|
47
|
+
if (count !== before.size || stamp(before) !== stamp(fstatSync(fd))) throw Error("Manifest changed");
|
|
48
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes.subarray(0, count)));
|
|
49
|
+
} finally { closeSync(fd); }
|
|
50
|
+
}
|
|
51
|
+
|
|
30
52
|
export function evaluate(action, options = {}, catalog = readCatalog(), context = runtimeFacts()) {
|
|
31
53
|
const result = { schema_version: 1, contract_version: catalog.contract_version,
|
|
32
54
|
requested_action: action, result: "success", error_category: null, message: "",
|
|
@@ -69,7 +91,7 @@ export function evaluate(action, options = {}, catalog = readCatalog(), context
|
|
|
69
91
|
while (!directoryExists(parent) && dirname(parent) !== parent) parent = dirname(parent);
|
|
70
92
|
if (!writable(parent)) blockers.push("target_unwritable");
|
|
71
93
|
if (!blockers.length && names.includes("package.json")) {
|
|
72
|
-
try { packageJson =
|
|
94
|
+
try { packageJson = readProjectManifest(join(target, "package.json")); if (!packageJson || typeof packageJson !== "object" || Array.isArray(packageJson) || Object.hasOwn(packageJson, "packageManager") && typeof packageJson.packageManager !== "string") throw Error(); }
|
|
73
95
|
catch { packageJson = null; blockers.push("invalid_manifest"); }
|
|
74
96
|
}
|
|
75
97
|
let manager = language === "typescript" ? "npm" : "pip";
|