codehere 0.2.2 → 0.3.0-rc.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/README.md +88 -68
- package/dist/domain/entities/task.js +4 -4
- package/dist/error-handler.js +4 -9
- package/dist/index.js +253 -1219
- package/dist/infrastructure/config/product-context.js +7 -6
- package/dist/infrastructure/hooks/claude-sdk-hook.js +335 -63
- package/dist/infrastructure/observability/execution-tracer.js +11 -6
- package/dist/infrastructure/orchestration/agent-adapter.js +13 -0
- package/dist/infrastructure/orchestration/agent-installer.js +101 -0
- package/dist/infrastructure/orchestration/agents-config-seed.js +56 -0
- package/dist/infrastructure/orchestration/aider-adapter.js +319 -0
- package/dist/infrastructure/orchestration/artifacts-extractor.js +175 -0
- package/dist/infrastructure/orchestration/claude-code-adapter.js +352 -0
- package/dist/infrastructure/orchestration/codex-adapter.js +310 -0
- package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
- package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
- package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
- package/dist/infrastructure/orchestration/readiness.js +106 -0
- package/dist/infrastructure/orchestration/session-manager.js +272 -0
- package/dist/infrastructure/orchestration/session-persistence.js +109 -0
- package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
- package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
- package/dist/infrastructure/protocols/ui-page.js +1827 -0
- package/dist/infrastructure/security/file-collection.js +115 -0
- package/dist/infrastructure/security/trust-scorer.js +301 -56
- package/dist/infrastructure/storage/task-repository.js +8 -7
- package/dist/monitoring.js +9 -38
- package/dist/presentation/cli/commands/help-command.js +96 -139
- package/dist/presentation/cli/commands/hook-command.js +17 -24
- package/dist/presentation/cli/commands/report-command.js +59 -72
- package/dist/presentation/cli/commands/setup-command.js +4 -4
- package/dist/presentation/cli/commands/status-command.js +321 -30
- package/dist/presentation/cli/commands/trust-command.js +84 -72
- package/dist/presentation/cli/error-display.js +17 -21
- package/dist/ui.js +11 -11
- package/package.json +24 -62
- package/dist/agents/base.js +0 -101
- package/dist/agents/orchestrator-model-driven.js +0 -141
- package/dist/agents/react-orchestrator-agent.js +0 -54
- package/dist/application/agents/execution-agent.js +0 -508
- package/dist/application/agents/multi-agent-orchestrator.js +0 -295
- package/dist/application/agents/planning-agent.js +0 -433
- package/dist/application/agents/validation-agent.js +0 -317
- package/dist/application/architectures/plan-and-act.js +0 -242
- package/dist/application/index.js +0 -12
- package/dist/application/services/agent-factory.js +0 -28
- package/dist/application/services/dependency-container.js +0 -596
- package/dist/application/services/git-context-service.js +0 -83
- package/dist/application/services/intelligent-router.js +0 -934
- package/dist/application/services/tool-executor-service.js +0 -94
- package/dist/application/use-cases/ask-question-use-case.js +0 -338
- package/dist/application/use-cases/edit-file-use-case.js +0 -830
- package/dist/application/use-cases/explain-file-use-case.js +0 -50
- package/dist/application/use-cases/index-codebase-use-case.js +0 -113
- package/dist/application/use-cases/planning-use-case.js +0 -276
- package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
- package/dist/application/use-cases/reflexion-use-case.js +0 -30
- package/dist/application/workflows/deterministic-workflows.js +0 -189
- package/dist/ast-parser.js +0 -331
- package/dist/cache.js +0 -180
- package/dist/chat.js +0 -251
- package/dist/code-analysis.js +0 -327
- package/dist/context.js +0 -187
- package/dist/docs.js +0 -146
- package/dist/domain/entities/code-chunk.js +0 -6
- package/dist/domain/entities/decision.js +0 -9
- package/dist/domain/entities/edit.js +0 -6
- package/dist/domain/entities/knowledge-node.js +0 -9
- package/dist/domain/entities/knowledge-preservation.js +0 -10
- package/dist/domain/entities/memory.js +0 -6
- package/dist/domain/entities/pattern.js +0 -7
- package/dist/domain/entities/plan.js +0 -6
- package/dist/domain/entities/query.js +0 -6
- package/dist/domain/errors/embeddings-not-found-error.js +0 -13
- package/dist/domain/index.js +0 -19
- package/dist/domain/interfaces/ai-service.interface.js +0 -6
- package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
- package/dist/domain/interfaces/decision-repository.interface.js +0 -9
- package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
- package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
- package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
- package/dist/domain/interfaces/memory-repository.interface.js +0 -6
- package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
- package/dist/domain/interfaces/verification-service.interface.js +0 -6
- package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
- package/dist/domain/services/decision-recorder.js +0 -223
- package/dist/domain/services/decision-retriever.js +0 -133
- package/dist/domain/services/environment-mode-manager.js +0 -22
- package/dist/domain/services/graded-memory-activation.js +0 -69
- package/dist/domain/services/knowledge-access.js +0 -132
- package/dist/domain/services/knowledge-extractor.js +0 -247
- package/dist/domain/services/knowledge-graph-builder.js +0 -268
- package/dist/domain/services/knowledge-graph-query.js +0 -187
- package/dist/domain/services/memory-retriever.js +0 -82
- package/dist/domain/services/memory-synthesizer.js +0 -91
- package/dist/domain/services/pattern-extractor.js +0 -442
- package/dist/domain/services/query-intent-classifier.js +0 -140
- package/dist/domain/services/react-loop.js +0 -186
- package/dist/domain/services/risk-tier-detector.js +0 -78
- package/dist/edit.js +0 -319
- package/dist/embed.js +0 -459
- package/dist/formatter.js +0 -168
- package/dist/git.js +0 -198
- package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
- package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
- package/dist/infrastructure/ai/model-config.js +0 -84
- package/dist/infrastructure/ai/provider-ai-service.js +0 -477
- package/dist/infrastructure/cache/embedding-cache.js +0 -175
- package/dist/infrastructure/cache/query-result-cache.js +0 -66
- package/dist/infrastructure/cache/response-cache.js +0 -48
- package/dist/infrastructure/cache/security-scan-cache.js +0 -47
- package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
- package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
- package/dist/infrastructure/context/context-compressor.js +0 -329
- package/dist/infrastructure/context/conversation-context.js +0 -128
- package/dist/infrastructure/context/session-manager.js +0 -94
- package/dist/infrastructure/cost/cost-tracker.js +0 -360
- package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
- package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
- package/dist/infrastructure/governance/policy-as-code.js +0 -258
- package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
- package/dist/infrastructure/index.js +0 -7
- package/dist/infrastructure/observability/prompt-versioner.js +0 -145
- package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
- package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
- package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
- package/dist/infrastructure/protocols/mcp-server.js +0 -333
- package/dist/infrastructure/protocols/streaming-handler.js +0 -103
- package/dist/infrastructure/providers/cohere-provider.js +0 -444
- package/dist/infrastructure/providers/fake-provider.js +0 -130
- package/dist/infrastructure/providers/local-llm-provider.js +0 -330
- package/dist/infrastructure/providers/model-config.types.js +0 -9
- package/dist/infrastructure/providers/model-provider.interface.js +0 -8
- package/dist/infrastructure/providers/openai-provider.js +0 -413
- package/dist/infrastructure/providers/openrouter-provider.js +0 -399
- package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
- package/dist/infrastructure/providers/provider-config-loader.js +0 -120
- package/dist/infrastructure/providers/provider-registry.js +0 -88
- package/dist/infrastructure/safety/pattern-detector.js +0 -133
- package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
- package/dist/infrastructure/security/docker-sandbox.js +0 -178
- package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
- package/dist/infrastructure/security/license-scanner.js +0 -167
- package/dist/infrastructure/security/provider-bias-detector.js +0 -164
- package/dist/infrastructure/security/sandbox-executor.js +0 -64
- package/dist/infrastructure/serialization/toon-serializer.js +0 -119
- package/dist/infrastructure/storage/memory-stream-service.js +0 -204
- package/dist/infrastructure/storage/plan-repository.js +0 -96
- package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
- package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
- package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
- package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
- package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
- package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
- package/dist/infrastructure/storage/task-helpers.js +0 -197
- package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
- package/dist/infrastructure/ux/appropriate-friction.js +0 -213
- package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
- package/dist/infrastructure/ux/capability-boundaries.js +0 -42
- package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
- package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
- package/dist/infrastructure/ux/expectation-management.js +0 -327
- package/dist/infrastructure/ux/feature-discovery.js +0 -14
- package/dist/infrastructure/ux/feedback-prompt.js +0 -45
- package/dist/infrastructure/ux/hitl-validation.js +0 -297
- package/dist/infrastructure/ux/progress-indicator.js +0 -116
- package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
- package/dist/infrastructure/ux/review-checkpoint.js +0 -72
- package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
- package/dist/infrastructure/ux/stream-markdown.js +0 -151
- package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
- package/dist/infrastructure/ux/team-standards.js +0 -196
- package/dist/infrastructure/ux/transparency.js +0 -71
- package/dist/infrastructure/validation/agent-feedback.js +0 -55
- package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
- package/dist/infrastructure/validation/review-handler.js +0 -40
- package/dist/infrastructure/validation/summary-aggregator.js +0 -70
- package/dist/infrastructure/validation/summary-extractor.js +0 -45
- package/dist/infrastructure/validation/trace-summary.js +0 -52
- package/dist/infrastructure/verification/verification-service.js +0 -47
- package/dist/infrastructure/xai/attention-visualizer.js +0 -172
- package/dist/infrastructure/xai/cot-visualizer.js +0 -283
- package/dist/infrastructure/xai/decision-tree-log.js +0 -212
- package/dist/infrastructure/xai/interactive-xai.js +0 -260
- package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
- package/dist/intelligent-retrieval.js +0 -272
- package/dist/intent/classifier.js +0 -2
- package/dist/intent/context.js +0 -2
- package/dist/iterative-refinement.js +0 -189
- package/dist/learning.js +0 -232
- package/dist/log.js +0 -31
- package/dist/migrate.js +0 -133
- package/dist/parallel-processor.js +0 -534
- package/dist/planner.js +0 -198
- package/dist/policy.js +0 -26
- package/dist/presentation/cli/commands/ask-command.js +0 -314
- package/dist/presentation/cli/commands/cost-command.js +0 -191
- package/dist/presentation/cli/commands/decision-command.js +0 -207
- package/dist/presentation/cli/commands/docs-command.js +0 -25
- package/dist/presentation/cli/commands/fix-command.js +0 -53
- package/dist/presentation/cli/commands/knowledge-command.js +0 -129
- package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
- package/dist/presentation/cli/commands/models-command.js +0 -194
- package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
- package/dist/presentation/cli/commands/plan-command.js +0 -246
- package/dist/presentation/cli/commands/product-command.js +0 -199
- package/dist/presentation/cli/commands/react-command.js +0 -181
- package/dist/presentation/cli/commands/review-command.js +0 -154
- package/dist/presentation/cli/commands/run-command.js +0 -188
- package/dist/presentation/cli/commands/smart-command.js +0 -395
- package/dist/presentation/cli/commands/suggest-command.js +0 -138
- package/dist/presentation/cli/commands/trace-command.js +0 -129
- package/dist/presentation/cli/commands/undo-command.js +0 -150
- package/dist/query-optimizer.js +0 -205
- package/dist/refactor.js +0 -116
- package/dist/review.js +0 -206
- package/dist/search.js +0 -163
- package/dist/session.js +0 -704
- package/dist/task-verification.js +0 -336
- package/dist/testgen.js +0 -166
- package/dist/token-optimizer.js +0 -277
- package/dist/tools/bash.js +0 -213
- package/dist/tools/edit.js +0 -235
- package/dist/tools/executor.js +0 -153
- package/dist/tools/git-tool.js +0 -292
- package/dist/tools/parser.js +0 -158
- package/dist/tools/registry.js +0 -302
- package/dist/tools/search.js +0 -100
- package/dist/types.js +0 -2
- package/dist/utils/check-api-status.js +0 -100
- package/dist/utils/diff-parser.js +0 -162
- package/dist/verification/backup.js +0 -259
- package/dist/verification/compiler.js +0 -264
- package/dist/verification/index.js +0 -273
- package/dist/verification/test-runner.js +0 -379
|
@@ -18,40 +18,27 @@
|
|
|
18
18
|
* codehere trust --diff HEAD # equivalent using git directly
|
|
19
19
|
* codehere trust --badge # output badge markdown
|
|
20
20
|
*/
|
|
21
|
-
import {
|
|
22
|
-
import { join,
|
|
23
|
-
import {
|
|
21
|
+
import { existsSync } from 'fs';
|
|
22
|
+
import { join, relative, isAbsolute } from 'path';
|
|
23
|
+
import { execFileSync } from 'child_process';
|
|
24
24
|
import { scoreFile } from '../../../infrastructure/security/trust-scorer.js';
|
|
25
|
+
import { collectCodeFiles } from '../../../infrastructure/security/file-collection.js';
|
|
25
26
|
import { colors, sectionHeader, error, newline, info, randomCleanScan } from '../../../ui.js';
|
|
26
27
|
import { loadProductContext, adjustRecommendation } from '../../../infrastructure/config/product-context.js';
|
|
27
28
|
// ── File collection ──────────────────────────────────────────────────────────
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
function walk(dir) {
|
|
41
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
42
|
-
if (IGNORE_DIRS.has(entry.name))
|
|
43
|
-
continue;
|
|
44
|
-
const full = join(dir, entry.name);
|
|
45
|
-
if (entry.isDirectory()) {
|
|
46
|
-
walk(full);
|
|
47
|
-
}
|
|
48
|
-
else if (CODE_EXTENSIONS.has(extname(entry.name))) {
|
|
49
|
-
files.push(full);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
29
|
+
// See src/infrastructure/security/file-collection.ts for exclusion rules.
|
|
30
|
+
/**
|
|
31
|
+
* Read a file safely — handles iCloud-evicted files on macOS.
|
|
32
|
+
* readFileSync blocks forever on iCloud-evicted files (dehydrated placeholders in ~/Documents).
|
|
33
|
+
* We use cat with a timeout as a subprocess so the main thread never blocks.
|
|
34
|
+
*/
|
|
35
|
+
function safeReadFile(filepath) {
|
|
36
|
+
try {
|
|
37
|
+
return execFileSync('cat', [filepath], { encoding: 'utf-8', timeout: 2000, maxBuffer: 5 * 1024 * 1024 });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null; // File unreadable (iCloud-evicted, permissions, too large) — skip silently
|
|
52
41
|
}
|
|
53
|
-
walk(target);
|
|
54
|
-
return files;
|
|
55
42
|
}
|
|
56
43
|
// ── Git diff mode ────────────────────────────────────────────────────────────
|
|
57
44
|
function parseDiffFiles(diff) {
|
|
@@ -68,8 +55,8 @@ function parseDiffFiles(diff) {
|
|
|
68
55
|
// Extract added lines only (lines starting with +, excluding +++)
|
|
69
56
|
const addedLines = block
|
|
70
57
|
.split('\n')
|
|
71
|
-
.filter(l => l.startsWith('+') && !l.startsWith('+++'))
|
|
72
|
-
.map(l => l.substring(1))
|
|
58
|
+
.filter((l) => l.startsWith('+') && !l.startsWith('+++'))
|
|
59
|
+
.map((l) => l.substring(1))
|
|
73
60
|
.join('\n');
|
|
74
61
|
if (addedLines.trim()) {
|
|
75
62
|
files.push({ filepath, code: addedLines });
|
|
@@ -80,12 +67,18 @@ function parseDiffFiles(diff) {
|
|
|
80
67
|
// ── Report formatting ────────────────────────────────────────────────────────
|
|
81
68
|
function gradeColor(grade) {
|
|
82
69
|
switch (grade) {
|
|
83
|
-
case 'A':
|
|
84
|
-
|
|
85
|
-
case '
|
|
86
|
-
|
|
87
|
-
case '
|
|
88
|
-
|
|
70
|
+
case 'A':
|
|
71
|
+
return colors.green(grade);
|
|
72
|
+
case 'B':
|
|
73
|
+
return colors.cyan(grade);
|
|
74
|
+
case 'C':
|
|
75
|
+
return colors.yellow(grade);
|
|
76
|
+
case 'D':
|
|
77
|
+
return colors.red(grade);
|
|
78
|
+
case 'F':
|
|
79
|
+
return colors.red(colors.bold(grade));
|
|
80
|
+
default:
|
|
81
|
+
return grade;
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
84
|
function scoreBar(score, width = 20) {
|
|
@@ -98,10 +91,14 @@ function scoreBar(score, width = 20) {
|
|
|
98
91
|
return colors.red(bar);
|
|
99
92
|
}
|
|
100
93
|
function badgeMarkdown(report) {
|
|
101
|
-
const color = report.grade === 'A'
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
94
|
+
const color = report.grade === 'A'
|
|
95
|
+
? 'brightgreen'
|
|
96
|
+
: report.grade === 'B'
|
|
97
|
+
? 'green'
|
|
98
|
+
: report.grade === 'C'
|
|
99
|
+
? 'yellow'
|
|
100
|
+
: report.grade === 'D'
|
|
101
|
+
? 'orange'
|
|
105
102
|
: 'red';
|
|
106
103
|
return ``;
|
|
107
104
|
}
|
|
@@ -113,8 +110,12 @@ export async function executeTrustCommand(target, options = {}) {
|
|
|
113
110
|
if (options.diff !== undefined) {
|
|
114
111
|
// Run git diff and scan added lines
|
|
115
112
|
try {
|
|
113
|
+
// THREAT-2 fix · ref comes from a user-supplied CLI flag. Using template-
|
|
114
|
+
// string interpolation with execSync allows shell metacharacters in `ref`
|
|
115
|
+
// (e.g. `--diff "main; rm -rf /"`) to escape the git invocation. Use the
|
|
116
|
+
// execFileSync array form so the shell is never invoked.
|
|
116
117
|
const ref = options.diff || 'HEAD';
|
|
117
|
-
const diffOutput =
|
|
118
|
+
const diffOutput = execFileSync('git', ['diff', ref], { cwd, encoding: 'utf-8' });
|
|
118
119
|
filesToScan = parseDiffFiles(diffOutput);
|
|
119
120
|
if (filesToScan.length === 0) {
|
|
120
121
|
console.log(info('No changed files to scan'));
|
|
@@ -151,30 +152,42 @@ export async function executeTrustCommand(target, options = {}) {
|
|
|
151
152
|
console.error(error(`Not found: ${resolved}`));
|
|
152
153
|
process.exit(1);
|
|
153
154
|
}
|
|
154
|
-
const paths =
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
code
|
|
158
|
-
|
|
155
|
+
const paths = collectCodeFiles(resolved);
|
|
156
|
+
let skippedCount = 0;
|
|
157
|
+
for (const p of paths) {
|
|
158
|
+
const code = safeReadFile(p);
|
|
159
|
+
if (code !== null) {
|
|
160
|
+
filesToScan.push({ filepath: relative(cwd, p), code });
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
skippedCount++;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (skippedCount > 0) {
|
|
167
|
+
console.log(colors.dim(` Skipped ${skippedCount} unreadable file${skippedCount > 1 ? 's' : ''}`));
|
|
168
|
+
}
|
|
169
|
+
if (filesToScan.length === 0 && skippedCount > 0) {
|
|
170
|
+
console.log(info('No readable files to scan.'));
|
|
171
|
+
console.log(colors.dim(' Check file permissions or availability and retry.'));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
159
174
|
}
|
|
160
175
|
// ── Scan ──────────────────────────────────────────────────────────────────
|
|
161
|
-
const results = filesToScan.map(f => scoreFile(f.filepath, f.code));
|
|
176
|
+
const results = filesToScan.map((f) => scoreFile(f.filepath, f.code));
|
|
162
177
|
const totalFindings = results.reduce((s, r) => s + r.findings.length, 0);
|
|
163
|
-
const criticalCount = results.reduce((s, r) => s + r.findings.filter(f => f.severity === 'critical').length, 0);
|
|
164
|
-
const highCount = results.reduce((s, r) => s + r.findings.filter(f => f.severity === 'high').length, 0);
|
|
165
|
-
const mediumCount = results.reduce((s, r) => s + r.findings.filter(f => f.severity === 'medium').length, 0);
|
|
166
|
-
const lowCount = results.reduce((s, r) => s + r.findings.filter(f => f.severity === 'low').length, 0);
|
|
167
|
-
const overallScore = results.length > 0
|
|
168
|
-
? Math.round(results.reduce((s, r) => s + r.score, 0) / results.length)
|
|
169
|
-
: 100;
|
|
178
|
+
const criticalCount = results.reduce((s, r) => s + r.findings.filter((f) => f.severity === 'critical').length, 0);
|
|
179
|
+
const highCount = results.reduce((s, r) => s + r.findings.filter((f) => f.severity === 'high').length, 0);
|
|
180
|
+
const mediumCount = results.reduce((s, r) => s + r.findings.filter((f) => f.severity === 'medium').length, 0);
|
|
181
|
+
const lowCount = results.reduce((s, r) => s + r.findings.filter((f) => f.severity === 'low').length, 0);
|
|
182
|
+
const overallScore = results.length > 0 ? Math.round(results.reduce((s, r) => s + r.score, 0) / results.length) : 100;
|
|
170
183
|
const grade = overallScore >= 90 ? 'A' : overallScore >= 75 ? 'B' : overallScore >= 60 ? 'C' : overallScore >= 40 ? 'D' : 'F';
|
|
171
184
|
const baseRecommendation = criticalCount > 0
|
|
172
185
|
? `${criticalCount} critical ${criticalCount === 1 ? 'issue' : 'issues'} — worth sorting before this merges.`
|
|
173
186
|
: highCount > 0
|
|
174
187
|
? `Nothing critical, but ${highCount} high-severity ${highCount === 1 ? 'pattern' : 'patterns'} worth a look.`
|
|
175
|
-
:
|
|
176
|
-
? '
|
|
177
|
-
: '
|
|
188
|
+
: mediumCount + lowCount > 0
|
|
189
|
+
? `${mediumCount + lowCount} low-priority ${mediumCount + lowCount === 1 ? 'finding' : 'findings'} — nothing blocking, but worth a pass.`
|
|
190
|
+
: 'Clean scan. Nothing blocking a merge.';
|
|
178
191
|
const productCtx = loadProductContext(process.cwd());
|
|
179
192
|
const recommendation = adjustRecommendation(baseRecommendation, criticalCount, highCount, overallScore, productCtx);
|
|
180
193
|
const report = {
|
|
@@ -244,8 +257,10 @@ export async function executeTrustCommand(target, options = {}) {
|
|
|
244
257
|
continue;
|
|
245
258
|
console.log(` ${colors.bold(r.filepath)}`);
|
|
246
259
|
for (const f of r.findings) {
|
|
247
|
-
const sev = f.severity === 'critical'
|
|
248
|
-
|
|
260
|
+
const sev = f.severity === 'critical'
|
|
261
|
+
? colors.red('crit')
|
|
262
|
+
: f.severity === 'high'
|
|
263
|
+
? colors.yellow('high')
|
|
249
264
|
: colors.dim(f.severity.slice(0, 4));
|
|
250
265
|
const ln = f.line ? colors.dim(`L${f.line}`) : '';
|
|
251
266
|
console.log(` ${sev} ${ln.padEnd(6)} ${f.description}`);
|
|
@@ -253,20 +268,17 @@ export async function executeTrustCommand(target, options = {}) {
|
|
|
253
268
|
}
|
|
254
269
|
newline();
|
|
255
270
|
}
|
|
256
|
-
else if (
|
|
271
|
+
else if (totalFindings > 0) {
|
|
257
272
|
console.log(colors.dim(' FINDINGS'));
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const sorted = allFindings.sort((a, b) => {
|
|
262
|
-
if (a.severity === 'critical' && b.severity !== 'critical')
|
|
263
|
-
return -1;
|
|
264
|
-
if (a.severity !== 'critical' && b.severity === 'critical')
|
|
265
|
-
return 1;
|
|
266
|
-
return 0;
|
|
267
|
-
});
|
|
273
|
+
const severityRank = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
274
|
+
const allFindings = results.flatMap((r) => r.findings.map((f) => ({ ...f, filepath: r.filepath })));
|
|
275
|
+
const sorted = allFindings.sort((a, b) => severityRank[a.severity] - severityRank[b.severity]);
|
|
268
276
|
for (const f of sorted.slice(0, 5)) {
|
|
269
|
-
const sev = f.severity === 'critical'
|
|
277
|
+
const sev = f.severity === 'critical'
|
|
278
|
+
? colors.red('crit')
|
|
279
|
+
: f.severity === 'high'
|
|
280
|
+
? colors.yellow('high')
|
|
281
|
+
: colors.dim(f.severity.slice(0, 4));
|
|
270
282
|
const ln = f.line ? `:${f.line}` : '';
|
|
271
283
|
console.log(` ${sev} ${f.filepath}${ln}`);
|
|
272
284
|
console.log(` ${colors.dim(f.description)}`);
|
|
@@ -63,11 +63,7 @@ function extractFilePath(errorMessage) {
|
|
|
63
63
|
*/
|
|
64
64
|
function extractLineNumber(errorMessage) {
|
|
65
65
|
// Patterns: "line 42", ":42", "at line 42"
|
|
66
|
-
const patterns = [
|
|
67
|
-
/(?:line|Line)\s+(\d+)/i,
|
|
68
|
-
/:(\d+):/,
|
|
69
|
-
/\((\d+)\)/,
|
|
70
|
-
];
|
|
66
|
+
const patterns = [/(?:line|Line)\s+(\d+)/i, /:(\d+):/, /\((\d+)\)/];
|
|
71
67
|
for (const pattern of patterns) {
|
|
72
68
|
const match = errorMessage.match(pattern);
|
|
73
69
|
if (match && match[1]) {
|
|
@@ -89,9 +85,8 @@ function getRecoveryCommands(errorType, errorMessage, context) {
|
|
|
89
85
|
case ErrorType.VALIDATION:
|
|
90
86
|
if (lowerMessage.includes('file') || lowerMessage.includes('not found')) {
|
|
91
87
|
if (context.filepath) {
|
|
92
|
-
commands.push(`codehere
|
|
88
|
+
commands.push(`codehere trust ${context.filepath}`);
|
|
93
89
|
}
|
|
94
|
-
commands.push('codehere index');
|
|
95
90
|
}
|
|
96
91
|
break;
|
|
97
92
|
case ErrorType.API_ERROR:
|
|
@@ -102,7 +97,7 @@ function getRecoveryCommands(errorType, errorMessage, context) {
|
|
|
102
97
|
break;
|
|
103
98
|
case ErrorType.POLICY:
|
|
104
99
|
if (context.filepath) {
|
|
105
|
-
commands.push(`codehere
|
|
100
|
+
commands.push(`codehere trust ${context.filepath}`);
|
|
106
101
|
commands.push('codehere config policies');
|
|
107
102
|
}
|
|
108
103
|
break;
|
|
@@ -174,7 +169,7 @@ function getDocumentationLink(errorType) {
|
|
|
174
169
|
function generateErrorCode(errorType, errorMessage) {
|
|
175
170
|
const prefix = errorType.toUpperCase().substring(0, 3);
|
|
176
171
|
const hash = errorMessage.split('').reduce((acc, char) => {
|
|
177
|
-
return (
|
|
172
|
+
return (acc << 5) - acc + char.charCodeAt(0);
|
|
178
173
|
}, 0);
|
|
179
174
|
const code = Math.abs(hash).toString(16).substring(0, 4).toUpperCase();
|
|
180
175
|
return `${prefix}-${code}`;
|
|
@@ -183,7 +178,7 @@ function generateErrorCode(errorType, errorMessage) {
|
|
|
183
178
|
* Display error with helpful context and recovery suggestions
|
|
184
179
|
*/
|
|
185
180
|
export function displayError(error, options = {}) {
|
|
186
|
-
const { operation = 'operation', query, showSuggestions = true, showStack = false
|
|
181
|
+
const { operation = 'operation', query, showSuggestions = true, showStack = false } = options;
|
|
187
182
|
const errorType = classifyError(error);
|
|
188
183
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
189
184
|
const isEnterpriseError = error instanceof EnterpriseError;
|
|
@@ -227,16 +222,21 @@ export function displayError(error, options = {}) {
|
|
|
227
222
|
const suggestions = getErrorSuggestions(errorType, errorMessage, { operation, query, filepath: fileContext });
|
|
228
223
|
if (suggestions.length > 0) {
|
|
229
224
|
console.log(colors.bold('Suggestions:'));
|
|
230
|
-
suggestions.forEach(suggestion => {
|
|
225
|
+
suggestions.forEach((suggestion) => {
|
|
231
226
|
console.log(colors.dim(` ${symbols.bullet} ${suggestion}`));
|
|
232
227
|
});
|
|
233
228
|
newline();
|
|
234
229
|
}
|
|
235
230
|
// Show recovery commands for certain error types
|
|
236
|
-
const recoveryCommands = getRecoveryCommands(errorType, errorMessage, {
|
|
231
|
+
const recoveryCommands = getRecoveryCommands(errorType, errorMessage, {
|
|
232
|
+
operation,
|
|
233
|
+
query,
|
|
234
|
+
filepath: fileContext,
|
|
235
|
+
lineNumber: lineContext,
|
|
236
|
+
});
|
|
237
237
|
if (recoveryCommands.length > 0) {
|
|
238
238
|
console.log(colors.bold('Recovery Commands:'));
|
|
239
|
-
recoveryCommands.forEach(cmd => {
|
|
239
|
+
recoveryCommands.forEach((cmd) => {
|
|
240
240
|
console.log(colors.cyan(` $ ${cmd}`));
|
|
241
241
|
});
|
|
242
242
|
newline();
|
|
@@ -271,7 +271,7 @@ function getErrorSuggestions(errorType, errorMessage, context) {
|
|
|
271
271
|
const lowerMessage = errorMessage.toLowerCase();
|
|
272
272
|
switch (errorType) {
|
|
273
273
|
case ErrorType.RATE_LIMIT:
|
|
274
|
-
suggestions.push(
|
|
274
|
+
suggestions.push("You've reached the API rate limit or monthly quota");
|
|
275
275
|
suggestions.push('Wait a moment and try again');
|
|
276
276
|
suggestions.push('Check your API key limits at: https://dashboard.cohere.com/api-keys');
|
|
277
277
|
suggestions.push('Consider upgrading your API key for higher limits');
|
|
@@ -286,11 +286,8 @@ function getErrorSuggestions(errorType, errorMessage, context) {
|
|
|
286
286
|
suggestions.push('For troubleshooting, include the error code when reporting issues');
|
|
287
287
|
}
|
|
288
288
|
else if (lowerMessage.includes('not found') || lowerMessage.includes('missing')) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
suggestions.push('Make sure you\'re in the correct directory');
|
|
293
|
-
suggestions.push('Run "codehere index" to build search index');
|
|
289
|
+
suggestions.push("Make sure you're in the correct directory");
|
|
290
|
+
suggestions.push('Run "codehere trust ." to verify the path is scanned');
|
|
294
291
|
}
|
|
295
292
|
else {
|
|
296
293
|
suggestions.push('Check the error message above for specific details');
|
|
@@ -319,8 +316,7 @@ function getErrorSuggestions(errorType, errorMessage, context) {
|
|
|
319
316
|
suggestions.push('Check file permissions');
|
|
320
317
|
}
|
|
321
318
|
else if (lowerMessage.includes('memory') || lowerMessage.includes('database')) {
|
|
322
|
-
suggestions.push('
|
|
323
|
-
suggestions.push('Try running "codehere index" to rebuild the index');
|
|
319
|
+
suggestions.push('Run "codehere health" to inspect runtime state');
|
|
324
320
|
}
|
|
325
321
|
else {
|
|
326
322
|
suggestions.push('This error may be temporary - try again');
|
package/dist/ui.js
CHANGED
|
@@ -39,7 +39,7 @@ export function printContextSummary(files, maxShow = 3) {
|
|
|
39
39
|
const shown = unique.slice(0, maxShow);
|
|
40
40
|
const more = unique.length - maxShow;
|
|
41
41
|
console.log(colors.dim('Context:'));
|
|
42
|
-
shown.forEach(f => console.log(colors.dim(` - ${f}`)));
|
|
42
|
+
shown.forEach((f) => console.log(colors.dim(` - ${f}`)));
|
|
43
43
|
if (more > 0) {
|
|
44
44
|
console.log(colors.dim(` ... and ${more} more file${more > 1 ? 's' : ''}`));
|
|
45
45
|
}
|
|
@@ -147,35 +147,35 @@ export function info(message) {
|
|
|
147
147
|
// Create professional table - minimal styling
|
|
148
148
|
export function createTable(headers, rows) {
|
|
149
149
|
const table = new Table({
|
|
150
|
-
head: headers.map(h => colors.bold(h)),
|
|
150
|
+
head: headers.map((h) => colors.bold(h)),
|
|
151
151
|
style: {
|
|
152
152
|
head: [],
|
|
153
153
|
border: ['gray'],
|
|
154
154
|
compact: false,
|
|
155
155
|
},
|
|
156
156
|
chars: {
|
|
157
|
-
|
|
157
|
+
top: '─',
|
|
158
158
|
'top-mid': '┬',
|
|
159
159
|
'top-left': '┌',
|
|
160
160
|
'top-right': '┐',
|
|
161
|
-
|
|
161
|
+
bottom: '─',
|
|
162
162
|
'bottom-mid': '┴',
|
|
163
163
|
'bottom-left': '└',
|
|
164
164
|
'bottom-right': '┘',
|
|
165
|
-
|
|
165
|
+
left: '│',
|
|
166
166
|
'left-mid': '├',
|
|
167
|
-
|
|
167
|
+
mid: '─',
|
|
168
168
|
'mid-mid': '┼',
|
|
169
|
-
|
|
169
|
+
right: '│',
|
|
170
170
|
'right-mid': '┤',
|
|
171
|
-
|
|
171
|
+
middle: '│',
|
|
172
172
|
},
|
|
173
173
|
colWidths: headers.map((_, i) => {
|
|
174
|
-
const maxWidth = Math.max(headers[i].length, ...rows.map(row => (row[i] || '').length));
|
|
174
|
+
const maxWidth = Math.max(headers[i].length, ...rows.map((row) => (row[i] || '').length));
|
|
175
175
|
return Math.min(maxWidth + 2, 50);
|
|
176
176
|
}),
|
|
177
177
|
});
|
|
178
|
-
rows.forEach(row => table.push(row));
|
|
178
|
+
rows.forEach((row) => table.push(row));
|
|
179
179
|
return table;
|
|
180
180
|
}
|
|
181
181
|
// Format file path - subtle
|
|
@@ -436,7 +436,7 @@ export function showSlashCommandMenu() {
|
|
|
436
436
|
newline();
|
|
437
437
|
console.log(colors.bold(' Slash commands'));
|
|
438
438
|
newline();
|
|
439
|
-
const maxNameLen = Math.max(...SLASH_COMMANDS.map(c => c.name.length + c.args.length)) + 1;
|
|
439
|
+
const maxNameLen = Math.max(...SLASH_COMMANDS.map((c) => c.name.length + c.args.length)) + 1;
|
|
440
440
|
for (const cmd of SLASH_COMMANDS) {
|
|
441
441
|
const signature = `/${cmd.name}${cmd.args ? ' ' + cmd.args : ''}`;
|
|
442
442
|
const pad = ' '.repeat(Math.max(0, maxNameLen + 2 - signature.length + 8));
|
package/package.json
CHANGED
|
@@ -1,115 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codehere",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.0-rc.1",
|
|
4
|
+
"description": "A PM for your AI coding agents. Delegate, orchestrate, and audit Claude Code, Codex, Aider, and OpenCode from one local web UI — every AI action traced, every file scored.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"codehere": "dist/index.js"
|
|
8
|
+
"codehere": "dist/index.js",
|
|
9
|
+
"ch": "dist/index.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"dist",
|
|
12
13
|
"README.md",
|
|
13
14
|
"LICENSE"
|
|
14
15
|
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
15
19
|
"scripts": {
|
|
20
|
+
"prebuild": "rm -rf dist",
|
|
16
21
|
"build": "tsc",
|
|
17
|
-
"
|
|
22
|
+
"postbuild": "chmod +x dist/index.js",
|
|
23
|
+
"repomap": "node scripts/gen-repo-map.mjs",
|
|
24
|
+
"prepublishOnly": "npm run build && find dist -name '*.map' -delete && find dist -name '*.d.ts' -delete && find dist -name '*.d.ts.map' -delete",
|
|
18
25
|
"start": "node dist/index.js",
|
|
19
|
-
"start:api": "npm run build && node dist/api/server.js",
|
|
20
26
|
"dev": "tsx src/index.ts",
|
|
21
|
-
"dev:api": "tsx api/server.ts",
|
|
22
27
|
"test": "npm run build && vitest run",
|
|
23
|
-
"test:unit": "npm run build && tsx test/unit/run-unit-tests.ts",
|
|
24
|
-
"test:cli": "npm run build && tsx test/integration/run-cli-tests.ts",
|
|
25
28
|
"test:watch": "vitest",
|
|
26
29
|
"lint": "eslint src/ --ext .ts",
|
|
27
30
|
"format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
|
|
28
31
|
"format:check": "prettier --check 'src/**/*.ts' 'test/**/*.ts'",
|
|
29
|
-
"
|
|
30
|
-
"test:scenarios": "npm run build && tsx test/scenarios/real-world-scenarios.ts",
|
|
31
|
-
"test:security": "npm run build && tsx test/security/sast-scanner.test.ts",
|
|
32
|
-
"test:security-gate": "npm run build && tsx test/security/security-gate.test.ts",
|
|
33
|
-
"test:git-workflow": "npm run build && tsx test/git/git-workflow.test.ts",
|
|
34
|
-
"test:git-react": "npm run build && tsx test/git/react-git-integration.test.ts",
|
|
35
|
-
"test:memory": "npm run build && tsx test/memory/memory-system.test.ts",
|
|
36
|
-
"test:performance": "npm run build && tsx test/performance/performance-analysis.test.ts",
|
|
37
|
-
"test:context-depth": "npm run build && tsx test/context-depth/context-depth.test.ts",
|
|
38
|
-
"test:compound-instruction": "npm run build && tsx test/compound-instruction/compound-instruction.test.ts",
|
|
39
|
-
"check-api": "npm run build && tsx -e \"import('./dist/utils/check-api-status.js').then(m => m.checkAPIStatus().then(s => { console.log(s.canProceed ? '✅ ' + s.message : '❌ ' + s.message); process.exit(s.canProceed ? 0 : 1); }))\"",
|
|
40
|
-
"test:all": "npm run build && npm run test:integration && npm run test:scenarios && npm run test:security && npm run test:security-gate && npm run test:git-workflow && npm run test:memory && npm run test:performance",
|
|
41
|
-
"test:coverage": "c8 npm run test:unit && c8 report --reporter=text --reporter=html",
|
|
42
|
-
"test:rerank": "tsx test/rerank-integration.test.ts",
|
|
43
|
-
"eval:command-r": "tsx test/command-a-evaluation.test.ts",
|
|
44
|
-
"test:verification": "npm run build && node test-verification-simple.js",
|
|
45
|
-
"measure:metrics": "npm run build && node test/measure-metrics.js",
|
|
46
|
-
"analyze:feedback": "tsx scripts/analyze-feedback.ts",
|
|
47
|
-
"check:trust": "tsx scripts/check-trust-thresholds.ts",
|
|
48
|
-
"smoke:cohere": "npm run build && tsx scripts/smoke-cohere.ts",
|
|
49
|
-
"smoke:openai": "npm run build && tsx scripts/smoke-openai.ts",
|
|
50
|
-
"test:real-providers": "npm run build && tsx test/integration/real-provider-comprehensive.test.ts",
|
|
51
|
-
"test:user-flows": "npm run build && tsx test/integration/user-flow-validation.test.ts"
|
|
32
|
+
"sbom": "npm sbom --sbom-format=spdx --omit=dev"
|
|
52
33
|
},
|
|
53
34
|
"keywords": [
|
|
54
|
-
"ai-coding-
|
|
55
|
-
"
|
|
56
|
-
"
|
|
35
|
+
"ai-coding-agents",
|
|
36
|
+
"agent-orchestration",
|
|
37
|
+
"audit-trail",
|
|
57
38
|
"trust-scoring",
|
|
58
39
|
"ai-safety",
|
|
59
|
-
"
|
|
60
|
-
"orchestration",
|
|
40
|
+
"ai-governance",
|
|
61
41
|
"claude-code",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"code-review",
|
|
42
|
+
"codex",
|
|
43
|
+
"aider",
|
|
44
|
+
"opencode",
|
|
66
45
|
"hook-system",
|
|
67
|
-
"
|
|
46
|
+
"sast",
|
|
47
|
+
"cli-tool",
|
|
68
48
|
"typescript"
|
|
69
49
|
],
|
|
70
|
-
"author": "
|
|
50
|
+
"author": "The codehere authors",
|
|
71
51
|
"license": "MIT",
|
|
72
52
|
"repository": {
|
|
73
53
|
"type": "git",
|
|
74
|
-
"url": "https://github.com/muhammadegaa/codehere.git"
|
|
54
|
+
"url": "git+https://github.com/muhammadegaa/codehere.git"
|
|
75
55
|
},
|
|
76
56
|
"bugs": {
|
|
77
57
|
"url": "https://github.com/muhammadegaa/codehere/issues"
|
|
78
58
|
},
|
|
79
59
|
"homepage": "https://codehere.uk",
|
|
80
|
-
"logo": "https://codehere.uk/icon.svg",
|
|
81
60
|
"dependencies": {
|
|
82
61
|
"boxen": "^8.0.1",
|
|
83
62
|
"chalk": "^5.3.0",
|
|
84
63
|
"cli-progress": "^3.12.0",
|
|
85
64
|
"cli-table3": "^0.6.5",
|
|
86
|
-
"cohere-ai": "^7.7.0",
|
|
87
65
|
"commander": "^11.1.0",
|
|
88
|
-
"cors": "^2.8.5",
|
|
89
|
-
"diff": "^5.1.0",
|
|
90
66
|
"dotenv": "^16.3.1",
|
|
91
|
-
"
|
|
92
|
-
"get-tsconfig": "^4.13.0",
|
|
93
|
-
"inquirer": "^13.0.1",
|
|
94
|
-
"ora": "^7.0.1",
|
|
95
|
-
"resolve-pkg-maps": "^1.0.0",
|
|
96
|
-
"sql.js": "^1.10.3",
|
|
97
|
-
"tiktoken": "^1.0.10",
|
|
98
|
-
"wrap-ansi": "^9.0.2"
|
|
67
|
+
"ora": "^7.0.1"
|
|
99
68
|
},
|
|
100
69
|
"devDependencies": {
|
|
101
70
|
"@eslint/js": "^10.0.1",
|
|
102
71
|
"@types/cli-progress": "^3.11.5",
|
|
103
|
-
"@types/cors": "^2.8.19",
|
|
104
|
-
"@types/diff": "^5.0.8",
|
|
105
|
-
"@types/express": "^5.0.5",
|
|
106
72
|
"@types/node": "^20.19.25",
|
|
107
|
-
"@types/sql.js": "^1.4.8",
|
|
108
|
-
"@types/supertest": "^6.0.3",
|
|
109
|
-
"c8": "^10.1.3",
|
|
110
73
|
"eslint": "^10.2.0",
|
|
111
74
|
"prettier": "^3.8.3",
|
|
112
|
-
"supertest": "^7.1.4",
|
|
113
75
|
"tsx": "^4.21.0",
|
|
114
76
|
"typescript": "^5.9.3",
|
|
115
77
|
"typescript-eslint": "^8.58.2",
|
package/dist/agents/base.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base Agent Interface
|
|
3
|
-
* Foundation for multi-agent system in Codehere
|
|
4
|
-
*
|
|
5
|
-
* These agents ARE Codehere - they help end-users.
|
|
6
|
-
* But organizing them this way makes it easier for YOU to develop and improve Codehere.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Base agent class
|
|
10
|
-
* Provides common functionality for all agents
|
|
11
|
-
*/
|
|
12
|
-
export class BaseAgent {
|
|
13
|
-
/** Agent registry (set by OrchestratorAgent) */
|
|
14
|
-
agentRegistry;
|
|
15
|
-
/**
|
|
16
|
-
* Call another agent
|
|
17
|
-
* Enables agent-to-agent collaboration
|
|
18
|
-
*/
|
|
19
|
-
async callAgent(agentName, request) {
|
|
20
|
-
if (!this.agentRegistry) {
|
|
21
|
-
return {
|
|
22
|
-
success: false,
|
|
23
|
-
error: 'AgentRegistry not set. Cannot call other agents.',
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const agent = this.agentRegistry.get(agentName);
|
|
27
|
-
if (!agent) {
|
|
28
|
-
return {
|
|
29
|
-
success: false,
|
|
30
|
-
error: `Agent "${agentName}" not found. Available agents: ${this.agentRegistry.getAll().map(a => a.name).join(', ')}`,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
// Check if this agent is allowed to call the target agent
|
|
34
|
-
if (!this.canCall.includes(agentName) && this.canCall.length > 0) {
|
|
35
|
-
return {
|
|
36
|
-
success: false,
|
|
37
|
-
error: `Agent "${this.name}" is not allowed to call "${agentName}". Allowed: ${this.canCall.join(', ')}`,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
return agent.handle({
|
|
41
|
-
...request,
|
|
42
|
-
caller: this.name,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Default canHandle implementation
|
|
47
|
-
* Checks if intent matches agent's name
|
|
48
|
-
*/
|
|
49
|
-
canHandle(request) {
|
|
50
|
-
return request.intent.intent === this.name;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Default validate implementation
|
|
54
|
-
* Can be overridden by subclasses
|
|
55
|
-
*/
|
|
56
|
-
validate(request) {
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Agent Registry
|
|
62
|
-
* Manages all agents in the system
|
|
63
|
-
*/
|
|
64
|
-
export class AgentRegistry {
|
|
65
|
-
agents = new Map();
|
|
66
|
-
/**
|
|
67
|
-
* Register an agent
|
|
68
|
-
*/
|
|
69
|
-
register(agent) {
|
|
70
|
-
this.agents.set(agent.name, agent);
|
|
71
|
-
// Set agent registry on BaseAgent instances
|
|
72
|
-
if (agent instanceof BaseAgent) {
|
|
73
|
-
agent.agentRegistry = this;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Get an agent by name
|
|
78
|
-
*/
|
|
79
|
-
get(name) {
|
|
80
|
-
return this.agents.get(name);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Get all registered agents
|
|
84
|
-
*/
|
|
85
|
-
getAll() {
|
|
86
|
-
return Array.from(this.agents.values());
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Get agents by capability
|
|
90
|
-
*/
|
|
91
|
-
getByCapability(capability) {
|
|
92
|
-
return this.getAll().filter(agent => agent.capabilities.includes(capability));
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Get agent names
|
|
96
|
-
*/
|
|
97
|
-
getNames() {
|
|
98
|
-
return Array.from(this.agents.keys());
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=base.js.map
|