mindkeeper-openclaw 0.2.30 → 0.2.32

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.
Files changed (2) hide show
  1. package/dist/index.js +118 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -718,11 +718,66 @@ var Tracker = class {
718
718
  await this.ensureConfigLoaded();
719
719
  await this.store.init();
720
720
  await this.ensureGitignore();
721
+ this.log?.info?.(
722
+ `[mindkeeper] init: commitMessage.mode=${this.config.commitMessage.mode}, llmProvider=${this.llmProvider ? "yes" : "no"}`
723
+ );
721
724
  const changed = await this.getTrackedChangedFiles();
722
725
  if (changed.length > 0) {
723
- await this.store.addFiles(changed.map((e) => e.filepath));
724
- const msg = generateTemplateMessage(changed.map((e) => e.filepath));
725
- await this.store.commit(msg);
726
+ const filesToCommit = changed.map((e) => e.filepath);
727
+ await this.store.addFiles(filesToCommit);
728
+ let message = null;
729
+ if (this.config.commitMessage.mode === "llm" && this.llmProvider) {
730
+ let headOid = null;
731
+ try {
732
+ headOid = await this.resolveHead();
733
+ } catch {
734
+ }
735
+ if (headOid) {
736
+ const diffs = [];
737
+ for (const file of filesToCommit) {
738
+ try {
739
+ const oldContent = await this.store.readFile(file, headOid) ?? "";
740
+ let newContent;
741
+ try {
742
+ newContent = await import_promises3.default.readFile(
743
+ import_node_path3.default.join(this.workDir, file),
744
+ "utf-8"
745
+ );
746
+ } catch {
747
+ newContent = "";
748
+ }
749
+ const d = computeDiff({
750
+ file,
751
+ fromVersion: headOid.slice(0, 8),
752
+ toVersion: "(staged)",
753
+ oldContent,
754
+ newContent
755
+ });
756
+ if (d.additions > 0 || d.deletions > 0) diffs.push(d);
757
+ } catch {
758
+ }
759
+ }
760
+ if (diffs.length > 0) {
761
+ message = await generateLlmMessage(diffs, this.llmProvider, this.log);
762
+ if (message) {
763
+ this.log?.info?.(
764
+ `[mindkeeper] init: LLM-generated commit \u2014 "${message.slice(0, 50)}${message.length > 50 ? "\u2026" : ""}"`
765
+ );
766
+ }
767
+ } else {
768
+ this.log?.info?.("[mindkeeper] init: diffs empty (all files unchanged vs HEAD)");
769
+ }
770
+ } else {
771
+ this.log?.info?.("[mindkeeper] init: no HEAD yet (first commit), LLM skipped");
772
+ }
773
+ }
774
+ if (!message) {
775
+ message = generateTemplateMessage(filesToCommit);
776
+ this.log?.info?.(`[mindkeeper] init: using template \u2014 "${message}"`);
777
+ }
778
+ await this.store.commit(message);
779
+ } else {
780
+ this.log?.info?.("[mindkeeper] init: no changed files");
726
781
  }
727
782
  return { initialFiles: changed.map((e) => e.filepath) };
728
783
  }
@@ -823,6 +878,9 @@ var Tracker = class {
823
878
  headOid = await this.resolveHead();
824
879
  } catch {
825
880
  }
