@bolloon/bolloon-agent 0.1.37 → 0.1.39

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 (31) hide show
  1. package/dist/agents/constraint-layer.js +1 -2
  2. package/package.json +1 -1
  3. package/scripts/auto-evolve-oneshot.sh +155 -0
  4. package/scripts/auto-evolve-snapshot.sh +136 -0
  5. package/scripts/build-cli.js +216 -0
  6. package/scripts/detect-schema-changes.sh +48 -0
  7. package/scripts/postinstall.js +153 -0
  8. package/dist/bollharness-integration/llm/pi-ai.js +0 -397
  9. package/dist/bollharness-integration/pi-ecosystem-colony/index.js +0 -365
  10. package/dist/bollharness-integration/pi-ecosystem-goals/index.js +0 -458
  11. package/dist/bollharness-integration/pi-ecosystem-judgment/decision.js +0 -300
  12. package/dist/bollharness-integration/pi-ecosystem-judgment/distillation.js +0 -291
  13. package/dist/bollharness-integration/pi-ecosystem-judgment/index.js +0 -445
  14. package/dist/bollharness-integration/pi-ecosystem-mcp/index.js +0 -331
  15. package/dist/bollharness-integration/pi-ecosystem-subagents/index.js +0 -303
  16. package/dist/constraints/commands.js +0 -100
  17. package/dist/constraints/permissions.js +0 -37
  18. package/dist/constraints/runtime.js +0 -135
  19. package/dist/constraints/session.js +0 -48
  20. package/dist/constraints/system-init.js +0 -51
  21. package/dist/constraints/tools.js +0 -104
  22. package/dist/llm/minimax-provider.js +0 -46
  23. package/dist/llm/minimax.js +0 -45
  24. package/dist/pi-ecosystem-colony/index.js +0 -365
  25. package/dist/runtime/context/minimax-prompt.js +0 -178
  26. package/dist/runtime/context/sys-prompt.js +0 -1
  27. package/dist/social/ant-colony/AdaptiveHeartbeat.js +0 -101
  28. package/dist/social/ant-colony/PheromoneEngine.js +0 -227
  29. package/dist/social/ant-colony/index.js +0 -6
  30. package/dist/social/ant-colony/types.js +0 -24
  31. package/dist/utils/double.js +0 -6
