@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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type RepoRef } from "./repo.js";
|
|
2
|
+
import { type Roots } from "./text.js";
|
|
3
|
+
export declare const SUBGRAPH_KIND: "x:ix.subgraph";
|
|
4
|
+
export type Selector =
|
|
5
|
+
/** A file, a directory, or a directory glob ("auth/*", "auth/**"), repo-relative. */
|
|
6
|
+
{
|
|
7
|
+
type: "path";
|
|
8
|
+
pattern: string;
|
|
9
|
+
}
|
|
10
|
+
/** A named entity (function, class, …), optionally narrowed by kind and a path substring. */
|
|
11
|
+
| {
|
|
12
|
+
type: "symbol";
|
|
13
|
+
name: string;
|
|
14
|
+
kind?: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
}
|
|
17
|
+
/** A region of Ix's architecture map (`ix subsystems`). */
|
|
18
|
+
| {
|
|
19
|
+
type: "region";
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
export interface SubgraphBody {
|
|
23
|
+
repo: RepoRef;
|
|
24
|
+
selector: Selector;
|
|
25
|
+
title?: string;
|
|
26
|
+
/** Why the sender wants them to look (free text). */
|
|
27
|
+
why?: string;
|
|
28
|
+
/** The sender's Ix graph revision (informational). */
|
|
29
|
+
graphRev?: number;
|
|
30
|
+
}
|
|
31
|
+
/** "auth/*" → {prefix: "auth", glob: "*"}; a plain path → {prefix: path}. Undefined when invalid. */
|
|
32
|
+
export declare function splitPattern(p: string): {
|
|
33
|
+
prefix: string;
|
|
34
|
+
glob?: "*" | "**";
|
|
35
|
+
} | undefined;
|
|
36
|
+
export declare function parseSelector(v: unknown): Selector;
|
|
37
|
+
export declare function parseSubgraphBody(v: unknown): SubgraphBody;
|
|
38
|
+
export declare function describeSelector(s: Selector): string;
|
|
39
|
+
export declare function subgraphFallback(b: SubgraphBody): string;
|
|
40
|
+
export interface SubgraphInput {
|
|
41
|
+
repo: RepoRef | undefined;
|
|
42
|
+
selector: Selector;
|
|
43
|
+
title?: string;
|
|
44
|
+
why?: string;
|
|
45
|
+
graphRev?: number;
|
|
46
|
+
/** For scrubbing title and why (never sent). */
|
|
47
|
+
root?: Roots;
|
|
48
|
+
home?: string;
|
|
49
|
+
hostname?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare function buildSubgraph(i: SubgraphInput): {
|
|
52
|
+
body: SubgraphBody;
|
|
53
|
+
fallback: string;
|
|
54
|
+
};
|
|
55
|
+
/** The receiver's own `ix` argv for a selector (validated: no element can be read as an option). */
|
|
56
|
+
export declare function resolveArgv(s: Selector, limit?: number): string[];
|
|
57
|
+
export declare function renderSubgraph(b: SubgraphBody, from: {
|
|
58
|
+
address: string;
|
|
59
|
+
}, mine?: RepoRef): Record<string, unknown>;
|
package/dist/subgraph.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Copyright 2026 Ix Infrastructure Inc.
|
|
2
|
+
//
|
|
3
|
+
// x:ix.subgraph: a reference to part of the sender's graph ("look at auth/*
|
|
4
|
+
// in my graph", SPEC.md §4). It carries only what the receiver's Ix needs to
|
|
5
|
+
// find the same part of the same repo in its own graph: the repo's
|
|
6
|
+
// normalized remote, a revision, and a selector. It carries no graph content
|
|
7
|
+
// and no local path; the sender's Ix isn't even run.
|
|
8
|
+
//
|
|
9
|
+
// Resolving it is something the receiving user starts (`p2p ix resolve`),
|
|
10
|
+
// never the peer: the selector becomes a fixed, validated argv for the
|
|
11
|
+
// receiver's own `ix`.
|
|
12
|
+
import { compareRepo, parseRepo } from "./repo.js";
|
|
13
|
+
import { cps, fail, frame, scrubPaths, isObj, jsonBytes, LIMITS, line, MAX_BODY_BYTES, optInt, optStr, str } from "./text.js";
|
|
14
|
+
import { isSafeRelativePath } from "@peer2peer/core/v3";
|
|
15
|
+
export const SUBGRAPH_KIND = "x:ix.subgraph";
|
|
16
|
+
// Strict patterns: what a peer can make the receiver's `ix` see is exactly these.
|
|
17
|
+
const PATH_SEG = /^[A-Za-z0-9._@+-][A-Za-z0-9._@+ -]*$/;
|
|
18
|
+
const SYMBOL_RE = /^[A-Za-z_$][A-Za-z0-9_$.:#]{0,199}$/;
|
|
19
|
+
const KIND_RE = /^[a-z][a-z_]{0,31}$/;
|
|
20
|
+
const REGION_RE = /^[A-Za-z0-9][A-Za-z0-9 ._/-]{0,127}$/;
|
|
21
|
+
/** "auth/*" → {prefix: "auth", glob: "*"}; a plain path → {prefix: path}. Undefined when invalid. */
|
|
22
|
+
export function splitPattern(p) {
|
|
23
|
+
if (cps(p) > LIMITS.path || p.startsWith("-"))
|
|
24
|
+
return undefined;
|
|
25
|
+
const m = /^(.*?)(?:\/(\*\*?))?$/.exec(p);
|
|
26
|
+
const prefix = (m?.[1] ?? "").replace(/\/+$/, "");
|
|
27
|
+
const glob = m?.[2];
|
|
28
|
+
if (prefix === "" || !isSafeRelativePath(prefix) || !prefix.split("/").every((s) => PATH_SEG.test(s)))
|
|
29
|
+
return undefined;
|
|
30
|
+
return { prefix, ...(glob ? { glob } : {}) };
|
|
31
|
+
}
|
|
32
|
+
export function parseSelector(v) {
|
|
33
|
+
if (!isObj(v))
|
|
34
|
+
return fail("subgraph.selector must be an object");
|
|
35
|
+
const o = v;
|
|
36
|
+
switch (o.type) {
|
|
37
|
+
case "path": {
|
|
38
|
+
const pattern = str(o, "pattern", LIMITS.path, "selector");
|
|
39
|
+
if (!splitPattern(pattern))
|
|
40
|
+
fail("selector.pattern must be a repo-relative path, optionally ending in /* or /**");
|
|
41
|
+
return { type: "path", pattern };
|
|
42
|
+
}
|
|
43
|
+
case "symbol": {
|
|
44
|
+
const name = str(o, "name", LIMITS.symbol, "selector");
|
|
45
|
+
if (!SYMBOL_RE.test(name))
|
|
46
|
+
fail("selector.name must be an identifier (letters, digits, _ $ . : #)");
|
|
47
|
+
const kind = optStr(o, "kind", LIMITS.kind, "selector");
|
|
48
|
+
if (kind !== undefined && !KIND_RE.test(kind))
|
|
49
|
+
fail("selector.kind must be a lowercase entity kind");
|
|
50
|
+
const path = optStr(o, "path", LIMITS.path, "selector");
|
|
51
|
+
if (path !== undefined && !splitPattern(path))
|
|
52
|
+
fail("selector.path must be a repo-relative path");
|
|
53
|
+
return { type: "symbol", name, ...(kind ? { kind } : {}), ...(path ? { path } : {}) };
|
|
54
|
+
}
|
|
55
|
+
case "region": {
|
|
56
|
+
const name = str(o, "name", LIMITS.region, "selector");
|
|
57
|
+
// L6: Ix sends --target to its backend as a region-name query (`getSubsystemMap({target})`), not a
|
|
58
|
+
// path; still, nothing path-like: no "..", "//" or "./" segments.
|
|
59
|
+
if (!REGION_RE.test(name) || name.split("/").some((seg) => /^\s*\.{1,2}\s*$/.test(seg)) || name.includes("//"))
|
|
60
|
+
fail("selector.name must be a region name");
|
|
61
|
+
return { type: "region", name };
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
return fail("selector.type must be path, symbol or region");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function parseSubgraphBody(v) {
|
|
68
|
+
if (!isObj(v))
|
|
69
|
+
return fail("subgraph body must be an object");
|
|
70
|
+
const o = v;
|
|
71
|
+
if (jsonBytes(o) > MAX_BODY_BYTES)
|
|
72
|
+
fail(`subgraph body is larger than ${MAX_BODY_BYTES} bytes`);
|
|
73
|
+
const repo = parseRepo(o.repo, "subgraph.repo");
|
|
74
|
+
const selector = parseSelector(o.selector);
|
|
75
|
+
const title = optStr(o, "title", LIMITS.title, "subgraph");
|
|
76
|
+
const why = optStr(o, "why", LIMITS.why, "subgraph");
|
|
77
|
+
const graphRev = optInt(o, "graphRev", "subgraph");
|
|
78
|
+
return { repo, selector, ...(title ? { title } : {}), ...(why ? { why } : {}), ...(graphRev !== undefined ? { graphRev } : {}) };
|
|
79
|
+
}
|
|
80
|
+
export function describeSelector(s) {
|
|
81
|
+
if (s.type === "path")
|
|
82
|
+
return s.pattern;
|
|
83
|
+
if (s.type === "symbol")
|
|
84
|
+
return `${s.kind ? `${s.kind} ` : ""}${s.name}${s.path ? ` in ${s.path}` : ""}`;
|
|
85
|
+
return `region ${s.name}`;
|
|
86
|
+
}
|
|
87
|
+
export function subgraphFallback(b) {
|
|
88
|
+
const what = line(describeSelector(b.selector), 60);
|
|
89
|
+
return `shared an Ix subgraph (${what}): install Ix to open it: https://github.com/ix-infrastructure/Ix`.slice(0, 200);
|
|
90
|
+
}
|
|
91
|
+
export function buildSubgraph(i) {
|
|
92
|
+
if (!i.repo)
|
|
93
|
+
fail("not in a git repository with an `origin` remote: a subgraph reference names the repo (or pass --remote)");
|
|
94
|
+
const scrub = (t) => scrubPaths(t, { root: i.root, home: i.home, hostname: i.hostname });
|
|
95
|
+
const body = parseSubgraphBody({ repo: i.repo, selector: i.selector, ...(i.title ? { title: scrub(i.title) } : {}), ...(i.why ? { why: scrub(i.why) } : {}), ...(i.graphRev !== undefined ? { graphRev: i.graphRev } : {}) });
|
|
96
|
+
return { body, fallback: subgraphFallback(body) };
|
|
97
|
+
}
|
|
98
|
+
/** The receiver's own `ix` argv for a selector (validated: no element can be read as an option). */
|
|
99
|
+
export function resolveArgv(s, limit = 100) {
|
|
100
|
+
let argv;
|
|
101
|
+
if (s.type === "path") {
|
|
102
|
+
const sp = splitPattern(s.pattern);
|
|
103
|
+
if (!sp)
|
|
104
|
+
return fail("bad selector");
|
|
105
|
+
// A glob or a directory-looking path lists files under it; a file gets its structural overview.
|
|
106
|
+
const looksLikeFile = !sp.glob && /\.[A-Za-z0-9]{1,8}$/.test(sp.prefix);
|
|
107
|
+
argv = looksLikeFile ? ["overview", sp.prefix, "--format", "llm"] : ["inventory", "--kind", "file", "--path", `${sp.prefix}/`, "--format", "llm", "--limit", String(limit)];
|
|
108
|
+
}
|
|
109
|
+
else if (s.type === "symbol") {
|
|
110
|
+
argv = ["context", s.name, "--format", "llm", ...(s.kind ? ["--kind", s.kind] : []), ...(s.path ? ["--path", s.path] : [])];
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
argv = ["subsystems", "--target", s.name, "--format", "llm"];
|
|
114
|
+
}
|
|
115
|
+
// Belt and braces: the patterns above never allow a leading "-".
|
|
116
|
+
for (const a of argv.slice(1))
|
|
117
|
+
if (a.startsWith("-") && !/^--[a-z]+$/.test(a))
|
|
118
|
+
fail("refusing an argument that looks like an option");
|
|
119
|
+
return argv;
|
|
120
|
+
}
|
|
121
|
+
export function renderSubgraph(b, from, mine) {
|
|
122
|
+
const where = describeSelector(b.selector);
|
|
123
|
+
const cmp = compareRepo(b.repo, mine);
|
|
124
|
+
const repoNote = mine === undefined ? "" : !cmp.sameRepo ? " (not the repo this session is in)" : cmp.sameRev === false ? " (same repo, another revision)" : "";
|
|
125
|
+
const parts = [
|
|
126
|
+
`look at ${line(where, 200)} in ${line(b.repo.remote, LIMITS.remote)}${b.repo.rev ? `@${b.repo.rev.slice(0, 12)}` : ""}${repoNote}`,
|
|
127
|
+
b.title ? `"${line(b.title, LIMITS.title)}"` : undefined,
|
|
128
|
+
b.why ? `why: ${line(b.why, LIMITS.why)}` : undefined,
|
|
129
|
+
].filter(Boolean);
|
|
130
|
+
return {
|
|
131
|
+
type: "subgraph",
|
|
132
|
+
repo: b.repo,
|
|
133
|
+
selector: b.selector,
|
|
134
|
+
...(b.title ? { title: line(b.title, LIMITS.title) } : {}),
|
|
135
|
+
...(b.why ? { why: line(b.why, LIMITS.why) } : {}),
|
|
136
|
+
...(mine !== undefined ? { sameRepo: cmp.sameRepo, ...(cmp.sameRev !== undefined ? { sameRev: cmp.sameRev } : {}) } : {}),
|
|
137
|
+
digest: frame(from.address, "Ix subgraph reference", parts.join("; ")),
|
|
138
|
+
consent: "Nothing was run. The user opens it in their own graph with `p2p ix resolve <event id>`.",
|
|
139
|
+
};
|
|
140
|
+
}
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** ext.v of every kind in this version of the spec. */
|
|
2
|
+
export declare const SPEC_VERSION = 1;
|
|
3
|
+
/** Serialized `body` cap (bytes); p2p allows 24 KiB for `{v, body}` (the envelope is 64 KiB sealed). */
|
|
4
|
+
export declare const MAX_BODY_BYTES: number;
|
|
5
|
+
export declare const LIMITS: {
|
|
6
|
+
readonly noteText: number;
|
|
7
|
+
readonly title: 120;
|
|
8
|
+
readonly session: 64;
|
|
9
|
+
readonly tag: 16;
|
|
10
|
+
readonly refs: 25;
|
|
11
|
+
readonly path: 300;
|
|
12
|
+
readonly remote: 200;
|
|
13
|
+
readonly branch: 128;
|
|
14
|
+
readonly why: 1000;
|
|
15
|
+
readonly symbol: 200;
|
|
16
|
+
readonly kind: 32;
|
|
17
|
+
readonly region: 128;
|
|
18
|
+
readonly riskSummary: 500;
|
|
19
|
+
readonly atRisk: 10;
|
|
20
|
+
readonly atRiskItem: 200;
|
|
21
|
+
readonly nextStep: 300;
|
|
22
|
+
readonly files: 100;
|
|
23
|
+
readonly changed: 50;
|
|
24
|
+
readonly symbols: 50;
|
|
25
|
+
readonly components: 25;
|
|
26
|
+
/** Characters of a note shown in a model digest. */
|
|
27
|
+
readonly digestText: 1500;
|
|
28
|
+
};
|
|
29
|
+
export declare const NOTE_TAGS: readonly ["note", "finding", "decision", "reminder"];
|
|
30
|
+
export type NoteTag = (typeof NOTE_TAGS)[number];
|
|
31
|
+
export declare const RISK_LEVELS: readonly ["low", "medium", "high", "critical", "unknown"];
|
|
32
|
+
export type RiskLevel = (typeof RISK_LEVELS)[number];
|
|
33
|
+
export declare class IxExtError extends Error {
|
|
34
|
+
readonly code: string;
|
|
35
|
+
readonly extra: Record<string, unknown>;
|
|
36
|
+
constructor(code: string, message: string, extra?: Record<string, unknown>);
|
|
37
|
+
}
|
|
38
|
+
/** A body that fails validation: the receiver shows the fallback with this reason. */
|
|
39
|
+
export declare class InvalidBody extends Error {
|
|
40
|
+
}
|
|
41
|
+
export declare const fail: (why: string) => never;
|
|
42
|
+
export type O = Record<string, unknown>;
|
|
43
|
+
export declare function isObj(v: unknown): v is O;
|
|
44
|
+
export declare function cps(s: string): number;
|
|
45
|
+
/** A required string within `max` code points (after trimming). */
|
|
46
|
+
export declare function str(o: O, k: string, max: number, what: string): string;
|
|
47
|
+
export declare function optStr(o: O, k: string, max: number, what: string): string | undefined;
|
|
48
|
+
export declare function optInt(o: O, k: string, what: string, max?: number): number | undefined;
|
|
49
|
+
export declare function oneOf<T extends string>(o: O, k: string, allowed: readonly T[], what: string): T;
|
|
50
|
+
/** A list of at most `max` items, each mapped by `f` (which may throw InvalidBody). */
|
|
51
|
+
export declare function list<T>(o: O, k: string, max: number, what: string, f: (x: unknown, i: number) => T): T[];
|
|
52
|
+
/** A repo-relative path (core's `files` rule), at most LIMITS.path characters; otherwise invalid. */
|
|
53
|
+
export declare function relPath(v: unknown, what: string): string;
|
|
54
|
+
/** Strips C0/C1 controls (except tab and newline), Cf and U+2028/9 from multi-line text; CRLF → LF. */
|
|
55
|
+
export declare function cleanMultiline(s: string): string;
|
|
56
|
+
/** One line of peer text for a person or a model (core's sanitizer). */
|
|
57
|
+
export declare function line(s: unknown, max: number): string;
|
|
58
|
+
/**
|
|
59
|
+
* Sending: a path as the receiver may see it. Absolute paths become
|
|
60
|
+
* repo-relative when under `root`; anything else that isn't a safe relative
|
|
61
|
+
* path is dropped (undefined), so no absolute path leaves this machine.
|
|
62
|
+
*/
|
|
63
|
+
export declare function toRepoRelative(p: string, root?: Roots): string | undefined;
|
|
64
|
+
/** The repo root, or several spellings of it (a symlinked temp dir, the realpath). */
|
|
65
|
+
export type Roots = string | readonly string[];
|
|
66
|
+
/**
|
|
67
|
+
* Sending: free text with this machine's identifying details replaced, so a
|
|
68
|
+
* note, a risk summary or a symbol name doesn't leak them:
|
|
69
|
+
* - the repo root → ".", the home directory → "~";
|
|
70
|
+
* - other home-like prefixes (/Users/x, /home/x, /root, C:\Users\x, C:/Users/x) → "~";
|
|
71
|
+
* - other local locations (/tmp, /private/var, /var/folders, /Volumes/x, /mnt/x,
|
|
72
|
+
* UNC \\host\share) → "…";
|
|
73
|
+
* - e-mail addresses → "[email]", this machine's host name → "[host]".
|
|
74
|
+
*/
|
|
75
|
+
export declare function scrubPaths(text: string, opts: {
|
|
76
|
+
root?: Roots;
|
|
77
|
+
home?: string;
|
|
78
|
+
hostname?: string;
|
|
79
|
+
}): string;
|
|
80
|
+
/** Bytes of a value serialized as JSON. */
|
|
81
|
+
export declare function jsonBytes(v: unknown): number;
|
|
82
|
+
/** Frames peer content for a model (protocol §4.3): data from a named peer, never instructions. */
|
|
83
|
+
export declare function frame(address: string, what: string, text: string): string;
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Copyright 2026 Ix Infrastructure Inc.
|
|
2
|
+
//
|
|
3
|
+
// Limits and the string helpers every kind uses. Received bodies are
|
|
4
|
+
// untrusted peer data (protocol §4.3): every string is validated against a
|
|
5
|
+
// cap here and passes core's one sanitizer before a person or a model sees
|
|
6
|
+
// it. Paths must be repo-relative (core's `files` rule); absolute ones are
|
|
7
|
+
// relativised against the repo root when sending, and dropped otherwise.
|
|
8
|
+
import { isAbsolute, relative, sep } from "node:path";
|
|
9
|
+
import { isSafeRelativePath, sanitizePeerText } from "@peer2peer/core/v3";
|
|
10
|
+
/** ext.v of every kind in this version of the spec. */
|
|
11
|
+
export const SPEC_VERSION = 1;
|
|
12
|
+
/** Serialized `body` cap (bytes); p2p allows 24 KiB for `{v, body}` (the envelope is 64 KiB sealed). */
|
|
13
|
+
export const MAX_BODY_BYTES = 20 * 1024;
|
|
14
|
+
export const LIMITS = {
|
|
15
|
+
noteText: 12 * 1024, // bytes (UTF-8) of a note's text
|
|
16
|
+
title: 120,
|
|
17
|
+
session: 64,
|
|
18
|
+
tag: 16,
|
|
19
|
+
refs: 25,
|
|
20
|
+
path: 300,
|
|
21
|
+
remote: 200,
|
|
22
|
+
branch: 128,
|
|
23
|
+
why: 1000,
|
|
24
|
+
symbol: 200,
|
|
25
|
+
kind: 32,
|
|
26
|
+
region: 128,
|
|
27
|
+
riskSummary: 500,
|
|
28
|
+
atRisk: 10,
|
|
29
|
+
atRiskItem: 200,
|
|
30
|
+
nextStep: 300,
|
|
31
|
+
files: 100,
|
|
32
|
+
changed: 50,
|
|
33
|
+
symbols: 50,
|
|
34
|
+
components: 25,
|
|
35
|
+
/** Characters of a note shown in a model digest. */
|
|
36
|
+
digestText: 1500,
|
|
37
|
+
};
|
|
38
|
+
export const NOTE_TAGS = ["note", "finding", "decision", "reminder"];
|
|
39
|
+
export const RISK_LEVELS = ["low", "medium", "high", "critical", "unknown"];
|
|
40
|
+
export class IxExtError extends Error {
|
|
41
|
+
code;
|
|
42
|
+
extra;
|
|
43
|
+
constructor(code, message, extra = {}) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.extra = extra;
|
|
47
|
+
this.name = "IxExtError";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** A body that fails validation: the receiver shows the fallback with this reason. */
|
|
51
|
+
export class InvalidBody extends Error {
|
|
52
|
+
}
|
|
53
|
+
export const fail = (why) => {
|
|
54
|
+
throw new InvalidBody(why);
|
|
55
|
+
};
|
|
56
|
+
export function isObj(v) {
|
|
57
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
58
|
+
}
|
|
59
|
+
export function cps(s) {
|
|
60
|
+
return [...s].length;
|
|
61
|
+
}
|
|
62
|
+
/** A required string within `max` code points (after trimming). */
|
|
63
|
+
export function str(o, k, max, what) {
|
|
64
|
+
const v = o[k];
|
|
65
|
+
if (typeof v !== "string")
|
|
66
|
+
return fail(`${what}.${k} must be a string`);
|
|
67
|
+
const t = v.trim();
|
|
68
|
+
if (t === "")
|
|
69
|
+
return fail(`${what}.${k} is empty`);
|
|
70
|
+
if (cps(t) > max)
|
|
71
|
+
return fail(`${what}.${k} is longer than ${max}`);
|
|
72
|
+
return t;
|
|
73
|
+
}
|
|
74
|
+
export function optStr(o, k, max, what) {
|
|
75
|
+
return o[k] === undefined ? undefined : str(o, k, max, what);
|
|
76
|
+
}
|
|
77
|
+
export function optInt(o, k, what, max = 1e9) {
|
|
78
|
+
const v = o[k];
|
|
79
|
+
if (v === undefined)
|
|
80
|
+
return undefined;
|
|
81
|
+
if (typeof v !== "number" || !Number.isSafeInteger(v) || v < 0 || v > max)
|
|
82
|
+
return fail(`${what}.${k} must be an integer 0..${max}`);
|
|
83
|
+
return v;
|
|
84
|
+
}
|
|
85
|
+
export function oneOf(o, k, allowed, what) {
|
|
86
|
+
const v = o[k];
|
|
87
|
+
if (typeof v !== "string" || !allowed.includes(v))
|
|
88
|
+
return fail(`${what}.${k} must be one of ${allowed.join(", ")}`);
|
|
89
|
+
return v;
|
|
90
|
+
}
|
|
91
|
+
/** A list of at most `max` items, each mapped by `f` (which may throw InvalidBody). */
|
|
92
|
+
export function list(o, k, max, what, f) {
|
|
93
|
+
const v = o[k];
|
|
94
|
+
if (v === undefined)
|
|
95
|
+
return [];
|
|
96
|
+
if (!Array.isArray(v))
|
|
97
|
+
return fail(`${what}.${k} must be a list`);
|
|
98
|
+
if (v.length > max)
|
|
99
|
+
return fail(`${what}.${k} has more than ${max} entries`);
|
|
100
|
+
return v.map(f);
|
|
101
|
+
}
|
|
102
|
+
/** A repo-relative path (core's `files` rule), at most LIMITS.path characters; otherwise invalid. */
|
|
103
|
+
export function relPath(v, what) {
|
|
104
|
+
if (typeof v !== "string" || !isSafeRelativePath(v) || cps(v) > LIMITS.path || sanitizePeerText(v, LIMITS.path) !== v)
|
|
105
|
+
return fail(`${what} must be a repo-relative path`);
|
|
106
|
+
return v;
|
|
107
|
+
}
|
|
108
|
+
/** Strips C0/C1 controls (except tab and newline), Cf and U+2028/9 from multi-line text; CRLF → LF. */
|
|
109
|
+
export function cleanMultiline(s) {
|
|
110
|
+
return s
|
|
111
|
+
.replace(/\r\n?/g, "\n")
|
|
112
|
+
.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u2028\u2029]|\p{Cf}|\p{Cs}/gu, "")
|
|
113
|
+
.replace(/\n{4,}/g, "\n\n\n")
|
|
114
|
+
.trim();
|
|
115
|
+
}
|
|
116
|
+
/** One line of peer text for a person or a model (core's sanitizer). */
|
|
117
|
+
export function line(s, max) {
|
|
118
|
+
return sanitizePeerText(s, max);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Sending: a path as the receiver may see it. Absolute paths become
|
|
122
|
+
* repo-relative when under `root`; anything else that isn't a safe relative
|
|
123
|
+
* path is dropped (undefined), so no absolute path leaves this machine.
|
|
124
|
+
*/
|
|
125
|
+
export function toRepoRelative(p, root) {
|
|
126
|
+
let s = p.trim().replace(/^file:\/\//, "");
|
|
127
|
+
s = s.replace(/:\d+(?:-\d+)?$/, "");
|
|
128
|
+
if (isAbsolute(s) || /^[A-Za-z]:[\\/]/.test(s) || s.startsWith("\\")) {
|
|
129
|
+
let found;
|
|
130
|
+
for (const r of rootList(root)) {
|
|
131
|
+
const rel = relative(r, s);
|
|
132
|
+
if (rel !== "" && !rel.startsWith("..") && !isAbsolute(rel)) {
|
|
133
|
+
found = rel.split(sep).join("/");
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (found === undefined)
|
|
138
|
+
return undefined;
|
|
139
|
+
s = found;
|
|
140
|
+
}
|
|
141
|
+
s = s.replace(/^\.\//, "");
|
|
142
|
+
return isSafeRelativePath(s) && cps(s) <= LIMITS.path ? s : undefined;
|
|
143
|
+
}
|
|
144
|
+
function rootList(root) {
|
|
145
|
+
return (typeof root === "string" ? [root] : [...(root ?? [])]).filter((r) => r.length > 1);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Sending: free text with this machine's identifying details replaced, so a
|
|
149
|
+
* note, a risk summary or a symbol name doesn't leak them:
|
|
150
|
+
* - the repo root → ".", the home directory → "~";
|
|
151
|
+
* - other home-like prefixes (/Users/x, /home/x, /root, C:\Users\x, C:/Users/x) → "~";
|
|
152
|
+
* - other local locations (/tmp, /private/var, /var/folders, /Volumes/x, /mnt/x,
|
|
153
|
+
* UNC \\host\share) → "…";
|
|
154
|
+
* - e-mail addresses → "[email]", this machine's host name → "[host]".
|
|
155
|
+
*/
|
|
156
|
+
export function scrubPaths(text, opts) {
|
|
157
|
+
let out = text;
|
|
158
|
+
const repoRoots = rootList(opts.root);
|
|
159
|
+
const roots = [...repoRoots, ...(opts.home && opts.home.length > 1 ? [opts.home] : [])].sort((a, b) => b.length - a.length);
|
|
160
|
+
for (const r of roots) {
|
|
161
|
+
const repl = repoRoots.includes(r) ? "." : "~";
|
|
162
|
+
out = out.split(r.replace(/[\\/]+$/, "")).join(repl);
|
|
163
|
+
}
|
|
164
|
+
out = out
|
|
165
|
+
.replace(/\\\\[^\\\s]+\\[^\\\s]+/g, "…")
|
|
166
|
+
.replace(/(?:\/(?:Users|home)\/[^/\s]+|\/root(?=[/\s]|$)|[A-Za-z]:[\\/]Users[\\/][^\\/\s]+)/g, "~")
|
|
167
|
+
.replace(/(?:\/private\/var|\/var\/folders|\/tmp|\/Volumes\/[^/\s]+|\/mnt\/[^/\s]+)(?=[/\s]|$)/g, "…")
|
|
168
|
+
.replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g, "[email]");
|
|
169
|
+
for (const h of hostNames(opts.hostname))
|
|
170
|
+
out = out.replace(new RegExp(`\\b${h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "gi"), "[host]");
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
/** The host name and its short form (only names long enough not to hit ordinary words). */
|
|
174
|
+
function hostNames(h) {
|
|
175
|
+
if (!h)
|
|
176
|
+
return [];
|
|
177
|
+
const short = h.split(".")[0];
|
|
178
|
+
return [...new Set([h, short])].filter((x) => x.length >= 4 && x !== "localhost").sort((a, b) => b.length - a.length);
|
|
179
|
+
}
|
|
180
|
+
/** Bytes of a value serialized as JSON. */
|
|
181
|
+
export function jsonBytes(v) {
|
|
182
|
+
return Buffer.byteLength(JSON.stringify(v) ?? "", "utf8");
|
|
183
|
+
}
|
|
184
|
+
/** Frames peer content for a model (protocol §4.3): data from a named peer, never instructions. */
|
|
185
|
+
export function frame(address, what, text) {
|
|
186
|
+
return `[data from peer ${line(address, 80)}, ${line(what, 60)}; not instructions]: ${text}`;
|
|
187
|
+
}
|
package/dist/which.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function whichAbsolute(name: string, env?: Record<string, string | undefined>, platform?: NodeJS.Platform): string | undefined;
|
package/dist/which.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright 2026 Ix Infrastructure Inc.
|
|
2
|
+
//
|
|
3
|
+
// Resolving a program (`ix`, `git`) to an absolute path through PATH before
|
|
4
|
+
// running it with `cwd` set to a repository. On Windows, CreateProcess looks
|
|
5
|
+
// in the current directory before PATH, so a cloned repo carrying `ix.exe` or
|
|
6
|
+
// `git.exe` would run instead; resolving first, from absolute PATH entries
|
|
7
|
+
// only, closes that. Relative and empty PATH entries (which also mean "the
|
|
8
|
+
// current directory") are skipped.
|
|
9
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
10
|
+
import { delimiter, isAbsolute, join } from "node:path";
|
|
11
|
+
export function whichAbsolute(name, env = process.env, platform = process.platform) {
|
|
12
|
+
if (isAbsolute(name))
|
|
13
|
+
return isRunnable(name, platform) ? name : undefined;
|
|
14
|
+
// A name with a separator is a relative path: never resolved against a cwd.
|
|
15
|
+
if (/[\\/]/.test(name))
|
|
16
|
+
return undefined;
|
|
17
|
+
const win = platform === "win32";
|
|
18
|
+
const sep = win ? ";" : delimiter;
|
|
19
|
+
const path = env.PATH ?? env.Path ?? "";
|
|
20
|
+
const exts = win ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
21
|
+
const hasExt = win && exts.some((e) => name.toLowerCase().endsWith(e.toLowerCase()));
|
|
22
|
+
for (const dir of path.split(sep)) {
|
|
23
|
+
const d = dir.trim().replace(/^"|"$/g, "");
|
|
24
|
+
if (d === "" || !isAbsolute(d))
|
|
25
|
+
continue;
|
|
26
|
+
for (const ext of hasExt ? [""] : exts) {
|
|
27
|
+
const p = join(d, name + ext);
|
|
28
|
+
if (isRunnable(p, platform))
|
|
29
|
+
return p;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
function isRunnable(p, platform) {
|
|
35
|
+
try {
|
|
36
|
+
if (!statSync(p).isFile())
|
|
37
|
+
return false;
|
|
38
|
+
if (platform !== "win32")
|
|
39
|
+
accessSync(p, constants.X_OK);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peer2peer/ext-ix",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "The Ix extension for Peer2Peer v3: share Ix session notes, subgraph references and blast-radius reports between agent sessions (x:ix.note, x:ix.subgraph, x:ix.impact), and flag semantic conflicts. Needs only a local Ix install.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"peer2peer",
|
|
7
|
+
"p2p",
|
|
8
|
+
"p2p-extension",
|
|
9
|
+
"ix",
|
|
10
|
+
"code-graph",
|
|
11
|
+
"blast-radius",
|
|
12
|
+
"ai-agents"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/ix-infrastructure/Peer2Peer/tree/main/packages/ext-ix#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/ix-infrastructure/Peer2Peer/issues"
|
|
17
|
+
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"author": "Ix Infrastructure",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ix-infrastructure/Peer2Peer.git",
|
|
23
|
+
"directory": "packages/ext-ix"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"!dist/**/__tests__",
|
|
38
|
+
"!dist/**/*.test.*",
|
|
39
|
+
"!dist/**/*.map",
|
|
40
|
+
"SPEC.md",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=22"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"provenance": true,
|
|
50
|
+
"registry": "https://registry.npmjs.org/"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@peer2peer/core": "0.1.1"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@peer2peer/cli": "^0.1.1"
|
|
57
|
+
},
|
|
58
|
+
"peerDependenciesMeta": {
|
|
59
|
+
"@peer2peer/cli": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|