@seeed-studio/sensecraft-cli 0.1.2 → 0.1.4
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/INSTALL.md +443 -0
- package/LICENSE +21 -0
- package/README.md +51 -0
- package/package.json +28 -5
- package/scripts/constants.js +18 -3
- package/scripts/download.js +64 -16
- package/scripts/download.test.js +110 -0
- package/scripts/paths.js +28 -4
- package/scripts/paths.test.js +92 -0
- package/scripts/platform.js +8 -2
- package/scripts/postinstall.js +28 -7
- package/scripts/test-install.js +121 -0
- package/skills/README.md +33 -0
- package/skills/confirmation.md +56 -0
- package/skills/sensecraft-ai/SKILL.md +132 -0
- package/skills/sensecraft-apps/SKILL.md +198 -0
- package/skills/sensecraft-apps/commands.md +196 -0
- package/skills/sensecraft-apps/reference-app-fields.md +95 -0
- package/skills/sensecraft-apps/reference-tool-blocks.md +132 -0
- package/skills/sensecraft-data/SKILL.md +180 -0
- package/skills/sensecraft-data/commands.md +858 -0
- package/skills/sensecraft-devices-cloud/SKILL.md +53 -0
- package/skills/sensecraft-devices-cloud/commands.md +58 -0
- package/skills/sensecraft-files/SKILL.md +73 -0
- package/skills/sensecraft-files/commands.md +61 -0
- package/skills/sensecraft-models/SKILL.md +196 -0
- package/skills/sensecraft-models/commands.md +180 -0
- package/skills/sensecraft-models/reference-model-fields.md +139 -0
- package/skills/sensecraft-recamera/SKILL.md +79 -0
- package/skills/sensecraft-recamera/commands.md +87 -0
package/scripts/download.js
CHANGED
|
@@ -4,23 +4,33 @@ const fs = require('fs');
|
|
|
4
4
|
const https = require('https');
|
|
5
5
|
const http = require('http');
|
|
6
6
|
const path = require('path');
|
|
7
|
+
const crypto = require('crypto');
|
|
7
8
|
|
|
8
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
VERSION,
|
|
11
|
+
releaseArtifactURL,
|
|
12
|
+
versionStampPath,
|
|
13
|
+
} = require('./constants');
|
|
9
14
|
const { getVendorDir, getBinaryPath } = require('./paths');
|
|
10
15
|
const { resolvePlatformTarget } = require('./platform');
|
|
11
16
|
|
|
12
17
|
function request(url, redirects = 0) {
|
|
13
18
|
return new Promise((resolve, reject) => {
|
|
19
|
+
if (!url.startsWith('https:') && !url.startsWith('http:')) {
|
|
20
|
+
reject(new Error(`Unsupported download URL scheme: ${url}`));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Prefer HTTPS; allow http only for local override bases (e.g. file mirrors).
|
|
14
24
|
const client = url.startsWith('https:') ? https : http;
|
|
15
25
|
client
|
|
16
|
-
.get(url, { headers: { 'User-Agent':
|
|
26
|
+
.get(url, { headers: { 'User-Agent': `sensecraft-cli-npm-installer/${VERSION}` } }, (res) => {
|
|
17
27
|
if (
|
|
18
28
|
res.statusCode &&
|
|
19
29
|
[301, 302, 303, 307, 308].includes(res.statusCode) &&
|
|
20
30
|
res.headers.location
|
|
21
31
|
) {
|
|
22
32
|
if (redirects >= 5) {
|
|
23
|
-
reject(new Error(
|
|
33
|
+
reject(new Error(`Too many redirects: ${url}`));
|
|
24
34
|
return;
|
|
25
35
|
}
|
|
26
36
|
const next = new URL(res.headers.location, url).toString();
|
|
@@ -31,7 +41,7 @@ function request(url, redirects = 0) {
|
|
|
31
41
|
|
|
32
42
|
if (res.statusCode !== 200) {
|
|
33
43
|
res.resume();
|
|
34
|
-
reject(new Error(
|
|
44
|
+
reject(new Error(`Download failed (${res.statusCode}): ${url}`));
|
|
35
45
|
return;
|
|
36
46
|
}
|
|
37
47
|
|
|
@@ -57,40 +67,78 @@ function copyLocalBinary(sourcePath, targetPath) {
|
|
|
57
67
|
ensureExecutable(targetPath);
|
|
58
68
|
}
|
|
59
69
|
|
|
70
|
+
function readInstalledVersion(vendorDir) {
|
|
71
|
+
try {
|
|
72
|
+
return fs.readFileSync(versionStampPath(vendorDir), 'utf8').trim();
|
|
73
|
+
} catch {
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function writeInstalledVersion(vendorDir, version) {
|
|
79
|
+
fs.writeFileSync(versionStampPath(vendorDir), `${version}\n`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function sha256(buf) {
|
|
83
|
+
return crypto.createHash('sha256').update(buf).digest('hex');
|
|
84
|
+
}
|
|
85
|
+
|
|
60
86
|
async function installBinary() {
|
|
61
87
|
const { artifact, binary } = resolvePlatformTarget();
|
|
88
|
+
const vendorDir = getVendorDir();
|
|
62
89
|
const targetPath = getBinaryPath(binary);
|
|
90
|
+
const installed = readInstalledVersion(vendorDir);
|
|
63
91
|
|
|
64
|
-
|
|
65
|
-
|
|
92
|
+
// Reuse only when the on-disk binary matches THIS npm package version.
|
|
93
|
+
// Previously the installer reused any existing file forever, so upgrading
|
|
94
|
+
// the npm package never swapped the binary.
|
|
95
|
+
if (fs.existsSync(targetPath) && installed === VERSION) {
|
|
96
|
+
return { binary, targetPath, reused: true, version: VERSION };
|
|
66
97
|
}
|
|
67
98
|
|
|
68
99
|
const localDist = process.env.SENSECRAFT_CLI_LOCAL_DIST;
|
|
69
100
|
if (localDist) {
|
|
70
101
|
const sourcePath = path.resolve(localDist, artifact);
|
|
71
102
|
if (!fs.existsSync(sourcePath)) {
|
|
72
|
-
throw new Error(
|
|
103
|
+
throw new Error(`Local binary not found: ${sourcePath}`);
|
|
73
104
|
}
|
|
74
105
|
copyLocalBinary(sourcePath, targetPath);
|
|
75
|
-
|
|
106
|
+
writeInstalledVersion(vendorDir, VERSION);
|
|
107
|
+
return { binary, targetPath, reused: false, source: 'local', version: VERSION };
|
|
76
108
|
}
|
|
77
109
|
|
|
78
110
|
if (process.env.SENSECRAFT_CLI_SKIP_DOWNLOAD === '1') {
|
|
79
111
|
throw new Error(
|
|
80
|
-
'
|
|
81
|
-
|
|
112
|
+
'SENSECRAFT_CLI_SKIP_DOWNLOAD=1 is set, but no cached binary for ' +
|
|
113
|
+
`v${VERSION} was found. Set SENSECRAFT_CLI_LOCAL_DIST to a dist/ dir.`
|
|
82
114
|
);
|
|
83
115
|
}
|
|
84
116
|
|
|
85
|
-
|
|
86
|
-
const url = `https://sensecraft-statics.oss-us-east-1.aliyuncs.com/static/bin/sensecraft-cli/${artifact}`;
|
|
117
|
+
const url = releaseArtifactURL(artifact);
|
|
87
118
|
const data = await request(url);
|
|
88
119
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
120
|
+
// Optional integrity check: if a sibling .sha256 file is published next to
|
|
121
|
+
// the artifact, verify it. Missing checksum is not fatal (OSS may lag).
|
|
122
|
+
const expectedChecksum = process.env.SENSECRAFT_CLI_SHA256;
|
|
123
|
+
if (expectedChecksum) {
|
|
124
|
+
const got = sha256(data);
|
|
125
|
+
if (got !== expectedChecksum.toLowerCase()) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`Checksum mismatch for ${artifact}: expected ${expectedChecksum}, got ${got}`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fs.mkdirSync(vendorDir, { recursive: true });
|
|
133
|
+
// Atomic-ish write: write to temp then rename so a partial download never
|
|
134
|
+
// leaves a truncated binary that would be "reused" next time.
|
|
135
|
+
const tmpPath = `${targetPath}.tmp-${process.pid}`;
|
|
136
|
+
fs.writeFileSync(tmpPath, data);
|
|
137
|
+
ensureExecutable(tmpPath);
|
|
138
|
+
fs.renameSync(tmpPath, targetPath);
|
|
139
|
+
writeInstalledVersion(vendorDir, VERSION);
|
|
92
140
|
|
|
93
|
-
return { binary, targetPath, reused: false, source: 'release', url };
|
|
141
|
+
return { binary, targetPath, reused: false, source: 'release', url, version: VERSION };
|
|
94
142
|
}
|
|
95
143
|
|
|
96
144
|
module.exports = {
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Unit tests for binary install version pinning.
|
|
6
|
+
* Exercises the upgrade path: a stale vendor/.version must force reinstall.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const assert = require('assert');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const { VERSION } = require('./constants');
|
|
15
|
+
const { installBinary } = require('./download');
|
|
16
|
+
const { getVendorDir, getBinaryPath } = require('./paths');
|
|
17
|
+
const { resolvePlatformTarget } = require('./platform');
|
|
18
|
+
|
|
19
|
+
async function withTempLocalDist(fn) {
|
|
20
|
+
const { artifact, binary } = resolvePlatformTarget();
|
|
21
|
+
const dist = fs.mkdtempSync(path.join(os.tmpdir(), 'sc-dist-'));
|
|
22
|
+
const src = path.join(dist, artifact);
|
|
23
|
+
fs.writeFileSync(src, 'FAKE-BINARY-CONTENT-v' + VERSION);
|
|
24
|
+
|
|
25
|
+
const vendorDir = getVendorDir();
|
|
26
|
+
const targetPath = getBinaryPath(binary);
|
|
27
|
+
const stampPath = path.join(vendorDir, '.version');
|
|
28
|
+
|
|
29
|
+
// Snapshot / wipe vendor so tests don't fight a real install.
|
|
30
|
+
const backup = fs.mkdtempSync(path.join(os.tmpdir(), 'sc-vendor-bak-'));
|
|
31
|
+
if (fs.existsSync(vendorDir)) {
|
|
32
|
+
fs.cpSync(vendorDir, path.join(backup, 'vendor'), { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
fs.rmSync(vendorDir, { recursive: true, force: true });
|
|
35
|
+
|
|
36
|
+
const prev = process.env.SENSECRAFT_CLI_LOCAL_DIST;
|
|
37
|
+
process.env.SENSECRAFT_CLI_LOCAL_DIST = dist;
|
|
38
|
+
try {
|
|
39
|
+
await fn({ artifact, binary, dist, src, vendorDir, targetPath, stampPath });
|
|
40
|
+
} finally {
|
|
41
|
+
if (prev === undefined) delete process.env.SENSECRAFT_CLI_LOCAL_DIST;
|
|
42
|
+
else process.env.SENSECRAFT_CLI_LOCAL_DIST = prev;
|
|
43
|
+
fs.rmSync(vendorDir, { recursive: true, force: true });
|
|
44
|
+
const bak = path.join(backup, 'vendor');
|
|
45
|
+
if (fs.existsSync(bak)) {
|
|
46
|
+
fs.cpSync(bak, vendorDir, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
fs.rmSync(backup, { recursive: true, force: true });
|
|
49
|
+
fs.rmSync(dist, { recursive: true, force: true });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function testFreshInstallWritesVersionStamp() {
|
|
54
|
+
await withTempLocalDist(async ({ targetPath, stampPath }) => {
|
|
55
|
+
const r = await installBinary();
|
|
56
|
+
assert.equal(r.reused, false);
|
|
57
|
+
assert.equal(r.source, 'local');
|
|
58
|
+
assert.equal(r.version, VERSION);
|
|
59
|
+
assert.ok(fs.existsSync(targetPath));
|
|
60
|
+
assert.equal(fs.readFileSync(stampPath, 'utf8').trim(), VERSION);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function testReuseWhenVersionMatches() {
|
|
65
|
+
await withTempLocalDist(async ({ targetPath, stampPath }) => {
|
|
66
|
+
await installBinary();
|
|
67
|
+
const first = fs.readFileSync(targetPath);
|
|
68
|
+
const r = await installBinary();
|
|
69
|
+
assert.equal(r.reused, true);
|
|
70
|
+
assert.deepEqual(fs.readFileSync(targetPath), first);
|
|
71
|
+
assert.equal(fs.readFileSync(stampPath, 'utf8').trim(), VERSION);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function testStaleVersionForcesReinstall() {
|
|
76
|
+
await withTempLocalDist(async ({ targetPath, stampPath, src }) => {
|
|
77
|
+
await installBinary();
|
|
78
|
+
// Simulate an older npm package left a binary + stamp behind.
|
|
79
|
+
fs.writeFileSync(stampPath, '0.0.1\n');
|
|
80
|
+
fs.writeFileSync(targetPath, 'OLD-BINARY');
|
|
81
|
+
fs.writeFileSync(src, 'NEW-BINARY-AFTER-UPGRADE');
|
|
82
|
+
|
|
83
|
+
const r = await installBinary();
|
|
84
|
+
assert.equal(r.reused, false, 'stale .version must not reuse');
|
|
85
|
+
assert.equal(fs.readFileSync(targetPath, 'utf8'), 'NEW-BINARY-AFTER-UPGRADE');
|
|
86
|
+
assert.equal(fs.readFileSync(stampPath, 'utf8').trim(), VERSION);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function testMissingStampForcesReinstall() {
|
|
91
|
+
await withTempLocalDist(async ({ targetPath, stampPath }) => {
|
|
92
|
+
await installBinary();
|
|
93
|
+
fs.rmSync(stampPath);
|
|
94
|
+
fs.writeFileSync(targetPath, 'ORPHAN-BINARY');
|
|
95
|
+
const r = await installBinary();
|
|
96
|
+
assert.equal(r.reused, false, 'missing .version must not reuse');
|
|
97
|
+
assert.equal(fs.readFileSync(stampPath, 'utf8').trim(), VERSION);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
(async () => {
|
|
102
|
+
await testFreshInstallWritesVersionStamp();
|
|
103
|
+
await testReuseWhenVersionMatches();
|
|
104
|
+
await testStaleVersionForcesReinstall();
|
|
105
|
+
await testMissingStampForcesReinstall();
|
|
106
|
+
console.log('OK: packages/cli/scripts/download.test.js');
|
|
107
|
+
})().catch((err) => {
|
|
108
|
+
console.error(err);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
});
|
package/scripts/paths.js
CHANGED
|
@@ -26,12 +26,35 @@ function getDefaultConfigDir() {
|
|
|
26
26
|
return path.join(os.homedir(), '.config', BINARY_NAME);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the config file the Go binary will actually read.
|
|
31
|
+
* Honours the same env vars as internal/config/path.go:
|
|
32
|
+
* SENSECRAFT_CONFIG_FILE → absolute/relative file path
|
|
33
|
+
* SENSECRAFT_CLI_PATH → config directory (file = <dir>/sensecraft.json)
|
|
34
|
+
* npm wrappers inject SENSECRAFT_CLI_PATH via buildEnv(), so the default for
|
|
35
|
+
* users of the npm package is ~/.config/sensecraft-cli/sensecraft.json.
|
|
36
|
+
*/
|
|
37
|
+
function resolveConfigPath() {
|
|
38
|
+
if (process.env.SENSECRAFT_CONFIG_FILE) {
|
|
39
|
+
return path.resolve(process.env.SENSECRAFT_CONFIG_FILE);
|
|
40
|
+
}
|
|
41
|
+
const dir = process.env.SENSECRAFT_CLI_PATH || getDefaultConfigDir();
|
|
42
|
+
return path.join(dir, 'sensecraft.json');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* True when either a SenseCAP Access Key profile or a SenseCraft AI profile
|
|
47
|
+
* is present. Previously only app_config_list was checked, so an AI-only
|
|
48
|
+
* config (auth init --kind ai) was treated as uninitialized.
|
|
49
|
+
*/
|
|
29
50
|
function isInitialized() {
|
|
30
|
-
const configPath =
|
|
51
|
+
const configPath = resolveConfigPath();
|
|
31
52
|
try {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
53
|
+
const cfg = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
54
|
+
const hasSensecap =
|
|
55
|
+
Array.isArray(cfg.app_config_list) && cfg.app_config_list.length > 0;
|
|
56
|
+
const hasAI = Array.isArray(cfg.ai_profiles) && cfg.ai_profiles.length > 0;
|
|
57
|
+
return hasSensecap || hasAI;
|
|
35
58
|
} catch {
|
|
36
59
|
return false;
|
|
37
60
|
}
|
|
@@ -42,5 +65,6 @@ module.exports = {
|
|
|
42
65
|
getVendorDir,
|
|
43
66
|
getBinaryPath,
|
|
44
67
|
getDefaultConfigDir,
|
|
68
|
+
resolveConfigPath,
|
|
45
69
|
isInitialized,
|
|
46
70
|
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const assert = require('assert');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
const { VERSION, releaseArtifactURL } = require('./constants');
|
|
10
|
+
const { isInitialized, resolveConfigPath } = require('./paths');
|
|
11
|
+
|
|
12
|
+
function withEnv(patch, fn) {
|
|
13
|
+
const saved = {};
|
|
14
|
+
for (const k of Object.keys(patch)) {
|
|
15
|
+
saved[k] = process.env[k];
|
|
16
|
+
if (patch[k] === undefined) delete process.env[k];
|
|
17
|
+
else process.env[k] = patch[k];
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
return fn();
|
|
21
|
+
} finally {
|
|
22
|
+
for (const k of Object.keys(patch)) {
|
|
23
|
+
if (saved[k] === undefined) delete process.env[k];
|
|
24
|
+
else process.env[k] = saved[k];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function testReleaseURL() {
|
|
30
|
+
const url = releaseArtifactURL('sensecraft-cli-darwin-arm64');
|
|
31
|
+
assert.ok(url.startsWith('https://sensecraft-statics.seeed.cc/static/bin/sensecraft-cli/'), url);
|
|
32
|
+
assert.ok(url.includes(`/v${VERSION}/sensecraft-cli-darwin-arm64`), url);
|
|
33
|
+
assert.equal(VERSION, require('../package.json').version);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function testResolveConfigPath() {
|
|
37
|
+
withEnv(
|
|
38
|
+
{
|
|
39
|
+
SENSECRAFT_CONFIG_FILE: '/tmp/custom.json',
|
|
40
|
+
SENSECRAFT_CLI_PATH: undefined,
|
|
41
|
+
},
|
|
42
|
+
() => {
|
|
43
|
+
assert.equal(resolveConfigPath(), path.resolve('/tmp/custom.json'));
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
withEnv(
|
|
47
|
+
{
|
|
48
|
+
SENSECRAFT_CONFIG_FILE: undefined,
|
|
49
|
+
SENSECRAFT_CLI_PATH: '/tmp/cfgdir',
|
|
50
|
+
},
|
|
51
|
+
() => {
|
|
52
|
+
assert.equal(resolveConfigPath(), path.join('/tmp/cfgdir', 'sensecraft.json'));
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function testIsInitializedAIOnly() {
|
|
58
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'sc-init-'));
|
|
59
|
+
const cfg = path.join(tmp, 'sensecraft.json');
|
|
60
|
+
fs.writeFileSync(
|
|
61
|
+
cfg,
|
|
62
|
+
JSON.stringify({
|
|
63
|
+
use_ai: 'p1',
|
|
64
|
+
ai_profiles: [{ profile_id: 'p1', access_token: 't' }],
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
withEnv({ SENSECRAFT_CONFIG_FILE: cfg, SENSECRAFT_CLI_PATH: undefined }, () => {
|
|
68
|
+
assert.equal(isInitialized(), true, 'AI-only config must count as initialized');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
fs.writeFileSync(cfg, JSON.stringify({ app_config_list: [] }));
|
|
72
|
+
withEnv({ SENSECRAFT_CONFIG_FILE: cfg }, () => {
|
|
73
|
+
assert.equal(isInitialized(), false, 'empty app_config_list alone is not initialized');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
fs.writeFileSync(
|
|
77
|
+
cfg,
|
|
78
|
+
JSON.stringify({
|
|
79
|
+
app_config_list: [{ key_id: 'k', access_key: 'a' }],
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
withEnv({ SENSECRAFT_CONFIG_FILE: cfg }, () => {
|
|
83
|
+
assert.equal(isInitialized(), true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
testReleaseURL();
|
|
90
|
+
testResolveConfigPath();
|
|
91
|
+
testIsInitializedAIOnly();
|
|
92
|
+
console.log('OK: packages/cli/scripts/paths.test.js');
|
package/scripts/platform.js
CHANGED
|
@@ -22,10 +22,16 @@ function resolvePlatformTarget() {
|
|
|
22
22
|
binary: 'sensecraft-cli.exe',
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
+
if (platform === 'win32' && arch === 'arm64') {
|
|
26
|
+
return {
|
|
27
|
+
artifact: 'sensecraft-cli-windows-arm64.exe',
|
|
28
|
+
binary: 'sensecraft-cli.exe',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
25
31
|
|
|
26
32
|
throw new Error(
|
|
27
|
-
|
|
28
|
-
'
|
|
33
|
+
`Unsupported platform: ${platform}/${arch}. ` +
|
|
34
|
+
'Supported: darwin/linux (x64, arm64) and windows (x64, arm64).'
|
|
29
35
|
);
|
|
30
36
|
}
|
|
31
37
|
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,20 +1,41 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { VERSION, RELEASE_BASE } = require('./constants');
|
|
3
4
|
const { installBinary } = require('./download');
|
|
4
5
|
|
|
5
6
|
async function main() {
|
|
6
7
|
try {
|
|
7
|
-
await installBinary();
|
|
8
|
+
const result = await installBinary();
|
|
9
|
+
if (result.reused) {
|
|
10
|
+
console.log(`sensecraft-cli v${VERSION} already installed (reused cache)`);
|
|
11
|
+
} else {
|
|
12
|
+
console.log(
|
|
13
|
+
`sensecraft-cli v${VERSION} installed from ${result.source || 'release'}`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
8
16
|
} catch (err) {
|
|
9
17
|
console.error('');
|
|
10
|
-
console.error(
|
|
18
|
+
console.error(`sensecraft-cli binary download failed: ${err.message}`);
|
|
11
19
|
console.error('');
|
|
12
|
-
console.error('
|
|
13
|
-
console.error(
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
console.error('Try:');
|
|
21
|
+
console.error(
|
|
22
|
+
` 1. Confirm Release / OSS has the v${VERSION} artifact under:`
|
|
23
|
+
);
|
|
24
|
+
console.error(` ${RELEASE_BASE.replace(/\/+$/, '')}/v${VERSION}/`);
|
|
25
|
+
console.error(
|
|
26
|
+
' 2. Set SENSECRAFT_CLI_LOCAL_DIST to a local dist/ directory and reinstall'
|
|
27
|
+
);
|
|
28
|
+
console.error(
|
|
29
|
+
' 3. Set SENSECRAFT_CLI_RELEASE_BASE to override the download base URL'
|
|
30
|
+
);
|
|
16
31
|
console.error('');
|
|
17
|
-
|
|
32
|
+
// Don't fail the whole npm install on a transient download error when the
|
|
33
|
+
// binary can still be fetched on first invocation (bin/sensecraft-cli.js
|
|
34
|
+
// calls ensureBinary). Exit 0 so `npm install` succeeds; the wrapper will
|
|
35
|
+
// retry. Set SENSECRAFT_CLI_STRICT_POSTINSTALL=1 to make this fatal.
|
|
36
|
+
if (process.env.SENSECRAFT_CLI_STRICT_POSTINSTALL === '1') {
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
18
39
|
}
|
|
19
40
|
}
|
|
20
41
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Isolated install smoke test.
|
|
6
|
+
*
|
|
7
|
+
* Runs postinstall + a non-interactive `sensecraft-cli --version` under a
|
|
8
|
+
* temporary HOME / npm prefix so the developer's real ~/.config and global
|
|
9
|
+
* npm install are never touched. Requires a pre-built binary tree:
|
|
10
|
+
*
|
|
11
|
+
* ./script/build.sh
|
|
12
|
+
* SENSECRAFT_CLI_LOCAL_DIST=$PWD/dist node packages/cli/scripts/test-install.js
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const { spawnSync } = require('child_process');
|
|
19
|
+
|
|
20
|
+
const { VERSION } = require('./constants');
|
|
21
|
+
const { getPackageRoot, getVendorDir } = require('./paths');
|
|
22
|
+
|
|
23
|
+
function fail(msg) {
|
|
24
|
+
console.error(`FAIL: ${msg}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function main() {
|
|
29
|
+
const packageRoot = getPackageRoot();
|
|
30
|
+
const repoRoot = path.resolve(packageRoot, '../..');
|
|
31
|
+
const localDist =
|
|
32
|
+
process.env.SENSECRAFT_CLI_LOCAL_DIST || path.join(repoRoot, 'dist');
|
|
33
|
+
|
|
34
|
+
if (!fs.existsSync(localDist)) {
|
|
35
|
+
fail(
|
|
36
|
+
`no local dist at ${localDist}. Run ./script/build.sh first, ` +
|
|
37
|
+
'or set SENSECRAFT_CLI_LOCAL_DIST.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'sensecraft-cli-test-'));
|
|
42
|
+
const home = path.join(tmp, 'home');
|
|
43
|
+
const npmPrefix = path.join(tmp, 'npm-prefix');
|
|
44
|
+
const vendorDir = getVendorDir();
|
|
45
|
+
fs.mkdirSync(home, { recursive: true });
|
|
46
|
+
fs.mkdirSync(npmPrefix, { recursive: true });
|
|
47
|
+
|
|
48
|
+
// Wipe any previous vendor binary so the install path is exercised.
|
|
49
|
+
fs.rmSync(vendorDir, { recursive: true, force: true });
|
|
50
|
+
|
|
51
|
+
const env = {
|
|
52
|
+
...process.env,
|
|
53
|
+
HOME: home,
|
|
54
|
+
USERPROFILE: home, // windows
|
|
55
|
+
APPDATA: path.join(home, 'AppData', 'Roaming'),
|
|
56
|
+
SENSECRAFT_CLI_LOCAL_DIST: localDist,
|
|
57
|
+
// Force the Go binary to write config under the temp HOME.
|
|
58
|
+
SENSECRAFT_CLI_PATH: path.join(home, '.config', 'sensecraft-cli'),
|
|
59
|
+
npm_config_prefix: npmPrefix,
|
|
60
|
+
// Non-interactive: install.js must skip auth init.
|
|
61
|
+
CI: '1',
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
console.log(`==> postinstall (LOCAL_DIST=${localDist})`);
|
|
65
|
+
let r = spawnSync(process.execPath, [path.join(packageRoot, 'scripts/postinstall.js')], {
|
|
66
|
+
stdio: 'inherit',
|
|
67
|
+
env,
|
|
68
|
+
cwd: packageRoot,
|
|
69
|
+
});
|
|
70
|
+
if (r.status !== 0) {
|
|
71
|
+
fail(`postinstall exited ${r.status}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const stamp = path.join(vendorDir, '.version');
|
|
75
|
+
if (!fs.existsSync(stamp) || fs.readFileSync(stamp, 'utf8').trim() !== VERSION) {
|
|
76
|
+
fail(`vendor/.version missing or != ${VERSION}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
console.log('==> sensecraft-cli --version');
|
|
80
|
+
r = spawnSync(
|
|
81
|
+
process.execPath,
|
|
82
|
+
[path.join(packageRoot, 'bin/sensecraft-cli.js'), '--version'],
|
|
83
|
+
{ encoding: 'utf8', env, cwd: packageRoot }
|
|
84
|
+
);
|
|
85
|
+
if (r.status !== 0) {
|
|
86
|
+
fail(`--version exited ${r.status}: ${r.stderr || r.stdout}`);
|
|
87
|
+
}
|
|
88
|
+
const out = ((r.stdout || '') + (r.stderr || '')).trim();
|
|
89
|
+
// Local ./script/build.sh injects git-describe (e.g. v2026061000-2-g…);
|
|
90
|
+
// release tags inject the npm package version. Accept any non-empty
|
|
91
|
+
// `--version` line — the point of this smoke is "binary runs".
|
|
92
|
+
if (!/version/i.test(out)) {
|
|
93
|
+
fail(`--version output unexpected: ${out}`);
|
|
94
|
+
}
|
|
95
|
+
console.log(out);
|
|
96
|
+
|
|
97
|
+
// Confirm we did not pollute the real home.
|
|
98
|
+
const realConfig = path.join(os.homedir(), '.config', 'sensecraft-cli');
|
|
99
|
+
// We can't assert the real config is untouched in content, but we can assert
|
|
100
|
+
// our temp HOME received the SENSECRAFT_CLI_PATH we set and nothing wrote
|
|
101
|
+
// outside tmp.
|
|
102
|
+
if (!tmp.startsWith(os.tmpdir())) {
|
|
103
|
+
fail('temp dir escaped os.tmpdir()');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Skills must be present in the package (synced by prepack / sync script).
|
|
107
|
+
const skillsIndex = path.join(packageRoot, 'skills', 'sensecraft-ai', 'SKILL.md');
|
|
108
|
+
if (!fs.existsSync(skillsIndex)) {
|
|
109
|
+
console.warn(
|
|
110
|
+
`WARN: ${skillsIndex} missing — run ./script/sync-skills-to-npm.sh before publish`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
console.log(`OK: isolated install smoke passed (tmp=${tmp})`);
|
|
115
|
+
// Leave tmp for inspection unless CLEAN=1.
|
|
116
|
+
if (process.env.CLEAN === '1') {
|
|
117
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
main();
|
package/skills/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Skills discovery (Cursor / Agents)
|
|
2
|
+
|
|
3
|
+
Skills for this repo live under `skills/`.
|
|
4
|
+
|
|
5
|
+
## Layout
|
|
6
|
+
|
|
7
|
+
| Path | Auth | Purpose |
|
|
8
|
+
|------|------|---------|
|
|
9
|
+
| `skills/sensecraft-ai/SKILL.md` | router | Meta: pick skill + auth kind |
|
|
10
|
+
| `skills/sensecraft-data/` | `sensecap` | SenseCAP PaaS: devices / groups / data |
|
|
11
|
+
| `skills/sensecraft-apps/` | Access Key | Application Plaza |
|
|
12
|
+
| `skills/sensecraft-files/` | Access Key | Upload file and obtain `file_url` |
|
|
13
|
+
| `skills/sensecraft-models/` | Access Key | Model library |
|
|
14
|
+
| `skills/sensecraft-recamera/` | `sensecap` Access Key | Classic reCamera 40 pick / check / open |
|
|
15
|
+
| `skills/sensecraft-devices-cloud/` | Access Key | Jetson / cloud kit deploy |
|
|
16
|
+
|
|
17
|
+
## Cursor / Agent setup
|
|
18
|
+
|
|
19
|
+
1. 安装 CLI:见仓库根目录 [`INSTALL.md`](../INSTALL.md) §2 / §9。
|
|
20
|
+
2. Point the agent at this repo (or copy/symlink these Skill folders into the agent’s skills path).
|
|
21
|
+
3. Prefer loading **`sensecraft-ai`** first for any SenseCraft AI question — it routes to domain skills (including SenseCAP via `sensecraft-data`).
|
|
22
|
+
4. **L2 writes:** follow [`confirmation.md`](confirmation.md). Never pass `--yes` on the same turn as the user's first request.
|
|
23
|
+
5. Binary: `sensecraft-cli` must be on `PATH` (`npx @seeed-studio/sensecraft-cli install` or build from repo root).
|
|
24
|
+
|
|
25
|
+
Finding skills after a global npm install:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
ls "$(npm root -g)/@seeed-studio/sensecraft-cli/skills"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Version sync
|
|
32
|
+
|
|
33
|
+
When adding a CLI command: update the domain skill `SKILL.md` + `commands.md` in the **same change**, and tick `website-sensecraft-console/docs/sensecraft-ai-skills-todo.md` if that doc is in the workspace.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# L2 confirmation protocol (mandatory)
|
|
2
|
+
|
|
3
|
+
`--yes` / `--agree-declaration` / `--agree-disclaimer` mean **the user already answered a confirmation question in this conversation**. They are not shortcuts.
|
|
4
|
+
|
|
5
|
+
## First user request is INTENT, not confirmation
|
|
6
|
+
|
|
7
|
+
These are **not** confirmation. Do **not** pass `--yes` on the same turn:
|
|
8
|
+
|
|
9
|
+
- 「删这个63760」「删除应用 demo」「把模型下架」「发布这个模型」
|
|
10
|
+
- 「delete this」「unpublish」「deploy to the device」
|
|
11
|
+
- Any first mention of create / modify / clone / publish / unpublish / delete / deploy / stop / bind / unbind
|
|
12
|
+
|
|
13
|
+
## Required chat question (before any L2 CLI)
|
|
14
|
+
|
|
15
|
+
Ask in chat. **Do not run** the write command yet. The question MUST include at least:
|
|
16
|
+
|
|
17
|
+
1. **操作类型** — 删除 / 发布 / 私有化 / 部署 / 停止 / 克隆 / 修改 / 绑定 / …
|
|
18
|
+
2. **环境** — `auth info` 的 Global / Develop / China(生产环境须点明)
|
|
19
|
+
3. **对象** — 名称 + ID(没有名称就先 `view` / `list` 再问)
|
|
20
|
+
|
|
21
|
+
Template:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
将从{环境}环境{操作}{对象}(ID: {id})。{后果}。是否确认执行?
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Example (user said 「删除应用 demo」):
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
将从 Global 环境删除应用 demo(ID: 123)。删除后可能无法恢复。是否确认执行?
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Example (user said 「删这个63760」):
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
将从 Develop 环境删除模型 63760。删除后可能无法恢复。是否确认执行?
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Classic reCamera flash is **not** an L2 `--yes` write. After the user picked the app/model (and firmware if several), `recamera open` may run. The user then clicks Deploy in Console (L3). Do not invent `recamera deploy`.
|
|
40
|
+
|
|
41
|
+
Wait for a **new** user reply: `确认` / `confirm` / `yes`. Only then:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
sensecraft-cli model delete --id 63760 --yes
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Never
|
|
48
|
+
|
|
49
|
+
- Never add `--yes` on the same turn as the first request
|
|
50
|
+
- Never treat `--yes` as “the user already said delete”
|
|
51
|
+
- Never skip the question because the user sounded sure
|
|
52
|
+
- Production / Global / China: say the environment explicitly (special confirm)
|
|
53
|
+
|
|
54
|
+
## After the user confirms
|
|
55
|
+
|
|
56
|
+
Then pass `--yes` (and `--agree-declaration` / `--agree-disclaimer` only if they also agreed to that legal text).
|