@miadi/relational-git-repository-mapper 0.3.0 → 0.5.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 +67 -0
- package/dist/capabilities.d.ts +74 -0
- package/dist/capabilities.js +221 -0
- package/dist/cli.js +166 -5
- package/dist/hosts.d.ts +56 -0
- package/dist/hosts.js +60 -0
- package/dist/impact.d.ts +89 -0
- package/dist/impact.js +169 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +45 -1
- package/dist/join.d.ts +4 -2
- package/dist/join.js +42 -5
- package/dist/lineage.d.ts +8 -8
- package/dist/read.d.ts +62 -1
- package/dist/read.js +111 -2
- package/dist/scan.d.ts +19 -0
- package/dist/scan.js +76 -0
- package/dist/shipped-capabilities.d.ts +8 -0
- package/dist/shipped-capabilities.js +3586 -0
- package/dist/shipped-hosts.d.ts +2 -0
- package/dist/shipped-hosts.js +190 -0
- package/dist/types.d.ts +36 -1
- package/dist/where.d.ts +11 -0
- package/dist/where.js +85 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -52,6 +52,66 @@ first file to name a pair speaks for it. Each row carries the attribution of
|
|
|
52
52
|
In the app: `GET /api/repositories/lineage[?repository=owner/name]`, and the `lineage`
|
|
53
53
|
field of `GET /api/repositories/{owner}/{name}`, shown as a Lineage card on its page.
|
|
54
54
|
|
|
55
|
+
## Capabilities: what a git repository provides
|
|
56
|
+
|
|
57
|
+
Each repository's packages, CLIs and skills are `capability` nodes of
|
|
58
|
+
`@medicine-wheel/capabilities` (`capability:package-…`, `capability:cli-…`,
|
|
59
|
+
`capability:skill-…`), and the repository `provides` each one.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
miadi-repomap capabilities jgwill/medicine-wheel # what does the medicine wheel provide?
|
|
63
|
+
miadi-repomap capabilities # every capability, and who provides it
|
|
64
|
+
miadi-repomap scan <clone>... --by "<who>" # read a clone's default branch, print JSONL rows
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`scan` reads a repository's default branch (`origin/HEAD`) from git objects, never its
|
|
68
|
+
working tree, so a clone on another branch or with edits of its own reads the same. It reads
|
|
69
|
+
the packages the repository declares (`workspaces`, or `pnpm-workspace.yaml`), each
|
|
70
|
+
package's `bin`, and every `SKILL.md` outside `node_modules` and archives. A statement is the
|
|
71
|
+
file's own description, kept only within 55 words; longer, the row is `needs-resolution`
|
|
72
|
+
without one. Every row names the commit it was read at and stays `pending` until a person
|
|
73
|
+
reads it.
|
|
74
|
+
|
|
75
|
+
The package ships a scan of `jgwill/Miadi` and the three lineages (`avadisabelle/coaia-narrative`,
|
|
76
|
+
`jgwill/coaiajs`, `jgwill/medicine-wheel`), regenerated with
|
|
77
|
+
`node scripts/ship-capabilities.mjs <scan.jsonl> <scan.log> <packages.jsonl>` (and the host readings with `node scripts/ship-hosts.mjs <hosts.jsonl>`). A host's JSONL
|
|
78
|
+
(`--capabilities` or `MIADI_REPOSITORY_CAPABILITIES`) is read first; the first source to name
|
|
79
|
+
a capability speaks for it.
|
|
80
|
+
|
|
81
|
+
In the app: `GET /api/repositories/capabilities[?repository=owner/name]` answers with the
|
|
82
|
+
capabilities and their `provides` edges, `GET /api/repositories/{owner}/{name}` carries them,
|
|
83
|
+
and the repository page's Lineage card lists them by kind.
|
|
84
|
+
|
|
85
|
+
## Where a repository lives
|
|
86
|
+
|
|
87
|
+
A name like `jgwill/episodes` does not say where the repository is. `miadi-repomap where`
|
|
88
|
+
checks each repository the mapper names: on GitHub (with a token from `GH_TOKEN`,
|
|
89
|
+
`GITHUB_TOKEN` or `gh auth token`, so a private one is seen), else as a bare repository on
|
|
90
|
+
this host (`/srv/git`, or `MIADI_HOST_GIT_ROOTS`). Each reading says `github`, `host-git`,
|
|
91
|
+
`missing` (a 404 a token could have seen, and no bare repository) or `unchecked`. Only a
|
|
92
|
+
GitHub repository gets a GitHub link. `list` and the `/repositories` page set the missing
|
|
93
|
+
ones apart: a session record named a repository that does not exist, and the record is what
|
|
94
|
+
needs correcting. The package ships the readings of its last check; a host's own
|
|
95
|
+
(`where --write <file>`, read through `--hosts` or `MIADI_REPOSITORY_HOSTS`) come first.
|
|
96
|
+
|
|
97
|
+
## What a version bump touches
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
miadi-repomap impact @miadi/hooks-interpreter --bump minor
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The scan reads each package's version and the ranges it declares on other packages it
|
|
104
|
+
read, across repositories. `impact` answers what a package consumes (upstream), who
|
|
105
|
+
consumes it, directly and through others (downstream), and with `--bump`, what each direct
|
|
106
|
+
consumer needs: nothing (its range already reaches the new version), a wider range, or a
|
|
107
|
+
new release because `workspace:*` and `workspace:^` publish the version current at the
|
|
108
|
+
time. In the app: `GET /api/repositories/impact?package=…&bump=…`.
|
|
109
|
+
|
|
110
|
+
## Episodes
|
|
111
|
+
|
|
112
|
+
A repository's view lists the episodes its sessions worked in, as their inventory records
|
|
113
|
+
name them (`miadi-chronicle://<number>`), linked to the chronicle page.
|
|
114
|
+
|
|
55
115
|
## Configuration
|
|
56
116
|
|
|
57
117
|
| variable | default | |
|
|
@@ -59,6 +119,9 @@ field of `GET /api/repositories/{owner}/{name}`, shown as a Lineage card on its
|
|
|
59
119
|
| `MIADI_REPOSITORY_MAPPING_HUB` | none | a hub clone (`…/jgwill/jgwill`) or its mapping folder |
|
|
60
120
|
| `MIADI_SESSION_INVENTORY_DIR` | `~/workspace/.mino/session-inventory` | the inventory records |
|
|
61
121
|
| `MIADI_REPOSITORY_LINEAGE` | none | a lineage JSONL read before the shipped rows |
|
|
122
|
+
| `MIADI_REPOSITORY_CAPABILITIES` | none | a capability JSONL read before the shipped rows |
|
|
123
|
+
| `MIADI_REPOSITORY_HOSTS` | none | a where JSONL (`where --write`) read before the shipped readings |
|
|
124
|
+
| `MIADI_HOST_GIT_ROOTS` | `/srv/git` | where `where` looks for bare repositories, colon-separated |
|
|
62
125
|
|
|
63
126
|
## CLI
|
|
64
127
|
|
|
@@ -66,6 +129,10 @@ field of `GET /api/repositories/{owner}/{name}`, shown as a Lineage card on its
|
|
|
66
129
|
miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
|
|
67
130
|
miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
|
|
68
131
|
miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
|
|
132
|
+
miadi-repomap capabilities [<owner/name>] [--capabilities <file>] [--json]
|
|
133
|
+
miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]
|
|
134
|
+
miadi-repomap where [<owner/name>...] [--write <file>] [--json]
|
|
135
|
+
miadi-repomap impact <package> [--bump major|minor|patch] [--json]
|
|
69
136
|
```
|
|
70
137
|
|
|
71
138
|
Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type CapabilityFacet } from "@medicine-wheel/capabilities";
|
|
2
|
+
export type CapabilityKind = "package" | "cli" | "skill";
|
|
3
|
+
export declare const CAPABILITY_KINDS: readonly CapabilityKind[];
|
|
4
|
+
/** `capability:<kind>-<slug>`: `@miadi/inquiry-weave` → `capability:package-miadi-inquiry-weave`. */
|
|
5
|
+
export declare function capabilityId(kind: CapabilityKind, name: string): string;
|
|
6
|
+
/** The kind a capability id names, or undefined for a capability no scan wrote. */
|
|
7
|
+
export declare function kindOf(nodeId: string): CapabilityKind | undefined;
|
|
8
|
+
/** One thing a repository's files say it provides. */
|
|
9
|
+
export interface Artefact {
|
|
10
|
+
kind: CapabilityKind;
|
|
11
|
+
name: string;
|
|
12
|
+
/** what the files say it is, uncut */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** the file that says so, relative to the repository */
|
|
15
|
+
path: string;
|
|
16
|
+
}
|
|
17
|
+
/** The fields of a package.json the scan reads. Never throws: an unreadable manifest has no name. */
|
|
18
|
+
export declare function parsePackageJson(text: string): {
|
|
19
|
+
name?: string;
|
|
20
|
+
version?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
bins: string[];
|
|
23
|
+
/** runtime dependencies (dependencies, peerDependencies, optionalDependencies): name → range */
|
|
24
|
+
dependsOn: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
/** `name` and `description` from a SKILL.md front matter, plain, quoted or folded (`>`, `|`). */
|
|
27
|
+
export declare function parseSkillFrontMatter(text: string): {
|
|
28
|
+
name?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The folders a repository declares as its packages: `workspaces` of the root
|
|
33
|
+
* package.json (an array, or `{ packages }`), else the `packages:` list of
|
|
34
|
+
* pnpm-workspace.yaml. `.` is the root. Only `dir` and `dir/*` are expanded.
|
|
35
|
+
*/
|
|
36
|
+
export declare function workspaceGlobs(rootPackageJson?: string, pnpmWorkspace?: string): string[];
|
|
37
|
+
/** The package.json paths of a repository's declared packages, among the files it holds. */
|
|
38
|
+
export declare function packageManifests(globs: readonly string[], files: readonly string[]): string[];
|
|
39
|
+
/** The SKILL.md files a repository holds, outside dependencies and archives. */
|
|
40
|
+
export declare function skillFiles(files: readonly string[]): string[];
|
|
41
|
+
export interface CapabilityRowContext {
|
|
42
|
+
/** `repository:<owner>/<name>` */
|
|
43
|
+
repository: string;
|
|
44
|
+
/** the commit the files were read at */
|
|
45
|
+
commit: string;
|
|
46
|
+
observedBy: string;
|
|
47
|
+
/** ISO 8601 */
|
|
48
|
+
observedAt: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Capability rows for one repository. One row per id: two files naming the
|
|
52
|
+
* same skill are one capability with both files as its grounding.
|
|
53
|
+
*/
|
|
54
|
+
export declare function capabilityRows(artefacts: readonly Artefact[], ctx: CapabilityRowContext): CapabilityFacet[];
|
|
55
|
+
/**
|
|
56
|
+
* Rows from several repositories as one inventory: a capability two
|
|
57
|
+
* repositories provide is one row that both provide, with both files as its
|
|
58
|
+
* grounding. The first row read keeps its name and statement.
|
|
59
|
+
*/
|
|
60
|
+
export declare function mergeCapabilityRows(rows: readonly CapabilityFacet[]): CapabilityFacet[];
|
|
61
|
+
/** One `provides` edge: a repository provides a capability, said by whoever said the capability. */
|
|
62
|
+
export interface ProvidesEdge {
|
|
63
|
+
from: string;
|
|
64
|
+
to: string;
|
|
65
|
+
type: "provides";
|
|
66
|
+
statedBy: string;
|
|
67
|
+
statedAt: string;
|
|
68
|
+
grounding: string[];
|
|
69
|
+
revision: CapabilityFacet["revision"];
|
|
70
|
+
}
|
|
71
|
+
/** The `provides` edges a set of capability rows holds, one per provider. */
|
|
72
|
+
export declare function providesEdges(capabilities: readonly CapabilityFacet[]): ProvidesEdge[];
|
|
73
|
+
/** The capabilities a repository provides, matched case-folded, by kind then id. */
|
|
74
|
+
export declare function capabilitiesOf(repository: string, capabilities: readonly CapabilityFacet[]): CapabilityFacet[];
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Capabilities, pure: what a git repository provides, read from its own files.
|
|
3
|
+
// Its packages (package.json), its CLIs (a package's `bin`) and its skills
|
|
4
|
+
// (SKILL.md) become `capability` nodes of @medicine-wheel/capabilities, and the
|
|
5
|
+
// repository `provides` each one. A row states what the files say, never what
|
|
6
|
+
// a model guesses: a description over 55 words is not cut, the row is
|
|
7
|
+
// `needs-resolution` without a statement. Every row is pending until a person
|
|
8
|
+
// reads it.
|
|
9
|
+
// Lane K7c (William, review d04556fd: "inventory and organize capabilities,
|
|
10
|
+
// repositories and recently missions related sessions").
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CAPABILITY_KINDS = void 0;
|
|
13
|
+
exports.capabilityId = capabilityId;
|
|
14
|
+
exports.kindOf = kindOf;
|
|
15
|
+
exports.parsePackageJson = parsePackageJson;
|
|
16
|
+
exports.parseSkillFrontMatter = parseSkillFrontMatter;
|
|
17
|
+
exports.workspaceGlobs = workspaceGlobs;
|
|
18
|
+
exports.packageManifests = packageManifests;
|
|
19
|
+
exports.skillFiles = skillFiles;
|
|
20
|
+
exports.capabilityRows = capabilityRows;
|
|
21
|
+
exports.mergeCapabilityRows = mergeCapabilityRows;
|
|
22
|
+
exports.providesEdges = providesEdges;
|
|
23
|
+
exports.capabilitiesOf = capabilitiesOf;
|
|
24
|
+
const capabilities_1 = require("@medicine-wheel/capabilities");
|
|
25
|
+
exports.CAPABILITY_KINDS = ["package", "cli", "skill"];
|
|
26
|
+
const slug = (value) => value
|
|
27
|
+
.toLowerCase()
|
|
28
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
29
|
+
.replace(/^-+|-+$/g, "");
|
|
30
|
+
/** `capability:<kind>-<slug>`: `@miadi/inquiry-weave` → `capability:package-miadi-inquiry-weave`. */
|
|
31
|
+
function capabilityId(kind, name) {
|
|
32
|
+
return `capability:${kind}-${slug(name)}`;
|
|
33
|
+
}
|
|
34
|
+
/** The kind a capability id names, or undefined for a capability no scan wrote. */
|
|
35
|
+
function kindOf(nodeId) {
|
|
36
|
+
const m = /^capability:(package|cli|skill)-/.exec(nodeId);
|
|
37
|
+
return m ? m[1] : undefined;
|
|
38
|
+
}
|
|
39
|
+
/** The fields of a package.json the scan reads. Never throws: an unreadable manifest has no name. */
|
|
40
|
+
function parsePackageJson(text) {
|
|
41
|
+
try {
|
|
42
|
+
const p = JSON.parse(text);
|
|
43
|
+
const str = (v) => (typeof v === "string" && v.trim() ? v.trim() : undefined);
|
|
44
|
+
const name = str(p.name);
|
|
45
|
+
const version = str(p.version);
|
|
46
|
+
const description = str(p.description);
|
|
47
|
+
let bins = [];
|
|
48
|
+
if (typeof p.bin === "string" && name)
|
|
49
|
+
bins = [name.replace(/^@[^/]+\//, "")];
|
|
50
|
+
else if (p.bin && typeof p.bin === "object")
|
|
51
|
+
bins = Object.keys(p.bin);
|
|
52
|
+
const dependsOn = {};
|
|
53
|
+
for (const key of ["optionalDependencies", "peerDependencies", "dependencies"]) {
|
|
54
|
+
const deps = p[key];
|
|
55
|
+
if (deps && typeof deps === "object") {
|
|
56
|
+
for (const [dep, range] of Object.entries(deps))
|
|
57
|
+
if (typeof range === "string")
|
|
58
|
+
dependsOn[dep] = range;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { ...(name ? { name } : {}), ...(version ? { version } : {}), ...(description ? { description } : {}), bins, dependsOn };
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return { bins: [], dependsOn: {} };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** `name` and `description` from a SKILL.md front matter, plain, quoted or folded (`>`, `|`). */
|
|
68
|
+
function parseSkillFrontMatter(text) {
|
|
69
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
|
|
70
|
+
if (!m)
|
|
71
|
+
return {};
|
|
72
|
+
const lines = m[1].split(/\r?\n/);
|
|
73
|
+
const field = (key) => {
|
|
74
|
+
const i = lines.findIndex((l) => new RegExp(`^${key}:`).test(l));
|
|
75
|
+
if (i < 0)
|
|
76
|
+
return undefined;
|
|
77
|
+
let value = lines[i].slice(key.length + 1).trim();
|
|
78
|
+
if (/^[>|][+-]?$/.test(value)) {
|
|
79
|
+
const folded = [];
|
|
80
|
+
for (const l of lines.slice(i + 1)) {
|
|
81
|
+
if (/^\S/.test(l))
|
|
82
|
+
break;
|
|
83
|
+
folded.push(l.trim());
|
|
84
|
+
}
|
|
85
|
+
value = folded.join(" ").trim();
|
|
86
|
+
}
|
|
87
|
+
value = value.replace(/^(["'])([\s\S]*)\1$/, "$2").trim();
|
|
88
|
+
return value || undefined;
|
|
89
|
+
};
|
|
90
|
+
const name = field("name");
|
|
91
|
+
const description = field("description");
|
|
92
|
+
return { ...(name ? { name } : {}), ...(description ? { description } : {}) };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The folders a repository declares as its packages: `workspaces` of the root
|
|
96
|
+
* package.json (an array, or `{ packages }`), else the `packages:` list of
|
|
97
|
+
* pnpm-workspace.yaml. `.` is the root. Only `dir` and `dir/*` are expanded.
|
|
98
|
+
*/
|
|
99
|
+
function workspaceGlobs(rootPackageJson, pnpmWorkspace) {
|
|
100
|
+
try {
|
|
101
|
+
const root = rootPackageJson ? JSON.parse(rootPackageJson) : {};
|
|
102
|
+
const w = root.workspaces;
|
|
103
|
+
const list = Array.isArray(w) ? w : w && typeof w === "object" ? w.packages : undefined;
|
|
104
|
+
if (Array.isArray(list) && list.length)
|
|
105
|
+
return [".", ...list.filter((x) => typeof x === "string")];
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// an unreadable root manifest declares nothing
|
|
109
|
+
}
|
|
110
|
+
if (pnpmWorkspace) {
|
|
111
|
+
const block = /(^|\n)packages:\s*\n((?:[ \t]+-[^\n]*\n?)+)/.exec(pnpmWorkspace);
|
|
112
|
+
if (block) {
|
|
113
|
+
return block[2]
|
|
114
|
+
.split("\n")
|
|
115
|
+
.map((l) => l.replace(/^[ \t]+-\s*/, "").replace(/\s+#.*$/, "").replace(/^['"]|['"]$/g, "").trim())
|
|
116
|
+
.filter(Boolean);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return ["."];
|
|
120
|
+
}
|
|
121
|
+
/** The package.json paths of a repository's declared packages, among the files it holds. */
|
|
122
|
+
function packageManifests(globs, files) {
|
|
123
|
+
const manifests = new Set();
|
|
124
|
+
const held = new Set(files);
|
|
125
|
+
for (const glob of globs) {
|
|
126
|
+
const dir = glob.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
127
|
+
if (dir === "." || dir === "") {
|
|
128
|
+
if (held.has("package.json"))
|
|
129
|
+
manifests.add("package.json");
|
|
130
|
+
}
|
|
131
|
+
else if (dir.endsWith("/*")) {
|
|
132
|
+
const base = `${dir.slice(0, -2)}/`;
|
|
133
|
+
for (const f of files) {
|
|
134
|
+
const rest = f.startsWith(base) ? f.slice(base.length) : "";
|
|
135
|
+
if (/^[^/]+\/package\.json$/.test(rest))
|
|
136
|
+
manifests.add(f);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (held.has(`${dir}/package.json`)) {
|
|
140
|
+
manifests.add(`${dir}/package.json`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return [...manifests].sort();
|
|
144
|
+
}
|
|
145
|
+
/** The SKILL.md files a repository holds, outside dependencies and archives. */
|
|
146
|
+
function skillFiles(files) {
|
|
147
|
+
return files
|
|
148
|
+
.filter((f) => /(^|\/)SKILL\.md$/.test(f))
|
|
149
|
+
.filter((f) => !/(^|\/)(node_modules|archives?|archived-[^/]*|dist|\.next)\//.test(f))
|
|
150
|
+
.sort();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Capability rows for one repository. One row per id: two files naming the
|
|
154
|
+
* same skill are one capability with both files as its grounding.
|
|
155
|
+
*/
|
|
156
|
+
function capabilityRows(artefacts, ctx) {
|
|
157
|
+
const where = `${ctx.repository.replace(/^repository:/, "")}@${ctx.commit.slice(0, 12)}`;
|
|
158
|
+
const rows = new Map();
|
|
159
|
+
for (const a of artefacts) {
|
|
160
|
+
const nodeId = capabilityId(a.kind, a.name);
|
|
161
|
+
const grounding = `${where}:${a.path}`;
|
|
162
|
+
const existing = rows.get(nodeId);
|
|
163
|
+
if (existing) {
|
|
164
|
+
if (!existing.grounding.includes(grounding))
|
|
165
|
+
existing.grounding.push(grounding);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const fits = a.description ? (0, capabilities_1.checkStatement)(a.description).fits : false;
|
|
169
|
+
rows.set(nodeId, {
|
|
170
|
+
nodeId,
|
|
171
|
+
name: a.name,
|
|
172
|
+
...(fits ? { statement: a.description } : {}),
|
|
173
|
+
status: fits ? "clear" : "needs-resolution",
|
|
174
|
+
providedBy: [ctx.repository],
|
|
175
|
+
statedBy: ctx.observedBy,
|
|
176
|
+
statedAt: ctx.observedAt,
|
|
177
|
+
grounding: [grounding],
|
|
178
|
+
revision: "pending",
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return [...rows.values()];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Rows from several repositories as one inventory: a capability two
|
|
185
|
+
* repositories provide is one row that both provide, with both files as its
|
|
186
|
+
* grounding. The first row read keeps its name and statement.
|
|
187
|
+
*/
|
|
188
|
+
function mergeCapabilityRows(rows) {
|
|
189
|
+
const merged = new Map();
|
|
190
|
+
for (const row of rows) {
|
|
191
|
+
const existing = merged.get(row.nodeId);
|
|
192
|
+
if (!existing) {
|
|
193
|
+
merged.set(row.nodeId, { ...row, providedBy: [...row.providedBy], grounding: [...row.grounding] });
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
for (const p of row.providedBy)
|
|
197
|
+
if (!existing.providedBy.includes(p))
|
|
198
|
+
existing.providedBy.push(p);
|
|
199
|
+
for (const g of row.grounding)
|
|
200
|
+
if (!existing.grounding.includes(g))
|
|
201
|
+
existing.grounding.push(g);
|
|
202
|
+
}
|
|
203
|
+
return [...merged.values()].sort((a, b) => (a.nodeId < b.nodeId ? -1 : a.nodeId > b.nodeId ? 1 : 0));
|
|
204
|
+
}
|
|
205
|
+
/** The `provides` edges a set of capability rows holds, one per provider. */
|
|
206
|
+
function providesEdges(capabilities) {
|
|
207
|
+
return capabilities.flatMap((c) => c.providedBy.map((from) => ({
|
|
208
|
+
from,
|
|
209
|
+
to: c.nodeId,
|
|
210
|
+
type: "provides",
|
|
211
|
+
statedBy: c.statedBy,
|
|
212
|
+
statedAt: c.statedAt,
|
|
213
|
+
grounding: c.grounding,
|
|
214
|
+
revision: c.revision,
|
|
215
|
+
})));
|
|
216
|
+
}
|
|
217
|
+
/** The capabilities a repository provides, matched case-folded, by kind then id. */
|
|
218
|
+
function capabilitiesOf(repository, capabilities) {
|
|
219
|
+
const id = (repository.startsWith("repository:") ? repository : `repository:${repository}`).toLowerCase();
|
|
220
|
+
return capabilities.filter((c) => c.providedBy.some((p) => p.toLowerCase() === id));
|
|
221
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -5,28 +5,92 @@
|
|
|
5
5
|
// miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
|
|
6
6
|
// miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
|
|
7
7
|
// miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
|
|
8
|
+
// miadi-repomap capabilities [<owner/name>] [--capabilities <file>] [--json]
|
|
9
|
+
// miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]
|
|
10
|
+
// miadi-repomap where [<owner/name>...] [--write <file>] [--json]
|
|
11
|
+
// miadi-repomap impact <package> [--bump major|minor|patch] [--json]
|
|
8
12
|
//
|
|
9
13
|
// `lineage <owner/name>` answers "what did this repository learn from", and
|
|
10
14
|
// who learned from it; with no repository it prints every lineage. A lineage
|
|
11
15
|
// is not a dependency: `learned-from` names what a repository took from
|
|
12
16
|
// another that it carries on its own. --lineage adds a host's JSONL before
|
|
13
17
|
// the rows this package ships (default MIADI_REPOSITORY_LINEAGE).
|
|
18
|
+
//
|
|
19
|
+
// `capabilities <owner/name>` answers what a repository provides: its
|
|
20
|
+
// packages, CLIs and skills as capability nodes, each with a `provides` edge.
|
|
21
|
+
// `scan` reads a clone's default branch from git objects (never its working
|
|
22
|
+
// tree) and prints those rows as JSONL, pending until a person reads them.
|
|
23
|
+
// --capabilities adds a host's JSONL before the shipped rows (default
|
|
24
|
+
// MIADI_REPOSITORY_CAPABILITIES).
|
|
25
|
+
//
|
|
26
|
+
// `where` checks where each repository lives, on GitHub (with a token from
|
|
27
|
+
// GH_TOKEN, GITHUB_TOKEN or `gh auth token`) or as a bare repository on this
|
|
28
|
+
// host (/srv/git, or MIADI_HOST_GIT_ROOTS), for the repositories named or
|
|
29
|
+
// every one the mapper names. `list` sets apart the repositories found
|
|
30
|
+
// nowhere. `impact` answers what bumping a package touches: what it consumes,
|
|
31
|
+
// who consumes it, and which ranges stop reaching the new version.
|
|
14
32
|
// --hub defaults to MIADI_REPOSITORY_MAPPING_HUB (a jgwill/jgwill clone, or a
|
|
15
33
|
// mapping folder); --inventory to MIADI_SESSION_INVENTORY_DIR, else
|
|
16
34
|
// ~/workspace/.mino/session-inventory. Read-only.
|
|
17
35
|
//
|
|
18
36
|
// Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
|
|
37
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
40
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
41
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
42
|
+
}
|
|
43
|
+
Object.defineProperty(o, k2, desc);
|
|
44
|
+
}) : (function(o, m, k, k2) {
|
|
45
|
+
if (k2 === undefined) k2 = k;
|
|
46
|
+
o[k2] = m[k];
|
|
47
|
+
}));
|
|
48
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
49
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
50
|
+
}) : function(o, v) {
|
|
51
|
+
o["default"] = v;
|
|
52
|
+
});
|
|
53
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
54
|
+
var ownKeys = function(o) {
|
|
55
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
56
|
+
var ar = [];
|
|
57
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
58
|
+
return ar;
|
|
59
|
+
};
|
|
60
|
+
return ownKeys(o);
|
|
61
|
+
};
|
|
62
|
+
return function (mod) {
|
|
63
|
+
if (mod && mod.__esModule) return mod;
|
|
64
|
+
var result = {};
|
|
65
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
66
|
+
__setModuleDefault(result, mod);
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
})();
|
|
19
70
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
+
const os = __importStar(require("node:os"));
|
|
72
|
+
const capabilities_1 = require("./capabilities");
|
|
73
|
+
const node_fs_1 = require("node:fs");
|
|
20
74
|
const read_1 = require("./read");
|
|
75
|
+
const where_1 = require("./where");
|
|
76
|
+
const scan_1 = require("./scan");
|
|
21
77
|
const USAGE = [
|
|
22
78
|
"usage: miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
|
|
23
79
|
" miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
|
|
24
80
|
" miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]",
|
|
81
|
+
" miadi-repomap capabilities [<owner/name>] [--capabilities <file>] [--json]",
|
|
82
|
+
" miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]",
|
|
83
|
+
" miadi-repomap where [<owner/name>...] [--write <file>] [--json]",
|
|
84
|
+
" miadi-repomap impact <package> [--bump major|minor|patch] [--json]",
|
|
25
85
|
].join("\n");
|
|
26
86
|
const FLAGS = {
|
|
27
|
-
list: ["hub", "inventory", "lineage", "json"],
|
|
28
|
-
show: ["hub", "inventory", "lineage", "json"],
|
|
87
|
+
list: ["hub", "inventory", "lineage", "capabilities", "hosts", "json"],
|
|
88
|
+
show: ["hub", "inventory", "lineage", "capabilities", "hosts", "json"],
|
|
29
89
|
lineage: ["lineage", "json"],
|
|
90
|
+
capabilities: ["capabilities", "json"],
|
|
91
|
+
scan: ["ref", "repository", "by", "packages"],
|
|
92
|
+
where: ["write", "json", "hub", "inventory", "by"],
|
|
93
|
+
impact: ["bump", "json"],
|
|
30
94
|
};
|
|
31
95
|
class UsageError extends Error {
|
|
32
96
|
}
|
|
@@ -83,7 +147,94 @@ async function main() {
|
|
|
83
147
|
console.log(USAGE);
|
|
84
148
|
return 0;
|
|
85
149
|
}
|
|
86
|
-
const options = {
|
|
150
|
+
const options = {
|
|
151
|
+
hub: value(flags, "hub"),
|
|
152
|
+
inventory: value(flags, "inventory"),
|
|
153
|
+
lineage: value(flags, "lineage"),
|
|
154
|
+
capabilities: value(flags, "capabilities"),
|
|
155
|
+
hosts: value(flags, "hosts"),
|
|
156
|
+
};
|
|
157
|
+
if (command === "where") {
|
|
158
|
+
const named = positional.slice(1);
|
|
159
|
+
const listing = named.length ? undefined : await (0, read_1.repositoryListing)(options);
|
|
160
|
+
const ids = listing ? [...listing.repositories, ...listing.missing].map((r) => r.nodeId) : named;
|
|
161
|
+
const readings = await (0, where_1.checkWhere)(ids, { checkedBy: value(flags, "by") ?? `miadi-repomap where (${os.userInfo().username}@${os.hostname()})` });
|
|
162
|
+
const write = value(flags, "write");
|
|
163
|
+
if (write)
|
|
164
|
+
(0, node_fs_1.writeFileSync)(write, readings.map((r) => JSON.stringify(r)).join("\n") + "\n");
|
|
165
|
+
if (flags.json)
|
|
166
|
+
console.log(JSON.stringify(readings, null, 2));
|
|
167
|
+
else
|
|
168
|
+
for (const r of readings)
|
|
169
|
+
console.log(`${short(r.repository).padEnd(48)} ${r.host.padEnd(10)} ${r.url ?? ""}${r.note ? ` (${r.note})` : ""}`);
|
|
170
|
+
if (write)
|
|
171
|
+
console.error(`${readings.length} readings written to ${write}`);
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
if (command === "impact") {
|
|
175
|
+
if (!positional[1])
|
|
176
|
+
throw new UsageError("impact needs a package: @scope/name or capability:package-…");
|
|
177
|
+
const bump = value(flags, "bump");
|
|
178
|
+
if (bump && !["major", "minor", "patch"].includes(bump))
|
|
179
|
+
throw new UsageError("--bump is major, minor or patch");
|
|
180
|
+
const read = (0, read_1.repositoryImpact)(positional[1], bump);
|
|
181
|
+
if (flags.json) {
|
|
182
|
+
console.log(JSON.stringify(read, null, 2));
|
|
183
|
+
return read.impact ? 0 : 1;
|
|
184
|
+
}
|
|
185
|
+
const i = read.impact;
|
|
186
|
+
if (!i) {
|
|
187
|
+
console.error(`miadi-repomap: ${positional[1]} is not a package the shipped scan read`);
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
const lines = [
|
|
191
|
+
`${i.package.name}${i.package.version ? `@${i.package.version}` : ""} (${short(i.package.repository)})${i.bump ? ` ${i.bump.level} bump → ${i.bump.to}` : ""}`,
|
|
192
|
+
` consumes (${i.consumes.length}):`,
|
|
193
|
+
...i.consumes.map((c) => ` ${c.name}${c.version ? `@${c.version}` : ""} ${c.range} (${short(c.repository)})`),
|
|
194
|
+
` consumed by (${i.consumers.length}):`,
|
|
195
|
+
...i.consumers.map((c) => ` ${" ".repeat(c.depth - 1)}${c.name} ${c.depth === 1 ? c.range : `via ${c.via}`} (${short(c.repository)})${c.action ? ` — ${c.action}` : ""}`),
|
|
196
|
+
];
|
|
197
|
+
console.log(lines.join("\n"));
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
200
|
+
if (command === "scan") {
|
|
201
|
+
const clones = positional.slice(1);
|
|
202
|
+
if (!clones.length)
|
|
203
|
+
throw new UsageError("scan needs at least one clone");
|
|
204
|
+
if (clones.length > 1 && value(flags, "repository"))
|
|
205
|
+
throw new UsageError("--repository names one clone's repository: scan one clone with it");
|
|
206
|
+
const observedBy = value(flags, "by") ?? `miadi-repomap scan (${os.userInfo().username}@${os.hostname()})`;
|
|
207
|
+
const rows = [];
|
|
208
|
+
const packages = [];
|
|
209
|
+
for (const clone of clones) {
|
|
210
|
+
const result = await (0, scan_1.scanRepository)(clone, { ref: value(flags, "ref"), repository: value(flags, "repository"), observedBy });
|
|
211
|
+
console.error(`${result.repository.replace(/^repository:/, "")} @ ${result.commit.slice(0, 12)} (${result.ref}): ${result.capabilities.length} capabilities`);
|
|
212
|
+
rows.push(...result.capabilities);
|
|
213
|
+
packages.push(...result.packages);
|
|
214
|
+
}
|
|
215
|
+
for (const row of (0, capabilities_1.mergeCapabilityRows)(rows))
|
|
216
|
+
console.log(JSON.stringify(row));
|
|
217
|
+
const packagesFile = value(flags, "packages");
|
|
218
|
+
if (packagesFile)
|
|
219
|
+
(0, node_fs_1.writeFileSync)(packagesFile, packages.map((p) => JSON.stringify(p)).join("\n") + "\n");
|
|
220
|
+
return 0;
|
|
221
|
+
}
|
|
222
|
+
if (command === "capabilities") {
|
|
223
|
+
const answer = (0, read_1.repositoryCapabilities)(positional[1], { capabilities: options.capabilities });
|
|
224
|
+
for (const i of answer.issues)
|
|
225
|
+
console.error(`${i.severity} ${i.file ?? ""}${i.line ? `:${i.line}` : ""} — ${i.message}`);
|
|
226
|
+
if (flags.json) {
|
|
227
|
+
console.log(JSON.stringify(answer, null, 2));
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
const subject = answer.repository ? short(answer.repository) : "every repository";
|
|
231
|
+
console.log(`${subject} provides ${answer.capabilities.length}: ${answer.counts.package} packages, ${answer.counts.cli} CLIs, ${answer.counts.skill} skills`);
|
|
232
|
+
for (const c of answer.capabilities) {
|
|
233
|
+
const by = answer.repository ? "" : ` (${c.providedBy.map(short).join(", ")})`;
|
|
234
|
+
console.log(` ${(c.kind ?? "other").padEnd(8)} ${c.name}${by}${c.statement ? ` — ${c.statement}` : ` [${c.status}]`}`);
|
|
235
|
+
}
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
87
238
|
if (command === "lineage") {
|
|
88
239
|
const answer = (0, read_1.repositoryLineage)(positional[1], { lineage: options.lineage });
|
|
89
240
|
for (const i of answer.issues)
|
|
@@ -117,9 +268,14 @@ async function main() {
|
|
|
117
268
|
console.error(hubLine(listing.hub));
|
|
118
269
|
for (const r of listing.repositories) {
|
|
119
270
|
const state = r.mapped ? `${r.lifecycle} · ${r.drift}` : "no mapping yet";
|
|
120
|
-
console.log(`${`${r.owner}/${r.name}`.padEnd(48)} ${String(r.sessions).padStart(4)} sessions ${(r.last_session ?? "").padEnd(10)} ${state.padEnd(24)} ${r.teams.join(",") || "-"}`);
|
|
271
|
+
console.log(`${`${r.owner}/${r.name}`.padEnd(48)} ${r.host.padEnd(10)} ${String(r.sessions).padStart(4)} sessions ${(r.last_session ?? "").padEnd(10)} ${state.padEnd(24)} ${r.teams.join(",") || "-"}`);
|
|
121
272
|
}
|
|
122
273
|
console.error(`${listing.repositories.length} repositories; ${listing.inventory.records} records read from ${listing.inventory.from}, ${listing.inventory.without_repo} without a repo`);
|
|
274
|
+
if (listing.missing.length) {
|
|
275
|
+
console.error(`named by session records but found nowhere (${listing.missing.length}):`);
|
|
276
|
+
for (const r of listing.missing)
|
|
277
|
+
console.error(` ${r.owner}/${r.name} ${r.sessions} sessions`);
|
|
278
|
+
}
|
|
123
279
|
return 0;
|
|
124
280
|
}
|
|
125
281
|
if (command === "show") {
|
|
@@ -136,7 +292,8 @@ async function main() {
|
|
|
136
292
|
return 1;
|
|
137
293
|
}
|
|
138
294
|
const lines = [
|
|
139
|
-
`${r.owner}/${r.name} ${r.url}`,
|
|
295
|
+
`${r.owner}/${r.name} ${r.url ?? r.where.url ?? ""} [${r.where.host}${r.where.private ? ", private" : ""}${r.where.archived ? ", archived" : ""}]`,
|
|
296
|
+
r.where.note ? ` where: ${r.where.note}` : "",
|
|
140
297
|
r.repository
|
|
141
298
|
? ` ${r.repository.lifecycle} · ${r.repository.origin} · ${r.repository.revision}${r.source ? ` · from ${r.source}` : ""}`
|
|
142
299
|
: ` ${hubLine(detail.hub)}`,
|
|
@@ -150,6 +307,10 @@ async function main() {
|
|
|
150
307
|
...linkLines(r.lineage.learned_from),
|
|
151
308
|
r.lineage.taught.length ? ` taught (${r.lineage.taught.length}):` : "",
|
|
152
309
|
...linkLines(r.lineage.taught),
|
|
310
|
+
r.capabilities.length ? ` provides (${r.capabilities.length}):` : "",
|
|
311
|
+
...r.capabilities.map((c) => ` ${(c.kind ?? "other").padEnd(8)} ${c.name}${c.statement ? ` — ${c.statement}` : ` [${c.status}]`}`),
|
|
312
|
+
r.episodes.length ? ` episodes (${r.episodes.length}):` : "",
|
|
313
|
+
...r.episodes.map((e) => ` ${e.number !== undefined ? `miadi-chronicle://${e.number}` : e.folder}${e.title ? ` ${e.title}` : ""} (${e.sessions} sessions)`),
|
|
153
314
|
` sessions (${r.sessions.length}):`,
|
|
154
315
|
...r.sessions.map(sessionLine),
|
|
155
316
|
];
|
package/dist/hosts.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type MappingIssue } from "@medicine-wheel/developer-repository-mapping";
|
|
3
|
+
export declare const RepositoryHostSchema: z.ZodEnum<["github", "host-git", "missing", "unchecked"]>;
|
|
4
|
+
export type RepositoryHost = z.infer<typeof RepositoryHostSchema>;
|
|
5
|
+
export declare const RepositoryWhereSchema: z.ZodObject<{
|
|
6
|
+
repository: z.ZodString;
|
|
7
|
+
host: z.ZodEnum<["github", "host-git", "missing", "unchecked"]>;
|
|
8
|
+
/** github: the web page; host-git: `<host>:<path>` of the bare repository */
|
|
9
|
+
url: z.ZodOptional<z.ZodString>;
|
|
10
|
+
private: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
archived: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
/** why, in a few words: "404 from GitHub with a token, no /srv/git/jgwill/x.git" */
|
|
13
|
+
note: z.ZodOptional<z.ZodString>;
|
|
14
|
+
checkedBy: z.ZodString;
|
|
15
|
+
checkedAt: z.ZodString;
|
|
16
|
+
}, "strict", z.ZodTypeAny, {
|
|
17
|
+
repository: string;
|
|
18
|
+
host: "github" | "host-git" | "missing" | "unchecked";
|
|
19
|
+
checkedBy: string;
|
|
20
|
+
checkedAt: string;
|
|
21
|
+
note?: string | undefined;
|
|
22
|
+
url?: string | undefined;
|
|
23
|
+
private?: boolean | undefined;
|
|
24
|
+
archived?: boolean | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
repository: string;
|
|
27
|
+
host: "github" | "host-git" | "missing" | "unchecked";
|
|
28
|
+
checkedBy: string;
|
|
29
|
+
checkedAt: string;
|
|
30
|
+
note?: string | undefined;
|
|
31
|
+
url?: string | undefined;
|
|
32
|
+
private?: boolean | undefined;
|
|
33
|
+
archived?: boolean | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
export type RepositoryWhere = z.infer<typeof RepositoryWhereSchema>;
|
|
36
|
+
/**
|
|
37
|
+
* Readings from several JSONL texts, in precedence order: the first to name a
|
|
38
|
+
* repository speaks for it. Never throws.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseWhere(texts: readonly {
|
|
41
|
+
text: string;
|
|
42
|
+
source: string;
|
|
43
|
+
}[]): {
|
|
44
|
+
readings: RepositoryWhere[];
|
|
45
|
+
issues: MappingIssue[];
|
|
46
|
+
};
|
|
47
|
+
/** Where a repository lives, or `unchecked` when no reading names it. Matched case-folded. */
|
|
48
|
+
export declare function whereOf(repository: string, readings: readonly RepositoryWhere[]): RepositoryWhere | {
|
|
49
|
+
repository: string;
|
|
50
|
+
host: "unchecked";
|
|
51
|
+
};
|
|
52
|
+
/** The web page of a repository: only GitHub repositories have one here. */
|
|
53
|
+
export declare function webUrlOf(where: {
|
|
54
|
+
host: RepositoryHost;
|
|
55
|
+
url?: string;
|
|
56
|
+
}): string | undefined;
|