harness-bujang 0.6.0 → 0.6.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.
@@ -45,6 +45,16 @@ async function runChat(args) {
45
45
  `INSERT INTO harness_messages (id, "from", "to", type, message, severity)
46
46
  VALUES (?, ?, ?, ?, ?, ?)`
47
47
  );
48
+ const readStateRowsStmt = db.prepare(
49
+ `SELECT room, last_seen_at FROM harness_read_state`
50
+ );
51
+ const readStateUpsertStmt = db.prepare(
52
+ `INSERT INTO harness_read_state (room, last_seen_at, updated_at)
53
+ VALUES (?, ?, strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
54
+ ON CONFLICT(room) DO UPDATE SET
55
+ last_seen_at = excluded.last_seen_at,
56
+ updated_at = excluded.updated_at`
57
+ );
48
58
  const port = await findOpenPort(opts.port);
49
59
  const server = http.createServer(async (req, res) => {
50
60
  const url2 = new URL(req.url ?? "/", `http://localhost:${port}`);
@@ -89,6 +99,39 @@ async function runChat(args) {
89
99
  }
90
100
  return;
91
101
  }
102
+ if (req.method === "GET" && url2.pathname === "/api/read-state") {
103
+ try {
104
+ const rows = readStateRowsStmt.all();
105
+ const map = {};
106
+ for (const r of rows) map[r.room] = r.last_seen_at;
107
+ res.writeHead(200, { "content-type": "application/json" });
108
+ res.end(JSON.stringify({ data: map }));
109
+ } catch (err) {
110
+ res.writeHead(500, { "content-type": "application/json" });
111
+ res.end(JSON.stringify({ data: {}, error: String(err) }));
112
+ }
113
+ return;
114
+ }
115
+ if (req.method === "POST" && url2.pathname === "/api/read-state") {
116
+ try {
117
+ const body = await readBody(req);
118
+ const parsed = JSON.parse(body);
119
+ const room = (parsed.room ?? "").trim();
120
+ const lastSeenAt = (parsed.last_seen_at ?? "").trim();
121
+ if (!room || !lastSeenAt) {
122
+ res.writeHead(400, { "content-type": "application/json" });
123
+ res.end(JSON.stringify({ error: "room and last_seen_at are required" }));
124
+ return;
125
+ }
126
+ readStateUpsertStmt.run(room, lastSeenAt);
127
+ res.writeHead(200, { "content-type": "application/json" });
128
+ res.end(JSON.stringify({ data: { room, last_seen_at: lastSeenAt } }));
129
+ } catch (err) {
130
+ res.writeHead(500, { "content-type": "application/json" });
131
+ res.end(JSON.stringify({ error: String(err) }));
132
+ }
133
+ return;
134
+ }
92
135
  res.writeHead(404);
93
136
  res.end("not found");
94
137
  });
@@ -203,6 +246,14 @@ var SCHEMA_SQL = `
203
246
  );
204
247
  CREATE INDEX IF NOT EXISTS harness_messages_timestamp_idx ON harness_messages(timestamp DESC);
205
248
  CREATE INDEX IF NOT EXISTS harness_messages_from_to_idx ON harness_messages("from", "to");
249
+
250
+ -- 0.6.1: per-room read marker (chat.db is the single source of truth, so
251
+ -- read state survives port changes / server restarts / browsers).
252
+ CREATE TABLE IF NOT EXISTS harness_read_state (
253
+ room TEXT PRIMARY KEY,
254
+ last_seen_at TEXT NOT NULL,
255
+ updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
256
+ );
206
257
  `;
