@powerbase/cli 0.0.0-stage → 0.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.
- package/README.md +62 -2
- package/bin/powerbase.js +47 -0
- package/install-config.json +3 -0
- package/package.json +26 -5
- package/scripts/postinstall.js +54 -0
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PowerBase CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
PowerBase CLI(`powerbase`)用于在终端或 AI 办公助手里检索、问答和管理 PowerBase 知识库。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
需要 Node.js 18 及以上。Windows 与 macOS 使用同一条命令:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @powerbase/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
安装会自动匹配当前平台(Windows x64/ARM64、macOS Apple 芯片/Intel),并预置公司服务器地址。
|
|
14
|
+
|
|
15
|
+
## 登录
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
powerbase auth login
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
命令会打开浏览器授权页,登录公司账号并点击“授权 CLI 登录”,终端会自动完成登录。凭据保存在系统凭据管理器(Windows 凭据管理器 / macOS 钥匙串)。
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
powerbase auth status # 查看当前账号与空间
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 快速开始
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
powerbase space list # 我有哪些空间
|
|
31
|
+
powerbase kb list # 当前空间的知识库
|
|
32
|
+
powerbase search chunks "合同评审流程" # 检索原文片段
|
|
33
|
+
powerbase chat "总结一下这份报告" # 基于知识库问答
|
|
34
|
+
powerbase doc upload ./报告.pdf # 上传文档(会先确认目标知识库)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 接入 AI 办公助手
|
|
38
|
+
|
|
39
|
+
技能是带 `SKILL.md` 的普通目录,任何支持 Agent Skills 的助手都能用:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
powerbase skills install --name powerbase --dir <助手技能目录>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
常见助手的技能目录(相对用户主目录):
|
|
46
|
+
|
|
47
|
+
| 助手 | Windows | macOS |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| WorkBuddy | `%USERPROFILE%\.workbuddy\skills` | `~/.workbuddy/skills` |
|
|
50
|
+
|
|
51
|
+
其他助手:在其设置中查看“技能/插件目录”,用同一条命令指过去即可。
|
|
52
|
+
|
|
53
|
+
## 升级与卸载
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install -g @powerbase/cli@latest # 升级
|
|
57
|
+
npm uninstall -g @powerbase/cli # 卸载(登录态保留在系统凭据管理器)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 说明
|
|
61
|
+
|
|
62
|
+
- 仅支持公司内网环境;公开包内的下载与更新逻辑不依赖外部服务。
|
|
63
|
+
- 所有命令默认输出 JSON,便于脚本和 Agent 解析;人工阅读可加 `--format text`。
|
package/bin/powerbase.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { spawnSync } = require('node:child_process');
|
|
6
|
+
|
|
7
|
+
const PLATFORM_PACKAGES = {
|
|
8
|
+
'win32-x64': '@powerbase/cli-win32-x64',
|
|
9
|
+
'win32-arm64': '@powerbase/cli-win32-arm64',
|
|
10
|
+
'darwin-arm64': '@powerbase/cli-darwin-arm64',
|
|
11
|
+
'darwin-x64': '@powerbase/cli-darwin-x64',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function resolveBinary() {
|
|
15
|
+
const key = `${process.platform}-${process.arch}`;
|
|
16
|
+
const pkg = PLATFORM_PACKAGES[key];
|
|
17
|
+
if (!pkg) {
|
|
18
|
+
console.error(
|
|
19
|
+
`PowerBase CLI 暂不支持当前系统:${process.platform}-${process.arch}\n` +
|
|
20
|
+
`支持的平台:${Object.keys(PLATFORM_PACKAGES).join(', ')}`,
|
|
21
|
+
);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const pkgJson = require.resolve(`${pkg}/package.json`);
|
|
26
|
+
const exe = process.platform === 'win32' ? 'powerbase.exe' : 'powerbase';
|
|
27
|
+
return path.join(path.dirname(pkgJson), 'bin', exe);
|
|
28
|
+
} catch {
|
|
29
|
+
console.error(
|
|
30
|
+
`PowerBase CLI 缺少平台组件 ${pkg}。\n` +
|
|
31
|
+
`请重新安装:npm install -g @powerbase/cli\n` +
|
|
32
|
+
`(若使用了 --omit=optional,请去掉后重装。)`,
|
|
33
|
+
);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result = spawnSync(resolveBinary(), process.argv.slice(2), { stdio: 'inherit' });
|
|
39
|
+
|
|
40
|
+
if (result.error) {
|
|
41
|
+
console.error(`PowerBase CLI 启动失败:${result.error.message}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
if (result.signal) {
|
|
45
|
+
process.kill(process.pid, result.signal);
|
|
46
|
+
}
|
|
47
|
+
process.exit(result.status === null ? 1 : result.status);
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@powerbase/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "PowerBase CLI - query and manage PowerBase knowledge bases from the terminal",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": {
|
|
7
|
+
"powerbase": "bin/powerbase.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"scripts/postinstall.js",
|
|
12
|
+
"install-config.json",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"postinstall": "node scripts/postinstall.js"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": "\u003e=18"
|
|
20
|
+
},
|
|
21
|
+
"optionalDependencies": {
|
|
22
|
+
"@powerbase/cli-win32-x64": "0.1.0",
|
|
23
|
+
"@powerbase/cli-win32-arm64": "0.1.0",
|
|
24
|
+
"@powerbase/cli-darwin-arm64": "0.1.0",
|
|
25
|
+
"@powerbase/cli-darwin-x64": "0.1.0"
|
|
26
|
+
}
|
|
6
27
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// 全局安装时预置默认 profile,员工装完只需 auth login。
|
|
4
|
+
// 任何异常都不阻断安装:失败时打印提示,由用户手动执行同样命令。
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { spawnSync } = require('node:child_process');
|
|
9
|
+
|
|
10
|
+
if (String(process.env.npm_config_global) !== 'true') process.exit(0);
|
|
11
|
+
|
|
12
|
+
const PLATFORM_PACKAGES = {
|
|
13
|
+
'win32-x64': '@powerbase/cli-win32-x64',
|
|
14
|
+
'win32-arm64': '@powerbase/cli-win32-arm64',
|
|
15
|
+
'darwin-arm64': '@powerbase/cli-darwin-arm64',
|
|
16
|
+
'darwin-x64': '@powerbase/cli-darwin-x64',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function resolveBinary() {
|
|
20
|
+
const pkg = PLATFORM_PACKAGES[`${process.platform}-${process.arch}`];
|
|
21
|
+
if (!pkg) return null;
|
|
22
|
+
try {
|
|
23
|
+
const pkgJson = require.resolve(`${pkg}/package.json`);
|
|
24
|
+
const exe = process.platform === 'win32' ? 'powerbase.exe' : 'powerbase';
|
|
25
|
+
return path.join(path.dirname(pkgJson), 'bin', exe);
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const configPath = path.join(__dirname, '..', 'install-config.json');
|
|
33
|
+
if (!fs.existsSync(configPath)) process.exit(0);
|
|
34
|
+
const { serverHost } = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
35
|
+
if (!serverHost) process.exit(0);
|
|
36
|
+
|
|
37
|
+
const binary = resolveBinary();
|
|
38
|
+
if (!binary) process.exit(0);
|
|
39
|
+
|
|
40
|
+
const result = spawnSync(
|
|
41
|
+
binary,
|
|
42
|
+
['profile', 'add', 'powerbase', '--host', serverHost, '--use', '--format', 'json'],
|
|
43
|
+
{ encoding: 'utf8' },
|
|
44
|
+
);
|
|
45
|
+
if (result.status !== 0) {
|
|
46
|
+
const output = `${result.stdout || ''}${result.stderr || ''}`;
|
|
47
|
+
if (!output.includes('already exists')) {
|
|
48
|
+
console.warn(`PowerBase CLI: 未能自动创建默认连接,请手动执行:powerbase profile add powerbase --host ${serverHost} --use`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch {
|
|
52
|
+
// 静默:安装不应因预置失败而中止。
|
|
53
|
+
}
|
|
54
|
+
process.exit(0);
|