@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,261 +0,0 @@
1
- /**
2
- * Judgment-Aware Context Router
3
- *
4
- * Extends ContextRouter with judgment lookup and injection capabilities.
5
- *
6
- * Architecture:
7
- * - Path → Fragment Names → Associated Judgments
8
- * - Confidence-based filtering
9
- * - YAML format for user-language injection
10
- *
11
- * Integration with existing Bollharness:
12
- * - Uses existing ContextRouter.match() for fragment lookup
13
- * - Extends with judgment lookup based on fragment context
14
- * - Injects at Gate 0, Gate 3, and file-edit time
15
- */
16
- import { match as contextMatch, } from './context-router.js';
17
- import { getCombinedJudgments, getJudgmentsForContext, calculateConfidence, } from '../pi-ecosystem-judgment/index.js';
18
- const DEFAULT_OPTIONS = {
19
- minConfidence: 0.7,
20
- maxJudgments: 5,
21
- format: 'yaml',
22
- includeEvidence: false,
23
- };
24
- /**
25
- * Get judgments associated with a fragment name
26
- */
27
- export async function getJudgmentsForFragment(fragmentName) {
28
- const allJudgments = await getCombinedJudgments();
29
- // Map fragment to judgment context categories
30
- const fragmentContextMap = {
31
- 'truth-source-hierarchy': ['truth-source', 'code', 'architecture', 'hierarchy', 'priority'],
32
- 'general-dev-principles': ['development', 'code-quality', 'best-practice'],
33
- 'code-quality': ['code-quality', 'readability', 'maintainability'],
34
- 'bridge-constitution': ['protocol', 'p2p', 'network'],
35
- 'agent-architecture': ['agent', 'multi-agent', 'collaboration'],
36
- 'multi-agent-patterns': ['multi-agent', 'delegation', 'coordination'],
37
- 'testing-patterns': ['testing', 'quality', 'verification'],
38
- 'decision-tracking': ['decision', 'adr', 'architecture'],
39
- };
40
- const contexts = fragmentContextMap[fragmentName] || [fragmentName];
41
- const relevantJudgments = [];
42
- for (const judgment of allJudgments) {
43
- if (!judgment.context)
44
- continue;
45
- const judgmentContexts = judgment.context.toLowerCase().split(/[,\s]+/);
46
- for (const ctx of contexts) {
47
- if (judgmentContexts.some(jc => jc.includes(ctx.toLowerCase()))) {
48
- relevantJudgments.push(judgment);
49
- break;
50
- }
51
- }
52
- }
53
- return relevantJudgments;
54
- }
55
- /**
56
- * Get high-confidence judgments for a file path
57
- */
58
- export async function getJudgmentsForPath(filePath, options = {}) {
59
- const opts = { ...DEFAULT_OPTIONS, ...options };
60
- // Get associated fragment names
61
- const fragmentNames = contextMatch(filePath);
62
- const allFragments = fragmentNames.length > 0 ? fragmentNames : ['general-dev-principles'];
63
- // Get judgments for each fragment
64
- const allJudgments = [];
65
- for (const fragment of allFragments) {
66
- const judgments = await getJudgmentsForFragment(fragment);
67
- allJudgments.push(...judgments);
68
- }
69
- // Deduplicate and filter by confidence
70
- const seen = new Set();
71
- const filteredJudgments = [];
72
- for (const j of allJudgments) {
73
- if (seen.has(j.id))
74
- continue;
75
- if (j.confidence < opts.minConfidence)
76
- continue;
77
- seen.add(j.id);
78
- filteredJudgments.push(j);
79
- }
80
- // Sort by confidence descending
81
- filteredJudgments.sort((a, b) => b.confidence - a.confidence);
82
- // Limit count
83
- const limitedJudgments = filteredJudgments.slice(0, opts.maxJudgments);
84
- // Calculate overall confidence
85
- const overallConfidence = calculateConfidence(limitedJudgments);
86
- // Format as YAML
87
- const contextYaml = formatJudgmentsAsYaml(limitedJudgments, opts);
88
- return {
89
- fragments: allFragments,
90
- judgments: limitedJudgments,
91
- contextYaml,
92
- confidence: overallConfidence,
93
- };
94
- }
95
- /**
96
- * Get core judgments for session start (high confidence only)
97
- */
98
- export async function getCoreJudgmentsForSession(minConfidence = 0.9) {
99
- const allJudgments = await getCombinedJudgments();
100
- const highConfidence = allJudgments
101
- .filter(j => j.confidence >= minConfidence && j.source === 'human')
102
- .sort((a, b) => b.confidence - a.confidence)
103
- .slice(0, 10);
104
- if (highConfidence.length === 0) {
105
- return '';
106
- }
107
- const lines = [
108
- `# User Core Values (Confidence >= ${minConfidence})`,
109
- `# Injected at session start - these represent fundamental user principles`,
110
- '',
111
- 'core_judgments:',
112
- ];
113
- for (const j of highConfidence) {
114
- lines.push(` - principle: "${escapeYamlString(j.content)}"`);
115
- lines.push(` type: ${j.type}`);
116
- lines.push(` confidence: ${j.confidence.toFixed(2)}`);
117
- if (j.context) {
118
- lines.push(` context: "${j.context}"`);
119
- }
120
- }
121
- return lines.join('\n');
122
- }
123
- /**
124
- * Get judgments for a specific context (e.g., "investment", "code-review")
125
- */
126
- export async function getJudgmentsForContextRequest(context, options = {}) {
127
- const opts = { ...DEFAULT_OPTIONS, ...options };
128
- const judgments = await getJudgmentsForContext(context);
129
- const filtered = judgments
130
- .filter(j => j.confidence >= opts.minConfidence)
131
- .sort((a, b) => b.confidence - a.confidence)
132
- .slice(0, opts.maxJudgments);
133
- const overallConfidence = calculateConfidence(filtered);
134
- const contextYaml = formatJudgmentsAsYaml(filtered, opts);
135
- return {
136
- fragments: [],
137
- judgments: filtered,
138
- contextYaml,
139
- confidence: overallConfidence,
140
- };
141
- }
142
- /**
143
- * Format judgments as YAML for injection
144
- */
145
- function formatJudgmentsAsYaml(judgments, opts) {
146
- if (judgments.length === 0) {
147
- return '';
148
- }
149
- const lines = [];
150
- if (opts.format === 'yaml') {
151
- lines.push('# Active Judgments');
152
- lines.push('# Based on user history and preferences');
153
- lines.push('');
154
- lines.push('active_judgments:');
155
- for (const j of judgments) {
156
- lines.push(` - principle: "${escapeYamlString(j.content)}"`);
157
- lines.push(` type: ${j.type}`);
158
- lines.push(` confidence: ${j.confidence.toFixed(2)}`);
159
- if (j.context) {
160
- lines.push(` context: "${j.context}"`);
161
- }
162
- if (opts.includeEvidence && j.evidence) {
163
- const evidenceStr = formatEvidence(j.evidence);
164
- lines.push(` evidence: ${evidenceStr}`);
165
- }
166
- lines.push('');
167
- }
168
- }
169
- else if (opts.format === 'json') {
170
- const obj = judgments.map(j => ({
171
- principle: j.content,
172
- type: j.type,
173
- confidence: j.confidence,
174
- context: j.context,
175
- evidence: opts.includeEvidence ? j.evidence : undefined,
176
- }));
177
- lines.push(JSON.stringify(obj, null, 2));
178
- }
179
- else {
180
- // text format
181
- for (const j of judgments) {
182
- lines.push(`[${(j.confidence * 100).toFixed(0)}%] ${j.content}`);
183
- if (j.context) {
184
- lines.push(` Context: ${j.context}`);
185
- }
186
- lines.push('');
187
- }
188
- }
189
- return lines.join('\n');
190
- }
191
- /**
192
- * Format evidence for YAML
193
- */
194
- function formatEvidence(evidence) {
195
- if (!evidence)
196
- return '""';
197
- const parts = [];
198
- if (evidence.trajectory && evidence.trajectory.length > 0) {
199
- const summary = evidence.trajectory
200
- .slice(-3)
201
- .map(t => `${t.timestamp}: ${t.action}`)
202
- .join(' → ');
203
- parts.push(`trajectory: "${escapeYamlString(summary)}"`);
204
- }
205
- if (evidence.preference_pair && evidence.preference_pair.length > 0) {
206
- const pp = evidence.preference_pair[0];
207
- parts.push(`preference: "chose '${escapeYamlString(pp.chosen)}' over '${escapeYamlString(pp.rejected)}'"`);
208
- }
209
- if (evidence.correction) {
210
- parts.push(`correction: "${escapeYamlString(evidence.correction.corrected)}"`);
211
- }
212
- return parts.length > 0 ? `"${parts.join('; ')}"` : '""';
213
- }
214
- /**
215
- * Escape string for YAML
216
- */
217
- function escapeYamlString(str) {
218
- return str
219
- .replace(/\\/g, '\\\\')
220
- .replace(/"/g, '\\"')
221
- .replace(/\n/g, '\\n')
222
- .replace(/\r/g, '\\r')
223
- .replace(/\t/g, '\\t');
224
- }
225
- /**
226
- * Generate injection prompt for a file path
227
- */
228
- export async function generateJudgmentInjection(filePath, gate, options = {}) {
229
- const opts = { ...DEFAULT_OPTIONS, ...options };
230
- // Gate-specific confidence thresholds
231
- const gateConfidence = {
232
- 0: 0.9, // Session start - only highest confidence
233
- 1: 0.8, // Architecture design
234
- 2: 0.75, // Review
235
- 3: 0.8, // Plan freeze
236
- 4: 0.75, // Review
237
- 5: 0.7, // Task architecture
238
- 6: 0.75, // Review
239
- 7: 0.7, // Execution
240
- 8: 0.7, // Test & Integration
241
- };
242
- const minConfidence = gateConfidence[gate] || opts.minConfidence;
243
- const effectiveOptions = { ...opts, minConfidence };
244
- if (gate === 0) {
245
- // Session start - inject core judgments
246
- return await getCoreJudgmentsForSession(minConfidence);
247
- }
248
- // Other gates - inject path-specific judgments
249
- const result = await getJudgmentsForPath(filePath, effectiveOptions);
250
- if (result.contextYaml.length === 0) {
251
- return '';
252
- }
253
- const header = gate === 3
254
- ? '# Plan Freeze - Decision Principles'
255
- : `# Gate ${gate} - Active Judgments`;
256
- return `${header}
257
- # Path: ${filePath}
258
- # Confidence: ${(result.confidence * 100).toFixed(0)}%
259
-
260
- ${result.contextYaml}`;
261
- }
@@ -1,110 +0,0 @@
1
- /**
2
- * Context Router - Port of Bollharness context-fragments to Bolloon
3
- *
4
- * Implements path-based automatic context injection.
5
- * When editing certain files, relevant context fragments are automatically injected.
6
- *
7
- * Loads fragments from src/bollharness/scripts/context-fragments/
8
- */
9
- export declare const BOLLHARNESS_CONTEXT_DIR: any;
10
- export declare const FRAGMENTS_DIR: any;
11
- /**
12
- * Context Map - Maps file paths to relevant context fragments
13
- * Uses actual fragment filenames from src/bollharness/scripts/context-fragments/
14
- */
15
- export declare const CONTEXT_MAP: Record<string, string[]>;
16
- /**
17
- * Default fragments to inject when no specific match
18
- */
19
- export declare const FALLBACK_FRAGMENTS: string[];
20
- /**
21
- * Load a context fragment by name
22
- */
23
- export declare function loadFragment(name: string): string;
24
- /**
25
- * Match file path to context fragments
26
- * Adapted from bollharness's match() function
27
- */
28
- export declare function match(filePath: string): string[];
29
- /**
30
- * Get all fragments for a file
31
- */
32
- export declare function getFragments(filePath: string): string[];
33
- /**
34
- * Load all fragments for a file
35
- */
36
- export declare function loadFragments(filePath: string): string[];
37
- /**
38
- * Context Router class for integration with Bolloon
39
- */
40
- export declare class ContextRouter {
41
- private fragmentsDir;
42
- private injectedFile;
43
- private injectedTTL;
44
- constructor(fragmentsDir?: string);
45
- /**
46
- * Get fragments for a file path
47
- */
48
- match(filePath: string): string[];
49
- /**
50
- * Load fragment content
51
- */
52
- loadFragment(name: string): string;
53
- /**
54
- * Get all context for a file
55
- */
56
- getContext(filePath: string): string;
57
- /**
58
- * Get judgments for a file path (judgment-aware extension)
59
- */
60
- getJudgmentsForPath(filePath: string, minConfidence?: number): Promise<string>;
61
- /**
62
- * Get core judgments for session start
63
- */
64
- getCoreJudgments(minConfidence?: number): Promise<string>;
65
- /**
66
- * Get judgments for a specific context
67
- */
68
- getJudgmentsForContext(context: string, minConfidence?: number): Promise<string>;
69
- /**
70
- * Generate judgment injection for a gate
71
- */
72
- generateJudgmentInjection(filePath: string, gate: number): Promise<string>;
73
- /**
74
- * Check if fragment was recently injected
75
- */
76
- wasRecentlyInjected(fragmentName: string): boolean;
77
- /**
78
- * Mark fragments as injected
79
- */
80
- markInjected(fragmentNames: string[]): void;
81
- }
82
- /**
83
- * Context fragments content
84
- * These can be stored in context-fragments/ directory
85
- */
86
- export declare const CONTEXT_FRAGMENTS: {
87
- 'general-dev-principles': string;
88
- 'code-quality': string;
89
- 'agent-architecture': string;
90
- 'multi-agent-patterns': string;
91
- 'documentation-standards': string;
92
- 'decision-tracking': string;
93
- 'adr-patterns': string;
94
- 'project-governance': string;
95
- 'truth-source-hierarchy': string;
96
- 'testing-patterns': string;
97
- 'quality-standards': string;
98
- 'workflow-patterns': string;
99
- 'orchestration-patterns': string;
100
- 'document-processing': string;
101
- 'parser-patterns': string;
102
- 'p2p-protocols': string;
103
- 'connection-patterns': string;
104
- 'constraint-design': string;
105
- 'validation-patterns': string;
106
- 'social-protocols': string;
107
- 'agent-discovery': string;
108
- 'project-intro': string;
109
- 'getting-started': string;
110
- };