@plot-app/cli 0.0.1
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 +33 -0
- package/bin/plot.js +129 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Plot CLI
|
|
2
|
+
|
|
3
|
+
Programmatic access to Plot workspaces for agents.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @plot-app/cli
|
|
9
|
+
plot login
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
This public npm package contains compiled Plot CLI executables and a small
|
|
13
|
+
launcher. It does not include the Plot CLI TypeScript source, tests, monorepo
|
|
14
|
+
configuration, local credentials, or environment files.
|
|
15
|
+
|
|
16
|
+
Supported platforms:
|
|
17
|
+
|
|
18
|
+
- macOS arm64
|
|
19
|
+
- macOS x64
|
|
20
|
+
- Linux arm64
|
|
21
|
+
- Linux x64
|
|
22
|
+
|
|
23
|
+
The CLI stores user credentials locally after `plot login`. No Plot API token
|
|
24
|
+
or OAuth credential is embedded in this package.
|
|
25
|
+
|
|
26
|
+
## Updates
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
plot update
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The launcher also checks npm for updates on first run and then at most once per
|
|
33
|
+
day. Set `PLOT_CLI_SKIP_UPDATE_CHECK=1` to disable automatic checks.
|
package/bin/plot.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { spawnSync } = require('node:child_process');
|
|
3
|
+
const { mkdirSync, readFileSync, writeFileSync } = require('node:fs');
|
|
4
|
+
const { homedir } = require('node:os');
|
|
5
|
+
const { dirname, join } = require('node:path');
|
|
6
|
+
|
|
7
|
+
const packageName = '@plot-app/cli';
|
|
8
|
+
const currentVersion = '0.0.1';
|
|
9
|
+
const updateIntervalMs = 24 * 60 * 60 * 1000;
|
|
10
|
+
const key = `${process.platform}-${process.arch}`;
|
|
11
|
+
const packages = {
|
|
12
|
+
'darwin-arm64': '@plot-app/cli-darwin-arm64',
|
|
13
|
+
'darwin-x64': '@plot-app/cli-darwin-x64',
|
|
14
|
+
'linux-arm64': '@plot-app/cli-linux-arm64',
|
|
15
|
+
'linux-x64': '@plot-app/cli-linux-x64',
|
|
16
|
+
};
|
|
17
|
+
const binaryPackageName = packages[key];
|
|
18
|
+
const updateStatePath = join(homedir(), '.plot', 'update-check.json');
|
|
19
|
+
|
|
20
|
+
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
21
|
+
|
|
22
|
+
const readLastUpdateCheck = () => {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(readFileSync(updateStatePath, 'utf8')).checkedAt ?? 0;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const writeLastUpdateCheck = () => {
|
|
31
|
+
try {
|
|
32
|
+
mkdirSync(dirname(updateStatePath), { recursive: true });
|
|
33
|
+
writeFileSync(updateStatePath, JSON.stringify({ checkedAt: Date.now() }));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const shouldCheckForUpdate = () => {
|
|
39
|
+
if (process.env.PLOT_CLI_SKIP_UPDATE_CHECK === '1') return false;
|
|
40
|
+
return Date.now() - readLastUpdateCheck() > updateIntervalMs;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const latestVersion = () => {
|
|
44
|
+
const result = spawnSync(npmCommand, ['view', `${packageName}@latest`, 'version', '--silent'], {
|
|
45
|
+
encoding: 'utf8',
|
|
46
|
+
env: process.env,
|
|
47
|
+
});
|
|
48
|
+
if (result.status !== 0) return null;
|
|
49
|
+
const version = result.stdout.trim();
|
|
50
|
+
return version.length > 0 ? version : null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const installLatest = (stdio) =>
|
|
54
|
+
spawnSync(npmCommand, ['install', '-g', `${packageName}@latest`], {
|
|
55
|
+
stdio,
|
|
56
|
+
env: process.env,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const update = (force) => {
|
|
60
|
+
const version = latestVersion();
|
|
61
|
+
writeLastUpdateCheck();
|
|
62
|
+
|
|
63
|
+
if (!version) {
|
|
64
|
+
if (force) {
|
|
65
|
+
console.error('Could not check the latest Plot CLI version from npm.');
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (version === currentVersion) {
|
|
72
|
+
if (force) console.log(`Plot CLI is already up to date (${currentVersion}).`);
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (force) {
|
|
77
|
+
console.log(`Updating Plot CLI from ${currentVersion} to ${version}...`);
|
|
78
|
+
}
|
|
79
|
+
const result = installLatest(force ? 'inherit' : 'ignore');
|
|
80
|
+
if (result.status === 0) {
|
|
81
|
+
if (force) console.log(`Updated Plot CLI to ${version}.`);
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (force) {
|
|
86
|
+
console.error('Plot CLI update failed.');
|
|
87
|
+
console.error(`Try manually: npm install -g ${packageName}@latest`);
|
|
88
|
+
return typeof result.status === 'number' ? result.status : 1;
|
|
89
|
+
}
|
|
90
|
+
return 0;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (process.argv[2] === 'update') {
|
|
94
|
+
process.exit(update(true));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (shouldCheckForUpdate()) {
|
|
98
|
+
update(false);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!binaryPackageName) {
|
|
102
|
+
console.error(`Plot CLI does not ship a binary for ${key}.`);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let binary;
|
|
107
|
+
try {
|
|
108
|
+
binary = require.resolve(binaryPackageName);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(`Plot CLI binary package is missing for ${key}.`);
|
|
111
|
+
console.error('Reinstall with: npm install -g @plot-app/cli');
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const result = spawnSync(binary, process.argv.slice(2), {
|
|
116
|
+
stdio: 'inherit',
|
|
117
|
+
env: process.env,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (result.error) {
|
|
121
|
+
console.error(result.error.message);
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (typeof result.status === 'number') {
|
|
126
|
+
process.exit(result.status);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
process.exit(1);
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plot-app/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Programmatic access to Plot workspaces for agents.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"bin": {
|
|
7
|
+
"plot": "./bin/plot.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"os": [
|
|
14
|
+
"darwin",
|
|
15
|
+
"linux"
|
|
16
|
+
],
|
|
17
|
+
"cpu": [
|
|
18
|
+
"x64",
|
|
19
|
+
"arm64"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"optionalDependencies": {
|
|
25
|
+
"@plot-app/cli-darwin-arm64": "0.0.1",
|
|
26
|
+
"@plot-app/cli-darwin-x64": "0.0.1",
|
|
27
|
+
"@plot-app/cli-linux-x64": "0.0.1",
|
|
28
|
+
"@plot-app/cli-linux-arm64": "0.0.1"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
}
|
|
34
|
+
}
|