Commit Graph
104 Commits
Author SHA1 Message Date
cat-shark 9821439603 fix: read prompt and tools from the transcript
CI / Lint, typecheck & build (push) Failing after 32s
pi 0.87 made the session transcript canonical for provider context: the
context handed to a custom provider's stream no longer carries
`systemPrompt` and `tools`; they live on the leading system message
(`sections` + `toolsAdded`). streamQoder still read the removed fields,
so every request went out with `system: ""` and `tools: []` - the model
saw no prompt and no tools and answered that it cannot access files.

- resolve the prompt with getCurrentSystemPrompt(messages) and the tool
  list with getCurrentTools(messages)
- give tool parameters a root `type: "object"`: Qoder's upstream rejects
  a union root ("schema must be a JSON Schema of 'type: \"object\"', got
  'type: null'"), e.g. the agent-browser Electron tool, which failed the
  whole request with a 400
- bump the pi-ai / pi-coding-agent devDependencies to ^0.87.1 and cover
  the transcript prompt/tools path with a regression test
2026-09-29 10:18:44 +08:00
cat-shark d0d69617da fix: keep a turn's tool results together when one returns an image
The OpenAI-shaped `tool` role content is a plain string, so a tool result
carrying images (pi's read/screenshot tools) follows as an extra user
message. It was emitted immediately after its own tool message, which broke
multi-call turns:

  assistant(tool_calls=[a, b]) -> tool(a) -> user(image) -> tool(b)

Qoder rejects that with "An assistant message with 'tool_calls' must be
followed by tool messages responding to each 'tool_call_id' (insufficient
tool messages following tool_calls message)", leaving the session unable to
send any further request.

Queue the image follow-up and flush it once the run of consecutive tool
results ends, so every tool_call_id is answered before the user message.
2026-09-24 17:17:25 +08:00
cat-shark e7d12b5532 fix: retry instead of stalling when DSML tool-call markup leaks
DeepSeek V4 sometimes expresses a tool call as its internal DSML markup
instead of filling `tool_calls`, and Qoder's gateway leaks the tag skeleton
rather than converting it. When no structured call arrives the turn used to
end as an empty `stop` and the agent stopped mid-task with no error.

Handle both shapes:

- Filter the delimited form (`||DSML||tool_calls` ...) on the reasoning and
  content channels, rebuilding a complete block into a structured call.
- Strip the delimiter-less form the gateway leaves behind
  (`<parameter name="command">…</parameter>`, `</invoke>`, `</tool_calls>`,
  a stray `</thinking>`) line-wise before the empty-turn guard reads the
  message, and make `hasVisibleText` ignore markup-only text. That form used
  to land in the *content* channel as a normal reply, so the guard saw
  visible text and never fired.

A turn that produces only leaked markup now fails with a retryable error
(matching pi's "ended without" pattern) instead of ending silently.
2026-09-24 17:17:18 +08:00
cat-shark a0be14764c feat(models): register every /model/list scenario
Qoder's /model/list groups one account catalog by UI scenario (chat,
assistant, quest, qwork, experts, ...). The CLI only read `chat`, so the
picker hid models the IDE exposes elsewhere — GLM-5.3, GLM-5.2 and
DeepSeek-V4-Pro live under experts/qwork.

Register the union of the scenario groups, keeping the first occurrence per
upstream key (chat wins) and excluding byok_* groups, which are
bring-your-own-key providers rather than part of the shared catalog.

Also keep an explicitly enabled `auto` model: live catalogs key `configs` by
the whitespace-stripped display name, so it arrives as `Auto` instead of the
legacy raw `auto` key.

Refresh the lockfile to the 0.4.5 already in package.json.
2026-09-24 17:17:10 +08:00
Cursor Agent 6ac304c9f9 chore: bump version to 0.4.5 2026-09-08 17:04:46 +00:00
shyoldmanandGitHub fda9a0421a fix: include "max" in supported thinking levels (#24) 2026-09-09 01:00:13 +08:00
Cursor Agent a238e428fe fix: load registerApiProvider dynamically for OMP
OMP rewrites @earendil-works/pi-ai/compat to a bundle without
registerApiProvider, which broke static import at install/load.
Probe the export at runtime; stock pi still registers qoder-api for
global streamSimple, while OMP relies on registerProvider(streamSimple).
2026-09-06 12:53:03 +00:00
Cursor Agent ab80759fe0 chore: bump version to 0.4.3 2026-09-06 12:37:37 +00:00
Cursor Agent dfe7308674 chore: refresh package dependencies 2026-09-06 12:36:23 +00:00
Cursor Agent 3d0c18f88b test: isolate oauth PAT env from host QODER_API_KEY 2026-09-06 10:09:04 +00:00
Cursor Agent 8a2a9b2481 perf: cut hot-path body copies, Cosy hashing, and per-request disk reads 2026-09-06 10:07:32 +00:00
Cursor Agent b854aa4685 chore: bump version to 0.4.2 2026-09-06 09:51:20 +00:00
Simon ShiandGitHub 01499361c0 Merge pull request #23 from acniray/perf/optimize-qoder-body-encoding
perf: optimize Qoder body encoding for large requests
2026-09-06 17:49:13 +08:00
ray 03fd968404 perf: optimize Qoder body encoding for large requests 2026-09-03 18:01:25 +08:00
Cursor Agent 8dd4cdbefb docs: drop leftover region-env notes from README 2026-08-31 18:15:36 +00:00
Cursor Agent b68cfd3e31 docs: rewrite README for region-bound providers and friendly model IDs 2026-08-31 18:10:47 +00:00
Cursor Agent bd3d020cee fix: register qoder-api for pi global streamSimple
Pi 0.84+ no longer registers custom APIs from registerProvider.streamSimple,
so a later agent-loop path threw No API provider registered for api: qoder-api.
2026-08-31 17:51:46 +00:00
Cursor AgentandSimon Shi 09bd3bcf07 chore: bump version to 0.4.0
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 17:23:32 +00:00
Cursor AgentandSimon Shi fb7305b0f8 chore: refresh npm lockfile
Refresh lockfile and dependencies within existing ranges via npm update.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 17:23:18 +00:00
Cursor AgentandSimon Shi dc8b9afad2 Require friendly names for live catalog models
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 17:12:20 +00:00
Cursor AgentandSimon Shi 10ab666f31 Use friendly CN model in region binding test
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 17:11:58 +00:00
Cursor AgentandSimon Shi 11249d12c4 Format reorganized provider modules
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 17:11:43 +00:00
Cursor AgentandSimon Shi 9d88e995ee Refactor provider around fixed regions and friendly model ids
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 17:11:18 +00:00
Cursor AgentandSimon Shi 63c517002e Fix provider binding test mocks
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:53:00 +00:00
Cursor AgentandSimon Shi 66f950f9c5 Bind Qoder providers to fixed regions
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:51:59 +00:00
Cursor AgentandSimon Shi b1d66d6eb4 fix: unblock live fixture recording
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:33:47 +00:00
Cursor AgentandSimon Shi 72a81d672f test: cover live chat endpoint classification
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:33:24 +00:00
Cursor AgentandSimon Shi 476a466076 style: format stream adapter test
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:32:09 +00:00
Cursor AgentandSimon Shi b4f504094e refactor: centralize regional provider configuration
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:31:54 +00:00
Cursor AgentandSimon Shi 9dc71be404 fix: correct friendly model table typing
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:30:15 +00:00
Cursor AgentandSimon Shi aaac381d76 refactor: use friendly model ids globally
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:29:52 +00:00
Cursor AgentandSimon Shi ca17a95270 test: correct fixture and abort harness
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:28:09 +00:00
Cursor AgentandSimon Shi 3d7df5d1e4 test: cover provider adapter scenarios
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:27:32 +00:00
Cursor AgentandSimon Shi 6d5cdfd171 test: add redacted Qoder protocol recorder and replays
Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:14:37 +00:00
Cursor AgentandSimon Shi 1eee02455c fix: bump COSY client identity to qodercli 1.1.38
Older Cosy-Version / cosyVersion values cause the model catalog and
gateway to treat the client as a stale qodercli and return a reduced
list. Align QoderIDEVersion with current CLI 1.1.38.

Leave PAT exchange and userinfo Cosy-Version at 1.0.1: those openapi
endpoints do not use a COSY signature, and I could not verify that
official qodercli 1.1.38 changed them.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 16:07:41 +00:00
Cursor AgentandSimon Shi e7b5990e5c ci: build and test on Node 24
@earendil-works/pi-coding-agent, pi-ai and the undici they pull in all
declare engines node >=22.19.0, so CI's Node 20 was below the floor: the
newly added test step failed loading pi-coding-agent with
"webidl.util.markAsUncloneable is not a function". Release already
publishes on Node 24.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 15:59:37 +00:00
Cursor AgentandSimon Shi 2d9e31ea4a ci: run the test suite
CI linted, typechecked and built but never ran vitest, so the suite could
break on main without anyone noticing.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 15:58:00 +00:00
Cursor AgentandSimon Shi 52f7752717 test: guard the published pi.extensions entry (#18, #21)
The npm tarball ships only dist/ and README.md, so the pi.extensions
"./src/index.ts" that shipped in 0.3.0 left Pi listing the package as
installed while never loading the provider. main already points at
./dist/index.js (6d9635e), but nothing stopped it regressing again -- it
had already flipped once in 1b110a6.

Assert the entry is ./dist/index.js and, more generally, that every
pi.extensions path falls inside the published files set.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 15:57:56 +00:00
Cursor AgentandSimon Shi 1e44cde685 fix(models): use the 1M context window Qoder actually supports (#13)
auto, efficient and lite carried a 180K contextWindow, so pi showed >100%
context usage and auto-compacted early. Live testing in #13 drove global
lite to 1,000K tokens successfully, so the 180K value was a stale
max_input_tokens floor rather than a real limit.

Introduce DEFAULT_CONTEXT_WINDOW (1M) and use it for the global static
models, including gm51model. Apply it as the catalog fallback too, but only
when /model/list advertises no context_config: models that do advertise a
smaller window (kmodel at 256K, CN GLM-5.2 and MiniMax at 200K) keep it
rather than being inflated to 1M. CN Auto stays at 200K since only global
lite was verified at 1M.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 15:57:49 +00:00
Cursor AgentandSimon Shi 1dd1b0988b test: isolate suites from the real ~/.pi and from each other
Several suites read and write ~/.pi/agent/{auth,qoder-models-cache}.json.
Vitest runs files in parallel, so one file could truncate a file another
was reading, and a run also clobbered the developer's own ~/.pi state.
Give each test file its own HOME.

Isolation exposed a latent coupling in the stream suite: with no resolved
identity on disk, streamQoder fetches /userinfo first and consumes the
single mocked Response, so the chat read failed on a locked stream. The
suite only passed because another file left credentials behind. Stub the
identity so the mock only ever serves the chat request.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 15:57:41 +00:00
Cursor AgentandSimon Shi e98526a8cd fix(types): restore npm run check
pi-coding-agent 0.84 no longer exports AuthStorage, so the named import
failed to compile even though the call site already guarded for its
absence. Read it off the module namespace instead, keeping the auth-file
fallback when the export is missing.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 15:57:26 +00:00
Cursor AgentandSimon Shi 70fba627e6 fix(lint): clear biome errors breaking CI on main
CI was red at the lint step: an unused providerID parameter in
createQoderOAuth, an unused getCachedCredentials import in stream.ts,
plus unsorted imports and stale formatting in stream.ts and pat.ts.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
2026-08-31 15:57:20 +00:00
Simon ShiandGitHub ab378b44e2 Merge pull request #16 from simonsmh/dependabot/npm_and_yarn/npm_and_yarn-0e29347d1a
build(deps): bump undici from 8.5.0 to 8.9.0 in the npm_and_yarn group across 1 directory
2026-08-31 23:44:05 +08:00
Simon ShiandGitHub 756be0159b Merge pull request #19 from huangxingx/fix/qoder-cn-login-windows-build
fix: qoder-cn chat identity, content normalization, and Windows build
2026-08-31 23:43:49 +08:00
Simon ShiandGitHub 6a0d08c04c Merge branch 'main' into fix/qoder-cn-login-windows-build 2026-08-31 23:43:40 +08:00
Simon ShiandGitHub 3e66ceb1a8 Merge pull request #20 from snufkintomo/fix/done-sentinel-hang-and-orphaned-tool-results
fix: end the stream at [DONE] and drop orphaned tool results
2026-08-31 23:42:52 +08:00
Simon ShiandGitHub d8fc2cb234 Merge pull request #22 from Loongphy/feat/cn-model-id-as-display
fix(cn): track upstream model catalog dynamically, forward reasoning effort, raise output to 128K
2026-08-31 23:42:35 +08:00
Loongphy 76c3b7201b feat: raise max output tokens to 128K (documented upstream ceiling)
Aliyun Model Studio (the upstream behind Qoder's CN catalog) documents
Max Output Length = 131072 for every model we expose, in both normal and
thinking modes (thinking chain alone goes to 262144):
  qwen3.8-max/flash, qwen3.7-max/plus/flash — all 131072.

The previous 32768 default (copied from qodercli's conservative 32e3) used
only 1/4 of the supported output budget. That truncates reasoning chains in
thinking mode (where the chain counts against output) and risks cutting long
generations / compaction summaries. qodercli caps its own UI at 65536, still
below the documented ceiling.

- models.ts: introduce MAX_OUTPUT_TOKENS = 131072 as the single source of
  truth; all 24 staticModels entries + the lazy-loaded CN entry now reference
  it. Remove the dead max_output_tokens field from the CN placeholder entry.
- stream.ts: maxTokens defaults to MAX_OUTPUT_TOKENS; still capped lower by
  options.maxTokens (e.g. pi compaction passes 40000).

Verified against the real CN endpoint: max_tokens=131072 returns 200 / stop
(accepted, not rejected); an xhigh reasoning run completes with
finish_reason=stop (not truncated). Field placement + reasoning_effort send
also confirmed working in the same request.
2026-08-28 19:36:59 +08:00
Loongphy 112da4deaf refactor: drop dead max_output_tokens, simplify maxTokens to 32K + pi cap
Qoder's /model/list catalog never returns max_output_tokens (the field does
not exist on any entry — only max_input_tokens is present), so the per-model
lookup `entry.max_output_tokens || 32768` was dead code that always fell back
to the 32768 literal.

- models.ts: remove max_output_tokens from QoderModelEntry; maxTokens is now a
  flat 32768 (matches qodercli's 32e3 fallback).
- stream.ts: remove the now-unused maxOutputTokens variable and its always-true
  branch; maxTokens = 32768, capped lower only by options.maxTokens (e.g. pi
  compaction passes 40000). pi-ai's maxTokens setting still has an outlet.
- stream.ts fallback modelConfig: drop the dead max_output_tokens: 32768 field.

qodercli does conditionally send max_tokens (user setting → generation config
→ 32K fallback), but the field is not required by the upstream API. Keeping it
gives pi-ai's options.maxTokens a place to flow through.
2026-08-28 19:07:16 +08:00
Loongphy 5393c24b7e feat: send reasoning_effort + enable_thinking to Qoder upstream
The picker was fixed to show thinking levels, but the chosen level was never
forwarded: stream.ts only used options.reasoning to toggle the local thinking
parser, so every request let the model default-decide its reasoning effort.

Reverse-engineered @qoder-ai/qodercli (bundle/qodercli.js) to confirm the
request shape: the chat body's `parameters` object carries `reasoning_effort`
("none"|"low"|"medium"|"high"|"xhigh"|"max") and `enable_thinking` (bool)
alongside `max_tokens`. qodercli's Zlr() sets reasoning_effort = zN(req)
(reasoning.enabled===false ? "none" : reasoning.effort) and enable_thinking.

Implementation follows the pi-ai OpenAI provider pattern:
  - clampThinkingLevel(model, options.reasoning) clamps the requested level to
    what the model advertises via thinkingLevelMap (returns "off" when
    unsupported or disabled);
  - map the clamped level to the upstream effort name via thinkingLevelMap,
    falling back to the pi level name (Qoder effort names already match pi);
  - effort-based models (thinking_config.enabled.efforts present, e.g.
    qwen3.8-max) get reasoning_effort + enable_thinking=true;
  - toggle-only models (qwen3.7-max: enabled/disabled, no efforts) get
    enable_thinking=true only — no reasoning_effort, since they accept no level;
  - no level / clamped to off: enable_thinking=false to explicitly disable.

Qoder has no "minimal" effort; clampThinkingLevel handles stepping it down
based on the model's thinkingLevelMap (minimal is pinned to null for effort
models, so it clamps to the next supported level).
2026-08-28 18:57:56 +08:00