Commit Graph

1605 Commits

Author SHA1 Message Date
can1357 37d4314f2d chore(config): organized publish type mapping from src to dist/types
- Added declaration-only compiler options to multiple package publish tsconfig files.
- Standardized publish include/exclude settings to emit types from src into dist/types.
- Added manifest rewrite helpers to remap type paths from ./src to ./dist/types/*.d.ts.
- Updated publish flow to append dist/types/extra files and skip publish build/rewrite for native packages.
2026-05-15 23:46:23 +02:00
can1357 feb6c74c84 feat(agent): implemented header-based gateway detection in agent telemetry
- Added MockResponse metadata fields and invoked onResponse pre-stream with lowercased headers, status fallback, and requestId.
- Wrapped request onResponse in agent-loop, captured response headers, and forwarded them with baseUrl to finish/fail span handling.
- Added detectGatewayFromHeaders export and pi.gen_ai.gateway.* span attributes via header-based gateway detection.
- Extended telemetry event/span payloads with responseHeaders and validated detection-priority and onResponse forwarding in tests.
2026-05-15 23:46:23 +02:00
can1357 7282d92bf4 fix: normalized line-ending handling for text and TUI output flows
- Unified line-ending normalization to `replace(/\r\n?/g, "\\n")` in editor, scraper, benchmark, and utils modules.
- Added terminal-aware line sanitization in code-cell rendering to collapse inline carriage returns and avoid overwrite corruption.
- Tightened editor and paste sanitizers to trim control characters consistently after CR normalization.
2026-05-15 23:46:23 +02:00
can1357 0d00f015ec feat(ai): added 2020-12 schema migration to ai strict validation
- Added draft-07-to-2020-12 schema upgrade logic for `$schema`, `definitions`, `$ref`, tuple, and nullable mapping.
- Integrated `upgradeJsonSchemaTo202012` into strict adaptation, validation, strict-mode, sanitizer, and wire/dereference flows.
- Replaced set-based traversal helpers with record maps, `for...in` loops, and epoch/`once` cycle guards.
- Added unreleased changelog entries and tests for schema normalization, `oneOf` to `anyOf`, and tuple validation edge cases.
2026-05-15 23:46:23 +02:00
can1357 5c7c5eccb8 fix(ai): corrected AI schema normalization to draft-2020-12 prefixItems
- Adopted draft-2020-12 tuple validation with `prefixItems`, rejecting array-valued `items`.
- Expanded strict-mode handling to recurse `prefixItems` entries and infer `array` when tuple prefixes exist.
- Normalized Anthropic schemas through `prefixItems`, keeping supported tuple constraints and dropping unsupported fields.
- Updated coding-agent schema metadata and tests to draft-2020-12 `$schema` targets, including MCP/theme fixtures.
- Added `trimTrailingWhitespace()` to strip trailing spaces/tabs and keep the original line when none exist.
2026-05-15 23:46:23 +02:00
can1357 0bfea39f3c chore: bump version to 15.1.1 2026-05-15 21:22:43 +02:00
can1357 0de3a5f9ce fix(ai/utils): updated wire schema generation to draft-2020-12
- Changed `zodToWireSchema` to generate wire schemas with `target: "draft-2020-12"` instead of `draft-7` for better Anthropic input schema compatibility.
- Updated the nearby comment to describe that OpenAI strict, Google, and Anthropic CCA sanitizers accept the newer structural superset.

Fixes #1101
2026-05-15 21:22:04 +02:00
can1357 2f2e72c5ac fix: updated metadata URLs and Bun WebSocket types
- Added homepage metadata entries to the Rust and Python package manifests.
- Replaced OpenRouter HTTP-Referer values with https://omp.sh/ in completion and image requests.
- Updated Codex WebSocket typing and construction to use Bun.WebSocket for handshake header capture.
Fixes #1102
2026-05-15 21:22:03 +02:00
can1357 06aadd08f2 chore: bump version to 15.1.0 2026-05-15 19:16:17 +02:00
can1357 45402a41e6 fix(ai): dropped unrecognized keys during tool argument coercion
- Added path-based key deletion helpers that remove keys from object and array arguments while preserving sibling structure sharing.
- Mapped Zod unrecognized_keys and JSON Schema additionalProperties violations to an unrecognized issue type and applied them in issue repair to tolerate strict input shapes.
- Updated tool argument coercion tests to confirm extra keys are stripped for strict and nested strict schemas and additionalProperties false payloads.
2026-05-15 18:50:28 +02:00
can1357 e1aaf78874 refactor(compaction): moved compaction APIs to @oh-my-pi/pi-agent-core
- Relocated compaction, branch-summarization, pruning, and utils from coding-agent to packages/agent/src/compaction.
- Moved OpenAI remote compaction helpers from packages/ai to the new compaction module.
- Added handoff.ts with extractHandoffDocument, createHandoffContext, and renderHandoffPrompt helpers.
- Exposed new entries.ts with standalone SessionEntry types so coding-agent no longer owns them.
2026-05-15 18:31:12 +02:00
can1357 734091f6f2 fix(ai/schema): fail validation when primitive ref recursion exceeds cap
Primitive $ref recursion now emits a validation issue when the depth cap is exceeded instead of returning true. This preserves termination without accepting invalid values at the end of a long ref chain.
2026-05-15 18:31:12 +02:00
can1357 0af6a08190 fix(ai/providers): preserve healed Kimi tool-use promotion after structured chunks
- Keep duplicate suppression for chunks that carry both leaked markers and structured delta.tool_calls, but allow later independently healed calls to promote stopReason from stop to toolUse even if earlier chunks had structured calls.
- Treat streamFirstEventTimeoutMs: 0 as disabling the SDK request timeout instead of passing timeout: 0 or falling back to the env timeout floor.
2026-05-15 18:31:12 +02:00
can1357 b0867ccb8a fix(ai/providers): recomputed mock totals and scoped tool-call ID counter to instance
- mergeUsage now recomputes totalTokens (and cost.total when cost components are supplied) when omitted by a Partial<Usage>, so mock-backed telemetry/run-summary tests don't under-count.
- Tool-call ID counter moved into MockState; reset() restores it, so two createMockModel() instances with identical scripted tool calls produce identical IDs regardless of test ordering.
2026-05-15 17:47:42 +02:00
can1357 9ca04c9e8c fix(ai): preserved custom tool calls and threaded abort signal in remote compaction
- buildOpenAiNativeHistory now emits custom_tool_call / custom_tool_call_output for blocks with customWireName (apply_patch and other freeform tools), matching the normal Responses replay path; previously demoted to function_call which broke remote-compaction replay or mismatched the original call.
- requestOpenAiRemoteCompaction and requestRemoteCompaction accept an optional AbortSignal; the coding-agent compaction caller forwards the existing signal so cancellation now terminates the in-flight fetch instead of stranding the session in the compacting state until the server replies.
2026-05-15 17:47:32 +02:00
can1357 82c24a3f74 fix(ai/schema): enforce conditional keywords, fix $ref recursion, preserve Zod root extras
- JSON Schema validator now enforces propertyNames, patternProperties, dependentRequired, dependencies, if/then/else, contains, and prefixItems instead of silently accepting values that violate them; unevaluated* still permissive but warns once.
- Recursive $ref no longer short-circuits to true on revisit: cycle detection keys on (ref, value-identity) with a primitive depth cap, so nested sub-schema violations are caught.
- Meta-validator now structurally validates if/then/else/dependencies sub-schemas and accepts draft-07 dependencies as either schemas or string-array dependent keys.
- Wire-schema null normalization no longer strips null-valued unknown root fields before preserveUnknownRootFields snapshots them, so task.simple and similar callers still see disallowed null arguments.
2026-05-15 17:47:20 +02:00
can1357 29f8e57a46 fix(ai/providers): tightened Kimi tool-call healing edge cases and SDK timeout override
- Promotion of healed stop→toolUse now gated on prior stopReason === "stop" so error/length/aborted finishes are preserved.
- When a chunk carries both leaked markers and a structured delta.tool_calls, the healer strips visible markers but discards its synthesized calls so structured payloads remain the single source of truth.
- Healer no longer finalizes tool calls outside an active <|tool_calls_section_begin|>…<|tool_calls_section_end|> section; bare tokens in assistant prose survive as text.
- OpenAI SDK client now honors per-request streamFirstEventTimeoutMs so slow-before-headers providers are not aborted at the env default before the wrapping watchdog arms.
2026-05-15 17:47:00 +02:00
can1357 45fe4df39e fix(ai): corrected AI tool handling via JSON-schema validation flow
- Replaced fromTypeBox conversion with a JSON-schema validator flow in ai tool handling and execution paths.
- Added recursive schema validation and expanded TypeBox checks for refs, enums, uniqueItems, and constraint keywords.
- Sanitized Azure/CCA tool schemas by dropping unsupported fields and rewriting oneOf tool branches as anyOf.
- Tightened argument and model-config validation, preserving unknown tool fields and adding apiKey plus compatibility flags.
2026-05-15 15:16:50 +02:00
can1357 2867e1f4e3 feat(deps): added pi.zod exports and removed TypeBox package exports
- Added canonical `pi.zod` schema API exports and removed TypeBox package exports/imports.
- Migrated Tool schema typing from TypeBox to shared `TSchema`/Zod flow with legacy TypeBox compatibility.
- Updated AI provider adapters and MCP/agent builders to convert tool params through `toolWireSchema()`.
- Reworked schema validation from AJV to Zod-safe parsing with `fromTypeBox`, `toolWireSchema`, and meta schema checks.
2026-05-15 14:46:54 +02:00
can1357 430eb12611 fix(ai/providers): filtered non-progress chunks and added stream timeout to OpenAI client
- Added OpenAI completions progress detection to treat usage, finish reason, and real content deltas as progress while ignoring keepalive and role-only preamble chunks.
- Applied the new detector through the stream idle watchdog via `isProgressItem` so the timeout only advances on meaningful model output.
- Derived an SDK request timeout from the stream first-event watchdog window and passed it to the OpenAI client to avoid long pre-header stalls.
2026-05-15 14:46:54 +02:00
can1357 6de3cf56e6 fix(ai): substituted schema defaults for null required fields
- Preserved description at the top level when wrapping optional properties with anyOf/null.
- Substituted schema-supplied defaults when a required field arrives as null or "null", cloning to prevent cross-call mutation.
- Added coercion tests for default substitution, isolation, optional null stripping, and nested JSON deserialization.
2026-05-15 14:46:54 +02:00
can1357 752c021f31 fix(ai): restored 120s idle timeout and fixed watchdog first-item logic
- Restored default stream idle timeout from 30s back to 120s (regression from 15.0.0).
- Fixed `iterateWithIdleTimeout` to only flip `awaitingFirstItem` on real progress items, not synthetic `start` events.
- Marked provider `start` events as non-progress keepalives in the lazy-stream wrapper.
2026-05-15 14:46:54 +02:00
can1357 eee9be7e67 feat(ai): implemented runMock with mock stream normalization and errors
- Added createMockModel() returning model, calls, stream, push, and reset helpers for mock streams.
- Added registerMockApi() and streamMock() to register MOCK_API, validate model ownership, and resolve handlers by responses, extras, then fallback.
- Implemented runMock() to normalize outputs, emit block stream events, and handle delays, aborts, errors, stop reasons, usage, and tool calls.
- Added mock-provider entrypoint export, changelog notes, and broader test coverage for cleanup, sequencing, async/sync scripts, and failures.
2026-05-15 14:46:54 +02:00
can1357 ea76fae05f feat: added OpenAI remote-compaction provider endpoint gating support
- Added OpenAI remote-compaction API support with provider-specific endpoint gating.
- Added buildOpenAiNativeHistory, token-budget estimation, and message trimming for remote-compaction.
- Added helpers to preserve and validate remote-compaction metadata in request/response handling.
- Refactored coding-agent compaction to consume pi-ai remote-compaction helpers with converted message history.
- Exported remote-compaction from ai index and documented the new APIs in CHANGELOG.
2026-05-15 14:46:54 +02:00
can1357 481e5df5a9 fix(ai): corrected OpenAI stream tool-call healing for leaked token markers
- Added a Kimi ToolCallHealer to strip leaked token markers while buffering partial stream chunks.
- Routed OpenAI completion deltas through healing and emitted cleaned text plus parsed toolCall blocks.
- Implemented healer finalization to normalize IDs, repair JSON arguments, and flush pending calls at stream end.
- Added regression SSE tests and CHANGELOG notes for marker leaks, split calls, multi-calls, and unknown tokens.
2026-05-15 14:46:53 +02:00
roboomp e49e4128be fix(ai): stop folding priority-tier into premiumRequests in usage data
Priority (fast-mode) requests were being added to usage.premiumRequests in
all three OpenAI provider paths (completions, responses, codex-responses).
This caused the status-line and footer to render a spurious star whenever
fast mode was active.

The packages/stats parser already derives priority-tier premium counts from
service_tier_change session entries when premiumRequests is unset, so omp-stats
continues to account for fast-mode traffic correctly. The premiumRequests field
in usage payloads now exclusively carries GitHub Copilot premium multipliers.

Fixes #1095
2026-05-15 10:57:11 +00:00
can1357 cb6c085a41 fix(coding-agent/lsp): fixed root marker glob detection and marksman warmup timeout
- Updated root marker detection to read the directory once and match glob markers against top-level entries, preventing recursive scans when checking project roots.
- Adjusted root-marker glob error handling to warn on directory listing failures and treat the marker set as absent when unreadable.
- Reduced marksman's configured warmup timeout from 15,000 ms to 2,000 ms in LSP defaults.
2026-05-15 10:20:44 +02:00
luwanglin 3120afaa97 fix(h2-fetch): fall back to HTTP/1.1 on connection-level errors, not just HTTP2Unsupported
Some HTTPS endpoints (e.g. corporate API gateways behind reverse proxies) advertise h2 via ALPN but then refuse or reset the connection at the HTTP/2 framing layer. Bun surfaces these failures as ConnectionRefused, ConnectionReset, or ConnectionClosed rather than HTTP2Unsupported.

Previously only HTTP2Unsupported triggered the transparent h1 retry, so any custom provider pointing at such a gateway would fail with a cryptic "Connection error." that was impossible to diagnose from user-land.

This commit widens the fallback set to include ConnectionRefused, ConnectionReset, and ConnectionClosed — all of which are transport-layer indicators that the h2 attempt itself failed, not the underlying application request.
2026-05-15 15:50:40 +08:00
can1357 fe6b5b42b4 chore: bump version to 15.0.2 2026-05-15 09:18:53 +02:00
can1357 3b1a714a01 chore: update homepage 2026-05-15 09:18:41 +02:00
can1357 1b47cd3042 feat(ai): fetch overrides
- Introduced `FetchImpl` type with optional `preconnect` to accept non-Bun fetch implementations without type errors.
- Applied the new type across all providers and `StreamOptions.fetch`.
- Added tests verifying fetch override routing for openai-completions, openai-responses, and fetchWithRetry.
2026-05-15 09:16:38 +02:00
can1357 1b76b60b17 feat(ai/providers): added configurable fetch overrides to AI provider request paths
- Introduced a `fetch` option on `StreamOptions` and threaded it through providers to let callers supply a custom request transport.
- Updated provider clients and direct HTTP calls across Anthropic, OpenAI, Azure, Google, GitLab Duo, Gemini CLI, Ollama, and Codex flows to use the injected fetch implementation.
- Extended retry helper options to accept a fetch override and preserved preconnect support from the selected fetch function.
2026-05-15 09:07:34 +02:00
can1357 7af87f773d fix(python/omp-rpc): marked RPC client as closed during stop to unblock prompt waits
- Stop now marks the client as closed via `_mark_closed` with `RpcProcessExitError`, so `_wait_for_agent_end` wakes immediately instead of waiting for a timeout.
- Added a regression test using a hanging server subprocess to verify `stop()` unblocks `prompt_and_wait` promptly and raises `RpcProcessExitError`.
- Updated Kimi compatibility tests to distinguish Moonshot-hosted models from OpenCode-hosted ones for `reasoning_content` and assistant-content tool-call behavior.
2026-05-15 05:45:48 +02:00
Can Bölük 6026dcedaa Merge pull request #1073 from ephraimduncan/fix/stream-stall-auto-retry
fix(ai): recover stalled lazy provider streams
2026-05-15 05:03:04 +02:00
Can Bölük 36fafb8f6f Merge pull request #1071 from Kukkerem/fix/opencode-kimi-reasoning-content-rejection
fix: exclude OpenCode providers from synthetic reasoning_content injection for Kimi models
2026-05-15 05:02:17 +02:00
shoucandanghehe 8b4b73e3c4 fix(ai): replay Kimi reasoning placeholder 2026-05-15 02:46:44 +08:00
shoucandanghehe 0bf280d079 fix(ai): disable Kimi thinking for forced tools 2026-05-15 02:29:14 +08:00
ephraimduncan bea95b056d fix(ai): recover stalled lazy provider streams 2026-05-14 15:28:59 +00:00
zolszabo 6ac5e4e1ce fix: exclude OpenCode providers from synthetic reasoning_content injection for Kimi models
OpenCode-Go and OpenCode-Zen handle reasoning content internally
and reject client-supplied reasoning_content in message history.
When retry fallback forwards conversation history to
opencode-go/kimi-k2.6, the compat layer was injecting synthetic
reasoning_content: '.' on assistant tool-call turns, causing
HTTP 400: 'Extra inputs are not permitted'.

Gate isKimiModel in requiresReasoningContentForToolCalls on
!isOpenCodeProvider so the injection path is skipped for
OpenCode providers while preserving existing behavior for
native Kimi API, DeepSeek, and OpenRouter.
2026-05-14 16:27:37 +02:00
can1357 09e4b58672 chore: bump version to 15.0.1 2026-05-14 07:28:49 +02:00
can1357 b9b2c381f0 fix(coding-agent/goals): skipped goal accounting operations when accounting state was absent
- Added an internal accounting-state guard and used it to skip goal usage flushing when accounting was inactive.
- Updated goal abort handling to return early unless accounting or pause logic was required, then paused only a cloned active goal state before committing.
- Aligned related tests/types by tightening OpenAI helper typing and using Tool typings for the goal tool registry.
2026-05-14 06:53:21 +02:00
can1357 88e486be29 fix(coding-agent/modes): hardened context breakdown against absent session fields
- Hardened context usage accounting to tolerate missing session fields by defaulting skills and tools to empty arrays.
- Guarded message and system-prompt token counting with presence checks to avoid access errors on partial session objects.
2026-05-14 06:37:25 +02:00
can1357 6d00cc1f08 test(ai): added reasoning model helper for OpenAI response history tests
- Added getOpenAIReasoningModel to wrap the bundled gpt-5-mini model with a non-gpt-5 name in tests.
- Replaced all OpenAI responses test model constructions using gpt-5-mini with the new helper to bypass reasoning-model branching during payload assertions.
2026-05-14 06:23:55 +02:00
can1357 f1f6516056 refactor: reorganized exports and removed obsolete helper branches
- Removed export leakage by demoting many helper and const symbols to module-local scope.
- Renamed underscore-prefixed internals and cache fields, then updated related references and `satisfies never` checks.
- Deleted obsolete logic branches and helpers, including harmony-stream interruption flow and unused benchmark runtime helpers.
- Updated Biome config and manifests by broadening lint coverage and removing an unused `@napi-rs/cli` dev dependency.
- Adjusted tests and utilities to use renamed test helpers and remove redundant private test-only helpers/locals.
2026-05-14 04:36:19 +02:00
can1357 6eda70aada refactor: replaced abortableSleep with scheduler.wait and fetchWithRetry
- Removed local `abortableSleep` in favour of Node's built-in `scheduler.wait` from `node:timers/promises`.
- Consolidated per-provider retry/fetch loops into a shared `fetchWithRetry` utility in `packages/utils`.
- Moved `extractHttpStatusFromError`, `isRetryableError`, and related helpers out of `packages/ai` into `packages/utils`.
- Deleted `extractRetryDelay` in favour of `extractRetryHint` with unified header and body parsing.
2026-05-13 16:40:58 +02:00
can1357 af07faec11 feat: Bun 1.3.14
- Raised the Bun minimum version to >=1.3.14 across package metadata, install scripts, and changelog notes.
- Removed the Photon native image pipeline and added SIXEL-based `sixel` support in pi-natives.
- Migrated coding-agent image handling and resizing to `Bun.Image`, including updated tests and a JPEG quality bump to 80.
- Added HTTP/2 fetch bootstrap with HTTPS-only fallback and updated Bun build flags for autoload suppression/`--keep-names`.
2026-05-13 13:21:59 +02:00
can1357 334b6782a5 feat(stats): counted priority service-tier traffic as premium requests in usage stats
- Added `getPriorityPremiumRequests` and used it in OpenAI and OpenAI Codex providers to increment `usage.premiumRequests` when `serviceTier: "priority"` was sent.
- Combined Copilot and priority premium counts in OpenAI completions and responses usage parsing so emitted usage uses the merged premium total.
- Updated stats parsing/backfill to re-read `service_tier_change` entries and UPSERT only `premium_requests`, so historical sessions pick up priority traffic without mutating other metrics.
2026-05-13 11:31:51 +02:00
can1357 1c8d4080b3 chore: bump version to 15.0.0 2026-05-13 06:20:54 +02:00
can1357 142c39569b chore: changelog update 2026-05-13 05:49:11 +02:00
can1357 5a37fd4516 fix(ai): resolved ai auth credential_disabled queueMicrotask flushing
- Deferred initialize to flush queued credential_disabled events via queueMicrotask and event splicing.
- Added tests for pre-initialize credential_disabled emissions and onError propagation of handler failures.
- Replaced auth credential disable flow with CAS checks in #tryDisableAuthCredentialIfMatches and matching SQL statement.
- Retried OAuth getApiKey after disable failures; added peer-rotation race test for fresh token and active credential retention.
- Updated CHANGELOG for deferred microtask flushing plus eval import renames and diff URL/quoted-path parsing fixes.
2026-05-13 05:33:03 +02:00