@miadi/relational-git-repository-mapper 0.2.0 → 0.4.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 +62 -4
- package/dist/capabilities.d.ts +71 -0
- package/dist/capabilities.js +210 -0
- package/dist/cli.js +139 -7
- package/dist/index.d.ts +6 -1
- package/dist/index.js +32 -1
- package/dist/join.d.ts +7 -5
- package/dist/join.js +25 -9
- package/dist/lineage.d.ts +105 -0
- package/dist/lineage.js +94 -0
- package/dist/read.d.ts +65 -1
- package/dist/read.js +102 -2
- package/dist/scan.d.ts +16 -0
- package/dist/scan.js +65 -0
- package/dist/shipped-capabilities.d.ts +7 -0
- package/dist/shipped-capabilities.js +2371 -0
- package/dist/shipped-lineage.d.ts +2 -0
- package/dist/shipped-lineage.js +15 -0
- package/dist/types.d.ts +11 -0
- package/package.json +7 -3
package/dist/join.js
CHANGED
|
@@ -13,6 +13,8 @@ exports.sessionsByRepository = sessionsByRepository;
|
|
|
13
13
|
exports.repositoryView = repositoryView;
|
|
14
14
|
exports.listRepositories = listRepositories;
|
|
15
15
|
const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
|
|
16
|
+
const capabilities_1 = require("./capabilities");
|
|
17
|
+
const lineage_1 = require("./lineage");
|
|
16
18
|
const text = (value) => (typeof value === "string" && value.trim() ? value : undefined);
|
|
17
19
|
/** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
|
|
18
20
|
function dayOf(date) {
|
|
@@ -75,18 +77,21 @@ function sessionsByRepository(records) {
|
|
|
75
77
|
}
|
|
76
78
|
const keyOfNode = (nodeId) => nodeId.slice("repository:".length).toLowerCase();
|
|
77
79
|
/**
|
|
78
|
-
* One repository: its rows when a hub holds them,
|
|
79
|
-
* when
|
|
80
|
+
* One repository: its rows when a hub holds them, its sessions, and its
|
|
81
|
+
* lineage. Undefined when no hub, no record and no lineage names it.
|
|
80
82
|
*/
|
|
81
|
-
function repositoryView(repository, mapping, bySessions, sources = {}) {
|
|
83
|
+
function repositoryView(repository, mapping, bySessions, sources = {}, lineageEdges = [], capabilityRows = []) {
|
|
82
84
|
const key = repositoryKey(repository);
|
|
83
85
|
if (!key)
|
|
84
86
|
return undefined;
|
|
85
87
|
const row = mapping?.repositories.find((r) => keyOfNode(r.nodeId) === key);
|
|
86
88
|
const sessions = bySessions.sessions.get(key) ?? [];
|
|
87
|
-
|
|
89
|
+
const lineage = (0, lineage_1.lineageOf)(key, lineageEdges);
|
|
90
|
+
const named = lineageEdges.flatMap((e) => [e.from, e.to]).find((id) => keyOfNode(id) === key) ??
|
|
91
|
+
capabilityRows.flatMap((c) => c.providedBy).find((id) => id.startsWith("repository:") && keyOfNode(id) === key);
|
|
92
|
+
if (!row && !sessions.length && !named)
|
|
88
93
|
return undefined;
|
|
89
|
-
const nodeId = row?.nodeId ?? `repository:${bySessions.spelled.get(key) ?? key}`;
|
|
94
|
+
const nodeId = row?.nodeId ?? named ?? `repository:${bySessions.spelled.get(key) ?? key}`;
|
|
90
95
|
const { owner, name } = (0, developer_repository_mapping_1.parseRepositoryNodeId)(nodeId);
|
|
91
96
|
return {
|
|
92
97
|
nodeId,
|
|
@@ -99,14 +104,24 @@ function repositoryView(repository, mapping, bySessions, sources = {}) {
|
|
|
99
104
|
features: row ? mapping.features.filter((f) => f.repository === row.nodeId) : [],
|
|
100
105
|
relations: row ? mapping.relations.filter((r) => r.from === row.nodeId || r.to === row.nodeId) : [],
|
|
101
106
|
sessions,
|
|
107
|
+
lineage,
|
|
108
|
+
capabilities: (0, capabilities_1.capabilitiesOf)(nodeId, capabilityRows).map((c) => {
|
|
109
|
+
const kind = (0, capabilities_1.kindOf)(c.nodeId);
|
|
110
|
+
return kind ? { ...c, kind } : { ...c };
|
|
111
|
+
}),
|
|
102
112
|
};
|
|
103
113
|
}
|
|
104
|
-
/** Every repository a hub holds or a
|
|
105
|
-
function listRepositories(mapping, bySessions) {
|
|
106
|
-
const keys = new Set([
|
|
114
|
+
/** Every repository a hub holds, a record names or a lineage names, most sessions first. */
|
|
115
|
+
function listRepositories(mapping, bySessions, lineageEdges = [], capabilityRows = []) {
|
|
116
|
+
const keys = new Set([
|
|
117
|
+
...bySessions.sessions.keys(),
|
|
118
|
+
...(mapping?.repositories ?? []).map((r) => keyOfNode(r.nodeId)),
|
|
119
|
+
...lineageEdges.flatMap((e) => [keyOfNode(e.from), keyOfNode(e.to)]),
|
|
120
|
+
...capabilityRows.flatMap((c) => c.providedBy.filter((p) => p.startsWith("repository:")).map(keyOfNode)),
|
|
121
|
+
]);
|
|
107
122
|
return [...keys]
|
|
108
123
|
.map((key) => {
|
|
109
|
-
const view = repositoryView(key, mapping, bySessions);
|
|
124
|
+
const view = repositoryView(key, mapping, bySessions, {}, lineageEdges, capabilityRows);
|
|
110
125
|
const teams = [...new Set(view.sessions.flatMap((s) => (s.team ? [s.team] : [])))].sort();
|
|
111
126
|
return {
|
|
112
127
|
nodeId: view.nodeId,
|
|
@@ -116,6 +131,7 @@ function listRepositories(mapping, bySessions) {
|
|
|
116
131
|
...(view.repository ? { lifecycle: view.repository.lifecycle } : {}),
|
|
117
132
|
...(view.reading ? { drift: view.reading.drift } : {}),
|
|
118
133
|
sessions: view.sessions.length,
|
|
134
|
+
capabilities: view.capabilities.length,
|
|
119
135
|
...(view.sessions[0]?.date ? { last_session: view.sessions[0].date } : {}),
|
|
120
136
|
teams,
|
|
121
137
|
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type MappingIssue } from "@medicine-wheel/developer-repository-mapping";
|
|
3
|
+
export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
|
|
4
|
+
statedBy: z.ZodString;
|
|
5
|
+
statedAt: z.ZodString;
|
|
6
|
+
grounding: z.ZodArray<z.ZodString, "many">;
|
|
7
|
+
revision: z.ZodEnum<["pending", "revised", "affirmed"]>;
|
|
8
|
+
revisedBy: z.ZodOptional<z.ZodString>;
|
|
9
|
+
revisedAt: z.ZodOptional<z.ZodString>;
|
|
10
|
+
/** the repository that learned */
|
|
11
|
+
from: z.ZodString;
|
|
12
|
+
/** the repository it learned from */
|
|
13
|
+
to: z.ZodString;
|
|
14
|
+
type: z.ZodLiteral<"learned-from">;
|
|
15
|
+
/** what was learned, at most 55 words */
|
|
16
|
+
description: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
17
|
+
}, "strict", z.ZodTypeAny, {
|
|
18
|
+
revision: "pending" | "revised" | "affirmed";
|
|
19
|
+
from: string;
|
|
20
|
+
to: string;
|
|
21
|
+
type: "learned-from";
|
|
22
|
+
statedBy: string;
|
|
23
|
+
statedAt: string;
|
|
24
|
+
grounding: string[];
|
|
25
|
+
description?: string | undefined;
|
|
26
|
+
revisedBy?: string | undefined;
|
|
27
|
+
revisedAt?: string | undefined;
|
|
28
|
+
}, {
|
|
29
|
+
revision: "pending" | "revised" | "affirmed";
|
|
30
|
+
from: string;
|
|
31
|
+
to: string;
|
|
32
|
+
type: "learned-from";
|
|
33
|
+
statedBy: string;
|
|
34
|
+
statedAt: string;
|
|
35
|
+
grounding: string[];
|
|
36
|
+
description?: string | undefined;
|
|
37
|
+
revisedBy?: string | undefined;
|
|
38
|
+
revisedAt?: string | undefined;
|
|
39
|
+
}>, {
|
|
40
|
+
revision: "pending" | "revised" | "affirmed";
|
|
41
|
+
from: string;
|
|
42
|
+
to: string;
|
|
43
|
+
type: "learned-from";
|
|
44
|
+
statedBy: string;
|
|
45
|
+
statedAt: string;
|
|
46
|
+
grounding: string[];
|
|
47
|
+
description?: string | undefined;
|
|
48
|
+
revisedBy?: string | undefined;
|
|
49
|
+
revisedAt?: string | undefined;
|
|
50
|
+
}, {
|
|
51
|
+
revision: "pending" | "revised" | "affirmed";
|
|
52
|
+
from: string;
|
|
53
|
+
to: string;
|
|
54
|
+
type: "learned-from";
|
|
55
|
+
statedBy: string;
|
|
56
|
+
statedAt: string;
|
|
57
|
+
grounding: string[];
|
|
58
|
+
description?: string | undefined;
|
|
59
|
+
revisedBy?: string | undefined;
|
|
60
|
+
revisedAt?: string | undefined;
|
|
61
|
+
}>;
|
|
62
|
+
/** One `learned-from` row: `from` learned from `to`. */
|
|
63
|
+
export type LineageRow = z.infer<typeof LineageRowSchema>;
|
|
64
|
+
/** A lineage row and the file it was read from. */
|
|
65
|
+
export interface LineageEdge extends LineageRow {
|
|
66
|
+
source: string;
|
|
67
|
+
}
|
|
68
|
+
/** One end of a lineage, seen from a repository. */
|
|
69
|
+
export interface LineageLink {
|
|
70
|
+
/** the other repository */
|
|
71
|
+
repository: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
statedBy: string;
|
|
74
|
+
statedAt: string;
|
|
75
|
+
grounding: string[];
|
|
76
|
+
revision: LineageRow["revision"];
|
|
77
|
+
source: string;
|
|
78
|
+
}
|
|
79
|
+
export interface RepositoryLineage {
|
|
80
|
+
/** what this repository learned from */
|
|
81
|
+
learned_from: LineageLink[];
|
|
82
|
+
/** the repositories that learned from this one */
|
|
83
|
+
taught: LineageLink[];
|
|
84
|
+
}
|
|
85
|
+
export interface LineageGraph {
|
|
86
|
+
/** every repository a lineage names, sorted */
|
|
87
|
+
nodes: string[];
|
|
88
|
+
edges: LineageEdge[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Lineage rows from several JSONL texts, in precedence order: the first text
|
|
92
|
+
* that names a pair speaks for it, and a later row on the same pair is
|
|
93
|
+
* reported and skipped. Never throws.
|
|
94
|
+
*/
|
|
95
|
+
export declare function parseLineage(texts: readonly {
|
|
96
|
+
text: string;
|
|
97
|
+
source: string;
|
|
98
|
+
}[]): {
|
|
99
|
+
edges: LineageEdge[];
|
|
100
|
+
issues: MappingIssue[];
|
|
101
|
+
};
|
|
102
|
+
/** What a repository learned from, and who learned from it. Matched case-folded. */
|
|
103
|
+
export declare function lineageOf(repository: string, edges: readonly LineageEdge[]): RepositoryLineage;
|
|
104
|
+
/** The whole forest: every repository a lineage names, and every edge. */
|
|
105
|
+
export declare function lineageGraph(edges: readonly LineageEdge[]): LineageGraph;
|
package/dist/lineage.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Lineage, pure: which git repository learned from which.
|
|
3
|
+
//
|
|
4
|
+
// A lineage is not a dependency. A repository that learned from another
|
|
5
|
+
// may import nothing from it: it took what the other explored and carries it
|
|
6
|
+
// on its own, sometimes with another way of knowing. A dependency is
|
|
7
|
+
// `consumes` in an owner hub's relations; a lineage is `learned-from`, here.
|
|
8
|
+
// William, screenwalk 2610221013 (Episode 297, V5 and V6): a forest of trees
|
|
9
|
+
// that grew independently of each other, influenced into their relationship,
|
|
10
|
+
// as a graph a model can navigate.
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LineageRowSchema = void 0;
|
|
13
|
+
exports.parseLineage = parseLineage;
|
|
14
|
+
exports.lineageOf = lineageOf;
|
|
15
|
+
exports.lineageGraph = lineageGraph;
|
|
16
|
+
const zod_1 = require("zod");
|
|
17
|
+
const capabilities_1 = require("@medicine-wheel/capabilities");
|
|
18
|
+
const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
|
|
19
|
+
exports.LineageRowSchema = zod_1.z
|
|
20
|
+
.object({
|
|
21
|
+
/** the repository that learned */
|
|
22
|
+
from: developer_repository_mapping_1.RepositoryNodeIdSchema,
|
|
23
|
+
/** the repository it learned from */
|
|
24
|
+
to: developer_repository_mapping_1.RepositoryNodeIdSchema,
|
|
25
|
+
type: zod_1.z.literal("learned-from"),
|
|
26
|
+
/** what was learned, at most 55 words */
|
|
27
|
+
description: capabilities_1.StatementSchema.optional(),
|
|
28
|
+
...capabilities_1.attributionShape,
|
|
29
|
+
})
|
|
30
|
+
.strict()
|
|
31
|
+
.superRefine((row, ctx) => {
|
|
32
|
+
(0, capabilities_1.refineAttribution)(row, ctx);
|
|
33
|
+
if (row.from.toLowerCase() === row.to.toLowerCase()) {
|
|
34
|
+
ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ["to"], message: "a repository does not learn from itself" });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const fold = (id) => id.toLowerCase();
|
|
38
|
+
const edgeKey = (row) => `${fold(row.from)} ${fold(row.to)}`;
|
|
39
|
+
/**
|
|
40
|
+
* Lineage rows from several JSONL texts, in precedence order: the first text
|
|
41
|
+
* that names a pair speaks for it, and a later row on the same pair is
|
|
42
|
+
* reported and skipped. Never throws.
|
|
43
|
+
*/
|
|
44
|
+
function parseLineage(texts) {
|
|
45
|
+
const edges = [];
|
|
46
|
+
const issues = [];
|
|
47
|
+
const seen = new Map();
|
|
48
|
+
for (const { text, source } of texts) {
|
|
49
|
+
const parsed = (0, developer_repository_mapping_1.parseJsonl)(text, exports.LineageRowSchema, source);
|
|
50
|
+
issues.push(...parsed.issues);
|
|
51
|
+
for (const row of parsed.rows) {
|
|
52
|
+
const key = edgeKey(row);
|
|
53
|
+
const earlier = seen.get(key);
|
|
54
|
+
if (earlier) {
|
|
55
|
+
issues.push({ severity: "warning", file: source, nodeId: row.from, message: `${row.from} learned-from ${row.to} is already read from ${earlier}; skipped` });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
seen.set(key, source);
|
|
59
|
+
edges.push({ ...row, source });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { edges, issues };
|
|
63
|
+
}
|
|
64
|
+
const linkOf = (edge, repository) => ({
|
|
65
|
+
repository,
|
|
66
|
+
...(edge.description ? { description: edge.description } : {}),
|
|
67
|
+
statedBy: edge.statedBy,
|
|
68
|
+
statedAt: edge.statedAt,
|
|
69
|
+
grounding: edge.grounding,
|
|
70
|
+
revision: edge.revision,
|
|
71
|
+
source: edge.source,
|
|
72
|
+
});
|
|
73
|
+
/** What a repository learned from, and who learned from it. Matched case-folded. */
|
|
74
|
+
function lineageOf(repository, edges) {
|
|
75
|
+
const id = fold(repository.startsWith("repository:") ? repository : `repository:${repository}`);
|
|
76
|
+
const byRepository = (a, b) => a.repository.toLowerCase().localeCompare(b.repository.toLowerCase());
|
|
77
|
+
return {
|
|
78
|
+
learned_from: edges.filter((e) => fold(e.from) === id).map((e) => linkOf(e, e.to)).sort(byRepository),
|
|
79
|
+
taught: edges.filter((e) => fold(e.to) === id).map((e) => linkOf(e, e.from)).sort(byRepository),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** The whole forest: every repository a lineage names, and every edge. */
|
|
83
|
+
function lineageGraph(edges) {
|
|
84
|
+
const nodes = new Map();
|
|
85
|
+
for (const e of edges) {
|
|
86
|
+
for (const id of [e.from, e.to])
|
|
87
|
+
if (!nodes.has(fold(id)))
|
|
88
|
+
nodes.set(fold(id), id);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
nodes: [...nodes.values()].sort((a, b) => fold(a).localeCompare(fold(b))),
|
|
92
|
+
edges: [...edges],
|
|
93
|
+
};
|
|
94
|
+
}
|
package/dist/read.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SHIPPED_CAPABILITIES_SCANS } from "./shipped-capabilities";
|
|
2
|
+
import { type CapabilityFacet } from "@medicine-wheel/capabilities";
|
|
3
|
+
import { type CapabilityKind, type ProvidesEdge } from "./capabilities";
|
|
4
|
+
import { type MappingIssue, type MergedMapping } from "@medicine-wheel/developer-repository-mapping";
|
|
2
5
|
import { type SessionsByRepository } from "./join";
|
|
6
|
+
import { type LineageEdge, type LineageGraph, type RepositoryLineage } from "./lineage";
|
|
3
7
|
import type { HubState, InventoryState, RepositoryListing, RepositoryView } from "./types";
|
|
4
8
|
type Env = Record<string, string | undefined>;
|
|
5
9
|
/** The witness team's inventory: `MIADI_SESSION_INVENTORY_DIR`, else `~/workspace/.mino/session-inventory`. */
|
|
@@ -11,7 +15,53 @@ export interface ReadOptions {
|
|
|
11
15
|
hub?: string;
|
|
12
16
|
/** inventory directory; default {@link inventoryDir} */
|
|
13
17
|
inventory?: string;
|
|
18
|
+
/** a lineage JSONL read before the shipped one; default `MIADI_REPOSITORY_LINEAGE` */
|
|
19
|
+
lineage?: string;
|
|
20
|
+
/** a capability JSONL read before the shipped rows; default `MIADI_REPOSITORY_CAPABILITIES` */
|
|
21
|
+
capabilities?: string;
|
|
14
22
|
}
|
|
23
|
+
export interface CapabilitiesRead {
|
|
24
|
+
/** the sources read, in precedence order */
|
|
25
|
+
from: string[];
|
|
26
|
+
/** the commits the shipped rows were scanned at */
|
|
27
|
+
scans: typeof SHIPPED_CAPABILITIES_SCANS;
|
|
28
|
+
capabilities: CapabilityFacet[];
|
|
29
|
+
issues: MappingIssue[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The capabilities: a host's own JSONL first (`--capabilities` or
|
|
33
|
+
* `MIADI_REPOSITORY_CAPABILITIES`), then the rows this package ships, scanned
|
|
34
|
+
* from the repositories' default branches. The first source to name a
|
|
35
|
+
* capability speaks for it; a later row on the same id is reported and skipped.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readCapabilities(path?: string | undefined): CapabilitiesRead;
|
|
38
|
+
export interface CapabilitiesAnswer {
|
|
39
|
+
from: string[];
|
|
40
|
+
scans: typeof SHIPPED_CAPABILITIES_SCANS;
|
|
41
|
+
issues: MappingIssue[];
|
|
42
|
+
/** with a repository: the one asked about */
|
|
43
|
+
repository?: string;
|
|
44
|
+
/** how many of each kind */
|
|
45
|
+
counts: Record<CapabilityKind | "other", number>;
|
|
46
|
+
capabilities: (CapabilityFacet & {
|
|
47
|
+
kind?: CapabilityKind;
|
|
48
|
+
})[];
|
|
49
|
+
provides: ProvidesEdge[];
|
|
50
|
+
}
|
|
51
|
+
/** "What does this repository provide?", or with no repository, every capability. Reads no hub and no inventory. */
|
|
52
|
+
export declare function repositoryCapabilities(repository?: string, options?: Pick<ReadOptions, "capabilities">): CapabilitiesAnswer;
|
|
53
|
+
export interface LineageRead {
|
|
54
|
+
/** the files read, in precedence order */
|
|
55
|
+
from: string[];
|
|
56
|
+
edges: LineageEdge[];
|
|
57
|
+
issues: MappingIssue[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The lineage: a host's own file first (`--lineage` or
|
|
61
|
+
* `MIADI_REPOSITORY_LINEAGE`), then the rows this package ships. The first
|
|
62
|
+
* to name a pair speaks for it. A file that cannot be read is reported.
|
|
63
|
+
*/
|
|
64
|
+
export declare function readLineage(path?: string | undefined): LineageRead;
|
|
15
65
|
export declare function readHubState(path: string | undefined): Promise<{
|
|
16
66
|
hub: HubState;
|
|
17
67
|
mapping?: MergedMapping;
|
|
@@ -21,6 +71,8 @@ export interface MapperRead {
|
|
|
21
71
|
mapping?: MergedMapping;
|
|
22
72
|
inventory: InventoryState;
|
|
23
73
|
sessions: SessionsByRepository;
|
|
74
|
+
lineage: LineageRead;
|
|
75
|
+
capabilities: CapabilitiesRead;
|
|
24
76
|
}
|
|
25
77
|
export declare function readMapper(options?: ReadOptions): Promise<MapperRead>;
|
|
26
78
|
export declare function repositoryListing(options?: ReadOptions): Promise<RepositoryListing>;
|
|
@@ -29,4 +81,16 @@ export declare function repositoryDetail(repository: string, options?: ReadOptio
|
|
|
29
81
|
inventory: InventoryState;
|
|
30
82
|
repository?: RepositoryView;
|
|
31
83
|
}>;
|
|
84
|
+
export interface LineageAnswer {
|
|
85
|
+
/** the files the lineage was read from, in precedence order */
|
|
86
|
+
from: string[];
|
|
87
|
+
issues: MappingIssue[];
|
|
88
|
+
/** with a repository: what it learned from and who learned from it */
|
|
89
|
+
repository?: string;
|
|
90
|
+
lineage?: RepositoryLineage;
|
|
91
|
+
/** without one: the whole forest */
|
|
92
|
+
graph?: LineageGraph;
|
|
93
|
+
}
|
|
94
|
+
/** "What did this repository learn from?", or with no repository, every lineage. Reads no hub and no inventory. */
|
|
95
|
+
export declare function repositoryLineage(repository?: string, options?: Pick<ReadOptions, "lineage">): LineageAnswer;
|
|
32
96
|
export {};
|
package/dist/read.js
CHANGED
|
@@ -5,15 +5,26 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.inventoryDir = inventoryDir;
|
|
7
7
|
exports.hubPath = hubPath;
|
|
8
|
+
exports.readCapabilities = readCapabilities;
|
|
9
|
+
exports.repositoryCapabilities = repositoryCapabilities;
|
|
10
|
+
exports.readLineage = readLineage;
|
|
8
11
|
exports.readHubState = readHubState;
|
|
9
12
|
exports.readMapper = readMapper;
|
|
10
13
|
exports.repositoryListing = repositoryListing;
|
|
11
14
|
exports.repositoryDetail = repositoryDetail;
|
|
15
|
+
exports.repositoryLineage = repositoryLineage;
|
|
16
|
+
const node_fs_1 = require("node:fs");
|
|
17
|
+
const shipped_lineage_1 = require("./shipped-lineage");
|
|
18
|
+
const shipped_capabilities_1 = require("./shipped-capabilities");
|
|
19
|
+
const capabilities_1 = require("@medicine-wheel/capabilities");
|
|
20
|
+
const capabilities_2 = require("./capabilities");
|
|
12
21
|
const node_os_1 = require("node:os");
|
|
13
22
|
const node_path_1 = require("node:path");
|
|
14
23
|
const node_1 = require("@medicine-wheel/developer-repository-mapping/node");
|
|
24
|
+
const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
|
|
15
25
|
const hooks_interpreter_1 = require("@miadi/hooks-interpreter");
|
|
16
26
|
const join_1 = require("./join");
|
|
27
|
+
const lineage_1 = require("./lineage");
|
|
17
28
|
/** The witness team's inventory: `MIADI_SESSION_INVENTORY_DIR`, else `~/workspace/.mino/session-inventory`. */
|
|
18
29
|
function inventoryDir(env = process.env) {
|
|
19
30
|
return env.MIADI_SESSION_INVENTORY_DIR?.trim() || (0, node_path_1.join)((0, node_os_1.homedir)(), "workspace", ".mino", "session-inventory");
|
|
@@ -22,6 +33,80 @@ function inventoryDir(env = process.env) {
|
|
|
22
33
|
function hubPath(env = process.env) {
|
|
23
34
|
return env.MIADI_REPOSITORY_MAPPING_HUB?.trim() || undefined;
|
|
24
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* The capabilities: a host's own JSONL first (`--capabilities` or
|
|
38
|
+
* `MIADI_REPOSITORY_CAPABILITIES`), then the rows this package ships, scanned
|
|
39
|
+
* from the repositories' default branches. The first source to name a
|
|
40
|
+
* capability speaks for it; a later row on the same id is reported and skipped.
|
|
41
|
+
*/
|
|
42
|
+
function readCapabilities(path = process.env.MIADI_REPOSITORY_CAPABILITIES?.trim() || undefined) {
|
|
43
|
+
const issues = [];
|
|
44
|
+
const sources = [];
|
|
45
|
+
if (path) {
|
|
46
|
+
try {
|
|
47
|
+
const parsed = (0, developer_repository_mapping_1.parseJsonl)((0, node_fs_1.readFileSync)(path, "utf8"), capabilities_1.CapabilityFacetSchema, path);
|
|
48
|
+
issues.push(...parsed.issues);
|
|
49
|
+
sources.push({ rows: parsed.rows, source: path });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
issues.push({ severity: "error", file: path, message: `capabilities not read: ${error.message}` });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
sources.push({ rows: [...shipped_capabilities_1.SHIPPED_CAPABILITIES], source: shipped_capabilities_1.SHIPPED_CAPABILITIES_SOURCE });
|
|
56
|
+
const capabilities = [];
|
|
57
|
+
const seen = new Map();
|
|
58
|
+
for (const { rows, source } of sources) {
|
|
59
|
+
rows.forEach((row, index) => {
|
|
60
|
+
const parsed = capabilities_1.CapabilityFacetSchema.safeParse(row);
|
|
61
|
+
if (!parsed.success) {
|
|
62
|
+
issues.push({ severity: "error", file: source, line: index + 1, message: parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ") });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const earlier = seen.get(parsed.data.nodeId);
|
|
66
|
+
if (earlier) {
|
|
67
|
+
issues.push({ severity: "warning", file: source, nodeId: parsed.data.nodeId, message: `${parsed.data.nodeId} is already read from ${earlier}; skipped` });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
seen.set(parsed.data.nodeId, source);
|
|
71
|
+
capabilities.push(parsed.data);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return { from: sources.map((s) => s.source), scans: shipped_capabilities_1.SHIPPED_CAPABILITIES_SCANS, capabilities, issues };
|
|
75
|
+
}
|
|
76
|
+
/** "What does this repository provide?", or with no repository, every capability. Reads no hub and no inventory. */
|
|
77
|
+
function repositoryCapabilities(repository, options = {}) {
|
|
78
|
+
const read = readCapabilities(options.capabilities);
|
|
79
|
+
const id = repository ? (repository.startsWith("repository:") ? repository : `repository:${repository}`) : undefined;
|
|
80
|
+
const rows = id ? (0, capabilities_2.capabilitiesOf)(id, read.capabilities) : read.capabilities;
|
|
81
|
+
const counts = { package: 0, cli: 0, skill: 0, other: 0 };
|
|
82
|
+
const capabilities = rows.map((c) => {
|
|
83
|
+
const kind = (0, capabilities_2.kindOf)(c.nodeId);
|
|
84
|
+
counts[kind ?? "other"] += 1;
|
|
85
|
+
return kind ? { ...c, kind } : { ...c };
|
|
86
|
+
});
|
|
87
|
+
const provides = (0, capabilities_2.providesEdges)(rows).filter((e) => !id || e.from.toLowerCase() === id.toLowerCase());
|
|
88
|
+
return { from: read.from, scans: read.scans, issues: read.issues, ...(id ? { repository: id } : {}), counts, capabilities, provides };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The lineage: a host's own file first (`--lineage` or
|
|
92
|
+
* `MIADI_REPOSITORY_LINEAGE`), then the rows this package ships. The first
|
|
93
|
+
* to name a pair speaks for it. A file that cannot be read is reported.
|
|
94
|
+
*/
|
|
95
|
+
function readLineage(path = process.env.MIADI_REPOSITORY_LINEAGE?.trim() || undefined) {
|
|
96
|
+
const texts = [];
|
|
97
|
+
const unread = [];
|
|
98
|
+
if (path) {
|
|
99
|
+
try {
|
|
100
|
+
texts.push({ text: (0, node_fs_1.readFileSync)(path, "utf8"), source: path });
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
unread.push({ severity: "error", file: path, message: `lineage not read: ${error.message}` });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
texts.push({ text: shipped_lineage_1.SHIPPED_LINEAGE_JSONL, source: shipped_lineage_1.SHIPPED_LINEAGE_SOURCE });
|
|
107
|
+
const parsed = (0, lineage_1.parseLineage)(texts);
|
|
108
|
+
return { from: [...(path ? [path] : []), shipped_lineage_1.SHIPPED_LINEAGE_SOURCE], edges: parsed.edges, issues: [...unread, ...parsed.issues] };
|
|
109
|
+
}
|
|
25
110
|
async function readHubState(path) {
|
|
26
111
|
if (!path)
|
|
27
112
|
return { hub: { state: "no-hub", hubs: [], errors: 0, warnings: 0 } };
|
|
@@ -44,14 +129,29 @@ async function readMapper(options = {}) {
|
|
|
44
129
|
...(mapping ? { mapping } : {}),
|
|
45
130
|
inventory: { from, records: sessions.records, without_repo: sessions.withoutRepo },
|
|
46
131
|
sessions,
|
|
132
|
+
lineage: readLineage(options.lineage),
|
|
133
|
+
capabilities: readCapabilities(options.capabilities),
|
|
47
134
|
};
|
|
48
135
|
}
|
|
49
136
|
async function repositoryListing(options = {}) {
|
|
50
137
|
const read = await readMapper(options);
|
|
51
|
-
return {
|
|
138
|
+
return {
|
|
139
|
+
hub: read.hub,
|
|
140
|
+
inventory: read.inventory,
|
|
141
|
+
repositories: (0, join_1.listRepositories)(read.mapping, read.sessions, read.lineage.edges, read.capabilities.capabilities),
|
|
142
|
+
};
|
|
52
143
|
}
|
|
53
144
|
async function repositoryDetail(repository, options = {}) {
|
|
54
145
|
const read = await readMapper(options);
|
|
55
|
-
const view = (0, join_1.repositoryView)(repository, read.mapping, read.sessions, read.mapping?.sources);
|
|
146
|
+
const view = (0, join_1.repositoryView)(repository, read.mapping, read.sessions, read.mapping?.sources, read.lineage.edges, read.capabilities.capabilities);
|
|
56
147
|
return { hub: read.hub, inventory: read.inventory, ...(view ? { repository: view } : {}) };
|
|
57
148
|
}
|
|
149
|
+
/** "What did this repository learn from?", or with no repository, every lineage. Reads no hub and no inventory. */
|
|
150
|
+
function repositoryLineage(repository, options = {}) {
|
|
151
|
+
const read = readLineage(options.lineage);
|
|
152
|
+
const base = { from: read.from, issues: read.issues };
|
|
153
|
+
if (!repository)
|
|
154
|
+
return { ...base, graph: (0, lineage_1.lineageGraph)(read.edges) };
|
|
155
|
+
const id = repository.startsWith("repository:") ? repository : `repository:${repository}`;
|
|
156
|
+
return { ...base, repository: id, lineage: (0, lineage_1.lineageOf)(id, read.edges) };
|
|
157
|
+
}
|
package/dist/scan.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CapabilityFacet } from "@medicine-wheel/capabilities";
|
|
2
|
+
export interface ScanOptions {
|
|
3
|
+
/** the ref to read; default the remote's default branch (`origin/HEAD`), else HEAD */
|
|
4
|
+
ref?: string;
|
|
5
|
+
/** `owner/name` or `repository:owner/name`; default from the `origin` remote */
|
|
6
|
+
repository?: string;
|
|
7
|
+
observedBy: string;
|
|
8
|
+
now?: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface ScanResult {
|
|
11
|
+
repository: string;
|
|
12
|
+
ref: string;
|
|
13
|
+
commit: string;
|
|
14
|
+
capabilities: CapabilityFacet[];
|
|
15
|
+
}
|
|
16
|
+
export declare function scanRepository(clone: string, options: ScanOptions): Promise<ScanResult>;
|
package/dist/scan.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The scan, on Node: a clone's packages, CLIs and skills read at one commit,
|
|
3
|
+
// from git objects, never from the working tree. A clone on another branch
|
|
4
|
+
// or with edits of its own reads the same as a clean one, and every row names
|
|
5
|
+
// the commit it was read at. Read-only: git ls-tree, git show, git rev-parse.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.scanRepository = scanRepository;
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
const node_util_1 = require("node:util");
|
|
10
|
+
const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
|
|
11
|
+
const capabilities_1 = require("./capabilities");
|
|
12
|
+
const run = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
13
|
+
async function git(clone, args) {
|
|
14
|
+
try {
|
|
15
|
+
const { stdout } = await run("git", ["-C", clone, ...args], { maxBuffer: 256 * 1024 * 1024 });
|
|
16
|
+
return stdout;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function scanRepository(clone, options) {
|
|
23
|
+
if ((await git(clone, ["rev-parse", "--git-dir"])) === undefined)
|
|
24
|
+
throw new Error(`not a git clone: ${clone}`);
|
|
25
|
+
const ref = options.ref ?? ((await git(clone, ["rev-parse", "--verify", "-q", "origin/HEAD"])) ? "origin/HEAD" : "HEAD");
|
|
26
|
+
const commit = (await git(clone, ["rev-parse", "--verify", `${ref}^{commit}`]))?.trim();
|
|
27
|
+
if (!commit)
|
|
28
|
+
throw new Error(`${clone}: no commit at ${ref}`);
|
|
29
|
+
let repository = options.repository
|
|
30
|
+
? options.repository.startsWith("repository:") ? options.repository : `repository:${options.repository}`
|
|
31
|
+
: undefined;
|
|
32
|
+
if (!repository) {
|
|
33
|
+
const remote = (0, developer_repository_mapping_1.parseGithubRemote)((await git(clone, ["remote", "get-url", "origin"]))?.trim() ?? "");
|
|
34
|
+
if (!remote)
|
|
35
|
+
throw new Error(`${clone}: origin is not on GitHub; pass --repository owner/name`);
|
|
36
|
+
repository = (0, developer_repository_mapping_1.repositoryNodeId)(remote.owner, remote.name);
|
|
37
|
+
}
|
|
38
|
+
const files = ((await git(clone, ["ls-tree", "-r", "--name-only", commit])) ?? "").split("\n").filter(Boolean);
|
|
39
|
+
const show = (path) => git(clone, ["show", `${commit}:${path}`]);
|
|
40
|
+
const globs = (0, capabilities_1.workspaceGlobs)(await show("package.json"), files.includes("pnpm-workspace.yaml") ? await show("pnpm-workspace.yaml") : undefined);
|
|
41
|
+
const artefacts = [];
|
|
42
|
+
for (const manifest of (0, capabilities_1.packageManifests)(globs, files)) {
|
|
43
|
+
const pkg = (0, capabilities_1.parsePackageJson)((await show(manifest)) ?? "");
|
|
44
|
+
if (!pkg.name)
|
|
45
|
+
continue;
|
|
46
|
+
artefacts.push({ kind: "package", name: pkg.name, ...(pkg.description ? { description: pkg.description } : {}), path: manifest });
|
|
47
|
+
for (const bin of pkg.bins) {
|
|
48
|
+
artefacts.push({ kind: "cli", name: bin, description: `The ${bin} command, shipped by ${pkg.name}.`, path: manifest });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const file of (0, capabilities_1.skillFiles)(files)) {
|
|
52
|
+
const front = (0, capabilities_1.parseSkillFrontMatter)((await show(file)) ?? "");
|
|
53
|
+
const name = front.name ?? file.split("/").slice(-2, -1)[0];
|
|
54
|
+
if (!name)
|
|
55
|
+
continue;
|
|
56
|
+
artefacts.push({ kind: "skill", name, ...(front.description ? { description: front.description } : {}), path: file });
|
|
57
|
+
}
|
|
58
|
+
const observedAt = (options.now ?? new Date()).toISOString();
|
|
59
|
+
return {
|
|
60
|
+
repository,
|
|
61
|
+
ref,
|
|
62
|
+
commit,
|
|
63
|
+
capabilities: (0, capabilities_1.capabilityRows)(artefacts, { repository, commit, observedBy: options.observedBy, observedAt }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const SHIPPED_CAPABILITIES_SOURCE = "@miadi/relational-git-repository-mapper (shipped capabilities)";
|
|
2
|
+
export declare const SHIPPED_CAPABILITIES_SCANS: readonly {
|
|
3
|
+
repository: string;
|
|
4
|
+
commit: string;
|
|
5
|
+
observedAt: string;
|
|
6
|
+
}[];
|
|
7
|
+
export declare const SHIPPED_CAPABILITIES: readonly unknown[];
|