@bolloon/bolloon-agent 0.1.13 → 0.1.14

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 (52) hide show
  1. package/dist/agents/pi-sdk.js +185 -0
  2. package/dist/agents/shell-guard.js +354 -0
  3. package/dist/agents/shell-tool.js +83 -0
  4. package/dist/agents/skill-loader.js +174 -0
  5. package/dist/bollharness-integration/context-chain-router.js +3 -3
  6. package/dist/bollharness-integration/context-router.js +1 -1
  7. package/dist/heartbeat/Watchdog.js +7 -5
  8. package/dist/heartbeat/index.js +1 -0
  9. package/dist/heartbeat/self-improve-bus.js +85 -0
  10. package/dist/pi-ecosystem-judgment/index.js +1 -2
  11. package/dist/utils/auto-update.js +44 -12
  12. package/dist/web/client.js +839 -103
  13. package/dist/web/components/p2p/P2PModal.js +188 -0
  14. package/dist/web/components/p2p/index.js +264 -226
  15. package/dist/web/components/p2p/p2p-modal.js +657 -0
  16. package/dist/web/components/p2p/p2p-tools.js +248 -0
  17. package/dist/web/index.html +88 -8
  18. package/dist/web/server.js +2360 -0
  19. package/dist/web/style.css +506 -9
  20. package/package.json +2 -2
  21. package/scripts/build-cli.js +11 -1
  22. package/src/agents/pi-sdk.ts +196 -0
  23. package/src/agents/shell-guard.ts +417 -0
  24. package/src/agents/shell-tool.ts +103 -0
  25. package/src/agents/skill-loader.ts +202 -0
  26. package/src/bollharness-integration/context-chain-router.ts +3 -3
  27. package/src/bollharness-integration/context-router.ts +1 -1
  28. package/src/heartbeat/Watchdog.ts +7 -5
  29. package/src/heartbeat/index.ts +1 -0
  30. package/src/heartbeat/self-improve-bus.ts +110 -0
  31. package/src/types.d.ts +12 -0
  32. package/src/utils/auto-update.ts +45 -14
  33. package/src/web/client.js +839 -103
  34. package/src/web/index.html +88 -8
  35. package/src/web/server.ts +427 -101
  36. package/src/web/style.css +506 -9
  37. package/dist/bollharness-integration/bollharness-integration/context-router-judgment.d.ts +0 -48
  38. package/dist/bollharness-integration/bollharness-integration/context-router-judgment.js +0 -261
  39. package/dist/bollharness-integration/bollharness-integration/context-router.d.ts +0 -110
  40. package/dist/bollharness-integration/bollharness-integration/context-router.js +0 -542
  41. package/dist/bollharness-integration/bollharness-integration/gate-state-machine.d.ts +0 -87
  42. package/dist/bollharness-integration/bollharness-integration/gate-state-machine.js +0 -231
  43. package/dist/bollharness-integration/bollharness-integration/gate-transition-hooks.d.ts +0 -30
  44. package/dist/bollharness-integration/bollharness-integration/gate-transition-hooks.js +0 -91
  45. package/dist/bollharness-integration/bollharness-integration/guard-checker.d.ts +0 -105
  46. package/dist/bollharness-integration/bollharness-integration/guard-checker.js +0 -353
  47. package/dist/bollharness-integration/bollharness-integration/index.d.ts +0 -66
  48. package/dist/bollharness-integration/bollharness-integration/index.js +0 -32
  49. package/dist/bollharness-integration/bollharness-integration/integration.d.ts +0 -219
  50. package/dist/bollharness-integration/bollharness-integration/integration.js +0 -420
  51. package/dist/bollharness-integration/bollharness-integration/skill-adapter.d.ts +0 -151
  52. package/dist/bollharness-integration/bollharness-integration/skill-adapter.js +0 -518
