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,486 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { detectProfile } = require("./model-profiles");
|
|
4
|
+
|
|
5
|
+
const COST_SCORE = { free_local: 0, local: 0, low: 1, medium: 2, high: 3, premium: 4, highest: 4, unknown: 2 };
|
|
6
|
+
const QUALITY_SCORE = { deterministic: 5, low: 1, medium: 2, medium_high: 3, high: 4, premium: 5, highest: 5, unknown: 1 };
|
|
7
|
+
const TRUST_SCORE = { local: 5, trusted: 4, unknown: 2, external: 1 };
|
|
8
|
+
const PRIVACY_SCORE = { local_only: 5, trusted_remote: 4, gateway_remote: 2, external_remote: 1, unknown: 1 };
|
|
9
|
+
|
|
10
|
+
const FALLBACK_REASON_CODES = {
|
|
11
|
+
WORKER_RECENTLY_LIMITED: "WORKER_RECENTLY_LIMITED",
|
|
12
|
+
WORKER_NEEDS_LOGIN: "WORKER_NEEDS_LOGIN",
|
|
13
|
+
WORKER_RECENTLY_FAILED: "WORKER_RECENTLY_FAILED",
|
|
14
|
+
WORKER_UNAVAILABLE: "WORKER_UNAVAILABLE",
|
|
15
|
+
LOCAL_WORKER_AVAILABLE: "LOCAL_WORKER_AVAILABLE",
|
|
16
|
+
LOCAL_WORKER_NOT_RUNNING: "LOCAL_WORKER_NOT_RUNNING",
|
|
17
|
+
FALLBACK_RECOMMENDED: "FALLBACK_RECOMMENDED",
|
|
18
|
+
ESCALATION_RECOMMENDED: "ESCALATION_RECOMMENDED",
|
|
19
|
+
PREMIUM_CONFIRMATION_REQUIRED: "PREMIUM_CONFIRMATION_REQUIRED",
|
|
20
|
+
LOCAL_PRIVATE_ONLY_MODE: "LOCAL_PRIVATE_ONLY_MODE",
|
|
21
|
+
SENSITIVE_TASK_BLOCKS_EXTERNAL: "SENSITIVE_TASK_BLOCKS_EXTERNAL",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function isExternalTool(tool) {
|
|
25
|
+
return tool.privacyTier === "external_remote" || tool.trustTier === "external" || tool.privacyTier === "gateway_remote";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function supportsRole(tool, role) {
|
|
29
|
+
return Array.isArray(tool.supportedRoles) && tool.supportedRoles.includes(role);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function chooseProfile(tool, task, settings) {
|
|
33
|
+
const profiles = Array.isArray(tool.candidateProfiles) ? tool.candidateProfiles : [];
|
|
34
|
+
const confirmed = profiles.find((profile) => profile.availability === "confirmed");
|
|
35
|
+
if (confirmed) return confirmed;
|
|
36
|
+
if (task.risk === "low" || task.taskType === "docs") {
|
|
37
|
+
return profiles.find((profile) => /fast|mini|cheap|flash|summary|local_private/i.test(profile.id)) || profiles[0] || null;
|
|
38
|
+
}
|
|
39
|
+
if (task.risk === "high") {
|
|
40
|
+
return profiles.find((profile) => /high|reason|opus/i.test(profile.id)) || profiles.find((profile) => /default|coding|sonnet/i.test(profile.id)) || profiles[0] || null;
|
|
41
|
+
}
|
|
42
|
+
return profiles.find((profile) => /default|coding|sonnet|standard/i.test(profile.id)) || profiles[0] || null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function chooseModel(tool, task, settings) {
|
|
46
|
+
const models = Array.isArray(tool.models) ? tool.models : [];
|
|
47
|
+
if (models.length === 0) return null;
|
|
48
|
+
const confirmed = models.filter((model) => model.availability === "confirmed");
|
|
49
|
+
const configured = models.filter((model) => model.availability === "configured");
|
|
50
|
+
const candidate = models.filter((model) => model.availability === "candidate");
|
|
51
|
+
const pool = confirmed.length ? confirmed : (configured.length ? configured : candidate);
|
|
52
|
+
if (task.risk === "high") {
|
|
53
|
+
return pool.find((model) => model.safeForHighRisk) || pool.find((model) => model.qualityTier === "highest" || model.qualityTier === "high") || null;
|
|
54
|
+
}
|
|
55
|
+
if (task.taskType === "docs" || task.risk === "low") {
|
|
56
|
+
return pool.find((model) => model.costTier === "free_local" || model.costTier === "low") || pool[0] || null;
|
|
57
|
+
}
|
|
58
|
+
return pool.find((model) => model.profiles.includes("coding_candidate")) || pool.find((model) => model.qualityTier === "high") || pool[0] || null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function safeForTask(tool, task, settings) {
|
|
62
|
+
const reasons = [];
|
|
63
|
+
if (tool.enabled === false) reasons.push("disabled_by_user");
|
|
64
|
+
if (["unavailable", "missing", "stale"].includes(tool.workerState) || tool.installStatus === "not_installed") reasons.push("unavailable");
|
|
65
|
+
if (tool.workerState === "needs_login" || tool.availability === "needs_login") reasons.push("needs_login");
|
|
66
|
+
if (tool.workerState === "recently_limited") reasons.push("recently_limited");
|
|
67
|
+
if (tool.workerState === "recently_failed") reasons.push("recently_failed");
|
|
68
|
+
if (settings.mode === "disabled" || settings.enabled === false) reasons.push("orchestration_disabled");
|
|
69
|
+
|
|
70
|
+
if (settings.mode === "local_private_only" && tool.privacyTier !== "local_only" && !["git", "test_runner"].includes(tool.toolId)) {
|
|
71
|
+
reasons.push("local_private_only_mode");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (task.risk === "high" && !tool.safeForHighRisk && !["git", "test_runner"].includes(tool.toolId)) {
|
|
75
|
+
reasons.push("not_safe_for_high_risk");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (task.risk === "high" && settings.safety.blockCheapExternalHighRisk && isExternalTool(tool) && ["low", "free_local"].includes(tool.costTier)) {
|
|
79
|
+
reasons.push("cheap_external_blocked_for_high_risk");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (["secret_risk", "customer_data_risk", "security_sensitive"].includes(task.sensitivity)
|
|
83
|
+
&& settings.safety.blockExternalSecrets
|
|
84
|
+
&& isExternalTool(tool)
|
|
85
|
+
&& !["git", "test_runner"].includes(tool.toolId)) {
|
|
86
|
+
reasons.push("external_blocked_for_sensitive_task");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
allowed: reasons.every((reason) => ![
|
|
91
|
+
"disabled_by_user",
|
|
92
|
+
"unavailable",
|
|
93
|
+
"needs_login",
|
|
94
|
+
"orchestration_disabled",
|
|
95
|
+
"local_private_only_mode",
|
|
96
|
+
"not_safe_for_high_risk",
|
|
97
|
+
"cheap_external_blocked_for_high_risk",
|
|
98
|
+
"external_blocked_for_sensitive_task",
|
|
99
|
+
"recently_limited",
|
|
100
|
+
"recently_failed",
|
|
101
|
+
].includes(reason)),
|
|
102
|
+
reasons,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function scoreTool(tool, role, task, settings, surface) {
|
|
107
|
+
if (!supportsRole(tool, role)) return -Infinity;
|
|
108
|
+
const safety = safeForTask(tool, task, settings);
|
|
109
|
+
if (!safety.allowed) return -Infinity;
|
|
110
|
+
|
|
111
|
+
let score = 10;
|
|
112
|
+
const profile = chooseProfile(tool, task, settings);
|
|
113
|
+
const model = chooseModel(tool, task, settings);
|
|
114
|
+
score += QUALITY_SCORE[tool.qualityTier] * (task.risk === "high" ? 3 : 2);
|
|
115
|
+
score -= COST_SCORE[tool.costTier] * (task.risk === "low" ? 2 : 1);
|
|
116
|
+
score += TRUST_SCORE[tool.trustTier] * (task.risk === "high" ? 3 : 1);
|
|
117
|
+
score += PRIVACY_SCORE[tool.privacyTier] * (settings.mode === "local_private_only" ? 3 : 1);
|
|
118
|
+
|
|
119
|
+
if (tool.availability === "confirmed") score += 3;
|
|
120
|
+
if (tool.availability === "configured") score += 2;
|
|
121
|
+
if (tool.executionMode === "in_session") score += 2;
|
|
122
|
+
if (surface === "claude_code" && tool.toolId === "claude_code") score += 2;
|
|
123
|
+
if (surface === "codex_cli" && tool.toolId === "codex") score += 2;
|
|
124
|
+
if (role === "verify" && ["test_runner", "git"].includes(tool.toolId)) score += 6;
|
|
125
|
+
if (task.taskType === "docs" && tool.toolId === "codex" && profile?.id === "fast_mini") score += 8;
|
|
126
|
+
if (["lm_studio", "ollama"].includes(tool.toolId) && settings.mode !== "local_private_only") score -= 6;
|
|
127
|
+
if (task.taskType === "security" && ["claude_code", "codex", "git", "test_runner"].includes(tool.toolId)) score += 4;
|
|
128
|
+
if (task.taskType === "docs" && ["lm_studio", "ollama"].includes(tool.toolId) && settings.mode === "local_private_only") score += 2;
|
|
129
|
+
if (model?.profiles?.includes("coding_candidate") && task.risk !== "high") score += 2;
|
|
130
|
+
if (settings.mode === "prefer_highest_quality") score += QUALITY_SCORE[tool.qualityTier] * 2;
|
|
131
|
+
return score;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function rankTools(tools, role, task, settings, surface) {
|
|
135
|
+
return tools
|
|
136
|
+
.map((tool) => ({
|
|
137
|
+
tool,
|
|
138
|
+
profile: chooseProfile(tool, task, settings),
|
|
139
|
+
model: chooseModel(tool, task, settings),
|
|
140
|
+
score: scoreTool(tool, role, task, settings, surface),
|
|
141
|
+
safety: safeForTask(tool, task, settings),
|
|
142
|
+
}))
|
|
143
|
+
.sort((a, b) => b.score - a.score);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function describeWhyChosen(selected, task, settings, role) {
|
|
147
|
+
const reasons = [];
|
|
148
|
+
reasons.push(`${selected.tool.label} is available for ${role}`);
|
|
149
|
+
if (selected.model?.modelId) reasons.push(`model ${selected.model.modelId} is available`);
|
|
150
|
+
if (task.risk === "high") reasons.push("high-risk work prefers trusted higher-quality paths");
|
|
151
|
+
if (settings.mode === "prefer_lowest_cost" || task.risk === "low") reasons.push("cost was optimized only after safety and capability checks");
|
|
152
|
+
if (settings.mode === "local_private_only") reasons.push("local/private-only mode restricted external routes");
|
|
153
|
+
if (selected.tool.executionMode === "in_session") reasons.push("the current surface can continue without a brittle external handoff");
|
|
154
|
+
if (selected.profile?.id) reasons.push(`profile ${selected.profile.id} matched the task quality/cost target`);
|
|
155
|
+
return reasons;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function describeWhyNotChosen(rankings, selectedToolId) {
|
|
159
|
+
return rankings
|
|
160
|
+
.filter((entry) => entry.tool.toolId !== selectedToolId)
|
|
161
|
+
.slice(0, 6)
|
|
162
|
+
.map((entry) => {
|
|
163
|
+
const safetyReason = entry.safety.reasons[0];
|
|
164
|
+
if (safetyReason) return `${entry.tool.label} was not chosen because ${safetyReason.replace(/_/g, " ")}`;
|
|
165
|
+
return `${entry.tool.label} was available but scored lower for this task`;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function blockedOptions(tools, task, settings) {
|
|
170
|
+
return tools
|
|
171
|
+
.map((tool) => ({ tool, safety: safeForTask(tool, task, settings), model: chooseModel(tool, task, settings) }))
|
|
172
|
+
.filter((entry) => !entry.safety.allowed || entry.safety.reasons.length > 0)
|
|
173
|
+
.map((entry) => ({
|
|
174
|
+
toolId: entry.tool.toolId,
|
|
175
|
+
label: entry.tool.label,
|
|
176
|
+
modelId: entry.model?.modelId || null,
|
|
177
|
+
reasons: entry.safety.reasons,
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function deriveQuotaSignal(tool) {
|
|
182
|
+
if (tool.workerState === "recently_limited") return "limited";
|
|
183
|
+
if (tool.quotaSignal === "local" || tool.costTier === "free_local") return "local";
|
|
184
|
+
if (tool.availability === "confirmed" || tool.availability === "configured") return "healthy";
|
|
185
|
+
return "unknown";
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function deriveFallbackReasonCodes(tools, task, settings) {
|
|
189
|
+
const codes = [];
|
|
190
|
+
const localAvailable = tools.some((t) =>
|
|
191
|
+
["lm_studio", "ollama"].includes(t.toolId) &&
|
|
192
|
+
!["unavailable", "missing"].includes(t.workerState)
|
|
193
|
+
);
|
|
194
|
+
const localNotRunning = tools.some((t) =>
|
|
195
|
+
["lm_studio", "ollama"].includes(t.toolId) &&
|
|
196
|
+
t.installStatus === "installed_or_configured_but_not_running"
|
|
197
|
+
);
|
|
198
|
+
if (localAvailable) codes.push(FALLBACK_REASON_CODES.LOCAL_WORKER_AVAILABLE);
|
|
199
|
+
if (localNotRunning) codes.push(FALLBACK_REASON_CODES.LOCAL_WORKER_NOT_RUNNING);
|
|
200
|
+
|
|
201
|
+
tools.forEach((t) => {
|
|
202
|
+
if (t.workerState === "recently_limited") codes.push(FALLBACK_REASON_CODES.WORKER_RECENTLY_LIMITED);
|
|
203
|
+
if (t.workerState === "needs_login") codes.push(FALLBACK_REASON_CODES.WORKER_NEEDS_LOGIN);
|
|
204
|
+
if (t.workerState === "recently_failed") codes.push(FALLBACK_REASON_CODES.WORKER_RECENTLY_FAILED);
|
|
205
|
+
if (["unavailable", "missing"].includes(t.workerState) && t.toolId !== "test_runner" && t.toolId !== "git") {
|
|
206
|
+
codes.push(FALLBACK_REASON_CODES.WORKER_UNAVAILABLE);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
if (task.risk === "high") codes.push(FALLBACK_REASON_CODES.ESCALATION_RECOMMENDED);
|
|
211
|
+
if (settings.mode === "local_private_only") codes.push(FALLBACK_REASON_CODES.LOCAL_PRIVATE_ONLY_MODE);
|
|
212
|
+
if (["secret_risk", "customer_data_risk", "security_sensitive"].includes(task.sensitivity)) {
|
|
213
|
+
codes.push(FALLBACK_REASON_CODES.SENSITIVE_TASK_BLOCKS_EXTERNAL);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return [...new Set(codes)];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function buildLocalWorkerRecommendation(tools, task) {
|
|
220
|
+
const localWorkers = tools.filter((t) =>
|
|
221
|
+
["lm_studio", "ollama"].includes(t.toolId) &&
|
|
222
|
+
!["unavailable", "missing", "recently_failed"].includes(t.workerState)
|
|
223
|
+
);
|
|
224
|
+
if (!localWorkers.length) return null;
|
|
225
|
+
const available = localWorkers.filter((t) => t.workerState !== "recently_limited");
|
|
226
|
+
if (!available.length) return null;
|
|
227
|
+
const w = available[0];
|
|
228
|
+
return {
|
|
229
|
+
workerId: w.toolId,
|
|
230
|
+
label: w.label,
|
|
231
|
+
recommendedFor: ["inspect", "summarize", "repo_reading", "planning"].filter((role) =>
|
|
232
|
+
(w.supportedRoles || []).includes(role) || ["planning", "summaries", "repo_reading"].some((r) => (w.supportedRoles || []).includes(r))
|
|
233
|
+
),
|
|
234
|
+
costTier: w.costTier,
|
|
235
|
+
quotaSignal: deriveQuotaSignal(w),
|
|
236
|
+
reason: "local worker is available and safe for low-sensitivity inspection/planning stages",
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function buildStage(id, role, selected, fallback, task, settings, routeSummary, extras = {}) {
|
|
241
|
+
return {
|
|
242
|
+
id,
|
|
243
|
+
role,
|
|
244
|
+
state: "pending",
|
|
245
|
+
chosenTool: selected.tool.toolId,
|
|
246
|
+
chosenLabel: selected.tool.label,
|
|
247
|
+
chosenModel: selected.model?.modelId || selected.tool.activeModel || null,
|
|
248
|
+
chosenModelProfile: selected.profile?.id || selected.tool.activeProfile || selected.tool.activeModel || "unknown",
|
|
249
|
+
executionMode: selected.tool.executionMode,
|
|
250
|
+
fallbackTool: fallback?.tool.toolId || null,
|
|
251
|
+
fallbackModel: fallback?.model?.modelId || fallback?.tool.activeModel || null,
|
|
252
|
+
fallbackModelProfile: fallback?.profile?.id || fallback?.tool.activeProfile || fallback?.tool.activeModel || null,
|
|
253
|
+
whyChosen: describeWhyChosen(selected, task, settings, role),
|
|
254
|
+
safetyNotes: routeSummary.safetyNotes,
|
|
255
|
+
requiresConfirmation: routeSummary.requiresConfirmation,
|
|
256
|
+
quotaSignal: deriveQuotaSignal(selected.tool),
|
|
257
|
+
...extras,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function planRoute({ taskText, task, inventory, settings, surface = "avorelo_cli" }) {
|
|
262
|
+
const tools = Array.isArray(inventory?.tools) ? inventory.tools : [];
|
|
263
|
+
const blocked = blockedOptions(tools, task, settings);
|
|
264
|
+
|
|
265
|
+
if (settings.mode === "disabled" || settings.enabled === false) {
|
|
266
|
+
return {
|
|
267
|
+
routeVersion: 2,
|
|
268
|
+
state: "blocked",
|
|
269
|
+
selectedRoute: "disabled",
|
|
270
|
+
stageList: [],
|
|
271
|
+
chosenTool: null,
|
|
272
|
+
selectedModel: null,
|
|
273
|
+
chosenModelProfile: null,
|
|
274
|
+
fallbackTool: null,
|
|
275
|
+
fallbackModel: null,
|
|
276
|
+
fallbackModelProfile: null,
|
|
277
|
+
whyChosen: ["Orchestration is disabled in settings"],
|
|
278
|
+
whyNotChosen: [],
|
|
279
|
+
blockedOptions: blocked,
|
|
280
|
+
expectedVerification: [],
|
|
281
|
+
safetyNotes: ["Avorelo will not route or hand off work while orchestration is disabled."],
|
|
282
|
+
requiresConfirmation: false,
|
|
283
|
+
externalModelInvolved: false,
|
|
284
|
+
premiumUseInvolved: false,
|
|
285
|
+
inventorySource: inventory?.inventorySource || "cache",
|
|
286
|
+
cacheUsed: inventory?.inventorySource === "cache",
|
|
287
|
+
lastFullModelRefreshAt: inventory?.lastFullModelRefreshAt || null,
|
|
288
|
+
nextFullModelRefreshAfter: inventory?.nextFullModelRefreshAfter || null,
|
|
289
|
+
refreshLevel: inventory?.refreshLevel || "cache",
|
|
290
|
+
task,
|
|
291
|
+
taskText,
|
|
292
|
+
surface,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const fallbackReasonCodes = deriveFallbackReasonCodes(tools, task, settings);
|
|
297
|
+
const localWorkerRecommendation = buildLocalWorkerRecommendation(tools, task);
|
|
298
|
+
|
|
299
|
+
const planRoleNeeded = task.risk !== "high" && task.taskType !== "docs";
|
|
300
|
+
const needsInspectStage = task.taskType !== "docs" && task.contextNeed !== "small";
|
|
301
|
+
const needsSecurityReview = task.taskType === "security" || task.sensitivity === "security_sensitive" || task.risk === "high";
|
|
302
|
+
const implementationRole = task.taskType === "docs" ? "docs" : (task.taskType === "tests" ? "tests" : "implementation");
|
|
303
|
+
const planningRank = rankTools(tools, "planning", task, settings, surface);
|
|
304
|
+
const implementationRank = rankTools(tools, implementationRole, task, settings, surface);
|
|
305
|
+
const verificationRank = rankTools(tools, "verify", task, settings, surface);
|
|
306
|
+
const reviewRank = rankTools(tools, "review", task, settings, surface);
|
|
307
|
+
const summaryRank = rankTools(tools, "summaries", task, settings, surface);
|
|
308
|
+
const securityRank = rankTools(tools, "security", task, settings, surface);
|
|
309
|
+
|
|
310
|
+
const selectedPlan = planRoleNeeded ? planningRank.find((entry) => Number.isFinite(entry.score) && entry.score > -Infinity) : null;
|
|
311
|
+
const selectedImplement = implementationRank.find((entry) => Number.isFinite(entry.score) && entry.score > -Infinity);
|
|
312
|
+
const selectedVerify = verificationRank.find((entry) => Number.isFinite(entry.score) && entry.score > -Infinity);
|
|
313
|
+
const selectedFallback = reviewRank.find((entry) => Number.isFinite(entry.score) && entry.score > -Infinity && entry.tool.toolId !== selectedImplement?.tool.toolId)
|
|
314
|
+
|| implementationRank.find((entry) => Number.isFinite(entry.score) && entry.score > -Infinity && entry.tool.toolId !== selectedImplement?.tool.toolId);
|
|
315
|
+
const selectedSummary = summaryRank.find((entry) => Number.isFinite(entry.score) && entry.score > -Infinity);
|
|
316
|
+
const selectedSecurityReview = needsSecurityReview ? (securityRank.find((entry) => Number.isFinite(entry.score) && entry.score > -Infinity && entry.tool.toolId !== selectedImplement?.tool.toolId) || selectedFallback) : null;
|
|
317
|
+
|
|
318
|
+
if (!selectedImplement) {
|
|
319
|
+
return {
|
|
320
|
+
routeVersion: 2,
|
|
321
|
+
state: tools.length ? "blocked" : "unavailable",
|
|
322
|
+
selectedRoute: task.risk === "high" ? "high_risk_blocked" : "no_capable_worker",
|
|
323
|
+
stageList: [],
|
|
324
|
+
chosenTool: null,
|
|
325
|
+
selectedModel: null,
|
|
326
|
+
chosenModelProfile: null,
|
|
327
|
+
fallbackTool: null,
|
|
328
|
+
fallbackModel: null,
|
|
329
|
+
fallbackModelProfile: null,
|
|
330
|
+
whyChosen: [],
|
|
331
|
+
whyNotChosen: describeWhyNotChosen(implementationRank, null),
|
|
332
|
+
blockedOptions: blocked,
|
|
333
|
+
expectedVerification: ["git diff"],
|
|
334
|
+
safetyNotes: task.risk === "high"
|
|
335
|
+
? ["Cheap or untrusted workers were blocked for this high-risk task."]
|
|
336
|
+
: ["No installed worker met the current safety/capability requirements."],
|
|
337
|
+
requiresConfirmation: false,
|
|
338
|
+
externalModelInvolved: false,
|
|
339
|
+
premiumUseInvolved: false,
|
|
340
|
+
inventorySource: inventory?.inventorySource || "cache",
|
|
341
|
+
cacheUsed: inventory?.inventorySource === "cache",
|
|
342
|
+
lastFullModelRefreshAt: inventory?.lastFullModelRefreshAt || null,
|
|
343
|
+
nextFullModelRefreshAfter: inventory?.nextFullModelRefreshAfter || null,
|
|
344
|
+
refreshLevel: inventory?.refreshLevel || "cache",
|
|
345
|
+
task,
|
|
346
|
+
taskText,
|
|
347
|
+
surface,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const premiumUseInvolved = ["high", "highest"].includes(selectedImplement.tool.costTier) || /high_reasoning|opus/i.test(selectedImplement.profile?.id || "");
|
|
352
|
+
const externalModelInvolved = isExternalTool(selectedImplement.tool) || (selectedPlan ? isExternalTool(selectedPlan.tool) : false) || (selectedFallback ? isExternalTool(selectedFallback.tool) : false);
|
|
353
|
+
const requiresConfirmation = Boolean(settings.askBeforePremium || settings.mode === "ask_before_premium") && premiumUseInvolved;
|
|
354
|
+
const safetyNotes = [];
|
|
355
|
+
if (task.risk === "high") safetyNotes.push("High-risk tasks block cheap external workers by default.");
|
|
356
|
+
if (["secret_risk", "customer_data_risk", "security_sensitive"].includes(task.sensitivity)) {
|
|
357
|
+
safetyNotes.push("External routing stays blocked when secrets, customer data, or security-sensitive scope is detected.");
|
|
358
|
+
}
|
|
359
|
+
if (settings.mode === "local_private_only") safetyNotes.push("Only local/private workers were considered.");
|
|
360
|
+
if (settings.safety.stopAfterRepeatedFailures) safetyNotes.push("Repeated worker failures stop or escalate instead of looping.");
|
|
361
|
+
|
|
362
|
+
const routeSummary = { requiresConfirmation, safetyNotes };
|
|
363
|
+
const stageList = [];
|
|
364
|
+
|
|
365
|
+
if (needsInspectStage && selectedSummary) {
|
|
366
|
+
stageList.push(buildStage("inspect", "summaries", selectedSummary, selectedPlan || null, task, settings, routeSummary, {
|
|
367
|
+
taskSlice: "Inspect repo structure, changed files, and relevant context",
|
|
368
|
+
contextNeed: "small",
|
|
369
|
+
reasoningNeed: "low",
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (selectedPlan) {
|
|
374
|
+
stageList.push(buildStage("plan", "planning", selectedPlan, selectedFallback, task, settings, routeSummary, {
|
|
375
|
+
taskSlice: "Plan implementation approach, identify affected files and tests",
|
|
376
|
+
contextNeed: task.risk === "high" ? "large" : "medium",
|
|
377
|
+
reasoningNeed: task.risk === "high" ? "high" : "medium",
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
stageList.push(buildStage("implement", implementationRole, selectedImplement, selectedFallback, task, settings, routeSummary, {
|
|
382
|
+
taskSlice: "Implement the changes with tests",
|
|
383
|
+
contextNeed: "large",
|
|
384
|
+
reasoningNeed: task.risk === "high" ? "high" : "medium",
|
|
385
|
+
}));
|
|
386
|
+
|
|
387
|
+
if (selectedVerify) {
|
|
388
|
+
stageList.push(buildStage("verify", "verify", selectedVerify, null, task, settings, routeSummary, {
|
|
389
|
+
taskSlice: "Run deterministic verification: tests, lint, git diff",
|
|
390
|
+
contextNeed: "small",
|
|
391
|
+
reasoningNeed: "low",
|
|
392
|
+
}));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (needsSecurityReview && selectedSecurityReview) {
|
|
396
|
+
stageList.push(buildStage("security_review", "security", selectedSecurityReview, null, task, settings, routeSummary, {
|
|
397
|
+
taskSlice: "Security review: check for regressions in safety/governance/safe-path",
|
|
398
|
+
contextNeed: "medium",
|
|
399
|
+
reasoningNeed: "high",
|
|
400
|
+
}));
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (task.risk === "high" && selectedFallback) {
|
|
404
|
+
stageList.push(buildStage("review", "review", selectedFallback, null, task, settings, routeSummary, {
|
|
405
|
+
taskSlice: "Final review and merge readiness check",
|
|
406
|
+
contextNeed: "medium",
|
|
407
|
+
reasoningNeed: "high",
|
|
408
|
+
}));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (selectedImplement.tool.executionMode === "handoff") {
|
|
412
|
+
stageList.push({
|
|
413
|
+
id: "handoff",
|
|
414
|
+
role: "handoff",
|
|
415
|
+
state: "pending",
|
|
416
|
+
chosenTool: "avorelo_handoff",
|
|
417
|
+
chosenLabel: "Avorelo handoff prompt",
|
|
418
|
+
chosenModel: null,
|
|
419
|
+
chosenModelProfile: "compact_handoff",
|
|
420
|
+
executionMode: "local_command",
|
|
421
|
+
fallbackTool: null,
|
|
422
|
+
fallbackModel: null,
|
|
423
|
+
fallbackModelProfile: null,
|
|
424
|
+
whyChosen: ["A handoff is needed to pass context to the next worker/session"],
|
|
425
|
+
safetyNotes: routeSummary.safetyNotes,
|
|
426
|
+
requiresConfirmation: false,
|
|
427
|
+
quotaSignal: "local",
|
|
428
|
+
taskSlice: "Generate compact handoff prompt for next worker/session",
|
|
429
|
+
contextNeed: "small",
|
|
430
|
+
reasoningNeed: "low",
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const limitedWorkers = tools.filter((t) => t.workerState === "recently_limited").map((t) => ({
|
|
435
|
+
toolId: t.toolId,
|
|
436
|
+
label: t.label,
|
|
437
|
+
reasonCode: FALLBACK_REASON_CODES.WORKER_RECENTLY_LIMITED,
|
|
438
|
+
}));
|
|
439
|
+
|
|
440
|
+
const localWorkersAvailable = tools.filter((t) =>
|
|
441
|
+
["lm_studio", "ollama"].includes(t.toolId) &&
|
|
442
|
+
!["unavailable", "missing"].includes(t.workerState)
|
|
443
|
+
).map((t) => t.toolId);
|
|
444
|
+
|
|
445
|
+
const state = selectedVerify ? (selectedImplement.tool.executionMode === "handoff" ? "partial" : "ready") : "partial";
|
|
446
|
+
return {
|
|
447
|
+
routeVersion: 3,
|
|
448
|
+
state,
|
|
449
|
+
selectedRoute: `${task.risk}_${settings.mode}`,
|
|
450
|
+
stageList,
|
|
451
|
+
stageCount: stageList.length,
|
|
452
|
+
chosenTool: selectedImplement.tool.toolId,
|
|
453
|
+
selectedModel: selectedImplement.model?.modelId || selectedImplement.tool.activeModel || null,
|
|
454
|
+
chosenModelProfile: selectedImplement.profile?.id || selectedImplement.tool.activeProfile || selectedImplement.tool.activeModel || "unknown",
|
|
455
|
+
fallbackTool: selectedFallback?.tool.toolId || null,
|
|
456
|
+
fallbackModel: selectedFallback?.model?.modelId || selectedFallback?.tool.activeModel || null,
|
|
457
|
+
fallbackModelProfile: selectedFallback?.profile?.id || selectedFallback?.tool.activeProfile || selectedFallback?.tool.activeModel || null,
|
|
458
|
+
whyChosen: describeWhyChosen(selectedImplement, task, settings, implementationRole),
|
|
459
|
+
whyNotChosen: describeWhyNotChosen(implementationRank, selectedImplement.tool.toolId),
|
|
460
|
+
blockedOptions: blocked,
|
|
461
|
+
expectedVerification: selectedVerify ? [`${selectedVerify.tool.label} deterministic verification`] : ["Verification is currently insufficient; Avorelo will still capture proof."],
|
|
462
|
+
safetyNotes,
|
|
463
|
+
requiresConfirmation,
|
|
464
|
+
externalModelInvolved,
|
|
465
|
+
premiumUseInvolved,
|
|
466
|
+
selectionReason: describeWhyChosen(selectedImplement, task, settings, implementationRole),
|
|
467
|
+
fallbackReasonCodes,
|
|
468
|
+
limitedWorkers,
|
|
469
|
+
localWorkersAvailable,
|
|
470
|
+
localWorkerRecommendation,
|
|
471
|
+
handoffAvailable: selectedImplement.tool.executionMode === "handoff",
|
|
472
|
+
inventorySource: inventory?.inventorySource || "cache",
|
|
473
|
+
cacheUsed: inventory?.inventorySource === "cache",
|
|
474
|
+
lastFullModelRefreshAt: inventory?.lastFullModelRefreshAt || null,
|
|
475
|
+
nextFullModelRefreshAfter: inventory?.nextFullModelRefreshAfter || null,
|
|
476
|
+
refreshLevel: inventory?.refreshLevel || "cache",
|
|
477
|
+
task,
|
|
478
|
+
taskText,
|
|
479
|
+
surface,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
module.exports = {
|
|
484
|
+
planRoute,
|
|
485
|
+
FALLBACK_REASON_CODES,
|
|
486
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { readProjectConfig, writeProjectConfig, ORCHESTRATION_WORKER_IDS } = require("../config");
|
|
4
|
+
|
|
5
|
+
const MODE_LABELS = {
|
|
6
|
+
auto_recommended: "Auto recommended",
|
|
7
|
+
prefer_lowest_cost: "Prefer lower cost",
|
|
8
|
+
prefer_highest_quality: "Prefer highest quality",
|
|
9
|
+
local_private_only: "Local/private only",
|
|
10
|
+
ask_before_premium: "Ask before premium tools",
|
|
11
|
+
premium_only_for_risky: "Premium only for risky",
|
|
12
|
+
disabled: "Disable orchestration",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function getSettings(cwd) {
|
|
16
|
+
return readProjectConfig(cwd).orchestration;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function updateSettings(cwd, mutator) {
|
|
20
|
+
const config = readProjectConfig(cwd);
|
|
21
|
+
const next = mutator(config);
|
|
22
|
+
return writeProjectConfig(cwd, next).orchestration;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setMode(cwd, mode) {
|
|
26
|
+
return updateSettings(cwd, (config) => ({
|
|
27
|
+
...config,
|
|
28
|
+
orchestration: {
|
|
29
|
+
...config.orchestration,
|
|
30
|
+
mode,
|
|
31
|
+
enabled: mode !== "disabled",
|
|
32
|
+
askBeforePremium: mode === "ask_before_premium" ? true : config.orchestration.askBeforePremium,
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function setBooleanFlag(cwd, keyPath, value) {
|
|
38
|
+
return updateSettings(cwd, (config) => {
|
|
39
|
+
const next = { ...config, orchestration: { ...config.orchestration, safety: { ...(config.orchestration?.safety || {}) } } };
|
|
40
|
+
if (keyPath === "askBeforePremium") {
|
|
41
|
+
next.orchestration.askBeforePremium = value;
|
|
42
|
+
} else {
|
|
43
|
+
next.orchestration.safety[keyPath] = value;
|
|
44
|
+
}
|
|
45
|
+
return next;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function setWorkerEnabled(cwd, workerId, enabled) {
|
|
50
|
+
if (!ORCHESTRATION_WORKER_IDS.includes(workerId)) {
|
|
51
|
+
throw new Error(`Unknown orchestration worker: ${workerId}`);
|
|
52
|
+
}
|
|
53
|
+
return updateSettings(cwd, (config) => ({
|
|
54
|
+
...config,
|
|
55
|
+
orchestration: {
|
|
56
|
+
...config.orchestration,
|
|
57
|
+
allowedWorkers: {
|
|
58
|
+
...(config.orchestration?.allowedWorkers || {}),
|
|
59
|
+
[workerId]: enabled,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function formatSettingsText(settings, inventory = null) {
|
|
66
|
+
const lines = [
|
|
67
|
+
"Avorelo Orchestration Settings",
|
|
68
|
+
`Mode: ${MODE_LABELS[settings.mode] || settings.mode}`,
|
|
69
|
+
`Ask before premium: ${settings.askBeforePremium ? "on" : "off"}`,
|
|
70
|
+
`Block cheap external models for high-risk tasks: ${settings.safety.blockCheapExternalHighRisk ? "on" : "off"}`,
|
|
71
|
+
`Block external models for secrets/customer-data risk: ${settings.safety.blockExternalSecrets ? "on" : "off"}`,
|
|
72
|
+
`Stop after repeated failures: ${settings.safety.stopAfterRepeatedFailures ? "on" : "off"}`,
|
|
73
|
+
`Require proof before completion: ${settings.safety.requireProofBeforeCompletion ? "on" : "off"}`,
|
|
74
|
+
`Full model refresh interval: ${settings.refreshPolicy?.fullRefreshIntervalHours || 72}h`,
|
|
75
|
+
`Single-model refresh on new usage: ${settings.refreshPolicy?.singleModelRefreshOnNewUsage !== false ? "on" : "off"}`,
|
|
76
|
+
"",
|
|
77
|
+
"Allowed workers:",
|
|
78
|
+
...ORCHESTRATION_WORKER_IDS.map((workerId) => `- ${workerId}: ${settings.allowedWorkers[workerId] !== false ? "enabled" : "disabled"}`),
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
if (inventory && Array.isArray(inventory.tools)) {
|
|
82
|
+
lines.push("", "Advanced detected tools/models:");
|
|
83
|
+
inventory.tools.forEach((tool) => {
|
|
84
|
+
lines.push(
|
|
85
|
+
`- ${tool.label}: ${tool.installStatus}/${tool.availability} · active ${tool.activeModel || tool.activeProfile || "unknown"} · roles ${(tool.supportedRoles || []).join(", ") || "n/a"} · cost ${tool.costTier} · trust ${tool.trustTier} · quota ${tool.quotaSignal}`
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return lines.join("\n");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function settingsMetadata(settings) {
|
|
94
|
+
return {
|
|
95
|
+
currentMode: settings.mode,
|
|
96
|
+
options: Object.entries(MODE_LABELS).map(([value, label]) => ({ value, label })),
|
|
97
|
+
askBeforePremium: settings.askBeforePremium,
|
|
98
|
+
safety: settings.safety,
|
|
99
|
+
allowedWorkers: settings.allowedWorkers,
|
|
100
|
+
refreshPolicy: settings.refreshPolicy,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = {
|
|
105
|
+
MODE_LABELS,
|
|
106
|
+
getSettings,
|
|
107
|
+
setMode,
|
|
108
|
+
setBooleanFlag,
|
|
109
|
+
setWorkerEnabled,
|
|
110
|
+
formatSettingsText,
|
|
111
|
+
settingsMetadata,
|
|
112
|
+
};
|