@miadi/relational-git-repository-mapper 0.6.2 → 0.7.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/dist/commit.d.ts +11 -3
- package/dist/commit.js +36 -5
- package/dist/read.js +8 -7
- package/package.json +3 -3
package/dist/commit.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export interface CommitCapability {
|
|
|
8
8
|
name: string;
|
|
9
9
|
/** the files of the commit that define it */
|
|
10
10
|
files: string[];
|
|
11
|
+
/** the version its package.json names at the commit (a CLI: the package that ships it); absent for a skill or when the manifest is unreadable there */
|
|
12
|
+
version?: string;
|
|
13
|
+
/** true when the commit itself changed that version: it is the release this change shipped in, not an earlier one */
|
|
14
|
+
versionChanged?: boolean;
|
|
11
15
|
/** the commit and its files; `revision` is `pending` until a person reads it */
|
|
12
16
|
attribution: Attribution;
|
|
13
17
|
}
|
|
@@ -24,7 +28,7 @@ export interface CommitCapabilities {
|
|
|
24
28
|
skipped?: "versions-only";
|
|
25
29
|
capabilities: CommitCapability[];
|
|
26
30
|
}
|
|
27
|
-
export type CommitReadFailure = "not-a-commit-ref" | "clone-not-of-repository" | "commit-not-in-clone";
|
|
31
|
+
export type CommitReadFailure = "not-a-commit-ref" | "clone-not-of-repository" | "commit-not-in-clone" | "merge-commit" | "not-on-origin";
|
|
28
32
|
export declare class CommitReadError extends Error {
|
|
29
33
|
readonly code: CommitReadFailure;
|
|
30
34
|
constructor(code: CommitReadFailure, message: string);
|
|
@@ -56,12 +60,16 @@ export interface CommitCapabilitiesOptions {
|
|
|
56
60
|
rows?: readonly CapabilityFacet[];
|
|
57
61
|
by?: string;
|
|
58
62
|
at?: string;
|
|
63
|
+
/** refuse a commit no `origin` remote-tracking branch holds: a local, amended or rebased-away commit is not what was pushed */
|
|
64
|
+
onOrigin?: boolean;
|
|
59
65
|
}
|
|
60
66
|
/**
|
|
61
67
|
* The capability rows `owner/name@sha` changed, read from a local clone whose
|
|
62
68
|
* `origin` is that repository. Read-only: `git remote get-url`, `rev-parse`,
|
|
63
69
|
* `diff`, `show`. Never fetches. Throws {@link CommitReadError} when the ref is
|
|
64
|
-
* not a commit ref, the clone's origin names another repository,
|
|
65
|
-
* does not hold the commit
|
|
70
|
+
* not a commit ref, the clone's origin names another repository, the clone
|
|
71
|
+
* does not hold the commit, the commit is a merge (against its first parent a merge
|
|
72
|
+
* counts everything it brought in as its own), or, with `onOrigin`, no `origin`
|
|
73
|
+
* remote-tracking branch holds it.
|
|
66
74
|
*/
|
|
67
75
|
export declare function capabilitiesOfCommit(ref: string, clone: string, options?: CommitCapabilitiesOptions): CommitCapabilities;
|
package/dist/commit.js
CHANGED
|
@@ -55,6 +55,18 @@ function changesOnlyVersions(before, after) {
|
|
|
55
55
|
const b = manifestShape(after);
|
|
56
56
|
return a !== undefined && a === b;
|
|
57
57
|
}
|
|
58
|
+
/** The `version` a package.json text names, or undefined. */
|
|
59
|
+
function manifestVersion(text) {
|
|
60
|
+
if (text === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
try {
|
|
63
|
+
const v = JSON.parse(text).version;
|
|
64
|
+
return typeof v === "string" && v.trim() ? v.trim() : undefined;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
58
70
|
/** The path a shipped row's grounding names (`owner/name@sha:<path>`), or undefined. */
|
|
59
71
|
function groundedPath(row) {
|
|
60
72
|
for (const g of row.grounding) {
|
|
@@ -134,7 +146,8 @@ function changedCapabilities(input) {
|
|
|
134
146
|
continue;
|
|
135
147
|
if (kind === "skill" && defining.includes(path))
|
|
136
148
|
add(row, "skill", path);
|
|
137
|
-
|
|
149
|
+
// A CLI's entry point lives in its package's folder: a commit that changed nothing there reads no manifest for it.
|
|
150
|
+
if (kind === "cli" && node_path_1.posix.basename(path) === "package.json" && defining.some((f) => inFolder(f, node_path_1.posix.dirname(path)))) {
|
|
138
151
|
const entry = binEntry(input.read(path, "after") ?? input.read(path, "before"), row.name);
|
|
139
152
|
if (!entry)
|
|
140
153
|
continue;
|
|
@@ -146,11 +159,21 @@ function changedCapabilities(input) {
|
|
|
146
159
|
const at = input.at ?? new Date().toISOString();
|
|
147
160
|
const by = input.by ?? "@miadi/relational-git-repository-mapper";
|
|
148
161
|
const capabilities = [...changed.values()]
|
|
149
|
-
.map(({ row, kind, files }) =>
|
|
162
|
+
.map(({ row, kind, files }) => {
|
|
163
|
+
// A package and a CLI are versioned by the manifest their row is grounded in, as it reads at the commit.
|
|
164
|
+
const manifest = kind === "skill" ? undefined : groundedPath(row);
|
|
165
|
+
const isManifest = manifest !== undefined && node_path_1.posix.basename(manifest) === "package.json";
|
|
166
|
+
const version = isManifest ? manifestVersion(input.read(manifest, "after")) : undefined;
|
|
167
|
+
const versionChanged = isManifest && version !== undefined && manifestVersion(input.read(manifest, "before")) !== version;
|
|
168
|
+
return { row, kind, files, version, versionChanged };
|
|
169
|
+
})
|
|
170
|
+
.map(({ row, kind, files, version, versionChanged }) => ({
|
|
150
171
|
address: (0, capabilities_1.capabilityAddress)(provider(row), kind, row.name),
|
|
151
172
|
nodeId: row.nodeId,
|
|
152
173
|
kind,
|
|
153
174
|
name: row.name,
|
|
175
|
+
...(version ? { version } : {}),
|
|
176
|
+
...(versionChanged ? { versionChanged: true } : {}),
|
|
154
177
|
files: files.sort(),
|
|
155
178
|
attribution: { statedBy: by, statedAt: at, grounding: [input.commit, ...files.sort().map((f) => `${input.commit}:${f}`)], revision: "pending" },
|
|
156
179
|
}))
|
|
@@ -167,7 +190,7 @@ function remoteRepository(url) {
|
|
|
167
190
|
}
|
|
168
191
|
const git = (clone, args) => {
|
|
169
192
|
try {
|
|
170
|
-
return (0, node_child_process_1.execFileSync)("git", ["-C", clone, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024 });
|
|
193
|
+
return (0, node_child_process_1.execFileSync)("git", ["-C", clone, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024, timeout: 15_000 });
|
|
171
194
|
}
|
|
172
195
|
catch {
|
|
173
196
|
return undefined;
|
|
@@ -177,8 +200,10 @@ const git = (clone, args) => {
|
|
|
177
200
|
* The capability rows `owner/name@sha` changed, read from a local clone whose
|
|
178
201
|
* `origin` is that repository. Read-only: `git remote get-url`, `rev-parse`,
|
|
179
202
|
* `diff`, `show`. Never fetches. Throws {@link CommitReadError} when the ref is
|
|
180
|
-
* not a commit ref, the clone's origin names another repository,
|
|
181
|
-
* does not hold the commit
|
|
203
|
+
* not a commit ref, the clone's origin names another repository, the clone
|
|
204
|
+
* does not hold the commit, the commit is a merge (against its first parent a merge
|
|
205
|
+
* counts everything it brought in as its own), or, with `onOrigin`, no `origin`
|
|
206
|
+
* remote-tracking branch holds it.
|
|
182
207
|
*/
|
|
183
208
|
function capabilitiesOfCommit(ref, clone, options = {}) {
|
|
184
209
|
const rows = options.rows ?? (0, read_1.readCapabilities)().capabilities;
|
|
@@ -193,6 +218,12 @@ function capabilitiesOfCommit(ref, clone, options = {}) {
|
|
|
193
218
|
const sha = git(clone, ["rev-parse", "--verify", "--quiet", `${t.sha}^{commit}`])?.trim();
|
|
194
219
|
if (!sha)
|
|
195
220
|
throw new CommitReadError("commit-not-in-clone", `${clone} does not hold ${t.sha}`);
|
|
221
|
+
const parents = (git(clone, ["rev-list", "--parents", "-n", "1", sha]) ?? "").trim().split(/\s+/).slice(1);
|
|
222
|
+
if (parents.length > 1)
|
|
223
|
+
throw new CommitReadError("merge-commit", `${sha} is a merge of ${parents.length} parents`);
|
|
224
|
+
if (options.onOrigin && !git(clone, ["for-each-ref", "--contains", sha, "--count=1", "--format=%(refname)", "refs/remotes/origin"])?.trim()) {
|
|
225
|
+
throw new CommitReadError("not-on-origin", `no origin branch holds ${sha}`);
|
|
226
|
+
}
|
|
196
227
|
const parent = git(clone, ["rev-parse", "--verify", "--quiet", `${sha}^1`])?.trim();
|
|
197
228
|
const listed = parent
|
|
198
229
|
? git(clone, ["diff", "--name-only", "--no-renames", parent, sha])
|
package/dist/read.js
CHANGED
|
@@ -119,12 +119,14 @@ function readCapabilities(path = process.env.MIADI_REPOSITORY_CAPABILITIES?.trim
|
|
|
119
119
|
issues.push({ severity: "error", file: source, line: index + 1, message: parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ") });
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
// One row per capability and provider: two repositories with one id (a fork and its upstream) each keep their own words.
|
|
123
|
+
const key = `${parsed.data.nodeId}|${parsed.data.providedBy.map((p) => p.toLowerCase()).sort().join(",")}`;
|
|
124
|
+
const earlier = seen.get(key);
|
|
123
125
|
if (earlier) {
|
|
124
|
-
issues.push({ severity: "warning", file: source, nodeId: parsed.data.nodeId, message: `${parsed.data.nodeId} is already read from ${earlier}; skipped` });
|
|
126
|
+
issues.push({ severity: "warning", file: source, nodeId: parsed.data.nodeId, message: `${parsed.data.nodeId} of ${parsed.data.providedBy.join(", ")} is already read from ${earlier}; skipped` });
|
|
125
127
|
return;
|
|
126
128
|
}
|
|
127
|
-
seen.set(
|
|
129
|
+
seen.set(key, source);
|
|
128
130
|
capabilities.push(parsed.data);
|
|
129
131
|
});
|
|
130
132
|
}
|
|
@@ -161,10 +163,9 @@ function findCapability(parts, options = {}) {
|
|
|
161
163
|
if (!provider)
|
|
162
164
|
continue;
|
|
163
165
|
// The provider's own reading: a fork, or another repository with a package of the same name, never speaks for it.
|
|
164
|
-
const { packages
|
|
165
|
-
const own =
|
|
166
|
-
const
|
|
167
|
-
const impact = kind === "package" && own ? (0, impact_1.impactOf)(c.name, packages) : undefined;
|
|
166
|
+
const { packages } = readPackages();
|
|
167
|
+
const own = packages.find((p) => p.name === c.name && p.repository.toLowerCase() === repository);
|
|
168
|
+
const impact = kind === "package" && own ? (0, impact_1.impactOf)(c.name, packages, undefined, { repository: own.repository }) : undefined;
|
|
168
169
|
const related = [];
|
|
169
170
|
const version = (v) => (v ? { version: v } : {});
|
|
170
171
|
if (impact) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/relational-git-repository-mapper",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A git repository as Miadi sees it (git, never a database Repository or Data Mapper): the rows its owner hub holds (@medicine-wheel/developer-repository-mapping) beside the agent sessions that worked in it (the witness team's session inventory), joined by owner/name; which git repository learned from which (a lineage, never a dependency); what each provides, its packages, CLIs and skills as capability nodes; where each lives; and what a version bump touches downstream.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Miadi",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@medicine-wheel/capabilities": "^0.27.
|
|
32
|
-
"@medicine-wheel/developer-repository-mapping": "^0.27.
|
|
31
|
+
"@medicine-wheel/capabilities": "^0.27.12",
|
|
32
|
+
"@medicine-wheel/developer-repository-mapping": "^0.27.12",
|
|
33
33
|
"@miadi/hooks-interpreter": "^0.11.0",
|
|
34
34
|
"zod": "^3.23.0"
|
|
35
35
|
},
|