sovkora 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +9 -0
- package/README.md +67 -2
- package/dist/commands/agent.command.js +267 -0
- package/dist/commands/chat.command.js +214 -0
- package/dist/commands/chat.handlers.js +150 -0
- package/dist/commands/chat.types.js +44 -0
- package/dist/commands/cinema.command.js +643 -0
- package/dist/commands/config.command.js +228 -0
- package/dist/commands/db.command.js +114 -0
- package/dist/commands/demo.command.js +55 -0
- package/dist/commands/dev.command.js +462 -0
- package/dist/commands/docs.command.js +135 -0
- package/dist/commands/doctor.command.js +119 -0
- package/dist/commands/forgot.command.js +57 -0
- package/dist/commands/generate.command.js +376 -0
- package/dist/commands/graph.command.js +54 -0
- package/dist/commands/init.command.js +380 -0
- package/dist/commands/init.steps.js +115 -0
- package/dist/commands/install.command.js +459 -0
- package/dist/commands/login.command.js +110 -0
- package/dist/commands/logs.command.js +215 -0
- package/dist/commands/logs.steps.js +130 -0
- package/dist/commands/mcp.command.js +104 -0
- package/dist/commands/models.command.js +164 -0
- package/dist/commands/onboard.command.js +236 -0
- package/dist/commands/pack.command.js +255 -0
- package/dist/commands/profile.command.js +51 -0
- package/dist/commands/recover.command.js +489 -0
- package/dist/commands/register.command.js +94 -0
- package/dist/commands/release.command.js +99 -0
- package/dist/commands/reset.command.js +79 -0
- package/dist/commands/runs.command.js +201 -0
- package/dist/commands/settings.command.js +85 -0
- package/dist/commands/start.command.js +590 -0
- package/dist/commands/status.command.js +167 -0
- package/dist/commands/stop.command.js +313 -0
- package/dist/commands/studio.command.js +266 -0
- package/dist/commands/test.command.js +134 -0
- package/dist/commands/verify.command.js +52 -0
- package/dist/commands/video.command.js +73 -0
- package/dist/commands/workspace-guard.js +72 -0
- package/dist/index.js +207 -0
- package/dist/renderers.js +250 -0
- package/dist/services/api-client.js +150 -0
- package/dist/services/auth.api.js +87 -0
- package/dist/services/chat.api.js +117 -0
- package/dist/services/cinema-estimate.json +42 -0
- package/dist/services/cinema.childsafe.js +52 -0
- package/dist/services/cinema.director.js +285 -0
- package/dist/services/cinema.production.js +417 -0
- package/dist/services/cinema.staging.js +323 -0
- package/dist/services/cinema.story.js +758 -0
- package/dist/services/cinema.treatment.js +393 -0
- package/dist/services/composer.run.js +94 -0
- package/dist/services/demo/demo.documents.js +108 -0
- package/dist/services/demo/demo.guard.js +49 -0
- package/dist/services/demo/demo.persona.js +114 -0
- package/dist/services/demo/demo.seed.js +281 -0
- package/dist/services/diagnostics.js +327 -0
- package/dist/services/image-model-recipes.json +93 -0
- package/dist/services/image-models.js +152 -0
- package/dist/services/local-store.js +145 -0
- package/dist/services/mcp.api.js +38 -0
- package/dist/services/model-catalog.js +70 -0
- package/dist/services/notify.js +55 -0
- package/dist/services/pack.api.js +23 -0
- package/dist/services/pack.bundle.js +241 -0
- package/dist/services/pack.sources.js +101 -0
- package/dist/services/release-manifest.js +266 -0
- package/dist/services/runs.view.js +80 -0
- package/dist/services/runs.wait.js +38 -0
- package/dist/services/semver.js +55 -0
- package/dist/services/settings.api.js +108 -0
- package/dist/services/string-utils.js +70 -0
- package/dist/services/studio.api.js +120 -0
- package/dist/services/templates.js +893 -0
- package/dist/services/tool-installer.js +353 -0
- package/dist/services/tool-path.js +72 -0
- package/dist/services/version-manager.js +253 -0
- package/dist/services/workspace-bootstrap.js +68 -0
- package/dist/threads.js +202 -0
- package/dist/types/api.types.js +6 -0
- package/dist/types/local.types.js +6 -0
- package/dist/ui/box.js +46 -0
- package/dist/ui/logger.js +28 -0
- package/dist/ui/platform.js +32 -0
- package/dist/ui/prompts.js +130 -0
- package/dist/ui/table.js +33 -0
- package/dist/utils/config.js +150 -0
- package/dist/utils/development-status.js +22 -0
- package/dist/utils/endpoints.js +41 -0
- package/dist/utils/health.js +94 -0
- package/dist/utils/pid.js +83 -0
- package/dist/utils/platform.js +358 -0
- package/dist/utils/process.js +139 -0
- package/dist/utils/state-dir.js +105 -0
- package/package.json +95 -4
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file start.command.ts
|
|
4
|
+
* @description Service startup with dev/full mode, selective service
|
|
5
|
+
* launching, and intelligent recovery strategies.
|
|
6
|
+
*
|
|
7
|
+
* Dev mode: Starts only Docker middleware + AI engines (you run the Router from your IDE,
|
|
8
|
+
* or via `sovkora dev` which spawns it for you alongside the web apps).
|
|
9
|
+
* Full mode: Starts everything including the Router (Spring Boot) and Next.js.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.startCommand = void 0;
|
|
49
|
+
const commander_1 = require("commander");
|
|
50
|
+
const fs = __importStar(require("node:fs"));
|
|
51
|
+
const path = __importStar(require("node:path"));
|
|
52
|
+
const node_child_process_1 = require("node:child_process");
|
|
53
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
54
|
+
const date_fns_1 = require("date-fns");
|
|
55
|
+
const workspace_guard_1 = require("./workspace-guard");
|
|
56
|
+
const prompts_1 = require("../ui/prompts");
|
|
57
|
+
const platform_1 = require("../ui/platform");
|
|
58
|
+
const health_1 = require("../utils/health");
|
|
59
|
+
const process_1 = require("../utils/process");
|
|
60
|
+
const config_1 = require("../utils/config");
|
|
61
|
+
const platform_2 = require("../utils/platform");
|
|
62
|
+
const tool_installer_1 = require("../services/tool-installer");
|
|
63
|
+
const image_models_1 = require("../services/image-models");
|
|
64
|
+
const model_catalog_1 = require("../services/model-catalog");
|
|
65
|
+
const tool_path_1 = require("../services/tool-path");
|
|
66
|
+
// `checkServiceHealth(port)` → service is up; `waitForService(port, retries)` →
|
|
67
|
+
// poll until up. Both delegate to the shared health primitives (utils/health),
|
|
68
|
+
// which load `.env`-driven timeouts via utils/config.
|
|
69
|
+
const checkServiceHealth = health_1.isPortInUse;
|
|
70
|
+
const waitForService = health_1.waitForPort;
|
|
71
|
+
exports.startCommand = new commander_1.Command("start")
|
|
72
|
+
.description("Start Sovkora infrastructure — dev mode (Docker middleware + AI engines) or full mode (also Router + UI)")
|
|
73
|
+
.option("--mode <mode>", "Startup mode: dev (default, infra + AI engines) or full (also Router + Next.js UI)", "dev")
|
|
74
|
+
.option("--only <service>", "Start only a specific service (postgres, redis, rabbitmq, ollama, localai, image-gen, media-worker)")
|
|
75
|
+
.option("--skip-health", "Skip final health verification")
|
|
76
|
+
.option("--wait-timeout <ms>", "Timeout for service startup (default: 60000ms)", "60000")
|
|
77
|
+
.option("--allow-partial", "Allow partial startup (some services may fail)")
|
|
78
|
+
.option("--verbose", "Show detailed startup logs")
|
|
79
|
+
.option("--logs", "Tail log files after startup")
|
|
80
|
+
.action(async (options) => {
|
|
81
|
+
const mode = (options.mode ?? "dev");
|
|
82
|
+
const onlyService = options.only;
|
|
83
|
+
await (0, prompts_1.intro)(chalk_1.default.cyan.bold(mode === "dev" ? "🥷 Sovkora Dev Infrastructure" : "🥷 Sovkora Full Infrastructure Bootstrap"));
|
|
84
|
+
(0, workspace_guard_1.requireWorkspace)("start");
|
|
85
|
+
const workspaceRoot = (0, platform_1.resolveWorkspaceRoot)();
|
|
86
|
+
const pidFile = (0, platform_1.resolvePidFile)();
|
|
87
|
+
const logDir = (0, platform_1.resolveLogDir)();
|
|
88
|
+
(0, platform_1.ensureDir)(logDir);
|
|
89
|
+
(0, platform_1.ensureDir)(path.dirname(pidFile));
|
|
90
|
+
// Verify compose file
|
|
91
|
+
const composeFile = (0, platform_1.resolveComposeFile)();
|
|
92
|
+
if (!fs.existsSync(composeFile)) {
|
|
93
|
+
await (0, prompts_1.logError)("docker-compose.yml not found.\n" + ` Run ${chalk_1.default.cyan("npx sovkora init")} to generate it.`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
const dockerComposeCmd = (0, platform_1.resolveDockerComposeCmd)();
|
|
97
|
+
if (!dockerComposeCmd) {
|
|
98
|
+
await (0, prompts_1.logError)("Docker Compose not found.\n" +
|
|
99
|
+
` Install Docker Desktop: ${chalk_1.default.cyan("https://www.docker.com/products/docker-desktop")}`);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
const dateStamp = (0, date_fns_1.format)(new Date(), "yyyyMMdd_HHmmss");
|
|
103
|
+
const startedServices = [];
|
|
104
|
+
const spinner = await (0, prompts_1.createSpinner)();
|
|
105
|
+
// Helper: should we start this service?
|
|
106
|
+
const shouldStart = (service) => {
|
|
107
|
+
if (onlyService)
|
|
108
|
+
return onlyService === service;
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
// ═══════════════════════════════════════════════════════════
|
|
112
|
+
// PHASE 1: Docker Middleware (Postgres, Redis, RabbitMQ)
|
|
113
|
+
// ═══════════════════════════════════════════════════════════
|
|
114
|
+
if (shouldStart("postgres") || shouldStart("redis") || shouldStart("rabbitmq")) {
|
|
115
|
+
await (0, prompts_1.logStep)("Phase 1: Docker Services (Postgres, Redis, RabbitMQ)");
|
|
116
|
+
const servicesToStart = [];
|
|
117
|
+
if (shouldStart("postgres"))
|
|
118
|
+
servicesToStart.push("postgres");
|
|
119
|
+
if (shouldStart("redis"))
|
|
120
|
+
servicesToStart.push("redis");
|
|
121
|
+
if (shouldStart("rabbitmq"))
|
|
122
|
+
servicesToStart.push("rabbitmq");
|
|
123
|
+
// Check if any compose service names differ (handle both naming conventions)
|
|
124
|
+
const composeContent = fs.readFileSync(composeFile, "utf-8");
|
|
125
|
+
const actualServices = [];
|
|
126
|
+
for (const svc of servicesToStart) {
|
|
127
|
+
// Check for alternative names in compose file
|
|
128
|
+
if (svc === "postgres") {
|
|
129
|
+
if (composeContent.includes("db-vector:"))
|
|
130
|
+
actualServices.push("db-vector");
|
|
131
|
+
else if (composeContent.includes("postgres:"))
|
|
132
|
+
actualServices.push("postgres");
|
|
133
|
+
else
|
|
134
|
+
actualServices.push(svc);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
actualServices.push(svc);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// The local SMTP sink the notification service delivers e-mail to (inbox on :8025).
|
|
141
|
+
if (composeContent.includes("mailpit:"))
|
|
142
|
+
actualServices.push("mailpit");
|
|
143
|
+
spinner.start("Launching Docker containers...");
|
|
144
|
+
try {
|
|
145
|
+
(0, node_child_process_1.execSync)(`${dockerComposeCmd} -p orazaka -f "${composeFile}" up -d ${actualServices.join(" ")}`, {
|
|
146
|
+
stdio: options.verbose ? "inherit" : "ignore",
|
|
147
|
+
});
|
|
148
|
+
spinner.stop("Docker containers launched.");
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
spinner.stop("Failed to launch Docker containers", 1);
|
|
152
|
+
if (!options.allowPartial) {
|
|
153
|
+
const msg = err instanceof Error ? err.message : "Unknown error";
|
|
154
|
+
await (0, prompts_1.logError)(`Docker error: ${msg}`);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
await (0, prompts_1.logWarning)("Continuing with partial startup...");
|
|
158
|
+
}
|
|
159
|
+
// Health checks
|
|
160
|
+
spinner.start("Verifying Docker services...");
|
|
161
|
+
const dockerChecks = [
|
|
162
|
+
{ port: config_1.PORTS.postgres, name: "PostgreSQL", service: "postgres" },
|
|
163
|
+
{ port: config_1.PORTS.redis, name: "Redis", service: "redis" },
|
|
164
|
+
{ port: config_1.PORTS.rabbitmq, name: "RabbitMQ", service: "rabbitmq" },
|
|
165
|
+
];
|
|
166
|
+
for (const check of dockerChecks) {
|
|
167
|
+
if (!shouldStart(check.service))
|
|
168
|
+
continue;
|
|
169
|
+
const healthy = await waitForService(check.port, 30);
|
|
170
|
+
if (healthy) {
|
|
171
|
+
await (0, prompts_1.logSuccess)(`✔ ${check.name} healthy (port ${String(check.port)})`);
|
|
172
|
+
startedServices.push(check.name);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
await (0, prompts_1.logWarning)(`⚠ ${check.name} not responding`);
|
|
176
|
+
if (!options.allowPartial)
|
|
177
|
+
process.exit(1);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
spinner.stop();
|
|
181
|
+
if (shouldStart("db-vector")) {
|
|
182
|
+
await applyRolePasswords(dockerComposeCmd);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// ═══════════════════════════════════════════════════════════
|
|
186
|
+
// PHASE 2: Ollama LLM Engine
|
|
187
|
+
// ═══════════════════════════════════════════════════════════
|
|
188
|
+
if (shouldStart("ollama")) {
|
|
189
|
+
await (0, prompts_1.logStep)("Phase 2: AI Engine (Ollama)");
|
|
190
|
+
const ollamaActive = await checkServiceHealth(config_1.PORTS.ollama);
|
|
191
|
+
if (ollamaActive) {
|
|
192
|
+
await (0, prompts_1.logSuccess)("✔ Ollama already active");
|
|
193
|
+
startedServices.push("Ollama");
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
await (0, prompts_1.logWarning)(`Ollama not active on port ${String(config_1.PORTS.ollama)}.`);
|
|
197
|
+
let started = false;
|
|
198
|
+
// Try macOS app first
|
|
199
|
+
if (process.platform === "darwin") {
|
|
200
|
+
try {
|
|
201
|
+
(0, node_child_process_1.execFileSync)((0, tool_path_1.toolPath)("open"), ["-a", "Ollama"], { stdio: "ignore" });
|
|
202
|
+
await (0, prompts_1.logStep)("Launched Ollama.app...");
|
|
203
|
+
started = true;
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
/* app not installed */
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Try CLI
|
|
210
|
+
if (!started && (0, platform_1.hasTool)("ollama")) {
|
|
211
|
+
const ollamaProcess = (0, process_1.spawnDetachedToLog)("ollama", ["serve"], {
|
|
212
|
+
logFile: path.join(logDir, `${dateStamp}_ollama.log`),
|
|
213
|
+
pidFile,
|
|
214
|
+
pidName: "ollama",
|
|
215
|
+
});
|
|
216
|
+
await (0, prompts_1.logStep)(`Started ollama serve (PID ${String(ollamaProcess.pid)})`);
|
|
217
|
+
started = true;
|
|
218
|
+
}
|
|
219
|
+
if (started) {
|
|
220
|
+
spinner.start("Waiting for Ollama...");
|
|
221
|
+
const healthy = await waitForService(config_1.PORTS.ollama, 60);
|
|
222
|
+
spinner.stop();
|
|
223
|
+
if (healthy) {
|
|
224
|
+
await (0, prompts_1.logSuccess)("✔ Ollama online");
|
|
225
|
+
startedServices.push("Ollama");
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
await (0, prompts_1.logWarning)("⚠ Ollama not responding");
|
|
229
|
+
if (!options.allowPartial)
|
|
230
|
+
process.exit(1);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
await (0, prompts_1.logWarning)("⚠ Ollama not found.\n" +
|
|
235
|
+
` Install: ${chalk_1.default.gray("https://ollama.ai")} or ${chalk_1.default.gray("brew install ollama")}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// Pull model if needed
|
|
239
|
+
if ((0, platform_1.hasTool)("ollama") && (await checkServiceHealth(config_1.PORTS.ollama))) {
|
|
240
|
+
try {
|
|
241
|
+
const model = config_1.OLLAMA_MODEL;
|
|
242
|
+
const modelList = (0, node_child_process_1.execFileSync)((0, tool_path_1.toolPath)("ollama"), ["list"]).toString();
|
|
243
|
+
if (!modelList.includes(model)) {
|
|
244
|
+
spinner.start(`Pulling model ${model}...`);
|
|
245
|
+
(0, node_child_process_1.execFileSync)((0, tool_path_1.toolPath)("ollama"), ["pull", model], {
|
|
246
|
+
stdio: options.verbose ? "inherit" : "ignore",
|
|
247
|
+
});
|
|
248
|
+
spinner.stop(`Model ${model} ready.`);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
await (0, prompts_1.logSuccess)(`✔ Model ${model} available`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
await (0, prompts_1.logWarning)("Could not verify Ollama models.");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// ═══════════════════════════════════════════════════════════
|
|
260
|
+
// PHASE 3: LocalAI Image Worker (macOS M1/M2/M3)
|
|
261
|
+
// ═══════════════════════════════════════════════════════════
|
|
262
|
+
if (shouldStart("localai")) {
|
|
263
|
+
await (0, prompts_1.logStep)("Phase 3: Image Generation (LocalAI)");
|
|
264
|
+
const imageWorkerPort = config_1.PORTS.localai;
|
|
265
|
+
const imageWorkerActive = await checkServiceHealth(imageWorkerPort);
|
|
266
|
+
if (imageWorkerActive) {
|
|
267
|
+
await (0, prompts_1.logSuccess)(`✔ Image Worker already active on port ${String(imageWorkerPort)}`);
|
|
268
|
+
startedServices.push("LocalAI");
|
|
269
|
+
}
|
|
270
|
+
else if (process.platform === "darwin" && (0, platform_1.hasTool)("local-ai")) {
|
|
271
|
+
const modelsPath = (0, platform_1.resolveModelsDir)();
|
|
272
|
+
spinner.start("Launching LocalAI (Metal GPU on Apple Silicon)...");
|
|
273
|
+
try {
|
|
274
|
+
// LocalAI v3+/v4: the API server is started via the `run` subcommand
|
|
275
|
+
// with `--address` (the old top-level `--listen` flag no longer exists).
|
|
276
|
+
const localAiProcess = (0, process_1.spawnDetachedToLog)("local-ai", [
|
|
277
|
+
"run",
|
|
278
|
+
`--address=127.0.0.1:${String(imageWorkerPort)}`,
|
|
279
|
+
`--models-path=${modelsPath}`,
|
|
280
|
+
// LocalAI 4.x looks for its backends (piper, whisper) in ./backends relative to the
|
|
281
|
+
// directory it was started from; the CLI starts it from the workspace, where there are
|
|
282
|
+
// none, and every speech and transcription call answered "backend not found" (ADR-076).
|
|
283
|
+
`--backends-path=${path.join(modelsPath, "backends")}`,
|
|
284
|
+
], {
|
|
285
|
+
logFile: path.join(logDir, `${dateStamp}_image-worker.log`),
|
|
286
|
+
env: { ...process.env, FORCE_CPU: "false" },
|
|
287
|
+
pidFile,
|
|
288
|
+
pidName: "image-worker",
|
|
289
|
+
});
|
|
290
|
+
spinner.stop(`LocalAI started (PID ${String(localAiProcess.pid)})`);
|
|
291
|
+
const healthy = await waitForService(imageWorkerPort, 45);
|
|
292
|
+
if (healthy) {
|
|
293
|
+
await (0, prompts_1.logSuccess)(`✔ Image Worker ready on port ${String(imageWorkerPort)}`);
|
|
294
|
+
startedServices.push("LocalAI");
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
await (0, prompts_1.logWarning)("⚠ Image Worker not responding (image generation may fail)");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
catch (e) {
|
|
301
|
+
spinner.stop("Failed to start LocalAI", 1);
|
|
302
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
303
|
+
await (0, prompts_1.logWarning)(`⚠ LocalAI startup failed: ${msg}`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
await (0, prompts_1.logWarning)("⚠ LocalAI not available (image generation disabled)\n" +
|
|
308
|
+
` On macOS: ${chalk_1.default.gray("brew install localai")}\n` +
|
|
309
|
+
` Or: ${chalk_1.default.gray("https://localai.io/docs/getting-started/")}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// ═══════════════════════════════════════════════════════════
|
|
313
|
+
// PHASE 3b: Image Generation Server (stable-diffusion.cpp — Metal, :8086)
|
|
314
|
+
// LocalAI (:8085) serves audio only; real image generation is the dedicated
|
|
315
|
+
// sd-server on :8086 (ai_providers.localai-image base-url). Without it, image
|
|
316
|
+
// jobs hit "connection refused" → SafeImageModel transparent-PNG fallback.
|
|
317
|
+
// ═══════════════════════════════════════════════════════════
|
|
318
|
+
if (shouldStart("image-gen")) {
|
|
319
|
+
await (0, prompts_1.logStep)("Phase 3b: Image Generation (stable-diffusion.cpp)");
|
|
320
|
+
const imageGenPort = config_1.PORTS.imageGen;
|
|
321
|
+
const imageGenActive = await checkServiceHealth(imageGenPort);
|
|
322
|
+
if (imageGenActive) {
|
|
323
|
+
await (0, prompts_1.logSuccess)(`✔ Image Gen Worker already active on port ${String(imageGenPort)}`);
|
|
324
|
+
startedServices.push("Image Gen");
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
// The catalogue's default image model is what this server serves — one model at a time,
|
|
328
|
+
// and never another one under its name (services/image-models.ts).
|
|
329
|
+
const modelsDir = (0, platform_1.resolveModelsDir)();
|
|
330
|
+
const sdServerBin = path.join(modelsDir, "stable-diffusion.cpp", "build", "bin", "sd-server");
|
|
331
|
+
let catalogued;
|
|
332
|
+
try {
|
|
333
|
+
catalogued = (0, model_catalog_1.defaultImageModel)();
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
catalogued = undefined;
|
|
337
|
+
}
|
|
338
|
+
const recipe = catalogued ? (0, image_models_1.findImageModel)(catalogued) : undefined;
|
|
339
|
+
if (recipe && (0, image_models_1.isInstalled)(recipe, modelsDir) && fs.existsSync(sdServerBin)) {
|
|
340
|
+
spinner.start(`Starting Image Gen Worker (${recipe.label}, stable-diffusion.cpp, Metal)...`);
|
|
341
|
+
try {
|
|
342
|
+
const sdProcess = (0, process_1.spawnDetachedToLog)(sdServerBin, (0, image_models_1.sdServerArgs)(recipe, modelsDir, { port: imageGenPort, seed: process.env.IMAGE_GEN_SEED }), {
|
|
343
|
+
logFile: path.join(logDir, `${dateStamp}_image-generation-worker.log`),
|
|
344
|
+
env: { ...process.env },
|
|
345
|
+
pidFile,
|
|
346
|
+
pidName: "image-gen-worker",
|
|
347
|
+
});
|
|
348
|
+
spinner.stop(`Image Gen Worker started (PID ${String(sdProcess.pid)})`);
|
|
349
|
+
// A 4–7 GB model loads in ~10–15 s from an SSD; leave room for a cold disk cache.
|
|
350
|
+
const healthy = await waitForService(imageGenPort, 90);
|
|
351
|
+
if (healthy) {
|
|
352
|
+
await (0, prompts_1.logSuccess)(`✔ Image Gen Worker ready on port ${String(imageGenPort)} — ${recipe.label}`);
|
|
353
|
+
startedServices.push("Image Gen");
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
await (0, prompts_1.logWarning)("⚠ Image Gen Worker not responding (image generation may fail)");
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
catch (e) {
|
|
360
|
+
spinner.stop("Failed to start Image Gen Worker", 1);
|
|
361
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
362
|
+
await (0, prompts_1.logWarning)(`⚠ Image Gen Worker startup failed: ${msg}`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
const issues = [];
|
|
367
|
+
if (!catalogued)
|
|
368
|
+
issues.push("the catalogue names no default image model (is the database up?)");
|
|
369
|
+
else if (!recipe)
|
|
370
|
+
issues.push(`no install recipe for the catalogue's default '${catalogued}'`);
|
|
371
|
+
else if (!(0, image_models_1.isInstalled)(recipe, modelsDir))
|
|
372
|
+
issues.push(`${recipe.label} is not downloaded`);
|
|
373
|
+
if (!fs.existsSync(sdServerBin))
|
|
374
|
+
issues.push(`sd-server binary not found: ${sdServerBin}`);
|
|
375
|
+
await (0, prompts_1.logWarning)(`⚠ Image Gen Worker not available (${issues.join("; ")})\n` +
|
|
376
|
+
` Setup: ${chalk_1.default.gray("sovkora models image list")} then ${chalk_1.default.gray("sovkora models image pull <id>")} ` +
|
|
377
|
+
`and ${chalk_1.default.gray("sovkora models image use <id>")}`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
// ═══════════════════════════════════════════════════════════
|
|
382
|
+
// PHASE 4: Media Worker (Python — orazaka-worker-media, MLX/Metal)
|
|
383
|
+
// ═══════════════════════════════════════════════════════════
|
|
384
|
+
if (shouldStart("media-worker")) {
|
|
385
|
+
await (0, prompts_1.logStep)("Phase 4: Media Generation Worker");
|
|
386
|
+
const mediaWorkerPort = config_1.PORTS.mediaWorker;
|
|
387
|
+
const mediaWorkerActive = await checkServiceHealth(mediaWorkerPort);
|
|
388
|
+
if (mediaWorkerActive) {
|
|
389
|
+
await (0, prompts_1.logSuccess)(`✔ Media Worker already active on port ${String(mediaWorkerPort)}`);
|
|
390
|
+
startedServices.push("Media Worker");
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
// Native Python media worker: workers/media
|
|
394
|
+
const mediaWorkerDir = path.join(workspaceRoot, "workers", "media");
|
|
395
|
+
const mainPy = path.join(mediaWorkerDir, "app", "main.py");
|
|
396
|
+
const pythonCmd = (0, tool_installer_1.resolveMediaWorkerPython)(workspaceRoot);
|
|
397
|
+
if (fs.existsSync(mainPy) && pythonCmd) {
|
|
398
|
+
spinner.start("Starting Media Worker (Python)...");
|
|
399
|
+
try {
|
|
400
|
+
// app.consumer consumes orazaka.jobs.video AND serves the :8188 HTTP
|
|
401
|
+
// pipeline in-process (Phase 3b); the port comes from MEDIA_WORKER_PORT.
|
|
402
|
+
const mediaProcess = (0, process_1.spawnDetachedToLog)(pythonCmd, ["-u", "-m", "app.consumer"], {
|
|
403
|
+
logFile: path.join(logDir, `${dateStamp}_media-worker.log`),
|
|
404
|
+
env: {
|
|
405
|
+
...process.env,
|
|
406
|
+
PYTHONPATH: mediaWorkerDir,
|
|
407
|
+
},
|
|
408
|
+
pidFile,
|
|
409
|
+
pidName: "media-worker",
|
|
410
|
+
});
|
|
411
|
+
spinner.stop(`Media Worker started (PID ${String(mediaProcess.pid)})`);
|
|
412
|
+
const healthy = await waitForService(mediaWorkerPort, 30);
|
|
413
|
+
if (healthy) {
|
|
414
|
+
await (0, prompts_1.logSuccess)(`✔ Media Worker ready on port ${String(mediaWorkerPort)}`);
|
|
415
|
+
startedServices.push("Media Worker");
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
await (0, prompts_1.logWarning)("⚠ Media Worker not responding");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
catch (e) {
|
|
422
|
+
spinner.stop("Failed to start Media Worker", 1);
|
|
423
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
424
|
+
await (0, prompts_1.logWarning)(`⚠ Media Worker startup failed: ${msg}`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
const issues = [];
|
|
429
|
+
if (!fs.existsSync(mainPy))
|
|
430
|
+
issues.push("main.py not found at expected path");
|
|
431
|
+
if (!pythonCmd)
|
|
432
|
+
issues.push("Python 3 not found");
|
|
433
|
+
await (0, prompts_1.logWarning)(`⚠ Media Worker not available (${issues.join(", ")})\n` +
|
|
434
|
+
` Setup: ${chalk_1.default.gray("npx sovkora install")} to configure the media worker environment`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
// ═══════════════════════════════════════════════════════════
|
|
439
|
+
// PHASE 5: Router + UI (full mode only)
|
|
440
|
+
// ═══════════════════════════════════════════════════════════
|
|
441
|
+
if (mode === "full" && !onlyService) {
|
|
442
|
+
// Router (Spring Boot ingress app — RouterApplication)
|
|
443
|
+
if (shouldStart("router")) {
|
|
444
|
+
await (0, prompts_1.logStep)("Phase 5a: Starting Router (Spring Boot)...");
|
|
445
|
+
const routerTargetDir = path.join(workspaceRoot, "services", "conversation", "sovkora-conversation-service", "target");
|
|
446
|
+
const routerJarName = fs.existsSync(routerTargetDir)
|
|
447
|
+
? fs.readdirSync(routerTargetDir).find((f) => f.endsWith(".jar") && !f.endsWith("-sources.jar"))
|
|
448
|
+
: undefined;
|
|
449
|
+
const routerJar = path.join(routerTargetDir, routerJarName ?? "orazaka-conversation-service.jar");
|
|
450
|
+
if (fs.existsSync(routerJar)) {
|
|
451
|
+
(0, process_1.spawnDetachedToLog)("java", ["-jar", routerJar], {
|
|
452
|
+
logFile: path.join(logDir, `${dateStamp}_router.log`),
|
|
453
|
+
pidFile,
|
|
454
|
+
pidName: "router",
|
|
455
|
+
});
|
|
456
|
+
const healthy = await waitForService(config_1.PORTS.router, 60);
|
|
457
|
+
if (healthy) {
|
|
458
|
+
await (0, prompts_1.logSuccess)(`✔ Router ready on port ${String(config_1.PORTS.router)}`);
|
|
459
|
+
startedServices.push("Router");
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
await (0, prompts_1.logWarning)("⚠ Router did not start in time");
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
await (0, prompts_1.logWarning)("⚠ Router JAR not found. Build first:\n" +
|
|
467
|
+
` ${chalk_1.default.gray("./mvnw clean package -pl services/conversation/sovkora-conversation-service -am -DskipTests")}`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// UI
|
|
471
|
+
if (shouldStart("ui")) {
|
|
472
|
+
await (0, prompts_1.logStep)("Phase 5b: Starting Next.js UI...");
|
|
473
|
+
const uiDir = path.join(workspaceRoot, "apps");
|
|
474
|
+
if (fs.existsSync(uiDir)) {
|
|
475
|
+
const uiProcess = (0, process_1.spawnDetachedToLog)("npm", ["run", "dev"], {
|
|
476
|
+
cwd: uiDir,
|
|
477
|
+
logFile: path.join(logDir, `${dateStamp}_ui.log`),
|
|
478
|
+
pidFile,
|
|
479
|
+
pidName: "ui",
|
|
480
|
+
});
|
|
481
|
+
await (0, prompts_1.logSuccess)(`✔ UI started on port ${String(config_1.PORTS.web)} (PID ${String(uiProcess.pid)})`);
|
|
482
|
+
startedServices.push("Next.js UI");
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
await (0, prompts_1.logWarning)("⚠ UI directory not found");
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
// ═══════════════════════════════════════════════════════════
|
|
490
|
+
// SUMMARY
|
|
491
|
+
// ═══════════════════════════════════════════════════════════
|
|
492
|
+
const summaryLines = [
|
|
493
|
+
`${chalk_1.default.green("✔")} Services: ${startedServices.length > 0 ? startedServices.join(", ") : chalk_1.default.yellow("none")}`,
|
|
494
|
+
`${chalk_1.default.yellow("📍")} Logs: ${chalk_1.default.cyan(path.relative(workspaceRoot, logDir))}`,
|
|
495
|
+
`${chalk_1.default.yellow("📋")} PIDs: ${chalk_1.default.cyan(path.relative(workspaceRoot, pidFile))}`,
|
|
496
|
+
];
|
|
497
|
+
if (mode === "dev") {
|
|
498
|
+
summaryLines.push("", `${chalk_1.default.cyan.bold("Dev mode — infra + AI engines are up. Now run the apps:")}`, ` ${chalk_1.default.white("→")} ${chalk_1.default.cyan("All apps at once")}: ${chalk_1.default.gray("npx sovkora dev")} ${chalk_1.default.dim("(spawns Router + Web + Mobile)")}`, ` ${chalk_1.default.white("→")} ${chalk_1.default.cyan("Router in IDE")}: Run/Debug ${chalk_1.default.yellow("RouterApplication")} in IntelliJ, then ${chalk_1.default.gray("npx sovkora dev --skip-router")}`, "", `${chalk_1.default.gray("Tip:")} Use ${chalk_1.default.cyan("npx sovkora logs")} to tail all service logs`, `${chalk_1.default.gray("Tip:")} Use ${chalk_1.default.cyan("npx sovkora status")} to check service health`);
|
|
499
|
+
}
|
|
500
|
+
await (0, prompts_1.note)(summaryLines.join("\n"), mode === "dev" ? "🛠 Dev Infrastructure Ready" : "🚀 Full Infrastructure Ready");
|
|
501
|
+
// Tail logs if requested
|
|
502
|
+
if (options.logs) {
|
|
503
|
+
await (0, prompts_1.logInfo)("Tailing logs (Ctrl+C to stop)...\n");
|
|
504
|
+
try {
|
|
505
|
+
const logFiles = fs
|
|
506
|
+
.readdirSync(logDir)
|
|
507
|
+
.filter((f) => f.startsWith(dateStamp))
|
|
508
|
+
.map((f) => path.join(logDir, f));
|
|
509
|
+
if (logFiles.length > 0) {
|
|
510
|
+
const tail = (0, node_child_process_1.spawn)((0, tool_path_1.toolPath)("tail"), ["-f", ...logFiles], {
|
|
511
|
+
stdio: "inherit",
|
|
512
|
+
});
|
|
513
|
+
await new Promise((resolve) => {
|
|
514
|
+
tail.on("exit", () => resolve());
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
catch {
|
|
519
|
+
/* ignore */
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
await (0, prompts_1.outro)(chalk_1.default.cyan(mode === "dev"
|
|
523
|
+
? "Dev infrastructure ready! Run `npx sovkora dev` (or start RouterApplication in IntelliJ) 🚀"
|
|
524
|
+
: `Full infrastructure ready! Open http://localhost:${String(config_1.PORTS.web)} 🚀`));
|
|
525
|
+
});
|
|
526
|
+
/**
|
|
527
|
+
* Sets each context role's password from the environment.
|
|
528
|
+
*
|
|
529
|
+
* `infra/initdb/*.sql` creates the roles with `LOGIN` and no password, because psql 15 cannot read
|
|
530
|
+
* the environment (`\getenv` arrived in 16) and ERR-125 bans a shell script in the initdb
|
|
531
|
+
* directory. A committed literal was the third option and is the defect being closed (audit #5).
|
|
532
|
+
*
|
|
533
|
+
* A role with no password cannot authenticate, so skipping this step leaves the stack unable to
|
|
534
|
+
* connect rather than reachable with a guessable credential — it fails closed. `ALTER ROLE` is
|
|
535
|
+
* idempotent, so re-running `sovkora start` on an existing volume simply re-applies the value.
|
|
536
|
+
*/
|
|
537
|
+
async function applyRolePasswords(dockerComposeCmd) {
|
|
538
|
+
const missing = platform_2.DB_ROLE_CONTEXTS.filter((ctx) => !process.env[`${ctx}_DB_PASSWORD`]);
|
|
539
|
+
if (missing.length > 0) {
|
|
540
|
+
await (0, prompts_1.logWarning)(`⚠ No password set for: ${missing.join(", ")} — those roles cannot connect. ` +
|
|
541
|
+
"Set <CTX>_DB_PASSWORD in .env (see exemple.env.txt).");
|
|
542
|
+
}
|
|
543
|
+
// Postgres accepts connections *before* /docker-entrypoint-initdb.d has finished, so the roles
|
|
544
|
+
// may not exist yet when the port opens. Waiting on the port is not waiting on the schema.
|
|
545
|
+
const superuser = process.env.DB_USERNAME ?? "orazaka_app";
|
|
546
|
+
for (let attempt = 0; attempt < 30; attempt += 1) {
|
|
547
|
+
let ready;
|
|
548
|
+
try {
|
|
549
|
+
ready =
|
|
550
|
+
(0, node_child_process_1.execSync)(`${dockerComposeCmd} -p orazaka exec -T db-vector psql -U ${superuser} -d postgres ` +
|
|
551
|
+
`-tAc "SELECT 1 FROM pg_roles WHERE rolname = 'krizaka_users';"`, { stdio: "pipe", env: process.env })
|
|
552
|
+
.toString()
|
|
553
|
+
.trim() === "1";
|
|
554
|
+
}
|
|
555
|
+
catch {
|
|
556
|
+
ready = false;
|
|
557
|
+
}
|
|
558
|
+
if (ready)
|
|
559
|
+
break;
|
|
560
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
561
|
+
}
|
|
562
|
+
let applied = 0;
|
|
563
|
+
for (const ctx of platform_2.DB_ROLE_CONTEXTS) {
|
|
564
|
+
const password = process.env[`${ctx}_DB_PASSWORD`];
|
|
565
|
+
if (!password)
|
|
566
|
+
continue;
|
|
567
|
+
const role = platform_2.DB_ROLES[ctx];
|
|
568
|
+
try {
|
|
569
|
+
// Over stdin, not `-c`: psql only interpolates `:'pw'` for file/stdin input, so `-c` sends
|
|
570
|
+
// the literal `:'pw'` to the server and fails with a syntax error. Interpolating means psql
|
|
571
|
+
// does the quoting, so a password containing a quote cannot terminate the statement — and
|
|
572
|
+
// the value never appears in argv, where `ps` would show it.
|
|
573
|
+
(0, node_child_process_1.execSync)(`${dockerComposeCmd} -p orazaka exec -T db-vector ` +
|
|
574
|
+
`psql -U ${superuser} -d postgres ` +
|
|
575
|
+
`-v ON_ERROR_STOP=1 -v pw=${JSON.stringify(password)}`, { input: `ALTER ROLE ${role} PASSWORD :'pw';\n`, stdio: ["pipe", "pipe", "pipe"], env: process.env });
|
|
576
|
+
applied += 1;
|
|
577
|
+
}
|
|
578
|
+
catch {
|
|
579
|
+
await (0, prompts_1.logWarning)(`⚠ Could not set the password for ${role}; it cannot connect until it is.`);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (applied === platform_2.DB_ROLE_CONTEXTS.length) {
|
|
583
|
+
await (0, prompts_1.logSuccess)("✔ Database role passwords applied from the environment");
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
// Never claim success on a partial run: a role left without a password cannot connect, and a
|
|
587
|
+
// green line here would send the reader looking for the fault anywhere but at this step.
|
|
588
|
+
await (0, prompts_1.logWarning)(`⚠ ${String(applied)}/${String(platform_2.DB_ROLE_CONTEXTS.length)} role passwords applied`);
|
|
589
|
+
}
|
|
590
|
+
}
|