@yanzc/claude-pro 0.5.4 → 0.5.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/agent.js +15 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanzc/claude-pro",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "claude-pro: a self-implemented coding agent for Anthropic-compatible APIs or local Claude Code subscription login. Full access with no permission prompts; file edits are checkpointed and can be rewound.",
5
5
  "type": "module",
6
6
  "repository": {
package/src/agent.js CHANGED
@@ -7,7 +7,7 @@ import { streamMessage, contextTokens, isAbort } from './api.js';
7
7
  import { compactPrompt, partialCompactPrompt, partialSummaryMessage, continuationMessage, PLAN_MODE_REMINDER, SUMMARY_SYSTEM } from './prompts.js';
8
8
  import { toolResultsDir } from './session.js';
9
9
  import { rebuildFileState } from './filestate.js';
10
- import { CacheStats } from './cache.js';
10
+ import { CacheStats, TTL_MS } from './cache.js';
11
11
  import { resolvePath } from './utils/paths.js';
12
12
  import { fitImagesIn } from './utils/images.js';
13
13
 
@@ -359,6 +359,14 @@ export class Agent {
359
359
  return out;
360
360
  }
361
361
 
362
+ // Is the conversation's prompt cache known to have run out? From the last request of this process when there was
363
+ // one, else (a resumed or restarted conversation) from when the last message was added, which is after its
364
+ // request started: that guess errs towards warm. Not knowing counts as warm.
365
+ cacheExpired(now = Date.now()) {
366
+ if (this.cache.expected != null) return now >= this.cache.expiresAt;
367
+ return this.lastActivityAt > 0 && now - this.lastActivityAt >= TTL_MS[this.config.cacheTtl('main')];
368
+ }
369
+
362
370
  // A new request from the user goes back to the effort the user chose, after the Effort tool changed it for
363
371
  // the one before. A request that a restart continues keeps it.
364
372
  endEffortBoost() {
@@ -728,8 +736,12 @@ export class Agent {
728
736
  // the biggest request there is). Only if that does not give a summary (the model went on calling tools, or
729
737
  // the request is too long by the size of the instruction) the plainer request is made: a short system prompt
730
738
  // and no effort, which cannot share the cache, but is smaller and cannot be led astray by the main prompt.
739
+ // The messages are marked for the cache only where that can be read: no request after the summary starts with
740
+ // this history, so writing it (25% over the plain input price) pays only for reading what is already there.
741
+ // When the cache is known to have run out, and in the plain request, only the tools and system prompt are marked.
731
742
  async requestSummary(messages, { signal, onEvent }) {
732
- const call = (request) => streamMessage(this.config, { model: this.model, tools: this.toolSchemas(), messages, cacheBucket: 'other', ...(this.effort ? { effort: this.effort } : {}), ...request }, { signal, onEvent });
743
+ const cacheMessages = !this.cacheExpired();
744
+ const call = (request) => streamMessage(this.config, { model: this.model, tools: this.toolSchemas(), messages, cacheBucket: 'other', cacheMessages, ...(this.effort ? { effort: this.effort } : {}), ...request }, { signal, onEvent });
733
745
  try {
734
746
  const res = await call({ system: this.currentSystem() });
735
747
  this.recordUsage(res, 'summary');
@@ -737,7 +749,7 @@ export class Agent {
737
749
  } catch (err) {
738
750
  if (isAbort(err) || signal?.aborted || !err.promptTooLong) throw err;
739
751
  }
740
- const res = await call({ system: SUMMARY_SYSTEM, effort: null });
752
+ const res = await call({ system: SUMMARY_SYSTEM, effort: null, cacheMessages: false });
741
753
  this.recordUsage({ ...res, cache: { ...res.cache, caching: false } }, 'summary'); // made to miss: not a miss to report
742
754
  return res;
743
755
  }