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,480 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const USER_CONFIG_SCHEMA_VERSION = 1;
|
|
8
|
+
const USER_CONFIG_DIRNAME = ".avorelo";
|
|
9
|
+
const USER_CONFIG_FILENAME = "config.json";
|
|
10
|
+
|
|
11
|
+
function isWindowsAbsolutePath(input) {
|
|
12
|
+
return typeof input === "string" && /^[A-Za-z]:[\\/]/.test(input.trim());
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function normalizePathValue(input) {
|
|
16
|
+
if (typeof input !== "string") return null;
|
|
17
|
+
const trimmed = input.trim();
|
|
18
|
+
if (!trimmed) return null;
|
|
19
|
+
if (isWindowsAbsolutePath(trimmed)) {
|
|
20
|
+
return path.win32.normalize(trimmed);
|
|
21
|
+
}
|
|
22
|
+
return path.resolve(trimmed);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function comparablePath(input) {
|
|
26
|
+
const normalized = normalizePathValue(input);
|
|
27
|
+
if (!normalized) return null;
|
|
28
|
+
const withoutTrailing = normalized.replace(/[\\/]+$/, "");
|
|
29
|
+
return process.platform === "win32" ? withoutTrailing.toLowerCase() : withoutTrailing;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function defaultUserHome(env = process.env) {
|
|
33
|
+
return env.USERPROFILE || env.HOME || os.homedir();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getUserConfigPath(env = process.env) {
|
|
37
|
+
return path.join(defaultUserHome(env), USER_CONFIG_DIRNAME, USER_CONFIG_FILENAME);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function fileExists(absPath) {
|
|
41
|
+
try {
|
|
42
|
+
return fs.existsSync(absPath);
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function directoryExists(absPath) {
|
|
49
|
+
try {
|
|
50
|
+
return fs.statSync(absPath).isDirectory();
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readJson(absPath, fallback = null) {
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(fs.readFileSync(absPath, "utf8").replace(/^\uFEFF/, ""));
|
|
59
|
+
} catch {
|
|
60
|
+
return fallback;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function safePackageJson(dirPath) {
|
|
65
|
+
const pkgPath = path.join(dirPath, "package.json");
|
|
66
|
+
if (!fileExists(pkgPath)) return null;
|
|
67
|
+
return readJson(pkgPath, null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getWorkspaceSignals(dirPath) {
|
|
71
|
+
const packageJson = safePackageJson(dirPath);
|
|
72
|
+
const hasPackageJson = Boolean(packageJson);
|
|
73
|
+
const hasGit = fileExists(path.join(dirPath, ".git"));
|
|
74
|
+
const hasCco = directoryExists(path.join(dirPath, ".claude", "cco"));
|
|
75
|
+
const hasClaudeSettings = fileExists(path.join(dirPath, ".claude", "settings.json"))
|
|
76
|
+
|| fileExists(path.join(dirPath, ".claude", "settings.local.json"));
|
|
77
|
+
const hasRepoBinary = fileExists(path.join(dirPath, "bin", "avorelo"));
|
|
78
|
+
const hasOrchestrationLib = directoryExists(path.join(dirPath, "scripts", "lib", "orchestration"));
|
|
79
|
+
const looksLikeAvoreloRepo = hasRepoBinary && hasOrchestrationLib && hasPackageJson;
|
|
80
|
+
const looksLikeActivatedWorkspace = hasCco && (hasPackageJson || hasGit || hasClaudeSettings || hasRepoBinary || hasOrchestrationLib);
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
path: dirPath,
|
|
84
|
+
packageName: packageJson?.name || null,
|
|
85
|
+
hasPackageJson,
|
|
86
|
+
hasGit,
|
|
87
|
+
hasCco,
|
|
88
|
+
hasClaudeSettings,
|
|
89
|
+
hasRepoBinary,
|
|
90
|
+
hasOrchestrationLib,
|
|
91
|
+
looksLikeAvoreloRepo,
|
|
92
|
+
looksLikeActivatedWorkspace,
|
|
93
|
+
isWorkspace: looksLikeAvoreloRepo || looksLikeActivatedWorkspace,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function findWorkspaceRoot(startDir) {
|
|
98
|
+
const initial = normalizePathValue(startDir);
|
|
99
|
+
if (!initial) return null;
|
|
100
|
+
|
|
101
|
+
let cursor = initial;
|
|
102
|
+
while (true) {
|
|
103
|
+
const signals = getWorkspaceSignals(cursor);
|
|
104
|
+
if (signals.isWorkspace) {
|
|
105
|
+
return {
|
|
106
|
+
workspace: cursor,
|
|
107
|
+
signals,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const parent = path.dirname(cursor);
|
|
111
|
+
if (parent === cursor) return null;
|
|
112
|
+
cursor = parent;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function normalizeUserConfig(raw) {
|
|
117
|
+
const source = raw && typeof raw === "object" ? raw : {};
|
|
118
|
+
const knownWorkspaces = Array.isArray(source.knownWorkspaces) ? source.knownWorkspaces : [];
|
|
119
|
+
const deduped = [];
|
|
120
|
+
const seen = new Set();
|
|
121
|
+
for (const item of knownWorkspaces) {
|
|
122
|
+
const normalized = normalizePathValue(item);
|
|
123
|
+
if (!normalized) continue;
|
|
124
|
+
const key = comparablePath(normalized);
|
|
125
|
+
if (seen.has(key)) continue;
|
|
126
|
+
seen.add(key);
|
|
127
|
+
deduped.push(normalized);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
schemaVersion: USER_CONFIG_SCHEMA_VERSION,
|
|
132
|
+
lastWorkspace: normalizePathValue(source.lastWorkspace),
|
|
133
|
+
knownWorkspaces: deduped,
|
|
134
|
+
updatedAt: typeof source.updatedAt === "string" && source.updatedAt.trim() ? source.updatedAt : null,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function readUserConfig(options = {}) {
|
|
139
|
+
const env = options.env || process.env;
|
|
140
|
+
const configPath = options.configPath || getUserConfigPath(env);
|
|
141
|
+
try {
|
|
142
|
+
if (!fileExists(configPath)) {
|
|
143
|
+
return {
|
|
144
|
+
configPath,
|
|
145
|
+
config: normalizeUserConfig({}),
|
|
146
|
+
exists: false,
|
|
147
|
+
corrupted: false,
|
|
148
|
+
error: null,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const raw = JSON.parse(fs.readFileSync(configPath, "utf8").replace(/^\uFEFF/, ""));
|
|
153
|
+
return {
|
|
154
|
+
configPath,
|
|
155
|
+
config: normalizeUserConfig(raw),
|
|
156
|
+
exists: true,
|
|
157
|
+
corrupted: false,
|
|
158
|
+
error: null,
|
|
159
|
+
};
|
|
160
|
+
} catch (error) {
|
|
161
|
+
return {
|
|
162
|
+
configPath,
|
|
163
|
+
config: normalizeUserConfig({}),
|
|
164
|
+
exists: true,
|
|
165
|
+
corrupted: true,
|
|
166
|
+
error: error.message,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function writeUserConfig(nextConfig, options = {}) {
|
|
172
|
+
const env = options.env || process.env;
|
|
173
|
+
const configPath = options.configPath || getUserConfigPath(env);
|
|
174
|
+
const normalized = normalizeUserConfig(nextConfig);
|
|
175
|
+
normalized.updatedAt = options.updatedAt || new Date().toISOString();
|
|
176
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
177
|
+
fs.writeFileSync(configPath, JSON.stringify(normalized, null, 2), "utf8");
|
|
178
|
+
return {
|
|
179
|
+
configPath,
|
|
180
|
+
config: normalized,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function validateWorkspacePath(candidatePath) {
|
|
185
|
+
if (process.platform !== "win32" && isWindowsAbsolutePath(candidatePath)) {
|
|
186
|
+
return {
|
|
187
|
+
ok: false,
|
|
188
|
+
workspace: null,
|
|
189
|
+
message: `Not an Avorelo workspace: ${candidatePath}`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const resolved = findWorkspaceRoot(candidatePath);
|
|
193
|
+
if (!resolved) {
|
|
194
|
+
return {
|
|
195
|
+
ok: false,
|
|
196
|
+
workspace: null,
|
|
197
|
+
message: `Not an Avorelo workspace: ${candidatePath}`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
ok: true,
|
|
202
|
+
workspace: resolved.workspace,
|
|
203
|
+
signals: resolved.signals,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function registerWorkspace(workspacePath, options = {}) {
|
|
208
|
+
const validation = validateWorkspacePath(workspacePath);
|
|
209
|
+
if (!validation.ok) {
|
|
210
|
+
return {
|
|
211
|
+
ok: false,
|
|
212
|
+
message: validation.message,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const current = readUserConfig(options);
|
|
217
|
+
const config = current.config;
|
|
218
|
+
const existing = config.knownWorkspaces.slice();
|
|
219
|
+
existing.push(validation.workspace);
|
|
220
|
+
const next = normalizeUserConfig({
|
|
221
|
+
...config,
|
|
222
|
+
lastWorkspace: validation.workspace,
|
|
223
|
+
knownWorkspaces: existing,
|
|
224
|
+
});
|
|
225
|
+
const written = writeUserConfig(next, options);
|
|
226
|
+
return {
|
|
227
|
+
ok: true,
|
|
228
|
+
workspace: validation.workspace,
|
|
229
|
+
configPath: written.configPath,
|
|
230
|
+
config: written.config,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function clearLastWorkspace(options = {}) {
|
|
235
|
+
const current = readUserConfig(options);
|
|
236
|
+
const next = normalizeUserConfig({
|
|
237
|
+
...current.config,
|
|
238
|
+
lastWorkspace: null,
|
|
239
|
+
});
|
|
240
|
+
const written = writeUserConfig(next, options);
|
|
241
|
+
return {
|
|
242
|
+
ok: true,
|
|
243
|
+
configPath: written.configPath,
|
|
244
|
+
config: written.config,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function listValidKnownWorkspaces(config) {
|
|
249
|
+
return (config.knownWorkspaces || [])
|
|
250
|
+
.map((workspace) => {
|
|
251
|
+
const validation = validateWorkspacePath(workspace);
|
|
252
|
+
return {
|
|
253
|
+
workspace,
|
|
254
|
+
valid: validation.ok,
|
|
255
|
+
normalizedWorkspace: validation.ok ? validation.workspace : normalizePathValue(workspace),
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function resolveWorkspace(options = {}) {
|
|
261
|
+
const cwd = normalizePathValue(options.cwd || process.cwd());
|
|
262
|
+
const env = options.env || process.env;
|
|
263
|
+
const currentMatch = cwd ? findWorkspaceRoot(cwd) : null;
|
|
264
|
+
const envOverrideRaw = normalizePathValue(env.AVORELO_WORKSPACE);
|
|
265
|
+
const envOverride = envOverrideRaw ? validateWorkspacePath(envOverrideRaw) : null;
|
|
266
|
+
const userConfig = readUserConfig(options);
|
|
267
|
+
const knownEntries = listValidKnownWorkspaces(userConfig.config);
|
|
268
|
+
const validKnown = knownEntries.filter((entry) => entry.valid);
|
|
269
|
+
const lastWorkspaceCandidate = userConfig.config.lastWorkspace
|
|
270
|
+
? validateWorkspacePath(userConfig.config.lastWorkspace)
|
|
271
|
+
: null;
|
|
272
|
+
|
|
273
|
+
if (currentMatch) {
|
|
274
|
+
return {
|
|
275
|
+
ok: true,
|
|
276
|
+
workspace: currentMatch.workspace,
|
|
277
|
+
source: "current_workspace",
|
|
278
|
+
cwd,
|
|
279
|
+
currentWorkspace: currentMatch.workspace,
|
|
280
|
+
envOverride: envOverrideRaw,
|
|
281
|
+
lastWorkspace: userConfig.config.lastWorkspace,
|
|
282
|
+
knownWorkspaces: userConfig.config.knownWorkspaces,
|
|
283
|
+
knownValidWorkspaces: validKnown.map((entry) => entry.normalizedWorkspace),
|
|
284
|
+
configPath: userConfig.configPath,
|
|
285
|
+
configCorrupted: userConfig.corrupted,
|
|
286
|
+
configError: userConfig.error,
|
|
287
|
+
message: null,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (envOverrideRaw) {
|
|
292
|
+
if (envOverride?.ok) {
|
|
293
|
+
return {
|
|
294
|
+
ok: true,
|
|
295
|
+
workspace: envOverride.workspace,
|
|
296
|
+
source: "env_override",
|
|
297
|
+
cwd,
|
|
298
|
+
currentWorkspace: null,
|
|
299
|
+
envOverride: envOverrideRaw,
|
|
300
|
+
lastWorkspace: userConfig.config.lastWorkspace,
|
|
301
|
+
knownWorkspaces: userConfig.config.knownWorkspaces,
|
|
302
|
+
knownValidWorkspaces: validKnown.map((entry) => entry.normalizedWorkspace),
|
|
303
|
+
configPath: userConfig.configPath,
|
|
304
|
+
configCorrupted: userConfig.corrupted,
|
|
305
|
+
configError: userConfig.error,
|
|
306
|
+
message: null,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
ok: false,
|
|
312
|
+
workspace: null,
|
|
313
|
+
source: "env_override_invalid",
|
|
314
|
+
cwd,
|
|
315
|
+
currentWorkspace: null,
|
|
316
|
+
envOverride: envOverrideRaw,
|
|
317
|
+
lastWorkspace: userConfig.config.lastWorkspace,
|
|
318
|
+
knownWorkspaces: userConfig.config.knownWorkspaces,
|
|
319
|
+
knownValidWorkspaces: validKnown.map((entry) => entry.normalizedWorkspace),
|
|
320
|
+
configPath: userConfig.configPath,
|
|
321
|
+
configCorrupted: userConfig.corrupted,
|
|
322
|
+
configError: userConfig.error,
|
|
323
|
+
message: `AVORELO_WORKSPACE is set but does not point to a valid Avorelo workspace: ${envOverrideRaw}`,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (lastWorkspaceCandidate?.ok) {
|
|
328
|
+
return {
|
|
329
|
+
ok: true,
|
|
330
|
+
workspace: lastWorkspaceCandidate.workspace,
|
|
331
|
+
source: "last_workspace",
|
|
332
|
+
cwd,
|
|
333
|
+
currentWorkspace: null,
|
|
334
|
+
envOverride: null,
|
|
335
|
+
lastWorkspace: userConfig.config.lastWorkspace,
|
|
336
|
+
knownWorkspaces: userConfig.config.knownWorkspaces,
|
|
337
|
+
knownValidWorkspaces: validKnown.map((entry) => entry.normalizedWorkspace),
|
|
338
|
+
configPath: userConfig.configPath,
|
|
339
|
+
configCorrupted: userConfig.corrupted,
|
|
340
|
+
configError: userConfig.error,
|
|
341
|
+
message: null,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (validKnown.length === 1) {
|
|
346
|
+
return {
|
|
347
|
+
ok: true,
|
|
348
|
+
workspace: validKnown[0].normalizedWorkspace,
|
|
349
|
+
source: "known_workspace",
|
|
350
|
+
cwd,
|
|
351
|
+
currentWorkspace: null,
|
|
352
|
+
envOverride: null,
|
|
353
|
+
lastWorkspace: userConfig.config.lastWorkspace,
|
|
354
|
+
knownWorkspaces: userConfig.config.knownWorkspaces,
|
|
355
|
+
knownValidWorkspaces: validKnown.map((entry) => entry.normalizedWorkspace),
|
|
356
|
+
configPath: userConfig.configPath,
|
|
357
|
+
configCorrupted: userConfig.corrupted,
|
|
358
|
+
configError: userConfig.error,
|
|
359
|
+
message: null,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const lastWorkspaceInvalid = Boolean(userConfig.config.lastWorkspace) && !lastWorkspaceCandidate?.ok;
|
|
364
|
+
const multipleKnown = validKnown.length > 1;
|
|
365
|
+
let message = `No Avorelo workspace found. Run "${options.cliName || "avorelo"} activate" inside your repo or set AVORELO_WORKSPACE.`;
|
|
366
|
+
if (lastWorkspaceInvalid) {
|
|
367
|
+
message = `The saved lastWorkspace is no longer valid. Run "${options.cliName || "avorelo"} activate" inside your repo, use "${options.cliName || "avorelo"} workspace set <path>", or set AVORELO_WORKSPACE.`;
|
|
368
|
+
} else if (multipleKnown) {
|
|
369
|
+
message = `Multiple Avorelo workspaces are known. Use "${options.cliName || "avorelo"} workspace set <path>" or set AVORELO_WORKSPACE.`;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return {
|
|
373
|
+
ok: false,
|
|
374
|
+
workspace: null,
|
|
375
|
+
source: multipleKnown ? "multiple_known_workspaces" : (lastWorkspaceInvalid ? "last_workspace_invalid" : "missing"),
|
|
376
|
+
cwd,
|
|
377
|
+
currentWorkspace: null,
|
|
378
|
+
envOverride: null,
|
|
379
|
+
lastWorkspace: userConfig.config.lastWorkspace,
|
|
380
|
+
knownWorkspaces: userConfig.config.knownWorkspaces,
|
|
381
|
+
knownValidWorkspaces: validKnown.map((entry) => entry.normalizedWorkspace),
|
|
382
|
+
configPath: userConfig.configPath,
|
|
383
|
+
configCorrupted: userConfig.corrupted,
|
|
384
|
+
configError: userConfig.error,
|
|
385
|
+
message,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function workspaceDoctor(options = {}) {
|
|
390
|
+
const resolution = resolveWorkspace(options);
|
|
391
|
+
const userConfig = readUserConfig(options);
|
|
392
|
+
const packageJson = readJson(path.join(options.repoRoot || process.cwd(), "package.json"), {});
|
|
393
|
+
const binMapping = packageJson?.bin?.avorelo || null;
|
|
394
|
+
const checks = [
|
|
395
|
+
{
|
|
396
|
+
id: "user_config",
|
|
397
|
+
label: "User config readable",
|
|
398
|
+
status: userConfig.corrupted ? "PARTIAL" : "GOOD",
|
|
399
|
+
details: userConfig.corrupted ? userConfig.error : userConfig.configPath,
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
id: "workspace_resolution",
|
|
403
|
+
label: "Workspace resolution",
|
|
404
|
+
status: resolution.ok ? "GOOD" : "BLOCKED",
|
|
405
|
+
details: resolution.ok ? `${resolution.workspace} (${resolution.source})` : resolution.message,
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
id: "package_bin",
|
|
409
|
+
label: "Package bin mapping",
|
|
410
|
+
status: binMapping === "bin/avorelo" ? "GOOD" : "PARTIAL",
|
|
411
|
+
details: binMapping === "bin/avorelo" ? "avorelo -> bin/avorelo" : `Unexpected bin mapping: ${binMapping || "missing"}`,
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
id: "bin_launcher",
|
|
415
|
+
label: "Repo launcher file",
|
|
416
|
+
status: fileExists(path.join(options.repoRoot || process.cwd(), "bin", "avorelo")) ? "GOOD" : "BLOCKED",
|
|
417
|
+
details: fileExists(path.join(options.repoRoot || process.cwd(), "bin", "avorelo"))
|
|
418
|
+
? path.join(options.repoRoot || process.cwd(), "bin", "avorelo")
|
|
419
|
+
: "bin/avorelo missing",
|
|
420
|
+
},
|
|
421
|
+
];
|
|
422
|
+
|
|
423
|
+
const overall = checks.some((check) => check.status === "BLOCKED")
|
|
424
|
+
? "BLOCKED"
|
|
425
|
+
: checks.some((check) => check.status === "PARTIAL")
|
|
426
|
+
? "PARTIAL"
|
|
427
|
+
: "GOOD";
|
|
428
|
+
|
|
429
|
+
return {
|
|
430
|
+
status: overall,
|
|
431
|
+
cwd: normalizePathValue(options.cwd || process.cwd()),
|
|
432
|
+
resolution,
|
|
433
|
+
configPath: userConfig.configPath,
|
|
434
|
+
checks,
|
|
435
|
+
knownWorkspaces: userConfig.config.knownWorkspaces,
|
|
436
|
+
lastWorkspace: userConfig.config.lastWorkspace,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function formatWorkspaceShowText(result) {
|
|
441
|
+
return [
|
|
442
|
+
"Avorelo Workspace",
|
|
443
|
+
`Current cwd: ${result.cwd || "unknown"}`,
|
|
444
|
+
`Resolved workspace: ${result.workspace || "not found"}`,
|
|
445
|
+
`Resolution source: ${result.source || "unknown"}`,
|
|
446
|
+
`AVORELO_WORKSPACE: ${result.envOverride || "not set"}`,
|
|
447
|
+
`lastWorkspace: ${result.lastWorkspace || "not set"}`,
|
|
448
|
+
`Known workspaces: ${Array.isArray(result.knownWorkspaces) ? result.knownWorkspaces.length : 0}`,
|
|
449
|
+
`User config: ${result.configPath}`,
|
|
450
|
+
result.message ? `Note: ${result.message}` : null,
|
|
451
|
+
].filter(Boolean).join("\n");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function formatWorkspaceDoctorText(result) {
|
|
455
|
+
return [
|
|
456
|
+
"Avorelo Workspace Doctor",
|
|
457
|
+
`Status: ${result.status}`,
|
|
458
|
+
`Current cwd: ${result.cwd || "unknown"}`,
|
|
459
|
+
`Config: ${result.configPath}`,
|
|
460
|
+
...result.checks.map((check) => `${check.status} ${check.label}: ${check.details}`),
|
|
461
|
+
result.resolution?.message ? `Next: ${result.resolution.message}` : null,
|
|
462
|
+
].filter(Boolean).join("\n");
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
module.exports = {
|
|
466
|
+
USER_CONFIG_SCHEMA_VERSION,
|
|
467
|
+
getUserConfigPath,
|
|
468
|
+
getWorkspaceSignals,
|
|
469
|
+
findWorkspaceRoot,
|
|
470
|
+
normalizeUserConfig,
|
|
471
|
+
readUserConfig,
|
|
472
|
+
writeUserConfig,
|
|
473
|
+
validateWorkspacePath,
|
|
474
|
+
registerWorkspace,
|
|
475
|
+
clearLastWorkspace,
|
|
476
|
+
resolveWorkspace,
|
|
477
|
+
workspaceDoctor,
|
|
478
|
+
formatWorkspaceShowText,
|
|
479
|
+
formatWorkspaceDoctorText,
|
|
480
|
+
};
|