wrapt-cli 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +77 -2
- package/assets/fonts/OFL.txt +93 -0
- package/assets/fonts/SpaceGrotesk-Bold.ttf +0 -0
- package/assets/fonts/SpaceGrotesk-Medium.ttf +0 -0
- package/assets/fonts/SpaceGrotesk-Regular.ttf +0 -0
- package/dist/analyze.js +35 -0
- package/dist/brand.js +11 -0
- package/dist/cli.js +261 -0
- package/dist/format.js +85 -0
- package/dist/index.js +5 -0
- package/dist/narrative.js +20 -0
- package/dist/parse/reader.js +200 -0
- package/dist/parse/schema.js +75 -0
- package/dist/publish.js +130 -0
- package/dist/render/cards.js +447 -0
- package/dist/render/h.js +25 -0
- package/dist/render/index.js +72 -0
- package/dist/render/measure.js +108 -0
- package/dist/render/theme.js +39 -0
- package/dist/share/page.js +218 -0
- package/dist/share/server.js +127 -0
- package/dist/site.js +56 -0
- package/dist/sources/copilot-cli.js +142 -0
- package/dist/sources/copilot-vscode.js +277 -0
- package/dist/sources/index.js +41 -0
- package/dist/sources/tools.js +86 -0
- package/dist/stats/engine.js +285 -0
- package/dist/stats/languages.js +45 -0
- package/dist/stats/schema.js +68 -0
- package/dist/stats/words.js +112 -0
- package/package.json +53 -4
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** One palette per card, in card order (cover … outro). */
|
|
2
|
+
export const THEMES = {
|
|
3
|
+
bold: [
|
|
4
|
+
{ bg: "#FF5A1F", fg: "#1A0B05", accent: "#FFF3D6" }, // cover — tangerine
|
|
5
|
+
{ bg: "#1239FF", fg: "#FFFFFF", accent: "#C8FF3D" }, // big number — ultramarine
|
|
6
|
+
{ bg: "#101014", fg: "#F4F1EA", accent: "#FFB627" }, // rhythm — ink
|
|
7
|
+
{ bg: "#C8FF3D", fg: "#101014", accent: "#1239FF" }, // top asks — acid lime
|
|
8
|
+
{ bg: "#FF3D7F", fg: "#14040A", accent: "#FFF3D6" }, // word — hot pink
|
|
9
|
+
{ bg: "#00B3A4", fg: "#04201D", accent: "#FFF3D6" }, // stack — teal
|
|
10
|
+
{ bg: "#FFB627", fg: "#1A1204", accent: "#7A1CFF" }, // archetype — saffron
|
|
11
|
+
{ bg: "#7A1CFF", fg: "#FFFFFF", accent: "#C8FF3D" }, // outro — violet
|
|
12
|
+
],
|
|
13
|
+
mono: [
|
|
14
|
+
{ bg: "#0B0B0B", fg: "#FAFAFA", accent: "#FAFAFA" },
|
|
15
|
+
{ bg: "#FAFAFA", fg: "#0B0B0B", accent: "#0B0B0B" },
|
|
16
|
+
{ bg: "#0B0B0B", fg: "#FAFAFA", accent: "#FAFAFA" },
|
|
17
|
+
{ bg: "#FAFAFA", fg: "#0B0B0B", accent: "#0B0B0B" },
|
|
18
|
+
{ bg: "#0B0B0B", fg: "#FAFAFA", accent: "#FAFAFA" },
|
|
19
|
+
{ bg: "#FAFAFA", fg: "#0B0B0B", accent: "#0B0B0B" },
|
|
20
|
+
{ bg: "#0B0B0B", fg: "#FAFAFA", accent: "#FAFAFA" },
|
|
21
|
+
{ bg: "#FAFAFA", fg: "#0B0B0B", accent: "#0B0B0B" },
|
|
22
|
+
],
|
|
23
|
+
pastel: [
|
|
24
|
+
{ bg: "#FFD6C9", fg: "#3A1A10", accent: "#D9481C" },
|
|
25
|
+
{ bg: "#C9D8FF", fg: "#0F1A44", accent: "#2C4BFF" },
|
|
26
|
+
{ bg: "#2A2633", fg: "#F3EEFF", accent: "#FFC9E4" },
|
|
27
|
+
{ bg: "#E4FFC9", fg: "#1B3305", accent: "#4F8A10" },
|
|
28
|
+
{ bg: "#FFC9E4", fg: "#3D0B24", accent: "#C21C6C" },
|
|
29
|
+
{ bg: "#C9FFF6", fg: "#06332D", accent: "#0F8577" },
|
|
30
|
+
{ bg: "#FFEBC2", fg: "#3A2A06", accent: "#B37A00" },
|
|
31
|
+
{ bg: "#E1C9FF", fg: "#240B44", accent: "#6A1CD9" },
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
export function getTheme(name) {
|
|
35
|
+
const t = THEMES[name ?? "bold"];
|
|
36
|
+
if (!t)
|
|
37
|
+
throw new Error(`Unknown --theme "${name}". Available: ${Object.keys(THEMES).join(", ")}`);
|
|
38
|
+
return t;
|
|
39
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { SITE, SITE_URL, captions } from "../site.js";
|
|
2
|
+
const esc = (s) => s.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
3
|
+
/** Self-contained mobile page. All assets are relative to the page; no third-party requests. */
|
|
4
|
+
export function sharePage(a, o) {
|
|
5
|
+
const local = (o.mode ?? "local") === "local";
|
|
6
|
+
const f = o.fileUrl ?? ((rel) => `${o.base}/f/${rel}`);
|
|
7
|
+
const dl = (rel) => (local ? `${f(rel)}?dl=1` : f(rel));
|
|
8
|
+
const fontUrl = o.fontUrl ?? `${o.base}/font.ttf`;
|
|
9
|
+
const heading = o.heading ?? `Your <em>${o.year}</em>, wrapped.`;
|
|
10
|
+
const card = (rel, i, kind) => `
|
|
11
|
+
<figure class="card ${kind}">
|
|
12
|
+
<img src="${esc(f(rel))}" alt="${kind} card ${i + 1}" loading="${i < 2 ? "eager" : "lazy"}">
|
|
13
|
+
<a class="dl" href="${esc(dl(rel))}" download>Save ${String(i + 1).padStart(2, "0")}</a>
|
|
14
|
+
</figure>`;
|
|
15
|
+
const og = o.og
|
|
16
|
+
? `
|
|
17
|
+
<meta property="og:type" content="website">
|
|
18
|
+
<meta property="og:title" content="${esc(o.og.title)}">
|
|
19
|
+
<meta property="og:description" content="${esc(o.og.description)}">
|
|
20
|
+
<meta property="og:url" content="${esc(o.og.url)}">
|
|
21
|
+
<meta property="og:image" content="${esc(o.og.image)}">
|
|
22
|
+
<meta property="og:image:width" content="1200">
|
|
23
|
+
<meta property="og:image:height" content="675">
|
|
24
|
+
<meta property="og:image:alt" content="${esc(o.og.title)}">
|
|
25
|
+
<meta name="twitter:card" content="summary_large_image">
|
|
26
|
+
<meta name="twitter:title" content="${esc(o.og.title)}">
|
|
27
|
+
<meta name="twitter:description" content="${esc(o.og.description)}">
|
|
28
|
+
<meta name="twitter:image" content="${esc(o.og.image)}">
|
|
29
|
+
<meta name="description" content="${esc(o.og.description)}">`
|
|
30
|
+
: "";
|
|
31
|
+
return `<!doctype html>
|
|
32
|
+
<html lang="en">
|
|
33
|
+
<head>
|
|
34
|
+
<meta charset="utf-8">
|
|
35
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
36
|
+
<meta name="robots" content="noindex">
|
|
37
|
+
<title>${o.og ? esc(o.og.title) : `Your ${o.year}, wrapped`}</title>${og}
|
|
38
|
+
<style>
|
|
39
|
+
@font-face { font-family: "Space Grotesk"; src: url("${esc(fontUrl)}") format("truetype"); font-weight: 700; }
|
|
40
|
+
:root { --bg: #101014; --fg: #F4F1EA; --dim: #A6A39C; --line: #2A2A31; --accent: #C8FF3D; --ink: #101014; }
|
|
41
|
+
* { box-sizing: border-box; }
|
|
42
|
+
html { -webkit-text-size-adjust: 100%; }
|
|
43
|
+
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
44
|
+
padding: max(20px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom)); }
|
|
45
|
+
.wrap { padding: 0 20px; max-width: 720px; margin: 0 auto; }
|
|
46
|
+
h1, h2, .big { font-family: "Space Grotesk", system-ui, sans-serif; font-weight: 700; letter-spacing: -0.02em; }
|
|
47
|
+
h1 { font-size: 40px; line-height: 1.02; margin: 8px 0 8px; }
|
|
48
|
+
h1 em { font-style: normal; color: var(--accent); }
|
|
49
|
+
h2 { font-size: 24px; margin: 40px 0 4px; }
|
|
50
|
+
p { margin: 0 0 12px; color: var(--dim); }
|
|
51
|
+
.note { font-size: 14px; color: var(--dim); }
|
|
52
|
+
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
|
|
53
|
+
border-radius: 999px; border: 0; background: var(--accent); color: var(--ink); font: 700 17px "Space Grotesk", system-ui, sans-serif;
|
|
54
|
+
text-decoration: none; cursor: pointer; }
|
|
55
|
+
.btn.secondary { background: transparent; color: var(--fg); border: 1.5px solid var(--line); }
|
|
56
|
+
button:disabled { opacity: .6; }
|
|
57
|
+
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 8px; }
|
|
58
|
+
.hint { display: none; margin-top: 12px; padding: 14px 16px; border-radius: 14px; background: #1B1B21; border: 1px solid var(--line); font-size: 15px; color: var(--fg); }
|
|
59
|
+
.hint.show { display: block; }
|
|
60
|
+
.strip { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 12px 20px 4px; scroll-padding: 0 20px;
|
|
61
|
+
-webkit-overflow-scrolling: touch; scrollbar-width: none; }
|
|
62
|
+
.strip::-webkit-scrollbar { display: none; }
|
|
63
|
+
.card { margin: 0; scroll-snap-align: start; flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; }
|
|
64
|
+
.card img { display: block; width: 100%; border-radius: 14px; background: #1B1B21; -webkit-touch-callout: default; }
|
|
65
|
+
.story { width: min(62vw, 300px); }
|
|
66
|
+
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
|
|
67
|
+
.dl { align-self: flex-start; font-size: 14px; font-weight: 600; color: var(--fg); text-decoration: none; padding: 6px 12px;
|
|
68
|
+
border-radius: 999px; border: 1px solid var(--line); }
|
|
69
|
+
.xcard img { width: 100%; border-radius: 14px; display: block; margin-top: 12px; }
|
|
70
|
+
ol { padding-left: 20px; margin: 8px 0 0; }
|
|
71
|
+
li { margin: 0 0 14px; color: var(--dim); }
|
|
72
|
+
li b { color: var(--fg); }
|
|
73
|
+
.caps { display: grid; gap: 14px; margin-top: 12px; }
|
|
74
|
+
.cap { padding: 14px 16px; border-radius: 14px; background: #1B1B21; border: 1px solid var(--line); }
|
|
75
|
+
.cap-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
|
|
76
|
+
.cap .copy { min-height: 36px; padding: 0 14px; font-size: 15px; }
|
|
77
|
+
.cap textarea { width: 100%; resize: none; border: 0; background: transparent; color: var(--fg); font: 15px/1.45 inherit; padding: 0; }
|
|
78
|
+
.cap .note { margin: 6px 0 0; }
|
|
79
|
+
footer { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); }
|
|
80
|
+
</style>
|
|
81
|
+
</head>
|
|
82
|
+
<body>
|
|
83
|
+
<div class="wrap">
|
|
84
|
+
<p class="note">${local ? "wrapt · served from your computer, nothing is uploaded" : "wrapt · a year in review for AI coding tools"}</p>
|
|
85
|
+
<h1>${heading}</h1>
|
|
86
|
+
<p>${local ? "Save the cards to your phone, then post them wherever you like." : `Swipe through the cards. Want your own? Go to <a href="${esc(SITE_URL)}">${esc(SITE)}</a>.`}</p>
|
|
87
|
+
<div class="actions">
|
|
88
|
+
<button id="save-story" data-set="story">Save all ${a.story.length} story cards</button>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="hint" id="hint-story"></div>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<h2 class="wrap">Instagram Story</h2>
|
|
94
|
+
<div class="strip">${a.story.map((r, i) => card(r, i, "story")).join("")}
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
${a.carousel.length
|
|
98
|
+
? `<div class="wrap">
|
|
99
|
+
<h2>Carousel post</h2>
|
|
100
|
+
<p>4:5 cards for an Instagram carousel.</p>
|
|
101
|
+
<div class="actions"><button class="btn secondary" id="save-carousel" data-set="carousel">Save all ${a.carousel.length} carousel cards</button></div>
|
|
102
|
+
<div class="hint" id="hint-carousel"></div>
|
|
103
|
+
<div class="grid">${a.carousel.map((r, i) => card(r, i, "carousel")).join("")}
|
|
104
|
+
</div>
|
|
105
|
+
</div>`
|
|
106
|
+
: ""}
|
|
107
|
+
|
|
108
|
+
<div class="wrap">
|
|
109
|
+
${a.pdf
|
|
110
|
+
? `<h2>LinkedIn document</h2>
|
|
111
|
+
<p>All eight carousel cards in one PDF, one per page.</p>
|
|
112
|
+
<div class="actions"><a class="btn secondary" href="${esc(dl(a.pdf))}" download>Download linkedin.pdf</a></div>`
|
|
113
|
+
: ""}
|
|
114
|
+
${a.xCard
|
|
115
|
+
? `<h2>X summary card</h2>
|
|
116
|
+
<div class="xcard"><img src="${esc(f(a.xCard))}" alt="X summary card"></div>
|
|
117
|
+
<div class="actions"><a class="btn secondary" href="${esc(dl(a.xCard))}" download>Save x-card.png</a></div>`
|
|
118
|
+
: ""}
|
|
119
|
+
|
|
120
|
+
${local
|
|
121
|
+
? ` <h2>How to post</h2>
|
|
122
|
+
<ol>
|
|
123
|
+
<li><b>Instagram Story.</b> Post the 8 story cards in order as one story. On the last card, add a <b>link sticker</b> with ${esc(SITE_URL)} so people can tap through and make their own. Afterwards, add them to a Highlight called “${o.year}” so they stay on your profile.</li>
|
|
124
|
+
<li><b>Instagram carousel.</b> New post → select multiple → choose carousel cards 01–08 in order. The 4:5 size fills the feed. Put ${esc(SITE)} in your bio, since links in captions can't be tapped.</li>
|
|
125
|
+
<li><b>LinkedIn.</b> Start a post → “Add a document” → upload linkedin.pdf and give it a title. It shows as a swipeable carousel.</li>
|
|
126
|
+
<li><b>X.</b> Attach x-card.png to a post.</li>
|
|
127
|
+
</ol>
|
|
128
|
+
|
|
129
|
+
<h2>Captions</h2>
|
|
130
|
+
<p>Copy one into your post so people know where to make their own.</p>
|
|
131
|
+
<div class="caps">${captions(o.year, o.tool)
|
|
132
|
+
.map((c, i) => `
|
|
133
|
+
<div class="cap">
|
|
134
|
+
<div class="cap-head"><b>${esc(c.platform)}</b><button class="btn secondary copy" data-cap="${i}">Copy</button></div>
|
|
135
|
+
<textarea id="cap-${i}" readonly rows="${c.text.split("\n").length + 1}">${esc(c.text)}</textarea>
|
|
136
|
+
<p class="note">${esc(c.tip)}</p>
|
|
137
|
+
</div>`)
|
|
138
|
+
.join("")}
|
|
139
|
+
</div>
|
|
140
|
+
|
|
141
|
+
<footer><p class="note">This page stops working when the share server on your computer stops (after 15 minutes, or when you press Ctrl+C).</p></footer>`
|
|
142
|
+
: `<h2>Get yours</h2>
|
|
143
|
+
<p>wrapt reads your local Claude Code and GitHub Copilot history and makes these cards. Your chats never leave your computer.</p>
|
|
144
|
+
<div class="actions"><a class="btn" href="${esc(SITE_URL)}">Make yours at ${esc(SITE)}</a></div>
|
|
145
|
+
<footer><p class="note">Only these images are online. The stats behind them stayed on the author’s computer.</p></footer>`}
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<script>
|
|
149
|
+
(function () {
|
|
150
|
+
var sets = ${JSON.stringify({ story: a.story.map(f), carousel: a.carousel.map(f) })};
|
|
151
|
+
var LOCAL = ${local ? "true" : "false"};
|
|
152
|
+
var ua = navigator.userAgent;
|
|
153
|
+
var iOS = /iPhone|iPad|iPod/.test(ua) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
|
|
154
|
+
|
|
155
|
+
function hint(name, html) {
|
|
156
|
+
var el = document.getElementById("hint-" + name);
|
|
157
|
+
if (el) { el.innerHTML = html; el.classList.add("show"); }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function shareFiles(urls) {
|
|
161
|
+
var files = await Promise.all(urls.map(async function (u, i) {
|
|
162
|
+
var b = await (await fetch(u)).blob();
|
|
163
|
+
return new File([b], "wrapt-" + String(i + 1).padStart(2, "0") + ".png", { type: "image/png" });
|
|
164
|
+
}));
|
|
165
|
+
if (!navigator.canShare || !navigator.canShare({ files: files })) return false;
|
|
166
|
+
await navigator.share({ files: files });
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function downloadAll(urls) {
|
|
171
|
+
urls.forEach(function (u, i) {
|
|
172
|
+
setTimeout(function () {
|
|
173
|
+
var a = document.createElement("a");
|
|
174
|
+
a.href = LOCAL ? u + "?dl=1" : u; a.download = ""; document.body.appendChild(a); a.click(); a.remove();
|
|
175
|
+
}, i * 400);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// This page is plain HTTP on the local network, where navigator.clipboard is unavailable; fall back to execCommand.
|
|
180
|
+
document.querySelectorAll("button[data-cap]").forEach(function (btn) {
|
|
181
|
+
btn.addEventListener("click", function () {
|
|
182
|
+
var ta = document.getElementById("cap-" + btn.getAttribute("data-cap"));
|
|
183
|
+
var done = function () { btn.textContent = "Copied"; setTimeout(function () { btn.textContent = "Copy"; }, 1600); };
|
|
184
|
+
if (navigator.clipboard && window.isSecureContext) {
|
|
185
|
+
navigator.clipboard.writeText(ta.value).then(done, function () { ta.focus(); ta.select(); });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
ta.focus(); ta.setSelectionRange(0, ta.value.length);
|
|
189
|
+
try { if (document.execCommand("copy")) done(); } catch (e) {}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
document.querySelectorAll("button[data-set]").forEach(function (btn) {
|
|
194
|
+
btn.addEventListener("click", async function () {
|
|
195
|
+
var name = btn.getAttribute("data-set");
|
|
196
|
+
var urls = sets[name];
|
|
197
|
+
btn.disabled = true;
|
|
198
|
+
try {
|
|
199
|
+
// The Web Share API (Save to Photos) only exists on HTTPS or localhost pages.
|
|
200
|
+
if (window.isSecureContext && navigator.share && (await shareFiles(urls))) return;
|
|
201
|
+
} catch (e) {
|
|
202
|
+
if (e && e.name === "AbortError") return;
|
|
203
|
+
} finally {
|
|
204
|
+
btn.disabled = false;
|
|
205
|
+
}
|
|
206
|
+
if (iOS) {
|
|
207
|
+
hint(name, "<b>On iPhone:</b> touch and hold each card below, then tap <b>Save to Photos</b>." + (LOCAL ? " Your browser doesn't allow saving them all at once from this local page." : ""));
|
|
208
|
+
} else {
|
|
209
|
+
hint(name, "Downloading " + urls.length + " images… If your browser asks, allow multiple downloads. You can also use the <b>Save</b> button under each card.");
|
|
210
|
+
downloadAll(urls);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
})();
|
|
215
|
+
</script>
|
|
216
|
+
</body>
|
|
217
|
+
</html>`;
|
|
218
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { brandFor } from "../brand.js";
|
|
8
|
+
import { StatsSchema } from "../stats/schema.js";
|
|
9
|
+
import { sharePage } from "./page.js";
|
|
10
|
+
const FONT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../assets/fonts/SpaceGrotesk-Bold.ttf");
|
|
11
|
+
const TYPES = {
|
|
12
|
+
".png": "image/png",
|
|
13
|
+
".pdf": "application/pdf",
|
|
14
|
+
".ttf": "font/ttf",
|
|
15
|
+
};
|
|
16
|
+
/** Best-guess LAN IPv4: prefer Wi-Fi/Ethernet interfaces, skip loopback, link-local and VPN tunnels. */
|
|
17
|
+
export function lanAddress(ifaces = os.networkInterfaces()) {
|
|
18
|
+
const candidates = [];
|
|
19
|
+
for (const [name, list] of Object.entries(ifaces)) {
|
|
20
|
+
for (const i of list ?? []) {
|
|
21
|
+
if (i.family !== "IPv4" || i.internal || i.address.startsWith("169.254."))
|
|
22
|
+
continue;
|
|
23
|
+
candidates.push({ name, address: i.address });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const rank = (c) => {
|
|
27
|
+
let r = 0;
|
|
28
|
+
if (/^(en|eth|wlan|wl|Wi-?Fi|Ethernet)/i.test(c.name))
|
|
29
|
+
r -= 10;
|
|
30
|
+
if (/^(utun|tun|tap|ppp|ipsec|gif|stf|bridge|vmnet|docker|veth|br-|awdl|llw|zt|tailscale)/i.test(c.name))
|
|
31
|
+
r += 20;
|
|
32
|
+
if (/^(192\.168\.|10\.|172\.(1[6-9]|2\d|3[01])\.)/.test(c.address))
|
|
33
|
+
r -= 5;
|
|
34
|
+
return r;
|
|
35
|
+
};
|
|
36
|
+
return candidates.sort((a, b) => rank(a) - rank(b))[0]?.address;
|
|
37
|
+
}
|
|
38
|
+
/** The only files the server will ever send: rendered cards and the PDF. Nothing else in ~/.wrapt is reachable. */
|
|
39
|
+
export function collectAssets(dir) {
|
|
40
|
+
const pngs = (sub) => {
|
|
41
|
+
const d = path.join(dir, sub);
|
|
42
|
+
if (!fs.existsSync(d))
|
|
43
|
+
return [];
|
|
44
|
+
return fs
|
|
45
|
+
.readdirSync(d)
|
|
46
|
+
.filter((f) => /^\d{2}\.png$/.test(f))
|
|
47
|
+
.sort()
|
|
48
|
+
.map((f) => `${sub}/${f}`);
|
|
49
|
+
};
|
|
50
|
+
const maybe = (f) => (fs.existsSync(path.join(dir, f)) ? f : undefined);
|
|
51
|
+
return { story: pngs("story"), carousel: pngs("carousel"), pdf: maybe("linkedin.pdf"), xCard: maybe("x-card.png") };
|
|
52
|
+
}
|
|
53
|
+
/** Names the tools behind this year's cards for the captions. Falls back to Claude Code when stats.json is missing or unreadable. */
|
|
54
|
+
function toolName(dir) {
|
|
55
|
+
try {
|
|
56
|
+
return brandFor(StatsSchema.parse(JSON.parse(fs.readFileSync(path.join(dir, "stats.json"), "utf8")))).long;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export async function startShare(opts) {
|
|
63
|
+
const assets = collectAssets(opts.dir);
|
|
64
|
+
if (!assets.story.length)
|
|
65
|
+
throw new Error(`No cards in ${opts.dir}. Run \`wrapt render\` first.`);
|
|
66
|
+
const token = crypto.randomBytes(12).toString("base64url");
|
|
67
|
+
const allowed = new Map(); // url path -> absolute file
|
|
68
|
+
for (const rel of [...assets.story, ...assets.carousel, assets.pdf, assets.xCard]) {
|
|
69
|
+
if (rel)
|
|
70
|
+
allowed.set(`/${token}/f/${rel}`, path.join(opts.dir, rel));
|
|
71
|
+
}
|
|
72
|
+
allowed.set(`/${token}/font.ttf`, FONT);
|
|
73
|
+
const html = sharePage(assets, { year: opts.year, base: `/${token}`, tool: toolName(opts.dir) });
|
|
74
|
+
const server = http.createServer((req, res) => {
|
|
75
|
+
const url = new URL(req.url ?? "/", "http://x");
|
|
76
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
77
|
+
res.setHeader("Referrer-Policy", "no-referrer");
|
|
78
|
+
res.setHeader("Cache-Control", "no-store");
|
|
79
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
80
|
+
res.writeHead(405).end();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (url.pathname === `/${token}` || url.pathname === `/${token}/`) {
|
|
84
|
+
opts.onRequest?.("/");
|
|
85
|
+
res.writeHead(200, {
|
|
86
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
87
|
+
"Content-Security-Policy": "default-src 'self'; img-src 'self' blob:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; font-src 'self'",
|
|
88
|
+
});
|
|
89
|
+
res.end(req.method === "HEAD" ? undefined : html);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const file = allowed.get(url.pathname);
|
|
93
|
+
if (!file) {
|
|
94
|
+
res.writeHead(404, { "Content-Type": "text/plain" }).end("Not found");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
opts.onRequest?.(url.pathname.slice(token.length + 1));
|
|
98
|
+
const headers = { "Content-Type": TYPES[path.extname(file)] ?? "application/octet-stream" };
|
|
99
|
+
if (url.searchParams.has("dl")) {
|
|
100
|
+
const name = `wrapt-${opts.year}-${url.pathname.split("/f/")[1]?.replace(/\//g, "-") ?? path.basename(file)}`;
|
|
101
|
+
headers["Content-Disposition"] = `attachment; filename="${name}"`;
|
|
102
|
+
}
|
|
103
|
+
res.writeHead(200, headers);
|
|
104
|
+
if (req.method === "HEAD")
|
|
105
|
+
res.end();
|
|
106
|
+
else
|
|
107
|
+
fs.createReadStream(file).pipe(res);
|
|
108
|
+
});
|
|
109
|
+
const host = opts.host ?? "0.0.0.0";
|
|
110
|
+
await new Promise((resolve, reject) => {
|
|
111
|
+
server.once("error", reject);
|
|
112
|
+
server.listen(opts.port ?? 0, host, () => resolve());
|
|
113
|
+
});
|
|
114
|
+
const port = server.address().port;
|
|
115
|
+
const lanIp = host === "0.0.0.0" ? lanAddress() : host;
|
|
116
|
+
const url = `http://${lanIp ?? "127.0.0.1"}:${port}/${token}/`;
|
|
117
|
+
let resolveClosed;
|
|
118
|
+
const closed = new Promise((r) => (resolveClosed = r));
|
|
119
|
+
const timer = setTimeout(() => close(), (opts.minutes ?? 15) * 60_000);
|
|
120
|
+
timer.unref();
|
|
121
|
+
function close() {
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
server.closeAllConnections?.();
|
|
124
|
+
server.close(() => resolveClosed());
|
|
125
|
+
}
|
|
126
|
+
return { url, localUrl: `http://127.0.0.1:${port}/${token}/`, token, lan: !!lanIp, server, closed, close };
|
|
127
|
+
}
|
package/dist/site.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
/** Where people go to make their own wrapt. Shown on the cards and in share captions. */
|
|
3
|
+
export const SITE = "wrapt.cc";
|
|
4
|
+
export const SITE_URL = `https://${SITE}`;
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
// qrcode-terminal ships a plain QR encoder; reuse it rather than adding another dependency.
|
|
7
|
+
const QRCode = require("qrcode-terminal/vendor/QRCode/index.js");
|
|
8
|
+
const Level = require("qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js");
|
|
9
|
+
/** QR code as a square boolean matrix (true = dark). Medium error correction survives screenshots and recompression. */
|
|
10
|
+
export function qrMatrix(text) {
|
|
11
|
+
const qr = new QRCode(-1, Level.M);
|
|
12
|
+
qr.addData(text);
|
|
13
|
+
qr.make();
|
|
14
|
+
const n = qr.getModuleCount();
|
|
15
|
+
return Array.from({ length: n }, (_, r) => Array.from({ length: n }, (_, c) => qr.isDark(r, c)));
|
|
16
|
+
}
|
|
17
|
+
/** QR code as an SVG data URI, with a quiet zone of `margin` modules. */
|
|
18
|
+
export function qrSvgDataUri(text, opts) {
|
|
19
|
+
const m = qrMatrix(text);
|
|
20
|
+
const pad = opts.margin ?? 2;
|
|
21
|
+
const size = m.length + pad * 2;
|
|
22
|
+
let d = "";
|
|
23
|
+
m.forEach((row, r) => row.forEach((dark, c) => {
|
|
24
|
+
if (dark)
|
|
25
|
+
d += `M${c + pad} ${r + pad}h1v1h-1z`;
|
|
26
|
+
}));
|
|
27
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" shape-rendering="crispEdges">` +
|
|
28
|
+
`<rect width="${size}" height="${size}" fill="${opts.bg}"/><path d="${d}" fill="${opts.fg}"/></svg>`;
|
|
29
|
+
return `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`;
|
|
30
|
+
}
|
|
31
|
+
/** Ready-to-paste post text for each platform, each pointing people to the site. */
|
|
32
|
+
export function captions(year, tool = "Claude Code") {
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
platform: "Instagram Story",
|
|
36
|
+
tip: `Add a link sticker to the last card with ${SITE_URL}.`,
|
|
37
|
+
text: `Make yours at ${SITE}`,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
platform: "Instagram post",
|
|
41
|
+
tip: `Instagram captions can't hold links, so put ${SITE_URL} in your bio too.`,
|
|
42
|
+
text: `My ${year} with ${tool}, wrapped. Make your own in a couple of minutes at ${SITE} (link in bio).`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
platform: "LinkedIn",
|
|
46
|
+
tip: "Paste this as the post text above linkedin.pdf.",
|
|
47
|
+
text: `My ${year} with ${tool}, in eight cards. wrapt reads your ${tool} history on your own computer ` +
|
|
48
|
+
`and turns it into a year in review. Nothing is uploaded.\n\nMake yours: ${SITE_URL}`,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
platform: "X",
|
|
52
|
+
tip: "Attach x-card.png and paste this.",
|
|
53
|
+
text: `My ${year} with ${tool}, wrapped. Make yours: ${SITE_URL}`,
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import readline from "node:readline";
|
|
5
|
+
import { cleanCopilotPrompt, normalizeTool, patchPaths, stripVendor } from "./tools.js";
|
|
6
|
+
/**
|
|
7
|
+
* GitHub Copilot CLI sessions.
|
|
8
|
+
*
|
|
9
|
+
* Observed format (2026): `~/.copilot/session-state/<session>/events.jsonl`, one event per
|
|
10
|
+
* line: `{ id, parentId, timestamp, type, data }`. Types we read:
|
|
11
|
+
* session.start data.sessionId, data.context.{cwd,gitRoot}
|
|
12
|
+
* user.message data.content (raw text; transformedContent has injected context)
|
|
13
|
+
* session.usage_record data.usage.{model,inputTokens,outputTokens,cacheReadTokens,cacheWriteTokens,apiCallId}
|
|
14
|
+
* inputTokens INCLUDES cache read + write tokens, so we subtract them.
|
|
15
|
+
* tool.execution_start data.toolName, data.arguments (path / patch text)
|
|
16
|
+
* Everything else with a timestamp only extends the session's time span.
|
|
17
|
+
* The sibling session-store.db holds a subset of the same data and is not needed.
|
|
18
|
+
*/
|
|
19
|
+
export function copilotHome() {
|
|
20
|
+
return process.env.COPILOT_HOME ?? path.join(os.homedir(), ".copilot");
|
|
21
|
+
}
|
|
22
|
+
function eventFiles(home) {
|
|
23
|
+
const root = path.join(home, "session-state");
|
|
24
|
+
let dirs;
|
|
25
|
+
try {
|
|
26
|
+
dirs = fs.readdirSync(root).sort();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
return dirs.map((d) => path.join(root, d, "events.jsonl")).filter((f) => fs.existsSync(f));
|
|
32
|
+
}
|
|
33
|
+
export function hasCopilotCli(home = copilotHome()) {
|
|
34
|
+
return eventFiles(home).length > 0;
|
|
35
|
+
}
|
|
36
|
+
function filesFromArgs(tool, args) {
|
|
37
|
+
if (typeof args === "string")
|
|
38
|
+
return tool === "apply_patch" ? patchPaths(args) : [];
|
|
39
|
+
if (!args || typeof args !== "object")
|
|
40
|
+
return [];
|
|
41
|
+
const a = args;
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const k of ["path", "file_path", "filePath"])
|
|
44
|
+
if (typeof a[k] === "string")
|
|
45
|
+
out.push(a[k]);
|
|
46
|
+
if (typeof a.input === "string" && tool === "apply_patch")
|
|
47
|
+
out.push(...patchPaths(a.input));
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
export async function* readCopilotCli(report, home = copilotHome()) {
|
|
51
|
+
const seen = new Set();
|
|
52
|
+
for (const file of eventFiles(home)) {
|
|
53
|
+
report.files++;
|
|
54
|
+
let sessionId = `cli:${path.basename(path.dirname(file))}`;
|
|
55
|
+
let project = "copilot";
|
|
56
|
+
const rl = readline.createInterface({ input: fs.createReadStream(file, "utf8"), crlfDelay: Infinity });
|
|
57
|
+
for await (const raw of rl) {
|
|
58
|
+
if (!raw.trim())
|
|
59
|
+
continue;
|
|
60
|
+
report.lines++;
|
|
61
|
+
let e;
|
|
62
|
+
try {
|
|
63
|
+
e = JSON.parse(raw);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
report.malformed++;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!e || typeof e.type !== "string") {
|
|
70
|
+
report.malformed++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (e.id) {
|
|
74
|
+
if (seen.has(e.id)) {
|
|
75
|
+
report.duplicates++;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
seen.add(e.id);
|
|
79
|
+
}
|
|
80
|
+
const data = e.data ?? {};
|
|
81
|
+
if (e.type === "session.start") {
|
|
82
|
+
const ctx = (data.context ?? {});
|
|
83
|
+
const dir = ctx.gitRoot || ctx.cwd;
|
|
84
|
+
if (dir)
|
|
85
|
+
project = path.basename(dir.replace(/[\\/]+$/, "")) || project;
|
|
86
|
+
if (typeof data.sessionId === "string")
|
|
87
|
+
sessionId = `cli:${data.sessionId}`;
|
|
88
|
+
}
|
|
89
|
+
const ts = e.timestamp ? new Date(e.timestamp) : null;
|
|
90
|
+
if (!ts || Number.isNaN(ts.getTime())) {
|
|
91
|
+
if (e.type !== "session.start")
|
|
92
|
+
report.skippedTypes[`copilot:${e.type}`] = (report.skippedTypes[`copilot:${e.type}`] ?? 0) + 1;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const base = { ts, sessionId, project, source: "copilot-cli" };
|
|
96
|
+
switch (e.type) {
|
|
97
|
+
case "user.message": {
|
|
98
|
+
const raw = typeof data.content === "string" ? data.content : "";
|
|
99
|
+
const text = raw.trimStart().startsWith("/") ? raw : cleanCopilotPrompt(raw);
|
|
100
|
+
if (!raw.trim())
|
|
101
|
+
report.excludedUser["copilot:empty"] = (report.excludedUser["copilot:empty"] ?? 0) + 1;
|
|
102
|
+
else if (text.trimStart().startsWith("/"))
|
|
103
|
+
report.excludedUser["copilot:slash-command"] = (report.excludedUser["copilot:slash-command"] ?? 0) + 1;
|
|
104
|
+
else {
|
|
105
|
+
yield { kind: "prompt", text, ...base };
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
yield { kind: "activity", ...base };
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case "session.usage_record": {
|
|
112
|
+
const u = (data.usage ?? {});
|
|
113
|
+
const cacheRead = u.cacheReadTokens ?? 0;
|
|
114
|
+
const cacheWrite = u.cacheWriteTokens ?? 0;
|
|
115
|
+
yield {
|
|
116
|
+
kind: "assistant",
|
|
117
|
+
messageId: `cli:${u.apiCallId ?? e.id ?? `${sessionId}:${report.lines}`}`,
|
|
118
|
+
model: stripVendor(u.model),
|
|
119
|
+
usage: {
|
|
120
|
+
input_tokens: Math.max(0, (u.inputTokens ?? 0) - cacheRead - cacheWrite),
|
|
121
|
+
output_tokens: u.outputTokens ?? 0,
|
|
122
|
+
cache_read_input_tokens: cacheRead,
|
|
123
|
+
cache_creation_input_tokens: cacheWrite,
|
|
124
|
+
},
|
|
125
|
+
tools: [],
|
|
126
|
+
...base,
|
|
127
|
+
};
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case "tool.execution_start": {
|
|
131
|
+
const name = typeof data.toolName === "string" ? data.toolName : "";
|
|
132
|
+
if (!name)
|
|
133
|
+
break;
|
|
134
|
+
yield { kind: "tool", tools: [{ name: normalizeTool(name), input: {} }], files: filesFromArgs(name, data.arguments), ...base };
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
default:
|
|
138
|
+
yield { kind: "activity", ...base };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|