@@ -1,445 +0,0 @@
1
- /**
2
- * Pi Judgment Integration for Bolloon
3
- *
4
- * Core module for capturing, distilling, and applying human judgment.
5
- *
6
- * Architecture:
7
- * Human Input → Distillation Trigger → LLM Extraction → Judgment YAML
8
- * ↓
9
- * ValueFunction
10
- * ↓
11
- * Runtime Decision
12
- *
13
- * Storage: Hybrid mode
14
- * - High-frequency rules: Embedded in context-fragments/*.md YAML frontmatter
15
- * - Long-term preferences: .bolloon/judgments/*.yaml
16
- */
17
- import * as fs from 'fs/promises';
18
- import * as path from 'path';
19
- const JUDGMENTS_DIR = path.join(process.env.HOME || '/tmp', '.bolloon', 'judgments');
20
- const JUDGMENT_FILES = {
21
- rules: path.join(JUDGMENTS_DIR, 'rules.yaml'),
22
- preferences: path.join(JUDGMENTS_DIR, 'preferences.yaml'),
23
- trajectories: path.join(JUDGMENTS_DIR, 'trajectories.yaml'),
24
- rewards: path.join(JUDGMENTS_DIR, 'rewards.yaml'),
25
- };
26
- let judgmentCache = new Map();
27
- let valueFunctionCache = null;
28
- let cacheDirty = true;
29
- function generateJudgmentId() {
30
- return `jdg-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
31
- }
32
- /**
33
- * Load all judgments from YAML files
34
- */
35
- export async function loadJudgments() {
36
- const judgments = new Map();
37
- await fs.mkdir(JUDGMENTS_DIR, { recursive: true });
38
- for (const [type, filePath] of Object.entries(JUDGMENT_FILES)) {
39
- try {
40
- const content = await fs.readFile(filePath, 'utf-8');
41
- const data = parseYaml(content);
42
- if (data && Array.isArray(data)) {
43
- judgments.set(type, data);
44
- }
45
- else if (data && 'judgments' in data && Array.isArray(data.judgments)) {
46
- judgments.set(type, data.judgments);
47
- }
48
- }
49
- catch {
50
- judgments.set(type, []);
51
- }
52
- }
53
- judgmentCache = judgments;
54
- cacheDirty = false;
55
- return judgments;
56
- }
57
- /**
58
- * Save judgments to YAML file
59
- */
60
- async function saveJudgments(type, judgments) {
61
- await fs.mkdir(JUDGMENTS_DIR, { recursive: true });
62
- const filePath = JUDGMENT_FILES[type];
63
- if (!filePath)
64
- return;
65
- const yaml = serializeYaml({ judgments });
66
- await fs.writeFile(filePath, yaml, 'utf-8');
67
- cacheDirty = true;
68
- }
69
- /**
70
- * Create a new judgment
71
- */
72
- export async function createJudgment(params) {
73
- const judgment = {
74
- id: generateJudgmentId(),
75
- type: params.type,
76
- content: params.content,
77
- source: params.source,
78
- confidence: params.confidence,
79
- context: params.context,
80
- createdAt: new Date().toISOString(),
81
- updatedAt: new Date().toISOString(),
82
- evidence: params.evidence,
83
- };
84
- const judgments = await loadJudgments();
85
- const typeJudgments = judgments.get(params.type) || [];
86
- typeJudgments.push(judgment);
87
- judgments.set(params.type, typeJudgments);
88
- await saveJudgments(params.type, typeJudgments);
89
- console.log(`[Judgment] Created ${judgment.id} (${params.type}): ${params.content.substring(0, 50)}...`);
90
- return judgment;
91
- }
92
- /**
93
- * Update judgment confidence based on feedback
94
- */
95
- export async function updateJudgmentConfidence(id, delta, feedbackType) {
96
- const judgments = await loadJudgments();
97
- for (const [type, typeJudgments] of judgments.entries()) {
98
- const judgment = typeJudgments.find((j) => j.id === id);
99
- if (judgment) {
100
- let confidenceChange = delta;
101
- if (feedbackType === 'approve') {
102
- confidenceChange = Math.min(delta, 1 - judgment.confidence);
103
- }
104
- else if (feedbackType === 'reject') {
105
- confidenceChange = -delta;
106
- }
107
- else if (feedbackType === 'correct') {
108
- confidenceChange = delta * 2;
109
- }
110
- judgment.confidence = Math.max(0, Math.min(1, judgment.confidence + confidenceChange));
111
- judgment.updatedAt = new Date().toISOString();
112
- await saveJudgments(type, typeJudgments);
113
- return judgment;
114
- }
115
- }
116
- return null;
117
- }
118
- /**
119
- * Get all judgments
120
- */
121
- export async function getAllJudgments() {
122
- const judgments = await loadJudgments();
123
- const all = [];
124
- for (const typeJudgments of judgments.values()) {
125
- all.push(...typeJudgments);
126
- }
127
- return all;
128
- }
129
- /**
130
- * Get judgments by type
131
- */
132
- export async function getJudgmentsByType(type) {
133
- const judgments = await loadJudgments();
134
- return judgments.get(type) || [];
135
- }
136
- /**
137
- * Get judgments relevant to a context
138
- */
139
- export async function getJudgmentsForContext(context) {
140
- const all = await getAllJudgments();
141
- return all.filter((j) => {
142
- if (!j.context)
143
- return false;
144
- return j.context.toLowerCase().includes(context.toLowerCase());
145
- });
146
- }
147
- /**
148
- * Calculate confidence score for a decision
149
- */
150
- export function calculateConfidence(judgments) {
151
- if (judgments.length === 0)
152
- return 0.5;
153
- let totalWeight = 0;
154
- let weightedSum = 0;
155
- for (const j of judgments) {
156
- const weight = j.confidence * (j.source === 'human' ? 1.5 : 1.0);
157
- weightedSum += weight;
158
- totalWeight += weight;
159
- }
160
- return totalWeight > 0 ? weightedSum / totalWeight : 0.5;
161
- }
162
- /**
163
- * Build ValueFunction from judgments
164
- */
165
- export async function buildValueFunction(context) {
166
- const judgments = context
167
- ? await getJudgmentsForContext(context)
168
- : await getAllJudgments();
169
- const contextWeights = {};
170
- const contextCounts = {};
171
- for (const j of judgments) {
172
- const ctx = j.context || 'general';
173
- contextCounts[ctx] = (contextCounts[ctx] || 0) + 1;
174
- }
175
- for (const [ctx, count] of Object.entries(contextCounts)) {
176
- contextWeights[ctx] = count / judgments.length;
177
- }
178
- return {
179
- judgments,
180
- contextWeights,
181
- lastUpdated: new Date().toISOString(),
182
- };
183
- }
184
- /**
185
- * Get cached ValueFunction
186
- */
187
- export async function getValueFunction(context) {
188
- if (!valueFunctionCache || cacheDirty) {
189
- valueFunctionCache = await buildValueFunction(context);
190
- }
191
- return valueFunctionCache;
192
- }
193
- /**
194
- * Extract judgments from context fragment YAML frontmatter
195
- */
196
- export async function extractFromFragment(fragmentPath) {
197
- try {
198
- const content = await fs.readFile(fragmentPath, 'utf-8');
199
- const frontmatter = extractFrontmatter(content);
200
- if (!frontmatter.judgment)
201
- return [];
202
- const j = frontmatter.judgment;
203
- return [{
204
- id: generateJudgmentId(),
205
- type: j.type || 'rule',
206
- content: extractMarkdownContent(content),
207
- source: j.source || 'human',
208
- confidence: typeof j.confidence === 'number' ? j.confidence : 0.9,
209
- context: j.category || path.basename(fragmentPath, '.md'),
210
- createdAt: j.last_reviewed || new Date().toISOString(),
211
- updatedAt: new Date().toISOString(),
212
- metadata: { source: 'fragment', fragment: fragmentPath },
213
- }];
214
- }
215
- catch {
216
- return [];
217
- }
218
- }
219
- /**
220
- * Load judgments from all context fragments
221
- */
222
- export async function loadFragmentJudgments() {
223
- const FRAGMENTS_DIR = path.join(process.cwd(), 'src', 'bollharness', 'scripts', 'context-fragments');
224
- const fragmentJudgments = [];
225
- try {
226
- const files = await fs.readdir(FRAGMENTS_DIR);
227
- for (const file of files) {
228
- if (file.endsWith('.md')) {
229
- const judgments = await extractFromFragment(path.join(FRAGMENTS_DIR, file));
230
- fragmentJudgments.push(...judgments);
231
- }
232
- }
233
- }
234
- catch {
235
- // Fragment directory doesn't exist
236
- }
237
- return fragmentJudgments;
238
- }
239
- /**
240
- * Get combined judgments (file + fragments)
241
- */
242
- export async function getCombinedJudgments() {
243
- const [fileJudgments, fragmentJudgments] = await Promise.all([
244
- getAllJudgments(),
245
- loadFragmentJudgments(),
246
- ]);
247
- const seen = new Set();
248
- const combined = [];
249
- for (const j of fragmentJudgments) {
250
- combined.push(j);
251
- seen.add(j.context || j.id);
252
- }
253
- for (const j of fileJudgments) {
254
- if (!seen.has(j.context || j.id)) {
255
- combined.push(j);
256
- }
257
- }
258
- return combined;
259
- }
260
- /**
261
- * Simple YAML parser (handles basic judgment format)
262
- */
263
- function parseYaml(content) {
264
- try {
265
- if (!content.trim())
266
- return [];
267
- const data = {};
268
- const lines = content.split('\n');
269
- let inArray = false;
270
- let arrayKey = '';
271
- const arrayItems = [];
272
- for (const line of lines) {
273
- if (line.trim().startsWith('judgments:')) {
274
- inArray = true;
275
- continue;
276
- }
277
- if (inArray && line.trim().startsWith('-')) {
278
- const item = {};
279
- let currentKey = '';
280
- let currentValue = '';
281
- const itemContent = line.trim().substring(1);
282
- const kvMatch = itemContent.match(/^(\w+):\s*(.*)/);
283
- if (kvMatch) {
284
- currentKey = kvMatch[1];
285
- currentValue = kvMatch[2];
286
- item[currentKey] = parseValue(currentValue);
287
- }
288
- arrayItems.push(item);
289
- continue;
290
- }
291
- if (inArray) {
292
- const kvMatch = line.match(/^(\w+):\s*(.*)/);
293
- if (kvMatch) {
294
- const key = kvMatch[1];
295
- const value = parseValue(kvMatch[2]);
296
- data[key] = value;
297
- }
298
- }
299
- }
300
- if (arrayItems.length > 0) {
301
- data['judgments'] = arrayItems;
302
- }
303
- return data;
304
- }
305
- catch {
306
- return [];
307
- }
308
- }
309
- function parseValue(value) {
310
- const trimmed = value.trim();
311
- if (trimmed === 'true')
312
- return true;
313
- if (trimmed === 'false')
314
- return false;
315
- if (trimmed === 'null' || trimmed === 'undefined')
316
- return null;
317
- if (!isNaN(Number(trimmed)) && trimmed !== '')
318
- return Number(trimmed);
319
- return trimmed;
320
- }
321
- /**
322
- * Simple YAML serializer
323
- */
324
- function serializeYaml(data) {
325
- const lines = ['# Auto-generated by Pi Judgment System', '# Do not edit manually', ''];
326
- if (typeof data === 'object' && data !== null) {
327
- lines.push('judgments:');
328
- const d = data;
329
- const arr = d.judgments;
330
- if (Array.isArray(arr)) {
331
- for (const item of arr) {
332
- lines.push(' - ' + serializeObject(item, 4));
333
- }
334
- }
335
- }
336
- return lines.join('\n');
337
- }
338
- function serializeObject(obj, indent) {
339
- if (typeof obj !== 'object' || obj === null) {
340
- return String(obj);
341
- }
342
- const spaces = ' '.repeat(indent);
343
- const innerSpace = ' '.repeat(indent + 2);
344
- const parts = [];
345
- for (const [key, value] of Object.entries(obj)) {
346
- if (value === undefined || value === null)
347
- continue;
348
- if (typeof value === 'object' && !Array.isArray(value)) {
349
- parts.push(`${key}:`);
350
- parts.push(serializeObject(value, indent + 2));
351
- }
352
- else if (Array.isArray(value)) {
353
- parts.push(`${key}:`);
354
- for (const item of value) {
355
- parts.push(`${innerSpace}- ${serializeObject(item, indent + 4)}`);
356
- }
357
- }
358
- else {
359
- const strValue = typeof value === 'string' ? `"${value}"` : String(value);
360
- parts.push(`${key}: ${strValue}`);
361
- }
362
- }
363
- if (parts.length === 1 && !parts[0].includes(':')) {
364
- return parts[0];
365
- }
366
- return parts.join(`\n${spaces}`);
367
- }
368
- /**
369
- * Extract YAML frontmatter from markdown
370
- */
371
- function extractFrontmatter(content) {
372
- const match = content.match(/^---\n([\s\S]*?)\n---/);
373
- if (!match)
374
- return {};
375
- const frontmatter = {};
376
- const lines = match[1].split('\n');
377
- let currentKey = '';
378
- let currentIndent = 0;
379
- for (const line of lines) {
380
- const indent = line.search(/\S/);
381
- const trimmed = line.trim();
382
- if (trimmed.startsWith('judgment:')) {
383
- currentKey = 'judgment';
384
- frontmatter[currentKey] = {};
385
- }
386
- else if (trimmed.startsWith('-')) {
387
- // Array item
388
- }
389
- else if (trimmed.includes(':')) {
390
- const [key, ...valueParts] = trimmed.split(':');
391
- const value = valueParts.join(':').trim();
392
- if (currentKey === 'judgment' && indent > 0) {
393
- frontmatter[currentKey][key] = parseValue(value);
394
- }
395
- else {
396
- frontmatter[key.trim()] = parseValue(value);
397
- currentKey = key.trim();
398
- }
399
- }
400
- }
401
- return frontmatter;
402
- }
403
- /**
404
- * Extract markdown content (after frontmatter)
405
- */
406
- function extractMarkdownContent(content) {
407
- const match = content.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/);
408
- return match ? match[1].trim() : content;
409
- }
410
- /**
411
- * Get judgment statistics
412
- */
413
- export async function getJudgmentStats() {
414
- const judgments = await getAllJudgments();
415
- const byType = {
416
- rule: 0,
417
- preference: 0,
418
- trajectory: 0,
419
- reward: 0,
420
- };
421
- const bySource = {
422
- human: 0,
423
- agent: 0,
424
- collaboration: 0,
425
- };
426
- let totalConfidence = 0;
427
- for (const j of judgments) {
428
- byType[j.type]++;
429
- bySource[j.source]++;
430
- totalConfidence += j.confidence;
431
- }
432
- return {
433
- total: judgments.length,
434
- byType,
435
- bySource,
436
- averageConfidence: judgments.length > 0 ? totalConfidence / judgments.length : 0,
437
- };
438
- }
439
- /**
440
- * Clear judgment cache
441
- */
442
- export function clearCache() {
443
- valueFunctionCache = null;
444
- cacheDirty = true;
445
- }