@miadi/relational-git-repository-mapper 0.5.2 → 0.6.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/README.md CHANGED
@@ -18,8 +18,10 @@ package). The CLI keeps its name, `miadi-repomap`.
18
18
  it registers. Lifecycle, purpose, git drift, features, relations.
19
19
  - **The sessions** come from the witness team's session inventory, read with
20
20
  `@miadi/hooks-interpreter` (`readInventoryRecords`): one record per Claude session.
21
- - **The join**: a record's `repo` (`owner/name`), case-folded, matched to
22
- `repository:<owner>/<name>`. Records without a `repo` are counted, not shown.
21
+ - **The join**: a record's `repo` (`owner/name`) and the repository of each commit its
22
+ `links.trace` names (`owner/name@sha`), case-folded, matched to `repository:<owner>/<name>`.
23
+ A session that committed to two repositories appears under both, with the commits it made
24
+ in each (`commits`). Records that name no repository are counted, not shown.
23
25
 
24
26
  Per session it carries `session_id`, `tmux_session_name`, `status`, the team
25
27
  (`team_fit.team.id`, else `team`), `mission`, `date` (as YYYY-MM-DD), the titles of `work_completed`, the
@@ -104,6 +106,29 @@ In the app: `GET /api/repositories/capabilities[?repository=owner/name]` answers
104
106
  capabilities and their `provides` edges, `GET /api/repositories/{owner}/{name}` carries them,
105
107
  and the repository page's Lineage card lists them by kind.
106
108
 
109
+ ## Which capabilities a commit changed
110
+
111
+ ```ts
112
+ import { capabilitiesOfCommit } from "@miadi/relational-git-repository-mapper";
113
+ capabilitiesOfCommit("jgwill/Miadi@b746c9a4", "/a/src/Miadi").capabilities.map((c) => c.address);
114
+ // → miadi-capability://jgwill/Miadi/package/@miadi/inquiry-weave, miadi-capability://jgwill/Miadi/package/miadi-project
115
+ ```
116
+
117
+ Given `owner/name@sha` and a local clone whose `origin` is that repository (GitHub, or a
118
+ host's own git server), it reads the commit against its first parent and answers the
119
+ registry's rows whose defining files changed: for a package any file in its folder (a file
120
+ counts for the deepest package folder that holds it), for a CLI its `bin` entry point (and
121
+ for a `dist/<x>.js` entry its `src/<x>` source), for a skill its `SKILL.md`. A lockfile, and
122
+ a `package.json` whose version or dependency ranges alone moved, define nothing, so a commit
123
+ that changes only those answers `skipped: "versions-only"`. Each answer carries an
124
+ attribution of `@medicine-wheel/capabilities` with revision `pending`, grounded in the commit
125
+ and its files. It never fetches: a clone that does not hold the commit, or whose origin names
126
+ another repository, is refused (`CommitReadError`). `changedCapabilities` is the pure half.
127
+
128
+ A record's `capabilities[]` is read back: `capabilitySessions(address, records)` lists the
129
+ sessions whose record names a capability, and `findCapability(parts, { sessions: true })`
130
+ carries them. The app's `/api/repositories/capability` answers them to the write tier only.
131
+
107
132
  ## Where a repository lives
108
133
 
109
134
  A name like `jgwill/episodes` does not say where the repository is. `miadi-repomap where`
package/dist/cli.js CHANGED
@@ -139,7 +139,8 @@ function linkLines(links) {
139
139
  }
140
140
  function sessionLine(s) {
141
141
  const ending = s.disposition ? ` ending ${s.disposition.decided ?? `${s.disposition.proposed} (proposed)`}` : "";
142
- return ` ${s.date ?? "?"} ${(s.tmux_session_name ?? s.session_id).padEnd(36)} ${(s.team ?? "-").padEnd(10)} ${s.status ?? "-"}${ending} ${s.session_id}`;
142
+ const commits = s.commits?.length ? ` commits ${s.commits.join(" ")}` : "";
143
+ return ` ${s.date ?? "?"} ${(s.tmux_session_name ?? s.session_id).padEnd(36)} ${(s.team ?? "-").padEnd(10)} ${s.status ?? "-"}${ending} ${s.session_id}${commits}`;
143
144
  }
