Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 2 to 318

Compare

+55 −52 in 9 places
Lines 19–27 at 318 (were 19–26 at 2)
1919// A use means a definition only through an import of it, or in the file
2020// that defines it (project.ts, #definitionCore).
2121
22−import type { LineId, View } from "../../src/engine/index.ts";
23−import { codeOfLines, isCommonName, isProse } from "./names.ts";
22+import type { LineId, ReadView } from "../../src/engine/index.ts";
23+import { withDefinitionCode } from "./definition-code.ts";
24+import { holdsNoCode, isCommonName } from "./names.ts";
2425
2526export interface Definition {
2627 readonly name: string;
Lines 91–103 at 318 (were 90–102 at 2)
9091const TOP_ASSIGN = new RegExp(`^(${NAME})\\s*(?::[^=]*)?=(?![=>])`);
9192const MAX_HEADER = 30;
9293
93−const cache = new WeakMap<View, Map<string, readonly Definition[]>>();
94+const cache = new WeakMap<ReadView, Map<string, readonly Definition[]>>();
9495
9596/**
9697 * Every definition in the view's code files (or only in `files`), by name.
9798 * Each file's definitions are cached per view.
9899 */
99−export function definitionsIn(view: View, files?: Iterable<string>): Map<string, Definition[]> {
100+export function definitionsIn(view: ReadView, files?: Iterable<string>): Map<string, Definition[]> {
100101 let perFile = cache.get(view);
101102 if (!perFile) {
102103 perFile = new Map();
Lines 119–149 at 318 (were 118–147 at 2)
118119 return out;
119120}
120121
121−function definitionsInFile(view: View, file: string, keepCommon = false): Definition[] {
122− if (isProse(file) || !view.hasFile(file)) return [];
122+function definitionsInFile(view: ReadView, file: string, keepCommon = false): Definition[] {
123+ if (holdsNoCode(file) || !view.hasFile(file)) return [];
123124 const out: Definition[] = [];
124− const visible = view.lines(file);
125− const code = codeOfLines(visible.map((l) => l.text));
126− for (let i = 0; i < code.length; i++) {
127− // Only top-level declarations: what another file can import. Locals,
128− // parameters and methods are indented.
129− if (/^\s/.test(code[i]!)) continue;
130− const found = defineAt(code, i);
131− if (!found || (!keepCommon && (found.name.length < 3 || isCommonName(found.name)))) continue;
132− out.push({
133− name: found.name,
134− file,
135− start: i,
136− end: found.end,
137− lines: visible.slice(i, found.end).map((l) => l.id),
138− text: visible
139− .slice(i, found.end)
140− .map((l) => l.text)
141− .join("\n"),
142− });
143− }
144− return out;
125+ const visible = view.buildLines(file);
126+ return withDefinitionCode(view, visible, (code) => {
127+ for (let i = 0; i < code.length; i++) {
128+ // Only top-level declarations: what another file can import. Locals,
129+ // parameters and methods are indented.
130+ if (/^\s/.test(code[i]!)) continue;
131+ const found = defineAt(code, i);
132+ if (!found || (!keepCommon && (found.name.length < 3 || isCommonName(found.name)))) continue;
133+ out.push({
134+ name: found.name,
135+ file,
136+ start: i,
137+ end: found.end,
138+ lines: visible.slice(i, found.end).map((l) => l.id),
139+ text: visible
140+ .slice(i, found.end)
141+ .map((l) => l.text)
142+ .join("\n"),
143+ });
144+ }
145+ return out;
146+ });
145147}
146148
147149/**
Lines 151–182 at 318 (were 149–179 at 2)
149151 * included (two `parse` functions in a file are a mistake whatever the name).
150152 * Each spans its whole block, body and all, for showing to the agent.
151153 */
152−export function definedTwice(view: View, file: string): Map<string, Definition[]> {
154+export function definedTwice(view: ReadView, file: string): Map<string, Definition[]> {
153155 const out = new Map<string, Definition[]>();
154156 const all = definitionsInFile(view, file, true);
155157 const count = new Map<string, number>();
156158 for (const d of all) count.set(d.name, (count.get(d.name) ?? 0) + 1);
157159 if (![...count.values()].some((n) => n > 1)) return out;
158− const visible = view.lines(file);
159− const code = codeOfLines(visible.map((l) => l.text));
160− for (const d of all) {
161− if (count.get(d.name)! < 2) continue;
162− const end = Math.max(d.end, wholeBlockEnd(code, d.start));
163− const whole: Definition = {
164− ...d,
165− end,
166− lines: visible.slice(d.start, end).map((l) => l.id),
167− text: visible
168− .slice(d.start, end)
169− .map((l) => l.text)
170− .join("\n"),
171− };
172− const list = out.get(d.name);
173− if (list) list.push(whole);
174− else out.set(d.name, [whole]);
175− }
176− return out;
160+ const visible = view.buildLines(file);
161+ return withDefinitionCode(view, visible, (code) => {
162+ for (const d of all) {
163+ if (count.get(d.name)! < 2) continue;
164+ const end = Math.max(d.end, wholeBlockEnd(code, d.start));
165+ const whole: Definition = {
166+ ...d,
167+ end,
168+ lines: visible.slice(d.start, end).map((l) => l.id),
169+ text: visible
170+ .slice(d.start, end)
171+ .map((l) => l.text)
172+ .join("\n"),
173+ };
174+ const list = out.get(d.name);
175+ if (list) list.push(whole);
176+ else out.set(d.name, [whole]);
177+ }
178+ return out;
179+ });
177180}
178181
179182/**
Lines 212–218 at 318 (were 209–215 at 2)
209212 * Whether a declaration found at `at` starts its line, after modifiers
210213 * only: `export const x`, `async function f`, `pub fn g`. A `let` inside
211214 * `for (let i = 0; ...)` or a `function` passed as an argument is not a
212− * definition of the file (#37, Builder 4).
215+ * definition of the file (#37).
213216 */
214217const LEADS =
215218 /^\s*(?:(?:export|default|declare|async|public|private|protected|static|abstract|override|readonly|pub(?:\([a-z]+\))?|unsafe|extern|const|final|sealed|open|data|inline|private\[this\])\s+)*$/;
Lines 309–315 at 318 (were 306–312 at 2)
306309 return i + 1;
307310}
308311
309−const importCache = new WeakMap<View, Map<string, ReadonlyMap<string, string>>>();
312+const importCache = new WeakMap<ReadView, Map<string, ReadonlyMap<string, string>>>();
310313
311314/**
312315 * Names a file imports by name, and the project file each comes from, when
Lines 319–325 at 318 (were 316–322 at 2)
316319 * x.y import a, b`. Lets a use of a name be matched to the definition it
317320 * means instead of every definition with that name.
318321 */
319−export function importsOf(view: View, file: string): ReadonlyMap<string, string> {
322+export function importsOf(view: ReadView, file: string): ReadonlyMap<string, string> {
320323 let perFile = importCache.get(view);
321324 if (!perFile) {
322325 perFile = new Map();
Lines 370–376 at 318 (were 367–373 at 2)
367370 return parts.join("/");
368371}
369372
370−function resolveModule(view: View, from: string, spec: string): string | undefined {
373+function resolveModule(view: ReadView, from: string, spec: string): string | undefined {
371374 if (!spec.startsWith(".")) return undefined;
372375 const base = joinPath(dirOf(from), spec);
373376 const stem = base.replace(/\.(?:js|mjs|cjs|jsx)$/, "");
Lines 388–394 at 318 (were 385–391 at 2)
385388 return undefined;
386389}
387390
388−function resolvePython(view: View, from: string, spec: string): string | undefined {
391+function resolvePython(view: ReadView, from: string, spec: string): string | undefined {
389392 const dots = /^\.*/.exec(spec)![0].length;
390393 const rest = spec.slice(dots).replace(/\./g, "/");
391394 let dir = dots > 0 ? dirOf(from) : "";
MCP
compare on this site's /mcp
CLI
abso diff 2 318 worker/project/definitions.ts --json
JSON
/christopher/abso-core/compare/2..318?file=worker%2Fproject%2Fdefinitions.ts&format=json