Commit Graph

148 Commits

Author SHA1 Message Date
Cristina Poncela Cubeiro 9e7582aa03 feat: sqlite session storage (#6594)
This PR:

- Adds retainedTail to compaction entries in the new agent harness so we don't have to walk up the tree for the 2000 tokens before compaction,
- Changes getPathToRoot to getPathToRootOrCompaction to only load until last compaction, as unnecessary to access all nodes where it is called,
- Adds a SQLite storage backend, in a separate packages/session-backend-sqlite, with a migration system and schemas as per on-site discussions: sessions to match session header messages (except for metadata, which I couldn't understand what it's used for or where it gets written, so I omitted it), session_entries for shared entry types as columns plus payload as a json for what remains, session_sequences to represent the append-only, serialized nature of the jsonl files, branch_entries to attribute nodes to branches (relationship one-to-many), and session_materialized with the session info (see /session in TUI) to act as a "cache" or quick-access for costs, message count, token info, labels, session name, and model-thinking-level config (e.g. for fast resume).
- This is compatible with the new agent harness Session abstraction.
2026-07-21 11:36:31 +02:00
Mario Zechner 1235c0ec64 fix(agent): decouple agent streams from compat
closes #6851
2026-07-20 17:54:36 +02:00
Mario Zechner f8b74a4507 fix: complete extension usage accounting
closes #6509
2026-07-20 17:06:22 +02:00
David Brailovsky 2fd3868401 add usage info to branch summary, compaction and tool result entries (#6671)
* add usage info to branch summary entries

* add usage to compaction entries

* allow custom tools to report llm usage in tool results

* allow observing and patching usage in tool_result hooks

* agent-harness: save usage in entries

for compaction, branch summaries and tool results
2026-07-20 16:41:43 +02:00
Alexey Zaytsev 94373d815d feat(ai): add shared contentText utility (#6840)
Co-authored-by: Armin Ronacher <armin.ronacher@active-4.com>
2026-07-20 01:50:36 +02:00
Alexey Zaytsev d2f8dafb0f fix(ai,agent,coding-agent): share UUIDv7 and use for Codex (#6834) 2026-07-20 01:23:47 +02:00
Armin Ronacher 3d8f74357c feat(ai): support message-anchored tool loading (#6474)
This adds cache-friendly dynamic tool loading anchored to tool results. Purely additive active-tool changes are recorded with `addedToolNames`, allowing supported Anthropic and OpenAI Responses models to load tool definitions at the point they become available instead of placing them in the cached prompt prefix.

It retains safe fallback behavior for unsupported models and non-additive changes but it will wipe caches.
2026-07-10 23:52:54 +02:00
Mario Zechner fbdd46389c feat(ai): add max thinking level 2026-07-09 22:30:53 +02:00
Mario Zechner cb222bf99d feat(agent): export InMemorySessionStorage and JsonlSessionStorage
Export both session storage implementations from @earendil-works/pi-agent-core
so they can be imported and extended directly instead of via repo workaround.

closes #6435
2026-07-09 10:22:30 +02:00
Mario Zechner dd1c690f36 fix(agent): add session context entry projection 2026-07-08 14:59:16 +02:00
ArcadiaLin 7198e78f99 feat(agent): support custom metadata in jsonl session headers (#6417)
Allow callers to attach an opaque JSON object to the session header so
application context needed to rebuild a harness (for example an agent
profile reference) is readable from the first line alone, without
scanning session entries. The field is optional and ignored by readers
that do not use it; fork inherits the source metadata unless overridden.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 11:18:43 +02:00
Armin Ronacher 351efc828b fix(agent): fail tool calls from length-truncated assistant messages (#6285)
* fix(ai,agent): stop salvaging malformed tool-call argument JSON

Finalized tool-call arguments must strict-parse (allowing only lossless
string-escape repair). When the streamed JSON is truncated or malformed,
the raw JSON is preserved on ToolCall.malformedArguments, arguments
become {}, and the agent loop refuses to execute the call with an error
tool result instead of running it with silently salvaged partial
arguments. Partial parsing is now only used for streaming previews.

* fix(agent): fail tool calls from length-truncated assistant messages

Reverts the malformed-arguments tracking approach in favor of handling
truncation in the agent loop: when an assistant message stops with
"length", all tool calls in it are potentially borked (streamed
arguments are salvage-parsed), so none are executed. Each gets an error
tool result telling the model to re-issue the call, and the loop
continues. No new fields on ToolCall and no provider changes.

fixes #6284
2026-07-07 14:30:31 +02:00
Armin Ronacher 8c0ccd14b3 fix(ai,agent,coding-agent): normalize null message content at ingestion boundaries (#6343)
The Message types require content to always be present, but untyped JS
extension tools, hand-built histories, and old or hand-edited session
files can violate that contract, crashing rendering, compaction, and
provider request conversion with 'content is not iterable'.

Normalize null/missing content to an empty array at the ingestion
boundaries instead of guarding every consumer:

- transformMessages (choke point before every provider request)
- createToolResultMessage in the agent loop
- session entry loading (message and custom_message entries)
- extension custom messages (sendCustomMessage, before_agent_start)
- message_end extension replacements

fixes #6259, fixes #6276
2026-07-06 20:47:08 +02:00
Armin Ronacher 1dac099022 fix(agent): derive short session entry ids from the uuidv7 random tail (closes #6242)
The uuidv7 prefix is timestamp-derived and nearly constant between calls, so slicing the first 8 chars degenerated short ids to full-UUID fallbacks. Regression from 80c918c2 which replaced randomUUID with uuidv7.
2026-07-05 23:35:53 +02:00
Armin Ronacher 035ea9c856 fix: remove redundant record guards 2026-07-05 18:55:09 +02:00
Vegard Stikbakke f58c115626 fix(coding-agent): serialize split-turn compaction summaries
closes #5536
2026-07-01 15:37:00 +02:00
Vegard Stikbakke 85b7c24741 fix(coding-agent): reject non-positive bash timeouts 2026-07-01 09:03:00 +02:00
Vegard Stikbakke cbcf4e04c3 fix(coding-agent): reject oversized bash timeouts
closes #6181
2026-07-01 08:49:31 +02:00
Mario Zechner fd6659dd5d fix(coding-agent): preserve run prompt during tool refresh
closes #6162
2026-06-30 14:08:48 +02:00
Mat e547bb9f41 fix(coding-agent): refresh session state before next turn 2026-06-30 13:56:04 +02:00
Mario Zechner b377623435 Type name change 2026-06-23 22:00:03 +02:00
Mario Zechner cd95c2749f fix(ai): require OpenAI Responses terminal events 2026-06-23 16:35:45 +02:00
Mario Zechner 7fedc3324e Merge pull request #5999 from haoqixu/fix-5996
fix(coding-agent): normalize session names
2026-06-23 15:15:52 +02:00
haoqixu e8ede14f5d fix(agent): normalize session names 2026-06-23 19:36:13 +08:00
Mario Zechner abbd911693 Merge main into model-registry 2026-06-22 14:00:18 +02:00
Mario Zechner 717a8f958a fix(ai): revert selective pi-ai base entrypoints 2026-06-22 12:54:32 +02:00
Vegard Stikbakke 1287b69fe0 fix(coding-agent): run legacy WSL bash commands via stdin
closes #5893
2026-06-19 15:08:25 +02:00
Fred K. Schott 0d89a33373 feat(packages): Add selective pi-ai base entrypoints (#5348) 2026-06-19 00:41:49 +02:00
Armin Ronacher daab056ac1 fix(agent): ignore late tool progress updates
closes #5573
2026-06-12 18:59:32 +02:00
Mario Zechner 9ab1292679 feat(agent): Models is the harness's only auth path
Remove AgentHarnessOptions.getApiKeyAndHeaders: turn streaming,
compaction, and branch summarization resolve auth exclusively through
the injected Models instance. compact()/generateSummary()/
generateBranchSummary() lose their explicit apiKey/headers parameters.
2026-06-10 21:39:13 +02:00
Mario Zechner f0ccbbf011 feat(agent): AgentHarness streams through a required Models instance (phase 6)
AgentHarnessOptions.models is required; the harness stream path,
compaction, and branch summarization go through models.streamSimple()/
completeSimple() instead of the compat globals. getApiKeyAndHeaders
stays and wins per-field over provider-resolved auth, but is no longer
required: without it, requests resolve through provider auth.

compact()/generateSummary()/generateBranchSummary() take a Models
parameter; explicit apiKey becomes optional. StreamFn is redefined
structurally (Models.streamSimple satisfies it), dropping the compat
type dependency from agent types.

Harness tests build per-file Models collections with fauxProvider()
and unique provider ids instead of mutating the global api-registry.
2026-06-10 21:27:21 +02:00
Mario Zechner 8a0903ebf2 feat(ai): compat entrypoint, core-only root barrel (phase 5)
The root barrel is now core-only and side-effect free: types,
createModels/createProvider, auth substrate, lazyStream/lazyApi, faux,
utils. Generated catalogs, api-registry, env-api-keys, images, global
stream functions, and per-API lazy wrappers leave the root.

New @earendil-works/pi-ai/compat preserves the old surface verbatim as
a strict superset of the root: api-dispatch stream/complete with env
key injection, the builtin registration side effect (skip-if-present so
it cannot clobber earlier overrides), deprecated getModel/getModels/
getProviders aliases of the new getBuiltin* reads in providers/all,
lazy api wrappers + setBedrockProviderModule, and image generation.
Compat dies with the coding-agent ModelManager migration.

Packaging: exports map gains ./compat, ./providers/*, ./api/*;
sideEffects array lists only the effectful modules.

Old-global imports across agent/coding-agent/examples and pi-ai tests
switch to /compat (path-only; compat is a superset). The coding-agent
extension loader resolves the pi-ai ROOT specifier to compat, so
existing user extensions using the old global API keep working at
runtime until compat is removed. vitest configs alias /compat to src;
browser smoke imports old globals from /compat.
2026-06-10 21:17:12 +02:00
Mario Zechner 8c6c8a4ef3 fix(agent): neutralize compaction summarization prompt
closes #5401
2026-06-07 11:19:10 +02:00
Mario Zechner b63d26332f Finish harness tool registry semantics 2026-05-28 12:34:02 +02:00
Mario Zechner 96f0edd02b Count user image tokens in context estimates
closes #4983
2026-05-26 18:46:54 +02:00
Armin Ronacher ae9450dc51 chore(ts): use source import extensions 2026-05-20 00:04:03 +02:00
Mario Zechner 06c6c324d7 chore: enforce erasable TypeScript syntax 2026-05-19 23:15:39 +02:00
Mario Zechner b944827623 fix(agent): stop tool preflight after extension abort
closes #4276
2026-05-19 13:10:03 +02:00
Armin Ronacher 29b3417a7a fix(windows): hide bash helper consoles
closes #4699
2026-05-18 23:21:22 +02:00
Mario Zechner b1893b3d77 fix(agent): preserve oversized tail output with trailing newline
closes #4715
2026-05-18 23:05:34 +02:00
Mario Zechner 4f40f62b7b refactor(agent): harden harness session semantics 2026-05-16 00:32:16 +02:00
Mario Zechner 80c918c247 refactor(agent): isolate node filesystem session dependencies 2026-05-15 00:53:33 +02:00
Mario Zechner a31ce0f47f refactor(agent): return results from compaction helpers 2026-05-14 21:56:45 +02:00
Mario Zechner b7ea82105a refactor(agent): run harness loop directly 2026-05-14 21:33:34 +02:00
Mario Zechner 846906e4d1 refactor(agent): add result-based execution env 2026-05-14 18:26:29 +02:00
Armin Ronacher c00f1cf130 fix(agent): correct uuidv7 sequence handling 2026-05-13 15:53:53 +02:00
Armin Ronacher 2829146dde chore(deps): Kill small dependencies (#4467) 2026-05-13 10:44:56 +02:00
Armin Ronacher 3d9e14d748 fix(compaction): clamp summary output tokens
Fixes #4390.
2026-05-11 16:36:27 +02:00
Mario Zechner c0f416aabc feat(agent): add harness stream configuration 2026-05-10 18:13:16 +02:00
Mario Zechner e25415dd5f refactor(agent): finalize harness resource config 2026-05-10 00:49:00 +02:00