@@ -1,231 +0,0 @@
1
- /**
2
- * Gate State Machine - Implements Bollharness's 8-Gate workflow governance
3
- *
4
- * Port of bollharness's lead skill Gate system to Bolloon's multi-agent architecture.
5
- *
6
- * Gates:
7
- * G0 → G1 → G2* → G3 → G4* → G5 → G6* → G7 → G8*
8
- * 审查门 审查门 审查门 审查门
9
- * (* = 独立审查者,使用独立的agent上下文)
10
- */
11
- import { AgentCoordinator } from '@bolloon/constraint-runtime';
12
- import { executeGateTransitionHooks, initializeGateHooks } from './gate-transition-hooks.js';
13
- const GATE_CONFIGS = {
14
- 0: {
15
- entryCondition: '用户提出需求',
16
- requiredArtifact: '问题陈述 + Change Classification',
17
- requiredNextSkill: 'arch',
18
- isReviewGate: false,
19
- },
20
- 1: {
21
- entryCondition: 'Gate 0 产物存在',
22
- requiredArtifact: 'ADR 草稿 + 消费方清单',
23
- requiredNextSkill: 'arch',
24
- isReviewGate: false,
25
- },
26
- 2: {
27
- entryCondition: 'ADR 草稿完成',
28
- requiredArtifact: '审查报告 (verdict: PASS/BLOCK)',
29
- requiredNextSkill: 'review',
30
- requiredReviewSubstrate: 'ref-review-sop.md 阶段②维度',
31
- isReviewGate: true,
32
- },
33
- 3: {
34
- entryCondition: 'Gate 2 PASS',
35
- requiredArtifact: 'PLAN 文档 + 架构覆盖矩阵',
36
- requiredNextSkill: 'harness-eng',
37
- isReviewGate: false,
38
- },
39
- 4: {
40
- entryCondition: 'PLAN vN-final 冻结',
41
- requiredArtifact: '审查报告 + plan-lock 确认',
42
- requiredNextSkill: 'review',
43
- requiredReviewSubstrate: 'ref-review-sop.md 阶段④维度 + C/D/E/F',
44
- isReviewGate: true,
45
- },
46
- 5: {
47
- entryCondition: 'Gate 4 PASS + plan-lock',
48
- requiredArtifact: 'WP 拆分 + TASK.md',
49
- requiredNextSkill: 'task-arch',
50
- isReviewGate: false,
51
- },
52
- 6: {
53
- entryCondition: '全部 TASK.md 完成',
54
- requiredArtifact: '审查报告 (verdict: PASS/BLOCK)',
55
- requiredNextSkill: 'review',
56
- requiredReviewSubstrate: 'ref-review-sop.md WP 拆分专项',
57
- isReviewGate: true,
58
- },
59
- 7: {
60
- entryCondition: 'Gate 6 PASS',
61
- requiredArtifact: '代码 + LOG.md',
62
- requiredNextSkill: 'harness-eng',
63
- isReviewGate: false,
64
- },
65
- 8: {
66
- entryCondition: '全部 WP 代码 + LOG.md 存在',
67
- requiredArtifact: '审查报告 + 验收确认',
68
- requiredNextSkill: 'harness-eng-test',
69
- requiredReviewSubstrate: 'ref-review-sop.md 阶段⑤⑥维度',
70
- isReviewGate: true,
71
- },
72
- };
73
- export class GateStateMachine {
74
- state;
75
- coordinator;
76
- reviewAgentContext = new Map();
77
- constructor() {
78
- this.state = this.initState();
79
- this.coordinator = new AgentCoordinator(3);
80
- initializeGateHooks();
81
- }
82
- initState() {
83
- return {
84
- currentGate: 0,
85
- entrySatisfied: true,
86
- blockers: [],
87
- requiredArtifact: GATE_CONFIGS[0].requiredArtifact,
88
- requiredNextSkill: GATE_CONFIGS[0].requiredNextSkill,
89
- artifacts: new Map(),
90
- };
91
- }
92
- getState() {
93
- return { ...this.state, artifacts: new Map(this.state.artifacts) };
94
- }
95
- getCurrentGate() {
96
- return this.state.currentGate;
97
- }
98
- getGateConfig(gate) {
99
- return GATE_CONFIGS[gate];
100
- }
101
- /**
102
- * 检查是否可以进入下一个Gate
103
- */
104
- canTransition() {
105
- return this.state.entrySatisfied && this.state.blockers.length === 0;
106
- }
107
- /**
108
- * 提交产物到当前Gate
109
- */
110
- submitArtifact(name, artifact) {
111
- this.state.artifacts.set(name, artifact);
112
- this.checkEntryCondition();
113
- }
114
- /**
115
- * 获取Gate包 - 用于skill输出
116
- */
117
- getGatePack() {
118
- return {
119
- current_gate: this.state.currentGate,
120
- entry_satisfied: this.state.entrySatisfied,
121
- blockers: [...this.state.blockers],
122
- required_artifact: this.state.requiredArtifact,
123
- required_next_skill: this.state.requiredNextSkill,
124
- required_review_substrate: this.state.requiredReviewSubstrate,
125
- };
126
- }
127
- /**
128
- * 尝试转移到下一个Gate
129
- */
130
- async transition(reviewResult) {
131
- const currentGate = this.state.currentGate;
132
- const blockers = [];
133
- // 检查审查门是否需要独立审查
134
- if (GATE_CONFIGS[currentGate].isReviewGate) {
135
- if (!reviewResult) {
136
- return {
137
- from: currentGate,
138
- to: currentGate,
139
- blockers: ['审查门需要审查结果'],
140
- };
141
- }
142
- if (reviewResult.verdict === 'BLOCK') {
143
- blockers.push(reviewResult.details || '审查未通过');
144
- }
145
- }
146
- // 检查entry condition
147
- if (!this.state.entrySatisfied) {
148
- blockers.push('入口条件未满足');
149
- }
150
- if (blockers.length > 0) {
151
- return { from: currentGate, to: currentGate, blockers };
152
- }
153
- // 执行转移
154
- const nextGate = (currentGate + 1);
155
- this.state.currentGate = nextGate;
156
- this.updateStateForGate(nextGate);
157
- // Execute gate transition hooks
158
- await executeGateTransitionHooks(currentGate, nextGate, true, []);
159
- return {
160
- from: currentGate,
161
- to: nextGate,
162
- blockers: [],
163
- artifact: this.getGatePack(),
164
- };
165
- }
166
- /**
167
- * 回退到指定Gate
168
- */
169
- rollback(gate) {
170
- if (gate < this.state.currentGate) {
171
- this.state.currentGate = gate;
172
- this.updateStateForGate(gate);
173
- }
174
- }
175
- /**
176
- * 检查快速通道条件
177
- */
178
- checkFastTrack(changeClassification) {
179
- if (changeClassification !== 'implementation')
180
- return false;
181
- // 5条全部满足才允许快速通道
182
- // 1. 改动不超过3个文件
183
- // 2. 无契约变更
184
- // 3. 无跨模块接缝
185
- // 4. 不影响用户心智或产品语义
186
- // 5. 不引入新的架构决策
187
- return true; // 需要实际检查实现
188
- }
189
- checkEntryCondition() {
190
- const config = GATE_CONFIGS[this.state.currentGate];
191
- // 这里应该检查具体的entry condition
192
- // 简化实现
193
- this.state.entrySatisfied = true;
194
- }
195
- updateStateForGate(gate) {
196
- const config = GATE_CONFIGS[gate];
197
- this.state.entrySatisfied = true;
198
- this.state.blockers = [];
199
- this.state.requiredArtifact = config.requiredArtifact;
200
- this.state.requiredNextSkill = config.requiredNextSkill;
201
- this.state.requiredReviewSubstrate = config.requiredReviewSubstrate;
202
- }
203
- /**
204
- * 执行独立审查(用于审查门)
205
- * 使用独立的agent上下文
206
- */
207
- async executeIndependentReview(task, substrate) {
208
- // 使用AgentCoordinator执行独立审查任务
209
- const subtasks = [
210
- {
211
- id: `review-gate-${this.state.currentGate}`,
212
- description: task,
213
- priority: 1,
214
- },
215
- ];
216
- try {
217
- const results = await this.coordinator.dispatch(subtasks.map(t => t.description).join(' ||| '), 1);
218
- // 简化处理 - 实际应该解析审查结果
219
- return {
220
- verdict: 'PASS',
221
- details: '审查完成',
222
- };
223
- }
224
- catch {
225
- return {
226
- verdict: 'BLOCK',
227
- details: '审查执行失败',
228
- };
229
- }
230
- }
231
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * Gate Transition Hook Manager
3
- *
4
- * Handles PreGateTransition and PostGateTransition hooks.
5
- * Hooks are triggered when a gate transition occurs.
6
- */
7
- export interface GateHookConfig {
8
- gates?: number[];
9
- matcher?: string;
10
- type: 'command' | 'skill';
11
- command?: string;
12
- skill?: string;
13
- action?: string;
14
- timeout?: number;
15
- }
16
- export interface GateTransitionEvent {
17
- from: number;
18
- to: number;
19
- success: boolean;
20
- blockers: string[];
21
- }
22
- export declare function initializeGateHooks(): void;
23
- export declare function onGateTransition(phase: 'PreGateTransition' | 'PostGateTransition', callback: (event: GateTransitionEvent) => void): void;
24
- export declare function offGateTransition(phase: 'PreGateTransition' | 'PostGateTransition', callback: (event: GateTransitionEvent) => void): void;
25
- export declare function emitGateTransition(event: GateTransitionEvent): void;
26
- export declare function runGateHooks(phase: 'PreGateTransition' | 'PostGateTransition', event: GateTransitionEvent): Promise<void>;
27
- export declare function executeGateTransitionHooks(from: number, to: number, success: boolean, blockers: string[]): Promise<void>;
28
- export declare function addGateHook(config: GateHookConfig): void;
29
- export declare function clearGateHooks(): void;
30
- export declare function listGateHooks(): GateHookConfig[];
@@ -1,91 +0,0 @@
1
- /**
2
- * Gate Transition Hook Manager
3
- *
4
- * Handles PreGateTransition and PostGateTransition hooks.
5
- * Hooks are triggered when a gate transition occurs.
6
- */
7
- import { EventEmitter } from 'events';
8
- import { exec } from 'child_process';
9
- import { promisify } from 'util';
10
- import * as path from 'path';
11
- import * as fs from 'fs';
12
- const execAsync = promisify(exec);
13
- class GateTransitionEmitter extends EventEmitter {
14
- }
15
- const transitionEmitter = new GateTransitionEmitter();
16
- const GATE_HOOKS = [];
17
- let initialized = false;
18
- export function initializeGateHooks() {
19
- if (initialized)
20
- return;
21
- initialized = true;
22
- loadGateHooksFromSettings();
23
- }
24
- function loadGateHooksFromSettings() {
25
- try {
26
- const settingsPath = path.join(process.cwd(), 'src', 'bollharness', '.boll', 'settings.json');
27
- if (!fs.existsSync(settingsPath))
28
- return;
29
- const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
30
- const gateHooks = settings.hooks?.PreGateTransition || settings.hooks?.PostGateTransition || [];
31
- for (const hook of gateHooks) {
32
- if (hook.type === 'command' || hook.type === 'skill') {
33
- GATE_HOOKS.push(hook);
34
- }
35
- }
36
- }
37
- catch (e) {
38
- console.warn('[GateHooks] Failed to load gate hooks from settings:', e);
39
- }
40
- }
41
- export function onGateTransition(phase, callback) {
42
- transitionEmitter.on(phase, callback);
43
- }
44
- export function offGateTransition(phase, callback) {
45
- transitionEmitter.off(phase, callback);
46
- }
47
- export function emitGateTransition(event) {
48
- transitionEmitter.emit('PreGateTransition', event);
49
- transitionEmitter.emit('PostGateTransition', event);
50
- }
51
- function matchGate(gates, to) {
52
- if (!gates || gates.length === 0)
53
- return true;
54
- return gates.includes(to);
55
- }
56
- export async function runGateHooks(phase, event) {
57
- for (const hook of GATE_HOOKS) {
58
- if (!matchGate(hook.gates, event.to))
59
- continue;
60
- try {
61
- if (hook.type === 'command' && hook.command) {
62
- const timeout = hook.timeout || 10;
63
- await execAsync(hook.command, { timeout: timeout * 1000, cwd: process.cwd() });
64
- }
65
- else if (hook.type === 'skill' && hook.skill) {
66
- await runSkillHook(hook.skill, hook.action || 'default', event);
67
- }
68
- }
69
- catch (e) {
70
- console.error(`[GateHooks] Hook failed (${phase}):`, e);
71
- }
72
- }
73
- }
74
- async function runSkillHook(skill, action, event) {
75
- console.log(`[GateHooks] Running skill hook: ${skill} action=${action} for Gate ${event.from} -> ${event.to}`);
76
- }
77
- export async function executeGateTransitionHooks(from, to, success, blockers) {
78
- const event = { from, to, success, blockers };
79
- await runGateHooks('PreGateTransition', event);
80
- emitGateTransition(event);
81
- await runGateHooks('PostGateTransition', event);
82
- }
83
- export function addGateHook(config) {
84
- GATE_HOOKS.push(config);
85
- }
86
- export function clearGateHooks() {
87
- GATE_HOOKS.length = 0;
88
- }
89
- export function listGateHooks() {
90
- return [...GATE_HOOKS];
91
- }
@@ -1,105 +0,0 @@
1
- /**
2
- * Guard Checker - Port of Bollharness checks to Bolloon guardrails
3
- *
4
- * Transforms bollharness's 15+ check functions into Bolloon's guardrail system.
5
- *
6
- * Key concepts:
7
- * - Finding: bollharness's issue report structure
8
- * - Guardrail: Bolloon's pre/post execution check interface
9
- * - Guard Map: Path → Check[] routing
10
- */
11
- export type Severity = 'P0' | 'P1' | 'P2';
12
- export interface Finding {
13
- severity: Severity;
14
- message: string;
15
- file: string;
16
- line?: number;
17
- blocking: boolean;
18
- category: string;
19
- problem_class: string;
20
- required_skills: string[];
21
- required_reads: string[];
22
- }
23
- export interface GuardFinding extends Finding {
24
- checkName: string;
25
- checkPath: string;
26
- }
27
- export interface GuardResult {
28
- passed: boolean;
29
- findings: GuardFinding[];
30
- blockingCount: number;
31
- highestSeverity: Severity | null;
32
- }
33
- export interface GuardConfig {
34
- name: string;
35
- description: string;
36
- run: (repoRoot: string, mode?: string) => Finding[];
37
- category?: string;
38
- }
39
- export interface GuardCheck {
40
- name: string;
41
- description: string;
42
- paths: string[] | RegExp[];
43
- run: (filePath: string, content?: string) => GuardFinding[];
44
- }
45
- /**
46
- * Port of bollharness's Finding interface
47
- */
48
- export declare function createFinding(params: {
49
- severity: Severity;
50
- message: string;
51
- file: string;
52
- line?: number;
53
- blocking?: boolean;
54
- category?: string;
55
- problem_class?: string;
56
- required_skills?: string[];
57
- required_reads?: string[];
58
- }): Finding;
59
- /**
60
- * Guard Map - Maps file paths to relevant checks
61
- * Adapted from bollharness's guard_router.ts
62
- */
63
- export declare const GUARD_MAP: Record<string, string[]>;
64
- /**
65
- * Default guards that run for all files
66
- */
67
- export declare const DEFAULT_GUARDS: string[];
68
- /**
69
- * Category to Skills mapping
70
- * Maps guard categories to required bollharness skills
71
- */
72
- export declare const CATEGORY_TO_SKILLS: Record<string, string[]>;
73
- /**
74
- * Check implementations - Ported from bollharness checks
75
- */
76
- export declare function checkApiTypes(filePath: string): GuardFinding[];
77
- export declare function checkDocFreshness(filePath: string): GuardFinding[];
78
- export declare function checkSkillParity(filePath: string): GuardFinding[];
79
- export declare function checkVersions(filePath: string): GuardFinding[];
80
- export declare function checkHookInstalled(filePath: string): GuardFinding[];
81
- export declare function checkArtifactLink(filePath: string): GuardFinding[];
82
- /**
83
- * All available checks
84
- */
85
- export declare const ALL_CHECKS: Record<string, (filePath: string) => GuardFinding[]>;
86
- /**
87
- * Route file path to relevant checks
88
- * Adapted from bollharness's route() function
89
- */
90
- export declare function route(filePath: string): string[];
91
- /**
92
- * Run guards for a file
93
- */
94
- export declare function runGuards(filePath: string): Promise<GuardResult>;
95
- /**
96
- * GuardChecker class for integration with Bolloon's constraint system
97
- */
98
- export declare class GuardChecker {
99
- private checksDir;
100
- private enabledChecks;
101
- constructor(checksDir?: string);
102
- enableCheck(name: string): void;
103
- disableCheck(name: string): void;
104
- check(filePath: string): Promise<GuardResult>;
105
- }