@ponythewhite/base-context 1.0.6 → 1.0.7

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.
@@ -592,7 +592,9 @@ export class AgentSession {
592
592
  try {
593
593
  const messages = await captured.readHistory(async (view) => {
594
594
  const sameSource = controls?.sessionId === view.source.sessionId && controls?.sessionFile === view.source.sessionFile;
595
- const result = await this._contextCompiler.compile(view, limits, sameSource ? omitted : undefined, {}, resource, this._initialContextMode, contextEpochsEnabled);
595
+ const result = await this._contextCompiler.compile(view, limits, sameSource ? omitted : undefined, {}, resource, this._initialContextMode,
596
+ // This MAIN owner binds public admission below, independently of optional token budgets.
597
+ true);
596
598
  if (sameSource && this._contextOmissions === controls) {
597
599
  // Only prune this captured set. A newer control or source switch must survive this read.
598
600
  for (const id of omitted)
@@ -608,7 +610,8 @@ export class AgentSession {
608
610
  const epochContext = getCanonicalEpochContext(messages);
609
611
  if (epochContext)
610
612
  this._contextMode = epochContext.mode;
611
- const nativeSkills = Boolean(contextEpochsEnabled || epochContext?.checkpoint);
613
+ const unbudgetedPublic = !contextEpochsEnabled && Boolean(epochContext?.toolContinuations?.length);
614
+ const nativeSkills = Boolean(contextEpochsEnabled || epochContext?.checkpoint || unbudgetedPublic);
612
615
  const skillPolicy = nativeSkills ? (this._nativeRecoveryEnabled() ? "enabled" : "unavailable") : undefined;
613
616
  if (this._baseSystemPromptOptions.nativeSkillSelection !== skillPolicy) {
614
617
  const previousBase = this._baseSystemPrompt;
@@ -618,14 +621,16 @@ export class AgentSession {
618
621
  if (epochContext?.resourceRevision !== undefined &&
619
622
  getCanonicalViewUnits(messages)?.length !== messages.length)
620
623
  throw new Error("Current resource view requires tracked canonical context");
621
- if (epochContext?.checkpoint && getCanonicalViewUnits(messages)?.length !== messages.length)
624
+ if ((epochContext?.checkpoint || unbudgetedPublic) &&
625
+ getCanonicalViewUnits(messages)?.length !== messages.length)
622
626
  throw new Error("Committed context epoch cannot admit untracked transient messages");
623
627
  if (epochContext &&
624
- (contextEpochsEnabled || epochContext.checkpoint) &&
628
+ (contextEpochsEnabled || epochContext.checkpoint || unbudgetedPublic) &&
625
629
  getCanonicalViewUnits(messages)?.length === messages.length) {
626
630
  let committed = epochContext.checkpoint;
627
631
  let committedEntry = epochContext.checkpointEntry;
628
- const fixed = epochContext.mode === "off" || (committed?.policyOnly === true && !contextEpochsEnabled);
632
+ const fixed = epochContext.mode === "off" ||
633
+ (committed?.policyOnly === true && !contextEpochsEnabled && !unbudgetedPublic);
629
634
  let requestContract = fixed ? retainedContextRequestContract(committed) : undefined;
630
635
  const nativeTail = messages.some((message) => message.role === "toolResult" ||
631
636
  (message.role === "assistant" &&
@@ -651,7 +656,7 @@ export class AgentSession {
651
656
  candidate.projection.pendingPublicMessageGroups?.length))
652
657
  throw new Error("Tool continuation requires its exact public candidate before epoch ACK");
653
658
  assertResourceCurrent(resource);
654
- const representation = contextEpochRepresentation(candidate.request, candidate.assessment, limits.maxSourceBytes);
659
+ const representation = contextEpochRepresentation(candidate.request, candidate.assessment, limits.maxSourceBytes, unbudgetedPublic);
655
660
  const replayContract = "replayContract" in candidate.projection &&
656
661
  candidate.projection.replayContract === "message-groups"
657
662
  ? "message-groups"
@@ -691,7 +696,7 @@ export class AgentSession {
691
696
  const prepared = prepareCanonicalEpoch(candidate.publicMessages ?? messages, candidate.selectedUnitIds, representation, limits.maxSourceBytes, replayContract, publicWindow);
692
697
  if (JSON.stringify(prepared.checkpoint.source) !== JSON.stringify(candidate.source))
693
698
  throw new Error("Context epoch candidate does not match its captured source");
694
- const tokensBefore = candidate.originalAssessment.estimatedInputTokens;
699
+ const tokensBefore = candidate.originalAssessment?.estimatedInputTokens ?? null;
695
700
  const result = {
696
701
  summary: "",
697
702
  firstKeptEntryId: prepared.checkpoint.literalTailId,
@@ -737,7 +742,7 @@ export class AgentSession {
737
742
  return;
738
743
  if (acceptedBody === undefined || request.body !== acceptedBody)
739
744
  throw new Error("Committed context epoch requires a compatible final provider projection");
740
- if (contextEpochRepresentation(request, assessment, limits.maxSourceBytes) !==
745
+ if (contextEpochRepresentation(request, assessment, limits.maxSourceBytes, unbudgetedPublic) !==
741
746
  committed.representation)
742
747
  throw new Error("Context epoch representation changed without a committed boundary");
743
748
  if (committed.resourceRevision !== epochContext.resourceRevision)
@@ -7816,7 +7821,7 @@ export class AgentSession {
7816
7821
  try {
7817
7822
  this._assertCompactionOwner(owner);
7818
7823
  const bootstrap = await readSessionBootstrap(owner.manager, this.settingsManager.getCanonicalContextLimits(), {
7819
- allowPendingToolPublic: this._contextEpochsEnabled,
7824
+ purpose: "read",
7820
7825
  initialContextMode: this._initialContextMode,
7821
7826
  });
7822
7827
  this._assertCompactionOwner(owner);
@@ -11977,7 +11982,7 @@ export class AgentSession {
11977
11982
  if (label && !summaryText) {
11978
11983
  await this.sessionManager.appendLabelChange(targetId, label);
11979
11984
  }
11980
- const { context: sessionContext } = await readSessionBootstrap(this.sessionManager, this.settingsManager.getCanonicalContextLimits(), { allowPendingToolPublic: this._contextEpochsEnabled, initialContextMode: this._initialContextMode });
11985
+ const { context: sessionContext } = await readSessionBootstrap(this.sessionManager, this.settingsManager.getCanonicalContextLimits(), { purpose: "read", initialContextMode: this._initialContextMode });
11981
11986
  this.agent.state.messages = sessionContext.messages;
11982
11987
  this._contextOmissions = undefined;
11983
11988
  this._mergeUnpersistedOutcomes(this.agent.state.messages);