pawmode 1.0.1 → 1.3.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.
@@ -0,0 +1,532 @@
1
+ import * as os$1 from "node:os";
2
+ import * as fs$1 from "node:fs";
3
+ import * as path$1 from "node:path";
4
+ import * as http from "node:http";
5
+ import * as crypto from "node:crypto";
6
+
7
+ //#region src/core/dashboard-html.ts
8
+ function generateDashboardHTML(theme, botName) {
9
+ const themes = {
10
+ paw: {
11
+ bg: "#1a1008",
12
+ surface: "#241a10",
13
+ surfaceHover: "#2e2218",
14
+ border: "#3a2a18",
15
+ text: "#e8d8c8",
16
+ textDim: "#8a7a6a",
17
+ accent: "#b4783c",
18
+ accentDim: "#8a5a2a",
19
+ done: "#6a9a5a",
20
+ high: "#d44",
21
+ low: "#666"
22
+ },
23
+ midnight: {
24
+ bg: "#0a0a0f",
25
+ surface: "#12121a",
26
+ surfaceHover: "#1a1a25",
27
+ border: "#222233",
28
+ text: "#d0d0e0",
29
+ textDim: "#6a6a8a",
30
+ accent: "#6688cc",
31
+ accentDim: "#445588",
32
+ done: "#5a8a5a",
33
+ high: "#cc5555",
34
+ low: "#555566"
35
+ },
36
+ neon: {
37
+ bg: "#050505",
38
+ surface: "#0a0a0a",
39
+ surfaceHover: "#111111",
40
+ border: "#1a1a1a",
41
+ text: "#e0e0e0",
42
+ textDim: "#555",
43
+ accent: "#00ff88",
44
+ accentDim: "#008844",
45
+ done: "#00cc66",
46
+ high: "#ff3355",
47
+ low: "#444"
48
+ }
49
+ };
50
+ const t = themes[theme];
51
+ const safeBotName = botName.replace(/[&<>"']/g, "");
52
+ return `<!DOCTYPE html>
53
+ <html lang="en">
54
+ <head>
55
+ <meta charset="UTF-8">
56
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
57
+ <title>${safeBotName} — Task Dashboard</title>
58
+ <link rel="preconnect" href="https://fonts.googleapis.com">
59
+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">
60
+ <style>
61
+ *{margin:0;padding:0;box-sizing:border-box}
62
+ :root{
63
+ --bg:${t.bg};--surface:${t.surface};--surface-hover:${t.surfaceHover};
64
+ --border:${t.border};--text:${t.text};--text-dim:${t.textDim};
65
+ --accent:${t.accent};--accent-dim:${t.accentDim};--done:${t.done};
66
+ --high:${t.high};--low:${t.low};
67
+ }
68
+ body{font-family:'JetBrains Mono',monospace;background:var(--bg);color:var(--text);min-height:100vh;font-size:13px}
69
+ header{display:flex;align-items:center;justify-content:space-between;padding:20px 28px;border-bottom:1px solid var(--border)}
70
+ .logo{display:flex;align-items:center;gap:10px;font-size:18px;font-weight:700;color:var(--accent)}
71
+ .theme-switcher{display:flex;gap:8px}
72
+ .theme-dot{width:14px;height:14px;border-radius:50%;cursor:pointer;border:2px solid var(--border);transition:border-color .2s}
73
+ .theme-dot:hover,.theme-dot.active{border-color:var(--text)}
74
+ .theme-dot[data-theme="paw"]{background:#b4783c}
75
+ .theme-dot[data-theme="midnight"]{background:#6688cc}
76
+ .theme-dot[data-theme="neon"]{background:#00ff88}
77
+ .board{display:grid;grid-template-columns:repeat(3,1fr);gap:20px;padding:24px 28px;min-height:calc(100vh - 80px)}
78
+ .column{background:var(--surface);border:1px solid var(--border);border-radius:10px;padding:16px;display:flex;flex-direction:column;min-height:300px}
79
+ .column.drag-over{border-color:var(--accent);background:var(--surface-hover)}
80
+ .col-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;padding-bottom:10px;border-bottom:1px solid var(--border)}
81
+ .col-title{font-weight:600;font-size:14px;text-transform:uppercase;letter-spacing:1px}
82
+ .col-count{font-size:11px;color:var(--text-dim);background:var(--bg);padding:2px 8px;border-radius:10px}
83
+ .col-todo .col-title{color:var(--accent)}
84
+ .col-progress .col-title{color:var(--text)}
85
+ .col-done .col-title{color:var(--done)}
86
+ .cards{flex:1;display:flex;flex-direction:column;gap:8px;min-height:50px}
87
+ .card{background:var(--bg);border:1px solid var(--border);border-radius:8px;padding:12px;cursor:grab;transition:all .15s;position:relative}
88
+ .card:hover{border-color:var(--accent);transform:translateY(-1px)}
89
+ .card.dragging{opacity:.4;transform:scale(.95)}
90
+ .card-title{font-size:13px;font-weight:500;margin-bottom:6px;outline:none}
91
+ .card-title:focus{border-bottom:1px solid var(--accent)}
92
+ .card-desc{font-size:11px;color:var(--text-dim);margin-bottom:8px;outline:none}
93
+ .card-desc:focus{border-bottom:1px solid var(--accent)}
94
+ .card-footer{display:flex;align-items:center;justify-content:space-between}
95
+ .priority{display:flex;gap:4px}
96
+ .priority-dot{width:8px;height:8px;border-radius:50%;cursor:pointer;transition:transform .1s}
97
+ .priority-dot:hover{transform:scale(1.4)}
98
+ .priority-dot.high{background:var(--high)}
99
+ .priority-dot.normal{background:var(--accent)}
100
+ .priority-dot.low{background:var(--low)}
101
+ .priority-dot.active{box-shadow:0 0 0 2px var(--bg),0 0 0 4px currentColor}
102
+ .card-delete{font-size:11px;color:var(--text-dim);cursor:pointer;opacity:0;transition:opacity .15s}
103
+ .card:hover .card-delete{opacity:1}
104
+ .card-delete:hover{color:var(--high)}
105
+ .add-btn{display:flex;align-items:center;justify-content:center;gap:6px;padding:10px;margin-top:8px;border:1px dashed var(--border);border-radius:8px;color:var(--text-dim);cursor:pointer;font-family:inherit;font-size:12px;background:none;transition:all .15s;width:100%}
106
+ .add-btn:hover{border-color:var(--accent);color:var(--accent)}
107
+ .empty{text-align:center;padding:40px 16px;color:var(--text-dim);font-size:12px;line-height:1.8}
108
+ .add-form{display:none;flex-direction:column;gap:8px;margin-top:8px}
109
+ .add-form.show{display:flex}
110
+ .add-form input,.add-form textarea{background:var(--bg);border:1px solid var(--border);border-radius:6px;padding:8px 10px;color:var(--text);font-family:inherit;font-size:12px;outline:none;resize:none}
111
+ .add-form input:focus,.add-form textarea:focus{border-color:var(--accent)}
112
+ .form-actions{display:flex;gap:6px}
113
+ .form-actions button{flex:1;padding:6px;border:1px solid var(--border);border-radius:6px;font-family:inherit;font-size:11px;cursor:pointer;background:var(--surface);color:var(--text);transition:all .15s}
114
+ .form-actions .save{background:var(--accent);color:var(--bg);border-color:var(--accent);font-weight:600}
115
+ .form-actions .save:hover{opacity:.9}
116
+ .form-actions .cancel:hover{border-color:var(--text-dim)}
117
+ .toast{position:fixed;bottom:20px;right:20px;padding:10px 16px;border-radius:8px;font-size:12px;opacity:0;transition:opacity .3s;pointer-events:none;z-index:100}
118
+ .toast.show{opacity:1}
119
+ .toast.error{background:var(--high);color:#fff}
120
+ .toast.success{background:var(--done);color:#fff}
121
+ </style>
122
+ </head>
123
+ <body>
124
+ <header>
125
+ <div class="logo"><span>&#x1F43E;</span> ${safeBotName}</div>
126
+ <div class="theme-switcher">
127
+ <div class="theme-dot${theme === "paw" ? " active" : ""}" data-theme="paw" title="Paw"></div>
128
+ <div class="theme-dot${theme === "midnight" ? " active" : ""}" data-theme="midnight" title="Midnight"></div>
129
+ <div class="theme-dot${theme === "neon" ? " active" : ""}" data-theme="neon" title="Neon"></div>
130
+ </div>
131
+ </header>
132
+ <div class="board" id="board"></div>
133
+ <div class="toast" id="toast"></div>
134
+ <script>
135
+ var BOTNAME = "${safeBotName}";
136
+ var tasks = [];
137
+ var dragId = null;
138
+
139
+ function toast(msg, type) {
140
+ var el = document.getElementById("toast");
141
+ el.textContent = msg;
142
+ el.className = "toast show " + (type || "success");
143
+ setTimeout(function() { el.className = "toast"; }, 2000);
144
+ }
145
+
146
+ function api(path, opts) {
147
+ return fetch("/api/" + path, Object.assign({ headers: {"Content-Type": "application/json"} }, opts || {}))
148
+ .then(function(r) {
149
+ if (!r.ok) throw new Error("Request failed: " + r.status);
150
+ return r.json();
151
+ })
152
+ .catch(function(err) {
153
+ toast(err.message, "error");
154
+ throw err;
155
+ });
156
+ }
157
+
158
+ function load() {
159
+ api("tasks").then(function(data) {
160
+ tasks = data;
161
+ render();
162
+ });
163
+ }
164
+
165
+ function esc(s) {
166
+ var d = document.createElement("div");
167
+ d.textContent = s;
168
+ return d.innerHTML;
169
+ }
170
+
171
+ function render() {
172
+ var statuses = ["todo", "in-progress", "done"];
173
+ var labels = { "todo": "Todo", "in-progress": "In Progress", "done": "Done" };
174
+ var colClass = { "todo": "col-todo", "in-progress": "col-progress", "done": "col-done" };
175
+ var board = document.getElementById("board");
176
+ board.innerHTML = "";
177
+
178
+ statuses.forEach(function(status) {
179
+ var filtered = tasks.filter(function(t) { return t.status === status; }).sort(function(a, b) { return a.order - b.order; });
180
+
181
+ var col = document.createElement("div");
182
+ col.className = "column " + colClass[status];
183
+ col.setAttribute("data-status", status);
184
+
185
+ // Header
186
+ var header = document.createElement("div");
187
+ header.className = "col-header";
188
+ header.innerHTML = '<span class="col-title">' + labels[status] + '</span><span class="col-count">' + filtered.length + '</span>';
189
+ col.appendChild(header);
190
+
191
+ // Cards container
192
+ var cardsDiv = document.createElement("div");
193
+ cardsDiv.className = "cards";
194
+
195
+ if (filtered.length === 0) {
196
+ cardsDiv.innerHTML = '<div class="empty">No tasks here yet.<br>' + BOTNAME + ' is waiting for work! &#x1F43E;</div>';
197
+ } else {
198
+ filtered.forEach(function(task) {
199
+ var card = document.createElement("div");
200
+ card.className = "card";
201
+ card.draggable = true;
202
+ card.setAttribute("data-id", task.id);
203
+
204
+ var titleDiv = document.createElement("div");
205
+ titleDiv.className = "card-title";
206
+ titleDiv.contentEditable = "true";
207
+ titleDiv.textContent = task.title;
208
+ titleDiv.addEventListener("blur", function() {
209
+ var newTitle = this.textContent.trim();
210
+ if (newTitle && newTitle !== task.title) {
211
+ api("tasks/" + task.id, { method: "PUT", body: JSON.stringify({ title: newTitle }) });
212
+ task.title = newTitle;
213
+ }
214
+ });
215
+ card.appendChild(titleDiv);
216
+
217
+ if (task.description) {
218
+ var descDiv = document.createElement("div");
219
+ descDiv.className = "card-desc";
220
+ descDiv.contentEditable = "true";
221
+ descDiv.textContent = task.description;
222
+ descDiv.addEventListener("blur", function() {
223
+ var newDesc = this.textContent.trim();
224
+ api("tasks/" + task.id, { method: "PUT", body: JSON.stringify({ description: newDesc || undefined }) });
225
+ task.description = newDesc || undefined;
226
+ });
227
+ card.appendChild(descDiv);
228
+ }
229
+
230
+ var footer = document.createElement("div");
231
+ footer.className = "card-footer";
232
+
233
+ var priorityDiv = document.createElement("div");
234
+ priorityDiv.className = "priority";
235
+ ["high", "normal", "low"].forEach(function(p) {
236
+ var dot = document.createElement("div");
237
+ dot.className = "priority-dot " + p + (task.priority === p ? " active" : "");
238
+ dot.title = p.charAt(0).toUpperCase() + p.slice(1);
239
+ dot.addEventListener("click", function(e) {
240
+ e.stopPropagation();
241
+ api("tasks/" + task.id, { method: "PUT", body: JSON.stringify({ priority: p }) }).then(function() {
242
+ task.priority = p;
243
+ render();
244
+ });
245
+ });
246
+ priorityDiv.appendChild(dot);
247
+ });
248
+ footer.appendChild(priorityDiv);
249
+
250
+ var delBtn = document.createElement("span");
251
+ delBtn.className = "card-delete";
252
+ delBtn.innerHTML = "&#x2715;";
253
+ delBtn.addEventListener("click", function(e) {
254
+ e.stopPropagation();
255
+ api("tasks/" + task.id, { method: "DELETE" }).then(function() {
256
+ tasks = tasks.filter(function(t) { return t.id !== task.id; });
257
+ render();
258
+ });
259
+ });
260
+ footer.appendChild(delBtn);
261
+ card.appendChild(footer);
262
+
263
+ // Drag events
264
+ card.addEventListener("dragstart", function(e) {
265
+ dragId = task.id;
266
+ this.classList.add("dragging");
267
+ e.dataTransfer.effectAllowed = "move";
268
+ });
269
+ card.addEventListener("dragend", function() {
270
+ this.classList.remove("dragging");
271
+ dragId = null;
272
+ document.querySelectorAll(".column").forEach(function(c) { c.classList.remove("drag-over"); });
273
+ });
274
+
275
+ cardsDiv.appendChild(card);
276
+ });
277
+ }
278
+ col.appendChild(cardsDiv);
279
+
280
+ // Add button
281
+ var addBtn = document.createElement("button");
282
+ addBtn.type = "button";
283
+ addBtn.className = "add-btn";
284
+ addBtn.textContent = "+ Add task";
285
+ addBtn.addEventListener("click", function() {
286
+ formDiv.classList.add("show");
287
+ titleInput.focus();
288
+ });
289
+ col.appendChild(addBtn);
290
+
291
+ // Add form
292
+ var formDiv = document.createElement("div");
293
+ formDiv.className = "add-form";
294
+
295
+ var titleInput = document.createElement("input");
296
+ titleInput.type = "text";
297
+ titleInput.placeholder = "Task title...";
298
+ titleInput.addEventListener("keydown", function(e) {
299
+ if (e.key === "Enter") doSave();
300
+ });
301
+ formDiv.appendChild(titleInput);
302
+
303
+ var descInput = document.createElement("textarea");
304
+ descInput.placeholder = "Description (optional)";
305
+ descInput.rows = 2;
306
+ formDiv.appendChild(descInput);
307
+
308
+ var actions = document.createElement("div");
309
+ actions.className = "form-actions";
310
+
311
+ var cancelBtn = document.createElement("button");
312
+ cancelBtn.type = "button";
313
+ cancelBtn.className = "cancel";
314
+ cancelBtn.textContent = "Cancel";
315
+ cancelBtn.addEventListener("click", function() {
316
+ formDiv.classList.remove("show");
317
+ titleInput.value = "";
318
+ descInput.value = "";
319
+ });
320
+ actions.appendChild(cancelBtn);
321
+
322
+ var saveBtn = document.createElement("button");
323
+ saveBtn.type = "button";
324
+ saveBtn.className = "save";
325
+ saveBtn.textContent = "Add";
326
+
327
+ function doSave() {
328
+ var title = titleInput.value.trim();
329
+ if (!title) return;
330
+ var desc = descInput.value.trim();
331
+ saveBtn.disabled = true;
332
+ saveBtn.textContent = "...";
333
+ var body = { title: title, status: status, priority: "normal" };
334
+ if (desc) body.description = desc;
335
+ api("tasks", { method: "POST", body: JSON.stringify(body) })
336
+ .then(function(task) {
337
+ tasks.push(task);
338
+ render();
339
+ toast("Task added!");
340
+ })
341
+ .catch(function() {
342
+ saveBtn.disabled = false;
343
+ saveBtn.textContent = "Add";
344
+ });
345
+ }
346
+
347
+ saveBtn.addEventListener("click", doSave);
348
+ actions.appendChild(saveBtn);
349
+ formDiv.appendChild(actions);
350
+ col.appendChild(formDiv);
351
+
352
+ // Drop events on column
353
+ col.addEventListener("dragover", function(e) {
354
+ e.preventDefault();
355
+ e.dataTransfer.dropEffect = "move";
356
+ this.classList.add("drag-over");
357
+ });
358
+ col.addEventListener("dragleave", function() {
359
+ this.classList.remove("drag-over");
360
+ });
361
+ col.addEventListener("drop", function(e) {
362
+ e.preventDefault();
363
+ this.classList.remove("drag-over");
364
+ if (!dragId) return;
365
+ var newStatus = this.getAttribute("data-status");
366
+ var order = tasks.filter(function(t) { return t.status === newStatus; }).length;
367
+ api("tasks/" + dragId, { method: "PUT", body: JSON.stringify({ status: newStatus, order: order }) })
368
+ .then(function() {
369
+ var task = tasks.find(function(t) { return t.id === dragId; });
370
+ if (task) { task.status = newStatus; task.order = order; }
371
+ render();
372
+ });
373
+ });
374
+
375
+ board.appendChild(col);
376
+ });
377
+ }
378
+
379
+ // Theme switcher
380
+ document.querySelectorAll(".theme-dot").forEach(function(dot) {
381
+ dot.addEventListener("click", function() {
382
+ window.location.href = "/?theme=" + this.getAttribute("data-theme");
383
+ });
384
+ });
385
+
386
+ load();
387
+ </script>
388
+ </body>
389
+ </html>`;
390
+ }
391
+
392
+ //#endregion
393
+ //#region src/core/dashboard-server.ts
394
+ const CONFIG_DIR = path$1.join(os$1.homedir(), ".config", "openpaw");
395
+ const CONFIG_FILE = path$1.join(CONFIG_DIR, "dashboard.json");
396
+ function readConfig() {
397
+ try {
398
+ return JSON.parse(fs$1.readFileSync(CONFIG_FILE, "utf-8"));
399
+ } catch {
400
+ return {
401
+ theme: "paw",
402
+ botName: "Paw",
403
+ port: 3141,
404
+ tasks: []
405
+ };
406
+ }
407
+ }
408
+ function writeConfig(config) {
409
+ if (!fs$1.existsSync(CONFIG_DIR)) fs$1.mkdirSync(CONFIG_DIR, { recursive: true });
410
+ fs$1.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), "utf-8");
411
+ }
412
+ function parseBody(req) {
413
+ return new Promise((resolve, reject) => {
414
+ let body = "";
415
+ req.on("data", (chunk) => {
416
+ body += chunk.toString();
417
+ });
418
+ req.on("end", () => {
419
+ try {
420
+ resolve(body ? JSON.parse(body) : {});
421
+ } catch {
422
+ reject(new Error("Invalid JSON"));
423
+ }
424
+ });
425
+ req.on("error", reject);
426
+ });
427
+ }
428
+ function json(res, data, status = 200) {
429
+ res.writeHead(status, { "Content-Type": "application/json" });
430
+ res.end(JSON.stringify(data));
431
+ }
432
+ function html(res, content) {
433
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
434
+ res.end(content);
435
+ }
436
+ function startDashboard(opts) {
437
+ const config = readConfig();
438
+ if (opts.theme) config.theme = opts.theme;
439
+ if (opts.botName) config.botName = opts.botName;
440
+ if (opts.port) config.port = opts.port;
441
+ writeConfig(config);
442
+ const port = config.port || 3141;
443
+ const server = http.createServer(async (req, res) => {
444
+ const url = new URL(req.url || "/", `http://localhost:${port}`);
445
+ const method = req.method || "GET";
446
+ const pathname = url.pathname;
447
+ try {
448
+ if (method === "GET" && pathname === "/") {
449
+ const current = readConfig();
450
+ const themeParam = url.searchParams.get("theme");
451
+ if (themeParam && (themeParam === "paw" || themeParam === "midnight" || themeParam === "neon")) {
452
+ current.theme = themeParam;
453
+ writeConfig(current);
454
+ }
455
+ html(res, generateDashboardHTML(current.theme, current.botName));
456
+ return;
457
+ }
458
+ if (method === "GET" && pathname === "/api/tasks") {
459
+ json(res, readConfig().tasks);
460
+ return;
461
+ }
462
+ if (method === "POST" && pathname === "/api/tasks") {
463
+ const body = await parseBody(req);
464
+ const current = readConfig();
465
+ const task = {
466
+ id: crypto.randomUUID().slice(0, 8),
467
+ title: String(body.title || "Untitled"),
468
+ description: body.description ? String(body.description) : void 0,
469
+ status: body.status || "todo",
470
+ priority: body.priority || "normal",
471
+ order: current.tasks.filter((t) => t.status === (body.status || "todo")).length,
472
+ createdAt: new Date().toISOString()
473
+ };
474
+ current.tasks.push(task);
475
+ writeConfig(current);
476
+ json(res, task, 201);
477
+ return;
478
+ }
479
+ const putMatch = method === "PUT" && pathname.match(/^\/api\/tasks\/(.+)$/);
480
+ if (putMatch) {
481
+ const id = putMatch[1];
482
+ const body = await parseBody(req);
483
+ const current = readConfig();
484
+ const task = current.tasks.find((t) => t.id === id);
485
+ if (!task) {
486
+ json(res, { error: "Not found" }, 404);
487
+ return;
488
+ }
489
+ if (body.title !== void 0) task.title = String(body.title);
490
+ if (body.description !== void 0) task.description = body.description ? String(body.description) : void 0;
491
+ if (body.status !== void 0) task.status = body.status;
492
+ if (body.priority !== void 0) task.priority = body.priority;
493
+ if (body.order !== void 0) task.order = Number(body.order);
494
+ writeConfig(current);
495
+ json(res, task);
496
+ return;
497
+ }
498
+ const delMatch = method === "DELETE" && pathname.match(/^\/api\/tasks\/(.+)$/);
499
+ if (delMatch) {
500
+ const id = delMatch[1];
501
+ const current = readConfig();
502
+ current.tasks = current.tasks.filter((t) => t.id !== id);
503
+ writeConfig(current);
504
+ json(res, { ok: true });
505
+ return;
506
+ }
507
+ if (method === "GET" && pathname === "/api/config") {
508
+ const { theme, botName, port: p } = readConfig();
509
+ json(res, {
510
+ theme,
511
+ botName,
512
+ port: p
513
+ });
514
+ return;
515
+ }
516
+ json(res, { error: "Not found" }, 404);
517
+ } catch (err) {
518
+ json(res, { error: "Internal error" }, 500);
519
+ }
520
+ });
521
+ server.listen(port, () => {
522
+ const url = `http://localhost:${port}`;
523
+ console.log(`\n Dashboard running at ${url}\n`);
524
+ const platform = os$1.platform();
525
+ if (platform === "darwin") import("node:child_process").then((cp) => cp.exec(`open ${url}`));
526
+ else if (platform === "linux") import("node:child_process").then((cp) => cp.exec(`xdg-open ${url}`));
527
+ });
528
+ return server;
529
+ }
530
+
531
+ //#endregion
532
+ export { CONFIG_FILE, readConfig, startDashboard, writeConfig };
@@ -0,0 +1,3 @@
1
+ import { CONFIG_FILE, readConfig, startDashboard, writeConfig } from "./dashboard-server-BAyeozOa.js";
2
+
3
+ export { startDashboard };