blun-king-cli 9.1.217 → 9.1.218

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.
@@ -206,9 +206,25 @@ function markCandidate(candidate, status, nowIso) {
206
206
  });
207
207
  }
208
208
 
209
+ function verificationCommandHash(signal) {
210
+ return crypto.createHash('sha256').update(signal.command).digest('hex');
211
+ }
212
+
213
+ function pendingCandidateForSignal(candidates, signal) {
214
+ const commandHash = verificationCommandHash(signal);
215
+ for (let index = candidates.length - 1; index >= 0; index -= 1) {
216
+ const candidate = candidates[index];
217
+ if (candidate.status === 'pending'
218
+ && candidate.verification?.commandHash === commandHash) {
219
+ return candidate;
220
+ }
221
+ }
222
+ return null;
223
+ }
224
+
209
225
  function createCandidate(signal, options, nowIso) {
210
226
  const profile = profileKey(options.profile);
211
- const commandHash = crypto.createHash('sha256').update(signal.command).digest('hex');
227
+ const commandHash = verificationCommandHash(signal);
212
228
  const digest = crypto.createHash('sha256').update([
213
229
  profile,
214
230
  commandHash,
@@ -264,20 +280,27 @@ function syncValidatedLearningCandidate(history, options = {}) {
264
280
  if (recordedCandidateIds.size > 0) {
265
281
  candidates = readValidatedLearningCandidates({ homeDir, profile: options.profile });
266
282
  }
267
- if (signal !== null) {
268
- return {
269
- ...createCandidate(signal, { homeDir, profile: options.profile }, nowIso),
270
- source: 'current_turn',
271
- };
272
- }
273
-
283
+ let expiredCandidate = false;
274
284
  for (const candidate of candidates) {
275
285
  if (candidate.status !== 'pending') continue;
276
286
  if (nowMs - Date.parse(candidate.createdAt) >= CANDIDATE_TTL_MS) {
277
287
  markCandidate(candidate, 'expired', nowIso);
288
+ expiredCandidate = true;
289
+ }
290
+ }
291
+ if (expiredCandidate) {
292
+ candidates = readValidatedLearningCandidates({ homeDir, profile: options.profile });
293
+ }
294
+ if (signal !== null) {
295
+ const duplicate = pendingCandidateForSignal(candidates, signal);
296
+ if (duplicate !== null) {
297
+ return { ...duplicate, source: 'current_turn' };
278
298
  }
299
+ return {
300
+ ...createCandidate(signal, { homeDir, profile: options.profile }, nowIso),
301
+ source: 'current_turn',
302
+ };
279
303
  }
280
- candidates = readValidatedLearningCandidates({ homeDir, profile: options.profile });
281
304
  const pending = newestPending(candidates);
282
305
  return pending === null ? null : { ...pending, source: 'persisted' };
283
306
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.217",
3
+ "version": "9.1.218",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {