@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,100 +0,0 @@
1
- export const PORTED_COMMANDS = [
2
- {
3
- name: 'read',
4
- responsibility: 'Read and display file contents',
5
- sourceHint: 'bolloon built-in',
6
- status: 'mirrored',
7
- },
8
- {
9
- name: 'summarize',
10
- responsibility: 'Summarize conversation or context',
11
- sourceHint: 'bolloon built-in',
12
- status: 'mirrored',
13
- },
14
- {
15
- name: 'improve',
16
- responsibility: 'Improve code or text quality',
17
- sourceHint: 'bolloon built-in',
18
- status: 'mirrored',
19
- },
20
- {
21
- name: 'broadcast',
22
- responsibility: 'Broadcast message to multiple targets',
23
- sourceHint: 'bolloon built-in',
24
- status: 'mirrored',
25
- },
26
- {
27
- name: 'send',
28
- responsibility: 'Send message to a specific target',
29
- sourceHint: 'bolloon built-in',
30
- status: 'mirrored',
31
- },
32
- {
33
- name: 'peers',
34
- responsibility: 'List connected peers',
35
- sourceHint: 'bolloon built-in',
36
- status: 'mirrored',
37
- },
38
- {
39
- name: 'identity',
40
- responsibility: 'Display current identity information',
41
- sourceHint: 'bolloon built-in',
42
- status: 'mirrored',
43
- },
44
- {
45
- name: 'logs',
46
- responsibility: 'Retrieve and display logs',
47
- sourceHint: 'bolloon built-in',
48
- status: 'mirrored',
49
- },
50
- {
51
- name: 'tools',
52
- responsibility: 'List available tools',
53
- sourceHint: 'bolloon built-in',
54
- status: 'mirrored',
55
- },
56
- {
57
- name: 'search',
58
- responsibility: 'Search across files or content',
59
- sourceHint: 'bolloon built-in',
60
- status: 'mirrored',
61
- },
62
- ];
63
- export function getCommand(name) {
64
- const needle = name.toLowerCase();
65
- for (const entry of PORTED_COMMANDS) {
66
- if (entry.name.toLowerCase() === needle) {
67
- return entry;
68
- }
69
- }
70
- return null;
71
- }
72
- export function getCommands() {
73
- return [...PORTED_COMMANDS];
74
- }
75
- export function findCommands(query, limit = 20) {
76
- const needle = query.toLowerCase();
77
- const matches = PORTED_COMMANDS.filter((entry) => entry.name.toLowerCase().includes(needle) ||
78
- entry.sourceHint.toLowerCase().includes(needle));
79
- return matches.slice(0, limit);
80
- }
81
- export function executeCommand(name, prompt = '') {
82
- const entry = getCommand(name);
83
- if (entry === null) {
84
- return {
85
- name,
86
- sourceHint: '',
87
- prompt,
88
- handled: false,
89
- message: `Unknown mirrored command: ${name}`,
90
- };
91
- }
92
- const action = `Mirrored command '${entry.name}' from ${entry.sourceHint} would handle prompt ${JSON.stringify(prompt)}.`;
93
- return {
94
- name: entry.name,
95
- sourceHint: entry.sourceHint,
96
- prompt,
97
- handled: true,
98
- message: action,
99
- };
100
- }
@@ -1,37 +0,0 @@
1
- export class ToolPermissionContext {
2
- denyNames;
3
- denyPrefixes;
4
- constructor(denyNames = new Set(), denyPrefixes = []) {
5
- this.denyNames = denyNames;
6
- this.denyPrefixes = denyPrefixes;
7
- }
8
- static fromIterables(denyNames, denyPrefixes) {
9
- return new ToolPermissionContext(new Set(denyNames
10
- ? Array.from(denyNames).map((n) => n.toLowerCase())
11
- : []), denyPrefixes
12
- ? Array.from(denyPrefixes).map((p) => p.toLowerCase())
13
- : []);
14
- }
15
- blocks(toolName) {
16
- const lowered = toolName.toLowerCase();
17
- return (this.denyNames.has(lowered) ||
18
- this.denyPrefixes.some((prefix) => lowered.startsWith(prefix)));
19
- }
20
- withDenial(name, reason) {
21
- const newDenyNames = new Set(this.denyNames);
22
- newDenyNames.add(name.toLowerCase());
23
- return {
24
- context: new ToolPermissionContext(newDenyNames, this.denyPrefixes),
25
- denial: { toolName: name, reason },
26
- };
27
- }
28
- }
29
- export function checkPermission(context, toolName, reason) {
30
- if (context.blocks(toolName)) {
31
- return {
32
- allowed: false,
33
- denialReason: { toolName, reason },
34
- };
35
- }
36
- return { allowed: true };
37
- }
@@ -1,135 +0,0 @@
1
- import { getCommands } from './commands';
2
- import { getTools, executeTool } from './tools';
3
- import { executeCommand } from './commands';
4
- import { ToolPermissionContext } from './permissions';
5
- import { buildSystemInitMessage } from './system-init';
6
- export class ConstraintRuntime {
7
- permissionContext;
8
- constructor(permissionContext) {
9
- this.permissionContext = permissionContext || new ToolPermissionContext();
10
- }
11
- routePrompt(prompt, limit = 5) {
12
- const tokens = new Set(prompt
13
- .replace(/\//g, ' ')
14
- .replace(/-/g, ' ')
15
- .split(/\s+/)
16
- .map((t) => t.toLowerCase())
17
- .filter((t) => t.length > 0));
18
- const commandMatches = this.scoreMatches(tokens, getCommands(), 'command');
19
- const toolMatches = this.scoreMatches(tokens, getTools(), 'tool');
20
- const selected = [];
21
- if (commandMatches.length > 0) {
22
- selected.push(commandMatches[0]);
23
- }
24
- if (toolMatches.length > 0) {
25
- selected.push(toolMatches[0]);
26
- }
27
- const leftovers = [...commandMatches, ...toolMatches]
28
- .filter((m) => !selected.some((s) => s.name === m.name))
29
- .sort((a, b) => b.score - a.score || a.name.localeCompare(b.name));
30
- selected.push(...leftovers.slice(0, Math.max(0, limit - selected.length)));
31
- return selected.slice(0, limit);
32
- }
33
- scoreMatches(tokens, entries, kind) {
34
- const matches = [];
35
- for (const entry of entries) {
36
- const haystacks = [entry.name.toLowerCase(), entry.sourceHint.toLowerCase()];
37
- let score = 0;
38
- for (const token of tokens) {
39
- if (haystacks.some((h) => h.includes(token))) {
40
- score += 1;
41
- }
42
- }
43
- if (score > 0) {
44
- matches.push({
45
- kind,
46
- name: entry.name,
47
- sourceHint: entry.sourceHint,
48
- score,
49
- });
50
- }
51
- }
52
- return matches.sort((a, b) => b.score - a.score || a.name.localeCompare(b.name));
53
- }
54
- bootstrapSession(prompt, limit = 5, trusted = true) {
55
- const sessionId = crypto.randomUUID();
56
- const matches = this.routePrompt(prompt, limit);
57
- const commandExecs = [];
58
- const toolExecs = [];
59
- const denials = [];
60
- for (const match of matches) {
61
- if (match.kind === 'command') {
62
- const result = executeCommand(match.name, prompt);
63
- if (result.handled) {
64
- commandExecs.push(result.message);
65
- }
66
- }
67
- else if (match.kind === 'tool') {
68
- if (this.permissionContext.blocks(match.name)) {
69
- denials.push({
70
- toolName: match.name,
71
- reason: 'permission denied by context',
72
- });
73
- }
74
- else {
75
- const result = executeTool(match.name, '');
76
- if (result.handled) {
77
- toolExecs.push(result.message);
78
- }
79
- }
80
- }
81
- }
82
- return {
83
- sessionId,
84
- prompt,
85
- trusted,
86
- systemInitMessage: buildSystemInitMessage(trusted),
87
- routedMatches: matches,
88
- commandExecutionMessages: commandExecs,
89
- toolExecutionMessages: toolExecs,
90
- permissionDenials: denials,
91
- };
92
- }
93
- runTurnLoop(prompt, limit = 5, maxTurns = 3) {
94
- const results = [];
95
- let currentPrompt = prompt;
96
- for (let turn = 0; turn < maxTurns; turn++) {
97
- const turnPrompt = turn === 0 ? currentPrompt : `${currentPrompt} [turn ${turn + 1}]`;
98
- const matches = this.routePrompt(turnPrompt, limit);
99
- const commandNames = matches
100
- .filter((m) => m.kind === 'command')
101
- .map((m) => m.name);
102
- const toolNames = matches
103
- .filter((m) => m.kind === 'tool')
104
- .map((m) => m.name);
105
- const outputLines = [
106
- `Turn ${turn + 1}`,
107
- `Prompt: ${turnPrompt}`,
108
- `Matched commands: ${commandNames.join(', ') || 'none'}`,
109
- `Matched tools: ${toolNames.join(', ') || 'none'}`,
110
- ];
111
- const output = outputLines.join('\n');
112
- const inputTokens = turnPrompt.split(/\s+/).length;
113
- const outputTokens = output.split(/\s+/).length;
114
- results.push({
115
- output,
116
- matchedCommands: commandNames,
117
- matchedTools: toolNames,
118
- permissionDenials: [],
119
- stopReason: 'completed',
120
- usage: { inputTokens, outputTokens },
121
- });
122
- if (turn < maxTurns - 1) {
123
- currentPrompt = turnPrompt;
124
- }
125
- }
126
- return results;
127
- }
128
- setPermissionContext(context) {
129
- this.permissionContext = context;
130
- }
131
- getPermissionContext() {
132
- return this.permissionContext;
133
- }
134
- }
135
- export const defaultRuntime = new ConstraintRuntime();
@@ -1,48 +0,0 @@
1
- import * as fs from 'fs/promises';
2
- import * as path from 'path';
3
- const DEFAULT_SESSION_DIR = path.join(process.env.HOME || '/tmp', '.bolloon', 'sessions');
4
- export async function saveSession(session, directory) {
5
- const targetDir = directory || DEFAULT_SESSION_DIR;
6
- await fs.mkdir(targetDir, { recursive: true });
7
- const filePath = path.join(targetDir, `${session.sessionId}.json`);
8
- await fs.writeFile(filePath, JSON.stringify(session, null, 2));
9
- return filePath;
10
- }
11
- export async function loadSession(sessionId, directory) {
12
- const targetDir = directory || DEFAULT_SESSION_DIR;
13
- const data = await fs.readFile(path.join(targetDir, `${sessionId}.json`), 'utf-8');
14
- return JSON.parse(data);
15
- }
16
- export async function listSessions(directory) {
17
- const targetDir = directory || DEFAULT_SESSION_DIR;
18
- try {
19
- const files = await fs.readdir(targetDir);
20
- const sessions = [];
21
- for (const file of files) {
22
- if (file.endsWith('.json')) {
23
- try {
24
- const data = await fs.readFile(path.join(targetDir, file), 'utf-8');
25
- sessions.push(JSON.parse(data));
26
- }
27
- catch {
28
- // Skip invalid session files
29
- }
30
- }
31
- }
32
- return sessions.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());
33
- }
34
- catch {
35
- return [];
36
- }
37
- }
38
- export async function deleteSession(sessionId, directory) {
39
- const targetDir = directory || DEFAULT_SESSION_DIR;
40
- const filePath = path.join(targetDir, `${sessionId}.json`);
41
- try {
42
- await fs.unlink(filePath);
43
- return true;
44
- }
45
- catch {
46
- return false;
47
- }
48
- }
@@ -1,51 +0,0 @@
1
- import { getCommands } from './commands';
2
- import { getTools } from './tools';
3
- const STARTUP_STEPS = [
4
- { name: 'start top-level prefetch side effects', description: 'Initiate background prefetch operations' },
5
- { name: 'build workspace context', description: 'Construct workspace context for agent operations' },
6
- { name: 'load mirrored command snapshot', description: 'Load command definitions from snapshot' },
7
- { name: 'load mirrored tool snapshot', description: 'Load tool definitions from snapshot' },
8
- { name: 'prepare parity audit hooks', description: 'Set up parity audit instrumentation' },
9
- { name: 'apply trust-gated deferred init', description: 'Execute deferred initialization based on trust level' },
10
- ];
11
- function buildWorkspaceSetup(trusted, context) {
12
- return {
13
- trusted,
14
- builtInCommandCount: getBuiltInCommandNames().size,
15
- loadedCommandCount: getCommands().length,
16
- loadedToolCount: getTools().length,
17
- startupSteps: STARTUP_STEPS,
18
- permissionContext: context?.permissionContext,
19
- currentTime: new Date().toISOString(),
20
- };
21
- }
22
- function getBuiltInCommandNames() {
23
- const commands = getCommands();
24
- return new Set(commands.map((c) => c.name));
25
- }
26
- export function buildSystemInitMessage(trusted, context) {
27
- const setup = buildWorkspaceSetup(trusted, context);
28
- const commands = getCommands();
29
- const tools = getTools();
30
- const lines = [
31
- '# System Init',
32
- '',
33
- `Trusted: ${setup.trusted}`,
34
- `Built-in command names: ${setup.builtInCommandCount}`,
35
- `Loaded command entries: ${commands.length}`,
36
- `Loaded tool entries: ${tools.length}`,
37
- '',
38
- '## Available Commands',
39
- ...commands.map((cmd) => `- ${cmd.name}: ${cmd.responsibility}`),
40
- '',
41
- '## Available Tools',
42
- ...tools.map((tool) => `- ${tool.name}: ${tool.responsibility}`),
43
- '',
44
- '## Startup Steps',
45
- ...setup.startupSteps.map((step) => `- ${step.name}`),
46
- '',
47
- `Current Time: ${setup.currentTime}`,
48
- ];
49
- return lines.join('\n');
50
- }
51
- export { STARTUP_STEPS };
@@ -1,104 +0,0 @@
1
- const PORTED_TOOLS_DATA = [
2
- {
3
- name: 'read_document',
4
- responsibility: 'Read content from a document or file',
5
- sourceHint: 'bolloon/documents/reader.ts',
6
- status: 'mirrored',
7
- },
8
- {
9
- name: 'summarize_document',
10
- responsibility: 'Generate a summary of a document',
11
- sourceHint: 'bolloon/documents/summarizer.ts',
12
- status: 'mirrored',
13
- },
14
- {
15
- name: 'improve_document',
16
- responsibility: 'Improve the quality of a document',
17
- sourceHint: 'bolloon/documents/improver.ts',
18
- status: 'mirrored',
19
- },
20
- {
21
- name: 'list_peers',
22
- responsibility: 'List all connected peers in the network',
23
- sourceHint: 'bolloon/network/p2p.ts',
24
- status: 'mirrored',
25
- },
26
- {
27
- name: 'send_message',
28
- responsibility: 'Send a direct message to a peer',
29
- sourceHint: 'bolloon/network/messaging.ts',
30
- status: 'mirrored',
31
- },
32
- {
33
- name: 'broadcast_message',
34
- responsibility: 'Broadcast a message to all connected peers',
35
- sourceHint: 'bolloon/network/messaging.ts',
36
- status: 'mirrored',
37
- },
38
- {
39
- name: 'get_identity',
40
- responsibility: 'Get the identity information of the current node',
41
- sourceHint: 'bolloon/agents/protocol.ts',
42
- status: 'mirrored',
43
- },
44
- {
45
- name: 'get_operation_logs',
46
- responsibility: 'Retrieve operation logs for the current session',
47
- sourceHint: 'bolloon/agents/protocol.ts',
48
- status: 'mirrored',
49
- },
50
- {
51
- name: 'search_files',
52
- responsibility: 'Search for files matching a query pattern',
53
- sourceHint: 'bolloon/documents/search.ts',
54
- status: 'mirrored',
55
- },
56
- ];
57
- export const PORTED_TOOLS = PORTED_TOOLS_DATA;
58
- export function getTool(name) {
59
- const needle = name.toLowerCase();
60
- for (const tool of PORTED_TOOLS) {
61
- if (tool.name.toLowerCase() === needle) {
62
- return tool;
63
- }
64
- }
65
- return null;
66
- }
67
- export function getTools() {
68
- return [...PORTED_TOOLS];
69
- }
70
- export function findTools(query, limit = 20) {
71
- const needle = query.toLowerCase();
72
- const matches = PORTED_TOOLS.filter((tool) => tool.name.toLowerCase().includes(needle) ||
73
- tool.sourceHint.toLowerCase().includes(needle));
74
- return matches.slice(0, limit);
75
- }
76
- export function executeTool(name, payload = '') {
77
- const tool = getTool(name);
78
- if (tool === null) {
79
- return {
80
- name,
81
- sourceHint: '',
82
- payload,
83
- handled: false,
84
- message: `Unknown mirrored tool: ${name}`,
85
- };
86
- }
87
- const message = `Mirrored tool '${tool.name}' from ${tool.sourceHint} would handle payload ${JSON.stringify(payload)}.`;
88
- return {
89
- name: tool.name,
90
- sourceHint: tool.sourceHint,
91
- payload,
92
- handled: true,
93
- message,
94
- };
95
- }
96
- export function filterToolsByPermissionContext(tools, permissionContext) {
97
- if (permissionContext === null) {
98
- return [...tools];
99
- }
100
- return tools.filter((tool) => !permissionContext.blocks(tool.name));
101
- }
102
- export function toolNames() {
103
- return PORTED_TOOLS.map((tool) => tool.name);
104
- }
@@ -1,46 +0,0 @@
1
- export class MinimaxProvider {
2
- apiKey;
3
- baseUrl = 'https://api.minimax.chat/v1';
4
- constructor(apiKey) {
5
- this.apiKey = apiKey;
6
- }
7
- async chat(options) {
8
- const response = await fetch(`${this.baseUrl}/text/chatcompletion_v2`, {
9
- method: 'POST',
10
- headers: {
11
- 'Content-Type': 'application/json',
12
- 'Authorization': `Bearer ${this.apiKey}`
13
- },
14
- body: JSON.stringify(options)
15
- });
16
- if (!response.ok) {
17
- throw new Error(`Minimax API error: ${response.status}`);
18
- }
19
- return response.json();
20
- }
21
- async chatPro(options) {
22
- const response = await fetch(`${this.baseUrl}/text/chatcompletion_pro`, {
23
- method: 'POST',
24
- headers: {
25
- 'Content-Type': 'application/json',
26
- 'Authorization': `Bearer ${this.apiKey}`
27
- },
28
- body: JSON.stringify(options)
29
- });
30
- if (!response.ok) {
31
- throw new Error(`Minimax API error: ${response.status}`);
32
- }
33
- return response.json();
34
- }
35
- }
36
- let providerInstance = null;
37
- export function initMinimaxProvider(apiKey) {
38
- providerInstance = new MinimaxProvider(apiKey);
39
- return providerInstance;
40
- }
41
- export function getMinimaxProvider() {
42
- if (!providerInstance) {
43
- throw new Error('Minimax provider not initialized. Call initMinimaxProvider first.');
44
- }
45
- return providerInstance;
46
- }
@@ -1,45 +0,0 @@
1
- import { initPiAI, getModel, isModelAvailable } from './pi-ai.js';
2
- export class MinimaxLLM {
3
- model;
4
- constructor(config) {
5
- this.model = initPiAI({
6
- provider: config.provider,
7
- apiKey: config.apiKey,
8
- baseUrl: config.baseUrl,
9
- model: config.model
10
- });
11
- }
12
- async chat(message, context) {
13
- return this.model.chat(message, context);
14
- }
15
- async summarize(text, context) {
16
- return this.model.summarize(text, context);
17
- }
18
- async improveContent(content, requirements, context) {
19
- return this.model.improveContent(content, requirements, context);
20
- }
21
- estimateQuality(original, summary) {
22
- return this.model.estimateQuality(original, summary);
23
- }
24
- async shouldAutoSend(qualityScore, threshold = 0.7) {
25
- return this.model.shouldAutoSend(qualityScore, threshold);
26
- }
27
- }
28
- export { initPiAI, getModel, isModelAvailable } from './pi-ai.js';
29
- let minimaxInstance = null;
30
- export function initMinimax(config) {
31
- minimaxInstance = new MinimaxLLM(config);
32
- return minimaxInstance;
33
- }
34
- export function getMinimax() {
35
- if (!minimaxInstance) {
36
- if (isModelAvailable()) {
37
- const piModel = getModel();
38
- minimaxInstance = new MinimaxLLM({});
39
- minimaxInstance.model = piModel;
40
- return minimaxInstance;
41
- }
42
- throw new Error('Minimax not initialized. Call initMinimax first.');
43
- }
44
- return minimaxInstance;
45
- }