visualproof 0.8.2 → 0.10.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/README.md +12 -9
- package/dist/assets/tips/tour-library.webp +0 -0
- package/dist/assets/tips/tour-source.webp +0 -0
- package/dist/assets/tips/tour.json +90 -90
- package/dist/extractor/Extract.lean +34 -11
- package/dist/mcp/visualproof-mcp.mjs +30 -5
- package/dist/server/agent.js +19 -7
- package/dist/server/agententry.js +13 -6
- package/dist/server/agentexport.js +2 -1
- package/dist/server/agentfollow.js +13 -3
- package/dist/server/agentlean.js +91 -1
- package/dist/server/agentnotes.js +6 -4
- package/dist/server/agentread.js +33 -1
- package/dist/server/app.js +7 -3
- package/dist/server/appagent.js +1 -1
- package/dist/server/appgraph.js +24 -0
- package/dist/server/appshare.js +119 -1
- package/dist/server/apptalk.js +26 -0
- package/dist/server/boardspots.js +1 -1
- package/dist/server/children.js +6 -2
- package/dist/server/claudetokens.js +113 -0
- package/dist/server/doctor.js +7 -0
- package/dist/server/goals.js +224 -0
- package/dist/server/hosted.js +480 -0
- package/dist/server/hover.js +281 -8
- package/dist/server/live.js +34 -2
- package/dist/server/main.js +30 -2
- package/dist/server/mcptools.js +15 -7
- package/dist/server/options.js +30 -2
- package/dist/server/presence.js +2 -2
- package/dist/server/prompt.js +25 -0
- package/dist/server/readonlygate.js +2 -1
- package/dist/server/reviewapi.js +5 -2
- package/dist/server/status.js +43 -5
- package/dist/server/tokens.js +7 -4
- package/dist/shared/build.js +9 -0
- package/dist/shared/collab.js +17 -2
- package/dist/shared/declfind.js +23 -3
- package/dist/shared/goals.js +309 -0
- package/dist/shared/hygiene.js +18 -0
- package/dist/shared/noteplace.js +45 -19
- package/dist/shared/scope.js +74 -45
- package/dist/shared/sharesnap.js +4 -2
- package/dist/web/bundle/app.js +2368 -591
- package/dist/web/index.html +2 -1
- package/dist/web/src/highlight.js +53 -3
- package/dist/web/style.css +151 -0
- package/docs/agent-api/README.md +1 -1
- package/docs/agent-api/mcp.md +4 -2
- package/docs/agent-api/notes.md +3 -2
- package/docs/agent-api/reading.md +38 -2
- package/docs/agent-api/talking.md +7 -0
- package/docs/agent-api/words.md +3 -2
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// The Claude Code OAuth tokens people give in Share (AgentSpec decision 10; the owner's decisions of
|
|
2
|
+
// 2026-11-08, experimental, behind --claude-oauth): a person's own token, made with `claude
|
|
3
|
+
// setup-token`, on which the agents they run on this server run (server/hosted.ts). One per person:
|
|
4
|
+
// their personal link's id where they came by one, else their name (as madeBy compares makers,
|
|
5
|
+
// shared/collab.ts), so that it is theirs whatever name they go by.
|
|
6
|
+
//
|
|
7
|
+
// It is worth more than anything else the site keeps: a year of the person's Claude subscription. So
|
|
8
|
+
// it is given once and never shown again — not to its holder, not to any page, agent, log or error —
|
|
9
|
+
// and kept in `<site>/claude-tokens.json`, readable by the server's user alone, as the agents' tokens
|
|
10
|
+
// and the personal links are. What the server does with it is hand it to the `claude` processes of
|
|
11
|
+
// its holder's agents, in their environment (never on a command line). Its holder replaces or removes
|
|
12
|
+
// it; a personal link revoked takes its token with it. Removing it here deletes the server's copy
|
|
13
|
+
// only: the token itself lasts until it expires or is revoked at Anthropic.
|
|
14
|
+
//
|
|
15
|
+
// No API key: the owner's decision (an `sk-ant-api…` key is refused, so that nobody gives one by
|
|
16
|
+
// mistake and is billed by the token).
|
|
17
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { sameName } from "../shared/collab.js";
|
|
20
|
+
const FILE = "claude-tokens.json";
|
|
21
|
+
/** what `claude setup-token` prints: `sk-ant-oat01-…` (108 characters on 2026-11-08) */
|
|
22
|
+
const OAUTH = /^sk-ant-oat\d{2}-[A-Za-z0-9_-]{20,400}$/;
|
|
23
|
+
/** Why `s` is not a Claude Code OAuth token; null when it looks like one. */
|
|
24
|
+
export function invalidClaudeToken(s) {
|
|
25
|
+
if (typeof s !== "string" || !s.trim())
|
|
26
|
+
return "Paste the token `claude setup-token` printed.";
|
|
27
|
+
const t = s.trim();
|
|
28
|
+
if (/^sk-ant-api/.test(t))
|
|
29
|
+
return "This is an API key: this server takes a Claude Code OAuth token, which `claude setup-token` prints (sk-ant-oat…).";
|
|
30
|
+
if (!OAUTH.test(t))
|
|
31
|
+
return "This is not a Claude Code OAuth token: `claude setup-token` prints one that starts with sk-ant-oat.";
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/** Whether `k` is `who`'s: by the personal link where it was given under one, else by the name. */
|
|
35
|
+
const holds = (k, who) => (k.person ? who.person === k.person : !who.person && sameName(k.name, who.name));
|
|
36
|
+
export class ClaudeTokens {
|
|
37
|
+
file;
|
|
38
|
+
kept = [];
|
|
39
|
+
/** told when a holder's token was given, replaced, refused or removed: their agents on the server
|
|
40
|
+
* start again, or stop (server/hosted.ts) */
|
|
41
|
+
onChanged = () => { };
|
|
42
|
+
/** `siteDir` null keeps them in memory only (tests). */
|
|
43
|
+
constructor(siteDir) {
|
|
44
|
+
this.file = siteDir ? join(siteDir, FILE) : null;
|
|
45
|
+
if (this.file && existsSync(this.file)) {
|
|
46
|
+
try {
|
|
47
|
+
const data = JSON.parse(readFileSync(this.file, "utf8"));
|
|
48
|
+
if (Array.isArray(data.tokens))
|
|
49
|
+
this.kept = data.tokens.filter(isKept);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// a file that cannot be read gives no token; it is kept aside, not overwritten blindly
|
|
53
|
+
renameSync(this.file, `${this.file}.broken-${Date.now()}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** What `who` is told of their token, or null where they gave none. */
|
|
58
|
+
info(who) {
|
|
59
|
+
const k = this.kept.find((x) => holds(x, who));
|
|
60
|
+
return k ? { given: k.given, refused: k.refused } : null;
|
|
61
|
+
}
|
|
62
|
+
/** The token an agent made by `maker` runs on (its record's `by` and `makerPerson`), or null: none
|
|
63
|
+
* given, or refused since. */
|
|
64
|
+
forMaker(maker) {
|
|
65
|
+
const k = this.kept.find((x) => holds(x, { person: maker.makerPerson ?? null, name: maker.by }));
|
|
66
|
+
return k && !k.refused ? k.token : null;
|
|
67
|
+
}
|
|
68
|
+
/** Give `who`'s token, in place of the one they gave before. Checked by the caller. */
|
|
69
|
+
give(who, token, now = Date.now()) {
|
|
70
|
+
this.kept = this.kept.filter((x) => !holds(x, who));
|
|
71
|
+
this.kept.push({ ...(who.person ? { person: who.person } : {}), name: who.name, token: token.trim(), given: new Date(now).toISOString(), refused: null });
|
|
72
|
+
this.save();
|
|
73
|
+
this.onChanged(who);
|
|
74
|
+
}
|
|
75
|
+
/** Remove `who`'s token; false when they gave none. */
|
|
76
|
+
remove(who) {
|
|
77
|
+
const before = this.kept.length;
|
|
78
|
+
this.kept = this.kept.filter((x) => !holds(x, who));
|
|
79
|
+
if (this.kept.length === before)
|
|
80
|
+
return false;
|
|
81
|
+
this.save();
|
|
82
|
+
this.onChanged(who);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
/** Claude Code refused `token` (expired, revoked at Anthropic): it is not used again until its
|
|
86
|
+
* holder gives one anew. */
|
|
87
|
+
refuse(token, now = Date.now()) {
|
|
88
|
+
const k = this.kept.find((x) => x.token === token);
|
|
89
|
+
if (!k || k.refused)
|
|
90
|
+
return;
|
|
91
|
+
k.refused = new Date(now).toISOString();
|
|
92
|
+
this.save();
|
|
93
|
+
this.onChanged({ person: k.person ?? null, name: k.name });
|
|
94
|
+
}
|
|
95
|
+
/** A personal link was revoked: its holder's token goes with it. */
|
|
96
|
+
dropPerson(person) {
|
|
97
|
+
const k = this.kept.find((x) => x.person === person);
|
|
98
|
+
if (k)
|
|
99
|
+
this.remove({ person, name: k.name });
|
|
100
|
+
}
|
|
101
|
+
save() {
|
|
102
|
+
if (!this.file)
|
|
103
|
+
return;
|
|
104
|
+
const tmp = `${this.file}.tmp`;
|
|
105
|
+
writeFileSync(tmp, JSON.stringify({ tokens: this.kept }, null, 1) + "\n", { mode: 0o600 });
|
|
106
|
+
renameSync(tmp, this.file);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function isKept(x) {
|
|
110
|
+
const k = x;
|
|
111
|
+
return !!k && typeof k === "object" && typeof k.name === "string" && typeof k.token === "string" && OAUTH.test(k.token) && typeof k.given === "string" &&
|
|
112
|
+
(k.person === undefined || typeof k.person === "string") && (k.refused === null || typeof k.refused === "string");
|
|
113
|
+
}
|
package/dist/server/doctor.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { spawnSync } from "node:child_process";
|
|
6
6
|
import { accessSync, constants, existsSync, readFileSync, statSync } from "node:fs";
|
|
7
7
|
import { filmPin } from "./film.js";
|
|
8
|
+
import { findClaude } from "./hosted.js";
|
|
8
9
|
import { freemem, tmpdir, totalmem } from "node:os";
|
|
9
10
|
import { dirname, join, relative, resolve } from "node:path";
|
|
10
11
|
import { cacheHome, projectDirs, siteHolder } from "./dirs.js";
|
|
@@ -182,6 +183,12 @@ export function doctor(o) {
|
|
|
182
183
|
if (exec("git", ["--version"]) === null) {
|
|
183
184
|
checks.push({ level: "info", what: "git not found: builds are kept without their commit, and past sources only as the builds kept them; a branch cannot be followed (serve <git URL>)" });
|
|
184
185
|
}
|
|
186
|
+
// the agents a server runs on their makers' Claude Code (--claude-oauth, AgentSpec decision 10)
|
|
187
|
+
const claude = findClaude();
|
|
188
|
+
const claudeVersion = exec(o.run ? "claude" : (claude ?? "claude"), ["--version"]);
|
|
189
|
+
checks.push(claudeVersion
|
|
190
|
+
? { level: "ok", what: `Claude Code ${claudeVersion.trim().split(/\s/)[0]} (for --claude-oauth, agents the server runs)` }
|
|
191
|
+
: { level: "info", what: "Claude Code (claude) not found: needed only for --claude-oauth (agents the server runs)", fix: "npm install -g @anthropic-ai/claude-code" });
|
|
185
192
|
const film = filmLine(o.cache ? resolve(o.cache) : cacheHome(), o.updates ?? process.env.VISUALPROOF_UPDATES);
|
|
186
193
|
const updates = updatesLine(exec, node, o.fromPackage ?? FROM_PACKAGE, o.cache ? resolve(o.cache) : cacheHome(), o.updates ?? process.env.VISUALPROOF_UPDATES, o.path === null ? null : projectDirs(resolve(o.path), o.site, o.cache).site);
|
|
187
194
|
if (o.path === null)
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// Lean's answers about goals, read for the InfoView (ReviewSpec, "The InfoView"; shared/goals.ts):
|
|
2
|
+
// its plain ones (`$/lean/plainGoal`, `$/lean/plainTermGoal`) and its interactive ones, through its
|
|
3
|
+
// RPC (`Lean.Widget.getInteractiveGoals`, `getInteractiveTermGoal`), whose text is tagged with what
|
|
4
|
+
// each subterm is: a reference into the RPC session (`{p: "12"}`), which Lean answers
|
|
5
|
+
// `infoToInteractive` about (the subterm's type and doc). A page is never given a reference: each
|
|
6
|
+
// subterm is numbered in the answer (`k`), and the server asks Lean by the reference it holds for
|
|
7
|
+
// that number. What is read is checked and bounded: a goal whose text runs past what a page shows
|
|
8
|
+
// is cut, and past a number of subterms the rest is text alone.
|
|
9
|
+
import { CHANGES } from "../shared/goals.js";
|
|
10
|
+
import { parsePlainGoal } from "../shared/goals.js";
|
|
11
|
+
/** the most subterms numbered in one answer: past it, the rest is text */
|
|
12
|
+
export const MAX_TAGS = 20_000;
|
|
13
|
+
/** the most characters of goals one answer carries, all its texts together */
|
|
14
|
+
export const MAX_TEXT = 400_000;
|
|
15
|
+
/** how deep a tagged text is read: deeper, it is text */
|
|
16
|
+
const MAX_DEPTH = 400;
|
|
17
|
+
const isRef = (x) => !!x && typeof x === "object" && typeof x.p === "string" && x.p.length <= 64;
|
|
18
|
+
/** What one answer reads: the references its subterms are numbered by (`refs[k]`), and what is
|
|
19
|
+
* left of its bounds. */
|
|
20
|
+
export class Reading {
|
|
21
|
+
refs = [];
|
|
22
|
+
text = 0;
|
|
23
|
+
cut = false;
|
|
24
|
+
/** Lean's tagged text (`CodeWithInfos`: `{text}`, `{append: […]}`, `{tag: [info, text]}`) read
|
|
25
|
+
* as the page's; a subterm numbered by its reference. */
|
|
26
|
+
code(c, depth = 0) {
|
|
27
|
+
if (!c || typeof c !== "object")
|
|
28
|
+
return "";
|
|
29
|
+
if (depth > MAX_DEPTH)
|
|
30
|
+
return this.take(plainText(c));
|
|
31
|
+
const o = c;
|
|
32
|
+
if (typeof o.text === "string")
|
|
33
|
+
return this.take(o.text);
|
|
34
|
+
if (Array.isArray(o.append)) {
|
|
35
|
+
const parts = o.append.map((x) => this.code(x, depth + 1)).filter((x) => x !== "");
|
|
36
|
+
return parts.length === 1 ? parts[0] : parts;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(o.tag) && o.tag.length === 2) {
|
|
39
|
+
const [info, inner] = o.tag;
|
|
40
|
+
const t = this.code(inner, depth + 1);
|
|
41
|
+
const ref = info && typeof info === "object" ? info.info : null;
|
|
42
|
+
if (!isRef(ref) || this.refs.length >= MAX_TAGS || this.cut)
|
|
43
|
+
return t;
|
|
44
|
+
const d = info.diffStatus;
|
|
45
|
+
this.refs.push(ref);
|
|
46
|
+
return { k: this.refs.length - 1, t, ...(CHANGES.includes(d) ? { d: d } : {}) };
|
|
47
|
+
}
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
/** a text, within what is left of the answer's */
|
|
51
|
+
take(s) {
|
|
52
|
+
if (this.cut)
|
|
53
|
+
return "";
|
|
54
|
+
const left = MAX_TEXT - this.text;
|
|
55
|
+
if (s.length <= left) {
|
|
56
|
+
this.text += s.length;
|
|
57
|
+
return s;
|
|
58
|
+
}
|
|
59
|
+
this.cut = true;
|
|
60
|
+
this.text = MAX_TEXT;
|
|
61
|
+
return s.slice(0, Math.max(0, left)) + "…";
|
|
62
|
+
}
|
|
63
|
+
/** A hypothesis bundle as Lean gives it (`InteractiveHypothesisBundle`). */
|
|
64
|
+
hyp(h) {
|
|
65
|
+
if (!h || typeof h !== "object")
|
|
66
|
+
return null;
|
|
67
|
+
const o = h;
|
|
68
|
+
const names = Array.isArray(o.names) ? o.names.filter((n) => typeof n === "string").map((n) => n.slice(0, 300)) : [];
|
|
69
|
+
if (!names.length)
|
|
70
|
+
return null;
|
|
71
|
+
const d = o.isInserted === true ? "inserted" : o.isRemoved === true ? "removed" : undefined;
|
|
72
|
+
return { names, type: this.code(o.type), ...(o.val ? { val: this.code(o.val) } : {}), ...(d ? { d } : {}) };
|
|
73
|
+
}
|
|
74
|
+
/** A goal as Lean gives it (`InteractiveGoal`). */
|
|
75
|
+
goal(g) {
|
|
76
|
+
if (!g || typeof g !== "object")
|
|
77
|
+
return null;
|
|
78
|
+
const o = g;
|
|
79
|
+
const hyps = (Array.isArray(o.hyps) ? o.hyps : []).map((h) => this.hyp(h)).filter((h) => h !== null);
|
|
80
|
+
const d = o.isInserted === true ? "inserted" : o.isRemoved === true ? "removed" : undefined;
|
|
81
|
+
const prefix = typeof o.goalPrefix === "string" && o.goalPrefix.length <= 8 ? o.goalPrefix : "⊢ ";
|
|
82
|
+
return { ...(typeof o.userName === "string" && o.userName ? { case: o.userName.slice(0, 300) } : {}), hyps, type: this.code(o.type), prefix, ...(d ? { d } : {}) };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Lean's interactive goals (`InteractiveGoals`, `{goals}`), or null where it has none there. */
|
|
86
|
+
export function readInteractiveGoals(r, reading) {
|
|
87
|
+
if (!r || typeof r !== "object" || !Array.isArray(r.goals))
|
|
88
|
+
return null;
|
|
89
|
+
return r.goals.map((g) => reading.goal(g)).filter((g) => g !== null);
|
|
90
|
+
}
|
|
91
|
+
/** Lean's interactive term goal (`InteractiveTermGoal`: hypotheses, type, range), or null. */
|
|
92
|
+
export function readInteractiveTermGoal(r, reading) {
|
|
93
|
+
if (!r || typeof r !== "object")
|
|
94
|
+
return null;
|
|
95
|
+
const o = r;
|
|
96
|
+
const range = readRange(o.range);
|
|
97
|
+
if (!range)
|
|
98
|
+
return null;
|
|
99
|
+
const hyps = (Array.isArray(o.hyps) ? o.hyps : []).map((h) => reading.hyp(h)).filter((h) => h !== null);
|
|
100
|
+
return { hyps, type: reading.code(o.type), range };
|
|
101
|
+
}
|
|
102
|
+
/** Lean's plain goals (`PlainGoal`: `{goals: [text], rendered}`), or null. */
|
|
103
|
+
export function readPlainGoals(r) {
|
|
104
|
+
if (!r || typeof r !== "object" || !Array.isArray(r.goals))
|
|
105
|
+
return null;
|
|
106
|
+
let left = MAX_TEXT;
|
|
107
|
+
return r.goals
|
|
108
|
+
.filter((g) => typeof g === "string")
|
|
109
|
+
.map((g) => {
|
|
110
|
+
const s = g.length > left ? g.slice(0, Math.max(0, left)) + "…" : g;
|
|
111
|
+
left = Math.max(0, left - g.length);
|
|
112
|
+
return parsePlainGoal(s);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/** Lean's plain term goal (`PlainTermGoal`: `{goal: text, range}`), or null. */
|
|
116
|
+
export function readPlainTermGoal(r) {
|
|
117
|
+
if (!r || typeof r !== "object")
|
|
118
|
+
return null;
|
|
119
|
+
const o = r;
|
|
120
|
+
const range = readRange(o.range);
|
|
121
|
+
if (typeof o.goal !== "string" || !range)
|
|
122
|
+
return null;
|
|
123
|
+
const g = parsePlainGoal(o.goal.slice(0, MAX_TEXT));
|
|
124
|
+
return { hyps: g.hyps, type: g.type, range };
|
|
125
|
+
}
|
|
126
|
+
/** An LSP range as [line, character, endLine, endCharacter]. */
|
|
127
|
+
function readRange(r) {
|
|
128
|
+
const o = r;
|
|
129
|
+
const ns = [o?.start?.line, o?.start?.character, o?.end?.line, o?.end?.character];
|
|
130
|
+
return ns.every((n) => Number.isInteger(n) && n >= 0) ? ns : null;
|
|
131
|
+
}
|
|
132
|
+
/** What Lean says of a subterm (`InfoPopup`: its type, the term with its implicit arguments, its
|
|
133
|
+
* constant's doc), as text. */
|
|
134
|
+
export function readInfo(r) {
|
|
135
|
+
if (!r || typeof r !== "object")
|
|
136
|
+
return {};
|
|
137
|
+
const o = r;
|
|
138
|
+
const text = (c) => {
|
|
139
|
+
const reading = new Reading();
|
|
140
|
+
const t = reading.code(c);
|
|
141
|
+
const flat = (x) => (typeof x === "string" ? x : Array.isArray(x) ? x.map(flat).join("") : flat(x.t));
|
|
142
|
+
return flat(t);
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
...(o.exprExplicit ? { expr: text(o.exprExplicit) } : {}),
|
|
146
|
+
...(o.type ? { type: text(o.type) } : {}),
|
|
147
|
+
...(typeof o.doc === "string" && o.doc ? { doc: o.doc.slice(0, 20_000) } : {}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** How many widgets Lean has at a place (`GetWidgetsResponse`, `{widgets: […]}`): only counted. */
|
|
151
|
+
export function readWidgets(r) {
|
|
152
|
+
const ws = r && typeof r === "object" ? r.widgets : null;
|
|
153
|
+
return Array.isArray(ws) ? ws.length : 0;
|
|
154
|
+
}
|
|
155
|
+
/** Every reference Lean gave in an answer, to release it when the answer is let go: walked with a
|
|
156
|
+
* stack of its own, however deep the answer is. */
|
|
157
|
+
export function refsIn(x) {
|
|
158
|
+
const out = [];
|
|
159
|
+
const stack = [x];
|
|
160
|
+
while (stack.length) {
|
|
161
|
+
const y = stack.pop();
|
|
162
|
+
if (!y || typeof y !== "object")
|
|
163
|
+
continue;
|
|
164
|
+
if (Array.isArray(y)) {
|
|
165
|
+
for (const z of y)
|
|
166
|
+
stack.push(z);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const o = y;
|
|
170
|
+
if (isRef(o) && Object.keys(o).length === 1)
|
|
171
|
+
out.push({ p: o.p });
|
|
172
|
+
else
|
|
173
|
+
for (const v of Object.values(o))
|
|
174
|
+
stack.push(v);
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/** A tagged text's characters alone, read with a stack of its own: what is deeper than a page
|
|
179
|
+
* reads tags in. */
|
|
180
|
+
function plainText(c) {
|
|
181
|
+
let out = "";
|
|
182
|
+
const stack = [c];
|
|
183
|
+
while (stack.length) {
|
|
184
|
+
const y = stack.pop();
|
|
185
|
+
if (!y || typeof y !== "object")
|
|
186
|
+
continue;
|
|
187
|
+
const o = y;
|
|
188
|
+
if (typeof o.text === "string")
|
|
189
|
+
out += o.text;
|
|
190
|
+
else if (Array.isArray(o.append))
|
|
191
|
+
for (let i = o.append.length - 1; i >= 0; i--)
|
|
192
|
+
stack.push(o.append[i]);
|
|
193
|
+
else if (Array.isArray(o.tag) && o.tag.length === 2)
|
|
194
|
+
stack.push(o.tag[1]);
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
/** The goals after a tactic that holds a block of its own, as Lean gives them at the start of the
|
|
199
|
+
* next line (shared/goals.ts, afterLine): there Lean's diff is about the tactic that line begins,
|
|
200
|
+
* not this one. It is taken off, and what this tactic added is marked instead: a hypothesis none of
|
|
201
|
+
* the goals before had, by its name and its type. */
|
|
202
|
+
export function afterTheLine(before, after) {
|
|
203
|
+
const had = new Set((before ?? []).flatMap((g) => g.hyps.flatMap((h) => h.names.map((n) => `${n} : ${plain(h.type)}`))));
|
|
204
|
+
return after.map((g) => ({
|
|
205
|
+
...(g.case ? { case: g.case } : {}),
|
|
206
|
+
hyps: g.hyps.map((h) => ({
|
|
207
|
+
names: h.names,
|
|
208
|
+
type: undiff(h.type),
|
|
209
|
+
...(h.val !== undefined ? { val: undiff(h.val) } : {}),
|
|
210
|
+
...(h.names.some((n) => !had.has(`${n} : ${plain(h.type)}`)) && before ? { d: "inserted" } : {}),
|
|
211
|
+
})),
|
|
212
|
+
type: undiff(g.type),
|
|
213
|
+
...(g.prefix ? { prefix: g.prefix } : {}),
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
/** A tagged text without Lean's diff marks, its subterms numbered as they were. */
|
|
217
|
+
function undiff(t) {
|
|
218
|
+
if (typeof t === "string")
|
|
219
|
+
return t;
|
|
220
|
+
if (Array.isArray(t))
|
|
221
|
+
return t.map(undiff);
|
|
222
|
+
return { k: t.k, t: undiff(t.t) };
|
|
223
|
+
}
|
|
224
|
+
const plain = (t) => (typeof t === "string" ? t : Array.isArray(t) ? t.map(plain).join("") : plain(t.t));
|