@miadi/relational-git-repository-mapper 0.6.3 → 0.7.1

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
@@ -91,7 +91,11 @@ scan now lives, so it runs without the Factory. `scan` reads a repository's defa
91
91
  (`origin/HEAD`) from git objects, never its
92
92
  working tree, so a clone on another branch or with edits of its own reads the same. It reads
93
93
  the packages the repository declares (`workspaces`, or `pnpm-workspace.yaml`), each
94
- package's `bin`, and every `SKILL.md` outside `node_modules` and archives. A statement is the
94
+ package's `bin`, every `SKILL.md` outside `node_modules` and archives, and what a file is
95
+ read for by a reader written for it: the medicine wheel's skills in `cli/skills.ts`, and the
96
+ decision of which model a mission runs on in Miadi's `packages/connector/src/claude-models.ts`
97
+ (`miadi-capability://jgwill/Miadi/decision/miadi.claude_model_routing`, kind `decision`,
98
+ jgwill/Miadi#1030). A statement is the
95
99
  file's own description, kept only within 55 words; longer, the row is `needs-resolution`
96
100
  without one. Every row names the commit it was read at and stays `pending` until a person
97
101
  reads it.
package/dist/cli.js CHANGED
@@ -232,7 +232,7 @@ async function main() {
232
232
  return 0;
233
233
  }
234
234
  const subject = answer.repository ? short(answer.repository) : "every repository";
235
- console.log(`${subject} provides ${answer.capabilities.length}: ${answer.counts.package} packages, ${answer.counts.cli} CLIs, ${answer.counts.skill} skills`);
235
+ console.log(`${subject} provides ${answer.capabilities.length}: ${answer.counts.package} packages, ${answer.counts.cli} CLIs, ${answer.counts.skill} skills, ${answer.counts.decision} decisions`);
236
236
  for (const c of answer.capabilities) {
237
237
  const by = answer.repository ? "" : ` (${c.providedBy.map(short).join(", ")})`;
238
238
  console.log(` ${(c.kind ?? "other").padEnd(8)} ${c.name}${by}${c.statement ? ` — ${c.statement}` : ` [${c.status}]`}`);
package/dist/commit.d.ts CHANGED
@@ -8,6 +8,10 @@ export interface CommitCapability {
8
8
  name: string;
9
9
  /** the files of the commit that define it */
10
10
  files: string[];
11
+ /** the version its package.json names at the commit (a CLI: the package that ships it); absent for a skill or when the manifest is unreadable there */
12
+ version?: string;
13
+ /** true when the commit itself changed that version: it is the release this change shipped in, not an earlier one */
14
+ versionChanged?: boolean;
11
15
  /** the commit and its files; `revision` is `pending` until a person reads it */
12
16
  attribution: Attribution;
13
17
  }
@@ -24,7 +28,7 @@ export interface CommitCapabilities {
24
28
  skipped?: "versions-only";
25
29
  capabilities: CommitCapability[];
26
30
  }
27
- export type CommitReadFailure = "not-a-commit-ref" | "clone-not-of-repository" | "commit-not-in-clone";
31
+ export type CommitReadFailure = "not-a-commit-ref" | "clone-not-of-repository" | "commit-not-in-clone" | "merge-commit" | "not-on-origin";
28
32
  export declare class CommitReadError extends Error {
29
33
  readonly code: CommitReadFailure;
30
34
  constructor(code: CommitReadFailure, message: string);
@@ -56,12 +60,16 @@ export interface CommitCapabilitiesOptions {
56
60
  rows?: readonly CapabilityFacet[];
57
61
  by?: string;
58
62
  at?: string;
63
+ /** refuse a commit no `origin` remote-tracking branch holds: a local, amended or rebased-away commit is not what was pushed */
64
+ onOrigin?: boolean;
59
65
  }
60
66
  /**
61
67
  * The capability rows `owner/name@sha` changed, read from a local clone whose
62
68
  * `origin` is that repository. Read-only: `git remote get-url`, `rev-parse`,
63
69
  * `diff`, `show`. Never fetches. Throws {@link CommitReadError} when the ref is
64
- * not a commit ref, the clone's origin names another repository, or the clone
65
- * does not hold the commit.
70
+ * not a commit ref, the clone's origin names another repository, the clone
71
+ * does not hold the commit, the commit is a merge (against its first parent a merge
72
+ * counts everything it brought in as its own), or, with `onOrigin`, no `origin`
73
+ * remote-tracking branch holds it.
66
74
  */
67
75
  export declare function capabilitiesOfCommit(ref: string, clone: string, options?: CommitCapabilitiesOptions): CommitCapabilities;
package/dist/commit.js CHANGED
@@ -55,6 +55,18 @@ function changesOnlyVersions(before, after) {
55
55
  const b = manifestShape(after);
56
56
  return a !== undefined && a === b;
57
57
  }
58
+ /** The `version` a package.json text names, or undefined. */
59
+ function manifestVersion(text) {
60
+ if (text === undefined)
61
+ return undefined;
62
+ try {
63
+ const v = JSON.parse(text).version;
64
+ return typeof v === "string" && v.trim() ? v.trim() : undefined;
65
+ }
66
+ catch {
67
+ return undefined;
68
+ }
69
+ }
58
70
  /** The path a shipped row's grounding names (`owner/name@sha:<path>`), or undefined. */
59
71
  function groundedPath(row) {
60
72
  for (const g of row.grounding) {
@@ -132,9 +144,11 @@ function changedCapabilities(input) {
132
144
  const path = groundedPath(row);
133
145
  if (!path)
134
146
  continue;
135
- if (kind === "skill" && defining.includes(path))
136
- add(row, "skill", path);
137
- if (kind === "cli" && node_path_1.posix.basename(path) === "package.json") {
147
+ // A skill and a decision are read from one file each: the commit changed them when it changed that file.
148
+ if ((kind === "skill" || kind === "decision") && defining.includes(path))
149
+ add(row, kind, path);
150
+ // A CLI's entry point lives in its package's folder: a commit that changed nothing there reads no manifest for it.
151
+ if (kind === "cli" && node_path_1.posix.basename(path) === "package.json" && defining.some((f) => inFolder(f, node_path_1.posix.dirname(path)))) {
138
152
  const entry = binEntry(input.read(path, "after") ?? input.read(path, "before"), row.name);
139
153
  if (!entry)
140
154
  continue;
@@ -146,11 +160,21 @@ function changedCapabilities(input) {
146
160
  const at = input.at ?? new Date().toISOString();
147
161
  const by = input.by ?? "@miadi/relational-git-repository-mapper";
148
162
  const capabilities = [...changed.values()]
149
- .map(({ row, kind, files }) => ({
163
+ .map(({ row, kind, files }) => {
164
+ // A package and a CLI are versioned by the manifest their row is grounded in, as it reads at the commit.
165
+ const manifest = kind === "skill" || kind === "decision" ? undefined : groundedPath(row);
166
+ const isManifest = manifest !== undefined && node_path_1.posix.basename(manifest) === "package.json";
167
+ const version = isManifest ? manifestVersion(input.read(manifest, "after")) : undefined;
168
+ const versionChanged = isManifest && version !== undefined && manifestVersion(input.read(manifest, "before")) !== version;
169
+ return { row, kind, files, version, versionChanged };
170
+ })
171
+ .map(({ row, kind, files, version, versionChanged }) => ({
150
172
  address: (0, capabilities_1.capabilityAddress)(provider(row), kind, row.name),
151
173
  nodeId: row.nodeId,
152
174
  kind,
153
175
  name: row.name,
176
+ ...(version ? { version } : {}),
177
+ ...(versionChanged ? { versionChanged: true } : {}),
154
178
  files: files.sort(),
155
179
  attribution: { statedBy: by, statedAt: at, grounding: [input.commit, ...files.sort().map((f) => `${input.commit}:${f}`)], revision: "pending" },
156
180
  }))
@@ -167,7 +191,7 @@ function remoteRepository(url) {
167
191
  }
168
192
  const git = (clone, args) => {
169
193
  try {
170
- return (0, node_child_process_1.execFileSync)("git", ["-C", clone, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024 });
194
+ return (0, node_child_process_1.execFileSync)("git", ["-C", clone, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 64 * 1024 * 1024, timeout: 15_000 });
171
195
  }
172
196
  catch {
173
197
  return undefined;
@@ -177,8 +201,10 @@ const git = (clone, args) => {
177
201
  * The capability rows `owner/name@sha` changed, read from a local clone whose
178
202
  * `origin` is that repository. Read-only: `git remote get-url`, `rev-parse`,
179
203
  * `diff`, `show`. Never fetches. Throws {@link CommitReadError} when the ref is
180
- * not a commit ref, the clone's origin names another repository, or the clone
181
- * does not hold the commit.
204
+ * not a commit ref, the clone's origin names another repository, the clone
205
+ * does not hold the commit, the commit is a merge (against its first parent a merge
206
+ * counts everything it brought in as its own), or, with `onOrigin`, no `origin`
207
+ * remote-tracking branch holds it.
182
208
  */
183
209
  function capabilitiesOfCommit(ref, clone, options = {}) {
184
210
  const rows = options.rows ?? (0, read_1.readCapabilities)().capabilities;
@@ -193,6 +219,12 @@ function capabilitiesOfCommit(ref, clone, options = {}) {
193
219
  const sha = git(clone, ["rev-parse", "--verify", "--quiet", `${t.sha}^{commit}`])?.trim();
194
220
  if (!sha)
195
221
  throw new CommitReadError("commit-not-in-clone", `${clone} does not hold ${t.sha}`);
222
+ const parents = (git(clone, ["rev-list", "--parents", "-n", "1", sha]) ?? "").trim().split(/\s+/).slice(1);
223
+ if (parents.length > 1)
224
+ throw new CommitReadError("merge-commit", `${sha} is a merge of ${parents.length} parents`);
225
+ if (options.onOrigin && !git(clone, ["for-each-ref", "--contains", sha, "--count=1", "--format=%(refname)", "refs/remotes/origin"])?.trim()) {
226
+ throw new CommitReadError("not-on-origin", `no origin branch holds ${sha}`);
227
+ }
196
228
  const parent = git(clone, ["rev-parse", "--verify", "--quiet", `${sha}^1`])?.trim();
197
229
  const listed = parent
198
230
  ? git(clone, ["diff", "--name-only", "--no-renames", parent, sha])
package/dist/join.js CHANGED
@@ -116,9 +116,10 @@ function sessionsByRepository(records) {
116
116
  list.sort(newestFirst);
117
117
  return { sessions, spelled, records: records.size, withoutRepo };
118
118
  }
119
+ const CAPABILITY_ADDRESS = new RegExp(`^miadi-capability:(?:\\/\\/)?([^/\\s]+)\\/([^/\\s]+)\\/(${capabilities_1.CAPABILITY_KINDS.join("|")})\\/(.+)$`);
119
120
  /** A capability address without its scheme, owner and repository case-folded: `miadi-capability:` and `miadi-capability://` read the same. */
120
121
  function capabilityKey(address) {
121
- const m = /^miadi-capability:(?:\/\/)?([^/\s]+)\/([^/\s]+)\/(package|cli|skill)\/(.+)$/.exec(address.trim());
122
+ const m = CAPABILITY_ADDRESS.exec(address.trim());
122
123
  return m ? `${m[1].toLowerCase()}/${m[2].toLowerCase()}/${m[3]}/${m[4]}` : undefined;
123
124
  }
124
125
  /** The sessions whose record's `capabilities[]` names this capability, newest first. */
package/dist/read.js CHANGED
@@ -137,7 +137,7 @@ function repositoryCapabilities(repository, options = {}) {
137
137
  const read = readCapabilities(options.capabilities);
138
138
  const id = repository ? (repository.startsWith("repository:") ? repository : `repository:${repository}`) : undefined;
139
139
  const rows = id ? (0, capabilities_2.capabilitiesOf)(id, read.capabilities) : read.capabilities;
140
- const counts = { package: 0, cli: 0, skill: 0, other: 0 };
140
+ const counts = Object.fromEntries([...capabilities_2.CAPABILITY_KINDS, "other"].map((k) => [k, 0]));
141
141
  const capabilities = rows.map((c) => {
142
142
  const kind = (0, capabilities_2.kindOf)(c.nodeId);
143
143
  counts[kind ?? "other"] += 1;