Commit Graph
871 Commits
Author SHA1 Message Date
can1357 eca3a08d25 chore: bump version to 15.5.9 2026-05-28 12:09:01 +02:00
can1357 6cc91fcb37 chore: bump version to 15.5.8 2026-05-28 10:37:49 +02:00
can1357 c1fa0e9f50 refactor(agent): replaced keepalive utility with disposable EventLoopKeepalive
- Replaced the `keepaliveWhile` Promise wrapper with a new `EventLoopKeepalive` class that registers and disposes an interval timer through `Symbol.dispose`.
- Updated `Agent` to instantiate `EventLoopKeepalive` via `using` during prompt execution instead of manually managing an interval.
- Wrapped interactive mode's await path with the new helper and removed redundant `keepaliveWhile` usage from the CLI entrypoint.
2026-05-28 09:51:57 +02:00
hezhiyang2000 f71e1db0c2 fix: restore #emit listener isolation (isPromise + try/catch)
The previous commit accidentally dropped the try/catch in #emit
because the local agent.ts was based on an older main that lacked
the listener-isolation code. Restore it to match main.
2026-05-28 14:09:01 +08:00
hezhiyang2000 af2011f5a1 fix: use inline setInterval instead of EventLoopKeepalive import
EventLoopKeepalive is not exported from yield.ts on main.
Use setInterval + unref() directly, matching the pattern in
keepaliveWhile(). Biome import order also fixed (type imports
before value imports within the same group).
2026-05-28 11:51:24 +08:00
hezhiyang2000 38d77f819d style: fix Biome import order (type imports before value imports)
Biome organizeImports sorts type imports before value imports within
the same relative-path group. Move EventLoopKeepalive import after
all type imports.
2026-05-28 11:50:15 +08:00
hezhiyang2000 6fb1983fbc fix: add EventLoopKeepalive to Agent.prompt()
Bun 1.3.x event loop busy-waits when the only pending work is an
unresolved Promise. Agent.prompt() sets #runningPromise via
Promise.withResolvers() which stays unresolved during the entire
agent loop execution (LLM calls + tool iterations), causing ~100%
CPU even when the process is idle.

PR #1419 added keepaliveWhile() to getUserInput() in main.ts, but
session.prompt() callers (interactive mode, resume, etc.) still
await the unresolved #runningPromise, bypassing the keepalive.

Install EventLoopKeepalive directly in Agent.prompt() so all
callers are covered. Dispose in the finally block after the agent
loop completes.
2026-05-28 10:07:22 +08:00
can1357 b87cd8f93f chore: bump version to 15.5.7 2026-05-27 19:01:33 +02:00
cognitiveandmetaphorics 0455c164f9 fix(agent): compact() propagates thinkingLevel to all three summarizers
The thinking-level fix (e07b47ee4) added SummaryOptions.thinkingLevel
and threaded it from agent-session.ts into compact(), but the
field-by-field rebuild of summaryOptions inside compact() (and a
second inline rebuild for generateShortSummary) silently dropped it.

Effect on every call site that fans through compact():
  generateSummary, generateTurnPrefixSummary, generateShortSummary all
  see options?.thinkingLevel === undefined => resolveCompactionEffort
  falls back to Effort.High => user's /model :off selection is
  silently overridden, and xai-oauth/grok-build still trips on the
  unsupported-effort path even though fix #2 strips it at the wire
  layer of the openai-responses mapper.

Add `thinkingLevel: options?.thinkingLevel` at both rebuild sites in
compact(): the summaryOptions literal feeding generateSummary and
generateTurnPrefixSummary, and the inline options literal feeding
generateShortSummary.

Extend compaction-thinking-level.test.ts with four compact()-level
cases driving isSplitTurn:true so all three summarizers fire:
  - Off                  -> every fan-out call gets reasoning=undefined
  - Low                  -> every fan-out call gets reasoning="low"
  - <unset>              -> every fan-out call gets reasoning="high" (default)
  - grok-build + High    -> every fan-out call gets reasoning=undefined (clamp)

