prism-mcp-server 20.13.1 → 20.14.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/dist/cli.js CHANGED
@@ -221,6 +221,7 @@ program
221
221
  .option('--dry-run', 'Preview configuration changes without writing files')
222
222
  .option('--refresh', 'Refresh only entries previously created by Prism; custom entries stay untouched')
223
223
  .option('--no-self-update', 'Skip the npm self-update check; configure with the currently installed version')
224
+ .option('--no-models', 'Skip model convergence; keep whatever model versions are installed')
224
225
  .action(async (options) => {
225
226
  try {
226
227
  // ── Converge the PACKAGE first, then the configs ──────────────
@@ -447,6 +448,17 @@ program
447
448
  if (!summary.usedApiKey) {
448
449
  console.log('PRISM_SYNALUX_API_KEY is not set; no Synalux subscription key was copied into new registrations.');
449
450
  }
451
+ // ── Converge the MODELS last ────────────────────────────────
452
+ // selfUpdate above is the package half of convergence; without this
453
+ // half a machine kept vision-less models for four days after the
454
+ // registry carried the fix (2026-08-18), and `ollama cp` aliases are
455
+ // snapshots that silently detach from their source on every re-pull.
456
+ // Failures here never fail connect — runOllamaConverge reports and
457
+ // returns.
458
+ if (options.models !== false) {
459
+ const { runOllamaConverge } = await import('./modelConvergeRunner.js');
460
+ await runOllamaConverge({ dryRun: options.dryRun === true });
461
+ }
450
462
  }
451
463
  catch (err) {
452
464
  console.error(`Connect failed: ${err instanceof Error ? err.message : String(err)}`);
@@ -1028,6 +1040,20 @@ scmCmd
1028
1040
  process.exit(1);
1029
1041
  }
1030
1042
  });
1043
+ // ─── prism update-models ──────────────────────────────────────
1044
+ // Standalone model convergence: pull each installed prism-coder tier from
1045
+ // the registry and repair its local alias. connect runs this automatically;
1046
+ // this command is for updating models without touching host configuration.
1047
+ program
1048
+ .command('update-models')
1049
+ .description('Pull installed prism-coder models from the registry and repair stale local aliases')
1050
+ .option('--dry-run', 'Print what would be pulled/re-aliased without executing')
1051
+ .action(async (options) => {
1052
+ const { runOllamaConverge } = await import('./modelConvergeRunner.js');
1053
+ const outcomes = await runOllamaConverge({ dryRun: options.dryRun === true });
1054
+ if (outcomes.every(o => o.action === 'failed'))
1055
+ process.exitCode = 1;
1056
+ });
1031
1057
  // ─── prism register-models ────────────────────────────────────
1032
1058
  // Convenience: alias namespaced HF-style prism-coder tags
