@echomem/mcp 1.4.52 → 1.4.54
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 +16 -0
- package/dist/index.js +65 -18
- package/dist/setup-page/client-core.js +4 -0
- package/dist/setup-page/client-extraction.js +30 -5
- package/dist/setup-page/styles-mvp.js +19 -0
- package/dist/source-session-hook.js +95 -2
- package/dist/source-session.js +55 -3
- package/dist/v1-contract.js +27 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,6 +133,22 @@ Both hook entries are merged idempotently into `~/.codex/hooks.json` and
|
|
|
133
133
|
`~/.claude/settings.json`; unrelated user hooks and settings are preserved. Hooks fail open when
|
|
134
134
|
their local input is missing so they cannot prevent a conversation from starting or finishing.
|
|
135
135
|
|
|
136
|
+
### Cloud Cowork through `remote-devices`
|
|
137
|
+
|
|
138
|
+
Cloud Cowork inference cannot use the local hook or transcript-verification path. The shared local
|
|
139
|
+
MCP process also must not retain one cloud conversation as global bridge state. Cloud Cowork agents
|
|
140
|
+
therefore pass their runtime-issued `session_...` identifier as `cloudCoworkSessionId` on each
|
|
141
|
+
EchoMem tool call. EchoMem binds that request to the canonical `cowork:session_...` context with
|
|
142
|
+
`cloud_cowork_tool_argument` evidence and `local_mcp` origin, then links or saves against that
|
|
143
|
+
context without changing shared bridge state.
|
|
144
|
+
|
|
145
|
+
This identity is intentionally reported as **provisional**: the authenticated user owns the
|
|
146
|
+
context and ticket link, but EchoMem cannot independently corroborate the cloud identifier from a
|
|
147
|
+
local transcript. Verified local Cowork remains `cowork:local_...` with trusted local evidence.
|
|
148
|
+
Never convert one form into the other or silently present a provisional cloud link as verified.
|
|
149
|
+
`remote-devices` is a relay into the installed local MCP process; it is not EchoMem's hosted
|
|
150
|
+
Streamable HTTP MCP endpoint. Transport origin and session-identity evidence are independent.
|
|
151
|
+
|
|
136
152
|
### Manual / headless (SSH, containers, CI)
|
|
137
153
|
|
|
138
154
|
No browser? Provide secrets directly — this is the documented headless path:
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { MCP_PACKAGE_VERSION, MCP_SERVER_INSTRUCTIONS, MEMORY_CITATION_INSTRUCTI
|
|
|
16
16
|
import { clearBillingAlert, writeBillingAlert } from "./billing-alert.js";
|
|
17
17
|
import { checkLatestUpdateStatus, formatUpdateNotice, formatUpdateStatusText, startBackgroundUpdateCheck, } from "./update-check.js";
|
|
18
18
|
import { autoUpdateHeadlessRuntime } from "./headless-runtime.js";
|
|
19
|
-
import { resolveSourceSessionRequestContext, resolveSourceSessionFromBindingToken, } from "./source-session.js";
|
|
19
|
+
import { SOURCE_SESSION_CLOUD_TOOL_ARGUMENT_EVIDENCE, resolveCloudCoworkSessionFromToolArguments, resolveSourceSessionRequestContext, resolveSourceSessionFromBindingToken, } from "./source-session.js";
|
|
20
20
|
const ECHO_API_BASE_URL = process.env.ECHO_API_BASE_URL || "https://echo-mem-chrome.vercel.app";
|
|
21
21
|
const ECHO_PRICING_URL = process.env.ECHO_PRICING_URL || "https://echoknows.com/account";
|
|
22
22
|
const ECHO_MEMORY_WEB_URL = (process.env.ECHO_MEMORY_WEB_URL || "https://echoknows.com/memory").replace(/\/$/, "");
|
|
@@ -711,7 +711,7 @@ class EchoMemApiClient {
|
|
|
711
711
|
const requestContext = this.requestContext.getStore();
|
|
712
712
|
return requestContext === undefined ? this.boundSourceSession : requestContext.sourceSession;
|
|
713
713
|
}
|
|
714
|
-
|
|
714
|
+
getRequestSourceSession() {
|
|
715
715
|
const requestContext = this.requestContext.getStore();
|
|
716
716
|
if (!requestContext || requestContext.lineageStatus === "unbound")
|
|
717
717
|
return null;
|
|
@@ -723,26 +723,42 @@ class EchoMemApiClient {
|
|
|
723
723
|
async withRequestContext(requestContext, operation) {
|
|
724
724
|
return this.requestContext.run(requestContext, operation);
|
|
725
725
|
}
|
|
726
|
-
async bindSourceSession(
|
|
726
|
+
async bindSourceSession(identity, persistForBridge = true) {
|
|
727
727
|
this.synchronizeAccountContext();
|
|
728
|
-
|
|
728
|
+
if (identity.evidence === SOURCE_SESSION_CLOUD_TOOL_ARGUMENT_EVIDENCE && persistForBridge) {
|
|
729
|
+
throw new Error("A provisional Cloud Cowork identity cannot become shared bridge state");
|
|
730
|
+
}
|
|
731
|
+
const cached = this.sourceSessionsByCanonicalKey.get(identity.canonicalKey);
|
|
729
732
|
if (cached) {
|
|
730
733
|
if (persistForBridge)
|
|
731
734
|
this.boundSourceSession = cached;
|
|
732
735
|
return { ...cached, created: false };
|
|
733
736
|
}
|
|
734
737
|
const response = await this.axios.post("/api/extension/source-sessions/bind", {
|
|
735
|
-
provider:
|
|
736
|
-
providerSessionId:
|
|
737
|
-
|
|
738
|
-
|
|
738
|
+
provider: identity.provider,
|
|
739
|
+
providerSessionId: identity.providerSessionId,
|
|
740
|
+
providerSessionAliases: identity.providerSessionAliases,
|
|
741
|
+
evidence: identity.evidence,
|
|
742
|
+
}, { headers: { "X-EchoMem-Origin-Channel": "local_mcp" } });
|
|
739
743
|
const contextId = readString(response.data, "contextId");
|
|
740
744
|
const canonicalKey = readString(response.data, "canonicalKey");
|
|
741
|
-
|
|
745
|
+
const provider = readString(response.data, "provider");
|
|
746
|
+
const providerSessionId = readString(response.data, "providerSessionId");
|
|
747
|
+
if (response.data?.success !== true
|
|
748
|
+
|| !contextId
|
|
749
|
+
|| provider !== identity.provider
|
|
750
|
+
|| !providerSessionId
|
|
751
|
+
|| canonicalKey !== `${provider}:${providerSessionId}`) {
|
|
742
752
|
throw new Error("EchoMem returned an invalid source-session binding receipt");
|
|
743
753
|
}
|
|
744
|
-
const bound = {
|
|
745
|
-
|
|
754
|
+
const bound = {
|
|
755
|
+
...identity,
|
|
756
|
+
providerSessionId,
|
|
757
|
+
canonicalKey,
|
|
758
|
+
contextId,
|
|
759
|
+
};
|
|
760
|
+
this.sourceSessionsByCanonicalKey.set(identity.canonicalKey, bound);
|
|
761
|
+
this.sourceSessionsByCanonicalKey.set(canonicalKey, bound);
|
|
746
762
|
if (this.sourceSessionsByCanonicalKey.size > 64) {
|
|
747
763
|
const oldestKey = this.sourceSessionsByCanonicalKey.keys().next().value;
|
|
748
764
|
if (oldestKey)
|
|
@@ -759,9 +775,10 @@ class EchoMemApiClient {
|
|
|
759
775
|
const parsed = linkWorkspaceTicketSessionSchema.parse(args ?? {});
|
|
760
776
|
// A bridge-level compatibility binding can outlive a conversation in
|
|
761
777
|
// long-running hosts. Ticket links are therefore allowed to take the fast
|
|
762
|
-
// path only from identity
|
|
763
|
-
//
|
|
764
|
-
|
|
778
|
+
// path only from identity scoped to this exact request. That identity is
|
|
779
|
+
// either verified host metadata or an explicitly marked provisional Cloud
|
|
780
|
+
// Cowork claim; otherwise Desktop completes the link from local evidence.
|
|
781
|
+
const sourceSession = this.getRequestSourceSession();
|
|
765
782
|
if (!sourceSession)
|
|
766
783
|
return null;
|
|
767
784
|
const response = await this.axios.post(`/api/extension/workspace-tickets/${encodeURIComponent(parsed.ticketId)}/sessions`, {
|
|
@@ -1040,9 +1057,13 @@ class EchoMemApiClient {
|
|
|
1040
1057
|
// For an encrypted account, hand the server the key transiently in the X-Encryption-Key header
|
|
1041
1058
|
// so it encrypts at rest (mirrors the extension's write path, spec §3.1a). Locked → LockedError.
|
|
1042
1059
|
const enc = await this.encState();
|
|
1060
|
+
const boundSourceSession = this.getBoundSourceSession();
|
|
1043
1061
|
const config = {
|
|
1044
1062
|
headers: {
|
|
1045
1063
|
"X-EchoMem-Request-Id": randomUUID(),
|
|
1064
|
+
// This package is the installed local MCP bridge. A Cloud Cowork
|
|
1065
|
+
// session can reach it through remote-devices, but its provisional
|
|
1066
|
+
// identity evidence does not change the bridge's transport channel.
|
|
1046
1067
|
"X-EchoMem-Origin-Channel": "local_mcp",
|
|
1047
1068
|
...(enc.enabled && enc.key ? { "X-Encryption-Key": enc.key } : {}),
|
|
1048
1069
|
},
|
|
@@ -1053,9 +1074,10 @@ class EchoMemApiClient {
|
|
|
1053
1074
|
sourceUrl: parsed.url,
|
|
1054
1075
|
source: parsed.source || "mcp_server",
|
|
1055
1076
|
title: parsed.title,
|
|
1056
|
-
// A
|
|
1077
|
+
// A source-session identity owns the memory context. Provisional Cloud Cowork identity
|
|
1078
|
+
// is explicitly marked by its evidence. The independent opaque scope still
|
|
1057
1079
|
// governs group-sharing consent and never becomes the source-session identity.
|
|
1058
|
-
conversationKey:
|
|
1080
|
+
conversationKey: boundSourceSession?.canonicalKey ?? groupSharingScopeId,
|
|
1059
1081
|
groupSharingScopeId,
|
|
1060
1082
|
passthrough: parsed.passthrough || false,
|
|
1061
1083
|
triggerMessage: parsed.triggerMessage ||
|
|
@@ -1502,6 +1524,23 @@ class EchoMemMCPServer {
|
|
|
1502
1524
|
catch {
|
|
1503
1525
|
// Malformed host metadata is not model input. Ignore it and retain the explicit fallback.
|
|
1504
1526
|
}
|
|
1527
|
+
let provisionalCloudSession = null;
|
|
1528
|
+
try {
|
|
1529
|
+
provisionalCloudSession = resolveCloudCoworkSessionFromToolArguments(toolArgs);
|
|
1530
|
+
}
|
|
1531
|
+
catch (error) {
|
|
1532
|
+
throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : "Invalid Cloud Cowork session identity");
|
|
1533
|
+
}
|
|
1534
|
+
if (provisionalCloudSession && sourceResolution.sourceSession) {
|
|
1535
|
+
throw new McpError(ErrorCode.InvalidParams, "This request already has a verified local source session. Omit cloudCoworkSessionId rather than mixing identities.");
|
|
1536
|
+
}
|
|
1537
|
+
if (provisionalCloudSession) {
|
|
1538
|
+
sourceResolution = {
|
|
1539
|
+
sourceSession: provisionalCloudSession,
|
|
1540
|
+
isSubagent: false,
|
|
1541
|
+
lineageStatus: "not_applicable",
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1505
1544
|
// A child request starts fail-closed. Resolved children bind to the originating root; unresolved
|
|
1506
1545
|
// children carry an explicit null so AsyncLocalStorage cannot fall through to a global binding.
|
|
1507
1546
|
let requestSourceSession = sourceResolution.isSubagent
|
|
@@ -2052,17 +2091,25 @@ Details: ${m.details || "N/A"}`)
|
|
|
2052
2091
|
const ticket = isRecord(result.ticket) ? result.ticket : {};
|
|
2053
2092
|
const workspaceId = readString(ticket, "workspaceId") ?? parsed.workspaceId;
|
|
2054
2093
|
const sourceSession = this.client.getBoundSourceSession();
|
|
2094
|
+
const provisional = sourceSession?.evidence === SOURCE_SESSION_CLOUD_TOOL_ARGUMENT_EVIDENCE;
|
|
2055
2095
|
return {
|
|
2056
2096
|
content: [{
|
|
2057
2097
|
type: "text",
|
|
2058
2098
|
text: [
|
|
2059
2099
|
result.changed === true
|
|
2060
|
-
?
|
|
2061
|
-
|
|
2100
|
+
? provisional
|
|
2101
|
+
? "Linked this provisional Cloud Cowork session to the Echo workspace ticket."
|
|
2102
|
+
: "Linked this verified source session to the Echo workspace ticket."
|
|
2103
|
+
: provisional
|
|
2104
|
+
? "This provisional Cloud Cowork session was already linked to the Echo workspace ticket."
|
|
2105
|
+
: "This verified source session was already linked to the Echo workspace ticket.",
|
|
2062
2106
|
`Ticket: ${parsed.ticketId}`,
|
|
2063
2107
|
workspaceId ? `Workspace: ${workspaceId}` : "",
|
|
2064
2108
|
sourceSession ? `Source session: ${sourceSession.canonicalKey}` : "",
|
|
2065
2109
|
sourceSession ? `Context: ${sourceSession.contextId}` : "",
|
|
2110
|
+
provisional
|
|
2111
|
+
? "Identity trust: provisional (reported by Cloud Cowork in the tool call; not verified by a local transcript). Repeat cloudCoworkSessionId on later EchoMem calls from this conversation."
|
|
2112
|
+
: "",
|
|
2066
2113
|
"Retries are safe and do not create duplicate links or history events.",
|
|
2067
2114
|
].filter(Boolean).join("\n"),
|
|
2068
2115
|
}],
|
|
@@ -53,11 +53,15 @@ export const SETUP_PAGE_CLIENT_CORE = String.raw ` var params = new URLSear
|
|
|
53
53
|
var accountStateEpoch = 0;
|
|
54
54
|
var statsPollStarted = false;
|
|
55
55
|
var readyStage = "";
|
|
56
|
+
// Apply the automatic Free fallback only once per connected-account lifecycle. After the
|
|
57
|
+
// user deliberately reopens plan selection, background billing refreshes must not close it.
|
|
58
|
+
var freePlanFallbackApplied = false;
|
|
56
59
|
|
|
57
60
|
try {
|
|
58
61
|
var storedSetupPlanChoice = sessionStorage.getItem("echomem:setup-plan:" + nonce) || "";
|
|
59
62
|
if (storedSetupPlanChoice === "free" || storedSetupPlanChoice === "pro" || storedSetupPlanChoice === "power") {
|
|
60
63
|
setupPlanChoice = storedSetupPlanChoice;
|
|
64
|
+
freePlanFallbackApplied = true;
|
|
61
65
|
}
|
|
62
66
|
var storedCheckoutSessionId = sessionStorage.getItem("echomem:checkout-session:" + nonce) || "";
|
|
63
67
|
if (/^cs_(?:test_|live_)?[A-Za-z0-9_]+$/.test(storedCheckoutSessionId)) {
|
|
@@ -99,9 +99,12 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
99
99
|
'<section class="planGateDecision">' +
|
|
100
100
|
'<div class="setupPlanSlot" id="setupPlan"></div>' +
|
|
101
101
|
'<aside class="planGateAccount" aria-label="Connected account"><div class="setupAccountSlot" id="setupAccount"></div></aside>' +
|
|
102
|
-
'</section>'
|
|
102
|
+
'</section>' +
|
|
103
|
+
'<div class="planGateSkip"><button type="button" class="textButton skipHistoryButton" id="skipPlanSelection">Continue without importing</button><p>You can import your local history later.</p></div>';
|
|
103
104
|
renderSetupPlan(true);
|
|
104
105
|
renderAccountChoice();
|
|
106
|
+
var skipPlan = document.getElementById("skipPlanSelection");
|
|
107
|
+
if (skipPlan) skipPlan.onclick = skip;
|
|
105
108
|
}
|
|
106
109
|
function renderDashboard(error) {
|
|
107
110
|
setExtractMode(false);
|
|
@@ -128,7 +131,7 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
128
131
|
var pendingCodex = typeof migratable.pendingCodex === "number" ? migratable.pendingCodex : null;
|
|
129
132
|
var pendingClaudeCode = typeof migratable.pendingClaudeCode === "number" ? migratable.pendingClaudeCode : null;
|
|
130
133
|
var pendingCowork = typeof migratable.pendingCowork === "number" ? migratable.pendingCowork : null;
|
|
131
|
-
if (connected && !
|
|
134
|
+
if (connected && !setupPlanConfirmed()) {
|
|
132
135
|
renderPlanGate();
|
|
133
136
|
return;
|
|
134
137
|
}
|
|
@@ -191,12 +194,14 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
191
194
|
'<div class="readyGo">' +
|
|
192
195
|
'<div class="actions">' +
|
|
193
196
|
'<button id="migrate" class="primary"></button>' +
|
|
197
|
+
'<button type="button" id="skipImport" class="skipHistoryButton">Continue without importing</button>' +
|
|
194
198
|
'</div>' +
|
|
195
199
|
'<p class="ctaMeta" id="exEta"></p>' +
|
|
196
200
|
'</div>' +
|
|
197
201
|
'</section>' +
|
|
198
202
|
'<dialog class="sessionPicker" id="sessionPicker" aria-labelledby="sessionPickerTitle"></dialog>';
|
|
199
203
|
document.getElementById("migrate").onclick = openSessionPicker;
|
|
204
|
+
document.getElementById("skipImport").onclick = skip;
|
|
200
205
|
dashMounted = true;
|
|
201
206
|
}
|
|
202
207
|
document.getElementById("exBanner").innerHTML =
|
|
@@ -239,6 +244,8 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
239
244
|
// While still counting, hide the primary button entirely; the headline + source split
|
|
240
245
|
// already say it is working, and the ready state should present one clear action.
|
|
241
246
|
var migrateBtn = document.getElementById("migrate");
|
|
247
|
+
var skipImportBtn = document.getElementById("skipImport");
|
|
248
|
+
if (skipImportBtn) skipImportBtn.style.display = canExtract ? "" : "none";
|
|
242
249
|
if (pendingTrusted || degradedWithoutCounts) {
|
|
243
250
|
migrateBtn.style.display = "";
|
|
244
251
|
var candidatesReady = !canExtract || candidateSessions().length > 0;
|
|
@@ -968,6 +975,7 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
968
975
|
billingStatus = null;
|
|
969
976
|
billingStatusLoading = false;
|
|
970
977
|
connected = false;
|
|
978
|
+
freePlanFallbackApplied = false;
|
|
971
979
|
rememberSetupPlanChoice("");
|
|
972
980
|
selectedSessionKeys = Object.create(null);
|
|
973
981
|
sessionSelectionTouched = false;
|
|
@@ -1098,6 +1106,16 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
1098
1106
|
function setupPlanConfirmed() {
|
|
1099
1107
|
return setupPlanChoice === "free" || paidRecallPlan(billingStatus && billingStatus.plan);
|
|
1100
1108
|
}
|
|
1109
|
+
function paidCheckoutPending() {
|
|
1110
|
+
return paidRecallPlan(billingActivationPendingPlan) ||
|
|
1111
|
+
(!!pendingCheckoutSessionId && paidRecallPlan(setupPlanChoice));
|
|
1112
|
+
}
|
|
1113
|
+
function applyFreePlanFallback() {
|
|
1114
|
+
if (freePlanFallbackApplied || setupPlanConfirmed() || paidCheckoutPending()) return false;
|
|
1115
|
+
freePlanFallbackApplied = true;
|
|
1116
|
+
rememberSetupPlanChoice("free");
|
|
1117
|
+
return true;
|
|
1118
|
+
}
|
|
1101
1119
|
function setupPlanDefinition(plan) {
|
|
1102
1120
|
var trialAvailable = !billingStatus || billingStatus.trialAvailable !== false;
|
|
1103
1121
|
var limits = quotaLimitsForPlan(plan);
|
|
@@ -1197,16 +1215,19 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
1197
1215
|
});
|
|
1198
1216
|
var free = document.getElementById("chooseFreePlan");
|
|
1199
1217
|
if (free) free.onclick = function () {
|
|
1218
|
+
freePlanFallbackApplied = true;
|
|
1200
1219
|
rememberSetupPlanChoice("free");
|
|
1201
1220
|
renderDashboard();
|
|
1202
1221
|
};
|
|
1203
1222
|
var pro = document.getElementById("chooseProPlan");
|
|
1204
1223
|
if (pro) pro.onclick = function () {
|
|
1224
|
+
freePlanFallbackApplied = true;
|
|
1205
1225
|
rememberSetupPlanChoice("pro");
|
|
1206
1226
|
openPaidPricing("pro");
|
|
1207
1227
|
};
|
|
1208
1228
|
var power = document.getElementById("choosePowerPlan");
|
|
1209
1229
|
if (power) power.onclick = function () {
|
|
1230
|
+
freePlanFallbackApplied = true;
|
|
1210
1231
|
rememberSetupPlanChoice("power");
|
|
1211
1232
|
openPaidPricing("power");
|
|
1212
1233
|
};
|
|
@@ -1372,13 +1393,15 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
1372
1393
|
var nextBillingStatus = await getJson("/billing-status");
|
|
1373
1394
|
if (billingEpoch !== accountStateEpoch || !connected) return;
|
|
1374
1395
|
billingStatus = nextBillingStatus;
|
|
1396
|
+
if (!paidRecallPlan(billingStatus && billingStatus.plan)) applyFreePlanFallback();
|
|
1375
1397
|
await refreshPlanQuotaCatalog();
|
|
1376
1398
|
billingLastCheckedAt = Date.now();
|
|
1377
1399
|
billingCheckMessage = "";
|
|
1378
|
-
if (
|
|
1400
|
+
if (stats && setupPlanConfirmed()) {
|
|
1379
1401
|
// Keep the visible promise in sync with the authoritative plan/quota response.
|
|
1380
|
-
//
|
|
1381
|
-
//
|
|
1402
|
+
// This also replaces the plan gate after the initial billing lookup. If the dashboard
|
|
1403
|
+
// is already mounted, renderDashboard patches it in place; an open picker is refreshed
|
|
1404
|
+
// after an upgrade so its quota and action stay authoritative.
|
|
1382
1405
|
renderDashboard();
|
|
1383
1406
|
var openPicker = document.getElementById("sessionPicker");
|
|
1384
1407
|
if (openPicker && openPicker.open) renderSessionPicker();
|
|
@@ -1392,6 +1415,8 @@ export const SETUP_PAGE_CLIENT_EXTRACTION = String.raw ` /* ---------- dash
|
|
|
1392
1415
|
if (billingEpoch !== accountStateEpoch || !connected) return;
|
|
1393
1416
|
billingLastCheckedAt = Date.now();
|
|
1394
1417
|
billingCheckMessage = "Could not check payment yet. Echo will keep trying automatically.";
|
|
1418
|
+
var fellBackToFree = applyFreePlanFallback();
|
|
1419
|
+
if (fellBackToFree && stats) renderDashboard();
|
|
1395
1420
|
setSetupPlanStatus("Plan check unavailable. Original still works.");
|
|
1396
1421
|
} finally {
|
|
1397
1422
|
if (billingEpoch === accountStateEpoch) billingStatusLoading = false;
|
|
@@ -570,6 +570,25 @@ export const SETUP_PAGE_STYLES_MVP = String.raw `
|
|
|
570
570
|
font-size: 11px;
|
|
571
571
|
font-weight: 700;
|
|
572
572
|
}
|
|
573
|
+
.planGateSkip {
|
|
574
|
+
display: grid;
|
|
575
|
+
justify-items: center;
|
|
576
|
+
gap: 2px;
|
|
577
|
+
margin-top: 14px;
|
|
578
|
+
text-align: center;
|
|
579
|
+
}
|
|
580
|
+
.planGateSkip .skipHistoryButton {
|
|
581
|
+
min-height: 36px;
|
|
582
|
+
border: 0;
|
|
583
|
+
background: transparent;
|
|
584
|
+
color: var(--echo-ink-mute);
|
|
585
|
+
box-shadow: none;
|
|
586
|
+
}
|
|
587
|
+
.planGateSkip p {
|
|
588
|
+
margin: 0;
|
|
589
|
+
color: var(--echo-ink-faint);
|
|
590
|
+
font-size: 11px;
|
|
591
|
+
}
|
|
573
592
|
.mvpPricing {
|
|
574
593
|
width: 100%;
|
|
575
594
|
}
|
|
@@ -2,9 +2,12 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import axios from "axios";
|
|
4
4
|
import { KeyStore } from "./keystore.js";
|
|
5
|
-
import { SOURCE_SESSION_HOOK_EVIDENCE, verifiedSourceSession, } from "./source-session.js";
|
|
5
|
+
import { SOURCE_SESSION_HOOK_EVIDENCE, verifiedClaudeDesktopSession, verifiedSourceSession, } from "./source-session.js";
|
|
6
6
|
const API_BASE = (process.env.ECHO_API_BASE_URL || "https://echo-mem-chrome.vercel.app").replace(/\/$/, "");
|
|
7
7
|
const MAX_HEAD_BYTES = 256 * 1024;
|
|
8
|
+
const MAX_CLAUDE_DESKTOP_INDEX_FILES = 2_000;
|
|
9
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
10
|
+
const CLAUDE_DESKTOP_ID_RE = /^local_[A-Za-z0-9_-]{1,194}$/;
|
|
8
11
|
function isRecord(value) {
|
|
9
12
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
13
|
}
|
|
@@ -43,6 +46,88 @@ function codexSessionFromTranscript(file) {
|
|
|
43
46
|
function coworkSessionFromPath(file) {
|
|
44
47
|
return file.split(path.sep).find((part) => /^local_[A-Za-z0-9_-]{1,194}$/.test(part)) ?? null;
|
|
45
48
|
}
|
|
49
|
+
function claudeDesktopSessionsRoot() {
|
|
50
|
+
const support = process.env.CLAUDE_DESKTOP_SUPPORT_DIR?.trim()
|
|
51
|
+
|| path.join(process.env.HOME || "", "Library", "Application Support", "Claude");
|
|
52
|
+
return path.join(support, "claude-code-sessions");
|
|
53
|
+
}
|
|
54
|
+
function readClaudeDesktopClaim(file) {
|
|
55
|
+
try {
|
|
56
|
+
const stat = fs.statSync(file);
|
|
57
|
+
if (!stat.isFile() || stat.size > MAX_HEAD_BYTES)
|
|
58
|
+
return null;
|
|
59
|
+
const row = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
60
|
+
if (!isRecord(row) || row.isArchived === true)
|
|
61
|
+
return null;
|
|
62
|
+
const desktopSessionId = typeof row.sessionId === "string" ? row.sessionId.trim() : "";
|
|
63
|
+
const currentCliSessionId = typeof row.cliSessionId === "string"
|
|
64
|
+
? row.cliSessionId.trim().toLowerCase()
|
|
65
|
+
: "";
|
|
66
|
+
if (!CLAUDE_DESKTOP_ID_RE.test(desktopSessionId) || !UUID_RE.test(currentCliSessionId)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const prior = Array.isArray(row.priorCliSessionIds)
|
|
70
|
+
? row.priorCliSessionIds
|
|
71
|
+
.filter((value) => typeof value === "string")
|
|
72
|
+
.map((value) => value.trim().toLowerCase())
|
|
73
|
+
.filter((value) => UUID_RE.test(value))
|
|
74
|
+
: [];
|
|
75
|
+
const focusedAt = typeof row.lastFocusedAt === "number"
|
|
76
|
+
? row.lastFocusedAt
|
|
77
|
+
: typeof row.lastActivityAt === "number"
|
|
78
|
+
? row.lastActivityAt
|
|
79
|
+
: typeof row.createdAt === "number"
|
|
80
|
+
? row.createdAt
|
|
81
|
+
: 0;
|
|
82
|
+
return {
|
|
83
|
+
desktopSessionId,
|
|
84
|
+
cliSessionIds: [...new Set([currentCliSessionId, ...prior])].slice(0, 32),
|
|
85
|
+
selfNamed: desktopSessionId === `local_${currentCliSessionId}`,
|
|
86
|
+
focusedAt,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function claudeDesktopSessionForCliId(cliSessionId) {
|
|
94
|
+
const root = claudeDesktopSessionsRoot();
|
|
95
|
+
const pending = [root];
|
|
96
|
+
let inspected = 0;
|
|
97
|
+
let best = null;
|
|
98
|
+
while (pending.length > 0 && inspected < MAX_CLAUDE_DESKTOP_INDEX_FILES) {
|
|
99
|
+
const directory = pending.pop();
|
|
100
|
+
if (!directory)
|
|
101
|
+
break;
|
|
102
|
+
let entries;
|
|
103
|
+
try {
|
|
104
|
+
entries = fs.readdirSync(directory, { withFileTypes: true });
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
const item = path.join(directory, entry.name);
|
|
111
|
+
if (entry.isDirectory()) {
|
|
112
|
+
pending.push(item);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!entry.isFile() || !entry.name.startsWith("local_") || !entry.name.endsWith(".json")) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
inspected += 1;
|
|
119
|
+
const claim = readClaudeDesktopClaim(item);
|
|
120
|
+
if (!claim || !claim.cliSessionIds.includes(cliSessionId))
|
|
121
|
+
continue;
|
|
122
|
+
if (!best
|
|
123
|
+
|| (best.selfNamed && !claim.selfNamed)
|
|
124
|
+
|| (best.selfNamed === claim.selfNamed && claim.focusedAt > best.focusedAt)) {
|
|
125
|
+
best = claim;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return best ? verifiedClaudeDesktopSession(best.desktopSessionId, best.cliSessionIds) : null;
|
|
130
|
+
}
|
|
46
131
|
export function resolveSourceSessionFromHookPayload(payload) {
|
|
47
132
|
const requestedSessionId = typeof payload.session_id === "string" ? payload.session_id.trim() : "";
|
|
48
133
|
const transcriptPath = typeof payload.transcript_path === "string" ? payload.transcript_path.trim() : "";
|
|
@@ -71,6 +156,9 @@ export function resolveSourceSessionFromHookPayload(payload) {
|
|
|
71
156
|
const filenameSession = path.basename(file, path.extname(file));
|
|
72
157
|
if (filenameSession !== requestedSessionId)
|
|
73
158
|
return null;
|
|
159
|
+
const desktopSession = claudeDesktopSessionForCliId(filenameSession.toLowerCase());
|
|
160
|
+
if (desktopSession)
|
|
161
|
+
return desktopSession;
|
|
74
162
|
return verifiedSourceSession("claude-code", filenameSession, SOURCE_SESSION_HOOK_EVIDENCE);
|
|
75
163
|
}
|
|
76
164
|
async function bindSourceSession(identity) {
|
|
@@ -80,9 +168,14 @@ async function bindSourceSession(identity) {
|
|
|
80
168
|
await axios.post(`${API_BASE}/api/extension/source-sessions/bind`, {
|
|
81
169
|
provider: identity.provider,
|
|
82
170
|
providerSessionId: identity.providerSessionId,
|
|
171
|
+
providerSessionAliases: identity.providerSessionAliases,
|
|
83
172
|
evidence: identity.evidence,
|
|
84
173
|
}, {
|
|
85
|
-
headers: {
|
|
174
|
+
headers: {
|
|
175
|
+
Authorization: `Bearer ${token}`,
|
|
176
|
+
"Content-Type": "application/json",
|
|
177
|
+
"X-EchoMem-Origin-Channel": "local_mcp",
|
|
178
|
+
},
|
|
86
179
|
timeout: 3_500,
|
|
87
180
|
});
|
|
88
181
|
}
|
package/dist/source-session.js
CHANGED
|
@@ -4,6 +4,8 @@ import { resolveClaudeCoworkSessionsDir, resolveClaudeProjectsDir, resolveCodexS
|
|
|
4
4
|
export const SOURCE_SESSION_BINDING_EVIDENCE = "local_jsonl_tool_call";
|
|
5
5
|
export const SOURCE_SESSION_HOOK_EVIDENCE = "local_session_start_hook";
|
|
6
6
|
export const SOURCE_SESSION_MCP_METADATA_EVIDENCE = "local_mcp_session_metadata";
|
|
7
|
+
export const SOURCE_SESSION_CLOUD_TOOL_ARGUMENT_EVIDENCE = "cloud_cowork_tool_argument";
|
|
8
|
+
export const SOURCE_SESSION_DESKTOP_INDEX_EVIDENCE = "echo_desktop_conversation_index";
|
|
7
9
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
10
|
const UUID_IN_TEXT_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
|
9
11
|
const MAX_TAIL_BYTES = 512 * 1024;
|
|
@@ -20,13 +22,18 @@ function normalizedProviderSessionId(provider, value) {
|
|
|
20
22
|
if (provider === "codex" && !UUID_RE.test(normalized)) {
|
|
21
23
|
throw new Error("Codex source-session ID must be a UUID");
|
|
22
24
|
}
|
|
23
|
-
if (provider === "cowork"
|
|
24
|
-
|
|
25
|
+
if (provider === "cowork"
|
|
26
|
+
&& !/^local_[A-Za-z0-9_-]{1,194}$/.test(normalized)
|
|
27
|
+
&& !/^session_[A-Za-z0-9_-]{1,192}$/.test(normalized)) {
|
|
28
|
+
throw new Error("Cowork source-session ID must use a local_ host ID or session_ Cloud Cowork ID");
|
|
25
29
|
}
|
|
26
30
|
return UUID_RE.test(normalized) ? normalized.toLowerCase() : normalized;
|
|
27
31
|
}
|
|
28
32
|
export function verifiedSourceSession(provider, providerSessionId, evidence) {
|
|
29
33
|
const normalized = normalizedProviderSessionId(provider, providerSessionId);
|
|
34
|
+
if (provider === "cowork" && !normalized.startsWith("local_")) {
|
|
35
|
+
throw new Error("Verified Cowork source-session ID must use the local_ host identifier");
|
|
36
|
+
}
|
|
30
37
|
return {
|
|
31
38
|
provider,
|
|
32
39
|
providerSessionId: normalized,
|
|
@@ -34,6 +41,48 @@ export function verifiedSourceSession(provider, providerSessionId, evidence) {
|
|
|
34
41
|
evidence,
|
|
35
42
|
};
|
|
36
43
|
}
|
|
44
|
+
export function verifiedClaudeDesktopSession(providerSessionId, providerSessionAliases) {
|
|
45
|
+
const normalized = normalizedProviderSessionId("claude-code", providerSessionId);
|
|
46
|
+
if (!/^local_[A-Za-z0-9_-]{1,194}$/.test(normalized)) {
|
|
47
|
+
throw new Error("Claude Desktop source-session ID must use its durable local_ conversation identifier");
|
|
48
|
+
}
|
|
49
|
+
if (providerSessionAliases.length === 0 || providerSessionAliases.length > 32) {
|
|
50
|
+
throw new Error("Claude Desktop source-session identity requires 1-32 CLI session aliases");
|
|
51
|
+
}
|
|
52
|
+
const aliases = [...new Set(providerSessionAliases.map((value) => {
|
|
53
|
+
const alias = normalizedProviderSessionId("claude-code", value);
|
|
54
|
+
if (!UUID_RE.test(alias))
|
|
55
|
+
throw new Error("Claude Desktop CLI session aliases must be UUIDs");
|
|
56
|
+
return alias;
|
|
57
|
+
}))].sort();
|
|
58
|
+
return {
|
|
59
|
+
provider: "claude-code",
|
|
60
|
+
providerSessionId: normalized,
|
|
61
|
+
providerSessionAliases: aliases,
|
|
62
|
+
canonicalKey: `claude-code:${normalized}`,
|
|
63
|
+
evidence: SOURCE_SESSION_DESKTOP_INDEX_EVIDENCE,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function provisionalCloudCoworkSession(providerSessionId) {
|
|
67
|
+
const normalized = normalizedProviderSessionId("cowork", providerSessionId);
|
|
68
|
+
if (!normalized.startsWith("session_")) {
|
|
69
|
+
throw new Error("Cloud Cowork source-session ID must use the session_ identifier from the cloud runtime");
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
provider: "cowork",
|
|
73
|
+
providerSessionId: normalized,
|
|
74
|
+
canonicalKey: `cowork:${normalized}`,
|
|
75
|
+
evidence: SOURCE_SESSION_CLOUD_TOOL_ARGUMENT_EVIDENCE,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function resolveCloudCoworkSessionFromToolArguments(args) {
|
|
79
|
+
if (!isRecord(args) || args.cloudCoworkSessionId === undefined)
|
|
80
|
+
return null;
|
|
81
|
+
if (typeof args.cloudCoworkSessionId !== "string") {
|
|
82
|
+
throw new Error("cloudCoworkSessionId must be the current Cloud Cowork session_ identifier");
|
|
83
|
+
}
|
|
84
|
+
return provisionalCloudCoworkSession(args.cloudCoworkSessionId);
|
|
85
|
+
}
|
|
37
86
|
function isRecord(value) {
|
|
38
87
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
39
88
|
}
|
|
@@ -393,7 +442,10 @@ export function resolveSourceSessionRequestContext(metadata, options = {}) {
|
|
|
393
442
|
return { sourceSession: null, isSubagent: false, lineageStatus: "unbound" };
|
|
394
443
|
}
|
|
395
444
|
export function resolveSourceSessionFromMcpContext(metadata, options = {}) {
|
|
396
|
-
|
|
445
|
+
const sourceSession = resolveSourceSessionRequestContext(metadata, options).sourceSession;
|
|
446
|
+
return sourceSession?.evidence === SOURCE_SESSION_CLOUD_TOOL_ARGUMENT_EVIDENCE
|
|
447
|
+
? null
|
|
448
|
+
: sourceSession;
|
|
397
449
|
}
|
|
398
450
|
export function resolveSourceSessionFromBindingToken(bindingToken, options = {}) {
|
|
399
451
|
const normalizedToken = bindingToken.trim().toLowerCase();
|
package/dist/v1-contract.js
CHANGED
|
@@ -164,7 +164,32 @@ function decorateLocalToolSpec(tool) {
|
|
|
164
164
|
const triggerMetadataSchema = {
|
|
165
165
|
triggerMessage: z.string().optional(),
|
|
166
166
|
triggerMessageRole: z.string().optional(),
|
|
167
|
+
cloudCoworkSessionId: z.string().regex(/^session_[A-Za-z0-9_-]{1,192}$/).optional(),
|
|
167
168
|
};
|
|
169
|
+
const CLOUD_COWORK_SESSION_DESCRIPTION = "Cloud Cowork only: the current session_ identifier supplied by the Cowork runtime. Repeat it on each EchoMem call so the shared remote-devices bridge can attach that one request to the same provisional conversation context. Never guess or reuse an ID from another conversation. Local Cowork, Claude Code, and Codex must omit this field.";
|
|
170
|
+
const CLOUD_COWORK_SESSION_PROPERTY = {
|
|
171
|
+
type: "string",
|
|
172
|
+
pattern: "^session_[A-Za-z0-9_-]{1,192}$",
|
|
173
|
+
description: CLOUD_COWORK_SESSION_DESCRIPTION,
|
|
174
|
+
};
|
|
175
|
+
const SOURCE_CONTEXT_FREE_TOOL_NAMES = new Set([
|
|
176
|
+
canonicalToolNames.bindSourceSession,
|
|
177
|
+
canonicalToolNames.updateStatus,
|
|
178
|
+
canonicalToolNames.contextHealth,
|
|
179
|
+
canonicalToolNames.recompose,
|
|
180
|
+
]);
|
|
181
|
+
function injectCloudCoworkSession(specs) {
|
|
182
|
+
for (const spec of specs) {
|
|
183
|
+
if (SOURCE_CONTEXT_FREE_TOOL_NAMES.has(spec.name))
|
|
184
|
+
continue;
|
|
185
|
+
const existing = spec.inputSchema.properties ?? {};
|
|
186
|
+
spec.inputSchema.properties = {
|
|
187
|
+
...existing,
|
|
188
|
+
cloudCoworkSessionId: CLOUD_COWORK_SESSION_PROPERTY,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return specs;
|
|
192
|
+
}
|
|
168
193
|
// Canonical workspace selector for tools that act inside a company workspace.
|
|
169
194
|
// `workspaceId` is the current name; `groupId` is the legacy alias kept working
|
|
170
195
|
// so existing prompts keep functioning. Handlers normalize with
|
|
@@ -478,7 +503,7 @@ export function listToolSpecs(opts = {}) {
|
|
|
478
503
|
{
|
|
479
504
|
name: canonicalToolNames.linkWorkspaceTicketSession,
|
|
480
505
|
title: "Link this agent conversation to an Echo workspace ticket",
|
|
481
|
-
description: withMcpVersion("Call when the user asks to work on, continue, attach, or bind this conversation to an Echo workspace ticket and supplies its UUID. Pass the ticketId exactly; pass workspaceId when a structured Echo ticket marker provides it. The operation is idempotent.
|
|
506
|
+
description: withMcpVersion("Call when the user asks to work on, continue, attach, or bind this conversation to an Echo workspace ticket and supplies its UUID. Pass the ticketId exactly; pass workspaceId when a structured Echo ticket marker provides it. The operation is idempotent. A verified local source session links immediately. Cloud Cowork has no local transcript, so pass its current session_ runtime identifier as cloudCoworkSessionId; EchoMem records that path explicitly as provisional and links it immediately. Otherwise Echo Desktop can recover this exact invocation from a local transcript. Never guess or ask the user for a source-session/context ID."),
|
|
482
507
|
inputSchema: {
|
|
483
508
|
type: "object",
|
|
484
509
|
properties: {
|
|
@@ -1097,5 +1122,5 @@ export function listToolSpecs(opts = {}) {
|
|
|
1097
1122
|
},
|
|
1098
1123
|
},
|
|
1099
1124
|
];
|
|
1100
|
-
return injectWorkspaceSelector(tools).map(decorateLocalToolSpec);
|
|
1125
|
+
return injectWorkspaceSelector(injectCloudCoworkSession(tools)).map(decorateLocalToolSpec);
|
|
1101
1126
|
}
|