codechart 0.5.0 → 0.6.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 +68 -0
- package/README.md +5 -5
- package/dist/cli.js +449 -90
- package/package.json +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
What's new in each codechart release. Update with `codechart update`; the [releases page](https://github.com/freeleex/codechart/releases) has the same notes.
|
|
4
|
+
|
|
5
|
+
## 0.6.0 (2026-11-06)
|
|
6
|
+
|
|
7
|
+
### New
|
|
8
|
+
|
|
9
|
+
- HTML: Light/Full switch in the header, remembered per browser. Light keeps the short diff preview; Full shows every change of a node so you can review without going back to your IDE.
|
|
10
|
+
- HTML Full: hunks are foldable per file, with a `‹ 4 / 7 ›` stepper, `+ all` / `− all`; keys `n`/`p` hunk, `]`/`[` unreviewed node, `r` reviewed, `o`/`O` fold, `?` help.
|
|
11
|
+
- HTML: review ticks, the `Reviewed` box and the `x/y reviewed` bar now live in Full mode.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Lockfiles, minified bundles, `dist/` and files marked `linguist-generated` show "generated file, not shown" instead of their diff. Full mode shows up to 1000 lines per file.
|
|
16
|
+
- HTML diffs: the `+`/`−` sign has its own column and long lines wrap under the code, keeping their indent.
|
|
17
|
+
|
|
18
|
+
## 0.5.0 (2026-11-05)
|
|
19
|
+
|
|
20
|
+
### New
|
|
21
|
+
|
|
22
|
+
- `codechart doctor` checks your setup for each agent (skill, reminder line, Stop hook, OpenCode plugin, CLI version); `--fix` repairs what's broken, `--last` explains why the last turn got no diagram.
|
|
23
|
+
- OpenCode plugin: OpenCode 2 now gets the same "3+ files changed and no map" nudge as Claude Code. `install-skill` adds it, `--no-plugin` skips it.
|
|
24
|
+
- HTML: selecting a node lights up its neighbours and dims the rest; the side panel lists its relations, each one a link.
|
|
25
|
+
- HTML: status chips under the header are the legend and a filter; click one to fade that status, `Δ changes only` fades unchanged nodes.
|
|
26
|
+
- HTML: tick nodes as reviewed, with an `x/y reviewed` count and `Next ▸`; ticks are kept per browser and reset when a node's diff changes.
|
|
27
|
+
|
|
28
|
+
## 0.4.0 (2026-11-05)
|
|
29
|
+
|
|
30
|
+
### New
|
|
31
|
+
|
|
32
|
+
- Maps in pull and merge requests: the map and its check overview in the description, re-rendered by CI on every push (GitHub and GitLab); set up with `setup-pr-maps`, see [PR maps](https://github.com/freeleex/codechart/blob/main/docs/pr-maps.md).
|
|
33
|
+
- `codechart update` installs the newest version and refreshes your skill copies and reminder lines; a once-a-day notice says when there is one (off with `updateCheck: false`).
|
|
34
|
+
- Summary maps flag changed files that no node covers, and say when the diff wasn't checked.
|
|
35
|
+
- HTML: browser Back/Forward and ← → buttons walk the nodes you opened; `#node=<id>` links open a node.
|
|
36
|
+
- Terminal map: status marker in a gutter (`+ invoices`), one block per node, and `--md` uses a `diff` fence so agents' chats colour new and removed lines.
|
|
37
|
+
- `install-skill` adds the reminder line and Claude Code hook by default (`--no-reminder`, `--no-hook` to skip) and updates older codechart skill copies in place.
|
|
38
|
+
|
|
39
|
+
### Fixed
|
|
40
|
+
|
|
41
|
+
- File and class nodes no longer look the same: map cards show the kind and a shape per kind.
|
|
42
|
+
- Labels that read as code (`_l([...])`) fail validation with a request to use plain words.
|
|
43
|
+
- Each check mismatch now says in plain words what it means.
|
|
44
|
+
|
|
45
|
+
## 0.3.1 (2026-11-03)
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
- Security review fixes; see [security review](https://github.com/freeleex/codechart/blob/main/docs/security-review.md).
|
|
50
|
+
- Faster previews on big diffs (100 files: 1.8 s → 0.1 s) and shorter agent output (one error per missing file).
|
|
51
|
+
|
|
52
|
+
## 0.3.0 (2026-11-03)
|
|
53
|
+
|
|
54
|
+
### New
|
|
55
|
+
|
|
56
|
+
- Infrastructure maps: Terraform, OpenTofu, Terragrunt, Helm, Kustomize and Kubernetes changes get a map through the built-in `infrastructure` path rule.
|
|
57
|
+
- Now/After pages show two panes only when they differ, with a `Panes: linked/separate` toggle.
|
|
58
|
+
- Listed on skills.sh; the skill says to run `npm i -g codechart` when the CLI is missing.
|
|
59
|
+
|
|
60
|
+
## 0.2.0 (2026-11-03)
|
|
61
|
+
|
|
62
|
+
### New
|
|
63
|
+
|
|
64
|
+
- Map nodes are checked against the code (file exists, quoted line matches, in the diff for summaries); output leads with the check result.
|
|
65
|
+
- Plans that change existing code render Now and After side by side, for maps and flows.
|
|
66
|
+
- Node panel shows the file's diff; the panel is wider, resizable and wraps code.
|
|
67
|
+
- Each map picks top-down or left-to-right layout, whichever fits.
|
|
68
|
+
- Opt-in reminder line and Claude Code Stop hook (`install-skill --hook`).
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<p align="center">
|
|
9
9
|
<a href="https://www.npmjs.com/package/codechart"><img alt="npm" src="https://img.shields.io/npm/v/codechart"></a>
|
|
10
10
|
<a href="https://github.com/freeleex/codechart/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/freeleex/codechart/actions/workflows/ci.yml/badge.svg"></a>
|
|
11
|
-
<a href="https://skills.sh/freeleex/codechart"><img alt="skills.sh" src="https://
|
|
11
|
+
<a href="https://skills.sh/freeleex/codechart"><img alt="skills.sh" src="https://skills.sh/b/freeleex/codechart"></a>
|
|
12
12
|
<img alt="Node 22.12+" src="https://img.shields.io/badge/node-%3E%3D22.12-339933">
|
|
13
13
|
<a href="LICENSE"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-blue"></a>
|
|
14
14
|
</p>
|
|
@@ -85,7 +85,7 @@ That's it. Open your coding agent in any repo and try:
|
|
|
85
85
|
> show me the flow of accepting an invite
|
|
86
86
|
```
|
|
87
87
|
|
|
88
|
-
Works with Claude Code, Codex, Gemini CLI, GitHub Copilot, Cursor, OpenCode and any other agent that supports [Agent Skills](https://agentskills.io). `install-skill` asks which agents get the skill, and adds a reminder line, a Claude Code hook and an OpenCode plugin so agents don't forget it in long sessions. `codechart update` brings everything up to date, and codechart tells you once a day when there's a new version. No diagram appeared? `codechart doctor` checks the setup (`--fix` repairs it, `--last` explains the last turn). Details, other agents, updating and uninstalling: [Install and agents](docs/install.md).
|
|
88
|
+
Works with Claude Code, Codex, Gemini CLI, GitHub Copilot, Cursor, OpenCode and any other agent that supports [Agent Skills](https://agentskills.io). `install-skill` asks which agents get the skill, and adds a reminder line, a Claude Code hook and an OpenCode plugin so agents don't forget it in long sessions. `codechart update` brings everything up to date (what changed: [CHANGELOG.md](CHANGELOG.md)), and codechart tells you once a day when there's a new version. No diagram appeared? `codechart doctor` checks the setup (`--fix` repairs it, `--last` explains the last turn). Details, other agents, updating and uninstalling: [Install and agents](docs/install.md).
|
|
89
89
|
|
|
90
90
|
## What you get
|
|
91
91
|
|
|
@@ -153,7 +153,7 @@ On the full page, a changed resource shows its HCL diff and changed attributes (
|
|
|
153
153
|
|
|
154
154
|
### Terminal first, page when it helps
|
|
155
155
|
|
|
156
|
-
Small diagrams stay in the reply. Big ones also get a self-contained HTML page: zoom, pan, light and dark themes, a node panel with back/forward through the nodes you opened and a list of the node's links (selecting a node dims all but it and its neighbours; Esc clears), a row of status chips under the header that count, explain and fade nodes (*Δ changes only* hides the context), and tickboxes to mark nodes reviewed (*7/12 reviewed*, *Next unreviewed*; a tick lasts until the node's diff changes)
|
|
156
|
+
Small diagrams stay in the reply. Big ones also get a self-contained HTML page: zoom, pan, light and dark themes, a node panel with back/forward through the nodes you opened and a list of the node's links (selecting a node dims all but it and its neighbours; Esc clears), a row of status chips under the header that count, explain and fade nodes (*Δ changes only* hides the context), nothing loaded from the internet. In a change summary, a node's diff is read from git when the page is built, so the agent spends no tokens on it (lockfiles, minified bundles, `dist/` and files marked `linguist-generated` are skipped). A header switch picks **Light** (default: the first 3 hunks of each diff, with a *see all in Full* hint) or **Full**: the whole diff (up to 1000 lines per file) as foldable hunks, tickboxes to mark nodes reviewed (*7/12 reviewed*, *Next unreviewed*; a tick lasts until the node's diff changes) a pager bar (‹ 3 / 10 ›, *+ all* / *− all*) and keys: `n`/`p` hunks (open one, fold the rest), `]`/`[` unreviewed nodes, `r` reviewed, `o`/`O` fold, `?` help.
|
|
157
157
|
|
|
158
158
|
### Maps in pull requests
|
|
159
159
|
|
|
@@ -184,11 +184,11 @@ The skill fires when the agent summarizes a change, writes a plan or explains ho
|
|
|
184
184
|
|
|
185
185
|
A diagram is about **2–3 extra API calls**. In a long session that's roughly 2–3% of your usage per diagram, and nothing for trivial changes. That's an estimate from Claude Code sessions with Sonnet; other agents and models will differ, and shorter sessions pay proportionally more. Measured runs are in [docs/efficiency.md](docs/efficiency.md).
|
|
186
186
|
|
|
187
|
-
The CLI is small: a
|
|
187
|
+
The CLI is small: a 110.3 kB package, 5 runtime dependencies, and a cold start around 150 ms.
|
|
188
188
|
|
|
189
189
|
## Safe to run
|
|
190
190
|
|
|
191
|
-
- No telemetry, no shell: only read-only `git` and your OS opener. The only network calls are a once-a-day version check to npm ([off with one setting](docs/install.md#updating)) and opt-in [PR maps](docs/pr-maps.md), whose CI job edits the PR description and publishes the map image.
|
|
191
|
+
- No telemetry, no shell: only read-only `git` and your OS opener. The only network calls are a once-a-day version check to npm, plus a read of the changelog from GitHub when there's a newer one ([off with one setting](docs/install.md#updating)) and opt-in [PR maps](docs/pr-maps.md), whose CI job edits the PR description and publishes the map image.
|
|
192
192
|
- HTML pages load nothing external, all text is escaped, and they're saved to `~/.cache/codechart`, never to your repo. A summary page holds your diff: share it only where you'd share the diff.
|
|
193
193
|
- Audited before release across 8 areas, including untrusted repos and prompt-injected specs: [SECURITY.md](SECURITY.md) and [docs/security-review.md](docs/security-review.md).
|
|
194
194
|
|
package/dist/cli.js
CHANGED
|
@@ -667,6 +667,17 @@ var diffArgs = (range, paths) => [
|
|
|
667
667
|
function gitFileDiff(cwd, range, rel, maxBytes) {
|
|
668
668
|
return git(cwd, diffArgs(range, [rel]), { config: [["core.bigFileThreshold", "5m"], ...range.config], maxBuffer: maxBytes });
|
|
669
669
|
}
|
|
670
|
+
function gitGeneratedAttr(cwd, rels) {
|
|
671
|
+
const out = /* @__PURE__ */ new Map();
|
|
672
|
+
if (!rels.length) return out;
|
|
673
|
+
const parts = git(cwd, ["check-attr", "-z", "--stdin", "linguist-generated"], { input: rels.map((r) => `${r}\0`).join("") }).split("\0");
|
|
674
|
+
for (let i = 0; i + 2 < parts.length; i += 3) {
|
|
675
|
+
const value = parts[i + 2];
|
|
676
|
+
if (value === "unspecified") continue;
|
|
677
|
+
out.set(parts[i], value !== "unset" && value !== "false");
|
|
678
|
+
}
|
|
679
|
+
return out;
|
|
680
|
+
}
|
|
670
681
|
var CHUNK_PATHS = 500;
|
|
671
682
|
var CHUNK_CHARS = 2e4;
|
|
672
683
|
function chunks(paths) {
|
|
@@ -1100,7 +1111,7 @@ function privateDir(dir) {
|
|
|
1100
1111
|
async function writeHtml(build, o) {
|
|
1101
1112
|
const { config, now } = o;
|
|
1102
1113
|
const file = htmlOutputPath(config, repoFolder(o.root), o.slug, now);
|
|
1103
|
-
const html = await build({ generatedAt: now, repo: basename2(o.root), repoKey: repoFolder(o.root), theme: o.theme, ...o.update && { update: o.update } });
|
|
1114
|
+
const html = await build({ generatedAt: now, repo: basename2(o.root), repoKey: repoFolder(o.root), theme: o.theme, ...o.update && { update: o.update, updateNotes: o.updateNotes } });
|
|
1104
1115
|
const dir = dirname3(file);
|
|
1105
1116
|
privateDir(dir);
|
|
1106
1117
|
writeFileSync(file, html, { mode: 384 });
|
|
@@ -1113,13 +1124,65 @@ async function writeHtml(build, o) {
|
|
|
1113
1124
|
return { file, openFailed: Boolean(failed) };
|
|
1114
1125
|
}
|
|
1115
1126
|
|
|
1127
|
+
// src/update/changelog.ts
|
|
1128
|
+
var NOTES_URL = "https://github.com/freeleex/codechart/blob/main/CHANGELOG.md";
|
|
1129
|
+
var RAW = "https://raw.githubusercontent.com/freeleex/codechart";
|
|
1130
|
+
var VERSION = /^\d+\.\d+\.\d+$/;
|
|
1131
|
+
var MAX_BYTES2 = 256 * 1024;
|
|
1132
|
+
var MAX_CHARS = 200;
|
|
1133
|
+
function parseChangelog(md2) {
|
|
1134
|
+
const releases = [];
|
|
1135
|
+
for (const line of md2.split(/\r?\n/)) {
|
|
1136
|
+
const heading = /^## (\d+\.\d+\.\d+)(?:\s|$)/.exec(line);
|
|
1137
|
+
if (heading) releases.push({ version: heading[1], bullets: [] });
|
|
1138
|
+
else if (line.startsWith("- ") && releases.length) releases.at(-1).bullets.push(line.slice(2).trim());
|
|
1139
|
+
}
|
|
1140
|
+
return releases;
|
|
1141
|
+
}
|
|
1142
|
+
function cleanBullet(s) {
|
|
1143
|
+
const text = stripInvisible(s).replace(/[\u0000-\u001f\u007f-\u009f]/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").trim();
|
|
1144
|
+
const chars = [...text];
|
|
1145
|
+
return chars.length > MAX_CHARS ? `${chars.slice(0, MAX_CHARS - 1).join("")}\u2026` : text;
|
|
1146
|
+
}
|
|
1147
|
+
function highlights(md2, current, latest, max = 5) {
|
|
1148
|
+
const all = parseChangelog(md2).filter((r) => isNewer(r.version, current) && !isNewer(r.version, latest)).sort((a, b) => isNewer(a.version, b.version) ? -1 : 1).flatMap((r) => r.bullets.map(cleanBullet)).filter(Boolean);
|
|
1149
|
+
return { bullets: all.slice(0, max), more: all.length > max };
|
|
1150
|
+
}
|
|
1151
|
+
async function readCapped(body) {
|
|
1152
|
+
const chunks2 = [];
|
|
1153
|
+
let size = 0;
|
|
1154
|
+
for await (const chunk of body) {
|
|
1155
|
+
size += chunk.byteLength;
|
|
1156
|
+
if (size > MAX_BYTES2) return void 0;
|
|
1157
|
+
chunks2.push(chunk);
|
|
1158
|
+
}
|
|
1159
|
+
return Buffer.concat(chunks2).toString("utf8");
|
|
1160
|
+
}
|
|
1161
|
+
async function fetchHighlights(fetchFn, current, latest, timeoutMs) {
|
|
1162
|
+
if (!VERSION.test(latest)) return void 0;
|
|
1163
|
+
try {
|
|
1164
|
+
const res = await fetchFn(`${RAW}/v${latest}/CHANGELOG.md`, { signal: AbortSignal.timeout(timeoutMs) });
|
|
1165
|
+
if (!res.ok || !res.body || Number(res.headers.get("content-length")) > MAX_BYTES2) return void 0;
|
|
1166
|
+
const md2 = await readCapped(res.body);
|
|
1167
|
+
if (md2 === void 0) return void 0;
|
|
1168
|
+
const found = highlights(md2, current, latest);
|
|
1169
|
+
return found.bullets.length ? found : void 0;
|
|
1170
|
+
} catch {
|
|
1171
|
+
return void 0;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function notesLines(h) {
|
|
1175
|
+
if (!h?.bullets.length) return [];
|
|
1176
|
+
return [...h.bullets.map((b) => ` - ${b}`), ...h.more ? [" - \u2026and more"] : [], ` all notes: ${NOTES_URL}`];
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1116
1179
|
// src/update/check.ts
|
|
1117
1180
|
var REGISTRY = "https://registry.npmjs.org/codechart/latest";
|
|
1118
1181
|
var DAY = 24 * 60 * 60 * 1e3;
|
|
1119
|
-
var
|
|
1182
|
+
var VERSION2 = /^\d+\.\d+\.\d+$/;
|
|
1120
1183
|
var currentVersion = () => JSON.parse(readFileSync(packageFile("package.json"), "utf8")).version;
|
|
1121
1184
|
function isNewer(a, b) {
|
|
1122
|
-
if (!
|
|
1185
|
+
if (!VERSION2.test(a) || !VERSION2.test(b)) return false;
|
|
1123
1186
|
const [x, y] = [a, b].map((v) => v.split(".").map(Number));
|
|
1124
1187
|
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i];
|
|
1125
1188
|
return false;
|
|
@@ -1129,7 +1192,7 @@ async function fetchLatest(fetchFn, timeoutMs) {
|
|
|
1129
1192
|
const res = await fetchFn(REGISTRY, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(timeoutMs) });
|
|
1130
1193
|
if (!res.ok) return void 0;
|
|
1131
1194
|
const version = (await res.json()).version;
|
|
1132
|
-
return typeof version === "string" &&
|
|
1195
|
+
return typeof version === "string" && VERSION2.test(version) ? version : void 0;
|
|
1133
1196
|
} catch {
|
|
1134
1197
|
return void 0;
|
|
1135
1198
|
}
|
|
@@ -1156,6 +1219,13 @@ function rememberSkillDir(cacheDir, dir) {
|
|
|
1156
1219
|
const dirs = skillDirs(state);
|
|
1157
1220
|
if (!dirs.includes(dir)) writeState(cacheDir, { ...state, skillDirs: [...dirs, dir] });
|
|
1158
1221
|
}
|
|
1222
|
+
var span = (from, to) => `${from}..${to}`;
|
|
1223
|
+
function knownHighlights(state, from, to) {
|
|
1224
|
+
if (state.highlightsFor !== span(from, to) || !Array.isArray(state.highlights)) return void 0;
|
|
1225
|
+
const bullets = state.highlights.filter((b) => typeof b === "string").map(cleanBullet).filter(Boolean).slice(0, 5);
|
|
1226
|
+
return bullets.length ? { bullets, more: state.highlightsMore === true } : void 0;
|
|
1227
|
+
}
|
|
1228
|
+
var withHighlights = (state, from, to, h) => h ? { ...state, highlights: h.bullets, highlightsMore: h.more, highlightsFor: span(from, to) } : state;
|
|
1159
1229
|
function knownUpdate(cacheDir, current = currentVersion()) {
|
|
1160
1230
|
const { latest } = readState(cacheDir);
|
|
1161
1231
|
return latest && isNewer(latest, current) ? latest : void 0;
|
|
@@ -1167,19 +1237,20 @@ function checkAllowed(c, installPath = packageFile("")) {
|
|
|
1167
1237
|
async function updateNotice(c) {
|
|
1168
1238
|
if (!checkAllowed(c)) return void 0;
|
|
1169
1239
|
const state = readState(c.cacheDir);
|
|
1240
|
+
const current = c.current ?? currentVersion();
|
|
1170
1241
|
let changed = false;
|
|
1171
1242
|
if (!state.checkedAt || c.now - state.checkedAt >= DAY) {
|
|
1172
1243
|
changed = true;
|
|
1173
1244
|
const latest = await fetchLatest(c.fetch, 1e3);
|
|
1174
1245
|
Object.assign(state, { checkedAt: c.now }, latest ? { latest } : {});
|
|
1246
|
+
if (latest && isNewer(latest, current) && !knownHighlights(state, current, latest)) Object.assign(state, withHighlights(state, current, latest, await fetchHighlights(c.fetch, current, latest, 1e3)));
|
|
1175
1247
|
}
|
|
1176
|
-
const current = c.current ?? currentVersion();
|
|
1177
1248
|
const told = c.terminal ? "toldTerminal" : "toldAgent";
|
|
1178
1249
|
let line;
|
|
1179
1250
|
if (state.latest && isNewer(state.latest, current) && c.now - (state[told] ?? 0) >= DAY) {
|
|
1180
1251
|
state[told] = c.now;
|
|
1181
1252
|
changed = true;
|
|
1182
|
-
line = c.terminal ? `codechart ${state.latest} is available (you have ${current}): run codechart update
|
|
1253
|
+
line = c.terminal ? [`codechart ${state.latest} is available (you have ${current}): run codechart update`, ...notesLines(knownHighlights(state, current, state.latest))].join("\n") : `codechart ${state.latest} is available (you have ${current}). Tell the user once: run \`codechart update\`.`;
|
|
1183
1254
|
}
|
|
1184
1255
|
if (changed) writeState(c.cacheDir, state);
|
|
1185
1256
|
return line;
|
|
@@ -1703,7 +1774,6 @@ import { existsSync as existsSync7, realpathSync as realpathSync3 } from "fs";
|
|
|
1703
1774
|
import { homedir as homedir3 } from "os";
|
|
1704
1775
|
import { dirname as dirname6, join as join12, resolve as resolve4, sep as sep2 } from "path";
|
|
1705
1776
|
import { Command as Command4 } from "commander";
|
|
1706
|
-
var RELEASES = "https://github.com/freeleex/codechart/releases";
|
|
1707
1777
|
var spawnOptions = (command, platform = process.platform) => platform === "win32" && command === "npm" ? { shell: true, cwd: dirname6(process.execPath) } : { shell: false };
|
|
1708
1778
|
var binary = (command) => command === "codechart" ? [process.execPath, [process.argv[1]]] : [command, []];
|
|
1709
1779
|
var defaultRunner = {
|
|
@@ -1759,7 +1829,9 @@ async function update(o, opts, runner) {
|
|
|
1759
1829
|
const latest = await fetchLatest(opts.fetch ?? fetch, 1e4);
|
|
1760
1830
|
if (!latest) throw new Error("couldn't reach the npm registry to look up the newest version");
|
|
1761
1831
|
const cacheDir = cacheDirOf(opts);
|
|
1762
|
-
|
|
1832
|
+
const state = { ...readState(cacheDir), checkedAt: opts.now?.().getTime() ?? Date.now(), latest };
|
|
1833
|
+
const notes = isNewer(latest, current) ? await fetchHighlights(opts.fetch ?? fetch, current, latest, 1e4) : void 0;
|
|
1834
|
+
writeState(cacheDir, withHighlights(state, current, latest, notes));
|
|
1763
1835
|
if (!isNewer(latest, current)) {
|
|
1764
1836
|
opts.stdout(`codechart ${current} is the newest version.
|
|
1765
1837
|
`);
|
|
@@ -1767,7 +1839,7 @@ async function update(o, opts, runner) {
|
|
|
1767
1839
|
return;
|
|
1768
1840
|
}
|
|
1769
1841
|
if (o.check) {
|
|
1770
|
-
opts.stdout(`codechart ${latest} is available (you have ${current}): run codechart update
|
|
1842
|
+
opts.stdout(`${[`codechart ${latest} is available (you have ${current}): run codechart update`, ...notesLines(notes)].join("\n")}
|
|
1771
1843
|
`);
|
|
1772
1844
|
return;
|
|
1773
1845
|
}
|
|
@@ -1779,15 +1851,16 @@ async function update(o, opts, runner) {
|
|
|
1779
1851
|
}
|
|
1780
1852
|
const how = installedBy(packageFile(""), npmRoot);
|
|
1781
1853
|
if (!how.npm) {
|
|
1782
|
-
opts.stdout(`codechart ${latest} is available (you have ${current}), but ${how.hint}.
|
|
1854
|
+
opts.stdout(`${[`codechart ${latest} is available (you have ${current}), but ${how.hint}.`, ...notesLines(notes)].join("\n")}
|
|
1783
1855
|
`);
|
|
1784
1856
|
return;
|
|
1785
1857
|
}
|
|
1786
|
-
|
|
1858
|
+
const lines = [`Updating codechart ${current} \u2192 ${latest}: npm install -g codechart@${latest}`, ...notesLines(notes)];
|
|
1859
|
+
opts.stdout(`${lines.join("\n")}
|
|
1787
1860
|
`);
|
|
1788
1861
|
runner.show("npm", ["install", "-g", `codechart@${latest}`]);
|
|
1789
1862
|
runner.show("codechart", ["update", "--skills-only"]);
|
|
1790
|
-
opts.stdout(`codechart ${latest} installed. What changed: ${
|
|
1863
|
+
opts.stdout(`codechart ${latest} installed. What changed: ${NOTES_URL}
|
|
1791
1864
|
`);
|
|
1792
1865
|
}
|
|
1793
1866
|
async function runUpdate(o, opts) {
|
|
@@ -2003,7 +2076,7 @@ function prune(dir, now) {
|
|
|
2003
2076
|
if (st.isFile() && now - st.mtimeMs > KEEP_DAYS * 864e5) unlinkSync3(p);
|
|
2004
2077
|
}
|
|
2005
2078
|
}
|
|
2006
|
-
var nudge = (
|
|
2079
|
+
var nudge = (count2) => `This turn changed ${count2} files and your reply has no codechart diagram. Unless the user said no diagram, follow the codechart skill now (check, then render) and reply with what it prints; if it says no diagram applies, stop without mentioning it.`;
|
|
2007
2080
|
function saveSnapshot(dir, file, root, now) {
|
|
2008
2081
|
const snap = snapshot(root);
|
|
2009
2082
|
mkdirSync4(dir, { recursive: true, mode: 448 });
|
|
@@ -2431,6 +2504,7 @@ aside .path{font-family:ui-monospace,monospace;font-size:11px;overflow-wrap:anyw
|
|
|
2431
2504
|
aside .snippet{font:11px/1.45 ui-monospace,monospace;background:var(--bg);border:1px solid var(--line);border-radius:4px;padding:6px 8px;margin:6px 0;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
2432
2505
|
aside .snippet code{display:grid;grid-template-columns:auto minmax(0,1fr);column-gap:10px}
|
|
2433
2506
|
aside .snippet .ln{min-width:3ch;color:var(--muted);text-align:right;user-select:none}
|
|
2507
|
+
aside .dr{display:flex}aside .dr .sg{flex:none;width:1ch;margin-right:1ch;user-select:none}aside .ind{white-space:pre;tab-size:4}aside .dr .cd{flex:1;min-width:0;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
2434
2508
|
aside .d-add{color:var(--add)}aside .d-del{color:var(--rem)}aside .d-hunk{color:var(--muted)}
|
|
2435
2509
|
aside .mismatch-note{color:var(--rem);margin:6px 0}
|
|
2436
2510
|
aside .mismatch-why{color:var(--muted);font-size:11.5px;margin:0 0 6px}
|
|
@@ -2485,10 +2559,32 @@ body.focus .node:not(.lit),body.focus .edge:not(.lit){--dim:.25}
|
|
|
2485
2559
|
.field-added-t{color:var(--add)}.field-removed-t{color:var(--muted);text-decoration:line-through}.field-modified-t{color:var(--chg-t)}
|
|
2486
2560
|
|
|
2487
2561
|
#info-toggle[aria-expanded="true"]{border-color:var(--edge)}
|
|
2488
|
-
#info-toggle,#link-toggle,#theme-toggle{align-self:center;padding:4px 10px;font:11px system-ui,sans-serif;color:var(--text);background:var(--panel);border:1px solid var(--line);border-radius:12px;cursor:pointer}
|
|
2489
|
-
#info-toggle:hover,#link-toggle:hover,#theme-toggle:hover,#next-unreviewed:hover:not(:disabled){border-color:var(--edge)}
|
|
2562
|
+
#info-toggle,#link-toggle,#mode-toggle,#theme-toggle{align-self:center;padding:4px 10px;font:11px system-ui,sans-serif;color:var(--text);background:var(--panel);border:1px solid var(--line);border-radius:12px;cursor:pointer}
|
|
2563
|
+
#info-toggle:hover,#link-toggle:hover,#mode-toggle:hover,#theme-toggle:hover,#next-unreviewed:hover:not(:disabled){border-color:var(--edge)}
|
|
2490
2564
|
#next-unreviewed{padding:0 8px;font:10.5px/16px system-ui,sans-serif;color:var(--text);background:var(--panel);border:1px solid var(--line);border-radius:10px;cursor:pointer}
|
|
2491
2565
|
#next-unreviewed:disabled{opacity:.4;cursor:default}
|
|
2566
|
+
html[data-mode="light"] .fo,html[data-mode="full"] .lo{display:none!important}
|
|
2567
|
+
aside .file-head{display:flex;gap:8px;align-items:baseline;justify-content:space-between;margin:6px 0 2px;color:var(--muted);font-size:11px}
|
|
2568
|
+
aside .file-head .path{min-width:0}
|
|
2569
|
+
aside .hunk{margin-left:-8px;padding-left:5px;border-left:3px solid transparent}
|
|
2570
|
+
aside .hunk.cur{border-left-color:var(--edge)}
|
|
2571
|
+
aside .hunk-sum{display:flex;gap:8px;align-items:baseline;width:100%;padding:1px 0;font:11px ui-monospace,monospace;color:var(--muted);background:none;border:0;text-align:left;cursor:pointer;white-space:nowrap;overflow:hidden}
|
|
2572
|
+
aside .hunk-sum:hover{color:var(--text)}
|
|
2573
|
+
aside .hunk-sum>*{flex:none}
|
|
2574
|
+
aside .hunk-sum .caret::before{content:"\\25BE"}aside .hunk.folded .caret::before{content:"\\25B8"}
|
|
2575
|
+
aside .hunk-sum .hs-fn{flex:0 1 auto;max-width:50%;min-width:0;overflow:hidden;text-overflow:ellipsis;color:var(--edge)}
|
|
2576
|
+
aside .hunk-sum .hs-first{flex:1 1 0;min-width:0;overflow:hidden;text-overflow:ellipsis}
|
|
2577
|
+
html[data-mode="full"] aside .hunk.folded .hunk-body{display:none}
|
|
2578
|
+
html[data-mode="full"] aside .hunk.folded{margin-bottom:0}
|
|
2579
|
+
aside .see-full{padding:0;font:inherit;color:var(--edge);background:none;border:0;cursor:pointer}aside .see-full:hover{text-decoration:underline}
|
|
2580
|
+
aside .hunk-end{margin:6px 0;color:var(--muted);font-size:11px;font-style:italic}
|
|
2581
|
+
#key-help{position:fixed;right:14px;bottom:14px;z-index:5;padding:8px 12px;font-size:11.5px;line-height:1.6;background:var(--panel);border:1px solid var(--line);border-radius:6px;box-shadow:0 2px 8px #0003;cursor:pointer}
|
|
2582
|
+
#key-help[hidden]{display:none}
|
|
2583
|
+
aside .pager{position:sticky;top:-10px;z-index:2;display:flex;flex-wrap:wrap;align-items:center;gap:4px 6px;margin:0 -14px 4px;padding:14px 14px 4px;background:var(--panel);border-bottom:1px solid var(--line);font-size:11px;color:var(--muted)}
|
|
2584
|
+
aside .pager button{padding:0 7px;font:13px/20px system-ui,sans-serif;color:var(--text);background:var(--panel);border:1px solid var(--line);border-radius:10px;cursor:pointer}
|
|
2585
|
+
aside .pager button:hover,aside .pager button:focus-visible{border-color:var(--edge)}aside .pager button:focus:not(:focus-visible){outline:none}
|
|
2586
|
+
aside .pager .pg-count{flex:1;min-width:0;text-align:center;white-space:nowrap}
|
|
2587
|
+
aside .pager .pg-keys{margin-left:auto;font-size:11px}aside .pager .pg-all{font:11px/20px system-ui,sans-serif}
|
|
2492
2588
|
`;
|
|
2493
2589
|
|
|
2494
2590
|
// src/render/web/client.ts
|
|
@@ -2770,17 +2866,190 @@ var CLIENT_JS = [
|
|
|
2770
2866
|
" if (id !== null)",
|
|
2771
2867
|
" toggle(id);",
|
|
2772
2868
|
" });",
|
|
2773
|
-
"
|
|
2774
|
-
"
|
|
2775
|
-
"
|
|
2776
|
-
"
|
|
2777
|
-
"
|
|
2778
|
-
"
|
|
2779
|
-
"
|
|
2780
|
-
"
|
|
2781
|
-
"
|
|
2869
|
+
" const step = (dir) => {",
|
|
2870
|
+
" var _a, _b;",
|
|
2871
|
+
" const at = ids.indexOf((_b = (_a = document.querySelector('.node.selected')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id')) !== null && _b !== void 0 ? _b : '');",
|
|
2872
|
+
" const from = at < 0 && dir < 0 ? ids.length : at;",
|
|
2873
|
+
" const to = ids.map((_, i) => ids[(((from + dir * (1 + i)) % ids.length) + ids.length) % ids.length]).find((id) => !done.has(id));",
|
|
2874
|
+
" if (to !== undefined)",
|
|
2875
|
+
" goTo(to);",
|
|
2876
|
+
" };",
|
|
2877
|
+
" if (next)",
|
|
2878
|
+
" next.addEventListener('click', () => step(1));",
|
|
2879
|
+
" const toggleSelected = () => {",
|
|
2880
|
+
" var _a;",
|
|
2881
|
+
" const id = (_a = document.querySelector('.node.selected')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-id');",
|
|
2882
|
+
" if (id)",
|
|
2883
|
+
" toggle(id);",
|
|
2884
|
+
" };",
|
|
2782
2885
|
" paint();",
|
|
2783
|
-
" return { paint };",
|
|
2886
|
+
" return { paint, step, toggleSelected };",
|
|
2887
|
+
"}",
|
|
2888
|
+
"",
|
|
2889
|
+
"const MODE_KEY = 'codechart.mode';",
|
|
2890
|
+
"const isFull = () => document.documentElement.getAttribute('data-mode') === 'full';",
|
|
2891
|
+
"function initMode(panel) {",
|
|
2892
|
+
" const btn = document.getElementById('mode-toggle');",
|
|
2893
|
+
" if (!btn)",
|
|
2894
|
+
" return;",
|
|
2895
|
+
" const set = (full, remember) => {",
|
|
2896
|
+
" document.documentElement.setAttribute('data-mode', full ? 'full' : 'light');",
|
|
2897
|
+
" btn.textContent = `Mode: ${full ? 'Full' : 'Light'}`;",
|
|
2898
|
+
" if (remember)",
|
|
2899
|
+
" save(MODE_KEY, full ? 'full' : 'light');",
|
|
2900
|
+
" };",
|
|
2901
|
+
" set(load(MODE_KEY) === 'full', false);",
|
|
2902
|
+
" btn.addEventListener('click', () => set(!isFull(), true));",
|
|
2903
|
+
" panel.addEventListener('click', (e) => {",
|
|
2904
|
+
` if (e.target.closest('[data-mode-set="full"]'))`,
|
|
2905
|
+
" set(true, true);",
|
|
2906
|
+
" });",
|
|
2907
|
+
"}",
|
|
2908
|
+
"",
|
|
2909
|
+
"const typing = (t) => {",
|
|
2910
|
+
" const el = t;",
|
|
2911
|
+
" if (!el)",
|
|
2912
|
+
" return false;",
|
|
2913
|
+
" if (el.tagName === 'INPUT')",
|
|
2914
|
+
" return !['checkbox', 'radio', 'button', 'submit', 'reset'].includes(el.type);",
|
|
2915
|
+
" return el.tagName === 'TEXTAREA' || el.tagName === 'SELECT' || el.isContentEditable === true;",
|
|
2916
|
+
"};",
|
|
2917
|
+
"const isOpen = (h) => !h.classList.contains('folded');",
|
|
2918
|
+
"function setOpen(h, open) {",
|
|
2919
|
+
" var _a;",
|
|
2920
|
+
" h.classList.toggle('folded', !open);",
|
|
2921
|
+
" (_a = h.querySelector('.hunk-sum')) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-expanded', String(open));",
|
|
2922
|
+
"}",
|
|
2923
|
+
"const hunksIn = (panel) => [...panel.querySelectorAll('.hunk')];",
|
|
2924
|
+
"function paintCount(panel, cur) {",
|
|
2925
|
+
" const label = panel.querySelector('.pg-count');",
|
|
2926
|
+
" if (!label)",
|
|
2927
|
+
" return;",
|
|
2928
|
+
" const hunks = hunksIn(panel);",
|
|
2929
|
+
" const at = cur ? hunks.indexOf(cur) + 1 : 0;",
|
|
2930
|
+
" label.textContent = `${at || '\\u2013'} / ${hunks.length}`;",
|
|
2931
|
+
" label.setAttribute('aria-label', at ? `hunk ${at} of ${hunks.length}` : `${hunks.length} hunks`);",
|
|
2932
|
+
"}",
|
|
2933
|
+
"function endNote(panel) {",
|
|
2934
|
+
" var _a;",
|
|
2935
|
+
" const note = document.createElement('p');",
|
|
2936
|
+
" note.className = 'hunk-end';",
|
|
2937
|
+
" note.textContent = 'end of node \xB7 ] next unreviewed';",
|
|
2938
|
+
" const last = (_a = hunksIn(panel).at(-1)) === null || _a === void 0 ? void 0 : _a.closest('.file');",
|
|
2939
|
+
" if (last)",
|
|
2940
|
+
" last.after(note);",
|
|
2941
|
+
" else",
|
|
2942
|
+
" panel.appendChild(note);",
|
|
2943
|
+
" return note;",
|
|
2944
|
+
"}",
|
|
2945
|
+
"function walker(panel, aside) {",
|
|
2946
|
+
" let cur = null;",
|
|
2947
|
+
" let end = null;",
|
|
2948
|
+
" const paint = () => paintCount(panel, cur);",
|
|
2949
|
+
" const mark = (h) => {",
|
|
2950
|
+
" cur === null || cur === void 0 ? void 0 : cur.classList.remove('cur');",
|
|
2951
|
+
" cur = h;",
|
|
2952
|
+
" h === null || h === void 0 ? void 0 : h.classList.add('cur');",
|
|
2953
|
+
" paint();",
|
|
2954
|
+
" };",
|
|
2955
|
+
" const hideEnd = () => {",
|
|
2956
|
+
" end === null || end === void 0 ? void 0 : end.remove();",
|
|
2957
|
+
" end = null;",
|
|
2958
|
+
" };",
|
|
2959
|
+
" const show = (h) => {",
|
|
2960
|
+
" hideEnd();",
|
|
2961
|
+
" mark(h);",
|
|
2962
|
+
" hunksIn(panel).forEach((x) => setOpen(x, x === h));",
|
|
2963
|
+
" };",
|
|
2964
|
+
" const showEnd = () => {",
|
|
2965
|
+
" end !== null && end !== void 0 ? end : (end = endNote(panel));",
|
|
2966
|
+
" };",
|
|
2967
|
+
" const setAll = (open) => hunksIn(panel).forEach((h) => setOpen(h, open));",
|
|
2968
|
+
" return {",
|
|
2969
|
+
" step(dir) {",
|
|
2970
|
+
" if (end && dir < 0) {",
|
|
2971
|
+
" if (cur)",
|
|
2972
|
+
" show(cur);",
|
|
2973
|
+
" return;",
|
|
2974
|
+
" }",
|
|
2975
|
+
" const hunks = hunksIn(panel);",
|
|
2976
|
+
" const i = cur ? hunks.indexOf(cur) : -1;",
|
|
2977
|
+
" const to = hunks[dir > 0 ? i + 1 : Math.max(0, i - 1)];",
|
|
2978
|
+
" if (to)",
|
|
2979
|
+
" show(to);",
|
|
2980
|
+
" else if (dir > 0)",
|
|
2981
|
+
" showEnd();",
|
|
2982
|
+
" },",
|
|
2983
|
+
" toggle() {",
|
|
2984
|
+
" const h = cur !== null && cur !== void 0 ? cur : hunksIn(panel)[0];",
|
|
2985
|
+
" if (h)",
|
|
2986
|
+
" setOpen(h, !isOpen(h));",
|
|
2987
|
+
" },",
|
|
2988
|
+
" toggleAll() {",
|
|
2989
|
+
" setAll(!hunksIn(panel).every(isOpen));",
|
|
2990
|
+
" },",
|
|
2991
|
+
" setAll,",
|
|
2992
|
+
" pick(h) {",
|
|
2993
|
+
" setOpen(h, !isOpen(h));",
|
|
2994
|
+
" mark(h);",
|
|
2995
|
+
" hideEnd();",
|
|
2996
|
+
" },",
|
|
2997
|
+
" reset() {",
|
|
2998
|
+
" cur = null;",
|
|
2999
|
+
" end = null;",
|
|
3000
|
+
" aside.scrollTop = 0;",
|
|
3001
|
+
" paint();",
|
|
3002
|
+
" },",
|
|
3003
|
+
" };",
|
|
3004
|
+
"}",
|
|
3005
|
+
"function initHunks(panel, review) {",
|
|
3006
|
+
" const nav = walker(panel, panel.closest('aside'));",
|
|
3007
|
+
" const help = document.getElementById('key-help');",
|
|
3008
|
+
" const toggleHelp = () => {",
|
|
3009
|
+
" help.hidden = !help.hidden;",
|
|
3010
|
+
" };",
|
|
3011
|
+
" const keys = {",
|
|
3012
|
+
" n: () => nav.step(1),",
|
|
3013
|
+
" p: () => nav.step(-1),",
|
|
3014
|
+
" ']': () => review.step(1),",
|
|
3015
|
+
" '[': () => review.step(-1),",
|
|
3016
|
+
" r: () => review.toggleSelected(),",
|
|
3017
|
+
" o: () => nav.toggle(),",
|
|
3018
|
+
" O: () => nav.toggleAll(),",
|
|
3019
|
+
" '?': toggleHelp,",
|
|
3020
|
+
" };",
|
|
3021
|
+
" const buttons = {",
|
|
3022
|
+
" '.pg-prev': () => nav.step(-1),",
|
|
3023
|
+
" '.pg-next': () => nav.step(1),",
|
|
3024
|
+
" '.pg-expand': () => nav.setAll(true),",
|
|
3025
|
+
" '.pg-collapse': () => nav.setAll(false),",
|
|
3026
|
+
" '.pg-keys': toggleHelp,",
|
|
3027
|
+
" };",
|
|
3028
|
+
" panel.addEventListener('click', (e) => {",
|
|
3029
|
+
" var _a;",
|
|
3030
|
+
" const t = e.target;",
|
|
3031
|
+
" const h = (_a = t.closest('.hunk-sum')) === null || _a === void 0 ? void 0 : _a.closest('.hunk');",
|
|
3032
|
+
" if (h)",
|
|
3033
|
+
" nav.pick(h);",
|
|
3034
|
+
" for (const [sel, run] of Object.entries(buttons))",
|
|
3035
|
+
" if (t.closest(sel))",
|
|
3036
|
+
" run();",
|
|
3037
|
+
" });",
|
|
3038
|
+
" help.addEventListener('click', () => {",
|
|
3039
|
+
" help.hidden = true;",
|
|
3040
|
+
" });",
|
|
3041
|
+
" window.addEventListener('keydown', (e) => {",
|
|
3042
|
+
" if (e.key === 'Escape')",
|
|
3043
|
+
" help.hidden = true;",
|
|
3044
|
+
" if (e.ctrlKey || e.metaKey || e.altKey || typing(e.target) || !isFull())",
|
|
3045
|
+
" return;",
|
|
3046
|
+
" const run = Object.hasOwn(keys, e.key) ? keys[e.key] : undefined;",
|
|
3047
|
+
" if (!run)",
|
|
3048
|
+
" return;",
|
|
3049
|
+
" e.preventDefault();",
|
|
3050
|
+
" run();",
|
|
3051
|
+
" });",
|
|
3052
|
+
" return { reset: nav.reset };",
|
|
2784
3053
|
"}",
|
|
2785
3054
|
"",
|
|
2786
3055
|
"const THEMES = ['auto', 'light', 'dark'];",
|
|
@@ -2883,6 +3152,7 @@ var CLIENT_JS = [
|
|
|
2883
3152
|
" }",
|
|
2884
3153
|
" setInfo(!tpl);",
|
|
2885
3154
|
" review.paint();",
|
|
3155
|
+
" hunks.reset();",
|
|
2886
3156
|
"}",
|
|
2887
3157
|
"function reveal(v) {",
|
|
2888
3158
|
" if (v === null)",
|
|
@@ -3026,12 +3296,14 @@ var CLIENT_JS = [
|
|
|
3026
3296
|
"initPanZoom();",
|
|
3027
3297
|
"initPaneLink();",
|
|
3028
3298
|
"initTheme();",
|
|
3299
|
+
"initMode(panel);",
|
|
3029
3300
|
"initPanelResize();",
|
|
3030
3301
|
"window.addEventListener('resize', fit);",
|
|
3031
3302
|
"fit();",
|
|
3032
3303
|
"dismissFocus(canvases, () => moved);",
|
|
3033
3304
|
"initChips();",
|
|
3034
3305
|
"const review = initReview(data.repoKey, goTo);",
|
|
3306
|
+
"const hunks = initHunks(panel, review);",
|
|
3035
3307
|
"initPanel();",
|
|
3036
3308
|
"})();",
|
|
3037
3309
|
""
|
|
@@ -3069,6 +3341,7 @@ function midpoint(points) {
|
|
|
3069
3341
|
return points[0] ?? { x: 0, y: 0 };
|
|
3070
3342
|
}
|
|
3071
3343
|
var keyHtml = (key) => key.map((k) => `<span class="k-${k.tone}">${esc(k.text)}</span>`).join(" \xB7 ");
|
|
3344
|
+
var KEY_HELP = ["n / p: next / previous hunk (opens it, folds the others)", "] / [: next / previous unreviewed node", "r: toggle reviewed", "o / O: fold this hunk / toggle all hunks", "?: this help"];
|
|
3072
3345
|
var CSP = `default-src 'none'; style-src 'unsafe-inline'; script-src 'sha256-${createHash2("sha256").update(CLIENT_JS).digest("base64")}'; img-src data:; base-uri 'none'; form-action 'none'`;
|
|
3073
3346
|
function renderPage(p) {
|
|
3074
3347
|
const theme = p.meta.theme && THEMES.includes(p.meta.theme) ? p.meta.theme : "auto";
|
|
@@ -3078,18 +3351,19 @@ function renderPage(p) {
|
|
|
3078
3351
|
<g class="viewport">${viewport3}</g></svg></div>`;
|
|
3079
3352
|
const body = p.panes ? `<div id="panes">${p.panes.map((pane, i) => `<section class="pane" aria-label="${esc(pane.title)}"><div class="pane-title">${esc(pane.title)}<span class="pane-key"> \xB7 ${keyHtml(pane.key)}</span></div>${canvas(pane.viewport, i)}</section>`).join("")}</div>` : canvas(p.viewport, 0);
|
|
3080
3353
|
return `<!doctype html>
|
|
3081
|
-
<html lang="en" data-theme="${theme}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
3354
|
+
<html lang="en" data-theme="${theme}" data-mode="${p.modes ? "light" : "full"}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
3082
3355
|
<meta http-equiv="Content-Security-Policy" content="${CSP}">
|
|
3083
3356
|
<title>${esc(p.title)}</title>
|
|
3084
3357
|
<style>${CSS}${p.extraCss ?? ""}</style></head>
|
|
3085
3358
|
<body>
|
|
3086
|
-
<header><h1>${esc(p.title)}</h1>${p.headerNote ?? ""}<span class="meta">${esc(p.meta.repo)} \xB7 ${esc(p.meta.generatedAt.toISOString())}</span>${p.meta.update ? `<span class="update" title="A newer codechart is out">codechart ${esc(p.meta.update)} is out: run <code>codechart update</code></span>` : ""}${p.infoButton}${p.panes ? '<button id="link-toggle" type="button" title="Linked: panning or zooming one pane moves both"></button>' : ""}<button id="theme-toggle" type="button" title="Cycle theme: auto, light, dark"></button></header>
|
|
3359
|
+
<header><h1>${esc(p.title)}</h1>${p.headerNote ?? ""}<span class="meta">${esc(p.meta.repo)} \xB7 ${esc(p.meta.generatedAt.toISOString())}</span>${p.meta.update ? `<span class="update" title="${esc(["A newer codechart is out", ...(p.meta.updateNotes ?? []).map((n) => `- ${n}`)].join("\n"))}">codechart ${esc(p.meta.update)} is out: run <code>codechart update</code></span>` : ""}${p.infoButton}${p.modes ? '<button id="mode-toggle" type="button" title="Light: short diffs. Full: whole diffs, review ticks and keys (n p ] [ r o ?)"></button>' : ""}${p.panes ? '<button id="link-toggle" type="button" title="Linked: panning or zooming one pane moves both"></button>' : ""}<button id="theme-toggle" type="button" title="Cycle theme: auto, light, dark"></button></header>
|
|
3087
3360
|
${p.toolbar ? `<div id="toolbar">${p.toolbar}</div>
|
|
3088
3361
|
` : ""}<main>
|
|
3089
3362
|
${body}
|
|
3090
3363
|
<div id="resize" role="separator" aria-orientation="vertical" aria-label="Resize panel" tabindex="0" title="Drag to resize the panel"></div>
|
|
3091
3364
|
<aside><nav id="panel-nav" aria-label="Panel history"><button id="nav-back" type="button" disabled aria-label="Back" title="Back (Alt+\u2190)">\u2190</button><button id="nav-forward" type="button" disabled aria-label="Forward" title="Forward (Alt+\u2192)">\u2192</button></nav>${p.aside}</aside>
|
|
3092
3365
|
</main>
|
|
3366
|
+
<div id="key-help" role="dialog" aria-label="Keys" hidden><b>Keys (Full)</b>${KEY_HELP.map((k) => `<div>${esc(k)}</div>`).join("")}</div>
|
|
3093
3367
|
<script type="application/json" id="spec-data">${jsonForScript(data)}</script>
|
|
3094
3368
|
<script>${CLIENT_JS}</script>
|
|
3095
3369
|
</body></html>
|
|
@@ -3193,8 +3467,8 @@ function labelLines(label) {
|
|
|
3193
3467
|
return [label.slice(0, at).trimEnd(), rest.length > LABEL_MORE_CHARS ? rest.slice(0, LABEL_MORE_CHARS - 1) + "\u2026" : rest];
|
|
3194
3468
|
}
|
|
3195
3469
|
var headerHeight = (label) => HEADER_HEIGHT + LABEL_LINE_HEIGHT * (labelLines(label).length - 1);
|
|
3196
|
-
function nodeHeight(label, fields,
|
|
3197
|
-
const summaryLines =
|
|
3470
|
+
function nodeHeight(label, fields, summary2) {
|
|
3471
|
+
const summaryLines = summary2 ? wrapSummary(summary2).length : 0;
|
|
3198
3472
|
return headerHeight(label) + LINE_HEIGHT * (fields + summaryLines);
|
|
3199
3473
|
}
|
|
3200
3474
|
var FIT_CANVASES = [
|
|
@@ -3436,19 +3710,19 @@ function shapeIssues(spec, facts, issue) {
|
|
|
3436
3710
|
for (const li of linkIdx) if (!spec.links[li].label) issue(["links", li, "label"], "required on a link leaving a decision");
|
|
3437
3711
|
};
|
|
3438
3712
|
spec.steps.forEach((step, i) => {
|
|
3439
|
-
const
|
|
3440
|
-
if (step.type === void 0 && step.label.trim().endsWith("?") &&
|
|
3441
|
-
issue(["steps", i, "type"], `label ends in "?", so this is a decision: it needs at least 2 outgoing links, has ${
|
|
3713
|
+
const count2 = (facts.live.get(step.id) ?? []).length;
|
|
3714
|
+
if (step.type === void 0 && step.label.trim().endsWith("?") && count2 < 2 && !facts.branchesNow(step.id)) {
|
|
3715
|
+
issue(["steps", i, "type"], `label ends in "?", so this is a decision: it needs at least 2 outgoing links, has ${count2}`);
|
|
3442
3716
|
return;
|
|
3443
3717
|
}
|
|
3444
3718
|
const type = facts.typeOf(step);
|
|
3445
|
-
if (type === "end" &&
|
|
3446
|
-
if (type === "step" &&
|
|
3719
|
+
if (type === "end" && count2 > 0) issue(["steps", i, "type"], `an end has no outgoing links, has ${count2}`);
|
|
3720
|
+
if (type === "step" && count2 > 1) issue(["steps", i, "type"], `has ${count2} outgoing links; make it a decision with labelled branches`);
|
|
3447
3721
|
if (type !== "decision") {
|
|
3448
3722
|
if (facts.branchesNow(step.id)) needLabels(facts.nowOut.get(step.id) ?? []);
|
|
3449
3723
|
return;
|
|
3450
3724
|
}
|
|
3451
|
-
if (
|
|
3725
|
+
if (count2 < 2) issue(["steps", i, "id"], `decision "${step.id}" needs at least 2 outgoing links, has ${count2}`);
|
|
3452
3726
|
needLabels(facts.outgoing.get(step.id) ?? []);
|
|
3453
3727
|
});
|
|
3454
3728
|
}
|
|
@@ -3535,10 +3809,10 @@ function statusChips(statuses) {
|
|
|
3535
3809
|
}
|
|
3536
3810
|
return chips.length ? `<div id="chips" role="group" aria-label="Status filter">${chips.join("")}</div>` : "";
|
|
3537
3811
|
}
|
|
3538
|
-
var reviewControls = (total) => `<div id="review"><span id="review-count">0/${total} reviewed</span><span id="review-bar" aria-hidden="true"><i></i></span><button id="next-unreviewed" type="button" title="Next unreviewed: select the next node not ticked as reviewed" aria-label="Next unreviewed">Next \u25B8</button></div>`;
|
|
3812
|
+
var reviewControls = (total) => `<div id="review" class="fo"><span id="review-count">0/${total} reviewed</span><span id="review-bar" aria-hidden="true"><i></i></span><button id="next-unreviewed" type="button" title="Next unreviewed: select the next node not ticked as reviewed" aria-label="Next unreviewed">Next \u25B8</button></div>`;
|
|
3539
3813
|
var diffRev = (p) => p ? createHash3("sha256").update(JSON.stringify(p)).digest("hex").slice(0, 12) : void 0;
|
|
3540
|
-
var tickSvg = (x, y) => `<g class="tick" aria-hidden="true"><rect class="tick-hit" x="${num(x - 9)}" y="${num(y - 9)}" width="18" height="18"/><rect class="tick-box" x="${num(x - 6)}" y="${num(y - 6)}" width="12" height="12" rx="2"/><path class="tick-mark" d="M${num(x - 3)},${num(y)} L${num(x - 1)},${num(y + 3)} L${num(x + 3.5)},${num(y - 3)}"/></g>`;
|
|
3541
|
-
var tickRow = (id) => `<label class="tick-row"><input type="checkbox" data-tick-for="${esc(id)}"> Reviewed</label>`;
|
|
3814
|
+
var tickSvg = (x, y) => `<g class="tick fo" aria-hidden="true"><rect class="tick-hit" x="${num(x - 9)}" y="${num(y - 9)}" width="18" height="18"/><rect class="tick-box" x="${num(x - 6)}" y="${num(y - 6)}" width="12" height="12" rx="2"/><path class="tick-mark" d="M${num(x - 3)},${num(y)} L${num(x - 1)},${num(y + 3)} L${num(x + 3.5)},${num(y - 3)}"/></g>`;
|
|
3815
|
+
var tickRow = (id) => `<label class="tick-row fo"><input type="checkbox" data-tick-for="${esc(id)}"> Reviewed</label>`;
|
|
3542
3816
|
var note = (l) => l.label || (l.kind !== "other" ? l.kind : void 0);
|
|
3543
3817
|
function relationsOf(id, links, labelOf2) {
|
|
3544
3818
|
return links.flatMap((l) => {
|
|
@@ -3591,7 +3865,8 @@ function renderDiagramPage(p) {
|
|
|
3591
3865
|
width: p.width,
|
|
3592
3866
|
height: p.height,
|
|
3593
3867
|
extraCss: p.extraCss,
|
|
3594
|
-
extraDefs: p.extraDefs
|
|
3868
|
+
extraDefs: p.extraDefs,
|
|
3869
|
+
modes: p.modes
|
|
3595
3870
|
});
|
|
3596
3871
|
}
|
|
3597
3872
|
|
|
@@ -3767,7 +4042,21 @@ function renderLink(link, e, tone, ends) {
|
|
|
3767
4042
|
});
|
|
3768
4043
|
}
|
|
3769
4044
|
var pathHtml = (p) => esc(p).replaceAll("/", "/<wbr>");
|
|
3770
|
-
var
|
|
4045
|
+
var TAB = 4;
|
|
4046
|
+
var splitIndent = (code) => {
|
|
4047
|
+
const rest = code.trimStart();
|
|
4048
|
+
const lead = code.slice(0, code.length - rest.length);
|
|
4049
|
+
const width = [...lead].reduce((w, c) => w + (c === " " ? TAB : 1), 0);
|
|
4050
|
+
return [width, lead ? `<span class="ind">${lead}</span>${rest}` : rest];
|
|
4051
|
+
};
|
|
4052
|
+
var codeRow = (n, code, cls, extra = "", sign) => {
|
|
4053
|
+
const both = (c) => c || extra ? ` class="${[c, extra].filter(Boolean).join(" ")}"` : "";
|
|
4054
|
+
const [indent, text] = n === void 0 ? [0, code] : splitIndent(code);
|
|
4055
|
+
const pad2 = indent ? ` style="padding-left:${indent}ch;text-indent:-${indent}ch"` : "";
|
|
4056
|
+
const ln = `<span${both("ln")}>${n ?? ""}</span>`;
|
|
4057
|
+
if (sign === void 0) return `${ln}<span${both(cls)}${pad2}>${text}</span>`;
|
|
4058
|
+
return `${ln}<span${both(`${cls} dr`)}><span class="sg">${sign}</span><span class="cd"${pad2}>${text}</span></span>`;
|
|
4059
|
+
};
|
|
3771
4060
|
function snippetHtml(s) {
|
|
3772
4061
|
const code = s.lines.map((l, i) => codeRow(s.startLine + i, esc(l))).join("\n");
|
|
3773
4062
|
const end = Number(s.source.match(/-(\d+)$/)?.[1] ?? s.startLine);
|
|
@@ -3848,6 +4137,56 @@ function renderFlowHtml(spec, layout, snippets, meta, check) {
|
|
|
3848
4137
|
});
|
|
3849
4138
|
}
|
|
3850
4139
|
|
|
4140
|
+
// src/render/web/changes.ts
|
|
4141
|
+
var LIGHT_HUNKS = 3;
|
|
4142
|
+
var LIGHT_ROWS = 40;
|
|
4143
|
+
var SMALL_LINES = 80;
|
|
4144
|
+
var SMALL_HUNKS = 6;
|
|
4145
|
+
var MARK3 = { add: "+", del: "-", ctx: " " };
|
|
4146
|
+
var HEADER = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@ ?(.*)$/;
|
|
4147
|
+
function hunksOf(lines) {
|
|
4148
|
+
const out = [];
|
|
4149
|
+
for (const l of lines) {
|
|
4150
|
+
if (l.kind === "hunk") out.push([l]);
|
|
4151
|
+
else out.at(-1)?.push(l);
|
|
4152
|
+
}
|
|
4153
|
+
return out;
|
|
4154
|
+
}
|
|
4155
|
+
var PAGER = '<div class="pager fo" role="group" aria-label="Hunks"><button type="button" class="pg-prev" aria-label="Previous hunk" title="Previous hunk (p)">\u2039</button><span class="pg-count" role="status" aria-label="{n} hunks">\u2013 / {n}</span><button type="button" class="pg-next" aria-label="Next hunk" title="Next hunk (n)">\u203A</button><button type="button" class="pg-all pg-expand" aria-label="Expand all" title="Expand all hunks">+ all</button><button type="button" class="pg-all pg-collapse" aria-label="Collapse all" title="Collapse all hunks">\u2212 all</button><button type="button" class="pg-keys" aria-label="Show keys" title="Keys">? keys</button></div>';
|
|
4156
|
+
var count = (n) => `${n} changed line${n === 1 ? "" : "s"}`;
|
|
4157
|
+
function summary(rows, folded) {
|
|
4158
|
+
const [head, ...body] = rows;
|
|
4159
|
+
const m = HEADER.exec(head.text);
|
|
4160
|
+
const add = body.filter((l) => l.kind === "add").length;
|
|
4161
|
+
const del = body.filter((l) => l.kind === "del").length;
|
|
4162
|
+
const first = body.find((l) => l.kind !== "ctx");
|
|
4163
|
+
return `<button type="button" class="hunk-sum fo" aria-expanded="${!folded}"><span class="caret" aria-hidden="true"></span><span class="hs-stat"><span class="d-add">+${add}</span> <span class="d-del">\u2212${del}</span></span>` + (m ? `<span class="hs-ln">L${m[1]}</span>` : "") + (m?.[2] ? `<span class="hs-fn">${esc(m[2])}</span>` : "") + (first ? `<span class="hs-first">${esc(MARK3[first.kind] + first.text.trim())}</span>` : "") + `</button>`;
|
|
4164
|
+
}
|
|
4165
|
+
function changesHtml(p) {
|
|
4166
|
+
const title = "<h3>Changes</h3>";
|
|
4167
|
+
if (p.note) return `${title}<p class="more">${esc(p.note)}</p>`;
|
|
4168
|
+
const hunks = hunksOf(p.lines);
|
|
4169
|
+
const pager = hunks.length > 1 ? PAGER.replaceAll("{n}", String(hunks.length)) : "";
|
|
4170
|
+
const folded = p.total > SMALL_LINES || hunks.length > SMALL_HUNKS;
|
|
4171
|
+
let before = 0;
|
|
4172
|
+
let lightChanged = 0;
|
|
4173
|
+
const body = hunks.map((rows, i) => {
|
|
4174
|
+
const start = before;
|
|
4175
|
+
before += rows.length;
|
|
4176
|
+
const inLight = (j) => i < LIGHT_HUNKS && start + j < LIGHT_ROWS;
|
|
4177
|
+
const html = rows.map((l, j) => {
|
|
4178
|
+
const fo = inLight(j) ? "" : "fo";
|
|
4179
|
+
if (l.kind === "hunk") return codeRow(void 0, esc(l.text), "d-hunk", `lo ${fo}`.trim());
|
|
4180
|
+
if (fo === "" && l.kind !== "ctx") lightChanged++;
|
|
4181
|
+
return codeRow(l.n, esc(l.text), `d-${l.kind}`, fo, MARK3[l.kind]);
|
|
4182
|
+
}).join("\n");
|
|
4183
|
+
return `<div class="hunk${folded ? " folded" : ""}${inLight(0) ? "" : " fo"}">${summary(rows, folded)}<code class="hunk-body">${html}</code></div>`;
|
|
4184
|
+
});
|
|
4185
|
+
const light = lightChanged < p.total ? `<button type="button" class="see-full" data-mode-set="full">showing ${lightChanged} of ${p.total} changed lines \xB7 see all in Full</button>` : count(p.total);
|
|
4186
|
+
const full = p.rows > p.lines.length ? `showing ${p.lines.length} of ${p.rows} lines` : count(p.total);
|
|
4187
|
+
return `${title}${pager}<div class="file"><div class="file-head fo"><span class="path">${pathHtml(p.path)}</span><span>${count(p.total)}</span></div><div class="snippet diff">${body.join("")}</div></div><p class="more"><span class="lo">${light}</span><span class="fo">${full}</span> \xB7 whole file: <span class="path">${pathHtml(p.path)}</span></p>`;
|
|
4188
|
+
}
|
|
4189
|
+
|
|
3851
4190
|
// src/render/web/html.ts
|
|
3852
4191
|
var FIELD_CHARS = 34;
|
|
3853
4192
|
function clip(s, max) {
|
|
@@ -3911,17 +4250,6 @@ function renderNode(n, box, flag, fields, rev) {
|
|
|
3911
4250
|
return `<g class="node status-${n.status} shape-${shape2}" data-id="${esc(n.id)}" data-status="${n.status}"${rev ? ` data-rev="${rev}"` : ""} tabindex="0" role="button" aria-label="${esc(`${n.label} (${nodeWhat(n)}${flagged2 ? ", doesn't match the code" : ""})`)}">` + flag + cardShape(shape2, { x, y, w, h: height }, head) + `<line class="head" x1="${x}" y1="${y + head}" x2="${x + w}" y2="${y + head}"/>` + (n.kind === "other" ? "" : `<text class="kind" x="${x + 8}" y="${y + 12}">${n.kind}</text>`) + labelLines(n.label).map((l, i) => `<text class="label" x="${x + 8}" y="${top + i * LABEL_LINE_HEIGHT}">${esc(l)}</text>`).join("") + `<text class="badge" x="${x + w - 8}" y="${top}">${esc(n.status)}</text>` + lines.join("") + tickSvg(x, y) + (flagged2 ? flagMark(shape2 === "file" ? x + w - FOLD - 6 : x + w, y) : "") + `</g>`;
|
|
3912
4251
|
}
|
|
3913
4252
|
var FIELDS_NOTE = "Only the fields the agent saw are listed. Set <code>defaults.context: full</code> in <code>.codechart.yaml</code> to let it read the full definition.";
|
|
3914
|
-
var DIFF_MARK = { add: "+", del: "-", ctx: " " };
|
|
3915
|
-
function previewHtml(p) {
|
|
3916
|
-
let out = "<h3>Changes</h3>";
|
|
3917
|
-
if (p.note) return `${out}<p class="more">${esc(p.note)}</p>`;
|
|
3918
|
-
const rows = p.lines.map(
|
|
3919
|
-
(l) => l.kind === "hunk" ? codeRow(void 0, esc(l.text), "d-hunk") : codeRow(l.n, esc(DIFF_MARK[l.kind] + l.text), `d-${l.kind}`)
|
|
3920
|
-
);
|
|
3921
|
-
out += `<pre class="snippet diff"><code>${rows.join("\n")}</code></pre>`;
|
|
3922
|
-
const count = p.shown < p.total ? `showing ${p.shown} of ${p.total} changed lines` : `${p.total} changed line${p.total === 1 ? "" : "s"}`;
|
|
3923
|
-
return `${out}<p class="more">${count} \xB7 whole file: <span class="path">${pathHtml(p.path)}</span></p>`;
|
|
3924
|
-
}
|
|
3925
4253
|
var fieldList = (fields) => `<ul>${fields.map((f) => `<li${f.change ? ` class="field-${f.change}-t"` : ""}>${esc(fieldText(f))}</li>`).join("")}</ul>`;
|
|
3926
4254
|
function fieldsHtml(n, sides2) {
|
|
3927
4255
|
if (!sides2 || !nodeOn("now", n.status) || !nodeOn("after", n.status)) return `<h3>Fields</h3>${fieldList(n.fields)}`;
|
|
@@ -3938,7 +4266,7 @@ function cardPanel(spec, n, check, previews, sides2) {
|
|
|
3938
4266
|
else if (n.path) out += `<div class="path">${pathHtml(n.path)}</div>`;
|
|
3939
4267
|
if (n.summary) out += `<p>${esc(n.summary)}</p>`;
|
|
3940
4268
|
const preview = previews?.get(n.id);
|
|
3941
|
-
if (preview) out +=
|
|
4269
|
+
if (preview) out += changesHtml(preview);
|
|
3942
4270
|
if (n.fields?.length) {
|
|
3943
4271
|
out += fieldsHtml(n, sides2);
|
|
3944
4272
|
if (n.fieldsComplete === false) out += `<p class="fields-note">${FIELDS_NOTE}</p>`;
|
|
@@ -3993,7 +4321,8 @@ function renderHtml(spec, layout, meta, check, previews) {
|
|
|
3993
4321
|
aside: `${pageInfo2(spec, check, sides2)}<div id="panel" hidden></div>${spec.nodes.map((n) => cardPanel(spec, n, check, previews, sides2)).join("")}`,
|
|
3994
4322
|
width: layout.width,
|
|
3995
4323
|
height: layout.height,
|
|
3996
|
-
extraDefs: CHANGE_ARROWS
|
|
4324
|
+
extraDefs: CHANGE_ARROWS,
|
|
4325
|
+
modes: Boolean(previews?.size)
|
|
3997
4326
|
});
|
|
3998
4327
|
}
|
|
3999
4328
|
|
|
@@ -4050,8 +4379,8 @@ ${JSON.stringify(spec).replace(/</g, "\\u003c").replace(/>/g, "\\u003e")}
|
|
|
4050
4379
|
-->`;
|
|
4051
4380
|
var imageHref = (url) => encodeURI(url).replace(/[()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
4052
4381
|
function prBlock(spec, check, imageUrl) {
|
|
4053
|
-
const
|
|
4054
|
-
const counts = [`${spec.nodes.length} nodes`, `${
|
|
4382
|
+
const count2 = (s) => spec.nodes.filter((n) => n.status === s).length;
|
|
4383
|
+
const counts = [`${spec.nodes.length} nodes`, `${count2("new")} new`, `${count2("changed")} changed`, ...count2("removed") ? [`${count2("removed")} removed`] : []].join(" \xB7 ");
|
|
4055
4384
|
const url = imageHref(imageUrl);
|
|
4056
4385
|
const nodes = [...spec.nodes].sort((a, b) => STATUS_ORDER.indexOf(a.status) - STATUS_ORDER.indexOf(b.status));
|
|
4057
4386
|
const parts = [
|
|
@@ -4201,12 +4530,12 @@ import { realpathSync as realpathSync4, statSync as statSync2 } from "fs";
|
|
|
4201
4530
|
import { isAbsolute as isAbsolute3, relative as relative2, resolve as resolve5, sep as sep3 } from "path";
|
|
4202
4531
|
|
|
4203
4532
|
// src/render/clip.ts
|
|
4204
|
-
var
|
|
4205
|
-
var clip2 = (l) => l.length >
|
|
4533
|
+
var MAX_CHARS2 = 300;
|
|
4534
|
+
var clip2 = (l) => l.length > MAX_CHARS2 ? `${l.slice(0, MAX_CHARS2)}\u2026` : l;
|
|
4206
4535
|
|
|
4207
4536
|
// src/render/flow/anchors.ts
|
|
4208
4537
|
var SNIPPET_MAX_LINES = 15;
|
|
4209
|
-
var
|
|
4538
|
+
var MAX_BYTES3 = 5 * 1024 * 1024;
|
|
4210
4539
|
var MAX_TOTAL_BYTES = 25 * 1024 * 1024;
|
|
4211
4540
|
var escapes = (rel) => rel === ".." || rel.startsWith(`..${sep3}`) || isAbsolute3(rel);
|
|
4212
4541
|
var inGit = (rel) => rel.split(sep3).some((s) => s.toLowerCase() === ".git");
|
|
@@ -4221,7 +4550,7 @@ var overBudget = (path3) => ({
|
|
|
4221
4550
|
function readLinesAt(path3, rel, root, sha, budget) {
|
|
4222
4551
|
try {
|
|
4223
4552
|
if (budget.left <= 0) return overBudget(path3);
|
|
4224
|
-
const r = gitFileAt(root, sha, rel.split(sep3).join("/"),
|
|
4553
|
+
const r = gitFileAt(root, sha, rel.split(sep3).join("/"), MAX_BYTES3);
|
|
4225
4554
|
if (typeof r !== "string") return r;
|
|
4226
4555
|
budget.left -= Buffer.byteLength(r);
|
|
4227
4556
|
return budget.left < 0 ? overBudget(path3) : toLines(r);
|
|
@@ -4244,7 +4573,7 @@ function readLines(path3, root, realRoot, budget) {
|
|
|
4244
4573
|
let refused2;
|
|
4245
4574
|
const text = readRegularFile(real, (st) => {
|
|
4246
4575
|
if (!st.isFile()) refused2 = { error: `${path3} is not a regular file` };
|
|
4247
|
-
else if (st.size >
|
|
4576
|
+
else if (st.size > MAX_BYTES3) refused2 = { error: `${path3} is too large (over 5 MB)` };
|
|
4248
4577
|
else if (st.size > budget.left) refused2 = overBudget(path3);
|
|
4249
4578
|
else budget.left -= st.size;
|
|
4250
4579
|
return refused2 === void 0;
|
|
@@ -4591,10 +4920,10 @@ function defaultWidth(stdout = process.stdout, env = process.env) {
|
|
|
4591
4920
|
return Number.isFinite(fromEnv) && fromEnv > 0 && fromEnv <= MAX_ENV_WIDTH ? fromEnv : NOT_TTY_WIDTH;
|
|
4592
4921
|
}
|
|
4593
4922
|
function footer(spec, hidden, { width, htmlPath, check }, keyLine) {
|
|
4594
|
-
const
|
|
4595
|
-
const removed =
|
|
4923
|
+
const count2 = (status) => spec.nodes.filter((n) => n.status === status).length;
|
|
4924
|
+
const removed = count2("removed") > 0 ? ` \xB7 ${count2("removed")} removed` : "";
|
|
4596
4925
|
const lines = [
|
|
4597
|
-
countLines(`${spec.nodes.length} nodes \xB7 ${
|
|
4926
|
+
countLines(`${spec.nodes.length} nodes \xB7 ${count2("new")} new \xB7 ${count2("changed")} changed${removed} \xB7 ${count2("config")} config`, check, width)
|
|
4598
4927
|
];
|
|
4599
4928
|
if (keyLine) lines.push(truncate(KEY2, width));
|
|
4600
4929
|
if (spec.gaps?.length) lines.push(wrapItems("gaps: ", spec.gaps.map(flat), width));
|
|
@@ -4774,10 +5103,10 @@ function chainLines(chain, first, rest, lead, ctx) {
|
|
|
4774
5103
|
return lines;
|
|
4775
5104
|
}
|
|
4776
5105
|
function footer2(spec, ctx, md2) {
|
|
4777
|
-
const
|
|
5106
|
+
const count2 = (status) => spec.steps.filter((s) => s.status === status).length;
|
|
4778
5107
|
const lines = [
|
|
4779
5108
|
countLines(
|
|
4780
|
-
`${spec.steps.length} steps \xB7 ${
|
|
5109
|
+
`${spec.steps.length} steps \xB7 ${count2("new")} new \xB7 ${count2("changed")} changed \xB7 ${count2("planned")} planned${count2("removed") ? ` \xB7 ${count2("removed")} removed` : ""}`,
|
|
4781
5110
|
ctx.check,
|
|
4782
5111
|
ctx.width
|
|
4783
5112
|
)
|
|
@@ -5150,22 +5479,47 @@ import { writeFileSync as writeFileSync6 } from "fs";
|
|
|
5150
5479
|
// src/render/preview.ts
|
|
5151
5480
|
import { lstatSync as lstatSync9, realpathSync as realpathSync5 } from "fs";
|
|
5152
5481
|
import { dirname as dirname7, join as join19, resolve as resolve9, sep as sep5 } from "path";
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
var
|
|
5482
|
+
|
|
5483
|
+
// src/render/generated.ts
|
|
5484
|
+
var LOCKFILES = /* @__PURE__ */ new Set([
|
|
5485
|
+
"package-lock.json",
|
|
5486
|
+
"npm-shrinkwrap.json",
|
|
5487
|
+
"yarn.lock",
|
|
5488
|
+
"pnpm-lock.yaml",
|
|
5489
|
+
"bun.lock",
|
|
5490
|
+
"Cargo.lock",
|
|
5491
|
+
"Gemfile.lock",
|
|
5492
|
+
"poetry.lock",
|
|
5493
|
+
"composer.lock",
|
|
5494
|
+
"go.sum"
|
|
5495
|
+
]);
|
|
5496
|
+
var byName = (rel) => LOCKFILES.has(rel.slice(rel.lastIndexOf("/") + 1)) || /\.min\.(js|css)$/.test(rel) || /(^|\/)dist\//.test(rel);
|
|
5497
|
+
function generatedFiles(root, rels) {
|
|
5498
|
+
let attr = /* @__PURE__ */ new Map();
|
|
5499
|
+
try {
|
|
5500
|
+
attr = gitGeneratedAttr(root, rels.filter((r) => !r.includes("\n")));
|
|
5501
|
+
} catch {
|
|
5502
|
+
}
|
|
5503
|
+
return new Set(rels.filter((r) => attr.get(r) ?? byName(r)));
|
|
5504
|
+
}
|
|
5505
|
+
|
|
5506
|
+
// src/render/preview.ts
|
|
5507
|
+
var MAX_ROWS = 1e3;
|
|
5508
|
+
var MAX_BYTES4 = 5 * 1024 * 1024;
|
|
5156
5509
|
var MAX_TOTAL_BYTES2 = 25 * 1024 * 1024;
|
|
5157
5510
|
function parseDiff(path3, text) {
|
|
5158
|
-
const p = { path: path3, lines: [],
|
|
5511
|
+
const p = { path: path3, lines: [], total: 0, rows: 0 };
|
|
5159
5512
|
let hunks = 0;
|
|
5160
5513
|
let oldN = 0;
|
|
5161
5514
|
let newN = 0;
|
|
5162
|
-
const room = () =>
|
|
5515
|
+
const room = () => p.lines.length < MAX_ROWS;
|
|
5163
5516
|
for (const raw of text.split("\n")) {
|
|
5164
5517
|
const h = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(raw);
|
|
5165
5518
|
if (h) {
|
|
5166
5519
|
hunks++;
|
|
5167
5520
|
oldN = Number(h[1]);
|
|
5168
5521
|
newN = Number(h[2]);
|
|
5522
|
+
p.rows++;
|
|
5169
5523
|
if (room()) p.lines.push({ kind: "hunk", text: clip2(raw) });
|
|
5170
5524
|
continue;
|
|
5171
5525
|
}
|
|
@@ -5181,32 +5535,32 @@ function parseDiff(path3, text) {
|
|
|
5181
5535
|
oldN++;
|
|
5182
5536
|
} else continue;
|
|
5183
5537
|
if (line.kind !== "ctx") p.total++;
|
|
5184
|
-
|
|
5185
|
-
p.lines.push({ ...line, text: clip2(line.text.replace(/\r$/, "")) });
|
|
5186
|
-
if (line.kind !== "ctx") p.shown++;
|
|
5538
|
+
p.rows++;
|
|
5539
|
+
if (room()) p.lines.push({ ...line, text: clip2(line.text.replace(/\r$/, "")) });
|
|
5187
5540
|
}
|
|
5188
5541
|
return p;
|
|
5189
5542
|
}
|
|
5190
5543
|
var TOO_LARGE2 = "diff is too large (over 5 MB)";
|
|
5191
5544
|
var OVER_BUDGET = "not shown: the diffs pass 25 MB together";
|
|
5545
|
+
var GENERATED = { note: "generated file, not shown" };
|
|
5192
5546
|
function untrackedPreview(root, rel, budget, max) {
|
|
5193
5547
|
let size = 0;
|
|
5194
5548
|
const text = readRegularFile(join19(root, rel), (st) => st.isFile() && (size = st.size) <= max);
|
|
5195
|
-
if (text === void 0) return { note: size >
|
|
5549
|
+
if (text === void 0) return { note: size > MAX_BYTES4 ? TOO_LARGE2 : size > max ? OVER_BUDGET : "not a regular file" };
|
|
5196
5550
|
if (text.includes("\0")) return { note: "binary file" };
|
|
5197
5551
|
if (PRIVATE_KEY.test(text)) return SECRET;
|
|
5198
5552
|
budget.left -= Buffer.byteLength(text);
|
|
5199
5553
|
const all = text.split("\n");
|
|
5200
5554
|
if (all[all.length - 1] === "") all.pop();
|
|
5201
|
-
const
|
|
5555
|
+
const kept = all.slice(0, MAX_ROWS - 1);
|
|
5202
5556
|
return {
|
|
5203
5557
|
path: rel,
|
|
5204
5558
|
lines: [
|
|
5205
5559
|
{ kind: "hunk", text: `@@ -0,0 +1,${all.length} @@` },
|
|
5206
|
-
...
|
|
5560
|
+
...kept.map((l, i) => ({ kind: "add", n: i + 1, text: clip2(l.replace(/\r$/, "")) }))
|
|
5207
5561
|
],
|
|
5208
|
-
|
|
5209
|
-
|
|
5562
|
+
total: all.length,
|
|
5563
|
+
rows: all.length + 1
|
|
5210
5564
|
};
|
|
5211
5565
|
}
|
|
5212
5566
|
var SECRET = { note: "not shown: looks like a secret" };
|
|
@@ -5231,10 +5585,10 @@ var worktreeSize = (root, rel) => {
|
|
|
5231
5585
|
const path3 = join19(root, rel);
|
|
5232
5586
|
return insideRoot(root, path3) ? lstatSync9(path3, { throwIfNoEntry: false })?.size ?? 0 : 0;
|
|
5233
5587
|
};
|
|
5234
|
-
function prefetch(root, range, rels) {
|
|
5588
|
+
function prefetch(root, range, rels, generated) {
|
|
5235
5589
|
const pre = noPrefetch();
|
|
5236
5590
|
try {
|
|
5237
|
-
const cands = rels.filter((r) => !looksSecret(r) && !r.includes("\n"));
|
|
5591
|
+
const cands = rels.filter((r) => !looksSecret(r) && !r.includes("\n") && !generated.has(r));
|
|
5238
5592
|
const specs = cands.flatMap((r) => range.revs.map((rev) => `${rev}:${r}`));
|
|
5239
5593
|
gitBlobSizes(root, specs).forEach((size, i) => pre.sizes.set(specs[i], size));
|
|
5240
5594
|
let room = MAX_TOTAL_BYTES2;
|
|
@@ -5243,7 +5597,7 @@ function prefetch(root, range, rels) {
|
|
|
5243
5597
|
for (const r of cands) {
|
|
5244
5598
|
const keys = range.revs.map((rev) => `${rev}:${r}`).filter((k) => pre.sizes.get(k) !== void 0);
|
|
5245
5599
|
const sizes = [...keys.map((k) => pre.sizes.get(k)), ...range.worktree ? [worktreeSize(root, r)] : []];
|
|
5246
|
-
if (sizes.some((n) => n >
|
|
5600
|
+
if (sizes.some((n) => n > MAX_BYTES4)) continue;
|
|
5247
5601
|
const cost = sizes.reduce((a, b) => a + b, 0);
|
|
5248
5602
|
if (cost > room) break;
|
|
5249
5603
|
room -= cost;
|
|
@@ -5266,7 +5620,7 @@ function prefetch(root, range, rels) {
|
|
|
5266
5620
|
}
|
|
5267
5621
|
function sides(root, range, rel, budget, pre) {
|
|
5268
5622
|
const take = (size) => {
|
|
5269
|
-
if (size >
|
|
5623
|
+
if (size > MAX_BYTES4) return TOO_LARGE2;
|
|
5270
5624
|
if (size > budget.left) return OVER_BUDGET;
|
|
5271
5625
|
budget.left -= size;
|
|
5272
5626
|
return void 0;
|
|
@@ -5291,15 +5645,16 @@ function sides(root, range, rel, budget, pre) {
|
|
|
5291
5645
|
}
|
|
5292
5646
|
return texts;
|
|
5293
5647
|
}
|
|
5294
|
-
function fileDiff(root, range, rel, budget, pre) {
|
|
5648
|
+
function fileDiff(root, range, rel, budget, pre, generated) {
|
|
5295
5649
|
if (looksSecret(rel)) return SECRET;
|
|
5296
5650
|
if (rel.includes("\n")) return { note: "not shown: the file name has a line break" };
|
|
5297
|
-
|
|
5651
|
+
if (generated.has(rel)) return GENERATED;
|
|
5652
|
+
let max = MAX_BYTES4;
|
|
5298
5653
|
try {
|
|
5299
5654
|
const files = sides(root, range, rel, budget, pre);
|
|
5300
5655
|
if (!Array.isArray(files)) return files;
|
|
5301
5656
|
if (files.some((t) => PRIVATE_KEY.test(t))) return SECRET;
|
|
5302
|
-
max = Math.min(
|
|
5657
|
+
max = Math.min(MAX_BYTES4, budget.left);
|
|
5303
5658
|
if (max <= 0) return { note: OVER_BUDGET };
|
|
5304
5659
|
const batched = pre.diffs.get(rel);
|
|
5305
5660
|
if (batched !== void 0 && Buffer.byteLength(batched) > max) throw new OutputTooLarge(`git output over ${max} bytes`);
|
|
@@ -5310,7 +5665,7 @@ function fileDiff(root, range, rel, budget, pre) {
|
|
|
5310
5665
|
budget.left -= Buffer.byteLength(shown);
|
|
5311
5666
|
return PRIVATE_KEY.test(shown) ? SECRET : shown;
|
|
5312
5667
|
} catch (e) {
|
|
5313
|
-
if (e instanceof OutputTooLarge) return { note: max <
|
|
5668
|
+
if (e instanceof OutputTooLarge) return { note: max < MAX_BYTES4 ? OVER_BUDGET : TOO_LARGE2 };
|
|
5314
5669
|
return { note: `diff not read (${e.message})` };
|
|
5315
5670
|
}
|
|
5316
5671
|
}
|
|
@@ -5325,15 +5680,17 @@ function nodePreviews(spec, root, diff, range, found, cwd) {
|
|
|
5325
5680
|
const rel = candidates2.find((p) => diff.hasFile(p));
|
|
5326
5681
|
if (rel !== void 0) rels.set(node.id, rel);
|
|
5327
5682
|
}
|
|
5328
|
-
const
|
|
5683
|
+
const files = [...new Set(rels.values())];
|
|
5684
|
+
const generated = generatedFiles(root, files);
|
|
5685
|
+
const pre = prefetch(root, range, files, generated);
|
|
5329
5686
|
const byFile = /* @__PURE__ */ new Map();
|
|
5330
5687
|
const budget = { left: MAX_TOTAL_BYTES2 };
|
|
5331
5688
|
for (const node of spec.nodes) {
|
|
5332
5689
|
const rel = rels.get(node.id);
|
|
5333
5690
|
if (rel === void 0) continue;
|
|
5334
5691
|
if (!byFile.has(rel)) {
|
|
5335
|
-
const r = budget.left > 0 ? fileDiff(root, range, rel, budget, pre) : { note: OVER_BUDGET };
|
|
5336
|
-
byFile.set(rel, typeof r === "string" ? r === "" ? void 0 : parseDiff(rel, r) : "lines" in r ? r : { path: rel, lines: [],
|
|
5692
|
+
const r = budget.left > 0 ? fileDiff(root, range, rel, budget, pre, generated) : { note: OVER_BUDGET };
|
|
5693
|
+
byFile.set(rel, typeof r === "string" ? r === "" ? void 0 : parseDiff(rel, r) : "lines" in r ? r : { path: rel, lines: [], total: 0, rows: 0, note: r.note });
|
|
5337
5694
|
}
|
|
5338
5695
|
const preview = byFile.get(rel);
|
|
5339
5696
|
if (preview) out.set(node.id, preview);
|
|
@@ -5468,6 +5825,7 @@ async function renderSpec(arg, o, opts, cwd) {
|
|
|
5468
5825
|
}
|
|
5469
5826
|
const env = opts.env ?? process.env;
|
|
5470
5827
|
const slug = fileSlug(spec.title, target.diagram);
|
|
5828
|
+
const update2 = checkAllowed({ enabled: config.updateCheck, env: { ...process.env, ...env } }) ? knownUpdate(config.web.outDir) : void 0;
|
|
5471
5829
|
const ctx = {
|
|
5472
5830
|
output,
|
|
5473
5831
|
minNodes: config.web.minNodes,
|
|
@@ -5493,7 +5851,8 @@ async function renderSpec(arg, o, opts, cwd) {
|
|
|
5493
5851
|
inEditor: inCodeEditor(env),
|
|
5494
5852
|
open: opts.open ?? openInBrowser,
|
|
5495
5853
|
stderr: opts.stderr,
|
|
5496
|
-
update:
|
|
5854
|
+
update: update2,
|
|
5855
|
+
updateNotes: update2 ? knownHighlights(readState(config.web.outDir), currentVersion(), update2)?.bullets : void 0
|
|
5497
5856
|
})
|
|
5498
5857
|
};
|
|
5499
5858
|
const { text, check, html } = target.diagram === "flow" ? await renderFlow(target.spec, target, ctx) : await renderMap(target.spec, ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codechart",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Agent skill + CLI: maps and flowcharts of code changes for AI coding agents, in terminal, chat and HTML",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-skills",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"skills",
|
|
40
40
|
"templates",
|
|
41
41
|
"config.schema.json",
|
|
42
|
+
"CHANGELOG.md",
|
|
42
43
|
"THIRD_PARTY_NOTICES.md"
|
|
43
44
|
],
|
|
44
45
|
"engines": {
|