@miadi/relational-git-repository-mapper 0.3.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 CHANGED
@@ -52,6 +52,36 @@ 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>`. 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
+
55
85
  ## Configuration
56
86
 
57
87
  | variable | default | |
@@ -59,6 +89,7 @@ field of `GET /api/repositories/{owner}/{name}`, shown as a Lineage card on its
59
89
  | `MIADI_REPOSITORY_MAPPING_HUB` | none | a hub clone (`…/jgwill/jgwill`) or its mapping folder |
60
90
  | `MIADI_SESSION_INVENTORY_DIR` | `~/workspace/.mino/session-inventory` | the inventory records |
61
91
  | `MIADI_REPOSITORY_LINEAGE` | none | a lineage JSONL read before the shipped rows |
92
+ | `MIADI_REPOSITORY_CAPABILITIES` | none | a capability JSONL read before the shipped rows |
62
93
 
63
94
  ## CLI
64
95
 
@@ -66,6 +97,8 @@ field of `GET /api/repositories/{owner}/{name}`, shown as a Lineage card on its
66
97
  miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
67
98
  miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
68
99
  miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
100
+ miadi-repomap capabilities [<owner/name>] [--capabilities <file>] [--json]
101
+ miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>]
69
102
  ```
70
103
 
71
104
  Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
