Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-16550-reader-context-lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The code activity reader now accepts unchanged diff context lines (`op: ' '`) from a regions source and renders them in a neutral color with their space prefix, instead of dropping the whole region; the current published-checkpoint source still emits only `+`/`-` lines ([#16550](https://github.com/hivecommons/hive/issues/16550)).
21 changes: 12 additions & 9 deletions src/pkg/dashboard/reader_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestReaderUIWiring(t *testing.T) {
}
css := read("css/reader.css")
// Long text wraps at a fixed size and the feed scrolls natively.
for _, want := range []string{"white-space: pre-wrap; overflow-wrap: anywhere;", "body.reader-mode .reader-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto;", "font: 20px/1.5 monospace;"} {
for _, want := range []string{"white-space: pre-wrap; overflow-wrap: anywhere;", "body.reader-mode .reader-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto;", "font: 20px/1.5 monospace;", "body.reader-mode .reader-context { color: var(--reader-text); }"} {
if !strings.Contains(css, want) {
t.Errorf("reader.css missing %q", want)
}
Expand Down Expand Up @@ -98,16 +98,18 @@ const reader = fs.readFileSync('static-src/js/reader.js', 'utf8');
const boot = fs.readFileSync('static-src/js/boot.js', 'utf8').split('})();')[0] + '})();';
const at = '2026-11-03T12:00:00Z';
const first = [
{seq: 1, repo: 'org/repo', pr: 2, head: 'abc', path: 'main.go', line: '<script>alert(1)</script>', at},
{seq: 1, repo: 'org/repo', pr: 2, head: 'abc', path: 'main.go', line: '<script>alert(1)</script>', op: '+', at},
{seq: 2, repo: 'org/repo', pr: 2, head: 'abc', path: 'main.go', line: '', at},
{seq: 3, repo: 'org/repo', pr: 2, head: 'abc', path: 'main.go', line: '\tx := 1', at},
{seq: 4, repo: 'org/repo', pr: 2, head: 'abc', path: 'main.go', line: '\tx := 1', at},
{seq: 5, repo: 'org/repo', pr: 2, head: 'abc', path: 'main.go', line: ' old()', op: '-', at},
{seq: 6, repo: 'org/other', pr: 7, head: 'def', path: 'README.md', line: 'a very long line '.repeat(40), pr_url: 'https://github.com/org/other/pull/7', at},
{seq: 6, repo: 'org/repo', pr: 2, head: 'abc', path: 'main.go', line: '\tunchanged()', op: ' ', at},
{seq: 7, repo: 'org/repo', pr: 2, head: 'abc', path: 'main.go', line: '', op: ' ', at},
{seq: 8, repo: 'org/other', pr: 7, head: 'def', path: 'README.md', line: 'a very long line '.repeat(40), pr_url: 'https://github.com/org/other/pull/7', at},
];
async function scenario(query, opts = {}) {
const docEvents = {}, timers = new Map(), requests = [], scrolls = [], sse = {};
let id = 0, status = opts.status || 200, seq = 6, lines = first;
let id = 0, status = opts.status || 200, seq = 8, lines = first;
const elements = [];
function el(tag) { const e = {tagName: tag.toUpperCase(), children: [], listeners: {}, attrs: {}, className: '',
textContent: '', hidden: false, scrollTop: 0, offsetHeight: 10, classList: {add(){}},
Expand Down Expand Up @@ -186,9 +188,10 @@ async function scenario(query, opts = {}) {

const checkFirst = card => {
// One contiguous region: blank, indented and repeated lines kept as text.
assert.deepEqual(rows(card), ['+ <script>alert(1)</script>\n', '+ \n', '+ \tx := 1\n', '+ \tx := 1\n', '\u2212 old()\n']);
// Context retains its space prefix and stays neutral, including blank lines.
assert.deepEqual(rows(card), ['+ <script>alert(1)</script>\n', '+ \n', '+ \tx := 1\n', '+ \tx := 1\n', '\u2212 old()\n', ' \tunchanged()\n', ' \n']);
assert.equal(card.children[1].tagName, 'PRE');
assert.deepEqual(card.children[1].children.map(r => r.className), ['reader-line reader-add', 'reader-line reader-add', 'reader-line reader-add', 'reader-line reader-add', 'reader-line reader-del']);
assert.deepEqual(card.children[1].children.map(r => r.className), ['reader-line reader-add', 'reader-line reader-add', 'reader-line reader-add', 'reader-line reader-add', 'reader-line reader-del', 'reader-line reader-context', 'reader-line reader-context']);
const [repo, file, stage, delivery, time] = meta(card);
assert.equal(repo.tagName, 'A'); assert.equal(repo.textContent, 'org/repo #2');
assert.equal(repo.href, 'https://github.com/org/repo/pull/2'); assert.equal(repo.attrs.rel, 'noopener noreferrer');
Expand All @@ -206,7 +209,7 @@ async function scenario(query, opts = {}) {
// Static and scrollable: everything shown at once, nothing scheduled or scrolled.
assert.equal(feed.children.length, 2); assert.equal(timers.size, 0); assert.equal(scrolls.length, 0);
checkFirst(feed.children[0]); checkSecond(feed.children[1]);
lines = [{seq: 7, repo: 'org/repo', pr: 2, head: 'abc', path: 'b.go', line: 'next', at}]; seq = 7;
lines = [{seq: 9, repo: 'org/repo', pr: 2, head: 'abc', path: 'b.go', line: 'next', at}]; seq = 9;
sse['code-lines'](); await flush();
assert.equal(feed.children.length, 3); assert.equal(timers.size, 0); assert.equal(scrolls.length, 0);
return;
Expand All @@ -216,9 +219,9 @@ async function scenario(query, opts = {}) {
assert.equal(timers.size, 1); assert.equal(scrolls.at(-1).behavior, 'smooth');
assert(statusEl.textContent.includes('1 change waiting'));
// Incoming work queues behind the paragraph being read.
lines = [{seq: 7, repo: 'org/repo', pr: 2, head: 'abc', path: 'b.go', line: 'next', at}]; seq = 7;
lines = [{seq: 9, repo: 'org/repo', pr: 2, head: 'abc', path: 'b.go', line: 'next', at}]; seq = 9;
sse['code-lines'](); await flush();
assert.equal(requests.at(-1), '/api/matrix/lines?since=6&format=regions');
assert.equal(requests.at(-1), '/api/matrix/lines?since=8&format=regions');
assert.equal(feed.children.length, 1); assert.equal(timers.size, 1);
// P pauses and resumes; the button mirrors it.
key('p'); assert.equal(timers.size, 0); assert.equal(button.textContent, 'Resume');
Expand Down
1 change: 1 addition & 0 deletions src/pkg/dashboard/static-src/css/reader.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ body.reader-mode a.reader-repo { text-decoration: underline; }
body.reader-mode .reader-diff { margin: .5rem 0 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
body.reader-mode .reader-add { color: var(--reader-add); }
body.reader-mode .reader-del { color: var(--reader-del); }
body.reader-mode .reader-context { color: var(--reader-text); }
body.reader-mode #hive-reader [hidden] { display: none !important; }
body.reader-mode #kiosk-cta { position: fixed; right: var(--sp-6); bottom: var(--sp-6); z-index: 100001; opacity: .85; }
8 changes: 4 additions & 4 deletions src/pkg/dashboard/static-src/js/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
function group(regions){
regions.forEach(function(region){
if (!region || !Array.isArray(region.lines) || !region.lines.length) return;
if (!region.lines.every(function(line){ return line && typeof line.line === 'string' && (line.op === '+' || line.op === '-'); })) return;
if (!region.lines.every(function(line){ return line && typeof line.line === 'string' && (line.op === '+' || line.op === '-' || line.op === ' '); })) return;
var size = region.lines.reduce(function(n, line){ return n + line.line.length * 2; }, 0);
if (region.lines.length > MAX_LINES || size > MAX_BYTES) return;
var item = {repo: region.repo, pr: region.pr, path: region.path, prURL: region.pr_url,
Expand Down Expand Up @@ -104,9 +104,9 @@
if (when.iso) time.setAttribute('datetime', when.iso);
var diff = element('pre', 'reader-diff', '', article);
region.lines.forEach(function(line){
var removed = line.op === '-';
var row = element('span', 'reader-line ' + (removed ? 'reader-del' : 'reader-add'), '', diff);
row.textContent = (removed ? '\u2212 ' : '+ ') + line.line + '\n';
var removed = line.op === '-', context = line.op === ' ';
var row = element('span', 'reader-line ' + (removed ? 'reader-del' : context ? 'reader-context' : 'reader-add'), '', diff);
row.textContent = (removed ? '\u2212 ' : context ? ' ' : '+ ') + line.line + '\n';
});
return article;
}
Expand Down
9 changes: 5 additions & 4 deletions src/pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7122,6 +7122,7 @@
body.reader-mode .reader-diff { margin: .5rem 0 0; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
body.reader-mode .reader-add { color: var(--reader-add); }
body.reader-mode .reader-del { color: var(--reader-del); }
body.reader-mode .reader-context { color: var(--reader-text); }
body.reader-mode #hive-reader [hidden] { display: none !important; }
body.reader-mode #kiosk-cta { position: fixed; right: var(--sp-6); bottom: var(--sp-6); z-index: 100001; opacity: .85; }
.var-empty{color:var(--muted);font-size:var(--fs-sm);padding:var(--sp-2) var(--sp-0)}
Expand Down Expand Up @@ -7541,7 +7542,7 @@
function group(regions){
regions.forEach(function(region){
if (!region || !Array.isArray(region.lines) || !region.lines.length) return;
if (!region.lines.every(function(line){ return line && typeof line.line === 'string' && (line.op === '+' || line.op === '-'); })) return;
if (!region.lines.every(function(line){ return line && typeof line.line === 'string' && (line.op === '+' || line.op === '-' || line.op === ' '); })) return;
var size = region.lines.reduce(function(n, line){ return n + line.line.length * 2; }, 0);
if (region.lines.length > MAX_LINES || size > MAX_BYTES) return;
var item = {repo: region.repo, pr: region.pr, path: region.path, prURL: region.pr_url,
Expand Down Expand Up @@ -7594,9 +7595,9 @@
if (when.iso) time.setAttribute('datetime', when.iso);
var diff = element('pre', 'reader-diff', '', article);
region.lines.forEach(function(line){
var removed = line.op === '-';
var row = element('span', 'reader-line ' + (removed ? 'reader-del' : 'reader-add'), '', diff);
row.textContent = (removed ? '\u2212 ' : '+ ') + line.line + '\n';
var removed = line.op === '-', context = line.op === ' ';
var row = element('span', 'reader-line ' + (removed ? 'reader-del' : context ? 'reader-context' : 'reader-add'), '', diff);
row.textContent = (removed ? '\u2212 ' : context ? ' ' : '+ ') + line.line + '\n';
});
return article;
}
Expand Down
Loading