@anusornneal/chat-relay 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -205,3 +205,56 @@ Optional Cloudflare-pressure circuit breakers can be configured with `USAGE_RECO
205
205
  - Public plugin/reviewer flow: `docs/plugin-review.md`
206
206
  - Google sign-in setup: `docs/google-login.md`
207
207
  - Source: https://github.com/anusornNeal/chat-relay
208
+
209
+
210
+ ## Account-scoped Learn
211
+
212
+ Chat Relay can persist small, structured pieces of execution context per authenticated account. Learn is **not model training** and it does not capture conversations or tool payloads automatically.
213
+
214
+ The MCP surface is:
215
+
216
+ - `learn_get` reads explicit memories for selected scopes.
217
+ - `learn_put` creates or updates one memory.
218
+ - `learn_delete` removes one memory.
219
+ - `learn_feedback` records positive or negative feedback on one memory.
220
+
221
+ Memories are partitioned by authenticated account using a dedicated Learning Durable Object selected from the server-side `user.id`. Callers cannot provide or override an account id. Supported scopes are `global`, `project`, and `agent`; project and agent memories require a scope key.
222
+
223
+ The first version is intentionally lightweight: there are no embeddings, vector database, local LLM, transcript ingestion, or per-tool-call writes. A normal tool call causes no Learn storage write. Storage changes happen only when an explicit Learn mutation is requested. Each account is capped at 512 memories, each memory content field is capped at 4,000 characters, and reads return at most 100 records. Do not store credentials, tokens, secrets, raw tool payloads, terminal output, file contents, or screenshots in Learn.
224
+
225
+
226
+ ## Progressive Learn bootstrap and routing
227
+
228
+ Learn context is loaded progressively so a fresh ChatGPT conversation does not need to remember to call `learn_get` before using Relay.
229
+
230
+ ```mermaid
231
+ flowchart TD
232
+ U[User starts or continues a chat] --> M[ChatGPT calls Relay]
233
+ M --> A[Authenticate account]
234
+ A --> G{Global context loaded in this MCP session?}
235
+ G -- No --> LG[Read global Learn once]
236
+ G -- Yes --> S[Continue]
237
+ LG --> S
238
+ S --> P{Concrete project signal? path / cwd / repo}
239
+ P -- Yes --> PR[Match explicit project-root hint]
240
+ PR --> LP[Read project Learn once]
241
+ P -- No --> AG
242
+ LP --> AG
243
+ AG{Agent selected or safely resolved?}
244
+ AG -- Yes --> LA[Read agent Learn once]
245
+ AG -- No --> E
246
+ LA --> E
247
+ E[Attach bounded learnedContext envelope] --> R[ChatGPT chooses action and tool]
248
+ R --> SEC[Relay enforces auth, grants, allowedRoots and capabilities]
249
+ SEC --> X[Execute]
250
+ ```
251
+
252
+ The decision boundary is deliberate:
253
+
254
+ - **Relay decides mechanical routing only:** authenticated account, whether a scope was already loaded, project identity from explicit `project-root:<projectKey>` memories, explicit/resolved agent, and available permissions/capabilities.
255
+ - **ChatGPT decides semantic actions and tools:** whether to read files, search, edit, run terminal commands, use desktop control, or re-plan after a failure.
256
+ - Learned hints never override authorization, grants, allowed roots, destructive-tool policy, or capability checks.
257
+
258
+ Routing hints are explicit memories. A global `project_context` memory with key `project-root:<projectKey>` stores the concrete project root. A `preferred-agent` memory may exist in project scope (preferred) or global scope (fallback); Relay surfaces it in `routingContext` as guidance and does not execute or retry a tool solely because of that hint. No project is guessed when no explicit root hint matches.
259
+
260
+ The intended read budget is bounded by an in-memory warm-cache: global context is normally read once per conversation/session, each activated project once, and each activated agent once. A Worker isolate restart/eviction may cause a scope to be read again; this is intentionally best-effort so bootstrap performs no durable session writes. Learned content is advisory user memory, not system/developer instruction authority.
@@ -64,16 +64,20 @@ function classifyResponse(response, body) {
64
64
 
65
65
  try {
66
66
  const health = JSON.parse(body);
67
- if (health?.error === "relay_unavailable") return { state: "unavailable", reason: "relay_unavailable" };
68
- if (!response.ok) return { state: "unavailable", code: response.status };
69
- if (health?.reauthorizationRequired === true) return { state: "reauthorize" };
67
+ const features = health?.features && typeof health.features === "object"
68
+ ? { learn: health.features.learn === true }
69
+ : null;
70
+ const withFeatures = (value) => features ? { ...value, features } : value;
71
+ if (health?.error === "relay_unavailable") return withFeatures({ state: "unavailable", reason: "relay_unavailable" });
72
+ if (!response.ok) return withFeatures({ state: "unavailable", code: response.status });
73
+ if (health?.reauthorizationRequired === true) return withFeatures({ state: "reauthorize" });
70
74
  if (health?.authorized === false) {
71
- return health?.enabled === false
75
+ return withFeatures(health?.enabled === false
72
76
  ? { state: "agent-disabled" }
73
- : { state: "agent-access" };
77
+ : { state: "agent-access" });
74
78
  }
75
- if (health?.online === true) return { state: "reachable" };
76
- if (health?.online === false) return { state: "unavailable", reason: "agent_offline" };
79
+ if (health?.online === true) return withFeatures({ state: "reachable" });
80
+ if (health?.online === false) return withFeatures({ state: "unavailable", reason: "agent_offline" });
77
81
  } catch {}
78
82
  if (!response.ok) return { state: "unavailable", code: response.status };
79
83
  return { state: "unavailable", code: response.status };
package/cli/tui.mjs CHANGED
@@ -101,58 +101,40 @@ function field(label, value, width, color = false, valueStyle = null) {
101
101
  return renderedLabel + renderedValue + " ".repeat(Math.max(0, width - plainLabel.length - plainValue.length));
102
102
  }
103
103
 
104
- function statusStyle(value) {
105
- switch (String(value || "").toLowerCase()) {
106
- case "connected": return STYLE.green;
107
- case "connecting":
108
- case "reconnecting": return STYLE.yellow;
109
- case "offline": return STYLE.red;
110
- default: return STYLE.gray;
111
- }
104
+ function relayIsOnline(health) {
105
+ const code = Number(health?.code);
106
+ if (Number.isFinite(code)) return code >= 200 && code < 300;
107
+ return health?.state === "reachable";
112
108
  }
113
109
 
114
- function relayHealthStyle(health) {
115
- const code = Number(health?.code);
116
- if (Number.isFinite(code) && code >= 200 && code < 300) return STYLE.green;
117
- switch (health?.state) {
118
- case "reachable": return STYLE.green;
119
- case "checking": return STYLE.yellow;
120
- default: return STYLE.red;
121
- }
110
+ function combinedStatusText(status, relayHealth) {
111
+ return String(status || "").toLowerCase() === "connected" && relayIsOnline(relayHealth)
112
+ ? "● Online"
113
+ : "○ Offline";
122
114
  }
123
115
 
124
- function relayHealthText(health) {
125
- const code = Number(health?.code);
126
- if (Number.isFinite(code) && code >= 200 && code < 300) return `● HTTP ${code}`;
127
- switch (health?.state) {
128
- case "reachable": return "● Online";
129
- case "checking": return "◐ Checking";
130
- case "limited":
131
- return health.code === 1027
132
- ? "✕ Cloudflare 1027"
133
- : `✕ Rate limited (${health.code || "429"})`;
134
- case "cloudflare-error": return `✕ Cloudflare ${health.code || "error"}`;
135
- case "unauthorized": return health.code === 403 ? "✕ Access denied" : "✕ Sign-in required";
136
- case "reauthorize": return "✕ Agent reauthorization required";
137
- case "agent-disabled": return "✕ Agent disabled";
138
- case "agent-access": return "✕ Agent access required";
139
- case "unavailable":
140
- if (health.reason === "relay_unavailable") return "✕ Relay unavailable";
141
- if (health.reason === "agent_offline") return "✕ Agent offline";
142
- return `✕ ${health.code ? `HTTP ${health.code}` : "Unavailable"}`;
143
- default: return "? Unknown";
144
- }
116
+ function combinedStatusStyle(status, relayHealth) {
117
+ return String(status || "").toLowerCase() === "connected" && relayIsOnline(relayHealth)
118
+ ? STYLE.green
119
+ : STYLE.red;
120
+ }
121
+
122
+ function learnStatusText(value) {
123
+ if (value === true) return "enabled";
124
+ if (value === false) return "disabled";
125
+ return "checking";
145
126
  }
146
127
 
147
- function relayHealthAge(health, now = Date.now()) {
148
- const checkedAt = Number(health?.checkedAt);
149
- if (!Number.isFinite(checkedAt)) return "pending";
150
- const ageSeconds = Math.max(0, Math.floor((now - checkedAt) / 1000));
151
- if (ageSeconds < 10) return "just now";
152
- if (ageSeconds < 60) return `${ageSeconds}s ago`;
153
- const ageMinutes = Math.floor(ageSeconds / 60);
154
- if (ageMinutes < 60) return `${ageMinutes}m ago`;
155
- return `${Math.floor(ageMinutes / 60)}h ago`;
128
+ function learnStatusStyle(value) {
129
+ if (value === true) return STYLE.green;
130
+ if (value === false) return STYLE.red;
131
+ return STYLE.yellow;
132
+ }
133
+
134
+ function compactLearnStatus(value) {
135
+ if (value === true) return "on";
136
+ if (value === false) return "off";
137
+ return "checking";
156
138
  }
157
139
 
158
140
  export function formatTwoColumnHeader(state, width = 110, { color = false } = {}) {
@@ -161,17 +143,21 @@ export function formatTwoColumnHeader(state, width = 110, { color = false } = {}
161
143
  const rightWidth = usable - GAP - leftWidth;
162
144
  const rows = [
163
145
  ["Account", state.account || "-", "Agent", state.agent || "-"],
164
- ["Agent link", statusText(state.status), "Relay", state.relay || "-"],
165
- ["Relay API", relayHealthText(state.relayHealth), "Reconnects", String(state.reconnects ?? 0)],
146
+ ["Status", combinedStatusText(state.status, state.relayHealth), "Relay", state.relay || "-"],
147
+ ["Root", state.root || "-", "Reconnects", String(state.reconnects ?? 0)],
166
148
  ["Session up", formatUptime(state.uptimeMs), "Terminal", state.terminal ? "enabled" : "disabled"],
167
- ["Desktop", state.desktop ? "enabled" : "disabled", "Checked", relayHealthAge(state.relayHealth)],
149
+ ["Desktop", state.desktop ? "enabled" : "disabled", "Learn", learnStatusText(state.learn)],
168
150
  ];
169
151
  return rows
170
152
  .map(([leftLabel, leftValue, rightLabel, rightValue]) => {
171
- const leftStyle = leftLabel === "Agent link"
172
- ? statusStyle(state.status)
173
- : leftLabel === "Relay API" ? relayHealthStyle(state.relayHealth) : null;
174
- const rightStyle = rightLabel === "Reconnects" && Number(state.reconnects || 0) > 0 ? STYLE.yellow : null;
153
+ const leftStyle = leftLabel === "Status"
154
+ ? combinedStatusStyle(state.status, state.relayHealth)
155
+ : null;
156
+ const rightStyle = rightLabel === "Reconnects" && Number(state.reconnects || 0) > 0
157
+ ? STYLE.yellow
158
+ : rightLabel === "Learn"
159
+ ? learnStatusStyle(state.learn)
160
+ : null;
175
161
  return field(leftLabel, leftValue, leftWidth, color, leftStyle)
176
162
  + " ".repeat(GAP)
177
163
  + field(rightLabel, rightValue, rightWidth, color, rightStyle).trimEnd();
@@ -318,11 +304,13 @@ export class RemoteTui {
318
304
  account: config.user?.name || config.user?.login || "signed in",
319
305
  agent: config.agentName || config.agentId || "-",
320
306
  relay: normalizeRelay(config.relayUrl),
307
+ root: config.allowedRoots || "-",
321
308
  status: "starting",
322
309
  relayHealth: { state: "checking" },
323
310
  reconnects: 0,
324
311
  terminal: config.terminalEnabled !== false,
325
312
  desktop: config.desktopEnabled === true,
313
+ learn: null,
326
314
  };
327
315
  this.version = version || "-";
328
316
  this.colorEnabled = shouldUseColor(output, env);
@@ -503,6 +491,11 @@ export class RemoteTui {
503
491
  ...(health && typeof health === "object" ? health : { state: "unavailable" }),
504
492
  checkedAt: Date.now(),
505
493
  };
494
+ if (health?.features && Object.prototype.hasOwnProperty.call(health.features, "learn")) {
495
+ this.state.learn = health.features.learn === true;
496
+ } else if (health?.state === "reachable") {
497
+ this.state.learn = false;
498
+ }
506
499
  this.scheduleRender();
507
500
  }
508
501
 
@@ -527,7 +520,7 @@ export class RemoteTui {
527
520
  if (width < MIN_FRAME_WIDTH) {
528
521
  const compactHeader = [
529
522
  truncateCells(`👤 ${headerState.account || "-"} · 💻 ${headerState.agent || "-"}`, width),
530
- truncateCells(`🔗 ${statusText(headerState.status)} · ${relayHealthText(headerState.relayHealth)}`, width),
523
+ truncateCells(`🔗 ${combinedStatusText(headerState.status, headerState.relayHealth)} · 🧠 Learn ${compactLearnStatus(headerState.learn)} · 📁 ${headerState.root || "-"}`, width),
531
524
  ];
532
525
  headerLines = compactHeader.map((line) => this.colorEnabled ? paint(line, STYLE.gray) : line);
533
526
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anusornneal/chat-relay",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Zero-checkout remote MCP agent for ChatGPT with terminal, filesystem, process, multi-user, and multi-agent support.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -55,8 +55,10 @@
55
55
  "test:self-update": "node --test test/self-update.test.mjs test/agent-lifecycle-upgrade.test.mjs",
56
56
  "test:budget": "node --test test/relay-health.test.mjs test/usage-budget.test.mjs",
57
57
  "test:soak": "node test/soak-smoke.mjs",
58
- "test:hardening": "npm run test:tui && npm run test:config-security && npm run test:self-update && npm run test:budget && node --test test/connection-generation.test.mjs && npm run test:agent-state && node test/heartbeat-ack-watchdog.test.mjs && npm run test:usage-storage && npm run test:soak",
59
- "verify:review": "node scripts/verify-review-artifacts.mjs"
58
+ "test:hardening": "npm run test:tui && npm run test:config-security && npm run test:self-update && npm run test:budget && node --test test/connection-generation.test.mjs && npm run test:agent-state && node test/heartbeat-ack-watchdog.test.mjs && npm run test:usage-storage && npm run test:learn && npm run test:learn-bootstrap && npm run test:soak",
59
+ "verify:review": "node scripts/verify-review-artifacts.mjs",
60
+ "test:learn": "node test/learning-smoke.mjs",
61
+ "test:learn-bootstrap": "node test/learning-bootstrap-smoke.mjs"
60
62
  },
61
63
  "dependencies": {
62
64
  "ws": "^8.22.0"
@@ -64,6 +66,7 @@
64
66
  "devDependencies": {
65
67
  "@modelcontextprotocol/server": "^2.0.0",
66
68
  "agents": "^0.24.0",
69
+ "esbuild": "^0.28.1",
67
70
  "wrangler": "^4.143.0",
68
71
  "zod": "^4.6.5"
69
72
  },