avorelo 0.1.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 +21 -0
- package/README.md +56 -0
- package/bin/avorelo +9 -0
- package/package.json +135 -0
- package/scripts/README.md +40 -0
- package/scripts/cco-dashboard.js +252 -0
- package/scripts/cco-status.js +430 -0
- package/scripts/lib/activation/account-state.js +37 -0
- package/scripts/lib/activation/activation-runner.js +546 -0
- package/scripts/lib/activation/activation-self-healing.js +480 -0
- package/scripts/lib/activation/activation-state.js +83 -0
- package/scripts/lib/activation/activation-summary.js +191 -0
- package/scripts/lib/activation/adapters/claude-code.js +77 -0
- package/scripts/lib/activation/adapters/codex-cli.js +52 -0
- package/scripts/lib/activation/adapters/cursor.js +37 -0
- package/scripts/lib/activation/adapters/github-agent.js +39 -0
- package/scripts/lib/activation/adapters/terminal.js +42 -0
- package/scripts/lib/activation/adapters/vscode.js +39 -0
- package/scripts/lib/activation/adapters/windsurf.js +37 -0
- package/scripts/lib/activation/ai-surface-detector.js +151 -0
- package/scripts/lib/activation/connect-account.js +145 -0
- package/scripts/lib/activation/detect-environment.js +75 -0
- package/scripts/lib/activation/detect-hosts.js +62 -0
- package/scripts/lib/activation/format-activation-output.js +109 -0
- package/scripts/lib/activation/next-action.js +43 -0
- package/scripts/lib/activation/repair-engine.js +219 -0
- package/scripts/lib/activation-distribution-readiness.js +507 -0
- package/scripts/lib/adapter-conformance.js +176 -0
- package/scripts/lib/adapter-readiness.js +417 -0
- package/scripts/lib/adapter-safety-boundaries.js +335 -0
- package/scripts/lib/adapter-technical-readiness-gate.js +205 -0
- package/scripts/lib/agent-access-governance.js +455 -0
- package/scripts/lib/agent-enforcement.js +765 -0
- package/scripts/lib/agent-policy-profile.js +210 -0
- package/scripts/lib/agent-security/action-evaluator.js +507 -0
- package/scripts/lib/agent-security/adapter-registry.js +98 -0
- package/scripts/lib/agent-security/auto-policy.js +139 -0
- package/scripts/lib/agent-security/bounded-scan.js +93 -0
- package/scripts/lib/agent-security/enforcement-adapter.js +174 -0
- package/scripts/lib/agent-security/enforcement-engine.js +1129 -0
- package/scripts/lib/agent-security/file-write-adapter.js +183 -0
- package/scripts/lib/agent-security/file-write-rules.js +178 -0
- package/scripts/lib/agent-security/index.js +3342 -0
- package/scripts/lib/agent-security/instruction-risk.js +181 -0
- package/scripts/lib/agent-security/mcp-action-adapter.js +185 -0
- package/scripts/lib/agent-security/mcp-action-rules.js +184 -0
- package/scripts/lib/agent-security/package-action-adapter.js +175 -0
- package/scripts/lib/agent-security/package-action-rules.js +233 -0
- package/scripts/lib/agent-security/performance.js +148 -0
- package/scripts/lib/agent-security/permission-minimizer.js +403 -0
- package/scripts/lib/agent-security/scan-cache.js +74 -0
- package/scripts/lib/agent-security/source-trust.js +146 -0
- package/scripts/lib/ai-install-prompt.js +288 -0
- package/scripts/lib/ai-workspace-hygiene.js +1499 -0
- package/scripts/lib/alpha-activation.js +520 -0
- package/scripts/lib/alpha-feedback.js +263 -0
- package/scripts/lib/alpha-readiness-gate.js +332 -0
- package/scripts/lib/anti-gaming.js +169 -0
- package/scripts/lib/artifact-health.js +431 -0
- package/scripts/lib/attribution.js +180 -0
- package/scripts/lib/audit.js +289 -0
- package/scripts/lib/avorelo-skill-registry.js +810 -0
- package/scripts/lib/batch-jobs.js +71 -0
- package/scripts/lib/brain-pack.js +578 -0
- package/scripts/lib/brand-boundary.js +424 -0
- package/scripts/lib/brand.js +74 -0
- package/scripts/lib/browser-capability.js +1048 -0
- package/scripts/lib/browser-proof-preflight.js +321 -0
- package/scripts/lib/cache-readiness.js +187 -0
- package/scripts/lib/canonical-reentry.js +162 -0
- package/scripts/lib/capability-packs.js +314 -0
- package/scripts/lib/capability-recommender.js +512 -0
- package/scripts/lib/capability-registry.js +1059 -0
- package/scripts/lib/carry-forward-surfacing.js +194 -0
- package/scripts/lib/ccusage-adapter.js +188 -0
- package/scripts/lib/company-loop.js +1149 -0
- package/scripts/lib/config.js +637 -0
- package/scripts/lib/context-acquisition-plan.js +287 -0
- package/scripts/lib/context-budget-guard.js +170 -0
- package/scripts/lib/context-budget-scanner.js +257 -0
- package/scripts/lib/context-optimizer.js +715 -0
- package/scripts/lib/context-reduction-plan.js +178 -0
- package/scripts/lib/context-safety.js +88 -0
- package/scripts/lib/context-savings-engine.js +158 -0
- package/scripts/lib/cost-evidence.js +254 -0
- package/scripts/lib/cross-host-install-plan.js +308 -0
- package/scripts/lib/cross-host-install-readiness.js +237 -0
- package/scripts/lib/cross-host-value-flow.js +268 -0
- package/scripts/lib/dashboard.js +900 -0
- package/scripts/lib/design-partner-feedback.js +346 -0
- package/scripts/lib/entitlements.js +100 -0
- package/scripts/lib/execution-packet.js +559 -0
- package/scripts/lib/experimentation-events.js +547 -0
- package/scripts/lib/external-capability-compliance.js +107 -0
- package/scripts/lib/external-user-simulation.js +166 -0
- package/scripts/lib/failure-recovery-readiness.js +81 -0
- package/scripts/lib/failure-recovery.js +419 -0
- package/scripts/lib/feedback-intelligence.js +537 -0
- package/scripts/lib/feedback-signals.js +205 -0
- package/scripts/lib/file-integrity.js +68 -0
- package/scripts/lib/fsx.js +127 -0
- package/scripts/lib/full-readiness-gate.js +451 -0
- package/scripts/lib/guidance-builder.js +174 -0
- package/scripts/lib/hook-apply.js +1019 -0
- package/scripts/lib/hook-baseline.js +310 -0
- package/scripts/lib/hook-config-preview.js +275 -0
- package/scripts/lib/hook-contracts.js +290 -0
- package/scripts/lib/hook-safety-boundary-readiness.js +80 -0
- package/scripts/lib/host-capability-matrix.js +351 -0
- package/scripts/lib/host-support-context.js +254 -0
- package/scripts/lib/http-hook-action.js +538 -0
- package/scripts/lib/install-ai-readiness.js +84 -0
- package/scripts/lib/install-intake-risk.js +1037 -0
- package/scripts/lib/install-journey-intelligence.js +329 -0
- package/scripts/lib/intervention-guidance.js +57 -0
- package/scripts/lib/known-limitations.js +115 -0
- package/scripts/lib/l8-path-truth.js +146 -0
- package/scripts/lib/launch-hardening-gate.js +436 -0
- package/scripts/lib/launch-readiness.js +628 -0
- package/scripts/lib/learning-memory.js +686 -0
- package/scripts/lib/lifecycle-hooks.js +802 -0
- package/scripts/lib/local-package-smoke.js +423 -0
- package/scripts/lib/local-pricing.js +299 -0
- package/scripts/lib/mcp-enforcement.js +311 -0
- package/scripts/lib/mcp-least-privilege-policy.js +303 -0
- package/scripts/lib/mcp-tool-inventory.js +388 -0
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +335 -0
- package/scripts/lib/metrics.js +699 -0
- package/scripts/lib/micro-proof.js +133 -0
- package/scripts/lib/next-run-context.js +436 -0
- package/scripts/lib/operating-value.js +1648 -0
- package/scripts/lib/optimization-v3.js +122 -0
- package/scripts/lib/orchestration/adapters/_shared.js +49 -0
- package/scripts/lib/orchestration/adapters/aider.js +18 -0
- package/scripts/lib/orchestration/adapters/claude-code.js +35 -0
- package/scripts/lib/orchestration/adapters/codex.js +35 -0
- package/scripts/lib/orchestration/adapters/gemini-cli.js +18 -0
- package/scripts/lib/orchestration/adapters/git.js +25 -0
- package/scripts/lib/orchestration/adapters/index.js +31 -0
- package/scripts/lib/orchestration/adapters/lm-studio.js +18 -0
- package/scripts/lib/orchestration/adapters/ollama.js +18 -0
- package/scripts/lib/orchestration/adapters/opencode.js +18 -0
- package/scripts/lib/orchestration/adapters/openrouter.js +18 -0
- package/scripts/lib/orchestration/adapters/test-runner.js +25 -0
- package/scripts/lib/orchestration/cli.js +438 -0
- package/scripts/lib/orchestration/execution-manager.js +279 -0
- package/scripts/lib/orchestration/handoff.js +314 -0
- package/scripts/lib/orchestration/index.js +456 -0
- package/scripts/lib/orchestration/inventory.js +47 -0
- package/scripts/lib/orchestration/model-discovery.js +498 -0
- package/scripts/lib/orchestration/model-profiler.js +170 -0
- package/scripts/lib/orchestration/model-profiles.js +252 -0
- package/scripts/lib/orchestration/model-refresh-policy.js +72 -0
- package/scripts/lib/orchestration/proof-writer.js +349 -0
- package/scripts/lib/orchestration/provider-discovery/aider.js +49 -0
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +56 -0
- package/scripts/lib/orchestration/provider-discovery/codex.js +49 -0
- package/scripts/lib/orchestration/provider-discovery/common.js +186 -0
- package/scripts/lib/orchestration/provider-discovery/gemini.js +106 -0
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +118 -0
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +12 -0
- package/scripts/lib/orchestration/provider-discovery/ollama.js +100 -0
- package/scripts/lib/orchestration/provider-discovery/opencode.js +47 -0
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +44 -0
- package/scripts/lib/orchestration/risk-classifier.js +130 -0
- package/scripts/lib/orchestration/routing-policy.js +486 -0
- package/scripts/lib/orchestration/settings.js +112 -0
- package/scripts/lib/orchestration/state.js +165 -0
- package/scripts/lib/orchestration/verification-manager.js +138 -0
- package/scripts/lib/output-profiles.js +146 -0
- package/scripts/lib/package-content-audit.js +368 -0
- package/scripts/lib/package-runtime.js +278 -0
- package/scripts/lib/plan-surface.js +53 -0
- package/scripts/lib/plans.js +2318 -0
- package/scripts/lib/policy-provider.js +27 -0
- package/scripts/lib/prelaunch-activation-readiness.js +409 -0
- package/scripts/lib/prelaunch-evidence-store.js +816 -0
- package/scripts/lib/prelaunch-intelligence.js +869 -0
- package/scripts/lib/pricing-experiment.js +118 -0
- package/scripts/lib/pro-moment-events.js +77 -0
- package/scripts/lib/pro-moment-state.js +227 -0
- package/scripts/lib/pro-moments.js +1216 -0
- package/scripts/lib/product-learning-events.js +629 -0
- package/scripts/lib/project-profile.js +555 -0
- package/scripts/lib/prompt-compiler.js +280 -0
- package/scripts/lib/prompt-lint.js +32 -0
- package/scripts/lib/prompt-suggestions.js +52 -0
- package/scripts/lib/proof-canonical.js +398 -0
- package/scripts/lib/proof-drilldown.js +383 -0
- package/scripts/lib/proof-events.js +342 -0
- package/scripts/lib/proof-history.js +243 -0
- package/scripts/lib/proof-metrics.js +296 -0
- package/scripts/lib/proof-outcome-evidence.js +134 -0
- package/scripts/lib/proof-receipt.js +335 -0
- package/scripts/lib/proof-record.js +461 -0
- package/scripts/lib/public-activation-distribution-gate.js +258 -0
- package/scripts/lib/public-cli.js +3891 -0
- package/scripts/lib/public-distribution-truth.js +211 -0
- package/scripts/lib/public-install-claim-checker.js +294 -0
- package/scripts/lib/publish-provenance-readiness.js +283 -0
- package/scripts/lib/readiness-delta.js +218 -0
- package/scripts/lib/readiness-evidence-closure.js +196 -0
- package/scripts/lib/reentry-memory-capture.js +241 -0
- package/scripts/lib/reentry-memory-retrieval.js +302 -0
- package/scripts/lib/reentry-memory-status.js +146 -0
- package/scripts/lib/reentry-memory-store.js +178 -0
- package/scripts/lib/reentry-state.js +66 -0
- package/scripts/lib/release-candidate-bundle.js +166 -0
- package/scripts/lib/remediation.js +81 -0
- package/scripts/lib/repo-map.js +391 -0
- package/scripts/lib/run-improvements-lifecycle.js +330 -0
- package/scripts/lib/run-improvements.js +789 -0
- package/scripts/lib/runtime-decision-policy.js +387 -0
- package/scripts/lib/safe-path-engine.js +705 -0
- package/scripts/lib/safe-run-controller.js +887 -0
- package/scripts/lib/score.js +262 -0
- package/scripts/lib/seamless-enforcement.js +329 -0
- package/scripts/lib/seamless-outcome.js +689 -0
- package/scripts/lib/seamless-reality-gate.js +5043 -0
- package/scripts/lib/security-risk-classifier.js +511 -0
- package/scripts/lib/security-scan.js +384 -0
- package/scripts/lib/session-context-optimizer.js +1211 -0
- package/scripts/lib/session-timing.js +315 -0
- package/scripts/lib/skill-hygiene.js +805 -0
- package/scripts/lib/skill-packs.js +161 -0
- package/scripts/lib/skills-operating-layer.js +580 -0
- package/scripts/lib/smart-work-routing.js +768 -0
- package/scripts/lib/source-catalog.js +700 -0
- package/scripts/lib/status-value-summary.js +32 -0
- package/scripts/lib/support-bundle.js +578 -0
- package/scripts/lib/task-continuation.js +440 -0
- package/scripts/lib/test-helpers.js +15 -0
- package/scripts/lib/tier.js +38 -0
- package/scripts/lib/token-context-quality-gate.js +370 -0
- package/scripts/lib/token-cost-capture.js +187 -0
- package/scripts/lib/token-cost-intelligence.js +358 -0
- package/scripts/lib/token-efficiency-evidence.js +213 -0
- package/scripts/lib/token-evidence.js +699 -0
- package/scripts/lib/tokenish.js +17 -0
- package/scripts/lib/tool-output-sandbox.js +304 -0
- package/scripts/lib/trust-audit.js +136 -0
- package/scripts/lib/unified-events.js +396 -0
- package/scripts/lib/upgrade-interruption-recovery.js +407 -0
- package/scripts/lib/usage-ledger.js +201 -0
- package/scripts/lib/value-ledger.js +130 -0
- package/scripts/lib/value-proof-calibration.js +531 -0
- package/scripts/lib/visual-qa.js +231 -0
- package/scripts/lib/voice-alpha.js +29 -0
- package/scripts/lib/work-aware-orchestration.js +976 -0
- package/scripts/lib/work-control-receipts.js +577 -0
- package/scripts/lib/work-ledger.js +1123 -0
- package/scripts/lib/work-panel-preview.js +352 -0
- package/scripts/lib/workflow-discipline.js +280 -0
- package/scripts/lib/workflow-signals.js +419 -0
- package/scripts/lib/workspace-map.js +281 -0
- package/scripts/lib/workspace-registry.js +1367 -0
- package/scripts/lib/workspace-resolver.js +480 -0
|
@@ -0,0 +1,498 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
};
|