somora 2026.930.1
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 +364 -0
- package/bin/node-version.d.mts +3 -0
- package/bin/node-version.mjs +45 -0
- package/bin/somora.mjs +77 -0
- package/config.example.yaml +896 -0
- package/docs/agents.md +677 -0
- package/docs/api.md +3194 -0
- package/docs/browser.md +317 -0
- package/docs/builder.md +331 -0
- package/docs/cache-strategy.md +373 -0
- package/docs/compaction.md +253 -0
- package/docs/display.md +154 -0
- package/docs/dream-phases.md +891 -0
- package/docs/files.md +387 -0
- package/docs/imagegen.md +366 -0
- package/docs/images/somora-hero.png +0 -0
- package/docs/images/somora-mobile-2026-05-23.png +0 -0
- package/docs/images/somora-tui-2026-05-23.png +0 -0
- package/docs/images/somora-web-2026-05-23.png +0 -0
- package/docs/index.md +178 -0
- package/docs/lsp.md +93 -0
- package/docs/mcp.md +332 -0
- package/docs/memory.md +407 -0
- package/docs/mobile.md +310 -0
- package/docs/models.md +379 -0
- package/docs/projects.md +425 -0
- package/docs/realtime-voice.md +293 -0
- package/docs/resources.md +230 -0
- package/docs/sampling.md +128 -0
- package/docs/security.md +189 -0
- package/docs/sentinel.md +295 -0
- package/docs/setup.md +1217 -0
- package/docs/skills.md +501 -0
- package/docs/team.md +189 -0
- package/docs/thinking.md +463 -0
- package/docs/tmux.md +399 -0
- package/docs/tools.md +117 -0
- package/docs/videogen.md +191 -0
- package/docs/voice.md +288 -0
- package/docs/web.md +893 -0
- package/docs/wiki.md +583 -0
- package/npm-shrinkwrap.json +5670 -0
- package/package.json +116 -0
- package/src/attachments/store.ts +196 -0
- package/src/browser/change-stream.ts +31 -0
- package/src/browser/display.ts +108 -0
- package/src/browser/policy.ts +121 -0
- package/src/browser/screencast.ts +374 -0
- package/src/browser/service.ts +1337 -0
- package/src/browser/session.ts +15 -0
- package/src/browser/snapshot.ts +40 -0
- package/src/cli/auth.ts +117 -0
- package/src/cli/codex.ts +41 -0
- package/src/cli/lsp.ts +71 -0
- package/src/cli/resolvers/clawhub.ts +400 -0
- package/src/cli/setup.ts +835 -0
- package/src/cli/skill.ts +619 -0
- package/src/cli/somora.ts +548 -0
- package/src/cli/systemd-unit.ts +72 -0
- package/src/cli/team.ts +148 -0
- package/src/cli/tui/activity-stream.ts +121 -0
- package/src/cli/tui/api.ts +479 -0
- package/src/cli/tui/app.tsx +1169 -0
- package/src/cli/tui/autocomplete.tsx +55 -0
- package/src/cli/tui/commands.ts +913 -0
- package/src/cli/tui/dream-glyphs.ts +22 -0
- package/src/cli/tui/footer.tsx +15 -0
- package/src/cli/tui/format.ts +28 -0
- package/src/cli/tui/header.tsx +279 -0
- package/src/cli/tui/index.tsx +120 -0
- package/src/cli/tui/markdown.tsx +63 -0
- package/src/cli/tui/sampling.ts +162 -0
- package/src/cli/tui/separator.tsx +13 -0
- package/src/cli/tui/state.ts +42 -0
- package/src/cli/tui/stream.ts +330 -0
- package/src/cli/tui/thinking-text.ts +54 -0
- package/src/cli/tui/turn-views.tsx +499 -0
- package/src/cli/tui/types.ts +410 -0
- package/src/cli/tui/work-queue.ts +161 -0
- package/src/cli/update-args.ts +55 -0
- package/src/cli/wiki.ts +406 -0
- package/src/compaction/index.ts +28 -0
- package/src/compaction/midturn.ts +210 -0
- package/src/compaction/policy.ts +154 -0
- package/src/compaction/summarize.ts +691 -0
- package/src/compaction/template.ts +90 -0
- package/src/compaction/types.ts +148 -0
- package/src/config/loader.ts +276 -0
- package/src/config/reload.ts +43 -0
- package/src/config/types.ts +2292 -0
- package/src/dream/deep-actions.ts +324 -0
- package/src/dream/deep-dispatcher.ts +237 -0
- package/src/dream/deep-llm.ts +388 -0
- package/src/dream/deep-prompts.ts +106 -0
- package/src/dream/deep-runner.ts +757 -0
- package/src/dream/deep-skip-cache.ts +199 -0
- package/src/dream/deep-worker.ts +229 -0
- package/src/dream/json-salvage.ts +34 -0
- package/src/dream/judge.ts +188 -0
- package/src/dream/loop-state.ts +286 -0
- package/src/dream/lucid-actions.ts +303 -0
- package/src/dream/lucid-batches.ts +94 -0
- package/src/dream/lucid-prompt.ts +82 -0
- package/src/dream/lucid-runner.ts +744 -0
- package/src/dream/lucid-storage.ts +277 -0
- package/src/dream/lucid-structure.ts +102 -0
- package/src/dream/lucid-types.ts +137 -0
- package/src/dream/lucid-worker.ts +224 -0
- package/src/dream/rem-dedup.ts +502 -0
- package/src/dream/rem-extract.ts +782 -0
- package/src/dream/rem-reset-run.ts +67 -0
- package/src/dream/rem-runner.ts +696 -0
- package/src/dream/rem-worker.ts +527 -0
- package/src/dream/review-window.ts +71 -0
- package/src/dream/scheduler-state.ts +129 -0
- package/src/dream/storage.ts +497 -0
- package/src/dream/types.ts +133 -0
- package/src/dream/wiki-context.ts +133 -0
- package/src/engine/a2a.ts +33 -0
- package/src/engine/availability.ts +63 -0
- package/src/engine/claude-cli.ts +969 -0
- package/src/engine/codex-app-server-client.ts +294 -0
- package/src/engine/codex-bin.ts +49 -0
- package/src/engine/codex-cli.ts +1014 -0
- package/src/engine/codex-dynamic-tools.ts +239 -0
- package/src/engine/codex-home.ts +63 -0
- package/src/engine/codex-thread-config.ts +74 -0
- package/src/engine/context-budget.ts +257 -0
- package/src/engine/engine-meta-labels.ts +211 -0
- package/src/engine/grok-cli.ts +941 -0
- package/src/engine/inline-think.ts +59 -0
- package/src/engine/model-availability.ts +105 -0
- package/src/engine/openai-compatible.ts +2464 -0
- package/src/engine/reasoning-retry.ts +83 -0
- package/src/engine/registry.ts +13 -0
- package/src/engine/replay.ts +195 -0
- package/src/engine/sampling.ts +90 -0
- package/src/engine/thinking-params.ts +264 -0
- package/src/engine/types.ts +269 -0
- package/src/engine/user-tag.ts +24 -0
- package/src/imagegen/aspect.ts +128 -0
- package/src/imagegen/generate.ts +642 -0
- package/src/imagegen/references.ts +75 -0
- package/src/imagegen/types.ts +154 -0
- package/src/lsp/client.ts +183 -0
- package/src/lsp/fake-server.helper.mjs +42 -0
- package/src/lsp/format.ts +29 -0
- package/src/lsp/index.ts +21 -0
- package/src/lsp/manager.ts +238 -0
- package/src/lsp/registry.ts +151 -0
- package/src/mcp/config.ts +117 -0
- package/src/mcp/hub/audit.ts +55 -0
- package/src/mcp/hub/bridge.ts +115 -0
- package/src/mcp/hub/catalog.ts +69 -0
- package/src/mcp/hub/credentials.ts +406 -0
- package/src/mcp/hub/env-expand.ts +14 -0
- package/src/mcp/hub/manager.ts +770 -0
- package/src/mcp/hub/normalize.ts +213 -0
- package/src/mcp/server.ts +368 -0
- package/src/mcp/tool-schema.ts +20 -0
- package/src/media/capabilities.ts +392 -0
- package/src/media/records.ts +175 -0
- package/src/media/store.ts +217 -0
- package/src/media/types.ts +69 -0
- package/src/memory/chunking.ts +168 -0
- package/src/memory/embeddings.ts +262 -0
- package/src/memory/index.ts +15 -0
- package/src/memory/inject.ts +197 -0
- package/src/memory/manager.ts +996 -0
- package/src/memory/registry.ts +176 -0
- package/src/memory/rescan.ts +101 -0
- package/src/memory/retrieval.ts +586 -0
- package/src/memory/shared-index.ts +372 -0
- package/src/memory/slug.ts +39 -0
- package/src/memory/storage.ts +385 -0
- package/src/memory/watcher.ts +134 -0
- package/src/multimodal/blocks.ts +101 -0
- package/src/multimodal/dimensions.ts +214 -0
- package/src/multimodal/load.ts +86 -0
- package/src/multimodal/mime.ts +135 -0
- package/src/multimodal/pdf-render.ts +80 -0
- package/src/multimodal/user-content.ts +266 -0
- package/src/persona/files.ts +144 -0
- package/src/persona/loader.ts +598 -0
- package/src/persona/skill-gating-store.ts +59 -0
- package/src/persona/tool-gating-store.ts +113 -0
- package/src/projects/focus.ts +186 -0
- package/src/projects/prompt-block.ts +106 -0
- package/src/projects/scheme.ts +107 -0
- package/src/projects/store.ts +144 -0
- package/src/projects/types.ts +73 -0
- package/src/sentinel/dispatcher.ts +97 -0
- package/src/sentinel/schedule.ts +271 -0
- package/src/sentinel/scheduler.ts +840 -0
- package/src/sentinel/store.ts +259 -0
- package/src/sentinel/types.ts +221 -0
- package/src/server/activity-stream.ts +160 -0
- package/src/server/ask-calls.ts +137 -0
- package/src/server/ask-wait-graph.ts +171 -0
- package/src/server/async-tasks.ts +199 -0
- package/src/server/builder-busy.ts +86 -0
- package/src/server/builder-prompt.ts +204 -0
- package/src/server/builder-questions.ts +117 -0
- package/src/server/builder-session.ts +249 -0
- package/src/server/chat-aborts.ts +83 -0
- package/src/server/claude-config-dir.ts +71 -0
- package/src/server/claude-credential-sync.ts +454 -0
- package/src/server/env-file.ts +100 -0
- package/src/server/env.ts +115 -0
- package/src/server/heal-session.ts +151 -0
- package/src/server/history-page.ts +46 -0
- package/src/server/index.ts +7244 -0
- package/src/server/lockfile.ts +89 -0
- package/src/server/logger.ts +67 -0
- package/src/server/logs.ts +187 -0
- package/src/server/loopback-fetch.ts +130 -0
- package/src/server/openai-client.ts +89 -0
- package/src/server/prompt-assembly.ts +334 -0
- package/src/server/restart-reconcile.ts +139 -0
- package/src/server/run-turn-fallback.ts +275 -0
- package/src/server/run-turn-types.ts +91 -0
- package/src/server/run-turn.ts +1474 -0
- package/src/server/sanitize-assistant-text.ts +112 -0
- package/src/server/session-export.ts +220 -0
- package/src/server/session-queue.ts +376 -0
- package/src/server/session-workdir.ts +49 -0
- package/src/server/sse-h2-safe.ts +61 -0
- package/src/server/sse-liveness.ts +162 -0
- package/src/server/sse-serializer.ts +161 -0
- package/src/server/start-turn.ts +249 -0
- package/src/server/steer-inbox.ts +107 -0
- package/src/server/tls-keeper.ts +153 -0
- package/src/server/tool-format.ts +167 -0
- package/src/server/turn-framing.ts +52 -0
- package/src/server/turn-origin-kind.ts +74 -0
- package/src/server/turn-origin.ts +40 -0
- package/src/server/work-ledger.ts +975 -0
- package/src/server/workspace.ts +114 -0
- package/src/setup/config-edit.ts +201 -0
- package/src/setup/presets.ts +71 -0
- package/src/setup/prompt.ts +163 -0
- package/src/setup/tailscale.ts +44 -0
- package/src/skills/bin-checks.ts +227 -0
- package/src/skills/bootstrap.ts +347 -0
- package/src/skills/env-scope.ts +175 -0
- package/src/skills/gating.ts +71 -0
- package/src/skills/lint.ts +202 -0
- package/src/skills/load.ts +368 -0
- package/src/skills/path-helpers.ts +102 -0
- package/src/skills/registry.ts +178 -0
- package/src/ssh/exec.ts +142 -0
- package/src/ssh/index.ts +12 -0
- package/src/ssh/known-hosts.ts +109 -0
- package/src/ssh/pool.ts +307 -0
- package/src/storage/sessions.ts +602 -0
- package/src/team/render.ts +149 -0
- package/src/team/resolve.ts +122 -0
- package/src/team/store.ts +124 -0
- package/src/team/types.ts +111 -0
- package/src/team/write.ts +95 -0
- package/src/testing/isolated-home.mts +46 -0
- package/src/tmux/attention-watcher.ts +272 -0
- package/src/tmux/attention.ts +336 -0
- package/src/tmux/list.ts +91 -0
- package/src/tmux/origin-store.ts +102 -0
- package/src/tmux/tui-markers.ts +267 -0
- package/src/tools/agents/ask-cancel.ts +94 -0
- package/src/tools/agents/ask-result.ts +235 -0
- package/src/tools/agents/ask.ts +704 -0
- package/src/tools/agents/builder-dispatch.ts +217 -0
- package/src/tools/agents/images.ts +104 -0
- package/src/tools/agents/index.ts +42 -0
- package/src/tools/agents/long-task-timeouts.ts +39 -0
- package/src/tools/agents/session-list.ts +136 -0
- package/src/tools/agents/session-model.ts +106 -0
- package/src/tools/agents/spawn.ts +845 -0
- package/src/tools/agents/status.ts +589 -0
- package/src/tools/browser/index.ts +6 -0
- package/src/tools/browser/ops.ts +145 -0
- package/src/tools/browser/tools.ts +184 -0
- package/src/tools/builder/short-descriptions.ts +80 -0
- package/src/tools/builder/tools.ts +222 -0
- package/src/tools/docs/index.ts +1 -0
- package/src/tools/docs/tools.ts +228 -0
- package/src/tools/dream/index.ts +11 -0
- package/src/tools/dream/tools.ts +1002 -0
- package/src/tools/exec/allowlist.ts +233 -0
- package/src/tools/exec/background-detach.helper.mts +27 -0
- package/src/tools/exec/blacklist.ts +336 -0
- package/src/tools/exec/concurrency.ts +150 -0
- package/src/tools/exec/fit-output.ts +82 -0
- package/src/tools/exec/index.ts +7 -0
- package/src/tools/exec/internal-env.ts +89 -0
- package/src/tools/exec/job-store.ts +403 -0
- package/src/tools/exec/local.ts +649 -0
- package/src/tools/exec/remote.ts +399 -0
- package/src/tools/exec/tools.ts +934 -0
- package/src/tools/file/analyze.ts +378 -0
- package/src/tools/file/index.ts +2 -0
- package/src/tools/file/local.ts +707 -0
- package/src/tools/file/lsp-hook.ts +72 -0
- package/src/tools/file/persona-guard.ts +61 -0
- package/src/tools/file/policy.ts +292 -0
- package/src/tools/file/read-format.ts +129 -0
- package/src/tools/file/remote.ts +680 -0
- package/src/tools/file/replace.ts +507 -0
- package/src/tools/file/search-window.ts +224 -0
- package/src/tools/file/tools.ts +658 -0
- package/src/tools/file/write-scope.ts +182 -0
- package/src/tools/gating.ts +106 -0
- package/src/tools/image/budget.ts +82 -0
- package/src/tools/image/index.ts +7 -0
- package/src/tools/image/tools.ts +601 -0
- package/src/tools/index.ts +99 -0
- package/src/tools/memory/index.ts +12 -0
- package/src/tools/memory/tools.ts +399 -0
- package/src/tools/projects/index.ts +1 -0
- package/src/tools/projects/tools.ts +643 -0
- package/src/tools/registry.ts +427 -0
- package/src/tools/resources/index.ts +8 -0
- package/src/tools/resources/tools.ts +176 -0
- package/src/tools/resources/visibility.ts +60 -0
- package/src/tools/sentinel/index.ts +1 -0
- package/src/tools/sentinel/tools.ts +592 -0
- package/src/tools/skill/index.ts +4 -0
- package/src/tools/skill/tools.ts +285 -0
- package/src/tools/time/index.ts +5 -0
- package/src/tools/time/tools.ts +123 -0
- package/src/tools/tmux/index.ts +1 -0
- package/src/tools/tmux/local.ts +277 -0
- package/src/tools/tmux/remote.ts +168 -0
- package/src/tools/tmux/tools.ts +1064 -0
- package/src/tools/tool-output.ts +97 -0
- package/src/tools/types.ts +227 -0
- package/src/tools/video/index.ts +1 -0
- package/src/tools/video/tools.ts +425 -0
- package/src/tools/web/fetch.ts +337 -0
- package/src/tools/web/index.ts +4 -0
- package/src/tools/web/tools.ts +186 -0
- package/src/tools/wiki/index.ts +1 -0
- package/src/tools/wiki/tools.ts +445 -0
- package/src/tts/cache-gc.ts +128 -0
- package/src/tts/prepare-for-tts.ts +114 -0
- package/src/tts/service.ts +332 -0
- package/src/types/events.ts +695 -0
- package/src/types/turn-origin.ts +53 -0
- package/src/version.ts +21 -0
- package/src/videogen/dialects.ts +222 -0
- package/src/videogen/generate.ts +484 -0
- package/src/videogen/jobs.ts +178 -0
- package/src/videogen/runner.ts +125 -0
- package/src/videogen/wake.ts +119 -0
- package/src/voice/realtime/call.ts +948 -0
- package/src/voice/realtime/consult.ts +293 -0
- package/src/voice/realtime/fake-provider.ts +134 -0
- package/src/voice/realtime/manager.ts +384 -0
- package/src/voice/realtime/openai-provider.ts +471 -0
- package/src/voice/realtime/persona.ts +227 -0
- package/src/voice/realtime/session-match.ts +116 -0
- package/src/voice/realtime/types.ts +182 -0
- package/src/wiki/conflict.ts +113 -0
- package/src/wiki/explorer.ts +578 -0
- package/src/wiki/index-builder.ts +172 -0
- package/src/wiki/language.ts +134 -0
- package/src/wiki/log-builder.ts +150 -0
- package/src/wiki/map.ts +258 -0
- package/src/wiki/migration/analyze.ts +304 -0
- package/src/wiki/migration/execute.ts +689 -0
- package/src/wiki/migration/refine.ts +402 -0
- package/src/wiki/migration/store.ts +100 -0
- package/src/wiki/move-page.ts +57 -0
- package/src/wiki/structure-file.ts +192 -0
- package/src/wiki/taxonomy.ts +140 -0
- package/src/wiki/templates.ts +163 -0
- package/src/wiki/types.ts +133 -0
- package/templates/skills/README.md +24 -0
- package/templates/skills/_templates/api-wrapper/SKILL.md +26 -0
- package/templates/skills/_templates/cli-wrapper/BOOTSTRAP.md +32 -0
- package/templates/skills/_templates/cli-wrapper/SKILL.md +24 -0
- package/templates/skills/_templates/default/SKILL.md +25 -0
- package/templates/skills/builder-handover/SKILL.md +96 -0
- package/templates/skills/builder-handover/assets/ORDER.md +12 -0
- package/templates/skills/skill-author/SKILL.md +110 -0
- package/tsconfig.json +22 -0
- package/web/dist/assets/index-BaVv6pB2.js +631 -0
- package/web/dist/assets/index-BaVv6pB2.js.map +1 -0
- package/web/dist/assets/index-V3FV3Z25.css +32 -0
- package/web/dist/favicon.svg +8 -0
- package/web/dist/index.html +20 -0
- package/web/package.json +36 -0
- package/web/tsconfig.json +25 -0
- package/web-mobile/dist/apple-touch-icon.png +0 -0
- package/web-mobile/dist/assets/index-BqKt7IMx.css +1 -0
- package/web-mobile/dist/assets/index-X_vRr6cd.js +88 -0
- package/web-mobile/dist/assets/index-X_vRr6cd.js.map +1 -0
- package/web-mobile/dist/favicon.svg +8 -0
- package/web-mobile/dist/icon-192.png +0 -0
- package/web-mobile/dist/icon-512.png +0 -0
- package/web-mobile/dist/index.html +27 -0
- package/web-mobile/dist/manifest.webmanifest +32 -0
- package/web-mobile/dist/service-worker.js +90 -0
- package/web-mobile/package.json +28 -0
- package/web-mobile/tsconfig.json +25 -0
package/src/cli/setup.ts
ADDED
|
@@ -0,0 +1,835 @@
|
|
|
1
|
+
// `somora setup` — the guided first-run assistant.
|
|
2
|
+
//
|
|
3
|
+
// Walks a person from "somora is installed" to "my agent answers, on my
|
|
4
|
+
// phone too": model providers and logins, the first agent, memory and
|
|
5
|
+
// the dream phases, the team file, HTTPS through Tailscale, and a real
|
|
6
|
+
// test message at the end. Every step looks at what is already there
|
|
7
|
+
// first, so it is safe to run again at any time — alone
|
|
8
|
+
// (`somora setup access`) or as a whole.
|
|
9
|
+
//
|
|
10
|
+
// It only ever edits config.yaml / agent.yaml through
|
|
11
|
+
// src/setup/config-edit.ts: comments survive, the old file is kept as a
|
|
12
|
+
// backup, and a result the server would refuse is never written.
|
|
13
|
+
|
|
14
|
+
import { chmodSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
15
|
+
import { homedir, networkInterfaces, userInfo } from 'node:os';
|
|
16
|
+
import { request as httpRequest } from 'node:http';
|
|
17
|
+
import { request as httpsRequest } from 'node:https';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
|
|
20
|
+
import { listAgents } from '../persona/loader.ts';
|
|
21
|
+
import { teamFilePath } from '../team/store.ts';
|
|
22
|
+
import { initialTeamFile, writeTeamFile } from '../team/write.ts';
|
|
23
|
+
import {
|
|
24
|
+
BASE_CONFIG, commit, configuredAliases, deleteIn, getIn, openYaml, setIn, upsertProvider, type YamlFile,
|
|
25
|
+
} from '../setup/config-edit.ts';
|
|
26
|
+
import { aliasFor, CLAUDE_PRESET, CODEX_PRESET, pickPreferred, type ModelPreset } from '../setup/presets.ts';
|
|
27
|
+
import {
|
|
28
|
+
bold, capture, cyan, dim, explain, fail, heading, ok, onPath, Prompter, say, warn, type Choice,
|
|
29
|
+
} from '../setup/prompt.ts';
|
|
30
|
+
import { isOperatorError, tailscaleState } from '../setup/tailscale.ts';
|
|
31
|
+
import { SOMORA_VERSION } from '../version.ts';
|
|
32
|
+
|
|
33
|
+
const HOME = homedir();
|
|
34
|
+
const SOMORA_HOME = process.env.SOMORA_HOME ?? join(HOME, '.somora');
|
|
35
|
+
const CONFIG_PATH = join(SOMORA_HOME, 'config.yaml');
|
|
36
|
+
const AGENTS_DIR = join(SOMORA_HOME, 'agents');
|
|
37
|
+
const UNIT_PATH = join(HOME, '.config', 'systemd', 'user', 'somora.service');
|
|
38
|
+
const BIN_PATH = process.env.SOMORA_BIN_PATH ?? '';
|
|
39
|
+
|
|
40
|
+
const STEPS = ['models', 'agent', 'memory', 'team', 'access', 'start'] as const;
|
|
41
|
+
type Step = (typeof STEPS)[number];
|
|
42
|
+
|
|
43
|
+
const STEP_TITLES: Record<Step, string> = {
|
|
44
|
+
models: 'Models — which AI your agents use',
|
|
45
|
+
agent: 'Your first agent',
|
|
46
|
+
memory: 'Memory and dreaming',
|
|
47
|
+
team: 'Team',
|
|
48
|
+
access: 'Access from your other devices',
|
|
49
|
+
start: 'Start and test',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
interface Ctx {
|
|
53
|
+
p: Prompter;
|
|
54
|
+
/** Something changed that a running server only sees after a restart. */
|
|
55
|
+
needsRestart: boolean;
|
|
56
|
+
/** Name the person gave for themselves, reused across steps. */
|
|
57
|
+
principal?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function usage(): string {
|
|
61
|
+
return `somora setup — the guided assistant (safe to run again at any time)
|
|
62
|
+
|
|
63
|
+
Usage:
|
|
64
|
+
somora setup all steps, in order
|
|
65
|
+
somora setup <step> one step only
|
|
66
|
+
|
|
67
|
+
Steps:
|
|
68
|
+
${STEPS.map((s) => ` ${s.padEnd(8)} ${STEP_TITLES[s]}`).join('\n')}
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ─── shared helpers ───────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
function openConfig(): YamlFile {
|
|
75
|
+
return openYaml(CONFIG_PATH, BASE_CONFIG);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Files this run already wrote — their state before the run is in the
|
|
79
|
+
* first backup; a second one per step would only be clutter. */
|
|
80
|
+
const written = new Set<string>();
|
|
81
|
+
|
|
82
|
+
/** Commit and report in one line. Returns true when the file changed. */
|
|
83
|
+
function save(file: YamlFile, kind: 'config' | 'plain', what: string): boolean {
|
|
84
|
+
const r = commit(file, kind, new Date(), !written.has(file.path));
|
|
85
|
+
if (!r.changed) return false;
|
|
86
|
+
written.add(file.path);
|
|
87
|
+
ok(`${what} ${dim(`→ ${tildify(file.path)}${r.backup ? ` (previous version kept as ${r.backup.split('/').pop()})` : ''}`)}`);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function tildify(p: string): string {
|
|
92
|
+
return p.startsWith(`${HOME}/`) ? `~/${p.slice(HOME.length + 1)}` : p;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function expandHome(p: string): string {
|
|
96
|
+
return p === '~' ? HOME : p.startsWith('~/') ? join(HOME, p.slice(2)) : p;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function somoraSelf(args: string[]): { cmd: string; args: string[] } {
|
|
100
|
+
return BIN_PATH ? { cmd: process.execPath, args: [BIN_PATH, ...args] } : { cmd: 'somora', args };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function agentYaml(name: string): YamlFile {
|
|
104
|
+
return openYaml(join(AGENTS_DIR, name, 'agent.yaml'));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function serverPort(config: YamlFile): number {
|
|
108
|
+
const port = getIn(config, ['server', 'port']);
|
|
109
|
+
return typeof port === 'number' ? port : 18737;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function baseUrl(config: YamlFile): string {
|
|
113
|
+
const tls = getIn(config, ['server', 'tls']) as { publicHost?: string } | undefined;
|
|
114
|
+
const port = serverPort(config);
|
|
115
|
+
return tls?.publicHost ? `https://${tls.publicHost}:${port}` : `http://127.0.0.1:${port}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Talk to the server on this machine. With HTTPS the connection goes
|
|
119
|
+
* to loopback but is verified against the public name — that works
|
|
120
|
+
* even where the Tailscale name does not resolve locally. */
|
|
121
|
+
function localRequest(config: YamlFile, path: string, opts: { body?: unknown; timeoutMs: number }): Promise<{ status: number; json: Record<string, unknown> }> {
|
|
122
|
+
const tls = getIn(config, ['server', 'tls']) as { publicHost?: string } | undefined;
|
|
123
|
+
const payload = opts.body === undefined ? null : JSON.stringify(opts.body);
|
|
124
|
+
const options = {
|
|
125
|
+
host: '127.0.0.1',
|
|
126
|
+
port: serverPort(config),
|
|
127
|
+
path,
|
|
128
|
+
method: payload ? 'POST' : 'GET',
|
|
129
|
+
headers: {
|
|
130
|
+
...(tls?.publicHost ? { Host: `${tls.publicHost}:${serverPort(config)}` } : {}),
|
|
131
|
+
...(payload ? { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) } : {}),
|
|
132
|
+
},
|
|
133
|
+
...(tls?.publicHost ? { servername: tls.publicHost } : {}),
|
|
134
|
+
};
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
const req = (tls?.publicHost ? httpsRequest : httpRequest)(options, (res) => {
|
|
137
|
+
let text = '';
|
|
138
|
+
res.setEncoding('utf8');
|
|
139
|
+
res.on('data', (d: string) => { text += d; });
|
|
140
|
+
res.on('end', () => {
|
|
141
|
+
try {
|
|
142
|
+
resolve({ status: res.statusCode ?? 0, json: JSON.parse(text) as Record<string, unknown> });
|
|
143
|
+
} catch {
|
|
144
|
+
reject(new Error(`unexpected answer (HTTP ${res.statusCode})`));
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
req.setTimeout(opts.timeoutMs, () => req.destroy(new Error('timed out')));
|
|
149
|
+
req.on('error', reject);
|
|
150
|
+
req.end(payload ?? undefined);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function health(config: YamlFile): Promise<Record<string, unknown> | null> {
|
|
155
|
+
try {
|
|
156
|
+
const r = await localRequest(config, '/health', { timeoutMs: 4000 });
|
|
157
|
+
return r.status === 200 ? r.json : null;
|
|
158
|
+
} catch {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function serviceAvailable(): boolean {
|
|
164
|
+
return existsSync(UNIT_PATH) && capture('systemctl', ['--user', 'show-environment']).code === 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ─── step: models ─────────────────────────────────────────────────────
|
|
168
|
+
|
|
169
|
+
function claudeBinary(): string | null {
|
|
170
|
+
const local = join(HOME, '.local', 'bin', 'claude');
|
|
171
|
+
if (existsSync(local)) return local;
|
|
172
|
+
const r = capture('sh', ['-c', 'command -v claude']);
|
|
173
|
+
return r.code === 0 ? r.stdout.trim() : null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function claudeLoggedIn(): boolean {
|
|
177
|
+
return existsSync(join(HOME, '.claude', '.credentials.json'))
|
|
178
|
+
|| existsSync(join(SOMORA_HOME, 'claude-home', '.credentials.json'));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function codexLoggedIn(): boolean {
|
|
182
|
+
return existsSync(join(SOMORA_HOME, 'codex-home', 'auth.json'))
|
|
183
|
+
|| existsSync(join(process.env.CODEX_HOME ?? join(HOME, '.codex'), 'auth.json'));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function pickModels(p: Prompter, title: string, models: ModelPreset[], have: string[]): Promise<ModelPreset[]> {
|
|
187
|
+
const choices: Array<Choice<ModelPreset>> = models.map((m) => ({
|
|
188
|
+
label: `${m.alias.padEnd(8)} ${dim(m.id)}`,
|
|
189
|
+
value: m,
|
|
190
|
+
hint: have.includes(m.id) ? 'already configured' : m.note,
|
|
191
|
+
}));
|
|
192
|
+
const all = models.map((_, i) => i);
|
|
193
|
+
return await p.chooseMany(title, choices, all);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function setupClaude(ctx: Ctx, config: YamlFile): Promise<void> {
|
|
197
|
+
const { p } = ctx;
|
|
198
|
+
let bin = claudeBinary();
|
|
199
|
+
if (!bin) {
|
|
200
|
+
explain('Claude runs through Anthropic\'s own program, Claude Code. It is not installed yet.');
|
|
201
|
+
if (await p.confirm('Install Claude Code now? (official installer from claude.ai, into ~/.local/bin)')) {
|
|
202
|
+
p.handOver('sh', ['-c', 'curl -fsSL https://claude.ai/install.sh | bash']);
|
|
203
|
+
bin = claudeBinary();
|
|
204
|
+
}
|
|
205
|
+
if (!bin) {
|
|
206
|
+
warn('Claude Code is not installed — skipping Claude. Later: curl -fsSL https://claude.ai/install.sh | bash, then `somora setup models`.');
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
ok(`Claude Code installed at ${tildify(bin)}`);
|
|
210
|
+
}
|
|
211
|
+
if (claudeLoggedIn()) {
|
|
212
|
+
ok('Claude login found');
|
|
213
|
+
} else {
|
|
214
|
+
explain(`Next, Claude Code asks you to log in with your Claude subscription:
|
|
215
|
+
it shows a link — open it in any browser (your laptop or phone is fine),
|
|
216
|
+
approve, and paste the code it gives you back here.`);
|
|
217
|
+
if (await p.confirm('Log in now?')) {
|
|
218
|
+
p.handOver(bin, ['auth', 'login']);
|
|
219
|
+
}
|
|
220
|
+
if (!claudeLoggedIn()) {
|
|
221
|
+
warn(`no login yet — the models are added anyway; log in later with: ${bin} auth login`);
|
|
222
|
+
} else {
|
|
223
|
+
ok('logged in');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Hand the login to somora's own Claude folder right away, so the
|
|
227
|
+
// first turn does not depend on the server's watcher having run.
|
|
228
|
+
const self = somoraSelf(['auth', 'sync']);
|
|
229
|
+
capture(self.cmd, self.args);
|
|
230
|
+
|
|
231
|
+
const have = configuredAliases(config).filter((a) => a.engine === 'claude-cli').map((a) => a.id);
|
|
232
|
+
const models = await pickModels(p, 'Which Claude models?', CLAUDE_PRESET.models, have);
|
|
233
|
+
if (models.length) upsertProvider(config, { ...CLAUDE_PRESET, key: providerKeyFor(config, 'claude-cli', 'anthropic'), models: dedupeAliases(config, models) });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function setupCodex(ctx: Ctx, config: YamlFile): Promise<void> {
|
|
237
|
+
const { p } = ctx;
|
|
238
|
+
if (codexLoggedIn()) {
|
|
239
|
+
ok('ChatGPT login found');
|
|
240
|
+
} else {
|
|
241
|
+
explain(`ChatGPT models run through Codex, which comes bundled with somora.
|
|
242
|
+
The login opens a browser on this machine. On a server without a screen,
|
|
243
|
+
choose the device login: it shows a code you enter on another device.`);
|
|
244
|
+
const how = await p.choose('Log in with your ChatGPT subscription:', [
|
|
245
|
+
{ label: 'Browser on this machine', value: 'browser' },
|
|
246
|
+
{ label: 'Device login (no browser here)', value: 'device' },
|
|
247
|
+
{ label: 'Not now', value: 'skip' },
|
|
248
|
+
], onPath('xdg-open') || process.platform === 'darwin' ? 0 : 1);
|
|
249
|
+
if (how !== 'skip') {
|
|
250
|
+
const self = somoraSelf(['codex', 'login', ...(how === 'device' ? ['--device-auth'] : [])]);
|
|
251
|
+
p.handOver(self.cmd, self.args);
|
|
252
|
+
}
|
|
253
|
+
if (codexLoggedIn()) ok('logged in');
|
|
254
|
+
else warn('no login yet — the models are added anyway; log in later with: somora codex login');
|
|
255
|
+
}
|
|
256
|
+
const have = configuredAliases(config).filter((a) => a.engine === 'codex-cli').map((a) => a.id);
|
|
257
|
+
const models = await pickModels(p, 'Which ChatGPT models?', CODEX_PRESET.models, have);
|
|
258
|
+
if (models.length) upsertProvider(config, { ...CODEX_PRESET, key: providerKeyFor(config, 'codex-cli', 'openai'), models: dedupeAliases(config, models) });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Reuse the provider that already runs this engine, else `preferred`
|
|
262
|
+
* (or `preferred-2` when that key is taken by something else). */
|
|
263
|
+
function providerKeyFor(config: YamlFile, engine: string, preferred: string): string {
|
|
264
|
+
const providers = (getIn(config, ['providers']) ?? {}) as Record<string, { engine?: string }>;
|
|
265
|
+
const same = Object.entries(providers).find(([, v]) => v?.engine === engine);
|
|
266
|
+
if (same) return same[0];
|
|
267
|
+
if (!(preferred in providers)) return preferred;
|
|
268
|
+
for (let i = 2; ; i++) if (!(`${preferred}-${i}` in providers)) return `${preferred}-${i}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** A preset alias may already be used by one of the person's own
|
|
272
|
+
* models — aliases must be unique, so the newcomer gets a suffix. */
|
|
273
|
+
function dedupeAliases(config: YamlFile, models: ModelPreset[]): ModelPreset[] {
|
|
274
|
+
const existing = configuredAliases(config);
|
|
275
|
+
const taken = existing.map((a) => a.alias);
|
|
276
|
+
return models.map((m) => {
|
|
277
|
+
if (existing.some((a) => a.id === m.id) || !taken.includes(m.alias)) { taken.push(m.alias); return m; }
|
|
278
|
+
const alias = aliasFor(m.alias, taken);
|
|
279
|
+
taken.push(alias);
|
|
280
|
+
return { ...m, alias };
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
interface RemoteModel { id: string; context_length?: number }
|
|
285
|
+
|
|
286
|
+
async function listRemoteModels(url: string, apiKey: string): Promise<RemoteModel[] | string> {
|
|
287
|
+
try {
|
|
288
|
+
const r = await fetch(`${url.replace(/\/+$/, '')}/models`, {
|
|
289
|
+
headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
|
|
290
|
+
signal: AbortSignal.timeout(10_000),
|
|
291
|
+
});
|
|
292
|
+
if (!r.ok) return `the server answered ${r.status} ${r.statusText}`;
|
|
293
|
+
const j = (await r.json()) as { data?: RemoteModel[] };
|
|
294
|
+
return (j.data ?? []).filter((m) => typeof m?.id === 'string');
|
|
295
|
+
} catch (err) {
|
|
296
|
+
return (err as Error).message;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function setupOwnServer(ctx: Ctx, config: YamlFile): Promise<void> {
|
|
301
|
+
const { p } = ctx;
|
|
302
|
+
explain(`Any server that speaks the OpenAI chat protocol works: Ollama, LM Studio, vLLM,
|
|
303
|
+
oMLX — or a hosted one such as OpenRouter (https://openrouter.ai/api/v1).`);
|
|
304
|
+
const url = await p.askValid('Address of the server (ends in /v1)', 'http://localhost:11434/v1', (v) => (/^https?:\/\/\S+$/.test(v) ? null : 'an address starting with http:// or https://'));
|
|
305
|
+
const apiKey = await p.ask('API key (leave empty if the server needs none)', '');
|
|
306
|
+
let remote = await listRemoteModels(url, apiKey);
|
|
307
|
+
while (typeof remote === 'string') {
|
|
308
|
+
warn(`could not list the models there: ${remote}`);
|
|
309
|
+
if (!(await p.confirm('Try again? (No = type the model name yourself)', p.interactive))) { remote = []; break; }
|
|
310
|
+
remote = await listRemoteModels(url, apiKey);
|
|
311
|
+
}
|
|
312
|
+
let picked: RemoteModel[];
|
|
313
|
+
if (remote.length > 0 && remote.length <= 40) {
|
|
314
|
+
ok(`the server offers ${remote.length} model(s)`);
|
|
315
|
+
picked = await p.chooseMany('Which ones should somora use?', remote.map((m) => ({ label: m.id, value: m })), remote.length === 1 ? [0] : []);
|
|
316
|
+
} else {
|
|
317
|
+
if (remote.length > 40) explain(`The server offers ${remote.length} models — type the names of the ones you want.`);
|
|
318
|
+
const ids = (await p.ask('Model name(s), separated by commas', '')).split(',').map((s) => s.trim()).filter(Boolean);
|
|
319
|
+
const known = remote as RemoteModel[];
|
|
320
|
+
picked = ids.map((id) => known.find((m) => m.id === id) ?? { id });
|
|
321
|
+
}
|
|
322
|
+
if (picked.length === 0) { warn('no model chosen — nothing added'); return; }
|
|
323
|
+
|
|
324
|
+
const taken = configuredAliases(config).map((a) => a.alias);
|
|
325
|
+
const models: ModelPreset[] = [];
|
|
326
|
+
for (const m of picked) {
|
|
327
|
+
say(` ${bold(m.id)}`);
|
|
328
|
+
const alias = await p.askValid(' Short name to call it by', aliasFor(m.id, taken), (v) => (!/^[a-z0-9][a-z0-9._-]*$/i.test(v) ? 'letters, digits, dot, dash' : taken.includes(v) ? 'that name is taken' : null));
|
|
329
|
+
taken.push(alias);
|
|
330
|
+
if (!m.context_length) {
|
|
331
|
+
explain(`How much text the model can hold at once, in tokens — as the SERVER is
|
|
332
|
+
configured (Ollama: num_ctx, vLLM: --max-model-len), not what the model card
|
|
333
|
+
says. Too high and long chats fail; when unsure, keep the careful default.`);
|
|
334
|
+
}
|
|
335
|
+
const ctxWindow = Number(await p.askValid(' Context window (tokens)', String(m.context_length ?? 32768), (v) => (Number.isInteger(Number(v)) && Number(v) >= 2048 ? null : 'a whole number, at least 2048')));
|
|
336
|
+
const caps = ['text'];
|
|
337
|
+
if (await p.confirm(' Can it read images?', false)) caps.push('image');
|
|
338
|
+
if (await p.confirm(' Does it have a thinking / reasoning mode?', false)) caps.push('reasoning');
|
|
339
|
+
models.push({ id: m.id, alias, contextWindow: ctxWindow, capabilities: caps, note: '' });
|
|
340
|
+
}
|
|
341
|
+
const providers = (getIn(config, ['providers']) ?? {}) as Record<string, { baseUrl?: string }>;
|
|
342
|
+
const sameServer = Object.entries(providers).find(([, v]) => v?.baseUrl === url)?.[0];
|
|
343
|
+
let key = sameServer;
|
|
344
|
+
if (!key) {
|
|
345
|
+
const guess = /openrouter/.test(url) ? 'openrouter' : /11434/.test(url) ? 'ollama' : 'local';
|
|
346
|
+
key = await p.askValid('Name for this server in the config', guess in providers ? `${guess}-2` : guess, (v) => (!/^[a-z0-9][a-z0-9_-]*$/i.test(v) ? 'letters, digits, dash' : v in providers ? 'that name is taken' : null));
|
|
347
|
+
}
|
|
348
|
+
// Local servers usually ignore the key, but the client library wants one.
|
|
349
|
+
upsertProvider(config, { key, engine: 'openai-compatible', baseUrl: url, apiKey: apiKey || 'none', models });
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async function stepModels(ctx: Ctx): Promise<void> {
|
|
353
|
+
const { p } = ctx;
|
|
354
|
+
const config = openConfig();
|
|
355
|
+
const before = configuredAliases(config);
|
|
356
|
+
if (before.length) {
|
|
357
|
+
ok(`configured: ${before.map((a) => a.alias).join(', ')}`);
|
|
358
|
+
if (!(await p.confirm('Connect another provider or add models?', false))) return;
|
|
359
|
+
} else {
|
|
360
|
+
explain(`somora brings no AI of its own — it uses the subscriptions or servers you have.
|
|
361
|
+
Connect at least one; more than one gives your agents a backup when one is down.`);
|
|
362
|
+
}
|
|
363
|
+
const engines = new Set(before.map((a) => a.engine));
|
|
364
|
+
const choices: Array<Choice<'claude' | 'codex' | 'own'>> = [
|
|
365
|
+
{ label: 'Claude subscription (Pro / Max)', value: 'claude', hint: claudeLoggedIn() ? 'login found on this machine' : claudeBinary() ? 'Claude Code installed, not logged in' : 'installs Claude Code' },
|
|
366
|
+
{ label: 'ChatGPT subscription (Plus / Pro / Business)', value: 'codex', hint: codexLoggedIn() ? 'login found on this machine' : 'Codex is bundled' },
|
|
367
|
+
{ label: 'My own model server or an API key', value: 'own', hint: 'Ollama, LM Studio, vLLM, OpenRouter, …' },
|
|
368
|
+
];
|
|
369
|
+
const def: number[] = [];
|
|
370
|
+
if (!engines.has('claude-cli') && claudeLoggedIn()) def.push(0);
|
|
371
|
+
if (!engines.has('codex-cli') && codexLoggedIn()) def.push(1);
|
|
372
|
+
if (def.length === 0 && before.length === 0) def.push(0);
|
|
373
|
+
const wanted = await p.chooseMany('What do you want to connect?', choices, def);
|
|
374
|
+
for (const w of wanted) {
|
|
375
|
+
say();
|
|
376
|
+
say(` ${bold(choices.find((c) => c.value === w)!.label)}`);
|
|
377
|
+
if (w === 'claude') await setupClaude(ctx, config);
|
|
378
|
+
else if (w === 'codex') await setupCodex(ctx, config);
|
|
379
|
+
else {
|
|
380
|
+
do { await setupOwnServer(ctx, config); } while (await p.confirm('Add another server?', false));
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (configuredAliases(config).length === 0) {
|
|
384
|
+
warn('no model configured — somora cannot answer without one. Run `somora setup models` when you have a login or a server.');
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (save(config, 'config', 'models saved')) ctx.needsRestart = true;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ─── step: agent ──────────────────────────────────────────────────────
|
|
391
|
+
|
|
392
|
+
function personaFiles(name: string, userName: string, language: string): Record<string, string> {
|
|
393
|
+
return {
|
|
394
|
+
'AGENTS.md': `---
|
|
395
|
+
name: ${name}
|
|
396
|
+
description: Personal assistant
|
|
397
|
+
icon: 🤖
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
- Answer in ${language} unless asked otherwise. Be concise and clear.
|
|
401
|
+
- Say honestly when you don't know something — never invent facts.
|
|
402
|
+
- Use your tools when they help; say what you did, not what you would do.
|
|
403
|
+
- If the user asks about your tools, list only what you actually have.
|
|
404
|
+
`,
|
|
405
|
+
'SOUL.md': `# Who I am
|
|
406
|
+
|
|
407
|
+
I am ${name}, a personal assistant. This file describes my character —
|
|
408
|
+
edit it (or ask me to) once you know how you want me to be.
|
|
409
|
+
|
|
410
|
+
For now: I speak plainly, stick to facts and keep things short.
|
|
411
|
+
`,
|
|
412
|
+
'USER.md': `# About the user
|
|
413
|
+
|
|
414
|
+
- Name: ${userName}
|
|
415
|
+
- Preferred language: ${language}
|
|
416
|
+
|
|
417
|
+
(Add what the agent should know about you: role, projects, preferences, timezone, …)
|
|
418
|
+
`,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async function chooseModel(p: Prompter, question: string, aliases: string[], def: string | undefined, allowNone = false): Promise<string | null> {
|
|
423
|
+
const choices: Array<Choice<string | null>> = aliases.map((a) => ({ label: a, value: a }));
|
|
424
|
+
if (allowNone) choices.push({ label: 'none', value: null });
|
|
425
|
+
const i = def ? aliases.indexOf(def) : -1;
|
|
426
|
+
return await p.choose(question, choices, i >= 0 ? i : allowNone ? choices.length - 1 : 0);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** A backup on a different provider than the primary, when there is one. */
|
|
430
|
+
function suggestFallback(config: YamlFile, primary: string): string | undefined {
|
|
431
|
+
const all = configuredAliases(config);
|
|
432
|
+
const mine = all.find((a) => a.alias === primary);
|
|
433
|
+
const other = all.filter((a) => a.provider !== mine?.provider).map((a) => a.alias);
|
|
434
|
+
return pickPreferred('chat', other);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
async function createAgent(ctx: Ctx, config: YamlFile, existing: string[]): Promise<string | null> {
|
|
438
|
+
const { p } = ctx;
|
|
439
|
+
const aliases = configuredAliases(config).map((a) => a.alias);
|
|
440
|
+
if (aliases.length === 0) { warn('no model configured yet — run `somora setup models` first'); return null; }
|
|
441
|
+
const name = await p.askValid('Name of the agent (lowercase, e.g. your assistant\'s first name)', existing.length ? undefined : 'assistant', (v) =>
|
|
442
|
+
!/^[a-z][a-z0-9-]{0,30}$/.test(v) ? 'lowercase letters, digits and dashes, starting with a letter' : existing.includes(v) ? 'an agent with that name exists' : null);
|
|
443
|
+
ctx.principal ??= await p.ask('What should it call you?', userInfo().username);
|
|
444
|
+
const language = await p.ask('Which language should it answer in?', (process.env.LANG ?? '').startsWith('de') ? 'German' : 'English');
|
|
445
|
+
const model = (await chooseModel(p, 'Which model should it think with?', aliases, pickPreferred('chat', aliases)))!;
|
|
446
|
+
let fallback: string | null = null;
|
|
447
|
+
if (aliases.length > 1) {
|
|
448
|
+
explain('A backup model takes over when the first one is unreachable — best on a different provider.');
|
|
449
|
+
fallback = await chooseModel(p, 'Backup model:', aliases.filter((a) => a !== model), suggestFallback(config, model), true);
|
|
450
|
+
}
|
|
451
|
+
const dir = join(AGENTS_DIR, name);
|
|
452
|
+
mkdirSync(dir, { recursive: true });
|
|
453
|
+
for (const [file, text] of Object.entries(personaFiles(name, ctx.principal, language))) {
|
|
454
|
+
writeFileSync(join(dir, file), text, 'utf8');
|
|
455
|
+
}
|
|
456
|
+
writeFileSync(join(dir, 'agent.yaml'), `# Operator config for this agent. Every option (thinking, sampling, tools,
|
|
457
|
+
# voice, rem, …) is described in docs/agents.md.
|
|
458
|
+
model: ${model}
|
|
459
|
+
${fallback ? `fallback: [${fallback}]\n` : ''}`, 'utf8');
|
|
460
|
+
written.add(join(dir, 'agent.yaml'));
|
|
461
|
+
ok(`agent ${bold(name)} created ${dim(`→ ${tildify(dir)}`)}`);
|
|
462
|
+
ctx.needsRestart = true;
|
|
463
|
+
return name;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
async function stepAgent(ctx: Ctx): Promise<void> {
|
|
467
|
+
const { p } = ctx;
|
|
468
|
+
const config = openConfig();
|
|
469
|
+
const agents = await listAgents();
|
|
470
|
+
const aliases = configuredAliases(config).map((a) => a.alias);
|
|
471
|
+
if (agents.length === 0) {
|
|
472
|
+
explain(`An agent is one assistant with its own name, character and memory.
|
|
473
|
+
You start with one; more can follow (here, or in the web client).`);
|
|
474
|
+
if (!(await createAgent(ctx, config, []))) return;
|
|
475
|
+
} else {
|
|
476
|
+
await checkAgentModels(ctx, agents, aliases);
|
|
477
|
+
}
|
|
478
|
+
while (await p.confirm('Add another agent?', false)) {
|
|
479
|
+
const names = (await listAgents()).map((a) => a.name);
|
|
480
|
+
if (!(await createAgent(ctx, config, names))) break;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
async function checkAgentModels(ctx: Ctx, agents: Array<{ name: string }>, aliases: string[]): Promise<void> {
|
|
485
|
+
const { p } = ctx;
|
|
486
|
+
// Agents whose model is gone would fail on the first message.
|
|
487
|
+
for (const a of agents) {
|
|
488
|
+
const file = agentYaml(a.name);
|
|
489
|
+
const model = getIn(file, ['model']) as string | undefined;
|
|
490
|
+
const known = model === undefined || aliases.includes(model) || model.includes('/');
|
|
491
|
+
if (known) { ok(`${a.name}${model ? dim(` — ${model}`) : ''}`); continue; }
|
|
492
|
+
warn(`${a.name} is set to model '${model}', which is not configured`);
|
|
493
|
+
if (aliases.length && await p.confirm(`Pick a model for ${a.name}?`)) {
|
|
494
|
+
setIn(file, ['model'], (await chooseModel(p, 'Model:', aliases, pickPreferred('chat', aliases)))!);
|
|
495
|
+
if (save(file, 'plain', `${a.name} updated`)) ctx.needsRestart = true;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// ─── step: memory ─────────────────────────────────────────────────────
|
|
501
|
+
|
|
502
|
+
async function stepMemory(ctx: Ctx): Promise<void> {
|
|
503
|
+
const { p } = ctx;
|
|
504
|
+
const config = openConfig();
|
|
505
|
+
const aliases = configuredAliases(config).map((a) => a.alias);
|
|
506
|
+
const agents = (await listAgents()).filter((a) => a.kind !== 'builder');
|
|
507
|
+
if (aliases.length === 0 || agents.length === 0) { warn('needs a model and an agent first — run `somora setup` from the start'); return; }
|
|
508
|
+
|
|
509
|
+
explain(`Your agents remember across conversations. Three background jobs do that —
|
|
510
|
+
somora calls them dreaming:
|
|
511
|
+
REM after a chat goes quiet, an agent notes what was worth keeping
|
|
512
|
+
Deep twice a day, those notes are filed into a shared wiki
|
|
513
|
+
Lucid once a week, the wiki is checked for contradictions and duplicates;
|
|
514
|
+
what it finds is shown to you, nothing is changed without a yes`);
|
|
515
|
+
|
|
516
|
+
// REM — per agent
|
|
517
|
+
const remState = agents.map((a) => ({ name: a.name, file: agentYaml(a.name) })).map((a) => ({ ...a, on: getIn(a.file, ['rem', 'enabled']) === true }));
|
|
518
|
+
const off = remState.filter((a) => !a.on);
|
|
519
|
+
if (off.length === 0) {
|
|
520
|
+
ok(`REM is on for ${remState.map((a) => a.name).join(', ')}`);
|
|
521
|
+
} else if (await p.confirm(`Turn on REM for ${off.map((a) => a.name).join(', ')}?`)) {
|
|
522
|
+
explain('REM runs often and reads whole conversations — a fast, inexpensive model is the right one.');
|
|
523
|
+
const model = (await chooseModel(p, 'Model for REM:', aliases, pickPreferred('rem', aliases)))!;
|
|
524
|
+
const rest = aliases.filter((a) => a !== model);
|
|
525
|
+
const fallback = rest.length ? await chooseModel(p, 'Backup model for REM:', rest, pickPreferred('rem', rest), true) : null;
|
|
526
|
+
for (const a of off) {
|
|
527
|
+
setIn(a.file, ['rem'], { enabled: true, model, ...(fallback ? { fallback } : {}), idleMinutes: 30 });
|
|
528
|
+
if (save(a.file, 'plain', `REM on for ${a.name}`)) ctx.needsRestart = true;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const anyRem = remState.some((a) => a.on) || remState.some((a) => getIn(a.file, ['rem', 'enabled']) === true);
|
|
532
|
+
if (anyRem && getIn(config, ['rem', 'dedup', 'judge', 'enabled']) !== true) {
|
|
533
|
+
explain(`Before a new note is kept, a model can check whether your agent already knows
|
|
534
|
+
it. That keeps the memory free of repeats, for a few extra model calls per run.`);
|
|
535
|
+
if (await p.confirm('Turn on this duplicate check?')) setIn(config, ['rem', 'dedup', 'judge', 'enabled'], true);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Wiki + Deep + Lucid — platform-wide
|
|
539
|
+
say();
|
|
540
|
+
const vault = getIn(config, ['obsidian', 'vault']) as string | undefined;
|
|
541
|
+
const wikiOn = getIn(config, ['wiki', 'enabled']) === true;
|
|
542
|
+
if (wikiOn && vault) {
|
|
543
|
+
ok(`shared wiki: ${vault}/${(getIn(config, ['wiki', 'vaultSubfolder']) as string | undefined) ?? 'somora'}`);
|
|
544
|
+
} else {
|
|
545
|
+
explain(`The shared wiki is a folder of plain text files that all agents read and Deep
|
|
546
|
+
writes to. If you use Obsidian, point it at your vault and the wiki becomes a
|
|
547
|
+
subfolder of it; otherwise a new folder is fine — you can open it with any editor.`);
|
|
548
|
+
const where = await p.choose('Where should the wiki live?', [
|
|
549
|
+
{ label: 'A new folder', value: 'new', hint: vault ? undefined : '~/somora-vault' },
|
|
550
|
+
{ label: 'My Obsidian vault (I type the path)', value: 'vault' },
|
|
551
|
+
{ label: 'No wiki for now', value: 'skip', hint: 'REM still works; Deep and Lucid stay off' },
|
|
552
|
+
], vault ? 1 : 0);
|
|
553
|
+
if (where !== 'skip') {
|
|
554
|
+
const path = await p.askValid('Folder', vault ?? (where === 'new' ? '~/somora-vault' : undefined), (v) => {
|
|
555
|
+
if (!v) return 'a folder path, please';
|
|
556
|
+
if (where === 'vault' && !existsSync(expandHome(v))) return `${v} does not exist`;
|
|
557
|
+
return null;
|
|
558
|
+
});
|
|
559
|
+
mkdirSync(expandHome(path), { recursive: true });
|
|
560
|
+
const language = await p.choose('Language of the wiki (folder names, headings, the text Deep writes):', [
|
|
561
|
+
{ label: 'English', value: 'en' }, { label: 'Deutsch', value: 'de' },
|
|
562
|
+
], (process.env.LANG ?? '').startsWith('de') ? 1 : 0);
|
|
563
|
+
explain('Deep and Lucid run rarely and decide what goes into the wiki — take a careful model.');
|
|
564
|
+
const model = (await chooseModel(p, 'Model for Deep and Lucid:', aliases, pickPreferred('deep', aliases)))!;
|
|
565
|
+
setIn(config, ['obsidian', 'vault'], path);
|
|
566
|
+
setIn(config, ['wiki', 'enabled'], true);
|
|
567
|
+
setIn(config, ['wiki', 'language'], language);
|
|
568
|
+
setIn(config, ['wiki', 'deep', 'enabled'], true);
|
|
569
|
+
setIn(config, ['wiki', 'deep', 'model'], model);
|
|
570
|
+
setIn(config, ['wiki', 'lucid', 'enabled'], true);
|
|
571
|
+
setIn(config, ['wiki', 'lucid', 'model'], model);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (save(config, 'config', 'memory settings saved')) ctx.needsRestart = true;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// ─── step: team ───────────────────────────────────────────────────────
|
|
578
|
+
|
|
579
|
+
async function stepTeam(ctx: Ctx): Promise<void> {
|
|
580
|
+
const { p } = ctx;
|
|
581
|
+
const agents = await listAgents();
|
|
582
|
+
if (existsSync(teamFilePath())) {
|
|
583
|
+
ok(`team file present — arrange it in the web client's team window`);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
if (agents.length < 2) {
|
|
587
|
+
explain(`With one agent there is no team yet. When a second one joins, run
|
|
588
|
+
\`somora setup team\` (or open the team window in the web client): every agent
|
|
589
|
+
then knows who the others are, who reports to whom and whom to ask for what.`);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
explain(`${agents.length} agents: ${agents.map((a) => a.name).join(', ')}. A team file tells each of them who the others
|
|
593
|
+
are and whom to involve for what. It starts flat — everyone reports to you.`);
|
|
594
|
+
if (!(await p.confirm('Write the team file?'))) return;
|
|
595
|
+
ctx.principal ??= await p.ask('Your name, as the agents should know you', userInfo().username);
|
|
596
|
+
const r = await writeTeamFile(initialTeamFile(agents.map((a) => ({ name: a.name, role: a.role, description: a.description })), ctx.principal));
|
|
597
|
+
ok(`team file written ${dim(`→ ${tildify(r.path)}`)} — refine roles in the web client's team window`);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// ─── step: access ─────────────────────────────────────────────────────
|
|
601
|
+
|
|
602
|
+
function lanAddress(): string | null {
|
|
603
|
+
for (const list of Object.values(networkInterfaces())) {
|
|
604
|
+
for (const a of list ?? []) {
|
|
605
|
+
if (a.family === 'IPv4' && !a.internal && !a.address.startsWith('100.')) return a.address;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
async function tailscaleHttps(ctx: Ctx, config: YamlFile): Promise<boolean> {
|
|
612
|
+
const { p } = ctx;
|
|
613
|
+
let ts = tailscaleState();
|
|
614
|
+
if (!ts.installed) {
|
|
615
|
+
explain(`Tailscale is a free private network between your own devices. somora uses it
|
|
616
|
+
to be reachable from your phone and laptop — and only from them — with a real
|
|
617
|
+
HTTPS certificate. It needs an account (tailscale.com) and its app on each device.`);
|
|
618
|
+
if (!(await p.confirm('Install Tailscale on this machine now? (official installer, asks for your password)'))) return false;
|
|
619
|
+
p.handOver('sh', ['-c', 'curl -fsSL https://tailscale.com/install.sh | sh']);
|
|
620
|
+
ts = tailscaleState();
|
|
621
|
+
if (!ts.installed) { fail('Tailscale is still not installed — see https://tailscale.com/download'); return false; }
|
|
622
|
+
}
|
|
623
|
+
if (!ts.running) {
|
|
624
|
+
explain('Tailscale is installed but this machine is not connected. The next command shows a link — open it and sign in.');
|
|
625
|
+
if (!(await p.confirm('Connect now? (sudo tailscale up)'))) return false;
|
|
626
|
+
p.handOver('sudo', ['tailscale', 'up']);
|
|
627
|
+
ts = tailscaleState();
|
|
628
|
+
if (!ts.running) { fail(`not connected (state: ${ts.backendState ?? 'unknown'}) — run \`sudo tailscale up\`, then \`somora setup access\``); return false; }
|
|
629
|
+
}
|
|
630
|
+
ok(`Tailscale connected${ts.dnsName ? ` as ${ts.dnsName}` : ''}`);
|
|
631
|
+
while (!ts.certsEnabled) {
|
|
632
|
+
explain('One switch is missing in your Tailscale account (once per account):');
|
|
633
|
+
say(` 1. open ${cyan('https://login.tailscale.com/admin/dns')}`);
|
|
634
|
+
say(' 2. turn on "MagicDNS" (if it is off)');
|
|
635
|
+
say(' 3. under "HTTPS Certificates" press "Enable HTTPS"');
|
|
636
|
+
if (!(await p.confirm('Done — check again?', p.interactive))) return false;
|
|
637
|
+
ts = tailscaleState();
|
|
638
|
+
}
|
|
639
|
+
const host = ts.dnsName!;
|
|
640
|
+
const certDir = join(SOMORA_HOME, 'certs');
|
|
641
|
+
mkdirSync(certDir, { recursive: true });
|
|
642
|
+
try { chmodSync(certDir, 0o700); } catch { /* best effort */ }
|
|
643
|
+
const cert = join(certDir, `${host}.crt`);
|
|
644
|
+
const key = join(certDir, `${host}.key`);
|
|
645
|
+
const issue = (): { code: number; stderr: string } => capture('tailscale', ['cert', '--cert-file', cert, '--key-file', key, host], 120_000);
|
|
646
|
+
say(` ${dim('requesting the certificate (can take half a minute)…')}`);
|
|
647
|
+
let r = issue();
|
|
648
|
+
if (r.code !== 0 && isOperatorError(r.stderr)) {
|
|
649
|
+
const user = userInfo().username;
|
|
650
|
+
explain(`Tailscale only lets administrators fetch certificates. One command allows your
|
|
651
|
+
user to do it too — needed so somora can renew the certificate by itself later.`);
|
|
652
|
+
if (await p.confirm(`Allow it? (sudo tailscale set --operator=${user})`)) {
|
|
653
|
+
p.handOver('sudo', ['tailscale', 'set', `--operator=${user}`]);
|
|
654
|
+
r = issue();
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
if (r.code !== 0 || !existsSync(cert) || !existsSync(key)) {
|
|
658
|
+
fail(`no certificate: ${r.stderr.trim().split('\n').pop() || 'unknown error'}`);
|
|
659
|
+
say(` ${dim(`Try by hand: tailscale cert --cert-file ${tildify(cert)} --key-file ${tildify(key)} ${host}`)}`);
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
ok(`certificate for ${host}`);
|
|
663
|
+
const rel = (f: string): string => (SOMORA_HOME === join(HOME, '.somora') ? tildify(f) : f);
|
|
664
|
+
setIn(config, ['server', 'host'], '0.0.0.0');
|
|
665
|
+
setIn(config, ['server', 'tls'], { cert: rel(cert), key: rel(key), publicHost: host, renew: 'tailscale' });
|
|
666
|
+
ok('somora renews the certificate by itself from now on (no restart needed)');
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
async function stepAccess(ctx: Ctx): Promise<void> {
|
|
671
|
+
const { p } = ctx;
|
|
672
|
+
const config = openConfig();
|
|
673
|
+
const port = serverPort(config);
|
|
674
|
+
const tls = getIn(config, ['server', 'tls']) as { publicHost?: string; renew?: string } | undefined;
|
|
675
|
+
const host = (getIn(config, ['server', 'host']) as string | undefined) ?? '127.0.0.1';
|
|
676
|
+
if (tls?.publicHost) {
|
|
677
|
+
ok(`HTTPS is set up: https://${tls.publicHost}:${port}/web/`);
|
|
678
|
+
if (!tls.renew && tls.publicHost.endsWith('.ts.net')) {
|
|
679
|
+
explain('The certificate is from Tailscale and runs out every 90 days. somora can renew it by itself — without a restart.');
|
|
680
|
+
if (await p.confirm('Turn on automatic renewal?')) {
|
|
681
|
+
setIn(config, ['server', 'tls', 'renew'], 'tailscale');
|
|
682
|
+
if (save(config, 'config', 'automatic renewal on')) ctx.needsRestart = true;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
explain(`somora's web client runs in any browser. Out of the box it answers only on this
|
|
688
|
+
machine. To use it from your phone or laptop — including microphone and voice —
|
|
689
|
+
it needs HTTPS; the simple way to get that is Tailscale.`);
|
|
690
|
+
const lan = lanAddress();
|
|
691
|
+
const mode = await p.choose('How do you want to reach somora?', [
|
|
692
|
+
{ label: 'Tailscale HTTPS', value: 'tailscale', hint: 'your devices only, from anywhere; microphone and voice work (recommended)' },
|
|
693
|
+
{ label: 'This machine only', value: 'local', hint: `http://127.0.0.1:${port}/web/` },
|
|
694
|
+
{ label: 'Local network, no HTTPS', value: 'lan', hint: `http://${lan ?? '<this machine>'}:${port}/web/ — no microphone, one window at a time` },
|
|
695
|
+
], host === '0.0.0.0' ? 2 : p.interactive ? 0 : 1);
|
|
696
|
+
if (mode === 'tailscale') {
|
|
697
|
+
if (!(await tailscaleHttps(ctx, config))) {
|
|
698
|
+
warn('HTTPS is not set up — somora stays reachable on this machine only. Run `somora setup access` to try again.');
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
} else if (mode === 'lan') {
|
|
702
|
+
explain(`somora has no login of its own: everyone who can reach this machine on port ${port}
|
|
703
|
+
can talk to your agents. Only do this in a network you trust.`);
|
|
704
|
+
if (!(await p.confirm('Open it to the local network?', false))) return;
|
|
705
|
+
setIn(config, ['server', 'host'], '0.0.0.0');
|
|
706
|
+
} else {
|
|
707
|
+
if (host !== '127.0.0.1') setIn(config, ['server', 'host'], '127.0.0.1');
|
|
708
|
+
deleteIn(config, ['server', 'tls']);
|
|
709
|
+
}
|
|
710
|
+
if (save(config, 'config', 'access settings saved')) ctx.needsRestart = true;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// ─── step: start ──────────────────────────────────────────────────────
|
|
714
|
+
|
|
715
|
+
async function waitHealthy(config: YamlFile, seconds: number): Promise<Record<string, unknown> | null> {
|
|
716
|
+
for (let i = 0; i < seconds; i++) {
|
|
717
|
+
const h = await health(config);
|
|
718
|
+
if (h) return h;
|
|
719
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
720
|
+
}
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
async function stepStart(ctx: Ctx): Promise<void> {
|
|
725
|
+
const { p } = ctx;
|
|
726
|
+
const config = openConfig();
|
|
727
|
+
const agents = await listAgents();
|
|
728
|
+
if (configuredAliases(config).length === 0 || agents.length === 0) {
|
|
729
|
+
warn('not starting: no model or no agent yet — run `somora setup` again when you have one');
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
let up = await health(config);
|
|
733
|
+
if (!serviceAvailable()) {
|
|
734
|
+
if (!up) {
|
|
735
|
+
warn('no background service on this system. Start somora in a terminal (or tmux):');
|
|
736
|
+
say(` ${cyan('somora server start --foreground')}`);
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
if (ctx.needsRestart) warn('somora is running but was changed — restart it to apply the new settings');
|
|
740
|
+
} else if (!up) {
|
|
741
|
+
const self = somoraSelf(['server', 'start']);
|
|
742
|
+
capture(self.cmd, self.args);
|
|
743
|
+
say(` ${dim('starting somora…')}`);
|
|
744
|
+
up = await waitHealthy(config, 90);
|
|
745
|
+
} else if (ctx.needsRestart) {
|
|
746
|
+
if (await p.confirm('somora is running. Restart it now to apply the changes? (running conversations are interrupted)')) {
|
|
747
|
+
const self = somoraSelf(['server', 'restart']);
|
|
748
|
+
capture(self.cmd, self.args);
|
|
749
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
750
|
+
up = await waitHealthy(config, 90);
|
|
751
|
+
ctx.needsRestart = false;
|
|
752
|
+
} else {
|
|
753
|
+
warn('not restarted — the changes apply after: somora server restart');
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (!up) {
|
|
757
|
+
fail('somora does not answer. Look at the log: journalctl --user -u somora -n 50');
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
ok(`somora ${SOMORA_VERSION} is running`);
|
|
761
|
+
|
|
762
|
+
const agent = agents.length === 1 ? agents[0]!.name
|
|
763
|
+
: await p.choose('Send a test message to which agent?', [...agents.map((a) => ({ label: a.name, value: a.name as string | null })), { label: 'skip the test', value: null }], 0);
|
|
764
|
+
if (agent && (agents.length > 1 || await p.confirm(`Send a test message to ${agent}?`))) {
|
|
765
|
+
say(` ${dim('asking… (the first answer can take a minute)')}`);
|
|
766
|
+
try {
|
|
767
|
+
const r = await localRequest(config, '/chat/send-sync', {
|
|
768
|
+
body: { agent, session: 'setup-check', create_session: true, text: 'This is the setup check. Reply with one short sentence to confirm you are working.' },
|
|
769
|
+
timeoutMs: 180_000,
|
|
770
|
+
});
|
|
771
|
+
const j = r.json as { finalText?: string; outcome?: string; outcome_reason?: string; error?: string; model?: string };
|
|
772
|
+
const text = (j.finalText ?? '').trim();
|
|
773
|
+
if (r.status === 200 && text && j.outcome !== 'failed') {
|
|
774
|
+
ok(`${agent} answered${j.model ? ` on ${j.model}` : ''}: ${text.split('\n')[0]!.slice(0, 200)}`);
|
|
775
|
+
// A backup that answers hides a broken first choice — say so.
|
|
776
|
+
const primary = getIn(agentYaml(agent), ['model']) as string | undefined;
|
|
777
|
+
const primaryId = configuredAliases(config).find((a) => a.alias === primary)?.id ?? primary?.split('/').pop();
|
|
778
|
+
if (j.model && primaryId && j.model !== primaryId) {
|
|
779
|
+
warn(`that was the backup model — the first choice (${primary}) did not respond. Check its login: somora setup models`);
|
|
780
|
+
}
|
|
781
|
+
} else {
|
|
782
|
+
fail(`${agent} did not answer: ${j.error ?? j.outcome_reason ?? j.outcome ?? `HTTP ${r.status}`}`);
|
|
783
|
+
explain('Usually the login of the model provider: run `somora setup models`, or see the log with journalctl --user -u somora -n 50');
|
|
784
|
+
}
|
|
785
|
+
} catch (err) {
|
|
786
|
+
fail(`test message failed: ${(err as Error).message}`);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const base = baseUrl(config);
|
|
791
|
+
heading('Ready');
|
|
792
|
+
say(` Web client ${cyan(`${base}/web/`)}`);
|
|
793
|
+
say(` Phone ${cyan(`${base}/mobile`)}${base.startsWith('https') ? dim(' (add to home screen)') : ''}`);
|
|
794
|
+
say(` Terminal ${cyan('somora tui')}`);
|
|
795
|
+
say(` Update ${cyan('somora update')}`);
|
|
796
|
+
say(` This assistant ${cyan('somora setup')}${dim(' — or one step: somora setup access')}`);
|
|
797
|
+
say();
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// ─── entry ────────────────────────────────────────────────────────────
|
|
801
|
+
|
|
802
|
+
const RUN: Record<Step, (ctx: Ctx) => Promise<void>> = {
|
|
803
|
+
models: stepModels,
|
|
804
|
+
agent: stepAgent,
|
|
805
|
+
memory: stepMemory,
|
|
806
|
+
team: stepTeam,
|
|
807
|
+
access: stepAccess,
|
|
808
|
+
start: stepStart,
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
export async function runSetupCli(args: string[]): Promise<number> {
|
|
812
|
+
if (args.includes('--help') || args.includes('-h')) { process.stdout.write(usage()); return 0; }
|
|
813
|
+
const only = args[0] as Step | undefined;
|
|
814
|
+
if (only && !STEPS.includes(only)) {
|
|
815
|
+
process.stderr.write(`unknown step: ${only}\n\n${usage()}`);
|
|
816
|
+
return 2;
|
|
817
|
+
}
|
|
818
|
+
mkdirSync(SOMORA_HOME, { recursive: true });
|
|
819
|
+
const ctx: Ctx = { p: new Prompter(), needsRestart: false };
|
|
820
|
+
say(bold(`somora setup`) + dim(` ${SOMORA_VERSION}`));
|
|
821
|
+
if (!only) say(dim(' Enter takes the suggestion in [brackets]. Ctrl-C stops; run it again to pick up where you left off.'));
|
|
822
|
+
const steps: Step[] = only ? (only === 'start' ? ['start'] : [only, 'start']) : [...STEPS];
|
|
823
|
+
try {
|
|
824
|
+
for (const [i, s] of steps.entries()) {
|
|
825
|
+
heading(only ? STEP_TITLES[s] : `${i + 1}/${steps.length} ${STEP_TITLES[s]}`);
|
|
826
|
+
// After a single step, only offer the restart/test when something changed.
|
|
827
|
+
if (only && s === 'start' && only !== 'start' && !ctx.needsRestart) { ok('nothing to apply'); break; }
|
|
828
|
+
await RUN[s](ctx);
|
|
829
|
+
}
|
|
830
|
+
} catch (err) {
|
|
831
|
+
fail((err as Error).message);
|
|
832
|
+
return 1;
|
|
833
|
+
}
|
|
834
|
+
return 0;
|
|
835
|
+
}
|