@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.
Files changed (200) hide show
  1. package/bin/bolloon-cli.cjs +165 -0
  2. package/bin/bolloon-daemon.sh +207 -0
  3. package/bin/bolloon.cmd +11 -0
  4. package/dist/agents/constraint-layer.js +10 -15
  5. package/dist/agents/pi-sdk.js +433 -106
  6. package/dist/agents/protocol.js +82 -1
  7. package/dist/agents/subagent-manager.js +2 -2
  8. package/dist/agents/workflow-engine.js +15 -20
  9. package/dist/agents/workflow-pivot-loop.js +541 -0
  10. package/dist/bollharness/src/index.js +5 -0
  11. package/dist/bollharness/src/scripts/checks/check_adr_plan_numbering.js +6 -0
  12. package/dist/bollharness/src/scripts/checks/check_api_types.js +45 -0
  13. package/dist/bollharness/src/scripts/checks/check_artifact_link.js +146 -0
  14. package/dist/bollharness/src/scripts/checks/check_bridge_deps.js +6 -0
  15. package/dist/bollharness/src/scripts/checks/check_bugfix_binding.js +6 -0
  16. package/dist/bollharness/src/scripts/checks/check_bugfix_binding_ci.js +6 -0
  17. package/dist/bollharness/src/scripts/checks/check_doc_file_references.js +6 -0
  18. package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +135 -0
  19. package/dist/bollharness/src/scripts/checks/check_doc_links.js +31 -0
  20. package/dist/bollharness/src/scripts/checks/check_file_existence_claims.js +6 -0
  21. package/dist/bollharness/src/scripts/checks/check_fragment_integrity.js +34 -0
  22. package/dist/bollharness/src/scripts/checks/check_hook_installed.js +63 -0
  23. package/dist/bollharness/src/scripts/checks/check_issue_closure.js +41 -0
  24. package/dist/bollharness/src/scripts/checks/check_mcp_parity.js +6 -0
  25. package/dist/bollharness/src/scripts/checks/check_security.js +48 -0
  26. package/dist/bollharness/src/scripts/checks/check_skill_parity.js +6 -0
  27. package/dist/bollharness/src/scripts/checks/check_versions.js +6 -0
  28. package/dist/bollharness/src/scripts/checks/finding.js +13 -0
  29. package/dist/bollharness/src/scripts/checks/next_decision_number.js +20 -0
  30. package/dist/bollharness/src/scripts/checks/regenerate_magic_docs.js +6 -0
  31. package/dist/bollharness/src/scripts/ci/detect_rebaseline_triggers.js +8 -0
  32. package/dist/bollharness/src/scripts/ci/scan_subprocess_cfg.js +8 -0
  33. package/dist/bollharness/src/scripts/ci/scan_verify_artifacts.js +8 -0
  34. package/dist/bollharness/src/scripts/ci/scan_yaml_schema.js +8 -0
  35. package/dist/bollharness/src/scripts/context_router.js +67 -0
  36. package/dist/bollharness/src/scripts/deploy-guard.js +157 -0
  37. package/dist/bollharness/src/scripts/guard-feedback.js +192 -0
  38. package/dist/bollharness/src/scripts/guard_router.js +158 -0
  39. package/dist/bollharness/src/scripts/hooks/_hook_output.js +6 -0
  40. package/dist/bollharness/src/scripts/hooks/auto-python3.js +6 -0
  41. package/dist/bollharness/src/scripts/hooks/deploy-progress-on-session-end.js +6 -0
  42. package/dist/bollharness/src/scripts/hooks/failure-analyzer.js +6 -0
  43. package/dist/bollharness/src/scripts/hooks/gate-judgment-inject.js +92 -0
  44. package/dist/bollharness/src/scripts/hooks/gate-transition-judgment.js +63 -0
  45. package/dist/bollharness/src/scripts/hooks/inbox-ack.js +6 -0
  46. package/dist/bollharness/src/scripts/hooks/inbox-inject-on-start.js +6 -0
  47. package/dist/bollharness/src/scripts/hooks/inbox-validate.js +6 -0
  48. package/dist/bollharness/src/scripts/hooks/inbox-write-ledger.js +6 -0
  49. package/dist/bollharness/src/scripts/hooks/initializer-agent.js +6 -0
  50. package/dist/bollharness/src/scripts/hooks/loop-detection.js +73 -0
  51. package/dist/bollharness/src/scripts/hooks/owner-guard.js +6 -0
  52. package/dist/bollharness/src/scripts/hooks/precompact.js +6 -0
  53. package/dist/bollharness/src/scripts/hooks/review-agent-gatekeeper.js +6 -0
  54. package/dist/bollharness/src/scripts/hooks/risk-tracker.js +108 -0
  55. package/dist/bollharness/src/scripts/hooks/sanitize-on-read.js +6 -0
  56. package/dist/bollharness/src/scripts/hooks/session-reflection.js +7 -0
  57. package/dist/bollharness/src/scripts/hooks/session-start-magic-docs.js +7 -0
  58. package/dist/bollharness/src/scripts/hooks/session-start-reset-risk.js +7 -0
  59. package/dist/bollharness/src/scripts/hooks/session-start-toolkit-reminder.js +7 -0
  60. package/dist/bollharness/src/scripts/hooks/stop-evaluator.js +157 -0
  61. package/dist/bollharness/src/scripts/hooks/tool-call-counter.js +6 -0
  62. package/dist/bollharness/src/scripts/hooks/trace-analyzer.js +10 -0
  63. package/dist/bollharness/src/scripts/install/install-trust-token.js +7 -0
  64. package/dist/bollharness/src/scripts/install/multi_project_registry.js +9 -0
  65. package/dist/bollharness/src/scripts/install/phase2_auto.js +21 -0
  66. package/dist/bollharness/src/scripts/install/pre_commit_installer.js +6 -0
  67. package/dist/bollharness/src/scripts/install/tier_selector.js +7 -0
  68. package/dist/bollharness/src/scripts/install/transcript_miner.js +7 -0
  69. package/dist/bollharness/src/scripts/lib/claim_patterns.js +10 -0
  70. package/dist/bollharness/src/scripts/lib/sanitize_patterns.js +12 -0
  71. package/dist/bollharness/src/scripts/sanitize.js +6 -0
  72. package/dist/bollharness-integration/channel-judgment-engine.js +530 -0
  73. package/dist/bollharness-integration/context-chain-router.js +383 -0
  74. package/dist/bollharness-integration/context-router-judgment.js +13 -21
  75. package/dist/bollharness-integration/context-router.js +22 -64
  76. package/dist/bollharness-integration/gate-state-machine.js +14 -19
  77. package/dist/bollharness-integration/gate-transition-hooks.js +16 -61
  78. package/dist/bollharness-integration/guard-checker.js +21 -68
  79. package/dist/bollharness-integration/index.js +14 -124
  80. package/dist/bollharness-integration/integration.js +13 -20
  81. package/dist/bollharness-integration/llm-judgment-engine.js +569 -0
  82. package/dist/bollharness-integration/skill-adapter.js +18 -64
  83. package/dist/cli-entry.js +261 -0
  84. package/dist/constraint-runtime/src/commands.js +17 -7
  85. package/dist/constraint-runtime/src/constraint/budget.js +1 -6
  86. package/dist/constraint-runtime/src/constraint/permission.js +1 -6
  87. package/dist/constraint-runtime/src/models.js +1 -3
  88. package/dist/constraint-runtime/src/tools.js +17 -7
  89. package/dist/constraints/index.js +1 -7
  90. package/dist/documents/reader.js +8 -49
  91. package/dist/heartbeat/DaemonManager.js +242 -0
  92. package/dist/heartbeat/HealthMonitor.js +285 -0
  93. package/dist/heartbeat/StartupVerifier.js +205 -0
  94. package/dist/heartbeat/Watchdog.js +168 -0
  95. package/dist/heartbeat/index.js +84 -0
  96. package/dist/heartbeat/types.js +5 -0
  97. package/dist/index.js +381 -28
  98. package/dist/llm/config-store.js +31 -57
  99. package/dist/llm/llm-judgment-client.js +389 -0
  100. package/dist/llm/pi-ai.js +9 -52
  101. package/dist/network/agent-network.js +46 -90
  102. package/dist/network/hybrid-messenger.js +125 -0
  103. package/dist/network/iroh-bootstrap.js +38 -0
  104. package/dist/network/iroh-discovery.js +145 -0
  105. package/dist/network/iroh-integration.js +9 -16
  106. package/dist/network/iroh-transport.js +10 -48
  107. package/dist/network/p2p.js +23 -62
  108. package/dist/network/storage/adapters/json-adapter.js +4 -42
  109. package/dist/network/storage/index.js +147 -0
  110. package/dist/network/storage/types.js +14 -0
  111. package/dist/pi-ecosystem/index.js +233 -0
  112. package/dist/pi-ecosystem-colony/index.js +29 -90
  113. package/dist/pi-ecosystem-goals/index.js +20 -74
  114. package/dist/pi-ecosystem-judgment/decision.js +29 -47
  115. package/dist/pi-ecosystem-judgment/distillation.js +16 -29
  116. package/dist/pi-ecosystem-judgment/human-value-store.js +13 -60
  117. package/dist/pi-ecosystem-judgment/index.js +21 -74
  118. package/dist/pi-ecosystem-judgment/value-injection.js +26 -72
  119. package/dist/pi-ecosystem-mcp/index.js +24 -78
  120. package/dist/pi-ecosystem-subagents/index.js +20 -69
  121. package/dist/social/ant-colony/AdaptiveHeartbeat.js +3 -8
  122. package/dist/social/ant-colony/PheromoneEngine.js +11 -49
  123. package/dist/social/ant-colony/index.js +6 -0
  124. package/dist/social/ant-colony/types.js +4 -8
  125. package/dist/social/channels/ChannelManager.js +8 -46
  126. package/dist/social/channels/DiapChannelBridge.js +9 -47
  127. package/dist/social/channels/InterestMatcher.js +2 -7
  128. package/dist/social/channels/channel-agent-session.js +309 -0
  129. package/dist/social/channels/channel-heartbeat-agent.js +494 -0
  130. package/dist/social/channels/diap-doc-parser.js +204 -0
  131. package/dist/social/channels/harness-workflow-integrator.js +446 -0
  132. package/dist/social/channels/index.js +9 -0
  133. package/dist/social/channels/types.js +3 -7
  134. package/dist/social/global-shared-context.js +6 -47
  135. package/dist/social/heartbeat.js +29 -72
  136. package/dist/social/persona/enhanced-persona.js +299 -0
  137. package/dist/web/client.js +302 -136
  138. package/dist/web/components/p2p/index.js +159 -9
  139. package/dist/web/components/p2p/p2p-connection.js +136 -0
  140. package/dist/web/components/p2p/p2p-manager.js +24 -0
  141. package/dist/web/components/p2p/p2p-store-memory.js +1 -1
  142. package/dist/web/components/p2p/types.js +7 -0
  143. package/dist/web/index.html +5 -0
  144. package/dist/web/style.css +118 -0
  145. package/package.json +12 -6
  146. package/scripts/build-cli.js +206 -0
  147. package/scripts/postinstall.js +153 -0
  148. package/src/agents/pi-sdk.ts +347 -28
  149. package/src/agents/protocol.ts +95 -1
  150. package/src/agents/workflow-pivot-loop.ts +674 -0
  151. package/src/bollharness/CLAUDE.md +73 -0
  152. package/src/bollharness/README.md +143 -0
  153. package/src/bollharness/README.zh-CN.md +131 -0
  154. package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +57 -0
  155. package/src/bollharness/scripts/context-fragments/artifact-linkage.md +14 -0
  156. package/src/bollharness/scripts/context-fragments/auth-consumers.md +17 -0
  157. package/src/bollharness/scripts/context-fragments/bridge-constitution.md +13 -0
  158. package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +18 -0
  159. package/src/bollharness/scripts/context-fragments/closure-checklist.md +13 -0
  160. package/src/bollharness/scripts/context-fragments/contract-consumers.md +15 -0
  161. package/src/bollharness/scripts/context-fragments/db-shared-structures.md +15 -0
  162. package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +19 -0
  163. package/src/bollharness/scripts/context-fragments/general-dev-principles.md +11 -0
  164. package/src/bollharness/scripts/context-fragments/issue-first.md +8 -0
  165. package/src/bollharness/scripts/context-fragments/mcp-parity.md +16 -0
  166. package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +108 -0
  167. package/src/bollharness/scripts/context-fragments/protocol-consumers.md +15 -0
  168. package/src/bollharness/scripts/context-fragments/run-events-consumers.md +15 -0
  169. package/src/bollharness/scripts/context-fragments/scene-fidelity.md +13 -0
  170. package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +15 -0
  171. package/src/bollharness/scripts/context-fragments/two-language.md +15 -0
  172. package/src/bollharness/scripts/context-fragments/version-sources.md +14 -0
  173. package/src/bollharness/scripts/hooks/stop-evaluator.md +83 -0
  174. package/src/bollharness/templates/scaffold/CLAUDE.md +89 -0
  175. package/src/cli-entry.ts +304 -0
  176. package/src/heartbeat/DaemonManager.ts +283 -0
  177. package/src/heartbeat/HealthMonitor.ts +316 -0
  178. package/src/heartbeat/StartupVerifier.ts +223 -0
  179. package/src/heartbeat/Watchdog.ts +198 -0
  180. package/src/heartbeat/index.ts +108 -0
  181. package/src/heartbeat/types.ts +82 -0
  182. package/src/llm/config-store.ts +23 -5
  183. package/src/network/iroh-transport.ts +3 -3
  184. package/src/web/client.js +302 -136
  185. package/src/web/components/p2p/P2PModal.tsx +91 -3
  186. package/src/web/components/p2p/index.ts +171 -9
  187. package/src/web/components/p2p/p2p-connection.ts +153 -1
  188. package/src/web/components/p2p/p2p-manager.ts +39 -1
  189. package/src/web/components/p2p/p2p-store-memory.ts +1 -1
  190. package/src/web/components/p2p/p2p-tools.ts +315 -0
  191. package/src/web/components/p2p/types.ts +58 -0
  192. package/src/web/design.md +99 -0
  193. package/src/web/index.html +5 -0
  194. package/src/web/server.ts +353 -36
  195. package/src/web/style.css +118 -0
  196. package/tsconfig.cli.json +16 -0
  197. package/tsconfig.electron.json +1 -1
  198. package/tsconfig.json +1 -2
  199. package/dist/web/server.js +0 -1647
  200. package/dist/web/server.js.map +0 -1
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env node
2
+ const path = require("path");
3
+ const { spawn } = require("child_process");
4
+ const fs = require("fs");
5
+
6
+ const RESET = "\x1b[0m";
7
+ const BOLD = "\x1b[1m";
8
+ const CYAN = "\x1b[36m";
9
+ const GREEN = "\x1b[32m";
10
+ const MAGENTA = "\x1b[35m";
11
+
12
+ function log(msg, color) {
13
+ console.log((color || RESET) + msg + RESET);
14
+ }
15
+
16
+ function printBanner() {
17
+ console.log("\n" + CYAN + BOLD + [
18
+ " ╔═══════════════════════════════════════════╗",
19
+ " ║ 🤖 Bolloon Agent ║",
20
+ " ║ P2P AI Document Processor ║",
21
+ " ╚═══════════════════════════════════════════╝"
22
+ ].join("\n") + RESET + "\n");
23
+ }
24
+
25
+ function getMainEntry() {
26
+ // bin is in: node_modules/.bin/bolloon
27
+ // package is in: node_modules/@bolloon/bolloon-agent/
28
+ // dist is in: node_modules/@bolloon/bolloon-agent/dist/
29
+ const binPath = require.main.filename; // /tmp/node_modules/.bin/bolloon
30
+ const binDir = path.dirname(binPath); // /tmp/node_modules/.bin
31
+ const packageDir = path.dirname(binDir); // /tmp/node_modules/@bolloon/bolloon-agent
32
+ const distIndex = path.join(packageDir, "dist", "index.js");
33
+ if (fs.existsSync(distIndex)) {
34
+ return distIndex;
35
+ }
36
+ // fallback to src (for development)
37
+ return path.join(packageDir, "src", "index.ts");
38
+ }
39
+
40
+ function parseArgs() {
41
+ const args = process.argv.slice(2);
42
+ if (args.length === 0) {
43
+ return { mode: "gui", args: [] };
44
+ }
45
+ const first = args[0];
46
+ switch (first) {
47
+ case "-v":
48
+ case "--version":
49
+ return { mode: "version", args: [] };
50
+ case "-h":
51
+ case "--help":
52
+ return { mode: "help", args: [] };
53
+ case "-g":
54
+ case "--gui":
55
+ return { mode: "gui", args: args.slice(1) };
56
+ case "-w":
57
+ case "--web":
58
+ return { mode: "web", args: args.slice(1) };
59
+ case "-c":
60
+ case "--cli":
61
+ return { mode: "cli", args: args.slice(1) };
62
+ default:
63
+ return { mode: "passthrough", args };
64
+ }
65
+ }
66
+
67
+ async function startElectron(additionalArgs) {
68
+ try {
69
+ const electron = require("electron");
70
+ const binPath = require.main.filename;
71
+ const binDir = path.dirname(binPath);
72
+ const packageDir = path.dirname(binDir);
73
+ let mainPath = path.join(packageDir, "dist", "electron.js");
74
+ if (!fs.existsSync(mainPath)) {
75
+ mainPath = path.join(packageDir, "src", "electron.ts");
76
+ }
77
+ log("启动 Electron...", CYAN);
78
+ const child = spawn(electron, [mainPath, ...additionalArgs], {
79
+ stdio: "inherit",
80
+ env: { ...process.env, NODE_ENV: "development" }
81
+ });
82
+ child.on("error", (err) => {
83
+ log("Electron 启动失败: " + err.message, MAGENTA);
84
+ process.exit(1);
85
+ });
86
+ child.on("exit", (code) => process.exit(code || 0));
87
+ } catch (err) {
88
+ log("Electron 不可用,切换到 Web 模式...", CYAN);
89
+ await startWebServer(additionalArgs);
90
+ }
91
+ }
92
+
93
+ async function startWebServer(additionalArgs) {
94
+ const mainPath = getMainEntry();
95
+ const webArgs = ["--web", ...additionalArgs];
96
+ log("启动 Web 服务...", CYAN);
97
+ const child = spawn(process.execPath, [mainPath, ...webArgs], { stdio: "inherit" });
98
+ child.on("error", (err) => {
99
+ log("Web 服务启动失败: " + err.message, MAGENTA);
100
+ process.exit(1);
101
+ });
102
+ child.on("exit", (code) => process.exit(code || 0));
103
+ }
104
+
105
+ async function startCLI(additionalArgs) {
106
+ const mainPath = getMainEntry();
107
+ log("启动命令行界面...", CYAN);
108
+ const child = spawn(process.execPath, [mainPath, ...additionalArgs], { stdio: "inherit" });
109
+ child.on("error", (err) => {
110
+ log("CLI 启动失败: " + err.message, MAGENTA);
111
+ process.exit(1);
112
+ });
113
+ child.on("exit", (code) => process.exit(code || 0));
114
+ }
115
+
116
+ async function main() {
117
+ const { mode, args } = parseArgs();
118
+ switch (mode) {
119
+ case "version":
120
+ console.log("Bolloon Agent v0.1.2");
121
+ break;
122
+ case "help":
123
+ printBanner();
124
+ console.log(BOLD + "用法:" + RESET + " bolloon [选项] [命令] [参数]");
125
+ console.log(BOLD + "选项:" + RESET + " --gui, -g 启动图形界面");
126
+ console.log(" --web, -w 启动 Web UI");
127
+ console.log(" --cli, -c 启动命令行界面");
128
+ console.log(" --version, -v 显示版本");
129
+ console.log(" --help, -h 显示帮助");
130
+ console.log(BOLD + "示例:" + RESET + " bolloon # 启动图形界面");
131
+ console.log(" bolloon --web # 启动 Web UI");
132
+ console.log(" bolloon --read file # 读取文档");
133
+ break;
134
+ case "gui":
135
+ printBanner();
136
+ await startElectron(args);
137
+ break;
138
+ case "web":
139
+ printBanner();
140
+ await startWebServer(args);
141
+ break;
142
+ case "cli":
143
+ await startCLI(args);
144
+ break;
145
+ case "passthrough":
146
+ const mainPath = getMainEntry();
147
+ const child = spawn(process.execPath, [mainPath, ...args], { stdio: "inherit" });
148
+ child.on("error", (err) => {
149
+ log("执行失败: " + err.message, MAGENTA);
150
+ process.exit(1);
151
+ });
152
+ child.on("exit", (code) => process.exit(code || 0));
153
+ break;
154
+ default:
155
+ log("未知模式: " + mode, MAGENTA);
156
+ printBanner();
157
+ console.log("输入 --help 查看帮助");
158
+ process.exit(1);
159
+ }
160
+ }
161
+
162
+ main().catch((err) => {
163
+ console.error("Fatal error:", err);
164
+ process.exit(1);
165
+ });
@@ -0,0 +1,207 @@
1
+ #!/bin/bash
2
+ # Bolloon Daemon - 守护进程启动脚本
3
+ # 支持自动重启、日志轮转、PID 管理
4
+
5
+ set -e
6
+
7
+ APP_NAME="bolloon"
8
+ APP_DIR="$(cd "$(dirname "$0")/.." && pwd)"
9
+ PID_FILE="$HOME/.bolloon/daemon.pid"
10
+ LOG_FILE="$HOME/.bolloon/daemon.log"
11
+ MAX_RESTARTS=5
12
+ RESTART_DELAY=5
13
+
14
+ # 颜色输出
15
+ RED='\033[0;31m'
16
+ GREEN='\033[0;32m'
17
+ YELLOW='\033[1;33m'
18
+ NC='\033[0m' # No Color
19
+
20
+ log() {
21
+ echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1"
22
+ }
23
+
24
+ warn() {
25
+ echo -e "${YELLOW}[$(date '+%Y-%m-%d %H:%M:%S')] WARN:${NC} $1"
26
+ }
27
+
28
+ error() {
29
+ echo -e "${RED}[$(date '+%Y-%m-%d %H:%M:%S')] ERROR:${NC} $1"
30
+ }
31
+
32
+ # 获取 PID
33
+ get_pid() {
34
+ if [ -f "$PID_FILE" ]; then
35
+ cat "$PID_FILE"
36
+ fi
37
+ }
38
+
39
+ # 检查进程是否运行
40
+ is_running() {
41
+ local pid=$(get_pid)
42
+ if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
43
+ return 0
44
+ fi
45
+ return 1
46
+ }
47
+
48
+ # 启动守护进程
49
+ start() {
50
+ if is_running; then
51
+ log "Bolloon 已在运行 (PID: $(get_pid))"
52
+ return 0
53
+ fi
54
+
55
+ log "启动 Bolloon 守护进程..."
56
+
57
+ # 确保日志目录存在
58
+ mkdir -p "$(dirname "$LOG_FILE")"
59
+
60
+ # 启动进程
61
+ cd "$APP_DIR"
62
+ nohup npx tsx src/index.ts >> "$LOG_FILE" 2>&1 &
63
+ local pid=$!
64
+
65
+ # 保存 PID
66
+ echo "$pid" > "$PID_FILE"
67
+ log "Bolloon 已启动 (PID: $pid)"
68
+ log "日志文件: $LOG_FILE"
69
+ }
70
+
71
+ # 停止守护进程
72
+ stop() {
73
+ local pid=$(get_pid)
74
+
75
+ if [ -z "$pid" ]; then
76
+ warn "Bolloon 未运行"
77
+ return 0
78
+ fi
79
+
80
+ log "停止 Bolloon (PID: $pid)..."
81
+
82
+ # 发送 SIGTERM
83
+ kill -TERM "$pid" 2>/dev/null || true
84
+
85
+ # 等待进程退出
86
+ local count=0
87
+ while kill -0 "$pid" 2>/dev/null && [ $count -lt 10 ]; do
88
+ sleep 1
89
+ count=$((count + 1))
90
+ done
91
+
92
+ # 如果还在运行,强制终止
93
+ if kill -0 "$pid" 2>/dev/null; then
94
+ warn "进程未响应,发送 SIGKILL..."
95
+ kill -KILL "$pid" 2>/dev/null || true
96
+ fi
97
+
98
+ # 清理 PID 文件
99
+ rm -f "$PID_FILE"
100
+ log "Bolloon 已停止"
101
+ }
102
+
103
+ # 重启守护进程
104
+ restart() {
105
+ log "重启 Bolloon..."
106
+ stop
107
+ sleep 2
108
+ start
109
+ }
110
+
111
+ # 查看状态
112
+ status() {
113
+ if is_running; then
114
+ log "Bolloon 运行中 (PID: $(get_pid))"
115
+ # 显示资源使用
116
+ local pid=$(get_pid)
117
+ if [ -n "$pid" ]; then
118
+ ps -p "$pid" -o %cpu,%mem,etime 2>/dev/null | tail -1 || true
119
+ fi
120
+ else
121
+ warn "Bolloon 未运行"
122
+ fi
123
+ }
124
+
125
+ # 查看日志
126
+ logs() {
127
+ if [ -f "$LOG_FILE" ]; then
128
+ tail -100 "$LOG_FILE"
129
+ else
130
+ warn "日志文件不存在: $LOG_FILE"
131
+ fi
132
+ }
133
+
134
+ # 健康检查
135
+ health() {
136
+ local port=${PORT:-54188}
137
+ local response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$port/api/health" 2>/dev/null || echo "000")
138
+
139
+ if [ "$response" = "200" ]; then
140
+ log "健康检查通过"
141
+ curl -s "http://localhost:$port/api/health" 2>/dev/null | head -5
142
+ else
143
+ error "健康检查失败 (HTTP $response)"
144
+ return 1
145
+ fi
146
+ }
147
+
148
+ # 清理日志
149
+ clean_logs() {
150
+ if [ -f "$LOG_FILE" ]; then
151
+ local size=$(du -h "$LOG_FILE" | cut -f1)
152
+ log "当前日志大小: $size"
153
+ > "$LOG_FILE"
154
+ log "日志已清空"
155
+ fi
156
+ }
157
+
158
+ # 显示帮助
159
+ show_help() {
160
+ echo "Bolloon Daemon 守护进程管理脚本"
161
+ echo ""
162
+ echo "用法: $0 [命令]"
163
+ echo ""
164
+ echo "命令:"
165
+ echo " start 启动 Bolloon 守护进程"
166
+ echo " stop 停止 Bolloon 守护进程"
167
+ echo " restart 重启 Bolloon 守护进程"
168
+ echo " status 查看运行状态"
169
+ echo " logs 查看最近日志"
170
+ echo " health 健康检查"
171
+ echo " clean 清空日志"
172
+ echo " help 显示帮助"
173
+ echo ""
174
+ }
175
+
176
+ # 主逻辑
177
+ case "${1:-help}" in
178
+ start)
179
+ start
180
+ ;;
181
+ stop)
182
+ stop
183
+ ;;
184
+ restart)
185
+ restart
186
+ ;;
187
+ status)
188
+ status
189
+ ;;
190
+ logs)
191
+ logs
192
+ ;;
193
+ health)
194
+ health
195
+ ;;
196
+ clean)
197
+ clean_logs
198
+ ;;
199
+ help|--help|-h)
200
+ show_help
201
+ ;;
202
+ *)
203
+ error "未知命令: $1"
204
+ show_help
205
+ exit 1
206
+ ;;
207
+ esac
@@ -0,0 +1,11 @@
1
+ @echo off
2
+ set "BOLLOON_ROOT=%~dp0"
3
+ set "BOLLOON_ROOT=%BOLLOON_ROOT:~0,-1%"
4
+
5
+ REM 确定入口文件
6
+ set "ENTRY=%BOLLOON_ROOT%\dist\index.js"
7
+ if not exist "%ENTRY%" (
8
+ set "ENTRY=%BOLLOON_ROOT%\src\index.ts"
9
+ )
10
+
11
+ node "%ENTRY%" %*
@@ -1,17 +1,14 @@
1
- "use strict";
2
1
  /**
3
2
  * ConstraintLayer - Guardrails for safe autonomous document processing
4
3
  * Part of OpenClaw dual-layer architecture (Constraint Layer + Execution Layer)
5
4
  */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ConstraintLayer = exports.CONFIRM_REQUIRED_ACTIONS = exports.AUTONOMOUS_ACTIONS = exports.SYSTEM_PROMPT = void 0;
