@bolloon/bolloon-agent 0.1.1 → 0.1.3
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/bin/bolloon-cli.cjs +165 -0
- package/bin/bolloon-daemon.sh +207 -0
- package/bin/bolloon.cmd +11 -0
- package/dist/agents/constraint-layer.js +10 -15
- package/dist/agents/pi-sdk.js +433 -106
- package/dist/agents/protocol.js +82 -1
- package/dist/agents/subagent-manager.js +2 -2
- package/dist/agents/workflow-engine.js +15 -20
- package/dist/agents/workflow-pivot-loop.js +541 -0
- package/dist/bollharness/src/index.js +5 -0
- package/dist/bollharness/src/scripts/checks/check_adr_plan_numbering.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_api_types.js +45 -0
- package/dist/bollharness/src/scripts/checks/check_artifact_link.js +146 -0
- package/dist/bollharness/src/scripts/checks/check_bridge_deps.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_bugfix_binding.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_bugfix_binding_ci.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_doc_file_references.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +135 -0
- package/dist/bollharness/src/scripts/checks/check_doc_links.js +31 -0
- package/dist/bollharness/src/scripts/checks/check_file_existence_claims.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_fragment_integrity.js +34 -0
- package/dist/bollharness/src/scripts/checks/check_hook_installed.js +63 -0
- package/dist/bollharness/src/scripts/checks/check_issue_closure.js +41 -0
- package/dist/bollharness/src/scripts/checks/check_mcp_parity.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_security.js +48 -0
- package/dist/bollharness/src/scripts/checks/check_skill_parity.js +6 -0
- package/dist/bollharness/src/scripts/checks/check_versions.js +6 -0
- package/dist/bollharness/src/scripts/checks/finding.js +13 -0
- package/dist/bollharness/src/scripts/checks/next_decision_number.js +20 -0
- package/dist/bollharness/src/scripts/checks/regenerate_magic_docs.js +6 -0
- package/dist/bollharness/src/scripts/ci/detect_rebaseline_triggers.js +8 -0
- package/dist/bollharness/src/scripts/ci/scan_subprocess_cfg.js +8 -0
- package/dist/bollharness/src/scripts/ci/scan_verify_artifacts.js +8 -0
- package/dist/bollharness/src/scripts/ci/scan_yaml_schema.js +8 -0
- package/dist/bollharness/src/scripts/context_router.js +67 -0
- package/dist/bollharness/src/scripts/deploy-guard.js +157 -0
- package/dist/bollharness/src/scripts/guard-feedback.js +192 -0
- package/dist/bollharness/src/scripts/guard_router.js +158 -0
- package/dist/bollharness/src/scripts/hooks/_hook_output.js +6 -0
- package/dist/bollharness/src/scripts/hooks/auto-python3.js +6 -0
- package/dist/bollharness/src/scripts/hooks/deploy-progress-on-session-end.js +6 -0
- package/dist/bollharness/src/scripts/hooks/failure-analyzer.js +6 -0
- package/dist/bollharness/src/scripts/hooks/gate-judgment-inject.js +92 -0
- package/dist/bollharness/src/scripts/hooks/gate-transition-judgment.js +63 -0
- package/dist/bollharness/src/scripts/hooks/inbox-ack.js +6 -0
- package/dist/bollharness/src/scripts/hooks/inbox-inject-on-start.js +6 -0
- package/dist/bollharness/src/scripts/hooks/inbox-validate.js +6 -0
- package/dist/bollharness/src/scripts/hooks/inbox-write-ledger.js +6 -0
- package/dist/bollharness/src/scripts/hooks/initializer-agent.js +6 -0
- package/dist/bollharness/src/scripts/hooks/loop-detection.js +73 -0
- package/dist/bollharness/src/scripts/hooks/owner-guard.js +6 -0
- package/dist/bollharness/src/scripts/hooks/precompact.js +6 -0
- package/dist/bollharness/src/scripts/hooks/review-agent-gatekeeper.js +6 -0
- package/dist/bollharness/src/scripts/hooks/risk-tracker.js +108 -0
- package/dist/bollharness/src/scripts/hooks/sanitize-on-read.js +6 -0
- package/dist/bollharness/src/scripts/hooks/session-reflection.js +7 -0
- package/dist/bollharness/src/scripts/hooks/session-start-magic-docs.js +7 -0
- package/dist/bollharness/src/scripts/hooks/session-start-reset-risk.js +7 -0
- package/dist/bollharness/src/scripts/hooks/session-start-toolkit-reminder.js +7 -0
- package/dist/bollharness/src/scripts/hooks/stop-evaluator.js +157 -0
- package/dist/bollharness/src/scripts/hooks/tool-call-counter.js +6 -0
- package/dist/bollharness/src/scripts/hooks/trace-analyzer.js +10 -0
- package/dist/bollharness/src/scripts/install/install-trust-token.js +7 -0
- package/dist/bollharness/src/scripts/install/multi_project_registry.js +9 -0
- package/dist/bollharness/src/scripts/install/phase2_auto.js +21 -0
- package/dist/bollharness/src/scripts/install/pre_commit_installer.js +6 -0
- package/dist/bollharness/src/scripts/install/tier_selector.js +7 -0
- package/dist/bollharness/src/scripts/install/transcript_miner.js +7 -0
- package/dist/bollharness/src/scripts/lib/claim_patterns.js +10 -0
- package/dist/bollharness/src/scripts/lib/sanitize_patterns.js +12 -0
- package/dist/bollharness/src/scripts/sanitize.js +6 -0
- package/dist/bollharness-integration/channel-judgment-engine.js +530 -0
- package/dist/bollharness-integration/context-chain-router.js +383 -0
- package/dist/bollharness-integration/context-router-judgment.js +13 -21
- package/dist/bollharness-integration/context-router.js +22 -64
- package/dist/bollharness-integration/gate-state-machine.js +14 -19
- package/dist/bollharness-integration/gate-transition-hooks.js +16 -61
- package/dist/bollharness-integration/guard-checker.js +21 -68
- package/dist/bollharness-integration/index.js +14 -124
- package/dist/bollharness-integration/integration.js +13 -20
- package/dist/bollharness-integration/llm-judgment-engine.js +569 -0
- package/dist/bollharness-integration/skill-adapter.js +18 -64
- package/dist/cli-entry.js +261 -0
- package/dist/constraint-runtime/src/commands.js +17 -7
- package/dist/constraint-runtime/src/constraint/budget.js +1 -6
- package/dist/constraint-runtime/src/constraint/permission.js +1 -6
- package/dist/constraint-runtime/src/models.js +1 -3
- package/dist/constraint-runtime/src/tools.js +17 -7
- package/dist/constraints/index.js +1 -7
- package/dist/documents/reader.js +8 -49
- package/dist/heartbeat/DaemonManager.js +242 -0
- package/dist/heartbeat/HealthMonitor.js +285 -0
- package/dist/heartbeat/StartupVerifier.js +205 -0
- package/dist/heartbeat/Watchdog.js +168 -0
- package/dist/heartbeat/index.js +84 -0
- package/dist/heartbeat/types.js +5 -0
- package/dist/index.js +381 -28
- package/dist/llm/config-store.js +31 -57
- package/dist/llm/llm-judgment-client.js +389 -0
- package/dist/llm/pi-ai.js +9 -52
- package/dist/network/agent-network.js +46 -90
- package/dist/network/hybrid-messenger.js +125 -0
- package/dist/network/iroh-bootstrap.js +38 -0
- package/dist/network/iroh-discovery.js +145 -0
- package/dist/network/iroh-integration.js +9 -16
- package/dist/network/iroh-transport.js +10 -48
- package/dist/network/p2p.js +23 -62
- package/dist/network/storage/adapters/json-adapter.js +4 -42
- package/dist/network/storage/index.js +147 -0
- package/dist/network/storage/types.js +14 -0
- package/dist/pi-ecosystem/index.js +233 -0
- package/dist/pi-ecosystem-colony/index.js +29 -90
- package/dist/pi-ecosystem-goals/index.js +20 -74
- package/dist/pi-ecosystem-judgment/decision.js +29 -47
- package/dist/pi-ecosystem-judgment/distillation.js +16 -29
- package/dist/pi-ecosystem-judgment/human-value-store.js +13 -60
- package/dist/pi-ecosystem-judgment/index.js +21 -74
- package/dist/pi-ecosystem-judgment/value-injection.js +26 -72
- package/dist/pi-ecosystem-mcp/index.js +24 -78
- package/dist/pi-ecosystem-subagents/index.js +20 -69
- package/dist/social/ant-colony/AdaptiveHeartbeat.js +3 -8
- package/dist/social/ant-colony/PheromoneEngine.js +11 -49
- package/dist/social/ant-colony/index.js +6 -0
- package/dist/social/ant-colony/types.js +4 -8
- package/dist/social/channels/ChannelManager.js +8 -46
- package/dist/social/channels/DiapChannelBridge.js +9 -47
- package/dist/social/channels/InterestMatcher.js +2 -7
- package/dist/social/channels/channel-agent-session.js +309 -0
- package/dist/social/channels/channel-heartbeat-agent.js +494 -0
- package/dist/social/channels/diap-doc-parser.js +204 -0
- package/dist/social/channels/harness-workflow-integrator.js +446 -0
- package/dist/social/channels/index.js +9 -0
- package/dist/social/channels/types.js +3 -7
- package/dist/social/global-shared-context.js +6 -47
- package/dist/social/heartbeat.js +29 -72
- package/dist/social/persona/enhanced-persona.js +299 -0
- package/dist/web/client.js +302 -136
- package/dist/web/components/p2p/index.js +159 -9
- package/dist/web/components/p2p/p2p-connection.js +136 -0
- package/dist/web/components/p2p/p2p-manager.js +24 -0
- package/dist/web/components/p2p/p2p-store-memory.js +1 -1
- package/dist/web/components/p2p/types.js +7 -0
- package/dist/web/index.html +5 -0
- package/dist/web/style.css +118 -0
- package/package.json +12 -6
- package/scripts/build-cli.js +206 -0
- package/scripts/postinstall.js +153 -0
- package/src/agents/pi-sdk.ts +347 -28
- package/src/agents/protocol.ts +95 -1
- package/src/agents/workflow-pivot-loop.ts +674 -0
- package/src/bollharness/CLAUDE.md +73 -0
- package/src/bollharness/README.md +143 -0
- package/src/bollharness/README.zh-CN.md +131 -0
- package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +57 -0
- package/src/bollharness/scripts/context-fragments/artifact-linkage.md +14 -0
- package/src/bollharness/scripts/context-fragments/auth-consumers.md +17 -0
- package/src/bollharness/scripts/context-fragments/bridge-constitution.md +13 -0
- package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +18 -0
- package/src/bollharness/scripts/context-fragments/closure-checklist.md +13 -0
- package/src/bollharness/scripts/context-fragments/contract-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/db-shared-structures.md +15 -0
- package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +19 -0
- package/src/bollharness/scripts/context-fragments/general-dev-principles.md +11 -0
- package/src/bollharness/scripts/context-fragments/issue-first.md +8 -0
- package/src/bollharness/scripts/context-fragments/mcp-parity.md +16 -0
- package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +108 -0
- package/src/bollharness/scripts/context-fragments/protocol-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/run-events-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/scene-fidelity.md +13 -0
- package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +15 -0
- package/src/bollharness/scripts/context-fragments/two-language.md +15 -0
- package/src/bollharness/scripts/context-fragments/version-sources.md +14 -0
- package/src/bollharness/scripts/hooks/stop-evaluator.md +83 -0
- package/src/bollharness/templates/scaffold/CLAUDE.md +89 -0
- package/src/cli-entry.ts +304 -0
- package/src/heartbeat/DaemonManager.ts +283 -0
- package/src/heartbeat/HealthMonitor.ts +316 -0
- package/src/heartbeat/StartupVerifier.ts +223 -0
- package/src/heartbeat/Watchdog.ts +198 -0
- package/src/heartbeat/index.ts +108 -0
- package/src/heartbeat/types.ts +82 -0
- package/src/llm/config-store.ts +23 -5
- package/src/network/iroh-transport.ts +3 -3
- package/src/web/client.js +302 -136
- package/src/web/components/p2p/P2PModal.tsx +91 -3
- package/src/web/components/p2p/index.ts +171 -9
- package/src/web/components/p2p/p2p-connection.ts +153 -1
- package/src/web/components/p2p/p2p-manager.ts +39 -1
- package/src/web/components/p2p/p2p-store-memory.ts +1 -1
- package/src/web/components/p2p/p2p-tools.ts +315 -0
- package/src/web/components/p2p/types.ts +58 -0
- package/src/web/design.md +99 -0
- package/src/web/index.html +5 -0
- package/src/web/server.ts +353 -36
- package/src/web/style.css +118 -0
- package/tsconfig.cli.json +16 -0
- package/tsconfig.electron.json +1 -1
- package/tsconfig.json +1 -2
- package/dist/web/server.js +0 -1647
- package/dist/web/server.js.map +0 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI 构建脚本
|
|
3
|
+
*
|
|
4
|
+
* 生成 bin/bolloon.js 和 bin/bolloon.cmd 入口文件
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
const rootDir = path.join(__dirname, '..');
|
|
14
|
+
|
|
15
|
+
const binDir = path.join(rootDir, 'bin');
|
|
16
|
+
if (!fs.existsSync(binDir)) {
|
|
17
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Windows 批处理入口
|
|
21
|
+
const winContent = `@echo off
|
|
22
|
+
set "BOLLOON_ROOT=%~dp0"
|
|
23
|
+
set "BOLLOON_ROOT=%BOLLOON_ROOT:~0,-1%"
|
|
24
|
+
|
|
25
|
+
REM 确定入口文件
|
|
26
|
+
set "ENTRY=%BOLLOON_ROOT%\\dist\\index.js"
|
|
27
|
+
if not exist "%ENTRY%" (
|
|
28
|
+
set "ENTRY=%BOLLOON_ROOT%\\src\\index.ts"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
node "%ENTRY%" %*
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
fs.writeFileSync(path.join(binDir, 'bolloon.cmd'), winContent);
|
|
35
|
+
|
|
36
|
+
// Unix/Linux/Mac 入口脚本
|
|
37
|
+
const unixContent = `#!/usr/bin/env node
|
|
38
|
+
const path = require("path");
|
|
39
|
+
const { spawn } = require("child_process");
|
|
40
|
+
const fs = require("fs");
|
|
41
|
+
|
|
42
|
+
const RESET = "\\x1b[0m";
|
|
43
|
+
const BOLD = "\\x1b[1m";
|
|
44
|
+
const CYAN = "\\x1b[36m";
|
|
45
|
+
const GREEN = "\\x1b[32m";
|
|
46
|
+
const MAGENTA = "\\x1b[35m";
|
|
47
|
+
|
|
48
|
+
function log(msg, color) {
|
|
49
|
+
console.log((color || RESET) + msg + RESET);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function printBanner() {
|
|
53
|
+
console.log("\\n" + CYAN + BOLD + [
|
|
54
|
+
" ╔═══════════════════════════════════════════╗",
|
|
55
|
+
" ║ 🤖 Bolloon Agent ║",
|
|
56
|
+
" ║ P2P AI Document Processor ║",
|
|
57
|
+
" ╚═══════════════════════════════════════════╝"
|
|
58
|
+
].join("\\n") + RESET + "\\n");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getMainEntry() {
|
|
62
|
+
const distDir = path.dirname(require.main.filename);
|
|
63
|
+
const distIndex = path.join(distDir, "index.js");
|
|
64
|
+
if (fs.existsSync(distIndex)) {
|
|
65
|
+
return distIndex;
|
|
66
|
+
}
|
|
67
|
+
return path.join(process.cwd(), "src", "index.ts");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseArgs() {
|
|
71
|
+
const args = process.argv.slice(2);
|
|
72
|
+
if (args.length === 0) {
|
|
73
|
+
return { mode: "gui", args: [] };
|
|
74
|
+
}
|
|
75
|
+
const first = args[0];
|
|
76
|
+
switch (first) {
|
|
77
|
+
case "-v":
|
|
78
|
+
case "--version":
|
|
79
|
+
return { mode: "version", args: [] };
|
|
80
|
+
case "-h":
|
|
81
|
+
case "--help":
|
|
82
|
+
return { mode: "help", args: [] };
|
|
83
|
+
case "-g":
|
|
84
|
+
case "--gui":
|
|
85
|
+
return { mode: "gui", args: args.slice(1) };
|
|
86
|
+
case "-w":
|
|
87
|
+
case "--web":
|
|
88
|
+
return { mode: "web", args: args.slice(1) };
|
|
89
|
+
case "-c":
|
|
90
|
+
case "--cli":
|
|
91
|
+
return { mode: "cli", args: args.slice(1) };
|
|
92
|
+
default:
|
|
93
|
+
return { mode: "passthrough", args };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function startElectron(additionalArgs) {
|
|
98
|
+
try {
|
|
99
|
+
const electron = require("electron");
|
|
100
|
+
const distDir = path.dirname(require.main.filename);
|
|
101
|
+
let mainPath = path.join(distDir, "electron.js");
|
|
102
|
+
if (!fs.existsSync(mainPath)) {
|
|
103
|
+
mainPath = path.join(process.cwd(), "src", "electron.ts");
|
|
104
|
+
}
|
|
105
|
+
log("启动 Electron...", CYAN);
|
|
106
|
+
const child = spawn(electron, [mainPath, ...additionalArgs], {
|
|
107
|
+
stdio: "inherit",
|
|
108
|
+
env: { ...process.env, NODE_ENV: "development" }
|
|
109
|
+
});
|
|
110
|
+
child.on("error", (err) => {
|
|
111
|
+
log("Electron 启动失败: " + err.message, MAGENTA);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
});
|
|
114
|
+
child.on("exit", (code) => process.exit(code || 0));
|
|
115
|
+
} catch (err) {
|
|
116
|
+
log("Electron 不可用,切换到 Web 模式...", CYAN);
|
|
117
|
+
await startWebServer(additionalArgs);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function startWebServer(additionalArgs) {
|
|
122
|
+
const mainPath = getMainEntry();
|
|
123
|
+
const webArgs = ["--web", ...additionalArgs];
|
|
124
|
+
log("启动 Web 服务...", CYAN);
|
|
125
|
+
const child = spawn(process.execPath, [mainPath, ...webArgs], { stdio: "inherit" });
|
|
126
|
+
child.on("error", (err) => {
|
|
127
|
+
log("Web 服务启动失败: " + err.message, MAGENTA);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
});
|
|
130
|
+
child.on("exit", (code) => process.exit(code || 0));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function startCLI(additionalArgs) {
|
|
134
|
+
const mainPath = getMainEntry();
|
|
135
|
+
log("启动命令行界面...", CYAN);
|
|
136
|
+
const child = spawn(process.execPath, [mainPath, ...additionalArgs], { stdio: "inherit" });
|
|
137
|
+
child.on("error", (err) => {
|
|
138
|
+
log("CLI 启动失败: " + err.message, MAGENTA);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
});
|
|
141
|
+
child.on("exit", (code) => process.exit(code || 0));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function main() {
|
|
145
|
+
const { mode, args } = parseArgs();
|
|
146
|
+
switch (mode) {
|
|
147
|
+
case "version":
|
|
148
|
+
console.log("Bolloon Agent v0.1.1");
|
|
149
|
+
break;
|
|
150
|
+
case "help":
|
|
151
|
+
printBanner();
|
|
152
|
+
console.log(BOLD + "用法:" + RESET + " bolloon [选项] [命令] [参数]");
|
|
153
|
+
console.log(BOLD + "选项:" + RESET + " --gui, -g 启动图形界面");
|
|
154
|
+
console.log(" --web, -w 启动 Web UI");
|
|
155
|
+
console.log(" --cli, -c 启动命令行界面");
|
|
156
|
+
console.log(" --version, -v 显示版本");
|
|
157
|
+
console.log(" --help, -h 显示帮助");
|
|
158
|
+
console.log(BOLD + "示例:" + RESET + " bolloon # 启动图形界面");
|
|
159
|
+
console.log(" bolloon --web # 启动 Web UI");
|
|
160
|
+
console.log(" bolloon --read file # 读取文档");
|
|
161
|
+
break;
|
|
162
|
+
case "gui":
|
|
163
|
+
printBanner();
|
|
164
|
+
await startElectron(args);
|
|
165
|
+
break;
|
|
166
|
+
case "web":
|
|
167
|
+
printBanner();
|
|
168
|
+
await startWebServer(args);
|
|
169
|
+
break;
|
|
170
|
+
case "cli":
|
|
171
|
+
await startCLI(args);
|
|
172
|
+
break;
|
|
173
|
+
case "passthrough":
|
|
174
|
+
const mainPath = getMainEntry();
|
|
175
|
+
const child = spawn(process.execPath, [mainPath, ...args], { stdio: "inherit" });
|
|
176
|
+
child.on("error", (err) => {
|
|
177
|
+
log("执行失败: " + err.message, MAGENTA);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
});
|
|
180
|
+
child.on("exit", (code) => process.exit(code || 0));
|
|
181
|
+
break;
|
|
182
|
+
default:
|
|
183
|
+
log("未知模式: " + mode, MAGENTA);
|
|
184
|
+
printBanner();
|
|
185
|
+
console.log("输入 --help 查看帮助");
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
main().catch((err) => {
|
|
191
|
+
console.error("Fatal error:", err);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
});
|
|
194
|
+
`;
|
|
195
|
+
|
|
196
|
+
fs.writeFileSync(path.join(binDir, 'bolloon.cjs'), unixContent);
|
|
197
|
+
|
|
198
|
+
// 确保 bin/bolloon.js 存在(npm link 需要)
|
|
199
|
+
const jsSymlink = path.join(binDir, 'bolloon.js');
|
|
200
|
+
if (fs.existsSync(jsSymlink)) fs.unlinkSync(jsSymlink);
|
|
201
|
+
fs.symlinkSync('bolloon.cjs', jsSymlink);
|
|
202
|
+
|
|
203
|
+
console.log("✓ CLI 构建完成");
|
|
204
|
+
console.log(" bin/bolloon.cjs - CommonJS 入口");
|
|
205
|
+
console.log(" bin/bolloon.js - 符号链接 -> bolloon.cjs");
|
|
206
|
+
console.log(" bin/bolloon.cmd - Windows 入口");
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postinstall 脚本
|
|
3
|
+
* npm 安装后自动执行
|
|
4
|
+
*
|
|
5
|
+
* 主要任务:
|
|
6
|
+
* 1. 确保 bin 目录存在且可执行
|
|
7
|
+
* 2. 初始化本地配置
|
|
8
|
+
* 3. 检查依赖完整性
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import { fileURLToPath } from 'url';
|
|
14
|
+
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = path.dirname(__filename);
|
|
17
|
+
const rootDir = path.join(__dirname, '..');
|
|
18
|
+
|
|
19
|
+
const RESET = '\x1b[0m';
|
|
20
|
+
const GREEN = '\x1b[32m';
|
|
21
|
+
const YELLOW = '\x1b[33m';
|
|
22
|
+
const CYAN = '\x1b[36m';
|
|
23
|
+
|
|
24
|
+
function log(msg, color = RESET) {
|
|
25
|
+
console.log(color + msg + RESET);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function initUserDirs() {
|
|
29
|
+
// 创建用户数据目录
|
|
30
|
+
const home = process.env.HOME || process.env.USERPROFILE || '/tmp';
|
|
31
|
+
const bolloonDir = path.join(home, '.bolloon');
|
|
32
|
+
|
|
33
|
+
const dirs = [
|
|
34
|
+
bolloonDir,
|
|
35
|
+
path.join(bolloonDir, 'sessions'),
|
|
36
|
+
path.join(bolloonDir, 'peer-store'),
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
for (const dir of dirs) {
|
|
40
|
+
if (!fs.existsSync(dir)) {
|
|
41
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
42
|
+
log(` ✓ 创建目录: ${dir}`, GREEN);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 初始化配置文件
|
|
47
|
+
const configPath = path.join(bolloonDir, 'config.json');
|
|
48
|
+
if (!fs.existsSync(configPath)) {
|
|
49
|
+
const defaultConfig = {
|
|
50
|
+
version: '0.1.1',
|
|
51
|
+
initializedAt: new Date().toISOString(),
|
|
52
|
+
defaults: {
|
|
53
|
+
port: 54188,
|
|
54
|
+
theme: 'dark',
|
|
55
|
+
autoConnect: true,
|
|
56
|
+
},
|
|
57
|
+
providers: {
|
|
58
|
+
minimax: { enabled: false },
|
|
59
|
+
openai: { enabled: false },
|
|
60
|
+
anthropic: { enabled: false },
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
64
|
+
log(` ✓ 创建配置: ${configPath}`, GREEN);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return bolloonDir;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function checkNativeDeps() {
|
|
71
|
+
// 检查必要的原生依赖
|
|
72
|
+
const nativeDeps = [
|
|
73
|
+
'libp2p',
|
|
74
|
+
'@diap/sdk',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
let allOk = true;
|
|
78
|
+
|
|
79
|
+
for (const dep of nativeDeps) {
|
|
80
|
+
const depPath = path.join(rootDir, 'node_modules', dep);
|
|
81
|
+
if (!fs.existsSync(depPath)) {
|
|
82
|
+
log(` ⚠ 缺少依赖: ${dep}`, YELLOW);
|
|
83
|
+
allOk = false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return allOk;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function setupPlatform() {
|
|
91
|
+
const platform = process.platform;
|
|
92
|
+
|
|
93
|
+
log(`\n 平台: ${platform}`, CYAN);
|
|
94
|
+
|
|
95
|
+
if (platform === 'win32') {
|
|
96
|
+
// Windows: 确保 .cmd 文件存在
|
|
97
|
+
const binDir = path.join(rootDir, 'bin');
|
|
98
|
+
const cmdPath = path.join(binDir, 'bolloon.cmd');
|
|
99
|
+
|
|
100
|
+
if (fs.existsSync(binDir) && !fs.existsSync(cmdPath)) {
|
|
101
|
+
const cmdContent = `@echo off
|
|
102
|
+
node "%~dp0..\\dist\\cli.js" %*
|
|
103
|
+
`;
|
|
104
|
+
fs.writeFileSync(cmdPath, cmdContent);
|
|
105
|
+
log(' ✓ Windows 入口已创建', GREEN);
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
// Unix/Linux/Mac: 确保 bin 文件可执行
|
|
109
|
+
const binDir = path.join(rootDir, 'bin');
|
|
110
|
+
const binPath = path.join(binDir, 'bolloon.js');
|
|
111
|
+
|
|
112
|
+
if (fs.existsSync(binPath)) {
|
|
113
|
+
try {
|
|
114
|
+
fs.chmodSync(binPath, 0o755);
|
|
115
|
+
log(' ✓ bin/bolloon.js 已设为可执行', GREEN);
|
|
116
|
+
} catch (err) {
|
|
117
|
+
log(` ⚠ 无法设置执行权限: ${err.message}`, YELLOW);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function main() {
|
|
124
|
+
console.log('\n📦 Bolloon 安装后处理...\n');
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
// 1. 初始化用户目录
|
|
128
|
+
const bolloonDir = initUserDirs();
|
|
129
|
+
log(` ✓ 用户数据目录: ${bolloonDir}`, GREEN);
|
|
130
|
+
|
|
131
|
+
// 2. 检查依赖
|
|
132
|
+
const depsOk = checkNativeDeps();
|
|
133
|
+
if (!depsOk) {
|
|
134
|
+
log('\n ⚠ 部分依赖缺失,建议运行: npm install', YELLOW);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 3. 平台特定设置
|
|
138
|
+
setupPlatform();
|
|
139
|
+
|
|
140
|
+
console.log('\n✅ 安装完成!\n');
|
|
141
|
+
console.log(' 使用方式:');
|
|
142
|
+
console.log(' bolloon # 启动 GUI');
|
|
143
|
+
console.log(' bolloon --web # 启动 Web UI');
|
|
144
|
+
console.log(' bolloon --cli # 命令行模式');
|
|
145
|
+
console.log(' bolloon --help # 显示帮助\n');
|
|
146
|
+
console.log(` 配置文件: ${path.join(bolloonDir, 'config.json')}\n`);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
console.error('\n❌ 安装后处理失败:', err.message);
|
|
149
|
+
console.error(' 这通常不影响基本功能,继续安装...\n');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
main();
|