agentic-qe 1.8.4 → 1.9.1
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.
- package/.claude/skills/agentic-jujutsu/SKILL.md +645 -0
- package/CHANGELOG.md +394 -0
- package/README.md +86 -18
- package/dist/App.d.ts +5 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +15 -0
- package/dist/App.js.map +1 -0
- package/dist/cli/commands/constitution.d.ts +34 -0
- package/dist/cli/commands/constitution.d.ts.map +1 -0
- package/dist/cli/commands/constitution.js +679 -0
- package/dist/cli/commands/constitution.js.map +1 -0
- package/dist/cli/commands/init.d.ts +8 -75
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +22 -2292
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/learn/index.d.ts.map +1 -1
- package/dist/cli/commands/learn/index.js +3 -4
- package/dist/cli/commands/learn/index.js.map +1 -1
- package/dist/cli/commands/telemetry.d.ts +36 -0
- package/dist/cli/commands/telemetry.d.ts.map +1 -0
- package/dist/cli/commands/telemetry.js +364 -0
- package/dist/cli/commands/telemetry.js.map +1 -0
- package/dist/cli/index.js +66 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init/agents.d.ts +22 -0
- package/dist/cli/init/agents.d.ts.map +1 -0
- package/dist/cli/init/agents.js +522 -0
- package/dist/cli/init/agents.js.map +1 -0
- package/dist/cli/init/bash-wrapper.d.ts +14 -0
- package/dist/cli/init/bash-wrapper.d.ts.map +1 -0
- package/dist/cli/init/bash-wrapper.js +47 -0
- package/dist/cli/init/bash-wrapper.js.map +1 -0
- package/dist/cli/init/claude-config.d.ts +24 -0
- package/dist/cli/init/claude-config.d.ts.map +1 -0
- package/dist/cli/init/claude-config.js +275 -0
- package/dist/cli/init/claude-config.js.map +1 -0
- package/dist/cli/init/claude-md.d.ts +19 -0
- package/dist/cli/init/claude-md.d.ts.map +1 -0
- package/dist/cli/init/claude-md.js +153 -0
- package/dist/cli/init/claude-md.js.map +1 -0
- package/dist/cli/init/commands.d.ts +6 -0
- package/dist/cli/init/commands.d.ts.map +1 -0
- package/dist/cli/init/commands.js +83 -0
- package/dist/cli/init/commands.js.map +1 -0
- package/dist/cli/init/database-init.d.ts +15 -0
- package/dist/cli/init/database-init.d.ts.map +1 -0
- package/dist/cli/init/database-init.js +203 -0
- package/dist/cli/init/database-init.js.map +1 -0
- package/dist/cli/init/directory-structure.d.ts +14 -0
- package/dist/cli/init/directory-structure.d.ts.map +1 -0
- package/dist/cli/init/directory-structure.js +91 -0
- package/dist/cli/init/directory-structure.js.map +1 -0
- package/dist/cli/init/documentation.d.ts +14 -0
- package/dist/cli/init/documentation.d.ts.map +1 -0
- package/dist/cli/init/documentation.js +195 -0
- package/dist/cli/init/documentation.js.map +1 -0
- package/dist/cli/init/fleet-config.d.ts +34 -0
- package/dist/cli/init/fleet-config.d.ts.map +1 -0
- package/dist/cli/init/fleet-config.js +269 -0
- package/dist/cli/init/fleet-config.js.map +1 -0
- package/dist/cli/init/helpers.d.ts +6 -0
- package/dist/cli/init/helpers.d.ts.map +1 -0
- package/dist/cli/init/helpers.js +94 -0
- package/dist/cli/init/helpers.js.map +1 -0
- package/dist/cli/init/index.d.ts +32 -0
- package/dist/cli/init/index.d.ts.map +1 -0
- package/dist/cli/init/index.js +294 -0
- package/dist/cli/init/index.js.map +1 -0
- package/dist/cli/init/skills.d.ts +6 -0
- package/dist/cli/init/skills.d.ts.map +1 -0
- package/dist/cli/init/skills.js +138 -0
- package/dist/cli/init/skills.js.map +1 -0
- package/dist/cli/init/utils/file-utils.d.ts +74 -0
- package/dist/cli/init/utils/file-utils.d.ts.map +1 -0
- package/dist/cli/init/utils/file-utils.js +187 -0
- package/dist/cli/init/utils/file-utils.js.map +1 -0
- package/dist/cli/init/utils/index.d.ts +18 -0
- package/dist/cli/init/utils/index.d.ts.map +1 -0
- package/dist/cli/init/utils/index.js +48 -0
- package/dist/cli/init/utils/index.js.map +1 -0
- package/dist/cli/init/utils/log-utils.d.ts +47 -0
- package/dist/cli/init/utils/log-utils.d.ts.map +1 -0
- package/dist/cli/init/utils/log-utils.js +68 -0
- package/dist/cli/init/utils/log-utils.js.map +1 -0
- package/dist/cli/init/utils/path-utils.d.ts +91 -0
- package/dist/cli/init/utils/path-utils.d.ts.map +1 -0
- package/dist/cli/init/utils/path-utils.js +208 -0
- package/dist/cli/init/utils/path-utils.js.map +1 -0
- package/dist/cli/init/utils/validation-utils.d.ts +44 -0
- package/dist/cli/init/utils/validation-utils.d.ts.map +1 -0
- package/dist/cli/init/utils/validation-utils.js +68 -0
- package/dist/cli/init/utils/validation-utils.js.map +1 -0
- package/dist/cli/init/utils.d.ts +183 -0
- package/dist/cli/init/utils.d.ts.map +1 -0
- package/dist/cli/init/utils.js +354 -0
- package/dist/cli/init/utils.js.map +1 -0
- package/dist/components/Dashboard/Dashboard.d.ts +4 -0
- package/dist/components/Dashboard/Dashboard.d.ts.map +1 -0
- package/dist/components/Dashboard/Dashboard.js +148 -0
- package/dist/components/Dashboard/Dashboard.js.map +1 -0
- package/dist/components/Dashboard/DashboardHeader.d.ts +4 -0
- package/dist/components/Dashboard/DashboardHeader.d.ts.map +1 -0
- package/dist/components/Dashboard/DashboardHeader.js +138 -0
- package/dist/components/Dashboard/DashboardHeader.js.map +1 -0
- package/dist/constitution/evaluators/ast-evaluator.d.ts +42 -0
- package/dist/constitution/evaluators/ast-evaluator.d.ts.map +1 -0
- package/dist/constitution/evaluators/ast-evaluator.js +303 -0
- package/dist/constitution/evaluators/ast-evaluator.js.map +1 -0
- package/dist/constitution/evaluators/base.d.ts +144 -0
- package/dist/constitution/evaluators/base.d.ts.map +1 -0
- package/dist/constitution/evaluators/base.js +144 -0
- package/dist/constitution/evaluators/base.js.map +1 -0
- package/dist/constitution/evaluators/index.d.ts +19 -0
- package/dist/constitution/evaluators/index.d.ts.map +1 -0
- package/dist/constitution/evaluators/index.js +56 -0
- package/dist/constitution/evaluators/index.js.map +1 -0
- package/dist/constitution/evaluators/metric-evaluator.d.ts +59 -0
- package/dist/constitution/evaluators/metric-evaluator.d.ts.map +1 -0
- package/dist/constitution/evaluators/metric-evaluator.js +195 -0
- package/dist/constitution/evaluators/metric-evaluator.js.map +1 -0
- package/dist/constitution/evaluators/pattern-evaluator.d.ts +66 -0
- package/dist/constitution/evaluators/pattern-evaluator.d.ts.map +1 -0
- package/dist/constitution/evaluators/pattern-evaluator.js +221 -0
- package/dist/constitution/evaluators/pattern-evaluator.js.map +1 -0
- package/dist/constitution/evaluators/semantic-evaluator.d.ts +68 -0
- package/dist/constitution/evaluators/semantic-evaluator.d.ts.map +1 -0
- package/dist/constitution/evaluators/semantic-evaluator.js +250 -0
- package/dist/constitution/evaluators/semantic-evaluator.js.map +1 -0
- package/dist/contexts/DashboardContext.d.ts +41 -0
- package/dist/contexts/DashboardContext.d.ts.map +1 -0
- package/dist/contexts/DashboardContext.js +187 -0
- package/dist/contexts/DashboardContext.js.map +1 -0
- package/dist/core/memory/SwarmMemoryManager.d.ts +40 -0
- package/dist/core/memory/SwarmMemoryManager.d.ts.map +1 -1
- package/dist/core/memory/SwarmMemoryManager.js +291 -120
- package/dist/core/memory/SwarmMemoryManager.js.map +1 -1
- package/dist/hooks/useKeyboardShortcuts.d.ts +12 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts.map +1 -0
- package/dist/hooks/useKeyboardShortcuts.js +69 -0
- package/dist/hooks/useKeyboardShortcuts.js.map +1 -0
- package/dist/telemetry/instrumentation/agent.d.ts +158 -0
- package/dist/telemetry/instrumentation/agent.d.ts.map +1 -0
- package/dist/telemetry/instrumentation/agent.js +372 -0
- package/dist/telemetry/instrumentation/agent.js.map +1 -0
- package/dist/telemetry/instrumentation/index.d.ts +24 -0
- package/dist/telemetry/instrumentation/index.d.ts.map +1 -0
- package/dist/telemetry/instrumentation/index.js +54 -0
- package/dist/telemetry/instrumentation/index.js.map +1 -0
- package/dist/telemetry/instrumentation/memory.d.ts +313 -0
- package/dist/telemetry/instrumentation/memory.d.ts.map +1 -0
- package/dist/telemetry/instrumentation/memory.js +552 -0
- package/dist/telemetry/instrumentation/memory.js.map +1 -0
- package/dist/telemetry/instrumentation/task.d.ts +146 -0
- package/dist/telemetry/instrumentation/task.d.ts.map +1 -0
- package/dist/telemetry/instrumentation/task.js +305 -0
- package/dist/telemetry/instrumentation/task.js.map +1 -0
- package/dist/telemetry/metrics/collectors/cost.d.ts +246 -0
- package/dist/telemetry/metrics/collectors/cost.d.ts.map +1 -0
- package/dist/telemetry/metrics/collectors/cost.js +526 -0
- package/dist/telemetry/metrics/collectors/cost.js.map +1 -0
- package/dist/telemetry/metrics/collectors/pricing-config.d.ts +87 -0
- package/dist/telemetry/metrics/collectors/pricing-config.d.ts.map +1 -0
- package/dist/telemetry/metrics/collectors/pricing-config.js +207 -0
- package/dist/telemetry/metrics/collectors/pricing-config.js.map +1 -0
- package/dist/telemetry/metrics/index.d.ts +4 -1
- package/dist/telemetry/metrics/index.d.ts.map +1 -1
- package/dist/telemetry/metrics/index.js +18 -2
- package/dist/telemetry/metrics/index.js.map +1 -1
- package/dist/telemetry/types.d.ts +1 -1
- package/dist/telemetry/types.d.ts.map +1 -1
- package/dist/visualization/api/RestEndpoints.d.ts +136 -0
- package/dist/visualization/api/RestEndpoints.d.ts.map +1 -0
- package/dist/visualization/api/RestEndpoints.js +428 -0
- package/dist/visualization/api/RestEndpoints.js.map +1 -0
- package/dist/visualization/api/WebSocketServer.d.ts +165 -0
- package/dist/visualization/api/WebSocketServer.d.ts.map +1 -0
- package/dist/visualization/api/WebSocketServer.js +518 -0
- package/dist/visualization/api/WebSocketServer.js.map +1 -0
- package/dist/visualization/core/DataTransformer.d.ts +89 -0
- package/dist/visualization/core/DataTransformer.d.ts.map +1 -0
- package/dist/visualization/core/DataTransformer.js +478 -0
- package/dist/visualization/core/DataTransformer.js.map +1 -0
- package/dist/visualization/index.d.ts +92 -0
- package/dist/visualization/index.d.ts.map +1 -0
- package/dist/visualization/index.js +121 -0
- package/dist/visualization/index.js.map +1 -0
- package/dist/visualization/types.d.ts +148 -0
- package/dist/visualization/types.d.ts.map +1 -0
- package/dist/visualization/types.js +7 -0
- package/dist/visualization/types.js.map +1 -0
- package/dist/voting/consensus.d.ts +87 -0
- package/dist/voting/consensus.d.ts.map +1 -0
- package/dist/voting/consensus.js +568 -0
- package/dist/voting/consensus.js.map +1 -0
- package/dist/voting/index.d.ts +12 -0
- package/dist/voting/index.d.ts.map +1 -0
- package/dist/voting/index.js +36 -0
- package/dist/voting/index.js.map +1 -0
- package/dist/voting/orchestrator.d.ts +65 -0
- package/dist/voting/orchestrator.d.ts.map +1 -0
- package/dist/voting/orchestrator.js +306 -0
- package/dist/voting/orchestrator.js.map +1 -0
- package/dist/voting/panel-assembly.d.ts +54 -0
- package/dist/voting/panel-assembly.d.ts.map +1 -0
- package/dist/voting/panel-assembly.js +192 -0
- package/dist/voting/panel-assembly.js.map +1 -0
- package/dist/voting/protocol.d.ts +119 -0
- package/dist/voting/protocol.d.ts.map +1 -0
- package/dist/voting/protocol.js +18 -0
- package/dist/voting/protocol.js.map +1 -0
- package/dist/voting/types.d.ts +125 -0
- package/dist/voting/types.d.ts.map +1 -0
- package/dist/voting/types.js +7 -0
- package/dist/voting/types.js.map +1 -0
- package/package.json +27 -2
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Constitution CLI Commands
|
|
4
|
+
*
|
|
5
|
+
* Provides commands for managing and evaluating quality constitutions:
|
|
6
|
+
* - validate: Validate constitution files against schema
|
|
7
|
+
* - list: List all loaded constitutions
|
|
8
|
+
* - show: Display details of a specific constitution
|
|
9
|
+
* - evaluate: Evaluate files against constitution with agent voting
|
|
10
|
+
*
|
|
11
|
+
* @module cli/commands/constitution
|
|
12
|
+
* @version 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.createConstitutionValidateCommand = createConstitutionValidateCommand;
|
|
52
|
+
exports.createConstitutionListCommand = createConstitutionListCommand;
|
|
53
|
+
exports.createConstitutionShowCommand = createConstitutionShowCommand;
|
|
54
|
+
exports.createConstitutionEvaluateCommand = createConstitutionEvaluateCommand;
|
|
55
|
+
exports.createConstitutionCommand = createConstitutionCommand;
|
|
56
|
+
const commander_1 = require("commander");
|
|
57
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
58
|
+
const ora_1 = __importDefault(require("ora"));
|
|
59
|
+
const fs = __importStar(require("fs/promises"));
|
|
60
|
+
const path = __importStar(require("path"));
|
|
61
|
+
const loader_1 = require("../../constitution/loader");
|
|
62
|
+
const base_1 = require("../../constitution/evaluators/base");
|
|
63
|
+
const orchestrator_1 = require("../../voting/orchestrator");
|
|
64
|
+
/**
|
|
65
|
+
* Validate constitution command
|
|
66
|
+
*/
|
|
67
|
+
function createConstitutionValidateCommand() {
|
|
68
|
+
return new commander_1.Command('validate')
|
|
69
|
+
.description('Validate constitution file(s) against schema')
|
|
70
|
+
.argument('[path]', 'Path to constitution file or directory', (0, loader_1.getBaseConstitutionsPath)())
|
|
71
|
+
.option('--strict', 'Strict validation mode')
|
|
72
|
+
.option('--json', 'Output as JSON')
|
|
73
|
+
.action(async (pathArg, options) => {
|
|
74
|
+
const spinner = (0, ora_1.default)('Validating constitutions...').start();
|
|
75
|
+
try {
|
|
76
|
+
const loader = (0, loader_1.getDefaultLoader)();
|
|
77
|
+
const absolutePath = path.resolve(pathArg);
|
|
78
|
+
const stats = await fs.stat(absolutePath);
|
|
79
|
+
let results = [];
|
|
80
|
+
if (stats.isDirectory()) {
|
|
81
|
+
// Validate all constitutions in directory
|
|
82
|
+
const files = await fs.readdir(absolutePath);
|
|
83
|
+
const constitutionFiles = files.filter(f => f.endsWith('.constitution.json'));
|
|
84
|
+
for (const file of constitutionFiles) {
|
|
85
|
+
const filePath = path.join(absolutePath, file);
|
|
86
|
+
try {
|
|
87
|
+
const constitution = loader.loadConstitution(filePath, { validate: false });
|
|
88
|
+
const result = loader.validateConstitution(constitution);
|
|
89
|
+
results.push({ path: filePath, result, constitution });
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
93
|
+
results.push({
|
|
94
|
+
path: filePath,
|
|
95
|
+
result: {
|
|
96
|
+
valid: false,
|
|
97
|
+
errors: [{ path: '/', message: errorMessage, code: 'LOAD_ERROR' }],
|
|
98
|
+
warnings: []
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
// Validate single file
|
|
106
|
+
const constitution = loader.loadConstitution(absolutePath, { validate: false });
|
|
107
|
+
const result = loader.validateConstitution(constitution);
|
|
108
|
+
results.push({ path: absolutePath, result, constitution });
|
|
109
|
+
}
|
|
110
|
+
spinner.stop();
|
|
111
|
+
if (options.json) {
|
|
112
|
+
console.log(JSON.stringify(results, null, 2));
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
displayValidationResults(results);
|
|
116
|
+
}
|
|
117
|
+
// Exit with error if any validation failed
|
|
118
|
+
const hasErrors = results.some(r => !r.result.valid);
|
|
119
|
+
process.exit(hasErrors ? 1 : 0);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
spinner.fail('Validation failed');
|
|
123
|
+
console.error(chalk_1.default.red('Error:'), error);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* List constitutions command
|
|
130
|
+
*/
|
|
131
|
+
function createConstitutionListCommand() {
|
|
132
|
+
return new commander_1.Command('list')
|
|
133
|
+
.description('List all available constitutions')
|
|
134
|
+
.option('-d, --directory <path>', 'Constitution directory', (0, loader_1.getBaseConstitutionsPath)())
|
|
135
|
+
.option('--detailed', 'Show detailed information')
|
|
136
|
+
.option('--json', 'Output as JSON')
|
|
137
|
+
.action(async (options) => {
|
|
138
|
+
try {
|
|
139
|
+
const loader = (0, loader_1.getDefaultLoader)();
|
|
140
|
+
const constitutions = loader.loadConstitutions(options.directory);
|
|
141
|
+
if (options.json) {
|
|
142
|
+
const constitutionArray = Array.from(constitutions.values());
|
|
143
|
+
console.log(JSON.stringify(constitutionArray, null, 2));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
displayConstitutionList(constitutions, options.detailed);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error(chalk_1.default.red('Error:'), error);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Show constitution details command
|
|
157
|
+
*/
|
|
158
|
+
function createConstitutionShowCommand() {
|
|
159
|
+
return new commander_1.Command('show')
|
|
160
|
+
.description('Show detailed information about a constitution')
|
|
161
|
+
.argument('<id>', 'Constitution ID or file path')
|
|
162
|
+
.option('-d, --directory <path>', 'Constitution directory', (0, loader_1.getBaseConstitutionsPath)())
|
|
163
|
+
.option('--json', 'Output as JSON')
|
|
164
|
+
.action(async (id, options) => {
|
|
165
|
+
try {
|
|
166
|
+
const loader = (0, loader_1.getDefaultLoader)();
|
|
167
|
+
let constitution;
|
|
168
|
+
// Try to load as file path first
|
|
169
|
+
if (await fs.stat(id).catch(() => null)) {
|
|
170
|
+
constitution = loader.loadConstitution(id);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// Load from directory by ID
|
|
174
|
+
const constitutions = loader.loadConstitutions(options.directory);
|
|
175
|
+
const found = constitutions.get(id);
|
|
176
|
+
if (!found) {
|
|
177
|
+
console.error(chalk_1.default.red(`Constitution not found: ${id}`));
|
|
178
|
+
console.log(chalk_1.default.gray(`Available: ${Array.from(constitutions.keys()).join(', ')}`));
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
constitution = found;
|
|
182
|
+
}
|
|
183
|
+
if (options.json) {
|
|
184
|
+
console.log(JSON.stringify(constitution, null, 2));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
displayConstitutionDetails(constitution);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error(chalk_1.default.red('Error:'), error);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Evaluate files against constitution command
|
|
198
|
+
*/
|
|
199
|
+
function createConstitutionEvaluateCommand() {
|
|
200
|
+
return new commander_1.Command('evaluate')
|
|
201
|
+
.description('Evaluate file(s) against constitution with agent voting')
|
|
202
|
+
.argument('<files...>', 'File(s) to evaluate')
|
|
203
|
+
.option('--output <format>', 'Output format (human|json|agent)', 'human')
|
|
204
|
+
.option('--min-agents <n>', 'Minimum voting agents', parseInt, 3)
|
|
205
|
+
.option('--constitution <id>', 'Constitution ID or path', 'default')
|
|
206
|
+
.option('--timeout <ms>', 'Vote timeout in milliseconds', parseInt, 30000)
|
|
207
|
+
.action(async (files, options) => {
|
|
208
|
+
const spinner = (0, ora_1.default)('Evaluating files against constitution...').start();
|
|
209
|
+
try {
|
|
210
|
+
// Load constitution
|
|
211
|
+
const loader = (0, loader_1.getDefaultLoader)();
|
|
212
|
+
let constitution;
|
|
213
|
+
if (await fs.stat(options.constitution).catch(() => null)) {
|
|
214
|
+
constitution = loader.loadConstitution(options.constitution);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const constitutions = loader.loadConstitutions((0, loader_1.getBaseConstitutionsPath)());
|
|
218
|
+
const found = constitutions.get(options.constitution);
|
|
219
|
+
if (!found) {
|
|
220
|
+
spinner.fail('Constitution not found');
|
|
221
|
+
console.error(chalk_1.default.red(`Constitution not found: ${options.constitution}`));
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
constitution = found;
|
|
225
|
+
}
|
|
226
|
+
spinner.text = 'Assembling voting panel...';
|
|
227
|
+
// Create voting panel
|
|
228
|
+
const panelConfig = {
|
|
229
|
+
minPanelSize: options.minAgents,
|
|
230
|
+
maxPanelSize: Math.max(options.minAgents + 2, 5),
|
|
231
|
+
consensusMethod: 'weighted-average',
|
|
232
|
+
timeoutMs: options.timeout,
|
|
233
|
+
maxRetries: 2,
|
|
234
|
+
retryDelayMs: 1000,
|
|
235
|
+
parallelExecution: true
|
|
236
|
+
};
|
|
237
|
+
const pool = createAgentPool();
|
|
238
|
+
const strategy = createVotingStrategy();
|
|
239
|
+
const orchestrator = new orchestrator_1.VotingOrchestrator(pool, strategy, executeAgentVote);
|
|
240
|
+
const panelResult = await orchestrator.assemblePanel(panelConfig);
|
|
241
|
+
spinner.text = `Evaluating with ${panelResult.panel.length} agents...`;
|
|
242
|
+
// Evaluate each file
|
|
243
|
+
const findings = [];
|
|
244
|
+
const allVotes = [];
|
|
245
|
+
for (const filePath of files) {
|
|
246
|
+
const absolutePath = path.resolve(filePath);
|
|
247
|
+
const sourceCode = await fs.readFile(absolutePath, 'utf-8');
|
|
248
|
+
const language = getLanguageFromExtension(path.extname(absolutePath));
|
|
249
|
+
// Create evaluation context
|
|
250
|
+
const context = {
|
|
251
|
+
sourceCode,
|
|
252
|
+
filePath: absolutePath,
|
|
253
|
+
language,
|
|
254
|
+
data: {}
|
|
255
|
+
};
|
|
256
|
+
// Create voting task for this file
|
|
257
|
+
const task = {
|
|
258
|
+
id: `eval-${Date.now()}-${path.basename(absolutePath)}`,
|
|
259
|
+
type: 'constitution-evaluation',
|
|
260
|
+
description: `Evaluate ${path.basename(absolutePath)} against ${constitution.id}`,
|
|
261
|
+
context: {
|
|
262
|
+
constitution: constitution.id,
|
|
263
|
+
file: absolutePath,
|
|
264
|
+
rules: constitution.rules.length
|
|
265
|
+
},
|
|
266
|
+
priority: 'high'
|
|
267
|
+
};
|
|
268
|
+
// Distribute and collect votes
|
|
269
|
+
await orchestrator.distributeTask(task, panelResult.panel);
|
|
270
|
+
const votes = await orchestrator.collectVotes(task.id, options.timeout);
|
|
271
|
+
// Convert votes to agent votes
|
|
272
|
+
votes.forEach(vote => {
|
|
273
|
+
const agent = panelResult.panel.find(a => a.id === vote.agentId);
|
|
274
|
+
if (agent) {
|
|
275
|
+
allVotes.push({
|
|
276
|
+
agentId: vote.agentId,
|
|
277
|
+
agentType: agent.type,
|
|
278
|
+
score: vote.score,
|
|
279
|
+
confidence: vote.confidence,
|
|
280
|
+
reasoning: vote.reasoning,
|
|
281
|
+
timestamp: vote.timestamp.toISOString()
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
// Evaluate rules with evaluators
|
|
286
|
+
const evaluators = getEvaluators();
|
|
287
|
+
for (const rule of constitution.rules) {
|
|
288
|
+
if (rule.enabled === false)
|
|
289
|
+
continue;
|
|
290
|
+
const evaluator = findEvaluatorForCondition(evaluators, rule.condition);
|
|
291
|
+
if (!evaluator) {
|
|
292
|
+
findings.push({
|
|
293
|
+
file: absolutePath,
|
|
294
|
+
rule: rule.id,
|
|
295
|
+
severity: 'warning',
|
|
296
|
+
message: `No evaluator available for rule ${rule.id}`,
|
|
297
|
+
passed: true
|
|
298
|
+
});
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const checkResult = await evaluator.evaluate(rule.condition, context);
|
|
302
|
+
findings.push({
|
|
303
|
+
file: absolutePath,
|
|
304
|
+
rule: rule.id,
|
|
305
|
+
severity: rule.severity,
|
|
306
|
+
message: checkResult.message || rule.action.message,
|
|
307
|
+
passed: checkResult.passed,
|
|
308
|
+
actualValue: checkResult.actualValue,
|
|
309
|
+
remediation: rule.remediation
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
spinner.stop();
|
|
314
|
+
// Generate output
|
|
315
|
+
const output = {
|
|
316
|
+
summary: {
|
|
317
|
+
verdict: determineVerdict(findings),
|
|
318
|
+
constitutionId: constitution.id,
|
|
319
|
+
filesEvaluated: files.length,
|
|
320
|
+
totalRules: constitution.rules.filter(r => r.enabled !== false).length,
|
|
321
|
+
passedRules: findings.filter(f => f.passed).length,
|
|
322
|
+
failedRules: findings.filter(f => !f.passed && f.severity === 'error').length,
|
|
323
|
+
warnings: findings.filter(f => !f.passed && f.severity === 'warning').length
|
|
324
|
+
},
|
|
325
|
+
findings,
|
|
326
|
+
agentVotes: allVotes,
|
|
327
|
+
nextSteps: generateNextSteps(findings)
|
|
328
|
+
};
|
|
329
|
+
// Display output
|
|
330
|
+
const format = options.output;
|
|
331
|
+
displayEvaluationOutput(output, format);
|
|
332
|
+
// Exit with appropriate code
|
|
333
|
+
process.exit(output.summary.verdict === 'fail' ? 1 : 0);
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
spinner.fail('Evaluation failed');
|
|
337
|
+
console.error(chalk_1.default.red('Error:'), error);
|
|
338
|
+
process.exit(1);
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Display validation results
|
|
344
|
+
*/
|
|
345
|
+
function displayValidationResults(results) {
|
|
346
|
+
console.log(chalk_1.default.bold('\n📋 Constitution Validation Results\n'));
|
|
347
|
+
for (const { path: filePath, result, constitution } of results) {
|
|
348
|
+
const fileName = path.basename(filePath);
|
|
349
|
+
if (result.valid) {
|
|
350
|
+
console.log(chalk_1.default.green(`✓ ${fileName}`));
|
|
351
|
+
if (constitution) {
|
|
352
|
+
console.log(chalk_1.default.gray(` ${constitution.name} v${constitution.version}`));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
console.log(chalk_1.default.red(`✗ ${fileName}`));
|
|
357
|
+
if (result.errors.length > 0) {
|
|
358
|
+
console.log(chalk_1.default.red('\n Errors:'));
|
|
359
|
+
result.errors.forEach(err => {
|
|
360
|
+
console.log(chalk_1.default.red(` • ${err.path}: ${err.message}`));
|
|
361
|
+
if (err.expected) {
|
|
362
|
+
console.log(chalk_1.default.gray(` Expected: ${err.expected}`));
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (result.warnings.length > 0) {
|
|
368
|
+
console.log(chalk_1.default.yellow('\n Warnings:'));
|
|
369
|
+
result.warnings.forEach(warn => {
|
|
370
|
+
console.log(chalk_1.default.yellow(` • ${warn.path}: ${warn.message}`));
|
|
371
|
+
if (warn.suggestion) {
|
|
372
|
+
console.log(chalk_1.default.gray(` Suggestion: ${warn.suggestion}`));
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
console.log('');
|
|
377
|
+
}
|
|
378
|
+
const totalValid = results.filter(r => r.result.valid).length;
|
|
379
|
+
const totalInvalid = results.filter(r => !r.result.valid).length;
|
|
380
|
+
console.log(chalk_1.default.bold('Summary:'));
|
|
381
|
+
console.log(` Valid: ${chalk_1.default.green(totalValid)}`);
|
|
382
|
+
console.log(` Invalid: ${chalk_1.default.red(totalInvalid)}`);
|
|
383
|
+
console.log(` Total: ${results.length}\n`);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Display constitution list
|
|
387
|
+
*/
|
|
388
|
+
function displayConstitutionList(constitutions, detailed) {
|
|
389
|
+
console.log(chalk_1.default.bold(`\n📚 Available Constitutions (${constitutions.size})\n`));
|
|
390
|
+
for (const [id, constitution] of constitutions) {
|
|
391
|
+
console.log(chalk_1.default.cyan(`${id}`) + chalk_1.default.gray(` (v${constitution.version})`));
|
|
392
|
+
console.log(` ${constitution.name}`);
|
|
393
|
+
console.log(chalk_1.default.gray(` ${constitution.description}`));
|
|
394
|
+
if (detailed) {
|
|
395
|
+
console.log(chalk_1.default.gray(` Status: ${constitution.metadata.status}`));
|
|
396
|
+
console.log(chalk_1.default.gray(` Principles: ${constitution.principles.length}`));
|
|
397
|
+
console.log(chalk_1.default.gray(` Rules: ${constitution.rules.length}`));
|
|
398
|
+
console.log(chalk_1.default.gray(` Metrics: ${constitution.metrics.length}`));
|
|
399
|
+
console.log(chalk_1.default.gray(` Applicable to: ${constitution.metadata.applicableTo.join(', ')}`));
|
|
400
|
+
}
|
|
401
|
+
console.log('');
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Display constitution details
|
|
406
|
+
*/
|
|
407
|
+
function displayConstitutionDetails(constitution) {
|
|
408
|
+
console.log(chalk_1.default.bold(`\n📜 ${constitution.name}\n`));
|
|
409
|
+
console.log(`ID: ${chalk_1.default.cyan(constitution.id)}`);
|
|
410
|
+
console.log(`Version: ${chalk_1.default.cyan(constitution.version)}`);
|
|
411
|
+
console.log(`Status: ${chalk_1.default.cyan(constitution.metadata.status)}`);
|
|
412
|
+
console.log(`Description: ${constitution.description}`);
|
|
413
|
+
console.log('');
|
|
414
|
+
console.log(chalk_1.default.bold('Principles:'));
|
|
415
|
+
constitution.principles.forEach(p => {
|
|
416
|
+
const priorityColor = p.priority === 'critical' ? chalk_1.default.red :
|
|
417
|
+
p.priority === 'high' ? chalk_1.default.yellow : chalk_1.default.gray;
|
|
418
|
+
console.log(` ${priorityColor(p.priority.toUpperCase())} ${p.name}`);
|
|
419
|
+
console.log(chalk_1.default.gray(` ${p.description}`));
|
|
420
|
+
});
|
|
421
|
+
console.log('');
|
|
422
|
+
console.log(chalk_1.default.bold('Rules:'));
|
|
423
|
+
console.log(` Total: ${constitution.rules.length}`);
|
|
424
|
+
console.log(` Enabled: ${constitution.rules.filter(r => r.enabled !== false).length}`);
|
|
425
|
+
console.log(` By severity:`);
|
|
426
|
+
console.log(` Error: ${constitution.rules.filter(r => r.severity === 'error').length}`);
|
|
427
|
+
console.log(` Warning: ${constitution.rules.filter(r => r.severity === 'warning').length}`);
|
|
428
|
+
console.log(` Info: ${constitution.rules.filter(r => r.severity === 'info').length}`);
|
|
429
|
+
console.log('');
|
|
430
|
+
console.log(chalk_1.default.bold('Metrics:'));
|
|
431
|
+
constitution.metrics.forEach(m => {
|
|
432
|
+
console.log(` ${m.name} (${m.unit})`);
|
|
433
|
+
if (m.targetValue !== undefined) {
|
|
434
|
+
console.log(chalk_1.default.gray(` Target: ${m.targetValue}`));
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
console.log('');
|
|
438
|
+
console.log(chalk_1.default.bold('Metadata:'));
|
|
439
|
+
console.log(` Author: ${constitution.metadata.author}`);
|
|
440
|
+
console.log(` Created: ${constitution.metadata.createdAt}`);
|
|
441
|
+
console.log(` Updated: ${constitution.metadata.updatedAt}`);
|
|
442
|
+
console.log(` Applicable to: ${constitution.metadata.applicableTo.join(', ')}`);
|
|
443
|
+
console.log('');
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Display evaluation output
|
|
447
|
+
*/
|
|
448
|
+
function displayEvaluationOutput(output, format) {
|
|
449
|
+
if (format === 'json') {
|
|
450
|
+
console.log(JSON.stringify(output, null, 2));
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (format === 'agent') {
|
|
454
|
+
// Machine-readable format for agent consumption
|
|
455
|
+
console.log(JSON.stringify({
|
|
456
|
+
verdict: output.summary.verdict,
|
|
457
|
+
constitution: output.summary.constitutionId,
|
|
458
|
+
passed: output.summary.passedRules,
|
|
459
|
+
failed: output.summary.failedRules,
|
|
460
|
+
warnings: output.summary.warnings,
|
|
461
|
+
nextSteps: output.nextSteps || [],
|
|
462
|
+
votes: output.agentVotes.map(v => ({
|
|
463
|
+
agent: v.agentId,
|
|
464
|
+
score: v.score,
|
|
465
|
+
confidence: v.confidence
|
|
466
|
+
}))
|
|
467
|
+
}));
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
// Human-readable format
|
|
471
|
+
console.log(chalk_1.default.bold('\n🔍 Constitution Evaluation Results\n'));
|
|
472
|
+
// Summary
|
|
473
|
+
const verdictColor = output.summary.verdict === 'pass' ? chalk_1.default.green :
|
|
474
|
+
output.summary.verdict === 'fail' ? chalk_1.default.red : chalk_1.default.yellow;
|
|
475
|
+
console.log(chalk_1.default.bold('Verdict: ') + verdictColor(output.summary.verdict.toUpperCase()));
|
|
476
|
+
console.log(`Constitution: ${chalk_1.default.cyan(output.summary.constitutionId)}`);
|
|
477
|
+
console.log(`Files Evaluated: ${output.summary.filesEvaluated}`);
|
|
478
|
+
console.log(`Rules: ${chalk_1.default.green(output.summary.passedRules)} passed, ${chalk_1.default.red(output.summary.failedRules)} failed, ${chalk_1.default.yellow(output.summary.warnings)} warnings`);
|
|
479
|
+
console.log('');
|
|
480
|
+
// Findings
|
|
481
|
+
if (output.findings.length > 0) {
|
|
482
|
+
const errors = output.findings.filter(f => !f.passed && f.severity === 'error');
|
|
483
|
+
const warnings = output.findings.filter(f => !f.passed && f.severity === 'warning');
|
|
484
|
+
if (errors.length > 0) {
|
|
485
|
+
console.log(chalk_1.default.red.bold('Errors:'));
|
|
486
|
+
errors.forEach(f => {
|
|
487
|
+
console.log(chalk_1.default.red(` ✗ ${f.rule}: ${f.message}`));
|
|
488
|
+
console.log(chalk_1.default.gray(` File: ${f.file}`));
|
|
489
|
+
if (f.actualValue !== undefined) {
|
|
490
|
+
console.log(chalk_1.default.gray(` Actual: ${JSON.stringify(f.actualValue)}`));
|
|
491
|
+
}
|
|
492
|
+
if (f.remediation) {
|
|
493
|
+
console.log(chalk_1.default.gray(` Fix: ${f.remediation}`));
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
console.log('');
|
|
497
|
+
}
|
|
498
|
+
if (warnings.length > 0) {
|
|
499
|
+
console.log(chalk_1.default.yellow.bold('Warnings:'));
|
|
500
|
+
warnings.forEach(f => {
|
|
501
|
+
console.log(chalk_1.default.yellow(` ⚠ ${f.rule}: ${f.message}`));
|
|
502
|
+
console.log(chalk_1.default.gray(` File: ${f.file}`));
|
|
503
|
+
});
|
|
504
|
+
console.log('');
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
// Agent votes
|
|
508
|
+
if (output.agentVotes.length > 0) {
|
|
509
|
+
console.log(chalk_1.default.bold('Agent Votes:'));
|
|
510
|
+
output.agentVotes.forEach(v => {
|
|
511
|
+
const scoreColor = v.score >= 0.7 ? chalk_1.default.green :
|
|
512
|
+
v.score >= 0.4 ? chalk_1.default.yellow : chalk_1.default.red;
|
|
513
|
+
console.log(` ${v.agentId} (${v.agentType}): ${scoreColor(v.score.toFixed(2))} confidence ${v.confidence.toFixed(2)}`);
|
|
514
|
+
console.log(chalk_1.default.gray(` ${v.reasoning}`));
|
|
515
|
+
});
|
|
516
|
+
console.log('');
|
|
517
|
+
}
|
|
518
|
+
// Next steps
|
|
519
|
+
if (output.nextSteps && output.nextSteps.length > 0) {
|
|
520
|
+
console.log(chalk_1.default.bold('Next Steps:'));
|
|
521
|
+
output.nextSteps.forEach((step, i) => {
|
|
522
|
+
console.log(` ${i + 1}. ${step}`);
|
|
523
|
+
});
|
|
524
|
+
console.log('');
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Helper functions
|
|
529
|
+
*/
|
|
530
|
+
function getEvaluators() {
|
|
531
|
+
const types = base_1.EvaluatorFactory.getTypes();
|
|
532
|
+
return types.map(type => base_1.EvaluatorFactory.create(type)).filter((e) => e !== null);
|
|
533
|
+
}
|
|
534
|
+
function findEvaluatorForCondition(evaluators, condition) {
|
|
535
|
+
return evaluators.find(e => e.canHandle(condition)) || null;
|
|
536
|
+
}
|
|
537
|
+
function getLanguageFromExtension(ext) {
|
|
538
|
+
const map = {
|
|
539
|
+
'.ts': 'typescript',
|
|
540
|
+
'.tsx': 'typescript',
|
|
541
|
+
'.js': 'javascript',
|
|
542
|
+
'.jsx': 'javascript',
|
|
543
|
+
'.py': 'python',
|
|
544
|
+
'.java': 'java',
|
|
545
|
+
'.go': 'go',
|
|
546
|
+
'.rs': 'rust',
|
|
547
|
+
'.rb': 'ruby'
|
|
548
|
+
};
|
|
549
|
+
return map[ext] || 'unknown';
|
|
550
|
+
}
|
|
551
|
+
function determineVerdict(findings) {
|
|
552
|
+
const hasErrors = findings.some(f => !f.passed && f.severity === 'error');
|
|
553
|
+
const hasWarnings = findings.some(f => !f.passed && f.severity === 'warning');
|
|
554
|
+
if (hasErrors)
|
|
555
|
+
return 'fail';
|
|
556
|
+
if (hasWarnings)
|
|
557
|
+
return 'warning';
|
|
558
|
+
return 'pass';
|
|
559
|
+
}
|
|
560
|
+
function generateNextSteps(findings) {
|
|
561
|
+
const steps = [];
|
|
562
|
+
const errors = findings.filter(f => !f.passed && f.severity === 'error');
|
|
563
|
+
const warnings = findings.filter(f => !f.passed && f.severity === 'warning');
|
|
564
|
+
if (errors.length > 0) {
|
|
565
|
+
steps.push(`Fix ${errors.length} critical error${errors.length > 1 ? 's' : ''}`);
|
|
566
|
+
errors.forEach(e => {
|
|
567
|
+
if (e.remediation) {
|
|
568
|
+
steps.push(` - ${e.rule}: ${e.remediation}`);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
if (warnings.length > 0) {
|
|
573
|
+
steps.push(`Address ${warnings.length} warning${warnings.length > 1 ? 's' : ''} to improve quality`);
|
|
574
|
+
}
|
|
575
|
+
if (errors.length === 0 && warnings.length === 0) {
|
|
576
|
+
steps.push('All checks passed - ready for next stage');
|
|
577
|
+
}
|
|
578
|
+
return steps;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Create agent pool for voting
|
|
582
|
+
*/
|
|
583
|
+
function createAgentPool() {
|
|
584
|
+
const agents = [
|
|
585
|
+
{ id: 'test-gen-1', type: 'test-generator', expertise: ['unit-testing', 'integration'], weight: 1.0 },
|
|
586
|
+
{ id: 'coverage-1', type: 'coverage-analyzer', expertise: ['code-coverage', 'gap-analysis'], weight: 1.2 },
|
|
587
|
+
{ id: 'quality-gate-1', type: 'quality-gate', expertise: ['quality-metrics', 'thresholds'], weight: 1.5 },
|
|
588
|
+
{ id: 'security-1', type: 'security-scanner', expertise: ['security', 'vulnerabilities'], weight: 1.3 },
|
|
589
|
+
{ id: 'performance-1', type: 'performance-tester', expertise: ['performance', 'benchmarks'], weight: 1.1 }
|
|
590
|
+
];
|
|
591
|
+
const pool = {
|
|
592
|
+
available: [...agents],
|
|
593
|
+
busy: new Map(),
|
|
594
|
+
failed: new Set(),
|
|
595
|
+
getAvailable(expertise) {
|
|
596
|
+
return this.available.filter(a => {
|
|
597
|
+
if (this.busy.has(a.id) || this.failed.has(a.id))
|
|
598
|
+
return false;
|
|
599
|
+
if (!expertise || expertise.length === 0)
|
|
600
|
+
return true;
|
|
601
|
+
return expertise.some(e => a.expertise.includes(e));
|
|
602
|
+
});
|
|
603
|
+
},
|
|
604
|
+
reserve(agentId, task) {
|
|
605
|
+
this.busy.set(agentId, task);
|
|
606
|
+
},
|
|
607
|
+
release(agentId) {
|
|
608
|
+
this.busy.delete(agentId);
|
|
609
|
+
},
|
|
610
|
+
markFailed(agentId) {
|
|
611
|
+
this.failed.add(agentId);
|
|
612
|
+
this.busy.delete(agentId);
|
|
613
|
+
},
|
|
614
|
+
restore(agentId) {
|
|
615
|
+
this.failed.delete(agentId);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
return pool;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Create voting strategy
|
|
622
|
+
*/
|
|
623
|
+
function createVotingStrategy() {
|
|
624
|
+
return {
|
|
625
|
+
selectAgents(pool, task, config) {
|
|
626
|
+
const available = pool.getAvailable(task.requiredExpertise);
|
|
627
|
+
const selected = available.slice(0, config.maxPanelSize);
|
|
628
|
+
return selected;
|
|
629
|
+
},
|
|
630
|
+
calculateWeight(agent, task) {
|
|
631
|
+
// Calculate weight based on expertise match
|
|
632
|
+
const expertiseMatch = task.requiredExpertise
|
|
633
|
+
? task.requiredExpertise.filter(e => agent.expertise.includes(e)).length / task.requiredExpertise.length
|
|
634
|
+
: 1.0;
|
|
635
|
+
return agent.weight * (0.5 + expertiseMatch * 0.5);
|
|
636
|
+
},
|
|
637
|
+
shouldRetry(agent, task, attempt, error) {
|
|
638
|
+
return attempt <= 2; // Max 2 retries
|
|
639
|
+
},
|
|
640
|
+
adjustTimeout(baseTimeout, attempt, systemLoad) {
|
|
641
|
+
return baseTimeout * (1 + attempt * 0.5) * (1 + systemLoad * 0.3);
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Execute agent vote (mock implementation for CLI)
|
|
647
|
+
*/
|
|
648
|
+
async function executeAgentVote(agent, task) {
|
|
649
|
+
// Simulate agent evaluation
|
|
650
|
+
await new Promise(resolve => setTimeout(resolve, 100 + Math.random() * 500));
|
|
651
|
+
// Generate score based on agent expertise match
|
|
652
|
+
const expertiseMatch = task.requiredExpertise
|
|
653
|
+
? task.requiredExpertise.filter(e => agent.expertise.includes(e)).length / task.requiredExpertise.length
|
|
654
|
+
: 1.0;
|
|
655
|
+
const score = 0.5 + (expertiseMatch * 0.3) + (Math.random() * 0.2);
|
|
656
|
+
const confidence = 0.7 + (Math.random() * 0.3);
|
|
657
|
+
return {
|
|
658
|
+
agentId: agent.id,
|
|
659
|
+
taskId: task.id,
|
|
660
|
+
score: Math.min(1.0, score),
|
|
661
|
+
confidence: Math.min(1.0, confidence),
|
|
662
|
+
reasoning: `Evaluated based on ${agent.expertise.join(', ')} expertise`,
|
|
663
|
+
timestamp: new Date(),
|
|
664
|
+
metadata: { agentType: agent.type, weight: agent.weight }
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Create main constitution command
|
|
669
|
+
*/
|
|
670
|
+
function createConstitutionCommand() {
|
|
671
|
+
const command = new commander_1.Command('constitution')
|
|
672
|
+
.description('Manage and evaluate quality constitutions');
|
|
673
|
+
command.addCommand(createConstitutionValidateCommand());
|
|
674
|
+
command.addCommand(createConstitutionListCommand());
|
|
675
|
+
command.addCommand(createConstitutionShowCommand());
|
|
676
|
+
command.addCommand(createConstitutionEvaluateCommand());
|
|
677
|
+
return command;
|
|
678
|
+
}
|
|
679
|
+
//# sourceMappingURL=constitution.js.map
|