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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/src/git-origin.ts?version=264&format=json
90 lineswhytrail 100%Last change whytrail in version 193, 1 version changed it

You're reading version 264. The newest is 318, and no version since then changed this file. Go to the newestCompare with 318

1// Where a push came from in git, when it was imported (abso-core issue 21).
2// A version imported by client/scripts/import-git.ts ends its message with
3// a line naming the commit, its author and its time, and, when the
4// repository's issues are on the web, a line saying where:
5//
6// git 4e1a7c2b9f03, Ada Lovelace, 2026-10-06T20:36:43-05:00
7// Issues: https://github.com/owner/repo/issues
8//
9// A commit pushed with plain git ends with "Git-Commit: <sha>" and
10// "Author: <name>". A host may also name the commit beside the version
11// (`commit`). Issue references like "#39" in an imported message, or in a
12// line it wrote, mean that repository's issues, not the project's.
14export interface GitOrigin {
15 readonly commit: string;
16 readonly author?: string;
17 readonly time?: string;
18 /** The repository's issues, as a web address, when known. */
19 readonly issues?: string;
20 /** The message with these lines taken off. */
21 readonly message: string;
24const IMPORTED = /^git ([0-9a-f]{7,64}), (.+), (\d{4}-\d\d-\d\dT[^,\s]+)$/;
25const ISSUES = /^Issues: (https?:\/\/\S+)$/;
26const PUSHED = /^Git-Commit: ([0-9a-f]{7,64})$/;
27const PUSHED_BY = /^Author: (.+)$/;
29/**
30 * A push's git origin, from its message's last lines or the commit its host
31 * names, or undefined when it didn't come from git. `issues` is where "#N"
32 * points when the message doesn't say (the project's "gitIssues").
33 */
34export function gitOrigin(
35 p: { readonly message: string; readonly commit?: string; readonly author?: string },
36 issues?: string,
37): GitOrigin | undefined {
38 const lines = p.message.trimEnd().split("\n");
39 let end = lines.length;
40 let found: Omit<GitOrigin, "message"> | undefined;
41 const tracker = ISSUES.exec(lines[end - 1] ?? "");
42 if (tracker) end--;
43 const imported = IMPORTED.exec(lines[end - 1] ?? "");
44 if (imported) {
45 end--;
46 found = { commit: imported[1]!, author: imported[2]!, time: imported[3]! };
47 } else {
48 const by = PUSHED_BY.exec(lines[end - 1] ?? "");
49 const sha = PUSHED.exec(lines[end - (by ? 2 : 1)] ?? "");
50 if (sha) {
51 end -= by ? 2 : 1;
52 found = { commit: sha[1]!, ...(by ? { author: by[1]! } : {}) };
53 }
54 }
55 if (!found && p.commit !== undefined) found = { commit: p.commit, ...(p.author ? { author: p.author } : {}) };
56 if (!found) return undefined;
57 const where = tracker?.[1] ?? issues;
58 return {
59 ...found,
60 ...(where ? { issues: where.replace(/\/+$/, "") } : {}),
61 message: lines.slice(0, end).join("\n").trimEnd(),
62 };
65/** A git remote's issues on the web: GitHub's or GitLab's, by https or ssh; else undefined. */
66export function issuesOf(remote: string): string | undefined {
67 const plain = remote
68 .trim()
69 .replace(/\/+$/, "")
70 .replace(/\.git$/, "");
71 const m = /^(?:https:\/\/|ssh:\/\/git@|git@)(github\.com|gitlab\.com)[:/]([\w.-]+(?:\/[\w.-]+)+)$/.exec(plain);
72 if (!m) return undefined;
73 return m[1] === "gitlab.com" ? `https://gitlab.com/${m[2]}/-/issues` : `https://github.com/${m[2]}/issues`;
76/** The issues "#N" names in text, each once, in order: not "owner/repo#N", which names its own. */
77export function issueNumbers(text: string): number[] {
78 const out: number[] = [];
79 for (const m of text.matchAll(/(^|[^\w/])#(\d+)\b/g)) {
80 const n = Number(m[2]);
81 if (!out.includes(n)) out.push(n);
82 }
83 return out;
86/** One line per "#N" in text, saying which tracker it's in. Empty without a tracker or a reference. */
87export function issueLinks(text: string, issues: string | undefined): string[] {
88 if (!issues) return [];
89 return issueNumbers(text).map((n) => `#${n} is ${issues}/${n}`);