picocode-core 0.9.175 → 0.9.176

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": "picocode-core",
3
- "version": "0.9.175",
3
+ "version": "0.9.176",
4
4
  "description": "The agent runtime behind pico: sessions, tools, subagents, MCP, memory, and model access",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/controller.js CHANGED
@@ -834,7 +834,11 @@ export function createController({ boot }) {
834
834
  const completed = completedToolCalls(state.derived.providerHistory)
835
835
  const unavailable = ids.filter((id) => !completed.has(id))
836
836
  if (unavailable.length) return flash(`error: tool calls are not completed in current context: ${unavailable.join(', ')}`)
837
- persist(makeEvent(type, { callIds: ids, version: TOOL_TRIM_VERSION }))
837
+ const eligible = type === 'tool_trim'
838
+ ? ids.filter((id) => state.derived.toolItems.get(id)?.contextCanTrim)
839
+ : ids.filter((id) => state.derived.toolItems.get(id)?.contextTrimmed)
840
+ if (!eligible.length) return false
841
+ persist(makeEvent(type, { callIds: eligible, version: TOOL_TRIM_VERSION }))
838
842
  ensureSession()
839
843
  reDerive()
840
844
  return true
@@ -118,15 +118,19 @@ function resultText(content) {
118
118
  return JSON.stringify(content ?? '')
119
119
  }
120
120
 
121
+ function entryTokens(args, result) {
122
+ return Math.ceil((String(args ?? '').length + resultText(result).length) / 4)
123
+ }
124
+
121
125
  export function annotateToolContext(state, effectiveHistory, trimmedIds) {
122
126
  const completed = completedToolCalls(effectiveHistory)
123
127
  for (const item of state.toolItems.values()) {
124
128
  const entry = completed.get(item.callId)
125
129
  item.contextAvailable = !!entry
126
130
  item.contextTrimmed = !!entry && trimmedIds.has(item.callId)
127
- item.contextTokens = entry
128
- ? Math.ceil((String(entry.call.function.arguments ?? '').length + resultText(entry.result.content).length) / 4)
129
- : 0
131
+ item.contextTokens = entry ? entryTokens(entry.call.function.arguments, entry.result.content) : 0
132
+ item.contextCanTrim = !!entry && !item.contextTrimmed &&
133
+ entryTokens(trimArguments(entry.call.function.arguments), trimResult(entry.result.content)) < item.contextTokens
130
134
  }
131
135
  }
132
136