@@ -0,0 +1,71 @@
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
+ description?: string;
21
+ bins: string[];
22
+ };
23
+ /** `name` and `description` from a SKILL.md front matter, plain, quoted or folded (`>`, `|`). */
24
+ export declare function parseSkillFrontMatter(text: string): {
25
+ name?: string;
26
+ description?: string;
27
+ };
28
+ /**
29
+ * The folders a repository declares as its packages: `workspaces` of the root
30
+ * package.json (an array, or `{ packages }`), else the `packages:` list of
31
+ * pnpm-workspace.yaml. `.` is the root. Only `dir` and `dir/*` are expanded.
32
+ */
33
+ export declare function workspaceGlobs(rootPackageJson?: string, pnpmWorkspace?: string): string[];
34
+ /** The package.json paths of a repository's declared packages, among the files it holds. */
35
+ export declare function packageManifests(globs: readonly string[], files: readonly string[]): string[];
36
+ /** The SKILL.md files a repository holds, outside dependencies and archives. */
37
+ export declare function skillFiles(files: readonly string[]): string[];
38
+ export interface CapabilityRowContext {
39
+ /** `repository:<owner>/<name>` */
40
+ repository: string;
41
+ /** the commit the files were read at */
42
+ commit: string;
43
+ observedBy: string;
44
+ /** ISO 8601 */
45
+ observedAt: string;
46
+ }
47
+ /**
48
+ * Capability rows for one repository. One row per id: two files naming the
49
+ * same skill are one capability with both files as its grounding.
50
+ */
51
+ export declare function capabilityRows(artefacts: readonly Artefact[], ctx: CapabilityRowContext): CapabilityFacet[];
52
+ /**
53
+ * Rows from several repositories as one inventory: a capability two
54
+ * repositories provide is one row that both provide, with both files as its
55
+ * grounding. The first row read keeps its name and statement.
56
+ */
57
+ export declare function mergeCapabilityRows(rows: readonly CapabilityFacet[]): CapabilityFacet[];
58
+ /** One `provides` edge: a repository provides a capability, said by whoever said the capability. */
59
+ export interface ProvidesEdge {
60
+ from: string;
61
+ to: string;
62
+ type: "provides";
63
+ statedBy: string;
64
+ statedAt: string;
65
+ grounding: string[];
66
+ revision: CapabilityFacet["revision"];
67
+ }
68
+ /** The `provides` edges a set of capability rows holds, one per provider. */
69
+ export declare function providesEdges(capabilities: readonly CapabilityFacet[]): ProvidesEdge[];
70
+ /** The capabilities a repository provides, matched case-folded, by kind then id. */
71
+ export declare function capabilitiesOf(repository: string, capabilities: readonly CapabilityFacet[]): CapabilityFacet[];
@@ -0,0 +1,210 @@
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 name = typeof p.name === "string" && p.name.trim() ? p.name.trim() : undefined;
44
+ const description = typeof p.description === "string" && p.description.trim() ? p.description.trim() : undefined;
45
+ let bins = [];
46
+ if (typeof p.bin === "string" && name)
47
+ bins = [name.replace(/^@[^/]+\//, "")];
48
+ else if (p.bin && typeof p.bin === "object")
49
+ bins = Object.keys(p.bin);
50
+ return { ...(name ? { name } : {}), ...(description ? { description } : {}), bins };
51
+ }
52
+ catch {
53
+ return { bins: [] };
54
+ }
55
+ }
56
+ /** `name` and `description` from a SKILL.md front matter, plain, quoted or folded (`>`, `|`). */
57
+ function parseSkillFrontMatter(text) {
58
+ const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
59
+ if (!m)
60
+ return {};
61
+ const lines = m[1].split(/\r?\n/);
62
+ const field = (key) => {
63
+ const i = lines.findIndex((l) => new RegExp(`^${key}:`).test(l));
64
+ if (i < 0)
65
+ return undefined;
66
+ let value = lines[i].slice(key.length + 1).trim();
67
+ if (/^[>|][+-]?$/.test(value)) {
68
+ const folded = [];
69
+ for (const l of lines.slice(i + 1)) {
70
+ if (/^\S/.test(l))
71
+ break;
72
+ folded.push(l.trim());
73
+ }
74
+ value = folded.join(" ").trim();
75
+ }
76
+ value = value.replace(/^(["'])([\s\S]*)\1$/, "$2").trim();
77
+ return value || undefined;
78
+ };
79
+ const name = field("name");
80
+ const description = field("description");
81
+ return { ...(name ? { name } : {}), ...(description ? { description } : {}) };
82
+ }
83
+ /**
84
+ * The folders a repository declares as its packages: `workspaces` of the root
85
+ * package.json (an array, or `{ packages }`), else the `packages:` list of
86
+ * pnpm-workspace.yaml. `.` is the root. Only `dir` and `dir/*` are expanded.
87
+ */
88
+ function workspaceGlobs(rootPackageJson, pnpmWorkspace) {
89
+ try {
90
+ const root = rootPackageJson ? JSON.parse(rootPackageJson) : {};
91
+ const w = root.workspaces;
92
+ const list = Array.isArray(w) ? w : w && typeof w === "object" ? w.packages : undefined;
93
+ if (Array.isArray(list) && list.length)
94
+ return [".", ...list.filter((x) => typeof x === "string")];
95
+ }
96
+ catch {
97
+ // an unreadable root manifest declares nothing
98
+ }
99
+ if (pnpmWorkspace) {
100
+ const block = /(^|\n)packages:\s*\n((?:[ \t]+-[^\n]*\n?)+)/.exec(pnpmWorkspace);
101
+ if (block) {
102
+ return block[2]
103
+ .split("\n")
104
+ .map((l) => l.replace(/^[ \t]+-\s*/, "").replace(/\s+#.*$/, "").replace(/^['"]|['"]$/g, "").trim())
105
+ .filter(Boolean);
106
+ }
107
+ }
108
+ return ["."];
109
+ }
110
+ /** The package.json paths of a repository's declared packages, among the files it holds. */
111
+ function packageManifests(globs, files) {
112
+ const manifests = new Set();
113
+ const held = new Set(files);
114
+ for (const glob of globs) {
115
+ const dir = glob.replace(/^\.\//, "").replace(/\/+$/, "");
116
+ if (dir === "." || dir === "") {
117
+ if (held.has("package.json"))
118
+ manifests.add("package.json");
119
+ }
120
+ else if (dir.endsWith("/*")) {
121
+ const base = `${dir.slice(0, -2)}/`;
122
+ for (const f of files) {
123
+ const rest = f.startsWith(base) ? f.slice(base.length) : "";
124
+ if (/^[^/]+\/package\.json$/.test(rest))
125
+ manifests.add(f);
126
+ }
127
+ }
128
+ else if (held.has(`${dir}/package.json`)) {
129
+ manifests.add(`${dir}/package.json`);
130
+ }
131
+ }
132
+ return [...manifests].sort();
133
+ }
134
+ /** The SKILL.md files a repository holds, outside dependencies and archives. */
135
+ function skillFiles(files) {
136
+ return files
137
+ .filter((f) => /(^|\/)SKILL\.md$/.test(f))
138
+ .filter((f) => !/(^|\/)(node_modules|archives?|archived-[^/]*|dist|\.next)\//.test(f))
139
+ .sort();
140
+ }
141
+ /**
142
+ * Capability rows for one repository. One row per id: two files naming the
143
+ * same skill are one capability with both files as its grounding.
144
+ */
145
+ function capabilityRows(artefacts, ctx) {
146
+ const where = `${ctx.repository.replace(/^repository:/, "")}@${ctx.commit.slice(0, 12)}`;
147
+ const rows = new Map();
148
+ for (const a of artefacts) {
149
+ const nodeId = capabilityId(a.kind, a.name);
150
+ const grounding = `${where}:${a.path}`;
151
+ const existing = rows.get(nodeId);
152
+ if (existing) {
153
+ if (!existing.grounding.includes(grounding))
154
+ existing.grounding.push(grounding);
155
+ continue;
156
+ }
157
+ const fits = a.description ? (0, capabilities_1.checkStatement)(a.description).fits : false;
158
+ rows.set(nodeId, {
159
+ nodeId,
160
+ name: a.name,
161
+ ...(fits ? { statement: a.description } : {}),
162
+ status: fits ? "clear" : "needs-resolution",
163
+ providedBy: [ctx.repository],
164
+ statedBy: ctx.observedBy,
165
+ statedAt: ctx.observedAt,
166
+ grounding: [grounding],
167
+ revision: "pending",
168
+ });
169
+ }
170
+ return [...rows.values()];
171
+ }
172
+ /**
173
+ * Rows from several repositories as one inventory: a capability two
174
+ * repositories provide is one row that both provide, with both files as its
175
+ * grounding. The first row read keeps its name and statement.
176
+ */
177
+ function mergeCapabilityRows(rows) {
178
+ const merged = new Map();
179
+ for (const row of rows) {
180
+ const existing = merged.get(row.nodeId);
181
+ if (!existing) {
182
+ merged.set(row.nodeId, { ...row, providedBy: [...row.providedBy], grounding: [...row.grounding] });
183
+ continue;
184
+ }
185
+ for (const p of row.providedBy)
186
+ if (!existing.providedBy.includes(p))
187
+ existing.providedBy.push(p);
188
+ for (const g of row.grounding)
189
+ if (!existing.grounding.includes(g))
190
+ existing.grounding.push(g);
191
+ }
192
+ return [...merged.values()].sort((a, b) => (a.nodeId < b.nodeId ? -1 : a.nodeId > b.nodeId ? 1 : 0));
193
+ }
194
+ /** The `provides` edges a set of capability rows holds, one per provider. */
195
+ function providesEdges(capabilities) {
196
+ return capabilities.flatMap((c) => c.providedBy.map((from) => ({
197
+ from,
198
+ to: c.nodeId,
199
+ type: "provides",
200
+ statedBy: c.statedBy,
201
+ statedAt: c.statedAt,
202
+ grounding: c.grounding,
203
+ revision: c.revision,
204
+ })));
205
+ }
206
+ /** The capabilities a repository provides, matched case-folded, by kind then id. */
207
+ function capabilitiesOf(repository, capabilities) {
208
+ const id = (repository.startsWith("repository:") ? repository : `repository:${repository}`).toLowerCase();
209
+ return capabilities.filter((c) => c.providedBy.some((p) => p.toLowerCase() === id));
210
+ }
package/dist/cli.js CHANGED
@@ -5,28 +5,77 @@
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>]
8
10
  //
9
11
  // `lineage <owner/name>` answers "what did this repository learn from", and
10
12
  // who learned from it; with no repository it prints every lineage. A lineage
11
13
  // is not a dependency: `learned-from` names what a repository took from
12
14
  // another that it carries on its own. --lineage adds a host's JSONL before
13
15
  // the rows this package ships (default MIADI_REPOSITORY_LINEAGE).
16
+ //
17
+ // `capabilities <owner/name>` answers what a repository provides: its
18
+ // packages, CLIs and skills as capability nodes, each with a `provides` edge.
19
+ // `scan` reads a clone's default branch from git objects (never its working
20
+ // tree) and prints those rows as JSONL, pending until a person reads them.
21
+ // --capabilities adds a host's JSONL before the shipped rows (default
22
+ // MIADI_REPOSITORY_CAPABILITIES).
14
23
  // --hub defaults to MIADI_REPOSITORY_MAPPING_HUB (a jgwill/jgwill clone, or a
15
24
  // mapping folder); --inventory to MIADI_SESSION_INVENTORY_DIR, else
16
25
  // ~/workspace/.mino/session-inventory. Read-only.
17
26
  //
18
27
  // Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || (function () {
45
+ var ownKeys = function(o) {
46
+ ownKeys = Object.getOwnPropertyNames || function (o) {
47
+ var ar = [];
48
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
49
+ return ar;
50
+ };
51
+ return ownKeys(o);
52
+ };
53
+ return function (mod) {
54
+ if (mod && mod.__esModule) return mod;
55
+ var result = {};
56
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
57
+ __setModuleDefault(result, mod);
58
+ return result;
59
+ };
60
+ })();
19
61
  Object.defineProperty(exports, "__esModule", { value: true });
62
+ const os = __importStar(require("node:os"));
63
+ const capabilities_1 = require("./capabilities");
20
64
  const read_1 = require("./read");
65
+ const scan_1 = require("./scan");
21
66
  const USAGE = [
22
67
  "usage: miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
23
68
  " miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
24
69
  " miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]",
70
+ " miadi-repomap capabilities [<owner/name>] [--capabilities <file>] [--json]",
71
+ " miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>]",
25
72
  ].join("\n");
26
73
  const FLAGS = {
27
- list: ["hub", "inventory", "lineage", "json"],
28
- show: ["hub", "inventory", "lineage", "json"],
74
+ list: ["hub", "inventory", "lineage", "capabilities", "json"],
75
+ show: ["hub", "inventory", "lineage", "capabilities", "json"],
29
76
  lineage: ["lineage", "json"],
77
+ capabilities: ["capabilities", "json"],
78
+ scan: ["ref", "repository", "by"],
30
79
  };
31
80
  class UsageError extends Error {
32
81
  }
@@ -83,7 +132,45 @@ async function main() {
83
132
  console.log(USAGE);
84
133
  return 0;
85
134
  }
86
- const options = { hub: value(flags, "hub"), inventory: value(flags, "inventory"), lineage: value(flags, "lineage") };
135
+ const options = {
136
+ hub: value(flags, "hub"),
137
+ inventory: value(flags, "inventory"),
138
+ lineage: value(flags, "lineage"),
139
+ capabilities: value(flags, "capabilities"),
140
+ };
141
+ if (command === "scan") {
142
+ const clones = positional.slice(1);
143
+ if (!clones.length)
144
+ throw new UsageError("scan needs at least one clone");
145
+ if (clones.length > 1 && value(flags, "repository"))
146
+ throw new UsageError("--repository names one clone's repository: scan one clone with it");
147
+ const observedBy = value(flags, "by") ?? `miadi-repomap scan (${os.userInfo().username}@${os.hostname()})`;
148
+ const rows = [];
149
+ for (const clone of clones) {
150
+ const result = await (0, scan_1.scanRepository)(clone, { ref: value(flags, "ref"), repository: value(flags, "repository"), observedBy });
151
+ console.error(`${result.repository.replace(/^repository:/, "")} @ ${result.commit.slice(0, 12)} (${result.ref}): ${result.capabilities.length} capabilities`);
152
+ rows.push(...result.capabilities);
153
+ }
154
+ for (const row of (0, capabilities_1.mergeCapabilityRows)(rows))
155
+ console.log(JSON.stringify(row));
156
+ return 0;
157
+ }
158
+ if (command === "capabilities") {
159
+ const answer = (0, read_1.repositoryCapabilities)(positional[1], { capabilities: options.capabilities });
160
+ for (const i of answer.issues)
161
+ console.error(`${i.severity} ${i.file ?? ""}${i.line ? `:${i.line}` : ""} — ${i.message}`);
162
+ if (flags.json) {
163
+ console.log(JSON.stringify(answer, null, 2));
164
+ return 0;
165
+ }
166
+ const subject = answer.repository ? short(answer.repository) : "every repository";
167
+ console.log(`${subject} provides ${answer.capabilities.length}: ${answer.counts.package} packages, ${answer.counts.cli} CLIs, ${answer.counts.skill} skills`);
168
+ for (const c of answer.capabilities) {
169
+ const by = answer.repository ? "" : ` (${c.providedBy.map(short).join(", ")})`;
170
+ console.log(` ${(c.kind ?? "other").padEnd(8)} ${c.name}${by}${c.statement ? ` — ${c.statement}` : ` [${c.status}]`}`);
171
+ }
172
+ return 0;
173
+ }
87
174
  if (command === "lineage") {
88
175
  const answer = (0, read_1.repositoryLineage)(positional[1], { lineage: options.lineage });
89
176
  for (const i of answer.issues)
@@ -150,6 +237,8 @@ async function main() {
150
237
  ...linkLines(r.lineage.learned_from),
151
238
  r.lineage.taught.length ? ` taught (${r.lineage.taught.length}):` : "",
152
239
  ...linkLines(r.lineage.taught),
240
+ r.capabilities.length ? ` provides (${r.capabilities.length}):` : "",
241
+ ...r.capabilities.map((c) => ` ${(c.kind ?? "other").padEnd(8)} ${c.name}${c.statement ? ` — ${c.statement}` : ` [${c.status}]`}`),
153
242
  ` sessions (${r.sessions.length}):`,
154
243
  ...r.sessions.map(sessionLine),
155
244
  ];
package/dist/index.d.ts CHANGED
@@ -2,4 +2,7 @@ export type { RepositorySession, MappingState, HubState, RepositoryView, Reposit
2
2
  export { dayOf, teamOf, dispositionOf, sessionOf, repositoryKey, 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
- export { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, readLineage, repositoryLineage, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, } from "./read";
5
+ export { CAPABILITY_KINDS, capabilityId, kindOf, parsePackageJson, parseSkillFrontMatter, workspaceGlobs, packageManifests, skillFiles, capabilityRows, mergeCapabilityRows, providesEdges, capabilitiesOf, type CapabilityKind, type Artefact, type CapabilityRowContext, type ProvidesEdge, } from "./capabilities";
6
+ export { SHIPPED_CAPABILITIES, SHIPPED_CAPABILITIES_SCANS, SHIPPED_CAPABILITIES_SOURCE } from "./shipped-capabilities";
7
+ export { scanRepository, type ScanOptions, type ScanResult } from "./scan";
8
+ export { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, readLineage, repositoryLineage, readCapabilities, repositoryCapabilities, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, type CapabilitiesRead, type CapabilitiesAnswer, } from "./read";
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@
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.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = exports.hubPath = exports.inventoryDir = 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;
7
+ exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = exports.hubPath = exports.inventoryDir = exports.scanRepository = exports.SHIPPED_CAPABILITIES_SOURCE = exports.SHIPPED_CAPABILITIES_SCANS = exports.SHIPPED_CAPABILITIES = 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
8
  var join_1 = require("./join");
9
9
  Object.defineProperty(exports, "dayOf", { enumerable: true, get: function () { return join_1.dayOf; } });
10
10
  Object.defineProperty(exports, "teamOf", { enumerable: true, get: function () { return join_1.teamOf; } });
@@ -22,6 +22,25 @@ Object.defineProperty(exports, "lineageGraph", { enumerable: true, get: function
22
22
  var shipped_lineage_1 = require("./shipped-lineage");
23
23
  Object.defineProperty(exports, "SHIPPED_LINEAGE_JSONL", { enumerable: true, get: function () { return shipped_lineage_1.SHIPPED_LINEAGE_JSONL; } });
24
24
  Object.defineProperty(exports, "SHIPPED_LINEAGE_SOURCE", { enumerable: true, get: function () { return shipped_lineage_1.SHIPPED_LINEAGE_SOURCE; } });
25
+ var capabilities_1 = require("./capabilities");
26
+ Object.defineProperty(exports, "CAPABILITY_KINDS", { enumerable: true, get: function () { return capabilities_1.CAPABILITY_KINDS; } });
27
+ Object.defineProperty(exports, "capabilityId", { enumerable: true, get: function () { return capabilities_1.capabilityId; } });
28
+ Object.defineProperty(exports, "kindOf", { enumerable: true, get: function () { return capabilities_1.kindOf; } });
29
+ Object.defineProperty(exports, "parsePackageJson", { enumerable: true, get: function () { return capabilities_1.parsePackageJson; } });
30
+ Object.defineProperty(exports, "parseSkillFrontMatter", { enumerable: true, get: function () { return capabilities_1.parseSkillFrontMatter; } });
31
+ Object.defineProperty(exports, "workspaceGlobs", { enumerable: true, get: function () { return capabilities_1.workspaceGlobs; } });
32
+ Object.defineProperty(exports, "packageManifests", { enumerable: true, get: function () { return capabilities_1.packageManifests; } });
33
+ Object.defineProperty(exports, "skillFiles", { enumerable: true, get: function () { return capabilities_1.skillFiles; } });
34
+ Object.defineProperty(exports, "capabilityRows", { enumerable: true, get: function () { return capabilities_1.capabilityRows; } });
35
+ Object.defineProperty(exports, "mergeCapabilityRows", { enumerable: true, get: function () { return capabilities_1.mergeCapabilityRows; } });
36
+ Object.defineProperty(exports, "providesEdges", { enumerable: true, get: function () { return capabilities_1.providesEdges; } });
37
+ Object.defineProperty(exports, "capabilitiesOf", { enumerable: true, get: function () { return capabilities_1.capabilitiesOf; } });
38
+ var shipped_capabilities_1 = require("./shipped-capabilities");
39
+ Object.defineProperty(exports, "SHIPPED_CAPABILITIES", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES; } });
40
+ Object.defineProperty(exports, "SHIPPED_CAPABILITIES_SCANS", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES_SCANS; } });
41
+ Object.defineProperty(exports, "SHIPPED_CAPABILITIES_SOURCE", { enumerable: true, get: function () { return shipped_capabilities_1.SHIPPED_CAPABILITIES_SOURCE; } });
42
+ var scan_1 = require("./scan");
43
+ Object.defineProperty(exports, "scanRepository", { enumerable: true, get: function () { return scan_1.scanRepository; } });
25
44
  var read_1 = require("./read");
26
45
  Object.defineProperty(exports, "inventoryDir", { enumerable: true, get: function () { return read_1.inventoryDir; } });
27
46
  Object.defineProperty(exports, "hubPath", { enumerable: true, get: function () { return read_1.hubPath; } });
@@ -31,3 +50,5 @@ Object.defineProperty(exports, "repositoryListing", { enumerable: true, get: fun
31
50
  Object.defineProperty(exports, "repositoryDetail", { enumerable: true, get: function () { return read_1.repositoryDetail; } });
32
51
  Object.defineProperty(exports, "readLineage", { enumerable: true, get: function () { return read_1.readLineage; } });
33
52
  Object.defineProperty(exports, "repositoryLineage", { enumerable: true, get: function () { return read_1.repositoryLineage; } });
53
+ Object.defineProperty(exports, "readCapabilities", { enumerable: true, get: function () { return read_1.readCapabilities; } });
54
+ Object.defineProperty(exports, "repositoryCapabilities", { enumerable: true, get: function () { return read_1.repositoryCapabilities; } });
package/dist/join.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type RepositoryMapping } from "@medicine-wheel/developer-repository-mapping";
2
2
  import type { InventorySnapshot } from "@miadi/hooks-interpreter";
3
+ import type { CapabilityFacet } from "@medicine-wheel/capabilities";
3
4
  import { type LineageEdge } from "./lineage";
4
5
  import type { RepositorySession, RepositorySummary, RepositoryView } from "./types";
5
6
  /** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
@@ -23,6 +24,6 @@ export declare function sessionsByRepository(records: ReadonlyMap<string, Invent
23
24
  * One repository: its rows when a hub holds them, its sessions, and its
24
25
  * lineage. Undefined when no hub, no record and no lineage names it.
25
26
  */
26
- export declare function repositoryView(repository: string, mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, sources?: Record<string, string>, lineageEdges?: readonly LineageEdge[]): RepositoryView | undefined;
27
+ export declare function repositoryView(repository: string, mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, sources?: Record<string, string>, lineageEdges?: readonly LineageEdge[], capabilityRows?: readonly CapabilityFacet[]): RepositoryView | undefined;
27
28
  /** Every repository a hub holds, a record names or a lineage names, most sessions first. */
28
- export declare function listRepositories(mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, lineageEdges?: readonly LineageEdge[]): RepositorySummary[];
29
+ export declare function listRepositories(mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, lineageEdges?: readonly LineageEdge[], capabilityRows?: readonly CapabilityFacet[]): RepositorySummary[];
package/dist/join.js CHANGED
@@ -13,6 +13,7 @@ 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");
16
17
  const lineage_1 = require("./lineage");
17
18
  const text = (value) => (typeof value === "string" && value.trim() ? value : undefined);
18
19
  /** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
@@ -79,14 +80,15 @@ const keyOfNode = (nodeId) => nodeId.slice("repository:".length).toLowerCase();
79
80
  * One repository: its rows when a hub holds them, its sessions, and its
80
81
  * lineage. Undefined when no hub, no record and no lineage names it.
81
82
  */
82
- function repositoryView(repository, mapping, bySessions, sources = {}, lineageEdges = []) {
83
+ function repositoryView(repository, mapping, bySessions, sources = {}, lineageEdges = [], capabilityRows = []) {
83
84
  const key = repositoryKey(repository);
84
85
  if (!key)
85
86
  return undefined;
86
87
  const row = mapping?.repositories.find((r) => keyOfNode(r.nodeId) === key);
87
88
  const sessions = bySessions.sessions.get(key) ?? [];
88
89
  const lineage = (0, lineage_1.lineageOf)(key, lineageEdges);
89
- const named = lineageEdges.flatMap((e) => [e.from, e.to]).find((id) => keyOfNode(id) === key);
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);
90
92
  if (!row && !sessions.length && !named)
91
93
  return undefined;
92
94
  const nodeId = row?.nodeId ?? named ?? `repository:${bySessions.spelled.get(key) ?? key}`;
@@ -103,18 +105,23 @@ function repositoryView(repository, mapping, bySessions, sources = {}, lineageEd
103
105
  relations: row ? mapping.relations.filter((r) => r.from === row.nodeId || r.to === row.nodeId) : [],
104
106
  sessions,
105
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
+ }),
106
112
  };
107
113
  }
108
114
  /** Every repository a hub holds, a record names or a lineage names, most sessions first. */
109
- function listRepositories(mapping, bySessions, lineageEdges = []) {
115
+ function listRepositories(mapping, bySessions, lineageEdges = [], capabilityRows = []) {
110
116
  const keys = new Set([
111
117
  ...bySessions.sessions.keys(),
112
118
  ...(mapping?.repositories ?? []).map((r) => keyOfNode(r.nodeId)),
113
119
  ...lineageEdges.flatMap((e) => [keyOfNode(e.from), keyOfNode(e.to)]),
120
+ ...capabilityRows.flatMap((c) => c.providedBy.filter((p) => p.startsWith("repository:")).map(keyOfNode)),
114
121
  ]);
115
122
  return [...keys]
116
123
  .map((key) => {
117
- const view = repositoryView(key, mapping, bySessions, {}, lineageEdges);
124
+ const view = repositoryView(key, mapping, bySessions, {}, lineageEdges, capabilityRows);
118
125
  const teams = [...new Set(view.sessions.flatMap((s) => (s.team ? [s.team] : [])))].sort();
119
126
  return {
120
127
  nodeId: view.nodeId,
@@ -124,6 +131,7 @@ function listRepositories(mapping, bySessions, lineageEdges = []) {
124
131
  ...(view.repository ? { lifecycle: view.repository.lifecycle } : {}),
125
132
  ...(view.reading ? { drift: view.reading.drift } : {}),
126
133
  sessions: view.sessions.length,
134
+ capabilities: view.capabilities.length,
127
135
  ...(view.sessions[0]?.date ? { last_session: view.sessions[0].date } : {}),
128
136
  teams,
129
137
  };
package/dist/lineage.d.ts CHANGED
@@ -15,46 +15,46 @@ export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
15
15
  /** what was learned, at most 55 words */
16
16
  description: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
17
17
  }, "strict", z.ZodTypeAny, {
18
+ revision: "pending" | "revised" | "affirmed";
18
19
  from: string;
19
20
  to: string;
20
21
  type: "learned-from";
21
22
  statedBy: string;
22
23
  statedAt: string;
23
24
  grounding: string[];
24
- revision: "pending" | "revised" | "affirmed";
25
25
  description?: string | undefined;
26
26
  revisedBy?: string | undefined;
27
27
  revisedAt?: string | undefined;
28
28
  }, {
29
+ revision: "pending" | "revised" | "affirmed";
29
30
  from: string;
30
31
  to: string;
31
32
  type: "learned-from";
32
33
  statedBy: string;
33
34
  statedAt: string;
34
35
  grounding: string[];
35
- revision: "pending" | "revised" | "affirmed";
36
36
  description?: string | undefined;
37
37
  revisedBy?: string | undefined;
38
38
  revisedAt?: string | undefined;
39
39
  }>, {
40
+ revision: "pending" | "revised" | "affirmed";
40
41
  from: string;
41
42
  to: string;
42
43
  type: "learned-from";
43
44
  statedBy: string;
44
45
  statedAt: string;
45
46
  grounding: string[];
46
- revision: "pending" | "revised" | "affirmed";
47
47
  description?: string | undefined;
48
48
  revisedBy?: string | undefined;
49
49
  revisedAt?: string | undefined;
50
50
  }, {
51
+ revision: "pending" | "revised" | "affirmed";
51
52
  from: string;
52
53
  to: string;
53
54
  type: "learned-from";
54
55
  statedBy: string;
55
56
  statedAt: string;
56
57
  grounding: string[];
57
- revision: "pending" | "revised" | "affirmed";
58
58
  description?: string | undefined;
59
59
  revisedBy?: string | undefined;
60
60
  revisedAt?: string | undefined;