claude-code-kanban 7.25.0 → 7.27.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.
- package/hub-app.json +5 -2
- package/lib/parsers.js +65 -7
- package/lib/retention.js +10 -1
- package/lib/show.js +89 -51
- package/mod-surface.json +38 -0
- package/package.json +2 -1
- package/public/app.js +671 -146
- package/public/index.html +41 -9
- package/public/style.css +364 -65
- package/public/vendor/claude-hub-sdk.js +4 -2
- package/server.js +41 -6
package/hub-app.json
CHANGED
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
"name": "Kanban",
|
|
5
5
|
"icon": "columns",
|
|
6
6
|
"run": { "entry": "server.js", "defaultPort": 3541 },
|
|
7
|
-
"publishes": ["session.changed"],
|
|
7
|
+
"publishes": ["session.changed", "voice.context"],
|
|
8
8
|
"actions": {
|
|
9
9
|
"handles": {
|
|
10
10
|
"session.open": { "params": { "session": "string" }, "mode": "message" },
|
|
11
11
|
"session.find": { "params": { "name": "string?" }, "mode": "message" },
|
|
12
12
|
"session.paste": { "params": { "text": "string", "submit": "string?", "session": "string?" }, "mode": "message" },
|
|
13
|
+
"session.approve": { "params": {}, "mode": "message" },
|
|
14
|
+
"session.deny": { "params": { "message": "string?" }, "mode": "message" },
|
|
15
|
+
"session.next": { "params": {}, "mode": "message" },
|
|
13
16
|
"task.add": { "params": { "subject": "string?", "description": "string?" }, "mode": "message" },
|
|
14
17
|
"task.live": { "params": { "subject": "string?", "description": "string?", "pending": "string?", "final": "string?", "submit": "string?", "cancel": "string?" }, "mode": "message" },
|
|
15
18
|
"session.live": { "params": { "text": "string", "final": "string?", "submit": "string?", "cancel": "string?", "session": "string?" }, "mode": "message" },
|
|
@@ -52,7 +55,7 @@
|
|
|
52
55
|
"default": "dots"
|
|
53
56
|
}
|
|
54
57
|
],
|
|
55
|
-
"keys": { "keeps": ["ctrl+alt+1", "ctrl+alt+2", "ctrl+alt+3", "ctrl+alt+4", "ctrl+alt+5", "ctrl+alt+6", "ctrl+alt+7", "ctrl+alt+8", "ctrl+alt+9", "ctrl+alt+n", "ctrl+alt+r", "ctrl+alt+s", "ctrl+shift+d", "ctrl+shift+k", "ctrl+shift+l", "ctrl+shift+m", "ctrl+shift+p", "ctrl+shift+z"] },
|
|
58
|
+
"keys": { "keeps": ["ctrl+alt+1", "ctrl+alt+2", "ctrl+alt+3", "ctrl+alt+4", "ctrl+alt+5", "ctrl+alt+6", "ctrl+alt+7", "ctrl+alt+8", "ctrl+alt+9", "ctrl+alt+n", "ctrl+alt+r", "ctrl+alt+s", "ctrl+alt+shift+s","ctrl+shift+d", "ctrl+shift+k", "ctrl+shift+l", "ctrl+shift+m", "ctrl+shift+p", "ctrl+shift+z"] },
|
|
56
59
|
"plugin": {
|
|
57
60
|
"marketplace": "plugin",
|
|
58
61
|
"name": "claude-code-kanban",
|
package/lib/parsers.js
CHANGED
|
@@ -371,6 +371,8 @@ function scrapeScalarFromBlob(blob, re) {
|
|
|
371
371
|
|
|
372
372
|
const sessionInfoCache = new Map();
|
|
373
373
|
const SESSION_INFO_CACHE_MAX = 2000;
|
|
374
|
+
const SCAN_HEAD_MAX = 1048576;
|
|
375
|
+
const BACK_CHUNK = 65536;
|
|
374
376
|
|
|
375
377
|
// A prompt line carries the mode it was sent in. After a Shift+Tab, Claude Code writes an
|
|
376
378
|
// auto_mode / auto_mode_exit attachment with the next tool result, and later rewrites a
|
|
@@ -388,6 +390,54 @@ const modeOf = (data) => {
|
|
|
388
390
|
const scratchpadOf = (data) =>
|
|
389
391
|
(data.type === 'attachment' && data.attachment?.type === 'environment' && data.attachment.snapshot?.scratchpadDirectory) || null;
|
|
390
392
|
|
|
393
|
+
const LAST_SCRATCHPAD_MAX = 16 * 1048576;
|
|
394
|
+
|
|
395
|
+
function scratchpadInLine(line) {
|
|
396
|
+
if (!line.includes('"scratchpadDirectory"')) return null;
|
|
397
|
+
try {
|
|
398
|
+
return scratchpadOf(JSON.parse(line.toString('utf8')));
|
|
399
|
+
} catch {
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// The last scratchpad dir recorded in [lower, upper) of an open transcript, at most
|
|
405
|
+
// LAST_SCRATCHPAD_MAX bytes back. The cold scan reads only a head and a tail, so it needs this for a
|
|
406
|
+
// record in the middle of a large transcript: docs/session-scanning.md. Bytes after the last newline
|
|
407
|
+
// before `upper` are not read as a line.
|
|
408
|
+
function lastScratchpadIn(fd, lower, upper) {
|
|
409
|
+
lower = Math.max(lower, upper - LAST_SCRATCHPAD_MAX);
|
|
410
|
+
// The bytes after the last newline read so far, in file order. Kept as pieces, so a line longer
|
|
411
|
+
// than a chunk is joined once and not on every read.
|
|
412
|
+
const tail = [];
|
|
413
|
+
const takeLine = () => scratchpadInLine(tail.length === 1 ? tail[0] : Buffer.concat(tail.splice(0)));
|
|
414
|
+
let pos = upper;
|
|
415
|
+
let complete = false;
|
|
416
|
+
let dir = null;
|
|
417
|
+
while (!dir && pos > lower) {
|
|
418
|
+
const len = Math.min(BACK_CHUNK, pos - lower);
|
|
419
|
+
pos -= len;
|
|
420
|
+
const chunk = Buffer.allocUnsafe(len);
|
|
421
|
+
if (fs.readSync(fd, chunk, 0, len, pos) < len) break;
|
|
422
|
+
let end = len;
|
|
423
|
+
while (!dir && end > 0) {
|
|
424
|
+
const nl = chunk.lastIndexOf(10, end - 1);
|
|
425
|
+
if (nl < 0) break;
|
|
426
|
+
if (complete) {
|
|
427
|
+
tail.unshift(chunk.subarray(nl + 1, end));
|
|
428
|
+
dir = takeLine();
|
|
429
|
+
} else {
|
|
430
|
+
complete = true;
|
|
431
|
+
}
|
|
432
|
+
tail.length = 0;
|
|
433
|
+
end = nl;
|
|
434
|
+
}
|
|
435
|
+
if (!dir && end > 0) tail.unshift(chunk.subarray(0, end));
|
|
436
|
+
}
|
|
437
|
+
if (!dir && complete && pos === lower && tail.length) dir = takeLine();
|
|
438
|
+
return dir;
|
|
439
|
+
}
|
|
440
|
+
|
|
391
441
|
const isMainReply = (data) =>
|
|
392
442
|
data.type === 'assistant' && !data.isSidechain && data.message?.usage && data.message.model !== '<synthetic>';
|
|
393
443
|
|
|
@@ -444,6 +494,8 @@ function readSessionInfoFromJsonl(jsonlPath) {
|
|
|
444
494
|
const canIncrement = sameFileGrown(cached, stat);
|
|
445
495
|
|
|
446
496
|
if (canIncrement && stat.size === cached.scannedUpTo) {
|
|
497
|
+
sessionInfoCache.delete(jsonlPath);
|
|
498
|
+
sessionInfoCache.set(jsonlPath, cached);
|
|
447
499
|
return {
|
|
448
500
|
slug: cached.slug,
|
|
449
501
|
projectPath: cached.projectPath,
|
|
@@ -504,8 +556,6 @@ function readSessionInfoFromJsonl(jsonlPath) {
|
|
|
504
556
|
|
|
505
557
|
const CHUNK_SIZE = 16384;
|
|
506
558
|
const TAIL_SIZE = 16384;
|
|
507
|
-
const HEAD_MAX = 1048576;
|
|
508
|
-
const BACK_CHUNK = 65536;
|
|
509
559
|
const BACK_MAX = 2097152;
|
|
510
560
|
let scannedUpTo = canIncrement ? cached.scannedUpTo : 0;
|
|
511
561
|
|
|
@@ -536,7 +586,7 @@ function readSessionInfoFromJsonl(jsonlPath) {
|
|
|
536
586
|
const buf = Buffer.alloc(CHUNK_SIZE);
|
|
537
587
|
let leftover = '';
|
|
538
588
|
let offset = 0;
|
|
539
|
-
while (offset < stat.size && offset <
|
|
589
|
+
while (offset < stat.size && offset < SCAN_HEAD_MAX) {
|
|
540
590
|
const len = Math.min(CHUNK_SIZE, stat.size - offset);
|
|
541
591
|
const n = fs.readSync(fd, buf, 0, len, offset);
|
|
542
592
|
if (n === 0) break;
|
|
@@ -557,7 +607,7 @@ function readSessionInfoFromJsonl(jsonlPath) {
|
|
|
557
607
|
if (!result.gitBranch) result.gitBranch = scrapeScalarFromBlob(leftover, SCRAPE_GITBRANCH_RE);
|
|
558
608
|
}
|
|
559
609
|
|
|
560
|
-
// Tail scan catches late cwd switches past
|
|
610
|
+
// Tail scan catches late cwd switches past SCAN_HEAD_MAX. projectPath stays
|
|
561
611
|
// anchored to the earliest cwd — it is never overwritten here.
|
|
562
612
|
// The first window is TAIL_SIZE. A tail of one long line (11% of transcripts over 1 MB)
|
|
563
613
|
// holds no reply, so it reads further back in BACK_CHUNK steps until it finds one.
|
|
@@ -612,8 +662,12 @@ function readSessionInfoFromJsonl(jsonlPath) {
|
|
|
612
662
|
if (latestTailCwd) lastCwdSeen = latestTailCwd;
|
|
613
663
|
if (latestTailMode) result.permissionMode = latestTailMode;
|
|
614
664
|
if (latestTailTtl) result.cacheTtl = latestTailTtl;
|
|
615
|
-
// A record in the unread middle would be newer than the head's, so the head's
|
|
616
|
-
if (latestTailScratchpad
|
|
665
|
+
// A record in the unread middle would be newer than the head's, so the head's is the last resort.
|
|
666
|
+
if (latestTailScratchpad) result.scratchpadDir = latestTailScratchpad;
|
|
667
|
+
else if (!reachedHead) {
|
|
668
|
+
const parsedFrom = end === window.length ? stat.size : stat.size - window.length + end + 1;
|
|
669
|
+
result.scratchpadDir = lastScratchpadIn(fd, offset, parsedFrom) || result.scratchpadDir;
|
|
670
|
+
}
|
|
617
671
|
if (latestTailUserTs || !reachedHead) lastUserTs = latestTailUserTs;
|
|
618
672
|
if (tailReply) {
|
|
619
673
|
const reply = replyOf(tailReply, tailRequestTs);
|
|
@@ -634,6 +688,7 @@ function readSessionInfoFromJsonl(jsonlPath) {
|
|
|
634
688
|
result.cwd = lastCwdSeen;
|
|
635
689
|
|
|
636
690
|
if (stat) {
|
|
691
|
+
sessionInfoCache.delete(jsonlPath);
|
|
637
692
|
sessionInfoCache.set(jsonlPath, {
|
|
638
693
|
ino: stat.ino,
|
|
639
694
|
mtimeMs: stat.mtimeMs,
|
|
@@ -649,6 +704,7 @@ function readSessionInfoFromJsonl(jsonlPath) {
|
|
|
649
704
|
cacheTtl: result.cacheTtl,
|
|
650
705
|
lastReply: result.lastReply,
|
|
651
706
|
scratchpadDir: result.scratchpadDir,
|
|
707
|
+
scratchpadMiddleRead: true,
|
|
652
708
|
lastUserTs
|
|
653
709
|
});
|
|
654
710
|
if (sessionInfoCache.size > SESSION_INFO_CACHE_MAX) {
|
|
@@ -725,6 +781,8 @@ function exportSessionCaches() {
|
|
|
725
781
|
function importSessionCaches(snapshot) {
|
|
726
782
|
const num = (v) => typeof v === 'number';
|
|
727
783
|
const scanned = (e) => num(e.ino) && num(e.scannedUpTo) && num(e.mtimeMs);
|
|
784
|
+
// An older cck dropped a record in the unread middle of a large transcript, so that entry is scanned again.
|
|
785
|
+
const scannedInfo = (e) => scanned(e) && (e.scratchpadDir || e.scratchpadMiddleRead || e.scannedUpTo <= SCAN_HEAD_MAX);
|
|
728
786
|
const grown = (e) => num(e.ino) && num(e.size) && num(e.mtimeMs);
|
|
729
787
|
const load = (map, entries, valid) => {
|
|
730
788
|
if (!Array.isArray(entries)) return;
|
|
@@ -733,7 +791,7 @@ function importSessionCaches(snapshot) {
|
|
|
733
791
|
map.set(pair[0], pair[1]);
|
|
734
792
|
}
|
|
735
793
|
};
|
|
736
|
-
load(sessionInfoCache, snapshot?.info?.slice(-SESSION_INFO_CACHE_MAX),
|
|
794
|
+
load(sessionInfoCache, snapshot?.info?.slice(-SESSION_INFO_CACHE_MAX), scannedInfo);
|
|
737
795
|
load(customTitleCache, snapshot?.titles?.slice(-SESSION_INFO_CACHE_MAX), scanned);
|
|
738
796
|
load(logActivityCache, snapshot?.activity?.slice(-SESSION_INFO_CACHE_MAX), grown);
|
|
739
797
|
}
|
package/lib/retention.js
CHANGED
|
@@ -88,6 +88,15 @@ function createDispatchedStore({ load, save, now = Date.now }) {
|
|
|
88
88
|
return true;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// Returns whether the flag changed; writes only then.
|
|
92
|
+
function setChild(id, child) {
|
|
93
|
+
const e = entries.get(id);
|
|
94
|
+
if (!e || e.child === child) return false;
|
|
95
|
+
e.child = child;
|
|
96
|
+
persist();
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
// Returns how many entries went; writes only when one did.
|
|
92
101
|
function prune({ known, maxAgeMs }) {
|
|
93
102
|
const removed = pruneMap(entries, (e) => e.at, { known, maxAgeMs, now: now() });
|
|
@@ -105,7 +114,7 @@ function createDispatchedStore({ load, save, now = Date.now }) {
|
|
|
105
114
|
return out;
|
|
106
115
|
}
|
|
107
116
|
|
|
108
|
-
return { record, move, prune, running, get: (id) => entries.get(id) || null, entries: () => entries.entries() };
|
|
117
|
+
return { record, move, setChild, prune, running, get: (id) => entries.get(id) || null, entries: () => entries.entries() };
|
|
109
118
|
}
|
|
110
119
|
|
|
111
120
|
// Names only, no stat or parse: the sweep needs which transcripts exist, not what they hold.
|
package/lib/show.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The show overlay's server side: posts a terminal's session makes through the plugin's show tool.
|
|
2
2
|
// The card belongs to the terminal and the posts to the session, so the store maps terminal id
|
|
3
|
-
// to its current session
|
|
3
|
+
// to its current session. Storage: docs/show.md.
|
|
4
4
|
|
|
5
5
|
const crypto = require('node:crypto');
|
|
6
6
|
const fs = require('node:fs');
|
|
@@ -8,6 +8,7 @@ const path = require('node:path');
|
|
|
8
8
|
const express = require('express');
|
|
9
9
|
const { startFolder } = require('./folder-dialog');
|
|
10
10
|
const { httpError } = require('./http-error');
|
|
11
|
+
const { writeJsonAtomic } = require('./write-json-atomic');
|
|
11
12
|
|
|
12
13
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
13
14
|
const SHOW_PATH = '/api/terminals/:terminalId/show';
|
|
@@ -36,22 +37,12 @@ function parsePost(body) {
|
|
|
36
37
|
return { sessionId, title, key: key ?? null, kind, file: file ?? null, base: base ?? null };
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
function writeAtomic(file, text) {
|
|
40
|
-
const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
41
|
-
try {
|
|
42
|
-
fs.writeFileSync(tmp, text, 'utf8');
|
|
43
|
-
fs.renameSync(tmp, file);
|
|
44
|
-
} catch (e) {
|
|
45
|
-
fs.rmSync(tmp, { force: true });
|
|
46
|
-
throw e;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
40
|
/**
|
|
51
41
|
* @param {object} o
|
|
52
42
|
* @param {() => Object<string, string>|null} o.load terminal id → session id, as saved
|
|
53
43
|
* @param {() => void} o.onChange the map changed and should be saved
|
|
54
|
-
* @param {(sessionId: string) => string|null} o.resolveDir the session's
|
|
44
|
+
* @param {(sessionId: string) => string|null} o.resolveDir the folder of the session's index, null when its transcript is unknown
|
|
45
|
+
* @param {(sessionId: string) => string[]} [o.scratchpadDirs] the session's show folders in its scratchpads, newest first: new claims go in the first, and an older cck kept its index in any of them
|
|
55
46
|
* @param {(terminalId: string) => string|null} [o.startedSession] the session a live terminal was started with
|
|
56
47
|
* @param {(e: object) => void} [o.onPosted] a post was made or its file changed on disk, once per terminal showing its session
|
|
57
48
|
* @param {() => number} [o.now]
|
|
@@ -62,22 +53,36 @@ function createShowStore(o) {
|
|
|
62
53
|
const watchers = new Map();
|
|
63
54
|
// Post id → the claim file's mtime as cck last saw it, so a second watch event for one save is not a change.
|
|
64
55
|
const seen = new Map();
|
|
56
|
+
// An older cck cannot write a legacy index while this one runs, so each session is probed once.
|
|
57
|
+
const probed = new Set();
|
|
58
|
+
const scratchpadDirs = o.scratchpadDirs || (() => []);
|
|
65
59
|
for (const [terminalId, sessionId] of Object.entries(o.load?.() || {})) {
|
|
66
60
|
if (UUID_RE.test(terminalId) && typeof sessionId === 'string' && UUID_RE.test(sessionId)) current.set(terminalId, sessionId);
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
function folder(sessionId) {
|
|
70
64
|
const dir = o.resolveDir(sessionId);
|
|
71
|
-
|
|
65
|
+
if (dir && !probed.has(sessionId)) {
|
|
66
|
+
probed.add(sessionId);
|
|
67
|
+
if (!fs.existsSync(path.join(dir, 'index.json'))) adopt(sessionId, dir);
|
|
68
|
+
}
|
|
69
|
+
return dir;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
// Older versions kept the index beside the claims in the session's scratchpad, which Claude Code
|
|
73
|
+
// can move. The claims stay where they are; the first folder wins a post id both hold.
|
|
74
|
+
function adopt(sessionId, dir) {
|
|
75
|
+
const byId = new Map();
|
|
76
|
+
for (const legacy of scratchpadDirs(sessionId)) {
|
|
77
|
+
for (const p of readPosts(legacy)) {
|
|
78
|
+
if (!p || !UUID_RE.test(p.id) || !Object.hasOwn(EXT, p.kind) || byId.has(p.id)) continue;
|
|
79
|
+
byId.set(p.id, p.file ? p : { ...p, claim: path.join(legacy, `${p.id}.${EXT[p.kind]}`) });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (byId.size) writeIndex(dir, sessionId, [...byId.values()]);
|
|
76
83
|
}
|
|
77
84
|
|
|
78
|
-
|
|
79
|
-
return entry.file || contentPath(dir, entry);
|
|
80
|
-
}
|
|
85
|
+
const postPath = (entry) => entry.file || entry.claim;
|
|
81
86
|
|
|
82
87
|
function locate(terminalId, postId) {
|
|
83
88
|
const sessionId = sessionOf(terminalId);
|
|
@@ -87,7 +92,7 @@ function createShowStore(o) {
|
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
function writeIndex(dir, sessionId, posts) {
|
|
90
|
-
|
|
95
|
+
writeJsonAtomic(path.join(dir, 'index.json'), { sessionId, posts });
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
function notify(sessionId, entry, at, count, replaced) {
|
|
@@ -98,14 +103,15 @@ function createShowStore(o) {
|
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
|
|
101
|
-
function touch(sessionId,
|
|
102
|
-
const
|
|
106
|
+
function touch(sessionId, postId) {
|
|
107
|
+
const dir = folder(sessionId);
|
|
108
|
+
const posts = dir ? readPosts(dir) : [];
|
|
103
109
|
const at = posts.findIndex((p) => p.id === postId);
|
|
104
110
|
const entry = posts[at];
|
|
105
111
|
if (!entry || entry.file) return;
|
|
106
112
|
let mtime;
|
|
107
113
|
try {
|
|
108
|
-
mtime = fs.statSync(
|
|
114
|
+
mtime = fs.statSync(entry.claim).mtimeMs;
|
|
109
115
|
} catch {
|
|
110
116
|
return;
|
|
111
117
|
}
|
|
@@ -116,14 +122,33 @@ function createShowStore(o) {
|
|
|
116
122
|
notify(sessionId, entry, at, posts.length, true);
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
// A session's claims can sit in more than one folder, because Claude Code can move a live
|
|
126
|
+
// session's scratchpad, for example when an update renames its root.
|
|
127
|
+
function watch(sessionId, posts) {
|
|
128
|
+
if (!o.onPosted) return;
|
|
129
|
+
const dirs = new Set(posts.filter((p) => !p.file).map((p) => path.dirname(p.claim)));
|
|
130
|
+
const open = watchers.get(sessionId) || new Map();
|
|
131
|
+
for (const [d, close] of open) {
|
|
132
|
+
if (dirs.has(d)) continue;
|
|
133
|
+
close();
|
|
134
|
+
open.delete(d);
|
|
135
|
+
}
|
|
136
|
+
for (const d of dirs) {
|
|
137
|
+
if (open.has(d)) continue;
|
|
138
|
+
const close = watchDir(sessionId, d);
|
|
139
|
+
if (close) open.set(d, close);
|
|
140
|
+
}
|
|
141
|
+
if (open.size) watchers.set(sessionId, open);
|
|
142
|
+
else watchers.delete(sessionId);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function watchDir(sessionId, dir) {
|
|
121
146
|
let w;
|
|
122
147
|
try {
|
|
123
148
|
// libuv aborts the process on a change under an 8.3 short path (NIKIFO~1), so watch the long form.
|
|
124
149
|
w = fs.watch(fs.realpathSync.native(dir));
|
|
125
150
|
} catch {
|
|
126
|
-
return;
|
|
151
|
+
return null;
|
|
127
152
|
}
|
|
128
153
|
w.unref();
|
|
129
154
|
const timers = new Map();
|
|
@@ -136,7 +161,7 @@ function createShowStore(o) {
|
|
|
136
161
|
const t = setTimeout(() => {
|
|
137
162
|
timers.delete(id);
|
|
138
163
|
try {
|
|
139
|
-
touch(sessionId,
|
|
164
|
+
touch(sessionId, id);
|
|
140
165
|
} catch (e) {
|
|
141
166
|
console.error('[show] refresh failed:', e.message);
|
|
142
167
|
}
|
|
@@ -145,14 +170,14 @@ function createShowStore(o) {
|
|
|
145
170
|
timers.set(id, t);
|
|
146
171
|
});
|
|
147
172
|
w.on('error', () => unwatch(sessionId));
|
|
148
|
-
|
|
173
|
+
return () => {
|
|
149
174
|
for (const t of timers.values()) clearTimeout(t);
|
|
150
175
|
w.close();
|
|
151
|
-
}
|
|
176
|
+
};
|
|
152
177
|
}
|
|
153
178
|
|
|
154
179
|
function unwatch(sessionId) {
|
|
155
|
-
watchers.get(sessionId)?.();
|
|
180
|
+
for (const close of watchers.get(sessionId)?.values() || []) close();
|
|
156
181
|
watchers.delete(sessionId);
|
|
157
182
|
}
|
|
158
183
|
|
|
@@ -169,17 +194,23 @@ function createShowStore(o) {
|
|
|
169
194
|
return [];
|
|
170
195
|
}
|
|
171
196
|
|
|
172
|
-
function
|
|
173
|
-
|
|
197
|
+
function move(from, to) {
|
|
198
|
+
try {
|
|
199
|
+
fs.renameSync(from, to);
|
|
200
|
+
} catch (e) {
|
|
201
|
+
if (e.code !== 'EXDEV') throw e;
|
|
202
|
+
fs.copyFileSync(from, to);
|
|
203
|
+
fs.rmSync(from, { force: true });
|
|
204
|
+
}
|
|
174
205
|
}
|
|
175
206
|
|
|
176
207
|
// The kind of `file` when it is the post's own claimed file, else null: posting that path as a
|
|
177
|
-
// file post would
|
|
178
|
-
function ownContentKind(
|
|
208
|
+
// file post would delete it.
|
|
209
|
+
function ownContentKind(claim, id, file) {
|
|
179
210
|
const m = CONTENT_FILE_RE.exec(path.basename(file));
|
|
180
211
|
if (!m || m[1].toLowerCase() !== id.toLowerCase()) return null;
|
|
181
212
|
const real = (p) => { try { return fs.realpathSync.native(p); } catch { return path.resolve(p); } };
|
|
182
|
-
if (real(path.dirname(file)).toLowerCase() !== real(
|
|
213
|
+
if (real(path.dirname(file)).toLowerCase() !== real(path.dirname(claim)).toLowerCase()) return null;
|
|
183
214
|
return Object.keys(EXT).find((k) => EXT[k] === m[2].toLowerCase());
|
|
184
215
|
}
|
|
185
216
|
|
|
@@ -208,30 +239,34 @@ function createShowStore(o) {
|
|
|
208
239
|
function post(terminalId, { sessionId, title, key, kind, file, base }) {
|
|
209
240
|
const dir = folder(sessionId);
|
|
210
241
|
if (!dir) throw httpError(409, 'no transcript found for that session');
|
|
211
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
212
242
|
const posts = readPosts(dir);
|
|
213
243
|
let at = key == null ? -1 : posts.findIndex((p) => p.key === key);
|
|
214
244
|
const old = at >= 0 ? posts[at] : null;
|
|
215
245
|
const id = old ? old.id : crypto.randomUUID();
|
|
216
|
-
const
|
|
246
|
+
const oldClaim = old?.claim || null;
|
|
247
|
+
const ownKind = oldClaim && file != null ? ownContentKind(oldClaim, id, file) : null;
|
|
217
248
|
if (ownKind) {
|
|
218
249
|
kind = ownKind;
|
|
219
250
|
file = null;
|
|
220
251
|
}
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
252
|
+
let target = null;
|
|
253
|
+
if (file == null) {
|
|
254
|
+
const into = scratchpadDirs(sessionId)[0] || dir;
|
|
255
|
+
fs.mkdirSync(into, { recursive: true });
|
|
256
|
+
target = path.join(into, `${id}.${EXT[kind]}`);
|
|
257
|
+
}
|
|
258
|
+
if (target && oldClaim) {
|
|
259
|
+
if (oldClaim !== target && fs.existsSync(oldClaim)) move(oldClaim, target);
|
|
260
|
+
} else if (oldClaim) {
|
|
261
|
+
fs.rmSync(oldClaim, { force: true });
|
|
227
262
|
seen.delete(id);
|
|
228
263
|
}
|
|
229
264
|
if (!old) at = posts.length;
|
|
230
|
-
const entry = { id, title, key, kind, file, base, updatedAt: new Date(now()).toISOString() };
|
|
265
|
+
const entry = { id, title, key, kind, file, base, claim: target, updatedAt: new Date(now()).toISOString() };
|
|
231
266
|
posts[at] = entry;
|
|
232
267
|
writeIndex(dir, sessionId, posts);
|
|
233
268
|
bind(terminalId, sessionId);
|
|
234
|
-
watch(sessionId,
|
|
269
|
+
watch(sessionId, posts);
|
|
235
270
|
notify(sessionId, entry, at, posts.length, !!old);
|
|
236
271
|
return { id, title, key, index: at + 1, count: posts.length, replaced: !!old, path: target };
|
|
237
272
|
}
|
|
@@ -241,16 +276,16 @@ function createShowStore(o) {
|
|
|
241
276
|
if (!sessionId) return { sessionId: null, posts: [] };
|
|
242
277
|
const dir = folder(sessionId);
|
|
243
278
|
const posts = dir ? readPosts(dir) : [];
|
|
244
|
-
if (posts.length) watch(sessionId,
|
|
279
|
+
if (posts.length) watch(sessionId, posts);
|
|
245
280
|
return { sessionId, posts };
|
|
246
281
|
}
|
|
247
282
|
|
|
248
283
|
// The post's index entry and its stored content; `waiting` when a claim file is not written yet.
|
|
249
284
|
function get(terminalId, postId) {
|
|
250
|
-
const {
|
|
285
|
+
const { posts, at } = locate(terminalId, postId);
|
|
251
286
|
if (at < 0) return null;
|
|
252
287
|
const entry = posts[at];
|
|
253
|
-
const file = postPath(
|
|
288
|
+
const file = postPath(entry);
|
|
254
289
|
if (entry.file) return { entry, content: null, path: file };
|
|
255
290
|
try {
|
|
256
291
|
return { entry, content: fs.readFileSync(file, 'utf8'), path: file };
|
|
@@ -268,9 +303,12 @@ function createShowStore(o) {
|
|
|
268
303
|
unwatch(sessionId);
|
|
269
304
|
for (const p of readPosts(dir)) {
|
|
270
305
|
seen.delete(p.id);
|
|
271
|
-
paths.push(postPath(
|
|
306
|
+
paths.push(postPath(p));
|
|
307
|
+
if (p.claim) fs.rmSync(p.claim, { force: true });
|
|
272
308
|
}
|
|
273
309
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
310
|
+
// Else the next board run adopts the cleared posts again.
|
|
311
|
+
for (const legacy of scratchpadDirs(sessionId)) fs.rmSync(path.join(legacy, 'index.json'), { force: true });
|
|
274
312
|
}
|
|
275
313
|
return { sessionId, paths };
|
|
276
314
|
}
|
|
@@ -281,9 +319,9 @@ function createShowStore(o) {
|
|
|
281
319
|
if (at < 0) return null;
|
|
282
320
|
const [entry] = posts.splice(at, 1);
|
|
283
321
|
writeIndex(dir, sessionId, posts);
|
|
284
|
-
|
|
322
|
+
if (entry.claim) fs.rmSync(entry.claim, { force: true });
|
|
285
323
|
seen.delete(postId);
|
|
286
|
-
return { sessionId, count: posts.length, path: postPath(
|
|
324
|
+
return { sessionId, count: posts.length, path: postPath(entry) };
|
|
287
325
|
}
|
|
288
326
|
|
|
289
327
|
// Drops the terminals that `keep` no longer knows, and gives the map to save.
|
package/mod-surface.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"surface": 1,
|
|
3
|
+
"functions": {
|
|
4
|
+
"renderTaskCard": "(task) -> the HTML string of one board card. Return the same string for the same task: the board rewrites a column only when its HTML changes.",
|
|
5
|
+
"renderSessions": "() -> rebuilds the session list in the sidebar. It returns early while the user drags or types in the list.",
|
|
6
|
+
"renderKanban": "() -> rebuilds the three board columns from currentTasks.",
|
|
7
|
+
"renderActivityChip": "() -> {waiting, active, terminal}: counts the sessions in each state and redraws the chips above the session list when the counts change. It runs on every session poll."
|
|
8
|
+
},
|
|
9
|
+
"events": {
|
|
10
|
+
"sessions.rendered": "After each renderSessions call, also one that returned early.",
|
|
11
|
+
"board.rendered": "After each renderKanban call.",
|
|
12
|
+
"activity.rendered": "After each renderActivityChip call, with its {waiting, active, terminal} counts as the detail. A waiting session also counts as active."
|
|
13
|
+
},
|
|
14
|
+
"parts": {
|
|
15
|
+
"sidebar": "The sidebar: header, session list, footer.",
|
|
16
|
+
"sessions": "The session list.",
|
|
17
|
+
"board": "The board with its three columns.",
|
|
18
|
+
"session-card": "One session in the session list, with data-session-id.",
|
|
19
|
+
"sidebar-footer": "The footer under the session list. Its children are rebuilt on each poll; the element stays.",
|
|
20
|
+
"progress": "The track of the progress bar in the session header.",
|
|
21
|
+
"progress-fill": "The fill inside progress, whose width is the share of the session's tasks done.",
|
|
22
|
+
"kanbot": "The Kanbot mascot, a 16x13 svg whose head is x 3-13 at the top row. It sits in the sidebar footer's button and in the Kanbot panel's head.",
|
|
23
|
+
"idle-mascot": "The mascot over the empty state, an svg.clawd that floats up and down.",
|
|
24
|
+
"task-card": "One card on the board, with data-task-id and data-session-id.",
|
|
25
|
+
"task-number": "The #id label at the top left of a task card.",
|
|
26
|
+
"done-title": "The title of the Completed column."
|
|
27
|
+
},
|
|
28
|
+
"states": {
|
|
29
|
+
"session-card": {
|
|
30
|
+
"active": "While it is the open session."
|
|
31
|
+
},
|
|
32
|
+
"task-card": {
|
|
33
|
+
"pending": "Not started.",
|
|
34
|
+
"in-progress": "Being worked on.",
|
|
35
|
+
"completed": "Done."
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-kanban",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.27.0",
|
|
4
4
|
"description": "A web-based Kanban board for viewing Claude Code tasks with agent teams support",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"files": [
|
|
56
56
|
"server.js",
|
|
57
57
|
"hub-app.json",
|
|
58
|
+
"mod-surface.json",
|
|
58
59
|
"cli.js",
|
|
59
60
|
"install.js",
|
|
60
61
|
"plugin/**/*",
|