1033
1059
  // (`dcostenco/prism-coder:9b`) to the bare tags (`prism-coder:9b`)
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Production wiring for model convergence — real Ollama, real registry.
3
+ *
4
+ * Kept out of cli.ts so the pure logic (utils/modelConverge.ts) stays
5
+ * testable with injected deps, and out of utils/ because this half owns
6
+ * process spawning. `ollama pull` runs with inherited stdio deliberately:
7
+ * a multi-GB download with no progress bar reads as a hang, and ollama's
8
+ * own progress output is better than anything we would reimplement.
9
+ *
10
+ * Adversarial review 2026-08-18 (pre-20.14.0), two findings fixed here:
11
+ *
12
+ * 1. SPLIT-BRAIN DAEMON TARGETING: listTags read /api/tags from
13
+ * PRISM_LOCAL_LLM_URL while the spawned `ollama` CLI targeted whatever
14
+ * OLLAMA_HOST the user's shell had (default localhost). On a machine
15
+ * with a remote Ollama, convergence read tags from one daemon and
16
+ * pulled/re-aliased against another. The spawn env now pins OLLAMA_HOST
17
+ * to the SAME url the tags came from — one daemon, one truth.
18
+ *
19
+ * 2. SILENT MULTI-GB DOWNLOADS: connect gave no warning before pulling.
20
+ * Measured the day this shipped: the registry 27b had just changed
21
+ * bytes, so every 27b holder's first converge pulls ~16 GB. The plan
22
+ * is now announced up front, with the --no-models escape hatch named,
23
+ * before any network transfer starts.
24
+ */
25
+ import { spawn } from "node:child_process";
26
+ import { convergeModels, MODEL_NAMESPACE, LOCAL_PREFIX, CONVERGE_TIERS } from "./utils/modelConverge.js";
27
+ const OLLAMA_URL = process.env.PRISM_LOCAL_LLM_URL || "http://localhost:11434";
28
+ /**
29
+ * Env for spawned `ollama` processes. OLLAMA_HOST is pinned to the same
30
+ * daemon /api/tags was read from — never the shell's ambient value — so
31
+ * list, pull, and cp can never disagree about which Ollama they act on.
32
+ * Exported for tests.
33
+ */
34
+ export function convergeEnv(base, ollamaUrl = OLLAMA_URL) {
35
+ return { ...base, OLLAMA_HOST: ollamaUrl };
36
+ }
37
+ function runOllama(args, inheritStdio) {
38
+ return new Promise((resolve, reject) => {
39
+ const child = spawn("ollama", args, {
40
+ stdio: inheritStdio ? "inherit" : "ignore",
41
+ env: convergeEnv(process.env),
42
+ });
43
+ child.on("error", (err) => reject(new Error(`ollama ${args[0]}: ${err.message}`)));
44
+ child.on("close", (code) => {
45
+ if (code === 0)
46
+ resolve();
47
+ else
48
+ reject(new Error(`ollama ${args.join(" ")} exited ${code}`));
49
+ });
50
+ });
51
+ }
52
+ export async function runOllamaConverge(opts = {}) {
53
+ // Announce the plan BEFORE any network transfer: which tiers are
54
+ // installed (and will be checked), that pulls can be large, and how to
55
+ // opt out. A 16 GB download must never be the first sign convergence
56
+ // is running.
57
+ let installedTiers = [];
58
+ try {
59
+ const res = await fetch(`${OLLAMA_URL}/api/tags`, { signal: AbortSignal.timeout(5_000) });
60
+ if (res.ok) {
61
+ const data = (await res.json());
62
+ const names = new Set((data.models ?? []).map((m) => m.name));
63
+ installedTiers = CONVERGE_TIERS.filter((t) => names.has(`${MODEL_NAMESPACE}:${t}`) || names.has(`${LOCAL_PREFIX}:${t}`));
64
+ }
65
+ }
66
+ catch {
67
+ // convergeModels handles the unreachable case with its own message
68
+ }
69
+ if (installedTiers.length > 0) {
70
+ console.log(`\nConverging ${installedTiers.length} installed model tier(s) [${installedTiers.join(", ")}] against the registry.`);
71
+ console.log(" Updated models download in full (can be multiple GB). Skip with: prism connect --no-models");
72
+ }
73
+ else {
74
+ console.log("\nConverging local models against the registry…");
75
+ }
76
+ const outcomes = await convergeModels({
77
+ listTags: async () => {
78
+ const res = await fetch(`${OLLAMA_URL}/api/tags`, { signal: AbortSignal.timeout(5_000) });
79
+ if (!res.ok)
80
+ throw new Error(`Ollama /api/tags HTTP ${res.status}`);
81
+ const data = (await res.json());
82
+ return (data.models ?? []).map((m) => ({ name: m.name, digest: m.digest }));
83
+ },
84
+ pull: (ref) => runOllama(["pull", ref], true),
85
+ copy: (from, to) => runOllama(["cp", from, to], false),
86
+ log: (line) => console.log(` ${line}`),
87
+ dryRun: opts.dryRun,
88
+ });
89
+ const failed = outcomes.filter((o) => o.action === "failed" && o.detail !== "ollama_unreachable");
90
+ if (failed.length > 0) {
91
+ console.log(` ⚠ ${failed.length} tier(s) did not converge — re-run \`prism update-models\` when the network allows`);
92
+ }
93
+ return outcomes;
94
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Model convergence for `prism connect` — the missing half of self-update.
3
+ *
4
+ * selfUpdate.ts converges the PACKAGE; nothing converged the MODELS. The gap
5
+ * was measured on 2026-08-18: the vision-restored artifacts had been on the
6
+ * Ollama registry for four days while a laptop that pulled earlier kept
7
+ * refusing image requests (layer1_classifier_no_vision) — and on the machine
8
+ * where this was written, the `prism-coder:2b` alias pointed at different
9
+ * bytes than `dcostenco/prism-coder:2b`, because `ollama cp` makes a
10
+ * SNAPSHOT: a re-pull updates the source name and silently leaves every
11
+ * alias behind.
12
+ *
13
+ * Design decisions, in order of importance:
14
+ *
15
+ * 1. DELEGATE freshness to `ollama pull`. The registry serves no
16
+ * docker-content-digest header and its manifest body hash is not the
17
+ * digest ollama reports locally, so a client-side digest comparison
18
+ * would reimplement (and drift from) ollama's own logic. `ollama pull`
19
+ * of an up-to-date tag is a manifest check that downloads nothing.
20
+ *
21
+ * 2. REPAIR the alias after every pull. `prism-coder:<t>` must equal
22
+ * `dcostenco/prism-coder:<t>` byte-for-byte; when digests differ, re-cp.
23
+ * This is the trap register-models cannot fix on its own — it only
24
+ * aliases tags that are MISSING, not tags that are stale.
25
+ *
26
+ * 3. Converge only tiers the machine already has (either the alias or the
27
+ * namespaced source). Convergence updates what you chose to install; it
28
+ * never decides that a 16 GB model belongs on your laptop.
29
+ *
30
+ * 4. Models must never break connect. Ollama down, registry unreachable,
31
+ * one tier failing — report and continue. A machine with stale models
32
+ * and fresh config beats a machine with neither.
33
+ */
34
+ export const MODEL_NAMESPACE = "dcostenco/prism-coder";
35
+ export const LOCAL_PREFIX = "prism-coder";
36
+ export const CONVERGE_TIERS = ["2b", "4b", "9b", "27b"];
37
+ export async function convergeModels(deps) {
38
+ let tags;
39
+ try {
40
+ tags = await deps.listTags();
41
+ }
42
+ catch (err) {
43
+ deps.log(`− model convergence skipped: Ollama unreachable (${err instanceof Error ? err.message : String(err)})`);
44
+ return CONVERGE_TIERS.map((tier) => ({ tier, action: "failed", detail: "ollama_unreachable" }));
45
+ }
46
+ const byName = new Map(tags.map((t) => [t.name, t]));
47
+ const outcomes = [];
48
+ for (const tier of CONVERGE_TIERS) {
49
+ const source = `${MODEL_NAMESPACE}:${tier}`;
50
+ const alias = `${LOCAL_PREFIX}:${tier}`;
51
+ const hadSource = byName.has(source);
52
+ const hadAlias = byName.has(alias);
53
+ if (!hadSource && !hadAlias) {
54
+ outcomes.push({ tier, action: "skipped_not_installed" });
55
+ continue;
56
+ }
57
+ if (deps.dryRun) {
58
+ deps.log(`• would pull ${source} and repair the ${alias} alias if stale`);
59
+ outcomes.push({ tier, action: "up_to_date", detail: "dry_run" });
60
+ continue;
61
+ }
62
+ try {
63
+ const digestBefore = byName.get(source)?.digest;
64
+ await deps.pull(source);
65
+ // Re-list AFTER the pull: both the freshness answer and the alias
66
+ // comparison must come from post-pull state, or a pull that
67
+ // changed bytes looks identical to one that did nothing.
68
+ const after = await deps.listTags();
69
+ const afterByName = new Map(after.map((t) => [t.name, t]));
70
+ const sourceNow = afterByName.get(source);
71
+ const aliasNow = afterByName.get(alias);
72
+ if (!sourceNow) {
73
+ outcomes.push({ tier, action: "failed", detail: "source_missing_after_pull" });
74
+ deps.log(`⚠ ${source}: pull reported success but the tag is not installed`);
75
+ continue;
76
+ }
77
+ const pulledNewBytes = digestBefore !== undefined && digestBefore !== sourceNow.digest;
78
+ const aliasStale = !aliasNow || aliasNow.digest !== sourceNow.digest;
79
+ if (aliasStale) {
80
+ await deps.copy(source, alias);
81
+ const action = pulledNewBytes || !hadSource ? "pulled_and_aliased" : "aliased_only";
82
+ outcomes.push({ tier, action });
83
+ deps.log(`✓ ${alias} ${aliasNow ? "re-aliased (was a stale snapshot)" : "aliased"} → ${sourceNow.digest.slice(0, 12)}`);
84
+ }
85
+ else if (pulledNewBytes) {
86
+ // Alias digest already matches the fresh source — cp raced us
87
+ // or the user re-aliased by hand; either way converged.
88
+ outcomes.push({ tier, action: "pulled_and_aliased" });
89
+ deps.log(`✓ ${source} updated; ${alias} already matches`);
90
+ }
91
+ else {
92
+ outcomes.push({ tier, action: "up_to_date" });
93
+ deps.log(`= ${alias} up to date (${sourceNow.digest.slice(0, 12)})`);
94
+ }
95
+ }
96
+ catch (err) {
97
+ outcomes.push({ tier, action: "failed", detail: err instanceof Error ? err.message : String(err) });
98
+ deps.log(`⚠ ${source}: ${err instanceof Error ? err.message : String(err)} — continuing with the other tiers`);
99
+ }
100
+ }
101
+ return outcomes;
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prism-mcp-server",
3
- "version": "20.13.1",
3
+ "version": "20.14.0",
4
4
  "mcpName": "io.github.dcostenco/prism-coder",
5
5
  "description": "Persistent session memory for AI coding agents that never leaves your machine — including the on-device model that reasons over it. Restores your prior decisions, open TODOs, and changed files across sessions; adds associative recall of related past work, semantic drift detection, and local inference. Local-first by default. Works with Claude Code, Cursor, and Codex.",
6
6
  "module": "index.ts",