881
+ this.log?.info?.(
882
+ `[mindkeeper] autoSnapshot: files=${filesToCommit.length}, headOid=${headOid ? headOid.slice(0, 8) : "none"}, mode=${this.config.commitMessage.mode}, llmProvider=${this.llmProvider ? "yes" : "no"}`
883
+ );
826
884
  if (headOid) {
827
885
  for (const file of filesToCommit) {
828
886
  try {
@@ -846,21 +904,42 @@ var Tracker = class {
846
904
  if (d.additions > 0 || d.deletions > 0) {
847
905
  diffs.push(d);
848
906
  }
849
- } catch {
907
+ } catch (err) {
908
+ this.log?.warn?.(
909
+ `[mindkeeper] autoSnapshot: diff failed for ${file}: ${err instanceof Error ? err.message : String(err)}`
910
+ );
850
911
  }
851
912
  }
852
913
  }
914
+ this.log?.info?.(`[mindkeeper] autoSnapshot: computed ${diffs.length} non-empty diff(s)`);
853
915
  let message = null;
916
+ let usedLlm = false;
917
+ let templateReason = null;
854
918
  if (this.config.commitMessage.mode === "llm" && diffs.length > 0) {
855
- message = await generateLlmMessage(diffs, this.llmProvider, this.log);
919
+ if (this.llmProvider) {
920
+ message = await generateLlmMessage(diffs, this.llmProvider, this.log);
921
+ if (message) usedLlm = true;
922
+ else templateReason = "LLM API call failed (check logs above for error details)";
923
+ } else {
924
+ templateReason = "llmProvider is null (createOpenClawLlmProvider returned null \u2014 check startup logs)";
925
+ }
926
+ } else if (this.config.commitMessage.mode === "llm" && diffs.length === 0) {
927
+ templateReason = headOid ? `diffs empty (${filesToCommit.length} file(s) changed but no textual diff vs HEAD)` : "no HEAD commit yet (first commit), cannot compute diff";
928
+ } else {
929
+ templateReason = `commitMessage.mode="${this.config.commitMessage.mode}" (not "llm")`;
856
930
  }
857
931
  if (!message) {
858
- if (this.config.commitMessage.mode === "llm" && this.log?.warn) {
859
- const reason = diffs.length === 0 ? "No diff available (first commit or no file changes), using template" : "LLM failed, falling back to template";
860
- this.log.warn(`[mindkeeper] ${reason}`);
861
- }
862
932
  message = generateTemplateMessage(filesToCommit);
863
933
  }
934
+ if (usedLlm) {
935
+ this.log?.info?.(
936
+ `[mindkeeper] Commit message: LLM \u2713 \u2014 "${message.slice(0, 60)}${message.length > 60 ? "\u2026" : ""}"`
937
+ );
938
+ } else {
939
+ this.log?.warn?.(
940
+ `[mindkeeper] Commit message: TEMPLATE \u2014 reason: ${templateReason}`
941
+ );
942
+ }
864
943
  const oid = await this.store.commit(message);
865
944
  return {
866
945
  oid,
@@ -1172,7 +1251,7 @@ function readEnvApiKey(provider) {
1172
1251
  // src/llm-provider.ts
1173
1252
  var MAX_DIFF_CHARS = 4e3;
1174
1253
  async function createOpenClawLlmProvider(api) {
1175
- const modelSpec = resolveModelFromConfig(api.config);
1254
+ const modelSpec = resolveModelFromConfig(api.config, api.log);
1176
1255
  if (!modelSpec) {
1177
1256
  api.log?.warn?.(
1178
1257
  "[mindkeeper] No default model configured in OpenClaw \u2014 LLM commit messages disabled."
@@ -1188,25 +1267,32 @@ async function createOpenClawLlmProvider(api) {
1188
1267
  const apiKey = await resolveApiKey(modelSpec.provider);
1189
1268
  if (!apiKey) {
1190
1269
  api.log?.warn?.(
1191
- `[mindkeeper] No API key found for provider "${modelSpec.provider}" \u2014 LLM commit messages disabled.`
1270
+ `[mindkeeper] No API key found for provider "${modelSpec.provider}" \u2014 LLM commit messages disabled. Checked: auth-profiles.json + env vars.`
1192
1271
  );
1193
1272
  return null;
1194
1273
  }
1195
1274
  api.log?.info?.(
1196
- `[mindkeeper] LLM commit messages enabled (${modelSpec.provider}/${modelSpec.model}).`
1275
+ `[mindkeeper] LLM commit messages enabled (${modelSpec.provider}/${modelSpec.model}${modelSpec.baseUrl ? `, baseUrl=${modelSpec.baseUrl}` : ""}).`
1197
1276
  );
1198
1277
  return {
1199
1278
  async generateCommitMessage(diffs) {
1200
1279
  const diffText = diffs.map((d) => `--- ${d.file} ---
1201
1280
  ${d.unified}`).join("\n").slice(0, MAX_DIFF_CHARS);
1281
+ api.log?.info?.(
1282
+ `[mindkeeper] Calling LLM for commit message (${diffs.length} diff(s), ${diffText.length} chars)\u2026`
1283
+ );
1202
1284
  const { callLlm } = await import("./llm-client.cjs");
1203
- return callLlm({
1285
+ const result = await callLlm({
1204
1286
  provider: modelSpec.provider,
1205
1287
  model: modelSpec.model,
1206
1288
  apiKey,
1207
1289
  userPrompt: diffText,
1208
1290
  baseUrl: modelSpec.baseUrl
1209
1291
  });
1292
+ api.log?.info?.(
1293
+ `[mindkeeper] LLM returned: "${(result ?? "").slice(0, 60)}${(result ?? "").length > 60 ? "\u2026" : ""}"`
1294
+ );
1295
+ return result;
1210
1296
  }
1211
1297
  };
1212
1298
  }
@@ -1214,10 +1300,13 @@ function isOAuthProvider(provider) {
1214
1300
  const normalized = normalizeProvider(provider);
1215
1301
  return normalized.includes("portal") || normalized.includes("oauth");
1216
1302
  }
1217
- function resolveModelFromConfig(config) {
1303
+ function resolveModelFromConfig(config, log) {
1218
1304
  const agents = config?.agents;
1219
1305
  const defaults = agents?.defaults;
1220
1306
  const raw = defaults?.model;
1307
+ log?.info?.(
1308
+ `[mindkeeper] resolveModel: config.agents=${agents ? "present" : "missing"}, config.agents.defaults=${defaults ? "present" : "missing"}, config.agents.defaults.model=${raw === void 0 ? "undefined" : typeof raw === "string" ? `"${raw}"` : JSON.stringify(raw)}`
1309
+ );
1221
1310
  let spec;
1222
1311
  if (typeof raw === "string") {
1223
1312
  spec = raw.trim();
@@ -1225,7 +1314,12 @@ function resolveModelFromConfig(config) {
1225
1314
  const primary = raw.primary;
1226
1315
  if (typeof primary === "string") spec = primary.trim();
1227
1316
  }
1228
- if (!spec?.includes("/")) return null;
1317
+ if (!spec?.includes("/")) {
1318
+ log?.warn?.(
1319
+ `[mindkeeper] resolveModel: no valid "provider/model" spec found (got: ${spec === void 0 ? "undefined" : `"${spec}"`})`
1320
+ );
1321
+ return null;
1322
+ }
1229
1323
  const slashIdx = spec.indexOf("/");
1230
1324
  const provider = spec.slice(0, slashIdx);
1231
1325
  const model = spec.slice(slashIdx + 1);
@@ -1295,10 +1389,16 @@ function createWatcherService(api, trackerRef) {
1295
1389
  return;
1296
1390
  }
1297
1391
  ensureWorkspaceSkillMirror(workspaceDir, { log: api.log });
1392
+ log.info(
1393
+ `[mindkeeper] Service starting: ctx.config=${ctx.config ? "present" : "missing"}, pluginConfig=${api.pluginConfig ? JSON.stringify(api.pluginConfig) : "none"}`
1394
+ );
1298
1395
  const llmProvider = await createOpenClawLlmProvider({
1299
1396
  config: ctx.config,
1300
1397
  log
1301
1398
  });
1399
+ log.info(
1400
+ `[mindkeeper] LLM provider: ${llmProvider ? "created successfully" : "null (will use template)"}`
1401
+ );
1302
1402
  const tracker = new Tracker({
1303
1403
  workDir: workspaceDir,
1304
1404
  llmProvider: llmProvider ?? void 0,
@@ -1307,6 +1407,9 @@ function createWatcherService(api, trackerRef) {
1307
1407
  });
1308
1408
  await tracker.init();
1309
1409
  trackerRef.current = tracker;
1410
+ log.info(
1411
+ `[mindkeeper] Tracker config: commitMessage.mode=${tracker.getConfig().commitMessage.mode}`
1412
+ );
1310
1413
  watcher = new Watcher({
1311
1414
  tracker,
1312
1415
  onSnapshot: (commit) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindkeeper-openclaw",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "description": "OpenClaw plugin for mindkeeper: auto-snapshot, diff, and rollback for agent context files",
5
5
  "keywords": [
6
6
  "openclaw",