207
258
  function renderHtml() {
208
259
  return (
@@ -290,12 +341,16 @@ const ROOMS = [
290
341
  { id: '\uC678\uBD80\uD300\uC6D0', name: '\uC678\uBD80\uD300\uC6D0', icon: '\u{1F310}', members: ['\uBD80\uC7A5', '\uC678\uBD80\uD300\uC6D0', '\uACF5\uB3D9\uB300\uD45C'] },
291
342
  ];
292
343
 
293
- const STORAGE_KEY = 'harness-bujang-read';
294
344
  const FILTER_KEY = 'harness-bujang-filter';
345
+ // 0.6.1: Read state moved server-side (chat.db harness_read_state table) so
346
+ // it survives port changes / server restarts / different browsers. The
347
+ // localStorage 'harness-bujang-read' key from 0.5.x\u20130.6.0 is now ignored
348
+ // (no migration needed \u2014 server first-run auto-marks current state as read).
295
349
  const state = {
296
350
  messages: [],
297
351
  selectedRoom: null,
298
- readCounts: JSON.parse(localStorage.getItem(STORAGE_KEY) || '{}'),
352
+ /** room id \u2192 last_seen_at ISO timestamp. Populated by GET /api/read-state. */
353
+ readByRoom: {},
299
354
  filter: localStorage.getItem(FILTER_KEY) || 'all', // 'all' | 'unread'
300
355
  loading: true,
301
356
  };
@@ -374,11 +429,16 @@ function render() {
374
429
  const infos = state.messages.filter((m) => m.severity === 'info').length;
375
430
 
376
431
  // Pre-compute unread per room (for the filter button + badges).
432
+ // 0.6.1: count messages newer than the per-room last_seen_at marker
433
+ // returned by the server. Survives port changes / server restarts.
377
434
  const unreadByRoom = {};
378
435
  let totalUnread = 0;
379
436
  for (const room of ROOMS) {
380
- const count = filterMessages(state.messages, room.id).length;
381
- const unread = Math.max(0, count - (state.readCounts[room.id] || 0));
437
+ const roomMsgs = filterMessages(state.messages, room.id);
438
+ const lastSeen = state.readByRoom[room.id];
439
+ const unread = lastSeen
440
+ ? roomMsgs.filter((m) => m.timestamp > lastSeen).length
441
+ : roomMsgs.length;
382
442
  unreadByRoom[room.id] = unread;
383
443
  totalUnread += unread;
384
444
  }
@@ -529,12 +589,24 @@ function render() {
529
589
  });
530
590
 
531
591
  // Re-bind room-click handlers (room list).
592
+ // 0.6.1: persist read marker via POST /api/read-state (server is SoT) and
593
+ // also update the in-memory map so the badge clears immediately without
594
+ // waiting for the next 2s poll.
532
595
  document.querySelectorAll('[data-room-id]').forEach((el) => {
533
596
  el.addEventListener('click', () => {
534
- state.selectedRoom = el.getAttribute('data-room-id');
535
- const count = filterMessages(state.messages, state.selectedRoom).length;
536
- state.readCounts[state.selectedRoom] = count;
537
- localStorage.setItem(STORAGE_KEY, JSON.stringify(state.readCounts));
597
+ const roomId = el.getAttribute('data-room-id');
598
+ state.selectedRoom = roomId;
599
+ const last = getLastMessage(state.messages, roomId);
600
+ if (last) {
601
+ state.readByRoom[roomId] = last.timestamp;
602
+ // Fire-and-forget; if it fails the next 2s poll re-syncs from the
603
+ // server. We don't block the UI on the round-trip.
604
+ fetch('/api/read-state', {
605
+ method: 'POST',
606
+ headers: { 'content-type': 'application/json' },
607
+ body: JSON.stringify({ room: roomId, last_seen_at: last.timestamp }),
608
+ }).catch(() => {});
609
+ }
538
610
  render();
539
611
  const conv = document.getElementById('conversation');
540
612
  if (conv) conv.scrollTop = conv.scrollHeight;
@@ -560,9 +632,15 @@ function render() {
560
632
 
561
633
  async function refresh() {
562
634
  try {
563
- const res = await fetch('/api/messages?days=14');
564
- const json = await res.json();
565
- state.messages = (json.data || []).map((m) => ({
635
+ // 0.6.1: fetch messages + read-state in parallel. chat.db is SoT for
636
+ // read state, so port/server/browser changes don't reset it.
637
+ const [msgRes, readRes] = await Promise.all([
638
+ fetch('/api/messages?days=14'),
639
+ fetch('/api/read-state'),
640
+ ]);
641
+ const msgJson = await msgRes.json();
642
+ const readJson = await readRes.json();
643
+ state.messages = (msgJson.data || []).map((m) => ({
566
644
  id: m.id,
567
645
  timestamp: m.timestamp,
568
646
  from: m.from,
@@ -571,6 +649,32 @@ async function refresh() {
571
649
  message: m.message,
572
650
  severity: m.severity || undefined,
573
651
  }));
652
+ state.readByRoom = readJson.data || {};
653
+
654
+ // First-run auto-mark: if the server returned an empty read-state but we
655
+ // have messages, this is a fresh upgrade from 0.6.0. Mark every room's
656
+ // current last message as read so the user only sees genuinely-new
657
+ // messages flagged unread from here on.
658
+ if (
659
+ Object.keys(state.readByRoom).length === 0 &&
660
+ state.messages.length > 0
661
+ ) {
662
+ const initial = {};
663
+ for (const room of ROOMS) {
664
+ const last = getLastMessage(state.messages, room.id);
665
+ if (last) initial[room.id] = last.timestamp;
666
+ }
667
+ state.readByRoom = initial;
668
+ // Persist to server (fire-and-forget per room \u2014 small N, ~18 calls).
669
+ for (const [room, ts] of Object.entries(initial)) {
670
+ fetch('/api/read-state', {
671
+ method: 'POST',
672
+ headers: { 'content-type': 'application/json' },
673
+ body: JSON.stringify({ room, last_seen_at: ts }),
674
+ }).catch(() => {});
675
+ }
676
+ }
677
+
574
678
  state.loading = false;
575
679
  render();
576
680
  } catch (e) {
package/dist/index.js CHANGED
@@ -113,7 +113,7 @@ async function main() {
113
113
  await (await import("./status-UE2TQQPU.js")).runStatus(args.slice(1));
114
114
  break;
115
115
  case "chat":
116
- await (await import("./chat-6VQQYMBV.js")).runChat(args.slice(1));
116
+ await (await import("./chat-XVTJ3XM7.js")).runChat(args.slice(1));
117
117
  break;
118
118
  case "adapt":
119
119
  await (await import("./adapt-VPWOYF6W.js")).runAdapt(args.slice(1));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-bujang",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Install the Harness-Bujang multi-agent harness into any project — Director, 7 specialist teams, real-time chat-room UI. Korean and English personas. Works with Claude Code, Cursor, Cline, Aider, or any tool that reads .claude/agents/.",
5
5
  "keywords": [
6
6
  "claude-code",