@hivemagnus/magnus 2.9.1 → 2.10.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/dist/adopt.js CHANGED
@@ -12,7 +12,7 @@ import { installVersion, publishPins } from './install.js';
12
12
  import { acquireLock, Project } from './project.js';
13
13
  import { releaseFor } from './release.js';
14
14
  import { checkSupervisor, enableServices, unitDirectory } from './supervisor.js';
15
- import { serverUnit, uiUnit } from './templates.js';
15
+ import { serverUnit, uiUnit, unitPathProblem } from './templates.js';
16
16
  import { loadCatalog, UpgradeError } from './upgrade.js';
17
17
  import { defaultProjectDir } from './init.js';
18
18
  async function detectVersion(io) {
@@ -35,6 +35,10 @@ export async function adopt(io, options) {
35
35
  if (options.supervisor === 'systemd') {
36
36
  if (io.platform !== 'linux')
37
37
  throw new UpgradeError(`systemd units need Linux; on ${io.platform} pass --supervisor none.`);
38
+ const problem = unitPathProblem('The project directory', dir) ?? unitPathProblem('--server-env-file', serverEnvFile)
39
+ ?? (uiEnvFile ? unitPathProblem('--ui-env-file', uiEnvFile) : null);
40
+ if (problem)
41
+ throw new UpgradeError(problem);
38
42
  if (options.installUnits)
39
43
  await checkSupervisor(io, 'systemd', options.system ? 'system' : 'user').catch((error) => {
40
44
  throw new UpgradeError(error instanceof Error ? error.message : String(error));
@@ -1,6 +1,13 @@
1
1
  export declare function readEnvFile(path: string): Record<string, string>;
2
2
  /** 64 hex characters: comfortably above every 32-character secret minimum. */
3
3
  export declare function generateSecret(): string;
4
+ /**
5
+ * One env-file value, readable unchanged by dotenv, `node --env-file` and `docker compose
6
+ * --env-file`. Single quotes are literal in all three. A value that itself holds a single quote is
7
+ * double-quoted when nothing in it is special there; anything else cannot be written faithfully,
8
+ * and is refused rather than silently altered (a changed password only shows up as a failed login).
9
+ */
10
+ export declare function quoteEnvValue(value: string): string;
4
11
  export interface EnvEntry {
5
12
  name: string;
6
13
  value: string;
package/dist/env-file.js CHANGED
@@ -18,8 +18,20 @@ export function readEnvFile(path) {
18
18
  export function generateSecret() {
19
19
  return randomBytes(32).toString('hex');
20
20
  }
21
- function quote(value) {
22
- return /^[A-Za-z0-9_./:@%+,=-]*$/.test(value) ? value : `'${value.replace(/'/g, '')}'`;
21
+ /**
22
+ * One env-file value, readable unchanged by dotenv, `node --env-file` and `docker compose
23
+ * --env-file`. Single quotes are literal in all three. A value that itself holds a single quote is
24
+ * double-quoted when nothing in it is special there; anything else cannot be written faithfully,
25
+ * and is refused rather than silently altered (a changed password only shows up as a failed login).
26
+ */
27
+ export function quoteEnvValue(value) {
28
+ if (/^[A-Za-z0-9_./:@%+,=-]*$/.test(value))
29
+ return value;
30
+ if (!value.includes("'"))
31
+ return `'${value}'`;
32
+ if (!/["\\$`]/.test(value))
33
+ return `"${value}"`;
34
+ throw new Error('An env-file value cannot mix a single quote with a double quote, backslash, dollar sign or backtick; percent-encode it (in a URL) or choose another value');
23
35
  }
24
36
  export function renderEnv(header, sections) {
25
37
  const lines = header.split('\n').map((line) => `# ${line}`.trimEnd());
@@ -28,7 +40,7 @@ export function renderEnv(header, sections) {
28
40
  for (const entry of section.entries) {
29
41
  if (entry.comment)
30
42
  lines.push(`# ${entry.comment}`);
31
- lines.push(`${entry.name}=${quote(entry.value)}`);
43
+ lines.push(`${entry.name}=${quoteEnvValue(entry.value)}`);
32
44
  }
33
45
  }
34
46
  return `${lines.join('\n')}\n`;
@@ -45,7 +57,7 @@ export function appendMissing(path, entries, note) {
45
57
  return [];
46
58
  const block = [`\n# ${note}`, ...missing.flatMap((entry) => [
47
59
  ...(entry.comment ? [`# ${entry.comment}`] : []),
48
- `${entry.name}=${quote(entry.value)}`,
60
+ `${entry.name}=${quoteEnvValue(entry.value)}`,
49
61
  ])].join('\n');
50
62
  const present = existsSync(path);
51
63
  const current = present ? readFileSync(path, 'utf8') : '';
package/dist/init.js CHANGED
@@ -15,7 +15,7 @@ import { mustRun } from './io.js';
15
15
  import { acquireLock, Project } from './project.js';
16
16
  import { ownPackage, releaseFor } from './release.js';
17
17
  import { checkSupervisor, enableServices, restartServices, unitDirectory } from './supervisor.js';
18
- import { composeProjectName, depsCompose, depsEnv, serverEnv, serverUnit, uiEnv, uiUnit } from './templates.js';
18
+ import { composeProjectName, depsCompose, depsEnv, serverEnv, serverUnit, uiEnv, uiUnit, unitPathProblem } from './templates.js';
19
19
  import { loadCatalog, UpgradeError } from './upgrade.js';
20
20
  export function defaultProjectDir(io, system) {
21
21
  return system ? '/opt/magnus' : join(io.env['HOME'] ?? '.', '.magnus');
@@ -50,6 +50,11 @@ export async function init(io, options) {
50
50
  const dir = resolve(options.dir ?? defaultProjectDir(io, options.system));
51
51
  if (Project.exists(dir))
52
52
  throw new UpgradeError(`${dir} already holds a Magnus project. Use \`magnus upgrade\` or \`magnus status\`.`);
53
+ if (options.supervisor === 'systemd') {
54
+ const problem = unitPathProblem('The project directory', dir) ?? unitPathProblem('The Node.js path', process.execPath);
55
+ if (problem)
56
+ throw new UpgradeError(problem);
57
+ }
53
58
  // Before anything is written: systemd needs Linux and (user units) a session bus.
54
59
  await checkSupervisor(io, options.supervisor, options.system ? 'system' : 'user').catch((error) => {
55
60
  throw new UpgradeError(`${error instanceof Error ? error.message : String(error)} Or pass --supervisor none.`);
@@ -22,6 +22,12 @@ export interface ServiceUnitOptions {
22
22
  export declare const UNIT_MARKER = "# Generated by `magnus init`";
23
23
  /** At most three failed starts in five minutes: a crash loop stops instead of filling the disk with dumps. */
24
24
  export declare const START_LIMIT: string[];
25
+ /**
26
+ * The generated units write paths unquoted, and systemd splits `ExecStart=` and `Environment=`
27
+ * on whitespace and expands `%` and `$`. A path with any of those would produce a unit that
28
+ * starts the wrong command, so it is refused before anything is written.
29
+ */
30
+ export declare function unitPathProblem(what: string, path: string): string | null;
25
31
  export declare function serverUnit(options: ServiceUnitOptions): string;
26
32
  /**
27
33
  * Bring a unit generated by an older engine up to date without touching
package/dist/templates.js CHANGED
@@ -57,6 +57,16 @@ function hardening(options, writable) {
57
57
  '',
58
58
  ];
59
59
  }
60
+ /**
61
+ * The generated units write paths unquoted, and systemd splits `ExecStart=` and `Environment=`
62
+ * on whitespace and expands `%` and `$`. A path with any of those would produce a unit that
63
+ * starts the wrong command, so it is refused before anything is written.
64
+ */
65
+ export function unitPathProblem(what, path) {
66
+ return /[\s"'\\%$;]/.test(path)
67
+ ? `${what} (${path}) contains whitespace or one of " ' \\ % $ ; which a generated systemd unit cannot carry. Choose another path, or pass --supervisor none and write your own units.`
68
+ : null;
69
+ }
60
70
  export function serverUnit(options) {
61
71
  const { project } = options;
62
72
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hivemagnus/magnus",
3
- "version": "2.9.1",
3
+ "version": "2.10.1",
4
4
  "description": "Install, upgrade and roll back a Magnus server and console with one command: `npx @hivemagnus/magnus init`, then `magnus upgrade`. Pins exact, tested component versions, backs up PostgreSQL before every migration and reverts automatically when the new version fails its health check.",
5
5
  "keywords": [
6
6
  "magnus",
@@ -47,7 +47,7 @@
47
47
  "clean": "node -e \"const fs=require('node:fs');fs.rmSync('dist',{recursive:true,force:true});fs.rmSync('tsconfig.tsbuildinfo',{force:true})\""
48
48
  },
49
49
  "dependencies": {
50
- "@hivemagnus/magnus-contracts": "2.9.1"
50
+ "@hivemagnus/magnus-contracts": "2.10.1"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^24.19.2",
@@ -56,15 +56,15 @@
56
56
  },
57
57
  "magnusRelease": {
58
58
  "schema": 1,
59
- "version": "2.9.1",
59
+ "version": "2.10.1",
60
60
  "engines": {
61
61
  "node": "^24.22.3 || ^26.13.1"
62
62
  },
63
63
  "components": {
64
- "@hivemagnus/magnus-server": "2.9.1",
65
- "@hivemagnus/magnus-ui": "2.9.1",
66
- "@hivemagnus/magnus-contracts": "2.9.1",
67
- "@hivemagnus/magnus-agent": "2.9.1"
64
+ "@hivemagnus/magnus-server": "2.10.1",
65
+ "@hivemagnus/magnus-ui": "2.10.1",
66
+ "@hivemagnus/magnus-contracts": "2.10.1",
67
+ "@hivemagnus/magnus-agent": "2.10.1"
68
68
  },
69
69
  "breaking": false,
70
70
  "minUpgradeFrom": "1.0.0",
@@ -77,8 +77,8 @@
77
77
  "selfUpgradeProtocol": 1,
78
78
  "minLauncher": 1
79
79
  },
80
- "summary": "Assistant model routes send their own model to non-Ollama providers.",
81
- "notesUrl": "https://github.com/ChefTaco/magnus/releases/tag/v2.9.1",
80
+ "summary": "Node agent: Hermes discovery caches the slow version probe per binary, runs it in the background with a 90-second budget, and reports a trusted Hermes that answers profile list as runnable with no version instead of degraded. Hidden profile directories such as profiles/.deleted are no longer reported as profiles. No migrations and no new settings.",
81
+ "notesUrl": "https://github.com/ChefTaco/magnus/releases/tag/v2.10.1",
82
82
  "allowScripts": {
83
83
  "@prisma/engines": true,
84
84
  "argon2": true,