@genesislcap/ai-assistant 15.99.0 → 15.99.2-GENC-1962.2

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.
@@ -5200,7 +5200,7 @@ var DEBUG_LOG_README = [
5200
5200
  "Timestamps are millisecond-resolution; entries that share the same millisecond are ordered by a fixed kind rank (event, then turn, then message), which is a heuristic and may not reflect exact causal order within that millisecond \u2014 e.g. a user message and the turn it triggered, or a final assistant message and its turn.end event, can appear in either order depending on whether they landed in the same millisecond. Read the logical structure of a turn rather than over-interpreting the micro-ordering of co-timestamped entries of different kinds.",
5201
5201
  "kind:'message' \u2014 the conversation. `role` is user/assistant/tool/system-event/synthetic-user; `agentName` says which agent produced it; `toolCalls`/`toolResult`/`interaction` carry tool and widget activity; `inputTokens`/`outputTokens`/`cost` are per-message LLM usage, where `inputTokens` is the WHOLE prompt for that request and `cacheReadTokens`/`cacheWriteTokens` BREAK IT DOWN rather than add to it \u2014 uncached input is `inputTokens` minus those two, and adding the cache fields to `inputTokens` counts the prompt twice. The cache fields are absent on providers that report no cache split (Gemini reports reads only, since implicit caching bills no write) and on messages persisted before they existed, so read them as 0 when missing. Each bucket bills at a different rate \u2014 cache reads a fraction of uncached input, cache writes a premium, output highest \u2014 so a large token count at a small cost means the prompt was mostly cache hits. `externalCostUsd` is any non-LLM cost a widget reported for its own external service calls (folded into the session cost total alongside `cost`). On model-produced assistant messages, `model` is the concrete model id that generated it (e.g. 'gemini-2.5-flash-lite') and `providerName` is the registry slot it resolved under (e.g. a tier name like 'high'/'low', or the default); together they attribute the message \u2014 and any tool calls it carries \u2014 to an exact model even across a mid-session vendor/tier switch, where one slot name can map to different models before and after the switch. Both are undefined on any entry that is NOT an LLM response: non-assistant roles (user/tool/system-event) and 'synthetic-user' echoes; assistant interaction/widget entries (empty content carrying an `interaction` \u2014 a rendered widget, not a model turn); driver-authored assistant fallbacks (the timeout, repeated-malformed-call, and empty-response apology messages); and messages restored from a session persisted before these fields existed. One partial case: on a genuine model turn whose provider exposes no `getStatus` (or reports no model), `providerName` is still set but `model` alone is undefined. A 'synthetic-user' message is a display-only echo of an interaction outcome (e.g. the answer a widget reported): it renders on the user's side of the chat and `agentName` is the agent that created it, but it is never sent to the LLM \u2014 so it has no matching 'turn' and the model learns the outcome only from the corresponding tool result. An echo of an answer an interceptor (such as an autopilot) gave is NOT synthetic-user: see the delegated-messages paragraph.",
5202
5202
  "The autopilot (GENC-1660) runs on a driver of its own, and everything it did is harvested into this log: entries with delegate: autopilot and an agentName ending in \u203A Autopilot are its turns (the decision message it was sent is the user message of its turn, so what it was shown is there verbatim; its systemPrompt is its grounding, such as the brief), its tool calls (widget_read, widget_act, hand_back, any read-only tools of its own, and its widget tools \u2014 reads with parameters that a widget type declares, routed to the interaction of that type being decided and refused with a reason when none is, offered on every decision so its tool list never changes; while one is open its tail starts with a line naming them) and their results (a read, view or widget tool, is capped at about 20,000 characters, cut with a note asking for less, and leaves its history at the end of the decision as a one-line note), and its own events. Its cost is already in the session total: it is booked as externalCostUsd on the interaction each decision answered, or, for a written question it answered, on the user message it sent on the user behalf (delegate: autopilot), so do not add its turns to that total. Spend that reached no message is recorded as autopilot.cost-dropped instead.",
5203
- "Delegated messages (GENC-1660): a message with a `delegate` field was written or sent ON THE USER'S BEHALF by a driver decorator, and `delegate` names it (e.g. autopilot). The platform stamps it; nothing else can. It renders as the assistant whatever its role. A delegated `user` message was NOT typed by the user: it is an answer given on their behalf, and the model read it with `delegateFraming` in brackets in front of the content (the stored `content` is the bare text). A delegated `assistant` message is display-only (`excludeFromProvider`): the decorator's narration note, or, when its answer carried no note, the widget's own echo of the answer (its `userMessage`), shown as the assistant and never as the person. A widget answer a decorator gave with a note is not echoed at all: the note already says what was chosen. To tell what the person decided from what was decided for them, read `interaction.answeredBy` and these fields, never the role alone. Driver notes: a `user` message with a `driverNote` field was written by the driver for the model, never by the user, and is hidden from the transcript; `driverNote: 'finish-guard'` is the agent's finishGuard holding the turn open after a prose reply, its content the guard's note in a `<system-reminder>`, and it follows a turn.finish-guard event; `driverNote: 'completion-nudge'` is the driver asking a sub-agent that replied in prose to call its completion tool; `driverNote: 'forced-tool-nudge'` is the driver asking a parent agent for the tool call its forced turn required, after a model that rejects forcing (responseMeta.toolChoiceDowngraded) replied in prose.",
5203
+ "Delegated messages (GENC-1660): a message with a `delegate` field was written or sent ON THE USER'S BEHALF by a driver decorator, and `delegate` names it (e.g. autopilot). The platform stamps it; nothing else can. It renders as the assistant whatever its role. A delegated `user` message was NOT typed by the user: it is an answer given on their behalf, and the model read it with `delegateFraming` in brackets in front of the content (the stored `content` is the bare text). A delegated `assistant` message is display-only (`excludeFromProvider`): the decorator's narration note, or, when its answer carried no note, the widget's own echo of the answer (its `userMessage`), shown as the assistant and never as the person. A widget answer a decorator gave with a note is not echoed at all: the note already says what was chosen. To tell what the person decided from what was decided for them, read `interaction.answeredBy` and these fields, never the role alone. Driver notes: a `user` message with a `driverNote` field was written by the driver for the model, never by the user, and is hidden from the transcript; `driverNote: 'finish-guard'` is the agent's finishGuard holding the turn open after a prose reply, its content the guard's note in a `<system-reminder>`, and it follows a turn.finish-guard event; `driverNote: 'completion-nudge'` is the driver asking a sub-agent that replied in prose to call its completion tool; `driverNote: 'forced-tool-nudge'` is the driver asking a parent agent for the tool call its forced turn required, after a model that rejects forcing (responseMeta.toolChoiceDowngraded) replied in prose. `driverNote: 'agent-context'` is an agent's tail context stored in history rather than sent as a volatile tail (the agent set tailContextMode: 'stored'): written only when it changes, so the latest one before a call is what that call's context was, and it is sent only to the agent named in its agentName.",
5204
5204
  "Sub-agent messages appear inline. When a tool delegates to a sub-agent (via `requestSubAgent`), the sub-agent's whole conversation \u2014 its own assistant/tool messages, each with their own `content`/`thinking`/`toolCalls`/`toolResult` and per-message `model`/`providerName`/`inputTokens`/`outputTokens`/`cacheReadTokens`/`cacheWriteTokens`/`cost` \u2014 is hoisted into the timeline as ordinary kind:'message' entries, interleaved by timestamp right after the tool call that spawned them (so you read the delegation top-to-bottom). A hoisted entry is marked: `subAgentDepth` is its delegation depth (1 for a sub-agent, 2 for a sub-agent's sub-agent, \u2026), `subAgentOf` is the id of the parent tool call that spawned it (correlates it back even when two sub-agents run in one parent turn), `subAgentName` is the sub-agent's own name, and `agentName` is rewritten to a `\"<parent> \u203A <sub-agent>\"` breadcrumb (composing when nested, e.g. `\"UI Builder \u203A Planner \u203A Grounding\"`). The sub-agent's per-LLM-call snapshots also surface as kind:'turn' entries with an N-M `turnIndex`, and subagent.started/completed (or subagent.failed) events bracket the run. Per-message `cost` on hoisted entries is already part of the session total (it is summed from the un-flattened history), so summing the top-level timeline does NOT double-count.",
5205
5205
  "kind:'turn' \u2014 one LLM call. `turnIndex` is a string: a top-level turn is the bare counter ('0', '1', \u2026); a sub-agent's turns are numbered under the parent turn that activated them ('3-1', '3-2', \u2026, and a nested sub-agent contributes '3-2-1', \u2026), and `agentName` names the agent that ran the turn. `systemPrompt` and `toolNames` are what the model saw. A systemPrompt of '<repeated \u2014 identical to turn N>' was byte-identical to turn N and de-duplicated; the full prompt is shown whenever it changes (often because a stateful agent advanced), so prompt evolution is visible.",
5206
5206
  "kind:'turn'.`model`/`providerName`/`provider` \u2014 which model ran that call: the concrete model id, the registry slot it resolved under (a tier name like 'high'/'low', or the default), and the vendor. Recorded per CALL, so an agent whose `provider` selector varies by state \u2014 a flow that plans on a high tier and executes on a low one \u2014 has every step attributed, including calls that produced no message. `model` is the SERVING model where the provider reports one, so a turn answered by a server-side fallback names the model that answered rather than the one requested; it always matches the `model` on the message that call produced. Absent when the provider exposes no `getStatus` and the transport stamped nothing.",
@@ -5246,6 +5246,15 @@ ${note.trim()}
5246
5246
  driverNote: kind
5247
5247
  };
