Files
devdesk/web/src/repo.js
T
jaredandClaude Opus 5.5 a2edec966a
build-deb / Notify on failure (push) Successful in 4s
build-deb / Lint, test, package (push) Failing after 2m22s
build-deb / Deploy to CT 126 (push) Skipped
feat: v0.10.0 quieter Matrix, worktrees, usage pace, repo diffs, copy reply, turn timer, compact
- Matrix "needs you": ignore Claude's idle reminder (no red, no post); post
  only when no tab is in view, after 60 s, once per session per 10 min, and
  say what is asked. Closes #50
- devdesk new NAME PROJECT --worktree: own checkout on devdesk/NAME,
  cleaned up on end when clean/merged. Closes #44
- Usage meters: reset time, pace warning; Matrix ping past 90% when away.
  Closes #45
- Repo panel lists changed files; click opens the diff. Closes #46
- Copy Claude's last reply (--last-reply). Closes #47
- Turn timer in chip, title and cards. Closes #48
- Compact button at 80% context when idle. Closes #49

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WHRLCCdXYm41Qx5kNhehaP
2026-10-11 23:28:11 -04:00

106 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Repo / CI panel: git state of the current session's folder plus the Gitea CI
// status of its HEAD commit (`devdesk attach --repo <session>`).
const CI = {
success: ['passing', 'lt-status-completed'],
failure: ['failed', 'lt-status-failed'],
error: ['error', 'lt-status-failed'],
pending: ['running', 'lt-status-running'],
warning: ['warning', 'lt-status-pending'],
};
function link(href, text) {
const a = document.createElement('a');
a.href = href;
a.target = '_blank';
a.rel = 'noopener';
a.textContent = text;
return a;
}
// hooks: openDiff(path, diffable), openChanges() (devdesk#46)
export function renderRepo(root, repo, hooks = {}) {
const field = (name) => root.querySelector(`[data-field="${name}"]`);
const set = (name, value) => field(name).replaceChildren(value);
const grid = root.querySelector('.dd-repo-grid');
const note = root.querySelector('.dd-repo-note');
const fix = root.querySelector('.dd-fix-ci');
fix.hidden = true;
const changes = root.querySelector('.dd-repo-changes');
changes.hidden = true;
// No repository: one line instead of a grid of dashes (devdesk#17).
if (!repo || !repo.git) {
root.dataset.state = 'empty';
grid.hidden = true;
note.textContent = repo ? `Not a git repository: ${repo.dir}` : 'Open a session to see its repository.';
return;
}
root.dataset.state = 'live';
grid.hidden = false;
set('repo', repo.url ? link(repo.url, repo.repo) : (repo.remote || 'no remote'));
const sync = repo.upstream
? [repo.ahead ? `↑${repo.ahead}` : '', repo.behind ? `↓${repo.behind}` : ''].filter(Boolean).join(' ') || 'in sync'
: 'no upstream';
set('branch', `${repo.branch} @ ${repo.sha || '—'} · ${sync}`);
if (repo.dirty) {
const all = document.createElement('button');
all.type = 'button';
all.className = 'dd-link-btn';
all.textContent = `${repo.dirty} changed`;
all.title = 'Review all changes';
all.addEventListener('click', () => hooks.openChanges?.());
set('dirty', all);
} else {
set('dirty', 'clean');
}
// The first changed files: click one for its diff against HEAD.
const files = (repo.changes ?? []).filter((f) => f.path !== null && f.path !== undefined);
if (files.length) {
changes.hidden = false;
changes.replaceChildren(...files.map((f) => {
const diffable = f.x !== '?' && f.y !== '?';
const code = f.x === '?' ? 'new' : (f.x !== ' ' ? f.x : f.y);
const li = document.createElement('li');
const b = document.createElement('button');
b.type = 'button';
b.className = 'dd-repo-change';
b.title = `${f.path}${diffable ? ' · diff against HEAD' : ' · new file'}${f.claude ? ' · edited by Claude' : ''}`;
const name = document.createElement('span');
name.className = 'dd-repo-change-name';
name.textContent = f.path;
const stat = document.createElement('span');
stat.className = 'dd-repo-change-stat';
stat.textContent = [f.add ? `+${f.add}` : '', f.del ? `−${f.del}` : '', code === 'new' ? 'new' : code.trim()]
.filter(Boolean).join(' ');
b.append(name, stat);
b.addEventListener('click', () => hooks.openDiff?.(f.path, diffable));
li.append(b);
return li;
}));
if (repo.dirty > files.length) {
const more = document.createElement('li');
more.className = 'dd-muted';
more.textContent = `+${repo.dirty - files.length} more`;
changes.append(more);
}
}
const ci = field('ci');
const [label, cls] = repo.ci?.total ? (CI[repo.ci.state] || [repo.ci.state, 'lt-status-pending'])
: [repo.ahead ? 'not pushed' : 'no CI', ''];
ci.className = `lt-status ${cls}`;
ci.replaceChildren(repo.ci?.url ? link(repo.ci.url, label) : label);
set('prs', repo.url && repo.prs != null ? link(`${repo.url}/pulls`, `${repo.prs} open`) : '—');
note.textContent = repo.repo ? '' : 'Not a Gitea repository; CI status unavailable.';
if (repo.ci?.total && ['failure', 'error'].includes(repo.ci.state)) {
fix.hidden = false;
fix.dataset.askClaude = `CI is failing for ${repo.repo} on ${repo.branch} at ${repo.sha}`
+ ` (${repo.ci.url || 'see Gitea Actions'}). Use the gitea MCP server to read the failed job's log,`
+ ' find the cause, and fix it. Tell me the plan before pushing anything.';
}
}