@lincolness/ponte 0.1.0 → 0.2.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/CHANGELOG.md +5 -0
- package/README.md +33 -0
- package/package.json +3 -2
- package/src/env.ts +41 -0
- package/src/index.ts +17 -36
- package/src/session-tool.ts +114 -0
- package/src/sessions-pi.ts +171 -0
- package/src/sessions.ts +538 -0
- package/src/viewer.ts +344 -0
package/src/viewer.ts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// Visualizador HTML (arquivo único, offline) das sessões de um projeto.
|
|
2
|
+
|
|
3
|
+
import { LEVELS, fmtDate, renderSession, sessionTitle, type Item, type Level, type LoadedSession } from "./sessions.ts";
|
|
4
|
+
|
|
5
|
+
interface ViewSession {
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
created: string;
|
|
9
|
+
updated: string;
|
|
10
|
+
models: string[];
|
|
11
|
+
turns: number;
|
|
12
|
+
kb: number;
|
|
13
|
+
otherBranch: number;
|
|
14
|
+
items: Item[];
|
|
15
|
+
texts: Record<Level, string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function toView(s: LoadedSession): ViewSession {
|
|
19
|
+
const texts = Object.fromEntries(LEVELS.map((l) => [l, renderSession(s, l)])) as Record<Level, string>;
|
|
20
|
+
return {
|
|
21
|
+
id: s.meta.id,
|
|
22
|
+
title: sessionTitle(s.meta),
|
|
23
|
+
created: fmtDate(s.meta.created),
|
|
24
|
+
updated: fmtDate(s.meta.updated),
|
|
25
|
+
models: s.meta.models,
|
|
26
|
+
turns: s.meta.userTurns,
|
|
27
|
+
kb: Math.round(s.meta.bytes / 1024),
|
|
28
|
+
otherBranch: s.otherBranch,
|
|
29
|
+
items: s.items,
|
|
30
|
+
texts,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** JSON seguro para ir dentro de <script>. */
|
|
35
|
+
function embed(data: unknown): string {
|
|
36
|
+
return JSON.stringify(data).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function esc(s: string): string {
|
|
40
|
+
return s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]!);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function renderViewer(project: string, sessions: LoadedSession[], generated: string): string {
|
|
44
|
+
const data = [...sessions].sort((a, b) => (a.meta.updated < b.meta.updated ? 1 : -1)).map(toView);
|
|
45
|
+
return `<!doctype html>
|
|
46
|
+
<html lang="pt-BR">
|
|
47
|
+
<head>
|
|
48
|
+
<meta charset="utf-8">
|
|
49
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
50
|
+
<title>Sessões · ${esc(project)}</title>
|
|
51
|
+
<style>
|
|
52
|
+
:root {
|
|
53
|
+
--bg: #f6f5f2; --panel: #ffffff; --ink: #1d1d1b; --muted: #6b6a66; --line: #e3e1db;
|
|
54
|
+
--user: #eef3fb; --user-line: #c9d8f0; --accent: #2f5fb3; --err: #b3261e; --err-bg: #fbeceb;
|
|
55
|
+
--code: #f1efea; --mark: #ffe58a; --chip: #efede7;
|
|
56
|
+
color-scheme: light;
|
|
57
|
+
}
|
|
58
|
+
@media (prefers-color-scheme: dark) {
|
|
59
|
+
:root:not([data-theme="light"]) {
|
|
60
|
+
--bg: #161614; --panel: #1e1e1c; --ink: #e9e7e2; --muted: #9b998f; --line: #33322e;
|
|
61
|
+
--user: #1d2635; --user-line: #34486a; --accent: #8fb3ff; --err: #ff8a80; --err-bg: #3a1f1d;
|
|
62
|
+
--code: #262623; --mark: #6b5600; --chip: #2a2a27;
|
|
63
|
+
color-scheme: dark;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
:root[data-theme="dark"] {
|
|
67
|
+
--bg: #161614; --panel: #1e1e1c; --ink: #e9e7e2; --muted: #9b998f; --line: #33322e;
|
|
68
|
+
--user: #1d2635; --user-line: #34486a; --accent: #8fb3ff; --err: #ff8a80; --err-bg: #3a1f1d;
|
|
69
|
+
--code: #262623; --mark: #6b5600; --chip: #2a2a27;
|
|
70
|
+
color-scheme: dark;
|
|
71
|
+
}
|
|
72
|
+
* { box-sizing: border-box; }
|
|
73
|
+
html, body { margin: 0; height: 100%; }
|
|
74
|
+
body { background: var(--bg); color: var(--ink); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
75
|
+
header { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
|
|
76
|
+
padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
|
|
77
|
+
header h1 { font-size: 15px; margin: 0 8px 0 0; font-weight: 650; }
|
|
78
|
+
header h1 small { color: var(--muted); font-weight: 400; }
|
|
79
|
+
input[type=search] { flex: 1 1 220px; min-width: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
|
|
80
|
+
background: var(--bg); color: var(--ink); font: inherit; }
|
|
81
|
+
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
|
|
82
|
+
.seg button { border: 0; background: transparent; color: var(--ink); padding: 6px 11px; font: inherit; cursor: pointer; }
|
|
83
|
+
.seg button[aria-pressed=true] { background: var(--accent); color: var(--panel); }
|
|
84
|
+
button.act { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 11px; border-radius: 8px;
|
|
85
|
+
font: inherit; cursor: pointer; }
|
|
86
|
+
button.act:hover { border-color: var(--accent); }
|
|
87
|
+
.wrap { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; height: calc(100% - 58px); }
|
|
88
|
+
nav { overflow: auto; border-right: 1px solid var(--line); background: var(--panel); }
|
|
89
|
+
nav .s { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
|
|
90
|
+
nav .s:hover { background: var(--bg); }
|
|
91
|
+
nav .s[aria-current=true] { background: var(--user); box-shadow: inset 3px 0 0 var(--accent); }
|
|
92
|
+
nav .s input { grid-row: span 2; margin-top: 3px; }
|
|
93
|
+
nav .s .t { font-weight: 560; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
|
|
94
|
+
nav .s .m { color: var(--muted); font-size: 12.5px; }
|
|
95
|
+
nav .s.hit .t::after { content: " •"; color: var(--accent); }
|
|
96
|
+
nav .tools { display: flex; gap: 8px; padding: 8px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
|
|
97
|
+
nav .tools a { color: var(--accent); cursor: pointer; }
|
|
98
|
+
main { overflow: auto; padding: 18px clamp(16px, 4vw, 48px) 80px; }
|
|
99
|
+
.meta { color: var(--muted); font-size: 13px; margin: -4px 0 18px; }
|
|
100
|
+
main h2 { font-size: 19px; margin: 0 0 6px; }
|
|
101
|
+
.msg { max-width: 860px; margin: 0 0 14px; }
|
|
102
|
+
.who { font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
|
|
103
|
+
.user .body { background: var(--user); border: 1px solid var(--user-line); border-radius: 10px; padding: 9px 13px; }
|
|
104
|
+
.body { overflow-wrap: anywhere; }
|
|
105
|
+
.body p { margin: 0 0 8px; white-space: pre-wrap; }
|
|
106
|
+
.body p:last-child { margin-bottom: 0; }
|
|
107
|
+
.body h4 { font-size: 15px; margin: 12px 0 6px; }
|
|
108
|
+
.tbl { overflow-x: auto; margin: 6px 0 10px; }
|
|
109
|
+
.tbl table { border-collapse: collapse; font-size: 13.5px; }
|
|
110
|
+
.tbl th, .tbl td { border: 1px solid var(--line); padding: 4px 9px; text-align: left; vertical-align: top; }
|
|
111
|
+
.tbl th { background: var(--chip); font-weight: 600; }
|
|
112
|
+
.body pre, details pre { white-space: pre; overflow: auto; background: var(--code); padding: 9px 11px; border-radius: 8px;
|
|
113
|
+
font: 12.5px/1.45 ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; margin: 6px 0; }
|
|
114
|
+
.body code { background: var(--code); padding: 0 4px; border-radius: 4px; font: 0.9em ui-monospace, Menlo, Consolas, monospace; }
|
|
115
|
+
.think { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); font-size: 13.5px; margin-bottom: 6px; white-space: pre-wrap; }
|
|
116
|
+
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 12px; max-width: 860px; }
|
|
117
|
+
.chip { background: var(--chip); border-radius: 999px; padding: 2px 10px; font-size: 12.5px; color: var(--muted); }
|
|
118
|
+
.chip.err { background: var(--err-bg); color: var(--err); }
|
|
119
|
+
details.tool { max-width: 860px; margin: 0 0 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
|
|
120
|
+
details.tool summary { cursor: pointer; padding: 5px 10px; font: 12.5px/1.5 ui-monospace, Menlo, Consolas, monospace;
|
|
121
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; list-style: none; }
|
|
122
|
+
details.tool summary::before { content: "▸ "; color: var(--muted); }
|
|
123
|
+
details.tool[open] summary::before { content: "▾ "; }
|
|
124
|
+
details.tool.err { border-color: var(--err); }
|
|
125
|
+
details.tool + .msg, details.tool + .note { margin-top: 12px; }
|
|
126
|
+
details.tool.err summary { color: var(--err); }
|
|
127
|
+
details.tool > div { padding: 0 10px 8px; }
|
|
128
|
+
.note { color: var(--muted); font-size: 13px; font-style: italic; margin: 0 0 12px; max-width: 860px; white-space: pre-wrap; }
|
|
129
|
+
.sum { max-width: 860px; border: 1px dashed var(--line); border-radius: 10px; padding: 9px 13px; margin: 0 0 16px; }
|
|
130
|
+
.sum b { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
|
|
131
|
+
mark { background: var(--mark); color: inherit; border-radius: 2px; }
|
|
132
|
+
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
|
|
133
|
+
padding: 8px 14px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; }
|
|
134
|
+
.toast.on { opacity: 1; }
|
|
135
|
+
.empty { color: var(--muted); padding: 40px 0; }
|
|
136
|
+
@media (max-width: 760px) {
|
|
137
|
+
.wrap { grid-template-columns: 1fr; height: auto; }
|
|
138
|
+
nav { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
|
|
139
|
+
main { overflow: visible; }
|
|
140
|
+
}
|
|
141
|
+
</style>
|
|
142
|
+
</head>
|
|
143
|
+
<body>
|
|
144
|
+
<header>
|
|
145
|
+
<h1>Sessões <small>· ${esc(project)} · gerado ${esc(generated)}</small></h1>
|
|
146
|
+
<input type="search" id="q" placeholder="Buscar em todas as sessões…" autocomplete="off">
|
|
147
|
+
<div class="seg" role="group" aria-label="Nível de detalhe">
|
|
148
|
+
<button data-level="conversa" title="Só o que você e o assistente escreveram">Conversa</button>
|
|
149
|
+
<button data-level="normal" title="Mais uma linha por ferramenta">Normal</button>
|
|
150
|
+
<button data-level="completo" title="Mais diffs, saídas e raciocínio">Completo</button>
|
|
151
|
+
</div>
|
|
152
|
+
<button class="act" id="copy" title="Copia as sessões marcadas (ou a aberta) no nível escolhido">Copiar para o chat</button>
|
|
153
|
+
<button class="act" id="dl">Baixar .txt</button>
|
|
154
|
+
</header>
|
|
155
|
+
<div class="wrap">
|
|
156
|
+
<nav>
|
|
157
|
+
<div class="tools"><span id="count"></span><a id="all">marcar todas</a><a id="none">limpar</a></div>
|
|
158
|
+
<div id="list"></div>
|
|
159
|
+
</nav>
|
|
160
|
+
<main id="view"></main>
|
|
161
|
+
</div>
|
|
162
|
+
<div class="toast" id="toast"></div>
|
|
163
|
+
<script id="data" type="application/json">${embed(data)}</script>
|
|
164
|
+
<script>
|
|
165
|
+
const S = JSON.parse(document.getElementById("data").textContent);
|
|
166
|
+
const st = { level: "normal", cur: S[0] ? S[0].id : null, checked: new Set(), q: "" };
|
|
167
|
+
try { st.level = localStorage.getItem("ponte.level") || st.level; } catch {}
|
|
168
|
+
const $ = (id) => document.getElementById(id);
|
|
169
|
+
const esc = (s) => String(s ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
170
|
+
|
|
171
|
+
function hl(html) {
|
|
172
|
+
if (!st.q) return html;
|
|
173
|
+
const terms = st.q.toLowerCase().split(/\\s+/).filter(Boolean).map((t) => t.replace(/[.*+?^\${}()|[\\]\\\\]/g, "\\\\$&"));
|
|
174
|
+
if (!terms.length) return html;
|
|
175
|
+
const re = new RegExp("(" + terms.join("|") + ")", "gi");
|
|
176
|
+
return html.split(/(<[^>]+>)/).map((p) => (p.startsWith("<") ? p : p.replace(re, "<mark>$1</mark>"))).join("");
|
|
177
|
+
}
|
|
178
|
+
function inline(s) {
|
|
179
|
+
return esc(s).replace(/\`([^\`\\n]+)\`/g, "<code>$1</code>").replace(/\\*\\*([^*\\n]+)\\*\\*/g, "<b>$1</b>");
|
|
180
|
+
}
|
|
181
|
+
function mdText(text) {
|
|
182
|
+
const out = [];
|
|
183
|
+
for (const chunk of String(text).split(/\\n\\s*\\n/)) {
|
|
184
|
+
const lines = chunk.split("\\n").filter((l) => l.trim() !== "");
|
|
185
|
+
if (!lines.length) continue;
|
|
186
|
+
if (lines.length > 1 && lines.every((l) => l.trim().startsWith("|"))) {
|
|
187
|
+
const rows = lines.filter((l) => !/^\\s*\\|?[\\s:|-]+\\|?\\s*$/.test(l)).map((l) => l.trim().replace(/^\\||\\|$/g, "").split("|"));
|
|
188
|
+
out.push('<div class="tbl"><table>' + rows.map((r, i) => "<tr>" + r.map((c) => (i ? "<td>" : "<th>") + inline(c.trim()) + (i ? "</td>" : "</th>")).join("") + "</tr>").join("") + "</table></div>");
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
let para = [];
|
|
192
|
+
let html = "";
|
|
193
|
+
const flushP = () => { if (para.length) html += "<p>" + para.map(inline).join("<br>") + "</p>"; para = []; };
|
|
194
|
+
for (const l of lines) {
|
|
195
|
+
const h = /^(#{1,6})\\s+(.*)$/.exec(l);
|
|
196
|
+
if (h) { flushP(); html += "<h4>" + inline(h[2]) + "</h4>"; } else para.push(l);
|
|
197
|
+
}
|
|
198
|
+
flushP();
|
|
199
|
+
out.push(html);
|
|
200
|
+
}
|
|
201
|
+
return out.join("");
|
|
202
|
+
}
|
|
203
|
+
function md(text) {
|
|
204
|
+
const parts = String(text ?? "").split(/(\`\`\`+)[^\\n]*\\n([\\s\\S]*?)\\n\\1/);
|
|
205
|
+
let out = "";
|
|
206
|
+
for (let i = 0; i < parts.length; i += 3) {
|
|
207
|
+
out += mdText(parts[i]);
|
|
208
|
+
if (i + 2 < parts.length) out += "<pre>" + esc(parts[i + 2]) + "</pre>";
|
|
209
|
+
}
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
function pre(text) { return text ? "<pre>" + esc(text) + "</pre>" : ""; }
|
|
213
|
+
function time(t) { const d = new Date(t); return isNaN(d) ? "" : d.toTimeString().slice(0, 5); }
|
|
214
|
+
|
|
215
|
+
function actionChips(tools) {
|
|
216
|
+
const changed = [...new Set(tools.map((t) => t.changed).filter(Boolean))];
|
|
217
|
+
const cmds = tools.filter((t) => t.name === "bash" || t.name === "powershell").length;
|
|
218
|
+
const reads = new Set(tools.filter((t) => t.name === "read").map((t) => t.summary)).size;
|
|
219
|
+
const other = tools.filter((t) => !["read", "bash", "powershell", "edit", "write"].includes(t.name)).length;
|
|
220
|
+
const errs = tools.filter((t) => t.isError).length;
|
|
221
|
+
const c = [];
|
|
222
|
+
changed.forEach((p) => c.push('<span class="chip">alterou ' + esc(p) + "</span>"));
|
|
223
|
+
if (cmds) c.push('<span class="chip">' + cmds + " comando(s)</span>");
|
|
224
|
+
if (reads) c.push('<span class="chip">leu ' + reads + " arquivo(s)</span>");
|
|
225
|
+
if (other) c.push('<span class="chip">' + other + " outra(s)</span>");
|
|
226
|
+
if (errs) c.push('<span class="chip err">' + errs + " com erro</span>");
|
|
227
|
+
return c.length ? '<div class="actions">' + c.join("") + "</div>" : "";
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function renderSession(s) {
|
|
231
|
+
const L = st.level;
|
|
232
|
+
let h = "<h2>" + hl(esc(s.title)) + "</h2>";
|
|
233
|
+
h += '<div class="meta">' + esc(s.created) + " → " + esc(s.updated) + " · " + s.turns + " pedido(s) · " +
|
|
234
|
+
esc(s.models.join(", ") || "—") + " · " + s.kb + " KB no .jsonl" +
|
|
235
|
+
(s.otherBranch ? " · " + s.otherBranch + " entrada(s) de ramos abandonados ocultas" : "") + "</div>";
|
|
236
|
+
let pending = [];
|
|
237
|
+
let last = "";
|
|
238
|
+
const flush = () => { if (L === "conversa" && pending.length) h += actionChips(pending); pending = []; };
|
|
239
|
+
const who = (role, label, t) => { if (last !== role) h += '<div class="who">' + esc(label) + " · " + time(t) + "</div>"; last = role; };
|
|
240
|
+
for (const it of s.items) {
|
|
241
|
+
if (it.k === "tool") {
|
|
242
|
+
if (L === "conversa") { pending.push(it); continue; }
|
|
243
|
+
const body = (it.detail ? pre(it.detail) : "") + (it.output && (L === "completo" || it.isError) ? pre(it.output) : "");
|
|
244
|
+
h += '<details class="tool' + (it.isError ? " err" : "") + '"' + (L === "completo" && body ? " open" : "") + "><summary>" +
|
|
245
|
+
hl(esc((it.isError ? "✗ " : "") + it.summary)) + "</summary><div>" + (hl(body) || '<span class="note">sem saída</span>') + "</div></details>";
|
|
246
|
+
last = "assistant";
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (it.k === "assistant" && !it.text && L !== "completo") continue;
|
|
250
|
+
flush();
|
|
251
|
+
if (it.k === "user") {
|
|
252
|
+
last = "";
|
|
253
|
+
h += '<div class="msg user"><div class="who">Você · ' + time(it.t) + '</div><div class="body">' + hl(md(it.text)) + "</div></div>";
|
|
254
|
+
} else if (it.k === "assistant") {
|
|
255
|
+
h += '<div class="msg">';
|
|
256
|
+
if (last !== "assistant") h += '<div class="who">Assistente' + (it.model ? " (" + esc(it.model) + ")" : "") + " · " + time(it.t) + "</div>";
|
|
257
|
+
if (L === "completo" && it.thinking) h += '<div class="think">' + hl(esc(it.thinking)) + "</div>";
|
|
258
|
+
if (it.text) h += '<div class="body">' + hl(md(it.text)) + "</div>";
|
|
259
|
+
h += "</div>";
|
|
260
|
+
last = "assistant";
|
|
261
|
+
} else if (it.k === "bash") {
|
|
262
|
+
last = "";
|
|
263
|
+
h += '<div class="msg user"><div class="who">Você (terminal) · ' + time(it.t) + '</div><div class="body"><code>$ ' +
|
|
264
|
+
hl(esc(it.command)) + "</code>" + (L !== "conversa" ? hl(pre(it.output)) : "") + "</div></div>";
|
|
265
|
+
} else if (it.k === "note") {
|
|
266
|
+
if (it.hidden && L !== "completo") continue;
|
|
267
|
+
h += '<div class="note">' + hl(esc(it.text)) + "</div>";
|
|
268
|
+
last = "";
|
|
269
|
+
} else if (it.k === "summary") {
|
|
270
|
+
h += '<div class="sum"><b>' + (it.kind === "compactação" ? "Contexto compactado aqui · resumo do que veio antes" : "Resumo de um ramo abandonado") +
|
|
271
|
+
'</b><div class="body">' + hl(md(it.text)) + "</div></div>";
|
|
272
|
+
last = "";
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
flush();
|
|
276
|
+
return h;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function matches(s) {
|
|
280
|
+
if (!st.q) return true;
|
|
281
|
+
const low = s.texts.completo.toLowerCase();
|
|
282
|
+
return st.q.toLowerCase().split(/\\s+/).filter(Boolean).every((t) => low.includes(t));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function drawList() {
|
|
286
|
+
const shown = S.filter(matches);
|
|
287
|
+
$("count").textContent = (st.q ? shown.length + " de " : "") + S.length + " sessão(ões)" + (st.checked.size ? " · " + st.checked.size + " marcada(s)" : "");
|
|
288
|
+
$("list").innerHTML = shown.map((s) =>
|
|
289
|
+
'<div class="s' + (st.q ? " hit" : "") + '" data-id="' + s.id + '" aria-current="' + (s.id === st.cur) + '">' +
|
|
290
|
+
'<input type="checkbox" aria-label="marcar"' + (st.checked.has(s.id) ? " checked" : "") + ">" +
|
|
291
|
+
'<div class="t">' + esc(s.title) + '</div><div class="m">' + esc(s.updated) + " · " + s.turns + " pedido(s) · " + s.kb + " KB</div></div>"
|
|
292
|
+
).join("") || '<div class="empty" style="padding:16px">Nenhuma sessão encontrada.</div>';
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function draw() {
|
|
296
|
+
document.querySelectorAll(".seg button").forEach((b) => b.setAttribute("aria-pressed", b.dataset.level === st.level));
|
|
297
|
+
drawList();
|
|
298
|
+
const s = S.find((x) => x.id === st.cur);
|
|
299
|
+
$("view").innerHTML = s ? renderSession(s) : '<div class="empty">Nenhuma sessão.</div>';
|
|
300
|
+
const m = $("view").querySelector("mark");
|
|
301
|
+
if (m) m.scrollIntoView({ block: "center" });
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function selectedText() {
|
|
305
|
+
const ids = st.checked.size ? S.filter((s) => st.checked.has(s.id)).map((s) => s.id) : [st.cur];
|
|
306
|
+
const chosen = S.filter((s) => ids.includes(s.id)).reverse(); // cronológico
|
|
307
|
+
const text = chosen.length > 1
|
|
308
|
+
? "# Histórico de " + chosen.length + " sessões do agente de código, em ordem cronológica\\n\\n" + chosen.map((s) => s.texts[st.level]).join("\\n\\n")
|
|
309
|
+
: (chosen[0] ? chosen[0].texts[st.level] : "");
|
|
310
|
+
return { text, n: chosen.length };
|
|
311
|
+
}
|
|
312
|
+
function toast(msg) { const t = $("toast"); t.textContent = msg; t.classList.add("on"); setTimeout(() => t.classList.remove("on"), 2200); }
|
|
313
|
+
|
|
314
|
+
$("list").addEventListener("click", (e) => {
|
|
315
|
+
const row = e.target.closest(".s"); if (!row) return;
|
|
316
|
+
if (e.target.matches("input")) { e.target.checked ? st.checked.add(row.dataset.id) : st.checked.delete(row.dataset.id); drawList(); return; }
|
|
317
|
+
st.cur = row.dataset.id; draw(); $("view").scrollTop = 0;
|
|
318
|
+
});
|
|
319
|
+
document.querySelectorAll(".seg button").forEach((b) => b.addEventListener("click", () => {
|
|
320
|
+
st.level = b.dataset.level; try { localStorage.setItem("ponte.level", st.level); } catch {} draw();
|
|
321
|
+
}));
|
|
322
|
+
let timer; $("q").addEventListener("input", (e) => { clearTimeout(timer); timer = setTimeout(() => {
|
|
323
|
+
st.q = e.target.value.trim(); const first = S.find(matches); if (first && !matches(S.find((s) => s.id === st.cur) || {texts:{completo:""}})) st.cur = first.id; draw();
|
|
324
|
+
}, 150); });
|
|
325
|
+
$("all").addEventListener("click", () => { S.filter(matches).forEach((s) => st.checked.add(s.id)); drawList(); });
|
|
326
|
+
$("none").addEventListener("click", () => { st.checked.clear(); drawList(); });
|
|
327
|
+
$("copy").addEventListener("click", async () => {
|
|
328
|
+
const { text, n } = selectedText();
|
|
329
|
+
try { await navigator.clipboard.writeText(text); }
|
|
330
|
+
catch { const ta = document.createElement("textarea"); ta.value = text; document.body.append(ta); ta.select(); document.execCommand("copy"); ta.remove(); }
|
|
331
|
+
toast(n + " sessão(ões) copiada(s) · nível " + st.level + " · ~" + Math.round(text.length / 4).toLocaleString("pt-BR") + " tokens");
|
|
332
|
+
});
|
|
333
|
+
$("dl").addEventListener("click", () => {
|
|
334
|
+
const { text, n } = selectedText();
|
|
335
|
+
const a = document.createElement("a");
|
|
336
|
+
a.href = URL.createObjectURL(new Blob([text], { type: "text/plain;charset=utf-8" }));
|
|
337
|
+
a.download = (n > 1 ? "sessoes" : "sessao") + "-" + st.level + ".txt"; a.click(); URL.revokeObjectURL(a.href);
|
|
338
|
+
});
|
|
339
|
+
draw();
|
|
340
|
+
</script>
|
|
341
|
+
</body>
|
|
342
|
+
</html>
|
|
343
|
+
`;
|
|
344
|
+
}
|