@useavalon/caelence-agent 0.2.5-canary.2 → 0.2.5-canary.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/caelence-agent",
3
- "version": "0.2.5-canary.2",
3
+ "version": "0.2.5-canary.3",
4
4
  "description": "Caelence agent: Strands turn loop, local tools, skills, evals, and a themable terminal UI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -19,6 +19,7 @@ import { modePrompt } from "./mode.ts";
19
19
  import {
20
20
  compactionSummaries,
21
21
  DEFAULT_CONTEXT_WINDOW_TOKENS,
22
+ isModelContextMessage,
22
23
  replaceUserTurn,
23
24
  type Session,
24
25
  type SessionMessage,
@@ -504,11 +505,10 @@ export function buildSystemPrompt(input: {
504
505
  export function defaultSummarizer(provider: MainModelProvider): SummarizerFn {
505
506
  return async ({ messages }) => {
506
507
  const text = messages
508
+ .filter(isModelContextMessage)
507
509
  .map((m) => {
508
510
  if (m.kind === "turn") return `${m.role}: ${m.content}`;
509
511
  if (m.kind === "system") return `system: ${m.text}`;
510
- if (m.kind === "tool") return `tool ${m.name}: ${m.preview}`;
511
- if (m.kind === "thought") return `thought: ${m.text}`;
512
512
  return `summary: ${m.summary}`;
513
513
  })
514
514
  .join("\n")
@@ -67,6 +67,34 @@ describe("session store", () => {
67
67
  "user",
68
68
  "assistant",
69
69
  ]);
70
+ expect(sessionToProviderMessages(session).some((line) => line.content.includes("abc"))).toBe(
71
+ false,
72
+ );
73
+ } finally {
74
+ await rm(cwd, { recursive: true, force: true });
75
+ }
76
+ });
77
+
78
+ test("tool payloads do not count toward live model context", async () => {
79
+ const cwd = await mkdtemp(join(tmpdir(), "harness-tool-ctx-"));
80
+ try {
81
+ const store = createFileSessionStore(cwd);
82
+ let session = await store.create("system");
83
+ session = await store.append(session, { kind: "turn", role: "user", content: "hi" });
84
+ session = await store.append(session, {
85
+ kind: "tool",
86
+ name: "read_file",
87
+ callId: "c1",
88
+ status: "ok",
89
+ preview: "big.ts",
90
+ output: "x".repeat(20_000),
91
+ });
92
+ session = await store.append(session, { kind: "turn", role: "assistant", content: "ok" });
93
+ expect(liveContextTokens(session)).toBeLessThan(400);
94
+ expect(sessionToProviderMessages(session)).toEqual([
95
+ { role: "user", content: "hi" },
96
+ { role: "assistant", content: "ok" },
97
+ ]);
70
98
  } finally {
71
99
  await rm(cwd, { recursive: true, force: true });
72
100
  }
@@ -74,6 +74,15 @@ export function latestCompactionCover(session: Session): number {
74
74
  return covered;
75
75
  }
76
76
 
77
+ /** Tool rows belong on the transcript, not in the next model prompt. */
78
+ export function isModelContextMessage(
79
+ message: SessionMessage,
80
+ ): message is Extract<SessionMessage, { kind: "turn" | "system" | "compaction_checkpoint" }> {
81
+ return (
82
+ message.kind === "turn" || message.kind === "system" || message.kind === "compaction_checkpoint"
83
+ );
84
+ }
85
+
77
86
  /** Tokens the next turn would send: summaries plus uncovered turns. */
78
87
  export function liveContextTokens(session: Session): number {
79
88
  const coveredThrough = latestCompactionCover(session);
@@ -81,6 +90,7 @@ export function liveContextTokens(session: Session): number {
81
90
  for (const summary of compactionSummaries(session)) chars += summary.length;
82
91
  session.messages.forEach((message, seq) => {
83
92
  if (seq <= coveredThrough) return;
93
+ if (!isModelContextMessage(message) || message.kind === "compaction_checkpoint") return;
84
94
  chars += JSON.stringify(message).length;
85
95
  });
86
96
  return Math.floor(chars / CHARS_PER_TOKEN);
package/src/index.ts CHANGED
@@ -57,6 +57,7 @@ export {
57
57
  createFileSessionStore,
58
58
  createMemorySessionStore,
59
59
  estimateTokens,
60
+ isModelContextMessage,
60
61
  latestCompactionCover,
61
62
  liveContextTokens,
62
63
  type Session,