prism-mcp-server 20.21.5 → 20.21.6

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/connect.js CHANGED
@@ -591,7 +591,13 @@ function serializeClaudeStartupBlock(newline) {
591
591
  ].join(newline);
592
592
  }
593
593
  /** Install or refresh Claude Code's native, hook-free first-turn instruction. */
594
- export function configureClaudeNativeStartup(homeDir = homedir(), dryRun = false, beforeCommit) {
594
+ export function configureClaudeNativeStartup(homeDir = homedir(), dryRun = false, beforeCommit,
595
+ /** Refresh an existing managed block and nothing else. With this set the
596
+ * install branch is unreachable, so a caller that did not receive the
597
+ * operator's consent (the unattended startup refresh) cannot create a
598
+ * block — not through a marker that only appears in prose, and not through
599
+ * a marker removed between a caller's check and this read. */
600
+ refreshOnly = false) {
595
601
  const instructionPath = join(homeDir, ".claude", "CLAUDE.md");
596
602
  let writePath = instructionPath;
597
603
  let symlinkPath;
@@ -613,6 +619,11 @@ export function configureClaudeNativeStartup(homeDir = homedir(), dryRun = false
613
619
  const newline = currentText.includes("\r\n") ? "\r\n" : "\n";
614
620
  const startRanges = findExactLineRanges(currentText, CLAUDE_STARTUP_MANAGED_START);
615
621
  const endRanges = findExactLineRanges(currentText, CLAUDE_STARTUP_MANAGED_END);
622
+ // Not ours: no opening marker at all. Under refreshOnly that is the ordinary
623
+ // case (a host the operator never connected), not an ambiguity to shout about.
624
+ if (refreshOnly && startRanges.length === 0) {
625
+ return { path: instructionPath, status: "unmanaged" };
626
+ }
616
627
  if (startRanges.length !== endRanges.length || startRanges.length > 1) {
617
628
  throw new Error(`Claude instructions contain ambiguous Prism startup ownership markers: ${instructionPath}`);
618
629
  }
@@ -631,6 +642,8 @@ export function configureClaudeNativeStartup(homeDir = homedir(), dryRun = false
631
642
  action = "refresh";
632
643
  }
633
644
  else {
645
+ if (refreshOnly)
646
+ return { path: instructionPath, status: "unmanaged" };
634
647
  const separator = currentText.length === 0
635
648
  ? ""
636
649
  : currentText.endsWith("\n") || currentText.endsWith("\r")
@@ -688,7 +701,9 @@ function legacyGeminiStartupBlock(newline) {
688
701
  ].join(newline);
689
702
  }
690
703
  /** Install or refresh Gemini CLI's native, hook-free first-turn instruction. */
691
- export function configureGeminiNativeStartup(homeDir = homedir(), dryRun = false, beforeCommit) {
704
+ export function configureGeminiNativeStartup(homeDir = homedir(), dryRun = false, beforeCommit,
705
+ /** See configureClaudeNativeStartup. */
706
+ refreshOnly = false) {
692
707
  const instructionPath = join(homeDir, ".gemini", "GEMINI.md");
693
708
  let writePath = instructionPath;
694
709
  let symlinkPath;
@@ -710,6 +725,11 @@ export function configureGeminiNativeStartup(homeDir = homedir(), dryRun = false
710
725
  const newline = currentText.includes("\r\n") ? "\r\n" : "\n";
711
726
  const startRanges = findExactLineRanges(currentText, GEMINI_STARTUP_MANAGED_START);
712
727
  const endRanges = findExactLineRanges(currentText, GEMINI_STARTUP_MANAGED_END);
728
+ // Not ours: no opening marker at all. Under refreshOnly that is the ordinary
729
+ // case (a host the operator never connected), not an ambiguity to shout about.
730
+ if (refreshOnly && startRanges.length === 0) {
731
+ return { path: instructionPath, status: "unmanaged" };
732
+ }
713
733
  if (startRanges.length !== endRanges.length || startRanges.length > 1) {
714
734
  throw new Error(`Gemini instructions contain ambiguous Prism startup ownership markers: ${instructionPath}`);
715
735
  }
@@ -728,6 +748,8 @@ export function configureGeminiNativeStartup(homeDir = homedir(), dryRun = false
728
748
  action = "refresh";
729
749
  }
730
750
  else {
751
+ if (refreshOnly)
752
+ return { path: instructionPath, status: "unmanaged" };
731
753
  const legacyBlock = legacyGeminiStartupBlock(newline);
732
754
  if (currentText.startsWith(legacyBlock)) {
733
755
  nextText = managedBlock + newline + currentText.slice(legacyBlock.length);
@@ -757,7 +779,9 @@ function serializeCodexStartupBlock(newline) {
757
779
  ].join(newline);
758
780
  }
759
781
  /** Install or refresh Codex's official global, hook-free first-turn instruction. */
760
- export function configureCodexNativeStartup(homeDir, dryRun = false, beforeCommit, env = homeDir === undefined ? process.env : {}) {
782
+ export function configureCodexNativeStartup(homeDir, dryRun = false, beforeCommit, env = homeDir === undefined ? process.env : {},
783
+ /** See configureClaudeNativeStartup. */
784
+ refreshOnly = false) {
761
785
  const userHome = homeDir ?? homedir();
762
786
  const configuredCodexHome = env.CODEX_HOME?.trim();
763
787
  const codexHome = configuredCodexHome ? resolve(configuredCodexHome) : join(userHome, ".codex");
@@ -782,6 +806,11 @@ export function configureCodexNativeStartup(homeDir, dryRun = false, beforeCommi
782
806
  const newline = currentText.includes("\r\n") ? "\r\n" : "\n";
783
807
  const startRanges = findExactLineRanges(currentText, CODEX_STARTUP_MANAGED_START);
784
808
  const endRanges = findExactLineRanges(currentText, CODEX_STARTUP_MANAGED_END);
809
+ // Not ours: no opening marker at all. Under refreshOnly that is the ordinary
810
+ // case (a host the operator never connected), not an ambiguity to shout about.
811
+ if (refreshOnly && startRanges.length === 0) {
812
+ return { path: instructionPath, status: "unmanaged" };
813
+ }
785
814
  if (startRanges.length !== endRanges.length || startRanges.length > 1) {
786
815
  throw new Error(`Codex instructions contain ambiguous Prism startup ownership markers: ${instructionPath}`);
787
816
  }
@@ -800,6 +829,8 @@ export function configureCodexNativeStartup(homeDir, dryRun = false, beforeCommi
800
829
  action = "refresh";
801
830
  }
802
831
  else {
832
+ if (refreshOnly)
833
+ return { path: instructionPath, status: "unmanaged" };
803
834
  const separator = currentText.length === 0
804
835
  ? ""
805
836
  : currentText.endsWith("\n") || currentText.endsWith("\r")
@@ -844,7 +875,128 @@ function configureJsonAgentPolicy(configPath, label, mutate, dryRun, beforeCommi
844
875
  writeTextAtomically(writePath, `${JSON.stringify(config, null, 2)}\n`, originalText, beforeCommit, symlinkPath);
845
876
  return { path: configPath, status: action === "install" ? "installed" : "refreshed" };
846
877
  }
847
- /** Configure Claude Code's economy fallback model; policy text prevents routine fan-out. */
878
+ /** Rewrite a managed startup block whose content differs from what THIS binary
879
+ * writes, and nothing else. Not "older": there is no version ordering in the
880
+ * block, so a pinned older install can rewrite what a newer one wrote.
881
+ *
882
+ * The instruction files are the one delivery channel that does not travel with
883
+ * the package: the MCP `initialize` instructions and every tool description
884
+ * update the moment the server binary does, but a native instruction file keeps
885
+ * whatever text `prism connect` last wrote. Released 20.21.0 changed that text —
886
+ * it used to tell hosts to pass `cloud_fallback: false`, which made a paid
887
+ * plan's escalation unreachable — and a machine that never re-runs connect keeps
888
+ * telling its host the retracted thing. `prism update` deliberately never
889
+ * touches host configuration, autoupdate runs `update`, and npm's ignore-scripts
890
+ * blocks the postinstall refresh, so on an ordinary machine nothing heals it.
891
+ *
892
+ * This is the narrow, safe subset of connect, and the narrowness is the point:
893
+ *
894
+ * - MARKER-GATED. A file without the ownership marker is left byte-for-byte
895
+ * alone. Connect is still the only thing that can FIRST install a block;
896
+ * consent is never inferred from a server start.
897
+ * - Startup blocks ONLY. It never touches MCP host registration — that is what
898
+ * connect's "close target hosts before registration" warning is about, since
899
+ * a live host rewrites its own config. These files DO have another writer —
900
+ * Gemini CLI writes GEMINI.md on a remember request, Claude Code writes
901
+ * CLAUDE.md on /init — so only the marker-delimited block is replaced,
902
+ * marker lines included, and the file is re-checked immediately before
903
+ * committing; a write landing inside that final window would still be
904
+ * lost.
905
+ * - Content-addressed, so it is a no-op once current: the block is compared
906
+ * byte-for-byte and only a difference writes.
907
+ *
908
+ * The host reads its instruction file when a session starts, so a refresh made
909
+ * during this session lands on the NEXT one. That is the cost of healing
910
+ * without asking, and it is one session. */
911
+ export function refreshManagedStartupBlocks(options = {}) {
912
+ const homeDir = options.homeDir ?? homedir();
913
+ const env = options.env ?? process.env;
914
+ // The opt-out lives here, next to the writing, so it is one decision and a
915
+ // test can exercise it without starting a server.
916
+ if (env.PRISM_NO_STARTUP_REFRESH === "1")
917
+ return [];
918
+ const dryRun = !!options.dryRun;
919
+ const codexHome = env.CODEX_HOME?.trim() ? resolve(env.CODEX_HOME.trim()) : join(homeDir, ".codex");
920
+ const targets = [
921
+ { host: "claude-code", path: join(homeDir, ".claude", "CLAUDE.md"), configure: () => configureClaudeNativeStartup(homeDir, dryRun, undefined, true) },
922
+ { host: "gemini", path: join(homeDir, ".gemini", "GEMINI.md"), configure: () => configureGeminiNativeStartup(homeDir, dryRun, undefined, true) },
923
+ { host: "codex", path: join(codexHome, "AGENTS.md"), configure: () => configureCodexNativeStartup(homeDir, dryRun, undefined, env, true) },
924
+ ];
925
+ const results = [];
926
+ // Two hosts can resolve to ONE file — GEMINI.md symlinked to CLAUDE.md is a
927
+ // common single-file setup — and Claude and Gemini serialize the SAME
928
+ // ownership marker, so without this each start rewrote that file twice and
929
+ // never converged: two "refreshed" lines on every start, forever. Whoever
930
+ // gets there first owns it; the second reports it as already handled.
931
+ // Identity is the FILE, not the path: statSync follows symlinks, and dev:ino
932
+ // is shared by hard links too, which a path comparison misses entirely (an
933
+ // atomic replace would then break the link and hand both hosts a "refreshed"
934
+ // they should never have got). Resolved ONCE per target and reused, so the
935
+ // decision below is the one that was actually measured; a target retargeted
936
+ // after this point is the same inherent window as the compare-to-rename one
937
+ // documented on writeTextAtomically.
938
+ const identityOf = (path) => {
939
+ try {
940
+ const info = statSync(path);
941
+ return `${info.dev}:${info.ino}`;
942
+ }
943
+ catch {
944
+ return `path:${path}`; // absent or unreadable: the path itself is identity enough
945
+ }
946
+ };
947
+ const resolved = targets.map(target => ({ target, identity: identityOf(target.path) }));
948
+ const shared = new Map();
949
+ for (const { target, identity } of resolved) {
950
+ shared.set(identity, [...(shared.get(identity) ?? []), target.host]);
951
+ }
952
+ for (const { target, identity } of resolved) {
953
+ const sharing = shared.get(identity) ?? [target.host];
954
+ if (sharing.length > 1) {
955
+ // One file, two hosts. Claude and Gemini serialize the SAME ownership
956
+ // marker but DIFFERENT instructions (the tool is named differently for
957
+ // each), so there is no content that satisfies both: healing it would
958
+ // hand one host the other's block, and before this check each start
959
+ // rewrote the file once per host, forever. Whose block it should be is
960
+ // the operator's call, not a background process's.
961
+ results.push({
962
+ host: target.host,
963
+ path: target.path,
964
+ status: "failed",
965
+ detail: `shared with ${sharing.filter(h => h !== target.host).join(", ")} (one file cannot hold both blocks); run: prism connect`,
966
+ });
967
+ continue;
968
+ }
969
+ try {
970
+ // No independent pre-read. The configurator's own exact-line marker
971
+ // recognition decides, from ONE snapshot: a second, weaker check here
972
+ // (a substring scan) would call a file managed because the marker
973
+ // appears in its prose, and the window between two reads is a way to
974
+ // lose the marker after the check. With refreshOnly the install branch
975
+ // is unreachable either way.
976
+ const outcome = target.configure();
977
+ results.push({
978
+ host: target.host,
979
+ path: outcome.path,
980
+ // A dry run must not claim a write it did not make: would-refresh is
981
+ // carried through as itself. installed/would-install are unreachable
982
+ // under refreshOnly, so anything else is a completed refresh.
983
+ status: outcome.status === "unchanged" || outcome.status === "unmanaged" || outcome.status === "would-refresh"
984
+ ? outcome.status
985
+ : "refreshed",
986
+ });
987
+ }
988
+ catch (error) {
989
+ // A self-heal must never be the reason a server fails to start.
990
+ results.push({
991
+ host: target.host,
992
+ path: target.path,
993
+ status: "failed",
994
+ detail: error instanceof Error ? error.message : String(error),
995
+ });
996
+ }
997
+ }
998
+ return results;
999
+ }
848
1000
  export function configureClaudeAgentPolicy(homeDir = homedir(), dryRun = false, beforeCommit) {
849
1001
  const configPath = join(homeDir, ".claude", "settings.json");
850
1002
  return configureJsonAgentPolicy(configPath, "Claude agent settings", (config) => {
package/dist/server.js CHANGED
@@ -1307,6 +1307,66 @@ export async function startServer() {
1307
1307
  const transport = new StdioServerTransport();
1308
1308
  await server.connect(transport);
1309
1309
  console.error(`[Prism] MCP Server successfully started and listening on stdio...`);
1310
+ // Heal a startup block whose content differs from what this binary writes.
1311
+ // (Not "older": nothing orders versions, so a pinned older install can
1312
+ // rewrite what a newer one wrote.) The instruction files are the
1313
+ // one channel that does not travel with the package — `initialize`
1314
+ // instructions and every tool description update with the binary, a native
1315
+ // instruction file keeps whatever connect last wrote — and nothing on an
1316
+ // ordinary machine re-runs connect: `prism update` never touches host
1317
+ // configuration by design, autoupdate runs `update`, and the postinstall
1318
+ // path covers only the prompt-routing hook and is routinely disabled by
1319
+ // npm's ignore-scripts. 20.21.0 is the release that
1320
+ // proved the cost: the old text told hosts to pass `cloud_fallback: false`,
1321
+ // which made a paid plan's escalation unreachable.
1322
+ //
1323
+ // Refresh-only, so this can only ever rewrite a block the operator already
1324
+ // consented to by running connect once: the install branch is unreachable
1325
+ // from here, and a file without exactly one ordered marker pair is left
1326
+ // byte-for-byte alone. Startup blocks only — never MCP registration, which
1327
+ // is what connect's "close your hosts first" warning is about. These files
1328
+ // do have another writer (Gemini CLI writes GEMINI.md on a remember
1329
+ // request, Claude Code writes CLAUDE.md on /init), so the refresh replaces
1330
+ // only its own marker-delimited block, marker lines included, and re-checks
1331
+ // immediately before committing. After the transport is connected, so the handshake is never
1332
+ // held behind disk I/O. PRISM_NO_STARTUP_REFRESH=1 opts out.
1333
+ //
1334
+ // DEFERRED, and unref'd, for two reasons. `connect.js` is a large module
1335
+ // (the whole CLI surface, TOML parser included) and importing it is
1336
+ // synchronous CPU work: awaited here it competes with the FIRST tool call,
1337
+ // which on a cold host is the one that has to do a storage round trip. And
1338
+ // an unref'd timer can never hold the process open. The block is read by the
1339
+ // host at session start, so it was always landing on the next session — a
1340
+ // couple of seconds changes nothing about when the fix arrives.
1341
+ if (process.env.PRISM_NO_STARTUP_REFRESH !== "1") {
1342
+ setTimeout(() => { void refreshStartupBlocksInBackground(); }, 2_000).unref();
1343
+ }
1344
+ await resumeServerStartup(server);
1345
+ }
1346
+ async function refreshStartupBlocksInBackground() {
1347
+ try {
1348
+ const { refreshManagedStartupBlocks } = await import("./connect.js");
1349
+ for (const result of refreshManagedStartupBlocks()) {
1350
+ if (result.status === "refreshed") {
1351
+ // The host read this file when the session began, so the corrected
1352
+ // text applies from the next one.
1353
+ console.error(`[Prism] refreshed the ${result.host} startup block to match this version: ${result.path} (applies from your next session)`);
1354
+ }
1355
+ else if (result.status === "failed") {
1356
+ console.error(`[Prism] could not refresh the ${result.host} startup block (${result.detail}); run: prism connect`);
1357
+ }
1358
+ else if (process.env.PRISM_DEBUG) {
1359
+ console.error(`[Prism] startup block ${result.host}: ${result.status}${result.detail ? ` (${result.detail})` : ""}`);
1360
+ }
1361
+ }
1362
+ }
1363
+ catch (error) {
1364
+ // Never the reason a server fails to start.
1365
+ if (process.env.PRISM_DEBUG)
1366
+ console.error(`[Prism] startup refresh skipped: ${error instanceof Error ? error.message : error}`);
1367
+ }
1368
+ }
1369
+ async function resumeServerStartup(server) {
1310
1370
  // Start the authoritative tier-skill refresh only after the MCP transport is
1311
1371
  // connected. session_load_context awaits this same single-flight promise,
1312
1372
  // while the initialize handshake is never held behind portal I/O. The
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prism-mcp-server",
3
- "version": "20.21.5",
3
+ "version": "20.21.6",
4
4
  "mcpName": "io.github.dcostenco/prism-coder",
5
5
  "description": "Persistent session memory for AI coding agents that never leaves your machine \u2014 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",