openclaw-telegram-manager 2.0.2 → 2.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.
Files changed (83) hide show
  1. package/README.md +10 -3
  2. package/dist/commands/archive.d.ts.map +1 -1
  3. package/dist/commands/archive.js +4 -6
  4. package/dist/commands/archive.js.map +1 -1
  5. package/dist/commands/autopilot.d.ts +3 -0
  6. package/dist/commands/autopilot.d.ts.map +1 -0
  7. package/dist/commands/autopilot.js +127 -0
  8. package/dist/commands/autopilot.js.map +1 -0
  9. package/dist/commands/daily-report.d.ts +4 -0
  10. package/dist/commands/daily-report.d.ts.map +1 -0
  11. package/dist/commands/daily-report.js +155 -0
  12. package/dist/commands/daily-report.js.map +1 -0
  13. package/dist/commands/doctor-all.d.ts.map +1 -1
  14. package/dist/commands/doctor-all.js +48 -14
  15. package/dist/commands/doctor-all.js.map +1 -1
  16. package/dist/commands/doctor.d.ts.map +1 -1
  17. package/dist/commands/doctor.js +3 -2
  18. package/dist/commands/doctor.js.map +1 -1
  19. package/dist/commands/help.d.ts.map +1 -1
  20. package/dist/commands/help.js +0 -1
  21. package/dist/commands/help.js.map +1 -1
  22. package/dist/commands/init.d.ts +6 -1
  23. package/dist/commands/init.d.ts.map +1 -1
  24. package/dist/commands/init.js +73 -28
  25. package/dist/commands/init.js.map +1 -1
  26. package/dist/commands/list.d.ts.map +1 -1
  27. package/dist/commands/list.js +0 -1
  28. package/dist/commands/list.js.map +1 -1
  29. package/dist/commands/rename.d.ts.map +1 -1
  30. package/dist/commands/rename.js +4 -6
  31. package/dist/commands/rename.js.map +1 -1
  32. package/dist/commands/snooze.d.ts.map +1 -1
  33. package/dist/commands/snooze.js +3 -5
  34. package/dist/commands/snooze.js.map +1 -1
  35. package/dist/commands/status.js +2 -2
  36. package/dist/commands/status.js.map +1 -1
  37. package/dist/commands/sync.d.ts.map +1 -1
  38. package/dist/commands/sync.js +1 -4
  39. package/dist/commands/sync.js.map +1 -1
  40. package/dist/commands/upgrade.d.ts.map +1 -1
  41. package/dist/commands/upgrade.js +4 -8
  42. package/dist/commands/upgrade.js.map +1 -1
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +43 -10
  45. package/dist/index.js.map +1 -1
  46. package/dist/lib/activity.d.ts +3 -0
  47. package/dist/lib/activity.d.ts.map +1 -0
  48. package/dist/lib/activity.js +11 -0
  49. package/dist/lib/activity.js.map +1 -0
  50. package/dist/lib/auth.d.ts.map +1 -1
  51. package/dist/lib/auth.js +1 -0
  52. package/dist/lib/auth.js.map +1 -1
  53. package/dist/lib/capsule.d.ts +5 -0
  54. package/dist/lib/capsule.d.ts.map +1 -1
  55. package/dist/lib/capsule.js +17 -2
  56. package/dist/lib/capsule.js.map +1 -1
  57. package/dist/lib/doctor-checks.d.ts +6 -1
  58. package/dist/lib/doctor-checks.d.ts.map +1 -1
  59. package/dist/lib/doctor-checks.js +54 -34
  60. package/dist/lib/doctor-checks.js.map +1 -1
  61. package/dist/lib/include-generator.d.ts.map +1 -1
  62. package/dist/lib/include-generator.js +21 -5
  63. package/dist/lib/include-generator.js.map +1 -1
  64. package/dist/lib/registry.d.ts.map +1 -1
  65. package/dist/lib/registry.js +18 -0
  66. package/dist/lib/registry.js.map +1 -1
  67. package/dist/lib/telegram.d.ts +25 -5
  68. package/dist/lib/telegram.d.ts.map +1 -1
  69. package/dist/lib/telegram.js +96 -46
  70. package/dist/lib/telegram.js.map +1 -1
  71. package/dist/lib/types.d.ts +8 -4
  72. package/dist/lib/types.d.ts.map +1 -1
  73. package/dist/lib/types.js +5 -2
  74. package/dist/lib/types.js.map +1 -1
  75. package/dist/plugin.js +1250 -714
  76. package/dist/setup.js +80 -4
  77. package/dist/setup.js.map +1 -1
  78. package/dist/tool.d.ts +2 -0
  79. package/dist/tool.d.ts.map +1 -1
  80. package/dist/tool.js +52 -7
  81. package/dist/tool.js.map +1 -1
  82. package/package.json +1 -1
  83. package/skills/tm/SKILL.md +15 -3