5248
5248
  }
5249
+ var AGENT_CONTEXT_PREAMBLE = "The current state, as of this point in the conversation. It replaces any earlier note like this one: where they differ, this one is right.";
5250
+ var NO_CONTEXT = "There is nothing to note at the moment.";
5251
+ function agentContextNote(body) {
5252
+ return `<system-reminder>
5253
+ ${AGENT_CONTEXT_PREAMBLE}
5254
+
5255
+ ${body.trim() || NO_CONTEXT}
5256
+ </system-reminder>`;
5257
+ }
5249
5258
 
5250
5259
  // src/utils/preserved-user-messages.ts
5251
5260
  function freshUserMessages(toCompact) {
@@ -8357,6 +8366,8 @@ var ChatDriver = class _ChatDriver extends EventTarget {
8357
8366
  this.messageController = new AbortController();
8358
8367
  /** Capabilities provided on this driver by decorators (GENC-1660). Only the root's are used. */
8359
8368
  this.handlerCapabilities = /* @__PURE__ */ new Map();
8369
+ /** Whether the active agent's tail context is stored in history (`tailContextMode: 'stored'`). */
8370
+ this.activeTailContextStored = false;
8360
8371
  /**
8361
8372
  * Caches validated provider lookups per name within the current agent. Cleared
8362
8373
  * by `installAgent` so each new agent's static/function-resolved names are
@@ -9028,6 +9039,7 @@ var ChatDriver = class _ChatDriver extends EventTarget {
9028
9039
  this.activeCachePolicyInput = config.cachePolicy;
9029
9040
  this.activeThinkingPolicyInput = config.thinkingPolicy;
9030
9041
  this.activeTailContextInput = config.tailContext;
9042
+ this.activeTailContextStored = config.tailContextMode === "stored";
9031
9043
  this.activeResponseSchemaInput = config.responseSchema;
9032
9044
  this.activeFallbacks = config.fallbacks;
9033
9045
  this.activeOnUnresolvedTool = config.onUnresolvedTool;
@@ -10452,11 +10464,17 @@ ${tailNote}` : "";
10452
10464
 
10453
10465
  ${closing}` : "";
10454
10466
  const frameworkSystemSuffix = `${foldSuffix}${firstCallNote}${closingNote}${retryNudge}`;
10455
- const primer = normalizeForProvider([
10456
- ...this.primerHistory ?? [],
10457
- ...transientPrimer ?? []
10458
- ]);
10459
- const baseHistory = firstLlmCall ? this.history.slice(0, -1) : this.history;
10467
+ if (this.activeTailContextStored) {
10468
+ const storedTail = await resolveTurnInput(this.activeTailContextInput, promptCtx);
10469
+ this.storeAgentContext(storedTail, firstLlmCall);
10470
+ }
10471
+ const ownContext = (m) => m.driverNote !== "agent-context" || m.agentName === this.activeAgentName;
10472
+ const primer = normalizeForProvider(
10473
+ [...this.primerHistory ?? [], ...transientPrimer ?? []].filter(ownContext)
10474
+ );
10475
+ const baseHistory = (firstLlmCall ? this.history.slice(0, -1) : this.history).filter(
10476
+ ownContext
10477
+ );
10460
10478
  firstLlmCall = false;
10461
10479
  const suspended = this.suspendedClocks();
10462
10480
  const condensedHistory = applyCondensation(
@@ -10492,7 +10510,8 @@ ${closing}` : "";
10492
10510
  resolveTurnInput(this.activeTemperatureInput, promptCtx),
10493
10511
  resolveTurnInput(this.activeToolChoiceInput, promptCtx),
10494
10512
  resolveTurnInput(this.activeCachePolicyInput, promptCtx),
10495
- resolveTurnInput(this.activeTailContextInput, promptCtx),
10513
+ // A stored tail was resolved and written into history above; only a volatile one is sent.
10514
+ this.activeTailContextStored ? Promise.resolve(void 0) : resolveTurnInput(this.activeTailContextInput, promptCtx),
10496
10515
  resolveTurnInput(this.activeResponseSchemaInput, promptCtx),
10497
10516
  // Only consulted on the first iteration (see `pinnedThinkingPolicy`); resolved
10498
10517
  // alongside the others so a resolver still sees the same turn context.
@@ -11200,7 +11219,12 @@ RECOVERY: this tool failed once \u2014 you may retry it, or take a different val
11200
11219
  this.appendToHistory({ role: "assistant", content, excludeFromProvider: true });
11201
11220
  }
11202
11221
  appendToHistory(message) {
11203
- const tagged = {
11222
+ this.history = [...this.history, this.tagMessage(message)];
11223
+ this.notifyHistoryUpdated();
11224
+ }
11225
+ /** Stamp a message for history: its timestamp (unless it has one) and the active agent. */
11226
+ tagMessage(message) {
11227
+ return {
11204
11228
  ...message,
11205
11229
  // Stamp on first append; preserve any caller-supplied timestamp.
11206
11230
  timestamp: message.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
@@ -11210,7 +11234,24 @@ RECOVERY: this tool failed once \u2014 you may retry it, or take a different val
11210
11234
  agentLabel: this.activeAgentLabel
11211
11235
  } : {}
11212
11236
  };
11213
- this.history = [...this.history, tagged];
11237
+ }
11238
+ /**
11239
+ * Write the active agent's tail context into history as a hidden note (`tailContextMode:
11240
+ * 'stored'`, GENC-1962), unless it is the same as the last one this agent stored. A tail that
11241
+ * resolves to nothing after there was one stores a note saying so, or the old one would still
11242
+ * read as current. `beforePendingUser`: the turn's first call, which sends the newest message (the
11243
+ * user's) separately, so the note goes in ahead of it. Either way the history only grows where
11244
+ * the next request already ends, which is what keeps earlier thinking replayable.
11245
+ */
11246
+ storeAgentContext(tail, beforePendingUser) {
11247
+ const body = (tail ?? "").trim();
11248
+ const previous = [...this.history].reverse().find((m) => m.driverNote === "agent-context" && m.agentName === this.activeAgentName);
11249
+ if (!body && !previous) return;
11250
+ const content = agentContextNote(body);
11251
+ if (previous?.content === content) return;
11252
+ const note = this.tagMessage({ role: "user", content, driverNote: "agent-context" });
11253
+ const at = beforePendingUser && this.history.length > 0 ? this.history.length - 1 : this.history.length;
11254
+ this.history = [...this.history.slice(0, at), note, ...this.history.slice(at)];
11214
11255
  this.notifyHistoryUpdated();
11215
11256
  }
11216
11257
  /** Announce the current history to the host. */
@@ -12504,6 +12545,18 @@ function bindStateOrDefault(hook, getState) {
12504
12545
  return hook({ ...ctx, state });
12505
12546
  };
12506
12547
  }
