prism-mcp-server 20.21.17 → 20.21.19
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/README.md +17 -1
- package/dist/connect.js +13 -6
- package/dist/contextRecoveryPolicy.js +21 -0
- package/dist/server.js +4 -2
- package/dist/session/sessionContext.js +66 -9
- package/dist/tools/prismInferHandler.js +3 -3
- package/dist/tools/sessionMemoryDefinitions.js +19 -7
- package/dist/tools/skillRouting.js +4 -4
- package/dist/utils/entitlements.js +5 -6
- package/docs/prism-browser.md +33 -0
- package/package.json +3 -3
- package/scripts/dev/browse.py +114 -4
package/README.md
CHANGED
|
@@ -158,6 +158,22 @@ or by re-enabling after each run.
|
|
|
158
158
|
<details>
|
|
159
159
|
<summary>Release history (optional)</summary>
|
|
160
160
|
|
|
161
|
+
## What's New in v20.21.19
|
|
162
|
+
|
|
163
|
+
- Prism Browser emulates phones and tablets. `--device iphone-17`, or one of
|
|
164
|
+
five other measured iPhones and iPads, turns on touch CSS, the pixel ratio,
|
|
165
|
+
and the iPhone safe area, so a layout that only breaks on the phone can be
|
|
166
|
+
caught in a test. `--touch`, `--device-scale-factor`, and `--safe-area` set
|
|
167
|
+
each part on its own.
|
|
168
|
+
|
|
169
|
+
## What's New in v20.21.18
|
|
170
|
+
|
|
171
|
+
- Fixed: when a save was refused with `context_not_loaded`, the instructions
|
|
172
|
+
Prism installs for Claude Code, Codex and Gemini CLI forbade the one call
|
|
173
|
+
that recovers. The refusal now prints that call, `session_load_context`
|
|
174
|
+
with the same project and conversation_id, and the installed instructions
|
|
175
|
+
allow it. First-turn startup is unchanged.
|
|
176
|
+
|
|
161
177
|
## What's New in v20.21.17
|
|
162
178
|
|
|
163
179
|
- Fixed: the on-device screen refused some ordinary coding requests. With a
|
|
@@ -1396,7 +1412,7 @@ Prism exposes 40+ MCP tools. The core memory loop:
|
|
|
1396
1412
|
| Tool | What it does |
|
|
1397
1413
|
|---|---|
|
|
1398
1414
|
| `session_bootstrap` | Hook-free first-turn greeting and dashboard-configured context |
|
|
1399
|
-
| `session_load_context` | Explicit project reload or older-server startup fallback |
|
|
1415
|
+
| `session_load_context` | Explicit project reload, recovery after a `context_not_loaded` save refusal, or older-server startup fallback |
|
|
1400
1416
|
| `session_save_ledger` | Append an immutable session log entry |
|
|
1401
1417
|
| `session_save_handoff` | Save live state for the next session |
|
|
1402
1418
|
| `knowledge_search` | Semantic + keyword search over all memories |
|
package/dist/connect.js
CHANGED
|
@@ -4,6 +4,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep, win32 as w
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { isDeepStrictEqual } from "node:util";
|
|
6
6
|
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
7
|
+
import { CONTEXT_RECOVERY_POLICY_LINES } from "./contextRecoveryPolicy.js";
|
|
7
8
|
import { EVIDENCE_WORKFLOW_POLICY_LINES } from "./evidenceWorkflowPolicy.js";
|
|
8
9
|
import { LOCAL_FIRST_POLICY_ID, LOCAL_FIRST_POLICY_LINES } from "./localFirstPolicy.js";
|
|
9
10
|
export const CONNECT_HOSTS = [
|
|
@@ -44,11 +45,13 @@ const CODEX_STARTUP_BODY = [
|
|
|
44
45
|
"reformat, or omit any returned section. Preserve its order and line content. For a greeting-only prompt, stop",
|
|
45
46
|
"after the verbatim startup display. If `session_bootstrap` is deferred, use native tool discovery to load that",
|
|
46
47
|
"exact tool, then invoke it. Do not use shell commands, file reads, subagents, or unrelated tool inspection as",
|
|
47
|
-
"a substitute
|
|
48
|
+
"a substitute, and do not use `session_load_context` in place of it. If discovery or invocation fails, report",
|
|
48
49
|
"`Prism startup failure` and stop. Reuse the `conversation_id` returned on the `<prism_session />` line for every",
|
|
49
50
|
"session_save_ledger, session_save_handoff, and session_detect_drift call in this conversation. This hook-free",
|
|
50
51
|
"block is managed by `prism connect`; do not edit it manually.",
|
|
51
52
|
"",
|
|
53
|
+
...CONTEXT_RECOVERY_POLICY_LINES,
|
|
54
|
+
"",
|
|
52
55
|
...LOCAL_FIRST_POLICY_LINES,
|
|
53
56
|
"",
|
|
54
57
|
...EVIDENCE_WORKFLOW_POLICY_LINES,
|
|
@@ -578,11 +581,13 @@ function serializeClaudeStartupBlock(newline) {
|
|
|
578
581
|
"content. For a greeting-only prompt, stop after the verbatim startup display. If `session_bootstrap` is",
|
|
579
582
|
"deferred, use native tool discovery/ToolSearch to load that",
|
|
580
583
|
"exact tool, then invoke it. Do not use shell commands, file reads, subagents, or unrelated tool inspection",
|
|
581
|
-
"as a substitute
|
|
584
|
+
"as a substitute, and do not use `session_load_context` in place of it. If discovery or invocation fails, report",
|
|
582
585
|
"`Prism startup failure` and stop. Reuse the `conversation_id` returned on the `<prism_session />` line for every",
|
|
583
586
|
"session_save_ledger, session_save_handoff, and session_detect_drift call in this conversation. This block is",
|
|
584
587
|
"managed by `prism connect`; do not edit it manually.",
|
|
585
588
|
"",
|
|
589
|
+
...CONTEXT_RECOVERY_POLICY_LINES,
|
|
590
|
+
"",
|
|
586
591
|
...LOCAL_FIRST_POLICY_LINES,
|
|
587
592
|
"",
|
|
588
593
|
...EVIDENCE_WORKFLOW_POLICY_LINES,
|
|
@@ -671,10 +676,12 @@ function serializeGeminiStartupBlock(newline) {
|
|
|
671
676
|
"reformat, or omit any returned section. Preserve its order and line content. For a greeting-only prompt, stop",
|
|
672
677
|
"after the verbatim startup display. If `session_bootstrap` is deferred, use native tool discovery/ToolSearch",
|
|
673
678
|
"to load that exact tool, then invoke it.",
|
|
674
|
-
"Do not use shell commands, file reads, subagents, or unrelated tool inspection as a substitute
|
|
675
|
-
"`session_load_context
|
|
676
|
-
"`conversation_id` returned on the `<prism_session />` line for session_save_ledger, session_save_handoff,
|
|
677
|
-
"session_detect_drift calls. This block is managed by `prism connect`; do not edit it manually.",
|
|
679
|
+
"Do not use shell commands, file reads, subagents, or unrelated tool inspection as a substitute, and do not use",
|
|
680
|
+
"`session_load_context` in place of it. If discovery or invocation fails, report `Prism startup failure` and stop.",
|
|
681
|
+
"Reuse the `conversation_id` returned on the `<prism_session />` line for session_save_ledger, session_save_handoff,",
|
|
682
|
+
"and session_detect_drift calls. This block is managed by `prism connect`; do not edit it manually.",
|
|
683
|
+
"",
|
|
684
|
+
...CONTEXT_RECOVERY_POLICY_LINES,
|
|
678
685
|
"",
|
|
679
686
|
...LOCAL_FIRST_POLICY_LINES,
|
|
680
687
|
"",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical context-recovery contract shared by every host instruction file.
|
|
3
|
+
*
|
|
4
|
+
* Startup is one `session_bootstrap` call. A later save can still be refused
|
|
5
|
+
* with `context_not_loaded`, and the refusal names one remedy; the host block
|
|
6
|
+
* must say the same thing instead of forbidding it. Keep this host-neutral: the
|
|
7
|
+
* Claude Code, Gemini CLI and Codex blocks splice these lines unchanged, and
|
|
8
|
+
* the server instructions, tool descriptions and refusal text state the same
|
|
9
|
+
* rule in their own words (pinned by tests/startup-recovery-contract.test.ts).
|
|
10
|
+
*/
|
|
11
|
+
export const CONTEXT_RECOVERY_POLICY_LINES = [
|
|
12
|
+
"## Prism context recovery",
|
|
13
|
+
"Startup is the one turn-one `session_bootstrap` call. Prism can still refuse `session_save_ledger` or",
|
|
14
|
+
"`session_save_handoff` with `context_not_loaded`: it has no record that this conversation loaded that project",
|
|
15
|
+
"(after a restart, a long idle gap, or for a project startup did not load). That is a recovery step, not a second",
|
|
16
|
+
"startup. Call `session_load_context` with the same `project` and the same `conversation_id` as the refused save",
|
|
17
|
+
"(the refusal prints the exact call; discover the tool the same way if it is deferred), then retry the save once.",
|
|
18
|
+
"Do not repeat `session_bootstrap` or print a startup display for it. If the reload or the retry fails, tell the",
|
|
19
|
+
"user; a local note is a fallback after that, never a substitute for the reload.",
|
|
20
|
+
];
|
|
21
|
+
export const CONTEXT_RECOVERY_POLICY_TEXT = CONTEXT_RECOVERY_POLICY_LINES.join(" ");
|
package/dist/server.js
CHANGED
|
@@ -361,8 +361,10 @@ export const PRISM_SERVER_INSTRUCTIONS = `Prism MCP — The Mind Palace for AI A
|
|
|
361
361
|
`Emit no preamble. Print the complete tool result verbatim as the entire first-turn startup display, before any optional ` +
|
|
362
362
|
`answer. Do not summarize, paraphrase, rename headings, reformat, or omit any returned section. Preserve its order and ` +
|
|
363
363
|
`line content. For a greeting-only prompt, stop after the verbatim startup display. ` +
|
|
364
|
-
`Do not substitute session_load_context while session_bootstrap is available
|
|
365
|
-
`
|
|
364
|
+
`Do not substitute session_load_context for the startup call while session_bootstrap is available. Use ` +
|
|
365
|
+
`session_load_context to recover when a save is refused with context_not_loaded (pass that save's project ` +
|
|
366
|
+
`and conversation_id, then retry the save once; recovery is not a second startup), for an explicit project ` +
|
|
367
|
+
`reload, or as an older-server fallback. ` +
|
|
366
368
|
`Use session_save_ledger to log completed work and session_save_handoff to preserve state for the next session. ` +
|
|
367
369
|
`Reuse the conversation_id from session_bootstrap's <prism_session /> line for those saves and for ` +
|
|
368
370
|
`session_detect_drift, the 60-minute goal-alignment drift check. Do not add the id to the visible greeting.\n\n` +
|
|
@@ -84,24 +84,75 @@ export function markContextLoaded(conversationId, project, boundariesVersion) {
|
|
|
84
84
|
s.boundariesVersion = boundariesVersion;
|
|
85
85
|
lastSeenConversationId = conversationId;
|
|
86
86
|
}
|
|
87
|
+
const ENFORCED = " (Enforced server-side — applies to every host.)";
|
|
88
|
+
/**
|
|
89
|
+
* The one remedy every refusal names, so the three variants cannot drift apart
|
|
90
|
+
* and the host instruction blocks (src/contextRecoveryPolicy.ts), the server
|
|
91
|
+
* instructions and the tool descriptions can say the same thing. A block that
|
|
92
|
+
* forbids the call a refusal asks for leaves an agent with no way forward
|
|
93
|
+
* (tests/startup-recovery-contract.test.ts pins every surface).
|
|
94
|
+
*/
|
|
95
|
+
const CONTEXT_RECOVERY = " To recover, call session_load_context with the same project and the same conversation_id you " +
|
|
96
|
+
"passed to this save, then retry the save once. You do not need to repeat session_bootstrap (it " +
|
|
97
|
+
"reloads only the dashboard Auto-Load projects and reprints the startup display). A recovery load " +
|
|
98
|
+
"is not a second startup. If the retry is refused too, stop and tell the user.";
|
|
87
99
|
function contextNotLoadedError(project) {
|
|
88
100
|
const projectNote = project
|
|
89
101
|
? " the requested project was not loaded for this conversation."
|
|
90
|
-
: "";
|
|
102
|
+
: " no context is registered for this conversation.";
|
|
103
|
+
return {
|
|
104
|
+
blocked: true,
|
|
105
|
+
error: "context_not_loaded:" + projectNote + CONTEXT_RECOVERY +
|
|
106
|
+
" This project-scoped tool needs confirmed working context to act correctly." + ENFORCED,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A save whose conversation_id is the empty string can never be recovered by
|
|
111
|
+
* "the same conversation_id you passed": the load handler registers nothing for
|
|
112
|
+
* an empty id. Say what is actually wrong and where the real id comes from.
|
|
113
|
+
*/
|
|
114
|
+
function emptyConversationIdError() {
|
|
91
115
|
return {
|
|
92
116
|
blocked: true,
|
|
93
|
-
error: "context_not_loaded:
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
117
|
+
error: "context_not_loaded: conversation_id is empty, so no context can be registered for it." +
|
|
118
|
+
" Pass this conversation's conversation_id (the value on session_bootstrap's <prism_session /> line)," +
|
|
119
|
+
" call session_load_context with that conversation_id and this project, then retry the save once." +
|
|
120
|
+
" If the retry is refused too, stop and tell the user." + ENFORCED,
|
|
97
121
|
};
|
|
98
122
|
}
|
|
99
123
|
function contextExpiredError() {
|
|
100
124
|
return {
|
|
101
125
|
blocked: true,
|
|
102
|
-
error: "context_not_loaded: session expired (6 h TTL).
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
error: "context_not_loaded: session expired (6 h TTL)." + CONTEXT_RECOVERY + ENFORCED,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Longest project or conversation_id a refusal echoes back. A longer value gets
|
|
131
|
+
* the remedy without a literal call: a clipped value would register the wrong
|
|
132
|
+
* project, and the retry would be refused again.
|
|
133
|
+
*/
|
|
134
|
+
const MAX_ECHOED_VALUE = 200;
|
|
135
|
+
/**
|
|
136
|
+
* Print the literal recovery call, built from the arguments the refused save
|
|
137
|
+
* used, so "the same project and conversation_id" cannot be mistyped or
|
|
138
|
+
* replaced by a host session id. Values are JSON-escaped and echoed whole, only
|
|
139
|
+
* to the caller that just sent them; a value too long to echo gets no call.
|
|
140
|
+
*/
|
|
141
|
+
function withExactCall(gate, conversationId, project) {
|
|
142
|
+
if (!gate || !gate.blocked || !conversationId || !project.trim() || !gate.error.endsWith(ENFORCED)) {
|
|
143
|
+
return gate;
|
|
144
|
+
}
|
|
145
|
+
if (project.length > MAX_ECHOED_VALUE || conversationId.length > MAX_ECHOED_VALUE)
|
|
146
|
+
return gate;
|
|
147
|
+
const call = JSON.stringify({
|
|
148
|
+
project,
|
|
149
|
+
conversation_id: conversationId,
|
|
150
|
+
toolAction: "Reload context",
|
|
151
|
+
toolSummary: "Recover from context_not_loaded",
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
blocked: true,
|
|
155
|
+
error: gate.error.slice(0, -ENFORCED.length) + ` Exact call: session_load_context(${call}).` + ENFORCED,
|
|
105
156
|
};
|
|
106
157
|
}
|
|
107
158
|
function hashReceiptScope(kind, value) {
|
|
@@ -196,9 +247,15 @@ export function requireContextLoaded(conversationId) {
|
|
|
196
247
|
* cross-project lookups remain fail-closed.
|
|
197
248
|
*/
|
|
198
249
|
export async function requireContextLoadedForProject(conversationId, project) {
|
|
250
|
+
const gate = await evaluateContextGateForProject(conversationId, project);
|
|
251
|
+
return conversationId === undefined ? gate : withExactCall(gate, conversationId, project);
|
|
252
|
+
}
|
|
253
|
+
async function evaluateContextGateForProject(conversationId, project) {
|
|
199
254
|
if (conversationId === undefined)
|
|
200
255
|
return null;
|
|
201
|
-
if (!conversationId
|
|
256
|
+
if (!conversationId)
|
|
257
|
+
return emptyConversationIdError();
|
|
258
|
+
if (!project.trim())
|
|
202
259
|
return contextNotLoadedError(project || undefined);
|
|
203
260
|
const memoryGate = requireContextLoaded(conversationId);
|
|
204
261
|
const memoryState = sessions.get(conversationId);
|
|
@@ -256,7 +256,7 @@ export function _resetLayer1HistoryCacheForTest() { layer1HistoryCache.clear();
|
|
|
256
256
|
* probe and read races the time left, and no clearance is accepted after it. */
|
|
257
257
|
export const LAYER1_SECOND_READ_MAX_CALLS = 48;
|
|
258
258
|
export const LAYER1_SECOND_READ_DEADLINE_MS = 30_000;
|
|
259
|
-
/** Reads in flight at once: ONE
|
|
259
|
+
/** Reads in flight at once: ONE.
|
|
260
260
|
* Two at once made each classifier read about twice as slow and some reads
|
|
261
261
|
* abort at the classifier's first-attempt timeout (an aborted read keeps the
|
|
262
262
|
* hedge: refusal or cloud), for little clearance time gained. The per-read
|
|
@@ -1498,8 +1498,8 @@ function makeReservedRefusal(verdict, attempts, category = null, cloudWasAllowed
|
|
|
1498
1498
|
});
|
|
1499
1499
|
return new ReservedRefusalError(verdict, attempts, category, cloudWasAllowed);
|
|
1500
1500
|
}
|
|
1501
|
-
/**
|
|
1502
|
-
*
|
|
1501
|
+
/** Server cap on the flattened conversation (`ROLE: content` lines): the
|
|
1502
|
+
* Synalux inference endpoint enforces the same limit. */
|
|
1503
1503
|
export const CLOUD_HISTORY_CAP_BYTES = 32 * 1024;
|
|
1504
1504
|
/** Exported for tests: the cap check must be provable without a portal. */
|
|
1505
1505
|
export async function callSynaluxInference(prompt, maxTokens, timeoutMs, opts) {
|
|
@@ -4,7 +4,10 @@ export const SESSION_SAVE_LEDGER_TOOL = {
|
|
|
4
4
|
description: "Save an immutable session log entry to the session ledger. " +
|
|
5
5
|
"Use this at the END of each work session to record what was accomplished. " +
|
|
6
6
|
"The ledger is append-only — entries cannot be updated or deleted. " +
|
|
7
|
-
"This creates a permanent audit trail of all agent work sessions."
|
|
7
|
+
"This creates a permanent audit trail of all agent work sessions. " +
|
|
8
|
+
"The save is refused with context_not_loaded until session_bootstrap or session_load_context has loaded " +
|
|
9
|
+
"this exact project for this conversation_id; on that refusal call session_load_context with the same " +
|
|
10
|
+
"project and conversation_id, then retry the save once.",
|
|
8
11
|
inputSchema: {
|
|
9
12
|
type: "object",
|
|
10
13
|
properties: {
|
|
@@ -60,7 +63,11 @@ export const SESSION_SAVE_HANDOFF_TOOL = {
|
|
|
60
63
|
"Pass expected_version to enable concurrency control.\n\n" +
|
|
61
64
|
"**v0.4.0 OCC**: If you received a version number from session_load_context, " +
|
|
62
65
|
"/resume_session prompt, or memory resource attachment, you MUST pass it as " +
|
|
63
|
-
"expected_version to prevent overwriting another session's changes
|
|
66
|
+
"expected_version to prevent overwriting another session's changes.\n\n" +
|
|
67
|
+
"Pass the same conversation_id as session_save_ledger: the save is refused with context_not_loaded until " +
|
|
68
|
+
"session_bootstrap or session_load_context has loaded this exact project for it; on that refusal call " +
|
|
69
|
+
"session_load_context with the same project and conversation_id, then retry the save once, passing the " +
|
|
70
|
+
"version it shows as expected_version.",
|
|
64
71
|
inputSchema: {
|
|
65
72
|
type: "object",
|
|
66
73
|
properties: {
|
|
@@ -101,7 +108,7 @@ export const SESSION_SAVE_HANDOFF_TOOL = {
|
|
|
101
108
|
},
|
|
102
109
|
conversation_id: {
|
|
103
110
|
type: "string",
|
|
104
|
-
description: "Optional. Session key for this conversation (same id used in session_load_context). When provided, the server verifies that session_load_context
|
|
111
|
+
description: "Optional. Session key for this conversation (same id used in session_load_context). When provided, the server verifies that session_bootstrap or session_load_context loaded this exact project for this conversation before accepting the write.",
|
|
105
112
|
},
|
|
106
113
|
},
|
|
107
114
|
required: ["project"],
|
|
@@ -111,7 +118,9 @@ export const SESSION_SAVE_HANDOFF_TOOL = {
|
|
|
111
118
|
export const SESSION_LOAD_CONTEXT_TOOL = {
|
|
112
119
|
name: "session_load_context",
|
|
113
120
|
description: "Load session context for a project using progressive context loading. " +
|
|
114
|
-
"Use this
|
|
121
|
+
"Use this to recover when session_save_ledger or session_save_handoff is refused with context_not_loaded " +
|
|
122
|
+
"(pass that save's project and the same conversation_id, then retry the save once; a recovery load is not a " +
|
|
123
|
+
"second startup), for an explicit project reload, or as a startup fallback only when session_bootstrap is unavailable. " +
|
|
115
124
|
"When session_bootstrap is available, do not substitute this tool for the first-turn bootstrap. " +
|
|
116
125
|
"Three levels available:\n" +
|
|
117
126
|
"- **quick**: Just the latest project state — keywords and open TODOs (~50 tokens)\n" +
|
|
@@ -148,7 +157,7 @@ export const SESSION_LOAD_CONTEXT_TOOL = {
|
|
|
148
157
|
},
|
|
149
158
|
conversation_id: {
|
|
150
159
|
type: "string",
|
|
151
|
-
description: "Optional.
|
|
160
|
+
description: "Optional for a plain read. Pass it whenever this load is meant to unlock saves (startup fallback, or recovery from context_not_loaded), using the same conversation_id as the refused or upcoming save. When provided, marks this project as context-loaded server-side so project-scoped saves are accepted; without it nothing is registered.",
|
|
152
161
|
},
|
|
153
162
|
prompt: {
|
|
154
163
|
type: "string",
|
|
@@ -209,7 +218,7 @@ export const SESSION_BOOTSTRAP_TOOL = {
|
|
|
209
218
|
"before any user-facing response, passing the user's verbatim first message as {prompt: \"<first user message>\"}. " +
|
|
210
219
|
"The prompt is matched against prompt_keywords ON-DEVICE to load symptom-triggered skills on turn one; it is used " +
|
|
211
220
|
"for routing only and never leaves the machine. Pass {} only when there is no user message. " +
|
|
212
|
-
"Do not substitute session_load_context
|
|
221
|
+
"Do not substitute session_load_context for this startup call. " +
|
|
213
222
|
"This starts a Prism-backed conversation without host hooks. " +
|
|
214
223
|
"Prism reads the dashboard's Auto-Load Projects, Context Depth (quick/standard/deep), developer name, and default role, " +
|
|
215
224
|
"then returns the greeting and correctly scoped prior-session context. Emit no preamble. Print the complete tool result " +
|
|
@@ -217,7 +226,10 @@ export const SESSION_BOOTSTRAP_TOOL = {
|
|
|
217
226
|
"headings, reformat, or omit any returned section. Preserve its order and line content. For a greeting-only prompt, " +
|
|
218
227
|
"stop after the verbatim startup display. Do not guess or pass a project or depth. Prism returns a stable " +
|
|
219
228
|
"conversation_id on the trailing <prism_session /> line; reuse it for session_save_ledger, session_save_handoff, and " +
|
|
220
|
-
"session_detect_drift throughout this conversation without adding it to the visible greeting."
|
|
229
|
+
"session_detect_drift throughout this conversation without adding it to the visible greeting. " +
|
|
230
|
+
"This is the first-turn startup call only: if a later save is refused with context_not_loaded, recover with " +
|
|
231
|
+
"session_load_context for that save's project and conversation_id, then retry the save once, rather than " +
|
|
232
|
+
"repeating this startup display.",
|
|
221
233
|
annotations: {
|
|
222
234
|
readOnlyHint: true,
|
|
223
235
|
destructiveHint: false,
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* regexes match, and the regexes are already public. Sending the raw first
|
|
14
14
|
* message bought nothing a local match could not compute — and free-tier
|
|
15
15
|
* callers paid that privacy cost for literally zero routing benefit, since
|
|
16
|
-
* the
|
|
17
|
-
*
|
|
16
|
+
* the server returns no prompt-matched skills to the free tier. Paid skill
|
|
17
|
+
* CONTENT stays gated server-side at
|
|
18
18
|
* /api/v1/prism/skill-manifest, which this change does not touch.
|
|
19
19
|
*
|
|
20
20
|
* Cache: portal keyed on (project,role) — no longer per-prompt, which never
|
|
@@ -464,8 +464,8 @@ export function stripQuotedEvidenceForRouting(prompt, promptKeywords = {}) {
|
|
|
464
464
|
return units.join('');
|
|
465
465
|
}
|
|
466
466
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
467
|
+
* Port of the server resolver's prompt-matching step and the sort that
|
|
468
|
+
* follows it. Parity is the whole point: any divergence silently changes
|
|
469
469
|
* which skills load. Do not "improve" this — the reference implementation and
|
|
470
470
|
* a scenario-level parity test both pin it.
|
|
471
471
|
*
|
|
@@ -14,9 +14,9 @@ import { debugLog } from "./logger.js";
|
|
|
14
14
|
import { resolvePortalBaseUrl, usablePortalKey } from "./synaluxSearch.js";
|
|
15
15
|
/** What a host with NO portal (unconfigured), a portal that says nothing
|
|
16
16
|
* (older deployment), or an assumed-free fallback gets: OFF. Multi-turn
|
|
17
|
-
* needs a Synalux account, and a free one is enough
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* needs a Synalux account, and a free one is enough: the answer check it
|
|
18
|
+
* depends on is served per account. The caps here are what an account gets
|
|
19
|
+
* when the portal omits them. */
|
|
20
20
|
export const DEFAULT_MULTI_TURN = { enabled: false, max_turns: 12, max_chars: 32_000 };
|
|
21
21
|
/** Structural ceiling no plan can exceed: the portal's own inference route
|
|
22
22
|
* takes at most 50 messages INCLUDING the current turn appended on
|
|
@@ -38,9 +38,8 @@ export function multiTurnPolicy(ent) {
|
|
|
38
38
|
}
|
|
39
39
|
// ── Free-tier defaults (no auth) ──────────────────────────────────
|
|
40
40
|
/** No account: everything local, with no cap on the model the user's own
|
|
41
|
-
* machine can run
|
|
42
|
-
*
|
|
43
|
-
* one is enough. */
|
|
41
|
+
* machine can run. Anything that needs Synalux (multi-turn with the answer
|
|
42
|
+
* check, cloud answers) needs an account; a free one is enough. */
|
|
44
43
|
export const FREE_ENTITLEMENTS = {
|
|
45
44
|
plan: "free",
|
|
46
45
|
model_ceiling: "27b",
|
package/docs/prism-browser.md
CHANGED
|
@@ -80,6 +80,39 @@ state carries between runs and makes them order dependent. For test runs use
|
|
|
80
80
|
`--trace PATH`, `--video DIR`, and `--har PATH` record Playwright artifacts for
|
|
81
81
|
a failing run.
|
|
82
82
|
|
|
83
|
+
## Phones and tablets
|
|
84
|
+
|
|
85
|
+
A desktop run never matches `(pointer: coarse)` and reads every
|
|
86
|
+
`env(safe-area-inset-*)` as 0, so CSS written for touchscreens, and layouts
|
|
87
|
+
that pad the iPhone status area and home indicator, cannot show up at a phone
|
|
88
|
+
size alone. Emulate the device instead:
|
|
89
|
+
|
|
90
|
+
- `--device NAME` — a measured iPhone or iPad in portrait: viewport, pixel
|
|
91
|
+
ratio, touch, and safe area. `iphone-se`, `iphone-17`, `iphone-air`,
|
|
92
|
+
`iphone-17-pro-max`, `ipad-a16`, `ipad-pro-13`. The values were read from a
|
|
93
|
+
full-screen web view on iOS 26.5 simulators.
|
|
94
|
+
- `--touch` — a touchscreen: `(pointer: coarse)` and `(hover: none)` match,
|
|
95
|
+
touch events exist, and the page's meta viewport is honoured.
|
|
96
|
+
- `--device-scale-factor N` — the device pixel ratio, for example `3`.
|
|
97
|
+
- `--safe-area T,R,B,L` — `env(safe-area-inset-*)` in CSS pixels, for example
|
|
98
|
+
`62,0,34,0`. On iOS a page reads the insets only if its meta viewport sets
|
|
99
|
+
`viewport-fit=cover`; without it an iPhone 17 reports 0. Chromium applies
|
|
100
|
+
them either way, so check that your page sets it.
|
|
101
|
+
|
|
102
|
+
Flags given explicitly override the preset, so a phone turned sideways is
|
|
103
|
+
`--device iphone-17 --viewport 874x402 --safe-area 0,62,21,62`. Landscape
|
|
104
|
+
insets are not part of the presets. The engine stays Chromium, and the user
|
|
105
|
+
agent stays the desktop one, so pages that branch on the user-agent string
|
|
106
|
+
still take their desktop path.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
printf '%s\n' \
|
|
110
|
+
'open http://127.0.0.1:3000/app' \
|
|
111
|
+
'assert-eval matchMedia("(pointer: coarse)").matches' \
|
|
112
|
+
'screenshot phone.png' \
|
|
113
|
+
| prism browser --headless --fast --ephemeral-profile --local-only --device iphone-17 pipe
|
|
114
|
+
```
|
|
115
|
+
|
|
83
116
|
## Multiple pages
|
|
84
117
|
|
|
85
118
|
A popup (OAuth, payment, print preview) opens a new page. `pages` lists them,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prism-mcp-server",
|
|
3
|
-
"version": "20.21.
|
|
3
|
+
"version": "20.21.19",
|
|
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",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"prebuild": "npm run clean",
|
|
23
23
|
"build": "tsc && npm run chmod-bins",
|
|
24
24
|
"chmod-bins": "node -e \"['dist/cli.js','dist/server.js','dist/utils/universalImporter.js'].forEach(f => { try { require('fs').chmodSync(f, 0o755); } catch (e) { console.warn('chmod skipped', f, e.message); } })\"",
|
|
25
|
-
"prepublishOnly": "node scripts/check-no-private-content.mjs && node scripts/check-publish-clean.mjs && npm run build",
|
|
25
|
+
"prepublishOnly": "node scripts/check-no-private-content.mjs && node scripts/private-identifier-scan.mjs && node scripts/check-publish-clean.mjs && npm run build",
|
|
26
26
|
"lint:dashboard": "node scripts/lint-dashboard-es5.cjs",
|
|
27
27
|
"check:lockfile": "node scripts/check-lockfile-drift.mjs",
|
|
28
28
|
"start": "node dist/server.js",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"overrides": {
|
|
80
80
|
"@hono/node-server": "^2.0.5",
|
|
81
81
|
"body-parser": "^2.3.0",
|
|
82
|
-
"fast-uri": "^3.1.
|
|
82
|
+
"fast-uri": "^3.1.8",
|
|
83
83
|
"hono": "^4.13.5",
|
|
84
84
|
"ip-address": "^10.2.0",
|
|
85
85
|
"protobufjs": "^7.6.5",
|
package/scripts/dev/browse.py
CHANGED
|
@@ -68,6 +68,19 @@ AUDIT_LOG_PATH = BROWSER_DATA_DIR / "audit.log"
|
|
|
68
68
|
DEFAULT_PROFILE = "default"
|
|
69
69
|
DEFAULT_TIMEOUT = 30000
|
|
70
70
|
DEFAULT_VIEWPORT = (1440, 900)
|
|
71
|
+
# iOS devices in portrait as a full-screen WKWebView page sees them: CSS
|
|
72
|
+
# viewport, devicePixelRatio, and env(safe-area-inset-*) as (top, right,
|
|
73
|
+
# bottom, left). Measured 2026-10-03 on iOS 26.5 simulators, each running a
|
|
74
|
+
# full-screen WKWebView app whose page reported these values. Landscape was not
|
|
75
|
+
# measured: pass --viewport and --safe-area for it.
|
|
76
|
+
DEVICE_PRESETS: dict[str, dict] = {
|
|
77
|
+
'iphone-se': {'viewport': (375, 667), 'scale': 2.0, 'safe_area': (20, 0, 0, 0)},
|
|
78
|
+
'iphone-17': {'viewport': (402, 874), 'scale': 3.0, 'safe_area': (62, 0, 34, 0)},
|
|
79
|
+
'iphone-air': {'viewport': (420, 912), 'scale': 3.0, 'safe_area': (68, 0, 34, 0)},
|
|
80
|
+
'iphone-17-pro-max': {'viewport': (440, 956), 'scale': 3.0, 'safe_area': (62, 0, 34, 0)},
|
|
81
|
+
'ipad-a16': {'viewport': (820, 1180), 'scale': 2.0, 'safe_area': (32, 0, 20, 0)},
|
|
82
|
+
'ipad-pro-13': {'viewport': (1032, 1376), 'scale': 2.0, 'safe_area': (32, 0, 20, 0)},
|
|
83
|
+
}
|
|
71
84
|
REPL_IDLE_TIMEOUT = 600 # 10 minutes — auto-close to prevent zombie Chromium
|
|
72
85
|
PIPE_IDLE_TIMEOUT = 600 # stdin held open with no commands — same protection
|
|
73
86
|
MAX_INIT_SCRIPT_BYTES = 256 * 1024
|
|
@@ -796,7 +809,8 @@ class StealthBrowserSession:
|
|
|
796
809
|
allow_degraded_stealth=False, ephemeral_profile=False,
|
|
797
810
|
storage_state_path=None, trace_path=None, video_dir=None,
|
|
798
811
|
har_path=None, grant_permissions=None, geolocation=None,
|
|
799
|
-
allow_http_error=False
|
|
812
|
+
allow_http_error=False, touch=False, device_scale_factor=None,
|
|
813
|
+
safe_area=None):
|
|
800
814
|
self.profile = validate_profile_name(profile)
|
|
801
815
|
self.headless = headless
|
|
802
816
|
self.timeout = timeout
|
|
@@ -814,6 +828,9 @@ class StealthBrowserSession:
|
|
|
814
828
|
self.grant_permissions = list(grant_permissions or [])
|
|
815
829
|
self.geolocation = geolocation
|
|
816
830
|
self.allow_http_error = allow_http_error
|
|
831
|
+
self.touch = touch
|
|
832
|
+
self.device_scale_factor = device_scale_factor
|
|
833
|
+
self.safe_area = safe_area # (top, right, bottom, left) CSS px, or None
|
|
817
834
|
self.stealth_degraded: list[str] = []
|
|
818
835
|
self.fingerprint: dict = {}
|
|
819
836
|
self._fingerprint_reverified = False
|
|
@@ -895,6 +912,13 @@ class StealthBrowserSession:
|
|
|
895
912
|
'latitude': self.geolocation[0],
|
|
896
913
|
'longitude': self.geolocation[1],
|
|
897
914
|
}
|
|
915
|
+
if self.touch:
|
|
916
|
+
# A phone or tablet: (pointer: coarse) and (hover: none) match, touch
|
|
917
|
+
# events exist, and the page's meta viewport is honoured.
|
|
918
|
+
launch_kwargs['has_touch'] = True
|
|
919
|
+
launch_kwargs['is_mobile'] = True
|
|
920
|
+
if self.device_scale_factor:
|
|
921
|
+
launch_kwargs['device_scale_factor'] = self.device_scale_factor
|
|
898
922
|
if self.video_dir:
|
|
899
923
|
launch_kwargs['record_video_dir'] = str(self.video_dir)
|
|
900
924
|
if self.har_path:
|
|
@@ -950,7 +974,8 @@ class StealthBrowserSession:
|
|
|
950
974
|
audit_log(
|
|
951
975
|
"session_start", f"profile={self.profile}",
|
|
952
976
|
f"stealth={self.stealth_level},headless={self.headless},"
|
|
953
|
-
f"local_only={self.local_only},degraded={len(self.stealth_degraded)}"
|
|
977
|
+
f"local_only={self.local_only},degraded={len(self.stealth_degraded)},"
|
|
978
|
+
f"touch={self.touch},scale={self.device_scale_factor},safe_area={self.safe_area}",
|
|
954
979
|
)
|
|
955
980
|
|
|
956
981
|
def _on_new_page(self, page):
|
|
@@ -990,6 +1015,29 @@ class StealthBrowserSession:
|
|
|
990
1015
|
self.diagnostics.attach(page)
|
|
991
1016
|
if self.stealth_level != "none":
|
|
992
1017
|
self._apply_cdp_user_agent(page)
|
|
1018
|
+
# After the user-agent override, never before: Emulation.setUserAgentOverride
|
|
1019
|
+
# resets an earlier safe-area override on the same page, and env() then
|
|
1020
|
+
# reads 0 under --stealth full.
|
|
1021
|
+
if self.safe_area:
|
|
1022
|
+
self._apply_safe_area(page)
|
|
1023
|
+
|
|
1024
|
+
def _apply_safe_area(self, page):
|
|
1025
|
+
"""
|
|
1026
|
+
Set env(safe-area-inset-*), which Playwright cannot emulate. Chromium
|
|
1027
|
+
applies it whether or not the page sets viewport-fit=cover; iOS reports
|
|
1028
|
+
0 without it. A runtime without the override fails the run: a silent 0
|
|
1029
|
+
would test the wrong layout.
|
|
1030
|
+
"""
|
|
1031
|
+
top, right, bottom, left = self.safe_area
|
|
1032
|
+
try:
|
|
1033
|
+
self._context.new_cdp_session(page).send('Emulation.setSafeAreaInsetsOverride', {
|
|
1034
|
+
'insets': {'top': top, 'right': right, 'bottom': bottom, 'left': left},
|
|
1035
|
+
})
|
|
1036
|
+
except Exception as exc:
|
|
1037
|
+
raise RuntimeError(
|
|
1038
|
+
f"--safe-area could not be applied ({type(exc).__name__}: {exc}). "
|
|
1039
|
+
"It needs a Chromium with Emulation.setSafeAreaInsetsOverride."
|
|
1040
|
+
) from exc
|
|
993
1041
|
|
|
994
1042
|
def _apply_cdp_user_agent(self, page):
|
|
995
1043
|
"""
|
|
@@ -2309,7 +2357,15 @@ def build_parser():
|
|
|
2309
2357
|
help='Delete screenshots captured in this run on exit (see --help notes)')
|
|
2310
2358
|
p.add_argument('--sanitize', action='store_true', help='Mask PHI patterns in text output')
|
|
2311
2359
|
p.add_argument('--timeout', type=int, default=DEFAULT_TIMEOUT, help='Timeout (ms)')
|
|
2312
|
-
p.add_argument('--viewport', default=
|
|
2360
|
+
p.add_argument('--viewport', default=None, help='Viewport WxH (default 1440x900, or the --device size)')
|
|
2361
|
+
p.add_argument('--device', choices=sorted(DEVICE_PRESETS),
|
|
2362
|
+
help='Emulate a measured iPhone or iPad in portrait: size, pixel ratio, touch and safe area')
|
|
2363
|
+
p.add_argument('--touch', action='store_true',
|
|
2364
|
+
help='Emulate a touchscreen: (pointer: coarse), (hover: none), touch events, meta viewport')
|
|
2365
|
+
p.add_argument('--device-scale-factor', metavar='N', help='Device pixel ratio, for example 3')
|
|
2366
|
+
p.add_argument('--safe-area', metavar='T,R,B,L',
|
|
2367
|
+
help='env(safe-area-inset-*) in CSS pixels, for example 62,0,34,0; unlike iOS, '
|
|
2368
|
+
'applied even when the page omits viewport-fit=cover')
|
|
2313
2369
|
p.add_argument('--stealth', choices=['full', 'light', 'none'], default='full',
|
|
2314
2370
|
help='Fingerprint level: full (stealth lib + CDP + JS), light (CDP + JS), none')
|
|
2315
2371
|
p.add_argument('--allow-degraded-stealth', action='store_true',
|
|
@@ -2422,6 +2478,54 @@ def parse_viewport(value: str) -> tuple[int, int]:
|
|
|
2422
2478
|
return int(match.group(1)), int(match.group(2))
|
|
2423
2479
|
|
|
2424
2480
|
|
|
2481
|
+
def parse_safe_area(value: str) -> tuple[int, int, int, int]:
|
|
2482
|
+
"""Parse T,R,B,L insets in CSS pixels, failing loudly like --viewport."""
|
|
2483
|
+
match = re.fullmatch(r'\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*', value or '')
|
|
2484
|
+
if not match:
|
|
2485
|
+
raise ValueError(
|
|
2486
|
+
f"Invalid --safe-area {value!r}. Expected T,R,B,L in CSS pixels, for example 62,0,34,0."
|
|
2487
|
+
)
|
|
2488
|
+
return tuple(int(group) for group in match.groups())
|
|
2489
|
+
|
|
2490
|
+
|
|
2491
|
+
def parse_device_scale_factor(value: str) -> float:
|
|
2492
|
+
"""Parse a device pixel ratio, failing loudly on anything outside 0.5 to 5."""
|
|
2493
|
+
try:
|
|
2494
|
+
scale = float(value)
|
|
2495
|
+
except (TypeError, ValueError):
|
|
2496
|
+
scale = 0.0
|
|
2497
|
+
if not 0.5 <= scale <= 5:
|
|
2498
|
+
raise ValueError(f"Invalid --device-scale-factor {value!r}. Expected a number from 0.5 to 5, for example 3.")
|
|
2499
|
+
return scale
|
|
2500
|
+
|
|
2501
|
+
|
|
2502
|
+
def resolve_device_options(device, viewport, touch, scale, safe_area):
|
|
2503
|
+
"""
|
|
2504
|
+
Combine --device with the individual flags. The preset supplies defaults;
|
|
2505
|
+
any flag given explicitly wins, so --device iphone-17 --viewport 874x402
|
|
2506
|
+
is the same phone turned sideways (pass its landscape --safe-area too).
|
|
2507
|
+
"""
|
|
2508
|
+
# "Given" means not None: an empty value (an unset shell variable) must fail
|
|
2509
|
+
# loudly, not quietly fall back to a desktop default.
|
|
2510
|
+
preset = DEVICE_PRESETS.get(device) if device is not None else None
|
|
2511
|
+
if device is not None and preset is None:
|
|
2512
|
+
raise ValueError(f"Unknown --device {device!r}. Known: {', '.join(sorted(DEVICE_PRESETS))}.")
|
|
2513
|
+
if viewport is not None:
|
|
2514
|
+
size = parse_viewport(viewport)
|
|
2515
|
+
elif preset:
|
|
2516
|
+
size = tuple(preset['viewport'])
|
|
2517
|
+
else:
|
|
2518
|
+
size = DEFAULT_VIEWPORT
|
|
2519
|
+
return {
|
|
2520
|
+
'viewport': size,
|
|
2521
|
+
'touch': bool(touch or preset),
|
|
2522
|
+
'device_scale_factor': (parse_device_scale_factor(scale) if scale is not None
|
|
2523
|
+
else (preset['scale'] if preset else None)),
|
|
2524
|
+
'safe_area': (parse_safe_area(safe_area) if safe_area is not None
|
|
2525
|
+
else (tuple(preset['safe_area']) if preset else None)),
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
|
|
2425
2529
|
def parse_geolocation(value: str) -> tuple[float, float]:
|
|
2426
2530
|
parts = (value or '').split(',')
|
|
2427
2531
|
if len(parts) != 2:
|
|
@@ -2447,9 +2551,12 @@ def main():
|
|
|
2447
2551
|
return 1
|
|
2448
2552
|
|
|
2449
2553
|
try:
|
|
2450
|
-
|
|
2554
|
+
device = resolve_device_options(
|
|
2555
|
+
args.device, args.viewport, args.touch, args.device_scale_factor, args.safe_area,
|
|
2556
|
+
)
|
|
2451
2557
|
except ValueError as exc:
|
|
2452
2558
|
parser.error(str(exc))
|
|
2559
|
+
viewport = device['viewport']
|
|
2453
2560
|
|
|
2454
2561
|
geolocation = None
|
|
2455
2562
|
if args.geolocation:
|
|
@@ -2488,6 +2595,9 @@ def main():
|
|
|
2488
2595
|
grant_permissions=args.grant,
|
|
2489
2596
|
geolocation=geolocation,
|
|
2490
2597
|
allow_http_error=args.allow_http_error,
|
|
2598
|
+
touch=device['touch'],
|
|
2599
|
+
device_scale_factor=device['device_scale_factor'],
|
|
2600
|
+
safe_area=device['safe_area'],
|
|
2491
2601
|
)
|
|
2492
2602
|
except (ValueError, StealthConfigurationError) as exc:
|
|
2493
2603
|
print(json.dumps({"status": "error", "message": str(exc)}), file=sys.stderr)
|