nemoris 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/.env.example +49 -0
- package/LICENSE +21 -0
- package/README.md +209 -0
- package/SECURITY.md +119 -0
- package/bin/nemoris +46 -0
- package/config/agents/agent.toml.example +28 -0
- package/config/agents/default.toml +22 -0
- package/config/agents/orchestrator.toml +18 -0
- package/config/delivery.toml +73 -0
- package/config/embeddings.toml +5 -0
- package/config/identity/default-purpose.md +1 -0
- package/config/identity/default-soul.md +3 -0
- package/config/identity/orchestrator-purpose.md +1 -0
- package/config/identity/orchestrator-soul.md +1 -0
- package/config/improvement-targets.toml +15 -0
- package/config/jobs/heartbeat-check.toml +30 -0
- package/config/jobs/memory-rollup.toml +46 -0
- package/config/jobs/workspace-health.toml +63 -0
- package/config/mcp.toml +16 -0
- package/config/output-contracts.toml +17 -0
- package/config/peers.toml +32 -0
- package/config/peers.toml.example +32 -0
- package/config/policies/memory-default.toml +10 -0
- package/config/policies/memory-heartbeat.toml +5 -0
- package/config/policies/memory-ops.toml +10 -0
- package/config/policies/tools-heartbeat-minimal.toml +8 -0
- package/config/policies/tools-interactive-safe.toml +8 -0
- package/config/policies/tools-ops-bounded.toml +8 -0
- package/config/policies/tools-orchestrator.toml +7 -0
- package/config/providers/anthropic.toml +15 -0
- package/config/providers/ollama.toml +5 -0
- package/config/providers/openai-codex.toml +9 -0
- package/config/providers/openrouter.toml +5 -0
- package/config/router.toml +22 -0
- package/config/runtime.toml +114 -0
- package/config/skills/self-improvement.toml +15 -0
- package/config/skills/telegram-onboarding-spec.md +240 -0
- package/config/skills/workspace-monitor.toml +15 -0
- package/config/task-router.toml +42 -0
- package/install.sh +50 -0
- package/package.json +90 -0
- package/src/auth/auth-profiles.js +169 -0
- package/src/auth/openai-codex-oauth.js +285 -0
- package/src/battle.js +449 -0
- package/src/cli/help.js +265 -0
- package/src/cli/output-filter.js +49 -0
- package/src/cli/runtime-control.js +704 -0
- package/src/cli-main.js +2763 -0
- package/src/cli.js +78 -0
- package/src/config/loader.js +332 -0
- package/src/config/schema-validator.js +214 -0
- package/src/config/toml-lite.js +8 -0
- package/src/daemon/action-handlers.js +71 -0
- package/src/daemon/healing-tick.js +87 -0
- package/src/daemon/health-probes.js +90 -0
- package/src/daemon/notifier.js +57 -0
- package/src/daemon/nurse.js +218 -0
- package/src/daemon/repair-log.js +106 -0
- package/src/daemon/rule-staging.js +90 -0
- package/src/daemon/rules.js +29 -0
- package/src/daemon/telegram-commands.js +54 -0
- package/src/daemon/updater.js +85 -0
- package/src/jobs/job-runner.js +78 -0
- package/src/mcp/consumer.js +129 -0
- package/src/memory/active-recall.js +171 -0
- package/src/memory/backend-manager.js +97 -0
- package/src/memory/backends/file-backend.js +38 -0
- package/src/memory/backends/qmd-backend.js +219 -0
- package/src/memory/embedding-guards.js +24 -0
- package/src/memory/embedding-index.js +118 -0
- package/src/memory/embedding-service.js +179 -0
- package/src/memory/file-index.js +177 -0
- package/src/memory/memory-signature.js +5 -0
- package/src/memory/memory-store.js +648 -0
- package/src/memory/retrieval-planner.js +66 -0
- package/src/memory/scoring.js +145 -0
- package/src/memory/simhash.js +78 -0
- package/src/memory/sqlite-active-store.js +824 -0
- package/src/memory/write-policy.js +36 -0
- package/src/onboarding/aliases.js +33 -0
- package/src/onboarding/auth/api-key.js +224 -0
- package/src/onboarding/auth/ollama-detect.js +42 -0
- package/src/onboarding/clack-prompter.js +77 -0
- package/src/onboarding/doctor.js +530 -0
- package/src/onboarding/lock.js +42 -0
- package/src/onboarding/model-catalog.js +344 -0
- package/src/onboarding/phases/auth.js +589 -0
- package/src/onboarding/phases/build.js +130 -0
- package/src/onboarding/phases/choose.js +82 -0
- package/src/onboarding/phases/detect.js +98 -0
- package/src/onboarding/phases/hatch.js +216 -0
- package/src/onboarding/phases/identity.js +79 -0
- package/src/onboarding/phases/ollama.js +345 -0
- package/src/onboarding/phases/scaffold.js +99 -0
- package/src/onboarding/phases/telegram.js +377 -0
- package/src/onboarding/phases/validate.js +204 -0
- package/src/onboarding/phases/verify.js +206 -0
- package/src/onboarding/platform.js +482 -0
- package/src/onboarding/status-bar.js +95 -0
- package/src/onboarding/templates.js +794 -0
- package/src/onboarding/toml-writer.js +38 -0
- package/src/onboarding/tui.js +250 -0
- package/src/onboarding/uninstall.js +153 -0
- package/src/onboarding/wizard.js +499 -0
- package/src/providers/anthropic.js +168 -0
- package/src/providers/base.js +247 -0
- package/src/providers/circuit-breaker.js +136 -0
- package/src/providers/ollama.js +163 -0
- package/src/providers/openai-codex.js +149 -0
- package/src/providers/openrouter.js +136 -0
- package/src/providers/registry.js +36 -0
- package/src/providers/router.js +16 -0
- package/src/runtime/bootstrap-cache.js +47 -0
- package/src/runtime/capabilities-prompt.js +25 -0
- package/src/runtime/completion-ping.js +99 -0
- package/src/runtime/config-validator.js +121 -0
- package/src/runtime/context-ledger.js +360 -0
- package/src/runtime/cutover-readiness.js +42 -0
- package/src/runtime/daemon.js +729 -0
- package/src/runtime/delivery-ack.js +195 -0
- package/src/runtime/delivery-adapters/local-file.js +41 -0
- package/src/runtime/delivery-adapters/openclaw-cli.js +94 -0
- package/src/runtime/delivery-adapters/openclaw-peer.js +98 -0
- package/src/runtime/delivery-adapters/shadow.js +13 -0
- package/src/runtime/delivery-adapters/standalone-http.js +98 -0
- package/src/runtime/delivery-adapters/telegram.js +104 -0
- package/src/runtime/delivery-adapters/tui.js +128 -0
- package/src/runtime/delivery-manager.js +807 -0
- package/src/runtime/delivery-store.js +168 -0
- package/src/runtime/dependency-health.js +118 -0
- package/src/runtime/envelope.js +114 -0
- package/src/runtime/evaluation.js +1089 -0
- package/src/runtime/exec-approvals.js +216 -0
- package/src/runtime/executor.js +500 -0
- package/src/runtime/failure-ping.js +67 -0
- package/src/runtime/flows.js +83 -0
- package/src/runtime/guards.js +45 -0
- package/src/runtime/handoff.js +51 -0
- package/src/runtime/identity-cache.js +28 -0
- package/src/runtime/improvement-engine.js +109 -0
- package/src/runtime/improvement-harness.js +581 -0
- package/src/runtime/input-sanitiser.js +72 -0
- package/src/runtime/interaction-contract.js +347 -0
- package/src/runtime/lane-readiness.js +226 -0
- package/src/runtime/migration.js +323 -0
- package/src/runtime/model-resolution.js +78 -0
- package/src/runtime/network.js +64 -0
- package/src/runtime/notification-store.js +97 -0
- package/src/runtime/notifier.js +256 -0
- package/src/runtime/orchestrator.js +53 -0
- package/src/runtime/orphan-reaper.js +41 -0
- package/src/runtime/output-contract-schema.js +139 -0
- package/src/runtime/output-contract-validator.js +439 -0
- package/src/runtime/peer-readiness.js +69 -0
- package/src/runtime/peer-registry.js +133 -0
- package/src/runtime/pilot-status.js +108 -0
- package/src/runtime/prompt-builder.js +261 -0
- package/src/runtime/provider-attempt.js +582 -0
- package/src/runtime/report-fallback.js +71 -0
- package/src/runtime/result-normalizer.js +183 -0
- package/src/runtime/retention.js +74 -0
- package/src/runtime/review.js +244 -0
- package/src/runtime/route-job.js +15 -0
- package/src/runtime/run-store.js +38 -0
- package/src/runtime/schedule.js +88 -0
- package/src/runtime/scheduler-state.js +434 -0
- package/src/runtime/scheduler.js +656 -0
- package/src/runtime/session-compactor.js +182 -0
- package/src/runtime/session-search.js +155 -0
- package/src/runtime/slack-inbound.js +249 -0
- package/src/runtime/ssrf.js +102 -0
- package/src/runtime/status-aggregator.js +330 -0
- package/src/runtime/task-contract.js +140 -0
- package/src/runtime/task-packet.js +107 -0
- package/src/runtime/task-router.js +140 -0
- package/src/runtime/telegram-inbound.js +1565 -0
- package/src/runtime/token-counter.js +134 -0
- package/src/runtime/token-estimator.js +59 -0
- package/src/runtime/tool-loop.js +200 -0
- package/src/runtime/transport-server.js +311 -0
- package/src/runtime/tui-server.js +411 -0
- package/src/runtime/ulid.js +44 -0
- package/src/security/ssrf-check.js +197 -0
- package/src/setup.js +369 -0
- package/src/shadow/bridge.js +303 -0
- package/src/skills/loader.js +84 -0
- package/src/tools/catalog.json +49 -0
- package/src/tools/cli-delegate.js +44 -0
- package/src/tools/mcp-client.js +106 -0
- package/src/tools/micro/cancel-task.js +6 -0
- package/src/tools/micro/complete-task.js +6 -0
- package/src/tools/micro/fail-task.js +6 -0
- package/src/tools/micro/http-fetch.js +74 -0
- package/src/tools/micro/index.js +36 -0
- package/src/tools/micro/lcm-recall.js +60 -0
- package/src/tools/micro/list-dir.js +17 -0
- package/src/tools/micro/list-skills.js +46 -0
- package/src/tools/micro/load-skill.js +38 -0
- package/src/tools/micro/memory-search.js +45 -0
- package/src/tools/micro/read-file.js +11 -0
- package/src/tools/micro/session-search.js +54 -0
- package/src/tools/micro/shell-exec.js +43 -0
- package/src/tools/micro/trigger-job.js +79 -0
- package/src/tools/micro/web-search.js +58 -0
- package/src/tools/micro/workspace-paths.js +39 -0
- package/src/tools/micro/write-file.js +14 -0
- package/src/tools/micro/write-memory.js +41 -0
- package/src/tools/registry.js +348 -0
- package/src/tools/tool-result-contract.js +36 -0
- package/src/tui/chat.js +835 -0
- package/src/tui/renderer.js +175 -0
- package/src/tui/socket-client.js +217 -0
- package/src/utils/canonical-json.js +29 -0
- package/src/utils/compaction.js +30 -0
- package/src/utils/env-loader.js +5 -0
- package/src/utils/errors.js +80 -0
- package/src/utils/fs.js +101 -0
- package/src/utils/ids.js +5 -0
- package/src/utils/model-context-limits.js +30 -0
- package/src/utils/token-budget.js +74 -0
- package/src/utils/usage-cost.js +25 -0
- package/src/utils/usage-metrics.js +14 -0
- package/vendor/smol-toml-1.5.2.tgz +0 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ollama onboarding sub-phase — optional, runs inside Build (Phase 3).
|
|
3
|
+
*
|
|
4
|
+
* Steps: binary check → optional install/start → model selection → config write → smoke test.
|
|
5
|
+
* Fully skippable — never blocks setup if Ollama is not installed.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { execFile } from "node:child_process";
|
|
11
|
+
import { promisify } from "node:util";
|
|
12
|
+
import {
|
|
13
|
+
prompt, select, confirm,
|
|
14
|
+
green, yellow, dim, cyan, progressLine,
|
|
15
|
+
} from "../tui.js";
|
|
16
|
+
import { writeEnvFile } from "../auth/api-key.js";
|
|
17
|
+
import { detectOllama } from "../auth/ollama-detect.js";
|
|
18
|
+
|
|
19
|
+
const execFileAsync = promisify(execFile);
|
|
20
|
+
|
|
21
|
+
const DEFAULT_PRIMARY_MODEL = "kimi-k2.5";
|
|
22
|
+
const DEFAULT_FALLBACK_MODEL = "qwen3:8b";
|
|
23
|
+
const DEFAULT_BUMP_MODEL = "qwen3:14b";
|
|
24
|
+
const EMBEDDING_MODEL = "nomic-embed-text";
|
|
25
|
+
|
|
26
|
+
// ── Helpers ──────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parse the text output of `ollama list` into model name strings.
|
|
30
|
+
* Skips the header row (starts with "NAME").
|
|
31
|
+
*/
|
|
32
|
+
export function parseOllamaList(output) {
|
|
33
|
+
const models = [];
|
|
34
|
+
for (const line of output.trim().split("\n")) {
|
|
35
|
+
const trimmed = line.trim();
|
|
36
|
+
if (!trimmed || /^NAME\s/i.test(trimmed)) continue;
|
|
37
|
+
const name = trimmed.split(/\s+/)[0];
|
|
38
|
+
if (name) models.push(name);
|
|
39
|
+
}
|
|
40
|
+
return models;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function upsertRouterSection(content, sectionName, sectionBody) {
|
|
44
|
+
const escaped = sectionName.replace(/\./g, "\\.");
|
|
45
|
+
const sectionRe = new RegExp(`\\n?\\[${escaped}\\][\\s\\S]*?(?=\\n\\[|$)`, "s");
|
|
46
|
+
if (sectionRe.test(content)) {
|
|
47
|
+
return content.replace(sectionRe, `\n${sectionBody}`);
|
|
48
|
+
}
|
|
49
|
+
return content.trimEnd() + `\n\n${sectionBody}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Patch config/router.toml to set or update the local Ollama lanes.
|
|
54
|
+
*/
|
|
55
|
+
export function patchRouterLocalModels(installDir, models = []) {
|
|
56
|
+
const routerPath = path.join(installDir, "config", "router.toml");
|
|
57
|
+
let content = "";
|
|
58
|
+
try { content = fs.readFileSync(routerPath, "utf8"); } catch { /* new file */ }
|
|
59
|
+
|
|
60
|
+
const primaryModel = models[0] || DEFAULT_PRIMARY_MODEL;
|
|
61
|
+
const reportModel = models[1] || models[0] || DEFAULT_FALLBACK_MODEL;
|
|
62
|
+
const bumpModel = models[2] || models[1] || DEFAULT_BUMP_MODEL;
|
|
63
|
+
const fallbackMatch = content.match(/\[lanes\.local_report\][\s\S]*?fallback = "([^"]+)"/);
|
|
64
|
+
const fallbackLine = fallbackMatch?.[1] ? `fallback = "${fallbackMatch[1]}"\n` : "";
|
|
65
|
+
|
|
66
|
+
content = upsertRouterSection(
|
|
67
|
+
content,
|
|
68
|
+
"lanes.local_primary",
|
|
69
|
+
`[lanes.local_primary]\nprimary = "ollama/${primaryModel}"\n`,
|
|
70
|
+
);
|
|
71
|
+
content = upsertRouterSection(
|
|
72
|
+
content,
|
|
73
|
+
"lanes.local_cheap",
|
|
74
|
+
`[lanes.local_cheap]\nprimary = "ollama/${primaryModel}"\n`,
|
|
75
|
+
);
|
|
76
|
+
content = upsertRouterSection(
|
|
77
|
+
content,
|
|
78
|
+
"lanes.local_report",
|
|
79
|
+
`[lanes.local_report]\nprimary = "ollama/${reportModel}"\n${fallbackLine}manual_bump = "ollama/${bumpModel}"\n`,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
fs.writeFileSync(routerPath, content.trimStart() + "\n", "utf8");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function patchRouterLocalPrimary(installDir, model) {
|
|
86
|
+
patchRouterLocalModels(installDir, [model]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Pull the embedding model if not already present.
|
|
91
|
+
* Returns true if the model is available after the attempt.
|
|
92
|
+
*/
|
|
93
|
+
export async function pullEmbeddingModel(exec, availableModels = []) {
|
|
94
|
+
const baseName = EMBEDDING_MODEL.split(":")[0];
|
|
95
|
+
if (availableModels.some((m) => m.startsWith(baseName))) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
await exec("ollama", ["pull", EMBEDDING_MODEL], { timeout: 120000 });
|
|
100
|
+
return true;
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Enable embeddings in config and env after Ollama setup succeeds.
|
|
108
|
+
*/
|
|
109
|
+
export function enableEmbeddings(installDir) {
|
|
110
|
+
const embeddingsPath = path.join(installDir, "config", "embeddings.toml");
|
|
111
|
+
try {
|
|
112
|
+
let content = fs.readFileSync(embeddingsPath, "utf8");
|
|
113
|
+
content = content.replace(/^enabled\s*=\s*false/m, "enabled = true");
|
|
114
|
+
content = content.replace(/^index_on_write\s*=\s*false/m, "index_on_write = true");
|
|
115
|
+
fs.writeFileSync(embeddingsPath, content, "utf8");
|
|
116
|
+
} catch { /* file may not exist yet — will be created on first run */ }
|
|
117
|
+
|
|
118
|
+
writeEnvFile(installDir, { NEMORIS_ALLOW_EMBEDDINGS: "1" });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function hasCommand(exec, command) {
|
|
122
|
+
try {
|
|
123
|
+
await exec(command, ["--version"], { timeout: 5000 });
|
|
124
|
+
return true;
|
|
125
|
+
} catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function waitForOllamaReady({ fetchImpl = globalThis.fetch, timeoutMs = 30000 } = {}) {
|
|
131
|
+
const deadline = Date.now() + timeoutMs;
|
|
132
|
+
while (Date.now() < deadline) {
|
|
133
|
+
const result = await detectOllama({ fetchImpl });
|
|
134
|
+
if (result.ok) {
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
138
|
+
}
|
|
139
|
+
return { ok: false, modelCount: 0, models: [] };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function installAndStartOllama(exec, { platform = process.platform, fetchImpl = globalThis.fetch } = {}) {
|
|
143
|
+
try {
|
|
144
|
+
const useBrew = platform === "darwin" && await hasCommand(exec, "brew");
|
|
145
|
+
if (useBrew) {
|
|
146
|
+
await exec("brew", ["install", "ollama"], { timeout: 300000 });
|
|
147
|
+
} else {
|
|
148
|
+
await exec("sh", ["-lc", "curl -fsSL https://ollama.com/install.sh | sh"], { timeout: 300000 });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
await exec("sh", ["-lc", "nohup ollama serve >/tmp/nemoris-ollama.log 2>&1 &"], { timeout: 5000 });
|
|
152
|
+
const ready = await waitForOllamaReady({ fetchImpl, timeoutMs: 30000 });
|
|
153
|
+
return ready.ok;
|
|
154
|
+
} catch {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function chooseOllamaModels(availableModels = []) {
|
|
160
|
+
const curated = [];
|
|
161
|
+
const addChoice = (value, description) => {
|
|
162
|
+
if (!curated.some((item) => item.value === value)) {
|
|
163
|
+
curated.push({ label: value, value, description });
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
for (const model of availableModels.slice(0, 8)) {
|
|
168
|
+
addChoice(model, "Already installed.");
|
|
169
|
+
}
|
|
170
|
+
addChoice(DEFAULT_PRIMARY_MODEL, "Fast default for local work.");
|
|
171
|
+
addChoice(DEFAULT_FALLBACK_MODEL, "Reliable local fallback.");
|
|
172
|
+
addChoice(DEFAULT_BUMP_MODEL, "Heavier local bump option.");
|
|
173
|
+
|
|
174
|
+
const chosen = [];
|
|
175
|
+
while (chosen.length < 3) {
|
|
176
|
+
const remaining = curated.filter((item) => !chosen.includes(item.value));
|
|
177
|
+
const options = [...remaining];
|
|
178
|
+
if (chosen.length > 0) {
|
|
179
|
+
options.push({
|
|
180
|
+
label: "Done",
|
|
181
|
+
value: "__done__",
|
|
182
|
+
description: "Continue setup with the models already selected.",
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
options.push({
|
|
186
|
+
label: "Enter a different model name...",
|
|
187
|
+
value: "__custom__",
|
|
188
|
+
description: "Use a specific Ollama tag not shown here.",
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const picked = await select(
|
|
192
|
+
chosen.length === 0 ? "Local default model:" : `Add another local model (${chosen.length}/3 selected):`,
|
|
193
|
+
options,
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
if (picked === "__done__") {
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
let model = picked;
|
|
201
|
+
if (picked === "__custom__") {
|
|
202
|
+
model = await prompt("Model name", DEFAULT_PRIMARY_MODEL);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
model = String(model || "").trim();
|
|
206
|
+
if (model && !chosen.includes(model)) {
|
|
207
|
+
chosen.push(model);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return chosen;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ── Main Phase ───────────────────────────────────────────────────
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Run the Ollama onboarding sub-phase.
|
|
218
|
+
*
|
|
219
|
+
* @param {{ installDir: string, nonInteractive?: boolean, execImpl?: Function, fetchImpl?: Function, platform?: string }} options
|
|
220
|
+
* @returns {Promise<{ configured: boolean, verified: boolean, model?: string, models?: string[] }>}
|
|
221
|
+
*/
|
|
222
|
+
export async function runOllamaPhase({ installDir, nonInteractive = false, execImpl = null, fetchImpl = globalThis.fetch, platform = process.platform }) {
|
|
223
|
+
const exec = execImpl || (async (cmd, args, opts) => execFileAsync(cmd, args, opts));
|
|
224
|
+
|
|
225
|
+
if (nonInteractive) {
|
|
226
|
+
if (process.env.NEMORIS_SKIP_OLLAMA === "true") {
|
|
227
|
+
return { configured: false, verified: false };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
await exec("ollama", ["--version"], { timeout: 5000 });
|
|
232
|
+
} catch {
|
|
233
|
+
console.log(` ${yellow("!")} Ollama not installed — skipping local model setup.`);
|
|
234
|
+
console.log(` ${dim("Install from https://ollama.com then run: nemoris setup ollama")}`);
|
|
235
|
+
return { configured: false, verified: false };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const requestedModels = String(process.env.NEMORIS_OLLAMA_MODELS || process.env.NEMORIS_OLLAMA_MODEL || "")
|
|
239
|
+
.split(",")
|
|
240
|
+
.map((item) => item.trim())
|
|
241
|
+
.filter(Boolean);
|
|
242
|
+
let model = requestedModels[0] || DEFAULT_PRIMARY_MODEL;
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
const { stdout } = await exec("ollama", ["list"], { timeout: 10000 });
|
|
246
|
+
const available = parseOllamaList(stdout);
|
|
247
|
+
const baseName = model.split(":")[0];
|
|
248
|
+
if (available.length > 0 && !available.some((item) => item.startsWith(baseName))) {
|
|
249
|
+
model = available[0];
|
|
250
|
+
}
|
|
251
|
+
} catch { /* keep configured/default model */ }
|
|
252
|
+
|
|
253
|
+
const localModels = requestedModels.length > 0 ? requestedModels : [model];
|
|
254
|
+
patchRouterLocalModels(installDir, localModels);
|
|
255
|
+
|
|
256
|
+
let availableForEmbed = [];
|
|
257
|
+
try {
|
|
258
|
+
const { stdout } = await exec("ollama", ["list"], { timeout: 10000 });
|
|
259
|
+
availableForEmbed = parseOllamaList(stdout);
|
|
260
|
+
} catch { /* best effort */ }
|
|
261
|
+
const embeddingReady = await pullEmbeddingModel(exec, availableForEmbed);
|
|
262
|
+
if (embeddingReady) {
|
|
263
|
+
enableEmbeddings(installDir);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
try {
|
|
267
|
+
await exec("ollama", ["run", localModels[0], "say hello"], { timeout: 30000 });
|
|
268
|
+
console.log(` ${green("✅")} Ollama connected — local inference ready`);
|
|
269
|
+
return { configured: true, verified: true, model: localModels[0], models: localModels, embeddingReady };
|
|
270
|
+
} catch (err) {
|
|
271
|
+
if (err.killed || err.signal || err.code === "ETIMEDOUT") {
|
|
272
|
+
console.log(` ${yellow("⚠️")} Model didn't respond — it may still be loading — you can try again later with \`nemoris setup ollama\``);
|
|
273
|
+
} else {
|
|
274
|
+
console.log(` ${yellow("⚠️")} Model test failed — you can try again later with \`nemoris setup ollama\``);
|
|
275
|
+
}
|
|
276
|
+
return { configured: true, verified: false, model: localModels[0], models: localModels, embeddingReady };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
console.log(`\n Want to run AI locally on your machine? ${cyan("Ollama")} lets you use powerful models for free — no API keys, no cloud costs.\n`);
|
|
281
|
+
|
|
282
|
+
const gate = await confirm("Want to add a free local fallback using Ollama?", true);
|
|
283
|
+
if (!gate) {
|
|
284
|
+
return { configured: false, verified: false };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
let version = "";
|
|
288
|
+
try {
|
|
289
|
+
const { stdout } = await exec("ollama", ["--version"], { timeout: 5000 });
|
|
290
|
+
version = stdout.trim();
|
|
291
|
+
} catch {
|
|
292
|
+
console.log(`\n ${yellow("!")} Ollama is not installed on this machine.`);
|
|
293
|
+
const shouldInstall = await confirm("Want to install Ollama now?", true);
|
|
294
|
+
if (!shouldInstall) {
|
|
295
|
+
console.log(` ${dim("Skipping local model setup for now.")}\n`);
|
|
296
|
+
return { configured: false, verified: false };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
console.log(`\n ${dim("Installing Ollama and waiting for it to start...")}`);
|
|
300
|
+
const installed = await installAndStartOllama(exec, { platform, fetchImpl });
|
|
301
|
+
if (!installed) {
|
|
302
|
+
console.log(` ${yellow("!")} Ollama install or startup failed — continuing without local models.\n`);
|
|
303
|
+
return { configured: false, verified: false };
|
|
304
|
+
}
|
|
305
|
+
version = "installed during setup";
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
console.log(progressLine("Ollama found", version || "installed"));
|
|
309
|
+
|
|
310
|
+
let availableModels = [];
|
|
311
|
+
try {
|
|
312
|
+
const { stdout } = await exec("ollama", ["list"], { timeout: 10000 });
|
|
313
|
+
availableModels = parseOllamaList(stdout);
|
|
314
|
+
} catch { /* no models listed */ }
|
|
315
|
+
|
|
316
|
+
console.log(`\n Which local models would you like to use? ${dim(`(${DEFAULT_PRIMARY_MODEL} is fastest, ${DEFAULT_FALLBACK_MODEL} is reliable)`)}`);
|
|
317
|
+
const chosenModels = await chooseOllamaModels(availableModels);
|
|
318
|
+
const localModels = chosenModels.length > 0 ? chosenModels : [DEFAULT_PRIMARY_MODEL];
|
|
319
|
+
|
|
320
|
+
patchRouterLocalModels(installDir, localModels);
|
|
321
|
+
console.log(progressLine("Local models set", `config/router.toml (${localModels.join(", ")})`));
|
|
322
|
+
|
|
323
|
+
console.log(`\n Pulling embedding model (${dim(EMBEDDING_MODEL)})...`);
|
|
324
|
+
const embeddingReady = await pullEmbeddingModel(exec, availableModels);
|
|
325
|
+
if (embeddingReady) {
|
|
326
|
+
enableEmbeddings(installDir);
|
|
327
|
+
console.log(progressLine("Embeddings enabled", `${EMBEDDING_MODEL} → semantic search`));
|
|
328
|
+
} else {
|
|
329
|
+
console.log(` ${yellow("!")} Embedding model pull failed — semantic search disabled for now.`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
console.log(`\n Testing ${cyan(localModels[0])}...`);
|
|
333
|
+
try {
|
|
334
|
+
await exec("ollama", ["run", localModels[0], "say hello"], { timeout: 30000 });
|
|
335
|
+
console.log(` ${green("✅")} Ollama connected — local inference ready`);
|
|
336
|
+
return { configured: true, verified: true, model: localModels[0], models: localModels, embeddingReady };
|
|
337
|
+
} catch (err) {
|
|
338
|
+
if (err.killed || err.signal || err.code === "ETIMEDOUT") {
|
|
339
|
+
console.log(` ${yellow("⚠️")} Model didn't respond — it may still be loading — you can try again later with \`nemoris setup ollama\``);
|
|
340
|
+
} else {
|
|
341
|
+
console.log(` ${yellow("⚠️")} Model test failed — you can try again later with \`nemoris setup ollama\``);
|
|
342
|
+
}
|
|
343
|
+
return { configured: true, verified: false, model: localModels[0], models: localModels, embeddingReady };
|
|
344
|
+
}
|
|
345
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scaffold phase — creates the full directory tree and writes default config
|
|
3
|
+
* files from templates. Safe to run multiple times (idempotent).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import {
|
|
9
|
+
runtimeTemplate,
|
|
10
|
+
deliveryTemplate,
|
|
11
|
+
peersTemplate,
|
|
12
|
+
outputContractsTemplate,
|
|
13
|
+
embeddingsTemplate,
|
|
14
|
+
improvementTargetsTemplate,
|
|
15
|
+
jobTemplate,
|
|
16
|
+
policyTemplates,
|
|
17
|
+
scaffoldToolsAndSkills,
|
|
18
|
+
} from "../templates.js";
|
|
19
|
+
|
|
20
|
+
// Directories to create under installDir
|
|
21
|
+
const DIRECTORIES = [
|
|
22
|
+
path.join("config", "agents"),
|
|
23
|
+
path.join("config", "providers"),
|
|
24
|
+
path.join("config", "jobs"),
|
|
25
|
+
path.join("config", "policies"),
|
|
26
|
+
path.join("config", "identity"),
|
|
27
|
+
"state",
|
|
28
|
+
path.join("state", "memory"),
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Write a file only if it does not already exist (idempotency).
|
|
33
|
+
* @param {string} filePath Absolute path to the target file.
|
|
34
|
+
* @param {string} content Content to write.
|
|
35
|
+
* @returns {"created"|"exists"}
|
|
36
|
+
*/
|
|
37
|
+
function writeIfMissing(filePath, content) {
|
|
38
|
+
if (fs.existsSync(filePath)) {
|
|
39
|
+
return "exists";
|
|
40
|
+
}
|
|
41
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
42
|
+
return "created";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Scaffold the nemoris installation directory.
|
|
47
|
+
*
|
|
48
|
+
* @param {{ installDir: string }} options
|
|
49
|
+
* @returns {Promise<{ dirs: string[], files: { path: string, status: "created"|"exists" }[] }>}
|
|
50
|
+
*/
|
|
51
|
+
export async function scaffold({ installDir }) {
|
|
52
|
+
const createdDirs = [];
|
|
53
|
+
|
|
54
|
+
// 1. Create all required directories
|
|
55
|
+
for (const rel of DIRECTORIES) {
|
|
56
|
+
const absPath = path.join(installDir, rel);
|
|
57
|
+
if (!fs.existsSync(absPath)) {
|
|
58
|
+
fs.mkdirSync(absPath, { recursive: true });
|
|
59
|
+
createdDirs.push(rel);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const fileResults = [];
|
|
64
|
+
|
|
65
|
+
// 2. Write top-level config files
|
|
66
|
+
const topLevelConfigs = [
|
|
67
|
+
{ rel: path.join("config", "runtime.toml"), content: runtimeTemplate() },
|
|
68
|
+
{ rel: path.join("config", "delivery.toml"), content: deliveryTemplate() },
|
|
69
|
+
{ rel: path.join("config", "peers.toml"), content: peersTemplate() },
|
|
70
|
+
{ rel: path.join("config", "output-contracts.toml"), content: outputContractsTemplate() },
|
|
71
|
+
{ rel: path.join("config", "embeddings.toml"), content: embeddingsTemplate() },
|
|
72
|
+
{ rel: path.join("config", "improvement-targets.toml"), content: improvementTargetsTemplate() },
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
for (const { rel, content } of topLevelConfigs) {
|
|
76
|
+
const absPath = path.join(installDir, rel);
|
|
77
|
+
const status = writeIfMissing(absPath, content);
|
|
78
|
+
fileResults.push({ path: rel, status });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 3. Write default job manifest
|
|
82
|
+
const jobId = "workspace-health";
|
|
83
|
+
const jobRel = path.join("config", "jobs", `${jobId}.toml`);
|
|
84
|
+
const jobStatus = writeIfMissing(path.join(installDir, jobRel), jobTemplate(jobId));
|
|
85
|
+
fileResults.push({ path: jobRel, status: jobStatus });
|
|
86
|
+
|
|
87
|
+
// 4. Write default policy files
|
|
88
|
+
const policies = policyTemplates();
|
|
89
|
+
for (const [stem, content] of Object.entries(policies)) {
|
|
90
|
+
const rel = path.join("config", "policies", `${stem}.toml`);
|
|
91
|
+
const status = writeIfMissing(path.join(installDir, rel), content);
|
|
92
|
+
fileResults.push({ path: rel, status });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 5. Scaffold execution layer directories and files
|
|
96
|
+
await scaffoldToolsAndSkills(installDir);
|
|
97
|
+
|
|
98
|
+
return { dirs: createdDirs, files: fileResults };
|
|
99
|
+
}
|