@miadi/relational-git-repository-mapper 0.2.0 → 0.3.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
@@ -29,26 +29,51 @@ keeper's descriptions and file lists stay in the record.
29
29
  When no hub is configured, or the hub clone holds no mapping folder yet, every repository
30
30
  reads "no mapping yet" and still lists its sessions.
31
31
 
32
+ ## Lineage: which git repository learned from which
33
+
34
+ A lineage is not a dependency. `learned-from` says that one repository took what another
35
+ explored and carries it on its own, sometimes with another way of knowing, without
36
+ importing it. Dependencies (`consumes`) stay in the owner hubs.
37
+
38
+ ```bash
39
+ miadi-repomap lineage jgwill/medicine-wheel # what did the medicine wheel learn from?
40
+ miadi-repomap lineage # every lineage, the whole forest
41
+ ```
42
+
43
+ The rows this package ships come from William's word in Episode 297
44
+ (screenwalk 2610221013, 10:03–11:21): `jgwill/coaiajs` learned from
45
+ `avadisabelle/coaia-narrative`, and `jgwill/medicine-wheel` learned from both. None
46
+ depends on another. Every row is `pending` until William reads it. A host adds or corrects
47
+ rows with a JSONL file (`--lineage <file>` or `MIADI_REPOSITORY_LINEAGE`), read first: the
48
+ first file to name a pair speaks for it. Each row carries the attribution of
49
+ `@medicine-wheel/capabilities`, a `description` of at most 55 words, and
50
+ `"type": "learned-from"`.
51
+
52
+ In the app: `GET /api/repositories/lineage[?repository=owner/name]`, and the `lineage`
53
+ field of `GET /api/repositories/{owner}/{name}`, shown as a Lineage card on its page.
54
+
32
55
  ## Configuration
33
56
 
34
57
  | variable | default | |
35
58
  |---|---|---|
36
59
  | `MIADI_REPOSITORY_MAPPING_HUB` | none | a hub clone (`…/jgwill/jgwill`) or its mapping folder |
37
60
  | `MIADI_SESSION_INVENTORY_DIR` | `~/workspace/.mino/session-inventory` | the inventory records |
61
+ | `MIADI_REPOSITORY_LINEAGE` | none | a lineage JSONL read before the shipped rows |
38
62
 
39
63
  ## CLI
40
64
 
41
65
  ```bash
42
- miadi-repomap list [--hub <path>] [--inventory <dir>] [--json]
43
- miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--json]
66
+ miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
67
+ miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
68
+ miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
44
69
  ```
45
70
 
46
- Exit codes: 0 done, 1 the repository is in no hub and no record, 2 usage error.
71
+ Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
47
72
 
48
73
  ## Library
49
74
 
50
75
  ```ts
51
- import { repositoryListing, repositoryDetail, sessionsByRepository, repositoryView } from "@miadi/relational-repository-mapper"
76
+ import { repositoryListing, repositoryDetail, sessionsByRepository, repositoryView } from "@miadi/relational-git-repository-mapper"
52
77
  ```
53
78
 
54
79
  `sessionsByRepository`, `repositoryView` and `listRepositories` are pure;
package/dist/cli.js CHANGED
@@ -2,21 +2,32 @@
2
2
  "use strict";
3
3
  // miadi-repomap — a repository's mapping rows beside the sessions that worked in it.
4
4
  //
5
- // miadi-repomap list [--hub <path>] [--inventory <dir>] [--json]
6
- // miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--json]
5
+ // miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
6
+ // miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]
7
+ // miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]
7
8
  //
9
+ // `lineage <owner/name>` answers "what did this repository learn from", and
10
+ // who learned from it; with no repository it prints every lineage. A lineage
11
+ // is not a dependency: `learned-from` names what a repository took from
12
+ // another that it carries on its own. --lineage adds a host's JSONL before
13
+ // the rows this package ships (default MIADI_REPOSITORY_LINEAGE).
8
14
  // --hub defaults to MIADI_REPOSITORY_MAPPING_HUB (a jgwill/jgwill clone, or a
9
15
  // mapping folder); --inventory to MIADI_SESSION_INVENTORY_DIR, else
10
16
  // ~/workspace/.mino/session-inventory. Read-only.
11
17
  //
12
- // Exit codes: 0 done, 1 the repository is in no hub and no record, 2 usage error.
18
+ // Exit codes: 0 done, 1 `show`: the repository is in no hub, no record and no lineage, 2 usage error.
13
19
  Object.defineProperty(exports, "__esModule", { value: true });
14
20
  const read_1 = require("./read");
15
21
  const USAGE = [
16
- "usage: miadi-repomap list [--hub <path>] [--inventory <dir>] [--json]",
17
- " miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--json]",
22
+ "usage: miadi-repomap list [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
23
+ " miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--lineage <file>] [--json]",
24
+ " miadi-repomap lineage [<owner/name>] [--lineage <file>] [--json]",
18
25
  ].join("\n");
