@imenam/mcp-documentor 1.0.80 → 1.0.81

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.
@@ -40,6 +40,7 @@ export declare class GitHubCodeApi {
40
40
  private readonly spec;
41
41
  private readonly token;
42
42
  private readonly treeByCommit;
43
+ private readonly commitByDate;
43
44
  private readonly truncatedCommits;
44
45
  private readonly blobCache;
45
46
  constructor(spec: RepoSpec, token: string | undefined);
@@ -52,6 +53,15 @@ export declare class GitHubCodeApi {
52
53
  * once within it, however many files that operation ends up reading.
53
54
  */
54
55
  resolveRef(): Promise<ResolvedRef>;
56
+ /**
57
+ * The newest commit on the configured ref at or before `isoDate`, or undefined if the branch
58
+ * has no commit that old.
59
+ *
60
+ * This is how a snapshot taken before commits were recorded still gets a diff base: the date it
61
+ * was taken at stands in for the revision it was taken from. History is immutable below the ref's
62
+ * head, so the answer is cached for the life of the process.
63
+ */
64
+ resolveCommitAtDate(isoDate: string): Promise<string | undefined>;
55
65
  /** path → blob sha for every file in the commit's tree. A commit's tree never changes. */
56
66
  getTree(commitSha: string): Promise<Map<string, string>>;
57
67
  /**
@@ -58,6 +58,7 @@ export class GitHubCodeApi {
58
58
  // at once, and they all need the same tree — and often the same blobs. Caching the promise makes
59
59
  // concurrent callers await one request instead of each firing its own.
60
60
  treeByCommit = new Map();
61
+ commitByDate = new Map();
61
62
  truncatedCommits = new Set();
62
63
  blobCache = new Map();
63
64
  constructor(spec, token) {
@@ -116,6 +117,24 @@ export class GitHubCodeApi {
116
117
  };
117
118
  });
118
119
  }
120
+ /**
121
+ * The newest commit on the configured ref at or before `isoDate`, or undefined if the branch
122
+ * has no commit that old.
123
+ *
124
+ * This is how a snapshot taken before commits were recorded still gets a diff base: the date it
125
+ * was taken at stands in for the revision it was taken from. History is immutable below the ref's
126
+ * head, so the answer is cached for the life of the process.
127
+ */
128
+ resolveCommitAtDate(isoDate) {
129
+ return this.cached(this.commitByDate, isoDate, async () => {
130
+ const ref = this.spec.ref ?? "HEAD";
131
+ const commits = await this.request(`/repos/${this.spec.owner}/${this.spec.repo}/commits` +
132
+ `?sha=${encodeURIComponent(ref)}&until=${encodeURIComponent(isoDate)}&per_page=1`);
133
+ const sha = Array.isArray(commits) && typeof commits[0]?.sha === "string" ? commits[0].sha : undefined;
134
+ logger.debug(`${this.label}: commit at or before ${isoDate} is ${sha ? sha.slice(0, 7) : "none"}`);
135
+ return sha;
136
+ });
137
+ }
119
138
  /** path → blob sha for every file in the commit's tree. A commit's tree never changes. */
120
139
  getTree(commitSha) {
121
140
  return this.cached(this.treeByCommit, commitSha, async () => {
@@ -46,31 +46,53 @@ function getLocalGitDiff(tracked, project) {
46
46
  * Diffs tracked files against the branch they are tracked on, using the commit each snapshot
47
47
  * was taken at as the base.
48
48
  *
49
+ * A snapshot with no recorded commit — taken before branch tracking, or from a local working copy —
50
+ * is anchored on the newest commit at or before its date instead, so it diffs like any other rather
51
+ * than demanding a refresh first.
52
+ *
49
53
  * Files are grouped by that base commit so one comparison covers every file snapshotted at the
50
54
  * same revision — which, for a doc refreshed in one go, means a single API call.
51
55
  */
52
56
  async function getGitHubDiffs(api, trackedFiles) {
53
57
  const diffs = new Map();
54
58
  const byBase = new Map();
59
+ const inferredBases = new Set();
55
60
  for (const tracked of trackedFiles) {
56
- if (!tracked.sourceRevision) {
57
- diffs.set(tracked.path, ` [INFO] No source commit recorded for "${tracked.path}" — this snapshot predates branch tracking, or was taken from a local working copy.\n` +
58
- ` → Call refresh_file_snapshot to re-anchor it on ${api.label}, after which diffs become available.`);
59
- continue;
61
+ let base = tracked.sourceRevision;
62
+ if (!base) {
63
+ try {
64
+ base = await api.resolveCommitAtDate(tracked.lastModifiedAt);
65
+ }
66
+ catch (err) {
67
+ const message = err instanceof Error ? err.message : String(err);
68
+ diffs.set(tracked.path, ` [ERROR] No source commit recorded, and the commit at the snapshot date (${tracked.lastModifiedAt}) could not be resolved on ${api.label}: ${message}`);
69
+ continue;
70
+ }
71
+ if (!base) {
72
+ diffs.set(tracked.path, ` [INFO] No source commit recorded, and ${api.label} has no commit at or before the snapshot date (${tracked.lastModifiedAt}) — nothing to diff against.\n` +
73
+ ` → Call refresh_file_snapshot to re-anchor this file on ${api.label}.`);
74
+ continue;
75
+ }
76
+ inferredBases.add(base);
60
77
  }
61
- const group = byBase.get(tracked.sourceRevision);
78
+ const group = byBase.get(base);
62
79
  if (group)
63
80
  group.push(tracked);
64
81
  else
65
- byBase.set(tracked.sourceRevision, [tracked]);
82
+ byBase.set(base, [tracked]);
66
83
  }
67
84
  if (byBase.size === 0)
68
85
  return diffs;
69
86
  const { commitSha: head } = await api.resolveRef();
70
87
  for (const [base, files] of byBase) {
88
+ // An inferred base is the branch state at the snapshot date, not a commit the snapshot was
89
+ // provably read from — worth saying, since the diff can then include changes already documented.
90
+ const note = inferredBases.has(base)
91
+ ? ` [INFO] Base commit ${base.slice(0, 7)} inferred from the snapshot date (no source commit recorded).\n\n`
92
+ : "";
71
93
  if (base === head) {
72
94
  for (const file of files) {
73
- diffs.set(file.path, ` [INFO] ${api.label} is still at the snapshot commit ${base.slice(0, 7)} — no changes.`);
95
+ diffs.set(file.path, `${note} [INFO] ${api.label} is still at the snapshot commit ${base.slice(0, 7)} — no changes.`);
74
96
  }
75
97
  continue;
76
98
  }
@@ -81,12 +103,12 @@ async function getGitHubDiffs(api, trackedFiles) {
81
103
  catch (err) {
82
104
  const message = err instanceof Error ? err.message : String(err);
83
105
  for (const file of files)
84
- diffs.set(file.path, ` [ERROR] Could not compare ${base.slice(0, 7)}...${head.slice(0, 7)}: ${message}`);
106
+ diffs.set(file.path, `${note} [ERROR] Could not compare ${base.slice(0, 7)}...${head.slice(0, 7)}: ${message}`);
85
107
  continue;
86
108
  }
87
109
  for (const file of files) {
88
110
  const patch = patches.get(file.path);
89
- diffs.set(file.path, patch ?? ` [INFO] No changes to this file between ${base.slice(0, 7)} and ${head.slice(0, 7)}.`);
111
+ diffs.set(file.path, note + (patch ?? ` [INFO] No changes to this file between ${base.slice(0, 7)} and ${head.slice(0, 7)}.`));
90
112
  }
91
113
  }
92
114
  return diffs;
@@ -1 +1 @@
1
- export declare const APP_VERSION = "1.0.80";
1
+ export declare const APP_VERSION = "1.0.81";
@@ -1,2 +1,2 @@
1
1
  // Auto-generated version file - do not edit manually
2
- export const APP_VERSION = '1.0.80';
2
+ export const APP_VERSION = '1.0.81';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imenam/mcp-documentor",
3
- "version": "1.0.80",
3
+ "version": "1.0.81",
4
4
  "main": "dist/src/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",