avorelo 0.1.0 → 0.3.0
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/LICENSE +23 -16
- package/README.md +90 -51
- package/bin/avorelo.mjs +7 -0
- package/dist/avorelo.mjs +19741 -0
- package/package.json +135 -120
- package/bin/avorelo +0 -9
- package/scripts/README.md +0 -40
- package/scripts/cco-dashboard.js +0 -252
- package/scripts/cco-status.js +0 -430
- package/scripts/lib/activation/account-state.js +0 -37
- package/scripts/lib/activation/activation-runner.js +0 -546
- package/scripts/lib/activation/activation-self-healing.js +0 -480
- package/scripts/lib/activation/activation-state.js +0 -83
- package/scripts/lib/activation/activation-summary.js +0 -191
- package/scripts/lib/activation/adapters/claude-code.js +0 -77
- package/scripts/lib/activation/adapters/codex-cli.js +0 -52
- package/scripts/lib/activation/adapters/cursor.js +0 -37
- package/scripts/lib/activation/adapters/github-agent.js +0 -39
- package/scripts/lib/activation/adapters/terminal.js +0 -42
- package/scripts/lib/activation/adapters/vscode.js +0 -39
- package/scripts/lib/activation/adapters/windsurf.js +0 -37
- package/scripts/lib/activation/ai-surface-detector.js +0 -151
- package/scripts/lib/activation/connect-account.js +0 -145
- package/scripts/lib/activation/detect-environment.js +0 -75
- package/scripts/lib/activation/detect-hosts.js +0 -62
- package/scripts/lib/activation/format-activation-output.js +0 -109
- package/scripts/lib/activation/next-action.js +0 -43
- package/scripts/lib/activation/repair-engine.js +0 -219
- package/scripts/lib/activation-distribution-readiness.js +0 -507
- package/scripts/lib/adapter-conformance.js +0 -176
- package/scripts/lib/adapter-readiness.js +0 -417
- package/scripts/lib/adapter-safety-boundaries.js +0 -335
- package/scripts/lib/adapter-technical-readiness-gate.js +0 -205
- package/scripts/lib/agent-access-governance.js +0 -455
- package/scripts/lib/agent-enforcement.js +0 -765
- package/scripts/lib/agent-policy-profile.js +0 -210
- package/scripts/lib/agent-security/action-evaluator.js +0 -507
- package/scripts/lib/agent-security/adapter-registry.js +0 -98
- package/scripts/lib/agent-security/auto-policy.js +0 -139
- package/scripts/lib/agent-security/bounded-scan.js +0 -93
- package/scripts/lib/agent-security/enforcement-adapter.js +0 -174
- package/scripts/lib/agent-security/enforcement-engine.js +0 -1129
- package/scripts/lib/agent-security/file-write-adapter.js +0 -183
- package/scripts/lib/agent-security/file-write-rules.js +0 -178
- package/scripts/lib/agent-security/index.js +0 -3342
- package/scripts/lib/agent-security/instruction-risk.js +0 -181
- package/scripts/lib/agent-security/mcp-action-adapter.js +0 -185
- package/scripts/lib/agent-security/mcp-action-rules.js +0 -184
- package/scripts/lib/agent-security/package-action-adapter.js +0 -175
- package/scripts/lib/agent-security/package-action-rules.js +0 -233
- package/scripts/lib/agent-security/performance.js +0 -148
- package/scripts/lib/agent-security/permission-minimizer.js +0 -403
- package/scripts/lib/agent-security/scan-cache.js +0 -74
- package/scripts/lib/agent-security/source-trust.js +0 -146
- package/scripts/lib/ai-install-prompt.js +0 -288
- package/scripts/lib/ai-workspace-hygiene.js +0 -1499
- package/scripts/lib/alpha-activation.js +0 -520
- package/scripts/lib/alpha-feedback.js +0 -263
- package/scripts/lib/alpha-readiness-gate.js +0 -332
- package/scripts/lib/anti-gaming.js +0 -169
- package/scripts/lib/artifact-health.js +0 -431
- package/scripts/lib/attribution.js +0 -180
- package/scripts/lib/audit.js +0 -289
- package/scripts/lib/avorelo-skill-registry.js +0 -810
- package/scripts/lib/batch-jobs.js +0 -71
- package/scripts/lib/brain-pack.js +0 -578
- package/scripts/lib/brand-boundary.js +0 -424
- package/scripts/lib/brand.js +0 -74
- package/scripts/lib/browser-capability.js +0 -1048
- package/scripts/lib/browser-proof-preflight.js +0 -321
- package/scripts/lib/cache-readiness.js +0 -187
- package/scripts/lib/canonical-reentry.js +0 -162
- package/scripts/lib/capability-packs.js +0 -314
- package/scripts/lib/capability-recommender.js +0 -512
- package/scripts/lib/capability-registry.js +0 -1059
- package/scripts/lib/carry-forward-surfacing.js +0 -194
- package/scripts/lib/ccusage-adapter.js +0 -188
- package/scripts/lib/company-loop.js +0 -1149
- package/scripts/lib/config.js +0 -637
- package/scripts/lib/context-acquisition-plan.js +0 -287
- package/scripts/lib/context-budget-guard.js +0 -170
- package/scripts/lib/context-budget-scanner.js +0 -257
- package/scripts/lib/context-optimizer.js +0 -715
- package/scripts/lib/context-reduction-plan.js +0 -178
- package/scripts/lib/context-safety.js +0 -88
- package/scripts/lib/context-savings-engine.js +0 -158
- package/scripts/lib/cost-evidence.js +0 -254
- package/scripts/lib/cross-host-install-plan.js +0 -308
- package/scripts/lib/cross-host-install-readiness.js +0 -237
- package/scripts/lib/cross-host-value-flow.js +0 -268
- package/scripts/lib/dashboard.js +0 -900
- package/scripts/lib/design-partner-feedback.js +0 -346
- package/scripts/lib/entitlements.js +0 -100
- package/scripts/lib/execution-packet.js +0 -559
- package/scripts/lib/experimentation-events.js +0 -547
- package/scripts/lib/external-capability-compliance.js +0 -107
- package/scripts/lib/external-user-simulation.js +0 -166
- package/scripts/lib/failure-recovery-readiness.js +0 -81
- package/scripts/lib/failure-recovery.js +0 -419
- package/scripts/lib/feedback-intelligence.js +0 -537
- package/scripts/lib/feedback-signals.js +0 -205
- package/scripts/lib/file-integrity.js +0 -68
- package/scripts/lib/fsx.js +0 -127
- package/scripts/lib/full-readiness-gate.js +0 -451
- package/scripts/lib/guidance-builder.js +0 -174
- package/scripts/lib/hook-apply.js +0 -1019
- package/scripts/lib/hook-baseline.js +0 -310
- package/scripts/lib/hook-config-preview.js +0 -275
- package/scripts/lib/hook-contracts.js +0 -290
- package/scripts/lib/hook-safety-boundary-readiness.js +0 -80
- package/scripts/lib/host-capability-matrix.js +0 -351
- package/scripts/lib/host-support-context.js +0 -254
- package/scripts/lib/http-hook-action.js +0 -538
- package/scripts/lib/install-ai-readiness.js +0 -84
- package/scripts/lib/install-intake-risk.js +0 -1037
- package/scripts/lib/install-journey-intelligence.js +0 -329
- package/scripts/lib/intervention-guidance.js +0 -57
- package/scripts/lib/known-limitations.js +0 -115
- package/scripts/lib/l8-path-truth.js +0 -146
- package/scripts/lib/launch-hardening-gate.js +0 -436
- package/scripts/lib/launch-readiness.js +0 -628
- package/scripts/lib/learning-memory.js +0 -686
- package/scripts/lib/lifecycle-hooks.js +0 -802
- package/scripts/lib/local-package-smoke.js +0 -423
- package/scripts/lib/local-pricing.js +0 -299
- package/scripts/lib/mcp-enforcement.js +0 -311
- package/scripts/lib/mcp-least-privilege-policy.js +0 -303
- package/scripts/lib/mcp-tool-inventory.js +0 -388
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +0 -335
- package/scripts/lib/metrics.js +0 -699
- package/scripts/lib/micro-proof.js +0 -133
- package/scripts/lib/next-run-context.js +0 -436
- package/scripts/lib/operating-value.js +0 -1648
- package/scripts/lib/optimization-v3.js +0 -122
- package/scripts/lib/orchestration/adapters/_shared.js +0 -49
- package/scripts/lib/orchestration/adapters/aider.js +0 -18
- package/scripts/lib/orchestration/adapters/claude-code.js +0 -35
- package/scripts/lib/orchestration/adapters/codex.js +0 -35
- package/scripts/lib/orchestration/adapters/gemini-cli.js +0 -18
- package/scripts/lib/orchestration/adapters/git.js +0 -25
- package/scripts/lib/orchestration/adapters/index.js +0 -31
- package/scripts/lib/orchestration/adapters/lm-studio.js +0 -18
- package/scripts/lib/orchestration/adapters/ollama.js +0 -18
- package/scripts/lib/orchestration/adapters/opencode.js +0 -18
- package/scripts/lib/orchestration/adapters/openrouter.js +0 -18
- package/scripts/lib/orchestration/adapters/test-runner.js +0 -25
- package/scripts/lib/orchestration/cli.js +0 -438
- package/scripts/lib/orchestration/execution-manager.js +0 -279
- package/scripts/lib/orchestration/handoff.js +0 -314
- package/scripts/lib/orchestration/index.js +0 -456
- package/scripts/lib/orchestration/inventory.js +0 -47
- package/scripts/lib/orchestration/model-discovery.js +0 -498
- package/scripts/lib/orchestration/model-profiler.js +0 -170
- package/scripts/lib/orchestration/model-profiles.js +0 -252
- package/scripts/lib/orchestration/model-refresh-policy.js +0 -72
- package/scripts/lib/orchestration/proof-writer.js +0 -349
- package/scripts/lib/orchestration/provider-discovery/aider.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +0 -56
- package/scripts/lib/orchestration/provider-discovery/codex.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/common.js +0 -186
- package/scripts/lib/orchestration/provider-discovery/gemini.js +0 -106
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +0 -118
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +0 -12
- package/scripts/lib/orchestration/provider-discovery/ollama.js +0 -100
- package/scripts/lib/orchestration/provider-discovery/opencode.js +0 -47
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +0 -44
- package/scripts/lib/orchestration/risk-classifier.js +0 -130
- package/scripts/lib/orchestration/routing-policy.js +0 -486
- package/scripts/lib/orchestration/settings.js +0 -112
- package/scripts/lib/orchestration/state.js +0 -165
- package/scripts/lib/orchestration/verification-manager.js +0 -138
- package/scripts/lib/output-profiles.js +0 -146
- package/scripts/lib/package-content-audit.js +0 -368
- package/scripts/lib/package-runtime.js +0 -278
- package/scripts/lib/plan-surface.js +0 -53
- package/scripts/lib/plans.js +0 -2318
- package/scripts/lib/policy-provider.js +0 -27
- package/scripts/lib/prelaunch-activation-readiness.js +0 -409
- package/scripts/lib/prelaunch-evidence-store.js +0 -816
- package/scripts/lib/prelaunch-intelligence.js +0 -869
- package/scripts/lib/pricing-experiment.js +0 -118
- package/scripts/lib/pro-moment-events.js +0 -77
- package/scripts/lib/pro-moment-state.js +0 -227
- package/scripts/lib/pro-moments.js +0 -1216
- package/scripts/lib/product-learning-events.js +0 -629
- package/scripts/lib/project-profile.js +0 -555
- package/scripts/lib/prompt-compiler.js +0 -280
- package/scripts/lib/prompt-lint.js +0 -32
- package/scripts/lib/prompt-suggestions.js +0 -52
- package/scripts/lib/proof-canonical.js +0 -398
- package/scripts/lib/proof-drilldown.js +0 -383
- package/scripts/lib/proof-events.js +0 -342
- package/scripts/lib/proof-history.js +0 -243
- package/scripts/lib/proof-metrics.js +0 -296
- package/scripts/lib/proof-outcome-evidence.js +0 -134
- package/scripts/lib/proof-receipt.js +0 -335
- package/scripts/lib/proof-record.js +0 -461
- package/scripts/lib/public-activation-distribution-gate.js +0 -258
- package/scripts/lib/public-cli.js +0 -3891
- package/scripts/lib/public-distribution-truth.js +0 -211
- package/scripts/lib/public-install-claim-checker.js +0 -294
- package/scripts/lib/publish-provenance-readiness.js +0 -283
- package/scripts/lib/readiness-delta.js +0 -218
- package/scripts/lib/readiness-evidence-closure.js +0 -196
- package/scripts/lib/reentry-memory-capture.js +0 -241
- package/scripts/lib/reentry-memory-retrieval.js +0 -302
- package/scripts/lib/reentry-memory-status.js +0 -146
- package/scripts/lib/reentry-memory-store.js +0 -178
- package/scripts/lib/reentry-state.js +0 -66
- package/scripts/lib/release-candidate-bundle.js +0 -166
- package/scripts/lib/remediation.js +0 -81
- package/scripts/lib/repo-map.js +0 -391
- package/scripts/lib/run-improvements-lifecycle.js +0 -330
- package/scripts/lib/run-improvements.js +0 -789
- package/scripts/lib/runtime-decision-policy.js +0 -387
- package/scripts/lib/safe-path-engine.js +0 -705
- package/scripts/lib/safe-run-controller.js +0 -887
- package/scripts/lib/score.js +0 -262
- package/scripts/lib/seamless-enforcement.js +0 -329
- package/scripts/lib/seamless-outcome.js +0 -689
- package/scripts/lib/seamless-reality-gate.js +0 -5043
- package/scripts/lib/security-risk-classifier.js +0 -511
- package/scripts/lib/security-scan.js +0 -384
- package/scripts/lib/session-context-optimizer.js +0 -1211
- package/scripts/lib/session-timing.js +0 -315
- package/scripts/lib/skill-hygiene.js +0 -805
- package/scripts/lib/skill-packs.js +0 -161
- package/scripts/lib/skills-operating-layer.js +0 -580
- package/scripts/lib/smart-work-routing.js +0 -768
- package/scripts/lib/source-catalog.js +0 -700
- package/scripts/lib/status-value-summary.js +0 -32
- package/scripts/lib/support-bundle.js +0 -578
- package/scripts/lib/task-continuation.js +0 -440
- package/scripts/lib/test-helpers.js +0 -15
- package/scripts/lib/tier.js +0 -38
- package/scripts/lib/token-context-quality-gate.js +0 -370
- package/scripts/lib/token-cost-capture.js +0 -187
- package/scripts/lib/token-cost-intelligence.js +0 -358
- package/scripts/lib/token-efficiency-evidence.js +0 -213
- package/scripts/lib/token-evidence.js +0 -699
- package/scripts/lib/tokenish.js +0 -17
- package/scripts/lib/tool-output-sandbox.js +0 -304
- package/scripts/lib/trust-audit.js +0 -136
- package/scripts/lib/unified-events.js +0 -396
- package/scripts/lib/upgrade-interruption-recovery.js +0 -407
- package/scripts/lib/usage-ledger.js +0 -201
- package/scripts/lib/value-ledger.js +0 -130
- package/scripts/lib/value-proof-calibration.js +0 -531
- package/scripts/lib/visual-qa.js +0 -231
- package/scripts/lib/voice-alpha.js +0 -29
- package/scripts/lib/work-aware-orchestration.js +0 -976
- package/scripts/lib/work-control-receipts.js +0 -577
- package/scripts/lib/work-ledger.js +0 -1123
- package/scripts/lib/work-panel-preview.js +0 -352
- package/scripts/lib/workflow-discipline.js +0 -280
- package/scripts/lib/workflow-signals.js +0 -419
- package/scripts/lib/workspace-map.js +0 -281
- package/scripts/lib/workspace-registry.js +0 -1367
- package/scripts/lib/workspace-resolver.js +0 -480
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { commandExists } = require("../activation/detect-environment");
|
|
6
|
-
const { readProjectConfig } = require("../config");
|
|
7
|
-
const { buildProfileSummary, detectProfile } = require("./model-profiles");
|
|
8
|
-
const { createModelKey, inferModelRecord, mergeModelRecord } = require("./model-profiler");
|
|
9
|
-
const {
|
|
10
|
-
INVENTORY_SCHEMA_VERSION,
|
|
11
|
-
determineRefreshDecision,
|
|
12
|
-
defaultRefreshPolicy,
|
|
13
|
-
nextRefreshAfter,
|
|
14
|
-
tryAcquireRefreshLock,
|
|
15
|
-
releaseRefreshLock,
|
|
16
|
-
} = require("./model-refresh-policy");
|
|
17
|
-
const {
|
|
18
|
-
ensureOrchestrationDirs,
|
|
19
|
-
getCurrentPaths,
|
|
20
|
-
safeReadJson,
|
|
21
|
-
writeJson,
|
|
22
|
-
readLatestRunProofs,
|
|
23
|
-
} = require("./state");
|
|
24
|
-
const claudeCode = require("./provider-discovery/claude-code");
|
|
25
|
-
const codex = require("./provider-discovery/codex");
|
|
26
|
-
const gemini = require("./provider-discovery/gemini");
|
|
27
|
-
const lmStudio = require("./provider-discovery/lm-studio");
|
|
28
|
-
const ollama = require("./provider-discovery/ollama");
|
|
29
|
-
const opencode = require("./provider-discovery/opencode");
|
|
30
|
-
const aider = require("./provider-discovery/aider");
|
|
31
|
-
const openrouter = require("./provider-discovery/openrouter");
|
|
32
|
-
const { envPresence, pathExists, safeReadJsonFile, findFirstModelValue, buildBaseToolRecord } = require("./provider-discovery/common");
|
|
33
|
-
|
|
34
|
-
const FAILURE_LIMIT = 40;
|
|
35
|
-
|
|
36
|
-
const PROVIDERS = {
|
|
37
|
-
claude_code: claudeCode,
|
|
38
|
-
codex,
|
|
39
|
-
gemini_cli: gemini,
|
|
40
|
-
lm_studio: lmStudio,
|
|
41
|
-
ollama,
|
|
42
|
-
opencode,
|
|
43
|
-
aider,
|
|
44
|
-
openrouter_api: openrouter,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
function readFailureState(cwd) {
|
|
48
|
-
const current = getCurrentPaths(cwd);
|
|
49
|
-
const payload = safeReadJson(current.workerFailures, { schemaVersion: 1, records: [] });
|
|
50
|
-
if (!Array.isArray(payload.records)) payload.records = [];
|
|
51
|
-
return payload;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function writeFailureState(cwd, state) {
|
|
55
|
-
const current = getCurrentPaths(cwd);
|
|
56
|
-
writeJson(current.workerFailures, {
|
|
57
|
-
schemaVersion: 1,
|
|
58
|
-
records: (state.records || []).slice(-FAILURE_LIMIT),
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function classifyFailureReason(reasonText = "") {
|
|
63
|
-
const text = String(reasonText || "").toLowerCase();
|
|
64
|
-
if (/(401|auth|login|credentials|not logged in|sign in)/.test(text)) return { classifiedReason: "needs_login", cooldownMs: null };
|
|
65
|
-
if (/(429|quota|rate limit|credits exhausted|too many requests|usage limit)/.test(text)) return { classifiedReason: "recently_limited", cooldownMs: 60 * 60 * 1000 };
|
|
66
|
-
if (/(timeout|timed out|econnrefused|server unavailable|not running)/.test(text)) return { classifiedReason: "recently_failed", cooldownMs: 15 * 60 * 1000 };
|
|
67
|
-
if (/(model not found|unknown model|no such model)/.test(text)) return { classifiedReason: "stale", cooldownMs: null };
|
|
68
|
-
if (/(verification failed|verification|tests failed)/.test(text)) return { classifiedReason: "verification_failed", cooldownMs: 15 * 60 * 1000 };
|
|
69
|
-
return { classifiedReason: "recently_failed", cooldownMs: 15 * 60 * 1000 };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function recordWorkerFailure(cwd, record) {
|
|
73
|
-
const state = readFailureState(cwd);
|
|
74
|
-
const classified = classifyFailureReason(record.reason);
|
|
75
|
-
const observedAt = record.observedAt || new Date().toISOString();
|
|
76
|
-
const cooldownUntil = classified.cooldownMs ? new Date(Date.parse(observedAt) + classified.cooldownMs).toISOString() : null;
|
|
77
|
-
state.records.push({
|
|
78
|
-
workerId: record.workerId,
|
|
79
|
-
modelId: record.modelId || null,
|
|
80
|
-
reason: record.reason,
|
|
81
|
-
classifiedReason: classified.classifiedReason,
|
|
82
|
-
observedAt,
|
|
83
|
-
cooldownUntil,
|
|
84
|
-
taskType: record.taskType || null,
|
|
85
|
-
risk: record.risk || null,
|
|
86
|
-
});
|
|
87
|
-
writeFailureState(cwd, state);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function activeFailures(cwd) {
|
|
91
|
-
const now = Date.now();
|
|
92
|
-
return readFailureState(cwd).records.filter((record) => {
|
|
93
|
-
if (!record.cooldownUntil) return record.classifiedReason === "needs_login" || record.classifiedReason === "stale";
|
|
94
|
-
const until = Date.parse(record.cooldownUntil);
|
|
95
|
-
return Number.isFinite(until) && until > now;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function aggregateRecentHistory(cwd) {
|
|
100
|
-
const history = {};
|
|
101
|
-
const proofs = readLatestRunProofs(cwd, 40);
|
|
102
|
-
proofs.forEach(({ proof }) => {
|
|
103
|
-
const workers = new Set();
|
|
104
|
-
(proof?.toolsUsed || []).forEach((worker) => {
|
|
105
|
-
if (worker && worker.toolId) workers.add(worker.toolId);
|
|
106
|
-
});
|
|
107
|
-
workers.forEach((toolId) => {
|
|
108
|
-
const bucket = history[toolId] || {
|
|
109
|
-
successes: 0,
|
|
110
|
-
failures: 0,
|
|
111
|
-
lastFailureReason: null,
|
|
112
|
-
recentlyLimited: false,
|
|
113
|
-
recentlyFailed: false,
|
|
114
|
-
};
|
|
115
|
-
if (proof?.finalStatus === "completed" || proof?.finalStatus === "verified") {
|
|
116
|
-
bucket.successes += 1;
|
|
117
|
-
} else if (proof?.finalStatus && proof.finalStatus !== "planned" && proof.finalStatus !== "dry_run") {
|
|
118
|
-
bucket.failures += 1;
|
|
119
|
-
bucket.recentlyFailed = true;
|
|
120
|
-
if (proof?.failureReason) bucket.lastFailureReason = proof.failureReason;
|
|
121
|
-
}
|
|
122
|
-
if ((proof?.failures || []).some((entry) => /limit/i.test(String(entry.reason || "")))) {
|
|
123
|
-
bucket.recentlyLimited = true;
|
|
124
|
-
}
|
|
125
|
-
history[toolId] = bucket;
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
activeFailures(cwd).forEach((record) => {
|
|
130
|
-
const bucket = history[record.workerId] || {
|
|
131
|
-
successes: 0,
|
|
132
|
-
failures: 0,
|
|
133
|
-
lastFailureReason: null,
|
|
134
|
-
recentlyLimited: false,
|
|
135
|
-
recentlyFailed: false,
|
|
136
|
-
};
|
|
137
|
-
bucket.failures += 1;
|
|
138
|
-
bucket.lastFailureReason = record.reason;
|
|
139
|
-
if (record.classifiedReason === "recently_limited") bucket.recentlyLimited = true;
|
|
140
|
-
if (record.classifiedReason === "recently_failed" || record.classifiedReason === "verification_failed") bucket.recentlyFailed = true;
|
|
141
|
-
history[record.workerId] = bucket;
|
|
142
|
-
});
|
|
143
|
-
return history;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function deriveWorkerState(base, enabled) {
|
|
147
|
-
if (enabled === false) return "disabled_by_user";
|
|
148
|
-
if (base.availability === "needs_login") return "needs_login";
|
|
149
|
-
if (base.recentHistory?.recentlyLimited) return "recently_limited";
|
|
150
|
-
if (base.recentHistory?.recentlyFailed) return "recently_failed";
|
|
151
|
-
if (base.installStatus === "not_installed") return "missing";
|
|
152
|
-
if (base.installStatus === "installed_not_on_path") return "installed_not_on_path";
|
|
153
|
-
if (base.availability === "confirmed") return "available";
|
|
154
|
-
if (base.availability === "configured") return "configured";
|
|
155
|
-
return "unknown";
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function applyHistoryAndSettings(tool, config, history, failureRecords) {
|
|
159
|
-
const enabled = config.orchestration?.allowedWorkers?.[tool.toolId] !== false;
|
|
160
|
-
const recentHistory = history[tool.toolId] || tool.recentHistory || {
|
|
161
|
-
successes: 0,
|
|
162
|
-
failures: 0,
|
|
163
|
-
lastFailureReason: null,
|
|
164
|
-
recentlyLimited: false,
|
|
165
|
-
recentlyFailed: false,
|
|
166
|
-
};
|
|
167
|
-
const activeForTool = failureRecords.filter((record) => record.workerId === tool.toolId);
|
|
168
|
-
const nextModels = (tool.models || []).map((model) => {
|
|
169
|
-
const matchedFailure = activeForTool.find((record) => !record.modelId || record.modelId === model.modelId);
|
|
170
|
-
if (!matchedFailure) return model;
|
|
171
|
-
return {
|
|
172
|
-
...model,
|
|
173
|
-
availability: matchedFailure.classifiedReason,
|
|
174
|
-
lastFailure: matchedFailure,
|
|
175
|
-
recentFailureScore: Number(model.recentFailureScore || 0) + 1,
|
|
176
|
-
lastCheckedAt: matchedFailure.observedAt,
|
|
177
|
-
};
|
|
178
|
-
});
|
|
179
|
-
let availability = tool.availability;
|
|
180
|
-
if (recentHistory.recentlyLimited && availability !== "needs_login") availability = "recently_limited";
|
|
181
|
-
if (recentHistory.recentlyFailed && !["needs_login", "recently_limited"].includes(availability)) availability = "recently_failed";
|
|
182
|
-
const workerState = deriveWorkerState({ ...tool, availability, recentHistory }, enabled);
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
...tool,
|
|
186
|
-
availability,
|
|
187
|
-
activeProfile: detectProfile(tool.toolId, tool.activeModel)?.id || tool.activeProfile || null,
|
|
188
|
-
models: nextModels,
|
|
189
|
-
availableModels: nextModels.map((model) => ({ id: model.modelId, availability: model.availability })),
|
|
190
|
-
candidateProfiles: buildProfileSummary(tool.toolId, tool.activeModel),
|
|
191
|
-
recentHistory,
|
|
192
|
-
lastFailureReason: recentHistory.lastFailureReason || null,
|
|
193
|
-
workerState,
|
|
194
|
-
enabled,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function discoverGenericTools(cwd, context = {}) {
|
|
199
|
-
const env = context.env || process.env;
|
|
200
|
-
const exists = context.commandExists || commandExists;
|
|
201
|
-
const packageJson = safeReadJsonFile(path.join(cwd, "package.json")) || {};
|
|
202
|
-
const scripts = packageJson.scripts || {};
|
|
203
|
-
const testScripts = ["test", "build", "lint", "typecheck"].filter((name) => typeof scripts[name] === "string");
|
|
204
|
-
const generic = [];
|
|
205
|
-
|
|
206
|
-
generic.push(buildBaseToolRecord({
|
|
207
|
-
toolId: "test_runner",
|
|
208
|
-
label: "Local test runner",
|
|
209
|
-
providerId: "local",
|
|
210
|
-
installStatus: testScripts.length > 0 ? "configured" : "available",
|
|
211
|
-
availability: testScripts.length > 0 ? "confirmed" : "configured",
|
|
212
|
-
supportedRoles: ["verify"],
|
|
213
|
-
costTier: "free_local",
|
|
214
|
-
qualityTier: "highest",
|
|
215
|
-
trustTier: "local",
|
|
216
|
-
privacyTier: "local_only",
|
|
217
|
-
latencyTier: "medium",
|
|
218
|
-
executionMode: "direct",
|
|
219
|
-
details: { packageScripts: testScripts },
|
|
220
|
-
safeForHighRisk: true,
|
|
221
|
-
}));
|
|
222
|
-
|
|
223
|
-
generic.push(buildBaseToolRecord({
|
|
224
|
-
toolId: "git",
|
|
225
|
-
label: "Git",
|
|
226
|
-
providerId: "local",
|
|
227
|
-
installStatus: exists("git", env) ? "configured" : "not_installed",
|
|
228
|
-
availability: exists("git", env) ? "confirmed" : "unavailable",
|
|
229
|
-
supportedRoles: ["status", "diff", "proof", "verify"],
|
|
230
|
-
costTier: "free_local",
|
|
231
|
-
qualityTier: "highest",
|
|
232
|
-
trustTier: "local",
|
|
233
|
-
privacyTier: "local_only",
|
|
234
|
-
latencyTier: "fast",
|
|
235
|
-
executionMode: "direct",
|
|
236
|
-
safeForHighRisk: true,
|
|
237
|
-
}));
|
|
238
|
-
|
|
239
|
-
const litellmFiles = [
|
|
240
|
-
"litellm.config.yaml",
|
|
241
|
-
"litellm.config.yml",
|
|
242
|
-
".litellm.json",
|
|
243
|
-
"requesty.config.json",
|
|
244
|
-
].filter((relPath) => fs.existsSync(path.join(cwd, relPath)));
|
|
245
|
-
const litellmModel = env.LITELLM_MODEL || env.REQUESTY_MODEL || null;
|
|
246
|
-
const litellmModels = litellmModel ? [
|
|
247
|
-
inferModelRecord({
|
|
248
|
-
toolId: "litellm_requesty",
|
|
249
|
-
providerId: "gateway",
|
|
250
|
-
modelId: litellmModel,
|
|
251
|
-
availability: "configured",
|
|
252
|
-
source: env.LITELLM_MODEL || env.REQUESTY_MODEL ? "env" : "config",
|
|
253
|
-
trustTier: "unknown",
|
|
254
|
-
privacyTier: "gateway_remote",
|
|
255
|
-
confidence: "low",
|
|
256
|
-
}),
|
|
257
|
-
] : [];
|
|
258
|
-
generic.push(buildBaseToolRecord({
|
|
259
|
-
toolId: "litellm_requesty",
|
|
260
|
-
label: "LiteLLM / Requesty",
|
|
261
|
-
providerId: "gateway",
|
|
262
|
-
installStatus: litellmFiles.length > 0 || envPresence(env, "LITELLM_MODEL") || envPresence(env, "REQUESTY_MODEL") ? "configured" : "not_installed",
|
|
263
|
-
availability: litellmFiles.length > 0 || envPresence(env, "LITELLM_MODEL") || envPresence(env, "REQUESTY_MODEL") ? "configured" : "unavailable",
|
|
264
|
-
activeModel: litellmModel,
|
|
265
|
-
configuredModelSource: env.LITELLM_MODEL ? "env:LITELLM_MODEL" : (env.REQUESTY_MODEL ? "env:REQUESTY_MODEL" : null),
|
|
266
|
-
models: litellmModels,
|
|
267
|
-
supportedRoles: ["planning", "implementation", "docs", "tests"],
|
|
268
|
-
costTier: "medium",
|
|
269
|
-
qualityTier: "unknown",
|
|
270
|
-
trustTier: "unknown",
|
|
271
|
-
privacyTier: "gateway_remote",
|
|
272
|
-
latencyTier: "medium",
|
|
273
|
-
details: {
|
|
274
|
-
configFiles: litellmFiles,
|
|
275
|
-
gatewayKeyPresent: envPresence(env, "LITELLM_API_KEY") || envPresence(env, "REQUESTY_API_KEY"),
|
|
276
|
-
},
|
|
277
|
-
}));
|
|
278
|
-
|
|
279
|
-
return generic;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function observedModelCandidates(cwd, options = {}) {
|
|
283
|
-
const env = options.env || process.env;
|
|
284
|
-
const candidates = [];
|
|
285
|
-
const map = [
|
|
286
|
-
["CODEX_MODEL", "codex", "openai"],
|
|
287
|
-
["OPENAI_MODEL", "codex", "openai"],
|
|
288
|
-
["ANTHROPIC_MODEL", "claude_code", "anthropic"],
|
|
289
|
-
["GEMINI_MODEL", "gemini_cli", "google"],
|
|
290
|
-
["OPENCODE_MODEL", "opencode", options.env?.OPENCODE_PROVIDER || "opencode"],
|
|
291
|
-
["AIDER_MODEL", "aider", "aider"],
|
|
292
|
-
["OLLAMA_MODEL", "ollama", "local"],
|
|
293
|
-
["LM_STUDIO_MODEL", "lm_studio", "local"],
|
|
294
|
-
["LMSTUDIO_MODEL", "lm_studio", "local"],
|
|
295
|
-
];
|
|
296
|
-
map.forEach(([name, toolId, providerId]) => {
|
|
297
|
-
if (env[name]) candidates.push({ toolId, providerId, modelId: env[name], source: `env:${name}` });
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
const claudeSettings = safeReadJsonFile(path.join(cwd, ".claude", "settings.json"));
|
|
301
|
-
const claudeLocalSettings = safeReadJsonFile(path.join(cwd, ".claude", "settings.local.json"));
|
|
302
|
-
const codexSettings = safeReadJsonFile(path.join(cwd, ".codex", "config.json")) || safeReadJsonFile(path.join(cwd, ".codex", "settings.json"));
|
|
303
|
-
const opencodeSettings = safeReadJsonFile(path.join(cwd, ".opencode", "config.json"));
|
|
304
|
-
const aiderSettings = safeReadJsonFile(path.join(cwd, ".aider.model.settings.json"));
|
|
305
|
-
const configFiles = [
|
|
306
|
-
[findFirstModelValue(claudeLocalSettings) || findFirstModelValue(claudeSettings), "claude_code", "anthropic", "config"],
|
|
307
|
-
[findFirstModelValue(codexSettings), "codex", "openai", "config"],
|
|
308
|
-
[findFirstModelValue(opencodeSettings), "opencode", "opencode", "config"],
|
|
309
|
-
[findFirstModelValue(aiderSettings), "aider", "aider", "config"],
|
|
310
|
-
];
|
|
311
|
-
configFiles.forEach(([modelId, toolId, providerId, source]) => {
|
|
312
|
-
if (modelId) candidates.push({ toolId, providerId, modelId, source });
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
const proofs = readLatestRunProofs(cwd, 20);
|
|
316
|
-
proofs.forEach(({ proof }) => {
|
|
317
|
-
(proof?.toolsUsed || []).forEach((tool) => {
|
|
318
|
-
const modelId = tool.actualModelUsed || tool.selectedModel || tool.activeModel || tool.modelId || null;
|
|
319
|
-
const providerId = tool.providerId || tool.provider || "unknown";
|
|
320
|
-
if (tool.toolId && modelId) {
|
|
321
|
-
candidates.push({ toolId: tool.toolId, providerId, modelId, source: "observed_usage" });
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
return candidates;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function mergeObservedModels(inventory, observed, reason = "new_model_observed") {
|
|
330
|
-
const next = { ...inventory, tools: (inventory.tools || []).map((tool) => ({ ...tool, models: (tool.models || []).slice() })) };
|
|
331
|
-
const existingKeys = new Set(next.knownModelKeys || []);
|
|
332
|
-
let changed = false;
|
|
333
|
-
observed.forEach((candidate) => {
|
|
334
|
-
const key = createModelKey(candidate.toolId, candidate.providerId, candidate.modelId);
|
|
335
|
-
if (existingKeys.has(key)) return;
|
|
336
|
-
const tool = next.tools.find((entry) => entry.toolId === candidate.toolId);
|
|
337
|
-
if (!tool) return;
|
|
338
|
-
tool.models = tool.models || [];
|
|
339
|
-
const inferred = inferModelRecord({
|
|
340
|
-
toolId: candidate.toolId,
|
|
341
|
-
providerId: candidate.providerId,
|
|
342
|
-
modelId: candidate.modelId,
|
|
343
|
-
availability: "candidate",
|
|
344
|
-
source: candidate.source || "observed_usage",
|
|
345
|
-
trustTier: tool.trustTier,
|
|
346
|
-
privacyTier: tool.privacyTier,
|
|
347
|
-
confidence: "low",
|
|
348
|
-
metadata: { notes: [reason] },
|
|
349
|
-
});
|
|
350
|
-
tool.models.push(inferred);
|
|
351
|
-
tool.availableModels = tool.models.map((model) => ({ id: model.modelId, availability: model.availability }));
|
|
352
|
-
if (!tool.activeModel) tool.activeModel = candidate.modelId;
|
|
353
|
-
existingKeys.add(key);
|
|
354
|
-
changed = true;
|
|
355
|
-
});
|
|
356
|
-
if (changed) {
|
|
357
|
-
next.knownModelKeys = Array.from(existingKeys).sort();
|
|
358
|
-
next.lastRefreshReason = reason;
|
|
359
|
-
next.refreshLevel = "single_model";
|
|
360
|
-
next.inventorySource = "partial";
|
|
361
|
-
}
|
|
362
|
-
return { inventory: next, changed };
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function discoverToolSet(cwd, options = {}) {
|
|
366
|
-
const context = {
|
|
367
|
-
env: options.env || process.env,
|
|
368
|
-
commandExists: options.commandExists || commandExists,
|
|
369
|
-
commandRunner: options.commandRunner,
|
|
370
|
-
httpGetJson: options.httpGetJson,
|
|
371
|
-
surface: options.surface || "avorelo_cli",
|
|
372
|
-
homeDir: options.homeDir,
|
|
373
|
-
refreshLevel: options.refreshLevel || "full",
|
|
374
|
-
tryNativeLmStudio: options.deepRefresh === true,
|
|
375
|
-
};
|
|
376
|
-
const tools = [
|
|
377
|
-
claudeCode.discover(cwd, context),
|
|
378
|
-
codex.discover(cwd, context),
|
|
379
|
-
gemini.discover(cwd, context),
|
|
380
|
-
lmStudio.discover(cwd, context),
|
|
381
|
-
opencode.discover(cwd, context),
|
|
382
|
-
aider.discover(cwd, context),
|
|
383
|
-
ollama.discover(cwd, context),
|
|
384
|
-
openrouter.discover(cwd, context),
|
|
385
|
-
...discoverGenericTools(cwd, context),
|
|
386
|
-
];
|
|
387
|
-
return tools;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function buildInventory(cwd, options = {}) {
|
|
391
|
-
ensureOrchestrationDirs(cwd);
|
|
392
|
-
const config = options.config || readProjectConfig(cwd);
|
|
393
|
-
const history = aggregateRecentHistory(cwd);
|
|
394
|
-
const failures = activeFailures(cwd);
|
|
395
|
-
const tools = discoverToolSet(cwd, options).map((tool) => applyHistoryAndSettings(tool, config, history, failures));
|
|
396
|
-
const policy = defaultRefreshPolicy(config.orchestration);
|
|
397
|
-
const now = new Date().toISOString();
|
|
398
|
-
const knownModelKeys = tools.flatMap((tool) => (tool.models || []).map((model) => createModelKey(tool.toolId, model.providerId, model.modelId)));
|
|
399
|
-
return {
|
|
400
|
-
schemaVersion: INVENTORY_SCHEMA_VERSION,
|
|
401
|
-
generatedAt: now,
|
|
402
|
-
lastFullModelRefreshAt: now,
|
|
403
|
-
nextFullModelRefreshAfter: nextRefreshAfter(now, policy),
|
|
404
|
-
refreshPolicy: policy,
|
|
405
|
-
knownModelKeys: Array.from(new Set(knownModelKeys)).sort(),
|
|
406
|
-
lastRefreshReason: options.lastRefreshReason || "explicit_refresh",
|
|
407
|
-
refreshLevel: options.refreshLevel || "full",
|
|
408
|
-
inventorySource: options.inventorySource || "rebuilt",
|
|
409
|
-
cwd,
|
|
410
|
-
tools,
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function rehydrateCachedInventory(cwd, cached, config) {
|
|
415
|
-
const history = aggregateRecentHistory(cwd);
|
|
416
|
-
const failures = activeFailures(cwd);
|
|
417
|
-
return {
|
|
418
|
-
...cached,
|
|
419
|
-
tools: (cached.tools || []).map((tool) => applyHistoryAndSettings(tool, config, history, failures)),
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function discoverInventory(cwd, options = {}) {
|
|
424
|
-
const config = options.config || readProjectConfig(cwd);
|
|
425
|
-
const current = getCurrentPaths(cwd);
|
|
426
|
-
const cached = safeReadJson(current.inventory, null);
|
|
427
|
-
const refresh = determineRefreshDecision(cached, config.orchestration, options);
|
|
428
|
-
const observed = observedModelCandidates(cwd, options);
|
|
429
|
-
|
|
430
|
-
if (refresh.refreshLevel === "cache" && cached) {
|
|
431
|
-
const rehydrated = rehydrateCachedInventory(cwd, cached, config);
|
|
432
|
-
rehydrated.inventorySource = "cache";
|
|
433
|
-
rehydrated.refreshLevel = "cache";
|
|
434
|
-
const merged = mergeObservedModels(rehydrated, observed);
|
|
435
|
-
if (merged.changed && refresh.policy.singleModelRefreshOnNewUsage) {
|
|
436
|
-
const changedToolIds = new Set((merged.inventory.tools || []).flatMap((tool) => (tool.models || []).filter((model) => (model.notes || []).includes("new_model_observed")).map(() => tool.toolId)));
|
|
437
|
-
if (changedToolIds.size > 0) {
|
|
438
|
-
const lock = tryAcquireRefreshLock(cwd);
|
|
439
|
-
if (lock.ok) {
|
|
440
|
-
try {
|
|
441
|
-
const rebuilt = buildInventory(cwd, {
|
|
442
|
-
...options,
|
|
443
|
-
refreshLevel: "single_model",
|
|
444
|
-
inventorySource: "partial",
|
|
445
|
-
lastRefreshReason: "new_model_observed",
|
|
446
|
-
});
|
|
447
|
-
const hydrated = mergeObservedModels(rebuilt, observed).inventory;
|
|
448
|
-
writeJson(current.inventory, hydrated);
|
|
449
|
-
return hydrated;
|
|
450
|
-
} finally {
|
|
451
|
-
releaseRefreshLock(cwd);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
if (merged.changed || JSON.stringify(rehydrated) !== JSON.stringify(cached)) writeJson(current.inventory, merged.inventory);
|
|
457
|
-
return merged.inventory;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
const lock = tryAcquireRefreshLock(cwd);
|
|
461
|
-
if (!lock.ok && cached) return cached;
|
|
462
|
-
try {
|
|
463
|
-
const inventory = buildInventory(cwd, {
|
|
464
|
-
...options,
|
|
465
|
-
refreshLevel: refresh.refreshLevel,
|
|
466
|
-
inventorySource: refresh.inventorySource,
|
|
467
|
-
lastRefreshReason: refresh.lastRefreshReason,
|
|
468
|
-
});
|
|
469
|
-
const finalInventory = mergeObservedModels(inventory, observed, refresh.lastRefreshReason === "explicit_refresh" ? "new_model_observed" : refresh.lastRefreshReason).inventory;
|
|
470
|
-
writeJson(current.inventory, finalInventory);
|
|
471
|
-
return finalInventory;
|
|
472
|
-
} finally {
|
|
473
|
-
releaseRefreshLock(cwd);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function summarizeInventoryForText(inventory) {
|
|
478
|
-
const tools = Array.isArray(inventory?.tools) ? inventory.tools : [];
|
|
479
|
-
return {
|
|
480
|
-
total: tools.length,
|
|
481
|
-
available: tools.filter((tool) => ["confirmed", "configured", "recently_failed", "recently_limited", "needs_login"].includes(tool.availability)).length,
|
|
482
|
-
enabled: tools.filter((tool) => tool.enabled).length,
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
function loadInventory(cwd, options = {}) {
|
|
487
|
-
return discoverInventory(cwd, options);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
module.exports = {
|
|
491
|
-
INVENTORY_SCHEMA_VERSION,
|
|
492
|
-
loadInventory,
|
|
493
|
-
discoverInventory,
|
|
494
|
-
summarizeInventoryForText,
|
|
495
|
-
recordWorkerFailure,
|
|
496
|
-
classifyFailureReason,
|
|
497
|
-
mergeObservedModels,
|
|
498
|
-
};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function normalizeModelId(value) {
|
|
4
|
-
return String(value || "").trim();
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function normalizeModelIdLower(value) {
|
|
8
|
-
return normalizeModelId(value).toLowerCase();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function createModelKey(toolId, providerId, modelId) {
|
|
12
|
-
return `${toolId}:${providerId}:${modelId}`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function inferProfilesFromModelId(modelId, displayName = "", metadata = {}) {
|
|
16
|
-
const text = `${modelId || ""} ${displayName || ""} ${metadata.family || ""} ${(metadata.families || []).join(" ")}`.toLowerCase();
|
|
17
|
-
const profiles = new Set();
|
|
18
|
-
|
|
19
|
-
if (/(mini|flash|lite|small|nano)/i.test(text)) profiles.add("fast_low_cost");
|
|
20
|
-
if (/(pro|sonnet|default)/i.test(text)) profiles.add("standard_quality");
|
|
21
|
-
if (/(opus|deep|reasoning|thinking|high|5\.5|xhigh)/i.test(text)) profiles.add("deep_reasoning");
|
|
22
|
-
if (/(coder|code|codestral|devstral|qwen-coder|deepseek-coder|codellama|starcoder|deepseek|qwen)/i.test(text)) profiles.add("coding_candidate");
|
|
23
|
-
if (/(embedding|embed)/i.test(text)) profiles.add("not_chat_worker");
|
|
24
|
-
if (/(vision|multimodal|vl)/i.test(text)) profiles.add("vision_capable");
|
|
25
|
-
if (/(instruct|chat)/i.test(text)) profiles.add("chat_candidate");
|
|
26
|
-
|
|
27
|
-
return Array.from(profiles);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function inferContextTier(metadata = {}) {
|
|
31
|
-
const context = Number(metadata.contextWindow || metadata.context_length || metadata.max_context || 0);
|
|
32
|
-
if (!Number.isFinite(context) || context <= 0) return "unknown";
|
|
33
|
-
if (context < 16000) return "small";
|
|
34
|
-
if (context < 64000) return "medium";
|
|
35
|
-
if (context < 200000) return "large";
|
|
36
|
-
return "very_large";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function inferLatencyTier({ providerId, modelId }) {
|
|
40
|
-
const text = normalizeModelIdLower(modelId);
|
|
41
|
-
if (providerId === "local") return "fast";
|
|
42
|
-
if (/(mini|flash|lite|small|nano)/.test(text)) return "fast";
|
|
43
|
-
if (/(opus|deep|reasoning|thinking|5\.5|xhigh)/.test(text)) return "slow";
|
|
44
|
-
if (!text) return "unknown";
|
|
45
|
-
return "medium";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function inferCostTier({ providerId, profiles = [], trustedRemote = false }) {
|
|
49
|
-
if (providerId === "local" || providerId === "ollama" || providerId === "lm_studio") return "free_local";
|
|
50
|
-
if (profiles.includes("fast_low_cost")) return "low";
|
|
51
|
-
if (profiles.includes("deep_reasoning")) return "high";
|
|
52
|
-
if (trustedRemote) return "medium";
|
|
53
|
-
return "unknown";
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function inferQualityTier({ profiles = [], providerId }) {
|
|
57
|
-
if (profiles.includes("deep_reasoning")) return "highest";
|
|
58
|
-
if (profiles.includes("standard_quality")) return "high";
|
|
59
|
-
if (profiles.includes("fast_low_cost")) return "medium";
|
|
60
|
-
if (providerId === "local") return "unknown";
|
|
61
|
-
return "unknown";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function defaultRolesForProfiles({ profiles = [], trustTier, privacyTier }) {
|
|
65
|
-
if (profiles.includes("not_chat_worker")) return [];
|
|
66
|
-
|
|
67
|
-
const roles = new Set(["planning", "summaries", "docs"]);
|
|
68
|
-
if (profiles.includes("chat_candidate")) roles.add("planning");
|
|
69
|
-
if (profiles.includes("coding_candidate")) roles.add("cheap_build");
|
|
70
|
-
if (privacyTier === "local_only") roles.add("local_private");
|
|
71
|
-
if (trustTier === "trusted" || trustTier === "local") roles.add("repo_reading");
|
|
72
|
-
return Array.from(roles);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function inferModelRecord({
|
|
76
|
-
toolId,
|
|
77
|
-
providerId,
|
|
78
|
-
modelId,
|
|
79
|
-
displayName = null,
|
|
80
|
-
availability = "candidate",
|
|
81
|
-
source = "inferred",
|
|
82
|
-
trustTier = "unknown",
|
|
83
|
-
privacyTier = "unknown",
|
|
84
|
-
metadata = {},
|
|
85
|
-
confidence = "low",
|
|
86
|
-
observedAt = null,
|
|
87
|
-
}) {
|
|
88
|
-
const normalized = normalizeModelId(modelId);
|
|
89
|
-
const firstSeenAt = observedAt || new Date().toISOString();
|
|
90
|
-
const profiles = inferProfilesFromModelId(normalized, displayName, metadata);
|
|
91
|
-
const localLike = trustTier === "local" || privacyTier === "local_only";
|
|
92
|
-
const trustedRemote = trustTier === "trusted";
|
|
93
|
-
const costTier = inferCostTier({ providerId, profiles, trustedRemote });
|
|
94
|
-
const qualityTier = inferQualityTier({ profiles, providerId });
|
|
95
|
-
const safeForHighRisk = Boolean(
|
|
96
|
-
!profiles.includes("not_chat_worker")
|
|
97
|
-
&& (trustTier === "local" || (trustTier === "trusted" && privacyTier === "trusted_remote"))
|
|
98
|
-
&& availability === "confirmed"
|
|
99
|
-
&& confidence !== "low"
|
|
100
|
-
&& !profiles.includes("fast_low_cost")
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
toolId,
|
|
105
|
-
providerId,
|
|
106
|
-
modelId: normalized,
|
|
107
|
-
displayName: displayName || normalized,
|
|
108
|
-
availability,
|
|
109
|
-
source,
|
|
110
|
-
profiles,
|
|
111
|
-
costTier,
|
|
112
|
-
qualityTier,
|
|
113
|
-
trustTier,
|
|
114
|
-
privacyTier,
|
|
115
|
-
latencyTier: inferLatencyTier({ providerId, modelId: normalized }),
|
|
116
|
-
contextTier: inferContextTier(metadata),
|
|
117
|
-
supportsTools: metadata.supportsTools === true,
|
|
118
|
-
supportsStructuredOutput: metadata.supportsStructuredOutput === true,
|
|
119
|
-
supportsVision: profiles.includes("vision_capable") || metadata.supportsVision === true,
|
|
120
|
-
supportsReasoning: profiles.includes("deep_reasoning") || metadata.supportsReasoning === true,
|
|
121
|
-
safeForHighRisk,
|
|
122
|
-
confidence,
|
|
123
|
-
firstSeenAt,
|
|
124
|
-
lastSeenAt: firstSeenAt,
|
|
125
|
-
lastCheckedAt: firstSeenAt,
|
|
126
|
-
lastFailure: null,
|
|
127
|
-
recentSuccessScore: 0,
|
|
128
|
-
recentFailureScore: 0,
|
|
129
|
-
notes: metadata.notes || [],
|
|
130
|
-
roles: defaultRolesForProfiles({ profiles, trustTier: localLike ? "local" : trustTier, privacyTier }),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function mergeModelRecord(previous, next) {
|
|
135
|
-
if (!previous) return next;
|
|
136
|
-
return {
|
|
137
|
-
...previous,
|
|
138
|
-
...next,
|
|
139
|
-
firstSeenAt: previous.firstSeenAt || next.firstSeenAt,
|
|
140
|
-
lastSeenAt: next.lastSeenAt || previous.lastSeenAt,
|
|
141
|
-
lastCheckedAt: next.lastCheckedAt || previous.lastCheckedAt,
|
|
142
|
-
profiles: Array.from(new Set([...(previous.profiles || []), ...(next.profiles || [])])),
|
|
143
|
-
roles: Array.from(new Set([...(previous.roles || []), ...(next.roles || [])])),
|
|
144
|
-
notes: Array.from(new Set([...(previous.notes || []), ...(next.notes || [])])),
|
|
145
|
-
recentSuccessScore: Number(previous.recentSuccessScore || 0) + Number(next.recentSuccessScore || 0),
|
|
146
|
-
recentFailureScore: Number(previous.recentFailureScore || 0) + Number(next.recentFailureScore || 0),
|
|
147
|
-
lastFailure: next.lastFailure || previous.lastFailure || null,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function buildProfileSummary(toolId, activeModel) {
|
|
152
|
-
const modelId = normalizeModelId(activeModel);
|
|
153
|
-
if (!modelId) return [];
|
|
154
|
-
return inferProfilesFromModelId(modelId).map((profileId) => ({
|
|
155
|
-
id: profileId,
|
|
156
|
-
provider: toolId,
|
|
157
|
-
label: profileId.replace(/_/g, " "),
|
|
158
|
-
availability: "confirmed",
|
|
159
|
-
}));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
module.exports = {
|
|
163
|
-
normalizeModelId,
|
|
164
|
-
normalizeModelIdLower,
|
|
165
|
-
createModelKey,
|
|
166
|
-
inferProfilesFromModelId,
|
|
167
|
-
inferModelRecord,
|
|
168
|
-
mergeModelRecord,
|
|
169
|
-
buildProfileSummary,
|
|
170
|
-
};
|