@luckydraw/cumulus 0.31.65 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +6 -555
  2. package/LICENSE +150 -0
  3. package/README.md +161 -17
  4. package/dist/gateway/adapters/webchat.d.ts +2 -0
  5. package/dist/gateway/adapters/webchat.d.ts.map +1 -1
  6. package/dist/gateway/adapters/webchat.js +22 -2
  7. package/dist/gateway/adapters/webchat.js.map +1 -1
  8. package/dist/gateway/config.d.ts +17 -2
  9. package/dist/gateway/config.d.ts.map +1 -1
  10. package/dist/gateway/config.js +10 -3
  11. package/dist/gateway/config.js.map +1 -1
  12. package/dist/gateway/daemon.d.ts +3 -1
  13. package/dist/gateway/daemon.d.ts.map +1 -1
  14. package/dist/gateway/daemon.js +128 -39
  15. package/dist/gateway/daemon.js.map +1 -1
  16. package/dist/gateway/namespaces.d.ts +34 -0
  17. package/dist/gateway/namespaces.d.ts.map +1 -1
  18. package/dist/gateway/namespaces.js +58 -0
  19. package/dist/gateway/namespaces.js.map +1 -1
  20. package/dist/gateway/server.d.ts +8 -0
  21. package/dist/gateway/server.d.ts.map +1 -1
  22. package/dist/gateway/server.js +150 -41
  23. package/dist/gateway/server.js.map +1 -1
  24. package/dist/gateway/setup.d.ts +32 -0
  25. package/dist/gateway/setup.d.ts.map +1 -1
  26. package/dist/gateway/setup.js +23 -3
  27. package/dist/gateway/setup.js.map +1 -1
  28. package/dist/gateway/static/widget.js +897 -611
  29. package/dist/lib/gateway.d.ts +30 -8
  30. package/dist/lib/gateway.d.ts.map +1 -1
  31. package/dist/lib/gateway.js +36 -11
  32. package/dist/lib/gateway.js.map +1 -1
  33. package/dist/lib/history.d.ts +22 -0
  34. package/dist/lib/history.d.ts.map +1 -1
  35. package/dist/lib/history.js +59 -21
  36. package/dist/lib/history.js.map +1 -1
  37. package/dist/lib/huggingface-provider.d.ts.map +1 -1
  38. package/dist/lib/huggingface-provider.js +11 -3
  39. package/dist/lib/huggingface-provider.js.map +1 -1
  40. package/dist/lib/license.d.ts +76 -0
  41. package/dist/lib/license.d.ts.map +1 -0
  42. package/dist/lib/license.js +141 -0
  43. package/dist/lib/license.js.map +1 -0
  44. package/docs/agentic-harness-primer.md +283 -0
  45. package/docs/conditional-continuation.md +167 -0
  46. package/docs/web-app-agent-guide.md +520 -0
  47. package/examples/web-app-agent/README.md +187 -0
  48. package/examples/web-app-agent/agent/mcp-shim.js +105 -0
  49. package/examples/web-app-agent/gateway.config.example.json +52 -0
  50. package/examples/web-app-agent/package.json +13 -0
  51. package/examples/web-app-agent/public/agent/bridge-mount.js +75 -0
  52. package/examples/web-app-agent/public/agent/chat-client.js +104 -0
  53. package/examples/web-app-agent/public/agent/commands.js +250 -0
  54. package/examples/web-app-agent/public/agent/device-thread.js +48 -0
  55. package/examples/web-app-agent/public/agent/panel.css +107 -0
  56. package/examples/web-app-agent/public/agent/panel.js +369 -0
  57. package/examples/web-app-agent/public/app.js +250 -0
  58. package/examples/web-app-agent/public/index.html +111 -0
  59. package/examples/web-app-agent/server.js +242 -0
  60. package/package.json +7 -3
