@miadi/relational-git-repository-mapper 0.8.0 → 0.9.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
@@ -80,11 +80,29 @@ Each repository's packages, CLIs and skills are `capability` nodes of
80
80
 
81
81
  ```bash
82
82
  miadi-repomap capabilities jgwill/medicine-wheel # what does the medicine wheel provide?
83
+ miadi-repomap capabilities jgwill/mia-code --clone /src/mia-code # read it from a clone a person names
83
84
  miadi-repomap capabilities # every capability, and who provides it
84
85
  miadi-repomap capabilities --stage specified # what is written down and not built yet
85
86
  miadi-repomap scan <clone>... --by "<who>" # read a clone's default branch, print JSONL rows
86
87
  ```
87
88
 
89
+ **A repository is read from its clone on this host when there is one** (0.9.0,
90
+ jgwill/Miadi#1148). A repository that committed its own `.miadi/capabilities.jsonl` is
91
+ shown as that file says, with no intermediate file: `capabilities <owner/name>` and
92
+ `show <owner/name>` read the clone named with `--clone`, else the one found under
93
+ `MIADI_REPOSITORY_CLONES`, else beside the hub clone (`…/repos/jgwill/jgwill` sits beside
94
+ `…/repos/jgwill/<name>`). A folder is the repository's clone only when its `origin`
95
+ names it. The clone is read at its default branch as last fetched (`git fetch` first for
96
+ today's), its own file first, merged with what the commit's files say, and its rows
97
+ replace the shipped rows of that repository. The first line on stderr says which clone,
98
+ which commit and whether it holds a file. With no clone the answer is the map's.
99
+
100
+ Since `@medicine-wheel/developer-repository-mapping` 0.27.20 (format version 5,
101
+ jgwill/medicine-wheel#188) a row also says which commands a CLI carries (`carries`),
102
+ which CLI a command belongs to, and what reads a capability where no `package.json`
103
+ says so (`read by`). A capability still being built is read at `prototype` or
104
+ `implementation` when its stage names an issue, a pull request or a branch.
105
+
88
106
  A capability says what it is (its `statement`, read from its files). Since
89
107
  `@medicine-wheel/capabilities` 0.27.15 it can also say what it achieves for someone
90
108
  (`achieves`, at most 55 words, signed), where it stands (`stage`: `specified`, `prototype`,
@@ -129,10 +147,24 @@ reads it.
129
147
 
130
148
  The package ships a scan of `jgwill/Miadi` and the three lineages (`avadisabelle/coaia-narrative`,
131
149
  `jgwill/coaiajs`, `jgwill/medicine-wheel`), regenerated with
132
- `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
150
+ `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 capability map
133
151
  (`--capabilities` or `MIADI_REPOSITORY_CAPABILITIES`) is read first; the first source to name
134
152
  a capability speaks for it.
135
153
 
154
+ `--capabilities` and `MIADI_REPOSITORY_CAPABILITIES` take a **capability map**: one row per
155
+ capability and provider, with `nodeId`, `name`, `providedBy` and its attribution. This
156
+ command writes one:
157
+
158
+ ```bash
159
+ mw-repomap capabilities map <clone>... --out map.jsonl # or --root <folder of clones>
160
+ miadi-repomap capabilities <owner/name> --capabilities map.jsonl
161
+ ```
162
+
163
+ A repository's own `.miadi/capabilities.jsonl` is not a map: its rows hold `kind`, `name`
164
+ and `address`, and are read with the commit they sit in. Given that file, the command says
165
+ so in one line and exits 1. Any file or clone that could not be read ends `capabilities`
166
+ with exit 1.
167
+
136
168
  In the app: `GET /api/repositories/capabilities[?repository=owner/name]` answers with the
137
169
  capabilities and their `provides` edges, `GET /api/repositories/{owner}/{name}` carries them,
138
170
  and the repository page's Lineage card lists them by kind.
@@ -198,7 +230,8 @@ name them (`miadi-chronicle://<number>`), linked to the chronicle page.
198
230
  | `MIADI_REPOSITORY_MAPPING_HUB` | none | a hub clone (`…/jgwill/jgwill`) or its mapping folder |
199
231
  | `MIADI_SESSION_INVENTORY_DIR` | `~/workspace/.mino/session-inventory` | the inventory records |
200
232
  | `MIADI_REPOSITORY_LINEAGE` | none | a lineage JSONL read before the shipped rows |
201
- | `MIADI_REPOSITORY_CAPABILITIES` | none | a capability JSONL read before the shipped rows |
233
+ | `MIADI_REPOSITORY_CAPABILITIES` | none | a capability map (`mw-repomap capabilities map --out`) read before the shipped rows |
234
+ | `MIADI_REPOSITORY_CLONES` | the folders around the hub clone | where a repository's clone is looked for, colon-separated: each holds `<owner>/<name>` or `<name>` |
202
235
  | `MIADI_REPOSITORY_HOSTS` | none | a where JSONL (`where --write`) read before the shipped readings |
203
236
  | `MIADI_REPOSITORY_PACKAGES` | none | a package readings JSONL (`mw-repomap capabilities map --packages`) read before the shipped ones |
204
237
  | `MIADI_HOST_GIT_ROOTS` | `/srv/git` | where `where` looks for bare repositories, colon-separated |
@@ -207,15 +240,15 @@ name them (`miadi-chronicle://<number>`), linked to the chronicle page.
207
240
 
208
241
  ```bash
209
242
  miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
210
- miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
243
+ miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--clone <path>] [--json]
211
244
  miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
212
- miadi-repomap capabilities [<owner/name>] [--stage <stage>] [--capabilities <file>] [--json]
245
+ miadi-repomap capabilities [<owner/name>] [--stage <stage>] [--capabilities <file>] [--clone <path>] [--json]
213
246
  miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]
214
247
  miadi-repomap where [<owner/name>...] [--write <file>] [--json]
215
248
  miadi-repomap impact <package> [--bump major|minor|patch] [--json]
216
249
  ```
217
250
 
218
- Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
251
+ Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage; `capabilities`: a file or a clone could not be read, 2 usage error.
219
252
 
220
253
  ## Library
221
254
 
package/dist/cli.js CHANGED
@@ -3,9 +3,9 @@
3
3
  // miadi-repomap — a repository's mapping rows beside the sessions that worked in it.
4
4
  //
5
5
  // miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
6
- // miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
6
+ // miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--clone <path>] [--json]
7
7
  // miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
8
- // miadi-repomap capabilities [<owner/name>] [--stage <stage>] [--capabilities <file>] [--json]
8
+ // miadi-repomap capabilities [<owner/name>] [--stage <stage>] [--capabilities <file>] [--clone <path>] [--json]
9
9
  // miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]
10
10
  // miadi-repomap where [<owner/name>...] [--write <file>] [--json]
11
11
  // miadi-repomap impact <package> [--bump major|minor|patch] [--json]
@@ -21,8 +21,15 @@
21
21
  // `scan` reads a clone's default branch from git objects, its own
22
22
  // .miadi/capabilities.jsonl first when it holds one (never its working
23
23
  // tree) and prints those rows as JSONL, pending until a person reads them.
24
- // --capabilities adds a host's JSONL before the shipped rows (default
25
- // MIADI_REPOSITORY_CAPABILITIES). Each capability shows what it achieves,
24
+ // With a repository, `capabilities` and `show` read its clone on this host
25
+ // when there is one: the clone named with --clone, else the one found under
26
+ // MIADI_REPOSITORY_CLONES (colon-separated folders holding <owner>/<name> or
27
+ // <name>), else beside the hub clone. The clone's own committed
28
+ // .miadi/capabilities.jsonl speaks first, at its default branch as last
29
+ // fetched, and replaces the shipped rows of that repository.
30
+ // --capabilities adds a host's capability map before the shipped rows (default
31
+ // MIADI_REPOSITORY_CAPABILITIES): the rows `mw-repomap capabilities map
32
+ // <clone>... --out <file>` writes, never a repository's own file. Each capability shows what it achieves,
26
33
  // where it stands, its specifications and its issues when someone said them;
27
34
  // --stage <stage> lists only those at one stage (specified, prototype,
28
35
  // implementation, released, retired, or unstated).
@@ -37,7 +44,8 @@
37
44
  // mapping folder); --inventory to MIADI_SESSION_INVENTORY_DIR, else
38
45
  // ~/workspace/.mino/session-inventory. Read-only.
39
46
  //
40
- // Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
47
+ // Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage;
48
+ // `capabilities`: a file or a clone could not be read, 2 usage error.
41
49
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
42
50
  if (k2 === undefined) k2 = k;
43
51
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -81,18 +89,18 @@ const where_1 = require("./where");
81
89
  const scan_1 = require("./scan");
82
90
  const USAGE = [
83
91
  "usage: miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
84
- " miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
92
+ " miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--clone <path>] [--json]",
85
93
  " miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]",
86
- " miadi-repomap capabilities [<owner/name>] [--stage <stage>] [--capabilities <file>] [--json]",
94
+ " miadi-repomap capabilities [<owner/name>] [--stage <stage>] [--capabilities <file>] [--clone <path>] [--json]",
87
95
  " miadi-repomap scan <clone>... [--ref <ref>] [--repository <owner/name>] [--by <who>] [--packages <file>]",
88
96
  " miadi-repomap where [<owner/name>...] [--write <file>] [--json]",
89
97
  " miadi-repomap impact <package> [--bump major|minor|patch] [--json]",
90
98
  ].join("\n");
91
99
  const FLAGS = {
92
100
  list: ["hub", "inventory", "lineage", "capabilities", "hosts", "json"],
93
- show: ["hub", "inventory", "lineage", "capabilities", "hosts", "json"],
101
+ show: ["hub", "inventory", "lineage", "capabilities", "hosts", "clone", "json"],
94
102
  lineage: ["lineage", "json"],
95
- capabilities: ["capabilities", "stage", "json"],
103
+ capabilities: ["capabilities", "stage", "clone", "json"],
96
104
  scan: ["ref", "repository", "by", "packages"],
97
105
  where: ["write", "json", "hub", "inventory", "by"],
98
106
  impact: ["bump", "json"],
@@ -119,6 +127,9 @@ function capabilityLines(c, by = "") {
119
127
  ]
120
128
  : []),
121
129
  ...(c.episodes?.length ? [` held by ${c.episodes.join(", ")}`] : []),
130
+ ...(c.commands ?? []).map((command) => ` carries ${command}`),
131
+ ...(c.cli ? [` a command of ${c.cli}`] : []),
132
+ ...(c.consumers ?? []).map((x) => ` read by ${x.consumer}${x.reads ? `: ${x.reads}` : ""} (${x.statedBy})`),
122
133
  ];
123
134
  }
124
135
  function parse(argv) {
@@ -182,6 +193,8 @@ async function main() {
182
193
  capabilities: value(flags, "capabilities"),
183
194
  hosts: value(flags, "hosts"),
184
195
  };
196
+ // `show` reads the repository's clone on this host for what it provides, as `capabilities` does.
197
+ const live = { live: true, ...(value(flags, "clone") ? { clone: value(flags, "clone") } : {}) };
185
198
  if (command === "where") {
186
199
  const named = positional.slice(1);
187
200
  const listing = named.length ? undefined : await (0, read_1.repositoryListing)(options);
@@ -254,15 +267,28 @@ async function main() {
254
267
  if (stage !== undefined && stage !== "unstated" && !capabilities_1.CAPABILITY_STAGES.includes(stage)) {
255
268
  throw new UsageError(`--stage is one of ${[...capabilities_1.CAPABILITY_STAGES, "unstated"].join(", ")}`);
256
269
  }
257
- const answer = (0, read_1.repositoryCapabilities)(positional[1], { capabilities: options.capabilities, ...(stage ? { stage: stage } : {}) });
270
+ const clone = value(flags, "clone");
271
+ if (clone && !positional[1])
272
+ throw new UsageError("--clone names one repository's clone: give the repository, owner/name");
273
+ const answer = await (0, read_1.repositoryCapabilitiesLive)(positional[1], {
274
+ capabilities: options.capabilities,
275
+ ...(clone ? { clone } : {}),
276
+ ...(stage ? { stage: stage } : {}),
277
+ observedBy: `miadi-repomap capabilities (${os.userInfo().username}@${os.hostname()})`,
278
+ });
258
279
  for (const i of answer.issues)
259
280
  console.error(`${i.severity} ${i.file ?? ""}${i.line ? `:${i.line}` : ""} — ${i.message}`);
281
+ // A file or a clone that could not be read is not an answer: the command says so with its exit code.
282
+ const failed = answer.issues.some((i) => i.severity === "error") ? 1 : 0;
260
283
  if (flags.json) {
261
284
  console.log(JSON.stringify(answer, null, 2));
262
- return 0;
285
+ return failed;
263
286
  }
264
287
  const subject = answer.repository ? short(answer.repository) : "every repository";
265
- console.log(`${subject} provides ${answer.capabilities.length}${answer.stage ? ` at stage ${answer.stage}` : ""}: ${answer.counts.package} packages, ${answer.counts.cli} CLIs, ${answer.counts.skill} skills, ${answer.counts.decision} decisions, ${answer.counts.app} apps`);
288
+ if (answer.clone)
289
+ console.error(`read from ${answer.clone.clone} @ ${answer.clone.commit.slice(0, 12)} (${answer.clone.ref}), ${answer.clone.source === "file" ? "its own .miadi/capabilities.jsonl" : "its files: it holds no capability file"}`);
290
+ const more = [answer.counts.command ? `${answer.counts.command} commands` : "", answer.counts.plugin ? `${answer.counts.plugin} plugins` : ""].filter(Boolean);
291
+ console.log(`${subject} provides ${answer.capabilities.length}${answer.stage ? ` at stage ${answer.stage}` : ""}: ${answer.counts.package} packages, ${answer.counts.cli} CLIs, ${answer.counts.skill} skills, ${answer.counts.decision} decisions, ${answer.counts.app} apps${more.length ? `, ${more.join(", ")}` : ""}`);
266
292
  const stated = Object.entries(answer.stages).filter(([k, n]) => k !== "unstated" && n > 0);
267
293
  if (stated.length)
268
294
  console.log(` stages: ${stated.map(([k, n]) => `${n} ${k}`).join(", ")}, ${answer.stages.unstated} unstated`);
@@ -273,7 +299,7 @@ async function main() {
273
299
  if (c.address)
274
300
  console.log(` ${c.address}`);
275
301
  }
276
- return 0;
302
+ return failed;
277
303
  }
278
304
  if (command === "lineage") {
279
305
  const answer = (0, read_1.repositoryLineage)(positional[1], { lineage: options.lineage });
@@ -321,7 +347,7 @@ async function main() {
321
347
  if (command === "show") {
322
348
  if (!positional[1])
323
349
  throw new UsageError("show needs a repository: owner/name");
324
- const detail = await (0, read_1.repositoryDetail)(positional[1], options);
350
+ const detail = await (0, read_1.repositoryDetail)(positional[1], { ...options, ...live });
325
351
  if (flags.json) {
326
352
  console.log(JSON.stringify(detail, null, 2));
327
353
  return detail.repository ? 0 : 1;
package/dist/index.d.ts CHANGED
@@ -10,5 +10,5 @@ export { RepositoryHostSchema, RepositoryWhereSchema, parseWhere, whereOf, webUr
10
10
  export { checkWhere, type CheckWhereOptions } from "./where";
11
11
  export { SHIPPED_PACKAGES } from "./shipped-capabilities";
12
12
  export { SHIPPED_HOSTS, SHIPPED_HOSTS_SOURCE } from "./shipped-hosts";
13
- export { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, readLineage, repositoryLineage, readCapabilities, repositoryCapabilities, stageOf, readWhere, readPackages, repositoryImpact, findCapability, type CapabilityRecord, type RelatedCapability, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, type CapabilitiesRead, type CapabilitiesAnswer, type WhereRead, type ImpactRead, } from "./read";
13
+ export { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, readLineage, repositoryLineage, readCapabilities, repositoryCapabilities, repositoryCapabilitiesLive, readCloneCapabilities, findRepositoryClone, cloneRoots, isRepositoryCapabilityFile, OWN_FILE_NOT_A_MAP, type CloneReading, stageOf, readWhere, readPackages, repositoryImpact, findCapability, type CapabilityRecord, type RelatedCapability, type ReadOptions, type MapperRead, type LineageRead, type LineageAnswer, type CapabilitiesRead, type CapabilitiesAnswer, type WhereRead, type ImpactRead, } from "./read";
14
14
  export { capabilitiesOfCommit, changedCapabilities, changesOnlyVersions, remoteRepository, CommitReadError, type CommitCapability, type CommitCapabilities, type CommitCapabilitiesOptions, type CommitReadFailure, type ChangedCapabilitiesInput, } from "./commit";
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // Data Mapper. Formerly @miadi/relational-repository-mapper (deprecated).
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SHIPPED_PACKAGES = exports.checkWhere = exports.webUrlOf = exports.whereOf = exports.parseWhere = exports.RepositoryWhereSchema = exports.RepositoryHostSchema = exports.impactOf = exports.satisfies = exports.bumpVersion = exports.consumesEdges = exports.PackageReadingSchema = exports.scanRepository = exports.readRepositoryCapabilities = exports.SHIPPED_CAPABILITIES_SOURCE = exports.SHIPPED_CAPABILITIES_SCANS = exports.SHIPPED_CAPABILITIES = exports.CODE_READERS = exports.medicineWheelSkills = exports.capabilityAddress = exports.capabilitiesOf = exports.providesEdges = exports.mergeCapabilityRows = exports.capabilityRows = exports.skillFiles = exports.packageManifests = exports.workspaceGlobs = exports.parseSkillFrontMatter = exports.parsePackageJson = exports.kindOf = exports.capabilityId = exports.CAPABILITY_KINDS = exports.SHIPPED_LINEAGE_SOURCE = exports.SHIPPED_LINEAGE_JSONL = exports.lineageGraph = exports.lineageOf = exports.parseLineage = exports.LineageRowSchema = exports.listRepositories = exports.repositoryView = exports.sessionsByRepository = exports.capabilitySessions = exports.capabilityKey = exports.repositoriesOfRecord = exports.parseTraceRef = exports.repositoryKey = exports.sessionOf = exports.dispositionOf = exports.teamOf = exports.dayOf = void 0;
8
- exports.CommitReadError = exports.remoteRepository = exports.changesOnlyVersions = exports.changedCapabilities = exports.capabilitiesOfCommit = exports.findCapability = exports.repositoryImpact = exports.readPackages = exports.readWhere = exports.stageOf = exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = exports.hubPath = exports.inventoryDir = exports.SHIPPED_HOSTS_SOURCE = exports.SHIPPED_HOSTS = void 0;
8
+ exports.CommitReadError = exports.remoteRepository = exports.changesOnlyVersions = exports.changedCapabilities = exports.capabilitiesOfCommit = exports.findCapability = exports.repositoryImpact = exports.readPackages = exports.readWhere = exports.stageOf = exports.OWN_FILE_NOT_A_MAP = exports.isRepositoryCapabilityFile = exports.cloneRoots = exports.findRepositoryClone = exports.readCloneCapabilities = exports.repositoryCapabilitiesLive = exports.repositoryCapabilities = exports.readCapabilities = exports.repositoryLineage = exports.readLineage = exports.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = exports.hubPath = exports.inventoryDir = exports.SHIPPED_HOSTS_SOURCE = exports.SHIPPED_HOSTS = void 0;
9
9
  var join_1 = require("./join");
10
10
  Object.defineProperty(exports, "dayOf", { enumerable: true, get: function () { return join_1.dayOf; } });
11
11
  Object.defineProperty(exports, "teamOf", { enumerable: true, get: function () { return join_1.teamOf; } });
@@ -80,6 +80,12 @@ Object.defineProperty(exports, "readLineage", { enumerable: true, get: function
80
80
  Object.defineProperty(exports, "repositoryLineage", { enumerable: true, get: function () { return read_1.repositoryLineage; } });
81
81
  Object.defineProperty(exports, "readCapabilities", { enumerable: true, get: function () { return read_1.readCapabilities; } });
82
82
  Object.defineProperty(exports, "repositoryCapabilities", { enumerable: true, get: function () { return read_1.repositoryCapabilities; } });
83
+ Object.defineProperty(exports, "repositoryCapabilitiesLive", { enumerable: true, get: function () { return read_1.repositoryCapabilitiesLive; } });
84
+ Object.defineProperty(exports, "readCloneCapabilities", { enumerable: true, get: function () { return read_1.readCloneCapabilities; } });
85
+ Object.defineProperty(exports, "findRepositoryClone", { enumerable: true, get: function () { return read_1.findRepositoryClone; } });
86
+ Object.defineProperty(exports, "cloneRoots", { enumerable: true, get: function () { return read_1.cloneRoots; } });
87
+ Object.defineProperty(exports, "isRepositoryCapabilityFile", { enumerable: true, get: function () { return read_1.isRepositoryCapabilityFile; } });
88
+ Object.defineProperty(exports, "OWN_FILE_NOT_A_MAP", { enumerable: true, get: function () { return read_1.OWN_FILE_NOT_A_MAP; } });
83
89
  Object.defineProperty(exports, "stageOf", { enumerable: true, get: function () { return read_1.stageOf; } });
84
90
  Object.defineProperty(exports, "readWhere", { enumerable: true, get: function () { return read_1.readWhere; } });
85
91
  Object.defineProperty(exports, "readPackages", { enumerable: true, get: function () { return read_1.readPackages; } });
package/dist/read.d.ts CHANGED
@@ -12,14 +12,34 @@ type Env = Record<string, string | undefined>;
12
12
  export declare function inventoryDir(env?: Env): string;
13
13
  /** The hub to read: `MIADI_REPOSITORY_MAPPING_HUB`, a hub clone or its mapping folder. Unset means none. */
14
14
  export declare function hubPath(env?: Env): string | undefined;
15
+ /**
16
+ * The folders that hold clones on this host, each as `<root>/<owner>/<name>` or
17
+ * `<root>/<name>`: `MIADI_REPOSITORY_CLONES`, colon-separated. Unset, the
18
+ * folders around the hub clone: `…/repos/jgwill/jgwill` sits beside its owner's
19
+ * other clones, so its parent holds `<name>` and its grandparent `<owner>/<name>`.
20
+ * With no hub either, none: a repository is then read only from a clone a person names.
21
+ */
22
+ export declare function cloneRoots(env?: Env): string[];
23
+ /**
24
+ * The clone of a repository under the roots: the first folder that is a git
25
+ * repository whose `origin` names it, compared case-folded. A folder of the
26
+ * right name that is a clone of something else is never read as it.
27
+ */
28
+ export declare function findRepositoryClone(repository: string, roots?: readonly string[]): Promise<string | undefined>;
15
29
  export interface ReadOptions {
30
+ /** the clone to read one repository's capabilities from, instead of looking for it under {@link cloneRoots} */
31
+ clone?: string;
32
+ /** the folders to look for a repository's clone in; default {@link cloneRoots} */
33
+ clones?: string[];
34
+ /** `repositoryDetail`: read the repository's clone on this host for what it provides. Off by default: it runs git for each file the scan reads. */
35
+ live?: boolean;
16
36
  /** hub clone or mapping folder; default {@link hubPath} */
17
37
  hub?: string;
18
38
  /** inventory directory; default {@link inventoryDir} */
19
39
  inventory?: string;
20
40
  /** a lineage JSONL read before the shipped one; default `MIADI_REPOSITORY_LINEAGE` */
21
41
  lineage?: string;
22
- /** a capability JSONL read before the shipped rows; default `MIADI_REPOSITORY_CAPABILITIES` */
42
+ /** a capability map (`mw-repomap capabilities map --out`) read before the shipped rows; default `MIADI_REPOSITORY_CAPABILITIES` */
23
43
  capabilities?: string;
24
44
  /** a where JSONL (`miadi-repomap where --write`) read before the shipped readings; default `MIADI_REPOSITORY_HOSTS` */
25
45
  hosts?: string;
@@ -59,6 +79,10 @@ export interface CapabilitiesRead {
59
79
  * capability speaks for it; a later row on the same id is reported and skipped.
60
80
  */
61
81
  export declare function readCapabilities(path?: string | undefined): CapabilitiesRead;
82
+ /** What `--capabilities` and `MIADI_REPOSITORY_CAPABILITIES` are told when they are given a repository's own file. */
83
+ export declare const OWN_FILE_NOT_A_MAP = "this is a repository's own .miadi/capabilities.jsonl, not a capability map. A map holds one row per capability and provider, written by \"mw-repomap capabilities map <clone>... --out <file>\". To read one repository from its clone: miadi-repomap capabilities <owner/name> --clone <clone>";
84
+ /** True for the text of a repository's own capability file: its first line is that format's header. */
85
+ export declare function isRepositoryCapabilityFile(text: string): boolean;
62
86
  export interface CapabilitiesAnswer {
63
87
  from: string[];
64
88
  scans: typeof SHIPPED_CAPABILITIES_SCANS;
@@ -87,6 +111,46 @@ export declare const stageOf: (c: CapabilityFacet) => CapabilityStage | "unstate
87
111
  export declare function repositoryCapabilities(repository?: string, options?: Pick<ReadOptions, "capabilities"> & {
88
112
  stage?: CapabilityStage | "unstated";
89
113
  }): CapabilitiesAnswer;
114
+ /** One repository's capabilities as its clone holds them at one commit. */
115
+ export interface CloneReading {
116
+ /** the clone read */
117
+ clone: string;
118
+ /** `repository:<owner>/<name>`, as the clone's origin names it */
119
+ repository: string;
120
+ ref: string;
121
+ commit: string;
122
+ /** `file` when the commit holds the repository's own capability file, `scan` when only its files were read */
123
+ source: "file" | "scan";
124
+ capabilities: CapabilityFacet[];
125
+ issues: MappingIssue[];
126
+ }
127
+ /**
128
+ * Read one repository from its clone on this host: the clone named, else the
129
+ * one found under {@link cloneRoots}. Its own committed capability file first,
130
+ * merged with what the commit's files say, at its default branch as last
131
+ * fetched. Undefined when this host holds no clone of it. A clone named that
132
+ * is another repository's is an error and is not read.
133
+ */
134
+ export declare function readCloneCapabilities(repository: string, options?: Pick<ReadOptions, "clone" | "clones"> & {
135
+ ref?: string;
136
+ observedBy?: string;
137
+ }): Promise<CloneReading | {
138
+ clone: string;
139
+ error: string;
140
+ } | undefined>;
141
+ /**
142
+ * "What does this repository provide?", read from its clone on this host when
143
+ * there is one (jgwill/Miadi#1148): a repository that committed its own
144
+ * capability file is shown as that file says, with no map made by hand. With no
145
+ * clone, or no repository, the answer is {@link repositoryCapabilities}'s.
146
+ */
147
+ export declare function repositoryCapabilitiesLive(repository?: string, options?: Pick<ReadOptions, "capabilities" | "clone" | "clones"> & {
148
+ stage?: CapabilityStage | "unstated";
149
+ ref?: string;
150
+ observedBy?: string;
151
+ }): Promise<CapabilitiesAnswer & {
152
+ clone?: Pick<CloneReading, "clone" | "ref" | "commit" | "source">;
153
+ }>;
90
154
  /** A capability beside another one, with the address that opens it. */
91
155
  export interface RelatedCapability {
92
156
  relation: "consumes" | "consumed-by" | "ships" | "shipped-by";
package/dist/read.js CHANGED
@@ -3,14 +3,19 @@
3
3
  // the hubs it registers) and the session inventory. Read-only; nothing here
4
4
  // writes a mapping or a record.
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.stageOf = void 0;
6
+ exports.stageOf = exports.OWN_FILE_NOT_A_MAP = void 0;
7
7
  exports.inventoryDir = inventoryDir;
8
8
  exports.hubPath = hubPath;
9
+ exports.cloneRoots = cloneRoots;
10
+ exports.findRepositoryClone = findRepositoryClone;
9
11
  exports.readWhere = readWhere;
10
12
  exports.readPackages = readPackages;
11
13
  exports.repositoryImpact = repositoryImpact;
12
14
  exports.readCapabilities = readCapabilities;
15
+ exports.isRepositoryCapabilityFile = isRepositoryCapabilityFile;
13
16
  exports.repositoryCapabilities = repositoryCapabilities;
17
+ exports.readCloneCapabilities = readCloneCapabilities;
18
+ exports.repositoryCapabilitiesLive = repositoryCapabilitiesLive;
14
19
  exports.findCapability = findCapability;
15
20
  exports.readLineage = readLineage;
16
21
  exports.readHubState = readHubState;
@@ -41,6 +46,60 @@ function inventoryDir(env = process.env) {
41
46
  function hubPath(env = process.env) {
42
47
  return env.MIADI_REPOSITORY_MAPPING_HUB?.trim() || undefined;
43
48
  }
49
+ /**
50
+ * The folders that hold clones on this host, each as `<root>/<owner>/<name>` or
51
+ * `<root>/<name>`: `MIADI_REPOSITORY_CLONES`, colon-separated. Unset, the
52
+ * folders around the hub clone: `…/repos/jgwill/jgwill` sits beside its owner's
53
+ * other clones, so its parent holds `<name>` and its grandparent `<owner>/<name>`.
54
+ * With no hub either, none: a repository is then read only from a clone a person names.
55
+ */
56
+ function cloneRoots(env = process.env) {
57
+ const named = env.MIADI_REPOSITORY_CLONES?.split(":").map((root) => root.trim()).filter(Boolean);
58
+ if (named?.length)
59
+ return named;
60
+ const hub = hubPath(env);
61
+ if (!hub)
62
+ return [];
63
+ const clone = (0, node_path_1.resolve)(hub.replace(/\/\.miadi\/repository-mapping\/?$/, ""));
64
+ return [(0, node_path_1.dirname)(clone), (0, node_path_1.dirname)((0, node_path_1.dirname)(clone))];
65
+ }
66
+ /**
67
+ * The clone of a repository under the roots: the first folder that is a git
68
+ * repository whose `origin` names it, compared case-folded. A folder of the
69
+ * right name that is a clone of something else is never read as it.
70
+ */
71
+ async function findRepositoryClone(repository, roots = cloneRoots()) {
72
+ const id = (repository.startsWith("repository:") ? repository : `repository:${repository}`).toLowerCase();
73
+ const [owner, name] = id.slice("repository:".length).split("/");
74
+ if (!owner || !name)
75
+ return undefined;
76
+ for (const root of roots) {
77
+ for (const candidate of [(0, node_path_1.join)(root, owner, name), (0, node_path_1.join)(root, name)]) {
78
+ if (!(0, node_fs_1.existsSync)((0, node_path_1.join)(candidate, ".git")))
79
+ continue;
80
+ if ((await (0, node_1.originRepository)(candidate))?.toLowerCase() === id)
81
+ return candidate;
82
+ }
83
+ // Folder names keep the repository's own spelling (jgwill/Miadi): match the remote, not the case of the path.
84
+ for (const dir of [(0, node_path_1.join)(root, owner), root]) {
85
+ let entries = [];
86
+ try {
87
+ entries = (0, node_fs_1.existsSync)(dir) ? (0, node_fs_1.readdirSync)(dir) : [];
88
+ }
89
+ catch {
90
+ entries = [];
91
+ }
92
+ for (const entry of entries) {
93
+ if (entry.toLowerCase() !== name)
94
+ continue;
95
+ const candidate = (0, node_path_1.join)(dir, entry);
96
+ if ((0, node_fs_1.existsSync)((0, node_path_1.join)(candidate, ".git")) && (await (0, node_1.originRepository)(candidate))?.toLowerCase() === id)
97
+ return candidate;
98
+ }
99
+ }
100
+ }
101
+ return undefined;
102
+ }
44
103
  /** Where repositories live: a host's own readings first, then the readings this package ships. */
45
104
  function readWhere(path = process.env.MIADI_REPOSITORY_HOSTS?.trim() || undefined) {
46
105
  const texts = [];
@@ -102,9 +161,16 @@ function readCapabilities(path = process.env.MIADI_REPOSITORY_CAPABILITIES?.trim
102
161
  const sources = [];
103
162
  if (path) {
104
163
  try {
105
- const parsed = (0, developer_repository_mapping_1.parseJsonl)((0, node_fs_1.readFileSync)(path, "utf8"), capabilities_1.CapabilityFacetSchema, path);
106
- issues.push(...parsed.issues);
107
- sources.push({ rows: parsed.rows, source: path });
164
+ const text = (0, node_fs_1.readFileSync)(path, "utf8");
165
+ if (isRepositoryCapabilityFile(text)) {
166
+ // One line instead of an error on every row: the two files hold different rows.
167
+ issues.push({ severity: "error", file: path, message: exports.OWN_FILE_NOT_A_MAP });
168
+ }
169
+ else {
170
+ const parsed = (0, developer_repository_mapping_1.parseJsonl)(text, capabilities_1.CapabilityFacetSchema, path);
171
+ issues.push(...parsed.issues);
172
+ sources.push({ rows: parsed.rows, source: path });
173
+ }
108
174
  }
109
175
  catch (error) {
110
176
  issues.push({ severity: "error", file: path, message: `capabilities not read: ${error.message}` });
@@ -133,6 +199,18 @@ function readCapabilities(path = process.env.MIADI_REPOSITORY_CAPABILITIES?.trim
133
199
  }
134
200
  return { from: sources.map((s) => s.source), scans: shipped_capabilities_1.SHIPPED_CAPABILITIES_SCANS, capabilities, issues };
135
201
  }
202
+ /** What `--capabilities` and `MIADI_REPOSITORY_CAPABILITIES` are told when they are given a repository's own file. */
203
+ exports.OWN_FILE_NOT_A_MAP = `this is a repository's own ${developer_repository_mapping_1.CAPABILITY_FILE}, not a capability map. A map holds one row per capability and provider, written by "mw-repomap capabilities map <clone>... --out <file>". To read one repository from its clone: miadi-repomap capabilities <owner/name> --clone <clone>`;
204
+ /** True for the text of a repository's own capability file: its first line is that format's header. */
205
+ function isRepositoryCapabilityFile(text) {
206
+ const first = text.replace(/^\uFEFF/, "").split(/\r?\n/, 1)[0] ?? "";
207
+ try {
208
+ return JSON.parse(first)?.schema === developer_repository_mapping_1.CAPABILITY_FILE_SCHEMA;
209
+ }
210
+ catch {
211
+ return false;
212
+ }
213
+ }
136
214
  /** Where a capability stands, `unstated` when nobody has said. */
137
215
  const stageOf = (c) => c.stage?.stage ?? "unstated";
138
216
  exports.stageOf = stageOf;
@@ -141,7 +219,67 @@ exports.stageOf = stageOf;
141
219
  * With `stage`, only the capabilities at that stage: `specified` lists what is written down and not yet built.
142
220
  */
143
221
  function repositoryCapabilities(repository, options = {}) {
222
+ return answerCapabilities(readCapabilities(options.capabilities), repository, options.stage);
223
+ }
224
+ /**
225
+ * Read one repository from its clone on this host: the clone named, else the
226
+ * one found under {@link cloneRoots}. Its own committed capability file first,
227
+ * merged with what the commit's files say, at its default branch as last
228
+ * fetched. Undefined when this host holds no clone of it. A clone named that
229
+ * is another repository's is an error and is not read.
230
+ */
231
+ async function readCloneCapabilities(repository, options = {}) {
232
+ const id = repository.startsWith("repository:") ? repository : `repository:${repository}`;
233
+ const clone = options.clone ?? (await findRepositoryClone(id, options.clones ?? cloneRoots()));
234
+ if (!clone)
235
+ return undefined;
236
+ try {
237
+ const read = await (0, node_1.readRepositoryCapabilities)(clone, { ...(options.ref ? { ref: options.ref } : {}), observedBy: options.observedBy ?? "miadi-repomap" });
238
+ if (read.repository.toLowerCase() !== id.toLowerCase()) {
239
+ return { clone, error: `${clone} is a clone of ${read.repository.replace(/^repository:/, "")}, not of ${id.replace(/^repository:/, "")}` };
240
+ }
241
+ return { clone, repository: read.repository, ref: read.ref, commit: read.commit, source: read.source, capabilities: read.capabilities, issues: read.issues };
242
+ }
243
+ catch (error) {
244
+ return { clone, error: error.message };
245
+ }
246
+ }
247
+ /** A map's rows with one repository's replaced by what its clone says: the clone speaks for its repository. */
248
+ function withClone(read, reading) {
249
+ const id = reading.repository.toLowerCase();
250
+ const others = read.capabilities.filter((c) => !c.providedBy.some((p) => p.toLowerCase() === id));
251
+ const where = `${reading.clone} @ ${reading.commit.slice(0, 12)} (${reading.source === "file" ? `its own ${developer_repository_mapping_1.CAPABILITY_FILE}` : "its files; it holds no capability file"})`;
252
+ return {
253
+ ...read,
254
+ from: [where, ...read.from],
255
+ capabilities: [...reading.capabilities, ...others],
256
+ issues: [...reading.issues.map((i) => ({ ...i, file: `${reading.repository.replace(/^repository:/, "")}:${i.file ?? ""}` })), ...read.issues],
257
+ };
258
+ }
259
+ /**
260
+ * "What does this repository provide?", read from its clone on this host when
261
+ * there is one (jgwill/Miadi#1148): a repository that committed its own
262
+ * capability file is shown as that file says, with no map made by hand. With no
263
+ * clone, or no repository, the answer is {@link repositoryCapabilities}'s.
264
+ */
265
+ async function repositoryCapabilitiesLive(repository, options = {}) {
144
266
  const read = readCapabilities(options.capabilities);
267
+ if (!repository)
268
+ return answerCapabilities(read, repository, options.stage);
269
+ const reading = await readCloneCapabilities(repository, options);
270
+ if (!reading)
271
+ return answerCapabilities(read, repository, options.stage);
272
+ if ("error" in reading) {
273
+ const answer = answerCapabilities(read, repository, options.stage);
274
+ return { ...answer, issues: [{ severity: "error", file: reading.clone, message: `the clone was not read: ${reading.error}` }, ...answer.issues] };
275
+ }
276
+ return {
277
+ ...answerCapabilities(withClone(read, reading), repository, options.stage),
278
+ clone: { clone: reading.clone, ref: reading.ref, commit: reading.commit, source: reading.source },
279
+ };
280
+ }
281
+ function answerCapabilities(read, repository, stage) {
282
+ const options = { stage };
145
283
  const id = repository ? (repository.startsWith("repository:") ? repository : `repository:${repository}`) : undefined;
146
284
  const provided = id ? (0, capabilities_2.capabilitiesOf)(id, read.capabilities) : read.capabilities;
147
285
  const stages = Object.fromEntries([...capabilities_1.CAPABILITY_STAGES, "unstated"].map((k) => [k, 0]));
@@ -263,6 +401,10 @@ async function repositoryListing(options = {}) {
263
401
  }
264
402
  async function repositoryDetail(repository, options = {}) {
265
403
  const read = await readMapper(options);
404
+ // The repository asked about is read from its clone on this host when there is one: its own committed file speaks first.
405
+ const reading = options.live || options.clone ? await readCloneCapabilities(repository, options) : undefined;
406
+ if (reading && !("error" in reading))
407
+ read.capabilities = withClone(read.capabilities, reading);
266
408
  const view = (0, join_1.repositoryView)(repository, read.mapping, read.sessions, read.mapping?.sources, read.lineage.edges, read.capabilities.capabilities, read.where.readings);
267
409
  return { hub: read.hub, inventory: read.inventory, ...(view ? { repository: view } : {}) };
268
410
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/relational-git-repository-mapper",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A git repository as Miadi sees it (git, never a database Repository or Data Mapper): the rows its owner hub holds (@medicine-wheel/developer-repository-mapping) beside the agent sessions that worked in it (the witness team's session inventory), joined by owner/name; which git repository learned from which (a lineage, never a dependency); what each provides, its packages, CLIs and skills as capability nodes; where each lives; and what a version bump touches downstream.",
5
5
  "license": "MIT",
6
6
  "author": "Miadi",
@@ -28,9 +28,9 @@
28
28
  "README.md"
29
29
  ],
30
30
  "dependencies": {
31
- "@medicine-wheel/capabilities": "^0.27.16",
32
- "@medicine-wheel/developer-repository-mapping": "^0.27.16",
33
- "@miadi/hooks-interpreter": "^0.12.0",
31
+ "@medicine-wheel/capabilities": "^0.27.20",
32
+ "@medicine-wheel/developer-repository-mapping": "^0.27.20",
33
+ "@miadi/hooks-interpreter": "^0.15.0",
34
34
  "zod": "^3.23.0"
35
35
  },
36
36
  "devDependencies": {