package/dist/plugin.js CHANGED
@@ -60,54 +60,54 @@ var require_polyfills = __commonJS({
60
60
  }
61
61
  var chdir;
62
62
  module.exports = patch;
63
- function patch(fs12) {
63
+ function patch(fs14) {
64
64
  if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
65
- patchLchmod(fs12);
66
- }
67
- if (!fs12.lutimes) {
68
- patchLutimes(fs12);
69
- }
70
- fs12.chown = chownFix(fs12.chown);
71
- fs12.fchown = chownFix(fs12.fchown);
72
- fs12.lchown = chownFix(fs12.lchown);
73
- fs12.chmod = chmodFix(fs12.chmod);
74
- fs12.fchmod = chmodFix(fs12.fchmod);
75
- fs12.lchmod = chmodFix(fs12.lchmod);
76
- fs12.chownSync = chownFixSync(fs12.chownSync);
77
- fs12.fchownSync = chownFixSync(fs12.fchownSync);
78
- fs12.lchownSync = chownFixSync(fs12.lchownSync);
79
- fs12.chmodSync = chmodFixSync(fs12.chmodSync);
80
- fs12.fchmodSync = chmodFixSync(fs12.fchmodSync);
81
- fs12.lchmodSync = chmodFixSync(fs12.lchmodSync);
82
- fs12.stat = statFix(fs12.stat);
83
- fs12.fstat = statFix(fs12.fstat);
84
- fs12.lstat = statFix(fs12.lstat);
85
- fs12.statSync = statFixSync(fs12.statSync);
86
- fs12.fstatSync = statFixSync(fs12.fstatSync);
87
- fs12.lstatSync = statFixSync(fs12.lstatSync);
88
- if (fs12.chmod && !fs12.lchmod) {
89
- fs12.lchmod = function(path13, mode, cb) {
65
+ patchLchmod(fs14);
66
+ }
67
+ if (!fs14.lutimes) {
68
+ patchLutimes(fs14);
69
+ }
70
+ fs14.chown = chownFix(fs14.chown);
71
+ fs14.fchown = chownFix(fs14.fchown);
72
+ fs14.lchown = chownFix(fs14.lchown);
73
+ fs14.chmod = chmodFix(fs14.chmod);
74
+ fs14.fchmod = chmodFix(fs14.fchmod);
75
+ fs14.lchmod = chmodFix(fs14.lchmod);
76
+ fs14.chownSync = chownFixSync(fs14.chownSync);
77
+ fs14.fchownSync = chownFixSync(fs14.fchownSync);
78
+ fs14.lchownSync = chownFixSync(fs14.lchownSync);
79
+ fs14.chmodSync = chmodFixSync(fs14.chmodSync);
80
+ fs14.fchmodSync = chmodFixSync(fs14.fchmodSync);
81
+ fs14.lchmodSync = chmodFixSync(fs14.lchmodSync);
82
+ fs14.stat = statFix(fs14.stat);
83
+ fs14.fstat = statFix(fs14.fstat);
84
+ fs14.lstat = statFix(fs14.lstat);
85
+ fs14.statSync = statFixSync(fs14.statSync);
86
+ fs14.fstatSync = statFixSync(fs14.fstatSync);
87
+ fs14.lstatSync = statFixSync(fs14.lstatSync);
88
+ if (fs14.chmod && !fs14.lchmod) {
89
+ fs14.lchmod = function(path15, mode, cb) {
90
90
  if (cb) process.nextTick(cb);
91
91
  };
92
- fs12.lchmodSync = function() {
92
+ fs14.lchmodSync = function() {
93
93
  };
94
94
  }
95
- if (fs12.chown && !fs12.lchown) {
96
- fs12.lchown = function(path13, uid, gid, cb) {
95
+ if (fs14.chown && !fs14.lchown) {
96
+ fs14.lchown = function(path15, uid, gid, cb) {
97
97
  if (cb) process.nextTick(cb);
98
98
  };
99
- fs12.lchownSync = function() {
99
+ fs14.lchownSync = function() {
100
100
  };
101
101
  }
102
102
  if (platform === "win32") {
103
- fs12.rename = typeof fs12.rename !== "function" ? fs12.rename : (function(fs$rename) {
103
+ fs14.rename = typeof fs14.rename !== "function" ? fs14.rename : (function(fs$rename) {
104
104
  function rename(from, to, cb) {
105
105
  var start = Date.now();
106
106
  var backoff = 0;
107
107
  fs$rename(from, to, function CB(er) {
108
108
  if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
109
109
  setTimeout(function() {
110
- fs12.stat(to, function(stater, st) {
110
+ fs14.stat(to, function(stater, st) {
111
111
  if (stater && stater.code === "ENOENT")
112
112
  fs$rename(from, to, CB);
113
113
  else
@@ -123,9 +123,9 @@ var require_polyfills = __commonJS({
123
123
  }
124
124
  if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
125
125
  return rename;
126
- })(fs12.rename);
126
+ })(fs14.rename);
127
127
  }
128
- fs12.read = typeof fs12.read !== "function" ? fs12.read : (function(fs$read) {
128
+ fs14.read = typeof fs14.read !== "function" ? fs14.read : (function(fs$read) {
129
129
  function read(fd, buffer, offset, length, position, callback_) {
130
130
  var callback;
131
131
  if (callback_ && typeof callback_ === "function") {
@@ -133,22 +133,22 @@ var require_polyfills = __commonJS({
133
133
  callback = function(er, _, __) {
134
134
  if (er && er.code === "EAGAIN" && eagCounter < 10) {
135
135
  eagCounter++;
136
- return fs$read.call(fs12, fd, buffer, offset, length, position, callback);
136
+ return fs$read.call(fs14, fd, buffer, offset, length, position, callback);
137
137
  }
138
138
  callback_.apply(this, arguments);
139
139
  };
140
140
  }
141
- return fs$read.call(fs12, fd, buffer, offset, length, position, callback);
141
+ return fs$read.call(fs14, fd, buffer, offset, length, position, callback);
142
142
  }
143
143
  if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
144
144
  return read;
145
- })(fs12.read);
146
- fs12.readSync = typeof fs12.readSync !== "function" ? fs12.readSync : /* @__PURE__ */ (function(fs$readSync) {
145
+ })(fs14.read);
146
+ fs14.readSync = typeof fs14.readSync !== "function" ? fs14.readSync : /* @__PURE__ */ (function(fs$readSync) {
147
147
  return function(fd, buffer, offset, length, position) {
148
148
  var eagCounter = 0;
149
149
  while (true) {
150
150
  try {
151
- return fs$readSync.call(fs12, fd, buffer, offset, length, position);
151
+ return fs$readSync.call(fs14, fd, buffer, offset, length, position);
152
152
  } catch (er) {
153
153
  if (er.code === "EAGAIN" && eagCounter < 10) {
154
154
  eagCounter++;
@@ -158,11 +158,11 @@ var require_polyfills = __commonJS({
158
158
  }
159
159
  }
160
160
  };
161
- })(fs12.readSync);
162
- function patchLchmod(fs13) {
163
- fs13.lchmod = function(path13, mode, callback) {
164
- fs13.open(
165
- path13,
161
+ })(fs14.readSync);
162
+ function patchLchmod(fs15) {
163
+ fs15.lchmod = function(path15, mode, callback) {
164
+ fs15.open(
165
+ path15,
166
166
  constants.O_WRONLY | constants.O_SYMLINK,
167
167
  mode,
168
168
  function(err, fd) {
@@ -170,80 +170,80 @@ var require_polyfills = __commonJS({
170
170
  if (callback) callback(err);
171
171
  return;
172
172
  }
173
- fs13.fchmod(fd, mode, function(err2) {
174
- fs13.close(fd, function(err22) {
173
+ fs15.fchmod(fd, mode, function(err2) {
174
+ fs15.close(fd, function(err22) {
175
175
  if (callback) callback(err2 || err22);
176
176
  });
177
177
  });
178
178
  }
179
179
  );
180
180
  };
181
- fs13.lchmodSync = function(path13, mode) {
182
- var fd = fs13.openSync(path13, constants.O_WRONLY | constants.O_SYMLINK, mode);
181
+ fs15.lchmodSync = function(path15, mode) {
182
+ var fd = fs15.openSync(path15, constants.O_WRONLY | constants.O_SYMLINK, mode);
183
183
  var threw = true;
184
184
  var ret;
185
185
  try {
186
- ret = fs13.fchmodSync(fd, mode);
186
+ ret = fs15.fchmodSync(fd, mode);
187
187
  threw = false;
188
188
  } finally {
189
189
  if (threw) {
190
190
  try {
191
- fs13.closeSync(fd);
191
+ fs15.closeSync(fd);
192
192
  } catch (er) {
193
193
  }
194
194
  } else {
195
- fs13.closeSync(fd);
195
+ fs15.closeSync(fd);
196
196
  }
197
197
  }
198
198
  return ret;
199
199
  };
200
200
  }
201
- function patchLutimes(fs13) {
202
- if (constants.hasOwnProperty("O_SYMLINK") && fs13.futimes) {
203
- fs13.lutimes = function(path13, at, mt, cb) {
204
- fs13.open(path13, constants.O_SYMLINK, function(er, fd) {
201
+ function patchLutimes(fs15) {
202
+ if (constants.hasOwnProperty("O_SYMLINK") && fs15.futimes) {
203
+ fs15.lutimes = function(path15, at, mt, cb) {
204
+ fs15.open(path15, constants.O_SYMLINK, function(er, fd) {
205
205
  if (er) {
206
206
  if (cb) cb(er);
207
207
  return;
208
208
  }
209
- fs13.futimes(fd, at, mt, function(er2) {
210
- fs13.close(fd, function(er22) {
209
+ fs15.futimes(fd, at, mt, function(er2) {
210
+ fs15.close(fd, function(er22) {
211
211
  if (cb) cb(er2 || er22);
212
212
  });
213
213
  });
214
214
  });
215
215
  };
216
- fs13.lutimesSync = function(path13, at, mt) {
217
- var fd = fs13.openSync(path13, constants.O_SYMLINK);
216
+ fs15.lutimesSync = function(path15, at, mt) {
217
+ var fd = fs15.openSync(path15, constants.O_SYMLINK);
218
218
  var ret;
219
219
  var threw = true;
220
220
  try {
221
- ret = fs13.futimesSync(fd, at, mt);
221
+ ret = fs15.futimesSync(fd, at, mt);
222
222
  threw = false;
223
223
  } finally {
224
224
  if (threw) {
225
225
  try {
226
- fs13.closeSync(fd);
226
+ fs15.closeSync(fd);
227
227
  } catch (er) {
228
228
  }
229
229
  } else {
230
- fs13.closeSync(fd);
230
+ fs15.closeSync(fd);
231
231
  }
232
232
  }
233
233
  return ret;
234
234
  };
235
- } else if (fs13.futimes) {
236
- fs13.lutimes = function(_a, _b, _c, cb) {
235
+ } else if (fs15.futimes) {
236
+ fs15.lutimes = function(_a, _b, _c, cb) {
237
237
  if (cb) process.nextTick(cb);
238
238
  };
239
- fs13.lutimesSync = function() {
239
+ fs15.lutimesSync = function() {
240
240
  };
241
241
  }
242
242
  }
243
243
  function chmodFix(orig) {
244
244
  if (!orig) return orig;
245
245
  return function(target, mode, cb) {
246
- return orig.call(fs12, target, mode, function(er) {
246
+ return orig.call(fs14, target, mode, function(er) {
247
247
  if (chownErOk(er)) er = null;
248
248
  if (cb) cb.apply(this, arguments);
249
249
  });
@@ -253,7 +253,7 @@ var require_polyfills = __commonJS({
253
253
  if (!orig) return orig;
254
254
  return function(target, mode) {
255
255
  try {
256
- return orig.call(fs12, target, mode);
256
+ return orig.call(fs14, target, mode);
257
257
  } catch (er) {
258
258
  if (!chownErOk(er)) throw er;
259
259
  }
@@ -262,7 +262,7 @@ var require_polyfills = __commonJS({
262
262
  function chownFix(orig) {
263
263
  if (!orig) return orig;
264
264
  return function(target, uid, gid, cb) {
265
- return orig.call(fs12, target, uid, gid, function(er) {
265
+ return orig.call(fs14, target, uid, gid, function(er) {
266
266
  if (chownErOk(er)) er = null;
267
267
  if (cb) cb.apply(this, arguments);
268
268
  });
@@ -272,7 +272,7 @@ var require_polyfills = __commonJS({
272
272
  if (!orig) return orig;
273
273
  return function(target, uid, gid) {
274
274
  try {
275
- return orig.call(fs12, target, uid, gid);
275
+ return orig.call(fs14, target, uid, gid);
276
276
  } catch (er) {
277
277
  if (!chownErOk(er)) throw er;
278
278
  }
@@ -292,13 +292,13 @@ var require_polyfills = __commonJS({
292
292
  }
293
293
  if (cb) cb.apply(this, arguments);
294
294
  }
295
- return options ? orig.call(fs12, target, options, callback) : orig.call(fs12, target, callback);
295
+ return options ? orig.call(fs14, target, options, callback) : orig.call(fs14, target, callback);
296
296
  };
297
297
  }
298
298
  function statFixSync(orig) {
299
299
  if (!orig) return orig;
300
300
  return function(target, options) {
301
- var stats = options ? orig.call(fs12, target, options) : orig.call(fs12, target);
301
+ var stats = options ? orig.call(fs14, target, options) : orig.call(fs14, target);
302
302
  if (stats) {
303
303
  if (stats.uid < 0) stats.uid += 4294967296;
304
304
  if (stats.gid < 0) stats.gid += 4294967296;
@@ -327,16 +327,16 @@ var require_legacy_streams = __commonJS({
327
327
  "node_modules/graceful-fs/legacy-streams.js"(exports, module) {
328
328
  var Stream = __require("stream").Stream;
329
329
  module.exports = legacy;
330
- function legacy(fs12) {
330
+ function legacy(fs14) {
331
331
  return {
332
332
  ReadStream,
333
333
  WriteStream
334
334
  };
335
- function ReadStream(path13, options) {
336
- if (!(this instanceof ReadStream)) return new ReadStream(path13, options);
335
+ function ReadStream(path15, options) {
336
+ if (!(this instanceof ReadStream)) return new ReadStream(path15, options);
337
337
  Stream.call(this);
338
338
  var self = this;
339
- this.path = path13;
339
+ this.path = path15;
340
340
  this.fd = null;
341
341
  this.readable = true;
342
342
  this.paused = false;
@@ -370,7 +370,7 @@ var require_legacy_streams = __commonJS({
370
370
  });
371
371
  return;
372
372
  }
373
- fs12.open(this.path, this.flags, this.mode, function(err, fd) {
373
+ fs14.open(this.path, this.flags, this.mode, function(err, fd) {
374
374
  if (err) {
375
375
  self.emit("error", err);
376
376
  self.readable = false;
@@ -381,10 +381,10 @@ var require_legacy_streams = __commonJS({
381
381
  self._read();
382
382
  });
383
383
  }
384
- function WriteStream(path13, options) {
385
- if (!(this instanceof WriteStream)) return new WriteStream(path13, options);
384
+ function WriteStream(path15, options) {
385
+ if (!(this instanceof WriteStream)) return new WriteStream(path15, options);
386
386
  Stream.call(this);
387
- this.path = path13;
387
+ this.path = path15;
388
388
  this.fd = null;
389
389
  this.writable = true;
390
390
  this.flags = "w";
@@ -409,7 +409,7 @@ var require_legacy_streams = __commonJS({
409
409
  this.busy = false;
410
410
  this._queue = [];
411
411
  if (this.fd === null) {
412
- this._open = fs12.open;
412
+ this._open = fs14.open;
413
413
  this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
414
414
  this.flush();
415
415
  }
@@ -444,7 +444,7 @@ var require_clone = __commonJS({
444
444
  // node_modules/graceful-fs/graceful-fs.js
445
445
  var require_graceful_fs = __commonJS({
446
446
  "node_modules/graceful-fs/graceful-fs.js"(exports, module) {
447
- var fs12 = __require("fs");
447
+ var fs14 = __require("fs");
448
448
  var polyfills = require_polyfills();
449
449
  var legacy = require_legacy_streams();
450
450
  var clone = require_clone();
@@ -476,12 +476,12 @@ var require_graceful_fs = __commonJS({
476
476
  m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
477
477
  console.error(m);
478
478
  };
479
- if (!fs12[gracefulQueue]) {
479
+ if (!fs14[gracefulQueue]) {
480
480
  queue = global[gracefulQueue] || [];
481
- publishQueue(fs12, queue);
482
- fs12.close = (function(fs$close) {
481
+ publishQueue(fs14, queue);
482
+ fs14.close = (function(fs$close) {
483
483
  function close(fd, cb) {
484
- return fs$close.call(fs12, fd, function(err) {
484
+ return fs$close.call(fs14, fd, function(err) {
485
485
  if (!err) {
486
486
  resetQueue();
487
487
  }
@@ -493,48 +493,48 @@ var require_graceful_fs = __commonJS({
493
493
  value: fs$close
494
494
  });
495
495
  return close;
496
- })(fs12.close);
497
- fs12.closeSync = (function(fs$closeSync) {
496
+ })(fs14.close);
497
+ fs14.closeSync = (function(fs$closeSync) {
498
498
  function closeSync2(fd) {
499
- fs$closeSync.apply(fs12, arguments);
499
+ fs$closeSync.apply(fs14, arguments);
500
500
  resetQueue();
501
501
  }
502
502
  Object.defineProperty(closeSync2, previousSymbol, {
503
503
  value: fs$closeSync
504
504
  });
505
505
  return closeSync2;
506
- })(fs12.closeSync);
506
+ })(fs14.closeSync);
507
507
  if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
508
508
  process.on("exit", function() {
509
- debug(fs12[gracefulQueue]);
510
- __require("assert").equal(fs12[gracefulQueue].length, 0);
509
+ debug(fs14[gracefulQueue]);
510
+ __require("assert").equal(fs14[gracefulQueue].length, 0);
511
511
  });
512
512
  }
513
513
  }
514
514
  var queue;
515
515
  if (!global[gracefulQueue]) {
516
- publishQueue(global, fs12[gracefulQueue]);
517
- }
518
- module.exports = patch(clone(fs12));
519
- if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs12.__patched) {
520
- module.exports = patch(fs12);
521
- fs12.__patched = true;
522
- }
523
- function patch(fs13) {
524
- polyfills(fs13);
525
- fs13.gracefulify = patch;
526
- fs13.createReadStream = createReadStream;
527
- fs13.createWriteStream = createWriteStream;
528
- var fs$readFile = fs13.readFile;
529
- fs13.readFile = readFile;
530
- function readFile(path13, options, cb) {
516
+ publishQueue(global, fs14[gracefulQueue]);
517
+ }
518
+ module.exports = patch(clone(fs14));
519
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs14.__patched) {
520
+ module.exports = patch(fs14);
521
+ fs14.__patched = true;
522
+ }
523
+ function patch(fs15) {
524
+ polyfills(fs15);
525
+ fs15.gracefulify = patch;
526
+ fs15.createReadStream = createReadStream;
527
+ fs15.createWriteStream = createWriteStream;
528
+ var fs$readFile = fs15.readFile;
529
+ fs15.readFile = readFile;
530
+ function readFile(path15, options, cb) {
531
531
  if (typeof options === "function")
532
532
  cb = options, options = null;
533
- return go$readFile(path13, options, cb);
534
- function go$readFile(path14, options2, cb2, startTime) {
535
- return fs$readFile(path14, options2, function(err) {
533
+ return go$readFile(path15, options, cb);
534
+ function go$readFile(path16, options2, cb2, startTime) {
535
+ return fs$readFile(path16, options2, function(err) {
536
536
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
537
- enqueue([go$readFile, [path14, options2, cb2], err, startTime || Date.now(), Date.now()]);
537
+ enqueue([go$readFile, [path16, options2, cb2], err, startTime || Date.now(), Date.now()]);
538
538
  else {
539
539
  if (typeof cb2 === "function")
540
540
  cb2.apply(this, arguments);
@@ -542,16 +542,16 @@ var require_graceful_fs = __commonJS({
542
542
  });
543
543
  }
544
544
  }
545
- var fs$writeFile = fs13.writeFile;
546
- fs13.writeFile = writeFile;
547
- function writeFile(path13, data, options, cb) {
545
+ var fs$writeFile = fs15.writeFile;
546
+ fs15.writeFile = writeFile;
547
+ function writeFile(path15, data, options, cb) {
548
548
  if (typeof options === "function")
549
549
  cb = options, options = null;
550
- return go$writeFile(path13, data, options, cb);
551
- function go$writeFile(path14, data2, options2, cb2, startTime) {
552
- return fs$writeFile(path14, data2, options2, function(err) {
550
+ return go$writeFile(path15, data, options, cb);
551
+ function go$writeFile(path16, data2, options2, cb2, startTime) {
552
+ return fs$writeFile(path16, data2, options2, function(err) {
553
553
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
554
- enqueue([go$writeFile, [path14, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
554
+ enqueue([go$writeFile, [path16, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
555
555
  else {
556
556
  if (typeof cb2 === "function")
557
557
  cb2.apply(this, arguments);
@@ -559,17 +559,17 @@ var require_graceful_fs = __commonJS({
559
559
  });
560
560
  }
561
561
  }
562
- var fs$appendFile = fs13.appendFile;
562
+ var fs$appendFile = fs15.appendFile;
563
563
  if (fs$appendFile)
564
- fs13.appendFile = appendFile;
565
- function appendFile(path13, data, options, cb) {
564
+ fs15.appendFile = appendFile;
565
+ function appendFile(path15, data, options, cb) {
566
566
  if (typeof options === "function")
567
567
  cb = options, options = null;
568
- return go$appendFile(path13, data, options, cb);
569
- function go$appendFile(path14, data2, options2, cb2, startTime) {
570
- return fs$appendFile(path14, data2, options2, function(err) {
568
+ return go$appendFile(path15, data, options, cb);
569
+ function go$appendFile(path16, data2, options2, cb2, startTime) {
570
+ return fs$appendFile(path16, data2, options2, function(err) {
571
571
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
572
- enqueue([go$appendFile, [path14, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
572
+ enqueue([go$appendFile, [path16, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
573
573
  else {
574
574
  if (typeof cb2 === "function")
575
575
  cb2.apply(this, arguments);
@@ -577,9 +577,9 @@ var require_graceful_fs = __commonJS({
577
577
  });
578
578
  }
579
579
  }
580
- var fs$copyFile = fs13.copyFile;
580
+ var fs$copyFile = fs15.copyFile;
581
581
  if (fs$copyFile)
582
- fs13.copyFile = copyFile;
582
+ fs15.copyFile = copyFile;
583
583
  function copyFile(src, dest, flags, cb) {
584
584
  if (typeof flags === "function") {
585
585
  cb = flags;
@@ -597,34 +597,34 @@ var require_graceful_fs = __commonJS({
597
597
  });
598
598
  }
599
599
  }
600
- var fs$readdir = fs13.readdir;
601
- fs13.readdir = readdir;
600
+ var fs$readdir = fs15.readdir;
601
+ fs15.readdir = readdir;
602
602
  var noReaddirOptionVersions = /^v[0-5]\./;
603
- function readdir(path13, options, cb) {
603
+ function readdir(path15, options, cb) {
604
604
  if (typeof options === "function")
605
605
  cb = options, options = null;
606
- var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path14, options2, cb2, startTime) {
607
- return fs$readdir(path14, fs$readdirCallback(
608
- path14,
606
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path16, options2, cb2, startTime) {
607
+ return fs$readdir(path16, fs$readdirCallback(
608
+ path16,
609
609
  options2,
610
610
  cb2,
611
611
  startTime
612
612
  ));
613
- } : function go$readdir2(path14, options2, cb2, startTime) {
614
- return fs$readdir(path14, options2, fs$readdirCallback(
615
- path14,
613
+ } : function go$readdir2(path16, options2, cb2, startTime) {
614
+ return fs$readdir(path16, options2, fs$readdirCallback(
615
+ path16,
616
616
  options2,
617
617
  cb2,
618
618
  startTime
619
619
  ));
620
620
  };
621
- return go$readdir(path13, options, cb);
622
- function fs$readdirCallback(path14, options2, cb2, startTime) {
621
+ return go$readdir(path15, options, cb);
622
+ function fs$readdirCallback(path16, options2, cb2, startTime) {
623
623
  return function(err, files) {
624
624
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
625
625
  enqueue([
626
626
  go$readdir,
627
- [path14, options2, cb2],
627
+ [path16, options2, cb2],
628
628
  err,
629
629
  startTime || Date.now(),
630
630
  Date.now()
@@ -639,21 +639,21 @@ var require_graceful_fs = __commonJS({
639
639
  }
640
640
  }
641
641
  if (process.version.substr(0, 4) === "v0.8") {
642
- var legStreams = legacy(fs13);
642
+ var legStreams = legacy(fs15);
643
643
  ReadStream = legStreams.ReadStream;
644
644
  WriteStream = legStreams.WriteStream;
645
645
  }
646
- var fs$ReadStream = fs13.ReadStream;
646
+ var fs$ReadStream = fs15.ReadStream;
647
647
  if (fs$ReadStream) {
648
648
  ReadStream.prototype = Object.create(fs$ReadStream.prototype);
649
649
  ReadStream.prototype.open = ReadStream$open;
650
650
  }
651
- var fs$WriteStream = fs13.WriteStream;
651
+ var fs$WriteStream = fs15.WriteStream;
652
652
  if (fs$WriteStream) {
653
653
  WriteStream.prototype = Object.create(fs$WriteStream.prototype);
654
654
  WriteStream.prototype.open = WriteStream$open;
655
655
  }
656
- Object.defineProperty(fs13, "ReadStream", {
656
+ Object.defineProperty(fs15, "ReadStream", {
657
657
  get: function() {
658
658
  return ReadStream;
659
659
  },
@@ -663,7 +663,7 @@ var require_graceful_fs = __commonJS({
663
663
  enumerable: true,
664
664
  configurable: true
665
665
  });
666
- Object.defineProperty(fs13, "WriteStream", {
666
+ Object.defineProperty(fs15, "WriteStream", {
667
667
  get: function() {
668
668
  return WriteStream;
669
669
  },
@@ -674,7 +674,7 @@ var require_graceful_fs = __commonJS({
674
674
  configurable: true
675
675
  });
676
676
  var FileReadStream = ReadStream;
677
- Object.defineProperty(fs13, "FileReadStream", {
677
+ Object.defineProperty(fs15, "FileReadStream", {
678
678
  get: function() {
679
679
  return FileReadStream;
680
680
  },
@@ -685,7 +685,7 @@ var require_graceful_fs = __commonJS({
685
685
  configurable: true
686
686
  });
687
687
  var FileWriteStream = WriteStream;
688
- Object.defineProperty(fs13, "FileWriteStream", {
688
+ Object.defineProperty(fs15, "FileWriteStream", {
689
689
  get: function() {
690
690
  return FileWriteStream;
691
691
  },
@@ -695,7 +695,7 @@ var require_graceful_fs = __commonJS({
695
695
  enumerable: true,
696
696
  configurable: true
697
697
  });
698
- function ReadStream(path13, options) {
698
+ function ReadStream(path15, options) {
699
699
  if (this instanceof ReadStream)
700
700
  return fs$ReadStream.apply(this, arguments), this;
701
701
  else
@@ -715,7 +715,7 @@ var require_graceful_fs = __commonJS({
715
715
  }
716
716
  });
717
717
  }
718
- function WriteStream(path13, options) {
718
+ function WriteStream(path15, options) {
719
719
  if (this instanceof WriteStream)
720
720
  return fs$WriteStream.apply(this, arguments), this;
721
721
  else
@@ -733,22 +733,22 @@ var require_graceful_fs = __commonJS({
733
733
  }
734
734
  });
735
735
  }
736
- function createReadStream(path13, options) {
737
- return new fs13.ReadStream(path13, options);
736
+ function createReadStream(path15, options) {
737
+ return new fs15.ReadStream(path15, options);
738
738
  }
739
- function createWriteStream(path13, options) {
740
- return new fs13.WriteStream(path13, options);
739
+ function createWriteStream(path15, options) {
740
+ return new fs15.WriteStream(path15, options);
741
741
  }
742
- var fs$open = fs13.open;
743
- fs13.open = open;
744
- function open(path13, flags, mode, cb) {
742
+ var fs$open = fs15.open;
743
+ fs15.open = open;
744
+ function open(path15, flags, mode, cb) {
745
745
  if (typeof mode === "function")
746
746
  cb = mode, mode = null;
747
- return go$open(path13, flags, mode, cb);
748
- function go$open(path14, flags2, mode2, cb2, startTime) {
749
- return fs$open(path14, flags2, mode2, function(err, fd) {
747
+ return go$open(path15, flags, mode, cb);
748
+ function go$open(path16, flags2, mode2, cb2, startTime) {
749
+ return fs$open(path16, flags2, mode2, function(err, fd) {
750
750
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
751
- enqueue([go$open, [path14, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
751
+ enqueue([go$open, [path16, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
752
752
  else {
753
753
  if (typeof cb2 === "function")
754
754
  cb2.apply(this, arguments);
@@ -756,20 +756,20 @@ var require_graceful_fs = __commonJS({
756
756
  });
757
757
  }
758
758
  }
759
- return fs13;
759
+ return fs15;
760
760
  }
761
761
  function enqueue(elem) {
762
762
  debug("ENQUEUE", elem[0].name, elem[1]);
763
- fs12[gracefulQueue].push(elem);
763
+ fs14[gracefulQueue].push(elem);
764
764
  retry();
765
765
  }
766
766
  var retryTimer;
767
767
  function resetQueue() {
768
768
  var now = Date.now();
769
- for (var i = 0; i < fs12[gracefulQueue].length; ++i) {
770
- if (fs12[gracefulQueue][i].length > 2) {
771
- fs12[gracefulQueue][i][3] = now;
772
- fs12[gracefulQueue][i][4] = now;
769
+ for (var i = 0; i < fs14[gracefulQueue].length; ++i) {
770
+ if (fs14[gracefulQueue][i].length > 2) {
771
+ fs14[gracefulQueue][i][3] = now;
772
+ fs14[gracefulQueue][i][4] = now;
773
773
  }
774
774
  }
775
775
  retry();
@@ -777,9 +777,9 @@ var require_graceful_fs = __commonJS({
777
777
  function retry() {
778
778
  clearTimeout(retryTimer);
779
779
  retryTimer = void 0;
780
- if (fs12[gracefulQueue].length === 0)
780
+ if (fs14[gracefulQueue].length === 0)
781
781
  return;
782
- var elem = fs12[gracefulQueue].shift();
782
+ var elem = fs14[gracefulQueue].shift();
783
783
  var fn = elem[0];
784
784
  var args = elem[1];
785
785
  var err = elem[2];
@@ -801,7 +801,7 @@ var require_graceful_fs = __commonJS({
801
801
  debug("RETRY", fn.name, args);
802
802
  fn.apply(null, args.concat([startTime]));
803
803
  } else {
804
- fs12[gracefulQueue].push(elem);
804
+ fs14[gracefulQueue].push(elem);
805
805
  }
806
806
  }
807
807
  if (retryTimer === void 0) {
@@ -1236,10 +1236,10 @@ var require_mtime_precision = __commonJS({
1236
1236
  "node_modules/proper-lockfile/lib/mtime-precision.js"(exports, module) {
1237
1237
  "use strict";
1238
1238
  var cacheSymbol = Symbol();
1239
- function probe(file, fs12, callback) {
1240
- const cachedPrecision = fs12[cacheSymbol];
1239
+ function probe(file, fs14, callback) {
1240
+ const cachedPrecision = fs14[cacheSymbol];
1241
1241
  if (cachedPrecision) {
1242
- return fs12.stat(file, (err, stat) => {
1242
+ return fs14.stat(file, (err, stat) => {
1243
1243
  if (err) {
1244
1244
  return callback(err);
1245
1245
  }
@@ -1247,16 +1247,16 @@ var require_mtime_precision = __commonJS({
1247
1247
  });
1248
1248
  }
1249
1249
  const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
1250
- fs12.utimes(file, mtime, mtime, (err) => {
1250
+ fs14.utimes(file, mtime, mtime, (err) => {
1251
1251
  if (err) {
1252
1252
  return callback(err);
1253
1253
  }
1254
- fs12.stat(file, (err2, stat) => {
1254
+ fs14.stat(file, (err2, stat) => {
1255
1255
  if (err2) {
1256
1256
  return callback(err2);
1257
1257
  }
1258
1258
  const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
1259
- Object.defineProperty(fs12, cacheSymbol, { value: precision });
1259
+ Object.defineProperty(fs14, cacheSymbol, { value: precision });
1260
1260
  callback(null, stat.mtime, precision);
1261
1261
  });
1262
1262
  });
@@ -1277,8 +1277,8 @@ var require_mtime_precision = __commonJS({
1277
1277
  var require_lockfile = __commonJS({
1278
1278
  "node_modules/proper-lockfile/lib/lockfile.js"(exports, module) {
1279
1279
  "use strict";
1280
- var path13 = __require("path");
1281
- var fs12 = require_graceful_fs();
1280
+ var path15 = __require("path");
1281
+ var fs14 = require_graceful_fs();
1282
1282
  var retry = require_retry2();
1283
1283
  var onExit = require_signal_exit();
1284
1284
  var mtimePrecision = require_mtime_precision();
@@ -1288,7 +1288,7 @@ var require_lockfile = __commonJS({
1288
1288
  }
1289
1289
  function resolveCanonicalPath(file, options, callback) {
1290
1290
  if (!options.realpath) {
1291
- return callback(null, path13.resolve(file));
1291
+ return callback(null, path15.resolve(file));
1292
1292
  }
1293
1293
  options.fs.realpath(file, callback);
1294
1294
  }
@@ -1409,7 +1409,7 @@ var require_lockfile = __commonJS({
1409
1409
  update: null,
1410
1410
  realpath: true,
1411
1411
  retries: 0,
1412
- fs: fs12,
1412
+ fs: fs14,
1413
1413
  onCompromised: (err) => {
1414
1414
  throw err;
1415
1415
  },
@@ -1453,7 +1453,7 @@ var require_lockfile = __commonJS({
1453
1453
  }
1454
1454
  function unlock(file, options, callback) {
1455
1455
  options = {
1456
- fs: fs12,
1456
+ fs: fs14,
1457
1457
  realpath: true,
1458
1458
  ...options
1459
1459
  };
@@ -1475,7 +1475,7 @@ var require_lockfile = __commonJS({
1475
1475
  options = {
1476
1476
  stale: 1e4,
1477
1477
  realpath: true,
1478
- fs: fs12,
1478
+ fs: fs14,
1479
1479
  ...options
1480
1480
  };
1481
1481
  options.stale = Math.max(options.stale || 0, 2e3);
@@ -1514,16 +1514,16 @@ var require_lockfile = __commonJS({
1514
1514
  var require_adapter = __commonJS({
1515
1515
  "node_modules/proper-lockfile/lib/adapter.js"(exports, module) {
1516
1516
  "use strict";
1517
- var fs12 = require_graceful_fs();
1518
- function createSyncFs(fs13) {
1517
+ var fs14 = require_graceful_fs();
1518
+ function createSyncFs(fs15) {
1519
1519
  const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
1520
- const newFs = { ...fs13 };
1520
+ const newFs = { ...fs15 };
1521
1521
  methods.forEach((method) => {
1522
1522
  newFs[method] = (...args) => {
1523
1523
  const callback = args.pop();
1524
1524
  let ret;
1525
1525
  try {
1526
- ret = fs13[`${method}Sync`](...args);
1526
+ ret = fs15[`${method}Sync`](...args);
1527
1527
  } catch (err) {
1528
1528
  return callback(err);
1529
1529
  }
@@ -1561,7 +1561,7 @@ var require_adapter = __commonJS({
1561
1561
  }
1562
1562
  function toSyncOptions(options) {
1563
1563
  options = { ...options };
1564
- options.fs = createSyncFs(options.fs || fs12);
1564
+ options.fs = createSyncFs(options.fs || fs14);
1565
1565
  if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
1566
1566
  throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
1567
1567
  }
@@ -2715,17 +2715,17 @@ var require_lib = __commonJS({
2715
2715
  "node_modules/json5/lib/index.js"(exports, module) {
2716
2716
  var parse = require_parse();
2717
2717
  var stringify = require_stringify();
2718
- var JSON52 = {
2718
+ var JSON53 = {
2719
2719
  parse,
2720
2720
  stringify
2721
2721
  };
2722
- module.exports = JSON52;
2722
+ module.exports = JSON53;
2723
2723
  }
2724
2724
  });
2725
2725
 
2726
2726
  // src/index.ts
2727
- import * as fs11 from "node:fs";
2728
- import * as path12 from "node:path";
2727
+ import * as fs13 from "node:fs";
2728
+ import * as path14 from "node:path";
2729
2729
 
2730
2730
  // node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
2731
2731
  var value_exports = {};
@@ -6298,32 +6298,32 @@ var ValueErrorIterator = class {
6298
6298
  return next.done ? void 0 : next.value;
6299
6299
  }
6300
6300
  };
6301
- function Create(errorType, schema, path13, value, errors = []) {
6301
+ function Create(errorType, schema, path15, value, errors = []) {
6302
6302
  return {
6303
6303
  type: errorType,
6304
6304
  schema,
6305
- path: path13,
6305
+ path: path15,
6306
6306
  value,
6307
- message: GetErrorFunction()({ errorType, path: path13, schema, value, errors }),
6307
+ message: GetErrorFunction()({ errorType, path: path15, schema, value, errors }),
6308
6308
  errors
6309
6309
  };
6310
6310
  }
6311
- function* FromAny3(schema, references, path13, value) {
6311
+ function* FromAny3(schema, references, path15, value) {
6312
6312
  }
6313
- function* FromArgument3(schema, references, path13, value) {
6313
+ function* FromArgument3(schema, references, path15, value) {
6314
6314
  }
6315
- function* FromArray8(schema, references, path13, value) {
6315
+ function* FromArray8(schema, references, path15, value) {
6316
6316
  if (!IsArray2(value)) {
6317
- return yield Create(ValueErrorType.Array, schema, path13, value);
6317
+ return yield Create(ValueErrorType.Array, schema, path15, value);
6318
6318
  }
6319
6319
  if (IsDefined2(schema.minItems) && !(value.length >= schema.minItems)) {
6320
- yield Create(ValueErrorType.ArrayMinItems, schema, path13, value);
6320
+ yield Create(ValueErrorType.ArrayMinItems, schema, path15, value);
6321
6321
  }
6322
6322
  if (IsDefined2(schema.maxItems) && !(value.length <= schema.maxItems)) {
6323
- yield Create(ValueErrorType.ArrayMaxItems, schema, path13, value);
6323
+ yield Create(ValueErrorType.ArrayMaxItems, schema, path15, value);
6324
6324
  }
6325
6325
  for (let i = 0; i < value.length; i++) {
6326
- yield* Visit6(schema.items, references, `${path13}/${i}`, value[i]);
6326
+ yield* Visit6(schema.items, references, `${path15}/${i}`, value[i]);
6327
6327
  }
6328
6328
  if (schema.uniqueItems === true && !(function() {
6329
6329
  const set = /* @__PURE__ */ new Set();
@@ -6337,116 +6337,116 @@ function* FromArray8(schema, references, path13, value) {
6337
6337
  }
6338
6338
  return true;
6339
6339
  })()) {
6340
- yield Create(ValueErrorType.ArrayUniqueItems, schema, path13, value);
6340
+ yield Create(ValueErrorType.ArrayUniqueItems, schema, path15, value);
6341
6341
  }
6342
6342
  if (!(IsDefined2(schema.contains) || IsDefined2(schema.minContains) || IsDefined2(schema.maxContains))) {
6343
6343
  return;
6344
6344
  }
6345
6345
  const containsSchema = IsDefined2(schema.contains) ? schema.contains : Never();
6346
- const containsCount = value.reduce((acc, value2, index) => Visit6(containsSchema, references, `${path13}${index}`, value2).next().done === true ? acc + 1 : acc, 0);
6346
+ const containsCount = value.reduce((acc, value2, index) => Visit6(containsSchema, references, `${path15}${index}`, value2).next().done === true ? acc + 1 : acc, 0);
6347
6347
  if (containsCount === 0) {
6348
- yield Create(ValueErrorType.ArrayContains, schema, path13, value);
6348
+ yield Create(ValueErrorType.ArrayContains, schema, path15, value);
6349
6349
  }
6350
6350
  if (IsNumber2(schema.minContains) && containsCount < schema.minContains) {
6351
- yield Create(ValueErrorType.ArrayMinContains, schema, path13, value);
6351
+ yield Create(ValueErrorType.ArrayMinContains, schema, path15, value);
6352
6352
  }
6353
6353
  if (IsNumber2(schema.maxContains) && containsCount > schema.maxContains) {
6354
- yield Create(ValueErrorType.ArrayMaxContains, schema, path13, value);
6354
+ yield Create(ValueErrorType.ArrayMaxContains, schema, path15, value);
6355
6355
  }
6356
6356
  }
6357
- function* FromAsyncIterator5(schema, references, path13, value) {
6357
+ function* FromAsyncIterator5(schema, references, path15, value) {
6358
6358
  if (!IsAsyncIterator2(value))
6359
- yield Create(ValueErrorType.AsyncIterator, schema, path13, value);
6359
+ yield Create(ValueErrorType.AsyncIterator, schema, path15, value);
6360
6360
  }
6361
- function* FromBigInt3(schema, references, path13, value) {
6361
+ function* FromBigInt3(schema, references, path15, value) {
6362
6362
  if (!IsBigInt2(value))
6363
- return yield Create(ValueErrorType.BigInt, schema, path13, value);
6363
+ return yield Create(ValueErrorType.BigInt, schema, path15, value);
6364
6364
  if (IsDefined2(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
6365
- yield Create(ValueErrorType.BigIntExclusiveMaximum, schema, path13, value);
6365
+ yield Create(ValueErrorType.BigIntExclusiveMaximum, schema, path15, value);
6366
6366
  }
6367
6367
  if (IsDefined2(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
6368
- yield Create(ValueErrorType.BigIntExclusiveMinimum, schema, path13, value);
6368
+ yield Create(ValueErrorType.BigIntExclusiveMinimum, schema, path15, value);
6369
6369
  }
6370
6370
  if (IsDefined2(schema.maximum) && !(value <= schema.maximum)) {
6371
- yield Create(ValueErrorType.BigIntMaximum, schema, path13, value);
6371
+ yield Create(ValueErrorType.BigIntMaximum, schema, path15, value);
6372
6372
  }
6373
6373
  if (IsDefined2(schema.minimum) && !(value >= schema.minimum)) {
6374
- yield Create(ValueErrorType.BigIntMinimum, schema, path13, value);
6374
+ yield Create(ValueErrorType.BigIntMinimum, schema, path15, value);
6375
6375
  }
6376
6376
  if (IsDefined2(schema.multipleOf) && !(value % schema.multipleOf === BigInt(0))) {
6377
- yield Create(ValueErrorType.BigIntMultipleOf, schema, path13, value);
6377
+ yield Create(ValueErrorType.BigIntMultipleOf, schema, path15, value);
6378
6378
  }
6379
6379
  }
6380
- function* FromBoolean3(schema, references, path13, value) {
6380
+ function* FromBoolean3(schema, references, path15, value) {
6381
6381
  if (!IsBoolean2(value))
6382
- yield Create(ValueErrorType.Boolean, schema, path13, value);
6382
+ yield Create(ValueErrorType.Boolean, schema, path15, value);
6383
6383
  }
6384
- function* FromConstructor5(schema, references, path13, value) {
6385
- yield* Visit6(schema.returns, references, path13, value.prototype);
6384
+ function* FromConstructor5(schema, references, path15, value) {
6385
+ yield* Visit6(schema.returns, references, path15, value.prototype);
6386
6386
  }
6387
- function* FromDate3(schema, references, path13, value) {
6387
+ function* FromDate3(schema, references, path15, value) {
6388
6388
  if (!IsDate2(value))
6389
- return yield Create(ValueErrorType.Date, schema, path13, value);
6389
+ return yield Create(ValueErrorType.Date, schema, path15, value);
6390
6390
  if (IsDefined2(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
6391
- yield Create(ValueErrorType.DateExclusiveMaximumTimestamp, schema, path13, value);
6391
+ yield Create(ValueErrorType.DateExclusiveMaximumTimestamp, schema, path15, value);
6392
6392
  }
6393
6393
  if (IsDefined2(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
6394
- yield Create(ValueErrorType.DateExclusiveMinimumTimestamp, schema, path13, value);
6394
+ yield Create(ValueErrorType.DateExclusiveMinimumTimestamp, schema, path15, value);
6395
6395
  }
6396
6396
  if (IsDefined2(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
6397
- yield Create(ValueErrorType.DateMaximumTimestamp, schema, path13, value);
6397
+ yield Create(ValueErrorType.DateMaximumTimestamp, schema, path15, value);
6398
6398
  }
6399
6399
  if (IsDefined2(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
6400
- yield Create(ValueErrorType.DateMinimumTimestamp, schema, path13, value);
6400
+ yield Create(ValueErrorType.DateMinimumTimestamp, schema, path15, value);
6401
6401
  }
6402
6402
  if (IsDefined2(schema.multipleOfTimestamp) && !(value.getTime() % schema.multipleOfTimestamp === 0)) {
6403
- yield Create(ValueErrorType.DateMultipleOfTimestamp, schema, path13, value);
6403
+ yield Create(ValueErrorType.DateMultipleOfTimestamp, schema, path15, value);
6404
6404
  }
6405
6405
  }
6406
- function* FromFunction5(schema, references, path13, value) {
6406
+ function* FromFunction5(schema, references, path15, value) {
6407
6407
  if (!IsFunction2(value))
6408
- yield Create(ValueErrorType.Function, schema, path13, value);
6408
+ yield Create(ValueErrorType.Function, schema, path15, value);
6409
6409
  }
6410
- function* FromImport2(schema, references, path13, value) {
6410
+ function* FromImport2(schema, references, path15, value) {
6411
6411
  const definitions = globalThis.Object.values(schema.$defs);
6412
6412
  const target = schema.$defs[schema.$ref];
6413
- yield* Visit6(target, [...references, ...definitions], path13, value);
6413
+ yield* Visit6(target, [...references, ...definitions], path15, value);
6414
6414
  }
6415
- function* FromInteger3(schema, references, path13, value) {
6415
+ function* FromInteger3(schema, references, path15, value) {
6416
6416
  if (!IsInteger(value))
6417
- return yield Create(ValueErrorType.Integer, schema, path13, value);
6417
+ return yield Create(ValueErrorType.Integer, schema, path15, value);
6418
6418
  if (IsDefined2(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
6419
- yield Create(ValueErrorType.IntegerExclusiveMaximum, schema, path13, value);
6419
+ yield Create(ValueErrorType.IntegerExclusiveMaximum, schema, path15, value);
6420
6420
  }
6421
6421
  if (IsDefined2(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
6422
- yield Create(ValueErrorType.IntegerExclusiveMinimum, schema, path13, value);
6422
+ yield Create(ValueErrorType.IntegerExclusiveMinimum, schema, path15, value);
6423
6423
  }
6424
6424
  if (IsDefined2(schema.maximum) && !(value <= schema.maximum)) {
6425
- yield Create(ValueErrorType.IntegerMaximum, schema, path13, value);
6425
+ yield Create(ValueErrorType.IntegerMaximum, schema, path15, value);
6426
6426
  }
6427
6427
  if (IsDefined2(schema.minimum) && !(value >= schema.minimum)) {
6428
- yield Create(ValueErrorType.IntegerMinimum, schema, path13, value);
6428
+ yield Create(ValueErrorType.IntegerMinimum, schema, path15, value);
6429
6429
  }
6430
6430
  if (IsDefined2(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
6431
- yield Create(ValueErrorType.IntegerMultipleOf, schema, path13, value);
6431
+ yield Create(ValueErrorType.IntegerMultipleOf, schema, path15, value);
6432
6432
  }
6433
6433
  }
6434
- function* FromIntersect10(schema, references, path13, value) {
6434
+ function* FromIntersect10(schema, references, path15, value) {
6435
6435
  let hasError = false;
6436
6436
  for (const inner of schema.allOf) {
6437
- for (const error of Visit6(inner, references, path13, value)) {
6437
+ for (const error of Visit6(inner, references, path15, value)) {
6438
6438
  hasError = true;
6439
6439
  yield error;
6440
6440
  }
6441
6441
  }
6442
6442
  if (hasError) {
6443
- return yield Create(ValueErrorType.Intersect, schema, path13, value);
6443
+ return yield Create(ValueErrorType.Intersect, schema, path15, value);
6444
6444
  }
6445
6445
  if (schema.unevaluatedProperties === false) {
6446
6446
  const keyCheck = new RegExp(KeyOfPattern(schema));
6447
6447
  for (const valueKey of Object.getOwnPropertyNames(value)) {
6448
6448
  if (!keyCheck.test(valueKey)) {
6449
- yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path13}/${valueKey}`, value);
6449
+ yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path15}/${valueKey}`, value);
6450
6450
  }
6451
6451
  }
6452
6452
  }
@@ -6454,59 +6454,59 @@ function* FromIntersect10(schema, references, path13, value) {
6454
6454
  const keyCheck = new RegExp(KeyOfPattern(schema));
6455
6455
  for (const valueKey of Object.getOwnPropertyNames(value)) {
6456
6456
  if (!keyCheck.test(valueKey)) {
6457
- const next = Visit6(schema.unevaluatedProperties, references, `${path13}/${valueKey}`, value[valueKey]).next();
6457
+ const next = Visit6(schema.unevaluatedProperties, references, `${path15}/${valueKey}`, value[valueKey]).next();
6458
6458
  if (!next.done)
6459
6459
  yield next.value;
6460
6460
  }
6461
6461
  }
6462
6462
  }
6463
6463
  }
6464
- function* FromIterator5(schema, references, path13, value) {
6464
+ function* FromIterator5(schema, references, path15, value) {
6465
6465
  if (!IsIterator2(value))
6466
- yield Create(ValueErrorType.Iterator, schema, path13, value);
6466
+ yield Create(ValueErrorType.Iterator, schema, path15, value);
6467
6467
  }
6468
- function* FromLiteral4(schema, references, path13, value) {
6468
+ function* FromLiteral4(schema, references, path15, value) {
6469
6469
  if (!(value === schema.const))
6470
- yield Create(ValueErrorType.Literal, schema, path13, value);
6470
+ yield Create(ValueErrorType.Literal, schema, path15, value);
6471
6471
  }
6472
- function* FromNever3(schema, references, path13, value) {
6473
- yield Create(ValueErrorType.Never, schema, path13, value);
6472
+ function* FromNever3(schema, references, path15, value) {
6473
+ yield Create(ValueErrorType.Never, schema, path15, value);
6474
6474
  }
6475
- function* FromNot3(schema, references, path13, value) {
6476
- if (Visit6(schema.not, references, path13, value).next().done === true)
6477
- yield Create(ValueErrorType.Not, schema, path13, value);
6475
+ function* FromNot3(schema, references, path15, value) {
6476
+ if (Visit6(schema.not, references, path15, value).next().done === true)
6477
+ yield Create(ValueErrorType.Not, schema, path15, value);
6478
6478
  }
6479
- function* FromNull3(schema, references, path13, value) {
6479
+ function* FromNull3(schema, references, path15, value) {
6480
6480
  if (!IsNull2(value))
6481
- yield Create(ValueErrorType.Null, schema, path13, value);
6481
+ yield Create(ValueErrorType.Null, schema, path15, value);
6482
6482
  }
6483
- function* FromNumber3(schema, references, path13, value) {
6483
+ function* FromNumber3(schema, references, path15, value) {
6484
6484
  if (!TypeSystemPolicy.IsNumberLike(value))
6485
- return yield Create(ValueErrorType.Number, schema, path13, value);
6485
+ return yield Create(ValueErrorType.Number, schema, path15, value);
6486
6486
  if (IsDefined2(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
6487
- yield Create(ValueErrorType.NumberExclusiveMaximum, schema, path13, value);
6487
+ yield Create(ValueErrorType.NumberExclusiveMaximum, schema, path15, value);
6488
6488
  }
6489
6489
  if (IsDefined2(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
6490
- yield Create(ValueErrorType.NumberExclusiveMinimum, schema, path13, value);
6490
+ yield Create(ValueErrorType.NumberExclusiveMinimum, schema, path15, value);
6491
6491
  }
6492
6492
  if (IsDefined2(schema.maximum) && !(value <= schema.maximum)) {
6493
- yield Create(ValueErrorType.NumberMaximum, schema, path13, value);
6493
+ yield Create(ValueErrorType.NumberMaximum, schema, path15, value);
6494
6494
  }
6495
6495
  if (IsDefined2(schema.minimum) && !(value >= schema.minimum)) {
6496
- yield Create(ValueErrorType.NumberMinimum, schema, path13, value);
6496
+ yield Create(ValueErrorType.NumberMinimum, schema, path15, value);
6497
6497
  }
6498
6498
  if (IsDefined2(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
6499
- yield Create(ValueErrorType.NumberMultipleOf, schema, path13, value);
6499
+ yield Create(ValueErrorType.NumberMultipleOf, schema, path15, value);
6500
6500
  }
6501
6501
  }
6502
- function* FromObject9(schema, references, path13, value) {
6502
+ function* FromObject9(schema, references, path15, value) {
6503
6503
  if (!TypeSystemPolicy.IsObjectLike(value))
6504
- return yield Create(ValueErrorType.Object, schema, path13, value);
6504
+ return yield Create(ValueErrorType.Object, schema, path15, value);
6505
6505
  if (IsDefined2(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
6506
- yield Create(ValueErrorType.ObjectMinProperties, schema, path13, value);
6506
+ yield Create(ValueErrorType.ObjectMinProperties, schema, path15, value);
6507
6507
  }
6508
6508
  if (IsDefined2(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
6509
- yield Create(ValueErrorType.ObjectMaxProperties, schema, path13, value);
6509
+ yield Create(ValueErrorType.ObjectMaxProperties, schema, path15, value);
6510
6510
  }
6511
6511
  const requiredKeys = Array.isArray(schema.required) ? schema.required : [];
6512
6512
  const knownKeys = Object.getOwnPropertyNames(schema.properties);
@@ -6514,12 +6514,12 @@ function* FromObject9(schema, references, path13, value) {
6514
6514
  for (const requiredKey of requiredKeys) {
6515
6515
  if (unknownKeys.includes(requiredKey))
6516
6516
  continue;
6517
- yield Create(ValueErrorType.ObjectRequiredProperty, schema.properties[requiredKey], `${path13}/${EscapeKey(requiredKey)}`, void 0);
6517
+ yield Create(ValueErrorType.ObjectRequiredProperty, schema.properties[requiredKey], `${path15}/${EscapeKey(requiredKey)}`, void 0);
6518
6518
  }
6519
6519
  if (schema.additionalProperties === false) {
6520
6520
  for (const valueKey of unknownKeys) {
6521
6521
  if (!knownKeys.includes(valueKey)) {
6522
- yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path13}/${EscapeKey(valueKey)}`, value[valueKey]);
6522
+ yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path15}/${EscapeKey(valueKey)}`, value[valueKey]);
6523
6523
  }
6524
6524
  }
6525
6525
  }
@@ -6527,235 +6527,235 @@ function* FromObject9(schema, references, path13, value) {
6527
6527
  for (const valueKey of unknownKeys) {
6528
6528
  if (knownKeys.includes(valueKey))
6529
6529
  continue;
6530
- yield* Visit6(schema.additionalProperties, references, `${path13}/${EscapeKey(valueKey)}`, value[valueKey]);
6530
+ yield* Visit6(schema.additionalProperties, references, `${path15}/${EscapeKey(valueKey)}`, value[valueKey]);
6531
6531
  }
6532
6532
  }
6533
6533
  for (const knownKey of knownKeys) {
6534
6534
  const property = schema.properties[knownKey];
6535
6535
  if (schema.required && schema.required.includes(knownKey)) {
6536
- yield* Visit6(property, references, `${path13}/${EscapeKey(knownKey)}`, value[knownKey]);
6536
+ yield* Visit6(property, references, `${path15}/${EscapeKey(knownKey)}`, value[knownKey]);
6537
6537
  if (ExtendsUndefinedCheck(schema) && !(knownKey in value)) {
6538
- yield Create(ValueErrorType.ObjectRequiredProperty, property, `${path13}/${EscapeKey(knownKey)}`, void 0);
6538
+ yield Create(ValueErrorType.ObjectRequiredProperty, property, `${path15}/${EscapeKey(knownKey)}`, void 0);
6539
6539
  }
6540
6540
  } else {
6541
6541
  if (TypeSystemPolicy.IsExactOptionalProperty(value, knownKey)) {
6542
- yield* Visit6(property, references, `${path13}/${EscapeKey(knownKey)}`, value[knownKey]);
6542
+ yield* Visit6(property, references, `${path15}/${EscapeKey(knownKey)}`, value[knownKey]);
6543
6543
  }
6544
6544
  }
6545
6545
  }
6546
6546
  }
6547
- function* FromPromise5(schema, references, path13, value) {
6547
+ function* FromPromise5(schema, references, path15, value) {
6548
6548
  if (!IsPromise(value))
6549
- yield Create(ValueErrorType.Promise, schema, path13, value);
6549
+ yield Create(ValueErrorType.Promise, schema, path15, value);
6550
6550
  }
6551
- function* FromRecord5(schema, references, path13, value) {
6551
+ function* FromRecord5(schema, references, path15, value) {
6552
6552
  if (!TypeSystemPolicy.IsRecordLike(value))
6553
- return yield Create(ValueErrorType.Object, schema, path13, value);
6553
+ return yield Create(ValueErrorType.Object, schema, path15, value);
6554
6554
  if (IsDefined2(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
6555
- yield Create(ValueErrorType.ObjectMinProperties, schema, path13, value);
6555
+ yield Create(ValueErrorType.ObjectMinProperties, schema, path15, value);
6556
6556
  }
6557
6557
  if (IsDefined2(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
6558
- yield Create(ValueErrorType.ObjectMaxProperties, schema, path13, value);
6558
+ yield Create(ValueErrorType.ObjectMaxProperties, schema, path15, value);
6559
6559
  }
6560
6560
  const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
6561
6561
  const regex = new RegExp(patternKey);
6562
6562
  for (const [propertyKey, propertyValue] of Object.entries(value)) {
6563
6563
  if (regex.test(propertyKey))
6564
- yield* Visit6(patternSchema, references, `${path13}/${EscapeKey(propertyKey)}`, propertyValue);
6564
+ yield* Visit6(patternSchema, references, `${path15}/${EscapeKey(propertyKey)}`, propertyValue);
6565
6565
  }
6566
6566
  if (typeof schema.additionalProperties === "object") {
6567
6567
  for (const [propertyKey, propertyValue] of Object.entries(value)) {
6568
6568
  if (!regex.test(propertyKey))
6569
- yield* Visit6(schema.additionalProperties, references, `${path13}/${EscapeKey(propertyKey)}`, propertyValue);
6569
+ yield* Visit6(schema.additionalProperties, references, `${path15}/${EscapeKey(propertyKey)}`, propertyValue);
6570
6570
  }
6571
6571
  }
6572
6572
  if (schema.additionalProperties === false) {
6573
6573
  for (const [propertyKey, propertyValue] of Object.entries(value)) {
6574
6574
  if (regex.test(propertyKey))
6575
6575
  continue;
6576
- return yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path13}/${EscapeKey(propertyKey)}`, propertyValue);
6576
+ return yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path15}/${EscapeKey(propertyKey)}`, propertyValue);
6577
6577
  }
6578
6578
  }
6579
6579
  }
6580
- function* FromRef6(schema, references, path13, value) {
6581
- yield* Visit6(Deref(schema, references), references, path13, value);
6580
+ function* FromRef6(schema, references, path15, value) {
6581
+ yield* Visit6(Deref(schema, references), references, path15, value);
6582
6582
  }
6583
- function* FromRegExp3(schema, references, path13, value) {
6583
+ function* FromRegExp3(schema, references, path15, value) {
6584
6584
  if (!IsString2(value))
6585
- return yield Create(ValueErrorType.String, schema, path13, value);
6585
+ return yield Create(ValueErrorType.String, schema, path15, value);
6586
6586
  if (IsDefined2(schema.minLength) && !(value.length >= schema.minLength)) {
6587
- yield Create(ValueErrorType.StringMinLength, schema, path13, value);
6587
+ yield Create(ValueErrorType.StringMinLength, schema, path15, value);
6588
6588
  }
6589
6589
  if (IsDefined2(schema.maxLength) && !(value.length <= schema.maxLength)) {
6590
- yield Create(ValueErrorType.StringMaxLength, schema, path13, value);
6590
+ yield Create(ValueErrorType.StringMaxLength, schema, path15, value);
6591
6591
  }
6592
6592
  const regex = new RegExp(schema.source, schema.flags);
6593
6593
  if (!regex.test(value)) {
6594
- return yield Create(ValueErrorType.RegExp, schema, path13, value);
6594
+ return yield Create(ValueErrorType.RegExp, schema, path15, value);
6595
6595
  }
6596
6596
  }
6597
- function* FromString3(schema, references, path13, value) {
6597
+ function* FromString3(schema, references, path15, value) {
6598
6598
  if (!IsString2(value))
6599
- return yield Create(ValueErrorType.String, schema, path13, value);
6599
+ return yield Create(ValueErrorType.String, schema, path15, value);
6600
6600
  if (IsDefined2(schema.minLength) && !(value.length >= schema.minLength)) {
6601
- yield Create(ValueErrorType.StringMinLength, schema, path13, value);
6601
+ yield Create(ValueErrorType.StringMinLength, schema, path15, value);
6602
6602
  }
6603
6603
  if (IsDefined2(schema.maxLength) && !(value.length <= schema.maxLength)) {
6604
- yield Create(ValueErrorType.StringMaxLength, schema, path13, value);
6604
+ yield Create(ValueErrorType.StringMaxLength, schema, path15, value);
6605
6605
  }
6606
6606
  if (IsString2(schema.pattern)) {
6607
6607
  const regex = new RegExp(schema.pattern);
6608
6608
  if (!regex.test(value)) {
6609
- yield Create(ValueErrorType.StringPattern, schema, path13, value);
6609
+ yield Create(ValueErrorType.StringPattern, schema, path15, value);
6610
6610
  }
6611
6611
  }
6612
6612
  if (IsString2(schema.format)) {
6613
6613
  if (!format_exports.Has(schema.format)) {
6614
- yield Create(ValueErrorType.StringFormatUnknown, schema, path13, value);
6614
+ yield Create(ValueErrorType.StringFormatUnknown, schema, path15, value);
6615
6615
  } else {
6616
6616
  const format = format_exports.Get(schema.format);
6617
6617
  if (!format(value)) {
6618
- yield Create(ValueErrorType.StringFormat, schema, path13, value);
6618
+ yield Create(ValueErrorType.StringFormat, schema, path15, value);
6619
6619
  }
6620
6620
  }
6621
6621
  }
6622
6622
  }
6623
- function* FromSymbol3(schema, references, path13, value) {
6623
+ function* FromSymbol3(schema, references, path15, value) {
6624
6624
  if (!IsSymbol2(value))
6625
- yield Create(ValueErrorType.Symbol, schema, path13, value);
6625
+ yield Create(ValueErrorType.Symbol, schema, path15, value);
6626
6626
  }
6627
- function* FromTemplateLiteral5(schema, references, path13, value) {
6627
+ function* FromTemplateLiteral5(schema, references, path15, value) {
6628
6628
  if (!IsString2(value))
6629
- return yield Create(ValueErrorType.String, schema, path13, value);
6629
+ return yield Create(ValueErrorType.String, schema, path15, value);
6630
6630
  const regex = new RegExp(schema.pattern);
6631
6631
  if (!regex.test(value)) {
6632
- yield Create(ValueErrorType.StringPattern, schema, path13, value);
6632
+ yield Create(ValueErrorType.StringPattern, schema, path15, value);
6633
6633
  }
6634
6634
  }
6635
- function* FromThis2(schema, references, path13, value) {
6636
- yield* Visit6(Deref(schema, references), references, path13, value);
6635
+ function* FromThis2(schema, references, path15, value) {
6636
+ yield* Visit6(Deref(schema, references), references, path15, value);
6637
6637
  }
6638
- function* FromTuple7(schema, references, path13, value) {
6638
+ function* FromTuple7(schema, references, path15, value) {
6639
6639
  if (!IsArray2(value))
6640
- return yield Create(ValueErrorType.Tuple, schema, path13, value);
6640
+ return yield Create(ValueErrorType.Tuple, schema, path15, value);
6641
6641
  if (schema.items === void 0 && !(value.length === 0)) {
6642
- return yield Create(ValueErrorType.TupleLength, schema, path13, value);
6642
+ return yield Create(ValueErrorType.TupleLength, schema, path15, value);
6643
6643
  }
6644
6644
  if (!(value.length === schema.maxItems)) {
6645
- return yield Create(ValueErrorType.TupleLength, schema, path13, value);
6645
+ return yield Create(ValueErrorType.TupleLength, schema, path15, value);
6646
6646
  }
6647
6647
  if (!schema.items) {
6648
6648
  return;
6649
6649
  }
6650
6650
  for (let i = 0; i < schema.items.length; i++) {
6651
- yield* Visit6(schema.items[i], references, `${path13}/${i}`, value[i]);
6651
+ yield* Visit6(schema.items[i], references, `${path15}/${i}`, value[i]);
6652
6652
  }
6653
6653
  }
6654
- function* FromUndefined3(schema, references, path13, value) {
6654
+ function* FromUndefined3(schema, references, path15, value) {
6655
6655
  if (!IsUndefined2(value))
6656
- yield Create(ValueErrorType.Undefined, schema, path13, value);
6656
+ yield Create(ValueErrorType.Undefined, schema, path15, value);
6657
6657
  }
6658
- function* FromUnion12(schema, references, path13, value) {
6658
+ function* FromUnion12(schema, references, path15, value) {
6659
6659
  if (Check(schema, references, value))
6660
6660
  return;
6661
- const errors = schema.anyOf.map((variant) => new ValueErrorIterator(Visit6(variant, references, path13, value)));
6662
- yield Create(ValueErrorType.Union, schema, path13, value, errors);
6661
+ const errors = schema.anyOf.map((variant) => new ValueErrorIterator(Visit6(variant, references, path15, value)));
6662
+ yield Create(ValueErrorType.Union, schema, path15, value, errors);
6663
6663
  }
6664
- function* FromUint8Array3(schema, references, path13, value) {
6664
+ function* FromUint8Array3(schema, references, path15, value) {
6665
6665
  if (!IsUint8Array2(value))
6666
- return yield Create(ValueErrorType.Uint8Array, schema, path13, value);
6666
+ return yield Create(ValueErrorType.Uint8Array, schema, path15, value);
6667
6667
  if (IsDefined2(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
6668
- yield Create(ValueErrorType.Uint8ArrayMaxByteLength, schema, path13, value);
6668
+ yield Create(ValueErrorType.Uint8ArrayMaxByteLength, schema, path15, value);
6669
6669
  }
6670
6670
  if (IsDefined2(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
6671
- yield Create(ValueErrorType.Uint8ArrayMinByteLength, schema, path13, value);
6671
+ yield Create(ValueErrorType.Uint8ArrayMinByteLength, schema, path15, value);
6672
6672
  }
6673
6673
  }
6674
- function* FromUnknown3(schema, references, path13, value) {
6674
+ function* FromUnknown3(schema, references, path15, value) {
6675
6675
  }
6676
- function* FromVoid3(schema, references, path13, value) {
6676
+ function* FromVoid3(schema, references, path15, value) {
6677
6677
  if (!TypeSystemPolicy.IsVoidLike(value))
6678
- yield Create(ValueErrorType.Void, schema, path13, value);
6678
+ yield Create(ValueErrorType.Void, schema, path15, value);
6679
6679
  }
6680
- function* FromKind2(schema, references, path13, value) {
6680
+ function* FromKind2(schema, references, path15, value) {
6681
6681
  const check2 = type_exports2.Get(schema[Kind]);
6682
6682
  if (!check2(schema, value))
6683
- yield Create(ValueErrorType.Kind, schema, path13, value);
6683
+ yield Create(ValueErrorType.Kind, schema, path15, value);
6684
6684
  }
6685
- function* Visit6(schema, references, path13, value) {
6685
+ function* Visit6(schema, references, path15, value) {
6686
6686
  const references_ = IsDefined2(schema.$id) ? [...references, schema] : references;
6687
6687
  const schema_ = schema;
6688
6688
  switch (schema_[Kind]) {
6689
6689
  case "Any":
6690
- return yield* FromAny3(schema_, references_, path13, value);
6690
+ return yield* FromAny3(schema_, references_, path15, value);
6691
6691
  case "Argument":
6692
- return yield* FromArgument3(schema_, references_, path13, value);
6692
+ return yield* FromArgument3(schema_, references_, path15, value);
6693
6693
  case "Array":
6694
- return yield* FromArray8(schema_, references_, path13, value);
6694
+ return yield* FromArray8(schema_, references_, path15, value);
6695
6695
  case "AsyncIterator":
6696
- return yield* FromAsyncIterator5(schema_, references_, path13, value);
6696
+ return yield* FromAsyncIterator5(schema_, references_, path15, value);
6697
6697
  case "BigInt":
6698
- return yield* FromBigInt3(schema_, references_, path13, value);
6698
+ return yield* FromBigInt3(schema_, references_, path15, value);
6699
6699
  case "Boolean":
6700
- return yield* FromBoolean3(schema_, references_, path13, value);
6700
+ return yield* FromBoolean3(schema_, references_, path15, value);
6701
6701
  case "Constructor":
6702
- return yield* FromConstructor5(schema_, references_, path13, value);
6702
+ return yield* FromConstructor5(schema_, references_, path15, value);
6703
6703
  case "Date":
6704
- return yield* FromDate3(schema_, references_, path13, value);
6704
+ return yield* FromDate3(schema_, references_, path15, value);
6705
6705
  case "Function":
6706
- return yield* FromFunction5(schema_, references_, path13, value);
6706
+ return yield* FromFunction5(schema_, references_, path15, value);
6707
6707
  case "Import":
6708
- return yield* FromImport2(schema_, references_, path13, value);
6708
+ return yield* FromImport2(schema_, references_, path15, value);
6709
6709
  case "Integer":
6710
- return yield* FromInteger3(schema_, references_, path13, value);
6710
+ return yield* FromInteger3(schema_, references_, path15, value);
6711
6711
  case "Intersect":
6712
- return yield* FromIntersect10(schema_, references_, path13, value);
6712
+ return yield* FromIntersect10(schema_, references_, path15, value);
6713
6713
  case "Iterator":
6714
- return yield* FromIterator5(schema_, references_, path13, value);
6714
+ return yield* FromIterator5(schema_, references_, path15, value);
6715
6715
  case "Literal":
6716
- return yield* FromLiteral4(schema_, references_, path13, value);
6716
+ return yield* FromLiteral4(schema_, references_, path15, value);
6717
6717
  case "Never":
6718
- return yield* FromNever3(schema_, references_, path13, value);
6718
+ return yield* FromNever3(schema_, references_, path15, value);
6719
6719
  case "Not":
6720
- return yield* FromNot3(schema_, references_, path13, value);
6720
+ return yield* FromNot3(schema_, references_, path15, value);
6721
6721
  case "Null":
6722
- return yield* FromNull3(schema_, references_, path13, value);
6722
+ return yield* FromNull3(schema_, references_, path15, value);
6723
6723
  case "Number":
6724
- return yield* FromNumber3(schema_, references_, path13, value);
6724
+ return yield* FromNumber3(schema_, references_, path15, value);
6725
6725
  case "Object":
6726
- return yield* FromObject9(schema_, references_, path13, value);
6726
+ return yield* FromObject9(schema_, references_, path15, value);
6727
6727
  case "Promise":
6728
- return yield* FromPromise5(schema_, references_, path13, value);
6728
+ return yield* FromPromise5(schema_, references_, path15, value);
6729
6729
  case "Record":
6730
- return yield* FromRecord5(schema_, references_, path13, value);
6730
+ return yield* FromRecord5(schema_, references_, path15, value);
6731
6731
  case "Ref":
6732
- return yield* FromRef6(schema_, references_, path13, value);
6732
+ return yield* FromRef6(schema_, references_, path15, value);
6733
6733
  case "RegExp":
6734
- return yield* FromRegExp3(schema_, references_, path13, value);
6734
+ return yield* FromRegExp3(schema_, references_, path15, value);
6735
6735
  case "String":
6736
- return yield* FromString3(schema_, references_, path13, value);
6736
+ return yield* FromString3(schema_, references_, path15, value);
6737
6737
  case "Symbol":
6738
- return yield* FromSymbol3(schema_, references_, path13, value);
6738
+ return yield* FromSymbol3(schema_, references_, path15, value);
6739
6739
  case "TemplateLiteral":
6740
- return yield* FromTemplateLiteral5(schema_, references_, path13, value);
6740
+ return yield* FromTemplateLiteral5(schema_, references_, path15, value);
6741
6741
  case "This":
6742
- return yield* FromThis2(schema_, references_, path13, value);
6742
+ return yield* FromThis2(schema_, references_, path15, value);
6743
6743
  case "Tuple":
6744
- return yield* FromTuple7(schema_, references_, path13, value);
6744
+ return yield* FromTuple7(schema_, references_, path15, value);
6745
6745
  case "Undefined":
6746
- return yield* FromUndefined3(schema_, references_, path13, value);
6746
+ return yield* FromUndefined3(schema_, references_, path15, value);
6747
6747
  case "Union":
6748
- return yield* FromUnion12(schema_, references_, path13, value);
6748
+ return yield* FromUnion12(schema_, references_, path15, value);
6749
6749
  case "Uint8Array":
6750
- return yield* FromUint8Array3(schema_, references_, path13, value);
6750
+ return yield* FromUint8Array3(schema_, references_, path15, value);
6751
6751
  case "Unknown":
6752
- return yield* FromUnknown3(schema_, references_, path13, value);
6752
+ return yield* FromUnknown3(schema_, references_, path15, value);
6753
6753
  case "Void":
6754
- return yield* FromVoid3(schema_, references_, path13, value);
6754
+ return yield* FromVoid3(schema_, references_, path15, value);
6755
6755
  default:
6756
6756
  if (!type_exports2.Has(schema_[Kind]))
6757
6757
  throw new ValueErrorsUnknownTypeError(schema);
6758
- return yield* FromKind2(schema_, references_, path13, value);
6758
+ return yield* FromKind2(schema_, references_, path15, value);
6759
6759
  }
6760
6760
  }
6761
6761
  function Errors(...args) {
@@ -7797,58 +7797,58 @@ var TransformDecodeCheckError = class extends TypeBoxError {
7797
7797
  }
7798
7798
  };
7799
7799
  var TransformDecodeError = class extends TypeBoxError {
7800
- constructor(schema, path13, value, error) {
7800
+ constructor(schema, path15, value, error) {
7801
7801
  super(error instanceof Error ? error.message : "Unknown error");
7802
7802
  this.schema = schema;
7803
- this.path = path13;
7803
+ this.path = path15;
7804
7804
  this.value = value;
7805
7805
  this.error = error;
7806
7806
  }
7807
7807
  };
7808
- function Default3(schema, path13, value) {
7808
+ function Default3(schema, path15, value) {
7809
7809
  try {
7810
7810
  return IsTransform(schema) ? schema[TransformKind].Decode(value) : value;
7811
7811
  } catch (error) {
7812
- throw new TransformDecodeError(schema, path13, value, error);
7812
+ throw new TransformDecodeError(schema, path15, value, error);
7813
7813
  }
7814
7814
  }
7815
- function FromArray14(schema, references, path13, value) {
7816
- return IsArray2(value) ? Default3(schema, path13, value.map((value2, index) => Visit11(schema.items, references, `${path13}/${index}`, value2))) : Default3(schema, path13, value);
7815
+ function FromArray14(schema, references, path15, value) {
7816
+ return IsArray2(value) ? Default3(schema, path15, value.map((value2, index) => Visit11(schema.items, references, `${path15}/${index}`, value2))) : Default3(schema, path15, value);
7817
7817
  }
7818
- function FromIntersect15(schema, references, path13, value) {
7818
+ function FromIntersect15(schema, references, path15, value) {
7819
7819
  if (!IsObject2(value) || IsValueType(value))
7820
- return Default3(schema, path13, value);
7820
+ return Default3(schema, path15, value);
7821
7821
  const knownEntries = KeyOfPropertyEntries(schema);
7822
7822
  const knownKeys = knownEntries.map((entry) => entry[0]);
7823
7823
  const knownProperties = { ...value };
7824
7824
  for (const [knownKey, knownSchema] of knownEntries)
7825
7825
  if (knownKey in knownProperties) {
7826
- knownProperties[knownKey] = Visit11(knownSchema, references, `${path13}/${knownKey}`, knownProperties[knownKey]);
7826
+ knownProperties[knownKey] = Visit11(knownSchema, references, `${path15}/${knownKey}`, knownProperties[knownKey]);
7827
7827
  }
7828
7828
  if (!IsTransform(schema.unevaluatedProperties)) {
7829
- return Default3(schema, path13, knownProperties);
7829
+ return Default3(schema, path15, knownProperties);
7830
7830
  }
7831
7831
  const unknownKeys = Object.getOwnPropertyNames(knownProperties);
7832
7832
  const unevaluatedProperties = schema.unevaluatedProperties;
7833
7833
  const unknownProperties = { ...knownProperties };
7834
7834
  for (const key of unknownKeys)
7835
7835
  if (!knownKeys.includes(key)) {
7836
- unknownProperties[key] = Default3(unevaluatedProperties, `${path13}/${key}`, unknownProperties[key]);
7836
+ unknownProperties[key] = Default3(unevaluatedProperties, `${path15}/${key}`, unknownProperties[key]);
7837
7837
  }
7838
- return Default3(schema, path13, unknownProperties);
7838
+ return Default3(schema, path15, unknownProperties);
7839
7839
  }
7840
- function FromImport7(schema, references, path13, value) {
7840
+ function FromImport7(schema, references, path15, value) {
7841
7841
  const additional = globalThis.Object.values(schema.$defs);
7842
7842
  const target = schema.$defs[schema.$ref];
7843
- const result = Visit11(target, [...references, ...additional], path13, value);
7844
- return Default3(schema, path13, result);
7843
+ const result = Visit11(target, [...references, ...additional], path15, value);
7844
+ return Default3(schema, path15, result);
7845
7845
  }
7846
- function FromNot5(schema, references, path13, value) {
7847
- return Default3(schema, path13, Visit11(schema.not, references, path13, value));
7846
+ function FromNot5(schema, references, path15, value) {
7847
+ return Default3(schema, path15, Visit11(schema.not, references, path15, value));
7848
7848
  }
7849
- function FromObject15(schema, references, path13, value) {
7849
+ function FromObject15(schema, references, path15, value) {
7850
7850
  if (!IsObject2(value))
7851
- return Default3(schema, path13, value);
7851
+ return Default3(schema, path15, value);
7852
7852
  const knownKeys = KeyOfPropertyKeys(schema);
7853
7853
  const knownProperties = { ...value };
7854
7854
  for (const key of knownKeys) {
@@ -7856,90 +7856,90 @@ function FromObject15(schema, references, path13, value) {
7856
7856
  continue;
7857
7857
  if (IsUndefined2(knownProperties[key]) && (!IsUndefined3(schema.properties[key]) || TypeSystemPolicy.IsExactOptionalProperty(knownProperties, key)))
7858
7858
  continue;
7859
- knownProperties[key] = Visit11(schema.properties[key], references, `${path13}/${key}`, knownProperties[key]);
7859
+ knownProperties[key] = Visit11(schema.properties[key], references, `${path15}/${key}`, knownProperties[key]);
7860
7860
  }
7861
7861
  if (!IsSchema(schema.additionalProperties)) {
7862
- return Default3(schema, path13, knownProperties);
7862
+ return Default3(schema, path15, knownProperties);
7863
7863
  }
7864
7864
  const unknownKeys = Object.getOwnPropertyNames(knownProperties);
7865
7865
  const additionalProperties = schema.additionalProperties;
7866
7866
  const unknownProperties = { ...knownProperties };
7867
7867
  for (const key of unknownKeys)
7868
7868
  if (!knownKeys.includes(key)) {
7869
- unknownProperties[key] = Default3(additionalProperties, `${path13}/${key}`, unknownProperties[key]);
7869
+ unknownProperties[key] = Default3(additionalProperties, `${path15}/${key}`, unknownProperties[key]);
7870
7870
  }
7871
- return Default3(schema, path13, unknownProperties);
7871
+ return Default3(schema, path15, unknownProperties);
7872
7872
  }
7873
- function FromRecord10(schema, references, path13, value) {
7873
+ function FromRecord10(schema, references, path15, value) {
7874
7874
  if (!IsObject2(value))
7875
- return Default3(schema, path13, value);
7875
+ return Default3(schema, path15, value);
7876
7876
  const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
7877
7877
  const knownKeys = new RegExp(pattern);
7878
7878
  const knownProperties = { ...value };
7879
7879
  for (const key of Object.getOwnPropertyNames(value))
7880
7880
  if (knownKeys.test(key)) {
7881
- knownProperties[key] = Visit11(schema.patternProperties[pattern], references, `${path13}/${key}`, knownProperties[key]);
7881
+ knownProperties[key] = Visit11(schema.patternProperties[pattern], references, `${path15}/${key}`, knownProperties[key]);
7882
7882
  }
7883
7883
  if (!IsSchema(schema.additionalProperties)) {
7884
- return Default3(schema, path13, knownProperties);
7884
+ return Default3(schema, path15, knownProperties);
7885
7885
  }
7886
7886
  const unknownKeys = Object.getOwnPropertyNames(knownProperties);
7887
7887
  const additionalProperties = schema.additionalProperties;
7888
7888
  const unknownProperties = { ...knownProperties };
7889
7889
  for (const key of unknownKeys)
7890
7890
  if (!knownKeys.test(key)) {
7891
- unknownProperties[key] = Default3(additionalProperties, `${path13}/${key}`, unknownProperties[key]);
7891
+ unknownProperties[key] = Default3(additionalProperties, `${path15}/${key}`, unknownProperties[key]);
7892
7892
  }
7893
- return Default3(schema, path13, unknownProperties);
7893
+ return Default3(schema, path15, unknownProperties);
7894
7894
  }
7895
- function FromRef11(schema, references, path13, value) {
7895
+ function FromRef11(schema, references, path15, value) {
7896
7896
  const target = Deref(schema, references);
7897
- return Default3(schema, path13, Visit11(target, references, path13, value));
7897
+ return Default3(schema, path15, Visit11(target, references, path15, value));
7898
7898
  }
7899
- function FromThis7(schema, references, path13, value) {
7899
+ function FromThis7(schema, references, path15, value) {
7900
7900
  const target = Deref(schema, references);
7901
- return Default3(schema, path13, Visit11(target, references, path13, value));
7901
+ return Default3(schema, path15, Visit11(target, references, path15, value));
7902
7902
  }
7903
- function FromTuple12(schema, references, path13, value) {
7904
- return IsArray2(value) && IsArray2(schema.items) ? Default3(schema, path13, schema.items.map((schema2, index) => Visit11(schema2, references, `${path13}/${index}`, value[index]))) : Default3(schema, path13, value);
7903
+ function FromTuple12(schema, references, path15, value) {
7904
+ return IsArray2(value) && IsArray2(schema.items) ? Default3(schema, path15, schema.items.map((schema2, index) => Visit11(schema2, references, `${path15}/${index}`, value[index]))) : Default3(schema, path15, value);
7905
7905
  }
7906
- function FromUnion17(schema, references, path13, value) {
7906
+ function FromUnion17(schema, references, path15, value) {
7907
7907
  for (const subschema of schema.anyOf) {
7908
7908
  if (!Check(subschema, references, value))
7909
7909
  continue;
7910
- const decoded = Visit11(subschema, references, path13, value);
7911
- return Default3(schema, path13, decoded);
7910
+ const decoded = Visit11(subschema, references, path15, value);
7911
+ return Default3(schema, path15, decoded);
7912
7912
  }
7913
- return Default3(schema, path13, value);
7913
+ return Default3(schema, path15, value);
7914
7914
  }
7915
- function Visit11(schema, references, path13, value) {
7915
+ function Visit11(schema, references, path15, value) {
7916
7916
  const references_ = Pushref(schema, references);
7917
7917
  const schema_ = schema;
7918
7918
  switch (schema[Kind]) {
7919
7919
  case "Array":
7920
- return FromArray14(schema_, references_, path13, value);
7920
+ return FromArray14(schema_, references_, path15, value);
7921
7921
  case "Import":
7922
- return FromImport7(schema_, references_, path13, value);
7922
+ return FromImport7(schema_, references_, path15, value);
7923
7923
  case "Intersect":
7924
- return FromIntersect15(schema_, references_, path13, value);
7924
+ return FromIntersect15(schema_, references_, path15, value);
7925
7925
  case "Not":
7926
- return FromNot5(schema_, references_, path13, value);
7926
+ return FromNot5(schema_, references_, path15, value);
7927
7927
  case "Object":
7928
- return FromObject15(schema_, references_, path13, value);
7928
+ return FromObject15(schema_, references_, path15, value);
7929
7929
  case "Record":
7930
- return FromRecord10(schema_, references_, path13, value);
7930
+ return FromRecord10(schema_, references_, path15, value);
7931
7931
  case "Ref":
7932
- return FromRef11(schema_, references_, path13, value);
7932
+ return FromRef11(schema_, references_, path15, value);
7933
7933
  case "Symbol":
7934
- return Default3(schema_, path13, value);
7934
+ return Default3(schema_, path15, value);
7935
7935
  case "This":
7936
- return FromThis7(schema_, references_, path13, value);
7936
+ return FromThis7(schema_, references_, path15, value);
7937
7937
  case "Tuple":
7938
- return FromTuple12(schema_, references_, path13, value);
7938
+ return FromTuple12(schema_, references_, path15, value);
7939
7939
  case "Union":
7940
- return FromUnion17(schema_, references_, path13, value);
7940
+ return FromUnion17(schema_, references_, path15, value);
7941
7941
  default:
7942
- return Default3(schema_, path13, value);
7942
+ return Default3(schema_, path15, value);
7943
7943
  }
7944
7944
  }
7945
7945
  function TransformDecode(schema, references, value) {
@@ -7956,33 +7956,33 @@ var TransformEncodeCheckError = class extends TypeBoxError {
7956
7956
  }
7957
7957
  };
7958
7958
  var TransformEncodeError = class extends TypeBoxError {
7959
- constructor(schema, path13, value, error) {
7959
+ constructor(schema, path15, value, error) {
7960
7960
  super(`${error instanceof Error ? error.message : "Unknown error"}`);
7961
7961
  this.schema = schema;
7962
- this.path = path13;
7962
+ this.path = path15;
7963
7963
  this.value = value;
7964
7964
  this.error = error;
7965
7965
  }
7966
7966
  };
7967
- function Default4(schema, path13, value) {
7967
+ function Default4(schema, path15, value) {
7968
7968
  try {
7969
7969
  return IsTransform(schema) ? schema[TransformKind].Encode(value) : value;
7970
7970
  } catch (error) {
7971
- throw new TransformEncodeError(schema, path13, value, error);
7971
+ throw new TransformEncodeError(schema, path15, value, error);
7972
7972
  }
7973
7973
  }
7974
- function FromArray15(schema, references, path13, value) {
7975
- const defaulted = Default4(schema, path13, value);
7976
- return IsArray2(defaulted) ? defaulted.map((value2, index) => Visit12(schema.items, references, `${path13}/${index}`, value2)) : defaulted;
7974
+ function FromArray15(schema, references, path15, value) {
7975
+ const defaulted = Default4(schema, path15, value);
7976
+ return IsArray2(defaulted) ? defaulted.map((value2, index) => Visit12(schema.items, references, `${path15}/${index}`, value2)) : defaulted;
7977
7977
  }
7978
- function FromImport8(schema, references, path13, value) {
7978
+ function FromImport8(schema, references, path15, value) {
7979
7979
  const additional = globalThis.Object.values(schema.$defs);
7980
7980
  const target = schema.$defs[schema.$ref];
7981
- const result = Default4(schema, path13, value);
7982
- return Visit12(target, [...references, ...additional], path13, result);
7981
+ const result = Default4(schema, path15, value);
7982
+ return Visit12(target, [...references, ...additional], path15, result);
7983
7983
  }
7984
- function FromIntersect16(schema, references, path13, value) {
7985
- const defaulted = Default4(schema, path13, value);
7984
+ function FromIntersect16(schema, references, path15, value) {
7985
+ const defaulted = Default4(schema, path15, value);
7986
7986
  if (!IsObject2(value) || IsValueType(value))
7987
7987
  return defaulted;
7988
7988
  const knownEntries = KeyOfPropertyEntries(schema);
@@ -7990,7 +7990,7 @@ function FromIntersect16(schema, references, path13, value) {
7990
7990
  const knownProperties = { ...defaulted };
7991
7991
  for (const [knownKey, knownSchema] of knownEntries)
7992
7992
  if (knownKey in knownProperties) {
7993
- knownProperties[knownKey] = Visit12(knownSchema, references, `${path13}/${knownKey}`, knownProperties[knownKey]);
7993
+ knownProperties[knownKey] = Visit12(knownSchema, references, `${path15}/${knownKey}`, knownProperties[knownKey]);
7994
7994
  }
7995
7995
  if (!IsTransform(schema.unevaluatedProperties)) {
7996
7996
  return knownProperties;
@@ -8000,15 +8000,15 @@ function FromIntersect16(schema, references, path13, value) {
8000
8000
  const properties = { ...knownProperties };
8001
8001
  for (const key of unknownKeys)
8002
8002
  if (!knownKeys.includes(key)) {
8003
- properties[key] = Default4(unevaluatedProperties, `${path13}/${key}`, properties[key]);
8003
+ properties[key] = Default4(unevaluatedProperties, `${path15}/${key}`, properties[key]);
8004
8004
  }
8005
8005
  return properties;
8006
8006
  }
8007
- function FromNot6(schema, references, path13, value) {
8008
- return Default4(schema.not, path13, Default4(schema, path13, value));
8007
+ function FromNot6(schema, references, path15, value) {
8008
+ return Default4(schema.not, path15, Default4(schema, path15, value));
8009
8009
  }
8010
- function FromObject16(schema, references, path13, value) {
8011
- const defaulted = Default4(schema, path13, value);
8010
+ function FromObject16(schema, references, path15, value) {
8011
+ const defaulted = Default4(schema, path15, value);
8012
8012
  if (!IsObject2(defaulted))
8013
8013
  return defaulted;
8014
8014
  const knownKeys = KeyOfPropertyKeys(schema);
@@ -8018,7 +8018,7 @@ function FromObject16(schema, references, path13, value) {
8018
8018
  continue;
8019
8019
  if (IsUndefined2(knownProperties[key]) && (!IsUndefined3(schema.properties[key]) || TypeSystemPolicy.IsExactOptionalProperty(knownProperties, key)))
8020
8020
  continue;
8021
- knownProperties[key] = Visit12(schema.properties[key], references, `${path13}/${key}`, knownProperties[key]);
8021
+ knownProperties[key] = Visit12(schema.properties[key], references, `${path15}/${key}`, knownProperties[key]);
8022
8022
  }
8023
8023
  if (!IsSchema(schema.additionalProperties)) {
8024
8024
  return knownProperties;
@@ -8028,12 +8028,12 @@ function FromObject16(schema, references, path13, value) {
8028
8028
  const properties = { ...knownProperties };
8029
8029
  for (const key of unknownKeys)
8030
8030
  if (!knownKeys.includes(key)) {
8031
- properties[key] = Default4(additionalProperties, `${path13}/${key}`, properties[key]);
8031
+ properties[key] = Default4(additionalProperties, `${path15}/${key}`, properties[key]);
8032
8032
  }
8033
8033
  return properties;
8034
8034
  }
8035
- function FromRecord11(schema, references, path13, value) {
8036
- const defaulted = Default4(schema, path13, value);
8035
+ function FromRecord11(schema, references, path15, value) {
8036
+ const defaulted = Default4(schema, path15, value);
8037
8037
  if (!IsObject2(value))
8038
8038
  return defaulted;
8039
8039
  const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
@@ -8041,7 +8041,7 @@ function FromRecord11(schema, references, path13, value) {
8041
8041
  const knownProperties = { ...defaulted };
8042
8042
  for (const key of Object.getOwnPropertyNames(value))
8043
8043
  if (knownKeys.test(key)) {
8044
- knownProperties[key] = Visit12(schema.patternProperties[pattern], references, `${path13}/${key}`, knownProperties[key]);
8044
+ knownProperties[key] = Visit12(schema.patternProperties[pattern], references, `${path15}/${key}`, knownProperties[key]);
8045
8045
  }
8046
8046
  if (!IsSchema(schema.additionalProperties)) {
8047
8047
  return knownProperties;
@@ -8051,65 +8051,65 @@ function FromRecord11(schema, references, path13, value) {
8051
8051
  const properties = { ...knownProperties };
8052
8052
  for (const key of unknownKeys)
8053
8053
  if (!knownKeys.test(key)) {
8054
- properties[key] = Default4(additionalProperties, `${path13}/${key}`, properties[key]);
8054
+ properties[key] = Default4(additionalProperties, `${path15}/${key}`, properties[key]);
8055
8055
  }
8056
8056
  return properties;
8057
8057
  }
8058
- function FromRef12(schema, references, path13, value) {
8058
+ function FromRef12(schema, references, path15, value) {
8059
8059
  const target = Deref(schema, references);
8060
- const resolved = Visit12(target, references, path13, value);
8061
- return Default4(schema, path13, resolved);
8060
+ const resolved = Visit12(target, references, path15, value);
8061
+ return Default4(schema, path15, resolved);
8062
8062
  }
8063
- function FromThis8(schema, references, path13, value) {
8063
+ function FromThis8(schema, references, path15, value) {
8064
8064
  const target = Deref(schema, references);
8065
- const resolved = Visit12(target, references, path13, value);
8066
- return Default4(schema, path13, resolved);
8065
+ const resolved = Visit12(target, references, path15, value);
8066
+ return Default4(schema, path15, resolved);
8067
8067
  }
8068
- function FromTuple13(schema, references, path13, value) {
8069
- const value1 = Default4(schema, path13, value);
8070
- return IsArray2(schema.items) ? schema.items.map((schema2, index) => Visit12(schema2, references, `${path13}/${index}`, value1[index])) : [];
8068
+ function FromTuple13(schema, references, path15, value) {
8069
+ const value1 = Default4(schema, path15, value);
8070
+ return IsArray2(schema.items) ? schema.items.map((schema2, index) => Visit12(schema2, references, `${path15}/${index}`, value1[index])) : [];
8071
8071
  }
8072
- function FromUnion18(schema, references, path13, value) {
8072
+ function FromUnion18(schema, references, path15, value) {
8073
8073
  for (const subschema of schema.anyOf) {
8074
8074
  if (!Check(subschema, references, value))
8075
8075
  continue;
8076
- const value1 = Visit12(subschema, references, path13, value);
8077
- return Default4(schema, path13, value1);
8076
+ const value1 = Visit12(subschema, references, path15, value);
8077
+ return Default4(schema, path15, value1);
8078
8078
  }
8079
8079
  for (const subschema of schema.anyOf) {
8080
- const value1 = Visit12(subschema, references, path13, value);
8080
+ const value1 = Visit12(subschema, references, path15, value);
8081
8081
  if (!Check(schema, references, value1))
8082
8082
  continue;
8083
- return Default4(schema, path13, value1);
8083
+ return Default4(schema, path15, value1);
8084
8084
  }
8085
- return Default4(schema, path13, value);
8085
+ return Default4(schema, path15, value);
8086
8086
  }
8087
- function Visit12(schema, references, path13, value) {
8087
+ function Visit12(schema, references, path15, value) {
8088
8088
  const references_ = Pushref(schema, references);
8089
8089
  const schema_ = schema;
8090
8090
  switch (schema[Kind]) {
8091
8091
  case "Array":
8092
- return FromArray15(schema_, references_, path13, value);
8092
+ return FromArray15(schema_, references_, path15, value);
8093
8093
  case "Import":
8094
- return FromImport8(schema_, references_, path13, value);
8094
+ return FromImport8(schema_, references_, path15, value);
8095
8095
  case "Intersect":
8096
- return FromIntersect16(schema_, references_, path13, value);
8096
+ return FromIntersect16(schema_, references_, path15, value);
8097
8097
  case "Not":
8098
- return FromNot6(schema_, references_, path13, value);
8098
+ return FromNot6(schema_, references_, path15, value);
8099
8099
  case "Object":
8100
- return FromObject16(schema_, references_, path13, value);
8100
+ return FromObject16(schema_, references_, path15, value);
8101
8101
  case "Record":
8102
- return FromRecord11(schema_, references_, path13, value);
8102
+ return FromRecord11(schema_, references_, path15, value);
8103
8103
  case "Ref":
8104
- return FromRef12(schema_, references_, path13, value);
8104
+ return FromRef12(schema_, references_, path15, value);
8105
8105
  case "This":
8106
- return FromThis8(schema_, references_, path13, value);
8106
+ return FromThis8(schema_, references_, path15, value);
8107
8107
  case "Tuple":
8108
- return FromTuple13(schema_, references_, path13, value);
8108
+ return FromTuple13(schema_, references_, path15, value);
8109
8109
  case "Union":
8110
- return FromUnion18(schema_, references_, path13, value);
8110
+ return FromUnion18(schema_, references_, path15, value);
8111
8111
  default:
8112
- return Default4(schema_, path13, value);
8112
+ return Default4(schema_, path15, value);
8113
8113
  }
8114
8114
  }
8115
8115
  function TransformEncode(schema, references, value) {
@@ -8377,18 +8377,18 @@ __export(pointer_exports, {
8377
8377
  ValuePointerRootSetError: () => ValuePointerRootSetError
8378
8378
  });
8379
8379
  var ValuePointerRootSetError = class extends TypeBoxError {
8380
- constructor(value, path13, update) {
8380
+ constructor(value, path15, update) {
8381
8381
  super("Cannot set root value");
8382
8382
  this.value = value;
8383
- this.path = path13;
8383
+ this.path = path15;
8384
8384
  this.update = update;
8385
8385
  }
8386
8386
  };
8387
8387
  var ValuePointerRootDeleteError = class extends TypeBoxError {
8388
- constructor(value, path13) {
8388
+ constructor(value, path15) {
8389
8389
  super("Cannot delete root value");
8390
8390
  this.value = value;
8391
- this.path = path13;
8391
+ this.path = path15;
8392
8392
  }
8393
8393
  };
8394
8394
  function Escape2(component) {
@@ -8532,82 +8532,82 @@ var ValueDiffError = class extends TypeBoxError {
8532
8532
  this.value = value;
8533
8533
  }
8534
8534
  };
8535
- function CreateUpdate(path13, value) {
8536
- return { type: "update", path: path13, value };
8535
+ function CreateUpdate(path15, value) {
8536
+ return { type: "update", path: path15, value };
8537
8537
  }
8538
- function CreateInsert(path13, value) {
8539
- return { type: "insert", path: path13, value };
8538
+ function CreateInsert(path15, value) {
8539
+ return { type: "insert", path: path15, value };
8540
8540
  }
8541
- function CreateDelete(path13) {
8542
- return { type: "delete", path: path13 };
8541
+ function CreateDelete(path15) {
8542
+ return { type: "delete", path: path15 };
8543
8543
  }
8544
8544
  function AssertDiffable(value) {
8545
8545
  if (globalThis.Object.getOwnPropertySymbols(value).length > 0)
8546
8546
  throw new ValueDiffError(value, "Cannot diff objects with symbols");
8547
8547
  }
8548
- function* ObjectType4(path13, current, next) {
8548
+ function* ObjectType4(path15, current, next) {
8549
8549
  AssertDiffable(current);
8550
8550
  AssertDiffable(next);
8551
8551
  if (!IsStandardObject(next))
8552
- return yield CreateUpdate(path13, next);
8552
+ return yield CreateUpdate(path15, next);
8553
8553
  const currentKeys = globalThis.Object.getOwnPropertyNames(current);
8554
8554
  const nextKeys = globalThis.Object.getOwnPropertyNames(next);
8555
8555
  for (const key of nextKeys) {
8556
8556
  if (HasPropertyKey2(current, key))
8557
8557
  continue;
8558
- yield CreateInsert(`${path13}/${key}`, next[key]);
8558
+ yield CreateInsert(`${path15}/${key}`, next[key]);
8559
8559
  }
8560
8560
  for (const key of currentKeys) {
8561
8561
  if (!HasPropertyKey2(next, key))
8562
8562
  continue;
8563
8563
  if (Equal(current, next))
8564
8564
  continue;
8565
- yield* Visit15(`${path13}/${key}`, current[key], next[key]);
8565
+ yield* Visit15(`${path15}/${key}`, current[key], next[key]);
8566
8566
  }
8567
8567
  for (const key of currentKeys) {
8568
8568
  if (HasPropertyKey2(next, key))
8569
8569
  continue;
8570
- yield CreateDelete(`${path13}/${key}`);
8570
+ yield CreateDelete(`${path15}/${key}`);
8571
8571
  }
8572
8572
  }
8573
- function* ArrayType4(path13, current, next) {
8573
+ function* ArrayType4(path15, current, next) {
8574
8574
  if (!IsArray2(next))
8575
- return yield CreateUpdate(path13, next);
8575
+ return yield CreateUpdate(path15, next);
8576
8576
  for (let i = 0; i < Math.min(current.length, next.length); i++) {
8577
- yield* Visit15(`${path13}/${i}`, current[i], next[i]);
8577
+ yield* Visit15(`${path15}/${i}`, current[i], next[i]);
8578
8578
  }
8579
8579
  for (let i = 0; i < next.length; i++) {
8580
8580
  if (i < current.length)
8581
8581
  continue;
8582
- yield CreateInsert(`${path13}/${i}`, next[i]);
8582
+ yield CreateInsert(`${path15}/${i}`, next[i]);
8583
8583
  }
8584
8584
  for (let i = current.length - 1; i >= 0; i--) {
8585
8585
  if (i < next.length)
8586
8586
  continue;
8587
- yield CreateDelete(`${path13}/${i}`);
8587
+ yield CreateDelete(`${path15}/${i}`);
8588
8588
  }
8589
8589
  }
8590
- function* TypedArrayType2(path13, current, next) {
8590
+ function* TypedArrayType2(path15, current, next) {
8591
8591
  if (!IsTypedArray(next) || current.length !== next.length || globalThis.Object.getPrototypeOf(current).constructor.name !== globalThis.Object.getPrototypeOf(next).constructor.name)
8592
- return yield CreateUpdate(path13, next);
8592
+ return yield CreateUpdate(path15, next);
8593
8593
  for (let i = 0; i < Math.min(current.length, next.length); i++) {
8594
- yield* Visit15(`${path13}/${i}`, current[i], next[i]);
8594
+ yield* Visit15(`${path15}/${i}`, current[i], next[i]);
8595
8595
  }
8596
8596
  }
8597
- function* ValueType2(path13, current, next) {
8597
+ function* ValueType2(path15, current, next) {
8598
8598
  if (current === next)
8599
8599
  return;
8600
- yield CreateUpdate(path13, next);
8600
+ yield CreateUpdate(path15, next);
8601
8601
  }
8602
- function* Visit15(path13, current, next) {
8602
+ function* Visit15(path15, current, next) {
8603
8603
  if (IsStandardObject(current))
8604
- return yield* ObjectType4(path13, current, next);
8604
+ return yield* ObjectType4(path15, current, next);
8605
8605
  if (IsArray2(current))
8606
- return yield* ArrayType4(path13, current, next);
8606
+ return yield* ArrayType4(path15, current, next);
8607
8607
  if (IsTypedArray(current))
8608
- return yield* TypedArrayType2(path13, current, next);
8608
+ return yield* TypedArrayType2(path15, current, next);
8609
8609
  if (IsValueType(current))
8610
- return yield* ValueType2(path13, current, next);
8610
+ return yield* ValueType2(path15, current, next);
8611
8611
  throw new ValueDiffError(current, "Unable to diff value");
8612
8612
  }
8613
8613
  function Diff(current, next) {
@@ -8664,9 +8664,9 @@ var ValueMutateError = class extends TypeBoxError {
8664
8664
  super(message);
8665
8665
  }
8666
8666
  };
8667
- function ObjectType5(root, path13, current, next) {
8667
+ function ObjectType5(root, path15, current, next) {
8668
8668
  if (!IsStandardObject2(current)) {
8669
- pointer_exports.Set(root, path13, Clone2(next));
8669
+ pointer_exports.Set(root, path15, Clone2(next));
8670
8670
  } else {
8671
8671
  const currentKeys = Object.getOwnPropertyNames(current);
8672
8672
  const nextKeys = Object.getOwnPropertyNames(next);
@@ -8681,43 +8681,43 @@ function ObjectType5(root, path13, current, next) {
8681
8681
  }
8682
8682
  }
8683
8683
  for (const nextKey of nextKeys) {
8684
- Visit16(root, `${path13}/${nextKey}`, current[nextKey], next[nextKey]);
8684
+ Visit16(root, `${path15}/${nextKey}`, current[nextKey], next[nextKey]);
8685
8685
  }
8686
8686
  }
8687
8687
  }
8688
- function ArrayType5(root, path13, current, next) {
8688
+ function ArrayType5(root, path15, current, next) {
8689
8689
  if (!IsArray2(current)) {
8690
- pointer_exports.Set(root, path13, Clone2(next));
8690
+ pointer_exports.Set(root, path15, Clone2(next));
8691
8691
  } else {
8692
8692
  for (let index = 0; index < next.length; index++) {
8693
- Visit16(root, `${path13}/${index}`, current[index], next[index]);
8693
+ Visit16(root, `${path15}/${index}`, current[index], next[index]);
8694
8694
  }
8695
8695
  current.splice(next.length);
8696
8696
  }
8697
8697
  }
8698
- function TypedArrayType3(root, path13, current, next) {
8698
+ function TypedArrayType3(root, path15, current, next) {
8699
8699
  if (IsTypedArray(current) && current.length === next.length) {
8700
8700
  for (let i = 0; i < current.length; i++) {
8701
8701
  current[i] = next[i];
8702
8702
  }
8703
8703
  } else {
8704
- pointer_exports.Set(root, path13, Clone2(next));
8704
+ pointer_exports.Set(root, path15, Clone2(next));
8705
8705
  }
8706
8706
  }
8707
- function ValueType3(root, path13, current, next) {
8707
+ function ValueType3(root, path15, current, next) {
8708
8708
  if (current === next)
8709
8709
  return;
8710
- pointer_exports.Set(root, path13, next);
8710
+ pointer_exports.Set(root, path15, next);
8711
8711
  }
8712
- function Visit16(root, path13, current, next) {
8712
+ function Visit16(root, path15, current, next) {
8713
8713
  if (IsArray2(next))
8714
- return ArrayType5(root, path13, current, next);
8714
+ return ArrayType5(root, path15, current, next);
8715
8715
  if (IsTypedArray(next))
8716
- return TypedArrayType3(root, path13, current, next);
8716
+ return TypedArrayType3(root, path15, current, next);
8717
8717
  if (IsStandardObject2(next))
8718
- return ObjectType5(root, path13, current, next);
8718
+ return ObjectType5(root, path15, current, next);
8719
8719
  if (IsValueType(next))
8720
- return ValueType3(root, path13, current, next);
8720
+ return ValueType3(root, path15, current, next);
8721
8721
  }
8722
8722
  function IsNonMutableValue(value) {
8723
8723
  return IsTypedArray(value) || IsValueType(value);
@@ -8815,8 +8815,8 @@ __export(value_exports2, {
8815
8815
  });
8816
8816
 
8817
8817
  // src/lib/types.ts
8818
- var CURRENT_REGISTRY_VERSION = 2;
8819
- var CAPSULE_VERSION = 1;
8818
+ var CURRENT_REGISTRY_VERSION = 4;
8819
+ var CAPSULE_VERSION = 3;
8820
8820
  var MAX_POST_ERROR_LENGTH = 500;
8821
8821
  var MAX_NAME_LENGTH = 100;
8822
8822
  var DOCTOR_ALL_COOLDOWN_MS = 60 * 60 * 1e3;
@@ -8850,6 +8850,7 @@ var TopicEntrySchema = Type.Object({
8850
8850
  lastMessageAt: Type.Union([Type.String(), Type.Null()]),
8851
8851
  lastDoctorReportAt: Type.Union([Type.String(), Type.Null()]),
8852
8852
  lastDoctorRunAt: Type.Union([Type.String(), Type.Null()]),
8853
+ lastCapsuleWriteAt: Type.Union([Type.String(), Type.Null()]),
8853
8854
  snoozeUntil: Type.Union([Type.String(), Type.Null()]),
8854
8855
  ignoreChecks: Type.Array(Type.String()),
8855
8856
  consecutiveSilentDoctors: Type.Integer({ minimum: 0 }),
@@ -8861,6 +8862,7 @@ var RegistrySchema = Type.Object({
8861
8862
  topicManagerAdmins: Type.Array(Type.String()),
8862
8863
  callbackSecret: Type.String(),
8863
8864
  lastDoctorAllRunAt: Type.Union([Type.String(), Type.Null()]),
8865
+ autopilotEnabled: Type.Boolean(),
8864
8866
  maxTopics: Type.Integer({ minimum: 1 }),
8865
8867
  topics: Type.Record(Type.String(), TopicEntrySchema)
8866
8868
  });
@@ -8877,7 +8879,8 @@ var BASE_FILES = [
8877
8879
  "COMMANDS.md",
8878
8880
  "LINKS.md",
8879
8881
  "CRON.md",
8880
- "NOTES.md"
8882
+ "NOTES.md",
8883
+ "LEARNINGS.md"
8881
8884
  ];
8882
8885
  function topicKey(groupId, threadId) {
8883
8886
  return `${groupId}:${threadId}`;
@@ -8908,6 +8911,23 @@ var migrations = {
8908
8911
  }
8909
8912
  }
8910
8913
  return data;
8914
+ },
8915
+ "2_to_3": (data) => {
8916
+ if (data["autopilotEnabled"] === void 0) {
8917
+ data["autopilotEnabled"] = false;
8918
+ }
8919
+ return data;
8920
+ },
8921
+ "3_to_4": (data) => {
8922
+ const topics = data["topics"];
8923
+ if (topics && typeof topics === "object" && !Array.isArray(topics)) {
8924
+ for (const entry of Object.values(topics)) {
8925
+ if (entry["lastCapsuleWriteAt"] === void 0) {
8926
+ entry["lastCapsuleWriteAt"] = null;
8927
+ }
8928
+ }
8929
+ }
8930
+ return data;
8911
8931
  }
8912
8932
  };
8913
8933
  function migrateRegistry(data) {
@@ -9098,62 +9118,6 @@ function buildAuditEntry(userId, cmd, slug, detail) {
9098
9118
  };
9099
9119
  }
9100
9120
 
9101
- // src/commands/init.ts
9102
- import * as fs6 from "node:fs";
9103
- import * as path6 from "node:path";
9104
-
9105
- // src/lib/auth.ts
9106
- var AuthTier = {
9107
- User: "User",
9108
- Admin: "Admin"
9109
- };
9110
- var ADMIN_COMMANDS = /* @__PURE__ */ new Set([
9111
- "doctor --all",
9112
- "doctor-all",
9113
- "list",
9114
- "sync",
9115
- "rename",
9116
- "archive",
9117
- "unarchive"
9118
- ]);
9119
- var USER_COMMANDS = /* @__PURE__ */ new Set([
9120
- "init",
9121
- "doctor",
9122
- "status",
9123
- "help",
9124
- "upgrade",
9125
- "snooze"
9126
- ]);
9127
- function getCommandTier(command) {
9128
- const normalized = command.toLowerCase().trim();
9129
- if (USER_COMMANDS.has(normalized)) return AuthTier.User;
9130
- if (ADMIN_COMMANDS.has(normalized)) return AuthTier.Admin;
9131
- return AuthTier.Admin;
9132
- }
9133
- function checkAuthorization(userId, command, registry, topicAllowFrom) {
9134
- const tier = getCommandTier(command);
9135
- const admins = registry.topicManagerAdmins;
9136
- if (admins.length === 0 && tier === AuthTier.User) {
9137
- return { authorized: true };
9138
- }
9139
- const isAdmin = admins.includes(userId);
9140
- if (tier === AuthTier.Admin) {
9141
- if (isAdmin) return { authorized: true };
9142
- return {
9143
- authorized: false,
9144
- message: "Not authorized. Ask a telegram-manager admin to run this command."
9145
- };
9146
- }
9147
- if (isAdmin) return { authorized: true };
9148
- if (topicAllowFrom && topicAllowFrom.includes(userId)) {
9149
- return { authorized: true };
9150
- }
9151
- return {
9152
- authorized: false,
9153
- message: "Not authorized. Ask a telegram-manager admin to run this command."
9154
- };
9155
- }
9156
-
9157
9121
  // src/lib/capsule.ts
9158
9122
  import * as fs4 from "node:fs";
9159
9123
  import * as path4 from "node:path";
@@ -9164,25 +9128,29 @@ _Describe what this topic is about._
9164
9128
  `,
9165
9129
  "STATUS.md": (name) => `# Status: ${name}
9166
9130
 
9131
+ > This file is maintained by the agent \u2014 just send messages in the chat.
9132
+
9167
9133
  ## Last done (UTC)
9168
9134
 
9169
9135
  ${(/* @__PURE__ */ new Date()).toISOString()}
9170
9136
 
9171
- _No work recorded yet._
9137
+ _Waiting for first instructions._
9138
+
9139
+ ## Next actions (now)
9172
9140
 
9173
- ## Next 3 actions
9141
+ 1. _e.g. Set up project scaffolding_
9174
9142
 
9175
- 1. [T-1] _Define first task in TODO.md_
9176
- 2. [T-2] _Define second task in TODO.md_
9177
- 3. [T-3] _Define third task in TODO.md_
9143
+ ## Upcoming actions
9144
+
9145
+ _See TODO.md for full backlog._
9178
9146
  `,
9179
9147
  "TODO.md": (name) => `# TODO: ${name}
9180
9148
 
9181
9149
  ## Backlog
9182
9150
 
9183
- - [T-1] _First task placeholder \u2014 replace with actual task_
9184
- - [T-2] _Second task placeholder \u2014 replace with actual task_
9185
- - [T-3] _Third task placeholder \u2014 replace with actual task_
9151
+ - [T-1] _e.g. Set up project scaffolding_
9152
+ - [T-2] _Waiting for next task_
9153
+ - [T-3] _Waiting for next task_
9186
9154
 
9187
9155
  ## Completed
9188
9156
 
@@ -9203,6 +9171,11 @@ _Cron job IDs and schedules for this topic._
9203
9171
  "NOTES.md": (name) => `# Notes: ${name}
9204
9172
 
9205
9173
  _Anything worth remembering about this topic._
9174
+ `,
9175
+ "LEARNINGS.md": (name) => `# Learnings: ${name}
9176
+
9177
+ _Hard-won insights, mistakes, and workarounds._
9178
+ _Agent prepends here automatically. Most recent entries first._
9206
9179
  `
9207
9180
  };
9208
9181
  var OVERLAY_TEMPLATES = {
@@ -9297,8 +9270,93 @@ function upgradeCapsule(projectsBase, slug, name, type, currentVersion) {
9297
9270
  };
9298
9271
  }
9299
9272
 
9273
+ // src/commands/init.ts
9274
+ import * as fs6 from "node:fs";
9275
+ import * as path6 from "node:path";
9276
+
9277
+ // src/lib/auth.ts
9278
+ var AuthTier = {
9279
+ User: "User",
9280
+ Admin: "Admin"
9281
+ };
9282
+ var ADMIN_COMMANDS = /* @__PURE__ */ new Set([
9283
+ "doctor --all",
9284
+ "doctor-all",
9285
+ "list",
9286
+ "sync",
9287
+ "rename",
9288
+ "archive",
9289
+ "unarchive",
9290
+ "autopilot"
9291
+ ]);
9292
+ var USER_COMMANDS = /* @__PURE__ */ new Set([
9293
+ "init",
9294
+ "doctor",
9295
+ "status",
9296
+ "help",
9297
+ "upgrade",
9298
+ "snooze"
9299
+ ]);
9300
+ function getCommandTier(command) {
9301
+ const normalized = command.toLowerCase().trim();
9302
+ if (USER_COMMANDS.has(normalized)) return AuthTier.User;
9303
+ if (ADMIN_COMMANDS.has(normalized)) return AuthTier.Admin;
9304
+ return AuthTier.Admin;
9305
+ }
9306
+ function checkAuthorization(userId, command, registry, topicAllowFrom) {
9307
+ const tier = getCommandTier(command);
9308
+ const admins = registry.topicManagerAdmins;
9309
+ if (admins.length === 0 && tier === AuthTier.User) {
9310
+ return { authorized: true };
9311
+ }
9312
+ const isAdmin = admins.includes(userId);
9313
+ if (tier === AuthTier.Admin) {
9314
+ if (isAdmin) return { authorized: true };
9315
+ return {
9316
+ authorized: false,
9317
+ message: "Not authorized. Ask a telegram-manager admin to run this command."
9318
+ };
9319
+ }
9320
+ if (isAdmin) return { authorized: true };
9321
+ if (topicAllowFrom && topicAllowFrom.includes(userId)) {
9322
+ return { authorized: true };
9323
+ }
9324
+ return {
9325
+ authorized: false,
9326
+ message: "Not authorized. Ask a telegram-manager admin to run this command."
9327
+ };
9328
+ }
9329
+
9300
9330
  // src/lib/telegram.ts
9301
9331
  var TELEGRAM_MSG_LIMIT = 4096;
9332
+ function buildDailyReport(data) {
9333
+ const n = htmlEscape(data.name);
9334
+ const lines = [
9335
+ `<b>Daily Report: ${n}</b>`,
9336
+ "",
9337
+ `<b>Done today</b>`,
9338
+ htmlEscape(data.doneContent),
9339
+ "",
9340
+ `<b>New learnings</b>`,
9341
+ htmlEscape(data.learningsContent),
9342
+ "",
9343
+ `<b>Blockers/Risks</b>`,
9344
+ htmlEscape(data.blockersContent),
9345
+ "",
9346
+ `<b>Next actions (now)</b>`,
9347
+ htmlEscape(data.nextContent),
9348
+ "",
9349
+ `<b>Upcoming</b>`,
9350
+ htmlEscape(data.upcomingContent),
9351
+ "",
9352
+ `<b>Health:</b> ${data.health}`
9353
+ ];
9354
+ return truncateMessage(lines.join("\n"));
9355
+ }
9356
+ var DEFAULT_RATE_LIMIT = {
9357
+ sameGroupDelayMs: 4e3,
9358
+ crossGroupDelayMs: 1e3
9359
+ };
9302
9360
  function buildInlineKeyboard(rows) {
9303
9361
  return { inline_keyboard: rows };
9304
9362
  }
@@ -9329,37 +9387,58 @@ function buildInitTypeButtons(groupId, threadId, secret, userId) {
9329
9387
  ]
9330
9388
  ]);
9331
9389
  }
9390
+ function buildInitConfirmButton(groupId, threadId, secret, userId, type) {
9391
+ const actionMap = {
9392
+ coding: "yc",
9393
+ research: "yr",
9394
+ marketing: "ym",
9395
+ custom: "yx"
9396
+ };
9397
+ const cb = buildCallbackData(actionMap[type], groupId, threadId, secret, userId);
9398
+ return buildInlineKeyboard([[{ text: "Confirm", callback_data: cb }]]);
9399
+ }
9332
9400
  function buildTopicCard(name, slug, type, capsuleVersion) {
9333
- const n = htmlEscape(name);
9334
- const s = htmlEscape(slug);
9335
- const t = htmlEscape(type);
9336
- const v = htmlEscape(String(capsuleVersion));
9337
9401
  return [
9338
- `<b>Topic: ${n}</b>`,
9339
- `Type: ${t} | Version: ${v}`,
9340
- `Capsule: projects/${s}/`,
9402
+ `**Topic: ${name}**`,
9403
+ `Type: ${type} | Version: ${capsuleVersion}`,
9404
+ `Capsule: projects/${slug}/`,
9341
9405
  "",
9342
- "<b>Commands:</b>",
9343
- "/tm doctor \u2014 health checks",
9344
- "/tm status \u2014 quick view",
9345
- "/tm sync \u2014 re-apply config",
9406
+ "**How it works**",
9407
+ "Just send your instructions in this topic. The agent",
9408
+ "maintains STATUS.md and TODO.md automatically as it",
9409
+ "works \u2014 nothing is lost on reset or context compaction.",
9410
+ "Doctor checks run periodically and alert you if anything",
9411
+ "needs attention.",
9412
+ "",
9413
+ "**Commands:**",
9414
+ "/tm status \u2014 quick STATUS.md view",
9415
+ "/tm doctor \u2014 run health checks",
9416
+ "/tm rename <name> \u2014 rename this topic",
9346
9417
  "/tm list \u2014 all topics",
9347
9418
  "/tm archive \u2014 archive this topic",
9348
- "/tm help \u2014 command reference"
9419
+ "/tm help \u2014 full command reference"
9349
9420
  ].join("\n");
9350
9421
  }
9351
- function buildDoctorReport(name, results) {
9352
- const n = htmlEscape(name);
9353
- const lines = [`<b>Doctor: ${n}</b>`, ""];
9422
+ function buildDoctorReport(name, results, format = "markdown") {
9423
+ const isHtml = format === "html";
9424
+ const n = isHtml ? htmlEscape(name) : name;
9425
+ const bold = (s) => isHtml ? `<b>${s}</b>` : `**${s}**`;
9426
+ const code = (s) => isHtml ? `<code>${s}</code>` : `\`${s}\``;
9427
+ const lines = [bold(`Doctor: ${n}`), ""];
9354
9428
  if (results.length === 0) {
9355
9429
  lines.push("All checks passed.");
9356
9430
  return lines.join("\n");
9357
9431
  }
9358
9432
  for (const r of results) {
9359
9433
  const icon = severityIcon(r.severity);
9360
- const msg = htmlEscape(r.message);
9434
+ const msg = isHtml ? htmlEscape(r.message) : r.message;
9435
+ const checkId = isHtml ? htmlEscape(r.checkId) : r.checkId;
9361
9436
  const fix = r.fixable ? " [fixable]" : "";
9362
- lines.push(`${icon} <code>${htmlEscape(r.checkId)}</code>: ${msg}${fix}`);
9437
+ lines.push(`${icon} ${code(checkId)}: ${msg}${fix}`);
9438
+ if (r.remediation) {
9439
+ const rem = isHtml ? htmlEscape(r.remediation) : r.remediation;
9440
+ lines.push(` \u2192 ${rem}`);
9441
+ }
9363
9442
  }
9364
9443
  lines.push("");
9365
9444
  lines.push("Reply /tm doctor to re-check, or use the buttons below.");
@@ -9382,37 +9461,39 @@ function severityIcon(severity) {
9382
9461
  }
9383
9462
  function buildHelpCard() {
9384
9463
  return [
9385
- "<b>Topic Manager Commands</b>",
9464
+ "**Topic Manager Commands**",
9386
9465
  "",
9387
9466
  "/tm init \u2014 register this topic",
9467
+ "/tm status \u2014 quick STATUS.md view",
9388
9468
  "/tm doctor \u2014 run health checks",
9389
9469
  "/tm doctor --all \u2014 check all topics",
9390
- "/tm status \u2014 quick STATUS.md view",
9391
- "/tm list \u2014 show all topics",
9470
+ "/tm rename <name> \u2014 rename this topic",
9471
+ "/tm list \u2014 all topics",
9392
9472
  "/tm sync \u2014 re-apply config",
9393
- "/tm rename &lt;name&gt; \u2014 rename topic",
9394
9473
  "/tm upgrade \u2014 update capsule template",
9395
- "/tm snooze &lt;Nd&gt; \u2014 snooze doctor (7d, 30d, etc.)",
9474
+ "/tm snooze <Nd> \u2014 snooze doctor (7d, 30d, etc.)",
9396
9475
  "/tm archive \u2014 archive topic",
9397
9476
  "/tm unarchive \u2014 reactivate topic",
9477
+ "/tm autopilot [enable|disable|status] \u2014 daily sweeps",
9478
+ "/tm daily-report \u2014 generate daily status report",
9398
9479
  "/tm help \u2014 this message"
9399
9480
  ].join("\n");
9400
9481
  }
9401
9482
  function buildListMessage(topics) {
9402
9483
  if (topics.length === 0) {
9403
- return "<b>Topic Registry</b> (0 topics)\n\nNo topics registered.";
9484
+ return "**Topic Registry** (0 topics)\n\nNo topics registered.";
9404
9485
  }
9405
9486
  const sorted = [...topics].sort((a, b) => {
9406
9487
  const order = { active: 0, snoozed: 1, archived: 2 };
9407
9488
  return (order[a.status] ?? 3) - (order[b.status] ?? 3);
9408
9489
  });
9409
- const lines = [`<b>Topic Registry</b> (${topics.length} topics)`, ""];
9490
+ const lines = [`**Topic Registry** (${topics.length} topics)`, ""];
9410
9491
  let rendered = 0;
9411
9492
  for (const t of sorted) {
9412
9493
  const entry = [
9413
- `<b>${htmlEscape(t.name)}</b> [${htmlEscape(t.type)}] ${htmlEscape(t.status)}`,
9494
+ `**${t.name}** [${t.type}] ${t.status}`,
9414
9495
  ` Last active: ${t.lastMessageAt ? relativeTime(t.lastMessageAt) : "never"}`,
9415
- ` Thread: #${htmlEscape(t.threadId)}`
9496
+ ` Thread: #${t.threadId}`
9416
9497
  ].join("\n");
9417
9498
  const tentative = [...lines, entry, ""].join("\n");
9418
9499
  if (tentative.length > TELEGRAM_MSG_LIMIT - 40) {
@@ -9436,14 +9517,52 @@ function relativeTime(iso) {
9436
9517
  const days = Math.floor(hours / 24);
9437
9518
  return `${days}d ago`;
9438
9519
  }
9520
+ function createRateLimitedPoster(postFn, config = DEFAULT_RATE_LIMIT) {
9521
+ let lastPostTime = 0;
9522
+ let lastGroupId = "";
9523
+ return async (groupId, threadId, text, keyboard) => {
9524
+ const now = Date.now();
9525
+ const delay = groupId === lastGroupId ? config.sameGroupDelayMs : config.crossGroupDelayMs;
9526
+ const elapsed = now - lastPostTime;
9527
+ if (elapsed < delay) {
9528
+ await sleep(delay - elapsed);
9529
+ }
9530
+ try {
9531
+ await postFn(groupId, threadId, text, keyboard);
9532
+ } catch (err) {
9533
+ if (isTooManyRequestsError(err)) {
9534
+ const retryAfter = getRetryAfter(err);
9535
+ await sleep(retryAfter * 1e3);
9536
+ await postFn(groupId, threadId, text, keyboard);
9537
+ } else {
9538
+ throw err;
9539
+ }
9540
+ }
9541
+ lastPostTime = Date.now();
9542
+ lastGroupId = groupId;
9543
+ };
9544
+ }
9545
+ function sleep(ms) {
9546
+ return new Promise((resolve4) => setTimeout(resolve4, ms));
9547
+ }
9548
+ function isTooManyRequestsError(err) {
9549
+ if (err && typeof err === "object" && "status" in err) {
9550
+ const status = err["status"];
9551
+ return typeof status === "number" && status === 429;
9552
+ }
9553
+ return false;
9554
+ }
9555
+ function getRetryAfter(err) {
9556
+ if (err && typeof err === "object" && "retryAfter" in err) {
9557
+ const val = err.retryAfter;
9558
+ if (typeof val === "number" && val > 0) return val;
9559
+ }
9560
+ return 5;
9561
+ }
9439
9562
  function truncateMessage(msg, limit = TELEGRAM_MSG_LIMIT) {
9440
9563
  if (msg.length <= limit) return msg;
9441
9564
  const suffix = "\n\n... (truncated)";
9442
- let truncated = msg.slice(0, limit - suffix.length);
9443
- const lastOpen = truncated.lastIndexOf("<");
9444
- if (lastOpen !== -1 && lastOpen > truncated.lastIndexOf(">")) {
9445
- truncated = truncated.slice(0, lastOpen);
9446
- }
9565
+ const truncated = msg.slice(0, limit - suffix.length);
9447
9566
  return truncated + suffix;
9448
9567
  }
9449
9568
 
@@ -9460,20 +9579,36 @@ function getSystemPromptTemplate(name, slug, absoluteWorkspacePath) {
9460
9579
  Determinism rules:
9461
9580
  - Source of truth is the project capsule at: ${absoluteWorkspacePath}/projects/${slug}/
9462
9581
  - After /reset, /new, or context compaction: ALWAYS re-read STATUS.md,
9463
- then TODO.md, then COMMANDS.md before continuing work. Do not rely on
9464
- summarized memory for paths, commands, or task state.
9582
+ then TODO.md, then LEARNINGS.md (last 20 entries), then COMMANDS.md
9583
+ before continuing work. Do not rely on summarized memory for paths,
9584
+ commands, or task state.
9465
9585
  - Before context compaction or when the conversation is long: proactively
9466
9586
  flush current progress to STATUS.md (update "Last done (UTC)" and
9467
- "Next 3 actions") so compaction cannot erase critical state.
9587
+ "Next actions (now)") so compaction cannot erase critical state.
9468
9588
  Use the standard file write tool directly \u2014 do not route through /tm.
9469
- - Keep STATUS.md accurate: always maintain "Last done (UTC)" and "Next 3 actions".
9589
+ - Keep STATUS.md accurate: always maintain "Last done (UTC)", "Next actions (now)",
9590
+ and "Upcoming actions".
9470
9591
  - When new commands appear, add them to COMMANDS.md (don't leave them only in chat).
9471
9592
  - When new links/paths/services appear, add them to LINKS.md.
9472
9593
  - If automation/cron is involved, record job IDs + schedules in CRON.md.
9473
9594
  - Task IDs (e.g., [T-1]) must stay consistent between STATUS.md and TODO.md.
9595
+ - STATUS.md has two priority sections: "Next actions (now)" for immediate work
9596
+ and "Upcoming actions" for the near-future pipeline.
9597
+
9598
+ Learning capture:
9599
+ - When you discover something unexpected, a mistake, a workaround, or a
9600
+ constraint \u2014 prepend a dated entry to LEARNINGS.md.
9601
+ - Format: ## YYYY-MM-DD\\n- source: (chat/debug/research)\\n- insight text
9602
+ - Most recent first (prepend after the header, before existing entries).
9603
+ - Only write when a genuinely new insight exists \u2014 avoid restating known facts.
9604
+ - If LEARNINGS.md exceeds ~200 lines, archive older entries to LEARNINGS-archive.md.
9474
9605
 
9475
9606
  Separation:
9476
- - Do not mix in other topics' work unless explicitly requested.
9607
+ - Your workspace is strictly projects/${slug}/. Do not read, write, or reference
9608
+ files in any other topic's capsule directory.
9609
+ - If the user mentions another topic by name or slug, ask for explicit
9610
+ confirmation before mixing work: "This references topic X \u2014 switch context?"
9611
+ - Never copy data between topic capsules without explicit user instruction.
9477
9612
  - Ask one clarifying question if the next action is ambiguous.`;
9478
9613
  }
9479
9614
  function computeRegistryHash(topics) {
@@ -9627,7 +9762,7 @@ async function triggerRestart(rpc, logger) {
9627
9762
  logger.warn(
9628
9763
  `config.patch baseHash mismatch (attempt ${attempt + 1}/${MAX_RETRIES + 1}). Retrying in ${delay}ms...`
9629
9764
  );
9630
- await sleep(delay);
9765
+ await sleep2(delay);
9631
9766
  continue;
9632
9767
  }
9633
9768
  const errMsg = err instanceof Error ? err.message : String(err);
@@ -9655,7 +9790,7 @@ function isHashMismatchError(err) {
9655
9790
  }
9656
9791
  return false;
9657
9792
  }
9658
- function sleep(ms) {
9793
+ function sleep2(ms) {
9659
9794
  return new Promise((resolve4) => setTimeout(resolve4, ms));
9660
9795
  }
9661
9796
  async function getConfigWrites(rpc) {
@@ -9673,6 +9808,21 @@ async function getConfigWrites(rpc) {
9673
9808
 
9674
9809
  // src/commands/init.ts
9675
9810
  var VALID_TYPES = /* @__PURE__ */ new Set(["coding", "research", "marketing", "custom"]);
9811
+ function deriveTopicName(nameArg, messageContext, threadId) {
9812
+ const topicTitle = messageContext?.["topicTitle"] ?? "";
9813
+ let name;
9814
+ if (nameArg) {
9815
+ name = nameArg;
9816
+ } else if (topicTitle) {
9817
+ name = topicTitle;
9818
+ } else {
9819
+ name = `Topic ${threadId}`;
9820
+ }
9821
+ if (name.length > MAX_NAME_LENGTH) {
9822
+ name = name.slice(0, MAX_NAME_LENGTH);
9823
+ }
9824
+ return name;
9825
+ }
9676
9826
  async function handleInit(ctx, args) {
9677
9827
  const { workspaceDir, configDir, userId, groupId, threadId, rpc, logger, messageContext } = ctx;
9678
9828
  if (!userId || !groupId || !threadId) {
@@ -9698,8 +9848,7 @@ async function handleInit(ctx, args) {
9698
9848
  const key = topicKey(groupId, threadId);
9699
9849
  if (registry.topics[key]) {
9700
9850
  return {
9701
- text: `This topic is already registered as <b>${htmlEscape(registry.topics[key].name)}</b>.`,
9702
- parseMode: "HTML"
9851
+ text: `This topic is already registered as "${registry.topics[key].name}".`
9703
9852
  };
9704
9853
  }
9705
9854
  const parts = args.trim().split(/\s+/);
@@ -9711,18 +9860,7 @@ async function handleInit(ctx, args) {
9711
9860
  } else {
9712
9861
  nameArg = parts.join(" ");
9713
9862
  }
9714
- const topicTitle = messageContext?.["topicTitle"] ?? "";
9715
- let name;
9716
- if (nameArg) {
9717
- name = nameArg;
9718
- } else if (topicTitle) {
9719
- name = topicTitle;
9720
- } else {
9721
- name = `Topic ${threadId}`;
9722
- }
9723
- if (name.length > MAX_NAME_LENGTH) {
9724
- name = name.slice(0, MAX_NAME_LENGTH);
9725
- }
9863
+ const name = deriveTopicName(nameArg, messageContext, threadId);
9726
9864
  const existingSlugs = new Set(Object.values(registry.topics).map((t) => t.slug));
9727
9865
  const finalSlug = generateSlug(threadId, groupId, existingSlugs);
9728
9866
  const projectsBase = path6.join(workspaceDir, "projects");
@@ -9733,7 +9871,7 @@ async function handleInit(ctx, args) {
9733
9871
  return { text: "Projects base is a symlink. Aborting for security." };
9734
9872
  }
9735
9873
  if (fs6.existsSync(path6.join(projectsBase, finalSlug))) {
9736
- return { text: `Directory projects/${htmlEscape(finalSlug)}/ already exists on disk.` };
9874
+ return { text: `Directory projects/${finalSlug}/ already exists on disk.` };
9737
9875
  }
9738
9876
  const targetPath = path6.join(projectsBase, finalSlug);
9739
9877
  if (rejectSymlink(targetPath)) {
@@ -9754,6 +9892,7 @@ async function handleInit(ctx, args) {
9754
9892
  lastMessageAt: (/* @__PURE__ */ new Date()).toISOString(),
9755
9893
  lastDoctorReportAt: null,
9756
9894
  lastDoctorRunAt: null,
9895
+ lastCapsuleWriteAt: null,
9757
9896
  snoozeUntil: null,
9758
9897
  ignoreChecks: [],
9759
9898
  consecutiveSilentDoctors: 0,
@@ -9767,7 +9906,7 @@ async function handleInit(ctx, args) {
9767
9906
  });
9768
9907
  } catch (err) {
9769
9908
  const msg = err instanceof Error ? err.message : String(err);
9770
- return { text: `Failed to initialize topic: ${htmlEscape(msg)}` };
9909
+ return { text: `Failed to initialize topic: ${msg}` };
9771
9910
  }
9772
9911
  let restartMsg = "";
9773
9912
  const configWritesEnabled = await getConfigWrites(ctx.rpc);
@@ -9782,7 +9921,7 @@ async function handleInit(ctx, args) {
9782
9921
  } catch (err) {
9783
9922
  const msg = err instanceof Error ? err.message : String(err);
9784
9923
  restartMsg = `
9785
- Warning: include generation failed: ${htmlEscape(msg)}`;
9924
+ Warning: include generation failed: ${msg}`;
9786
9925
  }
9787
9926
  }
9788
9927
  appendAudit(
@@ -9794,9 +9933,9 @@ Warning: include generation failed: ${htmlEscape(msg)}`;
9794
9933
  if (isFirstUser) {
9795
9934
  adminNote = "\n\nYou are the first user and have been added as a telegram-manager admin.";
9796
9935
  }
9936
+ const autopilotTip = "\n\nTip: Enable daily health sweeps with /tm autopilot enable";
9797
9937
  return {
9798
- text: `${topicCard}${adminNote}${restartMsg}`,
9799
- parseMode: "HTML",
9938
+ text: `${topicCard}${adminNote}${restartMsg}${autopilotTip}`,
9800
9939
  pin: true
9801
9940
  };
9802
9941
  }
@@ -9829,40 +9968,79 @@ async function buildTypePicker(ctx) {
9829
9968
  const key = topicKey(groupId, threadId);
9830
9969
  if (registry.topics[key]) {
9831
9970
  return {
9832
- text: `This topic is already registered as <b>${htmlEscape(registry.topics[key].name)}</b>.`,
9833
- parseMode: "HTML"
9971
+ text: `This topic is already registered as "${registry.topics[key].name}".`
9834
9972
  };
9835
9973
  }
9836
9974
  const keyboard = buildInitTypeButtons(groupId, threadId, registry.callbackSecret, userId);
9837
9975
  return {
9838
9976
  text: "Pick a topic type:",
9839
- parseMode: "HTML",
9840
9977
  inlineKeyboard: keyboard
9841
9978
  };
9842
9979
  }
9843
9980
  async function handleInitTypeSelect(ctx, type) {
9981
+ const { workspaceDir, userId, groupId, threadId, messageContext } = ctx;
9982
+ if (!userId || !groupId || !threadId) {
9983
+ return { text: "Missing context: groupId, threadId, or userId not available. Run this command inside a Telegram forum topic." };
9984
+ }
9985
+ if (!validateGroupId(groupId)) {
9986
+ return { text: "Invalid groupId format." };
9987
+ }
9988
+ if (!validateThreadId(threadId)) {
9989
+ return { text: "Invalid threadId format." };
9990
+ }
9991
+ const registry = readRegistry(workspaceDir);
9992
+ const auth = checkAuthorization(userId, "init", registry);
9993
+ if (!auth.authorized) {
9994
+ return { text: auth.message ?? "Not authorized." };
9995
+ }
9996
+ const topicCount = Object.keys(registry.topics).length;
9997
+ if (topicCount >= registry.maxTopics) {
9998
+ return { text: `Maximum number of topics (${registry.maxTopics}) reached. Archive or remove existing topics first.` };
9999
+ }
10000
+ const key = topicKey(groupId, threadId);
10001
+ if (registry.topics[key]) {
10002
+ return {
10003
+ text: `This topic is already registered as "${registry.topics[key].name}".`
10004
+ };
10005
+ }
10006
+ const name = deriveTopicName("", messageContext, threadId);
10007
+ const keyboard = buildInitConfirmButton(groupId, threadId, registry.callbackSecret, userId, type);
10008
+ return {
10009
+ text: buildInitConfirmMessage(name, type),
10010
+ inlineKeyboard: keyboard
10011
+ };
10012
+ }
10013
+ async function handleInitNameConfirm(ctx, type) {
9844
10014
  return handleInit(ctx, type);
9845
10015
  }
10016
+ function buildInitConfirmMessage(name, type) {
10017
+ return [
10018
+ `Name: **${name}** | Type: ${type}`,
10019
+ "",
10020
+ `To use a different name: /tm init <name> ${type}`
10021
+ ].join("\n");
10022
+ }
9846
10023
 
9847
10024
  // src/commands/doctor.ts
9848
10025
  import * as fs8 from "node:fs";
9849
10026
  import * as path8 from "node:path";
9850
10027
 
9851
10028
  // src/lib/doctor-checks.ts
10029
+ var import_json52 = __toESM(require_lib(), 1);
9852
10030
  import * as fs7 from "node:fs";
9853
10031
  import * as path7 from "node:path";
9854
10032
  function isIgnored(entry, checkId) {
9855
10033
  return entry.ignoreChecks.includes(checkId);
9856
10034
  }
9857
- function check(severity, checkId, message, fixable) {
9858
- return { severity, checkId, message, fixable };
10035
+ function check(severity, checkId, message, fixable, remediation) {
10036
+ return remediation ? { severity, checkId, message, fixable, remediation } : { severity, checkId, message, fixable };
9859
10037
  }
9860
10038
  function runRegistryChecks(entry, projectsBase) {
9861
10039
  const results = [];
9862
10040
  const capsuleDir = path7.join(projectsBase, entry.slug);
9863
10041
  if (!fs7.existsSync(capsuleDir)) {
9864
10042
  results.push(
9865
- check(Severity.ERROR, "pathMissing", `Capsule path does not exist: projects/${entry.slug}/`, false)
10043
+ check(Severity.ERROR, "pathMissing", `Capsule path does not exist: projects/${entry.slug}/`, false, "Run /tm init to create the capsule, or remove the registry entry")
9866
10044
  );
9867
10045
  return results;
9868
10046
  }
@@ -9886,13 +10064,13 @@ function runCapsuleChecks(entry, projectsBase) {
9886
10064
  if (!fs7.existsSync(capsuleDir)) return results;
9887
10065
  if (!fs7.existsSync(path7.join(capsuleDir, "STATUS.md"))) {
9888
10066
  results.push(
9889
- check(Severity.ERROR, "statusMissing", "STATUS.md is missing from capsule", true)
10067
+ check(Severity.ERROR, "statusMissing", "STATUS.md is missing from capsule", true, "Run /tm upgrade to recreate STATUS.md, or restore from .tm-backup/STATUS.md if available")
9890
10068
  );
9891
10069
  }
9892
10070
  if (!fs7.existsSync(path7.join(capsuleDir, "TODO.md"))) {
9893
10071
  if (!isIgnored(entry, "todoMissing")) {
9894
10072
  results.push(
9895
- check(Severity.WARN, "todoMissing", "TODO.md is missing from capsule", true)
10073
+ check(Severity.WARN, "todoMissing", "TODO.md is missing from capsule", true, "Run /tm upgrade to recreate TODO.md")
9896
10074
  );
9897
10075
  }
9898
10076
  }
@@ -9913,7 +10091,7 @@ function runCapsuleChecks(entry, projectsBase) {
9913
10091
  check(
9914
10092
  Severity.INFO,
9915
10093
  "capsuleVersionBehind",
9916
- `Capsule version ${entry.capsuleVersion} is behind current ${CAPSULE_VERSION}. Run /tm upgrade.`,
10094
+ `Capsule version ${entry.capsuleVersion} is behind current ${CAPSULE_VERSION}. Will auto-upgrade on next command.`,
9917
10095
  false
9918
10096
  )
9919
10097
  );
@@ -9922,7 +10100,7 @@ function runCapsuleChecks(entry, projectsBase) {
9922
10100
  return results;
9923
10101
  }
9924
10102
  var LAST_DONE_RE = /^##\s*Last done\s*\(UTC\)/im;
9925
- var NEXT_ACTIONS_RE = /^##\s*Next 3 actions/im;
10103
+ var NEXT_ACTIONS_RE = /^##\s*Next (?:3 )?actions(?: \(now\))?/im;
9926
10104
  var TIMESTAMP_RE = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;
9927
10105
  var TASK_ID_RE = /\[T-\d+\]/g;
9928
10106
  var ADHOC_RE = /\[AD-HOC\]/g;
@@ -9931,7 +10109,7 @@ function runStatusQualityChecks(statusContent, entry) {
9931
10109
  if (!LAST_DONE_RE.test(statusContent)) {
9932
10110
  if (!isIgnored(entry, "lastDoneMissing")) {
9933
10111
  results.push(
9934
- check(Severity.ERROR, "lastDoneMissing", 'STATUS.md missing "Last done (UTC)" section', true)
10112
+ check(Severity.ERROR, "lastDoneMissing", 'STATUS.md missing "Last done (UTC)" section', true, 'Add "## Last done (UTC)" section with a timestamp to STATUS.md, or restore from .tm-backup/STATUS.md if available')
9935
10113
  );
9936
10114
  }
9937
10115
  } else {
@@ -9942,7 +10120,7 @@ function runStatusQualityChecks(statusContent, entry) {
9942
10120
  if (!TIMESTAMP_RE.test(lastDoneSection)) {
9943
10121
  if (!isIgnored(entry, "lastDoneNoTimestamp")) {
9944
10122
  results.push(
9945
- check(Severity.ERROR, "lastDoneNoTimestamp", 'STATUS.md "Last done" section has no timestamp', true)
10123
+ check(Severity.ERROR, "lastDoneNoTimestamp", 'STATUS.md "Last done" section has no timestamp', true, 'Add a YYYY-MM-DDTHH:MM timestamp under "Last done (UTC)" in STATUS.md, or restore from .tm-backup/STATUS.md if available')
9946
10124
  );
9947
10125
  }
9948
10126
  } else if (entry.status === "active") {
@@ -9957,7 +10135,8 @@ function runStatusQualityChecks(statusContent, entry) {
9957
10135
  Severity.WARN,
9958
10136
  "lastDoneStale",
9959
10137
  `STATUS.md "Last done" timestamp is ${Math.floor(ageDays)} days old`,
9960
- false
10138
+ false,
10139
+ 'Update the "Last done (UTC)" timestamp in STATUS.md or /tm snooze 7d'
9961
10140
  )
9962
10141
  );
9963
10142
  }
@@ -9968,7 +10147,7 @@ function runStatusQualityChecks(statusContent, entry) {
9968
10147
  if (!NEXT_ACTIONS_RE.test(statusContent)) {
9969
10148
  if (!isIgnored(entry, "nextActionsMissing")) {
9970
10149
  results.push(
9971
- check(Severity.ERROR, "nextActionsMissing", 'STATUS.md missing "Next 3 actions" section', true)
10150
+ check(Severity.ERROR, "nextActionsMissing", 'STATUS.md missing "Next actions (now)" section', true, 'Add "## Next actions (now)" section with task IDs to STATUS.md')
9972
10151
  );
9973
10152
  }
9974
10153
  } else {
@@ -9984,8 +10163,9 @@ function runStatusQualityChecks(statusContent, entry) {
9984
10163
  check(
9985
10164
  Severity.WARN,
9986
10165
  "nextActionsEmpty",
9987
- '"Next 3 actions" has no task IDs or entries',
9988
- false
10166
+ '"Next actions (now)" has no task IDs or entries',
10167
+ false,
10168
+ 'Add task IDs like [T-1] under "Next actions (now)" in STATUS.md'
9989
10169
  )
9990
10170
  );
9991
10171
  }
@@ -10009,8 +10189,9 @@ function runNextVsTodoChecks(statusContent, todoContent) {
10009
10189
  check(
10010
10190
  Severity.WARN,
10011
10191
  "nextNotInTodo",
10012
- `${missing.length} task IDs in "Next 3 actions" not found in TODO.md: ${missing.join(", ")}`,
10013
- false
10192
+ `${missing.length} task IDs in "Next actions (now)" not found in TODO.md: ${missing.join(", ")}`,
10193
+ false,
10194
+ "Add missing task IDs to TODO.md or remove stale ones from STATUS.md"
10014
10195
  )
10015
10196
  );
10016
10197
  }
@@ -10023,7 +10204,7 @@ function runCommandsLinksChecks(entry, capsuleFiles) {
10023
10204
  if (commandsContent !== void 0 && isEffectivelyEmpty(commandsContent)) {
10024
10205
  if (!isIgnored(entry, "commandsEmpty")) {
10025
10206
  results.push(
10026
- check(Severity.INFO, "commandsEmpty", "COMMANDS.md is empty for a coding topic", false)
10207
+ check(Severity.INFO, "commandsEmpty", "COMMANDS.md is empty for a coding topic", false, "Add build/test/deploy commands to COMMANDS.md")
10027
10208
  );
10028
10209
  }
10029
10210
  }
@@ -10033,7 +10214,7 @@ function runCommandsLinksChecks(entry, capsuleFiles) {
10033
10214
  if (linksContent !== void 0 && isEffectivelyEmpty(linksContent)) {
10034
10215
  if (!isIgnored(entry, "linksEmpty")) {
10035
10216
  results.push(
10036
- check(Severity.INFO, "linksEmpty", "LINKS.md is empty for a coding/research topic", false)
10217
+ check(Severity.INFO, "linksEmpty", "LINKS.md is empty for a coding/research topic", false, "Add URLs and endpoints to LINKS.md")
10037
10218
  );
10038
10219
  }
10039
10220
  }
@@ -10083,8 +10264,7 @@ function runConfigChecks(entry, includeContent, registry) {
10083
10264
  const results = [];
10084
10265
  let includeObj;
10085
10266
  try {
10086
- const stripped = includeContent.split("\n").filter((l) => !l.startsWith("//")).join("\n");
10087
- includeObj = JSON.parse(stripped);
10267
+ includeObj = import_json52.default.parse(includeContent);
10088
10268
  } catch {
10089
10269
  return results;
10090
10270
  }
@@ -10092,7 +10272,7 @@ function runConfigChecks(entry, includeContent, registry) {
10092
10272
  if (!groupConfig) {
10093
10273
  if (!isIgnored(entry, "configGroupMissing")) {
10094
10274
  results.push(
10095
- check(Severity.WARN, "configGroupMissing", `Group ${entry.groupId} missing from generated include`, false)
10275
+ check(Severity.WARN, "configGroupMissing", `Group ${entry.groupId} missing from generated include`, false, "Run /tm sync to add group to generated include")
10096
10276
  );
10097
10277
  }
10098
10278
  return results;
@@ -10102,7 +10282,7 @@ function runConfigChecks(entry, includeContent, registry) {
10102
10282
  if (!topicConfig) {
10103
10283
  if (!isIgnored(entry, "configTopicMissing")) {
10104
10284
  results.push(
10105
- check(Severity.WARN, "configTopicMissing", `Topic config missing for thread ${entry.threadId}`, false)
10285
+ check(Severity.WARN, "configTopicMissing", `Topic config missing for thread ${entry.threadId}`, false, "Run /tm sync to add topic config to generated include")
10106
10286
  );
10107
10287
  }
10108
10288
  return results;
@@ -10110,14 +10290,14 @@ function runConfigChecks(entry, includeContent, registry) {
10110
10290
  if (!topicConfig["systemPrompt"]) {
10111
10291
  if (!isIgnored(entry, "configNoSystemPrompt")) {
10112
10292
  results.push(
10113
- check(Severity.WARN, "configNoSystemPrompt", "Per-topic systemPrompt is missing in generated include", false)
10293
+ check(Severity.WARN, "configNoSystemPrompt", "Per-topic systemPrompt is missing in generated include", false, "Run /tm sync to regenerate systemPrompt in config")
10114
10294
  );
10115
10295
  }
10116
10296
  }
10117
10297
  if (!topicConfig["skills"] || !Array.isArray(topicConfig["skills"])) {
10118
10298
  if (!isIgnored(entry, "configNoSkills")) {
10119
10299
  results.push(
10120
- check(Severity.WARN, "configNoSkills", "Per-topic skills list is missing in generated include", false)
10300
+ check(Severity.WARN, "configNoSkills", "Per-topic skills list is missing in generated include", false, "Run /tm sync to regenerate skills list in config")
10121
10301
  );
10122
10302
  }
10123
10303
  }
@@ -10132,7 +10312,8 @@ function runIncludeDriftCheck(includeFileContent, registry) {
10132
10312
  Severity.WARN,
10133
10313
  "includeDrift",
10134
10314
  "Generated include file has no registry-hash comment. Run /tm sync.",
10135
- false
10315
+ false,
10316
+ "Run /tm sync to regenerate the config include"
10136
10317
  )
10137
10318
  );
10138
10319
  return results;
@@ -10144,7 +10325,8 @@ function runIncludeDriftCheck(includeFileContent, registry) {
10144
10325
  Severity.WARN,
10145
10326
  "includeDrift",
10146
10327
  "Generated include is out of sync with registry. Run /tm sync.",
10147
- false
10328
+ false,
10329
+ "Run /tm sync to regenerate the config include"
10148
10330
  )
10149
10331
  );
10150
10332
  }
@@ -10158,7 +10340,8 @@ function runSpamControlCheck(entry) {
10158
10340
  Severity.INFO,
10159
10341
  "spamControl",
10160
10342
  `${entry.consecutiveSilentDoctors} consecutive doctor reports with no user interaction. Auto-snoozing for 30 days.`,
10161
- true
10343
+ true,
10344
+ "Interact with the topic or /tm snooze 30d to silence reports"
10162
10345
  )
10163
10346
  );
10164
10347
  }
@@ -10193,6 +10376,24 @@ function runAllChecksForTopic(entry, projectsBase, includeContent, registry, cro
10193
10376
  results.push(...runSpamControlCheck(entry));
10194
10377
  return results;
10195
10378
  }
10379
+ var BACKUP_DIR = ".tm-backup";
10380
+ var BACKUP_FILES = ["STATUS.md", "TODO.md"];
10381
+ function backupCapsuleIfHealthy(projectsBase, slug, results) {
10382
+ const hasIssues = results.some((r) => r.severity === Severity.ERROR || r.severity === Severity.WARN);
10383
+ if (hasIssues) return;
10384
+ const capsuleDir = path7.join(projectsBase, slug);
10385
+ const backupDir = path7.join(capsuleDir, BACKUP_DIR);
10386
+ if (!fs7.existsSync(backupDir)) {
10387
+ fs7.mkdirSync(backupDir, { recursive: true });
10388
+ }
10389
+ for (const file of BACKUP_FILES) {
10390
+ const src = path7.join(capsuleDir, file);
10391
+ const dst = path7.join(backupDir, file);
10392
+ if (fs7.existsSync(src)) {
10393
+ fs7.copyFileSync(src, dst);
10394
+ }
10395
+ }
10396
+ }
10196
10397
  function readCapsuleFiles(capsuleDir) {
10197
10398
  const files = /* @__PURE__ */ new Map();
10198
10399
  const filenames = [
@@ -10203,6 +10404,7 @@ function readCapsuleFiles(capsuleDir) {
10203
10404
  "CRON.md",
10204
10405
  "NOTES.md",
10205
10406
  "README.md",
10407
+ "LEARNINGS.md",
10206
10408
  "ARCHITECTURE.md",
10207
10409
  "DEPLOY.md",
10208
10410
  "SOURCES.md",
@@ -10262,6 +10464,7 @@ async function handleDoctor(ctx) {
10262
10464
  registry,
10263
10465
  cronJobsPath
10264
10466
  );
10467
+ backupCapsuleIfHealthy(projectsBase, entry.slug, results);
10265
10468
  const reportText = buildDoctorReport(entry.name, results);
10266
10469
  const keyboard = buildDoctorButtons(
10267
10470
  groupId,
@@ -10284,7 +10487,6 @@ async function handleDoctor(ctx) {
10284
10487
  });
10285
10488
  return {
10286
10489
  text: reportText + textCommands,
10287
- parseMode: "HTML",
10288
10490
  inlineKeyboard: keyboard
10289
10491
  };
10290
10492
  }
@@ -10346,7 +10548,8 @@ async function handleDoctorAll(ctx) {
10346
10548
  if (isSpam) {
10347
10549
  logger.info(`[doctor-all] Auto-snoozing ${entry.slug} (${entry.consecutiveSilentDoctors} silent runs)`);
10348
10550
  }
10349
- const reportText = buildDoctorReport(entry.name, results);
10551
+ backupCapsuleIfHealthy(projectsBase, entry.slug, results);
10552
+ const reportText = buildDoctorReport(entry.name, results, "html");
10350
10553
  const keyboard = buildDoctorButtons(
10351
10554
  entry.groupId,
10352
10555
  entry.threadId,
@@ -10386,6 +10589,36 @@ async function handleDoctorAll(ctx) {
10386
10589
  migrationGroups.push(gid);
10387
10590
  }
10388
10591
  }
10592
+ let postErrors = 0;
10593
+ let postSuccesses = 0;
10594
+ if (ctx.postFn && reports.length > 0) {
10595
+ const rateLimitedPost = createRateLimitedPoster(ctx.postFn);
10596
+ for (const report of reports) {
10597
+ try {
10598
+ await rateLimitedPost(report.groupId, report.threadId, report.text, report.keyboard);
10599
+ postSuccesses++;
10600
+ await withRegistry(workspaceDir, (data) => {
10601
+ const key = `${report.groupId}:${report.threadId}`;
10602
+ const entry = data.topics[key];
10603
+ if (entry) {
10604
+ entry.lastDoctorReportAt = now.toISOString();
10605
+ entry.lastPostError = null;
10606
+ }
10607
+ });
10608
+ } catch (err) {
10609
+ postErrors++;
10610
+ const msg = err instanceof Error ? err.message : String(err);
10611
+ logger.error(`[doctor-all] Post failed for ${report.slug}: ${msg}`);
10612
+ await withRegistry(workspaceDir, (data) => {
10613
+ const key = `${report.groupId}:${report.threadId}`;
10614
+ const entry = data.topics[key];
10615
+ if (entry) {
10616
+ entry.lastPostError = msg.slice(0, MAX_POST_ERROR_LENGTH);
10617
+ }
10618
+ });
10619
+ }
10620
+ }
10621
+ }
10389
10622
  await withRegistry(workspaceDir, (data) => {
10390
10623
  data.lastDoctorAllRunAt = now.toISOString();
10391
10624
  for (const [_key, entry] of Object.entries(data.topics)) {
@@ -10410,17 +10643,20 @@ async function handleDoctorAll(ctx) {
10410
10643
  }
10411
10644
  });
10412
10645
  const lines = [
10413
- `<b>Doctor All Summary</b>`,
10646
+ `**Doctor All Summary**`,
10414
10647
  "",
10415
10648
  `Processed: ${processed}`,
10416
10649
  `Skipped (ineligible): ${skipped}`,
10417
10650
  `Total: ${allEntries.length}`
10418
10651
  ];
10652
+ if (ctx.postFn) {
10653
+ lines.push(`Posted: ${postSuccesses}, Post failures: ${postErrors}`);
10654
+ }
10419
10655
  if (errors.length > 0) {
10420
10656
  lines.push("");
10421
- lines.push(`<b>Errors (${errors.length}):</b>`);
10657
+ lines.push(`**Errors (${errors.length}):**`);
10422
10658
  for (const e of errors.slice(0, 10)) {
10423
- lines.push(`- ${htmlEscape(e)}`);
10659
+ lines.push(`- ${e}`);
10424
10660
  }
10425
10661
  if (errors.length > 10) {
10426
10662
  lines.push(`... and ${errors.length - 10} more`);
@@ -10428,14 +10664,13 @@ async function handleDoctorAll(ctx) {
10428
10664
  }
10429
10665
  if (migrationGroups.length > 0) {
10430
10666
  lines.push("");
10431
- lines.push("<b>Possible group migrations detected:</b>");
10667
+ lines.push("**Possible group migrations detected:**");
10432
10668
  for (const gid of migrationGroups) {
10433
- lines.push(`- Group ${htmlEscape(gid)}: all topics failed. Check for group migration.`);
10669
+ lines.push(`- Group ${gid}: all topics failed. Check for group migration.`);
10434
10670
  }
10435
10671
  }
10436
10672
  return {
10437
- text: lines.join("\n"),
10438
- parseMode: "HTML"
10673
+ text: lines.join("\n")
10439
10674
  };
10440
10675
  }
10441
10676
  function isEligible(entry, now) {
@@ -10467,8 +10702,7 @@ async function handleList(ctx) {
10467
10702
  const topics = Object.values(registry.topics);
10468
10703
  const text = buildListMessage(topics);
10469
10704
  return {
10470
- text,
10471
- parseMode: "HTML"
10705
+ text
10472
10706
  };
10473
10707
  }
10474
10708
 
@@ -10509,7 +10743,7 @@ async function handleStatus(ctx) {
10509
10743
  };
10510
10744
  } catch (err) {
10511
10745
  const msg = err instanceof Error ? err.message : String(err);
10512
- return { text: `Failed to read STATUS.md: ${htmlEscape(msg)}` };
10746
+ return { text: `Failed to read STATUS.md: ${msg}` };
10513
10747
  }
10514
10748
  }
10515
10749
 
@@ -10529,8 +10763,7 @@ async function handleSync(ctx) {
10529
10763
  } catch (err) {
10530
10764
  const msg = err instanceof Error ? err.message : String(err);
10531
10765
  return {
10532
- text: `Sync failed: ${htmlEscape(msg)}`,
10533
- parseMode: "HTML"
10766
+ text: `Sync failed: ${msg}`
10534
10767
  };
10535
10768
  }
10536
10769
  const restartResult = await triggerRestart(rpc, logger);
@@ -10540,8 +10773,7 @@ async function handleSync(ctx) {
10540
10773
  text += "\n" + restartResult.fallbackMessage;
10541
10774
  }
10542
10775
  return {
10543
- text,
10544
- parseMode: "HTML"
10776
+ text
10545
10777
  };
10546
10778
  }
10547
10779
 
@@ -10553,7 +10785,7 @@ async function handleRename(ctx, newName) {
10553
10785
  }
10554
10786
  const trimmedName = newName.trim();
10555
10787
  if (!trimmedName) {
10556
- return { text: "Usage: /tm rename &lt;new-name&gt;" };
10788
+ return { text: "Usage: /tm rename <new-name>" };
10557
10789
  }
10558
10790
  if (trimmedName.length > MAX_NAME_LENGTH) {
10559
10791
  return { text: `Name too long (max ${MAX_NAME_LENGTH} characters).` };
@@ -10570,7 +10802,7 @@ async function handleRename(ctx, newName) {
10570
10802
  }
10571
10803
  const oldName = entry.name;
10572
10804
  if (oldName === trimmedName) {
10573
- return { text: `Topic is already named <b>${htmlEscape(oldName)}</b>.`, parseMode: "HTML" };
10805
+ return { text: `Topic is already named **${oldName}**.` };
10574
10806
  }
10575
10807
  await withRegistry(workspaceDir, (data) => {
10576
10808
  const topic = data.topics[key];
@@ -10587,7 +10819,7 @@ async function handleRename(ctx, newName) {
10587
10819
  } catch (err) {
10588
10820
  const msg = err instanceof Error ? err.message : String(err);
10589
10821
  restartMsg = `
10590
- Warning: include generation failed: ${htmlEscape(msg)}`;
10822
+ Warning: include generation failed: ${msg}`;
10591
10823
  }
10592
10824
  const result = await triggerRestart(rpc, logger);
10593
10825
  if (!result.success && result.fallbackMessage) {
@@ -10600,10 +10832,9 @@ Warning: include generation failed: ${htmlEscape(msg)}`;
10600
10832
  );
10601
10833
  const topicCard = buildTopicCard(trimmedName, entry.slug, entry.type, entry.capsuleVersion);
10602
10834
  return {
10603
- text: `Topic renamed from <b>${htmlEscape(oldName)}</b> to <b>${htmlEscape(trimmedName)}</b>.
10835
+ text: `Topic renamed from **${oldName}** to **${trimmedName}**.
10604
10836
 
10605
- ${topicCard}${restartMsg}`,
10606
- parseMode: "HTML"
10837
+ ${topicCard}${restartMsg}`
10607
10838
  };
10608
10839
  }
10609
10840
 
@@ -10626,16 +10857,14 @@ async function handleUpgrade(ctx) {
10626
10857
  }
10627
10858
  if (entry.capsuleVersion >= CAPSULE_VERSION) {
10628
10859
  return {
10629
- text: `Topic <b>${htmlEscape(entry.name)}</b> is already at capsule version ${CAPSULE_VERSION}. No upgrade needed.`,
10630
- parseMode: "HTML"
10860
+ text: `Topic **${entry.name}** is already at capsule version ${CAPSULE_VERSION}. No upgrade needed.`
10631
10861
  };
10632
10862
  }
10633
10863
  const projectsBase = path11.join(workspaceDir, "projects");
10634
10864
  const result = upgradeCapsule(projectsBase, entry.slug, entry.name, entry.type, entry.capsuleVersion);
10635
10865
  if (!result.upgraded) {
10636
10866
  return {
10637
- text: `No upgrade needed for <b>${htmlEscape(entry.name)}</b>.`,
10638
- parseMode: "HTML"
10867
+ text: `No upgrade needed for **${entry.name}**.`
10639
10868
  };
10640
10869
  }
10641
10870
  await withRegistry(workspaceDir, (data) => {
@@ -10645,10 +10874,9 @@ async function handleUpgrade(ctx) {
10645
10874
  }
10646
10875
  });
10647
10876
  const addedList = result.addedFiles.length > 0 ? `
10648
- Added files: ${result.addedFiles.map((f) => htmlEscape(f)).join(", ")}` : "\nNo new files added.";
10877
+ Added files: ${result.addedFiles.join(", ")}` : "\nNo new files added.";
10649
10878
  return {
10650
- text: `Topic <b>${htmlEscape(entry.name)}</b> upgraded from v${entry.capsuleVersion} to v${result.newVersion}.${addedList}`,
10651
- parseMode: "HTML"
10879
+ text: `Topic **${entry.name}** upgraded from v${entry.capsuleVersion} to v${result.newVersion}.${addedList}`
10652
10880
  };
10653
10881
  }
10654
10882
 
@@ -10661,11 +10889,11 @@ async function handleSnooze(ctx, args) {
10661
10889
  }
10662
10890
  const trimmed = args.trim();
10663
10891
  if (!trimmed) {
10664
- return { text: "Usage: /tm snooze &lt;Nd&gt; (e.g., 7d, 30d)" };
10892
+ return { text: "Usage: /tm snooze <Nd> (e.g., 7d, 30d)" };
10665
10893
  }
10666
10894
  const match = DURATION_RE.exec(trimmed);
10667
10895
  if (!match) {
10668
- return { text: `Invalid duration "${htmlEscape(trimmed)}". Use format: 7d, 30d, etc.` };
10896
+ return { text: `Invalid duration "${trimmed}". Use format: 7d, 30d, etc.` };
10669
10897
  }
10670
10898
  const days = parseInt(match[1], 10);
10671
10899
  if (days <= 0 || days > 365) {
@@ -10695,8 +10923,7 @@ async function handleSnooze(ctx, args) {
10695
10923
  buildAuditEntry(userId, "snooze", entry.slug, `Snoozed for ${days} days until ${snoozeUntil}`)
10696
10924
  );
10697
10925
  return {
10698
- text: `Topic <b>${htmlEscape(entry.name)}</b> snoozed for ${days} days (until ${htmlEscape(snoozeUntil)}).`,
10699
- parseMode: "HTML"
10926
+ text: `Topic **${entry.name}** snoozed for ${days} days (until ${snoozeUntil}).`
10700
10927
  };
10701
10928
  }
10702
10929
 
@@ -10724,10 +10951,10 @@ async function handleArchiveToggle(ctx, archive) {
10724
10951
  return { text: "This topic is not registered. Run /tm init first." };
10725
10952
  }
10726
10953
  if (archive && entry.status === "archived") {
10727
- return { text: `Topic <b>${htmlEscape(entry.name)}</b> is already archived.`, parseMode: "HTML" };
10954
+ return { text: `Topic **${entry.name}** is already archived.` };
10728
10955
  }
10729
10956
  if (!archive && entry.status !== "archived") {
10730
- return { text: `Topic <b>${htmlEscape(entry.name)}</b> is not archived.`, parseMode: "HTML" };
10957
+ return { text: `Topic **${entry.name}** is not archived.` };
10731
10958
  }
10732
10959
  const newStatus = archive ? "archived" : "active";
10733
10960
  await withRegistry(workspaceDir, (data) => {
@@ -10748,7 +10975,7 @@ async function handleArchiveToggle(ctx, archive) {
10748
10975
  } catch (err) {
10749
10976
  const msg = err instanceof Error ? err.message : String(err);
10750
10977
  restartMsg = `
10751
- Warning: include generation failed: ${htmlEscape(msg)}`;
10978
+ Warning: include generation failed: ${msg}`;
10752
10979
  }
10753
10980
  const result = await triggerRestart(rpc, logger);
10754
10981
  if (!result.success && result.fallbackMessage) {
@@ -10761,16 +10988,261 @@ Warning: include generation failed: ${htmlEscape(msg)}`;
10761
10988
  );
10762
10989
  const action = archive ? "archived" : "unarchived";
10763
10990
  return {
10764
- text: `Topic <b>${htmlEscape(entry.name)}</b> ${action}.${restartMsg}`,
10765
- parseMode: "HTML"
10991
+ text: `Topic **${entry.name}** ${action}.${restartMsg}`
10766
10992
  };
10767
10993
  }
10768
10994
 
10995
+ // src/commands/autopilot.ts
10996
+ import * as fs11 from "node:fs";
10997
+ import * as path12 from "node:path";
10998
+ var MARKER_START = "<!-- TM_AUTOPILOT_START -->";
10999
+ var MARKER_END = "<!-- TM_AUTOPILOT_END -->";
11000
+ var HEARTBEAT_BLOCK = `${MARKER_START}
11001
+ ## Topic Manager \u2014 Balanced Autopilot
11002
+
11003
+ Execute these steps IN ORDER. Do not skip steps.
11004
+
11005
+ 1. CALL \`topic_manager\` with command "doctor --all" to health-check all active topics.
11006
+ This handles stale timestamps, task ID mismatches, and posting errors automatically.
11007
+ 2. For each topic where STATUS.md "Last done (UTC)" is >3 days old:
11008
+ post a brief nudge in that topic asking the user for a status update.
11009
+ 3. If no actions were taken in steps 1-2, do nothing (HEARTBEAT_OK).
11010
+ ${MARKER_END}`;
11011
+ var HEARTBEAT_FILENAME = "HEARTBEAT.md";
11012
+ async function handleAutopilot(ctx, args) {
11013
+ const { workspaceDir, userId } = ctx;
11014
+ if (!userId) {
11015
+ return { text: "Missing context: userId not available." };
11016
+ }
11017
+ const registry = readRegistry(workspaceDir);
11018
+ const auth = checkAuthorization(userId, "autopilot", registry);
11019
+ if (!auth.authorized) {
11020
+ return { text: auth.message ?? "Not authorized." };
11021
+ }
11022
+ const subCommand = args.trim().toLowerCase() || "enable";
11023
+ switch (subCommand) {
11024
+ case "enable":
11025
+ return handleEnable(ctx);
11026
+ case "disable":
11027
+ return handleDisable(ctx);
11028
+ case "status":
11029
+ return handleStatus2(ctx);
11030
+ default:
11031
+ return { text: `Unknown autopilot sub-command: "${subCommand}". Use enable, disable, or status.` };
11032
+ }
11033
+ }
11034
+ async function handleEnable(ctx) {
11035
+ const { workspaceDir } = ctx;
11036
+ const heartbeatPath = path12.join(workspaceDir, HEARTBEAT_FILENAME);
11037
+ let content = "";
11038
+ try {
11039
+ if (fs11.existsSync(heartbeatPath)) {
11040
+ content = fs11.readFileSync(heartbeatPath, "utf-8");
11041
+ }
11042
+ } catch {
11043
+ }
11044
+ if (content.includes(MARKER_START)) {
11045
+ await withRegistry(workspaceDir, (data) => {
11046
+ data.autopilotEnabled = true;
11047
+ });
11048
+ return { text: "Autopilot is already enabled." };
11049
+ }
11050
+ const newContent = content ? content.trimEnd() + "\n\n" + HEARTBEAT_BLOCK + "\n" : HEARTBEAT_BLOCK + "\n";
11051
+ fs11.writeFileSync(heartbeatPath, newContent, { mode: 416 });
11052
+ await withRegistry(workspaceDir, (data) => {
11053
+ data.autopilotEnabled = true;
11054
+ });
11055
+ return {
11056
+ text: "**Autopilot enabled.**\nDaily health sweeps will run via the OpenClaw heartbeat."
11057
+ };
11058
+ }
11059
+ async function handleDisable(ctx) {
11060
+ const { workspaceDir } = ctx;
11061
+ const heartbeatPath = path12.join(workspaceDir, HEARTBEAT_FILENAME);
11062
+ if (!fs11.existsSync(heartbeatPath)) {
11063
+ await withRegistry(workspaceDir, (data) => {
11064
+ data.autopilotEnabled = false;
11065
+ });
11066
+ return { text: "Autopilot is not enabled (no HEARTBEAT.md found)." };
11067
+ }
11068
+ let content = fs11.readFileSync(heartbeatPath, "utf-8");
11069
+ if (!content.includes(MARKER_START)) {
11070
+ await withRegistry(workspaceDir, (data) => {
11071
+ data.autopilotEnabled = false;
11072
+ });
11073
+ return { text: "Autopilot is not enabled (no marker found in HEARTBEAT.md)." };
11074
+ }
11075
+ const startIdx = content.indexOf(MARKER_START);
11076
+ const endIdx = content.indexOf(MARKER_END);
11077
+ if (startIdx >= 0 && endIdx >= 0) {
11078
+ const before = content.slice(0, startIdx);
11079
+ const after = content.slice(endIdx + MARKER_END.length);
11080
+ content = (before + after).replace(/\n{3,}/g, "\n\n").trim();
11081
+ if (content) {
11082
+ fs11.writeFileSync(heartbeatPath, content + "\n", { mode: 416 });
11083
+ } else {
11084
+ fs11.unlinkSync(heartbeatPath);
11085
+ }
11086
+ }
11087
+ await withRegistry(workspaceDir, (data) => {
11088
+ data.autopilotEnabled = false;
11089
+ });
11090
+ return {
11091
+ text: "**Autopilot disabled.**\nDaily sweeps will no longer run automatically."
11092
+ };
11093
+ }
11094
+ async function handleStatus2(ctx) {
11095
+ const { workspaceDir } = ctx;
11096
+ const registry = readRegistry(workspaceDir);
11097
+ const enabled = registry.autopilotEnabled;
11098
+ const lastRun = registry.lastDoctorAllRunAt ?? "never";
11099
+ const lines = [
11100
+ `**Autopilot:** ${enabled ? "enabled" : "disabled"}`,
11101
+ `**Last doctor-all run:** ${lastRun}`
11102
+ ];
11103
+ return {
11104
+ text: lines.join("\n")
11105
+ };
11106
+ }
11107
+
11108
+ // src/commands/daily-report.ts
11109
+ import * as fs12 from "node:fs";
11110
+ import * as path13 from "node:path";
11111
+ async function handleDailyReport(ctx) {
11112
+ const { workspaceDir, groupId, threadId, logger } = ctx;
11113
+ if (!groupId || !threadId) {
11114
+ return { text: "Missing context: must be called from a topic thread." };
11115
+ }
11116
+ const key = topicKey(groupId, threadId);
11117
+ const registry = readRegistry(workspaceDir);
11118
+ const entry = registry.topics[key];
11119
+ if (!entry) {
11120
+ return { text: "This topic is not registered. Run /tm init first." };
11121
+ }
11122
+ if (entry.lastDoctorReportAt) {
11123
+ const lastReport = new Date(entry.lastDoctorReportAt);
11124
+ const now = /* @__PURE__ */ new Date();
11125
+ if (lastReport.getUTCFullYear() === now.getUTCFullYear() && lastReport.getUTCMonth() === now.getUTCMonth() && lastReport.getUTCDate() === now.getUTCDate()) {
11126
+ return { text: "Daily report already generated today. Try again tomorrow." };
11127
+ }
11128
+ }
11129
+ const projectsBase = path13.join(workspaceDir, "projects");
11130
+ const capsuleDir = path13.join(projectsBase, entry.slug);
11131
+ if (!fs12.existsSync(capsuleDir)) {
11132
+ return { text: `Capsule directory not found: projects/${entry.slug}/` };
11133
+ }
11134
+ const statusContent = readFileOrNull(path13.join(capsuleDir, "STATUS.md"));
11135
+ const todoContent = readFileOrNull(path13.join(capsuleDir, "TODO.md"));
11136
+ const learningsContent = readFileOrNull(path13.join(capsuleDir, "LEARNINGS.md"));
11137
+ const doneContent = extractDoneSection(statusContent);
11138
+ const newLearnings = extractTodayLearnings(learningsContent);
11139
+ const blockers = extractBlockers(todoContent);
11140
+ const nextContent = extractNextActions(statusContent);
11141
+ const upcomingContent = extractUpcoming(statusContent);
11142
+ const health = computeHealth(entry.lastMessageAt, statusContent, blockers);
11143
+ const reportText = buildDailyReport({
11144
+ name: entry.name,
11145
+ doneContent,
11146
+ learningsContent: newLearnings,
11147
+ blockersContent: blockers,
11148
+ nextContent,
11149
+ upcomingContent,
11150
+ health
11151
+ });
11152
+ if (ctx.postFn) {
11153
+ try {
11154
+ await ctx.postFn(groupId, threadId, reportText);
11155
+ await withRegistry(workspaceDir, (data) => {
11156
+ const e = data.topics[key];
11157
+ if (e) {
11158
+ e.lastDoctorReportAt = (/* @__PURE__ */ new Date()).toISOString();
11159
+ }
11160
+ });
11161
+ } catch (err) {
11162
+ const msg = err instanceof Error ? err.message : String(err);
11163
+ logger.error(`[daily-report] Post failed: ${msg}`);
11164
+ return { text: `Daily report generated but post failed: ${msg}` };
11165
+ }
11166
+ } else {
11167
+ await withRegistry(workspaceDir, (data) => {
11168
+ const e = data.topics[key];
11169
+ if (e) {
11170
+ e.lastDoctorReportAt = (/* @__PURE__ */ new Date()).toISOString();
11171
+ }
11172
+ });
11173
+ }
11174
+ return { text: reportText };
11175
+ }
11176
+ function readFileOrNull(filePath) {
11177
+ try {
11178
+ return fs12.readFileSync(filePath, "utf-8");
11179
+ } catch {
11180
+ return null;
11181
+ }
11182
+ }
11183
+ function extractDoneSection(statusContent) {
11184
+ if (!statusContent) return "_No STATUS.md found._";
11185
+ const match = statusContent.match(/^##\s*Last done\s*\(UTC\)\s*\n([\s\S]*?)(?=\n##\s|\n*$)/im);
11186
+ if (!match) return '_No "Last done" section found._';
11187
+ const text = match[1]?.trim();
11188
+ return text || "_Empty._";
11189
+ }
11190
+ function extractTodayLearnings(learningsContent) {
11191
+ if (!learningsContent) return "_No LEARNINGS.md found._";
11192
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
11193
+ const lines = learningsContent.split("\n");
11194
+ const todayLines = [];
11195
+ let inTodaySection = false;
11196
+ for (const line of lines) {
11197
+ if (line.startsWith("## ") && line.includes(today)) {
11198
+ inTodaySection = true;
11199
+ continue;
11200
+ }
11201
+ if (inTodaySection && line.startsWith("## ")) {
11202
+ break;
11203
+ }
11204
+ if (inTodaySection && line.trim()) {
11205
+ todayLines.push(line);
11206
+ }
11207
+ }
11208
+ return todayLines.length > 0 ? todayLines.join("\n") : "_None today._";
11209
+ }
11210
+ function extractBlockers(todoContent) {
11211
+ if (!todoContent) return "_No TODO.md found._";
11212
+ const lines = todoContent.split("\n");
11213
+ const blockerLines = lines.filter(
11214
+ (l) => /\[BLOCKED\]/i.test(l) || /\bblocked\b/i.test(l)
11215
+ );
11216
+ return blockerLines.length > 0 ? blockerLines.join("\n") : "_None._";
11217
+ }
11218
+ function extractNextActions(statusContent) {
11219
+ if (!statusContent) return "_No STATUS.md found._";
11220
+ const match = statusContent.match(/^##\s*Next (?:3 )?actions(?: \(now\))?\s*\n([\s\S]*?)(?=\n##\s|\n*$)/im);
11221
+ if (!match) return '_No "Next actions" section found._';
11222
+ const text = match[1]?.trim();
11223
+ return text || "_Empty._";
11224
+ }
11225
+ function extractUpcoming(statusContent) {
11226
+ if (!statusContent) return "_No STATUS.md found._";
11227
+ const match = statusContent.match(/^##\s*Upcoming actions\s*\n([\s\S]*?)(?=\n##\s|\n*$)/im);
11228
+ if (!match) return '_No "Upcoming actions" section found._';
11229
+ const text = match[1]?.trim();
11230
+ return text || "_Empty._";
11231
+ }
11232
+ function computeHealth(lastMessageAt, statusContent, blockers) {
11233
+ if (blockers && blockers !== "_None._" && blockers !== "_No TODO.md found._") {
11234
+ return "blocked";
11235
+ }
11236
+ if (!lastMessageAt) return "stale";
11237
+ const hoursSinceActivity = (Date.now() - new Date(lastMessageAt).getTime()) / 36e5;
11238
+ if (hoursSinceActivity > 72) return "stale";
11239
+ return "fresh";
11240
+ }
11241
+
10769
11242
  // src/commands/help.ts
10770
11243
  function handleHelp(_ctx) {
10771
11244
  return {
10772
- text: buildHelpCard(),
10773
- parseMode: "HTML"
11245
+ text: buildHelpCard()
10774
11246
  };
10775
11247
  }
10776
11248
 
@@ -10788,6 +11260,29 @@ function createTopicManagerTool(deps) {
10788
11260
  return handleCallback(commandStr, ctx);
10789
11261
  }
10790
11262
  const { subCommand, args, flags } = parseCommand(commandStr);
11263
+ if (ctx.groupId && ctx.threadId) {
11264
+ const key = topicKey(ctx.groupId, ctx.threadId);
11265
+ const projectsBase = `${workspaceDir}/projects`;
11266
+ void withRegistry(workspaceDir, (data) => {
11267
+ const entry = data.topics[key];
11268
+ if (!entry) return;
11269
+ entry.lastMessageAt = (/* @__PURE__ */ new Date()).toISOString();
11270
+ if (entry.capsuleVersion < CAPSULE_VERSION) {
11271
+ const oldVersion = entry.capsuleVersion;
11272
+ try {
11273
+ upgradeCapsule(projectsBase, entry.slug, entry.name, entry.type, entry.capsuleVersion);
11274
+ entry.capsuleVersion = CAPSULE_VERSION;
11275
+ logger.info(`[auto-upgrade] ${entry.slug} v${oldVersion} \u2192 v${CAPSULE_VERSION}`);
11276
+ } catch (err) {
11277
+ const msg = err instanceof Error ? err.message : String(err);
11278
+ logger.error(`[auto-upgrade] ${entry.slug} failed: ${msg}`);
11279
+ }
11280
+ }
11281
+ }).catch((err) => {
11282
+ const msg = err instanceof Error ? err.message : String(err);
11283
+ logger.error(`[activity-tracking] Failed: ${msg}`);
11284
+ });
11285
+ }
10791
11286
  try {
10792
11287
  switch (subCommand) {
10793
11288
  case "init":
@@ -10815,18 +11310,22 @@ function createTopicManagerTool(deps) {
10815
11310
  return await handleArchive(ctx);
10816
11311
  case "unarchive":
10817
11312
  return await handleUnarchive(ctx);
11313
+ case "autopilot":
11314
+ return await handleAutopilot(ctx, args);
11315
+ case "daily-report":
11316
+ return await handleDailyReport(ctx);
10818
11317
  case "help":
10819
11318
  return await handleHelp(ctx);
10820
11319
  default:
10821
11320
  return {
10822
- text: `Unknown command: "${htmlEscape(subCommand)}". Try /tm help for available commands.`
11321
+ text: `Unknown command: "${subCommand}". Try /tm help for available commands.`
10823
11322
  };
10824
11323
  }
10825
11324
  } catch (err) {
10826
11325
  const msg = err instanceof Error ? err.message : String(err);
10827
11326
  logger.error(`[topic_manager] Command "${subCommand}" failed: ${msg}`);
10828
11327
  return {
10829
- text: `Command failed: ${htmlEscape(msg)}`
11328
+ text: `Command failed: ${msg}`
10830
11329
  };
10831
11330
  }
10832
11331
  }
@@ -10863,7 +11362,8 @@ function buildContext(deps, execContext) {
10863
11362
  groupId: groupId ?? void 0,
10864
11363
  threadId: threadId ?? void 0,
10865
11364
  userId: userId ?? void 0,
10866
- messageContext: execContext
11365
+ messageContext: execContext,
11366
+ postFn: deps.postFn
10867
11367
  };
10868
11368
  }
10869
11369
  function extractString(obj, key) {
@@ -10902,10 +11402,19 @@ async function handleCallback(data, ctx) {
10902
11402
  im: "marketing",
10903
11403
  ix: "custom"
10904
11404
  };
11405
+ const initConfirmMap = {
11406
+ yc: "coding",
11407
+ yr: "research",
11408
+ ym: "marketing",
11409
+ yx: "custom"
11410
+ };
10905
11411
  const cbCtx = { ...ctx, groupId: cbGroupId, threadId: cbThreadId, userId: cbUserId };
10906
11412
  if (action in initTypeMap) {
10907
11413
  return handleInitTypeSelect(cbCtx, initTypeMap[action]);
10908
11414
  }
11415
+ if (action in initConfirmMap) {
11416
+ return handleInitNameConfirm(cbCtx, initConfirmMap[action]);
11417
+ }
10909
11418
  const key = topicKey(cbGroupId, cbThreadId);
10910
11419
  const entry = registry.topics[key];
10911
11420
  if (!entry) {
@@ -10926,7 +11435,7 @@ async function handleCallback(data, ctx) {
10926
11435
  };
10927
11436
  }
10928
11437
  default:
10929
- return { text: `Unknown callback action: ${htmlEscape(action)}` };
11438
+ return { text: `Unknown callback action: ${action}` };
10930
11439
  }
10931
11440
  }
10932
11441
  async function handleCallbackFix(ctx) {
@@ -10943,40 +11452,72 @@ async function handleCallbackFix(ctx) {
10943
11452
  // src/index.ts
10944
11453
  function resolveConfigDir() {
10945
11454
  const thisFile = new URL(import.meta.url).pathname;
10946
- const parts = thisFile.split(path12.sep);
11455
+ const parts = thisFile.split(path14.sep);
10947
11456
  const extIndex = parts.lastIndexOf("extensions");
10948
11457
  if (extIndex > 0) {
10949
- const candidate = parts.slice(0, extIndex).join(path12.sep);
10950
- if (fs11.existsSync(path12.join(candidate, "openclaw.json")) || fs11.existsSync(path12.join(candidate, "extensions"))) {
11458
+ const candidate = parts.slice(0, extIndex).join(path14.sep);
11459
+ if (fs13.existsSync(path14.join(candidate, "openclaw.json")) || fs13.existsSync(path14.join(candidate, "extensions"))) {
10951
11460
  return candidate;
10952
11461
  }
10953
11462
  }
10954
11463
  const envDir = process.env["OPENCLAW_CONFIG_DIR"];
10955
- if (envDir && fs11.existsSync(envDir)) return path12.resolve(envDir);
11464
+ if (envDir && fs13.existsSync(envDir)) return path14.resolve(envDir);
10956
11465
  const homeDir = process.env["HOME"] ?? process.env["USERPROFILE"] ?? "";
10957
- const defaultDir = path12.join(homeDir, ".openclaw");
10958
- if (fs11.existsSync(defaultDir)) return defaultDir;
11466
+ const defaultDir = path14.join(homeDir, ".openclaw");
11467
+ if (fs13.existsSync(defaultDir)) return defaultDir;
10959
11468
  return void 0;
10960
11469
  }
10961
11470
  function register(api) {
10962
11471
  const resolvedConfigDir = resolveConfigDir();
10963
11472
  const configDir = api.configDir ?? api.pluginConfig?.configDir ?? resolvedConfigDir;
10964
- const workspaceDir = api.workspaceDir ?? api.pluginConfig?.workspaceDir ?? (resolvedConfigDir ? path12.join(resolvedConfigDir, "workspace") : void 0);
11473
+ const workspaceDir = api.workspaceDir ?? api.pluginConfig?.workspaceDir ?? (resolvedConfigDir ? path14.join(resolvedConfigDir, "workspace") : void 0);
10965
11474
  if (!configDir || !workspaceDir) {
10966
11475
  api.logger.error(
10967
11476
  "telegram-manager: configDir or workspaceDir not available. Plugin cannot initialize."
10968
11477
  );
10969
11478
  return;
10970
11479
  }
11480
+ let resolvedPostFn;
11481
+ const lazyPostFn = async (groupId, threadId, text, keyboard) => {
11482
+ if (resolvedPostFn === null) throw new Error("openclaw SDK unavailable \u2013 cannot post");
11483
+ if (resolvedPostFn === void 0) {
11484
+ try {
11485
+ const sdkPath = ["openclaw", "dist", "plugin-sdk", "index.js"].join("/");
11486
+ const sdk = await import(
11487
+ /* @vite-ignore */
11488
+ sdkPath
11489
+ );
11490
+ if (typeof sdk["sendMessageTelegram"] === "function") {
11491
+ const sendMsg = sdk["sendMessageTelegram"];
11492
+ resolvedPostFn = async (gId, tId, txt, kb) => {
11493
+ const opts = {
11494
+ messageThreadId: Number(tId),
11495
+ textMode: "html"
11496
+ };
11497
+ if (kb) opts.buttons = kb.inline_keyboard;
11498
+ await sendMsg(gId, txt, opts);
11499
+ };
11500
+ api.logger.info("telegram-manager: postFn wired via plugin-sdk");
11501
+ } else {
11502
+ resolvedPostFn = null;
11503
+ }
11504
+ } catch {
11505
+ resolvedPostFn = null;
11506
+ }
11507
+ }
11508
+ if (!resolvedPostFn) throw new Error("openclaw SDK unavailable \u2013 cannot post");
11509
+ await resolvedPostFn(groupId, threadId, text, keyboard);
11510
+ };
10971
11511
  const tool = createTopicManagerTool({
10972
11512
  logger: api.logger,
10973
11513
  configDir,
10974
11514
  workspaceDir,
10975
- rpc: api.rpc
11515
+ rpc: api.rpc,
11516
+ postFn: lazyPostFn
10976
11517
  });
10977
11518
  api.registerTool({
10978
11519
  name: "topic_manager",
10979
- description: "Manage Telegram forum topics as deterministic workcells. Sub-commands: init, doctor, list, status, sync, rename, upgrade, snooze, archive, unarchive, help.",
11520
+ description: "Manage Telegram forum topics as deterministic workcells. Sub-commands: init, doctor, list, status, sync, rename, upgrade, snooze, archive, unarchive, autopilot, help.",
10980
11521
  parameters: Type.Object({
10981
11522
  command: Type.String({
10982
11523
  description: "Sub-command and arguments (e.g., 'init', 'doctor --all', 'rename new-name')"
@@ -10992,30 +11533,25 @@ function register(api) {
10992
11533
  if (api.registerCommand) {
10993
11534
  api.registerCommand({
10994
11535
  name: "tm",
10995
- description: "Manage Telegram forum topics as deterministic workcells. Sub-commands: init, doctor, list, status, sync, rename, upgrade, snooze, archive, unarchive, help.",
11536
+ description: "Manage Telegram forum topics as deterministic workcells. Sub-commands: init, doctor, list, status, sync, rename, upgrade, snooze, archive, unarchive, autopilot, help.",
10996
11537
  acceptsArgs: true,
10997
11538
  requireAuth: false,
10998
11539
  async handler(ctx) {
10999
11540
  const userId = ctx.senderId;
11000
11541
  const groupId = ctx.from?.replace(/^telegram:(?:group:)?/, "").split(":topic:")[0] || void 0;
11001
11542
  const threadId = ctx.messageThreadId != null ? String(ctx.messageThreadId) : void 0;
11543
+ const topicTitle = ctx["topicTitle"] ?? ctx["topicName"];
11002
11544
  const execContext = {};
11003
11545
  if (userId) execContext.userId = userId;
11004
11546
  if (groupId) execContext.groupId = groupId;
11005
11547
  if (threadId) execContext.threadId = threadId;
11548
+ if (topicTitle != null) execContext.topicTitle = String(topicTitle);
11006
11549
  const result = await tool.execute("cmd", { command: ctx.args }, execContext);
11007
11550
  const reply = {
11008
11551
  text: result.text
11009
11552
  };
11010
- const telegramData = {};
11011
11553
  if (result.inlineKeyboard) {
11012
- telegramData.buttons = result.inlineKeyboard.inline_keyboard;
11013
- }
11014
- if (result.parseMode) {
11015
- telegramData.parse_mode = result.parseMode;
11016
- }
11017
- if (Object.keys(telegramData).length > 0) {
11018
- reply.channelData = { telegram: telegramData };
11554
+ reply.channelData = { telegram: { buttons: result.inlineKeyboard.inline_keyboard } };
11019
11555
  }
11020
11556
  return reply;
11021
11557
  }