@@ -0,0 +1,111 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
6
+ <title>Demo Notes — cumulus web-app agent</title>
7
+ <style>
8
+ /* The six variables the agent panel themes itself from. Define these and
9
+ panel.css needs no edits. */
10
+ :root {
11
+ --panel: #16181d;
12
+ --panel2: #1e2128;
13
+ --panel3: #272b34;
14
+ --line: #333844;
15
+ --text: #e6e8ee;
16
+ --muted: #8a91a3;
17
+ --accent: #5b8cff;
18
+ }
19
+ @media (prefers-color-scheme: light) {
20
+ :root {
21
+ --panel: #ffffff; --panel2: #f4f5f8; --panel3: #e9ebf0;
22
+ --line: #d8dbe3; --text: #1b1e25; --muted: #6b7280; --accent: #3b6fe0;
23
+ }
24
+ }
25
+ * { box-sizing: border-box; }
26
+ body {
27
+ margin: 0; padding: 32px 20px 160px;
28
+ background: var(--panel); color: var(--text);
29
+ font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
30
+ }
31
+ main { max-width: 620px; margin: 0 auto; }
32
+ h1 { font-size: 20px; margin: 0 0 4px; }
33
+ .sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
34
+
35
+ input, button, textarea { font: inherit; }
36
+ .field {
37
+ width: 100%; padding: 9px 12px; border-radius: 9px;
38
+ background: var(--panel2); border: 1px solid var(--line); color: var(--text); outline: none;
39
+ }
40
+ .field:focus { border-color: var(--accent); }
41
+ .btn {
42
+ padding: 9px 16px; border-radius: 9px; cursor: pointer;
43
+ background: var(--accent); color: #fff; border: none;
44
+ }
45
+ .btn.ghost { background: var(--panel3); color: var(--text); border: 1px solid var(--line); }
46
+ .row { display: flex; gap: 8px; margin-bottom: 14px; }
47
+ .row .field { flex: 1; }
48
+
49
+ ul.notes { list-style: none; padding: 0; margin: 0; }
50
+ ul.notes li {
51
+ display: flex; align-items: center; gap: 10px;
52
+ padding: 10px 12px; margin-bottom: 6px;
53
+ background: var(--panel2); border: 1px solid var(--line); border-radius: 9px;
54
+ }
55
+ ul.notes li.done .text { color: var(--muted); text-decoration: line-through; }
56
+ ul.notes .text { flex: 1; }
57
+ ul.notes .id { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
58
+ .empty { color: var(--muted); padding: 18px 2px; }
59
+
60
+ #login { max-width: 300px; margin: 60px auto; }
61
+ #app[hidden], #login[hidden] { display: none; }
62
+ .err { color: #f2665e; font-size: 13px; min-height: 18px; }
63
+ .topbar { display: flex; align-items: baseline; justify-content: space-between; }
64
+ .link { background: none; border: none; color: var(--muted); cursor: pointer; text-decoration: underline; padding: 0; }
65
+ </style>
66
+ </head>
67
+ <body>
68
+
69
+ <section id="login">
70
+ <h1>Demo Notes</h1>
71
+ <p class="sub">Sign in to load the assistant. Default password: <code>demo</code></p>
72
+ <div class="row">
73
+ <input id="password" class="field" type="password" placeholder="Password" data-testid="login-password" autocomplete="current-password">
74
+ <button id="login-submit" class="btn" data-testid="login-submit">Sign in</button>
75
+ </div>
76
+ <div id="login-error" class="err" data-testid="login-error"></div>
77
+ </section>
78
+
79
+ <main id="app" hidden>
80
+ <div class="topbar">
81
+ <div>
82
+ <h1>Demo Notes</h1>
83
+ <p class="sub">The assistant at the bottom can read this list and change it.</p>
84
+ </div>
85
+ <button id="logout" class="link" data-testid="logout">Sign out</button>
86
+ </div>
87
+
88
+ <div class="row">
89
+ <input id="new-note" class="field" placeholder="Add a note…" data-testid="note-input">
90
+ <button id="add-note" class="btn" data-testid="note-add">Add</button>
91
+ </div>
92
+
93
+ <div class="row">
94
+ <input id="filter" class="field" placeholder="Filter…" data-testid="filter-input">
95
+ <button id="clear-filter" class="btn ghost" data-testid="filter-clear">Clear</button>
96
+ </div>
97
+
98
+ <ul class="notes" id="note-list" data-testid="note-list" data-loading="false"></ul>
99
+ </main>
100
+
101
+ <!-- Load order matters: the registry and its dependencies must exist before
102
+ bridge-mount runs. bridge-mount is a module (it imports the cumulus
103
+ BridgeClient), so it is deferred automatically. -->
104
+ <script src="/app.js"></script>
105
+ <script src="/agent/device-thread.js"></script>
106
+ <script src="/agent/commands.js"></script>
107
+ <script src="/agent/chat-client.js"></script>
108
+ <script src="/agent/panel.js"></script>
109
+ <script type="module" src="/agent/bridge-mount.js"></script>
110
+ </body>
111
+ </html>
@@ -0,0 +1,242 @@
1
+ // Serving layer for the demo app.
2
+ //
3
+ // The only part of this file that matters for the agent integration is
4
+ // GET /api/agent-config: the scoped gateway key is handed ONLY to an
5
+ // authenticated session, so it never appears in the static page. That is the
6
+ // difference between "anyone who views source can talk to your gateway" and
7
+ // "only your logged-in users can".
8
+ //
9
+ // Everything else here is a deliberately boring static file server so the kit
10
+ // runs with zero dependencies. Your real app already has this part.
11
+ //
12
+ // Env (same names the MCP shim uses — one vocabulary across the kit):
13
+ // PORT default 8199
14
+ // APP_PASSWORD default "demo" — the app's own login
15
+ // GATEWAY_API_KEY scoped cumulus key (namespace "demoapp"). Absent =>
16
+ // /api/agent-config 404s and the app runs agent-dark.
17
+ // GATEWAY_ORIGIN REQUIRED when GATEWAY_API_KEY is set. There is no default
18
+ // on purpose: whatever is listening on the usual gateway
19
+ // port is usually a REAL gateway, so a mistyped variable
20
+ // would silently point a demo app at production instead
21
+ // of failing.
22
+
23
+ import http from 'node:http';
24
+ import fs from 'node:fs';
25
+ import path from 'node:path';
26
+ import crypto from 'node:crypto';
27
+ import { fileURLToPath } from 'node:url';
28
+ import { createRequire } from 'node:module';
29
+
30
+ const ROOT = path.dirname(fileURLToPath(import.meta.url));
31
+ const PUBLIC = path.join(ROOT, 'public');
32
+
33
+ /* ---- env, checked loudly --------------------------------------------------
34
+ An unread environment variable is silent by nature, and the value most
35
+ likely to be mistyped here is the gateway origin — whose old default was a
36
+ live gateway. So: names that are NOT read but are plausible mistakes for
37
+ ones that are get named explicitly and refuse to start. */
38
+ const ENV_ALIASES = {
39
+ AGENT_GATEWAY_ORIGIN: 'GATEWAY_ORIGIN',
40
+ AGENT_GATEWAY_URL: 'GATEWAY_ORIGIN',
41
+ GATEWAY_URL: 'GATEWAY_ORIGIN',
42
+ CUMULUS_GATEWAY_URL: 'GATEWAY_ORIGIN',
43
+ AGENT_API_KEY: 'GATEWAY_API_KEY',
44
+ CUMULUS_API_KEY: 'GATEWAY_API_KEY',
45
+ API_KEY: 'GATEWAY_API_KEY',
46
+ DEMO_PASSWORD: 'APP_PASSWORD',
47
+ PASSWORD: 'APP_PASSWORD',
48
+ };
49
+
50
+ function checkEnv(env) {
51
+ const errors = [];
52
+ for (const [wrong, right] of Object.entries(ENV_ALIASES)) {
53
+ if (env[wrong] !== undefined && env[right] === undefined) {
54
+ errors.push(`${wrong} is not read by this server. Use ${right}.`);
55
+ }
56
+ }
57
+ if (env.GATEWAY_API_KEY && !env.GATEWAY_ORIGIN) {
58
+ errors.push(
59
+ 'GATEWAY_API_KEY is set but GATEWAY_ORIGIN is not. Set it explicitly ' +
60
+ '(e.g. GATEWAY_ORIGIN=http://127.0.0.1:8080) — there is no default, because ' +
61
+ 'guessing one would point this app at whatever gateway happens to be running.'
62
+ );
63
+ }
64
+ if (env.GATEWAY_ORIGIN) {
65
+ try {
66
+ const u = new URL(env.GATEWAY_ORIGIN);
67
+ if (!/^https?:$/.test(u.protocol)) throw new Error('not http(s)');
68
+ } catch {
69
+ errors.push(`GATEWAY_ORIGIN is not a valid http(s) origin: ${env.GATEWAY_ORIGIN}`);
70
+ }
71
+ }
72
+ return errors;
73
+ }
74
+
75
+ const envErrors = checkEnv(process.env);
76
+ if (envErrors.length > 0) {
77
+ for (const e of envErrors) console.error(`[env] ${e}`);
78
+ process.exit(1);
79
+ }
80
+
81
+ const PORT = Number(process.env.PORT || 8199);
82
+ const PASSWORD = process.env.APP_PASSWORD || 'demo';
83
+ const API_KEY = process.env.GATEWAY_API_KEY || '';
84
+ const GATEWAY_ORIGIN = process.env.GATEWAY_ORIGIN || '';
85
+
86
+ /* ---- where the browser's BridgeClient comes from --------------------------
87
+ Cumulus owns the bridge client (Rule #8: one implementation). We do NOT
88
+ vendor a copy into this example — we serve the compiled files straight out
89
+ of the package, so this kit can never drift from the gateway it talks to.
90
+ `dist/gateway/bridge/*.js` is plain ESM with no Node imports, so a browser
91
+ loads it directly. */
92
+ function resolveBridgeDir() {
93
+ const inRepo = path.join(ROOT, '..', '..', 'dist', 'gateway', 'bridge');
94
+ if (fs.existsSync(path.join(inRepo, 'client.js'))) return inRepo;
95
+ try {
96
+ const require = createRequire(import.meta.url);
97
+ return path.dirname(require.resolve('@luckydraw/cumulus/dist/gateway/bridge/client.js'));
98
+ } catch {
99
+ return null;
100
+ }
101
+ }
102
+ const BRIDGE_DIR = resolveBridgeDir();
103
+
104
+ /* ---- sessions (in-memory; your app has real ones) ------------------------ */
105
+ const sessions = new Set();
106
+
107
+ function sessionOf(req) {
108
+ const raw = req.headers.cookie || '';
109
+ const match = raw.match(/(?:^|;\s*)sid=([a-f0-9]{32})/);
110
+ return match && sessions.has(match[1]) ? match[1] : null;
111
+ }
112
+
113
+ /* ---- helpers ------------------------------------------------------------- */
114
+ const MIME = {
115
+ '.html': 'text/html; charset=utf-8',
116
+ '.js': 'text/javascript; charset=utf-8',
117
+ '.css': 'text/css; charset=utf-8',
118
+ '.json': 'application/json; charset=utf-8',
119
+ };
120
+
121
+ function json(res, status, body, headers = {}) {
122
+ res.writeHead(status, { 'content-type': MIME['.json'], ...headers });
123
+ res.end(JSON.stringify(body));
124
+ }
125
+
126
+ function readBody(req) {
127
+ return new Promise((resolve, reject) => {
128
+ let raw = '';
129
+ req.on('data', c => {
130
+ raw += c;
131
+ if (raw.length > 1e5) reject(new Error('body too large'));
132
+ });
133
+ req.on('end', () => {
134
+ try {
135
+ resolve(raw ? JSON.parse(raw) : {});
136
+ } catch {
137
+ reject(new Error('invalid JSON'));
138
+ }
139
+ });
140
+ req.on('error', reject);
141
+ });
142
+ }
143
+
144
+ function sendFile(res, file) {
145
+ fs.readFile(file, (err, buf) => {
146
+ if (err) {
147
+ res.writeHead(404);
148
+ return res.end('not found');
149
+ }
150
+ res.writeHead(200, { 'content-type': MIME[path.extname(file)] || 'application/octet-stream' });
151
+ res.end(buf);
152
+ });
153
+ }
154
+
155
+ /* ---- routes -------------------------------------------------------------- */
156
+ const server = http.createServer(async (req, res) => {
157
+ const url = new URL(req.url, 'http://localhost');
158
+ const p = url.pathname;
159
+
160
+ if (req.method === 'POST' && p === '/api/login') {
161
+ let body;
162
+ try {
163
+ body = await readBody(req);
164
+ } catch (e) {
165
+ return json(res, 400, { error: e.message });
166
+ }
167
+ if (body.password !== PASSWORD) return json(res, 401, { error: 'wrong password' });
168
+ const sid = crypto.randomBytes(16).toString('hex');
169
+ sessions.add(sid);
170
+ return json(
171
+ res,
172
+ 200,
173
+ { ok: true },
174
+ { 'set-cookie': `sid=${sid}; HttpOnly; SameSite=Lax; Path=/` }
175
+ );
176
+ }
177
+
178
+ if (req.method === 'POST' && p === '/api/logout') {
179
+ const sid = sessionOf(req);
180
+ if (sid) sessions.delete(sid);
181
+ return json(res, 200, { ok: true }, { 'set-cookie': 'sid=; Max-Age=0; Path=/' });
182
+ }
183
+
184
+ // Session probe. "Am I signed in?" is a different question from "give me the
185
+ // key", so it answers 200 either way. Asking the key endpoint instead would
186
+ // make every logged-out page load emit a 401 in the browser console — correct
187
+ // behaviour, alarming signal.
188
+ if (req.method === 'GET' && p === '/api/session') {
189
+ return json(res, 200, { authenticated: !!sessionOf(req) });
190
+ }
191
+
192
+ // THE ONE THAT MATTERS. The scoped key reaches only authenticated sessions.
193
+ // 404 when no key is configured, so the front end simply stays agent-dark
194
+ // instead of erroring.
195
+ if (req.method === 'GET' && p === '/api/agent-config') {
196
+ if (!sessionOf(req)) return json(res, 401, { error: 'not signed in' });
197
+ if (!API_KEY) return json(res, 404, { error: 'agent not configured' });
198
+ return json(res, 200, {
199
+ GATEWAY_URL: GATEWAY_ORIGIN,
200
+ BRIDGE_URL: GATEWAY_ORIGIN.replace(/^http/, 'ws') + '/bridge',
201
+ // Base name only. device-thread.js appends the per-visitor suffix in the
202
+ // browser, so the full thread name never travels from server to client.
203
+ THREAD_ID: 'demoapp-v',
204
+ API_KEY,
205
+ });
206
+ }
207
+
208
+ // Bridge client, served from the cumulus package rather than a local copy.
209
+ if (p.startsWith('/agent/bridge-client/')) {
210
+ const name = path.basename(p);
211
+ if (!BRIDGE_DIR || !/^(client|protocol)\.js$/.test(name)) {
212
+ res.writeHead(404);
213
+ return res.end('bridge client unavailable — build cumulus or npm i @luckydraw/cumulus');
214
+ }
215
+ return sendFile(res, path.join(BRIDGE_DIR, name));
216
+ }
217
+
218
+ if (req.method === 'GET') {
219
+ const rel = p === '/' ? 'index.html' : p.replace(/^\/+/, '');
220
+ const file = path.join(PUBLIC, rel);
221
+ if (!file.startsWith(PUBLIC)) {
222
+ res.writeHead(403);
223
+ return res.end('forbidden');
224
+ }
225
+ return sendFile(res, file);
226
+ }
227
+
228
+ res.writeHead(404);
229
+ res.end('not found');
230
+ });
231
+
232
+ server.listen(PORT, '127.0.0.1', () => {
233
+ console.log(`demo app: http://127.0.0.1:${PORT} (password: ${PASSWORD})`);
234
+ console.log(
235
+ `bridge client: ${BRIDGE_DIR ?? 'NOT FOUND — run `npm run build` in the cumulus repo'}`
236
+ );
237
+ console.log(
238
+ API_KEY
239
+ ? `agent: enabled -> ${GATEWAY_ORIGIN}`
240
+ : 'agent: disabled (set GATEWAY_API_KEY + GATEWAY_ORIGIN)'
241
+ );
242
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luckydraw/cumulus",
3
- "version": "0.31.65",
3
+ "version": "1.0.0",
4
4
  "description": "RLM-based CLI chat wrapper for Claude with external history context management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,6 +24,10 @@
24
24
  },
25
25
  "files": [
26
26
  "dist/",
27
+ "examples/",
28
+ "docs/web-app-agent-guide.md",
29
+ "docs/agentic-harness-primer.md",
30
+ "docs/conditional-continuation.md",
27
31
  "package.json",
28
32
  "CHANGELOG.md"
29
33
  ],
@@ -53,8 +57,8 @@
53
57
  "context",
54
58
  "mcp"
55
59
  ],
56
- "author": "",
57
- "license": "MIT",
60
+ "author": "Lucky Draw LLC",
61
+ "license": "SEE LICENSE IN LICENSE",
58
62
  "publishConfig": {
59
63
  "access": "public"
60
64
  },