8
- const permission_js_1 = require("../constraint-runtime/src/constraint/permission.js");
9
- const budget_js_1 = require("../constraint-runtime/src/constraint/budget.js");
5
+ import { ToolPermissionContext } from '../constraint-runtime/src/constraint/permission.js';
6
+ import { BudgetTracker } from '../constraint-runtime/src/constraint/budget.js';
10
7
  /**
11
8
  * System prompt for constraint layer
12
9
  * Defines boundaries and autonomous permissions
13
10
  */
14
- exports.SYSTEM_PROMPT = `
11
+ export const SYSTEM_PROMPT = `
15
12
  你是一个文档处理Agent,在以下规则下运行:
16
13
 
17
14
  【边界规则】
@@ -34,23 +31,23 @@ if (操作 === '发送文档' && 对等节点不在已知列表) {
34
31
  /**
35
32
  * Actions that can be executed autonomously without confirmation
36
33
  */
37
- exports.AUTONOMOUS_ACTIONS = ['summarize', 'chunk', 'improve'];
34
+ export const AUTONOMOUS_ACTIONS = ['summarize', 'chunk', 'improve'];
38
35
  /**
39
36
  * Actions that require explicit confirmation before execution
40
37
  */
41
- exports.CONFIRM_REQUIRED_ACTIONS = ['send', 'delete'];
38
+ export const CONFIRM_REQUIRED_ACTIONS = ['send', 'delete'];
42
39
  /**
43
40
  * ConstraintLayer provides guardrails for safe document processing
44
41
  * Implements the constraint layer of the OpenClaw dual-layer architecture
45
42
  */
46
- class ConstraintLayer {
43
+ export class ConstraintLayer {
47
44
  rules = new Map();
48
45
  logs = [];
49
46
  permission;
50
47
  budget;
51
48
  constructor(denyTools = [], denyPrefixes = [], maxBudgetTokens = 2000, maxTurns = 8) {
52
- this.permission = permission_js_1.ToolPermissionContext.fromIterables(denyTools, denyPrefixes);
53
- this.budget = new budget_js_1.BudgetTracker(maxBudgetTokens, maxTurns);
49
+ this.permission = ToolPermissionContext.fromIterables(denyTools, denyPrefixes);
50
+ this.budget = new BudgetTracker(maxBudgetTokens, maxTurns);
54
51
  this.registerDefaultRules();
55
52
  }
56
53
  /**
@@ -192,13 +189,13 @@ class ConstraintLayer {
192
189
  * Check if an action is autonomous (no confirmation required)
193
190
  */
194
191
  isAutonomousAction(action) {
195
- return exports.AUTONOMOUS_ACTIONS.includes(action);
192
+ return AUTONOMOUS_ACTIONS.includes(action);
196
193
  }
197
194
  /**
198
195
  * Check if an action requires confirmation
199
196
  */
200
197
  requiresConfirmation(action) {
201
- return exports.CONFIRM_REQUIRED_ACTIONS.includes(action);
198
+ return CONFIRM_REQUIRED_ACTIONS.includes(action);
202
199
  }
203
200
  /**
204
201
  * Get all registered rule IDs
@@ -207,5 +204,3 @@ class ConstraintLayer {
207
204
  return Array.from(this.rules.keys());
208
205
  }
209
206
  }
210
- exports.ConstraintLayer = ConstraintLayer;
211
- //# sourceMappingURL=constraint-layer.js.map