@peer2peer/ext-ix 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +79 -2
- package/SPEC.md +785 -0
- package/dist/conflicts.d.ts +64 -0
- package/dist/conflicts.js +188 -0
- package/dist/extension.d.ts +45 -0
- package/dist/extension.js +615 -0
- package/dist/footprint-command.d.ts +57 -0
- package/dist/footprint-command.js +398 -0
- package/dist/footprint-compute.d.ts +106 -0
- package/dist/footprint-compute.js +559 -0
- package/dist/footprint.d.ts +162 -0
- package/dist/footprint.js +451 -0
- package/dist/hmac.d.ts +18 -0
- package/dist/hmac.js +42 -0
- package/dist/impact.d.ts +66 -0
- package/dist/impact.js +208 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +21 -0
- package/dist/ix.d.ts +158 -0
- package/dist/ix.js +420 -0
- package/dist/listener.d.ts +48 -0
- package/dist/listener.js +203 -0
- package/dist/memory.d.ts +50 -0
- package/dist/memory.js +315 -0
- package/dist/note.d.ts +40 -0
- package/dist/note.js +82 -0
- package/dist/overlap-command.d.ts +37 -0
- package/dist/overlap-command.js +81 -0
- package/dist/overlap.d.ts +83 -0
- package/dist/overlap.js +227 -0
- package/dist/repo.d.ts +36 -0
- package/dist/repo.js +116 -0
- package/dist/subgraph.d.ts +59 -0
- package/dist/subgraph.js +140 -0
- package/dist/text.d.ts +83 -0
- package/dist/text.js +187 -0
- package/dist/which.d.ts +1 -0
- package/dist/which.js +45 -0
- package/package.json +61 -4
package/dist/note.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Copyright 2026 Ix Infrastructure Inc.
|
|
2
|
+
//
|
|
3
|
+
// x:ix.note: an Ix session note shared with a peer session (SPEC.md §3).
|
|
4
|
+
// The receiver's agent may preview it; writing it into the receiver's graph
|
|
5
|
+
// is a separate action only the user can take (`p2p ix import`), after
|
|
6
|
+
// seeing it.
|
|
7
|
+
import { parseRepo } from "./repo.js";
|
|
8
|
+
import { cleanMultiline, cps, fail, frame, isObj, jsonBytes, LIMITS, line, list, MAX_BODY_BYTES, NOTE_TAGS, oneOf, optStr, relPath, scrubPaths, toRepoRelative, } from "./text.js";
|
|
9
|
+
export const NOTE_KIND = "x:ix.note";
|
|
10
|
+
const ISO_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
11
|
+
/** Validates a received (or about-to-be-sent) note body. Unknown fields are dropped. */
|
|
12
|
+
export function parseNoteBody(v) {
|
|
13
|
+
if (!isObj(v))
|
|
14
|
+
return fail("note body must be an object");
|
|
15
|
+
const o = v;
|
|
16
|
+
if (jsonBytes(o) > MAX_BODY_BYTES)
|
|
17
|
+
fail(`note body is larger than ${MAX_BODY_BYTES} bytes`);
|
|
18
|
+
const tag = oneOf(o, "tag", NOTE_TAGS, "note");
|
|
19
|
+
if (typeof o.text !== "string")
|
|
20
|
+
fail("note.text must be a string");
|
|
21
|
+
const text = cleanMultiline(o.text);
|
|
22
|
+
if (text === "")
|
|
23
|
+
fail("note.text is empty");
|
|
24
|
+
if (Buffer.byteLength(text, "utf8") > LIMITS.noteText)
|
|
25
|
+
fail(`note.text is larger than ${LIMITS.noteText} bytes`);
|
|
26
|
+
const title = optStr(o, "title", LIMITS.title, "note");
|
|
27
|
+
const session = optStr(o, "session", LIMITS.session, "note");
|
|
28
|
+
const repo = o.repo === undefined ? undefined : parseRepo(o.repo, "note.repo");
|
|
29
|
+
const refs = list(o, "refs", LIMITS.refs, "note", (x, i) => relPath(x, `note.refs[${i}]`));
|
|
30
|
+
const at = optStr(o, "at", 40, "note");
|
|
31
|
+
if (at !== undefined && !ISO_RE.test(at))
|
|
32
|
+
fail("note.at must be an ISO 8601 time");
|
|
33
|
+
return {
|
|
34
|
+
tag,
|
|
35
|
+
text,
|
|
36
|
+
...(title ? { title } : {}),
|
|
37
|
+
...(session ? { session } : {}),
|
|
38
|
+
...(repo ? { repo } : {}),
|
|
39
|
+
...(refs.length ? { refs } : {}),
|
|
40
|
+
...(at ? { at } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function noteFallback(b) {
|
|
44
|
+
const what = b.tag === "note" ? "an Ix note" : `an Ix ${b.tag} note`;
|
|
45
|
+
return `shared ${what}: install Ix to open it: https://github.com/ix-infrastructure/Ix`;
|
|
46
|
+
}
|
|
47
|
+
/** Sending: a validated body and its fallback, with local paths scrubbed and refs made repo-relative. */
|
|
48
|
+
export function buildNote(i) {
|
|
49
|
+
const tag = NOTE_TAGS.includes(i.tag ?? "note") ? (i.tag ?? "note") : fail(`--tag must be one of ${NOTE_TAGS.join(", ")}`);
|
|
50
|
+
const scrub = (s) => scrubPaths(s, { root: i.root, home: i.home, hostname: i.hostname });
|
|
51
|
+
const refs = (i.refs ?? []).map((r) => toRepoRelative(r, i.root)).filter((r) => r !== undefined);
|
|
52
|
+
const raw = {
|
|
53
|
+
tag,
|
|
54
|
+
text: scrub(i.text),
|
|
55
|
+
...(i.title ? { title: scrub(i.title).trim().slice(0, LIMITS.title) } : {}),
|
|
56
|
+
...(i.session ? { session: scrub(i.session).trim().slice(0, LIMITS.session) } : {}),
|
|
57
|
+
...(i.repo ? { repo: i.repo } : {}),
|
|
58
|
+
...(refs.length ? { refs: [...new Set(refs)].slice(0, LIMITS.refs) } : {}),
|
|
59
|
+
...(i.at ? { at: i.at } : {}),
|
|
60
|
+
};
|
|
61
|
+
const body = parseNoteBody(raw);
|
|
62
|
+
return { body, fallback: noteFallback(body) };
|
|
63
|
+
}
|
|
64
|
+
/** Receiving: the model-safe digest, framed as data from the named peer. */
|
|
65
|
+
export function renderNote(b, from) {
|
|
66
|
+
const text = line(b.text, LIMITS.digestText);
|
|
67
|
+
const truncated = cps(line(b.text, LIMITS.noteText)) > cps(text);
|
|
68
|
+
const head = [b.title ? `"${line(b.title, LIMITS.title)}"` : undefined, b.session ? `from Ix session ${line(b.session, LIMITS.session)}` : undefined].filter(Boolean).join(" ");
|
|
69
|
+
return {
|
|
70
|
+
type: "note",
|
|
71
|
+
tag: b.tag,
|
|
72
|
+
...(b.title ? { title: line(b.title, LIMITS.title) } : {}),
|
|
73
|
+
...(b.session ? { session: line(b.session, LIMITS.session) } : {}),
|
|
74
|
+
...(b.repo ? { repo: b.repo } : {}),
|
|
75
|
+
...(b.refs ? { refs: b.refs } : {}),
|
|
76
|
+
...(b.at ? { at: b.at } : {}),
|
|
77
|
+
text,
|
|
78
|
+
...(truncated ? { truncated: true } : {}),
|
|
79
|
+
digest: frame(from.address, `Ix ${b.tag} note`, `${head ? `${head}: ` : ""}${text}${truncated ? " …" : ""}`),
|
|
80
|
+
consent: "Preview only. It is written into the local Ix graph only if the user runs `p2p ix import <event id>` themselves.",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ExtContext, ExtPeer } from "@peer2peer/cli";
|
|
2
|
+
import { type SemanticConflict } from "./conflicts.js";
|
|
3
|
+
import type { Here } from "./extension.js";
|
|
4
|
+
import { type FootprintBody } from "./footprint.js";
|
|
5
|
+
import type { NameKey } from "./hmac.js";
|
|
6
|
+
import { type IxRunner } from "./ix.js";
|
|
7
|
+
import { type Overlap } from "./overlap.js";
|
|
8
|
+
import type { RepoRef } from "./repo.js";
|
|
9
|
+
export interface OverlapsResult {
|
|
10
|
+
overlaps: Overlap[];
|
|
11
|
+
skipped: {
|
|
12
|
+
peer: {
|
|
13
|
+
own: string;
|
|
14
|
+
sid: string;
|
|
15
|
+
address: string;
|
|
16
|
+
};
|
|
17
|
+
reason: string;
|
|
18
|
+
}[];
|
|
19
|
+
/** Live peer sessions with a footprint compared. */
|
|
20
|
+
checked: number;
|
|
21
|
+
/** Live peer sessions without one (for the `ix around` fallback). */
|
|
22
|
+
withoutFootprint: ExtPeer[];
|
|
23
|
+
note?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The users a session's status reaches, and this user: whose sessions it may be compared with. */
|
|
26
|
+
export declare function audienceOf(ctx: ExtContext, sid: string, self: string): Promise<Set<string>>;
|
|
27
|
+
export declare function overlapsFor(ctx: ExtContext, sid: string, h: {
|
|
28
|
+
readMine(live: readonly string[]): Promise<FootprintBody | undefined>;
|
|
29
|
+
repo(): Promise<Here>;
|
|
30
|
+
nameKey(root: string, ref: RepoRef, env: NodeJS.ProcessEnv): Promise<{
|
|
31
|
+
key: NameKey;
|
|
32
|
+
} | {
|
|
33
|
+
why: string;
|
|
34
|
+
}>;
|
|
35
|
+
}): Promise<OverlapsResult>;
|
|
36
|
+
/** Peers without a footprint: today's semantic-conflict check (`ix around`) on their status files. */
|
|
37
|
+
export declare function conflictPeersWithoutFootprint(ctx: ExtContext, sid: string, peers: ExtPeer[], ix: IxRunner): Promise<SemanticConflict[]>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright 2026 Ix Infrastructure Inc.
|
|
2
|
+
//
|
|
3
|
+
// `p2p ix overlaps` (SPEC.md §9): this session's footprint against the live
|
|
4
|
+
// peer sessions' stored footprints, and, for peers without one, today's
|
|
5
|
+
// `ix around` check on their status files.
|
|
6
|
+
import { ixNeighbourhood, semanticConflicts } from "./conflicts.js";
|
|
7
|
+
import { FOOTPRINT_KIND, parseFootprintBody } from "./footprint.js";
|
|
8
|
+
import { ixAvailable } from "./ix.js";
|
|
9
|
+
import { computeOverlaps } from "./overlap.js";
|
|
10
|
+
import { InvalidBody } from "./text.js";
|
|
11
|
+
function parsed(v) {
|
|
12
|
+
if (v === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
try {
|
|
15
|
+
return parseFootprintBody(v);
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
if (e instanceof InvalidBody)
|
|
19
|
+
return undefined;
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** The users a session's status reaches, and this user: whose sessions it may be compared with. */
|
|
24
|
+
export async function audienceOf(ctx, sid, self) {
|
|
25
|
+
const aud = ctx.audience ? await ctx.audience(sid).catch(() => undefined) : undefined;
|
|
26
|
+
return new Set([self, ...(aud?.members ?? [])]);
|
|
27
|
+
}
|
|
28
|
+
export async function overlapsFor(ctx, sid, h) {
|
|
29
|
+
const rows = await ctx.peers();
|
|
30
|
+
const self = await ctx.self();
|
|
31
|
+
const isThis = (r) => r.own === self.userId && r.sid === sid;
|
|
32
|
+
const me = rows.find(isThis);
|
|
33
|
+
// My own names when this device computed them; else what this session published.
|
|
34
|
+
// (Own sessions still live on this device: the readable bodies of ended ones are pruned.)
|
|
35
|
+
const live = rows.filter((r) => r.own === self.userId && r.thisDevice && r.live).map((r) => r.sid);
|
|
36
|
+
const mine = parsed(await h.readMine(live.includes(sid) ? live : [...live, sid])) ?? parsed(me?.xstate?.[FOOTPRINT_KIND]?.body);
|
|
37
|
+
// Project boundaries (the CLI's projects.ts): only sessions this one's status reaches, and this
|
|
38
|
+
// user's own. A session in a private project compares with nobody else's; one in a shared project
|
|
39
|
+
// only with those its project shares (who see this session too). An audience that can't be read
|
|
40
|
+
// fails closed: own sessions only.
|
|
41
|
+
const reach = await audienceOf(ctx, sid, self.userId);
|
|
42
|
+
const others = rows.filter((r) => r.live && !isThis(r) && reach.has(r.own));
|
|
43
|
+
const withFp = [];
|
|
44
|
+
const withoutFootprint = [];
|
|
45
|
+
for (const r of others) {
|
|
46
|
+
const body = parsed(r.xstate?.[FOOTPRINT_KIND]?.body);
|
|
47
|
+
if (!body) {
|
|
48
|
+
withoutFootprint.push(r);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
withFp.push({ own: r.own, sid: r.sid, ref: r.ref, address: r.address, body });
|
|
52
|
+
}
|
|
53
|
+
if (!mine)
|
|
54
|
+
return { overlaps: [], skipped: [], checked: withFp.length, withoutFootprint, note: "This session has no footprint yet (`p2p ix footprint`)." };
|
|
55
|
+
let key;
|
|
56
|
+
if (mine.names === "hmac" || withFp.some((p) => p.body.names === "hmac")) {
|
|
57
|
+
const here = await h.repo();
|
|
58
|
+
if (here.root && here.ref && here.ref.remote === mine.repo.remote) {
|
|
59
|
+
const k = await h.nameKey(here.root, here.ref, { ...process.env, ...ctx.env });
|
|
60
|
+
if ("key" in k)
|
|
61
|
+
key = k.key;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// What my status already shares in the clear (a hashed overlap's line may name only these files).
|
|
65
|
+
const own = await ctx.ownStatus(sid);
|
|
66
|
+
const statusFiles = [...(own?.files ?? []), ...(own?.agents ?? []).flatMap((a) => (a.wt ? [] : (a.files ?? [])))];
|
|
67
|
+
// Who my status reaches (a peer outside it may still share theirs with me, and so be in peers()).
|
|
68
|
+
const aud = ctx.audience ? await ctx.audience(sid).catch(() => undefined) : undefined;
|
|
69
|
+
const statusAudience = [self.userId, ...(aud?.members ?? [])];
|
|
70
|
+
const publishedNames = parsed(me?.xstate?.[FOOTPRINT_KIND]?.body)?.names ?? "hmac";
|
|
71
|
+
const r = computeOverlaps({ mine, peers: withFp, statusFiles, statusAudience, publishedNames, ...(key ? { key } : {}) });
|
|
72
|
+
return { ...r, checked: withFp.length, withoutFootprint };
|
|
73
|
+
}
|
|
74
|
+
/** Peers without a footprint: today's semantic-conflict check (`ix around`) on their status files. */
|
|
75
|
+
export async function conflictPeersWithoutFootprint(ctx, sid, peers, ix) {
|
|
76
|
+
const own = await ctx.ownStatus(sid);
|
|
77
|
+
if (!own || own.files.length === 0 || !(await ixAvailable(ix)))
|
|
78
|
+
return [];
|
|
79
|
+
const r = await semanticConflicts({ mine: own.files, peers, ...(own.repo ? { repo: own.repo } : {}), neighbourhood: ixNeighbourhood(ix) });
|
|
80
|
+
return r.conflicts;
|
|
81
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { FootprintBody } from "./footprint.js";
|
|
2
|
+
import { type NameKey } from "./hmac.js";
|
|
3
|
+
export declare const OVERLAP_TIERS: readonly ["same-symbol", "depends", "same-file", "same-area", "transitive"];
|
|
4
|
+
export type OverlapTier = (typeof OVERLAP_TIERS)[number];
|
|
5
|
+
export type OverlapSeverity = "high" | "medium" | "low";
|
|
6
|
+
export type OverlapDirection = "both" | "mine-affects-theirs" | "theirs-affects-mine";
|
|
7
|
+
export interface OverlapPeer {
|
|
8
|
+
own: string;
|
|
9
|
+
sid: string;
|
|
10
|
+
ref: string;
|
|
11
|
+
address: string;
|
|
12
|
+
body: FootprintBody;
|
|
13
|
+
}
|
|
14
|
+
export interface Overlap {
|
|
15
|
+
peer: {
|
|
16
|
+
own: string;
|
|
17
|
+
sid: string;
|
|
18
|
+
ref: string;
|
|
19
|
+
address: string;
|
|
20
|
+
};
|
|
21
|
+
/** My actor ("main", "a1", …) and theirs. */
|
|
22
|
+
mine: string;
|
|
23
|
+
theirs: string;
|
|
24
|
+
tier: OverlapTier;
|
|
25
|
+
severity: OverlapSeverity;
|
|
26
|
+
direction: OverlapDirection;
|
|
27
|
+
/** The matched entry (compare keys: plain names, or h: tokens) and the ring relation. */
|
|
28
|
+
via: {
|
|
29
|
+
key: string;
|
|
30
|
+
rel?: string;
|
|
31
|
+
};
|
|
32
|
+
/** Up to 3 matched entries in all. */
|
|
33
|
+
examples: number;
|
|
34
|
+
/** Whether the line names things (the peer's body is plain); a hashed overlap stays generic. */
|
|
35
|
+
named: boolean;
|
|
36
|
+
/** Changes when the overlap does: (peer user, tier, direction, matched entry). */
|
|
37
|
+
key: string;
|
|
38
|
+
/** For a model: one line, at most 240 characters, sanitized; no name the peer doesn't already hold. */
|
|
39
|
+
message: string;
|
|
40
|
+
/** For the person (a terminal): the same, with my own readable names. Never for a model. */
|
|
41
|
+
detail: string;
|
|
42
|
+
}
|
|
43
|
+
export interface OverlapInput {
|
|
44
|
+
/** My footprint: preferably with plain names (`detail` names things for the person); hashed works too. */
|
|
45
|
+
mine: FootprintBody;
|
|
46
|
+
peers: OverlapPeer[];
|
|
47
|
+
/** The repository's name key (needed when either side is hashed and the other plain). */
|
|
48
|
+
key?: NameKey;
|
|
49
|
+
/**
|
|
50
|
+
* Files my own status shares in the clear (repo-relative): a model line about a hashed overlap
|
|
51
|
+
* may name one of these, for a peer in `statusAudience` (who already sees that status).
|
|
52
|
+
*/
|
|
53
|
+
statusFiles?: readonly string[];
|
|
54
|
+
/** The users my session's status reaches (its roster audience, and my own userId). Default: none. */
|
|
55
|
+
statusAudience?: readonly string[];
|
|
56
|
+
/**
|
|
57
|
+
* How my session's published footprint names things (default: hashed). A peer's plain names
|
|
58
|
+
* appear in a model line only when mine are plain too (we chose readable names for this
|
|
59
|
+
* audience) and the peer is in my status audience. Otherwise a peer could publish guesses and
|
|
60
|
+
* read our model's confirmation.
|
|
61
|
+
*/
|
|
62
|
+
publishedNames?: "plain" | "hmac";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Overlaps with each peer, both ways. Different remotes, or a different key id (another root
|
|
66
|
+
* commit), are skipped. Sorted: severity, then key; one per key (the peer user, tier, direction
|
|
67
|
+
* and matched entry: not the peer's session or agent ids, which they choose).
|
|
68
|
+
*
|
|
69
|
+
* `message` is for a model: it names something only when the peer's own plain body holds the
|
|
70
|
+
* name (they have it), or a file my status already shares; a hashed overlap otherwise stays
|
|
71
|
+
* generic and says so. `detail` names things with my own readable names, for the person only.
|
|
72
|
+
*/
|
|
73
|
+
export declare function computeOverlaps(i: OverlapInput): {
|
|
74
|
+
overlaps: Overlap[];
|
|
75
|
+
skipped: {
|
|
76
|
+
peer: {
|
|
77
|
+
own: string;
|
|
78
|
+
sid: string;
|
|
79
|
+
address: string;
|
|
80
|
+
};
|
|
81
|
+
reason: string;
|
|
82
|
+
}[];
|
|
83
|
+
};
|
package/dist/overlap.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Copyright 2026 Ix Infrastructure Inc.
|
|
2
|
+
//
|
|
3
|
+
// Footprint overlap (SPEC.md §9): this session's footprint against each live
|
|
4
|
+
// peer session's, both ways, per pair of actors, in tiers:
|
|
5
|
+
//
|
|
6
|
+
// T1 same symbol both change it high
|
|
7
|
+
// T2 depends one changes what the other's change calls, medium (high when it calls
|
|
8
|
+
// uses or imports (ring 1), either way it and my risk is high+)
|
|
9
|
+
// T3 same file both edit it, no T1 medium
|
|
10
|
+
// T4 same area a shared region, no T1-T3 low
|
|
11
|
+
// T5 transitive two hops (ring 2), no T1-T4 low
|
|
12
|
+
//
|
|
13
|
+
// No Ix call: only the two bodies. Hashed names compare as tokens (both sides
|
|
14
|
+
// derive the same key from the repository); a plain side is hashed with that
|
|
15
|
+
// key first, so plain, hashed and mixed bodies all compare. A peer body is
|
|
16
|
+
// never shown: messages name only what this side knows (its own readable
|
|
17
|
+
// names, or a peer's plain names), sanitized and capped.
|
|
18
|
+
import { hashFile, hashRegion, hashSymbol } from "./hmac.js";
|
|
19
|
+
import { line } from "./text.js";
|
|
20
|
+
export const OVERLAP_TIERS = ["same-symbol", "depends", "same-file", "same-area", "transitive"];
|
|
21
|
+
const SEVERITY_RANK = { high: 3, medium: 2, low: 1 };
|
|
22
|
+
const TIER_LABEL = { "same-symbol": "same symbol", depends: "depends", "same-file": "same file", "same-area": "same area", transitive: "transitive" };
|
|
23
|
+
const REL_WORD = { call: "calls", use: "uses", import: "imports", test: "tests" };
|
|
24
|
+
function compareKey(kind, name, plain, mode) {
|
|
25
|
+
if (!plain)
|
|
26
|
+
return name; // already a token
|
|
27
|
+
if (!mode.tokens) {
|
|
28
|
+
if (kind === "f")
|
|
29
|
+
return name.toLowerCase();
|
|
30
|
+
if (kind === "s") {
|
|
31
|
+
const i = name.indexOf("#");
|
|
32
|
+
return `${name.slice(0, i).toLowerCase()}#${name.slice(i + 1)}`;
|
|
33
|
+
}
|
|
34
|
+
return name;
|
|
35
|
+
}
|
|
36
|
+
if (!mode.key)
|
|
37
|
+
return undefined;
|
|
38
|
+
return kind === "f" ? hashFile(mode.key, name) : kind === "s" ? hashSymbol(mode.key, name) : hashRegion(mode.key, name);
|
|
39
|
+
}
|
|
40
|
+
function side(a, plain, mode) {
|
|
41
|
+
const put = (m, kind, name, v) => {
|
|
42
|
+
const k = compareKey(kind, name, plain, mode);
|
|
43
|
+
if (k !== undefined && !m.has(k))
|
|
44
|
+
m.set(k, v);
|
|
45
|
+
};
|
|
46
|
+
const d = (n) => (plain ? n : undefined);
|
|
47
|
+
const s = {
|
|
48
|
+
a: a.a,
|
|
49
|
+
risk: a.risk,
|
|
50
|
+
wt: a.wt === true,
|
|
51
|
+
approx: a.stale === true || a.coarse === true,
|
|
52
|
+
changedSyms: new Map(),
|
|
53
|
+
changedFiles: new Map(),
|
|
54
|
+
ring1Syms: new Map(),
|
|
55
|
+
ring1Files: new Map(),
|
|
56
|
+
ring2: new Map(),
|
|
57
|
+
comps: new Map(),
|
|
58
|
+
};
|
|
59
|
+
for (const x of a.changed.symbols)
|
|
60
|
+
put(s.changedSyms, "s", x.k, d(x.k));
|
|
61
|
+
for (const x of a.changed.new ?? [])
|
|
62
|
+
put(s.changedSyms, "s", x, d(x));
|
|
63
|
+
for (const f of a.changed.files)
|
|
64
|
+
put(s.changedFiles, "f", f, d(f));
|
|
65
|
+
for (const x of a.ring1.symbols)
|
|
66
|
+
put(s.ring1Syms, "s", x.k, { d: d(x.k), rel: x.rel });
|
|
67
|
+
for (const x of a.ring1.files)
|
|
68
|
+
put(s.ring1Files, "f", x.f, { d: d(x.f), rel: x.rel });
|
|
69
|
+
for (const f of a.ring2?.files ?? [])
|
|
70
|
+
put(s.ring2, "f", f, d(f));
|
|
71
|
+
for (const c of a.components)
|
|
72
|
+
put(s.comps, "c", c.n, d(c.n));
|
|
73
|
+
return s;
|
|
74
|
+
}
|
|
75
|
+
const sortedHits = (a, b) => [...a.keys()]
|
|
76
|
+
.filter((k) => b.has(k))
|
|
77
|
+
.sort()
|
|
78
|
+
.map((k) => [k, b.get(k)]);
|
|
79
|
+
/** The overlaps between my actor `m` and their actor `t`, top tier per direction. */
|
|
80
|
+
function pair(m, t, n) {
|
|
81
|
+
const out = [];
|
|
82
|
+
// My readable name for a key (I know my names): for the person only (`detail`).
|
|
83
|
+
const mine = (k) => m.changedSyms.get(k) ?? m.changedFiles.get(k) ?? m.ring1Syms.get(k)?.d ?? m.ring1Files.get(k)?.d ?? m.ring2.get(k) ?? m.comps.get(k);
|
|
84
|
+
// Their name for a key, from their own (plain) body: they already have it, so a model line may say it.
|
|
85
|
+
const theirs = (k) => t.changedSyms.get(k) ?? t.changedFiles.get(k) ?? t.ring1Syms.get(k)?.d ?? t.ring1Files.get(k)?.d ?? t.ring2.get(k) ?? t.comps.get(k);
|
|
86
|
+
/**
|
|
87
|
+
* A name for the model's line. Only a name the peer's plain body holds (they have it already);
|
|
88
|
+
* otherwise generic, with the file only when my own status already shares it in the clear.
|
|
89
|
+
*/
|
|
90
|
+
const say = (k, generic) => {
|
|
91
|
+
const t0 = n.peerPlain ? theirs(k) : undefined;
|
|
92
|
+
if (t0)
|
|
93
|
+
return t0;
|
|
94
|
+
const my = mine(k);
|
|
95
|
+
const file = my ? (my.includes("#") ? my.slice(0, my.indexOf("#")) : my) : undefined;
|
|
96
|
+
return file && n.statusFiles.has(file.toLowerCase()) ? `${generic} in ${file}` : generic;
|
|
97
|
+
};
|
|
98
|
+
const hashed = n.peerPlain ? "" : " (hashed: names stay private)";
|
|
99
|
+
const det = (k, fallback) => mine(k) ?? theirs(k) ?? fallback;
|
|
100
|
+
// T1
|
|
101
|
+
const t1 = sortedHits(m.changedSyms, t.changedSyms);
|
|
102
|
+
if (t1.length) {
|
|
103
|
+
const k = t1[0][0];
|
|
104
|
+
out.push({ tier: "same-symbol", severity: "high", direction: "both", key: k, examples: Math.min(3, t1.length), text: `you both change ${say(k, "a symbol you are changing")}${hashed}`, detail: `you both change ${det(k, "the same symbol")}` });
|
|
105
|
+
}
|
|
106
|
+
// T2, mine affects theirs: they edit what depends on my change (in my ring 1).
|
|
107
|
+
const a2 = sortedHits(t.changedSyms, m.ring1Syms);
|
|
108
|
+
const a2f = a2.length ? [] : sortedHits(t.changedFiles, m.ring1Files);
|
|
109
|
+
const a2hit = a2[0] ?? a2f[0];
|
|
110
|
+
if (a2hit) {
|
|
111
|
+
const [k, v] = a2hit;
|
|
112
|
+
const high = v.rel === "call" && (m.risk === "high" || m.risk === "critical");
|
|
113
|
+
const rel = REL_WORD[v.rel] ?? "depends on";
|
|
114
|
+
out.push({ tier: "depends", severity: high ? "high" : "medium", direction: "mine-affects-theirs", key: k, rel: v.rel, examples: Math.min(3, a2.length + a2f.length), text: `your change affects ${say(k, "code")} they're editing (it ${rel} it)${hashed}`, detail: `your change affects ${det(k, "code")} they're editing (it ${rel} it)` });
|
|
115
|
+
}
|
|
116
|
+
// T2, theirs affects mine: I edit what depends on their change (in their ring 1).
|
|
117
|
+
const b2 = sortedHits(m.changedSyms, t.ring1Syms);
|
|
118
|
+
const b2f = b2.length ? [] : sortedHits(m.changedFiles, t.ring1Files);
|
|
119
|
+
const b2hit = b2[0] ?? b2f[0];
|
|
120
|
+
if (b2hit) {
|
|
121
|
+
const [k, v] = b2hit;
|
|
122
|
+
const high = v.rel === "call" && (t.risk === "high" || t.risk === "critical");
|
|
123
|
+
const rel = REL_WORD[v.rel] ?? "depends on";
|
|
124
|
+
out.push({ tier: "depends", severity: high ? "high" : "medium", direction: "theirs-affects-mine", key: k, rel: v.rel, examples: Math.min(3, b2.length + b2f.length), text: `their change affects ${say(k, "code")} you're editing (it ${rel} their change)${hashed}`, detail: `their change affects ${det(k, "code")} you're editing (it ${rel} their change)` });
|
|
125
|
+
}
|
|
126
|
+
// T3
|
|
127
|
+
if (!t1.length) {
|
|
128
|
+
const t3 = sortedHits(m.changedFiles, t.changedFiles);
|
|
129
|
+
if (t3.length) {
|
|
130
|
+
const k = t3[0][0];
|
|
131
|
+
out.push({ tier: "same-file", severity: "medium", direction: "both", key: k, examples: Math.min(3, t3.length), text: `you both edit ${say(k, "a file")} (different symbols)${hashed}`, detail: `you both edit ${det(k, "a file")} (different symbols)` });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// T4
|
|
135
|
+
if (!out.length) {
|
|
136
|
+
const t4 = sortedHits(m.comps, t.comps);
|
|
137
|
+
if (t4.length) {
|
|
138
|
+
const k = t4[0][0];
|
|
139
|
+
out.push({ tier: "same-area", severity: "low", direction: "both", key: k, examples: Math.min(3, t4.length), text: `you both work in ${n.peerPlain ? (theirs(k) ?? "the same area") : "the same area"}${hashed}`, detail: `you both work in ${det(k, "the same area")}` });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// T5
|
|
143
|
+
if (!out.length) {
|
|
144
|
+
const a5 = sortedHits(t.changedFiles, m.ring2);
|
|
145
|
+
if (a5.length)
|
|
146
|
+
out.push({ tier: "transitive", severity: "low", direction: "mine-affects-theirs", key: a5[0][0], examples: Math.min(3, a5.length), text: `your change may reach ${say(a5[0][0], "a file")} they're editing (two hops)${hashed}`, detail: `your change may reach ${det(a5[0][0], "a file")} they're editing (two hops)` });
|
|
147
|
+
const b5 = sortedHits(m.changedFiles, t.ring2);
|
|
148
|
+
if (b5.length)
|
|
149
|
+
out.push({ tier: "transitive", severity: "low", direction: "theirs-affects-mine", key: b5[0][0], examples: Math.min(3, b5.length), text: `their change may reach ${say(b5[0][0], "a file")} you're editing (two hops)${hashed}`, detail: `their change may reach ${det(b5[0][0], "a file")} you're editing (two hops)` });
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
/** One line, at most 240 characters: the modifiers stay whole, the description gives way (with "…"). */
|
|
154
|
+
function fit(head, text, tail) {
|
|
155
|
+
const room = Math.max(20, 240 - [...head].length - [...tail].length);
|
|
156
|
+
const t = line(text, 1000);
|
|
157
|
+
return line(`${head}${[...t].length > room ? `${[...t].slice(0, room - 1).join("")}…` : t}${tail}`, 240);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Overlaps with each peer, both ways. Different remotes, or a different key id (another root
|
|
161
|
+
* commit), are skipped. Sorted: severity, then key; one per key (the peer user, tier, direction
|
|
162
|
+
* and matched entry: not the peer's session or agent ids, which they choose).
|
|
163
|
+
*
|
|
164
|
+
* `message` is for a model: it names something only when the peer's own plain body holds the
|
|
165
|
+
* name (they have it), or a file my status already shares; a hashed overlap otherwise stays
|
|
166
|
+
* generic and says so. `detail` names things with my own readable names, for the person only.
|
|
167
|
+
*/
|
|
168
|
+
export function computeOverlaps(i) {
|
|
169
|
+
const overlaps = [];
|
|
170
|
+
const skipped = [];
|
|
171
|
+
const statusFiles = new Set((i.statusFiles ?? []).map((f) => f.toLowerCase()));
|
|
172
|
+
const audience = new Set(i.statusAudience ?? []);
|
|
173
|
+
const published = i.publishedNames ?? "hmac";
|
|
174
|
+
for (const p of i.peers) {
|
|
175
|
+
const who = { own: p.own, sid: p.sid, address: p.address };
|
|
176
|
+
if (p.body.repo.remote !== i.mine.repo.remote) {
|
|
177
|
+
skipped.push({ peer: who, reason: "another repository" });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const tokens = i.mine.names === "hmac" || p.body.names === "hmac";
|
|
181
|
+
const keyIds = [i.mine.keyId, p.body.keyId, i.key?.keyId].filter((x) => !!x);
|
|
182
|
+
if (tokens && new Set(keyIds).size > 1) {
|
|
183
|
+
skipped.push({ peer: who, reason: "another repository key (a fork, or another root commit)" });
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const mixed = tokens && (i.mine.names === "plain" || p.body.names === "plain");
|
|
187
|
+
if (mixed && !i.key) {
|
|
188
|
+
skipped.push({ peer: who, reason: "no repository key to compare hashed names" });
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const mode = { tokens, ...(i.key ? { key: i.key } : {}) };
|
|
192
|
+
// Names in a model line: only when both sides chose readable names (theirs, and our published
|
|
193
|
+
// body), and status files only for someone our status reaches.
|
|
194
|
+
const naming = { peerPlain: p.body.names === "plain" && published === "plain" && audience.has(p.own), statusFiles: audience.has(p.own) ? statusFiles : new Set() };
|
|
195
|
+
const mySides = i.mine.actors.map((a) => side(a, i.mine.names === "plain", mode));
|
|
196
|
+
const theirSides = p.body.actors.map((a) => side(a, p.body.names === "plain", mode));
|
|
197
|
+
const branch = p.body.repo.branch && i.mine.repo.branch && p.body.repo.branch !== i.mine.repo.branch ? p.body.repo.branch : undefined;
|
|
198
|
+
for (const m of mySides) {
|
|
199
|
+
for (const t of theirSides) {
|
|
200
|
+
for (const f of pair(m, t, naming)) {
|
|
201
|
+
// Their agent by id only: a task line is theirs to write, and stays out of the model's line.
|
|
202
|
+
const agent = t.a === "main" ? "" : ` [agent ${t.a}${t.wt ? ", worktree" : ""}]`;
|
|
203
|
+
const mods = [m.a !== "main" ? `your agent ${m.a}` : "", m.wt || t.wt ? "unmerged, agent worktree" : "", branch && naming.peerPlain ? `on branch ${line(branch, 60)}` : "", m.approx || t.approx ? "approximate" : ""].filter(Boolean);
|
|
204
|
+
const head = `POSSIBLE CONFLICT (${f.severity}, ${TIER_LABEL[f.tier]}) with ${line(p.address, 80)}${agent}: `;
|
|
205
|
+
const tail = mods.length ? ` (${mods.join("; ")})` : "";
|
|
206
|
+
overlaps.push({
|
|
207
|
+
peer: { own: p.own, sid: p.sid, ref: p.ref, address: p.address },
|
|
208
|
+
mine: m.a,
|
|
209
|
+
theirs: t.a,
|
|
210
|
+
tier: f.tier,
|
|
211
|
+
severity: f.severity,
|
|
212
|
+
direction: f.direction,
|
|
213
|
+
via: { key: f.key, ...(f.rel ? { rel: f.rel } : {}) },
|
|
214
|
+
examples: f.examples,
|
|
215
|
+
named: naming.peerPlain,
|
|
216
|
+
key: JSON.stringify([p.own, f.tier, f.direction, f.key]),
|
|
217
|
+
message: fit(head, f.text, tail),
|
|
218
|
+
detail: fit(head, f.detail, tail),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
overlaps.sort((x, y) => SEVERITY_RANK[y.severity] - SEVERITY_RANK[x.severity] || (x.key < y.key ? -1 : x.key > y.key ? 1 : 0));
|
|
225
|
+
const seen = new Set();
|
|
226
|
+
return { overlaps: overlaps.filter((o) => !seen.has(o.key) && seen.add(o.key)), skipped };
|
|
227
|
+
}
|
package/dist/repo.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface RepoRef {
|
|
2
|
+
/** "github.com/ix-infrastructure/peer2peer". */
|
|
3
|
+
remote: string;
|
|
4
|
+
/** A commit id (7-64 hex). */
|
|
5
|
+
rev?: string;
|
|
6
|
+
branch?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* "https://user:tok@GitHub.com:443/Org/Repo.git", "git@github.com:org/repo",
|
|
10
|
+
* "ssh://git@host/org/repo" → "github.com/org/repo". Undefined when it isn't a
|
|
11
|
+
* remote (a local path, a file:// URL).
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeRemote(url: string): string | undefined;
|
|
14
|
+
export declare function parseRepo(v: unknown, what: string): RepoRef;
|
|
15
|
+
/**
|
|
16
|
+
* Runs git (resolved from PATH's absolute entries: never a git planted in the
|
|
17
|
+
* repo, the cwd) and returns its stdout, or undefined on any failure.
|
|
18
|
+
*/
|
|
19
|
+
export declare function gitOut(cwd: string, args: string[], env?: NodeJS.ProcessEnv, opts?: {
|
|
20
|
+
timeoutMs?: number;
|
|
21
|
+
maxBuffer?: number;
|
|
22
|
+
trim?: boolean;
|
|
23
|
+
}): Promise<string | undefined>;
|
|
24
|
+
export declare function gitEnv(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
25
|
+
export interface LocalRepo {
|
|
26
|
+
/** The working tree's root (absolute: local use only, never sent). */
|
|
27
|
+
root?: string;
|
|
28
|
+
ref?: RepoRef;
|
|
29
|
+
}
|
|
30
|
+
/** The repo `cwd` is in: its root, normalized origin remote, HEAD and branch. */
|
|
31
|
+
export declare function localRepo(cwd: string, env?: NodeJS.ProcessEnv): Promise<LocalRepo>;
|
|
32
|
+
/** How a received repo reference compares with the local checkout. */
|
|
33
|
+
export declare function compareRepo(theirs: RepoRef, mine: RepoRef | undefined): {
|
|
34
|
+
sameRepo: boolean;
|
|
35
|
+
sameRev?: boolean;
|
|
36
|
+
};
|
package/dist/repo.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright 2026 Ix Infrastructure Inc.
|
|
2
|
+
//
|
|
3
|
+
// Repository identity: how a sender says "this repo at this revision" so the
|
|
4
|
+
// receiver's Ix can find the same code in its own graph, without leaking a
|
|
5
|
+
// local path. A repo is named by its normalized remote ("host/owner/name":
|
|
6
|
+
// no scheme, no user or token, no port, no ".git", lower case), never by a
|
|
7
|
+
// directory.
|
|
8
|
+
import { execFile } from "node:child_process";
|
|
9
|
+
import { whichAbsolute } from "./which.js";
|
|
10
|
+
import { fail, isObj, LIMITS, optStr, str } from "./text.js";
|
|
11
|
+
const REMOTE_RE = /^[a-z0-9.-]+(?:\/[a-z0-9._~-]+){1,8}$/;
|
|
12
|
+
const REV_RE = /^[0-9a-f]{7,64}$/;
|
|
13
|
+
const BRANCH_RE = /^[A-Za-z0-9._/+@-]{1,128}$/;
|
|
14
|
+
/**
|
|
15
|
+
* "https://user:tok@GitHub.com:443/Org/Repo.git", "git@github.com:org/repo",
|
|
16
|
+
* "ssh://git@host/org/repo" → "github.com/org/repo". Undefined when it isn't a
|
|
17
|
+
* remote (a local path, a file:// URL).
|
|
18
|
+
*/
|
|
19
|
+
export function normalizeRemote(url) {
|
|
20
|
+
let s = url.trim();
|
|
21
|
+
if (s === "" || s.startsWith("/") || s.startsWith(".") || /^file:/i.test(s) || /^[A-Za-z]:[\\/]/.test(s))
|
|
22
|
+
return undefined;
|
|
23
|
+
let host;
|
|
24
|
+
let path;
|
|
25
|
+
const scp = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/)(.+)$/.exec(s);
|
|
26
|
+
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(s) && scp) {
|
|
27
|
+
host = scp[1];
|
|
28
|
+
path = scp[2];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
let u;
|
|
32
|
+
try {
|
|
33
|
+
u = new URL(s);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
if (u.protocol === "file:")
|
|
39
|
+
return undefined;
|
|
40
|
+
host = u.hostname;
|
|
41
|
+
path = u.pathname;
|
|
42
|
+
}
|
|
43
|
+
s = `${host}/${path}`
|
|
44
|
+
.toLowerCase()
|
|
45
|
+
.replace(/\/+/g, "/")
|
|
46
|
+
.replace(/\/$/, "")
|
|
47
|
+
.replace(/\.git$/, "");
|
|
48
|
+
return REMOTE_RE.test(s) ? s : undefined;
|
|
49
|
+
}
|
|
50
|
+
export function parseRepo(v, what) {
|
|
51
|
+
if (!isObj(v))
|
|
52
|
+
return fail(`${what} must be an object`);
|
|
53
|
+
const o = v;
|
|
54
|
+
const remote = str(o, "remote", LIMITS.remote, what);
|
|
55
|
+
if (!REMOTE_RE.test(remote))
|
|
56
|
+
fail(`${what}.remote must be a normalized remote (host/owner/name)`);
|
|
57
|
+
const rev = optStr(o, "rev", 64, what);
|
|
58
|
+
if (rev !== undefined && !REV_RE.test(rev))
|
|
59
|
+
fail(`${what}.rev must be a commit id`);
|
|
60
|
+
const branch = optStr(o, "branch", LIMITS.branch, what);
|
|
61
|
+
if (branch !== undefined && !BRANCH_RE.test(branch))
|
|
62
|
+
fail(`${what}.branch has characters a branch can't`);
|
|
63
|
+
return { remote, ...(rev ? { rev } : {}), ...(branch ? { branch } : {}) };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Runs git (resolved from PATH's absolute entries: never a git planted in the
|
|
67
|
+
* repo, the cwd) and returns its stdout, or undefined on any failure.
|
|
68
|
+
*/
|
|
69
|
+
export function gitOut(cwd, args, env, opts = {}) {
|
|
70
|
+
const bin = whichAbsolute("git", env ?? process.env);
|
|
71
|
+
if (!bin)
|
|
72
|
+
return Promise.resolve(undefined);
|
|
73
|
+
// The repository is the agent's to write: none of its config may run anything (an fsmonitor or
|
|
74
|
+
// hook program, an external diff), and git gets only what it needs from the environment, never
|
|
75
|
+
// a secret of p2p's (packages/p2p/src/projects.ts: the person token).
|
|
76
|
+
const safeArgs = ["-c", "core.fsmonitor=false", "-c", `core.hooksPath=${process.platform === "win32" ? "NUL" : "/dev/null"}`, "-c", "diff.external=", "-c", "core.sshCommand=false", ...args];
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
execFile(bin, safeArgs, { cwd, timeout: opts.timeoutMs ?? 5000, killSignal: "SIGKILL", maxBuffer: opts.maxBuffer ?? 1 << 20, env: gitEnv(env ?? process.env), windowsHide: true }, (err, stdout) => resolve(err ? undefined : opts.trim === false ? stdout : stdout.trim()));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const git = (cwd, args, env) => gitOut(cwd, args, env);
|
|
82
|
+
/** What git may see of the environment: where it lives, its home and temp, the locale and the user's own git config choice. */
|
|
83
|
+
const GIT_ENV_KEYS = ["PATH", "HOME", "USERPROFILE", "SystemRoot", "TMPDIR", "TEMP", "TMP", "LANG", "LC_ALL", "LC_CTYPE", "GIT_CONFIG_GLOBAL", "GIT_CONFIG_SYSTEM", "GIT_CONFIG_NOSYSTEM"];
|
|
84
|
+
export function gitEnv(env) {
|
|
85
|
+
const out = {};
|
|
86
|
+
for (const k of GIT_ENV_KEYS)
|
|
87
|
+
if (typeof env[k] === "string")
|
|
88
|
+
out[k] = env[k];
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
/** The repo `cwd` is in: its root, normalized origin remote, HEAD and branch. */
|
|
92
|
+
export async function localRepo(cwd, env) {
|
|
93
|
+
const root = await git(cwd, ["rev-parse", "--show-toplevel"], env);
|
|
94
|
+
if (!root)
|
|
95
|
+
return {};
|
|
96
|
+
const url = await git(cwd, ["remote", "get-url", "origin"], env);
|
|
97
|
+
const remote = url ? normalizeRemote(url) : undefined;
|
|
98
|
+
const rev = await git(cwd, ["rev-parse", "HEAD"], env);
|
|
99
|
+
const branch = await git(cwd, ["rev-parse", "--abbrev-ref", "HEAD"], env);
|
|
100
|
+
if (!remote)
|
|
101
|
+
return { root };
|
|
102
|
+
return {
|
|
103
|
+
root,
|
|
104
|
+
ref: { remote, ...(rev && REV_RE.test(rev) ? { rev } : {}), ...(branch && branch !== "HEAD" && BRANCH_RE.test(branch) ? { branch } : {}) },
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** How a received repo reference compares with the local checkout. */
|
|
108
|
+
export function compareRepo(theirs, mine) {
|
|
109
|
+
if (!mine)
|
|
110
|
+
return { sameRepo: false };
|
|
111
|
+
const sameRepo = theirs.remote === mine.remote;
|
|
112
|
+
if (!sameRepo || !theirs.rev || !mine.rev)
|
|
113
|
+
return { sameRepo };
|
|
114
|
+
const n = Math.min(theirs.rev.length, mine.rev.length);
|
|
115
|
+
return { sameRepo, sameRev: theirs.rev.slice(0, n) === mine.rev.slice(0, n) };
|
|
116
|
+
}
|