144
145
  async function main() {
145
146
  const { positional, flags } = parse(process.argv.slice(2));
@@ -0,0 +1,67 @@
1
+ import type { Attribution, CapabilityFacet } from "@medicine-wheel/capabilities";
2
+ import { type CapabilityKind } from "./capabilities";
3
+ export interface CommitCapability {
4
+ /** `miadi-capability://<owner>/<repo>/<kind>/<name>` */
5
+ address: string;
6
+ nodeId: string;
7
+ kind: CapabilityKind;
8
+ name: string;
9
+ /** the files of the commit that define it */
10
+ files: string[];
11
+ /** the commit and its files; `revision` is `pending` until a person reads it */
12
+ attribution: Attribution;
13
+ }
14
+ export interface CommitCapabilities {
15
+ /** `owner/name@sha`, as asked */
16
+ commit: string;
17
+ /** `repository:<owner>/<name>`, spelled as the registry rows spell it when one does */
18
+ repository: string;
19
+ /** the full sha */
20
+ sha: string;
21
+ /** every file the commit changed against its first parent */
22
+ files: string[];
23
+ /** `versions-only`: every file changed is a lockfile or a package.json whose version or dependency ranges alone moved */
24
+ skipped?: "versions-only";
25
+ capabilities: CommitCapability[];
26
+ }
27
+ export type CommitReadFailure = "not-a-commit-ref" | "clone-not-of-repository" | "commit-not-in-clone";
28
+ export declare class CommitReadError extends Error {
29
+ readonly code: CommitReadFailure;
30
+ constructor(code: CommitReadFailure, message: string);
31
+ }
32
+ /** A package.json whose change, before to after, is only its version and the ranges of the dependencies it already had. */
33
+ export declare function changesOnlyVersions(before: string | undefined, after: string | undefined): boolean;
34
+ export interface ChangedCapabilitiesInput {
35
+ /** `repository:<owner>/<name>` */
36
+ repository: string;
37
+ /** `owner/name@sha`, used in each attribution's grounding */
38
+ commit: string;
39
+ /** the files the commit changed */
40
+ files: readonly string[];
41
+ /** a file's text at the commit (`after`) or at its first parent (`before`); undefined when it is not there */
42
+ read: (path: string, at: "before" | "after") => string | undefined;
43
+ /** the registry's rows */
44
+ rows: readonly CapabilityFacet[];
45
+ /** who states the attributions; default this package */
46
+ by?: string;
47
+ /** when; default now */
48
+ at?: string;
49
+ }
50
+ /** The pure half: which of the repository's rows the changed files define. */
51
+ export declare function changedCapabilities(input: ChangedCapabilitiesInput): Pick<CommitCapabilities, "capabilities" | "skipped">;
52
+ /** `owner/name` of a remote URL: GitHub's, else the last two segments of the path (a host's own git server). */
53
+ export declare function remoteRepository(url: string): string | undefined;
54
+ export interface CommitCapabilitiesOptions {
55
+ /** the registry's rows; default {@link readCapabilities} (a host's JSONL, then the shipped scan) */
56
+ rows?: readonly CapabilityFacet[];
57
+ by?: string;
58
+ at?: string;
59
+ }
60
+ /**
61
+ * The capability rows `owner/name@sha` changed, read from a local clone whose
62
+ * `origin` is that repository. Read-only: `git remote get-url`, `rev-parse`,
63
+ * `diff`, `show`. Never fetches. Throws {@link CommitReadError} when the ref is
64
+ * not a commit ref, the clone's origin names another repository, or the clone
65
+ * does not hold the commit.
66
+ */
67
+ export declare function capabilitiesOfCommit(ref: string, clone: string, options?: CommitCapabilitiesOptions): CommitCapabilities;
package/dist/commit.js ADDED
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ // Which capability rows a commit changed (jgwill/Miadi#993). A row is changed
3
+ // when the commit changes a file that defines it: for a package, any file in
4
+ // its folder; for a CLI, its entry point; for a skill, its SKILL.md. A
5
+ // package.json whose change is only its version and its dependency ranges,
6
+ // and a lockfile, define nothing, so a commit that changes only those
7
+ // changes no capability. Each answer is a pending attribution until a person
8
+ // reads it.
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.CommitReadError = void 0;
11
+ exports.changesOnlyVersions = changesOnlyVersions;
12
+ exports.changedCapabilities = changedCapabilities;
13
+ exports.remoteRepository = remoteRepository;
14
+ exports.capabilitiesOfCommit = capabilitiesOfCommit;
15
+ const node_child_process_1 = require("node:child_process");
16
+ const node_path_1 = require("node:path");
17
+ const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
18
+ const capabilities_1 = require("./capabilities");
19
+ const join_1 = require("./join");
20
+ const read_1 = require("./read");
21
+ class CommitReadError extends Error {
22
+ code;
23
+ constructor(code, message) {
24
+ super(message);
25
+ this.code = code;
26
+ this.name = "CommitReadError";
27
+ }
28
+ }
29
+ exports.CommitReadError = CommitReadError;
30
+ const LOCKFILES = new Set(["pnpm-lock.yaml", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "bun.lockb"]);
31
+ const DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
32
+ /** A package.json with its version removed and each dependency map reduced to its names. Undefined when it does not parse. */
33
+ function manifestShape(text) {
34
+ if (text === undefined)
35
+ return undefined;
36
+ try {
37
+ const json = JSON.parse(text);
38
+ if (typeof json !== "object" || json === null || Array.isArray(json))
39
+ return undefined;
40
+ const { version: _version, ...rest } = json;
41
+ for (const field of DEPENDENCY_FIELDS) {
42
+ const map = rest[field];
43
+ if (map && typeof map === "object" && !Array.isArray(map))
44
+ rest[field] = Object.keys(map).sort();
45
+ }
46
+ return JSON.stringify(rest);
47
+ }
48
+ catch {
49
+ return undefined;
50
+ }
51
+ }
52
+ /** A package.json whose change, before to after, is only its version and the ranges of the dependencies it already had. */
53
+ function changesOnlyVersions(before, after) {
54
+ const a = manifestShape(before);
55
+ const b = manifestShape(after);
56
+ return a !== undefined && a === b;
57
+ }
58
+ /** The path a shipped row's grounding names (`owner/name@sha:<path>`), or undefined. */
59
+ function groundedPath(row) {
60
+ for (const g of row.grounding) {
61
+ const m = /^[^\s@]+@[0-9a-f]+:(.+)$/i.exec(g);
62
+ if (m)
63
+ return m[1];
64
+ }
65
+ return undefined;
66
+ }
67
+ /** The files a CLI entry point may be committed as: the `bin` path, and for a `dist/<x>.js` its `src/<x>` source. */
68
+ function entryCandidates(folder, entry) {
69
+ const rel = node_path_1.posix.normalize(entry.replace(/^\.\//, ""));
70
+ const out = [node_path_1.posix.join(folder, rel)];
71
+ const built = /^dist\/(.+)\.(?:c|m)?js$/.exec(rel);
72
+ if (built)
73
+ for (const ext of ["ts", "tsx", "mts", "cts", "js", "mjs", "cjs"])
74
+ out.push(node_path_1.posix.join(folder, "src", `${built[1]}.${ext}`));
75
+ return out;
76
+ }
77
+ /** A package's `bin` entry for one command: `bin` as a string ships the package's own name, unscoped. */
78
+ function binEntry(manifest, command) {
79
+ try {
80
+ const json = JSON.parse(manifest ?? "");
81
+ if (typeof json.bin === "string") {
82
+ const own = typeof json.name === "string" ? json.name.replace(/^@[^/]+\//, "") : undefined;
83
+ return own === command ? json.bin : undefined;
84
+ }
85
+ if (json.bin && typeof json.bin === "object") {
86
+ const entry = json.bin[command];
87
+ return typeof entry === "string" ? entry : undefined;
88
+ }
89
+ }
90
+ catch {
91
+ // an unreadable manifest ships no command
92
+ }
93
+ return undefined;
94
+ }
95
+ /** The pure half: which of the repository's rows the changed files define. */
96
+ function changedCapabilities(input) {
97
+ const key = (0, join_1.repositoryKey)(input.repository.replace(/^repository:/, ""));
98
+ const defining = input.files.filter((f) => {
99
+ if (LOCKFILES.has(node_path_1.posix.basename(f)))
100
+ return false;
101
+ if (node_path_1.posix.basename(f) === "package.json")
102
+ return !changesOnlyVersions(input.read(f, "before"), input.read(f, "after"));
103
+ return true;
104
+ });
105
+ if (input.files.length && !defining.length)
106
+ return { skipped: "versions-only", capabilities: [] };
107
+ const rows = input.rows.filter((r) => r.providedBy.some((p) => p.startsWith("repository:") && (0, join_1.repositoryKey)(p.slice("repository:".length)) === key));
108
+ const provider = (r) => r.providedBy.find((p) => p.startsWith("repository:") && (0, join_1.repositoryKey)(p.slice("repository:".length)) === key);
109
+ // A file belongs to the deepest package folder that holds it.
110
+ const packages = rows
111
+ .filter((r) => (0, capabilities_1.kindOf)(r.nodeId) === "package")
112
+ .flatMap((r) => {
113
+ const manifest = groundedPath(r);
114
+ return manifest && node_path_1.posix.basename(manifest) === "package.json" ? [{ row: r, folder: node_path_1.posix.dirname(manifest) }] : [];
115
+ })
116
+ .sort((a, b) => b.folder.length - a.folder.length);
117
+ const inFolder = (file, folder) => folder === "." || file.startsWith(`${folder}/`);
118
+ const changed = new Map();
119
+ const add = (row, kind, file) => {
120
+ const known = changed.get(row.nodeId) ?? { row, kind, files: [] };
121
+ if (!known.files.includes(file))
122
+ known.files.push(file);
123
+ changed.set(row.nodeId, known);
124
+ };
125
+ for (const file of defining) {
126
+ const owner = packages.find((p) => inFolder(file, p.folder));
127
+ if (owner)
128
+ add(owner.row, "package", file);
129
+ }
130
+ for (const row of rows) {
131
+ const kind = (0, capabilities_1.kindOf)(row.nodeId);
132
+ const path = groundedPath(row);
133
+ if (!path)
134
+ continue;
135
+ if (kind === "skill" && defining.includes(path))
136
+ add(row, "skill", path);
137
+ if (kind === "cli" && node_path_1.posix.basename(path) === "package.json") {
138
+ const entry = binEntry(input.read(path, "after") ?? input.read(path, "before"), row.name);
139
+ if (!entry)
140
+ continue;
141
+ for (const candidate of entryCandidates(node_path_1.posix.dirname(path), entry))
142
+ if (defining.includes(candidate))
143
+ add(row, "cli", candidate);
144
+ }
145
+ }
146
+ const at = input.at ?? new Date().toISOString();
147
+ const by = input.by ?? "@miadi/relational-git-repository-mapper";
148
+ const capabilities = [...changed.values()]
149
+ .map(({ row, kind, files }) => ({
150
+ address: (0, capabilities_1.capabilityAddress)(provider(row), kind, row.name),
151
+ nodeId: row.nodeId,
152
+ kind,
153
+ name: row.name,
154
+ files: files.sort(),
155
+ attribution: { statedBy: by, statedAt: at, grounding: [input.commit, ...files.sort().map((f) => `${input.commit}:${f}`)], revision: "pending" },
156
+ }))
157
+ .sort((a, b) => a.address.localeCompare(b.address));
158
+ return { capabilities };
159
+ }
160
+ /** `owner/name` of a remote URL: GitHub's, else the last two segments of the path (a host's own git server). */
161
+ function remoteRepository(url) {
162
+ const github = (0, developer_repository_mapping_1.parseGithubRemote)(url);
163
+ if (github)
164
+ return `${github.owner}/${github.name}`;
165
+ const m = /[/:]([^/:\s]+)\/([^/\s]+?)(?:\.git)?\/?$/.exec(url.trim());
166
+ return m ? `${m[1]}/${m[2]}` : undefined;
167
+ }
168
+ const git = (clone, args) => {
169
+ try {
170
+ return (0, node_child_process_1.execFileSync)("git", ["-C", clone, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024 });
171
+ }
172
+ catch {
173
+ return undefined;
174
+ }
175
+ };
176
+ /**
177
+ * The capability rows `owner/name@sha` changed, read from a local clone whose
178
+ * `origin` is that repository. Read-only: `git remote get-url`, `rev-parse`,
179
+ * `diff`, `show`. Never fetches. Throws {@link CommitReadError} when the ref is
180
+ * not a commit ref, the clone's origin names another repository, or the clone
181
+ * does not hold the commit.
182
+ */
183
+ function capabilitiesOfCommit(ref, clone, options = {}) {
184
+ const rows = options.rows ?? (0, read_1.readCapabilities)().capabilities;
185
+ const t = (0, join_1.parseTraceRef)(ref);
186
+ if (!t)
187
+ throw new CommitReadError("not-a-commit-ref", `${ref} is not owner/name@sha`);
188
+ const origin = git(clone, ["remote", "get-url", "origin"])?.trim();
189
+ const named = origin ? remoteRepository(origin) : undefined;
190
+ if (!named || (0, join_1.repositoryKey)(named) !== t.key) {
191
+ throw new CommitReadError("clone-not-of-repository", `${clone}'s origin is ${origin ?? "unset"}, not ${t.repository}`);
192
+ }
193
+ const sha = git(clone, ["rev-parse", "--verify", "--quiet", `${t.sha}^{commit}`])?.trim();
194
+ if (!sha)
195
+ throw new CommitReadError("commit-not-in-clone", `${clone} does not hold ${t.sha}`);
196
+ const parent = git(clone, ["rev-parse", "--verify", "--quiet", `${sha}^1`])?.trim();
197
+ const listed = parent
198
+ ? git(clone, ["diff", "--name-only", "--no-renames", parent, sha])
199
+ : git(clone, ["diff-tree", "--root", "-r", "--name-only", "--no-commit-id", "--no-renames", sha]);
200
+ const files = (listed ?? "").split("\n").map((f) => f.trim()).filter(Boolean);
201
+ const read = (path, at) => {
202
+ const rev = at === "after" ? sha : parent;
203
+ return rev ? git(clone, ["show", `${rev}:${path}`]) : undefined;
204
+ };
205
+ const repository = rows.flatMap((r) => r.providedBy).find((p) => p.startsWith("repository:") && (0, join_1.repositoryKey)(p.slice("repository:".length)) === t.key) ??
206
+ `repository:${t.repository}`;
207
+ const commit = `${t.repository}@${t.sha}`;
208
+ return { commit, repository, sha, files, ...changedCapabilities({ repository, commit, files, read, rows, by: options.by, at: options.at }) };
209
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { RepositorySession, MappingState, HubState, RepositoryView, RepositorySummary, InventoryState, RepositoryListing, } from "./types";
2
- export { dayOf, teamOf, dispositionOf, sessionOf, repositoryKey, sessionsByRepository, repositoryView, listRepositories, type SessionsByRepository, } from "./join";
2
+ export { dayOf, teamOf, dispositionOf, sessionOf, repositoryKey, parseTraceRef, repositoriesOfRecord, capabilityKey, capabilitySessions, type CapabilitySession, sessionsByRepository, repositoryView, listRepositories, type SessionsByRepository, } from "./join";
3
3
  export { LineageRowSchema, parseLineage, lineageOf, lineageGraph, type LineageRow, type LineageEdge, type LineageLink, type RepositoryLineage, type LineageGraph, } from "./lineage";
4
4
  export { SHIPPED_LINEAGE_JSONL, SHIPPED_LINEAGE_SOURCE } from "./shipped-lineage";
5
5
  export { CAPABILITY_KINDS, capabilityId, kindOf, parsePackageJson, parseSkillFrontMatter, workspaceGlobs, packageManifests, skillFiles, capabilityRows, mergeCapabilityRows, providesEdges, capabilitiesOf, capabilityAddress, medicineWheelSkills, CODE_READERS, type CapabilityKind, type CodeReader, type Artefact, type CapabilityRowContext, type ProvidesEdge, } from "./capabilities";
@@ -11,3 +11,4 @@ export { checkWhere, type CheckWhereOptions } from "./where";
11
11
  export { SHIPPED_PACKAGES } from "./shipped-capabilities";
12
12
  export { SHIPPED_HOSTS, SHIPPED_HOSTS_SOURCE } from "./shipped-hosts";
13
13
  export { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, readLineage, repositoryLineage, readCapabilities, repositoryCapabilities, readWhere, readPackages, repositoryImpact, findCapability, type CapabilityRecord, type RelatedCapability, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, type CapabilitiesRead, type CapabilitiesAnswer, type WhereRead, type ImpactRead, } from "./read";
14
+ export { capabilitiesOfCommit, changedCapabilities, changesOnlyVersions, remoteRepository, CommitReadError, type CommitCapability, type CommitCapabilities, type CommitCapabilitiesOptions, type CommitReadFailure, type ChangedCapabilitiesInput, } from "./commit";
package/dist/index.js CHANGED
@@ -4,14 +4,18 @@
4
4
  // "Repository" here is always a git repository, never the DDD Repository or a
5
5
  // Data Mapper. Formerly @miadi/relational-repository-mapper (deprecated).
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.hubPath = exports.inventoryDir = exports.SHIPPED_HOSTS_SOURCE = exports.SHIPPED_HOSTS = exports.SHIPPED_PACKAGES = exports.checkWhere = exports.webUrlOf = exports.whereOf = exports.parseWhere = exports.RepositoryWhereSchema = exports.RepositoryHostSchema = exports.impactOf = exports.satisfies = exports.bumpVersion = exports.consumesEdges = exports.PackageReadingSchema = exports.scanRepository = exports.readRepositoryCapabilities = exports.SHIPPED_CAPABILITIES_SOURCE = exports.SHIPPED_CAPABILITIES_SCANS = exports.SHIPPED_CAPABILITIES = exports.CODE_READERS = exports.medicineWheelSkills = exports.capabilityAddress = exports.capabilitiesOf = exports.providesEdges = exports.mergeCapabilityRows = exports.capabilityRows = exports.skillFiles = exports.packageManifests = exports.workspaceGlobs = exports.parseSkillFrontMatter = exports.parsePackageJson = exports.kindOf = exports.capabilityId = exports.CAPABILITY_KINDS = exports.SHIPPED_LINEAGE_SOURCE = exports.SHIPPED_LINEAGE_JSONL = exports.lineageGraph = exports.lineageOf = exports.parseLineage = exports.LineageRowSchema = exports.listRepositories = exports.repositoryView = exports.sessionsByRepository = exports.repositoryKey = exports.sessionOf = exports.dispositionOf = exports.teamOf = exports.dayOf = void 0;
8
- exports.findCapability = exports.repositoryImpact = exports.readPackages = exports.readWhere = exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = void 0;
7
+ exports.SHIPPED_PACKAGES = exports.checkWhere = exports.webUrlOf = exports.whereOf = exports.parseWhere = exports.RepositoryWhereSchema = exports.RepositoryHostSchema = exports.impactOf = exports.satisfies = exports.bumpVersion = exports.consumesEdges = exports.PackageReadingSchema = exports.scanRepository = exports.readRepositoryCapabilities = exports.SHIPPED_CAPABILITIES_SOURCE = exports.SHIPPED_CAPABILITIES_SCANS = exports.SHIPPED_CAPABILITIES = exports.CODE_READERS = exports.medicineWheelSkills = exports.capabilityAddress = exports.capabilitiesOf = exports.providesEdges = exports.mergeCapabilityRows = exports.capabilityRows = exports.skillFiles = exports.packageManifests = exports.workspaceGlobs = exports.parseSkillFrontMatter = exports.parsePackageJson = exports.kindOf = exports.capabilityId = exports.CAPABILITY_KINDS = exports.SHIPPED_LINEAGE_SOURCE = exports.SHIPPED_LINEAGE_JSONL = exports.lineageGraph = exports.lineageOf = exports.parseLineage = exports.LineageRowSchema = exports.listRepositories = exports.repositoryView = exports.sessionsByRepository = exports.capabilitySessions = exports.capabilityKey = exports.repositoriesOfRecord = exports.parseTraceRef = exports.repositoryKey = exports.sessionOf = exports.dispositionOf = exports.teamOf = exports.dayOf = void 0;
8
+ exports.CommitReadError = exports.remoteRepository = exports.changesOnlyVersions = exports.changedCapabilities = exports.capabilitiesOfCommit = exports.findCapability = exports.repositoryImpact = exports.readPackages = exports.readWhere = exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = exports.hubPath = exports.inventoryDir = exports.SHIPPED_HOSTS_SOURCE = exports.SHIPPED_HOSTS = void 0;
9
9
  var join_1 = require("./join");
10
10
  Object.defineProperty(exports, "dayOf", { enumerable: true, get: function () { return join_1.dayOf; } });
11
11
  Object.defineProperty(exports, "teamOf", { enumerable: true, get: function () { return join_1.teamOf; } });
12
12
  Object.defineProperty(exports, "dispositionOf", { enumerable: true, get: function () { return join_1.dispositionOf; } });
13
13
  Object.defineProperty(exports, "sessionOf", { enumerable: true, get: function () { return join_1.sessionOf; } });
14
14
  Object.defineProperty(exports, "repositoryKey", { enumerable: true, get: function () { return join_1.repositoryKey; } });
15
+ Object.defineProperty(exports, "parseTraceRef", { enumerable: true, get: function () { return join_1.parseTraceRef; } });
16
+ Object.defineProperty(exports, "repositoriesOfRecord", { enumerable: true, get: function () { return join_1.repositoriesOfRecord; } });
17
+ Object.defineProperty(exports, "capabilityKey", { enumerable: true, get: function () { return join_1.capabilityKey; } });
18
+ Object.defineProperty(exports, "capabilitySessions", { enumerable: true, get: function () { return join_1.capabilitySessions; } });
15
19
  Object.defineProperty(exports, "sessionsByRepository", { enumerable: true, get: function () { return join_1.sessionsByRepository; } });
16
20
  Object.defineProperty(exports, "repositoryView", { enumerable: true, get: function () { return join_1.repositoryView; } });
17
21
  Object.defineProperty(exports, "listRepositories", { enumerable: true, get: function () { return join_1.listRepositories; } });
@@ -80,3 +84,9 @@ Object.defineProperty(exports, "readWhere", { enumerable: true, get: function ()
80
84
  Object.defineProperty(exports, "readPackages", { enumerable: true, get: function () { return read_1.readPackages; } });
81
85
  Object.defineProperty(exports, "repositoryImpact", { enumerable: true, get: function () { return read_1.repositoryImpact; } });
82
86
  Object.defineProperty(exports, "findCapability", { enumerable: true, get: function () { return read_1.findCapability; } });
87
+ var commit_1 = require("./commit");
88
+ Object.defineProperty(exports, "capabilitiesOfCommit", { enumerable: true, get: function () { return commit_1.capabilitiesOfCommit; } });
89
+ Object.defineProperty(exports, "changedCapabilities", { enumerable: true, get: function () { return commit_1.changedCapabilities; } });
90
+ Object.defineProperty(exports, "changesOnlyVersions", { enumerable: true, get: function () { return commit_1.changesOnlyVersions; } });
91
+ Object.defineProperty(exports, "remoteRepository", { enumerable: true, get: function () { return commit_1.remoteRepository; } });
92
+ Object.defineProperty(exports, "CommitReadError", { enumerable: true, get: function () { return commit_1.CommitReadError; } });
package/dist/join.d.ts CHANGED
@@ -9,9 +9,24 @@ export declare function dayOf(date: string | undefined): string | undefined;
9
9
  /** `team_fit.team.id` first: it is measured at inventory time and includes a team set later. Then `team`. */
10
10
  export declare function teamOf(snapshot: InventorySnapshot): string | undefined;
11
11
  export declare function dispositionOf(snapshot: InventorySnapshot): RepositorySession["disposition"];
12
- export declare function sessionOf(sessionId: string, snapshot: InventorySnapshot): RepositorySession;
12
+ export declare function sessionOf(sessionId: string, snapshot: InventorySnapshot, commits?: readonly string[]): RepositorySession;
13
13
  /** `owner/name`, case-folded, of a record's `repo`, or undefined when it names no repository. */
14
14
  export declare function repositoryKey(repo: string | undefined): string | undefined;
15
+ /** One `links.trace` ref, `owner/name@sha`: its repository as written and the commit. Undefined for any other ref. */
16
+ export declare function parseTraceRef(ref: string): {
17
+ repository: string;
18
+ key: string;
19
+ sha: string;
20
+ } | undefined;
21
+ /**
22
+ * The repositories a record names, case-folded, each with the commits its
23
+ * `links.trace` holds there: its `repo` first (with no commit when the trace
24
+ * names none in it), then every other repository the trace names.
25
+ */
26
+ export declare function repositoriesOfRecord(snapshot: InventorySnapshot): Map<string, {
27
+ spelled: string;
28
+ commits: string[];
29
+ }>;
15
30
  export interface SessionsByRepository {
16
31
  /** case-folded owner/name → its sessions, newest first */
17
32
  sessions: Map<string, RepositorySession[]>;
@@ -21,6 +36,18 @@ export interface SessionsByRepository {
21
36
  withoutRepo: number;
22
37
  }
23
38
  export declare function sessionsByRepository(records: ReadonlyMap<string, InventorySnapshot>): SessionsByRepository;
39
+ /** A capability address without its scheme, owner and repository case-folded: `miadi-capability:` and `miadi-capability://` read the same. */
40
+ export declare function capabilityKey(address: string): string | undefined;
41
+ /** One session whose record says what it did with a capability. */
42
+ export interface CapabilitySession extends RepositorySession {
43
+ /** uses, revises or brings-into-being, as the record writes it */
44
+ relation?: string;
45
+ version?: string;
46
+ /** the record's evidence for it: commits, issues, npm versions */
47
+ capability_evidence?: string[];
48
+ }
49
+ /** The sessions whose record's `capabilities[]` names this capability, newest first. */
50
+ export declare function capabilitySessions(address: string, records: ReadonlyMap<string, InventorySnapshot>): CapabilitySession[];
24
51
  /**
25
52
  * One repository: its rows when a hub holds them, its sessions, and its
26
53
  * lineage. Undefined when no hub, no record and no lineage names it.
package/dist/join.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  // The join, pure: inventory records grouped by the repository they name, and a
3
- // repository's mapping rows beside its sessions. The key is the record's
4
- // `repo` (owner/name), case-folded, matched to repository:<owner>/<name>:
3
+ // repository's mapping rows beside its sessions. The keys are the record's
4
+ // `repo` (owner/name) and the repository of each commit its `links.trace`
5
+ // names (owner/name@sha), case-folded, matched to repository:<owner>/<name>:
5
6
  // GitHub names are case-insensitive, and records write them as they found them.
6
7
  Object.defineProperty(exports, "__esModule", { value: true });
7
8
  exports.dayOf = dayOf;
@@ -9,7 +10,11 @@ exports.teamOf = teamOf;
9
10
  exports.dispositionOf = dispositionOf;
10
11
  exports.sessionOf = sessionOf;
11
12
  exports.repositoryKey = repositoryKey;
13
+ exports.parseTraceRef = parseTraceRef;
14
+ exports.repositoriesOfRecord = repositoriesOfRecord;
12
15
  exports.sessionsByRepository = sessionsByRepository;
16
+ exports.capabilityKey = capabilityKey;
17
+ exports.capabilitySessions = capabilitySessions;
13
18
  exports.repositoryView = repositoryView;
14
19
  exports.listRepositories = listRepositories;
15
20
  const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
@@ -33,7 +38,7 @@ function dispositionOf(snapshot) {
33
38
  const decided = text(d?.decided);
34
39
  return proposed || decided ? { ...(proposed ? { proposed } : {}), ...(decided ? { decided } : {}) } : undefined;
35
40
  }
36
- function sessionOf(sessionId, snapshot) {
41
+ function sessionOf(sessionId, snapshot, commits = []) {
37
42
  const team = teamOf(snapshot);
38
43
  const disposition = dispositionOf(snapshot);
39
44
  const date = dayOf(snapshot.date);
@@ -52,6 +57,7 @@ function sessionOf(sessionId, snapshot) {
52
57
  ...(disposition ? { disposition } : {}),
53
58
  ...(snapshot.evidence?.length ? { evidence: snapshot.evidence } : {}),
54
59
  ...(episode ? { episode } : {}),
60
+ ...(commits.length ? { commits: [...commits] } : {}),
55
61
  modified_at: snapshot.modified_at,
56
62
  };
57
63
  }
@@ -60,27 +66,80 @@ function repositoryKey(repo) {
60
66
  const id = repo ? (0, developer_repository_mapping_1.toRepositoryNodeId)(repo.trim().replace(/\.git$/, "")) : undefined;
61
67
  return id ? id.slice("repository:".length).toLowerCase() : undefined;
62
68
  }
69
+ /** One `links.trace` ref, `owner/name@sha`: its repository as written and the commit. Undefined for any other ref. */
70
+ function parseTraceRef(ref) {
71
+ const m = /^([^\s@]+)@([0-9a-f]{4,40})$/i.exec(ref.trim());
72
+ const key = m ? repositoryKey(m[1]) : undefined;
73
+ return m && key ? { repository: m[1].replace(/\.git$/, ""), key, sha: m[2].toLowerCase() } : undefined;
74
+ }
75
+ /**
76
+ * The repositories a record names, case-folded, each with the commits its
77
+ * `links.trace` holds there: its `repo` first (with no commit when the trace
78
+ * names none in it), then every other repository the trace names.
79
+ */
80
+ function repositoriesOfRecord(snapshot) {
81
+ const out = new Map();
82
+ const own = repositoryKey(snapshot.repo);
83
+ if (own)
84
+ out.set(own, { spelled: snapshot.repo.trim().replace(/\.git$/, ""), commits: [] });
85
+ for (const ref of snapshot.trace ?? []) {
86
+ const t = parseTraceRef(ref);
87
+ if (!t)
88
+ continue;
89
+ const known = out.get(t.key) ?? { spelled: t.repository, commits: [] };
90
+ if (!known.commits.includes(t.sha))
91
+ known.commits.push(t.sha);
92
+ out.set(t.key, known);
93
+ }
94
+ return out;
95
+ }
63
96
  const newestFirst = (a, b) => (b.date ?? "").localeCompare(a.date ?? "") || b.modified_at.localeCompare(a.modified_at);
64
97
  function sessionsByRepository(records) {
65
98
  const sessions = new Map();
66
99
  const spelled = new Map();
67
100
  let withoutRepo = 0;
68
101
  for (const [id, snapshot] of records) {
69
- const key = repositoryKey(snapshot.repo);
70
- if (!key) {
102
+ const repositories = repositoriesOfRecord(snapshot);
103
+ if (!repositories.size) {
71
104
  withoutRepo += 1;
72
105
  continue;
73
106
  }
74
- const list = sessions.get(key) ?? [];
75
- list.push(sessionOf(id, snapshot));
76
- sessions.set(key, list);
77
- if (!spelled.has(key))
78
- spelled.set(key, snapshot.repo.trim().replace(/\.git$/, ""));
107
+ for (const [key, { spelled: name, commits }] of repositories) {
108
+ const list = sessions.get(key) ?? [];
109
+ list.push(sessionOf(id, snapshot, commits));
110
+ sessions.set(key, list);
111
+ if (!spelled.has(key))
112
+ spelled.set(key, name);
113
+ }
79
114
  }
80
115
  for (const list of sessions.values())
81
116
  list.sort(newestFirst);
82
117
  return { sessions, spelled, records: records.size, withoutRepo };
83
118
  }
119
+ /** A capability address without its scheme, owner and repository case-folded: `miadi-capability:` and `miadi-capability://` read the same. */
120
+ function capabilityKey(address) {
121
+ const m = /^miadi-capability:(?:\/\/)?([^/\s]+)\/([^/\s]+)\/(package|cli|skill)\/(.+)$/.exec(address.trim());
122
+ return m ? `${m[1].toLowerCase()}/${m[2].toLowerCase()}/${m[3]}/${m[4]}` : undefined;
123
+ }
124
+ /** The sessions whose record's `capabilities[]` names this capability, newest first. */
125
+ function capabilitySessions(address, records) {
126
+ const key = capabilityKey(address);
127
+ if (!key)
128
+ return [];
129
+ const out = [];
130
+ for (const [id, snapshot] of records) {
131
+ const entry = (snapshot.capabilities ?? []).find((c) => capabilityKey(c.capability) === key);
132
+ if (!entry)
133
+ continue;
134
+ out.push({
135
+ ...sessionOf(id, snapshot),
136
+ ...(entry.relation ? { relation: entry.relation } : {}),
137
+ ...(entry.version ? { version: entry.version } : {}),
138
+ ...(entry.evidence?.length ? { capability_evidence: entry.evidence } : {}),
139
+ });
140
+ }
141
+ return out.sort(newestFirst);
142
+ }
84
143
  const keyOfNode = (nodeId) => nodeId.slice("repository:".length).toLowerCase();
85
144
  /**
86
145
  * One repository: its rows when a hub holds them, its sessions, and its
package/dist/read.d.ts CHANGED
@@ -4,7 +4,7 @@ import { type RepositoryWhere } from "./hosts";
4
4
  import { type CapabilityFacet } from "@medicine-wheel/capabilities";
5
5
  import { type CapabilityKind, type ProvidesEdge } from "./capabilities";
6
6
  import { type MappingIssue, type MergedMapping } from "@medicine-wheel/developer-repository-mapping";
7
- import { type SessionsByRepository } from "./join";
7
+ import { type CapabilitySession, type SessionsByRepository } from "./join";
8
8
  import { type LineageEdge, type LineageGraph, type RepositoryLineage } from "./lineage";
9
9
  import type { HubState, InventoryState, RepositoryListing, RepositoryView } from "./types";
10
10
  type Env = Record<string, string | undefined>;
@@ -99,6 +99,8 @@ export interface CapabilityRecord {
99
99
  /** the capabilities beside it: what a package consumes, what consumes it, the commands it ships, the package a command comes from */
100
100
  related: RelatedCapability[];
101
101
  scans: typeof SHIPPED_CAPABILITIES_SCANS;
102
+ /** with `sessions`: the sessions whose inventory record names it (used, revised, brought into being), newest first */
103
+ sessions?: CapabilitySession[];
102
104
  }
103
105
  /**
104
106
  * The capability an address names (`miadi-capability:<owner>/<repo>/<kind>/<name>`):
@@ -110,7 +112,10 @@ export declare function findCapability(parts: {
110
112
  repo: string;
111
113
  kind: string;
112
114
  name: string;
113
- }, options?: Pick<ReadOptions, "capabilities">): CapabilityRecord | undefined;
115
+ }, options?: Pick<ReadOptions, "capabilities" | "inventory"> & {
116
+ /** read the session inventory for the sessions whose record names it: session data, for the write tier */
117
+ sessions?: boolean;
118
+ }): CapabilityRecord | undefined;
114
119
  export interface LineageRead {
115
120
  /** the files read, in precedence order */
116
121
  from: string[];
package/dist/read.js CHANGED
@@ -176,12 +176,14 @@ function findCapability(parts, options = {}) {
176
176
  if (shipper)
177
177
  related.push({ relation: "shipped-by", kind: "package", name: shipper.name, address: (0, capabilities_2.capabilityAddress)(shipper.repository, "package", shipper.name), ...version(shipper.version) });
178
178
  }
179
+ const address = (0, capabilities_2.capabilityAddress)(provider, kind, c.name);
179
180
  return {
180
- capability: { ...c, kind, address: (0, capabilities_2.capabilityAddress)(provider, kind, c.name) },
181
+ capability: { ...c, kind, address },
181
182
  repository: provider,
182
183
  ...(impact ? { impact } : {}),
183
184
  related,
184
185
  scans: read.scans,
186
+ ...(options.sessions ? { sessions: (0, join_1.capabilitySessions)(address, (0, hooks_interpreter_1.readInventoryRecords)(options.inventory ?? inventoryDir())) } : {}),
185
187
  };
186
188
  }
187
189
  return undefined;
package/dist/types.d.ts CHANGED
@@ -29,6 +29,8 @@ export interface RepositorySession {
29
29
  title?: string;
30
30
  folder?: string;
31
31
  };
32
+ /** the commits its `links.trace` names in this repository, as shas */
33
+ commits?: string[];
32
34
  /** the record file's modification time */
33
35
  modified_at: string;
34
36
  }
@@ -109,7 +111,7 @@ export interface InventoryState {
109
111
  /** the inventory directory read */
110
112
  from: string;
111
113
  records: number;
112
- /** records with no `repo`, or one that is not owner/name: counted, not shown */
114
+ /** records that name no repository (no owner/name `repo`, no `links.trace` commit): counted, not shown */
113
115
  without_repo: number;
114
116
  }
115
117
  export interface RepositoryListing {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/relational-git-repository-mapper",
3
- "version": "0.5.2",
3
+ "version": "0.6.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",
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@medicine-wheel/capabilities": "^0.27.10",
32
32
  "@medicine-wheel/developer-repository-mapping": "^0.27.10",
33
- "@miadi/hooks-interpreter": "^0.9.0",
33
+ "@miadi/hooks-interpreter": "^0.10.0",
34
34
  "zod": "^3.23.0"
35
35
  },
36
36
  "devDependencies": {