12548
+ function forwardedOptions(opts) {
12549
+ return {
12550
+ primerHistory: opts.primerHistory,
12551
+ subAgents: opts.subAgents,
12552
+ manualSelection: opts.manualSelection,
12553
+ chatInputDuringExecution: opts.chatInputDuringExecution,
12554
+ tailContextMode: opts.tailContextMode,
12555
+ notResumableMessage: opts.notResumableMessage,
12556
+ resumeOnRestore: opts.resumeOnRestore,
12557
+ contextReserve: opts.contextReserve
12558
+ };
12559
+ }
12507
12560
  function defineStatefulAgent(opts) {
12508
12561
  let state;
12509
12562
  const assertNoFolds = (handlers) => {
@@ -12605,10 +12658,7 @@ function defineStatefulAgent(opts) {
12605
12658
  const base = {
12606
12659
  name: opts.name,
12607
12660
  displayName: wrappedDisplayName,
12608
- primerHistory: opts.primerHistory,
12609
- subAgents: opts.subAgents,
12610
- manualSelection: opts.manualSelection,
12611
- chatInputDuringExecution: opts.chatInputDuringExecution,
12661
+ ...forwardedOptions(opts),
12612
12662
  toolDefinitions: wrappedTools,
12613
12663
  toolHandlers: wrappedHandlers,
12614
12664
  provider: wrappedProvider,
@@ -12620,9 +12670,6 @@ function defineStatefulAgent(opts) {
12620
12670
  onUnresolvedTool: wrappedOnUnresolvedTool,
12621
12671
  finishGuard: wrappedFinishGuard,
12622
12672
  resumable: wrappedResumable,
12623
- notResumableMessage: opts.notResumableMessage,
12624
- resumeOnRestore: opts.resumeOnRestore,
12625
- contextReserve: opts.contextReserve,
12626
12673
  // Bound to the live state, so the autopilot's resolvers see what this agent's do (GENC-1660).
12627
12674
  ...opts.autopilot && {
12628
12675
  autopilot: {