@ouro.bot/cli 0.1.0-alpha.812 → 0.1.0-alpha.814

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.
@@ -6,7 +6,7 @@
6
6
  <meta name="color-scheme" content="dark" />
7
7
  <title>Ouro Mailbox</title>
8
8
  <meta name="description" content="The daemon-hosted shared orientation surface for agents alive on this machine." />
9
- <script type="module" crossorigin src="/assets/index-J8zDwHmE.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-Cyv4mw3Y.js"></script>
10
10
  <link rel="modulepreload" crossorigin href="/assets/vendor-CcN1XpQ9.js">
11
11
  <link rel="stylesheet" crossorigin href="/assets/index-Du_9G9WO.css">
12
12
  </head>
@@ -393,7 +393,37 @@ function postTurnTrim(messages, usage, hooks) {
393
393
  const currentIngressTimes = preTrimMessages.map(session_events_1.getIngressTime);
394
394
  const currentIngressRelations = preTrimMessages.map(session_events_1.getIngressRelations);
395
395
  const currentMessages = (0, session_events_1.sanitizeProviderMessages)(messages);
396
- const tokenTrimmedMessages = trimMessages(currentMessages, maxTokens, contextMargin, usage?.input_tokens);
396
+ let tokenTrimmedMessages = trimMessages(currentMessages, maxTokens, contextMargin, usage?.input_tokens);
397
+ const estimatedTokens = (0, token_estimate_1.estimateTokensForMessages)(tokenTrimmedMessages);
398
+ if (estimatedTokens > maxTokens) {
399
+ const targetTokens = Math.floor(maxTokens * (1 - contextMargin / 100));
400
+ const lastUser = tokenTrimmedMessages.findLastIndex((message) => message.role === "user");
401
+ const lastAssistant = tokenTrimmedMessages.findLastIndex((message) => message.role === "assistant");
402
+ const dropped = new Set();
403
+ let remaining = estimatedTokens;
404
+ for (const block of buildTrimmableBlocks(tokenTrimmedMessages)) {
405
+ if (remaining <= targetTokens)
406
+ break;
407
+ if (block.indices.includes(lastUser) || lastAssistant > lastUser && block.indices.includes(lastAssistant))
408
+ continue;
409
+ for (const index of block.indices)
410
+ dropped.add(index);
411
+ remaining -= block.estimatedTokens;
412
+ }
413
+ tokenTrimmedMessages = remaining > maxTokens ? [] : tokenTrimmedMessages.filter((_message, index) => !dropped.has(index));
414
+ (0, runtime_1.emitNervesEvent)({
415
+ level: tokenTrimmedMessages.length === 0 ? "warn" : "info",
416
+ event: "mind.step_end",
417
+ component: "mind",
418
+ message: "bounded post-turn projection using canonical token estimates",
419
+ meta: {
420
+ maxTokens, targetTokens, estimated_before: estimatedTokens,
421
+ estimated_after: (0, token_estimate_1.estimateTokensForMessages)(tokenTrimmedMessages),
422
+ reported_input_tokens: usage?.input_tokens ?? null,
423
+ emptyProjection: tokenTrimmedMessages.length === 0,
424
+ },
425
+ });
426
+ }
397
427
  const trimmedMessages = compactIdleRestOnlyTurns(tokenTrimmedMessages);
398
428
  messages.splice(0, messages.length, ...trimmedMessages);
399
429
  return { currentMessages, trimmedMessages, currentIngressTimes, currentIngressRelations, maxTokens, contextMargin };
@@ -268,14 +268,26 @@ function rawSessionEvents(value) {
268
268
  const record = value;
269
269
  return record.version === 2 && Array.isArray(record.events) ? record.events : [];
270
270
  }
271
- function exactProjectedIngressMessage(existing, messages, eventId) {
271
+ function exactProjectedIngressMessage(existing, messages, eventId, nativeValue) {
272
+ if (!nativeValue || typeof nativeValue !== "object" || Array.isArray(nativeValue))
273
+ return null;
274
+ const native = nativeValue;
275
+ if (native.version !== 2 || !native.projection || typeof native.projection !== "object" || Array.isArray(native.projection))
276
+ return null;
277
+ const projection = native.projection;
278
+ if (!Array.isArray(projection.eventIds))
279
+ return null;
280
+ // Authorization must inspect stored IDs before a reader filters unresolved entries.
281
+ const projectionIds = projection.eventIds.length > 0
282
+ ? projection.eventIds
283
+ : projection.trimmed === true ? [] : existing.projectionEventIds;
272
284
  const eventsById = new Map(existing.events.map((event) => [event.id, event]));
273
285
  if (eventsById.size !== existing.events.length)
274
286
  return null;
275
287
  const seenProjectionIds = new Set();
276
288
  const effectiveIds = new Set((0, session_events_1.selectEffectiveSessionEvents)(existing.events).map((event) => event.id));
277
289
  const projectedEvents = [];
278
- for (const projectedId of existing.projectionEventIds) {
290
+ for (const projectedId of projectionIds) {
279
291
  if (typeof projectedId !== "string" || !projectedId.trim() || seenProjectionIds.has(projectedId))
280
292
  return null;
281
293
  const event = eventsById.get(projectedId);
@@ -285,7 +297,7 @@ function exactProjectedIngressMessage(existing, messages, eventId) {
285
297
  if (effectiveIds.has(event.id))
286
298
  projectedEvents.push(event);
287
299
  }
288
- if (existing.projectionEventIds.filter((projectedId) => projectedId === eventId).length !== 1)
300
+ if (projectionIds.filter((projectedId) => projectedId === eventId).length !== 1)
289
301
  return null;
290
302
  const projectedUsers = projectedEvents.filter((event) => event.role === "user");
291
303
  const providerUsers = messages.filter((message) => message.role === "user");
@@ -401,7 +413,8 @@ async function runSenseTurnExclusive(options, owner) {
401
413
  const runWithLease = options._withSessionTurnLease ?? session_transaction_1.withSessionTurnLease;
402
414
  try {
403
415
  return await runWithLease(sessPath, async (sessionTurnLease) => {
404
- const baseSessionRevision = (0, session_transaction_1.readSessionTransaction)(sessPath, sessionTurnLease).revision;
416
+ const baseSession = (0, session_transaction_1.readSessionTransaction)(sessPath, sessionTurnLease);
417
+ const baseSessionRevision = baseSession.revision;
405
418
  const existing = options.disablePersistence ? undefined : (0, context_1.loadSession)(sessPath);
406
419
  const precommittedIngressEvent = options.precommittedIngress
407
420
  ? existing?.events?.find((candidate) => candidate.id === options.precommittedIngress.eventId)
@@ -424,7 +437,7 @@ async function runSenseTurnExclusive(options, owner) {
424
437
  content: (0, prompt_1.flattenSystemPrompt)(await (0, prompt_1.buildSystem)(channel, options.disableTools ? { tools: [], hardDisableTools: true } : {}, undefined)),
425
438
  }];
426
439
  if (precommittedIngressEvent) {
427
- const projectedIngress = exactProjectedIngressMessage(existing, sessionMessages, precommittedIngressEvent.id);
440
+ const projectedIngress = exactProjectedIngressMessage(existing, sessionMessages, precommittedIngressEvent.id, baseSession.value);
428
441
  if (!projectedIngress || projectedIngress.role !== "user" || projectedIngress.content !== userMessage)
429
442
  throw new Error("shared turn precommitted ingress is absent from the provider projection");
430
443
  (0, session_events_1.stampIngressRelations)(projectedIngress, {
@@ -724,11 +724,15 @@ function appendTelegramArtifactEvents(envelope, artifact, recordedAt) {
724
724
  };
725
725
  });
726
726
  const eventIds = events.map((event) => event.id);
727
+ const priorIds = (0, session_events_1.projectedSessionEventIds)(envelope);
727
728
  return {
728
729
  envelope: {
729
730
  ...envelope,
730
731
  events: [...envelope.events, ...events],
731
- projection: { ...envelope.projection, eventIds: [...envelope.projection.eventIds, ...eventIds], projectedAt: recordedAt, trimmed: false },
732
+ projection: {
733
+ ...envelope.projection, eventIds: [...priorIds, ...eventIds], projectedAt: recordedAt,
734
+ trimmed: new Set(priorIds).size < (0, session_events_1.selectEffectiveSessionEvents)(envelope.events).length,
735
+ },
732
736
  },
733
737
  eventIds,
734
738
  };
@@ -758,10 +762,14 @@ function appendTelegramInboundEvent(envelope, input) {
758
762
  },
759
763
  provenance: { captureKind: "live", legacyVersion: null, sourceMessageIndex: null },
760
764
  };
765
+ const priorIds = (0, session_events_1.projectedSessionEventIds)(envelope);
761
766
  return {
762
767
  ...envelope,
763
768
  events: [...envelope.events, event],
764
- projection: { ...envelope.projection, eventIds: [...envelope.projection.eventIds, id], projectedAt: input.recordedAt, trimmed: false },
769
+ projection: {
770
+ ...envelope.projection, eventIds: [...priorIds, id], projectedAt: input.recordedAt,
771
+ trimmed: new Set(priorIds).size < (0, session_events_1.selectEffectiveSessionEvents)(envelope.events).length,
772
+ },
765
773
  };
766
774
  }
767
775
  async function recordTelegramEffectsInSession(input) {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.812",
3
+ "version": "0.1.0-alpha.814",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@ouro.bot/cli",
9
- "version": "0.1.0-alpha.812",
9
+ "version": "0.1.0-alpha.814",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.78.0",
12
12
  "@azure/identity": "^4.13.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.812",
3
+ "version": "0.1.0-alpha.814",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },