@miadi/relational-git-repository-mapper 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +130 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +23 -0
- package/dist/join.d.ts +27 -0
- package/dist/join.js +124 -0
- package/dist/read.d.ts +32 -0
- package/dist/read.js +57 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +7 -0
- package/package.json +54 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Miadi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @miadi/relational-git-repository-mapper
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A git repository as Miadi sees it: the rows its owner's hub holds, beside the agent
|
|
4
|
+
sessions that worked in it.
|
|
5
|
+
|
|
6
|
+
**"Repository" in this package always means a git repository**: a project such as
|
|
7
|
+
`jgwill/Miadi`, cloned, committed to, pushed. It never means a database repository: not
|
|
8
|
+
the DDD Repository pattern, not a Data Mapper, not a persistence layer. Nothing here
|
|
9
|
+
stores records in a database. The name leaves out GitHub on purpose: today the owners
|
|
10
|
+
and names are GitHub's, and the mapping is meant to hold other git hosts too.
|
|
11
|
+
|
|
12
|
+
Formerly `@miadi/relational-repository-mapper` (0.1.x, deprecated on npm in favour of this
|
|
13
|
+
package). The CLI keeps its name, `miadi-repomap`.
|
|
14
|
+
|
|
15
|
+
- **The rows** come from a repository mapping hub, read with
|
|
16
|
+
[`@medicine-wheel/developer-repository-mapping`](https://www.npmjs.com/package/@medicine-wheel/developer-repository-mapping):
|
|
17
|
+
`<owner>/<owner>/.miadi/repository-mapping/`, and for a meta hub (`jgwill/jgwill`) every hub
|
|
18
|
+
it registers. Lifecycle, purpose, git drift, features, relations.
|
|
19
|
+
- **The sessions** come from the witness team's session inventory, read with
|
|
20
|
+
`@miadi/hooks-interpreter` (`readInventoryRecords`): one record per Claude session.
|
|
21
|
+
- **The join**: a record's `repo` (`owner/name`), case-folded, matched to
|
|
22
|
+
`repository:<owner>/<name>`. Records without a `repo` are counted, not shown.
|
|
23
|
+
|
|
24
|
+
Per session it carries `session_id`, `tmux_session_name`, `status`, the team
|
|
25
|
+
(`team_fit.team.id`, else `team`), `mission`, `date` (as YYYY-MM-DD), the titles of `work_completed`, the
|
|
26
|
+
ending (`disposition.proposed`, `disposition.decided`) and `links.evidence` refs. The
|
|
27
|
+
keeper's descriptions and file lists stay in the record.
|
|
28
|
+
|
|
29
|
+
When no hub is configured, or the hub clone holds no mapping folder yet, every repository
|
|
30
|
+
reads "no mapping yet" and still lists its sessions.
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
| variable | default | |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| `MIADI_REPOSITORY_MAPPING_HUB` | none | a hub clone (`…/jgwill/jgwill`) or its mapping folder |
|
|
37
|
+
| `MIADI_SESSION_INVENTORY_DIR` | `~/workspace/.mino/session-inventory` | the inventory records |
|
|
38
|
+
|
|
39
|
+
## CLI
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
miadi-repomap list [--hub <path>] [--inventory <dir>] [--json]
|
|
43
|
+
miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--json]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Exit codes: 0 done, 1 the repository is in no hub and no record, 2 usage error.
|
|
47
|
+
|
|
48
|
+
## Library
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { repositoryListing, repositoryDetail, sessionsByRepository, repositoryView } from "@miadi/relational-repository-mapper"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`sessionsByRepository`, `repositoryView` and `listRepositories` are pure;
|
|
55
|
+
`repositoryListing` and `repositoryDetail` read the hub and the inventory.
|
|
56
|
+
|
|
57
|
+
In the Miadi app: `GET /api/repositories`, `GET /api/repositories/{owner}/{name}` (write
|
|
58
|
+
access, as session missions are), and the pages `/repositories` and
|
|
59
|
+
`/repositories/{owner}/{name}`.
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// miadi-repomap — a repository's mapping rows beside the sessions that worked in it.
|
|
4
|
+
//
|
|
5
|
+
// miadi-repomap list [--hub <path>] [--inventory <dir>] [--json]
|
|
6
|
+
// miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--json]
|
|
7
|
+
//
|
|
8
|
+
// --hub defaults to MIADI_REPOSITORY_MAPPING_HUB (a jgwill/jgwill clone, or a
|
|
9
|
+
// mapping folder); --inventory to MIADI_SESSION_INVENTORY_DIR, else
|
|
10
|
+
// ~/workspace/.mino/session-inventory. Read-only.
|
|
11
|
+
//
|
|
12
|
+
// Exit codes: 0 done, 1 the repository is in no hub and no record, 2 usage error.
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const read_1 = require("./read");
|
|
15
|
+
const USAGE = [
|
|
16
|
+
"usage: miadi-repomap list [--hub <path>] [--inventory <dir>] [--json]",
|
|
17
|
+
" miadi-repomap show <owner/name> [--hub <path>] [--inventory <dir>] [--json]",
|
|
18
|
+
].join("\n");
|
|
19
|
+
const FLAGS = { list: ["hub", "inventory", "json"], show: ["hub", "inventory", "json"] };
|
|
20
|
+
class UsageError extends Error {
|
|
21
|
+
}
|
|
22
|
+
function parse(argv) {
|
|
23
|
+
const positional = [];
|
|
24
|
+
const flags = {};
|
|
25
|
+
for (let i = 0; i < argv.length; i++) {
|
|
26
|
+
const arg = argv[i];
|
|
27
|
+
if (!arg.startsWith("--")) {
|
|
28
|
+
positional.push(arg);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const key = arg.slice(2);
|
|
32
|
+
if (key === "json" || key === "help") {
|
|
33
|
+
flags[key] = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const value = argv[++i];
|
|
37
|
+
if (value === undefined || value.startsWith("--") || !value.trim())
|
|
38
|
+
throw new UsageError(`--${key} needs a value`);
|
|
39
|
+
flags[key] = value;
|
|
40
|
+
}
|
|
41
|
+
const allowed = FLAGS[positional[0]];
|
|
42
|
+
const unknown = allowed ? Object.keys(flags).filter((k) => !allowed.includes(k)) : [];
|
|
43
|
+
if (unknown.length)
|
|
44
|
+
throw new UsageError(`${positional[0]} does not take ${unknown.map((k) => `--${k}`).join(", ")}`);
|
|
45
|
+
return { positional, flags };
|
|
46
|
+
}
|
|
47
|
+
const value = (flags, key) => (typeof flags[key] === "string" ? flags[key] : undefined);
|
|
48
|
+
function hubLine(hub) {
|
|
49
|
+
switch (hub.state) {
|
|
50
|
+
case "no-hub":
|
|
51
|
+
return "no mapping yet: no hub configured (MIADI_REPOSITORY_MAPPING_HUB)";
|
|
52
|
+
case "no-mapping-yet":
|
|
53
|
+
return `no mapping yet: ${hub.path} holds no .miadi/repository-mapping/`;
|
|
54
|
+
case "unreadable":
|
|
55
|
+
return `the mapping at ${hub.path} does not read (${hub.errors} errors)`;
|
|
56
|
+
case "read":
|
|
57
|
+
return `mapping read from ${hub.hubs.length} hub(s): ${hub.errors} errors, ${hub.warnings} warnings`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function sessionLine(s) {
|
|
61
|
+
const ending = s.disposition ? ` ending ${s.disposition.decided ?? `${s.disposition.proposed} (proposed)`}` : "";
|
|
62
|
+
return ` ${s.date ?? "?"} ${(s.tmux_session_name ?? s.session_id).padEnd(36)} ${(s.team ?? "-").padEnd(10)} ${s.status ?? "-"}${ending} ${s.session_id}`;
|
|
63
|
+
}
|
|
64
|
+
async function main() {
|
|
65
|
+
const { positional, flags } = parse(process.argv.slice(2));
|
|
66
|
+
const command = positional[0];
|
|
67
|
+
if (command === "help" || (!command && flags.help)) {
|
|
68
|
+
console.log(USAGE);
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
const options = { hub: value(flags, "hub"), inventory: value(flags, "inventory") };
|
|
72
|
+
if (command === "list") {
|
|
73
|
+
const listing = await (0, read_1.repositoryListing)(options);
|
|
74
|
+
if (flags.json) {
|
|
75
|
+
console.log(JSON.stringify(listing, null, 2));
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
console.error(hubLine(listing.hub));
|
|
79
|
+
for (const r of listing.repositories) {
|
|
80
|
+
const state = r.mapped ? `${r.lifecycle} · ${r.drift}` : "no mapping yet";
|
|
81
|
+
console.log(`${`${r.owner}/${r.name}`.padEnd(48)} ${String(r.sessions).padStart(4)} sessions ${(r.last_session ?? "").padEnd(10)} ${state.padEnd(24)} ${r.teams.join(",") || "-"}`);
|
|
82
|
+
}
|
|
83
|
+
console.error(`${listing.repositories.length} repositories; ${listing.inventory.records} records read from ${listing.inventory.from}, ${listing.inventory.without_repo} without a repo`);
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
if (command === "show") {
|
|
87
|
+
if (!positional[1])
|
|
88
|
+
throw new UsageError("show needs a repository: owner/name");
|
|
89
|
+
const detail = await (0, read_1.repositoryDetail)(positional[1], options);
|
|
90
|
+
if (flags.json) {
|
|
91
|
+
console.log(JSON.stringify(detail, null, 2));
|
|
92
|
+
return detail.repository ? 0 : 1;
|
|
93
|
+
}
|
|
94
|
+
const r = detail.repository;
|
|
95
|
+
if (!r) {
|
|
96
|
+
console.error(`miadi-repomap: ${positional[1]} is in no hub and no inventory record`);
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
const lines = [
|
|
100
|
+
`${r.owner}/${r.name} ${r.url}`,
|
|
101
|
+
r.repository
|
|
102
|
+
? ` ${r.repository.lifecycle} · ${r.repository.origin} · ${r.repository.revision}${r.source ? ` · from ${r.source}` : ""}`
|
|
103
|
+
: ` ${hubLine(detail.hub)}`,
|
|
104
|
+
r.reading ? ` git: ${r.reading.reason} (${r.reading.drift})` : "",
|
|
105
|
+
r.repository?.purpose ? ` purpose: ${r.repository.purpose}` : "",
|
|
106
|
+
r.features.length ? ` features (${r.features.length}):` : "",
|
|
107
|
+
...r.features.map((f) => ` ${f.nodeId} [${f.status}]${f.statement ? ` ${f.statement}` : ""}`),
|
|
108
|
+
r.relations.length ? ` relations (${r.relations.length}):` : "",
|
|
109
|
+
...r.relations.map((x) => ` ${x.from} ${x.type} ${x.to}`),
|
|
110
|
+
` sessions (${r.sessions.length}):`,
|
|
111
|
+
...r.sessions.map(sessionLine),
|
|
112
|
+
];
|
|
113
|
+
console.log(lines.filter(Boolean).join("\n"));
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
if (!command)
|
|
117
|
+
throw new UsageError("a command is needed");
|
|
118
|
+
throw new UsageError(`unknown command: ${command}`);
|
|
119
|
+
}
|
|
120
|
+
main().then((code) => {
|
|
121
|
+
process.exitCode = code;
|
|
122
|
+
}, (error) => {
|
|
123
|
+
console.error(`miadi-repomap: ${error.message}`);
|
|
124
|
+
if (error instanceof UsageError) {
|
|
125
|
+
console.error(USAGE);
|
|
126
|
+
process.exitCode = 2;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
process.exitCode = 1;
|
|
130
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { RepositorySession, MappingState, HubState, RepositoryView, RepositorySummary, InventoryState, RepositoryListing, } from "./types";
|
|
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";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @miadi/relational-git-repository-mapper — a git repository as Miadi sees it:
|
|
3
|
+
// the rows its owner hub holds beside the agent sessions that worked in it.
|
|
4
|
+
// "Repository" here is always a git repository, never the DDD Repository or a
|
|
5
|
+
// Data Mapper. Formerly @miadi/relational-repository-mapper (deprecated).
|
|
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;
|
|
8
|
+
var join_1 = require("./join");
|
|
9
|
+
Object.defineProperty(exports, "dayOf", { enumerable: true, get: function () { return join_1.dayOf; } });
|
|
10
|
+
Object.defineProperty(exports, "teamOf", { enumerable: true, get: function () { return join_1.teamOf; } });
|
|
11
|
+
Object.defineProperty(exports, "dispositionOf", { enumerable: true, get: function () { return join_1.dispositionOf; } });
|
|
12
|
+
Object.defineProperty(exports, "sessionOf", { enumerable: true, get: function () { return join_1.sessionOf; } });
|
|
13
|
+
Object.defineProperty(exports, "repositoryKey", { enumerable: true, get: function () { return join_1.repositoryKey; } });
|
|
14
|
+
Object.defineProperty(exports, "sessionsByRepository", { enumerable: true, get: function () { return join_1.sessionsByRepository; } });
|
|
15
|
+
Object.defineProperty(exports, "repositoryView", { enumerable: true, get: function () { return join_1.repositoryView; } });
|
|
16
|
+
Object.defineProperty(exports, "listRepositories", { enumerable: true, get: function () { return join_1.listRepositories; } });
|
|
17
|
+
var read_1 = require("./read");
|
|
18
|
+
Object.defineProperty(exports, "inventoryDir", { enumerable: true, get: function () { return read_1.inventoryDir; } });
|
|
19
|
+
Object.defineProperty(exports, "hubPath", { enumerable: true, get: function () { return read_1.hubPath; } });
|
|
20
|
+
Object.defineProperty(exports, "readHubState", { enumerable: true, get: function () { return read_1.readHubState; } });
|
|
21
|
+
Object.defineProperty(exports, "readMapper", { enumerable: true, get: function () { return read_1.readMapper; } });
|
|
22
|
+
Object.defineProperty(exports, "repositoryListing", { enumerable: true, get: function () { return read_1.repositoryListing; } });
|
|
23
|
+
Object.defineProperty(exports, "repositoryDetail", { enumerable: true, get: function () { return read_1.repositoryDetail; } });
|
package/dist/join.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type RepositoryMapping } from "@medicine-wheel/developer-repository-mapping";
|
|
2
|
+
import type { InventorySnapshot } from "@miadi/hooks-interpreter";
|
|
3
|
+
import type { RepositorySession, RepositorySummary, RepositoryView } from "./types";
|
|
4
|
+
/** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
|
|
5
|
+
export declare function dayOf(date: string | undefined): string | undefined;
|
|
6
|
+
/** `team_fit.team.id` first: it is measured at inventory time and includes a team set later. Then `team`. */
|
|
7
|
+
export declare function teamOf(snapshot: InventorySnapshot): string | undefined;
|
|
8
|
+
export declare function dispositionOf(snapshot: InventorySnapshot): RepositorySession["disposition"];
|
|
9
|
+
export declare function sessionOf(sessionId: string, snapshot: InventorySnapshot): RepositorySession;
|
|
10
|
+
/** `owner/name`, case-folded, of a record's `repo`, or undefined when it names no repository. */
|
|
11
|
+
export declare function repositoryKey(repo: string | undefined): string | undefined;
|
|
12
|
+
export interface SessionsByRepository {
|
|
13
|
+
/** case-folded owner/name → its sessions, newest first */
|
|
14
|
+
sessions: Map<string, RepositorySession[]>;
|
|
15
|
+
/** case-folded owner/name → the repo as the first record (newest) wrote it */
|
|
16
|
+
spelled: Map<string, string>;
|
|
17
|
+
records: number;
|
|
18
|
+
withoutRepo: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function sessionsByRepository(records: ReadonlyMap<string, InventorySnapshot>): SessionsByRepository;
|
|
21
|
+
/**
|
|
22
|
+
* One repository: its rows when a hub holds them, and its sessions. Undefined
|
|
23
|
+
* when neither a hub nor any record names it.
|
|
24
|
+
*/
|
|
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[];
|
package/dist/join.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The join, pure: inventory records grouped by the repository they name, and a
|
|
3
|
+
// repository's mapping rows beside its sessions. The key is the record's
|
|
4
|
+
// `repo` (owner/name), case-folded, matched to repository:<owner>/<name>:
|
|
5
|
+
// GitHub names are case-insensitive, and records write them as they found them.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.dayOf = dayOf;
|
|
8
|
+
exports.teamOf = teamOf;
|
|
9
|
+
exports.dispositionOf = dispositionOf;
|
|
10
|
+
exports.sessionOf = sessionOf;
|
|
11
|
+
exports.repositoryKey = repositoryKey;
|
|
12
|
+
exports.sessionsByRepository = sessionsByRepository;
|
|
13
|
+
exports.repositoryView = repositoryView;
|
|
14
|
+
exports.listRepositories = listRepositories;
|
|
15
|
+
const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
|
|
16
|
+
const text = (value) => (typeof value === "string" && value.trim() ? value : undefined);
|
|
17
|
+
/** A record's `date` as YYYY-MM-DD: older records write a full timestamp, newer ones the day. */
|
|
18
|
+
function dayOf(date) {
|
|
19
|
+
const m = date ? /^(\d{4}-\d{2}-\d{2})/.exec(date.trim()) : null;
|
|
20
|
+
return m ? m[1] : undefined;
|
|
21
|
+
}
|
|
22
|
+
/** `team_fit.team.id` first: it is measured at inventory time and includes a team set later. Then `team`. */
|
|
23
|
+
function teamOf(snapshot) {
|
|
24
|
+
const fit = snapshot.team_fit;
|
|
25
|
+
return text(fit?.team?.id) ?? snapshot.team;
|
|
26
|
+
}
|
|
27
|
+
function dispositionOf(snapshot) {
|
|
28
|
+
const d = snapshot.disposition;
|
|
29
|
+
const proposed = text(d?.proposed);
|
|
30
|
+
const decided = text(d?.decided);
|
|
31
|
+
return proposed || decided ? { ...(proposed ? { proposed } : {}), ...(decided ? { decided } : {}) } : undefined;
|
|
32
|
+
}
|
|
33
|
+
function sessionOf(sessionId, snapshot) {
|
|
34
|
+
const team = teamOf(snapshot);
|
|
35
|
+
const disposition = dispositionOf(snapshot);
|
|
36
|
+
const date = dayOf(snapshot.date);
|
|
37
|
+
return {
|
|
38
|
+
session_id: sessionId,
|
|
39
|
+
...(snapshot.tmux_session_name ? { tmux_session_name: snapshot.tmux_session_name } : {}),
|
|
40
|
+
...(snapshot.status ? { status: snapshot.status } : {}),
|
|
41
|
+
...(team ? { team } : {}),
|
|
42
|
+
...(snapshot.mission ? { mission: snapshot.mission } : {}),
|
|
43
|
+
...(date ? { date } : {}),
|
|
44
|
+
work_completed: (snapshot.work_completed ?? []).map((item) => item.title),
|
|
45
|
+
...(disposition ? { disposition } : {}),
|
|
46
|
+
...(snapshot.evidence?.length ? { evidence: snapshot.evidence } : {}),
|
|
47
|
+
modified_at: snapshot.modified_at,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** `owner/name`, case-folded, of a record's `repo`, or undefined when it names no repository. */
|
|
51
|
+
function repositoryKey(repo) {
|
|
52
|
+
const id = repo ? (0, developer_repository_mapping_1.toRepositoryNodeId)(repo.trim().replace(/\.git$/, "")) : undefined;
|
|
53
|
+
return id ? id.slice("repository:".length).toLowerCase() : undefined;
|
|
54
|
+
}
|
|
55
|
+
const newestFirst = (a, b) => (b.date ?? "").localeCompare(a.date ?? "") || b.modified_at.localeCompare(a.modified_at);
|
|
56
|
+
function sessionsByRepository(records) {
|
|
57
|
+
const sessions = new Map();
|
|
58
|
+
const spelled = new Map();
|
|
59
|
+
let withoutRepo = 0;
|
|
60
|
+
for (const [id, snapshot] of records) {
|
|
61
|
+
const key = repositoryKey(snapshot.repo);
|
|
62
|
+
if (!key) {
|
|
63
|
+
withoutRepo += 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const list = sessions.get(key) ?? [];
|
|
67
|
+
list.push(sessionOf(id, snapshot));
|
|
68
|
+
sessions.set(key, list);
|
|
69
|
+
if (!spelled.has(key))
|
|
70
|
+
spelled.set(key, snapshot.repo.trim().replace(/\.git$/, ""));
|
|
71
|
+
}
|
|
72
|
+
for (const list of sessions.values())
|
|
73
|
+
list.sort(newestFirst);
|
|
74
|
+
return { sessions, spelled, records: records.size, withoutRepo };
|
|
75
|
+
}
|
|
76
|
+
const keyOfNode = (nodeId) => nodeId.slice("repository:".length).toLowerCase();
|
|
77
|
+
/**
|
|
78
|
+
* One repository: its rows when a hub holds them, and its sessions. Undefined
|
|
79
|
+
* when neither a hub nor any record names it.
|
|
80
|
+
*/
|
|
81
|
+
function repositoryView(repository, mapping, bySessions, sources = {}) {
|
|
82
|
+
const key = repositoryKey(repository);
|
|
83
|
+
if (!key)
|
|
84
|
+
return undefined;
|
|
85
|
+
const row = mapping?.repositories.find((r) => keyOfNode(r.nodeId) === key);
|
|
86
|
+
const sessions = bySessions.sessions.get(key) ?? [];
|
|
87
|
+
if (!row && !sessions.length)
|
|
88
|
+
return undefined;
|
|
89
|
+
const nodeId = row?.nodeId ?? `repository:${bySessions.spelled.get(key) ?? key}`;
|
|
90
|
+
const { owner, name } = (0, developer_repository_mapping_1.parseRepositoryNodeId)(nodeId);
|
|
91
|
+
return {
|
|
92
|
+
nodeId,
|
|
93
|
+
owner,
|
|
94
|
+
name,
|
|
95
|
+
url: (0, developer_repository_mapping_1.repositoryUrl)(nodeId),
|
|
96
|
+
mapped: Boolean(row),
|
|
97
|
+
...(row ? { repository: row, reading: (0, developer_repository_mapping_1.reconcileLifecycle)(row) } : {}),
|
|
98
|
+
...(row && sources[row.nodeId] ? { source: sources[row.nodeId] } : {}),
|
|
99
|
+
features: row ? mapping.features.filter((f) => f.repository === row.nodeId) : [],
|
|
100
|
+
relations: row ? mapping.relations.filter((r) => r.from === row.nodeId || r.to === row.nodeId) : [],
|
|
101
|
+
sessions,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
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))]);
|
|
107
|
+
return [...keys]
|
|
108
|
+
.map((key) => {
|
|
109
|
+
const view = repositoryView(key, mapping, bySessions);
|
|
110
|
+
const teams = [...new Set(view.sessions.flatMap((s) => (s.team ? [s.team] : [])))].sort();
|
|
111
|
+
return {
|
|
112
|
+
nodeId: view.nodeId,
|
|
113
|
+
owner: view.owner,
|
|
114
|
+
name: view.name,
|
|
115
|
+
mapped: view.mapped,
|
|
116
|
+
...(view.repository ? { lifecycle: view.repository.lifecycle } : {}),
|
|
117
|
+
...(view.reading ? { drift: view.reading.drift } : {}),
|
|
118
|
+
sessions: view.sessions.length,
|
|
119
|
+
...(view.sessions[0]?.date ? { last_session: view.sessions[0].date } : {}),
|
|
120
|
+
teams,
|
|
121
|
+
};
|
|
122
|
+
})
|
|
123
|
+
.sort((a, b) => b.sessions - a.sessions || a.nodeId.toLowerCase().localeCompare(b.nodeId.toLowerCase()));
|
|
124
|
+
}
|
package/dist/read.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { MergedMapping } from "@medicine-wheel/developer-repository-mapping";
|
|
2
|
+
import { type SessionsByRepository } from "./join";
|
|
3
|
+
import type { HubState, InventoryState, RepositoryListing, RepositoryView } from "./types";
|
|
4
|
+
type Env = Record<string, string | undefined>;
|
|
5
|
+
/** The witness team's inventory: `MIADI_SESSION_INVENTORY_DIR`, else `~/workspace/.mino/session-inventory`. */
|
|
6
|
+
export declare function inventoryDir(env?: Env): string;
|
|
7
|
+
/** The hub to read: `MIADI_REPOSITORY_MAPPING_HUB`, a hub clone or its mapping folder. Unset means none. */
|
|
8
|
+
export declare function hubPath(env?: Env): string | undefined;
|
|
9
|
+
export interface ReadOptions {
|
|
10
|
+
/** hub clone or mapping folder; default {@link hubPath} */
|
|
11
|
+
hub?: string;
|
|
12
|
+
/** inventory directory; default {@link inventoryDir} */
|
|
13
|
+
inventory?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function readHubState(path: string | undefined): Promise<{
|
|
16
|
+
hub: HubState;
|
|
17
|
+
mapping?: MergedMapping;
|
|
18
|
+
}>;
|
|
19
|
+
export interface MapperRead {
|
|
20
|
+
hub: HubState;
|
|
21
|
+
mapping?: MergedMapping;
|
|
22
|
+
inventory: InventoryState;
|
|
23
|
+
sessions: SessionsByRepository;
|
|
24
|
+
}
|
|
25
|
+
export declare function readMapper(options?: ReadOptions): Promise<MapperRead>;
|
|
26
|
+
export declare function repositoryListing(options?: ReadOptions): Promise<RepositoryListing>;
|
|
27
|
+
export declare function repositoryDetail(repository: string, options?: ReadOptions): Promise<{
|
|
28
|
+
hub: HubState;
|
|
29
|
+
inventory: InventoryState;
|
|
30
|
+
repository?: RepositoryView;
|
|
31
|
+
}>;
|
|
32
|
+
export {};
|
package/dist/read.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Reading, on Node: the hub (a jgwill/jgwill clone, whose meta mapping reads
|
|
3
|
+
// the hubs it registers) and the session inventory. Read-only; nothing here
|
|
4
|
+
// writes a mapping or a record.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.inventoryDir = inventoryDir;
|
|
7
|
+
exports.hubPath = hubPath;
|
|
8
|
+
exports.readHubState = readHubState;
|
|
9
|
+
exports.readMapper = readMapper;
|
|
10
|
+
exports.repositoryListing = repositoryListing;
|
|
11
|
+
exports.repositoryDetail = repositoryDetail;
|
|
12
|
+
const node_os_1 = require("node:os");
|
|
13
|
+
const node_path_1 = require("node:path");
|
|
14
|
+
const node_1 = require("@medicine-wheel/developer-repository-mapping/node");
|
|
15
|
+
const hooks_interpreter_1 = require("@miadi/hooks-interpreter");
|
|
16
|
+
const join_1 = require("./join");
|
|
17
|
+
/** The witness team's inventory: `MIADI_SESSION_INVENTORY_DIR`, else `~/workspace/.mino/session-inventory`. */
|
|
18
|
+
function inventoryDir(env = process.env) {
|
|
19
|
+
return env.MIADI_SESSION_INVENTORY_DIR?.trim() || (0, node_path_1.join)((0, node_os_1.homedir)(), "workspace", ".mino", "session-inventory");
|
|
20
|
+
}
|
|
21
|
+
/** The hub to read: `MIADI_REPOSITORY_MAPPING_HUB`, a hub clone or its mapping folder. Unset means none. */
|
|
22
|
+
function hubPath(env = process.env) {
|
|
23
|
+
return env.MIADI_REPOSITORY_MAPPING_HUB?.trim() || undefined;
|
|
24
|
+
}
|
|
25
|
+
async function readHubState(path) {
|
|
26
|
+
if (!path)
|
|
27
|
+
return { hub: { state: "no-hub", hubs: [], errors: 0, warnings: 0 } };
|
|
28
|
+
const dir = await (0, node_1.findMappingDir)(path);
|
|
29
|
+
if (!dir)
|
|
30
|
+
return { hub: { state: "no-mapping-yet", path, hubs: [], errors: 0, warnings: 0 } };
|
|
31
|
+
const read = await (0, node_1.readHub)(dir);
|
|
32
|
+
const errors = read.issues.filter((i) => i.severity === "error").length;
|
|
33
|
+
return {
|
|
34
|
+
hub: { state: read.merged ? "read" : "unreadable", path, hubs: read.hubs, errors, warnings: read.issues.length - errors },
|
|
35
|
+
...(read.merged ? { mapping: read.merged } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async function readMapper(options = {}) {
|
|
39
|
+
const { hub, mapping } = await readHubState(options.hub ?? hubPath());
|
|
40
|
+
const from = options.inventory ?? inventoryDir();
|
|
41
|
+
const sessions = (0, join_1.sessionsByRepository)((0, hooks_interpreter_1.readInventoryRecords)(from));
|
|
42
|
+
return {
|
|
43
|
+
hub,
|
|
44
|
+
...(mapping ? { mapping } : {}),
|
|
45
|
+
inventory: { from, records: sessions.records, without_repo: sessions.withoutRepo },
|
|
46
|
+
sessions,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function repositoryListing(options = {}) {
|
|
50
|
+
const read = await readMapper(options);
|
|
51
|
+
return { hub: read.hub, inventory: read.inventory, repositories: (0, join_1.listRepositories)(read.mapping, read.sessions) };
|
|
52
|
+
}
|
|
53
|
+
async function repositoryDetail(repository, options = {}) {
|
|
54
|
+
const read = await readMapper(options);
|
|
55
|
+
const view = (0, join_1.repositoryView)(repository, read.mapping, read.sessions, read.mapping?.sources);
|
|
56
|
+
return { hub: read.hub, inventory: read.inventory, ...(view ? { repository: view } : {}) };
|
|
57
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { FeatureFacet, LifecycleReading, RelationRow, RepositoryFacet } from "@medicine-wheel/developer-repository-mapping";
|
|
2
|
+
import type { HubStatus } from "@medicine-wheel/developer-repository-mapping/node";
|
|
3
|
+
/** One session that worked in a repository, as its inventory record says it, by title. */
|
|
4
|
+
export interface RepositorySession {
|
|
5
|
+
session_id: string;
|
|
6
|
+
tmux_session_name?: string;
|
|
7
|
+
status?: string;
|
|
8
|
+
/** `team_fit.team.id` (measured at inventory time), else `team` (the binding line's at session start). */
|
|
9
|
+
team?: string;
|
|
10
|
+
mission?: string;
|
|
11
|
+
/** the record's `date`, as YYYY-MM-DD */
|
|
12
|
+
date?: string;
|
|
13
|
+
/** titles of `work_completed` */
|
|
14
|
+
work_completed: string[];
|
|
15
|
+
/** the ending proposed for the session, and the one decided */
|
|
16
|
+
disposition?: {
|
|
17
|
+
proposed?: string;
|
|
18
|
+
decided?: string;
|
|
19
|
+
};
|
|
20
|
+
/** `links.evidence` refs: what the session started from */
|
|
21
|
+
evidence?: string[];
|
|
22
|
+
/** the record file's modification time */
|
|
23
|
+
modified_at: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Where the mapping stands on this host.
|
|
27
|
+
* - `no-hub`: no hub configured (`MIADI_REPOSITORY_MAPPING_HUB` unset).
|
|
28
|
+
* - `no-mapping-yet`: the hub clone holds no `.miadi/repository-mapping/`.
|
|
29
|
+
* - `read`: the hub was read (a meta hub with the hubs it registers).
|
|
30
|
+
* - `unreadable`: the folder is there and its manifest does not read.
|
|
31
|
+
*/
|
|
32
|
+
export type MappingState = "no-hub" | "no-mapping-yet" | "read" | "unreadable";
|
|
33
|
+
export interface HubState {
|
|
34
|
+
state: MappingState;
|
|
35
|
+
/** the hub clone or mapping folder configured */
|
|
36
|
+
path?: string;
|
|
37
|
+
hubs: HubStatus[];
|
|
38
|
+
errors: number;
|
|
39
|
+
warnings: number;
|
|
40
|
+
}
|
|
41
|
+
export interface RepositoryView {
|
|
42
|
+
/** `repository:<owner>/<name>`, in the case the mapping holds, else the first record's */
|
|
43
|
+
nodeId: string;
|
|
44
|
+
owner: string;
|
|
45
|
+
name: string;
|
|
46
|
+
url: string;
|
|
47
|
+
/** whether a hub holds the repository's row */
|
|
48
|
+
mapped: boolean;
|
|
49
|
+
repository?: RepositoryFacet;
|
|
50
|
+
/** the declared lifecycle against git */
|
|
51
|
+
reading?: LifecycleReading;
|
|
52
|
+
/** the hub the row came from */
|
|
53
|
+
source?: string;
|
|
54
|
+
features: FeatureFacet[];
|
|
55
|
+
relations: RelationRow[];
|
|
56
|
+
/** newest first */
|
|
57
|
+
sessions: RepositorySession[];
|
|
58
|
+
}
|
|
59
|
+
export interface RepositorySummary {
|
|
60
|
+
nodeId: string;
|
|
61
|
+
owner: string;
|
|
62
|
+
name: string;
|
|
63
|
+
mapped: boolean;
|
|
64
|
+
lifecycle?: string;
|
|
65
|
+
drift?: string;
|
|
66
|
+
sessions: number;
|
|
67
|
+
/** the newest session's date */
|
|
68
|
+
last_session?: string;
|
|
69
|
+
/** distinct teams of its sessions, sorted */
|
|
70
|
+
teams: string[];
|
|
71
|
+
}
|
|
72
|
+
export interface InventoryState {
|
|
73
|
+
/** the inventory directory read */
|
|
74
|
+
from: string;
|
|
75
|
+
records: number;
|
|
76
|
+
/** records with no `repo`, or one that is not owner/name: counted, not shown */
|
|
77
|
+
without_repo: number;
|
|
78
|
+
}
|
|
79
|
+
export interface RepositoryListing {
|
|
80
|
+
hub: HubState;
|
|
81
|
+
inventory: InventoryState;
|
|
82
|
+
repositories: RepositorySummary[];
|
|
83
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// What P4 shows for a repository: the rows its owner hub holds, beside the
|
|
3
|
+
// agent sessions that worked in it. The rows come from
|
|
4
|
+
// @medicine-wheel/developer-repository-mapping; the sessions from the witness
|
|
5
|
+
// team's session inventory, read through @miadi/hooks-interpreter.
|
|
6
|
+
// Ref: rispecs/developer-suite/repository-mapping/STATUS.md (P4) in jgwill/medicine-wheel.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/relational-git-repository-mapper",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
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.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Miadi",
|
|
7
|
+
"homepage": "https://github.com/jgwill/Miadi/tree/main/packages/relational-git-repository-mapper",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/jgwill/Miadi.git",
|
|
11
|
+
"directory": "packages/relational-git-repository-mapper"
|
|
12
|
+
},
|
|
13
|
+
"type": "commonjs",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"miadi-repomap": "dist/cli.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@medicine-wheel/developer-repository-mapping": "^0.25.0",
|
|
32
|
+
"@miadi/hooks-interpreter": "^0.7.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^22.0.0",
|
|
36
|
+
"typescript": "^5.4.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"miadi",
|
|
46
|
+
"git-repository",
|
|
47
|
+
"repository-mapping",
|
|
48
|
+
"session-inventory",
|
|
49
|
+
"medicine-wheel",
|
|
50
|
+
"relational"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsc -p tsconfig.build.json && node -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
|
|
54
|
+
"type-check": "tsc -p tsconfig.build.json --noEmit",
|
|
55
|
+
"test": "d=$(mktemp -d \"${TMPDIR:-/tmp}/miadi-relational-git-repository-mapper-test.XXXXXX\") && trap 'rm -rf \"$d\"' EXIT && tsc -p tsconfig.test.json --outDir \"$d\" && NODE_PATH=\"$PWD/node_modules\" node --test \"$d\"/test/*.test.js"
|
|
56
|
+
}
|
|
6
57
|
}
|