19
- const FLAGS = { list: ["hub", "inventory", "json"], show: ["hub", "inventory", "json"] };
26
+ const FLAGS = {
27
+ list: ["hub", "inventory", "lineage", "json"],
28
+ show: ["hub", "inventory", "lineage", "json"],
29
+ lineage: ["lineage", "json"],
30
+ };
20
31
  class UsageError extends Error {
21
32
  }
22
33
  function parse(argv) {
@@ -57,6 +68,10 @@ function hubLine(hub) {
57
68
  return `mapping read from ${hub.hubs.length} hub(s): ${hub.errors} errors, ${hub.warnings} warnings`;
58
69
  }
59
70
  }
71
+ const short = (id) => id.replace(/^repository:/, "");
72
+ function linkLines(links) {
73
+ return links.map((l) => ` ${short(l.repository)}${l.description ? ` — ${l.description}` : ""} [${l.revision}]`);
74
+ }
60
75
  function sessionLine(s) {
61
76
  const ending = s.disposition ? ` ending ${s.disposition.decided ?? `${s.disposition.proposed} (proposed)`}` : "";
62
77
  return ` ${s.date ?? "?"} ${(s.tmux_session_name ?? s.session_id).padEnd(36)} ${(s.team ?? "-").padEnd(10)} ${s.status ?? "-"}${ending} ${s.session_id}`;
@@ -68,7 +83,31 @@ async function main() {
68
83
  console.log(USAGE);
69
84
  return 0;
70
85
  }
71
- const options = { hub: value(flags, "hub"), inventory: value(flags, "inventory") };
86
+ const options = { hub: value(flags, "hub"), inventory: value(flags, "inventory"), lineage: value(flags, "lineage") };
87
+ if (command === "lineage") {
88
+ const answer = (0, read_1.repositoryLineage)(positional[1], { lineage: options.lineage });
89
+ for (const i of answer.issues)
90
+ console.error(`${i.severity} ${i.file ?? ""}${i.line ? `:${i.line}` : ""} — ${i.message}`);
91
+ if (flags.json) {
92
+ console.log(JSON.stringify(answer, null, 2));
93
+ return 0;
94
+ }
95
+ if (answer.graph) {
96
+ for (const e of answer.graph.edges)
97
+ console.log(`${short(e.from)} learned from ${short(e.to)}${e.description ? ` — ${e.description}` : ""}`);
98
+ console.error(`${answer.graph.edges.length} lineages among ${answer.graph.nodes.length} repositories, read from ${answer.from.join(", ")}`);
99
+ return 0;
100
+ }
101
+ const l = answer.lineage;
102
+ const lines = [
103
+ `${short(answer.repository)} learned from (${l.learned_from.length}):`,
104
+ ...(l.learned_from.length ? linkLines(l.learned_from) : [" no lineage recorded"]),
105
+ `${short(answer.repository)} taught (${l.taught.length}):`,
106
+ ...(l.taught.length ? linkLines(l.taught) : [" no lineage recorded"]),
107
+ ];
108
+ console.log(lines.join("\n"));
109
+ return 0;
110
+ }
72
111
  if (command === "list") {
73
112
  const listing = await (0, read_1.repositoryListing)(options);
74
113
  if (flags.json) {
@@ -107,6 +146,10 @@ async function main() {
107
146
  ...r.features.map((f) => ` ${f.nodeId} [${f.status}]${f.statement ? ` ${f.statement}` : ""}`),
108
147
  r.relations.length ? ` relations (${r.relations.length}):` : "",
109
148
  ...r.relations.map((x) => ` ${x.from} ${x.type} ${x.to}`),
149
+ r.lineage.learned_from.length ? ` learned from (${r.lineage.learned_from.length}):` : "",
150
+ ...linkLines(r.lineage.learned_from),
151
+ r.lineage.taught.length ? ` taught (${r.lineage.taught.length}):` : "",
152
+ ...linkLines(r.lineage.taught),
110
153
  ` sessions (${r.sessions.length}):`,
111
154
  ...r.sessions.map(sessionLine),
112
155
  ];
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export type { RepositorySession, MappingState, HubState, RepositoryView, RepositorySummary, InventoryState, RepositoryListing, } from "./types";
2
2
  export { dayOf, teamOf, dispositionOf, sessionOf, repositoryKey, sessionsByRepository, repositoryView, listRepositories, type SessionsByRepository, } from "./join";
3
- export { inventoryDir, hubPath, readHubState, readMapper, repositoryListing, repositoryDetail, type ReadOptions, type MapperRead, } from "./read";
3
+ export { LineageRowSchema, parseLineage, lineageOf, lineageGraph, type LineageRow, type LineageEdge, type LineageLink, type RepositoryLineage, type LineageGraph, } from "./lineage";
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";
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.repositoryDetail = exports.repositoryListing = exports.readMapper = exports.readHubState = exports.hubPath = exports.inventoryDir = exports.listRepositories = exports.repositoryView = exports.sessionsByRepository = exports.repositoryKey = exports.sessionOf = exports.dispositionOf = exports.teamOf = exports.dayOf = void 0;
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;
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; } });
@@ -14,6 +14,14 @@ Object.defineProperty(exports, "repositoryKey", { enumerable: true, get: functio
14
14
  Object.defineProperty(exports, "sessionsByRepository", { enumerable: true, get: function () { return join_1.sessionsByRepository; } });
15
15
  Object.defineProperty(exports, "repositoryView", { enumerable: true, get: function () { return join_1.repositoryView; } });
16
16
  Object.defineProperty(exports, "listRepositories", { enumerable: true, get: function () { return join_1.listRepositories; } });
17
+ var lineage_1 = require("./lineage");
18
+ Object.defineProperty(exports, "LineageRowSchema", { enumerable: true, get: function () { return lineage_1.LineageRowSchema; } });
19
+ Object.defineProperty(exports, "parseLineage", { enumerable: true, get: function () { return lineage_1.parseLineage; } });
20
+ Object.defineProperty(exports, "lineageOf", { enumerable: true, get: function () { return lineage_1.lineageOf; } });
21
+ Object.defineProperty(exports, "lineageGraph", { enumerable: true, get: function () { return lineage_1.lineageGraph; } });
22
+ var shipped_lineage_1 = require("./shipped-lineage");
23
+ Object.defineProperty(exports, "SHIPPED_LINEAGE_JSONL", { enumerable: true, get: function () { return shipped_lineage_1.SHIPPED_LINEAGE_JSONL; } });
24
+ Object.defineProperty(exports, "SHIPPED_LINEAGE_SOURCE", { enumerable: true, get: function () { return shipped_lineage_1.SHIPPED_LINEAGE_SOURCE; } });
17
25
  var read_1 = require("./read");
18
26
  Object.defineProperty(exports, "inventoryDir", { enumerable: true, get: function () { return read_1.inventoryDir; } });
19
27
  Object.defineProperty(exports, "hubPath", { enumerable: true, get: function () { return read_1.hubPath; } });
@@ -21,3 +29,5 @@ Object.defineProperty(exports, "readHubState", { enumerable: true, get: function
21
29
  Object.defineProperty(exports, "readMapper", { enumerable: true, get: function () { return read_1.readMapper; } });
22
30
  Object.defineProperty(exports, "repositoryListing", { enumerable: true, get: function () { return read_1.repositoryListing; } });
23
31
  Object.defineProperty(exports, "repositoryDetail", { enumerable: true, get: function () { return read_1.repositoryDetail; } });
32
+ Object.defineProperty(exports, "readLineage", { enumerable: true, get: function () { return read_1.readLineage; } });
33
+ Object.defineProperty(exports, "repositoryLineage", { enumerable: true, get: function () { return read_1.repositoryLineage; } });
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 LineageEdge } from "./lineage";
3
4
  import type { RepositorySession, RepositorySummary, RepositoryView } from "./types";
4
5
  /** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
5
6
  export declare function dayOf(date: string | undefined): string | undefined;
@@ -19,9 +20,9 @@ export interface SessionsByRepository {
19
20
  }
20
21
  export declare function sessionsByRepository(records: ReadonlyMap<string, InventorySnapshot>): SessionsByRepository;
21
22
  /**
22
- * One repository: its rows when a hub holds them, and its sessions. Undefined
23
- * when neither a hub nor any record names it.
23
+ * One repository: its rows when a hub holds them, its sessions, and its
24
+ * lineage. Undefined when no hub, no record and no lineage names it.
24
25
  */
25
- export declare function repositoryView(repository: string, mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, sources?: Record<string, string>): RepositoryView | undefined;
26
- /** Every repository a hub holds or a record names, most sessions first. */
27
- export declare function listRepositories(mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository): RepositorySummary[];
26
+ export declare function repositoryView(repository: string, mapping: RepositoryMapping | undefined, bySessions: SessionsByRepository, sources?: Record<string, string>, lineageEdges?: readonly LineageEdge[]): RepositoryView | undefined;
27
+ /** 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[];
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 lineage_1 = require("./lineage");
16
17
  const text = (value) => (typeof value === "string" && value.trim() ? value : undefined);
17
18
  /** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
18
19
  function dayOf(date) {
@@ -75,18 +76,20 @@ function sessionsByRepository(records) {
75
76
  }
76
77
  const keyOfNode = (nodeId) => nodeId.slice("repository:".length).toLowerCase();
77
78
  /**
78
- * One repository: its rows when a hub holds them, and its sessions. Undefined
79
- * when neither a hub nor any record names it.
79
+ * One repository: its rows when a hub holds them, its sessions, and its
80
+ * lineage. Undefined when no hub, no record and no lineage names it.
80
81
  */
81
- function repositoryView(repository, mapping, bySessions, sources = {}) {
82
+ function repositoryView(repository, mapping, bySessions, sources = {}, lineageEdges = []) {
82
83
  const key = repositoryKey(repository);
83
84
  if (!key)
84
85
  return undefined;
85
86
  const row = mapping?.repositories.find((r) => keyOfNode(r.nodeId) === key);
86
87
  const sessions = bySessions.sessions.get(key) ?? [];
87
- if (!row && !sessions.length)
88
+ const lineage = (0, lineage_1.lineageOf)(key, lineageEdges);
89
+ const named = lineageEdges.flatMap((e) => [e.from, e.to]).find((id) => keyOfNode(id) === key);
90
+ if (!row && !sessions.length && !named)
88
91
  return undefined;
89
- const nodeId = row?.nodeId ?? `repository:${bySessions.spelled.get(key) ?? key}`;
92
+ const nodeId = row?.nodeId ?? named ?? `repository:${bySessions.spelled.get(key) ?? key}`;
90
93
  const { owner, name } = (0, developer_repository_mapping_1.parseRepositoryNodeId)(nodeId);
91
94
  return {
92
95
  nodeId,
@@ -99,14 +102,19 @@ function repositoryView(repository, mapping, bySessions, sources = {}) {
99
102
  features: row ? mapping.features.filter((f) => f.repository === row.nodeId) : [],
100
103
  relations: row ? mapping.relations.filter((r) => r.from === row.nodeId || r.to === row.nodeId) : [],
101
104
  sessions,
105
+ lineage,
102
106
  };
103
107
  }
104
- /** Every repository a hub holds or a record names, most sessions first. */
105
- function listRepositories(mapping, bySessions) {
106
- const keys = new Set([...bySessions.sessions.keys(), ...(mapping?.repositories ?? []).map((r) => keyOfNode(r.nodeId))]);
108
+ /** Every repository a hub holds, a record names or a lineage names, most sessions first. */
109
+ function listRepositories(mapping, bySessions, lineageEdges = []) {
110
+ const keys = new Set([
111
+ ...bySessions.sessions.keys(),
112
+ ...(mapping?.repositories ?? []).map((r) => keyOfNode(r.nodeId)),
113
+ ...lineageEdges.flatMap((e) => [keyOfNode(e.from), keyOfNode(e.to)]),
114
+ ]);
107
115
  return [...keys]
108
116
  .map((key) => {
109
- const view = repositoryView(key, mapping, bySessions);
117
+ const view = repositoryView(key, mapping, bySessions, {}, lineageEdges);
110
118
  const teams = [...new Set(view.sessions.flatMap((s) => (s.team ? [s.team] : [])))].sort();
111
119
  return {
112
120
  nodeId: view.nodeId,
@@ -0,0 +1,105 @@
1
+ import { z } from "zod";
2
+ import { type MappingIssue } from "@medicine-wheel/developer-repository-mapping";
3
+ export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
4
+ statedBy: z.ZodString;
5
+ statedAt: z.ZodString;
6
+ grounding: z.ZodArray<z.ZodString, "many">;
7
+ revision: z.ZodEnum<["pending", "revised", "affirmed"]>;
8
+ revisedBy: z.ZodOptional<z.ZodString>;
9
+ revisedAt: z.ZodOptional<z.ZodString>;
10
+ /** the repository that learned */
11
+ from: z.ZodString;
12
+ /** the repository it learned from */
13
+ to: z.ZodString;
14
+ type: z.ZodLiteral<"learned-from">;
15
+ /** what was learned, at most 55 words */
16
+ description: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
17
+ }, "strict", z.ZodTypeAny, {
18
+ from: string;
19
+ to: string;
20
+ type: "learned-from";
21
+ statedBy: string;
22
+ statedAt: string;
23
+ grounding: string[];
24
+ revision: "pending" | "revised" | "affirmed";
25
+ description?: string | undefined;
26
+ revisedBy?: string | undefined;
27
+ revisedAt?: string | undefined;
28
+ }, {
29
+ from: string;
30
+ to: string;
31
+ type: "learned-from";
32
+ statedBy: string;
33
+ statedAt: string;
34
+ grounding: string[];
35
+ revision: "pending" | "revised" | "affirmed";
36
+ description?: string | undefined;
37
+ revisedBy?: string | undefined;
38
+ revisedAt?: string | undefined;
39
+ }>, {
40
+ from: string;
41
+ to: string;
42
+ type: "learned-from";
43
+ statedBy: string;
44
+ statedAt: string;
45
+ grounding: string[];
46
+ revision: "pending" | "revised" | "affirmed";
47
+ description?: string | undefined;
48
+ revisedBy?: string | undefined;
49
+ revisedAt?: string | undefined;
50
+ }, {
51
+ from: string;
52
+ to: string;
53
+ type: "learned-from";
54
+ statedBy: string;
55
+ statedAt: string;
56
+ grounding: string[];
57
+ revision: "pending" | "revised" | "affirmed";
58
+ description?: string | undefined;
59
+ revisedBy?: string | undefined;
60
+ revisedAt?: string | undefined;
61
+ }>;
62
+ /** One `learned-from` row: `from` learned from `to`. */
63
+ export type LineageRow = z.infer<typeof LineageRowSchema>;
64
+ /** A lineage row and the file it was read from. */
65
+ export interface LineageEdge extends LineageRow {
66
+ source: string;
67
+ }
68
+ /** One end of a lineage, seen from a repository. */
69
+ export interface LineageLink {
70
+ /** the other repository */
71
+ repository: string;
72
+ description?: string;
73
+ statedBy: string;
74
+ statedAt: string;
75
+ grounding: string[];
76
+ revision: LineageRow["revision"];
77
+ source: string;
78
+ }
79
+ export interface RepositoryLineage {
80
+ /** what this repository learned from */
81
+ learned_from: LineageLink[];
82
+ /** the repositories that learned from this one */
83
+ taught: LineageLink[];
84
+ }
85
+ export interface LineageGraph {
86
+ /** every repository a lineage names, sorted */
87
+ nodes: string[];
88
+ edges: LineageEdge[];
89
+ }
90
+ /**
91
+ * Lineage rows from several JSONL texts, in precedence order: the first text
92
+ * that names a pair speaks for it, and a later row on the same pair is
93
+ * reported and skipped. Never throws.
94
+ */
95
+ export declare function parseLineage(texts: readonly {
96
+ text: string;
97
+ source: string;
98
+ }[]): {
99
+ edges: LineageEdge[];
100
+ issues: MappingIssue[];
101
+ };
102
+ /** What a repository learned from, and who learned from it. Matched case-folded. */
103
+ export declare function lineageOf(repository: string, edges: readonly LineageEdge[]): RepositoryLineage;
104
+ /** The whole forest: every repository a lineage names, and every edge. */
105
+ export declare function lineageGraph(edges: readonly LineageEdge[]): LineageGraph;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ // Lineage, pure: which git repository learned from which.
3
+ //
4
+ // A lineage is not a dependency. A repository that learned from another
5
+ // may import nothing from it: it took what the other explored and carries it
6
+ // on its own, sometimes with another way of knowing. A dependency is
7
+ // `consumes` in an owner hub's relations; a lineage is `learned-from`, here.
8
+ // William, screenwalk 2610221013 (Episode 297, V5 and V6): a forest of trees
9
+ // that grew independently of each other, influenced into their relationship,
10
+ // as a graph a model can navigate.
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LineageRowSchema = void 0;
13
+ exports.parseLineage = parseLineage;
14
+ exports.lineageOf = lineageOf;
15
+ exports.lineageGraph = lineageGraph;
16
+ const zod_1 = require("zod");
17
+ const capabilities_1 = require("@medicine-wheel/capabilities");
18
+ const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
19
+ exports.LineageRowSchema = zod_1.z
20
+ .object({
21
+ /** the repository that learned */
22
+ from: developer_repository_mapping_1.RepositoryNodeIdSchema,
23
+ /** the repository it learned from */
24
+ to: developer_repository_mapping_1.RepositoryNodeIdSchema,
25
+ type: zod_1.z.literal("learned-from"),
26
+ /** what was learned, at most 55 words */
27
+ description: capabilities_1.StatementSchema.optional(),
28
+ ...capabilities_1.attributionShape,
29
+ })
30
+ .strict()
31
+ .superRefine((row, ctx) => {
32
+ (0, capabilities_1.refineAttribution)(row, ctx);
33
+ if (row.from.toLowerCase() === row.to.toLowerCase()) {
34
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ["to"], message: "a repository does not learn from itself" });
35
+ }
36
+ });
37
+ const fold = (id) => id.toLowerCase();
38
+ const edgeKey = (row) => `${fold(row.from)} ${fold(row.to)}`;
39
+ /**
40
+ * Lineage rows from several JSONL texts, in precedence order: the first text
41
+ * that names a pair speaks for it, and a later row on the same pair is
42
+ * reported and skipped. Never throws.
43
+ */
44
+ function parseLineage(texts) {
45
+ const edges = [];
46
+ const issues = [];
47
+ const seen = new Map();
48
+ for (const { text, source } of texts) {
49
+ const parsed = (0, developer_repository_mapping_1.parseJsonl)(text, exports.LineageRowSchema, source);
50
+ issues.push(...parsed.issues);
51
+ for (const row of parsed.rows) {
52
+ const key = edgeKey(row);
53
+ const earlier = seen.get(key);
54
+ if (earlier) {
55
+ issues.push({ severity: "warning", file: source, nodeId: row.from, message: `${row.from} learned-from ${row.to} is already read from ${earlier}; skipped` });
56
+ continue;
57
+ }
58
+ seen.set(key, source);
59
+ edges.push({ ...row, source });
60
+ }
61
+ }
62
+ return { edges, issues };
63
+ }
64
+ const linkOf = (edge, repository) => ({
65
+ repository,
66
+ ...(edge.description ? { description: edge.description } : {}),
67
+ statedBy: edge.statedBy,
68
+ statedAt: edge.statedAt,
69
+ grounding: edge.grounding,
70
+ revision: edge.revision,
71
+ source: edge.source,
72
+ });
73
+ /** What a repository learned from, and who learned from it. Matched case-folded. */
74
+ function lineageOf(repository, edges) {
75
+ const id = fold(repository.startsWith("repository:") ? repository : `repository:${repository}`);
76
+ const byRepository = (a, b) => a.repository.toLowerCase().localeCompare(b.repository.toLowerCase());
77
+ return {
78
+ learned_from: edges.filter((e) => fold(e.from) === id).map((e) => linkOf(e, e.to)).sort(byRepository),
79
+ taught: edges.filter((e) => fold(e.to) === id).map((e) => linkOf(e, e.from)).sort(byRepository),
80
+ };
81
+ }
82
+ /** The whole forest: every repository a lineage names, and every edge. */
83
+ function lineageGraph(edges) {
84
+ const nodes = new Map();
85
+ for (const e of edges) {
86
+ for (const id of [e.from, e.to])
87
+ if (!nodes.has(fold(id)))
88
+ nodes.set(fold(id), id);
89
+ }
90
+ return {
91
+ nodes: [...nodes.values()].sort((a, b) => fold(a).localeCompare(fold(b))),
92
+ edges: [...edges],
93
+ };
94
+ }
package/dist/read.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { MergedMapping } from "@medicine-wheel/developer-repository-mapping";
1
+ import type { MappingIssue, MergedMapping } from "@medicine-wheel/developer-repository-mapping";
2
2
  import { type SessionsByRepository } from "./join";
3
+ import { type LineageEdge, type LineageGraph, type RepositoryLineage } from "./lineage";
3
4
  import type { HubState, InventoryState, RepositoryListing, RepositoryView } from "./types";
4
5
  type Env = Record<string, string | undefined>;
5
6
  /** The witness team's inventory: `MIADI_SESSION_INVENTORY_DIR`, else `~/workspace/.mino/session-inventory`. */
@@ -11,7 +12,21 @@ export interface ReadOptions {
11
12
  hub?: string;
12
13
  /** inventory directory; default {@link inventoryDir} */
13
14
  inventory?: string;
15
+ /** a lineage JSONL read before the shipped one; default `MIADI_REPOSITORY_LINEAGE` */
16
+ lineage?: string;
14
17
  }
18
+ export interface LineageRead {
19
+ /** the files read, in precedence order */
20
+ from: string[];
21
+ edges: LineageEdge[];
22
+ issues: MappingIssue[];
23
+ }
24
+ /**
25
+ * The lineage: a host's own file first (`--lineage` or
26
+ * `MIADI_REPOSITORY_LINEAGE`), then the rows this package ships. The first
27
+ * to name a pair speaks for it. A file that cannot be read is reported.
28
+ */
29
+ export declare function readLineage(path?: string | undefined): LineageRead;
15
30
  export declare function readHubState(path: string | undefined): Promise<{
16
31
  hub: HubState;
17
32
  mapping?: MergedMapping;
@@ -21,6 +36,7 @@ export interface MapperRead {
21
36
  mapping?: MergedMapping;
22
37
  inventory: InventoryState;
23
38
  sessions: SessionsByRepository;
39
+ lineage: LineageRead;
24
40
  }
25
41
  export declare function readMapper(options?: ReadOptions): Promise<MapperRead>;
26
42
  export declare function repositoryListing(options?: ReadOptions): Promise<RepositoryListing>;
@@ -29,4 +45,16 @@ export declare function repositoryDetail(repository: string, options?: ReadOptio
29
45
  inventory: InventoryState;
30
46
  repository?: RepositoryView;
31
47
  }>;
48
+ export interface LineageAnswer {
49
+ /** the files the lineage was read from, in precedence order */
50
+ from: string[];
51
+ issues: MappingIssue[];
52
+ /** with a repository: what it learned from and who learned from it */
53
+ repository?: string;
54
+ lineage?: RepositoryLineage;
55
+ /** without one: the whole forest */
56
+ graph?: LineageGraph;
57
+ }
58
+ /** "What did this repository learn from?", or with no repository, every lineage. Reads no hub and no inventory. */
59
+ export declare function repositoryLineage(repository?: string, options?: Pick<ReadOptions, "lineage">): LineageAnswer;
32
60
  export {};
package/dist/read.js CHANGED
@@ -5,15 +5,20 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.inventoryDir = inventoryDir;
7
7
  exports.hubPath = hubPath;
8
+ exports.readLineage = readLineage;
8
9
  exports.readHubState = readHubState;
9
10
  exports.readMapper = readMapper;
10
11
  exports.repositoryListing = repositoryListing;
11
12
  exports.repositoryDetail = repositoryDetail;
13
+ exports.repositoryLineage = repositoryLineage;
14
+ const node_fs_1 = require("node:fs");
15
+ const shipped_lineage_1 = require("./shipped-lineage");
12
16
  const node_os_1 = require("node:os");
13
17
  const node_path_1 = require("node:path");
14
18
  const node_1 = require("@medicine-wheel/developer-repository-mapping/node");
15
19
  const hooks_interpreter_1 = require("@miadi/hooks-interpreter");
16
20
  const join_1 = require("./join");
21
+ const lineage_1 = require("./lineage");
17
22
  /** The witness team's inventory: `MIADI_SESSION_INVENTORY_DIR`, else `~/workspace/.mino/session-inventory`. */
18
23
  function inventoryDir(env = process.env) {
19
24
  return env.MIADI_SESSION_INVENTORY_DIR?.trim() || (0, node_path_1.join)((0, node_os_1.homedir)(), "workspace", ".mino", "session-inventory");
@@ -22,6 +27,26 @@ function inventoryDir(env = process.env) {
22
27
  function hubPath(env = process.env) {
23
28
  return env.MIADI_REPOSITORY_MAPPING_HUB?.trim() || undefined;
24
29
  }
30
+ /**
31
+ * The lineage: a host's own file first (`--lineage` or
32
+ * `MIADI_REPOSITORY_LINEAGE`), then the rows this package ships. The first
33
+ * to name a pair speaks for it. A file that cannot be read is reported.
34
+ */
35
+ function readLineage(path = process.env.MIADI_REPOSITORY_LINEAGE?.trim() || undefined) {
36
+ const texts = [];
37
+ const unread = [];
38
+ if (path) {
39
+ try {
40
+ texts.push({ text: (0, node_fs_1.readFileSync)(path, "utf8"), source: path });
41
+ }
42
+ catch (error) {
43
+ unread.push({ severity: "error", file: path, message: `lineage not read: ${error.message}` });
44
+ }
45
+ }
46
+ texts.push({ text: shipped_lineage_1.SHIPPED_LINEAGE_JSONL, source: shipped_lineage_1.SHIPPED_LINEAGE_SOURCE });
47
+ const parsed = (0, lineage_1.parseLineage)(texts);
48
+ return { from: [...(path ? [path] : []), shipped_lineage_1.SHIPPED_LINEAGE_SOURCE], edges: parsed.edges, issues: [...unread, ...parsed.issues] };
49
+ }
25
50
  async function readHubState(path) {
26
51
  if (!path)
27
52
  return { hub: { state: "no-hub", hubs: [], errors: 0, warnings: 0 } };
@@ -44,14 +69,24 @@ async function readMapper(options = {}) {
44
69
  ...(mapping ? { mapping } : {}),
45
70
  inventory: { from, records: sessions.records, without_repo: sessions.withoutRepo },
46
71
  sessions,
72
+ lineage: readLineage(options.lineage),
47
73
  };
48
74
  }
49
75
  async function repositoryListing(options = {}) {
50
76
  const read = await readMapper(options);
51
- return { hub: read.hub, inventory: read.inventory, repositories: (0, join_1.listRepositories)(read.mapping, read.sessions) };
77
+ return { hub: read.hub, inventory: read.inventory, repositories: (0, join_1.listRepositories)(read.mapping, read.sessions, read.lineage.edges) };
52
78
  }
53
79
  async function repositoryDetail(repository, options = {}) {
54
80
  const read = await readMapper(options);
55
- const view = (0, join_1.repositoryView)(repository, read.mapping, read.sessions, read.mapping?.sources);
81
+ const view = (0, join_1.repositoryView)(repository, read.mapping, read.sessions, read.mapping?.sources, read.lineage.edges);
56
82
  return { hub: read.hub, inventory: read.inventory, ...(view ? { repository: view } : {}) };
57
83
  }
84
+ /** "What did this repository learn from?", or with no repository, every lineage. Reads no hub and no inventory. */
85
+ function repositoryLineage(repository, options = {}) {
86
+ const read = readLineage(options.lineage);
87
+ const base = { from: read.from, issues: read.issues };
88
+ if (!repository)
89
+ return { ...base, graph: (0, lineage_1.lineageGraph)(read.edges) };
90
+ const id = repository.startsWith("repository:") ? repository : `repository:${repository}`;
91
+ return { ...base, repository: id, lineage: (0, lineage_1.lineageOf)(id, read.edges) };
92
+ }
@@ -0,0 +1,2 @@
1
+ export declare const SHIPPED_LINEAGE_SOURCE = "@miadi/relational-git-repository-mapper (shipped)";
2
+ export declare const SHIPPED_LINEAGE_JSONL = "{\"from\":\"repository:jgwill/coaiajs\",\"to\":\"repository:avadisabelle/coaia-narrative\",\"type\":\"learned-from\",\"description\":\"coaiajs holds what the coaia-narrative prototype explored, the narrative context protocol applied to structural tension charts, plus more, and works on its own. Neither depends on the other.\",\"statedBy\":\"William, screenwalk 2610221013, transcribed by mw-rwl-repo (claude-opus-5-5)\",\"statedAt\":\"2026-10-22T10:13:00-04:00\",\"grounding\":[\"miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/transcription-gemini.txt 10:03-10:20, 10:49-11:10\",\"miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/feedback-map.md V5\"],\"revision\":\"pending\"}\n{\"from\":\"repository:jgwill/medicine-wheel\",\"to\":\"repository:avadisabelle/coaia-narrative\",\"type\":\"learned-from\",\"description\":\"The medicine wheel learns from coaia-narrative's exploration of the narrative context protocol on structural tension charts, to implement the same thing with a different way of knowing. It does not depend on coaia-narrative.\",\"statedBy\":\"William, screenwalk 2610221013, transcribed by mw-rwl-repo (claude-opus-5-5)\",\"statedAt\":\"2026-10-22T10:13:00-04:00\",\"grounding\":[\"miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/transcription-gemini.txt 10:49-11:21\",\"miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/feedback-map.md V5\"],\"revision\":\"pending\"}\n{\"from\":\"repository:jgwill/medicine-wheel\",\"to\":\"repository:jgwill/coaiajs\",\"type\":\"learned-from\",\"description\":\"The medicine wheel learns from coaiajs, which holds coaia-narrative's work and more, to implement the same thing with a different way of knowing. It does not depend on coaiajs.\",\"statedBy\":\"William, screenwalk 2610221013, transcribed by mw-rwl-repo (claude-opus-5-5)\",\"statedAt\":\"2026-10-22T10:13:00-04:00\",\"grounding\":[\"miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/transcription-gemini.txt 11:03-11:21\",\"miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/feedback-map.md V5\"],\"revision\":\"pending\"}\n";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // The lineage this package ships: rows recorded from William's word, read
3
+ // after a host's own file (`--lineage`, `MIADI_REPOSITORY_LINEAGE`). Kept as a module, not a file beside dist/, so it
4
+ // travels with the code into a bundle. One JSON row per line, as in a hub.
5
+ //
6
+ // Source: Episode 297, screenwalk 2610221013 at 10:03-11:21, and the feedback
7
+ // map's V5 and V6. Three lineages applying one principle, none depending on
8
+ // another. Every row is pending until William reads it.
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SHIPPED_LINEAGE_JSONL = exports.SHIPPED_LINEAGE_SOURCE = void 0;
11
+ exports.SHIPPED_LINEAGE_SOURCE = "@miadi/relational-git-repository-mapper (shipped)";
12
+ exports.SHIPPED_LINEAGE_JSONL = `{"from":"repository:jgwill/coaiajs","to":"repository:avadisabelle/coaia-narrative","type":"learned-from","description":"coaiajs holds what the coaia-narrative prototype explored, the narrative context protocol applied to structural tension charts, plus more, and works on its own. Neither depends on the other.","statedBy":"William, screenwalk 2610221013, transcribed by mw-rwl-repo (claude-opus-5-5)","statedAt":"2026-10-22T10:13:00-04:00","grounding":["miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/transcription-gemini.txt 10:03-10:20, 10:49-11:10","miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/feedback-map.md V5"],"revision":"pending"}
13
+ {"from":"repository:jgwill/medicine-wheel","to":"repository:avadisabelle/coaia-narrative","type":"learned-from","description":"The medicine wheel learns from coaia-narrative's exploration of the narrative context protocol on structural tension charts, to implement the same thing with a different way of knowing. It does not depend on coaia-narrative.","statedBy":"William, screenwalk 2610221013, transcribed by mw-rwl-repo (claude-opus-5-5)","statedAt":"2026-10-22T10:13:00-04:00","grounding":["miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/transcription-gemini.txt 10:49-11:21","miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/feedback-map.md V5"],"revision":"pending"}
14
+ {"from":"repository:jgwill/medicine-wheel","to":"repository:jgwill/coaiajs","type":"learned-from","description":"The medicine wheel learns from coaiajs, which holds coaia-narrative's work and more, to implement the same thing with a different way of knowing. It does not depend on coaiajs.","statedBy":"William, screenwalk 2610221013, transcribed by mw-rwl-repo (claude-opus-5-5)","statedAt":"2026-10-22T10:13:00-04:00","grounding":["miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/transcription-gemini.txt 11:03-11:21","miadi-chronicle://297 captures/screenwalk-2610221013-DD-VideoExplainerFeedback-001/feedback-map.md V5"],"revision":"pending"}
15
+ `;
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { FeatureFacet, LifecycleReading, RelationRow, RepositoryFacet } from "@medicine-wheel/developer-repository-mapping";
2
2
  import type { HubStatus } from "@medicine-wheel/developer-repository-mapping/node";
3
+ import type { RepositoryLineage } from "./lineage";
3
4
  /** One session that worked in a repository, as its inventory record says it, by title. */
4
5
  export interface RepositorySession {
5
6
  session_id: string;
@@ -55,6 +56,8 @@ export interface RepositoryView {
55
56
  relations: RelationRow[];
56
57
  /** newest first */
57
58
  sessions: RepositorySession[];
59
+ /** what it learned from, and who learned from it */
60
+ lineage: RepositoryLineage;
58
61
  }
59
62
  export interface RepositorySummary {
60
63
  nodeId: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@miadi/relational-git-repository-mapper",
3
- "version": "0.2.0",
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.",
3
+ "version": "0.3.0",
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; and which git repository learned from which (a lineage, never a dependency).",
5
5
  "license": "MIT",
6
6
  "author": "Miadi",
7
7
  "homepage": "https://github.com/jgwill/Miadi/tree/main/packages/relational-git-repository-mapper",
@@ -28,8 +28,10 @@
28
28
  "README.md"
29
29
  ],
30
30
  "dependencies": {
31
+ "@medicine-wheel/capabilities": "^0.25.0",
31
32
  "@medicine-wheel/developer-repository-mapping": "^0.25.0",
32
- "@miadi/hooks-interpreter": "^0.7.0"
33
+ "@miadi/hooks-interpreter": "^0.7.0",
34
+ "zod": "^3.23.0"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@types/node": "^22.0.0",
@@ -44,6 +46,7 @@
44
46
  "keywords": [
45
47
  "miadi",
46
48
  "git-repository",
49
+ "lineage",
47
50
  "repository-mapping",
48
51
  "session-inventory",
49
52
  "medicine-wheel",