TDD red-green verified: stashing the source fix flips the Off and Low
cases to fail with received="high" (exactly the reviewer's prediction);
restoring the fix returns all four to green. Suite: 131 pass / 0 fail
(baseline 127 + 4 new). biome + tsgo --noEmit clean.

Op: correct
Restores: spec:compaction-honors-session-thinking-level
(cherry picked from commit 9b501e369b820cb992345ceb3f2a207ccc9ee233)
2026-05-27 15:01:24 +00:00
cognitiveandmetaphorics 25c6794cd5 fix(agent): compaction honors session thinking level and silent-clamps unsupported-effort models
Triple-stacked failure on the same axis (thinking effort) produced the
user-visible

    Error: Compaction failed: Thinking effort high is not supported by
           xai-oauth/grok-build.
    Supported efforts:

(empty list after the colon) whenever the active model was a curated
xAI catalog entry with compat.supportsReasoningEffort: false.

Three defects lined up. (1) Behavior: compaction at four call sites
in packages/agent/src/compaction/compaction.ts hardcoded
reasoning: Effort.High and never threaded session.thinkingLevel —
the user's /model :off selection (and any explicit low/medium) was
silently overridden. On every other model this was invisible.
(2) Validation: requireSupportedEffort threw at the openai-flavored
mapper layer before the wire-side omitReasoningEffort gate in
providers/xai-responses.ts ever ran; two contradictory guards on the
same wire param. (3) Message: when getSupportedEfforts returned [],
the rendered error tail was 'Supported efforts: ' with nothing after
the colon — disappears as a side-effect of fix #2.

Fix #1 — thread ThinkingLevel | undefined end-to-end. Add
SummaryOptions.thinkingLevel and HandoffOptions.thinkingLevel.
Convert via a single exhaustive switch (effortFromThinkingLevel) in
the new resolveCompactionEffort helper:
  - Off            → undefined  (omit reasoning entirely)
  - undefined/Inherit → Effort.High → clamp per model (preserves the
                                       historical default for users
                                       who never touched the dial)
  - explicit Effort → respect user → clamp per model

resolveCompactionEffort lives in compaction.ts; all four call sites
(generateSummary, generateHandoff, generateShortSummary,
generateTurnPrefixSummary) route through it. agent-session.ts threads
this.thinkingLevel into all three production compaction entry points
(manual /compact at L6201, auto-compaction at L6458 — the most-fired
path, originally missed in plan review — and direct generateHandoff
at L5465). The audit-gate test
(test/agent-session-compaction-thinking-threading.test.ts) scans the
file with a brace-balanced extractor and refuses any unthreaded site.

Fix #2 — silent-clamp at the openai-flavored mapper layer. Extract
exported modelOmitsReasoningEffort(model) in model-thinking.ts as the
single source of truth for compat.supportsReasoningEffort: false on
openai-responses* APIs. getSupportedEfforts now calls it instead of
inlining the check (pure refactor — observable behavior preserved).
resolveOpenAiReasoningEffort in stream.ts early-returns undefined
when the predicate is true, so the wire-side omitReasoningEffort
gate (providers/xai-responses.ts:78) becomes the single source of
truth for the actual strip — no redundant throw.

Three regression tests pin the contract:
  - packages/ai/test/xai-oauth-effort-strip.test.ts (5 tests):
    modelOmitsReasoningEffort returns true for grok-build and
    grok-4.20-0309-reasoning, false for grok-4.3 / Anthropic /
    openai-completions.
  - packages/agent/test/compaction-thinking-level.test.ts (5 tests):
    every ThinkingLevel outcome through generateHandoff — Off stays
    undefined (not coerced to High), Low stays Low, Inherit / undefined
    default to High, grok-build clamps to undefined regardless of
    requested level. Covers the Codex-caught Off-vs-not-provided
    distinction.
  - packages/coding-agent/test/agent-session-compaction-thinking-threading.test.ts
    (2 tests): brace-balanced source scan asserts every direct
    compact() / generateHandoff() in agent-session.ts threads
    'thinkingLevel: this.thinkingLevel'; floor of 3 threaded sites.

TDD red-green verified for fix #1: temporarily reverted the handoff
call-site back to hardcoded Effort.High → compaction-thinking-level
went 2 pass / 3 fail (Off coerced, Low overridden, grok-build throws);
restored → 5 pass / 0 fail.

Verified:
  - packages/agent:  127 pass / 0 fail
  - packages/ai:     1061 pass / 337 skip / 0 fail
  - packages/coding-agent (focused): 179 pass / 5 skip / 0 fail
  - biome + tsgo --noEmit clean across all three packages

Out of scope (follow-ups):
  - branch-summarization.ts:307 already passes no reasoning — no edit.
  - The empty-list error message at model-thinking.ts:296 is now
    structurally unreachable from the openai-responses path.
  - modelOmitsReasoningEffort and grokSupportsReasoningEffort
    (xai-responses.ts:22) overlap; collapse into a single predicate
    in a future commit.

Op: correct
Restores: spec:compaction-honors-session-thinking-level
Restores: spec:xai-oauth-grok-build-compaction-no-throw
(cherry picked from commit e07b47ee46769053c658819437e2478389a4cee0)
2026-05-27 15:01:20 +00:00
can1357 bf92a3dd4d chore: bump version to 15.5.6 2026-05-27 15:04:44 +02:00
can1357 ca86239bda Revert "wip: gentle"
This reverts commit 99bae2ce6c.
2026-05-27 15:01:59 +02:00
can1357 99bae2ce6c wip: gentle 2026-05-27 14:45:02 +02:00
can1357 f0c7df60d5 chore: bump version to 15.5.5 2026-05-27 14:44:30 +02:00
can1357 6643178d6a refactor: replaced instanceof Promise checks with isPromise utility
- Imported isPromise from node:util/types in four modules.
- Replaced four instanceof Promise checks with isPromise calls for more reliable promise detection.
2026-05-27 13:02:52 +02:00
can1357 0e9137a703 refactor(agent/utils): simplified keepaliveWhile implementation using unrefed interval
- Removed the EventLoopKeepalive class and replaced it with a direct setInterval call.
- Added an unref call to the interval timer to prevent blocking the process exit.
2026-05-27 13:01:49 +02:00
Can BölükandGitHub ad8bf18189 Merge pull request #1426 from oldschoola/fix/session-emit-listener-isolation
fix(session): isolate event listener failures in agent fan-out
2026-05-27 13:45:01 +03:00
Can BölükandGitHub 0b52b8c0d0 Merge pull request #1419 from hezhiyang2000/fix/bash-busy-wait-yield
fix: eliminate Bun event-loop busy-wait with setTimeout keepalive (v2)
2026-05-27 13:39:01 +03:00
can1357 69ab1656ff chore: bump version to 15.5.4 2026-05-27 10:27:32 +02:00
oldschoola 48d63d4ddf fix(session): satisfy tsgo strict checks on void-return listener
Two TS errors in CI:
1. `agent-session.ts:1317` — `error TS1345: An expression of type 'void'
   cannot be tested for truthiness`. The listener type is
   `(event: AgentSessionEvent) => void`, so the returned value can't be
   directly tested. Same shape in `agent.ts:1079`.
2. `test/session/emit-listener-isolation.test.ts:19` — the test fixture
   for `AgentEvent.tool_execution_start` was missing the required `args`
   field.

Cast the return to `unknown` and check `instanceof Promise` instead of
duck-typing `.then` — type-safe and matches what async functions actually
return. Add `args: {}` to the test fixture.
2026-05-27 01:07:09 -07:00
hezhiyang2000 1126934300 fix: replace ReturnType<typeof setInterval> with NodeJS.Timeout
Project convention (AGENTS.md) prohibits ReturnType<> — use the
concrete type name instead. NodeJS.Timeout matches the existing
pattern used throughout the codebase (e.g. interactive-mode.ts).
2026-05-27 14:59:08 +08:00
hezhiyang2000 2159f56386 fix: add EventLoopKeepalive to eliminate idle busy-wait
Root cause: Bun 1.3.x (JavaScriptCore) busy-waits when the only
pending work is an unresolved Promise. A setInterval keepalive
keeps the event loop in epoll_wait instead of userspace spinning.

- EventLoopKeepalive: setInterval-based keepalive (re-arms after each
  firing, addressing the bot review concern about setTimeout expiry)
- keepaliveWhile(): wrapper to await a Promise with keepalive active
- Applied to getUserInput() in main.ts
- Retains yieldIfDue() and ExponentialYield from #1396

Idle CPU drops from ~100% to ~0% (wchan=do_epoll_wait).
2026-05-27 14:57:46 +08:00
oldschoola 08bccfe0ec fix(session): isolate event listener failures in agent fan-out
Both `AgentSession.#emit` (session/agent-session.ts) and `Agent.#emit`
(packages/agent/src/agent.ts) iterated listeners with no error isolation.
A synchronous throw in any subscriber aborted the for-loop, so later
subscribers (TUI rendering, ACP bridge, task executor progress,
hindsight) silently missed events. Many listeners — see
`modes/controllers/event-controller.ts:141` and
`modes/controllers/input-controller.ts:576` — are registered as
`async (event) => { await this.handleEvent(event); }`; the returned
Promise was dropped, so any rejection became an unhandled rejection.

Wrap each listener invocation in try/catch and attach a `.catch` to any
returned thenable. Errors are logged via `logger.warn` (already imported
in agent-session.ts) and `console.error` (agent.ts has no logger
dependency, keep it that way).

Test: new `test/session/emit-listener-isolation.test.ts` registers two
listeners on both classes; first listener throws (or returns a rejecting
Promise); asserts the second listener still receives the event AND no
`unhandledRejection` fires. 4 cases (sync+async × Agent+AgentSession).
All fail on current main; all pass with the fix.
2026-05-26 23:26:15 -07:00
can1357 280b638cc8 chore: bump version to 15.5.3 2026-05-27 03:20:33 +02:00
can1357 2ae57b85dc chore: bump version to 15.5.2 2026-05-27 00:46:37 +02:00
can1357 8d429e96fb chore: bump version to 15.5.1 2026-05-27 00:05:59 +02:00
can1357 f19469c96c chore: bump version to 15.5.0 2026-05-26 22:55:07 +02:00
can1357 e4a16451ec feat(coding-agent): added coding-agent approval types and mode options
- Added `ToolTier`, `ToolApproval`, and `ToolApprovalDecision` types and exported approval APIs.
- Updated approval-mode options from `auto|prompt|custom` to `always-ask|write|yolo` and defaulted mode to `yolo`.
- Changed approval resolution to apply per-tool decisions first, then mode-tier limits, with legacy-mode migration.
- Assigned read/write/exec `approval` and approval-detail prompts across built-in, custom, extension, and MCP tools.
2026-05-26 21:52:16 +02:00
can1357 3078d31a4c chore: reformat 2026-05-26 20:44:09 +02:00
can1357 1d8ee5a891 refactor(yield): migrated to scheduler.wait with abort support and gate
- Replaced Bun.sleep with scheduler.wait for Node-compatible cancellable sleeps.
- Added module-level timestamp gate to skip yields within 50ms of the last one.
- Threaded AbortSignal through ExponentialYield.sleep to cancel losing timers in race.
- Added tests covering gate behaviour and stray-timer cancellation.
2026-05-26 20:37:39 +02:00
oldschoolaandcan1357 29d5392d3e feat(ai): add Fireworks Fire Pass support + AI provider review fixes
Fire Pass support:
- New provider with login command 'omp /login firepass'
- Hand-seeded kimi-k2.6-turbo model with Fire Pass router wire id
- pi-ai CLI --help lists firepass

AI provider fixes surfaced during the Fire Pass review:
- service_tier whitelist restored for openai/openai-codex only (was leaking to
  Fireworks, Firepass, OpenRouter, Azure OpenAI Responses)
- Anthropic tool schema normalizer collapses {} -> true for additionalProperties
- anthropic.prepareParams fires onPayload after drop helpers so callers see the
  real wire body
- isServiceTier type guard narrowed to ResolvedServiceTier
- transformMessages stops dropping orphan tool_result when all pending tool
  calls have already resolved
- zodToWireSchema preserves null for non-scalar nullable() inner schemas
- isEmptyObject / isJsonObjectEmpty use Object.keys().length === 0 instead of
  prototype-walking for...in
- Telemetry records resolved service_tier (priority) instead of scoped
  placeholder (openai-only/claude-only)
- Robomp dirty-state reminder no longer asserts a formatter-failure premise
2026-05-26 20:36:15 +02:00
Can BölükandGitHub 1595c4c766 Merge pull request #1396 from hezhiyang2000/fix/bash-busy-wait-yield
fix: prevent busy-wait in agent loop and bash executor
2026-05-26 21:34:37 +03:00
can1357 6899e0aaed chore: bump version to 15.4.3 2026-05-26 18:55:58 +02:00
can1357 38b7966894 chore: bump version to 15.4.2 2026-05-26 17:51:35 +02:00
can1357 774d32cc3f chore: bump version to 15.4.1 2026-05-26 16:53:12 +02:00
can1357 30793c1655 refactor: restructured hashline to use file-level hash validation with colon separators
- Replaced per-line hash anchors with file-level hash validation in hashline format, changing anchor syntax from LINE+HASH to bare LINE numbers.
- Simplified hashline line separator from pipe (|) to colon (:) and replaced replace operator (->) with colon, added delete operator (!) for explicit line deletion.
- Implemented file-read snapshot caching with multi-snapshot ring buffer per path and file-hash-based recovery to detect and recover from stale edits.
- Refactored hashline grammar, parser, and execution to support file-level hash binding, anchor-scoped validation, and structural bracket warnings for delete operations.
- Updated documentation and test fixtures to reflect new hashline syntax with file hashes, colon separators, and delete operator throughout.
2026-05-26 13:25:22 +02:00
hezhiyang2000 afe574b351 fix: prevent busy-wait in agent loop and bash executor
- yieldIfDue() uses compensated sleep (sleepAtLeast): retries Bun.sleep()
  until the requested wall-clock duration has elapsed. This is necessary
  because napi callbacks (uv_async_send) can wake the event loop
  prematurely, causing Bun.sleep(N) to return after only ~1-2ms.
- ExponentialYield for bash-executor: starts at 20ms, doubles to 10s.

Closes #1384
2026-05-26 17:35:00 +08:00
can1357 732dae7b11 chore: bump version to 15.4.0 2026-05-26 11:26:08 +02:00
can1357 7acc631ce9 chore: bump version to 15.3.2 2026-05-25 20:30:37 +02:00
can1357 e2b86b8a41 chore: bump version to 15.3.1 2026-05-25 14:07:16 +02:00
can1357 80186e341c feat(agent): threaded intentTracing option through append-only context
- Exported `normalizeTools` so `AppendOnlyContext` uses the same tool normalization as the agent loop.
- Added `BuildOptions.intentTracing` to `build()`/`reset()`/`takeSnapshot()` so intent injection is consistent and included in the prefix fingerprint.
- Improved `#computeDigest` to cover tool_calls, tool_call_id, name, and id fields to catch in-place mutations.
- Fixed `#unsubscribeAppendOnly` leak and added no-op guard in `#syncAppendOnlyContext`.
2026-05-25 14:06:44 +02:00
can1357 45345f43b0 chore: bump version to 15.3.0 2026-05-25 12:56:19 +02:00
Brit 05232eaaee fix: include strict/customFormat/customWireName in tool fingerprint 2026-05-24 23:06:55 +02:00
Brit 79973d69de fix: preserve system prompt array structure in fingerprint 2026-05-24 23:01:41 +02:00
Brit e71d2ff49e fix: detect content rewrites in syncMessages, reset append-only cache on model switch 2026-05-24 22:39:20 +02:00
Brit 648bbdc163 fix(agent): passed AbortSignal to transformContext and re-evaluated append-only on model switch 2026-05-24 22:28:38 +02:00
Brit ee04dd8e21 chore: bun check 2026-05-24 22:17:15 +02:00
Brit 2a86049f0f feat(agent): add append-only context mode for DeepSeek prefix-cache stability
ImmutablePrefix caches system prompt + tool specs after first build()
so subsequent turns reuse identical byte sequences. AppendOnlyLog
converts messages once via syncMessages() and only appends deltas
on further turns — prior-turn bytes stay stable.

- New module: packages/agent/src/append-only-context.ts
  StablePrefix, AppendOnlyLog, AppendOnlyContextManager
- AppendOnlyContextManager added to AgentLoopConfig
- Wired into streamAssistantResponse in agent-loop.ts
- Toggleable via provider.appendOnlyContext setting (auto/on/off)
- Default auto enables for deepseek provider
- 38 tests covering prefix, log, sync, compaction handling
- /session info surfaces current active state
2026-05-24 22:08:53 +02:00
can1357 e6c08c1155 chore: bump version to 15.2.4 2026-05-22 17:48:11 +09:00
can1357 3ecfac846c chore: bump version to 15.2.3 2026-05-22 13:34:49 +09:00