mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-02 14:43:01 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a8ed8f588 | ||
|
|
4d76f2176b | ||
|
|
e4a49b414f | ||
|
|
fbd7890f78 | ||
|
|
83ae20ff06 | ||
|
|
9df005f602 | ||
|
|
d1a1eba23d | ||
|
|
133481d75c | ||
|
|
e640fe4281 | ||
|
|
43f7dc4ad1 | ||
|
|
f783c46301 | ||
|
|
2fddf0b98c | ||
|
|
593773a381 | ||
|
|
e4d4ba7489 | ||
|
|
1b5731cebe | ||
|
|
0f1ebda942 | ||
|
|
7a1eae245b | ||
|
|
3383ee80bc | ||
|
|
5cdbfef48b | ||
|
|
0c378889d1 | ||
|
|
8460e5126a | ||
|
|
51a87b98b9 | ||
|
|
427c2d0743 | ||
|
|
a8d539ca7c | ||
|
|
993eef1668 | ||
|
|
c2677a2690 | ||
|
|
f3c3461d67 | ||
|
|
85edc9da9c | ||
|
|
fd2315495f | ||
|
|
3a3300b69e | ||
|
|
0fef7414fc | ||
|
|
c0c181425f | ||
|
|
301b49e381 | ||
|
|
ee936d51c0 | ||
|
|
8e28e3988b | ||
|
|
62df2f3253 | ||
|
|
aba0c78449 | ||
|
|
a0754e9f9b | ||
|
|
9d8747cd3a | ||
|
|
13ad4a13ff | ||
|
|
9de8cbf2b8 | ||
|
|
2dd83e43cb | ||
|
|
ac6b5440e8 | ||
|
|
0da2781520 | ||
|
|
f487316a9d | ||
|
|
1ee149c85b | ||
|
|
72d488f17a | ||
|
|
8e83d9346a | ||
|
|
6c22bc72df | ||
|
|
bc00edf904 | ||
|
|
afce426a43 |
@@ -135,6 +135,32 @@ jobs:
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Backport electron-builder#10172 to the pinned build tool only.
|
||||
# Remove this step when app-builder-lib is upgraded to a release containing it.
|
||||
- name: Repair temporary keychain password in signing tool
|
||||
shell: bash
|
||||
run: |
|
||||
node <<'KEYCHAIN_FIX'
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const manifestPath = require.resolve('app-builder-lib/package.json');
|
||||
if (JSON.parse(fs.readFileSync(manifestPath, 'utf8')).version !== '26.8.1') {
|
||||
throw new Error('Reassess/remove the signing backport for the new app-builder-lib version');
|
||||
}
|
||||
const sourcePath = path.join(path.dirname(manifestPath), 'out/codeSign/macCodeSign.js');
|
||||
let source = fs.readFileSync(sourcePath, 'utf8');
|
||||
const replacements = [
|
||||
['importCerts(keychainFile, certPaths, cscPasswords)', 'importCerts(keychainFile, certPaths, cscPasswords, keychainPassword)'],
|
||||
['importCerts(keychainFile, paths, keyPasswords)', 'importCerts(keychainFile, paths, keyPasswords, keychainPassword)'],
|
||||
['["set-key-partition-list", "-S", "apple-tool:,apple:", "-s", "-k", password, keychainFile]', '["set-key-partition-list", "-S", "apple-tool:,apple:", "-s", "-k", keychainPassword, keychainFile]'],
|
||||
];
|
||||
for (const [before, after] of replacements) {
|
||||
if (source.split(before).length !== 2) throw new Error('Unexpected signing tool source; refusing to patch');
|
||||
source = source.replace(before, after);
|
||||
}
|
||||
fs.writeFileSync(sourcePath, source);
|
||||
KEYCHAIN_FIX
|
||||
|
||||
- name: Set desktop package version from tag
|
||||
shell: bash
|
||||
run: |
|
||||
|
||||
@@ -406,7 +406,10 @@
|
||||
{
|
||||
"files": [
|
||||
"packages/app/src/app/_layout.tsx",
|
||||
"packages/app/src/app/pair-scan.tsx",
|
||||
"packages/app/src/components/adaptive-modal-sheet.tsx",
|
||||
"packages/app/src/components/add-host-method-modal.tsx",
|
||||
"packages/app/src/components/add-host-modal.tsx",
|
||||
"packages/app/src/components/agent-list.tsx",
|
||||
"packages/app/src/components/agent-status-dot.tsx",
|
||||
"packages/app/src/components/attachment-lightbox.tsx",
|
||||
@@ -425,6 +428,7 @@
|
||||
"packages/app/src/components/hosts/host-picker.tsx",
|
||||
"packages/app/src/components/icons/paseo-logo.tsx",
|
||||
"packages/app/src/components/left-sidebar.tsx",
|
||||
"packages/app/src/components/pair-link-modal.tsx",
|
||||
"packages/app/src/components/plan-card.tsx",
|
||||
"packages/app/src/components/provider-diagnostic-sheet.tsx",
|
||||
"packages/app/src/components/question-form-card.tsx",
|
||||
@@ -539,10 +543,14 @@
|
||||
"packages/app/src/agent-skills/selection-sheet.tsx",
|
||||
"packages/app/src/agent-stream/chat-outline/rail.web.tsx",
|
||||
"packages/app/src/agent-stream/view.tsx",
|
||||
"packages/app/src/app/pair-scan.tsx",
|
||||
"packages/app/src/changelog/internal/changelog-sheet.tsx",
|
||||
"packages/app/src/command-center/command-center.tsx",
|
||||
"packages/app/src/components/adaptive-modal-sheet.tsx",
|
||||
"packages/app/src/components/add-host-method-modal.tsx",
|
||||
"packages/app/src/components/add-host-modal.tsx",
|
||||
"packages/app/src/components/add-project-flow.tsx",
|
||||
"packages/app/src/components/add-remote-ssh-host-modal.tsx",
|
||||
"packages/app/src/components/agent-list.tsx",
|
||||
"packages/app/src/components/app-diagnostic-sheet.tsx",
|
||||
"packages/app/src/components/attachment-lightbox.tsx",
|
||||
|
||||
@@ -74,10 +74,7 @@ registrations remain inspectable; a changed destination requires explicit identi
|
||||
|
||||
Both daemons advertise `connectedHosts`; the shared link additionally requires `hostMultiplexing`.
|
||||
A completes capability and pinned-identity checks on each physical recovery before admitting channels. There is no local fallback. An older daemon continues to serve existing local
|
||||
operations; requesting this feature gives update guidance. The registry retries an older destination
|
||||
with capped backoff, so it comes online once updated. Self, duplicate, changed-identity, and
|
||||
authentication failures stay in `error` until an update changes the connection, `enabled`, or
|
||||
`replaceIdentity`, or A restarts.
|
||||
operations; requesting this feature gives update guidance.
|
||||
|
||||
Disposing a routed API releases its observations and session. It does not remove the saved host or
|
||||
affect sibling API scopes. Disposing the origin cascades to its derived scopes. Observations restore
|
||||
|
||||
+4
-4
@@ -35,7 +35,7 @@ The authored interface ramp uses a 14px base. New native installs default to 15p
|
||||
Weight has three tiers, applied by role:
|
||||
|
||||
- **Screen titles** — the title in app chrome — use `<ScreenTitle>` (`packages/app/src/components/headers/screen-title.tsx`), which renders `fontSize.base` at weight `400` on compact and `300` on desktop. The New workspace hero is the only larger product title; it uses `fontSize["2xl"]` (`packages/app/src/screens/new-workspace-screen.tsx`).
|
||||
- **Structural labels** use `fontWeight.medium`. This applies to section labels above a stack of rows (`packages/app/src/components/agent-list.tsx:519-523`, `packages/app/src/components/keyboard-shortcuts-dialog.tsx:63-67`), form field labels above an input inside a modal (`packages/app/src/hosts/add-host/internal/add-host-modal.tsx:19-23`, `packages/app/src/hosts/add-host/internal/pair-link-modal.tsx:24-28`), the title at the top of a modal/sheet/dialog (`packages/app/src/components/adaptive-modal-sheet.tsx:90-94`, `packages/app/src/components/ui/combobox.tsx:1607-1611`, `packages/app/src/components/welcome-screen.tsx:48-53`), action button labels in tight components such as the sidebar callout actions (`packages/app/src/components/sidebar-callout.tsx:218-221`), and inline data emphasis on dense metadata rows (`packages/app/src/components/git-diff-pane.tsx:2322-2327`, `packages/app/src/components/file-explorer-pane.tsx:1115-1122`).
|
||||
- **Structural labels** use `fontWeight.medium`. This applies to section labels above a stack of rows (`packages/app/src/components/agent-list.tsx:519-523`, `packages/app/src/components/keyboard-shortcuts-dialog.tsx:63-67`), form field labels above an input inside a modal (`packages/app/src/components/add-host-modal.tsx:19-23`, `packages/app/src/components/pair-link-modal.tsx:24-28`), the title at the top of a modal/sheet/dialog (`packages/app/src/components/adaptive-modal-sheet.tsx:90-94`, `packages/app/src/components/ui/combobox.tsx:1607-1611`, `packages/app/src/components/welcome-screen.tsx:48-53`), action button labels in tight components such as the sidebar callout actions (`packages/app/src/components/sidebar-callout.tsx:218-221`), and inline data emphasis on dense metadata rows (`packages/app/src/components/git-diff-pane.tsx:2322-2327`, `packages/app/src/components/file-explorer-pane.tsx:1115-1122`).
|
||||
- **Content** uses `fontWeight.normal`. This applies to settings rows (`packages/app/src/styles/settings.ts`), sidebar primary list-item titles (`packages/app/src/components/sidebar-workspace-list.tsx:2680-2686`, `packages/app/src/components/agent-list.tsx:572-578`), `<Button>` text (`packages/app/src/components/ui/button.tsx:80-84`), `<StatusBadge>` text (`packages/app/src/components/ui/status-badge.tsx:56-60`), and `<SidebarCallout>` titles (`packages/app/src/components/sidebar-callout.tsx:175-180`).
|
||||
|
||||
The rule, condensed: text that _names_ a surface or a group is `medium`. Text that lives _inside_ a surface or a group is `normal`. Top-of-screen titles are `<ScreenTitle>`, which is lighter still.
|
||||
@@ -102,7 +102,7 @@ Five primitives. The pick is determined by option count, the need to search, and
|
||||
|
||||
`<ContextMenu>` is for right-click and long-press on a target. The row is the trigger; there is no visible affordance. Used for incidental actions on workspace rows in the sidebar (`packages/app/src/components/sidebar-workspace-list.tsx`).
|
||||
|
||||
`<AdaptiveModalSheet>` is for a focused task. Multi-field forms (`packages/app/src/hosts/add-host/internal/add-host-modal.tsx`, `packages/app/src/hosts/add-host/internal/pair-link-modal.tsx`, `packages/app/src/components/project-picker-modal.tsx`), confirmations with detail, anything that earns a backdrop. Bottom sheet on compact, centered card on desktop. Raw `Modal` is wrong for any of these.
|
||||
`<AdaptiveModalSheet>` is for a focused task. Multi-field forms (`packages/app/src/components/add-host-modal.tsx`, `packages/app/src/components/pair-link-modal.tsx`, `packages/app/src/components/project-picker-modal.tsx`), confirmations with detail, anything that earns a backdrop. Bottom sheet on compact, centered card on desktop. Raw `Modal` is wrong for any of these.
|
||||
|
||||
`<AdaptiveModalSheet>` owns the presentation. Its content inset — the gutter that puts sheet content on the same rails as the sheet header — and compact bottom safe-area padding are the sheet's, not the caller's. A caller declares layout intent through `contentStyle` and never branches on form factor to add its own margins. If a sheet's first snap point is shorter than its header, content, and safe-area clearance, raise that snap point rather than moving the sheet container.
|
||||
|
||||
@@ -114,7 +114,7 @@ Three themes is `DropdownMenu`. Thirty hosts is `Combobox`. A label and a value
|
||||
|
||||
## 7. Density and rhythm
|
||||
|
||||
Settings detail pages, the projects detail page, and any list+detail content sit inside a centered, max-width 720 column (`packages/app/src/screens/settings-screen.tsx`, `packages/app/src/screens/projects-screen.tsx`). Lines stay readable, the eye does not have to track wide horizontal distances. Form modals carry their own narrower content frame (`packages/app/src/hosts/add-host/internal/add-host-modal.tsx`).
|
||||
Settings detail pages, the projects detail page, and any list+detail content sit inside a centered, max-width 720 column (`packages/app/src/screens/settings-screen.tsx`, `packages/app/src/screens/projects-screen.tsx`). Lines stay readable, the eye does not have to track wide horizontal distances. Form modals carry their own narrower content frame (`packages/app/src/components/add-host-modal.tsx`).
|
||||
|
||||
Workspace and chat surfaces use the full width — these are working surfaces, not reading surfaces. The composer carries `MAX_CONTENT_WIDTH` from `packages/app/src/constants/layout.ts` to keep lines readable while letting the workspace pane fill the rest.
|
||||
|
||||
@@ -278,7 +278,7 @@ New status pills use `<StatusBadge>`. Identity, shortcut, and interactive link b
|
||||
| List+detail (compact stack, desktop sidebar+pane) | `packages/app/src/screens/settings-screen.tsx`, `packages/app/src/screens/projects-screen.tsx` |
|
||||
| Detail card+row | `packages/app/src/screens/settings/host-page.tsx`, `packages/app/src/screens/settings/providers-section.tsx` |
|
||||
| Section grouping inside a card list | `packages/app/src/screens/settings/settings-section.tsx` |
|
||||
| Form modal (label + input fields, primary + cancel) | `packages/app/src/hosts/add-host/internal/add-host-modal.tsx`, `packages/app/src/hosts/add-host/internal/pair-link-modal.tsx`, `packages/app/src/components/project-picker-modal.tsx` |
|
||||
| Form modal (label + input fields, primary + cancel) | `packages/app/src/components/add-host-modal.tsx`, `packages/app/src/components/pair-link-modal.tsx`, `packages/app/src/components/project-picker-modal.tsx` |
|
||||
| Destructive confirmation | `confirmDialog` invoked from `packages/app/src/screens/settings/host-page.tsx:541-547` |
|
||||
| Centered hero / first-run | `packages/app/src/components/welcome-screen.tsx` |
|
||||
| Sidebar list (workspaces, hosts) | `packages/app/src/components/sidebar-workspace-list.tsx`, `packages/app/src/components/left-sidebar.tsx` |
|
||||
|
||||
@@ -58,12 +58,6 @@ restore the same workspace and could repeat the crash.
|
||||
|
||||
## App-Wide Route Hops
|
||||
|
||||
Keep Add host in `hosts/add-host`, opened through `useAddHost()`. It is an in-place
|
||||
flow; callers choose what happens after success. Settings opts into the new host’s
|
||||
Overview. Do not send callers to Settings with an `addHost` query parameter: a
|
||||
retained route replays that request when appearance changes remount its content.
|
||||
The flow provider and sheet host stay outside appearance keys so open drafts survive.
|
||||
|
||||
When app-wide routes such as `/new`, `/settings`, or `/sessions` navigate back
|
||||
into a host workspace, use `navigateToWorkspace()`. Do not make the caller
|
||||
branch on its current route.
|
||||
|
||||
@@ -12,7 +12,7 @@ Every block is separated by one gap, `density.blockGap`: 12 on compact layouts,
|
||||
|
||||
Workspace file links use the shared file-link resolver. The workspace supplies its client, root and open-file action once; chat can supply the agent's more specific context. URLs use the same link press path. Recognized inline-code paths stay tappable. The library callback carries the tapped occurrence’s syntax context. Preserve it when opening files: explicit Markdown links decode URL escapes, while recognized inline-code paths preserve literal percent characters and use suffix lookup. Identical URL strings in different occurrences must stay distinct. Explicit absolute workspace links receive a relative hover title; existing authored titles remain intact.
|
||||
|
||||
Resolve workspace image paths over the existing session RPC, then give the library a cached native file URL or web blob URL. HTTP(S) images pass through unchanged. This preserves relay, SSH and local socket connections, which do not expose a daemon HTTP endpoint. Each mounted renderer owns its image acquisition identity, so a later reply reads a rewritten path again while the earlier mounted reply retains its snapshot. Image taps open the attachment lightbox. File previews resolve relative images against the Markdown file's directory. An image alone on its line becomes its own paragraph before the library sees it, so it renders as a block on every platform; the library only treats sole-child paragraph images as blocks, and with hard soft breaks every newline is a break node, which left own-line images inline on iOS and web. Images that share a line with text stay inline at line height and keep their aspect ratio. A linked image counts as an image, so review-bot badges such as `[](url) Confidence` stay inline on web; the library's web renderer only checked direct paragraph children, so it rendered them as full-width block images (local patch in `patches/react-native-enriched-markdown+*.patch`).
|
||||
Resolve workspace image paths over the existing session RPC, then give the library a cached native file URL or web blob URL. HTTP(S) images pass through unchanged. This preserves relay, SSH and local socket connections, which do not expose a daemon HTTP endpoint. Each mounted renderer owns its image acquisition identity, so a later reply reads a rewritten path again while the earlier mounted reply retains its snapshot. Image taps open the attachment lightbox. File previews resolve relative images against the Markdown file's directory. An image alone on its line becomes its own paragraph before the library sees it, so it renders as a block on every platform; the library only treats sole-child paragraph images as blocks, and with hard soft breaks every newline is a break node, which left own-line images inline on iOS and web. Images that share a line with text stay inline.
|
||||
|
||||
## Engine constraints
|
||||
|
||||
|
||||
+47
-3
@@ -30,6 +30,50 @@ at session startup. See [provider configuration](custom-providers.md#provider-op
|
||||
for defaults and merge rules, and the [SDK guide](../public-docs/sdk/provider-options.md)
|
||||
for native keys and examples.
|
||||
|
||||
### Options flow
|
||||
|
||||
`options` on the agent snapshot is the only option state. Controls describe how to draw an
|
||||
option and read `options`; they hold no value of their own. Any option can be read and set with
|
||||
or without a control.
|
||||
|
||||
- **Create and resume.** The provider opens with the options it is given and emits nothing about
|
||||
them while opening. `openOptionsPatch` carries every option the session ended up with that
|
||||
differs from what it was given, including a setting nobody asked for (a native default such as
|
||||
Cursor opening with Fast on). It is set before `createSession`/`resumeSession` resolves and the
|
||||
daemon stores it before the agent is published. A reopened agent resumes that state, so a
|
||||
native default the provider later changes does not follow. `options` on the snapshot is what
|
||||
the session opened with, and afterwards it moves only through an apply or an `options_changed`.
|
||||
Editing a provider default in `config.json` affects agents the next time they open.
|
||||
- **Live apply.** `applyOptions` receives the keys the patch touches, resolved against the
|
||||
`config.json` defaults. A removal arrives as the default the key falls back to, or `null` when
|
||||
there is none; the provider returns the setting to its own default if it can, or throws to
|
||||
reject. A key the running session cannot apply (one the provider reads only when it opens) is
|
||||
rejected too, so a stored option always describes what runs. Claude reads most options when it
|
||||
starts its query, and replacing a started query would end its background work, so after the
|
||||
first prompt only Fast can change. Codex fixes its approval policy and sandbox when the thread
|
||||
starts, so it applies only `service_tier` and `plan_mode` live. A session with no
|
||||
`applyOptions` rejects every patch; the daemon enforces this. The provider returns the options
|
||||
it ended up with when they differ from the request. The daemon
|
||||
stores the patch and that result in one step after the call resolves, onto the agent's options
|
||||
as they are at that moment, so the last write wins. Throwing rejects the whole patch and
|
||||
none of it is stored. Emit nothing from inside the call. If the provider's own state moved
|
||||
before it refused, it reports the moved values once as `options_changed` after the call has
|
||||
ended, because the stored options must match what runs.
|
||||
- **Old data converts in the agent manager.** Codex used to take `fast_mode`; it takes
|
||||
`service_tier` now. `AgentManager` runs `convertLegacyOptions` (`option-controls.ts`) on an
|
||||
agent's own options when it creates, resumes, imports, reloads or applies to it, and on draft
|
||||
controls, before defaults merge and before anything is stored (`true` is `"fast"`, `false` is
|
||||
`"default"`, and a `service_tier` in the same input wins). The manager converts for the adapter
|
||||
behind the provider id, following `derivedFromProviderId`, so a custom provider with
|
||||
`extends: "codex"` is converted too. Configured defaults convert in the provider registry. A
|
||||
stored record keeps `fast_mode` until the agent is next opened or applied to, and is stored
|
||||
converted from then on. Nothing past the manager sees `fast_mode` for Codex. Codex resolves
|
||||
`"fast"` to the model's Fast tier and reports the id it runs through `openOptionsPatch` or the
|
||||
`applyOptions` result like any other value. The `featureValues` to `options` fold is separate
|
||||
and provider-agnostic; it stays at the protocol and legacy edges.
|
||||
- **Provider-initiated changes.** A setting the provider changes on its own is an
|
||||
`options_changed` event. The daemon stores and forwards it and does not push the old value back.
|
||||
|
||||
Exact MCP preapproval is a separate daemon-owned contract. A new provider must fail
|
||||
closed for Hub unattended execution until it can approve one exact injected MCP
|
||||
server and tool identity without approving native tools.
|
||||
@@ -115,7 +159,7 @@ Submitted user-message wire items carry the same Paseo ID in `messageId` and `cl
|
||||
|
||||
Provider adapters must terminalize every transient timeline row before emitting the turn's terminal event. Codex may omit the completed `contextCompaction` item when a turn ends during compaction, so its adapter closes any pending root compaction before forwarding `turn_completed`, `turn_failed`, or `turn_canceled`. A terminal turn must never leave the client showing an operation as still loading.
|
||||
|
||||
Draft metadata lookups should avoid creating provider sessions when the upstream provider has top-level APIs for that metadata. Prefer `AgentClient.fetchCatalog`, `listCommands`, or `listFeatures` over creating a scratch `AgentSession`; scratch sessions can show up as empty native sessions in provider import/history UIs. `fetchCatalog` is the single discovery API for models and modes — provider implementations may use one process, separate upstream calls, or static data internally, but callers outside the provider do not get separate runtime model/mode probes. Draft command listing and scratch-session feature listing require an explicit draft model. Do not resolve a default model through catalog discovery. A client-level `listFeatures` implementation may return features from an incomplete, model-less draft and owns which features are valid in that state.
|
||||
Draft metadata lookups should avoid creating provider sessions when the upstream provider has top-level APIs for that metadata. Prefer `AgentClient.fetchCatalog`, `listCommands`, or `listControls` over creating a scratch `AgentSession`; scratch sessions can show up as empty native sessions in provider import/history UIs. `fetchCatalog` is the single discovery API for models and modes — provider implementations may use one process, separate upstream calls, or static data internally, but callers outside the provider do not get separate runtime model/mode probes. Draft command listing and scratch-session control listing require an explicit draft model. Do not resolve a default model through catalog discovery. A client-level `listControls` implementation may return controls from an incomplete, model-less draft and owns which features are valid in that state.
|
||||
|
||||
Provider session import has its own contract. The picker calls `listImportableSessions` and receives rows only: provider handle, cwd, title, prompt previews, and last activity. Import calls `importSession({ providerHandleId, cwd })` for the selected row and must not call listing again. The provider returns the resumed session, storage config, persistence handle, and hydrated timeline for that one native session; `AgentManager.importProviderSession` seeds the daemon timeline and publishes the Paseo agent only after it is ready.
|
||||
|
||||
@@ -478,7 +522,7 @@ interface AgentSession {
|
||||
readonly provider: AgentProvider;
|
||||
readonly id: string | null;
|
||||
readonly capabilities: AgentCapabilityFlags;
|
||||
readonly features?: AgentFeature[];
|
||||
readonly controls?: AgentOptionControl[];
|
||||
run(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<AgentRunResult>;
|
||||
startTurn(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<{ turnId: string }>;
|
||||
steerActiveTurn?(prompt: AgentPromptInput, options: SteerActiveTurnOptions): Promise<SteerResult>;
|
||||
@@ -500,7 +544,7 @@ interface AgentSession {
|
||||
listCommands?(): Promise<AgentSlashCommand[]>;
|
||||
setModel?(modelId: string | null): Promise<void>;
|
||||
setThinkingOption?(thinkingOptionId: string | null): Promise<void | AgentProviderNotice>;
|
||||
setFeature?(featureId: string, value: unknown): Promise<void>;
|
||||
applyOptions?(options: ProviderOptions): Promise<void>;
|
||||
tryHandleOutOfBand?(prompt: AgentPromptInput): {
|
||||
run(ctx: { emit: (event: AgentStreamEvent) => void }): Promise<void>;
|
||||
} | null;
|
||||
|
||||
@@ -127,7 +127,7 @@ buildNpmPackage {
|
||||
# The Nix output is not a distributable DMG, so leave it unsigned and
|
||||
# disable the hardened runtime that requires a matching signature.
|
||||
CSC_IDENTITY_AUTO_DISCOVERY=false \
|
||||
npm exec --offline -- electron-builder \
|
||||
../../node_modules/.bin/electron-builder \
|
||||
--config electron-builder.yml \
|
||||
--dir \
|
||||
--mac \
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
sha256-KN/AVZV/o0TleLLpmggSrdJqjFDJ/NJYVHiC54xb4jQ=
|
||||
sha256-CeT2PtYIAFwvBC9LIku8VkTl0pvKxYzSCn0QW2ManfU=
|
||||
|
||||
Generated
+1295
-1018
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,6 @@ import path from "node:path";
|
||||
import { test, expect } from "../support/fixtures";
|
||||
import {
|
||||
addProjectFlow,
|
||||
chooseAddHostFromProjectFlow,
|
||||
addProjectFlowBack,
|
||||
addProjectFlowHost,
|
||||
addProjectFlowInput,
|
||||
@@ -20,7 +19,6 @@ import {
|
||||
} from "../support/helpers/add-project-flow";
|
||||
import { gotoAppShell } from "../support/helpers/app";
|
||||
import {
|
||||
disconnectAllHostsAndReload,
|
||||
addConnectedHostAndReload,
|
||||
addConnectedHostsAndReload,
|
||||
addOfflineHostAndReload,
|
||||
@@ -71,19 +69,6 @@ async function expectProjectHasNoWorkspaces(projectId: string): Promise<void> {
|
||||
test.describe("Add Project command-center flow", () => {
|
||||
test.describe.configure({ timeout: 180_000 });
|
||||
|
||||
test("Add host replaces the project dialog when no hosts are connected", async ({ page }) => {
|
||||
await gotoAppShell(page);
|
||||
await disconnectAllHostsAndReload(page);
|
||||
await openAddProjectHostSelection(page);
|
||||
const originalUrl = page.url();
|
||||
await chooseAddHostFromProjectFlow(page);
|
||||
await expect(addProjectFlow(page)).toBeHidden();
|
||||
await expect(
|
||||
page.getByRole("button", { name: "Direct connection", exact: true }),
|
||||
).toBeVisible();
|
||||
await expect(page).toHaveURL(originalUrl);
|
||||
});
|
||||
|
||||
test("method selection shows the daemon's available project sources without search", async ({
|
||||
page,
|
||||
}) => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
composerLocator,
|
||||
expectComposerDraft,
|
||||
expectComposerVisible,
|
||||
fillComposerDraft,
|
||||
submitMessage,
|
||||
typeIntoFocusedComposer,
|
||||
} from "../support/helpers/composer";
|
||||
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
|
||||
@@ -12,14 +12,8 @@ function userMessages(page: Page) {
|
||||
return page.getByTestId("user-message");
|
||||
}
|
||||
|
||||
async function sendDraftWhenReady(page: Page) {
|
||||
await expect(page.getByRole("button", { name: "Send message", exact: true })).toBeEnabled();
|
||||
await pressInComposer(page, "Enter");
|
||||
}
|
||||
|
||||
async function sendAndWaitForMessage(page: Page, text: string, expectedCount: number) {
|
||||
await fillComposerDraft(page, text);
|
||||
await sendDraftWhenReady(page);
|
||||
await submitMessage(page, text);
|
||||
await expect(userMessages(page)).toHaveCount(expectedCount, { timeout: 30_000 });
|
||||
await expectComposerDraft(page, "");
|
||||
}
|
||||
@@ -55,7 +49,7 @@ test.describe("Composer recall", () => {
|
||||
await pressInComposer(page, "ArrowUp");
|
||||
await expectComposerDraft(page, "add tests for login");
|
||||
|
||||
await sendDraftWhenReady(page);
|
||||
await pressInComposer(page, "Enter");
|
||||
await expect(userMessages(page)).toHaveCount(3, { timeout: 30_000 });
|
||||
await expect(userMessages(page).last()).toContainText("add tests for login");
|
||||
} finally {
|
||||
|
||||
@@ -294,17 +294,10 @@ test("creates, renames, copies, and deletes entries through the file explorer",
|
||||
|
||||
await entry("renamed.txt").click({ button: "right" });
|
||||
const deleteAction = page.getByTestId(/file-explorer-row-\d+-delete$/);
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const labelColor = await deleteAction
|
||||
.getByText("Delete", { exact: true })
|
||||
.evaluate((element) => getComputedStyle(element).color);
|
||||
const iconColor = await deleteAction
|
||||
.locator("svg")
|
||||
.evaluate((element) => getComputedStyle(element).stroke);
|
||||
return labelColor !== "" && iconColor === labelColor;
|
||||
})
|
||||
.toBe(true);
|
||||
const deleteLabelColor = await deleteAction
|
||||
.getByText("Delete", { exact: true })
|
||||
.evaluate((element) => getComputedStyle(element).color);
|
||||
await expect(deleteAction.locator("svg")).toHaveCSS("stroke", deleteLabelColor);
|
||||
const cancelledConfirmation = new Promise<string>((resolve) => {
|
||||
page.once("dialog", async (dialog) => {
|
||||
const message = dialog.message();
|
||||
|
||||
@@ -122,14 +122,10 @@ test.describe("New workspace entry points", () => {
|
||||
});
|
||||
const hostTrigger = page.getByTestId("host-picker-trigger");
|
||||
await expect(hostTrigger).toContainText("localhost", { timeout: 30_000 });
|
||||
const originalUrl = page.url();
|
||||
await hostTrigger.click();
|
||||
await expect(page.getByTestId("new-workspace-host-picker-add-host")).toBeVisible();
|
||||
await page.getByTestId("new-workspace-host-picker-add-host").click();
|
||||
await expect(
|
||||
page.getByRole("button", { name: "Direct connection", exact: true }),
|
||||
).toBeVisible();
|
||||
await expect(page).toHaveURL(originalUrl);
|
||||
await expect(page).toHaveURL(/\/settings\/general\?addHost=/);
|
||||
} finally {
|
||||
await seeded.cleanup();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
import {
|
||||
openGlobalNewWorkspaceComposer,
|
||||
fillNewWorkspaceDraft,
|
||||
expectNewWorkspaceDraft,
|
||||
} from "../support/helpers/new-workspace";
|
||||
import { readFile, mkdir, rename, rm } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
@@ -278,71 +273,3 @@ test("restart recovery host controls persist the opt-out and custom prompt", asy
|
||||
await expectRestartRecoveryPrompt(page, "Continue the interrupted work.");
|
||||
await editRestartRecoveryPrompt(page, "Resume working.");
|
||||
});
|
||||
|
||||
test("sidebar Add host preserves its caller and stays closed after theme changes", async ({
|
||||
page,
|
||||
}) => {
|
||||
await gotoAppShell(page);
|
||||
await expect(page).toHaveURL(/\/open-project$/);
|
||||
const originalUrl = page.url();
|
||||
await openSidebarAddHost(page);
|
||||
await expect(page).toHaveURL(originalUrl);
|
||||
await closeAddHostAndChangeTheme(page);
|
||||
await expect(page.getByRole("button", { name: "Direct connection", exact: true })).toBeHidden();
|
||||
await expect(page).toHaveURL(originalUrl);
|
||||
});
|
||||
|
||||
async function openSidebarAddHost(page: import("@playwright/test").Page) {
|
||||
await page.getByRole("button", { name: "Hosts", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Add host", exact: true }).click();
|
||||
await expect(page.getByRole("button", { name: "Direct connection", exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
async function closeAddHostAndChangeTheme(page: import("@playwright/test").Page) {
|
||||
await page.getByRole("button", { name: "Close", exact: true }).click();
|
||||
await expect(page.getByRole("button", { name: "Direct connection", exact: true })).toBeHidden();
|
||||
await page.keyboard.press("Control+Alt+t");
|
||||
}
|
||||
|
||||
test("sidebar Add host completes without navigating", async ({ page }) => {
|
||||
await gotoAppShell(page);
|
||||
await expect(page).toHaveURL(/\/open-project$/);
|
||||
const originalUrl = page.url();
|
||||
await openSidebarAddHost(page);
|
||||
await connectToTestHost(page);
|
||||
await expect(page).toHaveURL(originalUrl);
|
||||
await expect(page.getByRole("button", { name: "Hosts", exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test("Settings Add host opens the saved host Overview", async ({ page }) => {
|
||||
await gotoAppShell(page);
|
||||
await openSettings(page);
|
||||
await addDirectHostFromSettings(page, { host: "127.0.0.1", port: Number(getE2EDaemonPort()) });
|
||||
await expectSettingsHeader(page, "Overview");
|
||||
await expect(page).toHaveURL(new RegExp(`/settings/hosts/${getServerId()}/host$`));
|
||||
});
|
||||
|
||||
test("New workspace Add host preserves the prompt after connecting", async ({ page }) => {
|
||||
await gotoAppShell(page);
|
||||
await openGlobalNewWorkspaceComposer(page);
|
||||
await fillNewWorkspaceDraft(page, "Keep this unfinished prompt while I add a host.");
|
||||
const originalUrl = page.url();
|
||||
await openNewWorkspaceAddHost(page);
|
||||
await expect(page).toHaveURL(originalUrl);
|
||||
await connectToTestHost(page);
|
||||
await expect(page).toHaveURL(originalUrl);
|
||||
await expectNewWorkspaceDraft(page, "Keep this unfinished prompt while I add a host.");
|
||||
});
|
||||
|
||||
async function openNewWorkspaceAddHost(page: import("@playwright/test").Page) {
|
||||
await page.getByTestId("host-picker-trigger").click();
|
||||
await page.getByRole("button", { name: "Add host", exact: true }).click();
|
||||
}
|
||||
|
||||
async function connectToTestHost(page: import("@playwright/test").Page) {
|
||||
await page.getByRole("button", { name: "Direct connection", exact: true }).click();
|
||||
await page.getByRole("textbox", { name: "Host", exact: true }).fill("127.0.0.1");
|
||||
await page.getByRole("textbox", { name: "Port", exact: true }).fill(String(getE2EDaemonPort()));
|
||||
await page.getByRole("button", { name: "Connect", exact: true }).click();
|
||||
await expect(page.getByTestId("add-host-modal")).toBeHidden({ timeout: 30_000 });
|
||||
}
|
||||
|
||||
@@ -113,7 +113,3 @@ export async function expectAddProjectResultVisible(page: Page, text: string): P
|
||||
})
|
||||
.toBe(true);
|
||||
}
|
||||
|
||||
export async function chooseAddHostFromProjectFlow(page: Page): Promise<void> {
|
||||
await page.getByRole("button", { name: /Add host.*No connected hosts/ }).click();
|
||||
}
|
||||
|
||||
@@ -273,25 +273,3 @@ export async function reloadPreservingHostRegistry(page: Page): Promise<void> {
|
||||
);
|
||||
await page.reload();
|
||||
}
|
||||
|
||||
export async function disconnectAllHostsAndReload(page: Page): Promise<void> {
|
||||
await page.evaluate(
|
||||
({ registryKey, nonceKey, disableSeedKey }) => {
|
||||
const nonce = localStorage.getItem(nonceKey);
|
||||
if (!nonce) throw new Error("Expected the e2e seed nonce");
|
||||
const hosts = JSON.parse(localStorage.getItem(registryKey) ?? "[]");
|
||||
for (const host of hosts) {
|
||||
host.connections = [{ id: "offline", type: "directTcp", endpoint: "127.0.0.1:59999" }];
|
||||
host.preferredConnectionId = "offline";
|
||||
}
|
||||
localStorage.setItem(registryKey, JSON.stringify(hosts));
|
||||
localStorage.setItem(disableSeedKey, nonce);
|
||||
},
|
||||
{
|
||||
registryKey: REGISTRY_KEY,
|
||||
nonceKey: SEED_NONCE_KEY,
|
||||
disableSeedKey: DISABLE_DEFAULT_SEED_ONCE_KEY,
|
||||
},
|
||||
);
|
||||
await page.reload();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { AddHostProvider, AddHostFlowHost } from "@/hosts/add-host";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { useActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
|
||||
import { useIsExplorerSidebarOpen } from "@/workspace-tabs/explorer-sidebar";
|
||||
@@ -466,7 +465,6 @@ function AppContainer({ children, chromeEnabled: chromeEnabledOverride }: AppCon
|
||||
const surface = (
|
||||
<View style={layoutStyles.surfaceFill}>
|
||||
{workspaceChrome}
|
||||
<AddHostFlowHost />
|
||||
<AppearanceStyleBoundary>
|
||||
{!isCompactLayout && appChromeLayout.sidebarToggleOwner === "window" ? (
|
||||
<WindowChromeRegion corners="top-left">
|
||||
@@ -807,6 +805,7 @@ function RootStack() {
|
||||
<Stack.Screen name="open-project" />
|
||||
<Stack.Screen name="sessions" />
|
||||
<Stack.Screen name="schedules" />
|
||||
<Stack.Screen name="pair-scan" />
|
||||
</Stack.Protected>
|
||||
<Stack.Screen name="h/[serverId]" />
|
||||
<Stack.Screen name="settings/hosts/[serverId]/index" />
|
||||
@@ -891,13 +890,11 @@ function RootAppTree() {
|
||||
<GestureHandlerRootView style={flexStyle}>
|
||||
<View style={layoutStyles.surfaceFill}>
|
||||
<LucideProvider strokeWidth={ICON_STROKE_WIDTH}>
|
||||
<AddHostProvider>
|
||||
<RootProviders>
|
||||
<RuntimeProviders>
|
||||
<AppShell />
|
||||
</RuntimeProviders>
|
||||
</RootProviders>
|
||||
</AddHostProvider>
|
||||
<RootProviders>
|
||||
<RuntimeProviders>
|
||||
<AppShell />
|
||||
</RuntimeProviders>
|
||||
</RootProviders>
|
||||
</LucideProvider>
|
||||
</View>
|
||||
</GestureHandlerRootView>
|
||||
|
||||
+59
-24
@@ -1,14 +1,17 @@
|
||||
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Text, View } from "react-native";
|
||||
import { Pressable, Text, View } from "react-native";
|
||||
import { useLocalSearchParams, useRouter, type Href } from "expo-router";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { CameraView, useCameraPermissions } from "expo-camera";
|
||||
import type { BarcodeScanningResult, BarcodeSettings } from "expo-camera";
|
||||
import { getHostRuntimeStore } from "@/runtime/host-runtime";
|
||||
import { openPairScan } from "./pair-scan-model";
|
||||
import { openPairScan } from "@/hosts/pair-scan-model";
|
||||
import { buildHostRootRoute, buildSettingsHostRoute } from "@/utils/host-routes";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
import { PairLinkModal } from "./pair-link-modal";
|
||||
import { BackHeader } from "@/components/headers/back-header";
|
||||
import { PairLinkModal } from "@/components/pair-link-modal";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
@@ -110,26 +113,50 @@ const styles = StyleSheet.create((theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
export function PairScanContent({
|
||||
onConnected,
|
||||
onClose,
|
||||
}: {
|
||||
onConnected: (serverId: string) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
export default function PairScanScreen() {
|
||||
const { theme } = useUnistyles();
|
||||
const { t } = useTranslation();
|
||||
const insets = useSafeAreaInsets();
|
||||
const router = useRouter();
|
||||
const params = useLocalSearchParams<{
|
||||
source?: string;
|
||||
}>();
|
||||
const source = typeof params.source === "string" ? params.source : "settings";
|
||||
|
||||
const [permission, requestPermission] = useCameraPermissions();
|
||||
|
||||
const navigateToPairedHost = useCallback(
|
||||
(serverId: string) => {
|
||||
if (source === "onboarding") {
|
||||
router.replace(buildHostRootRoute(serverId));
|
||||
return;
|
||||
}
|
||||
router.replace(buildSettingsHostRoute(serverId));
|
||||
},
|
||||
[router, source],
|
||||
);
|
||||
|
||||
const [scan] = useState(() =>
|
||||
openPairScan({
|
||||
importConnectionLink: (link) => getHostRuntimeStore().importConnectionLink(link, "hostRoot"),
|
||||
onConnected,
|
||||
importConnectionLink: (link) =>
|
||||
getHostRuntimeStore().importConnectionLink(
|
||||
link,
|
||||
source === "onboarding" ? "hostRoot" : "hostSettings",
|
||||
),
|
||||
onConnected: navigateToPairedHost,
|
||||
}),
|
||||
);
|
||||
const scanState = useSyncExternalStore(scan.subscribe, scan.getState, scan.getState);
|
||||
useEffect(() => () => scan.close(), [scan]);
|
||||
|
||||
const closeToSource = useCallback(() => {
|
||||
try {
|
||||
router.back();
|
||||
} catch {
|
||||
router.replace("/" as Href);
|
||||
}
|
||||
}, [router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isWeb) return;
|
||||
if (permission && permission.granted) return;
|
||||
@@ -142,29 +169,35 @@ export function PairScanContent({
|
||||
[scan],
|
||||
);
|
||||
|
||||
const handleRouterBack = useCallback(() => router.back(), [router]);
|
||||
const savePasswordPairing = useCallback(
|
||||
({ serverId }: { serverId: string }) => onConnected(serverId),
|
||||
[onConnected],
|
||||
({ serverId }: { serverId: string }) => navigateToPairedHost(serverId),
|
||||
[navigateToPairedHost],
|
||||
);
|
||||
const handleRequestPermission = useCallback(() => {
|
||||
void requestPermission();
|
||||
}, [requestPermission]);
|
||||
|
||||
const bodyStyle = useMemo(
|
||||
() => [styles.body, { paddingBottom: insets.bottom + 24 }],
|
||||
[insets.bottom],
|
||||
() => [styles.body, { paddingBottom: insets.bottom + theme.spacing[6] }],
|
||||
[insets.bottom, theme.spacing],
|
||||
);
|
||||
const helperTextStyle = useMemo(
|
||||
() => [styles.helperText, { color: theme.colors.foreground }],
|
||||
[theme.colors.foreground],
|
||||
);
|
||||
|
||||
if (isWeb) {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<BackHeader title={t("pairing.scan.title")} onBack={handleRouterBack} />
|
||||
<View style={bodyStyle}>
|
||||
<View style={styles.permissionCard}>
|
||||
<Text style={styles.permissionTitle}>{t("pairing.scan.webUnavailableTitle")}</Text>
|
||||
<Text style={styles.permissionBody}>{t("pairing.scan.webUnavailableBody")}</Text>
|
||||
<Button style={styles.permissionButton} onPress={onClose}>
|
||||
<Text style={styles.permissionButtonText}>{t("common.actions.back")}</Text>
|
||||
</Button>
|
||||
<Pressable style={styles.permissionButton} onPress={closeToSource}>
|
||||
<Text style={styles.permissionButtonText}>{t("pairing.scan.backToSettings")}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
@@ -175,14 +208,16 @@ export function PairScanContent({
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<BackHeader title={t("pairing.scan.title")} onBack={closeToSource} />
|
||||
|
||||
<View style={bodyStyle}>
|
||||
{!granted ? (
|
||||
<View style={styles.permissionCard}>
|
||||
<Text style={styles.permissionTitle}>{t("pairing.scan.cameraPermissionTitle")}</Text>
|
||||
<Text style={styles.permissionBody}>{t("pairing.scan.cameraPermissionBody")}</Text>
|
||||
<Button style={styles.permissionButton} onPress={handleRequestPermission}>
|
||||
<Pressable style={styles.permissionButton} onPress={handleRequestPermission}>
|
||||
<Text style={styles.permissionButtonText}>{t("pairing.scan.grantPermission")}</Text>
|
||||
</Button>
|
||||
</Pressable>
|
||||
</View>
|
||||
) : (
|
||||
<View style={styles.cameraWrap}>
|
||||
@@ -200,10 +235,10 @@ export function PairScanContent({
|
||||
<View style={[styles.corner, styles.cornerBR]} />
|
||||
</View>
|
||||
{scanState.status === "pairing" ? (
|
||||
<Text style={styles.helperText}>{t("pairing.scan.pairing")}</Text>
|
||||
<Text style={helperTextStyle}>{t("pairing.scan.pairing")}</Text>
|
||||
) : null}
|
||||
{scanState.status === "stopped" && scanState.error ? (
|
||||
<Text style={styles.helperText}>{scanState.error}</Text>
|
||||
<Text style={helperTextStyle}>{scanState.error}</Text>
|
||||
) : null}
|
||||
{scanState.status === "stopped" ? (
|
||||
<Button
|
||||
@@ -35,9 +35,10 @@ function SettingsDaemonRedirect() {
|
||||
}
|
||||
|
||||
export default function SettingsSectionRoute() {
|
||||
const params = useLocalSearchParams<{ section?: string }>();
|
||||
const params = useLocalSearchParams<{ section?: string; addHost?: string }>();
|
||||
const rawSection = typeof params.section === "string" ? params.section : "";
|
||||
const section: SettingsSectionSlug = isSettingsSectionSlug(rawSection) ? rawSection : "general";
|
||||
const openAddHostIntent = typeof params.addHost === "string" ? params.addHost : null;
|
||||
const view = useMemo(() => ({ kind: "section" as const, section }), [section]);
|
||||
|
||||
// COMPAT(settingsDaemonRedirect): added 2026-07-08, remove after 2027-01-08.
|
||||
@@ -49,5 +50,5 @@ export default function SettingsSectionRoute() {
|
||||
);
|
||||
}
|
||||
|
||||
return <SettingsScreen view={view} />;
|
||||
return <SettingsScreen view={view} openAddHostIntent={openAddHostIntent} />;
|
||||
}
|
||||
|
||||
+10
-11
@@ -1,10 +1,9 @@
|
||||
import { PressHighlight } from "@/components/ui/press-highlight";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Text, View } from "react-native";
|
||||
import { Pressable, Text, View } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { QrCode, Link2, ClipboardPaste, Terminal } from "lucide-react-native";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "./adaptive-modal-sheet";
|
||||
import { isFdroidBuild } from "@/constants/build-profile";
|
||||
import { isNative } from "@/constants/platform";
|
||||
import { isElectronRuntime } from "@/desktop/host";
|
||||
@@ -85,7 +84,7 @@ export function AddHostMethodModal({
|
||||
onClose={onClose}
|
||||
testID="add-host-method-modal"
|
||||
>
|
||||
<PressHighlight
|
||||
<Pressable
|
||||
style={styles.option}
|
||||
onPress={handleDirect}
|
||||
accessibilityRole="button"
|
||||
@@ -99,10 +98,10 @@ export function AddHostMethodModal({
|
||||
{t("pairing.connectionMethods.direct.description")}
|
||||
</Text>
|
||||
</View>
|
||||
</PressHighlight>
|
||||
</Pressable>
|
||||
|
||||
{isElectronRuntime() ? (
|
||||
<PressHighlight
|
||||
<Pressable
|
||||
style={styles.option}
|
||||
onPress={handleRemoteSsh}
|
||||
accessibilityRole="button"
|
||||
@@ -116,11 +115,11 @@ export function AddHostMethodModal({
|
||||
{t("pairing.connectionMethods.remoteSsh.description")}
|
||||
</Text>
|
||||
</View>
|
||||
</PressHighlight>
|
||||
</Pressable>
|
||||
) : null}
|
||||
|
||||
{isNative && !isFdroidBuild ? (
|
||||
<PressHighlight
|
||||
<Pressable
|
||||
style={styles.option}
|
||||
onPress={handleScan}
|
||||
accessibilityRole="button"
|
||||
@@ -133,10 +132,10 @@ export function AddHostMethodModal({
|
||||
{t("pairing.connectionMethods.scanQr.description")}
|
||||
</Text>
|
||||
</View>
|
||||
</PressHighlight>
|
||||
</Pressable>
|
||||
) : null}
|
||||
|
||||
<PressHighlight
|
||||
<Pressable
|
||||
style={styles.option}
|
||||
onPress={handlePaste}
|
||||
accessibilityRole="button"
|
||||
@@ -150,7 +149,7 @@ export function AddHostMethodModal({
|
||||
{t("pairing.connectionMethods.pasteLink.description")}
|
||||
</Text>
|
||||
</View>
|
||||
</PressHighlight>
|
||||
</Pressable>
|
||||
</AdaptiveModalSheet>
|
||||
);
|
||||
}
|
||||
+30
-47
@@ -1,22 +1,17 @@
|
||||
import { PressHighlight } from "@/components/ui/press-highlight";
|
||||
import { useCallback, useMemo, useReducer, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Alert, Text, View } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { Alert, Pressable, Text, View } from "react-native";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { Check, ChevronDown, ChevronRight, Eye, EyeOff, Link2 } from "lucide-react-native";
|
||||
import type { HostProfile } from "@/types/host-connection";
|
||||
import { useHosts, useHostMutations } from "@/runtime/host-runtime";
|
||||
import { parseConnectionUri, serializeConnectionUri } from "@/utils/daemon-endpoints";
|
||||
import { buildConnectionFailureCopy } from "@/components/connection-failure-copy";
|
||||
import {
|
||||
AdaptiveModalSheet,
|
||||
AdaptiveTextInput,
|
||||
type SheetHeader,
|
||||
} from "@/components/adaptive-modal-sheet";
|
||||
import { buildConnectionFailureCopy } from "./connection-failure-copy";
|
||||
import { AdaptiveModalSheet, AdaptiveTextInput, type SheetHeader } from "./adaptive-modal-sheet";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { PairingTargetTracker } from "@/components/pair-link-credentials";
|
||||
import { buildDirectConnectionUri } from "@/components/direct-connection-host";
|
||||
import { PairingTargetTracker } from "./pair-link-credentials";
|
||||
import { buildDirectConnectionUri } from "./direct-connection-host";
|
||||
|
||||
const FLEX_ONE_STYLE = { flex: 1 } as const;
|
||||
|
||||
@@ -193,6 +188,7 @@ export function AddHostModal({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
}
|
||||
|
||||
function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostModalProps) {
|
||||
const { theme } = useUnistyles();
|
||||
const { t } = useTranslation();
|
||||
const daemons = useHosts();
|
||||
const { probeAndUpsertDirectConnection, beginLinkPairing } = useHostMutations();
|
||||
@@ -211,7 +207,10 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
const [inputResetKey, bumpInputResetKey] = useReducer((key: number) => key + 1, 0);
|
||||
const advancedTarget = useRef(new PairingTargetTracker("", true));
|
||||
|
||||
const connectIcon = useMemo(() => <ThemedLink2 size={16} />, []);
|
||||
const connectIcon = useMemo(
|
||||
() => <Link2 size={16} color={theme.colors.accentForeground} />,
|
||||
[theme.colors.accentForeground],
|
||||
);
|
||||
const hostFieldStyle = useMemo(() => [styles.field, styles.hostField], []);
|
||||
const portFieldStyle = useMemo(() => [styles.field, styles.portField], []);
|
||||
const checkboxStyle = useMemo(
|
||||
@@ -416,8 +415,8 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
setIsAdvancedOpen(false);
|
||||
}, [advancedUri, directConnectionLabels, host, isAdvancedOpen, password, port, useTls]);
|
||||
|
||||
const AdvancedIcon = isAdvancedOpen ? ThemedChevronDown : ThemedChevronRight;
|
||||
const PasswordIcon = isPasswordVisible ? ThemedEyeOff : ThemedEye;
|
||||
const AdvancedIcon = isAdvancedOpen ? ChevronDown : ChevronRight;
|
||||
const PasswordIcon = isPasswordVisible ? EyeOff : Eye;
|
||||
|
||||
return (
|
||||
<AdaptiveModalSheet
|
||||
@@ -431,7 +430,7 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
<View style={styles.portRow}>
|
||||
<View style={hostFieldStyle}>
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.host")}</Text>
|
||||
<ThemedAdaptiveTextInput
|
||||
<AdaptiveTextInput
|
||||
testID="direct-host-input"
|
||||
nativeID="direct-host-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.host")}
|
||||
@@ -439,6 +438,7 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
resetKey={`direct-host-${inputResetKey}`}
|
||||
onChangeText={setHost}
|
||||
placeholder="localhost"
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
style={styles.input}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
@@ -449,7 +449,7 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
</View>
|
||||
<View style={portFieldStyle}>
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.port")}</Text>
|
||||
<ThemedAdaptiveTextInput
|
||||
<AdaptiveTextInput
|
||||
testID="direct-port-input"
|
||||
nativeID="direct-port-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.port")}
|
||||
@@ -457,6 +457,7 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
resetKey={`direct-port-${inputResetKey}`}
|
||||
onChangeText={setPort}
|
||||
placeholder="6767"
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
style={styles.input}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
@@ -468,7 +469,7 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<PressHighlight
|
||||
<Pressable
|
||||
style={styles.checkboxRow}
|
||||
onPress={handleToggleUseTls}
|
||||
disabled={isSaving}
|
||||
@@ -481,17 +482,17 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
<View style={checkboxStyle}>
|
||||
{useTls ? (
|
||||
<View testID="direct-ssl-toggle-checked">
|
||||
<ThemedCheck size={14} />
|
||||
<Check size={14} color={theme.colors.accentForeground} />
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.useSsl")}</Text>
|
||||
</PressHighlight>
|
||||
</Pressable>
|
||||
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.password")}</Text>
|
||||
<View style={styles.passwordRow}>
|
||||
<ThemedAdaptiveTextInput
|
||||
<AdaptiveTextInput
|
||||
testID="direct-password-input"
|
||||
nativeID="direct-password-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.password")}
|
||||
@@ -499,6 +500,7 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
resetKey={`direct-password-${inputResetKey}`}
|
||||
onChangeText={setPassword}
|
||||
placeholder={t("pairing.direct.fields.optional")}
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
style={passwordInputStyle}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
@@ -507,7 +509,7 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={handleSubmitEditing}
|
||||
/>
|
||||
<PressHighlight
|
||||
<Pressable
|
||||
style={styles.iconButton}
|
||||
onPress={handleTogglePasswordVisibility}
|
||||
disabled={isSaving}
|
||||
@@ -519,13 +521,13 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
}
|
||||
testID="direct-password-visibility-toggle"
|
||||
>
|
||||
<PasswordIcon size={18} />
|
||||
</PressHighlight>
|
||||
<PasswordIcon size={18} color={theme.colors.foregroundMuted} />
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View style={styles.field}>
|
||||
<PressHighlight
|
||||
<Pressable
|
||||
style={styles.advancedToggle}
|
||||
onPress={handleToggleAdvanced}
|
||||
disabled={isSaving}
|
||||
@@ -535,11 +537,11 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
}
|
||||
testID="direct-host-advanced-toggle"
|
||||
>
|
||||
<AdvancedIcon size={16} />
|
||||
<AdvancedIcon size={16} color={theme.colors.foregroundMuted} />
|
||||
<Text style={styles.advancedText}>{t("pairing.direct.advanced.label")}</Text>
|
||||
</PressHighlight>
|
||||
</Pressable>
|
||||
{isAdvancedOpen ? (
|
||||
<ThemedAdaptiveTextInput
|
||||
<AdaptiveTextInput
|
||||
testID="direct-host-uri-input"
|
||||
nativeID="direct-host-uri-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.connectionUri")}
|
||||
@@ -547,6 +549,7 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
resetKey={`direct-host-uri-${inputResetKey}`}
|
||||
onChangeText={handleChangeAdvancedUri}
|
||||
placeholder="tcp://localhost:6767?ssl=true"
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
style={styles.input}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
@@ -582,23 +585,3 @@ function AddHostModalContent({ visible, onClose, onCancel, onSaved }: AddHostMod
|
||||
</AdaptiveModalSheet>
|
||||
);
|
||||
}
|
||||
|
||||
const ThemedLink2 = withUnistyles(Link2, (theme) => ({ color: theme.colors.accentForeground }));
|
||||
|
||||
const ThemedCheck = withUnistyles(Check, (theme) => ({ color: theme.colors.accentForeground }));
|
||||
|
||||
const ThemedChevronDown = withUnistyles(ChevronDown, (theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
}));
|
||||
|
||||
const ThemedChevronRight = withUnistyles(ChevronRight, (theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
}));
|
||||
|
||||
const ThemedEye = withUnistyles(Eye, (theme) => ({ color: theme.colors.foregroundMuted }));
|
||||
|
||||
const ThemedEyeOff = withUnistyles(EyeOff, (theme) => ({ color: theme.colors.foregroundMuted }));
|
||||
|
||||
const ThemedAdaptiveTextInput = withUnistyles(AdaptiveTextInput, (theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
}));
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useAddHost } from "@/hosts/add-host";
|
||||
import { Modal } from "@/components/ui/modal";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { getHostRuntimeStore } from "@/runtime/host-runtime";
|
||||
@@ -93,7 +92,7 @@ import { useRecommendedProjectPaths } from "@/stores/session-store-hooks";
|
||||
import type { AddProjectFlowRequest } from "@/stores/add-project-flow-store";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import { shortenPath } from "@/utils/shorten-path";
|
||||
import { buildNewWorkspaceRoute } from "@/utils/host-routes";
|
||||
import { buildNewWorkspaceRoute, buildSettingsAddHostRoute } from "@/utils/host-routes";
|
||||
|
||||
interface AddProjectFlowProps {
|
||||
request: AddProjectFlowRequest;
|
||||
@@ -326,7 +325,6 @@ function setPageStatus(
|
||||
// The product flow is intentionally one cohesive page-stack state machine.
|
||||
// eslint-disable-next-line complexity
|
||||
export function AddProjectFlow({ request, onClose }: AddProjectFlowProps) {
|
||||
const addHost = useAddHost();
|
||||
const hosts = useHosts();
|
||||
const hostIds = useMemo(() => hosts.map((host) => host.serverId), [hosts]);
|
||||
const connectionStatuses = useHostRuntimeConnectionStatuses(hostIds);
|
||||
@@ -618,9 +616,9 @@ export function AddProjectFlow({ request, onClose }: AddProjectFlowProps) {
|
||||
icon: Plus,
|
||||
testID: "add-project-flow-add-host",
|
||||
select: () => {
|
||||
// The native project Modal must release its window before the root sheet opens.
|
||||
onClose();
|
||||
addHost();
|
||||
usePanelStore.getState().showMobileAgent();
|
||||
router.push(buildSettingsAddHostRoute(Date.now()));
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -719,7 +717,6 @@ export function AddProjectFlow({ request, onClose }: AddProjectFlowProps) {
|
||||
directoryPaths,
|
||||
githubQuery.data,
|
||||
host,
|
||||
addHost,
|
||||
onClose,
|
||||
openAddedProject,
|
||||
page,
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
import { PressHighlight } from "@/components/ui/press-highlight";
|
||||
import { useCallback, useMemo, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Pressable,
|
||||
Text,
|
||||
View,
|
||||
type PressableStateCallbackType,
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { DaemonConnectionTestError } from "@/utils/test-daemon-connection";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "./adaptive-modal-sheet";
|
||||
|
||||
const FLEX_ONE_STYLE = { flex: 1 } as const;
|
||||
const ThemedTerminal = withUnistyles(Terminal);
|
||||
@@ -174,11 +174,11 @@ export function AddRemoteSshHostModal({
|
||||
}
|
||||
|
||||
clear();
|
||||
onClose();
|
||||
onSaved?.({
|
||||
...result,
|
||||
isNewHost: !hosts.some((profile) => profile.serverId === result.serverId),
|
||||
});
|
||||
onClose();
|
||||
}, [clear, hosts, isSaving, onClose, onSaved, probeAndUpsertRemoteSshConnection, t]);
|
||||
const handleTargetChange = useCallback((value: string) => {
|
||||
targetRef.current = value;
|
||||
@@ -260,7 +260,7 @@ export function AddRemoteSshHostModal({
|
||||
onSubmitEditing={handleSubmit}
|
||||
/>
|
||||
</View>
|
||||
<PressHighlight
|
||||
<Pressable
|
||||
style={iconButtonStyle}
|
||||
onPress={handleTogglePasswordVisibility}
|
||||
disabled={isSaving}
|
||||
@@ -273,7 +273,7 @@ export function AddRemoteSshHostModal({
|
||||
testID="remote-ssh-password-visibility-toggle"
|
||||
>
|
||||
{isPasswordVisible ? <ThemedEyeOff size={18} /> : <ThemedEye size={18} />}
|
||||
</PressHighlight>
|
||||
</Pressable>
|
||||
</View>
|
||||
</Field>
|
||||
<View style={styles.actions}>
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useAddHost } from "@/hosts/add-host";
|
||||
import { router } from "expo-router";
|
||||
import {
|
||||
CircleGauge,
|
||||
@@ -63,7 +62,7 @@ import { usePanelStore } from "@/stores/panel-store";
|
||||
import { useOwnsWindowChromeCorner, WindowChromeSafeArea } from "@/utils/desktop-window";
|
||||
import { useCloseAgentListGesture } from "@/mobile-panels/gestures";
|
||||
import { MobilePanelOverlay } from "@/mobile-panels/presentation";
|
||||
import { buildSettingsRoute } from "@/utils/host-routes";
|
||||
import { buildSettingsAddHostRoute, buildSettingsRoute } from "@/utils/host-routes";
|
||||
import { openHostOverview } from "@/navigation/settings-navigation";
|
||||
import { UsageSidebarItem, UsageSidebarRoot, useUsageSummary, useOpenSidebarUsage } from "@/usage";
|
||||
import { SidebarAgentListSkeleton } from "./sidebar-agent-list-skeleton";
|
||||
@@ -178,8 +177,14 @@ export const LeftSidebar = memo(function LeftSidebar({ active }: { active: boole
|
||||
router.push(buildSettingsRoute());
|
||||
}, []);
|
||||
|
||||
const handleAddHostMobile = useAddHost();
|
||||
const handleAddHostDesktop = handleAddHostMobile;
|
||||
const handleAddHostMobile = useCallback(() => {
|
||||
showMobileAgent();
|
||||
router.push(buildSettingsAddHostRoute(Date.now()));
|
||||
}, [showMobileAgent]);
|
||||
|
||||
const handleAddHostDesktop = useCallback(() => {
|
||||
router.push(buildSettingsAddHostRoute(Date.now()));
|
||||
}, []);
|
||||
|
||||
const handleOpenHostSettingsMobile = useCallback(
|
||||
(serverId: string) => {
|
||||
|
||||
@@ -110,37 +110,6 @@ describe("shared Markdown source adaptation", () => {
|
||||
["https://x/q.png", false],
|
||||
]);
|
||||
});
|
||||
it("renders linked images that share a line with text inline", async () => {
|
||||
// A review bot's summary header: linked badges inside a heading with the score text.
|
||||
const reviewHeader =
|
||||
'<h2><a href="https://x/retrigger"><picture><source media="(prefers-color-scheme: dark)" srcset="https://x/r-dark.svg"><img alt="Retrigger" src="https://x/r.svg" align="right"></picture></a>Confidence Score: 5/5</h2>';
|
||||
const source = [
|
||||
reviewHeader,
|
||||
"[](https://x)",
|
||||
"[](https://x) [](https://x)",
|
||||
"See [ GitHub](https://x) for more.",
|
||||
].join("\n\n");
|
||||
const tree = await parseMarkdown(prepareMarkdownSource(source).render(), {
|
||||
hardSoftBreaks: true,
|
||||
latexMath: false,
|
||||
});
|
||||
markInlineImages(tree);
|
||||
const images: ASTNode[] = [];
|
||||
const collect = (node: ASTNode) => {
|
||||
if (node.type === "Image") images.push(node);
|
||||
node.children?.forEach(collect);
|
||||
};
|
||||
collect(tree);
|
||||
expect(
|
||||
images.map((image) => [image.attributes?.url, image.attributes?.isInline === true]),
|
||||
).toEqual([
|
||||
["https://x/r.svg", true],
|
||||
["https://x/alone.png", false],
|
||||
["https://x/a.png", true],
|
||||
["https://x/b.png", true],
|
||||
["https://x/gh.png", true],
|
||||
]);
|
||||
});
|
||||
it("escapes spoiler delimiters only in prose", () => {
|
||||
expect(prepareMarkdownSource("Show ||words|| and `||code||`.").render()).toBe(
|
||||
"Show \\|\\|words\\|\\| and `||code||`.",
|
||||
@@ -161,186 +130,6 @@ it("preserves empty table cells while escaping spoilers in cell text", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("renders a table directly after a paragraph through the library parser", async () => {
|
||||
const source = "**Notes**\n| Item | Detail |\n| --- | --- |\n| A | one |\n| B | two |";
|
||||
const separated = "**Notes**\n\n| Item | Detail |\n| --- | --- |\n| A | one |\n| B | two |";
|
||||
const flags = { hardSoftBreaks: true, latexMath: false };
|
||||
const expected = await parseMarkdown(separated, flags);
|
||||
expect(expected.children?.map((node) => node.type)).toEqual(["Paragraph", "Table"]);
|
||||
expect(await parseMarkdown(prepareMarkdownSource(source).render(), flags)).toEqual(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
"a quote",
|
||||
"> Notes\n> | Item |\n> | --- |\n> | A |",
|
||||
"> Notes\n>\n> | Item |\n> | --- |\n> | A |",
|
||||
["Document", ["Blockquote", "Paragraph", "Table"]],
|
||||
],
|
||||
[
|
||||
"a list item",
|
||||
"- Notes\n | Item |\n | --- |\n | A |\n- Next",
|
||||
"- Notes\n\n | Item |\n | --- |\n | A |\n- Next",
|
||||
["Document", ["UnorderedList", ["ListItem", "Paragraph", "Table"], ["ListItem", "Paragraph"]]],
|
||||
],
|
||||
[
|
||||
"a quoted list item",
|
||||
"> - Notes\n> | Item |\n> | --- |\n> | A |",
|
||||
"> - Notes\n>\n> | Item |\n> | --- |\n> | A |",
|
||||
["Document", ["Blockquote", ["UnorderedList", ["ListItem", "Paragraph", "Table"]]]],
|
||||
],
|
||||
[
|
||||
"a quote inside a list item",
|
||||
"- > Notes\n > | Item |\n > | --- |\n > | A |",
|
||||
"- > Notes\n >\n > | Item |\n > | --- |\n > | A |",
|
||||
["Document", ["UnorderedList", ["ListItem", ["Blockquote", "Paragraph", "Table"]]]],
|
||||
],
|
||||
[
|
||||
"aligned columns without outer pipes",
|
||||
"Notes\nItem | Detail\n:--- | ---:\nA | one",
|
||||
"Notes\n\nItem | Detail\n:--- | ---:\nA | one",
|
||||
["Document", "Paragraph", "Table"],
|
||||
],
|
||||
[
|
||||
"an entity at the start of a header without outer pipes",
|
||||
"Notes\nAT&T | Detail\n--- | ---\nA | one",
|
||||
"Notes\n\nAT\\&T | Detail\n--- | ---\nA | one",
|
||||
["Document", "Paragraph", "Table"],
|
||||
],
|
||||
[
|
||||
"a local image at the start of a header without outer pipes",
|
||||
"Notes\n | Detail\n--- | ---\nA | one",
|
||||
"Notes\n\nLocal | Detail\n--- | ---\nA | one",
|
||||
["Document", "Paragraph", "Table"],
|
||||
],
|
||||
[
|
||||
"CRLF lines",
|
||||
"Notes\r\n| Item |\r\n| --- |\r\n| A |",
|
||||
"Notes\r\n\r\n| Item |\r\n| --- |\r\n| A |",
|
||||
["Document", "Paragraph", "Table"],
|
||||
],
|
||||
[
|
||||
"CR lines",
|
||||
"Notes\r| Item |\r| --- |\r| A |",
|
||||
"Notes\r\r| Item |\r| --- |\r| A |",
|
||||
["Document", "Paragraph", "Table"],
|
||||
],
|
||||
[
|
||||
"a quote with CRLF lines",
|
||||
"> Notes\r\n> | Item |\r\n> | --- |\r\n> | A |",
|
||||
"> Notes\r\n>\r\n> | Item |\r\n> | --- |\r\n> | A |",
|
||||
["Document", ["Blockquote", "Paragraph", "Table"]],
|
||||
],
|
||||
[
|
||||
"a list item with CRLF lines",
|
||||
"- Notes\r\n | Item |\r\n | --- |\r\n | A |\r\n- Next",
|
||||
"- Notes\r\n\r\n | Item |\r\n | --- |\r\n | A |\r\n- Next",
|
||||
["Document", ["UnorderedList", ["ListItem", "Paragraph", "Table"], ["ListItem", "Paragraph"]]],
|
||||
],
|
||||
[
|
||||
"a quote with CR lines",
|
||||
"> Notes\r> | Item |\r> | --- |\r> | A |",
|
||||
"> Notes\r>\r> | Item |\r> | --- |\r> | A |",
|
||||
["Document", ["Blockquote", "Paragraph", "Table"]],
|
||||
],
|
||||
[
|
||||
"a list item with CR lines",
|
||||
"- Notes\r | Item |\r | --- |\r | A |\r- Next",
|
||||
"- Notes\r\r | Item |\r | --- |\r | A |\r- Next",
|
||||
["Document", ["UnorderedList", ["ListItem", "Paragraph", "Table"], ["ListItem", "Paragraph"]]],
|
||||
],
|
||||
[
|
||||
"a non-interrupting ordered marker with tildes",
|
||||
"Intro\n2. ~~~\n Notes\n | A |\n | --- |\n | x |",
|
||||
"Intro\n2. ~~~\n Notes\n\n | A |\n | --- |\n | x |",
|
||||
["Document", "Paragraph", "Table"],
|
||||
],
|
||||
[
|
||||
"a non-interrupting ordered marker with backticks",
|
||||
"Notes\n2. ```\n | Item |\n | --- |\n | A |",
|
||||
"Notes\n2. ```\n\n | Item |\n | --- |\n | A |",
|
||||
["Document", "Paragraph", "Table"],
|
||||
],
|
||||
])("preserves tables after paragraphs in %s", async (_name, source, separated, expected) => {
|
||||
const rendered = prepareMarkdownSource(source).render();
|
||||
expect(rendered).toEqual(separated);
|
||||
const flags = { hardSoftBreaks: true, latexMath: false };
|
||||
function blocks(node: ASTNode): unknown {
|
||||
if (node.type === "Paragraph" || node.type === "Table") return node.type;
|
||||
return [node.type, ...(node.children ?? []).map(blocks)];
|
||||
}
|
||||
expect(blocks(await parseMarkdown(rendered, flags))).toEqual(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
"a literal backslash",
|
||||
"Notes\\\n| Item |\n| --- |\n| A |",
|
||||
"Notes\\\n\n| Item |\n| --- |\n| A |",
|
||||
"Notes\\",
|
||||
],
|
||||
[
|
||||
"an entity and literal backslash with LF lines",
|
||||
"AT&T\\\n| Item |\n| --- |\n| A |",
|
||||
"AT\\&T\\\n\n| Item |\n| --- |\n| A |",
|
||||
"AT&T\\",
|
||||
],
|
||||
[
|
||||
"an entity and literal backslash with CRLF lines",
|
||||
"AT&T\\\r\n| Item |\r\n| --- |\r\n| A |",
|
||||
"AT\\&T\\\r\n\r\n| Item |\r\n| --- |\r\n| A |",
|
||||
"AT&T\\",
|
||||
],
|
||||
[
|
||||
"an entity and literal backslash with CR lines",
|
||||
"AT&T\\\r| Item |\r| --- |\r| A |",
|
||||
"AT\\&T\\\r\r| Item |\r| --- |\r| A |",
|
||||
"AT&T\\",
|
||||
],
|
||||
])(
|
||||
"preserves paragraph text before an interrupting table in %s",
|
||||
async (_name, source, separated, text) => {
|
||||
const rendered = prepareMarkdownSource(source).render();
|
||||
expect(rendered).toEqual(separated);
|
||||
const tree = await parseMarkdown(rendered, { hardSoftBreaks: true, latexMath: false });
|
||||
expect(tree.children?.map((node) => node.type)).toEqual(["Paragraph", "Table"]);
|
||||
expect(tree.children?.[0]?.children?.map((node) => node.content).join("")).toEqual(text);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"```yaml\n---\nkey: value\n---\n```\n",
|
||||
"~~~md\n| Item |\n| --- |\n| A |\n~~~\n",
|
||||
"````md\n```\n| Item |\n| --- |\n```\n`````\n",
|
||||
"> ```md\n> | Item |\n> | --- |\n> ```\n",
|
||||
"> ```md\n> Code\n",
|
||||
"- ```md\n Code\n",
|
||||
" ```\n\n",
|
||||
"```not`a-fence\n",
|
||||
])("renders a table after a fence without changing its code: %s", async (prefix) => {
|
||||
const table = "| Item |\n| --- |\n| A |";
|
||||
const rendered = prepareMarkdownSource(`${prefix}Notes\n${table}`).render();
|
||||
expect(rendered).toEqual(`${prefix}Notes\n\n${table}`);
|
||||
const tree = await parseMarkdown(rendered, { hardSoftBreaks: true, latexMath: false });
|
||||
expect(tree.children?.slice(-2).map((node) => node.type)).toEqual(["Paragraph", "Table"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"| Item | Detail |\n| --- | --- |\n" + "| A | one |\n".repeat(100),
|
||||
"Notes\n\n| Item | Detail |\n| --- | --- |\n" + "| A | one |\n".repeat(100),
|
||||
"Notes\n\n| Item |\n| --- |\n| A |",
|
||||
"| Item |\n| --- |\n| A |",
|
||||
"```md\nNotes\n| Item |\n| --- |\n| A |\n```",
|
||||
"```yaml\n---\nkey: value\n---\n```",
|
||||
"```yaml\n---\nkey: value",
|
||||
"~~~md\n| Item |\n| --- |\n| A |\n~~~",
|
||||
"````md\n```\n| Item |\n| --- |\n```\n````",
|
||||
" Notes\n | Item |\n | --- |\n | A |",
|
||||
"Notes\n| Item | Detail |\n| --- |\n| A |",
|
||||
])("leaves separated tables and table-like text unchanged: %s", (source) => {
|
||||
expect(prepareMarkdownSource(source).render()).toEqual(source);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"src/components/message.tsx",
|
||||
"C:\\repo\\file.ts",
|
||||
|
||||
@@ -138,10 +138,6 @@ export function prepareMarkdownSource(
|
||||
!source.includes("![") &&
|
||||
!source.includes("||") &&
|
||||
!source.includes("&") &&
|
||||
// Match content, header, and delimiter lines; quote-only lines count as blank.
|
||||
!/^[\t >]*[^\t >\r\n][^\r\n]*(?:\r\n|\r|\n)[^\r\n]+(?:\r\n|\r|\n)(?=[\t >:|-]*\|)[\t >|]*:?-[-\t :|]*$/m.test(
|
||||
source,
|
||||
) &&
|
||||
!(workspaceRoot && source.includes("]("))
|
||||
) {
|
||||
return { images, ...metadata, render: () => source };
|
||||
@@ -216,25 +212,11 @@ export function prepareMarkdownSource(
|
||||
if (lineEnd < end) split(lineEnd);
|
||||
}
|
||||
}
|
||||
function visit(node: Nodes, previous?: Nodes) {
|
||||
const position = node.position;
|
||||
if (position?.start.offset !== undefined && position.end.offset !== undefined) {
|
||||
const start = position.start.offset;
|
||||
const end = position.end.offset;
|
||||
function visit(node: Nodes) {
|
||||
const start = node.position?.start.offset;
|
||||
const end = node.position?.end.offset;
|
||||
if (start !== undefined && end !== undefined) {
|
||||
if (node.type === "paragraph") splitStandaloneImages(node, start, end);
|
||||
if (
|
||||
node.type === "table" &&
|
||||
previous?.type === "paragraph" &&
|
||||
previous.position?.end.line === position.start.line - 1
|
||||
) {
|
||||
// MD4C only recognizes a table header on the first line of a paragraph.
|
||||
const lineStart =
|
||||
Math.max(source.lastIndexOf("\n", start - 1), source.lastIndexOf("\r", start - 1)) + 1;
|
||||
const newline = source.slice(lineStart - 2, lineStart).replace(/[^\r\n]/g, "");
|
||||
const blank = source.slice(lineStart, start).replace(/[^>]/g, " ").trimEnd();
|
||||
const boundary = lineStart - newline.length;
|
||||
edits.push({ start: boundary, end: lineStart, text: `${newline}${blank}${newline}` });
|
||||
}
|
||||
if (node.type === "link") {
|
||||
const title = workspaceHoverTitle(node, source.slice(start, end), workspaceRoot);
|
||||
if (title !== null)
|
||||
@@ -262,8 +244,7 @@ export function prepareMarkdownSource(
|
||||
if (text !== source.slice(start, end)) edits.push({ start, end, text });
|
||||
}
|
||||
}
|
||||
if ("children" in node)
|
||||
node.children.forEach((child, index) => visit(child, node.children[index - 1]));
|
||||
if ("children" in node) node.children.forEach(visit);
|
||||
}
|
||||
visit(getTree());
|
||||
return {
|
||||
|
||||
+11
-16
@@ -1,20 +1,16 @@
|
||||
import { useCallback, useMemo, useReducer, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Alert, Text, View } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { Link } from "lucide-react-native";
|
||||
import type { HostProfile } from "@/types/host-connection";
|
||||
import { useHosts, useHostMutations, type PasswordRequiredPairing } from "@/runtime/host-runtime";
|
||||
import { parseRelayConnectionUri } from "@/utils/daemon-endpoints";
|
||||
import { parseConnectionOfferFromUrl } from "@getpaseo/protocol/connection-offer";
|
||||
import {
|
||||
AdaptiveModalSheet,
|
||||
AdaptiveTextInput,
|
||||
type SheetHeader,
|
||||
} from "@/components/adaptive-modal-sheet";
|
||||
import { AdaptiveModalSheet, AdaptiveTextInput, type SheetHeader } from "./adaptive-modal-sheet";
|
||||
import { getConnectionAuthFailureReason } from "@/utils/test-daemon-connection";
|
||||
import { PairingTargetTracker } from "@/components/pair-link-credentials";
|
||||
import { PairingTargetTracker } from "./pair-link-credentials";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
|
||||
@@ -104,6 +100,7 @@ function PairLinkModalContent({
|
||||
onCancel,
|
||||
onSaved,
|
||||
}: PairLinkModalProps) {
|
||||
const { theme } = useUnistyles();
|
||||
const { t } = useTranslation();
|
||||
const daemons = useHosts();
|
||||
const { beginLinkPairing } = useHostMutations();
|
||||
@@ -129,7 +126,10 @@ function PairLinkModalContent({
|
||||
resetPasswordInput();
|
||||
}, []);
|
||||
|
||||
const pairIcon = useMemo(() => <ThemedLink size={16} />, []);
|
||||
const pairIcon = useMemo(
|
||||
() => <Link size={16} color={theme.colors.accentForeground} />,
|
||||
[theme.colors.accentForeground],
|
||||
);
|
||||
|
||||
const handleClose = useCallback(() => {
|
||||
if (isSaving) return;
|
||||
@@ -212,7 +212,7 @@ function PairLinkModalContent({
|
||||
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>{t("pairing.link.label")}</Text>
|
||||
<ThemedAdaptiveTextInput
|
||||
<AdaptiveTextInput
|
||||
ref={inputRef}
|
||||
initialValue={initialUrl}
|
||||
testID="pair-link-input"
|
||||
@@ -220,6 +220,7 @@ function PairLinkModalContent({
|
||||
accessibilityLabel={t("pairing.link.label")}
|
||||
onChangeText={handleChangeOfferUrl}
|
||||
placeholder="https://app.paseo.sh/#offer=..."
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
style={styles.input}
|
||||
autoFocus
|
||||
autoCapitalize="none"
|
||||
@@ -234,7 +235,7 @@ function PairLinkModalContent({
|
||||
<Text style={styles.label}>
|
||||
{t("pairing.hostPassword.title", { host: parsedHostLabel(offerUrlRef.current) })}
|
||||
</Text>
|
||||
<ThemedAdaptiveTextInput
|
||||
<AdaptiveTextInput
|
||||
testID="pair-link-password-input"
|
||||
resetKey={`pair-link-password-${passwordResetKey}`}
|
||||
accessibilityLabel={t("pairing.hostPassword.label")}
|
||||
@@ -273,9 +274,3 @@ function PairLinkModalContent({
|
||||
</AdaptiveModalSheet>
|
||||
);
|
||||
}
|
||||
|
||||
const ThemedLink = withUnistyles(Link, (theme) => ({ color: theme.colors.accentForeground }));
|
||||
|
||||
const ThemedAdaptiveTextInput = withUnistyles(AdaptiveTextInput, (theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
}));
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useAddHost } from "@/hosts/add-host";
|
||||
import { useCallback, useEffect, useMemo, useSyncExternalStore } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Pressable, Text, View, ScrollView } from "react-native";
|
||||
import { useRouter } from "expo-router";
|
||||
@@ -13,7 +12,11 @@ import {
|
||||
Terminal,
|
||||
} from "lucide-react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import type { HostProfile } from "@/types/host-connection";
|
||||
import { getHostRuntimeStore, isHostRuntimeConnected, useHosts } from "@/runtime/host-runtime";
|
||||
import { AddHostModal } from "./add-host-modal";
|
||||
import { AddRemoteSshHostModal } from "./add-remote-ssh-host-modal";
|
||||
import { PairLinkModal } from "./pair-link-modal";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { resolveAppVersion } from "@/utils/app-version";
|
||||
import { formatVersionWithPrefix } from "@/desktop/updates/desktop-updates";
|
||||
@@ -159,13 +162,20 @@ function useAnyHostOnline(serverIds: string[]): string | null {
|
||||
);
|
||||
}
|
||||
|
||||
export function WelcomeScreen() {
|
||||
export interface WelcomeScreenProps {
|
||||
onHostAdded?: (profile: HostProfile) => void;
|
||||
}
|
||||
|
||||
export function WelcomeScreen({ onHostAdded }: WelcomeScreenProps) {
|
||||
const { theme } = useUnistyles();
|
||||
const { t } = useTranslation();
|
||||
const insets = useSafeAreaInsets();
|
||||
const router = useRouter();
|
||||
const appVersion = resolveAppVersion();
|
||||
const appVersionText = formatVersionWithPrefix(appVersion);
|
||||
const [isDirectOpen, setIsDirectOpen] = useState(false);
|
||||
const [isRemoteSshOpen, setIsRemoteSshOpen] = useState(false);
|
||||
const [isPasteLinkOpen, setIsPasteLinkOpen] = useState(false);
|
||||
const hosts = useHosts();
|
||||
const anyOnlineServerId = useAnyHostOnline(hosts.map((h) => h.serverId));
|
||||
|
||||
@@ -186,10 +196,23 @@ export function WelcomeScreen() {
|
||||
router.push("/settings");
|
||||
}, [router]);
|
||||
|
||||
const handleOpenDirect = useAddHost({ method: "direct", onAdded: finishOnboarding });
|
||||
const handleOpenRemoteSsh = useAddHost({ method: "ssh", onAdded: finishOnboarding });
|
||||
const handleOpenPasteLink = useAddHost({ method: "link", onAdded: finishOnboarding });
|
||||
const handleScanQr = useAddHost({ method: "scan", onAdded: finishOnboarding });
|
||||
const handleOpenDirect = useCallback(() => setIsDirectOpen(true), []);
|
||||
const handleCloseDirect = useCallback(() => setIsDirectOpen(false), []);
|
||||
const handleOpenRemoteSsh = useCallback(() => setIsRemoteSshOpen(true), []);
|
||||
const handleCloseRemoteSsh = useCallback(() => setIsRemoteSshOpen(false), []);
|
||||
const handleOpenPasteLink = useCallback(() => setIsPasteLinkOpen(true), []);
|
||||
const handleClosePasteLink = useCallback(() => setIsPasteLinkOpen(false), []);
|
||||
const handleScanQr = useCallback(() => {
|
||||
router.push("/pair-scan?source=onboarding");
|
||||
}, [router]);
|
||||
|
||||
const handleHostSaved = useCallback(
|
||||
({ profile }: { profile: HostProfile; serverId: string }) => {
|
||||
onHostAdded?.(profile);
|
||||
finishOnboarding();
|
||||
},
|
||||
[onHostAdded, finishOnboarding],
|
||||
);
|
||||
|
||||
const actions: WelcomeAction[] =
|
||||
isWeb || isFdroidBuild
|
||||
@@ -293,6 +316,24 @@ export function WelcomeScreen() {
|
||||
</Button>
|
||||
</View>
|
||||
<Text style={styles.versionLabel}>{appVersionText}</Text>
|
||||
|
||||
<AddHostModal
|
||||
visible={isDirectOpen}
|
||||
onClose={handleCloseDirect}
|
||||
onSaved={handleHostSaved}
|
||||
/>
|
||||
|
||||
<AddRemoteSshHostModal
|
||||
visible={isRemoteSshOpen}
|
||||
onClose={handleCloseRemoteSsh}
|
||||
onSaved={handleHostSaved}
|
||||
/>
|
||||
|
||||
<PairLinkModal
|
||||
visible={isPasteLinkOpen}
|
||||
onClose={handleClosePasteLink}
|
||||
onSaved={handleHostSaved}
|
||||
/>
|
||||
</ScrollView>
|
||||
</View>
|
||||
);
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import { createContext, useCallback, useContext, useState, useMemo, type ReactNode } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useStore } from "zustand";
|
||||
import { AddHostMethodModal } from "./internal/add-host-method-modal";
|
||||
import { AddHostModal } from "./internal/add-host-modal";
|
||||
import { AddRemoteSshHostModal } from "./internal/add-remote-ssh-host-modal";
|
||||
import { PairLinkModal } from "./internal/pair-link-modal";
|
||||
import { AdaptiveModalSheet } from "@/components/adaptive-modal-sheet";
|
||||
import { PairScanContent } from "./internal/scan";
|
||||
import { createAddHostFlow, type AddHostOptions, type AddHostSession } from "./internal/model";
|
||||
|
||||
const Context = createContext<ReturnType<typeof createAddHostFlow> | null>(null);
|
||||
|
||||
/** Owns the flow outside screen and appearance lifetimes. Callers own success navigation. */
|
||||
export function AddHostProvider({ children }: { children: ReactNode }) {
|
||||
const [flow] = useState(createAddHostFlow);
|
||||
return <Context.Provider value={flow}>{children}</Context.Provider>;
|
||||
}
|
||||
|
||||
export function AddHostFlowHost() {
|
||||
const flow = useContext(Context);
|
||||
if (!flow) throw new Error("AddHostFlowHost requires AddHostProvider");
|
||||
const session = useStore(flow.store, (state) => state.session);
|
||||
return session ? <AddHostSessionView key={session.id} session={session} /> : null;
|
||||
}
|
||||
|
||||
export function useAddHost({ method, onAdded }: AddHostOptions = {}) {
|
||||
const flow = useContext(Context);
|
||||
if (!flow) throw new Error("useAddHost requires AddHostProvider");
|
||||
return useCallback(() => flow.open({ method, onAdded }), [flow, method, onAdded]);
|
||||
}
|
||||
|
||||
function AddHostSessionView({ session }: { session: AddHostSession }) {
|
||||
const { t } = useTranslation();
|
||||
const method = useStore(session.step, (state) => state.method);
|
||||
const back = useCallback(() => session.choose(null), [session]);
|
||||
const direct = useCallback(() => session.choose("direct"), [session]);
|
||||
const ssh = useCallback(() => session.choose("ssh"), [session]);
|
||||
const link = useCallback(() => session.choose("link"), [session]);
|
||||
const scan = useCallback(() => session.choose("scan"), [session]);
|
||||
const scanned = useCallback((serverId: string) => session.complete({ serverId }), [session]);
|
||||
const header = useMemo(
|
||||
() => ({ title: t("pairing.scan.title"), back: { onPress: back } }),
|
||||
[t, back],
|
||||
);
|
||||
return (
|
||||
<>
|
||||
<AddHostMethodModal
|
||||
visible={method === null}
|
||||
onClose={session.close}
|
||||
onDirectConnection={direct}
|
||||
onRemoteSsh={ssh}
|
||||
onPasteLink={link}
|
||||
onScanQr={scan}
|
||||
/>
|
||||
<AddHostModal
|
||||
visible={method === "direct"}
|
||||
onClose={session.close}
|
||||
onCancel={back}
|
||||
onSaved={session.complete}
|
||||
/>
|
||||
<AddRemoteSshHostModal
|
||||
visible={method === "ssh"}
|
||||
onClose={session.close}
|
||||
onCancel={back}
|
||||
onSaved={session.complete}
|
||||
/>
|
||||
<PairLinkModal
|
||||
visible={method === "link"}
|
||||
onClose={session.close}
|
||||
onCancel={back}
|
||||
onSaved={session.complete}
|
||||
/>
|
||||
{method === "scan" ? (
|
||||
<AdaptiveModalSheet
|
||||
header={header}
|
||||
visible
|
||||
onClose={session.close}
|
||||
scrollable={false}
|
||||
snapPoints={SCAN_SNAP_POINTS}
|
||||
desktopHeight="85%"
|
||||
>
|
||||
<PairScanContent onConnected={scanned} onClose={back} />
|
||||
</AdaptiveModalSheet>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
const SCAN_SNAP_POINTS = ["90%"];
|
||||
@@ -1,49 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createAddHostFlow } from "./model";
|
||||
|
||||
describe("add host flow", () => {
|
||||
it("closes before notifying the consumer and ignores duplicate completion", () => {
|
||||
const flow = createAddHostFlow();
|
||||
const added: string[] = [];
|
||||
flow.open({
|
||||
onAdded: (serverId) => {
|
||||
expect(flow.store.getState().session).toBeNull();
|
||||
added.push(serverId);
|
||||
},
|
||||
});
|
||||
const session = flow.store.getState().session!;
|
||||
session.choose("direct");
|
||||
session.complete({ serverId: "new-host" });
|
||||
session.complete({ serverId: "new-host" });
|
||||
expect(added).toEqual(["new-host"]);
|
||||
});
|
||||
|
||||
it("cancels without a success action and accepts a fresh request", () => {
|
||||
const flow = createAddHostFlow();
|
||||
const added: string[] = [];
|
||||
flow.open({ onAdded: (id) => added.push(id) });
|
||||
const cancelled = flow.store.getState().session!;
|
||||
cancelled.choose("scan");
|
||||
cancelled.close();
|
||||
expect(flow.store.getState().session).toBeNull();
|
||||
flow.open({ method: "link" });
|
||||
const current = flow.store.getState().session!;
|
||||
cancelled.complete({ serverId: "late-result" });
|
||||
cancelled.close();
|
||||
expect(flow.store.getState().session).toBe(current);
|
||||
expect(current.step.getState()).toEqual({ method: "link" });
|
||||
expect(added).toEqual([]);
|
||||
current.complete({ serverId: "new-host" });
|
||||
expect(flow.store.getState().session).toBeNull();
|
||||
});
|
||||
|
||||
it("returns to method selection within the same request", () => {
|
||||
const flow = createAddHostFlow();
|
||||
flow.open();
|
||||
const session = flow.store.getState().session!;
|
||||
session.choose("ssh");
|
||||
session.choose(null);
|
||||
expect(flow.store.getState().session).toBe(session);
|
||||
expect(session.step.getState()).toEqual({ method: null });
|
||||
});
|
||||
});
|
||||
@@ -1,47 +0,0 @@
|
||||
import { createStore, type StoreApi } from "zustand/vanilla";
|
||||
|
||||
export type AddHostMethod = "direct" | "ssh" | "link" | "scan";
|
||||
export interface AddHostOptions {
|
||||
method?: AddHostMethod;
|
||||
onAdded?: (serverId: string) => void;
|
||||
}
|
||||
|
||||
export interface AddHostSession {
|
||||
id: number;
|
||||
step: StoreApi<{ method: AddHostMethod | null }>;
|
||||
choose(method: AddHostMethod | null): void;
|
||||
close(): void;
|
||||
complete(result: { serverId: string }): void;
|
||||
}
|
||||
|
||||
export function createAddHostFlow() {
|
||||
const store = createStore<{ session: AddHostSession | null }>(() => ({ session: null }));
|
||||
let nextId = 0;
|
||||
function createSession(options: AddHostOptions) {
|
||||
const step = createStore<{ method: AddHostMethod | null }>(() => ({
|
||||
method: options.method ?? null,
|
||||
}));
|
||||
const session = {
|
||||
id: ++nextId,
|
||||
step,
|
||||
choose(method: AddHostMethod | null) {
|
||||
step.setState({ method });
|
||||
},
|
||||
close() {
|
||||
if (store.getState().session === session) store.setState({ session: null });
|
||||
},
|
||||
complete({ serverId }: { serverId: string }) {
|
||||
if (store.getState().session !== session) return;
|
||||
session.close();
|
||||
options.onAdded?.(serverId);
|
||||
},
|
||||
};
|
||||
return session;
|
||||
}
|
||||
return {
|
||||
store,
|
||||
open(options: AddHostOptions = {}) {
|
||||
store.setState({ session: createSession(options) });
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import { useAddHost } from "@/hosts/add-host";
|
||||
import { Modal } from "@/components/ui/modal";
|
||||
import { usePanelStore } from "@/stores/panel-store";
|
||||
import { createElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Pressable, ScrollView, Text, View, type PressableStateCallbackType } from "react-native";
|
||||
import {
|
||||
EditingTextInput as TextInput,
|
||||
type EditingTextInputHandle,
|
||||
} from "@/components/ui/text-input";
|
||||
import { router } from "expo-router";
|
||||
import { Server } from "lucide-react-native";
|
||||
import { create } from "zustand";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
} from "@/lib/overlay-root";
|
||||
import { useHosts } from "@/runtime/host-runtime";
|
||||
import { orderHostsLocalFirst, type HostProfile } from "@/types/host-connection";
|
||||
import { buildSettingsAddHostRoute } from "@/utils/host-routes";
|
||||
|
||||
type HostFilter = (host: HostProfile) => boolean;
|
||||
type HostChoiceHandler = (serverId: string) => void | Promise<void>;
|
||||
@@ -63,7 +65,6 @@ function matchesHostQuery(host: HostProfile, query: string): boolean {
|
||||
}
|
||||
|
||||
export function useHostChooser() {
|
||||
const addHost = useAddHost();
|
||||
const hosts = useHosts();
|
||||
const localServerId = useLocalDaemonServerId();
|
||||
const open = useHostChooserStore((state) => state.open);
|
||||
@@ -75,7 +76,13 @@ export function useHostChooser() {
|
||||
);
|
||||
|
||||
if (availableHosts.length === 0) {
|
||||
(input.onNoHosts ?? addHost)();
|
||||
(
|
||||
input.onNoHosts ??
|
||||
(() => {
|
||||
usePanelStore.getState().showMobileAgent();
|
||||
router.push(buildSettingsAddHostRoute(Date.now()));
|
||||
})
|
||||
)();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -91,7 +98,7 @@ export function useHostChooser() {
|
||||
});
|
||||
return true;
|
||||
},
|
||||
[hosts, localServerId, open, addHost],
|
||||
[hosts, localServerId, open],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,45 +14,6 @@ function thought(text: string, status: "loading" | "ready" = "loading"): StreamI
|
||||
}
|
||||
|
||||
describe("plugin timeline projection", () => {
|
||||
it.each(["message", "finished", "errored", "permission-required", "closed"] as const)(
|
||||
"preserves immutable agent-message provenance for %s cards",
|
||||
(event) => {
|
||||
const agentMessage = {
|
||||
event,
|
||||
sender: { id: "remote::reviewer", title: "QA question-timing #7014/#7000/#6809" },
|
||||
text: "The original message, including **Markdown**.",
|
||||
};
|
||||
const source: StreamItem = {
|
||||
kind: "tool_call",
|
||||
id: "message-1",
|
||||
timestamp: new Date("2026-01-01T00:00:00.000Z"),
|
||||
payload: {
|
||||
source: "agent",
|
||||
data: {
|
||||
provider: "codex",
|
||||
callId: "delivery-1",
|
||||
name: "agent_message",
|
||||
status: "completed",
|
||||
error: null,
|
||||
detail: { type: "plain_text", text: agentMessage.text, icon: "bot" },
|
||||
agentMessage,
|
||||
},
|
||||
},
|
||||
};
|
||||
const inspect: TimelineItemTransform = ({ item }) => {
|
||||
expect(item.type).toBe("tool_call");
|
||||
if (item.type !== "tool_call") throw new Error("Expected a tool call");
|
||||
expect(item.agentMessage).toEqual(agentMessage);
|
||||
expect(item.agentMessage).not.toBe(agentMessage);
|
||||
expect(Object.isFrozen(item.agentMessage)).toBe(true);
|
||||
expect(Object.isFrozen(item.agentMessage?.sender)).toBe(true);
|
||||
return undefined;
|
||||
};
|
||||
expect(projectPluginTimelineItems([source], inspect)).toEqual([source]);
|
||||
expect(Object.isFrozen(agentMessage.sender)).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not expose mutable tool detail from stream state", () => {
|
||||
const detail = { type: "read" as const, filePath: "/repo/original.ts" };
|
||||
const source: StreamItem = {
|
||||
|
||||
@@ -22,14 +22,13 @@ function cloneAndFreeze<T>(value: T): T {
|
||||
}
|
||||
|
||||
function sourceToolCallTimelineItem(data: AgentToolCallData): ToolCallTimelineItem {
|
||||
const { callId, name, status, error, detail, metadata, agentMessage } = data;
|
||||
const { callId, name, status, error, detail, metadata } = data;
|
||||
const base = {
|
||||
type: "tool_call" as const,
|
||||
callId,
|
||||
name,
|
||||
detail,
|
||||
...(metadata ? { metadata } : {}),
|
||||
...(agentMessage ? { agentMessage } : {}),
|
||||
};
|
||||
switch (status) {
|
||||
case "running":
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useAddHost } from "@/hosts/add-host";
|
||||
import type {
|
||||
CreateAgentRequestOptions,
|
||||
CreateWorkspaceRequestOptions,
|
||||
@@ -9,6 +8,7 @@ import { getHostRuntimeStore } from "@/runtime/host-runtime";
|
||||
import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from "react";
|
||||
import type { ReactNode } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { router } from "expo-router";
|
||||
import { Text, View } from "react-native";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { createNameId } from "mnemonic-id";
|
||||
@@ -62,6 +62,7 @@ import type { KeyboardActionId } from "@/keyboard/keyboard-action-dispatcher";
|
||||
import { useFormPreferences } from "@/hooks/use-form-preferences";
|
||||
import type { CreateAgentInitialValues } from "@/hooks/use-agent-form-state";
|
||||
import { toErrorMessage } from "@/utils/error-messages";
|
||||
import { buildSettingsAddHostRoute } from "@/utils/host-routes";
|
||||
import {
|
||||
getHostProjectId,
|
||||
getWorktreeSupportForHostProject,
|
||||
@@ -1165,7 +1166,9 @@ export function NewWorkspaceScreen({
|
||||
openAddProjectPicker(selectedServerId);
|
||||
}, [openAddProjectPicker, selectedServerId]);
|
||||
|
||||
const handleAddHost = useAddHost();
|
||||
const handleAddHost = useCallback(() => {
|
||||
router.push(buildSettingsAddHostRoute(Date.now()));
|
||||
}, []);
|
||||
|
||||
const openPicker = useCallback(() => {
|
||||
setPickerOpen(true);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useAddHost } from "@/hosts/add-host";
|
||||
import { useCallback, useMemo, useRef, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { ComponentType, ReactNode } from "react";
|
||||
import {
|
||||
Alert,
|
||||
@@ -75,6 +74,10 @@ import { WindowChromeRegion, WindowChromeSafeArea } from "@/utils/desktop-window
|
||||
import { confirmDialog } from "@/utils/confirm-dialog";
|
||||
import { BackHeader } from "@/components/headers/back-header";
|
||||
import { PageLayout } from "@/components/page-layout";
|
||||
import { AddHostMethodModal } from "@/components/add-host-method-modal";
|
||||
import { AddHostModal } from "@/components/add-host-modal";
|
||||
import { AddRemoteSshHostModal } from "@/components/add-remote-ssh-host-modal";
|
||||
import { PairLinkModal } from "@/components/pair-link-modal";
|
||||
import { KeyboardShortcutsSection } from "@/screens/settings/keyboard-shortcuts-section";
|
||||
import { EditorSection } from "@/screens/settings/editor-section";
|
||||
import { FilesSection } from "@/screens/settings/files-section";
|
||||
@@ -1086,15 +1089,21 @@ function SettingsSidebar({
|
||||
|
||||
export interface SettingsScreenProps {
|
||||
view: SettingsView;
|
||||
openAddHostIntent?: string | null;
|
||||
}
|
||||
|
||||
export default function SettingsScreen({ view }: SettingsScreenProps) {
|
||||
export default function SettingsScreen({ view, openAddHostIntent = null }: SettingsScreenProps) {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation();
|
||||
const voiceAudioEngine = useVoiceAudioEngineOptional();
|
||||
const { settings, isLoading: settingsLoading, updateSettings } = useAppSettings();
|
||||
const [isAddHostMethodVisible, setIsAddHostMethodVisible] = useState(false);
|
||||
const [isDirectHostVisible, setIsDirectHostVisible] = useState(false);
|
||||
const [isRemoteSshVisible, setIsRemoteSshVisible] = useState(false);
|
||||
const [isPasteLinkVisible, setIsPasteLinkVisible] = useState(false);
|
||||
const [isPlaybackTestRunning, setIsPlaybackTestRunning] = useState(false);
|
||||
const [playbackTestResult, setPlaybackTestResult] = useState<string | null>(null);
|
||||
const lastOpenedAddHostIntentRef = useRef<string | null>(null);
|
||||
const isDesktopApp = isElectronRuntime();
|
||||
const appVersion = resolveAppVersion();
|
||||
const appVersionText = formatVersionWithPrefix(appVersion);
|
||||
@@ -1155,10 +1164,50 @@ export default function SettingsScreen({ view }: SettingsScreenProps) {
|
||||
}
|
||||
}, [isPlaybackTestRunning, t, voiceAudioEngine]);
|
||||
|
||||
const closeAddConnectionFlow = useCallback(() => {
|
||||
setIsAddHostMethodVisible(false);
|
||||
setIsDirectHostVisible(false);
|
||||
setIsRemoteSshVisible(false);
|
||||
setIsPasteLinkVisible(false);
|
||||
}, []);
|
||||
|
||||
const goBackToAddConnectionMethods = useCallback(() => {
|
||||
setIsDirectHostVisible(false);
|
||||
setIsRemoteSshVisible(false);
|
||||
setIsPasteLinkVisible(false);
|
||||
setIsAddHostMethodVisible(true);
|
||||
}, []);
|
||||
|
||||
const handleAddHost = useCallback(() => {
|
||||
setIsAddHostMethodVisible(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!openAddHostIntent || lastOpenedAddHostIntentRef.current === openAddHostIntent) {
|
||||
return;
|
||||
}
|
||||
lastOpenedAddHostIntentRef.current = openAddHostIntent;
|
||||
handleAddHost();
|
||||
}, [handleAddHost, openAddHostIntent]);
|
||||
|
||||
const handleSelectDirectConnection = useCallback(() => {
|
||||
setIsAddHostMethodVisible(false);
|
||||
setIsDirectHostVisible(true);
|
||||
}, []);
|
||||
|
||||
const handleSelectRemoteSsh = useCallback(() => {
|
||||
setIsAddHostMethodVisible(false);
|
||||
setIsRemoteSshVisible(true);
|
||||
}, []);
|
||||
|
||||
const handleSelectPasteLink = useCallback(() => {
|
||||
setIsAddHostMethodVisible(false);
|
||||
setIsPasteLinkVisible(true);
|
||||
}, []);
|
||||
|
||||
const handleHostAdded = useCallback(
|
||||
(serverId: string) => {
|
||||
selectSettingsHost(serverId);
|
||||
const target = buildSettingsHostSectionRoute(serverId, "host");
|
||||
({ serverId }: { serverId: string }) => {
|
||||
const target = buildSettingsHostSectionRoute(serverId, "connections");
|
||||
if (isCompactLayout) {
|
||||
router.push(target);
|
||||
} else {
|
||||
@@ -1168,8 +1217,6 @@ export default function SettingsScreen({ view }: SettingsScreenProps) {
|
||||
[isCompactLayout, router],
|
||||
);
|
||||
|
||||
const handleAddHost = useAddHost({ onAdded: handleHostAdded });
|
||||
|
||||
const handleSelectSection = useCallback(
|
||||
(section: SettingsSectionSlug) => {
|
||||
const target = buildSettingsSectionRoute(section);
|
||||
@@ -1225,6 +1272,14 @@ export default function SettingsScreen({ view }: SettingsScreenProps) {
|
||||
[activeHostServerId, handleAddHost, isCompactLayout, router],
|
||||
);
|
||||
|
||||
const handleScanQr = useCallback(() => {
|
||||
closeAddConnectionFlow();
|
||||
router.push({
|
||||
pathname: "/pair-scan",
|
||||
params: { source: "settings" },
|
||||
});
|
||||
}, [closeAddConnectionFlow, router]);
|
||||
|
||||
const handleHostRemoved = useCallback(() => {
|
||||
const fallback = buildSettingsSectionRoute("general");
|
||||
if (isCompactLayout) {
|
||||
@@ -1333,6 +1388,37 @@ export default function SettingsScreen({ view }: SettingsScreenProps) {
|
||||
);
|
||||
}
|
||||
|
||||
const addHostModals = (
|
||||
<>
|
||||
<AddHostMethodModal
|
||||
visible={isAddHostMethodVisible}
|
||||
onClose={closeAddConnectionFlow}
|
||||
onDirectConnection={handleSelectDirectConnection}
|
||||
onRemoteSsh={handleSelectRemoteSsh}
|
||||
onPasteLink={handleSelectPasteLink}
|
||||
onScanQr={handleScanQr}
|
||||
/>
|
||||
<AddHostModal
|
||||
visible={isDirectHostVisible}
|
||||
onClose={closeAddConnectionFlow}
|
||||
onCancel={goBackToAddConnectionMethods}
|
||||
onSaved={handleHostAdded}
|
||||
/>
|
||||
<AddRemoteSshHostModal
|
||||
visible={isRemoteSshVisible}
|
||||
onClose={closeAddConnectionFlow}
|
||||
onCancel={goBackToAddConnectionMethods}
|
||||
onSaved={handleHostAdded}
|
||||
/>
|
||||
<PairLinkModal
|
||||
visible={isPasteLinkVisible}
|
||||
onClose={closeAddConnectionFlow}
|
||||
onCancel={goBackToAddConnectionMethods}
|
||||
onSaved={handleHostAdded}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
// Mobile root: full-screen sidebar-as-list.
|
||||
if (isCompactLayout && view.kind === "root") {
|
||||
return (
|
||||
@@ -1350,6 +1436,7 @@ export default function SettingsScreen({ view }: SettingsScreenProps) {
|
||||
layout="mobile"
|
||||
/>
|
||||
</ScrollView>
|
||||
{addHostModals}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1360,6 +1447,7 @@ export default function SettingsScreen({ view }: SettingsScreenProps) {
|
||||
<PageLayout title={detailTitle} onBack={handleBackFromDetail}>
|
||||
{content}
|
||||
</PageLayout>
|
||||
{addHostModals}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -1394,6 +1482,7 @@ export default function SettingsScreen({ view }: SettingsScreenProps) {
|
||||
</View>
|
||||
</WindowChromeRegion>
|
||||
</View>
|
||||
{addHostModals}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -717,13 +717,11 @@ describe("terminal emulator runtime in a real browser", () => {
|
||||
{ name: "DA1-zero", bytes: "\x1b[0c" },
|
||||
{ name: "DA2", bytes: "\x1b[>c" },
|
||||
{ name: "DA3", bytes: "\x1b[=c" },
|
||||
{ name: "XTVERSION", bytes: "\x1b[>q" },
|
||||
{ name: "DSR-5", bytes: "\x1b[5n" },
|
||||
{ name: "DSR-6", bytes: "\x1b[6n" },
|
||||
{ name: "DSR-?6", bytes: "\x1b[?6n" },
|
||||
{ name: "DECRQM", bytes: "\x1b[1$p" },
|
||||
{ name: "DECRQM-?", bytes: "\x1b[?1$p" },
|
||||
{ name: "DECRQSS", bytes: "\x1bP$qm\x1b\\" },
|
||||
{ name: "OSC-10-foreground-color", bytes: "\x1b]10;?\x07" },
|
||||
{ name: "OSC-11-background-color", bytes: "\x1b]11;?\x07" },
|
||||
{ name: "OSC-12-cursor-color", bytes: "\x1b]12;?\x07" },
|
||||
|
||||
@@ -647,7 +647,6 @@ export class TerminalEmulatorRuntime {
|
||||
terminal.parser.registerCsiHandler({ final: "c" }, () => true);
|
||||
terminal.parser.registerCsiHandler({ prefix: ">", final: "c" }, () => true);
|
||||
terminal.parser.registerCsiHandler({ prefix: "=", final: "c" }, () => true);
|
||||
terminal.parser.registerCsiHandler({ prefix: ">", final: "q" }, () => true);
|
||||
terminal.parser.registerCsiHandler({ final: "n" }, () => true);
|
||||
terminal.parser.registerCsiHandler({ prefix: "?", final: "n" }, () => true);
|
||||
terminal.parser.registerCsiHandler({ final: "R" }, () => true);
|
||||
@@ -656,7 +655,6 @@ export class TerminalEmulatorRuntime {
|
||||
{ prefix: "?", intermediates: "$", final: "p" },
|
||||
() => true,
|
||||
);
|
||||
terminal.parser.registerDcsHandler({ intermediates: "$", final: "q" }, () => true);
|
||||
for (const code of [10, 11, 12]) {
|
||||
terminal.parser.registerOscHandler(code, (data) => data.trim() === "?");
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
buildOpenProjectRoute,
|
||||
resolveKnownHostRoute,
|
||||
buildSessionsRoute,
|
||||
buildSettingsAddHostRoute,
|
||||
buildProjectSettingsRoute,
|
||||
buildProjectsSettingsRoute,
|
||||
decodeFilePathFromPathSegment,
|
||||
@@ -184,6 +185,14 @@ describe("workspace route parsing", () => {
|
||||
});
|
||||
|
||||
describe("projects settings routes", () => {
|
||||
it("buildSettingsAddHostRoute opens settings with the add-host flag", () => {
|
||||
expect(buildSettingsAddHostRoute()).toBe("/settings/general?addHost=1");
|
||||
});
|
||||
|
||||
it("buildSettingsAddHostRoute accepts a repeatable intent id", () => {
|
||||
expect(buildSettingsAddHostRoute("retry 1")).toBe("/settings/general?addHost=retry%201");
|
||||
});
|
||||
|
||||
it("buildProjectsSettingsRoute scopes the list to a host", () => {
|
||||
expect(buildProjectsSettingsRoute("host a")).toBe("/settings/hosts/host%20a/projects");
|
||||
});
|
||||
|
||||
@@ -553,6 +553,10 @@ export function buildSettingsSectionRoute(section: SettingsSectionSlug) {
|
||||
return `/settings/${section}` as const;
|
||||
}
|
||||
|
||||
export function buildSettingsAddHostRoute(intentId: string | number = "1") {
|
||||
return `/settings/general?addHost=${encodeURIComponent(String(intentId))}` as const;
|
||||
}
|
||||
|
||||
export function buildSettingsHostRoute(serverId: string) {
|
||||
const normalized = trimNonEmpty(serverId);
|
||||
if (!normalized) {
|
||||
|
||||
@@ -204,16 +204,15 @@ export function createHostTransportFactory(
|
||||
}
|
||||
export function createHostClient(
|
||||
connection: string,
|
||||
config: Omit<DaemonClientConfig, "url"> & HostTransportOptions,
|
||||
config: Omit<DaemonClientConfig, "url" | "transportFactory"> & HostTransportOptions,
|
||||
budget?: HostTransportBudget,
|
||||
): DaemonClient {
|
||||
const target = parseHostTarget(connection);
|
||||
const { webSocketAgent, transportFactory, ...clientConfig } = config;
|
||||
const { webSocketAgent, ...clientConfig } = config;
|
||||
return new DaemonClient({
|
||||
...clientConfig,
|
||||
url: "ws://host-connector/ws",
|
||||
...(target.password ? { password: target.password } : {}),
|
||||
transportFactory:
|
||||
transportFactory ?? createHostTransportFactory(connection, budget, { webSocketAgent }),
|
||||
transportFactory: createHostTransportFactory(connection, budget, { webSocketAgent }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import { fileURLToPath } from "node:url";
|
||||
import { experimental_createMCPClient } from "ai";
|
||||
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
||||
import { chromium } from "playwright";
|
||||
import { expect } from "@playwright/test";
|
||||
import { hideDeveloperToasts } from "../../app/e2e/support/developer-ui.mjs";
|
||||
import { runAppearanceFontSizeRegression } from "./appearance-font-size.electron.mjs";
|
||||
import { runAdaptiveThemeRegression } from "./appearance-theme.electron.mjs";
|
||||
@@ -199,20 +198,6 @@ async function waitForDesktopStatus(page) {
|
||||
);
|
||||
}
|
||||
|
||||
async function settleDesktopStartup(page) {
|
||||
await expect(
|
||||
page.getByRole("button", { name: "Desktop browser workspace 1", exact: true }),
|
||||
).toBeVisible({ timeout: timeoutMs });
|
||||
// The dev launcher supplies its package directory as an open-project request.
|
||||
// Before the local host connects, that request opens the connection prompt.
|
||||
// Finish startup before exercising the unrelated Settings/browser workflows.
|
||||
const connectionPrompt = page.getByTestId("add-host-method-modal");
|
||||
if (await connectionPrompt.isVisible()) {
|
||||
await connectionPrompt.getByRole("button", { name: "Close", exact: true }).click();
|
||||
await expect(connectionPrompt).toBeHidden();
|
||||
}
|
||||
}
|
||||
|
||||
async function startTargetPage() {
|
||||
const server = createServer((_request, response) => {
|
||||
response.writeHead(200, { "content-type": "text/html; charset=utf-8" });
|
||||
@@ -1223,7 +1208,6 @@ async function main() {
|
||||
const page = await waitForAppPage(browser, expoPort);
|
||||
await hideDeveloperToasts(page);
|
||||
const status = await waitForDesktopStatus(page);
|
||||
await settleDesktopStartup(page);
|
||||
|
||||
const checkPluginLinks = () =>
|
||||
runPluginLinksRegression({
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
"@types/node": "24.6.0",
|
||||
"@types/ws": "^8.5.14",
|
||||
"electron": "44.2.0",
|
||||
"electron-builder": "26.18.0",
|
||||
"electron-builder": "26.8.1",
|
||||
"typescript": "5.9.3",
|
||||
"unzip-crx-3": "^0.2.0",
|
||||
"vitest": "^4.1.6",
|
||||
|
||||
@@ -21,7 +21,10 @@ export const AgentProfileSchema = z
|
||||
model: z.string().optional(),
|
||||
modeId: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Read as `options`.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
/** Provider options applied when the profile creates an agent. */
|
||||
options: z.record(z.string(), z.unknown()).optional(),
|
||||
/** Free text, surfaced to orchestrating agents by the `list_profiles` MCP tool. */
|
||||
notes: z.string().optional(),
|
||||
})
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import type { AgentMessage } from "./agent-message.js";
|
||||
import type { AgentAttachment } from "./messages.js";
|
||||
import type {
|
||||
AgentAttachment,
|
||||
AgentOptionChoiceSchema,
|
||||
AgentOptionControlSchema,
|
||||
AgentOptionSelectControlSchema,
|
||||
AgentOptionToggleControlSchema,
|
||||
} from "./messages.js";
|
||||
import type { z } from "zod";
|
||||
|
||||
export type AgentProvider = string;
|
||||
|
||||
@@ -154,6 +161,20 @@ export interface AgentFeatureSelect {
|
||||
|
||||
export type AgentFeature = AgentFeatureToggle | AgentFeatureSelect;
|
||||
|
||||
export type AgentOptionChoice = z.infer<typeof AgentOptionChoiceSchema>;
|
||||
|
||||
/** `key` is the top-level provider option key the control reads and writes. */
|
||||
export type AgentOptionToggleControl = z.infer<typeof AgentOptionToggleControlSchema>;
|
||||
|
||||
/** `defaultValue` is the choice an unset option stands for. */
|
||||
export type AgentOptionSelectControl = z.infer<typeof AgentOptionSelectControlSchema>;
|
||||
|
||||
/**
|
||||
* A provider's description of a composer control over one top-level option key.
|
||||
* The control carries no value: it is read from the agent's effective options.
|
||||
*/
|
||||
export type AgentOptionControl = z.infer<typeof AgentOptionControlSchema>;
|
||||
|
||||
export interface AgentCapabilityFlags {
|
||||
[capability: string]: boolean | undefined;
|
||||
supportsStreaming: boolean;
|
||||
@@ -523,6 +544,10 @@ export interface AgentSessionConfig {
|
||||
modeId?: string;
|
||||
model?: string;
|
||||
thinkingOptionId?: string;
|
||||
/**
|
||||
* @deprecated COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* Folded into `providerOptions` at the daemon's edge; the daemon never reads it internally.
|
||||
*/
|
||||
featureValues?: Record<string, unknown>;
|
||||
title?: string | null;
|
||||
providerOptions?: ProviderOptions;
|
||||
|
||||
@@ -361,6 +361,39 @@ export const AgentFeatureSchema = z.discriminatedUnion("type", [
|
||||
AgentFeatureSelectSchema,
|
||||
]);
|
||||
|
||||
export const AgentOptionChoiceSchema = z.object({
|
||||
value: z.string(),
|
||||
label: z.string(),
|
||||
description: z.string().optional(),
|
||||
});
|
||||
|
||||
export const AgentOptionToggleControlSchema = z.object({
|
||||
type: z.literal("toggle"),
|
||||
key: z.string(),
|
||||
label: z.string(),
|
||||
description: z.string().optional(),
|
||||
tooltip: z.string().optional(),
|
||||
icon: z.string().optional(),
|
||||
defaultValue: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const AgentOptionSelectControlSchema = z.object({
|
||||
type: z.literal("select"),
|
||||
key: z.string(),
|
||||
label: z.string(),
|
||||
description: z.string().optional(),
|
||||
tooltip: z.string().optional(),
|
||||
icon: z.string().optional(),
|
||||
desktopTrigger: z.enum(["icon", "label"]).optional(),
|
||||
defaultValue: z.string().optional(),
|
||||
choices: z.array(AgentOptionChoiceSchema),
|
||||
});
|
||||
|
||||
export const AgentOptionControlSchema = z.discriminatedUnion("type", [
|
||||
AgentOptionToggleControlSchema,
|
||||
AgentOptionSelectControlSchema,
|
||||
]);
|
||||
|
||||
const AgentModelDefinitionSchema = z.object({
|
||||
provider: AgentProviderSchema,
|
||||
id: z.string(),
|
||||
@@ -490,6 +523,7 @@ const AgentSessionConfigSchema = z.object({
|
||||
modeId: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Folded into providerOptions.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
title: z.string().trim().min(1).max(MAX_EXPLICIT_AGENT_TITLE_CHARS).optional().nullable(),
|
||||
providerOptions: ProviderOptionsSchema.optional(),
|
||||
@@ -866,7 +900,11 @@ export const AgentSnapshotPayloadSchema = z.object({
|
||||
cwd: z.string(),
|
||||
workspaceId: z.string().optional(),
|
||||
model: z.string().nullable(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Built from controls + options.
|
||||
features: z.array(AgentFeatureSchema).optional(),
|
||||
/** Effective provider options: `config.json` defaults deep-merged with the agent's own. */
|
||||
options: ProviderOptionsSchema.optional(),
|
||||
controls: z.array(AgentOptionControlSchema).optional(),
|
||||
thinkingOptionId: z.string().nullable().optional(),
|
||||
effectiveThinkingOptionId: z.string().nullable().optional(),
|
||||
createdAt: z.string(),
|
||||
@@ -2055,7 +2093,10 @@ export const AgentConfigApplySchema = z.object({
|
||||
modelId: z.string().nullable().optional(),
|
||||
modeId: z.string().optional(),
|
||||
thinkingOptionId: z.string().nullable().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Maps to an options patch.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
/** Patch of the agent's own options: replaces top-level keys; `null` removes the key. */
|
||||
options: ProviderOptionsSchema.optional(),
|
||||
});
|
||||
|
||||
export type AgentConfigApply = z.infer<typeof AgentConfigApplySchema>;
|
||||
@@ -2971,7 +3012,9 @@ const ListCommandsDraftConfigSchema = z.object({
|
||||
modeId: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Folded into providerOptions.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
providerOptions: ProviderOptionsSchema.optional(),
|
||||
});
|
||||
|
||||
export const ListProviderFeaturesRequestMessageSchema = z.object({
|
||||
@@ -2980,6 +3023,12 @@ export const ListProviderFeaturesRequestMessageSchema = z.object({
|
||||
requestId: z.string(),
|
||||
});
|
||||
|
||||
export const ProviderControlsListRequestMessageSchema = z.object({
|
||||
type: z.literal("provider.controls.list.request"),
|
||||
draftConfig: ListCommandsDraftConfigSchema,
|
||||
requestId: z.string(),
|
||||
});
|
||||
|
||||
export const ListCommandsRequestSchema = z.object({
|
||||
type: z.literal("list_commands_request"),
|
||||
agentId: z.string(),
|
||||
@@ -3157,6 +3206,7 @@ export const HubExecutionAgentCreateRequestSchema = z.object({
|
||||
model: z.string().optional(),
|
||||
modeId: z.string().optional(),
|
||||
thinkingOptionId: z.string().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Folded into providerOptions.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
providerOptions: ProviderOptionsSchema.optional(),
|
||||
toolPolicy: ToolPolicySchema.optional(),
|
||||
@@ -3357,6 +3407,7 @@ export const SessionInboundMessageSchema = z.discriminatedUnion("type", [
|
||||
ListProviderModelsRequestMessageSchema,
|
||||
ListProviderModesRequestMessageSchema,
|
||||
ListProviderFeaturesRequestMessageSchema,
|
||||
ProviderControlsListRequestMessageSchema,
|
||||
ListAvailableProvidersRequestMessageSchema,
|
||||
GetProvidersSnapshotRequestMessageSchema,
|
||||
RefreshProvidersSnapshotRequestMessageSchema,
|
||||
@@ -3836,6 +3887,7 @@ export const ServerInfoStatusPayloadSchema = z
|
||||
selectiveAgentTimeline: z.boolean().optional(),
|
||||
explicitEventSubscriptions: z.boolean().optional(),
|
||||
ownedSubscriptions: z.boolean().optional(),
|
||||
providerOptionControls: z.boolean().optional(),
|
||||
binaryChunkingV1: z.boolean().optional(),
|
||||
workspaceSetupObservation: z.boolean().optional(),
|
||||
workspaceSortTimes: z.boolean().optional(),
|
||||
@@ -6303,6 +6355,19 @@ export const ListProviderModesResponseMessageSchema = z.object({
|
||||
}),
|
||||
});
|
||||
|
||||
export const ProviderControlsListResponseMessageSchema = z.object({
|
||||
type: z.literal("provider.controls.list.response"),
|
||||
payload: z.object({
|
||||
provider: AgentProviderSchema,
|
||||
controls: z.array(AgentOptionControlSchema).optional(),
|
||||
/** Effective options for the draft: `config.json` defaults merged with the draft's own. */
|
||||
options: ProviderOptionsSchema.optional(),
|
||||
error: z.string().nullable().optional(),
|
||||
fetchedAt: z.string(),
|
||||
requestId: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const ListProviderFeaturesResponseMessageSchema = z.object({
|
||||
type: z.literal("list_provider_features_response"),
|
||||
payload: z.object({
|
||||
@@ -7195,6 +7260,7 @@ export const SessionOutboundMessageSchema = z.discriminatedUnion("type", [
|
||||
ListProviderModelsResponseMessageSchema,
|
||||
ListProviderModesResponseMessageSchema,
|
||||
ListProviderFeaturesResponseMessageSchema,
|
||||
ProviderControlsListResponseMessageSchema,
|
||||
ListAvailableProvidersResponseSchema,
|
||||
GetProvidersSnapshotResponseMessageSchema,
|
||||
ProvidersSnapshotUpdateMessageSchema,
|
||||
@@ -7449,6 +7515,12 @@ export type ListProviderModelsRequestMessage = z.infer<
|
||||
typeof ListProviderModelsRequestMessageSchema
|
||||
>;
|
||||
export type ListProviderModesRequestMessage = z.infer<typeof ListProviderModesRequestMessageSchema>;
|
||||
export type ProviderControlsListRequestMessage = z.infer<
|
||||
typeof ProviderControlsListRequestMessageSchema
|
||||
>;
|
||||
export type ProviderControlsListResponseMessage = z.infer<
|
||||
typeof ProviderControlsListResponseMessageSchema
|
||||
>;
|
||||
export type ListProviderFeaturesRequestMessage = z.infer<
|
||||
typeof ListProviderFeaturesRequestMessageSchema
|
||||
>;
|
||||
|
||||
@@ -34,6 +34,7 @@ export const ScheduleTargetSchema = z.discriminatedUnion("type", [
|
||||
isolation: z.enum(["local", "worktree"]).optional(),
|
||||
title: z.string().trim().min(1).nullable().optional(),
|
||||
providerOptions: z.record(z.string(), z.unknown()).optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Folded into providerOptions.
|
||||
featureValues: z.record(z.string(), z.unknown()).optional(),
|
||||
systemPrompt: z.string().optional(),
|
||||
mcpServers: z.record(z.string(), z.unknown()).optional(),
|
||||
|
||||
@@ -56,9 +56,6 @@ function spawnRelayDevServer(port: number): ChildProcess {
|
||||
wranglerCliPath,
|
||||
"dev",
|
||||
"--local",
|
||||
// Local execution still inherits production vars; exercise the local Durable Object.
|
||||
"--var",
|
||||
"PASEO_RELAY_UPSTREAM:",
|
||||
"--ip",
|
||||
"127.0.0.1",
|
||||
"--port",
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
"speech:transcribe:local": "tsx scripts/transcribe-local-wav.ts",
|
||||
"test": "npm run test:unit && npm run test:integration",
|
||||
"test:unit": "vitest run --fileParallelism --exclude \"**/*.e2e.test.ts\"",
|
||||
"test:integration": "vitest run --maxWorkers=1 src/server/git-filename-diffs.e2e.test.ts src/server/daemon-e2e/checkout-diff-content.e2e.test.ts src/server/daemon-e2e/create-agent-mode.e2e.test.ts src/server/daemon-e2e/filesystem.e2e.test.ts src/server/daemon-e2e/file-download.e2e.test.ts src/server/daemon-e2e/cli-logs-follow.e2e.test.ts src/server/creation/creation.e2e.test.ts src/server/daemon-e2e/creation-status.e2e.test.ts src/server/daemon-e2e/terminal-workspace-sdk.e2e.test.ts src/server/daemon-e2e/terminal-worker-lifecycle.e2e.test.ts src/server/workspace-create-worktree-source.e2e.test.ts src/server/daemon-e2e/models.e2e.test.ts src/server/daemon-e2e/live-preferences.e2e.test.ts src/server/daemon-e2e/oversized-message.e2e.test.ts src/server/agent/model-catalog.e2e.test.ts src/server/plugins/plugin-paseo-api.e2e.test.ts src/server/plugins/usage-sources.e2e.test.ts src/server/plugins/lifecycle.e2e.test.ts src/server/connected-hosts/hosts.e2e.test.ts src/server/owned-subscriptions.e2e.test.ts && vitest run --maxWorkers=1 src/server/agent/providers/omp/history.e2e.test.ts src/server/daemon-e2e/git-operations.e2e.test.ts src/server/session.create-agent-worktree-autoarchive.e2e.test.ts src/server/agent/providers/opencode-bridge.local.e2e.test.ts src/server/daemon-e2e/relay-transport.e2e.test.ts -t \"merges into|creates a worktree and auto-archives both|versioned runtime|oversized attachments|connected hosts|password-protected daemon refuses|replays selected OMP history\"",
|
||||
"test:integration": "vitest run --maxWorkers=1 src/server/git-filename-diffs.e2e.test.ts src/server/daemon-e2e/checkout-diff-content.e2e.test.ts src/server/daemon-e2e/filesystem.e2e.test.ts src/server/daemon-e2e/file-download.e2e.test.ts src/server/daemon-e2e/cli-logs-follow.e2e.test.ts src/server/creation/creation.e2e.test.ts src/server/daemon-e2e/creation-status.e2e.test.ts src/server/daemon-e2e/terminal-workspace-sdk.e2e.test.ts src/server/daemon-e2e/terminal-worker-lifecycle.e2e.test.ts src/server/workspace-create-worktree-source.e2e.test.ts src/server/daemon-e2e/models.e2e.test.ts src/server/daemon-e2e/live-preferences.e2e.test.ts src/server/daemon-e2e/oversized-message.e2e.test.ts src/server/agent/model-catalog.e2e.test.ts src/server/plugins/plugin-paseo-api.e2e.test.ts src/server/plugins/usage-sources.e2e.test.ts src/server/plugins/lifecycle.e2e.test.ts src/server/connected-hosts/hosts.e2e.test.ts src/server/owned-subscriptions.e2e.test.ts && vitest run --maxWorkers=1 src/server/agent/providers/omp/history.e2e.test.ts src/server/daemon-e2e/git-operations.e2e.test.ts src/server/session.create-agent-worktree-autoarchive.e2e.test.ts src/server/agent/providers/opencode-bridge.local.e2e.test.ts src/server/daemon-e2e/relay-transport.e2e.test.ts -t \"merges into|creates a worktree and auto-archives both|versioned runtime|oversized attachments|connected hosts|password-protected daemon refuses|replays selected OMP history\"",
|
||||
"test:hub-cli-contract": "vitest run --maxWorkers=1 src/server/hub/hub-cli-contract.test.ts",
|
||||
"test:integration:all": "npm run test:e2e",
|
||||
"test:integration:real": "vitest run real.e2e.test.ts",
|
||||
|
||||
@@ -23,6 +23,7 @@ import { AgentStorage } from "./agent-storage.js";
|
||||
import { InMemoryAgentTimelineStore } from "./agent-timeline-store.js";
|
||||
import { limitAgentTimelineItemContent } from "./agent-timeline-content.js";
|
||||
import { toAgentPayload } from "./agent-projections.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { projectTimelineRows } from "./timeline-projection.js";
|
||||
import { getOpenAgentTabLabel, PARENT_AGENT_ID_LABEL } from "@getpaseo/protocol/agent-labels";
|
||||
import { startAgentRun } from "./agent-prompt.js";
|
||||
@@ -38,7 +39,7 @@ import type {
|
||||
import type {
|
||||
AgentClient,
|
||||
AgentCreateSessionOptions,
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
AgentLaunchContext,
|
||||
AgentPromptInput,
|
||||
AgentProvider,
|
||||
@@ -57,6 +58,7 @@ import type {
|
||||
} from "./agent-sdk-types.js";
|
||||
import type { PaseoToolCatalog } from "./tools/types.js";
|
||||
import type { ProviderDefinition } from "./provider-registry.js";
|
||||
import { mergeProviderOptions } from "./provider-options.js";
|
||||
|
||||
const DESKTOP_OPEN_AGENT_TAB_LABEL = getOpenAgentTabLabel("desktop-client");
|
||||
const MOBILE_OPEN_AGENT_TAB_LABEL = getOpenAgentTabLabel("mobile-client");
|
||||
@@ -182,13 +184,8 @@ class RecordingTimelineStore implements AgentTimelineStore {
|
||||
}
|
||||
}
|
||||
|
||||
function createFeature(args: { id: string; label: string; value: boolean }): AgentFeature {
|
||||
return {
|
||||
type: "toggle",
|
||||
id: args.id,
|
||||
label: args.label,
|
||||
value: args.value,
|
||||
};
|
||||
function createControl(args: { key: string; label: string }): AgentOptionControl {
|
||||
return { type: "toggle", key: args.key, label: args.label };
|
||||
}
|
||||
|
||||
function expectArchivedAgentRecord(
|
||||
@@ -2332,7 +2329,7 @@ test("listDraftCommands uses explicit model config without default model fetchin
|
||||
]);
|
||||
});
|
||||
|
||||
test("listDraftFeatures does not start a fallback session without a model", async () => {
|
||||
test("listDraftControls does not start a fallback session without a model", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-draft-features-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
@@ -2365,18 +2362,21 @@ test("listDraftFeatures does not start a fallback session without a model", asyn
|
||||
logger,
|
||||
});
|
||||
|
||||
await expect(manager.listDraftFeatures({ provider: "codex", cwd: workdir })).resolves.toEqual([]);
|
||||
await expect(manager.listDraftControls({ provider: "codex", cwd: workdir })).resolves.toEqual({
|
||||
controls: [],
|
||||
options: {},
|
||||
});
|
||||
|
||||
expect(client.fetchCatalogCalls).toBe(0);
|
||||
expect(client.createSessionCalls).toBe(0);
|
||||
expect(client.availabilityCalls).toBe(0);
|
||||
});
|
||||
|
||||
test("listDraftFeatures uses client feature listing without a model", async () => {
|
||||
test("listDraftControls uses client feature listing without a model", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-draft-features-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
const draftFeature = createFeature({ id: "auto_accept", label: "Auto Accept", value: false });
|
||||
const draftControl = createControl({ key: "auto_accept", label: "Auto Accept" });
|
||||
class DraftFeatureClient extends TestAgentClient {
|
||||
fetchCatalogCalls = 0;
|
||||
createSessionCalls = 0;
|
||||
@@ -2398,9 +2398,9 @@ test("listDraftFeatures uses client feature listing without a model", async () =
|
||||
return await super.createSession(config);
|
||||
}
|
||||
|
||||
async listFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
async listControls(config: AgentSessionConfig): Promise<AgentOptionControl[]> {
|
||||
this.featureConfigs.push(config);
|
||||
return [draftFeature];
|
||||
return [draftControl];
|
||||
}
|
||||
}
|
||||
const client = new DraftFeatureClient();
|
||||
@@ -2412,9 +2412,13 @@ test("listDraftFeatures uses client feature listing without a model", async () =
|
||||
logger,
|
||||
});
|
||||
|
||||
await expect(manager.listDraftFeatures({ provider: "codex", cwd: workdir })).resolves.toEqual([
|
||||
draftFeature,
|
||||
]);
|
||||
await expect(
|
||||
manager.listDraftControls({
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { auto_accept: true },
|
||||
}),
|
||||
).resolves.toEqual({ controls: [draftControl], options: { auto_accept: true } });
|
||||
|
||||
expect(client.fetchCatalogCalls).toBe(0);
|
||||
expect(client.createSessionCalls).toBe(0);
|
||||
@@ -2423,15 +2427,28 @@ test("listDraftFeatures uses client feature listing without a model", async () =
|
||||
{
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { auto_accept: true },
|
||||
},
|
||||
]);
|
||||
|
||||
// Options without a control come back too.
|
||||
await expect(
|
||||
manager.listDraftControls({
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { auto_accept: true, sandbox_mode: "workspace-write" },
|
||||
}),
|
||||
).resolves.toEqual({
|
||||
controls: [draftControl],
|
||||
options: { auto_accept: true, sandbox_mode: "workspace-write" },
|
||||
});
|
||||
});
|
||||
|
||||
test("listDraftFeatures uses explicit model config without default model fetching", async () => {
|
||||
test("listDraftControls uses explicit model config without default model fetching", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-draft-features-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
const draftFeature = createFeature({ id: "fast_mode", label: "Fast mode", value: false });
|
||||
const draftControl = createControl({ key: "web_search", label: "Fast mode" });
|
||||
class DraftFeatureClient extends TestAgentClient {
|
||||
fetchCatalogCalls = 0;
|
||||
createSessionCalls = 0;
|
||||
@@ -2447,9 +2464,9 @@ test("listDraftFeatures uses explicit model config without default model fetchin
|
||||
return await super.createSession(config);
|
||||
}
|
||||
|
||||
async listFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
async listControls(config: AgentSessionConfig): Promise<AgentOptionControl[]> {
|
||||
this.featureConfigs.push(config);
|
||||
return [draftFeature];
|
||||
return [draftControl];
|
||||
}
|
||||
}
|
||||
const client = new DraftFeatureClient();
|
||||
@@ -2461,13 +2478,13 @@ test("listDraftFeatures uses explicit model config without default model fetchin
|
||||
logger,
|
||||
});
|
||||
|
||||
const features = await manager.listDraftFeatures({
|
||||
const draft = await manager.listDraftControls({
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
model: "gpt-5.4",
|
||||
});
|
||||
|
||||
expect(features).toEqual([draftFeature]);
|
||||
expect(draft).toEqual({ controls: [draftControl], options: {} });
|
||||
expect(client.fetchCatalogCalls).toBe(0);
|
||||
expect(client.createSessionCalls).toBe(0);
|
||||
expect(client.featureConfigs).toEqual([
|
||||
@@ -4550,6 +4567,46 @@ test("resumeAgentFromPersistence keeps metadata config, applies overrides, and p
|
||||
});
|
||||
});
|
||||
|
||||
test("importProviderSession reports the defaults the session launched with, not defaults edited during the import", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-import-options-"));
|
||||
let tier = "default";
|
||||
class ImportClient extends TestAgentClient {
|
||||
effectiveOptions(own: ProviderOptions | undefined): ProviderOptions {
|
||||
return { service_tier: tier, ...own };
|
||||
}
|
||||
|
||||
async importSession(input: ImportProviderSessionInput) {
|
||||
// The user edits the default in config.json after the provider has launched.
|
||||
tier = "fast";
|
||||
return {
|
||||
session: new TestAgentSession({ provider: "codex", cwd: workdir }),
|
||||
config: { provider: "codex" as const, cwd: workdir },
|
||||
persistence: {
|
||||
provider: "codex" as const,
|
||||
sessionId: input.providerHandleId,
|
||||
nativeHandle: input.providerHandleId,
|
||||
metadata: { provider: "codex", cwd: workdir },
|
||||
},
|
||||
timeline: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: new ImportClient() },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
|
||||
const imported = await manager.importProviderSession({
|
||||
provider: "codex",
|
||||
providerHandleId: "thread-selected",
|
||||
cwd: workdir,
|
||||
workspaceId: "ws-imported",
|
||||
});
|
||||
|
||||
expect(imported.effectiveOptions).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
test("importProviderSession imports the selected session without listing and publishes ready state", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-import-session-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
@@ -9984,16 +10041,13 @@ test("respondToPermission updates currentModeId after plan approval", async () =
|
||||
expect(client.resumedModeId).toBe("acceptEdits");
|
||||
});
|
||||
|
||||
test("respondToPermission refreshes features and runtime info after provider-managed plan approval", async () => {
|
||||
test("respondToPermission applies provider option changes and refreshes runtime info after provider-managed plan approval", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-test-"));
|
||||
const storagePath = join(workdir, "agents");
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
|
||||
class RefreshingPermissionSession extends TestAgentSession {
|
||||
private featureState: AgentFeature[] = [
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
createFeature({ id: "plan_mode", label: "Plan", value: true }),
|
||||
];
|
||||
private planMode = true;
|
||||
private modeId = "auto";
|
||||
private pending = [
|
||||
{
|
||||
@@ -10005,8 +10059,11 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
},
|
||||
];
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
return this.featureState;
|
||||
get controls(): AgentOptionControl[] {
|
||||
return [
|
||||
createControl({ key: "web_search", label: "Fast" }),
|
||||
createControl({ key: "plan_mode", label: "Plan" }),
|
||||
];
|
||||
}
|
||||
|
||||
override async getRuntimeInfo() {
|
||||
@@ -10015,7 +10072,7 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
sessionId: this.id,
|
||||
model: "gpt-5.4",
|
||||
modeId: this.modeId,
|
||||
extra: { collaborationMode: this.features[1]?.value ? "Plan" : "Code" },
|
||||
extra: { collaborationMode: this.planMode ? "Plan" : "Code" },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10030,10 +10087,12 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
override async respondToPermission(): Promise<void> {
|
||||
this.modeId = "auto";
|
||||
this.pending = [];
|
||||
this.featureState = [
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
createFeature({ id: "plan_mode", label: "Plan", value: false }),
|
||||
];
|
||||
this.planMode = false;
|
||||
this.pushEvent({
|
||||
type: "options_changed",
|
||||
provider: this.provider,
|
||||
patch: { plan_mode: false },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10056,6 +10115,7 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
{
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { web_search: true, plan_mode: true },
|
||||
},
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
@@ -10080,20 +10140,14 @@ test("respondToPermission refreshes features and runtime info after provider-man
|
||||
|
||||
const updated = manager.getAgent(snapshot.id);
|
||||
expect(updated?.pendingPermissions.size).toBe(0);
|
||||
expect(updated?.features).toEqual([
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
createFeature({ id: "plan_mode", label: "Plan", value: false }),
|
||||
]);
|
||||
expect(updated?.effectiveOptions).toEqual({ web_search: true, plan_mode: false });
|
||||
expect(updated?.runtimeInfo).toMatchObject({
|
||||
model: "gpt-5.4",
|
||||
extra: { collaborationMode: "Code" },
|
||||
});
|
||||
|
||||
const persisted = await storage.get(snapshot.id);
|
||||
expect(persisted?.features).toEqual([
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
createFeature({ id: "plan_mode", label: "Plan", value: false }),
|
||||
]);
|
||||
expect(persisted?.config?.providerOptions).toEqual({ web_search: true, plan_mode: false });
|
||||
});
|
||||
|
||||
test("respondToPermission emits refreshed state before permission_resolved", async () => {
|
||||
@@ -10102,9 +10156,6 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
|
||||
class OrderedPermissionSession extends TestAgentSession {
|
||||
private featureState: AgentFeature[] = [
|
||||
createFeature({ id: "fast_mode", label: "Fast", value: true }),
|
||||
];
|
||||
private modeId = "plan";
|
||||
private pending = [
|
||||
{
|
||||
@@ -10116,8 +10167,8 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
},
|
||||
];
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
return this.featureState;
|
||||
get controls(): AgentOptionControl[] {
|
||||
return [createControl({ key: "web_search", label: "Fast" })];
|
||||
}
|
||||
|
||||
override async getRuntimeInfo() {
|
||||
@@ -10138,6 +10189,11 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
}
|
||||
|
||||
override async respondToPermission(): Promise<void> {
|
||||
this.pushEvent({
|
||||
type: "options_changed",
|
||||
provider: this.provider,
|
||||
patch: { web_search: false },
|
||||
});
|
||||
this.pushEvent({
|
||||
type: "permission_resolved",
|
||||
provider: this.provider,
|
||||
@@ -10145,7 +10201,6 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
resolution: { behavior: "allow" },
|
||||
});
|
||||
this.modeId = "acceptEdits";
|
||||
this.featureState = [createFeature({ id: "fast_mode", label: "Fast", value: false })];
|
||||
this.pending = [];
|
||||
}
|
||||
}
|
||||
@@ -10169,6 +10224,7 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
{
|
||||
provider: "codex",
|
||||
cwd: workdir,
|
||||
providerOptions: { web_search: true },
|
||||
},
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
@@ -10180,9 +10236,8 @@ test("respondToPermission emits refreshed state before permission_resolved", asy
|
||||
return;
|
||||
}
|
||||
if (event.type === "agent_state" && event.agent.id === snapshot.id) {
|
||||
const fastMode = event.agent.features?.find((feature) => feature.id === "fast_mode");
|
||||
seen.push(
|
||||
`state:${event.agent.currentModeId}:${String(fastMode?.type === "toggle" ? fastMode.value : null)}`,
|
||||
`state:${event.agent.currentModeId}:${String(event.agent.effectiveOptions?.web_search)}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -12695,3 +12750,478 @@ test("an out-of-band command racing idle cleanup waits for the resumed runtime",
|
||||
expect(h.commands).toEqual(["/maintenance"]);
|
||||
expect(h.prompts).toEqual([]);
|
||||
});
|
||||
|
||||
describe("agent options", () => {
|
||||
class OptionsSession extends TestAgentSession {
|
||||
readonly applied: ProviderOptions[] = [];
|
||||
rejectWith: Error | null = null;
|
||||
applyGate: Promise<void> | null = null;
|
||||
/** What the session says it ended up with after the next apply. */
|
||||
ended: Record<string, unknown> = {};
|
||||
openOptionsPatch: Record<string, unknown> = {};
|
||||
|
||||
async applyOptions(options: ProviderOptions): Promise<Record<string, unknown>> {
|
||||
if (this.rejectWith) throw this.rejectWith;
|
||||
await this.applyGate;
|
||||
this.applied.push(options);
|
||||
return this.ended;
|
||||
}
|
||||
}
|
||||
|
||||
class OptionsClient extends TestAgentClient {
|
||||
session: OptionsSession | null = null;
|
||||
openOptionsPatch: Record<string, unknown> = {};
|
||||
|
||||
// Stands in for the `config.json` provider defaults the registry wrapper merges in.
|
||||
effectiveOptions(own: ProviderOptions | undefined): ProviderOptions {
|
||||
return { service_tier: "default", ...own };
|
||||
}
|
||||
|
||||
override async createSession(config: AgentSessionConfig): Promise<AgentSession> {
|
||||
this.session = new OptionsSession(config);
|
||||
this.session.openOptionsPatch = this.openOptionsPatch;
|
||||
return this.session;
|
||||
}
|
||||
}
|
||||
|
||||
async function createOptionsAgent(
|
||||
providerOptions?: ProviderOptions,
|
||||
openOptionsPatch: Record<string, unknown> = {},
|
||||
) {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-options-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const client = new OptionsClient();
|
||||
client.openOptionsPatch = openOptionsPatch;
|
||||
const manager = new AgentManager({ clients: { codex: client }, registry: storage, logger });
|
||||
const agent = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, ...(providerOptions ? { providerOptions } : {}) },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
return { manager, client, storage, agentId: agent.id };
|
||||
}
|
||||
|
||||
test("config.json defaults show as effective options without entering the agent's own options", async () => {
|
||||
const { manager, agentId } = await createOptionsAgent({ web_search: true });
|
||||
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toEqual({ web_search: true });
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "default", web_search: true });
|
||||
expect(toAgentPayload(agent!).options).toEqual({ service_tier: "default", web_search: true });
|
||||
});
|
||||
|
||||
test("setAgentOptions hands the provider only the keys the patch sets", async () => {
|
||||
const { manager, client, storage, agentId } = await createOptionsAgent({ web_search: true });
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: "fast" });
|
||||
|
||||
expect(client.session?.applied).toEqual([{ service_tier: "fast" }]);
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toEqual({ web_search: true, service_tier: "fast" });
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "fast", web_search: true });
|
||||
await manager.flush();
|
||||
expect((await storage.get(agentId))?.config?.providerOptions).toEqual({
|
||||
web_search: true,
|
||||
service_tier: "fast",
|
||||
});
|
||||
});
|
||||
|
||||
test("a patch key is resolved against the configured defaults, merging nested objects", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-options-"));
|
||||
const client = new OptionsClient();
|
||||
client.effectiveOptions = (own) =>
|
||||
mergeProviderOptions({ sandbox: { enabled: true, failIfUnavailable: true } }, own) ?? {};
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
const agent = await manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
|
||||
await manager.setAgentOptions(agent.id, {
|
||||
sandbox: { network: { allowedDomains: ["a.test"] } },
|
||||
});
|
||||
|
||||
expect(client.session?.applied).toEqual([
|
||||
{
|
||||
sandbox: {
|
||||
enabled: true,
|
||||
failIfUnavailable: true,
|
||||
network: { allowedDomains: ["a.test"] },
|
||||
},
|
||||
},
|
||||
]);
|
||||
expect(manager.getAgent(agent.id)?.config.providerOptions).toEqual({
|
||||
sandbox: { network: { allowedDomains: ["a.test"] } },
|
||||
});
|
||||
// The snapshot shows what the provider was given, defaults included, and keeps showing it.
|
||||
await manager.markAgentUnread(agent.id);
|
||||
expect(manager.getAgent(agent.id)?.effectiveOptions).toEqual({
|
||||
sandbox: {
|
||||
enabled: true,
|
||||
failIfUnavailable: true,
|
||||
network: { allowedDomains: ["a.test"] },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("setAgentOptions sends a removal to the provider like any change, as the default it falls back to", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ service_tier: "fast" });
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: null });
|
||||
|
||||
expect(client.session?.applied).toEqual([{ service_tier: "default" }]);
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toBeUndefined();
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
test("a removal with no default is sent as null", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ web_search: true });
|
||||
|
||||
await manager.setAgentOptions(agentId, { web_search: null });
|
||||
|
||||
expect(client.session?.applied).toEqual([{ web_search: null }]);
|
||||
expect(manager.getAgent(agentId)?.config.providerOptions).toBeUndefined();
|
||||
});
|
||||
|
||||
test("a value the provider kept through a removal is stored", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ web_search: true });
|
||||
client.session!.ended = { web_search: true };
|
||||
|
||||
await manager.setAgentOptions(agentId, { web_search: null });
|
||||
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toEqual({ web_search: true });
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "default", web_search: true });
|
||||
});
|
||||
|
||||
test("what the provider ended up with is stored together with the patch", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent();
|
||||
client.session!.ended = { service_tier: "slow" };
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: "fast", plan_mode: true });
|
||||
|
||||
expect(manager.getAgent(agentId)?.config.providerOptions).toEqual({
|
||||
service_tier: "slow",
|
||||
plan_mode: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("the difference a session opened with is stored before the agent is published", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-options-"));
|
||||
const client = new OptionsClient();
|
||||
client.openOptionsPatch = { service_tier: "slow", web_search: null };
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
const published: Array<ProviderOptions | undefined> = [];
|
||||
manager.subscribe((event) => {
|
||||
if (event.type === "agent_state") published.push(event.agent.config.providerOptions);
|
||||
});
|
||||
|
||||
const agent = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: true } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
expect(agent.config.providerOptions).toEqual({ service_tier: "slow" });
|
||||
expect(published.length).toBeGreaterThan(0);
|
||||
expect(published.every((options) => options?.service_tier === "slow")).toBe(true);
|
||||
});
|
||||
|
||||
test("a default edited while the session is opening does not change the opening snapshot", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-options-"));
|
||||
const client = new OptionsClient();
|
||||
let tier = "default";
|
||||
client.effectiveOptions = (own) => ({ service_tier: tier, ...own });
|
||||
const open = client.createSession.bind(client);
|
||||
client.createSession = async (config) => {
|
||||
const session = await open(config);
|
||||
// The user edits the default in config.json after the provider has launched.
|
||||
tier = "fast";
|
||||
return session;
|
||||
};
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
|
||||
const agent = await manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
|
||||
expect(agent.effectiveOptions).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
test("an option the session dropped when opening does not come back from a configured default", async () => {
|
||||
const { manager, agentId } = await createOptionsAgent(undefined, { service_tier: null });
|
||||
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.effectiveOptions).toEqual({});
|
||||
await manager.markAgentUnread(agentId);
|
||||
expect(toAgentPayload(manager.getAgent(agentId)!).options).toEqual({});
|
||||
});
|
||||
|
||||
test("an option without a control is settable through the patch and readable in the snapshot", async () => {
|
||||
const { manager, client, storage, agentId } = await createOptionsAgent();
|
||||
|
||||
await manager.setAgentOptions(agentId, { sandbox_mode: "read-only" });
|
||||
|
||||
expect(client.session?.applied).toEqual([{ sandbox_mode: "read-only" }]);
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.config.providerOptions).toEqual({ sandbox_mode: "read-only" });
|
||||
expect(toAgentPayload(agent!).options).toEqual({
|
||||
service_tier: "default",
|
||||
sandbox_mode: "read-only",
|
||||
});
|
||||
await manager.flush();
|
||||
expect((await storage.get(agentId))?.config?.providerOptions).toEqual({
|
||||
sandbox_mode: "read-only",
|
||||
});
|
||||
});
|
||||
|
||||
test("concurrent patches both land: each is applied to the options as they are when its provider call resolves", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent();
|
||||
let release!: () => void;
|
||||
client.session!.applyGate = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
|
||||
const slow = manager.setAgentOptions(agentId, { sandbox_mode: "read-only" });
|
||||
client.session!.applyGate = null;
|
||||
await manager.setAgentOptions(agentId, { web_search: true });
|
||||
release();
|
||||
await slow;
|
||||
|
||||
expect(manager.getAgent(agentId)?.config.providerOptions).toEqual({
|
||||
sandbox_mode: "read-only",
|
||||
web_search: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("a stored agent that is not loaded still reports its effective options", async () => {
|
||||
const { manager, agentId } = await createOptionsAgent({ web_search: true });
|
||||
await manager.closeAgent(agentId);
|
||||
const states: ManagedAgent[] = [];
|
||||
manager.subscribe(
|
||||
(event) => {
|
||||
if (event.type === "agent_state" && event.agent.id === agentId) states.push(event.agent);
|
||||
},
|
||||
{ replayState: false },
|
||||
);
|
||||
|
||||
await manager.markAgentUnread(agentId);
|
||||
|
||||
expect(states.at(-1)?.effectiveOptions).toEqual({ service_tier: "default", web_search: true });
|
||||
});
|
||||
|
||||
test("editing a provider default does not change the options of a loaded agent", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ web_search: true });
|
||||
expect(manager.getAgent(agentId)?.effectiveOptions).toEqual({
|
||||
service_tier: "default",
|
||||
web_search: true,
|
||||
});
|
||||
|
||||
// The user edits the default in config.json while the agent is running.
|
||||
client.effectiveOptions = (own) => ({ service_tier: "fast", ...own });
|
||||
await manager.markAgentUnread(agentId);
|
||||
|
||||
const agent = manager.getAgent(agentId);
|
||||
expect(agent?.effectiveOptions).toEqual({ service_tier: "default", web_search: true });
|
||||
expect(toAgentPayload(agent!).options).toEqual({ service_tier: "default", web_search: true });
|
||||
});
|
||||
|
||||
test("a provider that rejects an option leaves the stored options unchanged", async () => {
|
||||
const { manager, client, agentId } = await createOptionsAgent({ web_search: false });
|
||||
client.session!.rejectWith = new Error("fast mode unavailable");
|
||||
|
||||
await expect(manager.setAgentOptions(agentId, { web_search: true })).rejects.toThrow(
|
||||
"fast mode unavailable",
|
||||
);
|
||||
|
||||
expect(manager.getAgent(agentId)?.config.providerOptions).toEqual({ web_search: false });
|
||||
});
|
||||
|
||||
test("a provider whose session cannot apply options rejects a patch and stores nothing", async () => {
|
||||
// Like a provider with no live option support: the session has no `applyOptions`.
|
||||
class NoOptionsSession extends TestAgentSession {
|
||||
constructor(config: AgentSessionConfig) {
|
||||
super(config);
|
||||
Object.defineProperty(this, "applyOptions", { value: undefined });
|
||||
}
|
||||
}
|
||||
class NoOptionsClient extends TestAgentClient {
|
||||
override async createSession(config: AgentSessionConfig): Promise<AgentSession> {
|
||||
return new NoOptionsSession(config);
|
||||
}
|
||||
}
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-no-options-"));
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: new NoOptionsClient() },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
});
|
||||
const agent = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: false } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
await expect(manager.setAgentOptions(agent.id, { web_search: true })).rejects.toThrow(
|
||||
/web_search.*cannot change on a running session/,
|
||||
);
|
||||
|
||||
expect(manager.getAgent(agent.id)?.config.providerOptions).toEqual({ web_search: false });
|
||||
});
|
||||
|
||||
test("agent.create.before hook featureValues fold into providerOptions", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-hook-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const client = new OptionsClient();
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: storage,
|
||||
logger,
|
||||
pluginLifecycle: {
|
||||
emit: () => {},
|
||||
before: async (_name, request) => ({
|
||||
...request,
|
||||
config: { ...request.config, featureValues: { web_search: true } },
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const created = await manager.createAgent({ provider: "codex", cwd: workdir }, undefined, {
|
||||
workspaceId: undefined,
|
||||
});
|
||||
|
||||
expect(manager.getAgent(created.id)?.config.providerOptions).toEqual({ web_search: true });
|
||||
expect(manager.getAgent(created.id)?.config).not.toHaveProperty("featureValues");
|
||||
});
|
||||
|
||||
test("agent.create.before hook featureValues edit overrides an option the create already set", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-hook-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const client = new OptionsClient();
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: storage,
|
||||
logger,
|
||||
pluginLifecycle: {
|
||||
emit: () => {},
|
||||
// A plugin written against the previous SDK: flips one value, leaves the rest.
|
||||
before: async (name, request) =>
|
||||
name === "agent.create.before"
|
||||
? {
|
||||
...request,
|
||||
config: {
|
||||
...request.config,
|
||||
featureValues: { ...request.config.featureValues, web_search: true },
|
||||
},
|
||||
}
|
||||
: request,
|
||||
},
|
||||
});
|
||||
|
||||
const created = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: false, plan_mode: true } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
expect(manager.getAgent(created.id)?.config.providerOptions).toEqual({
|
||||
web_search: true,
|
||||
plan_mode: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("agent.create.before hook leaving featureValues untouched keeps providerOptions edits", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-hook-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const client = new OptionsClient();
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: client },
|
||||
registry: storage,
|
||||
logger,
|
||||
pluginLifecycle: {
|
||||
emit: () => {},
|
||||
before: async (name, request) =>
|
||||
name === "agent.create.before"
|
||||
? {
|
||||
...request,
|
||||
config: {
|
||||
...request.config,
|
||||
providerOptions: { ...request.config.providerOptions, plan_mode: false },
|
||||
},
|
||||
}
|
||||
: request,
|
||||
},
|
||||
});
|
||||
|
||||
const created = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: false, plan_mode: true } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
expect(manager.getAgent(created.id)?.config.providerOptions).toEqual({
|
||||
web_search: false,
|
||||
plan_mode: false,
|
||||
});
|
||||
});
|
||||
|
||||
describe.each([
|
||||
{
|
||||
name: "deletes a key",
|
||||
edit: (values: Record<string, unknown> | undefined) => {
|
||||
const { web_search: _removed, ...rest } = values ?? {};
|
||||
return { featureValues: rest };
|
||||
},
|
||||
expected: { plan_mode: true },
|
||||
},
|
||||
{
|
||||
name: "empties featureValues",
|
||||
edit: () => ({ featureValues: {} }),
|
||||
expected: {},
|
||||
},
|
||||
{
|
||||
name: "drops featureValues",
|
||||
edit: () => ({ featureValues: undefined }),
|
||||
expected: {},
|
||||
},
|
||||
])("agent.create.before hook that $name", ({ edit, expected }) => {
|
||||
test("removes those options from the new agent", async () => {
|
||||
const workdir = mkdtempSync(join(tmpdir(), "agent-manager-hook-"));
|
||||
const manager = new AgentManager({
|
||||
clients: { codex: new OptionsClient() },
|
||||
registry: new AgentStorage(join(workdir, "agents"), logger),
|
||||
logger,
|
||||
pluginLifecycle: {
|
||||
emit: () => {},
|
||||
before: async (name, request) =>
|
||||
name === "agent.create.before"
|
||||
? {
|
||||
...request,
|
||||
config: { ...request.config, ...edit(request.config.featureValues) },
|
||||
}
|
||||
: request,
|
||||
},
|
||||
});
|
||||
|
||||
const created = await manager.createAgent(
|
||||
{ provider: "codex", cwd: workdir, providerOptions: { web_search: true, plan_mode: true } },
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
|
||||
expect(manager.getAgent(created.id)?.config.providerOptions).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AttachedAgentTool, PluginAgentToolsRuntime } from "../plugins/agent-tools.js";
|
||||
import { ProviderOptionsValidationError } from "./provider-options.js";
|
||||
import type { AgentToolResult } from "@getpaseo/plugin/server";
|
||||
import type { RuntimeCleanupCandidate } from "./idle-runtime-cleanup/index.js";
|
||||
import { ensureAgentLoaded } from "./agent-loading.js";
|
||||
@@ -33,7 +34,7 @@ import {
|
||||
type AgentCreateSessionOptions,
|
||||
type AgentResumePurpose,
|
||||
type AgentResumeSessionOptions,
|
||||
type AgentFeature,
|
||||
type AgentOptionControl,
|
||||
type AgentLaunchContext,
|
||||
type AgentSlashCommand,
|
||||
type AgentMode,
|
||||
@@ -59,7 +60,16 @@ import {
|
||||
type ListImportableSessionsOptions,
|
||||
} from "./agent-sdk-types.js";
|
||||
import { buildArchivedAgentRecord, type ArchivedStoredAgentRecord } from "./agent-archive.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { toStoredAgentRecord } from "./agent-projections.js";
|
||||
import {
|
||||
applyProviderOptionsPatch,
|
||||
exposeFeatureValuesToHook,
|
||||
convertLegacyOptions,
|
||||
resolveAdapter,
|
||||
foldHookFeatureValues,
|
||||
type ProviderOptionsPatch,
|
||||
} from "./option-controls.js";
|
||||
import type { StoredAgentRecord, AgentStorage } from "./agent-storage.js";
|
||||
import type { AgentOwner } from "./agent-owner.js";
|
||||
import {
|
||||
@@ -210,9 +220,6 @@ function buildStoredAgentConfig(record: StoredAgentRecord): AgentSessionConfig {
|
||||
if (record.config.thinkingOptionId != null) {
|
||||
config.thinkingOptionId = record.config.thinkingOptionId;
|
||||
}
|
||||
if (record.config.featureValues != null) {
|
||||
config.featureValues = record.config.featureValues;
|
||||
}
|
||||
if (record.config.providerOptions != null) {
|
||||
config.providerOptions = record.config.providerOptions;
|
||||
}
|
||||
@@ -428,7 +435,9 @@ interface ManagedAgentBase {
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
availableModes: AgentMode[];
|
||||
features?: AgentFeature[];
|
||||
controls?: AgentOptionControl[];
|
||||
/** `config.json` defaults deep-merged with `config.providerOptions`; refreshed on every state emit. */
|
||||
effectiveOptions?: ProviderOptions;
|
||||
currentModeId: string | null;
|
||||
pendingPermissions: Map<string, AgentPermissionRequest>;
|
||||
bufferedPermissionResolutions: Map<
|
||||
@@ -1243,11 +1252,17 @@ export class AgentManager {
|
||||
}
|
||||
}
|
||||
|
||||
async listDraftFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
async listDraftControls(
|
||||
config: AgentSessionConfig,
|
||||
): Promise<{ controls: AgentOptionControl[]; options: ProviderOptions }> {
|
||||
const normalizedConfig = await this.normalizeConfig(config, { resolveDefaultModel: false });
|
||||
const client = this.requireClient(normalizedConfig.provider);
|
||||
if (!normalizedConfig.model && !client.listFeatures) {
|
||||
return [];
|
||||
const options = this.effectiveOptionsFor(
|
||||
normalizedConfig.provider,
|
||||
normalizedConfig.providerOptions,
|
||||
);
|
||||
if (!normalizedConfig.model && !client.listControls) {
|
||||
return { controls: [], options };
|
||||
}
|
||||
const available = await client.isAvailable();
|
||||
if (!available) {
|
||||
@@ -1256,13 +1271,18 @@ export class AgentManager {
|
||||
);
|
||||
}
|
||||
|
||||
if (client.listFeatures) {
|
||||
return await client.listFeatures(normalizedConfig);
|
||||
if (client.listControls) {
|
||||
return { controls: await client.listControls(normalizedConfig), options };
|
||||
}
|
||||
|
||||
const session = await client.createSession(normalizedConfig);
|
||||
try {
|
||||
return session.features ?? [];
|
||||
// The options a session opens with, as create would report them, so the controls'
|
||||
// selection matches what the first turn runs with.
|
||||
return {
|
||||
controls: session.controls ?? [],
|
||||
options: this.openedEffectiveOptions({ session, launchedOptions: options }),
|
||||
};
|
||||
} finally {
|
||||
try {
|
||||
await session.close();
|
||||
@@ -1360,12 +1380,23 @@ export class AgentManager {
|
||||
): Promise<ManagedAgent> {
|
||||
this.assertAcceptingAgentRegistrations();
|
||||
const resolvedAgentId = validateAgentId(agentId ?? this.idFactory(), "createAgent");
|
||||
config = this.withConvertedOptions(config);
|
||||
if (this.pluginLifecycle && !config.internal) {
|
||||
const sent = exposeFeatureValuesToHook(config);
|
||||
const request = await this.pluginLifecycle.before("agent.create.before", {
|
||||
config,
|
||||
config: sent,
|
||||
env: options.env,
|
||||
});
|
||||
config = { ...request.config, internal: config.internal };
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. A plugin written
|
||||
// against the previous SDK edits `config.featureValues`.
|
||||
config = {
|
||||
...foldHookFeatureValues({
|
||||
returned: request.config,
|
||||
sent,
|
||||
convert: (values) => this.convertLegacyOptions(request.config.provider, values),
|
||||
}),
|
||||
internal: config.internal,
|
||||
};
|
||||
options = { ...options, env: request.env };
|
||||
}
|
||||
await this.deleteAgentState(resolvedAgentId);
|
||||
@@ -1395,9 +1426,11 @@ export class AgentManager {
|
||||
);
|
||||
const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||
const createOptions = this.buildCreateSessionOptions(options);
|
||||
const launchedOptions = this.launchOptionsFor({ client, own: storedConfig.providerOptions });
|
||||
const session = await client.createSession(providerLaunchConfig, launchContext, createOptions);
|
||||
await this.requireExternalMcpSupport(session, providerLaunchConfig, launchContext);
|
||||
const agent = await this.registerSession(session, storedConfig, resolvedAgentId, {
|
||||
launchedOptions,
|
||||
labels: options.labels,
|
||||
initialTitle: options.initialTitle,
|
||||
workspaceId: options.workspaceId,
|
||||
@@ -1520,6 +1553,7 @@ export class AgentManager {
|
||||
},
|
||||
);
|
||||
const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||
const launchedOptions = this.launchOptionsFor({ client, own: storedConfig.providerOptions });
|
||||
const session = await client.resumeSession(
|
||||
handle,
|
||||
providerLaunchConfig,
|
||||
@@ -1528,6 +1562,7 @@ export class AgentManager {
|
||||
);
|
||||
await this.requireExternalMcpSupport(session, providerLaunchConfig, launchContext);
|
||||
return this.registerSession(session, storedConfig, resolvedAgentId, {
|
||||
launchedOptions,
|
||||
...options,
|
||||
launchEnv,
|
||||
persistence: handle,
|
||||
@@ -1583,6 +1618,7 @@ export class AgentManager {
|
||||
},
|
||||
);
|
||||
const providerLaunchConfig = this.resolveProviderLaunchConfig(launchConfig, launchContext);
|
||||
const launchedOptions = this.launchOptionsFor({ client, own: storedConfig.providerOptions });
|
||||
const imported = await client.importSession(
|
||||
{
|
||||
providerHandleId: input.providerHandleId,
|
||||
@@ -1601,6 +1637,7 @@ export class AgentManager {
|
||||
|
||||
handedToRegistration = true;
|
||||
const agent = await this.registerSession(imported.session, importedConfig, resolvedAgentId, {
|
||||
launchedOptions,
|
||||
labels: input.labels,
|
||||
workspaceId: input.workspaceId,
|
||||
timelineRows,
|
||||
@@ -1706,6 +1743,7 @@ export class AgentManager {
|
||||
this.assertAcceptingAgentRegistrations();
|
||||
|
||||
this.paseoToolPolicies.set(agentId, paseoToolPolicy);
|
||||
const launchedOptions = this.launchOptionsFor({ client, own: storedConfig.providerOptions });
|
||||
session = handle
|
||||
? await client.resumeSession(handle, providerLaunchConfig, launchContext)
|
||||
: await client.createSession(providerLaunchConfig, launchContext);
|
||||
@@ -1724,6 +1762,7 @@ export class AgentManager {
|
||||
// Preserve existing labels and timeline during reload.
|
||||
handedToRegistration = true;
|
||||
return this.registerSession(session, storedConfig, agentId, {
|
||||
launchedOptions,
|
||||
labels: existing.labels,
|
||||
workspaceId: existing.workspaceId,
|
||||
owner: existing.owner,
|
||||
@@ -2161,7 +2200,11 @@ export class AgentManager {
|
||||
createdAt: new Date(record.createdAt),
|
||||
updatedAt,
|
||||
availableModes: [],
|
||||
features: record.features,
|
||||
controls: record.controls,
|
||||
effectiveOptions: this.effectiveOptionsFor(
|
||||
record.provider,
|
||||
record.config?.providerOptions ?? undefined,
|
||||
),
|
||||
currentModeId: record.lastModeId ?? null,
|
||||
pendingPermissions: new Map(),
|
||||
bufferedPermissionResolutions: new Map(),
|
||||
@@ -2254,20 +2297,109 @@ export class AgentManager {
|
||||
return notice;
|
||||
}
|
||||
|
||||
async setAgentFeature(agentId: string, featureId: string, value: unknown): Promise<void> {
|
||||
/**
|
||||
* Applies an options patch to a running agent (see `AgentSession.applyOptions`). The provider
|
||||
* gets each key the patch touches, resolved against the `config.json` defaults, with `null`
|
||||
* where nothing is set. The patch and whatever the provider says it ended up with are stored in
|
||||
* one step once the provider accepts, over the options as they are at that moment, so concurrent
|
||||
* writes to one agent resolve by arrival order.
|
||||
*/
|
||||
async setAgentOptions(agentId: string, requested: ProviderOptionsPatch): Promise<void> {
|
||||
const agent = this.requireAgent(agentId);
|
||||
|
||||
if (!agent.session.setFeature) {
|
||||
throw new Error("Agent session does not support setting features");
|
||||
const patch = this.convertLegacyOptions(agent.provider, requested);
|
||||
let ended: ProviderOptionsPatch = {};
|
||||
let sent: ProviderOptionsPatch = {};
|
||||
if (Object.keys(patch).length > 0) {
|
||||
// A provider that cannot apply options to a running agent must not store them either.
|
||||
if (!agent.session.applyOptions) {
|
||||
throw new ProviderOptionsValidationError(
|
||||
agent.provider,
|
||||
Object.keys(patch).map((key) => ({
|
||||
path: [key],
|
||||
message: "cannot change on a running session; it applies when the agent is opened",
|
||||
})),
|
||||
);
|
||||
}
|
||||
const set = Object.fromEntries(Object.entries(patch).filter(([, value]) => value != null));
|
||||
const resolved = this.effectiveOptionsFor(agent.provider, set);
|
||||
sent = Object.fromEntries(Object.keys(patch).map((key) => [key, resolved[key] ?? null]));
|
||||
ended = (await agent.session.applyOptions(sent)) ?? {};
|
||||
// Changes the provider made on its own while applying are older than its final answer.
|
||||
await this.drainSessionEvents(agentId);
|
||||
}
|
||||
|
||||
await agent.session.setFeature(featureId, value);
|
||||
await this.drainSessionEvents(agentId);
|
||||
agent.config.featureValues = { ...agent.config.featureValues, [featureId]: value };
|
||||
this.storeOptionsPatch({ agent, patch: { ...patch, ...ended } });
|
||||
this.updateEffectiveOptions({ agent, sent, reported: ended });
|
||||
this.touchUpdatedAt(agent);
|
||||
this.emitState(agent);
|
||||
}
|
||||
|
||||
/** The config as the opened session left it: its own difference from the options it was given. */
|
||||
private withOpenedOptions(input: {
|
||||
config: AgentSessionConfig;
|
||||
session: AgentSession;
|
||||
}): AgentSessionConfig {
|
||||
const { config } = input;
|
||||
const opened = input.session.openOptionsPatch;
|
||||
if (!opened || Object.keys(opened).length === 0) return config;
|
||||
const own = applyProviderOptionsPatch({ options: config.providerOptions, patch: opened });
|
||||
return { ...config, providerOptions: Object.keys(own).length > 0 ? own : undefined };
|
||||
}
|
||||
|
||||
private storeOptionsPatch(input: { agent: ManagedAgent; patch: ProviderOptionsPatch }): void {
|
||||
const { agent } = input;
|
||||
const own = applyProviderOptionsPatch({
|
||||
options: agent.config.providerOptions,
|
||||
patch: input.patch,
|
||||
});
|
||||
agent.config.providerOptions = Object.keys(own).length > 0 ? own : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the running session has: the options it opened with, moved only by what an apply sent
|
||||
* it (defaults merged in, `null` where a removal left nothing) and by what the provider reports
|
||||
* back. The agent's own stored options keep only the raw patch.
|
||||
*/
|
||||
private updateEffectiveOptions(input: {
|
||||
agent: ManagedAgent;
|
||||
sent: ProviderOptionsPatch;
|
||||
reported: ProviderOptionsPatch;
|
||||
}): void {
|
||||
input.agent.effectiveOptions = applyProviderOptionsPatch({
|
||||
options: input.agent.effectiveOptions,
|
||||
patch: { ...input.sent, ...input.reported },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Defaults merge into what the session was given; what it reports it ended up with comes
|
||||
* after, so an option it dropped does not come back from a default.
|
||||
*/
|
||||
private openedEffectiveOptions(input: {
|
||||
session: AgentSession;
|
||||
launchedOptions: ProviderOptions;
|
||||
}): ProviderOptions {
|
||||
return applyProviderOptionsPatch({
|
||||
options: input.launchedOptions,
|
||||
patch: input.session.openOptionsPatch ?? {},
|
||||
});
|
||||
}
|
||||
|
||||
/** The options a client opens with: its own defaults merged under the agent's. */
|
||||
private launchOptionsFor(input: {
|
||||
client: AgentClient;
|
||||
own: ProviderOptions | undefined;
|
||||
}): ProviderOptions {
|
||||
return input.client.effectiveOptions?.(input.own) ?? input.own ?? {};
|
||||
}
|
||||
|
||||
private effectiveOptionsFor(
|
||||
provider: AgentProvider,
|
||||
own: ProviderOptions | undefined,
|
||||
): ProviderOptions {
|
||||
const client = this.clients.get(provider);
|
||||
return client ? this.launchOptionsFor({ client, own }) : (own ?? {});
|
||||
}
|
||||
|
||||
async setTitle(agentId: string, title: string): Promise<void> {
|
||||
const agent = this.requireAgent(agentId);
|
||||
const normalizedTitle = title.trim();
|
||||
@@ -3780,9 +3912,9 @@ export class AgentManager {
|
||||
|
||||
private async registerSession(
|
||||
session: AgentSession,
|
||||
config: AgentSessionConfig,
|
||||
openedConfig: AgentSessionConfig,
|
||||
agentId: string,
|
||||
options?: {
|
||||
options: {
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
lastUserMessageAt?: Date | null;
|
||||
@@ -3800,6 +3932,12 @@ export class AgentManager {
|
||||
* attention come from what was already recorded, and installing the session is not
|
||||
* activity in it.
|
||||
*/
|
||||
/**
|
||||
* The effective options the opening resolved before the session started. Registration
|
||||
* starts from these rather than reading the defaults again, which may have been edited
|
||||
* while the provider was opening.
|
||||
*/
|
||||
launchedOptions: ProviderOptions;
|
||||
restoring?: boolean;
|
||||
initialTitle?: string | null;
|
||||
publishWhenReady?: boolean;
|
||||
@@ -3811,6 +3949,7 @@ export class AgentManager {
|
||||
let registered = false;
|
||||
try {
|
||||
this.assertAcceptingAgentRegistrations();
|
||||
const config = this.withOpenedOptions({ config: openedConfig, session });
|
||||
const resolvedAgentId = validateAgentId(agentId, "registerSession");
|
||||
if (this.agents.has(resolvedAgentId)) {
|
||||
throw new Error(`Agent with id ${resolvedAgentId} already exists`);
|
||||
@@ -3832,6 +3971,10 @@ export class AgentManager {
|
||||
resolvedAgentId,
|
||||
session,
|
||||
config,
|
||||
effectiveOptions: this.openedEffectiveOptions({
|
||||
session,
|
||||
launchedOptions: options.launchedOptions,
|
||||
}),
|
||||
now,
|
||||
durableTimelineHasRows,
|
||||
options,
|
||||
@@ -3976,6 +4119,7 @@ export class AgentManager {
|
||||
resolvedAgentId: string;
|
||||
session: AgentSession;
|
||||
config: AgentSessionConfig;
|
||||
effectiveOptions: ProviderOptions;
|
||||
now: Date;
|
||||
durableTimelineHasRows: boolean;
|
||||
options:
|
||||
@@ -3995,7 +4139,15 @@ export class AgentManager {
|
||||
}
|
||||
| undefined;
|
||||
}): ActiveManagedAgent {
|
||||
const { resolvedAgentId, session, config, now, durableTimelineHasRows, options } = params;
|
||||
const {
|
||||
resolvedAgentId,
|
||||
session,
|
||||
config,
|
||||
effectiveOptions,
|
||||
now,
|
||||
durableTimelineHasRows,
|
||||
options,
|
||||
} = params;
|
||||
return {
|
||||
id: resolvedAgentId,
|
||||
provider: config.provider,
|
||||
@@ -4006,6 +4158,8 @@ export class AgentManager {
|
||||
session,
|
||||
capabilities: session.capabilities,
|
||||
config,
|
||||
// What the session opened with. Provider defaults edited later reach it when it next opens.
|
||||
effectiveOptions,
|
||||
runtimeInfo: undefined,
|
||||
lifecycle: "initializing",
|
||||
createdAt: options?.createdAt ?? now,
|
||||
@@ -4311,7 +4465,7 @@ export class AgentManager {
|
||||
agent.pendingPermissions.clear();
|
||||
}
|
||||
|
||||
this.syncFeaturesFromSession(agent);
|
||||
this.syncControls(agent);
|
||||
await this.refreshRuntimeInfo(agent, options);
|
||||
}
|
||||
|
||||
@@ -4657,6 +4811,18 @@ export class AgentManager {
|
||||
);
|
||||
}
|
||||
|
||||
private onStreamOptionsChanged(params: {
|
||||
agent: ActiveManagedAgent;
|
||||
patch: ProviderOptionsPatch;
|
||||
flags: StreamEventFlags;
|
||||
}): void {
|
||||
const { agent, patch, flags } = params;
|
||||
this.storeOptionsPatch({ agent, patch });
|
||||
this.updateEffectiveOptions({ agent, sent: {}, reported: patch });
|
||||
flags.shouldDispatchEvent = false;
|
||||
this.emitState(agent);
|
||||
}
|
||||
|
||||
private dispatchStreamEventByType(params: {
|
||||
agent: ActiveManagedAgent;
|
||||
event: AgentStreamEvent;
|
||||
@@ -4708,6 +4874,9 @@ export class AgentManager {
|
||||
flags.shouldDispatchEvent = false;
|
||||
this.emitState(agent);
|
||||
return undefined;
|
||||
case "options_changed":
|
||||
this.onStreamOptionsChanged({ agent, patch: event.patch, flags });
|
||||
return undefined;
|
||||
case "timeline":
|
||||
return this.onStreamTimelineEvent({ agent, event, options, flags });
|
||||
case "turn_completed":
|
||||
@@ -5183,7 +5352,7 @@ export class AgentManager {
|
||||
this.enqueueBackgroundPersist(agent);
|
||||
}
|
||||
|
||||
this.syncFeaturesFromSession(agent);
|
||||
this.syncControls(agent);
|
||||
|
||||
this.logger.trace(
|
||||
{
|
||||
@@ -5205,9 +5374,9 @@ export class AgentManager {
|
||||
});
|
||||
}
|
||||
|
||||
private syncFeaturesFromSession(agent: ManagedAgent): void {
|
||||
if ("session" in agent && agent.session?.features) {
|
||||
agent.features = agent.session.features;
|
||||
private syncControls(agent: ManagedAgent): void {
|
||||
if ("session" in agent && agent.session?.controls) {
|
||||
agent.controls = agent.session.controls;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5454,7 +5623,7 @@ export class AgentManager {
|
||||
config: AgentSessionConfig,
|
||||
options: NormalizeConfigOptions = {},
|
||||
): Promise<AgentSessionConfig> {
|
||||
const normalized: AgentSessionConfig = { ...config };
|
||||
const normalized: AgentSessionConfig = { ...this.withConvertedOptions(config) };
|
||||
|
||||
// Always resolve cwd to absolute path for consistent history file lookup
|
||||
if (normalized.cwd) {
|
||||
@@ -5526,6 +5695,30 @@ export class AgentManager {
|
||||
}
|
||||
}
|
||||
|
||||
/** The adapter a provider id runs on: a custom provider is named by the one it extends. */
|
||||
private adapterOf(provider: AgentProvider): AgentProvider {
|
||||
return resolveAdapter({
|
||||
provider,
|
||||
extendsOf: (id) => this.providerDefinitions.get(id)?.derivedFromProviderId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Options older data carries are converted for the adapter the provider runs on, before
|
||||
* defaults merge and before anything is stored; nothing past the manager sees the old keys.
|
||||
*/
|
||||
private convertLegacyOptions<T extends ProviderOptions | undefined>(
|
||||
provider: AgentProvider,
|
||||
options: T,
|
||||
): T {
|
||||
return convertLegacyOptions({ provider: this.adapterOf(provider), options }) as T;
|
||||
}
|
||||
|
||||
private withConvertedOptions(config: AgentSessionConfig): AgentSessionConfig {
|
||||
const providerOptions = this.convertLegacyOptions(config.provider, config.providerOptions);
|
||||
return providerOptions === config.providerOptions ? config : { ...config, providerOptions };
|
||||
}
|
||||
|
||||
private async prepareSessionConfig(
|
||||
config: AgentSessionConfig,
|
||||
agentId: string,
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from "./agent-projections.js";
|
||||
import type { AgentSession } from "./agent-sdk-types.js";
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
ImportableProviderSession,
|
||||
AgentPermissionRequest,
|
||||
AgentPersistenceHandle,
|
||||
@@ -128,16 +128,6 @@ function createPermission(overrides: Partial<AgentPermissionRequest> = {}): Agen
|
||||
return { ...base, ...overrides };
|
||||
}
|
||||
|
||||
function createFeature(overrides: Partial<AgentFeature> = {}): AgentFeature {
|
||||
return {
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
label: "Fast mode",
|
||||
value: true,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("toStoredAgentRecord", () => {
|
||||
it("captures lifecycle metadata, config, and persistence", () => {
|
||||
const agent = createManagedAgent({
|
||||
@@ -474,13 +464,44 @@ describe("toAgentPayload", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("includes features in the snapshot payload", () => {
|
||||
const features = [createFeature()];
|
||||
const agent = createManagedAgent({ features });
|
||||
it("projects controls, effective options, and legacy features from the same source", () => {
|
||||
const controls: AgentOptionControl[] = [
|
||||
{ type: "toggle", key: "fast_mode", label: "Fast mode" },
|
||||
{
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "fast", label: "Fast" },
|
||||
],
|
||||
},
|
||||
];
|
||||
// `config.json` supplies fast_mode; the agent itself sets nothing for service_tier.
|
||||
// Options without a control are part of the snapshot too.
|
||||
const agent = createManagedAgent({
|
||||
controls,
|
||||
effectiveOptions: { fast_mode: true, sandbox_mode: "workspace-write" },
|
||||
});
|
||||
|
||||
const payload = toAgentPayload(agent);
|
||||
|
||||
expect(payload.features).toEqual(features);
|
||||
expect(payload.controls).toEqual(controls);
|
||||
expect(payload.options).toEqual({ fast_mode: true, sandbox_mode: "workspace-write" });
|
||||
expect(payload.features).toEqual([
|
||||
{ type: "toggle", id: "fast_mode", label: "Fast mode", value: true },
|
||||
{
|
||||
type: "select",
|
||||
id: "service_tier",
|
||||
label: "Speed",
|
||||
value: "default",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "fast", label: "Fast" },
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
import type { SerializableAgentConfig, StoredAgentRecord } from "./agent-storage.js";
|
||||
import type {
|
||||
AgentCapabilityFlags,
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
AgentMetadata,
|
||||
AgentMode,
|
||||
AgentPermissionRequest,
|
||||
@@ -18,7 +18,9 @@ import type {
|
||||
AgentUsage,
|
||||
ImportableProviderSession,
|
||||
} from "./agent-sdk-types.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import type { ManagedAgent } from "./agent-manager.js";
|
||||
import { featuresFromControls } from "./option-controls.js";
|
||||
import type { JsonValue } from "../json-utils.js";
|
||||
import {
|
||||
isStoredAgentProviderAvailable,
|
||||
@@ -97,7 +99,7 @@ export function toStoredAgentRecord(
|
||||
config: config ?? null,
|
||||
launchEnv: agent.launchEnv ? { ...agent.launchEnv } : undefined,
|
||||
runtimeInfo,
|
||||
features: normalizeFeatures(agent.features),
|
||||
controls: normalizeControls(agent.controls),
|
||||
persistence,
|
||||
lastError: agent.lastError ?? undefined,
|
||||
requiresAttention: agent.attention.requiresAttention,
|
||||
@@ -143,7 +145,12 @@ export function toAgentPayload(
|
||||
capabilities: cloneCapabilities(agent.capabilities),
|
||||
currentModeId: agent.currentModeId,
|
||||
availableModes: cloneAvailableModes(agent.availableModes),
|
||||
features: normalizeFeatures(agent.features),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
features: featuresFromControls({ controls: agent.controls, options: agent.effectiveOptions }),
|
||||
...(agent.effectiveOptions
|
||||
? { options: sanitizeEffectiveOptions(agent.effectiveOptions) }
|
||||
: {}),
|
||||
controls: normalizeControls(agent.controls),
|
||||
pendingPermissions: sanitizePendingPermissions(agent.pendingPermissions),
|
||||
persistence: projectPersistenceHandleForWire(agent.persistence),
|
||||
title: options?.title ?? null,
|
||||
@@ -375,12 +382,6 @@ function buildSerializableConfig(config: AgentSessionConfig): SerializableAgentC
|
||||
if (config.thinkingOptionId) {
|
||||
serializable.thinkingOptionId = config.thinkingOptionId;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(config, "featureValues")) {
|
||||
const featureValues = sanitizeMetadata(config.featureValues);
|
||||
if (featureValues !== undefined) {
|
||||
serializable.featureValues = featureValues;
|
||||
}
|
||||
}
|
||||
if (config.providerOptions !== undefined) {
|
||||
const providerOptions = sanitizeOptionalJson(config.providerOptions);
|
||||
if (providerOptions && isJsonObject(providerOptions)) {
|
||||
@@ -456,8 +457,15 @@ function cloneAvailableModes(modes: AgentMode[]): AgentMode[] {
|
||||
return modes.map((mode) => ({ ...mode }));
|
||||
}
|
||||
|
||||
function normalizeFeatures(features: AgentFeature[] | null | undefined): AgentFeature[] {
|
||||
return Array.isArray(features) ? features.map((feature) => ({ ...feature })) : [];
|
||||
function normalizeControls(
|
||||
controls: AgentOptionControl[] | null | undefined,
|
||||
): AgentOptionControl[] {
|
||||
return Array.isArray(controls) ? controls.map((control) => ({ ...control })) : [];
|
||||
}
|
||||
|
||||
function sanitizeEffectiveOptions(options: ProviderOptions): ProviderOptions {
|
||||
const sanitized = sanitizeOptionalJson(options);
|
||||
return sanitized && isJsonObject(sanitized) ? sanitized : {};
|
||||
}
|
||||
|
||||
function sanitizeOptionalJson(value: unknown): JsonValue | undefined {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentFeatureSelect,
|
||||
AgentFeatureToggle,
|
||||
AgentOptionControl,
|
||||
AgentOptionSelectControl,
|
||||
AgentOptionToggleControl,
|
||||
AgentProviderNotice,
|
||||
AgentTaskItem,
|
||||
JsonValue,
|
||||
@@ -13,9 +13,9 @@ import type { AgentAttachment } from "@getpaseo/protocol/messages";
|
||||
import type { PaseoToolCatalog } from "./tools/types.js";
|
||||
|
||||
export type {
|
||||
AgentFeature,
|
||||
AgentFeatureSelect,
|
||||
AgentFeatureToggle,
|
||||
AgentOptionControl,
|
||||
AgentOptionSelectControl,
|
||||
AgentOptionToggleControl,
|
||||
AgentProviderNotice,
|
||||
AgentTaskItem,
|
||||
};
|
||||
@@ -148,7 +148,7 @@ export interface AgentCreateConfigParent {
|
||||
export interface ResolveAgentCreateConfigInput {
|
||||
provider: AgentProvider;
|
||||
requestedMode: string | undefined;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: ProviderOptions | undefined;
|
||||
parent: AgentCreateConfigParent | null;
|
||||
unattended: boolean;
|
||||
availableModes: AgentMode[] | undefined;
|
||||
@@ -156,13 +156,13 @@ export interface ResolveAgentCreateConfigInput {
|
||||
|
||||
export interface ResolveAgentCreateConfigResult {
|
||||
modeId: string | undefined;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: ProviderOptions | undefined;
|
||||
}
|
||||
|
||||
export interface AgentCreateConfigUnattendedInput {
|
||||
modeId: string | null;
|
||||
config: AgentSessionConfig;
|
||||
features?: AgentFeature[];
|
||||
controls?: AgentOptionControl[];
|
||||
availableModes: AgentMode[];
|
||||
}
|
||||
|
||||
@@ -429,6 +429,14 @@ export type AgentStreamEvent =
|
||||
provider: AgentProvider;
|
||||
thinkingOptionId: string | null;
|
||||
}
|
||||
/**
|
||||
* The provider changed options on its own: after `createSession`/`resumeSession` or
|
||||
* `applyOptions` it ended up different from what it was given, or later it changed a setting
|
||||
* itself. The daemon stores the patch and forwards it; it does not undo it. `null` removes the
|
||||
* agent's own value. Only for changes that happen on the provider's own initiative: the result
|
||||
* of opening goes in `openOptionsPatch` and the result of `applyOptions` is its return value.
|
||||
*/
|
||||
| { type: "options_changed"; provider: AgentProvider; patch: Record<string, unknown> }
|
||||
| {
|
||||
type: "turn_failed";
|
||||
provider: AgentProvider;
|
||||
@@ -610,7 +618,6 @@ export interface AgentSessionConfig {
|
||||
modeId?: string;
|
||||
model?: string;
|
||||
thinkingOptionId?: string;
|
||||
featureValues?: Record<string, unknown>;
|
||||
title?: string | null;
|
||||
providerOptions?: ProviderOptions;
|
||||
toolPolicy?: ToolPolicy;
|
||||
@@ -679,7 +686,14 @@ export interface AgentSession {
|
||||
readonly provider: AgentProvider;
|
||||
readonly id: string | null;
|
||||
readonly capabilities: AgentCapabilityFlags;
|
||||
readonly features?: AgentFeature[];
|
||||
/** Composer controls over top-level option keys. Values come from the agent's effective options. */
|
||||
readonly controls?: AgentOptionControl[];
|
||||
/**
|
||||
* How the session ended up different from the options it was opened with, as a patch (`null`
|
||||
* removes a key). Set by the time `createSession`/`resumeSession` resolves; the daemon stores it
|
||||
* before the agent is published.
|
||||
*/
|
||||
readonly openOptionsPatch?: Record<string, unknown>;
|
||||
/** New provider-owned rows to commit on registration. streamHistory must also
|
||||
* replay them at their original timestamps; restored sessions omit old rows. */
|
||||
readonly initialTimeline?: ImportedTimelineEntry[];
|
||||
@@ -714,7 +728,20 @@ export interface AgentSession {
|
||||
listCommands?(): Promise<AgentSlashCommand[]>;
|
||||
setModel?(modelId: string | null): Promise<void>;
|
||||
setThinkingOption?(thinkingOptionId: string | null): Promise<void | AgentProviderNotice>;
|
||||
setFeature?(featureId: string, value: unknown): Promise<void>;
|
||||
/**
|
||||
* Apply an options patch. `options` holds only the keys the patch touches, resolved against
|
||||
* the `config.json` defaults; `null` means nothing is set for the key, so return it to the
|
||||
* session's own default if that can be done. Leave every other setting alone. Throw to reject a
|
||||
* value, or a key the running session cannot apply (one the provider reads only when it
|
||||
* opens): the daemon stores the patch only when this resolves, so a stored option always
|
||||
* describes what runs, and the call is all-or-nothing.
|
||||
* Emit nothing from here. Return the options the session ended up with when they differ from
|
||||
* the request (a patch, `null` removes a key), for example a value it kept because it could not
|
||||
* be reverted; the daemon stores it together with the patch. When a throw leaves the session's
|
||||
* state moved anyway, report the moved values once as `options_changed` after the call has
|
||||
* ended, so the stored options still match what runs.
|
||||
*/
|
||||
applyOptions?(options: ProviderOptions): Promise<Record<string, unknown> | void>;
|
||||
revertConversation?(input: { messageId: string }): Promise<void>;
|
||||
revertFiles?(input: { messageId: string }): Promise<void>;
|
||||
revertBoth?(input: { messageId: string }): Promise<void>;
|
||||
@@ -764,11 +791,17 @@ export interface ResolveAgentDefaultModeInput {
|
||||
export interface AgentClient {
|
||||
readonly provider: AgentProvider;
|
||||
readonly capabilities: AgentCapabilityFlags;
|
||||
/**
|
||||
* Create the agent with `config.providerOptions` (defaults already merged in). Emit nothing
|
||||
* about options while creating. If the agent ended up different from the options, say so in the
|
||||
* session's `openOptionsPatch`.
|
||||
*/
|
||||
createSession(
|
||||
config: AgentSessionConfig,
|
||||
launchContext?: AgentLaunchContext,
|
||||
options?: AgentCreateSessionOptions,
|
||||
): Promise<AgentSession>;
|
||||
/** Same contract as `createSession`: open with the options, report any difference in `openOptionsPatch`. */
|
||||
resumeSession(
|
||||
handle: AgentPersistenceHandle,
|
||||
overrides?: Partial<AgentSessionConfig>,
|
||||
@@ -797,7 +830,9 @@ export interface AgentClient {
|
||||
resolveCreateConfig?(input: ResolveAgentCreateConfigInput): ResolveAgentCreateConfigResult;
|
||||
isCreateConfigUnattended?(input: AgentCreateConfigUnattendedInput): boolean;
|
||||
listCommands?(config: AgentSessionConfig): Promise<AgentSlashCommand[]>;
|
||||
listFeatures?(config: AgentSessionConfig): Promise<AgentFeature[]>;
|
||||
listControls?(config: AgentSessionConfig): Promise<AgentOptionControl[]>;
|
||||
/** Effective options: provider defaults from `config.json` deep-merged with the agent's own. */
|
||||
effectiveOptions?(own: ProviderOptions | undefined): ProviderOptions;
|
||||
listImportableSessions?(
|
||||
options?: ListImportableSessionsOptions,
|
||||
): Promise<ImportableProviderSession[]>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test, beforeEach, afterEach } from "vitest";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { mkdtempSync, readdirSync, rmSync } from "node:fs";
|
||||
import { existsSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
|
||||
import { promises as fs } from "node:fs";
|
||||
|
||||
import { createTestLogger } from "../../test-utils/test-logger.js";
|
||||
@@ -44,9 +44,6 @@ function buildManagedAgentConfig(
|
||||
systemPrompt: configOverrides.systemPrompt,
|
||||
mcpServers: configOverrides.mcpServers,
|
||||
};
|
||||
if (Object.prototype.hasOwnProperty.call(configOverrides, "featureValues")) {
|
||||
config.featureValues = configOverrides.featureValues;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -132,6 +129,14 @@ function createManagedAgent(overrides: ManagedAgentOverrides = {}): ManagedAgent
|
||||
};
|
||||
}
|
||||
|
||||
function findRecordFile(baseDir: string, agentId: string): string {
|
||||
for (const entry of readdirSync(baseDir, { withFileTypes: true })) {
|
||||
const candidate = path.join(baseDir, entry.name, `${agentId}.json`);
|
||||
if (entry.isDirectory() && existsSync(candidate)) return candidate;
|
||||
}
|
||||
throw new Error(`No stored record for ${agentId}`);
|
||||
}
|
||||
|
||||
describe("AgentStorage", () => {
|
||||
let tmpDir: string;
|
||||
let storagePath: string;
|
||||
@@ -195,62 +200,77 @@ describe("AgentStorage", () => {
|
||||
expect(persisted.config?.providerOptions).toEqual({ allowedTools: ["Read"] });
|
||||
});
|
||||
|
||||
test("applySnapshot stores and reloads featureValues when present", async () => {
|
||||
test("applySnapshot stores and reloads composer values as providerOptions", async () => {
|
||||
await storage.applySnapshot(
|
||||
createManagedAgent({
|
||||
id: "agent-feature-values",
|
||||
config: {
|
||||
featureValues: {
|
||||
fast_mode: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const record = await storage.get("agent-feature-values");
|
||||
expect(record?.config?.featureValues).toEqual({ fast_mode: true });
|
||||
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const persisted = await reloaded.get("agent-feature-values");
|
||||
expect(persisted?.config?.featureValues).toEqual({ fast_mode: true });
|
||||
expect(buildSessionConfig(persisted!).featureValues).toEqual({ fast_mode: true });
|
||||
});
|
||||
|
||||
test("applySnapshot keeps featureValues absent when they were never set", async () => {
|
||||
await storage.applySnapshot(
|
||||
createManagedAgent({
|
||||
id: "agent-no-feature-values",
|
||||
id: "agent-provider-options",
|
||||
config: { providerOptions: { fast_mode: true } },
|
||||
}),
|
||||
);
|
||||
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const persisted = await reloaded.get("agent-no-feature-values");
|
||||
expect(persisted?.config?.featureValues).toBeUndefined();
|
||||
expect(buildSessionConfig(persisted!).featureValues).toBeUndefined();
|
||||
});
|
||||
|
||||
test("buildConfigOverrides includes featureValues when present in stored config", async () => {
|
||||
await storage.applySnapshot(
|
||||
createManagedAgent({
|
||||
id: "agent-resume-overrides",
|
||||
config: {
|
||||
featureValues: {
|
||||
fast_mode: true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const record = await storage.get("agent-resume-overrides");
|
||||
expect(record).not.toBeNull();
|
||||
expect(buildConfigOverrides(record!)).toMatchObject({
|
||||
const persisted = await reloaded.get("agent-provider-options");
|
||||
expect(persisted?.config?.providerOptions).toEqual({ fast_mode: true });
|
||||
expect(buildSessionConfig(persisted!).providerOptions).toEqual({ fast_mode: true });
|
||||
expect(buildConfigOverrides(persisted!)).toMatchObject({
|
||||
cwd: "/tmp/project",
|
||||
featureValues: {
|
||||
fast_mode: true,
|
||||
},
|
||||
providerOptions: { fast_mode: true },
|
||||
});
|
||||
});
|
||||
|
||||
test("a record stored with featureValues loads them in providerOptions", async () => {
|
||||
await storage.applySnapshot(createManagedAgent({ id: "agent-legacy" }));
|
||||
const file = findRecordFile(storagePath, "agent-legacy");
|
||||
const stored = JSON.parse(await fs.readFile(file, "utf8"));
|
||||
stored.config.providerOptions = { allowedTools: ["Read"], fast_mode: false };
|
||||
stored.config.featureValues = { fast_mode: true, service_tier: "fast" };
|
||||
delete stored.controls;
|
||||
stored.features = [
|
||||
{ type: "toggle", id: "fast_mode", label: "Fast mode", value: true },
|
||||
{
|
||||
type: "select",
|
||||
id: "service_tier",
|
||||
label: "Speed",
|
||||
value: "fast",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "fast", label: "Fast" },
|
||||
],
|
||||
},
|
||||
];
|
||||
await fs.writeFile(file, JSON.stringify(stored));
|
||||
|
||||
const reloaded = new AgentStorage(storagePath, logger);
|
||||
const persisted = await reloaded.get("agent-legacy");
|
||||
|
||||
// An explicit providerOptions key wins over the same featureValues key.
|
||||
expect(persisted?.config?.providerOptions).toEqual({
|
||||
allowedTools: ["Read"],
|
||||
fast_mode: false,
|
||||
service_tier: "fast",
|
||||
});
|
||||
expect(persisted?.config).not.toHaveProperty("featureValues");
|
||||
expect(persisted).not.toHaveProperty("features");
|
||||
expect(persisted?.controls).toEqual([
|
||||
{ type: "toggle", key: "fast_mode", label: "Fast mode" },
|
||||
{
|
||||
type: "select",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "fast", label: "Fast" },
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
await reloaded.applySnapshot(createManagedAgent({ id: "agent-legacy" }));
|
||||
const rewritten = JSON.parse(await fs.readFile(file, "utf8"));
|
||||
expect(rewritten.config).not.toHaveProperty("featureValues");
|
||||
expect(rewritten).not.toHaveProperty("features");
|
||||
});
|
||||
|
||||
test("applySnapshot preserves original createdAt timestamp", async () => {
|
||||
const agentId = "agent-created-at";
|
||||
const firstTimestamp = new Date("2025-01-01T00:00:00.000Z");
|
||||
|
||||
@@ -4,17 +4,19 @@ import { z } from "zod";
|
||||
import type { Logger } from "pino";
|
||||
|
||||
import { writeJsonFileAtomic } from "../atomic-file.js";
|
||||
import { AgentFeatureSchema, AgentStatusSchema } from "../messages.js";
|
||||
import { AgentFeatureSchema, AgentOptionControlSchema, AgentStatusSchema } from "../messages.js";
|
||||
import { toStoredAgentRecord } from "./agent-projections.js";
|
||||
import type { ManagedAgent } from "./agent-manager.js";
|
||||
import type { AgentSessionConfig } from "./agent-sdk-types.js";
|
||||
import { AgentOwnerSchema, daemonExecutionKey, type DaemonAgentOwner } from "./agent-owner.js";
|
||||
import { controlsFromFeatures, foldFeatureValues } from "./option-controls.js";
|
||||
|
||||
const SERIALIZABLE_CONFIG_SCHEMA = z
|
||||
.object({
|
||||
modeId: z.string().nullable().optional(),
|
||||
model: z.string().nullable().optional(),
|
||||
thinkingOptionId: z.string().nullable().optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Read-only; folded on parse.
|
||||
featureValues: z.record(z.string(), z.unknown()).nullable().optional(),
|
||||
providerOptions: z.record(z.string(), z.unknown()).nullable().optional(),
|
||||
toolPolicy: z
|
||||
@@ -42,7 +44,7 @@ const PERSISTENCE_HANDLE_SCHEMA = z
|
||||
.nullable()
|
||||
.optional();
|
||||
|
||||
const STORED_AGENT_SCHEMA = z.object({
|
||||
const RAW_STORED_AGENT_SCHEMA = z.object({
|
||||
id: z.string(),
|
||||
provider: z.string(),
|
||||
cwd: z.string(),
|
||||
@@ -68,6 +70,8 @@ const STORED_AGENT_SCHEMA = z.object({
|
||||
extra: z.record(z.string(), z.unknown()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
controls: z.array(AgentOptionControlSchema).optional(),
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. Read-only; becomes controls.
|
||||
features: z.array(AgentFeatureSchema).optional(),
|
||||
persistence: PERSISTENCE_HANDLE_SCHEMA,
|
||||
lastError: z.string().nullable().optional(),
|
||||
@@ -84,14 +88,32 @@ export type SerializableAgentConfig = Pick<
|
||||
| "modeId"
|
||||
| "model"
|
||||
| "thinkingOptionId"
|
||||
| "featureValues"
|
||||
| "providerOptions"
|
||||
| "toolPolicy"
|
||||
| "systemPrompt"
|
||||
| "mcpServers"
|
||||
>;
|
||||
|
||||
export type StoredAgentRecord = z.infer<typeof STORED_AGENT_SCHEMA>;
|
||||
type RawStoredAgentRecord = z.infer<typeof RAW_STORED_AGENT_SCHEMA>;
|
||||
type RawStoredAgentConfig = NonNullable<RawStoredAgentRecord["config"]>;
|
||||
|
||||
/** Records carry `providerOptions` and `controls` only; legacy fields are folded when read. */
|
||||
export type StoredAgentRecord = Omit<RawStoredAgentRecord, "config" | "features"> & {
|
||||
config?: Omit<RawStoredAgentConfig, "featureValues"> | null;
|
||||
};
|
||||
|
||||
// COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
function foldLegacyRecordFields(record: RawStoredAgentRecord): StoredAgentRecord {
|
||||
const { features, config, controls, ...rest } = record;
|
||||
return {
|
||||
...rest,
|
||||
...(config ? { config: foldFeatureValues(config) } : { config }),
|
||||
...((controls ?? features) ? { controls: controls ?? controlsFromFeatures(features) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
const STORED_AGENT_SCHEMA = RAW_STORED_AGENT_SCHEMA.transform(foldLegacyRecordFields);
|
||||
|
||||
export function parseStoredAgentRecord(value: unknown): StoredAgentRecord {
|
||||
return STORED_AGENT_SCHEMA.parse(value);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ describe("resolveAndValidateCreateAgentMode", () => {
|
||||
availableModes: OPENCODE_MODES,
|
||||
}),
|
||||
).toThrow(
|
||||
"cannot inherit mode 'bypassPermissions' from caller (provider 'claude') for new agent (provider 'opencode'). Pass an explicit mode in settings.modeId. Available modes for 'opencode': build, plan",
|
||||
"cannot inherit mode 'bypassPermissions' from caller (provider 'claude') for new agent (provider 'opencode'). Pass an explicit mode. Available modes for 'opencode': build, plan",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -92,7 +92,7 @@ describe("resolveAndValidateCreateAgentMode", () => {
|
||||
availableModes: CODEX_MODES,
|
||||
}),
|
||||
).toThrow(
|
||||
"cannot inherit mode '<none>' from caller (provider 'opencode') for new agent (provider 'codex'). Pass an explicit mode in settings.modeId. Available modes for 'codex': auto, full-access",
|
||||
"cannot inherit mode '<none>' from caller (provider 'opencode') for new agent (provider 'codex'). Pass an explicit mode. Available modes for 'codex': auto, full-access",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -180,7 +180,7 @@ describe("resolveAndValidateCreateAgentMode", () => {
|
||||
targetUnattendedMode: "full-access",
|
||||
}),
|
||||
).toThrow(
|
||||
"cannot inherit mode 'default' from caller (provider 'claude') for new agent (provider 'codex'). Pass an explicit mode in settings.modeId. Available modes for 'codex': auto, full-access",
|
||||
"cannot inherit mode 'default' from caller (provider 'claude') for new agent (provider 'codex'). Pass an explicit mode. Available modes for 'codex': auto, full-access",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -195,7 +195,7 @@ describe("resolveAndValidateCreateAgentMode", () => {
|
||||
targetUnattendedMode: undefined,
|
||||
}),
|
||||
).toThrow(
|
||||
"cannot inherit mode 'bypassPermissions' from caller (provider 'claude') for new agent (provider 'zai-custom'). Pass an explicit mode in settings.modeId. Available modes for 'zai-custom': unknown",
|
||||
"cannot inherit mode 'bypassPermissions' from caller (provider 'claude') for new agent (provider 'zai-custom'). Pass an explicit mode. Available modes for 'zai-custom': unknown",
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ export function resolveAndValidateCreateAgentMode(
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`cannot inherit mode '${formatCreateConfigParentMode(parent)}' from ${formatCreateConfigParentSource(parent)} for new agent (provider '${targetProvider}'). Pass an explicit mode in settings.modeId. Available modes for '${targetProvider}': ${listModes(availableModes)}`,
|
||||
`cannot inherit mode '${formatCreateConfigParentMode(parent)}' from ${formatCreateConfigParentSource(parent)} for new agent (provider '${targetProvider}'). Pass an explicit mode. Available modes for '${targetProvider}': ${listModes(availableModes)}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ export function resolveDefaultAgentCreateConfig(
|
||||
availableModes: availableModeIds,
|
||||
targetUnattendedMode: input.availableModes?.find(isUnattendedMode)?.id,
|
||||
}),
|
||||
featureValues: input.featureValues,
|
||||
providerOptions: input.providerOptions,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ test("session create applies the resolved mode from the provider create config",
|
||||
const stub = createProviderSnapshotManagerStub();
|
||||
stub.resolveCreateConfig.mockResolvedValue({
|
||||
modeId: "build",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
const dependencies: Parameters<typeof createAgentCommand>[0] = {
|
||||
agentManager: {
|
||||
@@ -171,7 +171,7 @@ test("session create applies the resolved mode from the provider create config",
|
||||
expect(createAgent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
modeId: "build",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
}),
|
||||
undefined,
|
||||
expect.anything(),
|
||||
|
||||
@@ -22,6 +22,8 @@ import { buildAgentPrompt } from "../prompt-attachments.js";
|
||||
import { normalizeClientMessageId, resolveClientMessageId } from "../../client-message-id.js";
|
||||
import { resolveRequiredProviderModel, type ResolvedProviderModel } from "../mcp-shared.js";
|
||||
import { resolveCreateAgentIntent } from "./intent.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { foldFeatureValues, type LegacyFeatureValues } from "../option-controls.js";
|
||||
|
||||
export interface CreateAgentCommandDependencies {
|
||||
finishSubscriptions?: FinishSubscriptions;
|
||||
@@ -47,7 +49,8 @@ export interface CreateAgentFromSessionInput {
|
||||
kind: "session";
|
||||
onAgentReady?: (agent: ManagedAgent) => Promise<void>;
|
||||
agentId?: string;
|
||||
config: AgentSessionConfig;
|
||||
/** Wire configs from older clients can still carry `featureValues`; they are folded on entry. */
|
||||
config: AgentSessionConfig & LegacyFeatureValues;
|
||||
workspaceId: string;
|
||||
initialPrompt?: string;
|
||||
source?: AgentPromptSource;
|
||||
@@ -70,7 +73,7 @@ export interface CreateAgentFromMcpInput {
|
||||
cwd?: string;
|
||||
workspaceId?: string;
|
||||
thinking?: string;
|
||||
features?: Record<string, unknown>;
|
||||
providerOptions?: ProviderOptions;
|
||||
labels?: Record<string, string>;
|
||||
mode?: string;
|
||||
unattended?: boolean;
|
||||
@@ -218,19 +221,19 @@ async function resolveSessionCreateAgent(
|
||||
input: CreateAgentFromSessionInput,
|
||||
): Promise<ResolvedCreateAgent> {
|
||||
const trimmedPrompt = input.initialPrompt?.trim();
|
||||
const builtSessionConfig = input.config;
|
||||
const builtSessionConfig = foldFeatureValues(input.config);
|
||||
const resolvedCreateConfig = await dependencies.providerSnapshotManager.resolveCreateConfig({
|
||||
cwd: builtSessionConfig.cwd,
|
||||
provider: builtSessionConfig.provider,
|
||||
requestedMode: builtSessionConfig.modeId,
|
||||
featureValues: builtSessionConfig.featureValues,
|
||||
providerOptions: builtSessionConfig.providerOptions,
|
||||
parent: null,
|
||||
unattended: false,
|
||||
});
|
||||
const sessionConfig: AgentSessionConfig = {
|
||||
...builtSessionConfig,
|
||||
modeId: resolvedCreateConfig.modeId,
|
||||
featureValues: resolvedCreateConfig.featureValues,
|
||||
providerOptions: resolvedCreateConfig.providerOptions,
|
||||
};
|
||||
const prompt = buildAgentPrompt(trimmedPrompt ?? "", input.images, input.attachments);
|
||||
const hasPromptContent = Array.isArray(prompt) ? prompt.length > 0 : prompt.length > 0;
|
||||
@@ -323,7 +326,7 @@ async function resolveMcpCreateAgent(
|
||||
resolvedCwd: intent.cwd,
|
||||
trimmedPrompt,
|
||||
resolvedMode: resolvedCreateConfig.modeId,
|
||||
resolvedFeatures: resolvedCreateConfig.featureValues,
|
||||
resolvedProviderOptions: resolvedCreateConfig.providerOptions,
|
||||
}),
|
||||
createOptions: {
|
||||
...(Object.keys(intent.labels).length > 0 ? { labels: intent.labels } : {}),
|
||||
@@ -361,18 +364,23 @@ async function resolveMcpProviderCreateConfig(params: {
|
||||
provider: string;
|
||||
resolvedCwd: string;
|
||||
parentAgent: ManagedAgent | null;
|
||||
}): Promise<{ modeId?: string; featureValues?: Record<string, unknown> }> {
|
||||
}): Promise<{ modeId?: string; providerOptions?: ProviderOptions }> {
|
||||
const passthroughConfig = params.input.config;
|
||||
return params.dependencies.providerSnapshotManager.resolveCreateConfig({
|
||||
cwd: params.resolvedCwd,
|
||||
provider: params.provider,
|
||||
requestedMode: params.input.mode ?? passthroughConfig?.modeId,
|
||||
featureValues: params.input.features ?? passthroughConfig?.featureValues,
|
||||
providerOptions: mergeMcpProviderOptions(params.input),
|
||||
parent: params.parentAgent,
|
||||
unattended: params.input.unattended ?? false,
|
||||
});
|
||||
}
|
||||
|
||||
function mergeMcpProviderOptions(input: CreateAgentFromMcpInput): ProviderOptions | undefined {
|
||||
if (!input.providerOptions) return input.config?.providerOptions;
|
||||
return { ...input.config?.providerOptions, ...input.providerOptions };
|
||||
}
|
||||
|
||||
function buildMcpSessionConfig(params: {
|
||||
input: CreateAgentFromMcpInput;
|
||||
resolvedProviderModel: ResolvedProviderModel;
|
||||
@@ -380,14 +388,14 @@ function buildMcpSessionConfig(params: {
|
||||
resolvedCwd: string;
|
||||
trimmedPrompt: string;
|
||||
resolvedMode?: string;
|
||||
resolvedFeatures?: Record<string, unknown>;
|
||||
resolvedProviderOptions?: ProviderOptions;
|
||||
}): AgentSessionConfig {
|
||||
const passthroughConfig = params.input.config;
|
||||
const { provisionalTitle } = resolveCreateAgentTitles({
|
||||
configTitle: passthroughConfig?.title ?? params.input.title,
|
||||
initialPrompt: params.trimmedPrompt,
|
||||
});
|
||||
const featureValues = params.resolvedFeatures ?? passthroughConfig?.featureValues;
|
||||
const providerOptions = params.resolvedProviderOptions ?? mergeMcpProviderOptions(params.input);
|
||||
const config: AgentSessionConfig = {
|
||||
...passthroughConfig,
|
||||
provider: params.provider,
|
||||
@@ -400,8 +408,8 @@ function buildMcpSessionConfig(params: {
|
||||
if (provisionalTitle) {
|
||||
config.title = provisionalTitle;
|
||||
}
|
||||
if (featureValues) {
|
||||
config.featureValues = featureValues;
|
||||
if (providerOptions) {
|
||||
config.providerOptions = providerOptions;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ function buildAgentManagerSpies() {
|
||||
setAgentMode: vi.fn().mockResolvedValue(undefined),
|
||||
setAgentModel: vi.fn().mockResolvedValue(undefined),
|
||||
setAgentThinkingOption: vi.fn().mockResolvedValue(undefined),
|
||||
setAgentFeature: vi.fn().mockResolvedValue(undefined),
|
||||
setAgentOptions: vi.fn().mockResolvedValue(undefined),
|
||||
setLabels: vi.fn().mockResolvedValue(undefined),
|
||||
setTitle: vi.fn().mockResolvedValue(undefined),
|
||||
updateAgentMetadata: vi.fn().mockResolvedValue(undefined),
|
||||
@@ -282,7 +282,7 @@ function buildAgentManagerSpies() {
|
||||
cancelAgentRun: vi.fn(),
|
||||
getPendingPermissions: vi.fn(),
|
||||
getRegisteredProviderIds: vi.fn().mockReturnValue(["claude"]),
|
||||
listDraftFeatures: vi.fn(),
|
||||
listDraftControls: vi.fn(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -472,9 +472,9 @@ function configureOpenCodeProviderStub(
|
||||
const opts = input as {
|
||||
provider: AgentProvider;
|
||||
requestedMode: string | undefined;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: Record<string, unknown> | undefined;
|
||||
};
|
||||
return { modeId: opts.requestedMode, featureValues: opts.featureValues };
|
||||
return { modeId: opts.requestedMode, providerOptions: opts.providerOptions };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1805,7 +1805,7 @@ describe("create_agent MCP tool", () => {
|
||||
lifecycle: "idle",
|
||||
currentModeId: null,
|
||||
availableModes: [],
|
||||
config: { title: "Feature test", featureValues: { fast_mode: true } },
|
||||
config: { title: "Feature test", providerOptions: { fast_mode: true } },
|
||||
} as ManagedAgent);
|
||||
|
||||
const server = await createAgentMcpServer({
|
||||
@@ -1834,7 +1834,7 @@ describe("create_agent MCP tool", () => {
|
||||
expect.objectContaining({
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
}),
|
||||
undefined,
|
||||
{ workspaceId: "workspace-created" },
|
||||
@@ -3039,12 +3039,12 @@ describe("create_agent MCP tool", () => {
|
||||
lifecycle: "idle",
|
||||
currentModeId: null,
|
||||
availableModes: [],
|
||||
config: { title: "Child", featureValues: { fast_mode: true } },
|
||||
config: { title: "Child", providerOptions: { fast_mode: true } },
|
||||
} as ManagedAgent);
|
||||
const providerSnapshot = createOpenCodeManager();
|
||||
providerSnapshot.stub.resolveCreateConfig.mockImplementation(async (input) => {
|
||||
const opts = input as { featureValues: Record<string, unknown> | undefined };
|
||||
return { modeId: undefined, featureValues: opts.featureValues };
|
||||
const opts = input as { providerOptions: Record<string, unknown> | undefined };
|
||||
return { modeId: undefined, providerOptions: opts.providerOptions };
|
||||
});
|
||||
|
||||
const server = await createAgentMcpServer({
|
||||
@@ -3072,7 +3072,7 @@ describe("create_agent MCP tool", () => {
|
||||
expect.objectContaining({
|
||||
provider: "codex",
|
||||
model: "gpt-5.4",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
@@ -3273,7 +3273,7 @@ describe("create_agent MCP tool", () => {
|
||||
provStub.resolveCreateConfig.mockImplementation(async (input) => {
|
||||
const opts = input as { requestedMode: string | undefined };
|
||||
expect(opts.requestedMode).toBe("dynamic");
|
||||
return { modeId: "dynamic", featureValues: undefined };
|
||||
return { modeId: "dynamic", providerOptions: undefined };
|
||||
});
|
||||
const server = await createAgentMcpServer({
|
||||
agentManager,
|
||||
@@ -3307,12 +3307,12 @@ describe("create_agent MCP tool", () => {
|
||||
lifecycle: "idle",
|
||||
currentModeId: "build",
|
||||
availableModes: [],
|
||||
config: { title: "Child", featureValues: { auto_accept: true } },
|
||||
config: { title: "Child", providerOptions: { auto_accept: true } },
|
||||
} as ManagedAgent);
|
||||
const providerSnapshot = createOpenCodeManager();
|
||||
providerSnapshot.stub.resolveCreateConfig.mockResolvedValue({
|
||||
modeId: "build",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
const server = await createAgentMcpServer({
|
||||
agentManager,
|
||||
@@ -3332,7 +3332,7 @@ describe("create_agent MCP tool", () => {
|
||||
});
|
||||
|
||||
expect(spies.agentManager.createAgent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ modeId: "build", featureValues: { auto_accept: true } }),
|
||||
expect.objectContaining({ modeId: "build", providerOptions: { auto_accept: true } }),
|
||||
undefined,
|
||||
{ workspaceId: "workspace-created" },
|
||||
);
|
||||
@@ -3360,7 +3360,7 @@ describe("create_agent MCP tool", () => {
|
||||
const providerSnapshot = createOpenCodeManager();
|
||||
providerSnapshot.stub.resolveCreateConfig.mockResolvedValue({
|
||||
modeId: "resolver-mode",
|
||||
featureValues: { resolver_feature: true },
|
||||
providerOptions: { resolver_feature: true },
|
||||
});
|
||||
|
||||
const server = await createAgentMcpServer({
|
||||
@@ -3384,7 +3384,7 @@ describe("create_agent MCP tool", () => {
|
||||
expect(spies.agentManager.createAgent).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
modeId: "resolver-mode",
|
||||
featureValues: { resolver_feature: true },
|
||||
providerOptions: { resolver_feature: true },
|
||||
}),
|
||||
undefined,
|
||||
expect.any(Object),
|
||||
@@ -4717,7 +4717,7 @@ describe("update_agent MCP tool", () => {
|
||||
expect(spies.agentManager.setAgentMode).toHaveBeenCalledWith("agent-1", "full-access");
|
||||
expect(spies.agentManager.setAgentModel).toHaveBeenCalledWith("agent-1", "gpt-5.4");
|
||||
expect(spies.agentManager.setAgentThinkingOption).toHaveBeenCalledWith("agent-1", "high");
|
||||
expect(spies.agentManager.setAgentFeature).toHaveBeenCalledWith("agent-1", "fast_mode", true);
|
||||
expect(spies.agentManager.setAgentOptions).toHaveBeenCalledWith("agent-1", { fast_mode: true });
|
||||
expect(spies.agentManager.updateAgentMetadata).toHaveBeenCalledWith("agent-1", {
|
||||
title: "Updated agent",
|
||||
labels: { role: "worker" },
|
||||
@@ -4742,12 +4742,12 @@ describe("update_agent MCP tool", () => {
|
||||
expect(spies.agentManager.setAgentMode).not.toHaveBeenCalled();
|
||||
expect(spies.agentManager.setAgentModel).not.toHaveBeenCalled();
|
||||
expect(spies.agentManager.setAgentThinkingOption).not.toHaveBeenCalled();
|
||||
expect(spies.agentManager.setAgentFeature).not.toHaveBeenCalled();
|
||||
expect(spies.agentManager.setAgentOptions).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not update metadata when runtime settings fail", async () => {
|
||||
const { agentManager, agentStorage, spies } = createTestDeps();
|
||||
spies.agentManager.setAgentFeature.mockRejectedValue(new Error("unsupported feature"));
|
||||
spies.agentManager.setAgentOptions.mockRejectedValue(new Error("unsupported feature"));
|
||||
const server = await createAgentMcpServer({
|
||||
agentManager,
|
||||
agentStorage,
|
||||
@@ -5065,7 +5065,7 @@ describe("create_schedule MCP tool", () => {
|
||||
config: {
|
||||
title: "Parent agent",
|
||||
model: "openai/gpt-5.5",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
},
|
||||
} as ManagedAgent);
|
||||
const createOrReplace = vi.fn(async (input: CreateScheduleInput) =>
|
||||
@@ -5093,7 +5093,7 @@ describe("create_schedule MCP tool", () => {
|
||||
cwd: REPO_CWD,
|
||||
modeId: "build",
|
||||
model: "openai/gpt-5.5",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -5867,7 +5867,7 @@ describe("agent profile listing MCP tool", () => {
|
||||
model: "claude-test-model",
|
||||
modeId: "bypassPermissions",
|
||||
thinkingOptionId: "high",
|
||||
featureValues: { fast_mode: true },
|
||||
options: { fast_mode: true },
|
||||
notes: "Use for UI work: components, layout, design tokens. Not for backend.",
|
||||
},
|
||||
];
|
||||
@@ -5882,7 +5882,21 @@ describe("agent profile listing MCP tool", () => {
|
||||
|
||||
const response = await tool.handler({});
|
||||
|
||||
expect(response.structuredContent).toEqual({ profiles });
|
||||
// The config store holds profiles with `options` only; the tool reports them as stored.
|
||||
expect(response.structuredContent).toEqual({
|
||||
profiles: [
|
||||
{
|
||||
id: "ui-profile",
|
||||
name: "UI work",
|
||||
provider: "claude",
|
||||
model: "claude-test-model",
|
||||
modeId: "bypassPermissions",
|
||||
thinkingOptionId: "high",
|
||||
options: { fast_mode: true },
|
||||
notes: "Use for UI work: components, layout, design tokens. Not for backend.",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("returns an empty array when no profiles are configured", async () => {
|
||||
@@ -5934,14 +5948,10 @@ describe("provider MCP tools", () => {
|
||||
|
||||
it("inspects provider features for a draft agent configuration", async () => {
|
||||
const { agentManager, agentStorage, spies } = createTestDeps();
|
||||
spies.agentManager.listDraftFeatures.mockResolvedValue([
|
||||
{
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
label: "Fast mode",
|
||||
value: false,
|
||||
},
|
||||
]);
|
||||
spies.agentManager.listDraftControls.mockResolvedValue({
|
||||
controls: [{ type: "toggle", key: "fast_mode", label: "Fast mode" }],
|
||||
options: { fast_mode: true },
|
||||
});
|
||||
const provStub = createProviderSnapshotManagerStub();
|
||||
provStub.listRegisteredProviderIds.mockReturnValue(["codex"]);
|
||||
const codexEntry = buildSnapshotEntry({
|
||||
@@ -5974,13 +5984,13 @@ describe("provider MCP tools", () => {
|
||||
|
||||
const response = await tool.handler(input);
|
||||
|
||||
expect(spies.agentManager.listDraftFeatures).toHaveBeenCalledWith({
|
||||
expect(spies.agentManager.listDraftControls).toHaveBeenCalledWith({
|
||||
provider: "codex",
|
||||
cwd: expect.stringContaining("repo"),
|
||||
modeId: "full-access",
|
||||
model: "gpt-5.4",
|
||||
thinkingOptionId: "high",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
});
|
||||
expect(response.structuredContent).toEqual({
|
||||
provider: "codex",
|
||||
@@ -5995,7 +6005,7 @@ describe("provider MCP tools", () => {
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
label: "Fast mode",
|
||||
value: false,
|
||||
value: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -6211,14 +6221,8 @@ describe("agent snapshot MCP serialization", () => {
|
||||
description: "Default coding mode",
|
||||
},
|
||||
],
|
||||
features: [
|
||||
{
|
||||
type: "toggle",
|
||||
id: "web-search",
|
||||
label: "Web search",
|
||||
value: true,
|
||||
},
|
||||
],
|
||||
controls: [{ type: "toggle", key: "web-search", label: "Web search" }],
|
||||
effectiveOptions: { "web-search": true },
|
||||
pendingPermissions: new Map(),
|
||||
persistence: {
|
||||
provider: "codex",
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { convertLegacyOptions, foldHookFeatureValues } from "./option-controls.js";
|
||||
|
||||
describe("convertLegacyOptions rejects a malformed Codex fast_mode", () => {
|
||||
test.each(["false", 1, {}])("%j", (value) => {
|
||||
expect(() =>
|
||||
convertLegacyOptions({ provider: "codex", options: { fast_mode: value } }),
|
||||
).toThrow(/fast_mode must be true, false or null/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("convertLegacyOptions", () => {
|
||||
test.each([
|
||||
{ legacy: true, tier: "fast" },
|
||||
{ legacy: false, tier: "default" },
|
||||
{ legacy: null, tier: null },
|
||||
])("Codex fast_mode: $legacy becomes service_tier: $tier", ({ legacy, tier }) => {
|
||||
expect(
|
||||
convertLegacyOptions({ provider: "codex", options: { fast_mode: legacy, plan_mode: true } }),
|
||||
).toEqual({ plan_mode: true, service_tier: tier });
|
||||
});
|
||||
|
||||
test("a service_tier in the same input wins", () => {
|
||||
expect(
|
||||
convertLegacyOptions({
|
||||
provider: "codex",
|
||||
options: { service_tier: "default", fast_mode: true },
|
||||
}),
|
||||
).toEqual({ service_tier: "default" });
|
||||
});
|
||||
|
||||
test("other providers keep fast_mode", () => {
|
||||
const options = { fast_mode: true };
|
||||
expect(convertLegacyOptions({ provider: "claude", options })).toBe(options);
|
||||
});
|
||||
});
|
||||
|
||||
describe("foldHookFeatureValues", () => {
|
||||
const convert = (options: Record<string, unknown>) =>
|
||||
convertLegacyOptions({ provider: "codex", options });
|
||||
|
||||
test("a hook that edits featureValues.fast_mode sets service_tier", () => {
|
||||
const sent = { providerOptions: {}, featureValues: {} };
|
||||
const returned = { providerOptions: {}, featureValues: { fast_mode: true } };
|
||||
|
||||
expect(foldHookFeatureValues({ returned, sent, convert }).providerOptions).toEqual({
|
||||
service_tier: "fast",
|
||||
});
|
||||
});
|
||||
|
||||
test("a hook that replaces the speed it was sent with fast_mode selects Fast", () => {
|
||||
const sent = {
|
||||
providerOptions: { service_tier: "default" },
|
||||
featureValues: { service_tier: "default" },
|
||||
};
|
||||
const returned = { ...sent, featureValues: { fast_mode: true } };
|
||||
|
||||
expect(foldHookFeatureValues({ returned, sent, convert }).providerOptions).toEqual({
|
||||
service_tier: "fast",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,304 @@
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import type {
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
AgentOptionSelectControl,
|
||||
ProviderOptions,
|
||||
} from "@getpaseo/protocol/agent-types";
|
||||
|
||||
/**
|
||||
* A patch over an agent's own options: top-level keys replace, `null` removes the key so the
|
||||
* `config.json` default (or the provider's own default) applies again.
|
||||
*/
|
||||
export type ProviderOptionsPatch = Record<string, unknown>;
|
||||
|
||||
export function applyProviderOptionsPatch(input: {
|
||||
options: ProviderOptions | undefined;
|
||||
patch: ProviderOptionsPatch;
|
||||
}): ProviderOptions {
|
||||
const { options, patch } = input;
|
||||
const next: ProviderOptions = { ...options };
|
||||
for (const [key, value] of Object.entries(patch)) {
|
||||
if (value === null) {
|
||||
delete next[key];
|
||||
} else if (value !== undefined) {
|
||||
next[key] = value;
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/** COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01. */
|
||||
export interface LegacyFeatureValues {
|
||||
featureValues?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(codexFastPreference): added in v0.10.0, remove after 2027-03-29 once saved Fast
|
||||
* preferences have migrated. Codex used to take `fast_mode`; it takes `service_tier` now. Old
|
||||
* data (stored records, config.json defaults, profiles, older clients, hooks) is converted here
|
||||
* as it enters, so nothing past this point sees `fast_mode` for Codex. A `service_tier` in the
|
||||
* same input wins. A patch's `null` stays `null`, which removes the speed.
|
||||
*/
|
||||
interface LegacyOptionsInput<O> {
|
||||
provider: string | undefined;
|
||||
options: O;
|
||||
}
|
||||
|
||||
export function convertLegacyOptions(
|
||||
input: LegacyOptionsInput<Record<string, unknown>>,
|
||||
): Record<string, unknown>;
|
||||
export function convertLegacyOptions(
|
||||
input: LegacyOptionsInput<Record<string, unknown> | undefined>,
|
||||
): Record<string, unknown> | undefined;
|
||||
export function convertLegacyOptions(
|
||||
input: LegacyOptionsInput<Record<string, unknown> | undefined>,
|
||||
): Record<string, unknown> | undefined {
|
||||
const { provider, options } = input;
|
||||
if (provider !== "codex" || !options || !("fast_mode" in options)) return options;
|
||||
const { fast_mode: legacy, ...rest } = options;
|
||||
if (legacy !== undefined && legacy !== null && typeof legacy !== "boolean") {
|
||||
throw new Error("Codex fast_mode must be true, false or null");
|
||||
}
|
||||
if ("service_tier" in rest || legacy === undefined) return rest;
|
||||
if (legacy === null) return { ...rest, service_tier: null };
|
||||
return { ...rest, service_tier: legacy ? "fast" : "default" };
|
||||
}
|
||||
|
||||
/**
|
||||
* The built-in adapter a provider id runs on: a custom provider is named by the one it
|
||||
* `extends`, followed until a provider that extends nothing. `extendsOf` is where the caller
|
||||
* reads that link (the registry's definitions, or `config.json`'s `providers` section).
|
||||
*/
|
||||
export function resolveAdapter(input: {
|
||||
provider: string;
|
||||
extendsOf: (provider: string) => string | null | undefined;
|
||||
}): string {
|
||||
const seen = new Set<string>();
|
||||
let current = input.provider;
|
||||
for (;;) {
|
||||
seen.add(current);
|
||||
const base = input.extendsOf(current);
|
||||
if (!base || seen.has(base)) return current;
|
||||
current = base;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* Older clients, stored records, profiles, and plugin hooks carry composer values in
|
||||
* `featureValues`. This is the one place they become `providerOptions`; an explicit
|
||||
* `providerOptions` key wins over a `featureValues` key of the same name.
|
||||
*/
|
||||
export function foldFeatureValues<
|
||||
T extends {
|
||||
providerOptions?: ProviderOptions | null;
|
||||
featureValues?: Record<string, unknown> | null;
|
||||
},
|
||||
>(config: T): Omit<T, "featureValues"> {
|
||||
const { featureValues, ...rest } = config;
|
||||
if (!featureValues || Object.keys(featureValues).length === 0) return rest;
|
||||
return { ...rest, providerOptions: { ...featureValues, ...rest.providerOptions } };
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* A plugin written against the previous SDK reads and edits `config.featureValues`, so a
|
||||
* hook sees a copy of the config's options there. What the hook did to that copy (set,
|
||||
* replaced or deleted a key, or dropped the field) is applied as a patch over the options it
|
||||
* returned; keys it left alone change nothing.
|
||||
*/
|
||||
export function exposeFeatureValuesToHook<
|
||||
T extends { providerOptions?: ProviderOptions | null; featureValues?: Record<string, unknown> },
|
||||
>(config: T): T {
|
||||
if (!config.providerOptions || Object.keys(config.providerOptions).length === 0) return config;
|
||||
return { ...config, featureValues: { ...config.providerOptions } };
|
||||
}
|
||||
|
||||
export function foldHookFeatureValues<
|
||||
T extends {
|
||||
providerOptions?: ProviderOptions | null;
|
||||
featureValues?: Record<string, unknown>;
|
||||
},
|
||||
>(input: {
|
||||
returned: T;
|
||||
sent: T;
|
||||
/** Brings what the hook returned to the form of the copy it was sent. */
|
||||
convert: (options: Record<string, unknown>) => Record<string, unknown>;
|
||||
}): Omit<T, "featureValues"> {
|
||||
const { returned, sent, convert } = input;
|
||||
const { featureValues, ...rest } = returned;
|
||||
const before = sent.featureValues;
|
||||
if (!before) {
|
||||
// No copy was sent, so everything the hook put in `featureValues` is new.
|
||||
return foldFeatureValues(returned);
|
||||
}
|
||||
// A hook may return an older key where it was sent the current one; comparing in the same
|
||||
// form keeps a replaced value from reading as a deletion.
|
||||
const after = convert(featureValues ?? {});
|
||||
const patch: ProviderOptionsPatch = {};
|
||||
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
||||
if (isDeepStrictEqual(after[key], before[key])) continue;
|
||||
patch[key] = key in after ? after[key] : null;
|
||||
}
|
||||
return {
|
||||
...rest,
|
||||
providerOptions: applyProviderOptionsPatch({
|
||||
options: rest.providerOptions ?? undefined,
|
||||
patch,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
type ConvertedOptions = Record<string, unknown> | undefined;
|
||||
|
||||
interface ProfileOptionFields {
|
||||
provider?: string;
|
||||
options?: Record<string, unknown>;
|
||||
featureValues?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* Profiles saved before options carry `featureValues`; when one comes from storage, `options`
|
||||
* wins over a stale `featureValues` key.
|
||||
*
|
||||
* A write that carries `options` is from a client that knows them: its `featureValues` fold
|
||||
* over those. A write without `options` is from the unchanged app, whose form only knows the
|
||||
* controls: its `featureValues` are a patch (`null` deletes) over the options stored for that
|
||||
* profile, so options the form never shows, such as `sandbox_mode`, survive an edit. A profile
|
||||
* moved to another provider starts from no options, because the old provider's keys mean
|
||||
* nothing to the new one.
|
||||
*/
|
||||
export function foldProfileFeatureValues<T extends ProfileOptionFields>(input: {
|
||||
profile: T;
|
||||
stored: ProfileOptionFields | undefined;
|
||||
source: "stored" | "client write";
|
||||
/** Renames old option keys for the adapter the profile's provider runs on. */
|
||||
convert: (provider: string, options: Record<string, unknown> | undefined) => ConvertedOptions;
|
||||
}): Omit<T, "featureValues"> {
|
||||
const { profile, stored, source, convert } = input;
|
||||
const { featureValues: legacyValues, ...rest } = profile;
|
||||
// A profile is stored in the current keys, so removal and merging below see one vocabulary.
|
||||
const provider = rest.provider ?? "";
|
||||
const featureValues = convert(provider, legacyValues);
|
||||
const ownOptions = convert(provider, rest.options);
|
||||
if (source === "stored") {
|
||||
if (featureValues) return { ...rest, options: { ...featureValues, ...ownOptions } };
|
||||
return ownOptions ? { ...rest, options: ownOptions } : rest;
|
||||
}
|
||||
const base =
|
||||
ownOptions ??
|
||||
(stored?.provider === rest.provider ? convert(provider, stored?.options) : undefined);
|
||||
// The form sends no `featureValues` when no control is set, which is still an edit of a
|
||||
// profile that may hold other options.
|
||||
if (!featureValues && !base) return rest;
|
||||
return {
|
||||
...rest,
|
||||
options: applyProviderOptionsPatch({ options: base, patch: featureValues ?? {} }),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* The unchanged app reads a profile's options from `featureValues`; the config API answers with
|
||||
* both fields.
|
||||
*/
|
||||
export function withLegacyProfileFeatureValues<T extends ProfileOptionFields>(profile: T): T {
|
||||
return profile.options ? { ...profile, featureValues: { ...profile.options } } : profile;
|
||||
}
|
||||
|
||||
function selectedChoice(control: AgentOptionSelectControl, options: ProviderOptions) {
|
||||
const value = options[control.key];
|
||||
if (typeof value === "string") {
|
||||
const choice = control.choices.find((candidate) => candidate.value === value);
|
||||
if (choice) return choice.value;
|
||||
}
|
||||
return control.defaultValue ?? null;
|
||||
}
|
||||
|
||||
function describe(control: { description?: string; tooltip?: string; icon?: string }): {
|
||||
description?: string;
|
||||
tooltip?: string;
|
||||
icon?: string;
|
||||
} {
|
||||
return {
|
||||
...(control.description !== undefined ? { description: control.description } : {}),
|
||||
...(control.tooltip !== undefined ? { tooltip: control.tooltip } : {}),
|
||||
...(control.icon !== undefined ? { icon: control.icon } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function featureFromControl(control: AgentOptionControl, effective: ProviderOptions): AgentFeature {
|
||||
if (control.type === "toggle") {
|
||||
const value = effective[control.key];
|
||||
return {
|
||||
type: "toggle",
|
||||
id: control.key,
|
||||
label: control.label,
|
||||
...describe(control),
|
||||
value: typeof value === "boolean" ? value : (control.defaultValue ?? false),
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "select",
|
||||
id: control.key,
|
||||
label: control.label,
|
||||
...describe(control),
|
||||
...(control.desktopTrigger ? { desktopTrigger: control.desktopTrigger } : {}),
|
||||
value: selectedChoice(control, effective),
|
||||
options: control.choices.map((choice) => ({
|
||||
id: choice.value,
|
||||
label: choice.label,
|
||||
...(choice.description ? { description: choice.description } : {}),
|
||||
...(choice.value === control.defaultValue ? { isDefault: true } : {}),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* Apps that predate controls render `features`; build them from controls + effective options.
|
||||
*/
|
||||
export function featuresFromControls(input: {
|
||||
controls: readonly AgentOptionControl[] | undefined;
|
||||
options: ProviderOptions | undefined;
|
||||
}): AgentFeature[] {
|
||||
const { controls, options } = input;
|
||||
const effective = options ?? {};
|
||||
return (controls ?? []).map((control) => featureFromControl(control, effective));
|
||||
}
|
||||
|
||||
/** A recorded feature's value is not carried over: controls hold no state, only `options` do. */
|
||||
function controlFromFeature(feature: AgentFeature): AgentOptionControl {
|
||||
const descriptor = {
|
||||
key: feature.id,
|
||||
label: feature.label,
|
||||
...describe(feature),
|
||||
};
|
||||
if (feature.type === "toggle") {
|
||||
return { type: "toggle", ...descriptor };
|
||||
}
|
||||
const defaultChoice = feature.options.find((option) => option.isDefault);
|
||||
return {
|
||||
type: "select",
|
||||
...descriptor,
|
||||
...(feature.desktopTrigger ? { desktopTrigger: feature.desktopTrigger } : {}),
|
||||
...(defaultChoice ? { defaultValue: defaultChoice.id } : {}),
|
||||
choices: feature.options.map((option) => ({
|
||||
value: option.id,
|
||||
label: option.label,
|
||||
...(option.description ? { description: option.description } : {}),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* COMPAT(featureValues): added in v0.15.0, remove after 2027-05-01.
|
||||
* Agent records written before controls stored `features`; their descriptors become controls.
|
||||
*/
|
||||
export function controlsFromFeatures(
|
||||
features: readonly AgentFeature[] | undefined,
|
||||
): AgentOptionControl[] {
|
||||
return (features ?? []).map(controlFromFeature);
|
||||
}
|
||||
@@ -58,6 +58,10 @@ interface ProviderHarnessOptions {
|
||||
handleInput?: (input: ProviderInput, emit: (event: ProviderEvent) => void) => Promise<boolean>;
|
||||
}
|
||||
|
||||
function lastConfigure(inputs: ProviderInput[]): ProviderInput | undefined {
|
||||
return inputs.findLast((input) => input.type === "session.configure");
|
||||
}
|
||||
|
||||
function createProviderHarness(options: ProviderHarnessOptions = {}) {
|
||||
let listener: ((event: ProviderEvent) => void) | null = null;
|
||||
let closeCount = 0;
|
||||
@@ -970,7 +974,7 @@ describe("PluginAgentClientRegistry", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("stores only agent options while the plugin receives merged defaults", async () => {
|
||||
test("stores the agent options and the settings the plugin opened with, not the merged config defaults", async () => {
|
||||
const logger = createTestLogger();
|
||||
const harness = createProviderHarness();
|
||||
const plugins = new PluginAgentClientRegistry(logger);
|
||||
@@ -992,13 +996,174 @@ describe("PluginAgentClientRegistry", () => {
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
expect(toStoredAgentRecord(agent).config?.providerOptions).toEqual(own);
|
||||
// `nested.base` comes from `config.json` and is not stored; `voice` is the plugin's own opening state.
|
||||
expect(toStoredAgentRecord(agent).config?.providerOptions).toEqual({ ...own, voice: "direct" });
|
||||
expect(harness.inputs.find((input) => input.type === "session.open")).toMatchObject({
|
||||
config: { providerOptions: { nested: { base: true, replace: "agent" } } },
|
||||
});
|
||||
await agent.session?.close();
|
||||
});
|
||||
|
||||
describe("settings", () => {
|
||||
// A plugin that keeps `voice` on "direct" whatever it is asked, and takes `loud` as given.
|
||||
async function openStubbornVoiceSession(
|
||||
given: Record<string, boolean | string>,
|
||||
{ refuseAfterChanging = false }: { refuseAfterChanging?: boolean } = {},
|
||||
) {
|
||||
const state = { voice: "direct", loud: false };
|
||||
let openedSessionId = "";
|
||||
const settings = () => [
|
||||
{
|
||||
type: "select" as const,
|
||||
id: "voice",
|
||||
label: "Voice",
|
||||
value: state.voice,
|
||||
options: [
|
||||
{ label: "Direct", value: "direct" },
|
||||
{ label: "Other", value: "other" },
|
||||
],
|
||||
},
|
||||
{ type: "toggle" as const, id: "loud", label: "Loud", value: state.loud },
|
||||
];
|
||||
const emitConfig = (emit: (event: ProviderEvent) => void, sessionId: string) =>
|
||||
emit({
|
||||
type: "session.config",
|
||||
sessionId,
|
||||
config: {
|
||||
model: "plugin-model",
|
||||
mode: "build",
|
||||
models: [{ id: "plugin-model", label: "Plugin model" }],
|
||||
modes: [{ id: "build", label: "Build" }],
|
||||
thinkingOptions: [],
|
||||
settings: settings(),
|
||||
},
|
||||
});
|
||||
const harness = createProviderHarness({
|
||||
async handleInput(input, emit) {
|
||||
if (input.type === "session.open") {
|
||||
openedSessionId = input.sessionId;
|
||||
emit({
|
||||
type: "session.opened",
|
||||
requestId: input.requestId,
|
||||
sessionId: input.sessionId,
|
||||
capabilities: CAPABILITIES,
|
||||
restoration: "core",
|
||||
persistence: { version: 1, data: { token: "root" } },
|
||||
cwd: input.config.cwd,
|
||||
});
|
||||
emitConfig(emit, input.sessionId);
|
||||
emit({ type: "session.ready", requestId: input.requestId, sessionId: input.sessionId });
|
||||
return true;
|
||||
}
|
||||
if (input.type === "session.configure") {
|
||||
const loud = input.changes.settings?.loud;
|
||||
if (typeof loud === "boolean") state.loud = loud;
|
||||
emitConfig(emit, input.sessionId);
|
||||
emit(
|
||||
refuseAfterChanging
|
||||
? { type: "request.failed", requestId: input.requestId, error: { message: "no" } }
|
||||
: { type: "request.completed", requestId: input.requestId },
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
});
|
||||
const plugins = new PluginAgentClientRegistry(createTestLogger());
|
||||
plugins.replace([harness.registration]);
|
||||
const session = await plugins.clients()["plugin-direct"]!.createSession({
|
||||
provider: "plugin-direct",
|
||||
cwd: tmpdir(),
|
||||
providerOptions: given,
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
const changeOnItsOwn = (change: Partial<typeof state>) => {
|
||||
Object.assign(state, change);
|
||||
emitConfig(harness.emit, openedSessionId);
|
||||
};
|
||||
return { harness, session, events, changeOnItsOwn };
|
||||
}
|
||||
|
||||
test("forwards a setting the plugin changes on its own", async () => {
|
||||
const { session, events, changeOnItsOwn } = await openStubbornVoiceSession({});
|
||||
|
||||
changeOnItsOwn({ loud: true });
|
||||
|
||||
expect(eventsOfType(events, "options_changed")).toEqual([
|
||||
{ type: "options_changed", provider: "plugin-direct", patch: { loud: true } },
|
||||
]);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("a rejected apply reports what the plugin moved before refusing, since nothing is stored", async () => {
|
||||
const { session, events } = await openStubbornVoiceSession({}, { refuseAfterChanging: true });
|
||||
|
||||
await expect(session.applyOptions?.({ loud: true })).rejects.toThrow("no");
|
||||
|
||||
expect(eventsOfType(events, "options_changed")).toEqual([
|
||||
{ type: "options_changed", provider: "plugin-direct", patch: { loud: true } },
|
||||
]);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("a setting the plugin opened differently is the session's open patch, not an event", async () => {
|
||||
const { session, events } = await openStubbornVoiceSession({ voice: "other", loud: false });
|
||||
|
||||
expect(session.openOptionsPatch).toEqual({ voice: "direct" });
|
||||
expect(eventsOfType(events, "options_changed")).toEqual([]);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("settings the plugin opened with that nobody set are in the open patch", async () => {
|
||||
const { session, events } = await openStubbornVoiceSession({});
|
||||
|
||||
expect(session.openOptionsPatch).toEqual({ voice: "direct", loud: false });
|
||||
expect(eventsOfType(events, "options_changed")).toEqual([]);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("applying options configures only the settings it is given", async () => {
|
||||
const { harness, session } = await openStubbornVoiceSession({});
|
||||
|
||||
await session.applyOptions?.({ loud: true });
|
||||
|
||||
const configure = lastConfigure(harness.inputs);
|
||||
expect(configure).toMatchObject({ changes: { settings: { loud: true } } });
|
||||
expect(
|
||||
Object.keys((configure as { changes: { settings: object } }).changes.settings),
|
||||
).toEqual(["loud"]);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("rejects a key the plugin does not report as a setting, and configures none of a mixed patch", async () => {
|
||||
const { harness, session } = await openStubbornVoiceSession({ launch_key: "original" });
|
||||
const configureBefore = lastConfigure(harness.inputs);
|
||||
|
||||
await expect(session.applyOptions?.({ loud: true, launch_key: "changed" })).rejects.toThrow(
|
||||
/launch_key.*cannot change on a running session/,
|
||||
);
|
||||
|
||||
expect(lastConfigure(harness.inputs)).toBe(configureBefore);
|
||||
|
||||
// The value it opened with is not a change, so a whole profile can be applied.
|
||||
await session.applyOptions?.({ loud: true, launch_key: "original" });
|
||||
const configure = lastConfigure(harness.inputs) as { changes: { settings: object } };
|
||||
expect(Object.keys(configure.changes.settings)).toEqual(["loud"]);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("applying options returns the settings that ended up different, and emits nothing", async () => {
|
||||
const { session, events } = await openStubbornVoiceSession({});
|
||||
|
||||
const ended = await session.applyOptions?.({ voice: "other", loud: true });
|
||||
|
||||
expect(ended).toEqual({ voice: "direct" });
|
||||
expect(eventsOfType(events, "options_changed")).toEqual([]);
|
||||
await session.close();
|
||||
});
|
||||
});
|
||||
|
||||
test.each([
|
||||
{ options: { nested: { base: true, replace: "config" }, list: [1, 2], scalar: "config" } },
|
||||
{ params: { nested: { base: true, replace: "config" }, list: [1, 2], scalar: "config" } },
|
||||
@@ -1511,12 +1676,13 @@ describe("PluginAgentClientRegistry", () => {
|
||||
});
|
||||
|
||||
const session = await client!.createSession({ provider: "plugin-direct", cwd: "/workspace" });
|
||||
expect(session.features).toEqual([
|
||||
expect.objectContaining({
|
||||
expect(session.controls).toEqual([
|
||||
{
|
||||
type: "select",
|
||||
id: "voice",
|
||||
options: [{ id: "direct", label: "Direct", value: "direct" }],
|
||||
}),
|
||||
key: "voice",
|
||||
label: "Voice",
|
||||
choices: [{ value: "direct", label: "Direct" }],
|
||||
},
|
||||
]);
|
||||
expect(session.describePersistence()).toMatchObject({
|
||||
provider: "plugin-direct",
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import { PluginSessionHistory } from "./plugin-session-history.js";
|
||||
import { resolve as resolvePath } from "node:path";
|
||||
import type { Logger } from "pino";
|
||||
import type { JsonValue } from "@getpaseo/protocol/agent-types";
|
||||
import type { JsonValue, ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
PROVIDER_CAPABILITIES,
|
||||
@@ -31,10 +32,10 @@ import type {
|
||||
AgentCapabilityFlags,
|
||||
AgentClient,
|
||||
AgentCreateSessionOptions,
|
||||
AgentFeature,
|
||||
AgentLaunchContext,
|
||||
AgentMode,
|
||||
AgentModelDefinition,
|
||||
AgentOptionControl,
|
||||
AgentPermissionRequest,
|
||||
AgentPermissionResponse,
|
||||
AgentPersistenceHandle,
|
||||
@@ -63,6 +64,7 @@ import {
|
||||
createProviderEnv,
|
||||
type ProviderRuntimeSettings,
|
||||
} from "./provider-launch-config.js";
|
||||
import { assertChangesAreLive } from "./provider-options.js";
|
||||
import type { RegisteredProviderDefinition } from "./provider-registry.js";
|
||||
import { runProviderTurn } from "./providers/provider-runner.js";
|
||||
import { StaleProviderSessionError } from "./stale-provider-session-error.js";
|
||||
@@ -1133,6 +1135,7 @@ class PluginAgentClient implements AgentClient {
|
||||
});
|
||||
},
|
||||
bind,
|
||||
config.settings,
|
||||
);
|
||||
bind(bridge);
|
||||
return session;
|
||||
@@ -1201,6 +1204,11 @@ class PluginAgentSession implements AgentSession {
|
||||
>();
|
||||
private readonly childSnapshots = new Map<string, Map<string, TimelineTextSnapshot>>();
|
||||
private unsubscribe: (() => void) | null = null;
|
||||
/** How the opened session differs from the settings it was given. */
|
||||
readonly openOptionsPatch: Record<string, JsonValue>;
|
||||
private knownSettings: Record<string, JsonValue> = {};
|
||||
/** While `applyOptions` waits on the plugin, its `session.config` answers that call. */
|
||||
private applyingOptions = false;
|
||||
private currentTurnId: string | null = null;
|
||||
private closed = false;
|
||||
private replay: {
|
||||
@@ -1221,8 +1229,12 @@ class PluginAgentSession implements AgentSession {
|
||||
state: ProviderConfigState,
|
||||
) => Promise<ProviderRuntimeSession>,
|
||||
private readonly onBind: (bridge: ProviderRuntimeSession) => void,
|
||||
private readonly givenSettings: Readonly<Record<string, JsonValue>>,
|
||||
) {
|
||||
this.subagentIdsBySession.set(bridge.id, null);
|
||||
// Every setting the session opened with that was not given, including ones nobody set.
|
||||
this.openOptionsPatch = this.settingDifferences(givenSettings);
|
||||
this.knownSettings = this.currentSettings();
|
||||
for (const event of bridge.history) this.accept(event, false);
|
||||
// Opening notices arrive before the manager subscribes to the session.
|
||||
// Commit them on registration and replay the same timestamps from history.
|
||||
@@ -1246,14 +1258,27 @@ class PluginAgentSession implements AgentSession {
|
||||
};
|
||||
}
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
return this.bridge.config.settings.map((setting) =>
|
||||
setting.type === "toggle"
|
||||
? { ...setting }
|
||||
: {
|
||||
...setting,
|
||||
options: setting.options.map((option) => ({ ...option, id: option.value })),
|
||||
},
|
||||
/** The plugin's `settings` are its option controls; each setting id is an option key. */
|
||||
get controls(): AgentOptionControl[] {
|
||||
return this.bridge.config.settings.map(
|
||||
(setting): AgentOptionControl =>
|
||||
setting.type === "toggle"
|
||||
? {
|
||||
type: "toggle",
|
||||
key: setting.id,
|
||||
label: setting.label,
|
||||
...(setting.description ? { description: setting.description } : {}),
|
||||
}
|
||||
: {
|
||||
type: "select",
|
||||
key: setting.id,
|
||||
label: setting.label,
|
||||
...(setting.description ? { description: setting.description } : {}),
|
||||
choices: setting.options.map((option) => ({
|
||||
value: option.value,
|
||||
label: option.label,
|
||||
})),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1410,11 +1435,38 @@ class PluginAgentSession implements AgentSession {
|
||||
await this.bridge.configure({ thinkingOption: thinkingOptionId });
|
||||
}
|
||||
|
||||
async setFeature(featureId: string, value: unknown): Promise<void> {
|
||||
async applyOptions(options: ProviderOptions): Promise<Record<string, JsonValue>> {
|
||||
this.assertReplayComplete();
|
||||
await this.bridge.configure({
|
||||
settings: { [featureId]: toJsonValue(value, `setting '${featureId}'`) },
|
||||
const before = this.currentSettings();
|
||||
// A key the plugin does not report as a setting is one it only reads when the session opens;
|
||||
// a value equal to the one it opened with is not a change.
|
||||
assertChangesAreLive({
|
||||
provider: this.provider,
|
||||
patch: options,
|
||||
current: this.givenSettings,
|
||||
live: Object.keys(before),
|
||||
});
|
||||
const settings: Record<string, JsonValue> = {};
|
||||
for (const [id, value] of Object.entries(options)) {
|
||||
if (!(id in before)) continue;
|
||||
settings[id] = toJsonValue(value, `setting '${id}'`);
|
||||
}
|
||||
if (Object.keys(settings).length === 0) return {};
|
||||
this.applyingOptions = true;
|
||||
try {
|
||||
await this.bridge.configure({ settings });
|
||||
} catch (error) {
|
||||
// Nothing is stored for a refused patch, so what the plugin moved is reported once the
|
||||
// call has ended.
|
||||
this.applyingOptions = false;
|
||||
for (const event of this.reportSettingChanges()) this.publish(event);
|
||||
throw error;
|
||||
} finally {
|
||||
this.applyingOptions = false;
|
||||
}
|
||||
const ended = this.settingDifferences({ ...before, ...settings });
|
||||
this.knownSettings = this.currentSettings();
|
||||
return ended;
|
||||
}
|
||||
|
||||
async revertConversation(input: { messageId: string }): Promise<void> {
|
||||
@@ -1596,10 +1648,36 @@ class PluginAgentSession implements AgentSession {
|
||||
};
|
||||
}
|
||||
|
||||
private currentSettings(): Record<string, JsonValue> {
|
||||
return Object.fromEntries(
|
||||
this.bridge.config.settings.map((setting) => [setting.id, setting.value]),
|
||||
);
|
||||
}
|
||||
|
||||
/** Settings whose value differs from `known`: the plugin's own change or its opening state. */
|
||||
private settingDifferences(
|
||||
known: Readonly<Record<string, JsonValue>>,
|
||||
): Record<string, JsonValue> {
|
||||
const patch: Record<string, JsonValue> = {};
|
||||
for (const [id, value] of Object.entries(this.currentSettings())) {
|
||||
if (!isDeepStrictEqual(known[id], value)) patch[id] = value;
|
||||
}
|
||||
return patch;
|
||||
}
|
||||
|
||||
private reportSettingChanges(): AgentStreamEvent[] {
|
||||
if (this.applyingOptions) return [];
|
||||
const patch = this.settingDifferences(this.knownSettings);
|
||||
if (Object.keys(patch).length === 0) return [];
|
||||
this.knownSettings = this.currentSettings();
|
||||
return [{ type: "options_changed", provider: this.provider, patch }];
|
||||
}
|
||||
|
||||
private translateConfig(
|
||||
event: Extract<ProviderEvent, { type: "session.config" }>,
|
||||
): AgentStreamEvent[] {
|
||||
return [
|
||||
...this.reportSettingChanges(),
|
||||
{
|
||||
type: "mode_changed",
|
||||
provider: this.provider,
|
||||
@@ -1852,7 +1930,8 @@ function mapSessionConfig(
|
||||
model: config.model,
|
||||
mode: config.modeId,
|
||||
thinkingOption: config.thinkingOptionId,
|
||||
settings: toJsonObject(config.featureValues ?? {}, "provider settings"),
|
||||
// The plugin SDK reads composer values from `settings`; they are options here.
|
||||
settings: toJsonObject(config.providerOptions ?? {}, "provider settings"),
|
||||
providerOptions: config.providerOptions,
|
||||
title: config.title ?? undefined,
|
||||
persist,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import type { z } from "zod";
|
||||
|
||||
export interface ProviderOptionIssue {
|
||||
@@ -103,3 +104,26 @@ function isPlainObject(value: unknown): value is ProviderOptions {
|
||||
const prototype = Object.getPrototypeOf(value);
|
||||
return prototype === Object.prototype || prototype === null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects a live patch that changes a key the running session cannot apply (one the provider
|
||||
* reads only when it opens). A key whose value already matches the session's is not a change.
|
||||
*/
|
||||
export function assertChangesAreLive(input: {
|
||||
provider: string;
|
||||
patch: ProviderOptions;
|
||||
current: ProviderOptions | undefined;
|
||||
live: readonly string[];
|
||||
}): void {
|
||||
const issues = Object.entries(input.patch)
|
||||
.filter(
|
||||
([key, value]) =>
|
||||
!input.live.includes(key) &&
|
||||
!isDeepStrictEqual(input.current?.[key] ?? null, value ?? null),
|
||||
)
|
||||
.map(([key]) => ({
|
||||
path: [key],
|
||||
message: "cannot change on a running session; it applies when the agent is opened",
|
||||
}));
|
||||
if (issues.length > 0) throw new ProviderOptionsValidationError(input.provider, issues);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ const OPTIONAL_AGENT_SESSION_METHOD_NAMES = [
|
||||
"listCommands",
|
||||
"setModel",
|
||||
"setThinkingOption",
|
||||
"setFeature",
|
||||
"applyOptions",
|
||||
"revertConversation",
|
||||
"revertFiles",
|
||||
"revertBoth",
|
||||
@@ -152,8 +152,8 @@ class FakeSession implements AgentSession {
|
||||
this.recordedCalls.push("setThinkingOption");
|
||||
}
|
||||
|
||||
async setFeature() {
|
||||
this.recordedCalls.push("setFeature");
|
||||
async applyOptions() {
|
||||
this.recordedCalls.push("applyOptions");
|
||||
}
|
||||
|
||||
async revertConversation() {
|
||||
@@ -193,7 +193,7 @@ describe("wrapSessionProvider", () => {
|
||||
await wrapped.listCommands?.();
|
||||
await wrapped.setModel?.("sonnet");
|
||||
await wrapped.setThinkingOption?.("high");
|
||||
await wrapped.setFeature?.("feature-1", true);
|
||||
await wrapped.applyOptions?.({ "feature-1": true });
|
||||
await wrapped.revertConversation?.({ messageId: "message-1" });
|
||||
await wrapped.revertFiles?.({ messageId: "message-1" });
|
||||
await wrapped.revertBoth?.({ messageId: "message-1" });
|
||||
@@ -208,7 +208,7 @@ describe("wrapSessionProvider", () => {
|
||||
"listCommands",
|
||||
"setModel",
|
||||
"setThinkingOption",
|
||||
"setFeature",
|
||||
"applyOptions",
|
||||
"revertConversation",
|
||||
"revertFiles",
|
||||
"revertBoth",
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { ToolPolicy } from "@getpaseo/protocol/agent-types";
|
||||
import { createTestLogger } from "../../test-utils/test-logger.js";
|
||||
import type {
|
||||
AgentClient,
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
AgentModelDefinition,
|
||||
AgentMode,
|
||||
AgentSessionConfig,
|
||||
@@ -392,15 +392,15 @@ vi.mock("./providers/cursor-acp-agent.js", () => ({
|
||||
return true;
|
||||
}
|
||||
|
||||
async listFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
async listControls(config: AgentSessionConfig): Promise<AgentOptionControl[]> {
|
||||
mockState.cursorListFeaturesConfigs.push(config);
|
||||
return [
|
||||
{
|
||||
type: "select",
|
||||
id: "fast",
|
||||
key: "fast",
|
||||
label: "Fast",
|
||||
value: "false",
|
||||
options: [{ id: "false", label: "Off" }],
|
||||
defaultValue: "false",
|
||||
choices: [{ value: "false", label: "Off" }],
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -791,6 +791,33 @@ test("ACP provider configuration retains opaque options", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("a saved legacy Codex Fast preference wins over a configured service_tier default", () => {
|
||||
const registry = buildProviderRegistry(logger, {
|
||||
providerOverrides: { codex: { options: { service_tier: "default", plan_mode: false } } },
|
||||
});
|
||||
const client = registry.codex.createClient(logger);
|
||||
|
||||
// The manager hands the registry a pre-v0.10 record's `fast_mode` already converted.
|
||||
expect(client.effectiveOptions?.({ service_tier: "fast" })).toEqual({
|
||||
service_tier: "fast",
|
||||
plan_mode: false,
|
||||
});
|
||||
expect(client.effectiveOptions?.({})).toEqual({ service_tier: "default", plan_mode: false });
|
||||
});
|
||||
|
||||
test("a configured legacy Codex Fast default supplies the service_tier default", () => {
|
||||
const registry = buildProviderRegistry(logger, {
|
||||
providerOverrides: { codex: { options: { fast_mode: true } } },
|
||||
});
|
||||
const client = registry.codex.createClient(logger);
|
||||
|
||||
// Removing an agent's own speed falls back to the configured Fast.
|
||||
expect(client.effectiveOptions?.({})).toEqual({ service_tier: "fast" });
|
||||
expect(client.effectiveOptions?.({ service_tier: "default" })).toEqual({
|
||||
service_tier: "default",
|
||||
});
|
||||
});
|
||||
|
||||
test("cursor provider extending acp uses CursorACPAgentClient", () => {
|
||||
const registry = buildProviderRegistry(logger, {
|
||||
providerOverrides: {
|
||||
@@ -823,7 +850,7 @@ test("cursor provider extending acp uses CursorACPAgentClient", () => {
|
||||
expect(mockState.constructorArgs.genericAcp).toEqual([]);
|
||||
});
|
||||
|
||||
test("wrapped cursor client lists ACP features through the inner provider", async () => {
|
||||
test("wrapped cursor client lists ACP controls through the inner provider", async () => {
|
||||
const registry = buildProviderRegistry(logger, {
|
||||
providerOverrides: {
|
||||
cursor: {
|
||||
@@ -837,17 +864,17 @@ test("wrapped cursor client lists ACP features through the inner provider", asyn
|
||||
const client = registry.cursor.createClient(logger);
|
||||
|
||||
await expect(
|
||||
client.listFeatures?.({
|
||||
client.listControls?.({
|
||||
provider: "cursor",
|
||||
cwd: "/tmp/cursor",
|
||||
}),
|
||||
).resolves.toEqual([
|
||||
{
|
||||
type: "select",
|
||||
id: "fast",
|
||||
key: "fast",
|
||||
label: "Fast",
|
||||
value: "false",
|
||||
options: [{ id: "false", label: "Off" }],
|
||||
defaultValue: "false",
|
||||
choices: [{ value: "false", label: "Off" }],
|
||||
},
|
||||
]);
|
||||
expect(mockState.cursorListFeaturesConfigs).toEqual([
|
||||
|
||||
@@ -48,6 +48,7 @@ import { PiRpcAgentClient } from "./providers/pi/agent.js";
|
||||
import { TraeACPAgentClient } from "./providers/trae-acp-agent.js";
|
||||
import { MockLoadTestAgentClient } from "./providers/mock-load-test-agent.js";
|
||||
import { MockSlowProviderClient } from "./providers/mock-slow-provider.js";
|
||||
import { convertLegacyOptions } from "./option-controls.js";
|
||||
import { ToolPolicyUnsupportedError, mergeProviderOptions } from "./provider-options.js";
|
||||
import {
|
||||
AGENT_PROVIDER_DEFINITIONS,
|
||||
@@ -447,8 +448,11 @@ export function wrapSessionProvider(provider: AgentProvider, inner: AgentSession
|
||||
get initialTimeline() {
|
||||
return inner.initialTimeline;
|
||||
},
|
||||
get features() {
|
||||
return inner.features;
|
||||
get controls() {
|
||||
return inner.controls;
|
||||
},
|
||||
get openOptionsPatch() {
|
||||
return inner.openOptionsPatch;
|
||||
},
|
||||
usageSession: inner.usageSession?.bind(inner),
|
||||
run: (prompt, options) => inner.run(prompt, options),
|
||||
@@ -473,7 +477,7 @@ export function wrapSessionProvider(provider: AgentProvider, inner: AgentSession
|
||||
listCommands: inner.listCommands?.bind(inner),
|
||||
setModel: inner.setModel?.bind(inner),
|
||||
setThinkingOption: inner.setThinkingOption?.bind(inner),
|
||||
setFeature: inner.setFeature?.bind(inner),
|
||||
applyOptions: inner.applyOptions?.bind(inner),
|
||||
revertConversation: inner.revertConversation?.bind(inner),
|
||||
revertFiles: inner.revertFiles?.bind(inner),
|
||||
revertBoth: inner.revertBoth?.bind(inner),
|
||||
@@ -487,14 +491,20 @@ function wrapClientProvider(
|
||||
profileModels: ProviderProfileModel[],
|
||||
additionalModels: ProviderProfileModel[],
|
||||
profileModelsAreAdditive: boolean,
|
||||
providerOptions: ProviderOptions | undefined,
|
||||
configuredOptions: ProviderOptions | undefined,
|
||||
): AgentClient {
|
||||
const listImportableSessions = inner.listImportableSessions?.bind(inner);
|
||||
const importSession = inner.importSession?.bind(inner);
|
||||
const listFeatures = inner.listFeatures?.bind(inner);
|
||||
const listControls = inner.listControls?.bind(inner);
|
||||
const archiveNativeSession = inner.archiveNativeSession?.bind(inner);
|
||||
const unarchiveNativeSession = inner.unarchiveNativeSession?.bind(inner);
|
||||
const configuredModelIds = [...profileModels, ...additionalModels].map((model) => model.id);
|
||||
// Converted where it is used, so a malformed configured default fails the call that reads it
|
||||
// rather than the registry that holds every provider.
|
||||
const configuredDefaults = () =>
|
||||
convertLegacyOptions({ provider: inner.provider, options: configuredOptions });
|
||||
const withDefaults = (own: ProviderOptions | undefined) =>
|
||||
mergeProviderOptions(configuredDefaults(), own);
|
||||
|
||||
return {
|
||||
provider,
|
||||
@@ -509,7 +519,7 @@ function wrapClientProvider(
|
||||
{
|
||||
...config,
|
||||
provider: inner.provider,
|
||||
providerOptions: mergeProviderOptions(providerOptions, config.providerOptions),
|
||||
providerOptions: withDefaults(config.providerOptions),
|
||||
},
|
||||
launchContext,
|
||||
{ ...options, configuredModelIds },
|
||||
@@ -526,14 +536,17 @@ function wrapClientProvider(
|
||||
{
|
||||
...overrides,
|
||||
provider: inner.provider,
|
||||
providerOptions: mergeProviderOptions(providerOptions, overrides?.providerOptions),
|
||||
providerOptions: withDefaults(overrides?.providerOptions),
|
||||
},
|
||||
launchContext,
|
||||
{ ...options, configuredModelIds },
|
||||
),
|
||||
),
|
||||
fetchCatalog: async (options, context) => {
|
||||
const catalog = await inner.fetchCatalog({ ...options, providerOptions }, context);
|
||||
const catalog = await inner.fetchCatalog(
|
||||
{ ...options, providerOptions: configuredDefaults() },
|
||||
context,
|
||||
);
|
||||
return {
|
||||
...catalog,
|
||||
models: mergeModels(provider, profileModels, additionalModels, catalog.models, {
|
||||
@@ -548,7 +561,7 @@ function wrapClientProvider(
|
||||
config: {
|
||||
...config,
|
||||
provider: inner.provider,
|
||||
providerOptions: mergeProviderOptions(providerOptions, config.providerOptions),
|
||||
providerOptions: withDefaults(config.providerOptions),
|
||||
},
|
||||
env,
|
||||
signal,
|
||||
@@ -557,16 +570,18 @@ function wrapClientProvider(
|
||||
resolveCreateConfig: inner.resolveCreateConfig?.bind(inner),
|
||||
resolveConfiguredModel: inner.resolveConfiguredModel?.bind(inner),
|
||||
isCreateConfigUnattended: inner.isCreateConfigUnattended?.bind(inner),
|
||||
listFeatures: listFeatures
|
||||
effectiveOptions: (own) => withDefaults(own) ?? {},
|
||||
listControls: listControls
|
||||
? async (config) =>
|
||||
await listFeatures({
|
||||
await listControls({
|
||||
...config,
|
||||
provider: inner.provider,
|
||||
providerOptions: mergeProviderOptions(providerOptions, config.providerOptions),
|
||||
providerOptions: withDefaults(config.providerOptions),
|
||||
})
|
||||
: undefined,
|
||||
listImportableSessions: listImportableSessions
|
||||
? async (options) => await listImportableSessions({ ...options, providerOptions })
|
||||
? async (options) =>
|
||||
await listImportableSessions({ ...options, providerOptions: configuredDefaults() })
|
||||
: undefined,
|
||||
importSession: importSession
|
||||
? async (input, context) => {
|
||||
@@ -575,10 +590,7 @@ function wrapClientProvider(
|
||||
config: {
|
||||
...context.config,
|
||||
provider: inner.provider,
|
||||
providerOptions: mergeProviderOptions(
|
||||
providerOptions,
|
||||
context.config.providerOptions,
|
||||
),
|
||||
providerOptions: withDefaults(context.config.providerOptions),
|
||||
},
|
||||
storedConfig: {
|
||||
...context.storedConfig,
|
||||
|
||||
@@ -1307,7 +1307,7 @@ describe("ProviderSnapshotManager public surface", () => {
|
||||
resolverInputs.push(input);
|
||||
return {
|
||||
modeId: input.parent?.isUnattended ? "child-unattended" : undefined,
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
};
|
||||
},
|
||||
}),
|
||||
@@ -1338,17 +1338,17 @@ describe("ProviderSnapshotManager public surface", () => {
|
||||
cwd: "/tmp/project",
|
||||
provider: "codex",
|
||||
requestedMode: undefined,
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent,
|
||||
unattended: false,
|
||||
});
|
||||
|
||||
expect(resolved).toEqual({ modeId: "child-unattended", featureValues: undefined });
|
||||
expect(resolved).toEqual({ modeId: "child-unattended", providerOptions: undefined });
|
||||
expect(resolverInputs).toEqual([
|
||||
{
|
||||
provider: "codex",
|
||||
requestedMode: undefined,
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent: {
|
||||
provider: "claude",
|
||||
modeId: "parent-unattended",
|
||||
@@ -1386,7 +1386,7 @@ describe("ProviderSnapshotManager public surface", () => {
|
||||
resolverInputs.push(input);
|
||||
return {
|
||||
modeId: input.unattended ? "worker" : undefined,
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
};
|
||||
},
|
||||
}),
|
||||
@@ -1397,17 +1397,17 @@ describe("ProviderSnapshotManager public surface", () => {
|
||||
cwd: "/tmp/project",
|
||||
provider: "codex",
|
||||
requestedMode: undefined,
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
parent: null,
|
||||
unattended: true,
|
||||
});
|
||||
|
||||
expect(resolved).toEqual({ modeId: "worker", featureValues: undefined });
|
||||
expect(resolved).toEqual({ modeId: "worker", providerOptions: undefined });
|
||||
expect(resolverInputs).toEqual([
|
||||
{
|
||||
provider: "codex",
|
||||
requestedMode: undefined,
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
parent: null,
|
||||
unattended: true,
|
||||
availableModes: modes,
|
||||
@@ -1456,7 +1456,7 @@ describe("ProviderSnapshotManager public surface", () => {
|
||||
config: {
|
||||
provider: "opencode",
|
||||
cwd: "/tmp/project",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1464,12 +1464,28 @@ describe("ProviderSnapshotManager public surface", () => {
|
||||
cwd: "/tmp/project",
|
||||
provider: "opencode",
|
||||
requestedMode: "base",
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent,
|
||||
unattended: false,
|
||||
});
|
||||
|
||||
expect(resolved).toEqual({ modeId: "base", featureValues: { auto_accept: true } });
|
||||
expect(resolved).toEqual({ modeId: "base", providerOptions: { auto_accept: true } });
|
||||
|
||||
// A parent whose Auto Accept comes from the provider's config.json default has no own
|
||||
// option; it is classified on its effective options.
|
||||
const inheriting = await manager.resolveCreateConfig({
|
||||
cwd: "/tmp/project",
|
||||
provider: "opencode",
|
||||
requestedMode: "base",
|
||||
providerOptions: undefined,
|
||||
parent: {
|
||||
...parent,
|
||||
config: { provider: "opencode", cwd: "/tmp/project" },
|
||||
effectiveOptions: { auto_accept: true },
|
||||
},
|
||||
unattended: false,
|
||||
});
|
||||
expect(inheriting).toEqual({ modeId: "base", providerOptions: { auto_accept: true } });
|
||||
} finally {
|
||||
manager.destroy();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { normalizeAgentModelCatalog } from "@getpaseo/protocol/agent-types";
|
||||
import { normalizeAgentModelCatalog, type ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { createHash } from "node:crypto";
|
||||
import { EventEmitter } from "node:events";
|
||||
import { homedir } from "node:os";
|
||||
@@ -160,14 +160,14 @@ export interface ResolveProviderCreateConfigOptions {
|
||||
cwd?: string | null;
|
||||
provider: AgentProvider;
|
||||
requestedMode: string | undefined;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: ProviderOptions | undefined;
|
||||
parent: ManagedAgent | null;
|
||||
unattended: boolean;
|
||||
}
|
||||
|
||||
export interface ResolvedProviderCreateConfig {
|
||||
modeId: string | undefined;
|
||||
featureValues: Record<string, unknown> | undefined;
|
||||
providerOptions: ProviderOptions | undefined;
|
||||
}
|
||||
|
||||
interface ResolveDefaultModelOptions {
|
||||
@@ -563,7 +563,7 @@ export class ProviderSnapshotManager {
|
||||
return definition.resolveCreateConfig({
|
||||
provider: input.provider,
|
||||
requestedMode: input.requestedMode,
|
||||
featureValues: input.featureValues,
|
||||
providerOptions: input.providerOptions,
|
||||
parent,
|
||||
unattended: input.unattended || parent?.isUnattended === true,
|
||||
availableModes: entry.modes ?? [],
|
||||
@@ -744,8 +744,13 @@ export class ProviderSnapshotManager {
|
||||
modeId: parent.currentModeId,
|
||||
isUnattended: definition.isCreateConfigUnattended({
|
||||
modeId: parent.currentModeId,
|
||||
config: parent.config,
|
||||
features: parent.features,
|
||||
// Provider defaults from `config.json` apply to the parent too, so classify on the
|
||||
// effective options while the stored overrides stay as they are.
|
||||
config: {
|
||||
...parent.config,
|
||||
providerOptions: parent.effectiveOptions ?? parent.config.providerOptions,
|
||||
},
|
||||
controls: parent.controls,
|
||||
availableModes: parent.availableModes ?? definition.modes ?? [],
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import {
|
||||
AgentSideConnection,
|
||||
@@ -198,7 +198,7 @@ function createSessionWithConfig(
|
||||
provider?: string;
|
||||
modeId?: string | null;
|
||||
model?: string | null;
|
||||
featureValues?: Record<string, unknown>;
|
||||
providerOptions?: Record<string, unknown>;
|
||||
} = {},
|
||||
logger: ReturnType<typeof createTestLogger> = createTestLogger(),
|
||||
): ACPAgentSession {
|
||||
@@ -208,7 +208,7 @@ function createSessionWithConfig(
|
||||
cwd: "/tmp/paseo-acp-test",
|
||||
modeId: config.modeId ?? undefined,
|
||||
model: config.model ?? undefined,
|
||||
featureValues: config.featureValues,
|
||||
providerOptions: config.providerOptions,
|
||||
},
|
||||
{
|
||||
provider: config.provider ?? "claude-acp",
|
||||
@@ -300,19 +300,20 @@ function selectConfigOption(
|
||||
|
||||
function createCopilotSessionWithConfig(
|
||||
modeId?: string | null,
|
||||
featureValues?: Record<string, unknown>,
|
||||
providerOptions?: Record<string, unknown>,
|
||||
defaultCommand: string[] = ["copilot", "--acp"],
|
||||
): ACPAgentSession {
|
||||
return new ACPAgentSession(
|
||||
{
|
||||
provider: "copilot",
|
||||
cwd: "/tmp/paseo-acp-test",
|
||||
modeId: modeId ?? undefined,
|
||||
...(featureValues ? { featureValues } : {}),
|
||||
...(providerOptions ? { providerOptions } : {}),
|
||||
},
|
||||
{
|
||||
provider: "copilot",
|
||||
logger: createTestLogger(),
|
||||
defaultCommand: ["copilot", "--acp"],
|
||||
defaultCommand,
|
||||
defaultModes: COPILOT_MODES,
|
||||
sessionResponseTransformer: transformCopilotSessionResponse,
|
||||
configOptionsTransformer: transformCopilotConfigOptions,
|
||||
@@ -1498,7 +1499,7 @@ describe("ACPAgentSession Zed parity", () => {
|
||||
test("auto-accepts ACP permission requests when the shared feature is enabled", async () => {
|
||||
const session = createSessionWithConfig({
|
||||
provider: "cursor-acp",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
const events: Array<{ type: string }> = [];
|
||||
|
||||
@@ -1530,7 +1531,7 @@ describe("ACPAgentSession Zed parity", () => {
|
||||
test("does not auto-accept ACP chooser requests", async () => {
|
||||
const session = createSessionWithConfig({
|
||||
provider: "kimi-acp",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
|
||||
@@ -1583,11 +1584,8 @@ describe("ACPAgentSession Zed parity", () => {
|
||||
internals.sessionId = "session-1";
|
||||
internals.connection = {};
|
||||
|
||||
await session.setFeature("auto_accept", true);
|
||||
await session.applyOptions({ auto_accept: true });
|
||||
|
||||
expect(session.features).toContainEqual(
|
||||
expect.objectContaining({ type: "toggle", id: "auto_accept", value: true }),
|
||||
);
|
||||
await expect(
|
||||
session.requestPermission({
|
||||
sessionId: "session-1",
|
||||
@@ -1605,7 +1603,7 @@ describe("ACPAgentSession Zed parity", () => {
|
||||
});
|
||||
|
||||
test("surfaces an ACP permission when auto-accept has no allow option", async () => {
|
||||
const session = createSessionWithConfig({ featureValues: { auto_accept: true } });
|
||||
const session = createSessionWithConfig({ providerOptions: { auto_accept: true } });
|
||||
const events: Array<{ type: string; request?: { id: string } }> = [];
|
||||
asInternals<ACPSessionInternals>(session).sessionId = "session-1";
|
||||
session.subscribe((event) => events.push(event as { type: string; request?: { id: string } }));
|
||||
@@ -1765,35 +1763,18 @@ describe("ACPAgentSession Zed parity", () => {
|
||||
const internals = asInternals<ACPSessionInternals>(session);
|
||||
internals.configOptions = [copilotAgentConfigOption("")];
|
||||
|
||||
expect(session.features).toEqual([
|
||||
expect.objectContaining({
|
||||
type: "toggle",
|
||||
id: "auto_accept",
|
||||
value: false,
|
||||
}),
|
||||
expect(session.controls).toEqual([
|
||||
expect.objectContaining({ type: "toggle", key: "auto_accept" }),
|
||||
{
|
||||
type: "select",
|
||||
id: "agent",
|
||||
key: "agent",
|
||||
label: "Agent",
|
||||
description: "Use a Copilot custom agent profile",
|
||||
tooltip: "Select Copilot agent",
|
||||
icon: undefined,
|
||||
value: "",
|
||||
options: [
|
||||
{
|
||||
id: "",
|
||||
label: "Default",
|
||||
description: undefined,
|
||||
isDefault: true,
|
||||
metadata: undefined,
|
||||
},
|
||||
{
|
||||
id: "Probe Agent",
|
||||
label: "Probe Agent",
|
||||
description: "Temporary probe agent",
|
||||
isDefault: false,
|
||||
metadata: undefined,
|
||||
},
|
||||
choices: [
|
||||
{ value: "", label: "Default", description: undefined },
|
||||
{ value: "Probe Agent", label: "Probe Agent", description: "Temporary probe agent" },
|
||||
],
|
||||
},
|
||||
]);
|
||||
@@ -1816,15 +1797,9 @@ describe("ACPAgentSession Zed parity", () => {
|
||||
configId: "agent",
|
||||
value: "Probe Agent",
|
||||
});
|
||||
expect(session.features).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "auto_accept",
|
||||
value: false,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "agent",
|
||||
value: "Probe Agent",
|
||||
}),
|
||||
expect(session.controls).toEqual([
|
||||
expect.objectContaining({ key: "auto_accept" }),
|
||||
expect.objectContaining({ key: "agent" }),
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1838,26 +1813,182 @@ describe("ACPAgentSession Zed parity", () => {
|
||||
connection: { setSessionConfigOption },
|
||||
});
|
||||
|
||||
await session.setFeature("agent", "Probe Agent");
|
||||
await session.applyOptions({ agent: "Probe Agent" });
|
||||
|
||||
expect(setSessionConfigOption).toHaveBeenCalledWith({
|
||||
sessionId: "session-1",
|
||||
configId: "agent",
|
||||
value: "Probe Agent",
|
||||
});
|
||||
expect(session.features).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "auto_accept",
|
||||
value: false,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "agent",
|
||||
value: "Probe Agent",
|
||||
}),
|
||||
expect(session.controls).toEqual([
|
||||
expect.objectContaining({ key: "auto_accept" }),
|
||||
expect.objectContaining({ key: "agent" }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ACPAgentSession options against an ACP agent", () => {
|
||||
const fakeAgentPath = fileURLToPath(new URL("./test-utils/fake-acp-agent.mjs", import.meta.url));
|
||||
const sessions: ACPAgentSession[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(sessions.splice(0).map((session) => session.close()));
|
||||
});
|
||||
|
||||
function thoughtOption(currentValue: string): SessionConfigOption {
|
||||
return {
|
||||
id: "thought",
|
||||
name: "Thinking",
|
||||
category: "thought_level",
|
||||
type: "select",
|
||||
currentValue,
|
||||
options: [
|
||||
{ value: "low", name: "Low" },
|
||||
{ value: "high", name: "High" },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
async function openSession(input: {
|
||||
agent?: string;
|
||||
scenario?: Record<string, unknown>;
|
||||
providerOptions?: Record<string, unknown>;
|
||||
}): Promise<{ session: ACPAgentSession; optionEvents: AgentStreamEvent[] }> {
|
||||
const scenario = {
|
||||
options: [copilotAgentConfigOption(input.agent ?? ""), thoughtOption("low")],
|
||||
...input.scenario,
|
||||
};
|
||||
await mkdir("/tmp/paseo-acp-test", { recursive: true });
|
||||
const session = createCopilotSessionWithConfig(null, input.providerOptions, [
|
||||
process.execPath,
|
||||
fakeAgentPath,
|
||||
JSON.stringify(scenario),
|
||||
]);
|
||||
sessions.push(session);
|
||||
const optionEvents: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => {
|
||||
if (event.type === "options_changed") optionEvents.push(event);
|
||||
});
|
||||
await session.initializeNewSession();
|
||||
return { session, optionEvents };
|
||||
}
|
||||
|
||||
test("a select the agent opened differently from the options is the open patch, not an event", async () => {
|
||||
const { session, optionEvents } = await openSession({
|
||||
providerOptions: { agent: "Probe Agent" },
|
||||
scenario: { answers: { agent: "" } },
|
||||
});
|
||||
|
||||
expect(session.openOptionsPatch).toEqual({ agent: "" });
|
||||
expect(optionEvents).toEqual([]);
|
||||
});
|
||||
|
||||
test("a select the agent opened with that nobody set is in the open patch", async () => {
|
||||
const { session, optionEvents } = await openSession({ agent: "Probe Agent" });
|
||||
|
||||
expect(session.openOptionsPatch).toEqual({ agent: "Probe Agent" });
|
||||
expect(optionEvents).toEqual([]);
|
||||
});
|
||||
|
||||
test("a notification that arrives before the open write is answered is not an event", async () => {
|
||||
const { session, optionEvents } = await openSession({
|
||||
providerOptions: { agent: "Probe Agent" },
|
||||
scenario: { onWrite: "notify-first" },
|
||||
});
|
||||
|
||||
expect(session.openOptionsPatch).toEqual({});
|
||||
expect(optionEvents).toEqual([]);
|
||||
});
|
||||
|
||||
test("applying a patch returns the selects that ended up different and emits nothing", async () => {
|
||||
const { session, optionEvents } = await openSession({ scenario: { answers: { agent: "" } } });
|
||||
|
||||
await expect(session.applyOptions({ agent: "Probe Agent" })).resolves.toEqual({ agent: "" });
|
||||
expect(optionEvents).toEqual([]);
|
||||
});
|
||||
|
||||
test("a notification that arrives before the apply write is answered is not an event", async () => {
|
||||
const { session, optionEvents } = await openSession({ scenario: { onWrite: "notify-first" } });
|
||||
|
||||
await expect(session.applyOptions({ agent: "Probe Agent" })).resolves.toEqual({});
|
||||
expect(optionEvents).toEqual([]);
|
||||
});
|
||||
|
||||
test("a rejected apply reports what the agent moved before refusing, since nothing is stored", async () => {
|
||||
const { session, optionEvents } = await openSession({
|
||||
scenario: { onWrite: "notify-then-reject" },
|
||||
});
|
||||
|
||||
await expect(session.applyOptions({ agent: "Probe Agent" })).rejects.toThrow(/write refused/);
|
||||
expect(optionEvents).toEqual([
|
||||
{ type: "options_changed", provider: "copilot", patch: { agent: "Probe Agent" } },
|
||||
]);
|
||||
});
|
||||
|
||||
test("overlapping applies that both fail still report what the agent moved", async () => {
|
||||
const { session, optionEvents } = await openSession({ scenario: { onWrite: "slow-reject" } });
|
||||
|
||||
const first = session.applyOptions({ agent: "Probe Agent" });
|
||||
const second = session.applyOptions({ agent: null });
|
||||
|
||||
await expect(first).rejects.toThrow(/write refused/);
|
||||
await expect(second).rejects.toThrow(/write refused/);
|
||||
expect(optionEvents).toEqual([
|
||||
{ type: "options_changed", provider: "copilot", patch: { agent: "Probe Agent" } },
|
||||
]);
|
||||
});
|
||||
|
||||
test("a removal writes the select's empty choice and returns nothing when that took", async () => {
|
||||
const { session, optionEvents } = await openSession({ agent: "Probe Agent" });
|
||||
|
||||
await expect(session.applyOptions({ agent: null })).resolves.toEqual({});
|
||||
expect(optionEvents).toEqual([]);
|
||||
});
|
||||
|
||||
test("rejects a live auto_accept the creation schema would reject, and writes nothing", async () => {
|
||||
const { session, optionEvents } = await openSession({
|
||||
scenario: { onWrite: "notify-then-reject" },
|
||||
});
|
||||
|
||||
await expect(
|
||||
session.applyOptions({ auto_accept: "yes", agent: "Probe Agent" }),
|
||||
).rejects.toThrow(/auto_accept/);
|
||||
expect(optionEvents).toEqual([]);
|
||||
});
|
||||
|
||||
test("forwards a select the agent changes on its own", async () => {
|
||||
const { session, optionEvents } = await openSession({
|
||||
scenario: { moves: { thought: { agent: "Probe Agent" } } },
|
||||
});
|
||||
|
||||
await session.setThinkingOption("high");
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(optionEvents).toEqual([
|
||||
{ type: "options_changed", provider: "copilot", patch: { agent: "Probe Agent" } },
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test("a select that appears after startup is reported with its native value", async () => {
|
||||
const { session, optionEvents } = await openSession({
|
||||
scenario: {
|
||||
options: [thoughtOption("low")],
|
||||
adds: { thought: [copilotAgentConfigOption("Probe Agent")] },
|
||||
},
|
||||
});
|
||||
expect(session.openOptionsPatch).toEqual({});
|
||||
|
||||
await session.setThinkingOption("high");
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(optionEvents).toEqual([
|
||||
{ type: "options_changed", provider: "copilot", patch: { agent: "Probe Agent" } },
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("deriveModelDefinitionsFromACP", () => {
|
||||
test("attaches shared thinking options to ACP model state", () => {
|
||||
const result = deriveModelDefinitionsFromACP(
|
||||
@@ -2084,14 +2215,14 @@ describe("ACPAgentClient config features", () => {
|
||||
client.resolveCreateConfig({
|
||||
provider: "generic-acp",
|
||||
requestedMode: undefined,
|
||||
featureValues: { provider_feature: "kept" },
|
||||
providerOptions: { provider_feature: "kept" },
|
||||
parent: null,
|
||||
unattended: true,
|
||||
availableModes: [],
|
||||
}),
|
||||
).toEqual({
|
||||
modeId: undefined,
|
||||
featureValues: { provider_feature: "kept", auto_accept: true },
|
||||
providerOptions: { provider_feature: "kept", auto_accept: true },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2106,12 +2237,12 @@ describe("ACPAgentClient config features", () => {
|
||||
client.resolveCreateConfig({
|
||||
provider: "generic-acp",
|
||||
requestedMode: undefined,
|
||||
featureValues: { auto_accept: false },
|
||||
providerOptions: { auto_accept: false },
|
||||
parent: null,
|
||||
unattended: true,
|
||||
availableModes: [],
|
||||
}),
|
||||
).toEqual({ modeId: undefined, featureValues: { auto_accept: false } });
|
||||
).toEqual({ modeId: undefined, providerOptions: { auto_accept: false } });
|
||||
});
|
||||
|
||||
test("maps an unattended cross-provider parent to ACP Auto Accept", () => {
|
||||
@@ -2125,7 +2256,7 @@ describe("ACPAgentClient config features", () => {
|
||||
client.resolveCreateConfig({
|
||||
provider: "generic-acp",
|
||||
requestedMode: undefined,
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent: {
|
||||
provider: "claude",
|
||||
modeId: "bypassPermissions",
|
||||
@@ -2134,7 +2265,7 @@ describe("ACPAgentClient config features", () => {
|
||||
unattended: false,
|
||||
availableModes: [{ id: "agent", label: "Agent" }],
|
||||
}),
|
||||
).toEqual({ modeId: undefined, featureValues: { auto_accept: true } });
|
||||
).toEqual({ modeId: undefined, providerOptions: { auto_accept: true } });
|
||||
});
|
||||
|
||||
test("treats Auto Accept as an unattended ACP configuration", () => {
|
||||
@@ -2150,7 +2281,7 @@ describe("ACPAgentClient config features", () => {
|
||||
config: {
|
||||
provider: "generic-acp",
|
||||
cwd: "/tmp/acp-features",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
},
|
||||
availableModes: [],
|
||||
}),
|
||||
@@ -2165,22 +2296,17 @@ describe("ACPAgentClient config features", () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "generic-acp",
|
||||
cwd: "/tmp/acp-features",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
}),
|
||||
).resolves.toEqual([
|
||||
expect.objectContaining({
|
||||
type: "toggle",
|
||||
id: "auto_accept",
|
||||
label: "Auto Accept",
|
||||
value: true,
|
||||
}),
|
||||
expect.objectContaining({ type: "toggle", key: "auto_accept", label: "Auto Accept" }),
|
||||
]);
|
||||
});
|
||||
|
||||
test("derives features from configured ACP select options", async () => {
|
||||
test("derives controls from configured ACP select options", async () => {
|
||||
class TestACPAgentClient extends ACPAgentClient {
|
||||
protected override async spawnProcess(): Promise<SpawnedACPProcess> {
|
||||
return {
|
||||
@@ -2206,23 +2332,18 @@ describe("ACPAgentClient config features", () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "copilot",
|
||||
cwd: "/tmp/acp-features",
|
||||
}),
|
||||
).resolves.toEqual([
|
||||
expect.objectContaining({
|
||||
type: "toggle",
|
||||
id: "auto_accept",
|
||||
value: false,
|
||||
}),
|
||||
expect.objectContaining({ type: "toggle", key: "auto_accept" }),
|
||||
expect.objectContaining({
|
||||
type: "select",
|
||||
id: "agent",
|
||||
value: "Probe Agent",
|
||||
options: [
|
||||
expect.objectContaining({ id: "", label: "Default", isDefault: false }),
|
||||
expect.objectContaining({ id: "Probe Agent", label: "Probe Agent", isDefault: true }),
|
||||
key: "agent",
|
||||
choices: [
|
||||
expect.objectContaining({ value: "", label: "Default" }),
|
||||
expect.objectContaining({ value: "Probe Agent", label: "Probe Agent" }),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
@@ -3997,7 +4118,7 @@ describe("ACPAgentClient probe cleanup", () => {
|
||||
terminateProcess: terminator.terminate,
|
||||
});
|
||||
|
||||
await client.listFeatures({ provider: "copilot", cwd: "/tmp/acp-features" });
|
||||
await client.listControls({ provider: "copilot", cwd: "/tmp/acp-features" });
|
||||
|
||||
expect(closeSession).toHaveBeenCalledWith({ sessionId: "feature-probe-session" });
|
||||
expect(terminator.terminated).toContain(child);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { ACPProviderOptionsSchema } from "./acp-options.js";
|
||||
import { applyProviderOptionsPatch } from "../option-controls.js";
|
||||
import { assertChangesAreLive } from "../provider-options.js";
|
||||
import { type ChildProcess, type ChildProcessWithoutNullStreams } from "node:child_process";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
@@ -65,7 +68,7 @@ import {
|
||||
type AgentCapabilityFlags,
|
||||
type AgentClient,
|
||||
type AgentCreateConfigUnattendedInput,
|
||||
type AgentFeature,
|
||||
type AgentOptionControl,
|
||||
type AgentLaunchContext,
|
||||
type AgentMetadata,
|
||||
type AgentMode,
|
||||
@@ -848,10 +851,10 @@ export function deriveModelDefinitionsFromACP(
|
||||
}));
|
||||
}
|
||||
|
||||
export function deriveFeaturesFromACP(
|
||||
export function deriveControlsFromACP(
|
||||
configOptions: SessionConfigOption[] | null | undefined,
|
||||
featureOptions: ACPConfigFeatureOption[],
|
||||
): AgentFeature[] {
|
||||
): AgentOptionControl[] {
|
||||
return featureOptions.flatMap((featureOption) => {
|
||||
const option = findSelectConfigFeatureOption(configOptions, featureOption);
|
||||
if (!option) {
|
||||
@@ -861,42 +864,42 @@ export function deriveFeaturesFromACP(
|
||||
return [
|
||||
{
|
||||
type: "select",
|
||||
id: featureOption.id,
|
||||
key: featureOption.id,
|
||||
label: featureOption.label,
|
||||
description: featureOption.description,
|
||||
tooltip: featureOption.tooltip,
|
||||
icon: featureOption.icon,
|
||||
value: option.currentValue ?? null,
|
||||
options: deriveConfigFeatureSelectOptions(option, featureOption),
|
||||
choices: deriveConfigFeatureSelectOptions(option, featureOption).map((choice) => ({
|
||||
value: choice.id,
|
||||
label: choice.label,
|
||||
description: choice.description,
|
||||
})),
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
function isACPAutoAcceptEnabled(config: AgentSessionConfig): boolean {
|
||||
return config.featureValues?.[ACP_AUTO_ACCEPT_FEATURE_ID] === true;
|
||||
return config.providerOptions?.[ACP_AUTO_ACCEPT_FEATURE_ID] === true;
|
||||
}
|
||||
|
||||
function buildACPAutoAcceptFeature(config: AgentSessionConfig): AgentFeature {
|
||||
return {
|
||||
type: "toggle",
|
||||
id: ACP_AUTO_ACCEPT_FEATURE_ID,
|
||||
label: "Auto Accept",
|
||||
description: "Automatically approves ACP permission prompts.",
|
||||
tooltip: "Auto accept permission prompts",
|
||||
icon: "shield-check",
|
||||
value: isACPAutoAcceptEnabled(config),
|
||||
};
|
||||
}
|
||||
const ACP_AUTO_ACCEPT_CONTROL: AgentOptionControl = {
|
||||
type: "toggle",
|
||||
key: ACP_AUTO_ACCEPT_FEATURE_ID,
|
||||
label: "Auto Accept",
|
||||
description: "Automatically approves ACP permission prompts.",
|
||||
tooltip: "Auto accept permission prompts",
|
||||
icon: "shield-check",
|
||||
};
|
||||
|
||||
function resolveACPCreateConfig(
|
||||
input: ResolveAgentCreateConfigInput,
|
||||
): ResolveAgentCreateConfigResult {
|
||||
const isUnattendedCreate = input.unattended || input.parent?.isUnattended === true;
|
||||
const featureValues =
|
||||
isUnattendedCreate && input.featureValues?.[ACP_AUTO_ACCEPT_FEATURE_ID] === undefined
|
||||
? { ...input.featureValues, [ACP_AUTO_ACCEPT_FEATURE_ID]: true }
|
||||
: input.featureValues;
|
||||
const providerOptions =
|
||||
isUnattendedCreate && input.providerOptions?.[ACP_AUTO_ACCEPT_FEATURE_ID] === undefined
|
||||
? { ...input.providerOptions, [ACP_AUTO_ACCEPT_FEATURE_ID]: true }
|
||||
: input.providerOptions;
|
||||
|
||||
if (
|
||||
input.requestedMode === undefined &&
|
||||
@@ -904,22 +907,16 @@ function resolveACPCreateConfig(
|
||||
input.parent !== null &&
|
||||
input.parent.provider !== input.provider
|
||||
) {
|
||||
return { modeId: undefined, featureValues };
|
||||
return { modeId: undefined, providerOptions };
|
||||
}
|
||||
|
||||
return resolveDefaultAgentCreateConfig({ ...input, featureValues });
|
||||
return resolveDefaultAgentCreateConfig({ ...input, providerOptions });
|
||||
}
|
||||
|
||||
function isACPCreateConfigUnattended(input: AgentCreateConfigUnattendedInput): boolean {
|
||||
return (
|
||||
isDefaultAgentCreateConfigUnattended(input) ||
|
||||
input.config.featureValues?.[ACP_AUTO_ACCEPT_FEATURE_ID] === true ||
|
||||
input.features?.some(
|
||||
(feature) =>
|
||||
feature.id === ACP_AUTO_ACCEPT_FEATURE_ID &&
|
||||
feature.type === "toggle" &&
|
||||
feature.value === true,
|
||||
) === true
|
||||
input.config.providerOptions?.[ACP_AUTO_ACCEPT_FEATURE_ID] === true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1198,10 +1195,9 @@ export class ACPAgentClient implements AgentClient {
|
||||
}
|
||||
}
|
||||
|
||||
async listFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
const autoAcceptFeature = buildACPAutoAcceptFeature(config);
|
||||
async listControls(config: AgentSessionConfig): Promise<AgentOptionControl[]> {
|
||||
if (this.configFeatureOptions.length === 0) {
|
||||
return [autoAcceptFeature];
|
||||
return [ACP_AUTO_ACCEPT_CONTROL];
|
||||
}
|
||||
|
||||
this.assertProvider(config);
|
||||
@@ -1217,8 +1213,8 @@ export class ACPAgentClient implements AgentClient {
|
||||
probeSessionId = response.sessionId;
|
||||
const transformed = this.transformSessionResponse(response);
|
||||
return [
|
||||
autoAcceptFeature,
|
||||
...deriveFeaturesFromACP(transformed.configOptions, this.configFeatureOptions),
|
||||
ACP_AUTO_ACCEPT_CONTROL,
|
||||
...deriveControlsFromACP(transformed.configOptions, this.configFeatureOptions),
|
||||
];
|
||||
} finally {
|
||||
await this.closeProbe(probe, probeSessionId);
|
||||
@@ -1761,6 +1757,11 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
private currentTitle: string | null = null;
|
||||
private lastActivityAt: string | null = null;
|
||||
private configOptions: SessionConfigOption[] = [];
|
||||
/** How the opened session differs from the options it was given. */
|
||||
openOptionsPatch: Record<string, unknown> = {};
|
||||
/** Selects the provider moves while Paseo is opening or applying options belong to that result, not to events. */
|
||||
private optionsTransactionDepth = 0;
|
||||
private applying: Promise<unknown> = Promise.resolve();
|
||||
private cachedCommands: AgentSlashCommand[] = [];
|
||||
/** When the last command batch arrived; null while nothing has been published. */
|
||||
private commandsUpdatedAt: number | null = null;
|
||||
@@ -2054,10 +2055,10 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
return this.currentMode;
|
||||
}
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
get controls(): AgentOptionControl[] {
|
||||
return [
|
||||
buildACPAutoAcceptFeature(this.config),
|
||||
...deriveFeaturesFromACP(this.configOptions, this.configFeatureOptions),
|
||||
ACP_AUTO_ACCEPT_CONTROL,
|
||||
...deriveControlsFromACP(this.configOptions, this.configFeatureOptions),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2198,6 +2199,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
}
|
||||
|
||||
const { connection, sessionId } = this;
|
||||
const before = this.featureValues();
|
||||
const response = await this.runACPRequest(() =>
|
||||
connection.setSessionConfigOption({
|
||||
sessionId,
|
||||
@@ -2212,6 +2214,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
requestedValue: modeId,
|
||||
label: "mode",
|
||||
});
|
||||
this.reportFeatureChanges(before);
|
||||
this.availableModes = deriveModesFromACP(this.defaultModes, null, this.configOptions).modes;
|
||||
this.pushEvent({
|
||||
type: "mode_changed",
|
||||
@@ -2323,6 +2326,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
}
|
||||
|
||||
const { connection, sessionId } = this;
|
||||
const before = this.featureValues();
|
||||
const response = await this.runACPRequest(() =>
|
||||
connection.setSessionConfigOption({
|
||||
sessionId,
|
||||
@@ -2337,6 +2341,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
requestedValue: modelId,
|
||||
label: "model",
|
||||
});
|
||||
this.reportFeatureChanges(before);
|
||||
this.pushEvent({
|
||||
type: "model_changed",
|
||||
provider: this.provider,
|
||||
@@ -2374,6 +2379,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
throw new Error(`${this.provider} does not expose ACP thought-level selection`);
|
||||
}
|
||||
const { connection, sessionId } = this;
|
||||
const before = this.featureValues();
|
||||
const response = await this.runACPRequest(() =>
|
||||
connection.setSessionConfigOption({
|
||||
sessionId,
|
||||
@@ -2388,6 +2394,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
requestedValue: thinkingOptionId,
|
||||
label: "thought-level",
|
||||
});
|
||||
this.reportFeatureChanges(before);
|
||||
this.pushEvent({
|
||||
type: "thinking_option_changed",
|
||||
provider: this.provider,
|
||||
@@ -2395,14 +2402,103 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
});
|
||||
}
|
||||
|
||||
async setFeature(featureId: string, value: unknown): Promise<void> {
|
||||
/**
|
||||
* Applies only the options the patch sets; returns the selects that ended up different.
|
||||
* Provider notifications that arrive meanwhile are part of that result. When a write is
|
||||
* rejected, what the provider moved is reported as an event, since nothing is stored.
|
||||
*/
|
||||
/** One apply at a time: each reconciles against the state the one before it left. */
|
||||
applyOptions(options: ProviderOptions): Promise<Record<string, unknown>> {
|
||||
const run = this.applying.then(() => this.applyOptionsNow(options));
|
||||
this.applying = run.catch(() => undefined);
|
||||
return run;
|
||||
}
|
||||
|
||||
private async applyOptionsNow(options: ProviderOptions): Promise<Record<string, unknown>> {
|
||||
assertChangesAreLive({
|
||||
provider: this.config.provider,
|
||||
patch: options,
|
||||
current: this.config.providerOptions,
|
||||
live: [ACP_AUTO_ACCEPT_FEATURE_ID, ...this.configFeatureOptions.map(({ id }) => id)],
|
||||
});
|
||||
ACPProviderOptionsSchema.parse(
|
||||
applyProviderOptionsPatch({ options: this.config.providerOptions, patch: options }),
|
||||
);
|
||||
const before = this.featureValues();
|
||||
const requested: Record<string, unknown> = {};
|
||||
try {
|
||||
await this.inOptionsTransaction(async () => {
|
||||
for (const [id, value] of Object.entries(options)) {
|
||||
const featureOption = this.configFeatureOptions.find((candidate) => candidate.id === id);
|
||||
if (!featureOption) continue;
|
||||
// A removal asks for the select's empty choice; a provider without one rejects it.
|
||||
requested[id] = value ?? "";
|
||||
const option = findSelectConfigFeatureOption(this.configOptions, featureOption);
|
||||
if (!option || requested[id] !== option.currentValue) {
|
||||
await this.setConfigFeature(id, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.reportFeatureChanges(before);
|
||||
throw error;
|
||||
}
|
||||
// Auto Accept is Paseo's own setting, so it changes only once every write has been accepted.
|
||||
if (ACP_AUTO_ACCEPT_FEATURE_ID in options) {
|
||||
this.config.providerOptions = {
|
||||
...this.config.providerOptions,
|
||||
[ACP_AUTO_ACCEPT_FEATURE_ID]: options[ACP_AUTO_ACCEPT_FEATURE_ID] === true,
|
||||
};
|
||||
}
|
||||
return this.featureDifferences({ ...before, ...requested });
|
||||
}
|
||||
|
||||
private async inOptionsTransaction<T>(run: () => Promise<T>): Promise<T> {
|
||||
this.optionsTransactionDepth += 1;
|
||||
try {
|
||||
return await run();
|
||||
} finally {
|
||||
this.optionsTransactionDepth -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/** The selects as the provider reports them now. */
|
||||
private featureValues(): Record<string, string> {
|
||||
const values: Record<string, string> = {};
|
||||
for (const featureOption of this.configFeatureOptions) {
|
||||
const current = findSelectConfigFeatureOption(
|
||||
this.configOptions,
|
||||
featureOption,
|
||||
)?.currentValue;
|
||||
if (current != null) values[featureOption.id] = current;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/** The selects whose value is not what `expected` says, including ones it does not name. */
|
||||
private featureDifferences(expected: Record<string, unknown>): Record<string, string> {
|
||||
return Object.fromEntries(
|
||||
Object.entries(this.featureValues()).filter(([id, value]) => expected[id] !== value),
|
||||
);
|
||||
}
|
||||
|
||||
/** Reports the selects the provider moved on its own, compared with their values `before`. */
|
||||
private reportFeatureChanges(before: Record<string, string>): void {
|
||||
if (this.optionsTransactionDepth > 0) return;
|
||||
const patch = this.featureDifferences(before);
|
||||
if (Object.keys(patch).length > 0) {
|
||||
this.pushEvent({ type: "options_changed", provider: this.provider, patch });
|
||||
}
|
||||
}
|
||||
|
||||
private async setConfigFeature(featureId: string, value: unknown): Promise<void> {
|
||||
if (!this.connection || !this.sessionId) {
|
||||
throw new Error("ACP session not initialized");
|
||||
}
|
||||
|
||||
if (featureId === ACP_AUTO_ACCEPT_FEATURE_ID) {
|
||||
this.config.featureValues = {
|
||||
...this.config.featureValues,
|
||||
this.config.providerOptions = {
|
||||
...this.config.providerOptions,
|
||||
[ACP_AUTO_ACCEPT_FEATURE_ID]: value === true,
|
||||
};
|
||||
return;
|
||||
@@ -2434,14 +2530,13 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
value: requestedValue,
|
||||
}),
|
||||
);
|
||||
const currentValue = this.applyConfigOptionResponse({
|
||||
this.applyConfigOptionResponse({
|
||||
response,
|
||||
configId: option.id,
|
||||
category: featureOption.category,
|
||||
requestedValue,
|
||||
label: featureOption.label,
|
||||
});
|
||||
this.config.featureValues = { ...this.config.featureValues, [featureId]: currentValue };
|
||||
}
|
||||
|
||||
private applyConfigOptionResponse({
|
||||
@@ -2986,7 +3081,11 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
return this.modeIdTransformer ? this.modeIdTransformer(modeId) : modeId;
|
||||
}
|
||||
|
||||
private async applyConfiguredOverrides(): Promise<void> {
|
||||
private applyConfiguredOverrides(): Promise<void> {
|
||||
return this.inOptionsTransaction(() => this.writeConfiguredOverrides());
|
||||
}
|
||||
|
||||
private async writeConfiguredOverrides(): Promise<void> {
|
||||
const configuredModeId = this.config.modeId;
|
||||
if (configuredModeId && configuredModeId !== this.currentMode) {
|
||||
const selection = resolveACPModeSelection({
|
||||
@@ -3018,13 +3117,13 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
if (this.config.thinkingOptionId && this.config.thinkingOptionId !== this.thinkingOptionId) {
|
||||
await this.setThinkingOption(this.config.thinkingOptionId);
|
||||
}
|
||||
const configuredFeatureValues = this.config.featureValues ?? {};
|
||||
const configuredFeatureValues = this.config.providerOptions ?? {};
|
||||
for (const featureOption of this.configFeatureOptions) {
|
||||
if (!Object.prototype.hasOwnProperty.call(configuredFeatureValues, featureOption.id)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await this.setFeature(featureOption.id, configuredFeatureValues[featureOption.id]);
|
||||
await this.setConfigFeature(featureOption.id, configuredFeatureValues[featureOption.id]);
|
||||
} catch (error) {
|
||||
if (!this.isStaleFeatureValueError(error, featureOption.id, switchedModel)) {
|
||||
throw error;
|
||||
@@ -3035,6 +3134,9 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
);
|
||||
}
|
||||
}
|
||||
// The options are the state, so every select the session opened with is reported, including
|
||||
// ones nobody set (a native default is stored like any other value).
|
||||
this.openOptionsPatch = this.featureDifferences(configuredFeatureValues);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3248,6 +3350,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
}
|
||||
|
||||
private handleConfigOptionUpdate(update: ConfigOptionUpdate): AgentStreamEvent[] {
|
||||
const before = this.featureValues();
|
||||
this.configOptions = this.transformConfigOptions(update.configOptions);
|
||||
const modeInfo = deriveModesFromACP(this.defaultModes, null, this.configOptions);
|
||||
const nextMode = modeInfo.currentModeId;
|
||||
@@ -3258,6 +3361,7 @@ export class ACPAgentSession implements AgentSession, ACPClient {
|
||||
this.currentMode = nextMode ?? this.currentMode;
|
||||
this.currentModel = nextModel ?? this.currentModel;
|
||||
this.thinkingOptionId = nextThinkingOptionId ?? this.thinkingOptionId;
|
||||
this.reportFeatureChanges(before);
|
||||
|
||||
const events: AgentStreamEvent[] = [];
|
||||
if (nextMode !== null) {
|
||||
|
||||
@@ -2,6 +2,8 @@ import { z } from "zod";
|
||||
|
||||
export const ACPProviderOptionsSchema = z
|
||||
.object({
|
||||
// Composer control: approves permission prompts without asking.
|
||||
auto_accept: z.boolean().optional(),
|
||||
supportsMcpServers: z.boolean().optional(),
|
||||
clientCapabilities: z
|
||||
.object({
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { createTestLogger } from "../../../../test-utils/test-logger.js";
|
||||
import { collectSessionTurnEvents } from "../test-utils/session-stream-adapter.js";
|
||||
import { ClaudeAgentClient } from "./agent.js";
|
||||
import type { ClaudeQueryFactory } from "./query.js";
|
||||
|
||||
const LIMIT = "You've hit your session limit · resets 5:20pm (Asia/Singapore)";
|
||||
|
||||
interface ScriptedTurn {
|
||||
// An API error reply as Claude Code writes it: a synthetic assistant message with `error`.
|
||||
errorReply?: string;
|
||||
// Assistant text the model wrote before or after it.
|
||||
before?: string;
|
||||
after?: string;
|
||||
isError: boolean;
|
||||
usage?: {
|
||||
inputTokens: number;
|
||||
cachedInputTokens: number;
|
||||
outputTokens: number;
|
||||
totalCostUsd: number;
|
||||
};
|
||||
}
|
||||
|
||||
// A query dependency that speaks Claude Code's stream interface, one scripted turn per prompt.
|
||||
function scriptedQuery(turns: ScriptedTurn[]): ClaudeQueryFactory {
|
||||
return ({ prompt }) => {
|
||||
let index = 0;
|
||||
const assistant = (id: string, text: string, error?: string) => ({
|
||||
type: "assistant",
|
||||
session_id: "error-session",
|
||||
parent_tool_use_id: null,
|
||||
uuid: id,
|
||||
message: {
|
||||
id,
|
||||
role: "assistant",
|
||||
model: error ? "<synthetic>" : "claude-opus-5-5",
|
||||
content: [{ type: "text", text }],
|
||||
stop_reason: "stop_sequence",
|
||||
usage: { input_tokens: 0, output_tokens: 0 },
|
||||
},
|
||||
...(error ? { error } : {}),
|
||||
});
|
||||
const messages = (async function* () {
|
||||
if (typeof prompt === "string") throw new Error("Expected streaming input");
|
||||
for await (const _message of prompt) {
|
||||
const turn = turns[index];
|
||||
index += 1;
|
||||
yield {
|
||||
type: "system",
|
||||
subtype: "init",
|
||||
session_id: "error-session",
|
||||
permissionMode: "default",
|
||||
model: "claude-opus-5-5",
|
||||
};
|
||||
if (turn.before) yield assistant(`before-${index}`, turn.before);
|
||||
if (turn.errorReply) yield assistant(`error-${index}`, turn.errorReply, "rate_limit");
|
||||
if (turn.after) yield assistant(`after-${index}`, turn.after);
|
||||
yield {
|
||||
type: "result",
|
||||
subtype: "success",
|
||||
session_id: "error-session",
|
||||
duration_ms: 1,
|
||||
duration_api_ms: 0,
|
||||
is_error: turn.isError,
|
||||
num_turns: 1,
|
||||
result: turn.isError ? (turn.errorReply ?? "") : (turn.after ?? turn.errorReply ?? ""),
|
||||
stop_reason: "stop_sequence",
|
||||
total_cost_usd: turn.usage?.totalCostUsd ?? 0,
|
||||
usage: {
|
||||
input_tokens: turn.usage?.inputTokens ?? 0,
|
||||
output_tokens: turn.usage?.outputTokens ?? 0,
|
||||
cache_read_input_tokens: turn.usage?.cachedInputTokens ?? 0,
|
||||
},
|
||||
modelUsage: {},
|
||||
permission_denials: [],
|
||||
uuid: `result-${index}`,
|
||||
};
|
||||
}
|
||||
})();
|
||||
return Object.assign(messages, {
|
||||
close: () => {
|
||||
void messages.return();
|
||||
},
|
||||
interrupt: async () => undefined,
|
||||
setModel: async () => undefined,
|
||||
setPermissionMode: async () => undefined,
|
||||
supportedModels: async () => [],
|
||||
supportedCommands: async () => [],
|
||||
}) as ReturnType<ClaudeQueryFactory>;
|
||||
};
|
||||
}
|
||||
|
||||
async function runTurns(turns: ScriptedTurn[]) {
|
||||
const client = new ClaudeAgentClient({
|
||||
logger: createTestLogger(),
|
||||
queryFactory: scriptedQuery(turns),
|
||||
resolveBinary: async () => process.execPath,
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
});
|
||||
try {
|
||||
const results = [];
|
||||
for (const [index] of turns.entries()) {
|
||||
results.push(await collectSessionTurnEvents(session, `turn ${index + 1}`));
|
||||
}
|
||||
return results;
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
}
|
||||
|
||||
function assistantTexts(events: Awaited<ReturnType<typeof runTurns>>[number]): string[] {
|
||||
return events.flatMap((event) =>
|
||||
event.type === "timeline" && event.item.type === "assistant_message" ? [event.item.text] : [],
|
||||
);
|
||||
}
|
||||
|
||||
function terminal(events: Awaited<ReturnType<typeof runTurns>>[number]) {
|
||||
return events.find(
|
||||
(event) =>
|
||||
event.type === "turn_completed" ||
|
||||
event.type === "turn_failed" ||
|
||||
event.type === "turn_canceled",
|
||||
);
|
||||
}
|
||||
|
||||
test("a turn Claude Code ends on an API error fails with the error, shown once", async () => {
|
||||
const [limited, overloaded, next] = await runTurns([
|
||||
{ errorReply: LIMIT, isError: true },
|
||||
{
|
||||
before: "Checking the deploy doc.",
|
||||
errorReply: "API Error: 529 Overloaded",
|
||||
isError: true,
|
||||
},
|
||||
{ after: "Done.", isError: false },
|
||||
]);
|
||||
|
||||
expect(terminal(limited)).toMatchObject({
|
||||
type: "turn_failed",
|
||||
error: LIMIT,
|
||||
});
|
||||
expect(assistantTexts(limited)).toEqual([]);
|
||||
|
||||
expect(terminal(overloaded)).toMatchObject({
|
||||
type: "turn_failed",
|
||||
error: "API Error: 529 Overloaded",
|
||||
});
|
||||
expect(assistantTexts(overloaded)).toEqual(["Checking the deploy doc."]);
|
||||
|
||||
// The session keeps working after a failed turn.
|
||||
expect(terminal(next)).toMatchObject({ type: "turn_completed" });
|
||||
expect(assistantTexts(next)).toEqual(["Done."]);
|
||||
});
|
||||
|
||||
test("a failed turn retains its final token counts and cost", async () => {
|
||||
const usage = {
|
||||
inputTokens: 120,
|
||||
cachedInputTokens: 80,
|
||||
outputTokens: 30,
|
||||
totalCostUsd: 0.012,
|
||||
};
|
||||
const [failed] = await runTurns([
|
||||
{ before: "Checking the deploy doc.", errorReply: LIMIT, isError: true, usage },
|
||||
]);
|
||||
|
||||
expect(failed).toContainEqual(
|
||||
expect.objectContaining({ type: "usage_updated", usage: expect.objectContaining(usage) }),
|
||||
);
|
||||
expect(terminal(failed)).toMatchObject({ type: "turn_failed", error: LIMIT });
|
||||
expect(assistantTexts(failed)).toEqual(["Checking the deploy doc."]);
|
||||
});
|
||||
|
||||
test("an error reply the turn moves past is still shown", async () => {
|
||||
const [recovered, completed] = await runTurns([
|
||||
{
|
||||
errorReply: "API Error: 529 Overloaded",
|
||||
after: "Recovered.",
|
||||
isError: false,
|
||||
},
|
||||
{ errorReply: LIMIT, isError: false },
|
||||
]);
|
||||
|
||||
expect(terminal(recovered)).toMatchObject({ type: "turn_completed" });
|
||||
expect(assistantTexts(recovered)).toEqual(["API Error: 529 Overloaded", "Recovered."]);
|
||||
|
||||
expect(terminal(completed)).toMatchObject({ type: "turn_completed" });
|
||||
expect(assistantTexts(completed)).toEqual([LIMIT]);
|
||||
});
|
||||
@@ -1,4 +1,3 @@
|
||||
import { constants as bufferConstants } from "node:buffer";
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
@@ -237,64 +236,4 @@ describe("importing a renamed Claude session", () => {
|
||||
|
||||
await expect(importSession(sessionId)).rejects.toThrow();
|
||||
});
|
||||
|
||||
test("reads the rename from a transcript too large to hold as one string", async () => {
|
||||
const sessionId = "oversized-transcript";
|
||||
const projectDir = claudeProjectDirSync(SESSION_CWD, { configDir });
|
||||
await fs.mkdir(projectDir, { recursive: true });
|
||||
const transcript = path.join(projectDir, `${sessionId}.jsonl`);
|
||||
// A hole stands in for the long session this used to fail on: the file only
|
||||
// has to be longer than a string can be, and the rename sits at its end.
|
||||
await fs.writeFile(transcript, "");
|
||||
await fs.truncate(transcript, bufferConstants.MAX_STRING_LENGTH + 1);
|
||||
await fs.appendFile(
|
||||
transcript,
|
||||
`\n${[
|
||||
userRecord({ sessionId, content: "Trace the slow query" }),
|
||||
{ type: "custom-title", customTitle: "Slow query hunt", sessionId },
|
||||
]
|
||||
.map((record) => JSON.stringify(record))
|
||||
.join("\n")}\n`,
|
||||
);
|
||||
|
||||
const imported = await importSession(sessionId);
|
||||
|
||||
expect(imported.config.title).toBe("Slow query hunt");
|
||||
});
|
||||
|
||||
test("reads the rename from behind more records than one read covers", async () => {
|
||||
const sessionId = "late-records-rename";
|
||||
await writeSession({
|
||||
sessionId,
|
||||
records: [
|
||||
userRecord({ sessionId, content: "Review this project" }),
|
||||
{ type: "custom-title", customTitle: "Scrollback review", sessionId },
|
||||
// One record longer than a single read, then enough records to leave the
|
||||
// rename several reads back from the end of the file.
|
||||
userRecord({ sessionId, content: "x".repeat(128 * 1024) }),
|
||||
...Array.from({ length: 64 }, (_, index) =>
|
||||
userRecord({ sessionId, content: `${"y".repeat(4 * 1024)} ${index}` }),
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
const imported = await importSession(sessionId);
|
||||
|
||||
expect(imported.config.title).toBe("Scrollback review");
|
||||
});
|
||||
|
||||
test("imports a large record after the last rename without repeatedly copying it", async () => {
|
||||
const sessionId = "large-record-after-rename";
|
||||
await writeSession({
|
||||
sessionId,
|
||||
records: [
|
||||
{ type: "custom-title", customTitle: "Large attachment review", sessionId },
|
||||
userRecord({ sessionId, content: "x".repeat(96 * 1024 * 1024) }),
|
||||
],
|
||||
});
|
||||
|
||||
const imported = await importSession(sessionId);
|
||||
|
||||
expect(imported.config.title).toBe("Large attachment review");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import pino from "pino";
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { ClaudeAgentClient } from "./agent.js";
|
||||
|
||||
describe("Claude runtime info before a turn", () => {
|
||||
const client = new ClaudeAgentClient({ logger: pino({ level: "silent" }) });
|
||||
|
||||
test("reports the explicitly configured model before the first turn", async () => {
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-haiku-5-5",
|
||||
});
|
||||
try {
|
||||
expect(await session.getRuntimeInfo()).toMatchObject({ model: "claude-haiku-5-5" });
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("reports the persisted configured model after rebuilding an idle session", async () => {
|
||||
const session = await client.resumeSession({
|
||||
provider: "claude",
|
||||
sessionId: "runtime-model-before-turn",
|
||||
metadata: { cwd: process.cwd(), model: "claude-haiku-5-5" },
|
||||
});
|
||||
try {
|
||||
expect(await session.getRuntimeInfo()).toMatchObject({
|
||||
sessionId: "runtime-model-before-turn",
|
||||
model: "claude-haiku-5-5",
|
||||
});
|
||||
expect((await session.getRuntimeInfo()).model).toBe("claude-haiku-5-5");
|
||||
expect((await session.getRuntimeInfo()).extra?.runtimeModel).toBeUndefined();
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("leaves the model unknown when Claude will choose its default", async () => {
|
||||
const session = await client.createSession({ provider: "claude", cwd: process.cwd() });
|
||||
try {
|
||||
expect((await session.getRuntimeInfo()).model).toBeNull();
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -18,6 +18,9 @@ import {
|
||||
resolveClaudeCodeVersion,
|
||||
toClaudeSdkMcpConfig,
|
||||
} from "./agent.js";
|
||||
import { AgentManager } from "../../agent-manager.js";
|
||||
import { ensureAgentLoaded } from "../../agent-loading.js";
|
||||
import { AgentStorage } from "../../agent-storage.js";
|
||||
import { createImportDescriptorScheduler } from "./import-descriptor-scheduler.js";
|
||||
import { claudeProjectDirSync } from "./project-dir.js";
|
||||
import { streamSession } from "../test-utils/session-stream-adapter.js";
|
||||
@@ -30,6 +33,8 @@ import type {
|
||||
} from "../../agent-sdk-types.js";
|
||||
import type { AgentAttachment } from "@getpaseo/protocol/messages";
|
||||
import { buildAgentPrompt, renderPromptAttachmentAsText } from "../../prompt-attachments.js";
|
||||
import { applyProviderOptionsPatch } from "../../option-controls.js";
|
||||
import { mergeProviderOptions } from "../../provider-options.js";
|
||||
|
||||
interface TestClaudeSession {
|
||||
translateMessageToEvents(message: SDKMessage): Promise<AgentStreamEvent[]>;
|
||||
@@ -953,39 +958,39 @@ describe("ClaudeAgentSession features", () => {
|
||||
const client = new ClaudeAgentClient({ logger, resolveBinary: async () => "/test/claude/bin" });
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8",
|
||||
}),
|
||||
).resolves.toEqual([expect.objectContaining({ id: "fast_mode", value: false })]);
|
||||
).resolves.toEqual([expect.objectContaining({ key: "fast_mode", type: "toggle" })]);
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8[1m]",
|
||||
}),
|
||||
).resolves.toEqual([expect.objectContaining({ id: "fast_mode", value: false })]);
|
||||
).resolves.toEqual([expect.objectContaining({ key: "fast_mode", type: "toggle" })]);
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8-20260101",
|
||||
}),
|
||||
).resolves.toEqual([expect.objectContaining({ id: "fast_mode", value: false })]);
|
||||
).resolves.toEqual([expect.objectContaining({ key: "fast_mode", type: "toggle" })]);
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-5",
|
||||
}),
|
||||
).resolves.toEqual([expect.objectContaining({ id: "fast_mode", value: false })]);
|
||||
).resolves.toEqual([expect.objectContaining({ key: "fast_mode", type: "toggle" })]);
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "openrouter/anthropic/claude-opus-4-8",
|
||||
@@ -993,7 +998,7 @@ describe("ClaudeAgentSession features", () => {
|
||||
).resolves.toEqual([]);
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-sonnet-5",
|
||||
@@ -1001,7 +1006,7 @@ describe("ClaudeAgentSession features", () => {
|
||||
).resolves.toEqual([]);
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-sonnet-4-6",
|
||||
@@ -1009,6 +1014,25 @@ describe("ClaudeAgentSession features", () => {
|
||||
).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
test("opens with Fast off on a model that has none, so unrelated options still apply", async () => {
|
||||
const { queryFactory } = createQueryMock();
|
||||
const client = new ClaudeAgentClient({
|
||||
logger,
|
||||
queryFactory,
|
||||
resolveBinary: async () => "/test/claude/bin",
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-sonnet-5",
|
||||
providerOptions: { fast_mode: true },
|
||||
});
|
||||
|
||||
expect(session.openOptionsPatch).toEqual({ fast_mode: false });
|
||||
await expect(session.applyOptions?.({ allowedTools: ["Read"] })).resolves.toBeUndefined();
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("passes initial fast mode through Claude flag settings", async () => {
|
||||
const { queryFactory, queryMock } = createQueryMock();
|
||||
const client = new ClaudeAgentClient({
|
||||
@@ -1020,7 +1044,7 @@ describe("ClaudeAgentSession features", () => {
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { fast_mode: true },
|
||||
});
|
||||
|
||||
await expect(
|
||||
@@ -1492,7 +1516,7 @@ describe("ClaudeAgentSession features", () => {
|
||||
ensureQuery(): Promise<unknown>;
|
||||
}
|
||||
).ensureQuery();
|
||||
await session.setFeature?.("fast_mode", true);
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
|
||||
expect(queryFactory).toHaveBeenCalledTimes(1);
|
||||
expect(queryMock.applyFlagSettings).toHaveBeenLastCalledWith({ fastMode: true });
|
||||
@@ -1501,6 +1525,242 @@ describe("ClaudeAgentSession features", () => {
|
||||
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("rejects a change to a launch option while the first query is starting", async () => {
|
||||
const { queryFactory } = createQueryMock();
|
||||
let releaseBinary!: () => void;
|
||||
const binaryLookup = new Promise<void>((resolve) => {
|
||||
releaseBinary = resolve;
|
||||
});
|
||||
let lookupStarted!: () => void;
|
||||
const lookupEntered = new Promise<void>((resolve) => {
|
||||
lookupStarted = resolve;
|
||||
});
|
||||
const client = new ClaudeAgentClient({
|
||||
logger,
|
||||
queryFactory,
|
||||
resolveBinary: async () => {
|
||||
lookupStarted();
|
||||
await binaryLookup;
|
||||
return "/test/claude/bin";
|
||||
},
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8",
|
||||
providerOptions: { disallowedTools: ["Bash"] },
|
||||
});
|
||||
|
||||
const turn = session.startTurn("hello");
|
||||
await lookupEntered;
|
||||
await expect(session.applyOptions?.({ disallowedTools: [] })).rejects.toThrow(
|
||||
/disallowedTools.*cannot change on a running session/,
|
||||
);
|
||||
releaseBinary();
|
||||
await turn;
|
||||
|
||||
expect(queryFactory.mock.calls[0]?.[0].options).toMatchObject({ disallowedTools: ["Bash"] });
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("a patch before the first prompt keeps the restrictions the session opened with", async () => {
|
||||
const { queryFactory } = createQueryMock();
|
||||
const client = new ClaudeAgentClient({
|
||||
logger,
|
||||
queryFactory,
|
||||
resolveBinary: async () => "/test/claude/bin",
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8",
|
||||
providerOptions: {
|
||||
disallowedTools: ["Bash"],
|
||||
sandbox: { enabled: true, failIfUnavailable: true },
|
||||
},
|
||||
});
|
||||
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
await (session as unknown as { ensureQuery(): Promise<unknown> }).ensureQuery();
|
||||
|
||||
expect(queryFactory.mock.calls[0]?.[0].options).toMatchObject({
|
||||
disallowedTools: ["Bash"],
|
||||
sandbox: { enabled: true, failIfUnavailable: true },
|
||||
});
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("an option Claude reads when it starts changes before the query exists and is rejected after", async () => {
|
||||
const { queryFactory } = createQueryMock();
|
||||
const client = new ClaudeAgentClient({
|
||||
logger,
|
||||
queryFactory,
|
||||
resolveBinary: async () => "/test/claude/bin",
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8",
|
||||
providerOptions: { disallowedTools: ["Bash"] },
|
||||
});
|
||||
|
||||
await session.applyOptions?.({ disallowedTools: ["Bash", "Write"] });
|
||||
await (session as unknown as { ensureQuery(): Promise<unknown> }).ensureQuery();
|
||||
expect(queryFactory.mock.calls[0]?.[0].options).toMatchObject({
|
||||
disallowedTools: ["Bash", "Write"],
|
||||
});
|
||||
|
||||
// The query now runs with these; replacing it would end its background work.
|
||||
await expect(session.applyOptions?.({ disallowedTools: [] })).rejects.toThrow(
|
||||
/disallowedTools.*cannot change on a running session/,
|
||||
);
|
||||
// The same value is not a change, and Fast still applies.
|
||||
await expect(
|
||||
session.applyOptions?.({ disallowedTools: ["Bash", "Write"], fast_mode: true }),
|
||||
).resolves.toBeUndefined();
|
||||
expect(queryFactory).toHaveBeenCalledTimes(1);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("switching to a model without Fast turns it off, reports that, and later patches still apply", async () => {
|
||||
const { queryFactory, queryMock } = createQueryMock();
|
||||
const client = new ClaudeAgentClient({
|
||||
logger,
|
||||
queryFactory,
|
||||
resolveBinary: async () => "/test/claude/bin",
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8",
|
||||
providerOptions: { fast_mode: true },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
|
||||
await session.setModel?.("claude-fable-5");
|
||||
|
||||
expect(queryMock.applyFlagSettings).toHaveBeenLastCalledWith({ fastMode: false });
|
||||
const reported = events.filter((event) => event.type === "options_changed");
|
||||
expect(reported).toEqual([
|
||||
{ type: "options_changed", provider: "claude", patch: { fast_mode: false } },
|
||||
]);
|
||||
// With a `config.json` default of `fast_mode: true`, the agent's effective options must
|
||||
// still read Fast as off: a removed key would let the default fill `true` back in.
|
||||
const stored = applyProviderOptionsPatch({
|
||||
options: { fast_mode: true },
|
||||
patch: reported[0].patch,
|
||||
});
|
||||
expect(mergeProviderOptions({ fast_mode: true }, stored)).toEqual({ fast_mode: false });
|
||||
await expect(session.applyOptions?.({ fast_mode: null })).resolves.toBeUndefined();
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("removing fast_mode turns Fast off", async () => {
|
||||
const { queryFactory, queryMock } = createQueryMock();
|
||||
const client = new ClaudeAgentClient({
|
||||
logger,
|
||||
queryFactory,
|
||||
resolveBinary: async () => "/test/claude/bin",
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8",
|
||||
});
|
||||
await (session as unknown as { ensureQuery(): Promise<unknown> }).ensureQuery();
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
|
||||
await session.applyOptions?.({ fast_mode: null });
|
||||
|
||||
expect(queryMock.applyFlagSettings).toHaveBeenLastCalledWith({ fastMode: false });
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("retries a fast mode change the runtime rejected", async () => {
|
||||
const { queryFactory, queryMock } = createQueryMock();
|
||||
const client = new ClaudeAgentClient({
|
||||
logger,
|
||||
queryFactory,
|
||||
resolveBinary: async () => "/test/claude/bin",
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "claude",
|
||||
cwd: process.cwd(),
|
||||
model: "claude-opus-4-8",
|
||||
});
|
||||
await (session as unknown as { ensureQuery(): Promise<unknown> }).ensureQuery();
|
||||
queryMock.applyFlagSettings.mockClear();
|
||||
queryMock.applyFlagSettings.mockRejectedValueOnce(new Error("runtime unavailable"));
|
||||
|
||||
await expect(session.applyOptions?.({ fast_mode: true })).rejects.toThrow(
|
||||
"runtime unavailable",
|
||||
);
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
|
||||
expect(queryMock.applyFlagSettings).toHaveBeenCalledTimes(2);
|
||||
expect(queryMock.applyFlagSettings).toHaveBeenLastCalledWith({ fastMode: true });
|
||||
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("fast mode survives a daemon restart through the stored providerOptions", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "claude-fast-restart-"));
|
||||
const storagePath = path.join(root, "agents");
|
||||
const makeClient = () => {
|
||||
const mock = createQueryMock();
|
||||
const client = new ClaudeAgentClient({
|
||||
logger,
|
||||
queryFactory: mock.queryFactory,
|
||||
resolveBinary: async () => "/test/claude/bin",
|
||||
});
|
||||
return { ...mock, client };
|
||||
};
|
||||
const agentId = "00000000-0000-4000-8000-0000000000f1";
|
||||
const before = makeClient();
|
||||
const storage = new AgentStorage(storagePath, logger);
|
||||
const manager = new AgentManager({
|
||||
clients: { claude: before.client },
|
||||
registry: storage,
|
||||
logger,
|
||||
});
|
||||
try {
|
||||
await manager.createAgent(
|
||||
{ provider: "claude", cwd: root, model: "claude-opus-4-8" },
|
||||
agentId,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
await manager.setAgentOptions(agentId, { fast_mode: true });
|
||||
await manager.closeAgent(agentId);
|
||||
await manager.flush();
|
||||
await storage.flush();
|
||||
|
||||
const after = makeClient();
|
||||
const restartedStorage = new AgentStorage(storagePath, logger);
|
||||
const restarted = new AgentManager({
|
||||
clients: { claude: after.client },
|
||||
registry: restartedStorage,
|
||||
logger,
|
||||
});
|
||||
const agent = await ensureAgentLoaded(agentId, {
|
||||
agentManager: restarted,
|
||||
agentStorage: restartedStorage,
|
||||
logger,
|
||||
});
|
||||
const session = (agent as unknown as { session: { ensureQuery(): Promise<unknown> } | null })
|
||||
.session;
|
||||
await session?.ensureQuery();
|
||||
|
||||
expect(restarted.getAgent(agentId)?.config.providerOptions).toEqual({ fast_mode: true });
|
||||
expect(after.queryFactory.mock.calls[0]?.[0].options.settings).toMatchObject({
|
||||
fastMode: true,
|
||||
});
|
||||
await restarted.closeAgent(agentId);
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeClaudeAskUserQuestionUpdatedInput", () => {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { setImmediate } from "node:timers/promises";
|
||||
import { ClaudeRuntimeSafety } from "./runtime-safety.js";
|
||||
import { validateProviderOptions } from "../../provider-options.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { applyProviderOptionsPatch } from "../../option-controls.js";
|
||||
import { assertChangesAreLive, validateProviderOptions } from "../../provider-options.js";
|
||||
import type { ChildProcess } from "node:child_process";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
@@ -65,7 +67,7 @@ import { foldSubagentObservations, type SubagentObservation } from "./subagents/
|
||||
import { observeReplayWorkflows } from "./subagents/workflow-replay-source.js";
|
||||
import { limitAgentTimelineItemContent } from "../../agent-timeline-content.js";
|
||||
import { readClaudeWorkflowResultFile } from "./subagents/workflow-output.js";
|
||||
import { buildClaudeFeatures, claudeModelSupportsFastMode } from "./feature-definitions.js";
|
||||
import { buildClaudeControls, claudeModelSupportsFastMode } from "./feature-definitions.js";
|
||||
import {
|
||||
buildBinaryDiagnosticRows,
|
||||
buildCommandResolutionDiagnosticRows,
|
||||
@@ -104,7 +106,7 @@ import {
|
||||
type AgentCapabilityFlags,
|
||||
type AgentClient,
|
||||
type AgentCreateSessionOptions,
|
||||
type AgentFeature,
|
||||
type AgentOptionControl,
|
||||
type AgentLaunchContext,
|
||||
type AgentMetadata,
|
||||
type AgentMode,
|
||||
@@ -1752,12 +1754,8 @@ export class ClaudeAgentClient implements AgentClient {
|
||||
});
|
||||
}
|
||||
|
||||
async listFeatures(config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
const claudeConfig = this.assertConfig(config);
|
||||
return buildClaudeFeatures({
|
||||
modelId: claudeConfig.model,
|
||||
fastModeEnabled: claudeConfig.featureValues?.fast_mode === true,
|
||||
});
|
||||
async listControls(config: AgentSessionConfig): Promise<AgentOptionControl[]> {
|
||||
return buildClaudeControls(this.assertConfig(config).model);
|
||||
}
|
||||
|
||||
async listImportableSessions(
|
||||
@@ -2380,6 +2378,8 @@ class ClaudeAgentSession implements AgentSession {
|
||||
private compactionMarkerOpen = false;
|
||||
private queryPumpPromise: Promise<void> | null = null;
|
||||
private queryRestartNeeded = false;
|
||||
/** True from the moment a query's launch options are copied until the query exists. */
|
||||
private queryStarting = false;
|
||||
private pendingInterruptAbort = false;
|
||||
/**
|
||||
* Whether Claude's main session is inside one of its own turns: set by system/init and by a
|
||||
@@ -2389,12 +2389,6 @@ class ClaudeAgentSession implements AgentSession {
|
||||
private mainTurnInFlight = false;
|
||||
private foregroundHasVisibleActivity = false;
|
||||
private activeTurnHasAssistantText = false;
|
||||
/**
|
||||
* The reply Claude Code writes when a turn stops on an API error ("You've hit your session
|
||||
* limit", "API Error: 529 ..."), held back until the result says whether the turn failed: a
|
||||
* failed turn shows the same text as its error, so showing both would repeat it.
|
||||
*/
|
||||
private withheldErrorReply: AgentTimelineItem[] = [];
|
||||
private readonly contextUsage: ClaudeContextUsageState;
|
||||
private userMessageIds: string[] = [];
|
||||
private readonly emittedUserMessageIds = new Set<string>();
|
||||
@@ -2403,6 +2397,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
private pendingFreshSessionId: string | null = null;
|
||||
private recentStderr = "";
|
||||
private closed = false;
|
||||
readonly openOptionsPatch: Record<string, unknown> = {};
|
||||
|
||||
constructor(config: ClaudeAgentConfig, options: ClaudeAgentSessionOptions) {
|
||||
this.config = config;
|
||||
@@ -2446,17 +2441,21 @@ class ClaudeAgentSession implements AgentSession {
|
||||
if (this.currentMode !== "plan") {
|
||||
this.planResumeMode = this.currentMode;
|
||||
}
|
||||
|
||||
// Fast cannot run on this model, so the session opens with it off. Off rather than removed
|
||||
// keeps a `config.json` default of `fast_mode: true` from filling it back in.
|
||||
if (config.providerOptions.fast_mode === true && !claudeModelSupportsFastMode(config.model)) {
|
||||
this.config.providerOptions = { ...config.providerOptions, fast_mode: false };
|
||||
this.openOptionsPatch = { fast_mode: false };
|
||||
}
|
||||
}
|
||||
|
||||
get id(): string | null {
|
||||
return this.claudeSessionId;
|
||||
}
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
return buildClaudeFeatures({
|
||||
modelId: this.config.model,
|
||||
fastModeEnabled: this.config.featureValues?.fast_mode === true,
|
||||
});
|
||||
get controls(): AgentOptionControl[] {
|
||||
return buildClaudeControls(this.config.model);
|
||||
}
|
||||
|
||||
async getRuntimeInfo(): Promise<AgentRuntimeInfo> {
|
||||
@@ -2466,7 +2465,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
const info: AgentRuntimeInfo = {
|
||||
provider: "claude",
|
||||
sessionId: this.claudeSessionId,
|
||||
model: this.lastOptionsModel ?? this.config.model ?? null,
|
||||
model: this.lastOptionsModel,
|
||||
modeId: this.currentMode ?? null,
|
||||
...(this.lastRuntimeModel
|
||||
? {
|
||||
@@ -2537,7 +2536,6 @@ class ClaudeAgentSession implements AgentSession {
|
||||
this.activeForegroundTurnId = turnId;
|
||||
this.foregroundHasVisibleActivity = false;
|
||||
this.activeTurnHasAssistantText = false;
|
||||
this.withheldErrorReply = [];
|
||||
this.contextUsage.beginTurn();
|
||||
this.transitionTurnState("foreground", "foreground turn started");
|
||||
this.clearRecentStderr();
|
||||
@@ -2755,8 +2753,20 @@ class ClaudeAgentSession implements AgentSession {
|
||||
await activeQuery.setModel(normalizedModelId ?? undefined);
|
||||
this.config.model = normalizedModelId ?? undefined;
|
||||
this.reconcileThinkingOptionForModel(normalizedModelId);
|
||||
if (!claudeModelSupportsFastMode(this.config.model) && this.config.featureValues?.fast_mode) {
|
||||
await this.applyFastModeFeature(false, activeQuery);
|
||||
if (this.config.providerOptions.fast_mode) {
|
||||
const supported = claudeModelSupportsFastMode(this.config.model);
|
||||
await activeQuery.applyFlagSettings({ fastMode: supported });
|
||||
if (!supported) {
|
||||
// Fast cannot run on this model. Reporting it off rather than removed keeps a
|
||||
// `config.json` default of `fast_mode: true` from filling it back in.
|
||||
this.config.providerOptions = { ...this.config.providerOptions, fast_mode: false };
|
||||
this.pushEvent({
|
||||
type: "options_changed",
|
||||
provider: "claude",
|
||||
patch: { fast_mode: false },
|
||||
});
|
||||
}
|
||||
this.cachedRuntimeInfo = null;
|
||||
}
|
||||
this.contextUsage.setInitialContextWindowMaxTokens(
|
||||
getClaudeContextWindowMaxTokens(this.config.model),
|
||||
@@ -2808,31 +2818,41 @@ class ClaudeAgentSession implements AgentSession {
|
||||
}
|
||||
}
|
||||
|
||||
async setFeature(featureId: string, value: unknown): Promise<void> {
|
||||
if (featureId !== "fast_mode") {
|
||||
throw new Error(`Unknown Claude feature: ${featureId}`);
|
||||
async applyOptions(options: ProviderOptions): Promise<void> {
|
||||
// Every option but Fast is read when the query is built, and replacing a started query would
|
||||
// end its background work, so once it exists only Fast can change.
|
||||
if (this.query || this.queryStarting) {
|
||||
assertChangesAreLive({
|
||||
provider: "claude",
|
||||
patch: options,
|
||||
current: this.config.providerOptions,
|
||||
live: ["fast_mode"],
|
||||
});
|
||||
}
|
||||
|
||||
const enabled = Boolean(value);
|
||||
if (enabled && !claudeModelSupportsFastMode(this.config.model)) {
|
||||
const providerOptions =
|
||||
validateProviderOptions(
|
||||
"claude",
|
||||
ClaudeProviderOptionsSchema,
|
||||
applyProviderOptionsPatch({ options: this.config.providerOptions, patch: options }),
|
||||
) ?? {};
|
||||
if (providerOptions.fast_mode === true && !claudeModelSupportsFastMode(this.config.model)) {
|
||||
throw new Error(
|
||||
`Claude fast mode is not available for model '${this.config.model ?? "default"}'`,
|
||||
);
|
||||
}
|
||||
|
||||
await this.applyFastModeFeature(enabled);
|
||||
}
|
||||
|
||||
private async applyFastModeFeature(enabled: boolean, query?: Query): Promise<void> {
|
||||
this.config.featureValues = {
|
||||
...this.config.featureValues,
|
||||
fast_mode: enabled,
|
||||
};
|
||||
const activeQuery = query ?? this.query;
|
||||
if (activeQuery) {
|
||||
await activeQuery.applyFlagSettings({ fastMode: enabled });
|
||||
const fastModeChanged =
|
||||
(providerOptions.fast_mode === true) !== (this.config.providerOptions.fast_mode === true);
|
||||
if (fastModeChanged) {
|
||||
await this.query?.applyFlagSettings({ fastMode: providerOptions.fast_mode === true });
|
||||
this.cachedRuntimeInfo = null;
|
||||
}
|
||||
this.cachedRuntimeInfo = null;
|
||||
// Held until the runtime accepts, so a rejected change is retried instead of skipped. Only
|
||||
// this call's keys are applied, over the options as they are now: another patch may have
|
||||
// landed while the runtime was answering.
|
||||
this.config.providerOptions = applyProviderOptionsPatch({
|
||||
options: this.config.providerOptions,
|
||||
patch: options,
|
||||
});
|
||||
}
|
||||
|
||||
getPendingPermissions(): AgentPermissionRequest[] {
|
||||
@@ -3524,7 +3544,15 @@ class ClaudeAgentSession implements AgentSession {
|
||||
this.persistence = null;
|
||||
|
||||
const input = createAsyncMessageInput<SDKUserMessage>();
|
||||
const options = await this.buildOptions(launchMode);
|
||||
// buildOptions copies the launch options before it waits, so from here they are fixed.
|
||||
this.queryStarting = true;
|
||||
let options: ClaudeOptions;
|
||||
try {
|
||||
options = await this.buildOptions(launchMode);
|
||||
} catch (error) {
|
||||
this.queryStarting = false;
|
||||
throw error;
|
||||
}
|
||||
this.logger.debug({ options: summarizeClaudeOptionsForLog(options) }, "claude query");
|
||||
this.input = input;
|
||||
this.runtimeSafety.reset();
|
||||
@@ -3542,6 +3570,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
},
|
||||
},
|
||||
);
|
||||
this.queryStarting = false;
|
||||
const fastMode = this.resolveFastModeSetting();
|
||||
if (fastMode !== null) {
|
||||
await this.query.applyFlagSettings({ fastMode });
|
||||
@@ -3661,10 +3690,9 @@ class ClaudeAgentSession implements AgentSession {
|
||||
private async buildOptions(permissionMode: PermissionMode): Promise<ClaudeOptions> {
|
||||
const { thinking, effort, ultracode } = this.resolveThinkingConfig();
|
||||
const appendedSystemPrompt = this.buildAppendedSystemPrompt();
|
||||
const providerOptions = applyClaudeToolPolicy(
|
||||
this.config.providerOptions,
|
||||
this.config.toolPolicy,
|
||||
);
|
||||
// `fast_mode` is a composer control the provider applies through flag settings.
|
||||
const { fast_mode: _fastMode, ...sdkProviderOptions } = this.config.providerOptions;
|
||||
const providerOptions = applyClaudeToolPolicy(sdkProviderOptions, this.config.toolPolicy);
|
||||
const settingsOptions = await this.buildSettingsOptions(providerOptions, { ultracode });
|
||||
const sdkEnv = this.harnessEnvironment;
|
||||
assertClaudeModeCanRun(permissionMode, sdkEnv);
|
||||
@@ -3783,7 +3811,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
if (!claudeModelSupportsFastMode(this.config.model)) {
|
||||
return null;
|
||||
}
|
||||
return this.config.featureValues?.fast_mode === true;
|
||||
return this.config.providerOptions.fast_mode === true;
|
||||
}
|
||||
|
||||
private normalizeMcpServers(
|
||||
@@ -4426,21 +4454,6 @@ class ClaudeAgentSession implements AgentSession {
|
||||
}) satisfies AgentStreamEvent,
|
||||
);
|
||||
|
||||
if (!readClaudeParentToolUseId(message)) {
|
||||
if (message.type === "assistant" && message.error) {
|
||||
this.withheldErrorReply.push(...assistantTimelineEvents.map((event) => event.item));
|
||||
return messageEvents;
|
||||
}
|
||||
if (
|
||||
message.type === "assistant" ||
|
||||
message.type === "user" ||
|
||||
message.type === "stream_event"
|
||||
) {
|
||||
const released: AgentStreamEvent[] = [];
|
||||
this.releaseWithheldErrorReply(released);
|
||||
return [...released, ...messageEvents, ...assistantTimelineEvents];
|
||||
}
|
||||
}
|
||||
return [...messageEvents, ...assistantTimelineEvents];
|
||||
}
|
||||
|
||||
@@ -4988,23 +5001,6 @@ class ClaudeAgentSession implements AgentSession {
|
||||
events: AgentStreamEvent[],
|
||||
): void {
|
||||
const usage = this.convertUsage(message);
|
||||
// Claude Code reports a turn that stopped on an API error (a usage limit, an overloaded or
|
||||
// rejected request) as `success` with `is_error`, carrying the error text in `result`.
|
||||
if (message.subtype === "success" && message.is_error) {
|
||||
const withheld = this.withheldErrorReply;
|
||||
this.withheldErrorReply = [];
|
||||
const resultText = typeof message.result === "string" ? message.result.trim() : "";
|
||||
const withheldText = withheld
|
||||
.map((item) => (item.type === "assistant_message" ? item.text : ""))
|
||||
.join("\n")
|
||||
.trim();
|
||||
if (usage) events.push({ type: "usage_updated", provider: "claude", usage });
|
||||
events.push(...this.sidechainTracker.finishAll("failed"));
|
||||
events.push(this.buildTurnFailedEvent(resultText || withheldText || "Claude run failed"));
|
||||
return;
|
||||
}
|
||||
const releasedErrorReply = this.withheldErrorReply.length > 0;
|
||||
this.releaseWithheldErrorReply(events);
|
||||
if (message.subtype === "success") {
|
||||
events.push(...this.sidechainTracker.finishAll("completed"));
|
||||
// Built-in slash commands (e.g. /voice, /usage, "Unknown command: …")
|
||||
@@ -5014,12 +5010,7 @@ class ClaudeAgentSession implements AgentSession {
|
||||
// accounting from provider gateways does not duplicate streamed output.
|
||||
const resultText = typeof message.result === "string" ? message.result.trim() : "";
|
||||
const outputTokens = message.usage?.output_tokens;
|
||||
if (
|
||||
resultText.length > 0 &&
|
||||
outputTokens === 0 &&
|
||||
!this.activeTurnHasAssistantText &&
|
||||
!releasedErrorReply
|
||||
) {
|
||||
if (resultText.length > 0 && outputTokens === 0 && !this.activeTurnHasAssistantText) {
|
||||
events.push({
|
||||
type: "timeline",
|
||||
provider: "claude",
|
||||
@@ -5041,14 +5032,6 @@ class ClaudeAgentSession implements AgentSession {
|
||||
events.push(this.buildTurnFailedEvent(errorMessage));
|
||||
}
|
||||
|
||||
private releaseWithheldErrorReply(events: AgentStreamEvent[]): void {
|
||||
if (this.withheldErrorReply.length === 0) return;
|
||||
for (const item of this.withheldErrorReply) {
|
||||
events.push({ type: "timeline", item, provider: "claude" });
|
||||
}
|
||||
this.withheldErrorReply = [];
|
||||
}
|
||||
|
||||
private createClaudeSessionChangedNotice(
|
||||
oldSessionId: string,
|
||||
newSessionId: string,
|
||||
@@ -6905,79 +6888,40 @@ function normalizeClaudeSessionTitle(title: string | null): string | null {
|
||||
}
|
||||
|
||||
const CLAUDE_CUSTOM_TITLE_TYPE = "custom-title";
|
||||
const CLAUDE_CUSTOM_TITLE_NEEDLE = Buffer.from(`"${CLAUDE_CUSTOM_TITLE_TYPE}"`);
|
||||
const CLAUDE_TITLE_SCAN_CHUNK_BYTES = 64 * 1024;
|
||||
|
||||
function readClaudeCustomTitleFromRecord(record: Buffer): string | null {
|
||||
// The needle also matches a prompt that quotes it, so a record still has to
|
||||
// parse as a `custom-title` entry carrying a usable name. Records without the
|
||||
// needle are never decoded, so a long one costs a byte search and nothing more.
|
||||
if (!record.includes(CLAUDE_CUSTOM_TITLE_NEEDLE)) {
|
||||
return null;
|
||||
}
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(record.toString("utf8").trim());
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
const entry = toObjectRecord(parsed);
|
||||
if (!entry || entry.isSidechain || entry.type !== CLAUDE_CUSTOM_TITLE_TYPE) {
|
||||
return null;
|
||||
}
|
||||
return normalizeClaudeSessionTitle(
|
||||
typeof entry.customTitle === "string" ? entry.customTitle : null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The `custom-title` record is re-emitted every time the session is saved, so
|
||||
* the current name is the last usable one in the file. Reading backwards a chunk
|
||||
* at a time finds it without walking the transcript, which matters because
|
||||
* sessions reach tens of megabytes, and never holds the file as one string, so a
|
||||
* transcript past V8's maximum string length still imports.
|
||||
* the current name is the last usable one in the file. Searching backwards finds it without
|
||||
* walking the transcript, which matters because sessions reach tens of
|
||||
* megabytes.
|
||||
*/
|
||||
async function readLastClaudeCustomTitle(filePath: string): Promise<string | null> {
|
||||
const handle = await fsPromises.open(filePath, "r");
|
||||
try {
|
||||
const stats = await handle.stat();
|
||||
if (!stats.isFile()) {
|
||||
// Opening a directory succeeds on Windows even though reading it does not,
|
||||
// so reject the way reading the transcript as a file would.
|
||||
throw Object.assign(
|
||||
new Error(`EISDIR: illegal operation on a directory, read '${filePath}'`),
|
||||
{ code: "EISDIR", path: filePath },
|
||||
function readLastClaudeCustomTitle(content: string): string | null {
|
||||
const needle = `"${CLAUDE_CUSTOM_TITLE_TYPE}"`;
|
||||
let at = content.lastIndexOf(needle);
|
||||
while (at >= 0) {
|
||||
const lineStart = content.lastIndexOf("\n", at) + 1;
|
||||
const lineEnd = content.indexOf("\n", at);
|
||||
const line = lineEnd === -1 ? content.slice(lineStart) : content.slice(lineStart, lineEnd);
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(line.trim());
|
||||
} catch {
|
||||
parsed = undefined;
|
||||
}
|
||||
const entry = toObjectRecord(parsed);
|
||||
if (entry && !entry.isSidechain && entry.type === CLAUDE_CUSTOM_TITLE_TYPE) {
|
||||
const title = normalizeClaudeSessionTitle(
|
||||
typeof entry.customTitle === "string" ? entry.customTitle : null,
|
||||
);
|
||||
}
|
||||
let end = stats.size;
|
||||
// Retain unfinished record pieces in reverse file order. Assemble each
|
||||
// complete record once, so a large tool/image record costs linear work.
|
||||
let pieces: Buffer[] = [];
|
||||
while (end > 0) {
|
||||
const length = Math.min(CLAUDE_TITLE_SCAN_CHUNK_BYTES, end);
|
||||
const chunk = Buffer.alloc(length);
|
||||
await handle.read(chunk, 0, length, end - length);
|
||||
let recordEnd = chunk.length;
|
||||
for (
|
||||
let at = chunk.lastIndexOf(10);
|
||||
at >= 0;
|
||||
at = at === 0 ? -1 : chunk.lastIndexOf(10, at - 1)
|
||||
) {
|
||||
pieces.push(chunk.subarray(at + 1, recordEnd));
|
||||
const record = Buffer.concat(pieces.toReversed());
|
||||
const title = readClaudeCustomTitleFromRecord(record);
|
||||
if (title) return title;
|
||||
pieces = [];
|
||||
recordEnd = at;
|
||||
if (title) {
|
||||
return title;
|
||||
}
|
||||
if (recordEnd > 0) pieces.push(chunk.subarray(0, recordEnd));
|
||||
end -= length;
|
||||
}
|
||||
// The first record in the file has no newline in front of it.
|
||||
return readClaudeCustomTitleFromRecord(Buffer.concat(pieces.toReversed()));
|
||||
} finally {
|
||||
await handle.close();
|
||||
// The needle also matches a prompt that quotes it, and a record can carry no
|
||||
// usable name, so keep looking backwards for one that does.
|
||||
at = at <= 0 ? -1 : content.lastIndexOf(needle, at - 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isErrnoException(error: unknown): error is NodeJS.ErrnoException {
|
||||
@@ -6989,8 +6933,9 @@ async function readClaudeRenamedSessionTitle(input: {
|
||||
sessionId: string;
|
||||
configDir: string;
|
||||
}): Promise<string | null> {
|
||||
let content: string;
|
||||
try {
|
||||
return await readLastClaudeCustomTitle(await claudeTranscriptPath(input));
|
||||
content = await fsPromises.readFile(await claudeTranscriptPath(input), "utf8");
|
||||
} catch (error) {
|
||||
// A session with no transcript on disk has no rename to carry over. Every
|
||||
// other read failure is a real fault and stays explicit.
|
||||
@@ -6999,6 +6944,7 @@ async function readClaudeRenamedSessionTitle(input: {
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return readLastClaudeCustomTitle(content);
|
||||
}
|
||||
|
||||
function normalizeImportablePromptPreview(text: string): string | null {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { AgentFeature, AgentFeatureToggle } from "../../agent-sdk-types.js";
|
||||
import type { AgentOptionControl, AgentOptionToggleControl } from "../../agent-sdk-types.js";
|
||||
import { claudeManifestModelSupportsFastMode } from "./model-manifest.js";
|
||||
|
||||
export const CLAUDE_FAST_MODE_FEATURE: Omit<AgentFeatureToggle, "value"> = {
|
||||
export const CLAUDE_FAST_MODE_CONTROL: AgentOptionToggleControl = {
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
key: "fast_mode",
|
||||
label: "Fast",
|
||||
description: "Lower latency Opus responses at higher token cost",
|
||||
tooltip: "Toggle fast mode",
|
||||
@@ -14,18 +14,6 @@ export function claudeModelSupportsFastMode(modelId: string | null | undefined):
|
||||
return claudeManifestModelSupportsFastMode(modelId);
|
||||
}
|
||||
|
||||
export function buildClaudeFeatures(input: {
|
||||
modelId: string | null | undefined;
|
||||
fastModeEnabled: boolean;
|
||||
}): AgentFeature[] {
|
||||
if (!claudeModelSupportsFastMode(input.modelId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
...CLAUDE_FAST_MODE_FEATURE,
|
||||
value: input.fastModeEnabled,
|
||||
},
|
||||
];
|
||||
export function buildClaudeControls(modelId: string | null | undefined): AgentOptionControl[] {
|
||||
return claudeModelSupportsFastMode(modelId) ? [{ ...CLAUDE_FAST_MODE_CONTROL }] : [];
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ const SandboxFilesystemSchema = z
|
||||
// Claude Agent SDK Options, maintained against @anthropic-ai/claude-agent-sdk 0.3.246.
|
||||
export const ClaudeProviderOptionsSchema = z
|
||||
.object({
|
||||
/** Composer control, not a Claude SDK option: the provider reads it and keeps it out of the SDK options. */
|
||||
fast_mode: z.boolean().optional(),
|
||||
allowedTools: z.array(z.string()).optional(),
|
||||
disallowedTools: z.array(z.string()).optional(),
|
||||
additionalDirectories: z.array(z.string()).optional(),
|
||||
|
||||
+536
-153
@@ -1,7 +1,19 @@
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import pino from "pino";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
|
||||
import type { AgentSession, AgentSessionConfig } from "../agent-sdk-types.js";
|
||||
import { AgentManager } from "../agent-manager.js";
|
||||
import { toAgentPayload } from "../agent-projections.js";
|
||||
import { AgentStorage } from "../agent-storage.js";
|
||||
import { convertLegacyOptions, featuresFromControls } from "../option-controls.js";
|
||||
import type {
|
||||
AgentClient,
|
||||
AgentSession,
|
||||
AgentSessionConfig,
|
||||
AgentStreamEvent,
|
||||
} from "../agent-sdk-types.js";
|
||||
import { CodexAppServerAgentSession } from "./codex-app-server-agent.js";
|
||||
import {
|
||||
createFakeCodexAppServer,
|
||||
@@ -37,23 +49,32 @@ const TEST_SPEED_MODELS = [
|
||||
serviceTiers: [{ id: "priority", name: "Fast", description: "Faster processing" }],
|
||||
}));
|
||||
|
||||
function speedFeature(value: string) {
|
||||
function speedControl() {
|
||||
return {
|
||||
type: "select",
|
||||
id: "service_tier",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
description: "Choose processing speed. Faster tiers increase usage.",
|
||||
tooltip: "Select speed",
|
||||
icon: "zap",
|
||||
desktopTrigger: "icon",
|
||||
value,
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "priority", label: "Fast" },
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
const PLAN_CONTROL = {
|
||||
type: "toggle",
|
||||
key: "plan_mode",
|
||||
label: "Plan",
|
||||
description: "Switch Codex into planning-only collaboration mode",
|
||||
tooltip: "Toggle plan mode",
|
||||
icon: "list-todo",
|
||||
};
|
||||
|
||||
const TEST_COLLABORATION_MODES: CollaborationModeRecord[] = [
|
||||
{
|
||||
name: "Code",
|
||||
@@ -132,7 +153,7 @@ async function createConnectedSession(
|
||||
return harness;
|
||||
}
|
||||
|
||||
describe("Codex app-server provider features", () => {
|
||||
describe("Codex app-server provider controls", () => {
|
||||
test("GPT-6.1 Sol offers catalog speed tiers and sends Ultrafast", async () => {
|
||||
const { session, appServer } = await createConnectedSession(
|
||||
{ model: "gpt-6.1-sol" },
|
||||
@@ -149,19 +170,19 @@ describe("Codex app-server provider features", () => {
|
||||
},
|
||||
);
|
||||
try {
|
||||
expect(session.features).toContainEqual(
|
||||
expect(session.controls).toContainEqual(
|
||||
expect.objectContaining({
|
||||
id: "service_tier",
|
||||
key: "service_tier",
|
||||
type: "select",
|
||||
value: "default",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "priority", label: "Fast" },
|
||||
{ id: "ultrafast", label: "Ultrafast" },
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
{ value: "ultrafast", label: "Ultrafast" },
|
||||
],
|
||||
}),
|
||||
);
|
||||
await session.setFeature?.("service_tier", "ultrafast");
|
||||
await session.applyOptions?.({ service_tier: "ultrafast" });
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
serviceTier: "ultrafast",
|
||||
@@ -186,16 +207,16 @@ describe("Codex app-server provider features", () => {
|
||||
},
|
||||
);
|
||||
try {
|
||||
expect(session.features).toContainEqual(
|
||||
expect(session.controls).toContainEqual(
|
||||
expect.objectContaining({
|
||||
id: "service_tier",
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
{ id: "future-tier", label: "Future speed" },
|
||||
key: "service_tier",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "future-tier", label: "Future speed" },
|
||||
],
|
||||
}),
|
||||
);
|
||||
await session.setFeature?.("service_tier", "future-tier");
|
||||
await session.applyOptions?.({ service_tier: "future-tier" });
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
model: "future-codex-model",
|
||||
@@ -210,7 +231,7 @@ describe("Codex app-server provider features", () => {
|
||||
"restores %s and Normal explicitly overrides an existing thread tier",
|
||||
async (tier) => {
|
||||
const { session, appServer } = await createConnectedSession(
|
||||
{ model: "future-model", featureValues: { service_tier: tier } },
|
||||
{ model: "future-model", providerOptions: { service_tier: tier } },
|
||||
{
|
||||
models: [
|
||||
{
|
||||
@@ -224,11 +245,8 @@ describe("Codex app-server provider features", () => {
|
||||
},
|
||||
);
|
||||
try {
|
||||
expect(session.features).toContainEqual(
|
||||
expect.objectContaining({ id: "service_tier", value: tier }),
|
||||
);
|
||||
await session.getRuntimeInfo();
|
||||
await session.setFeature?.("service_tier", "default");
|
||||
await session.applyOptions?.({ service_tier: "default" });
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
serviceTier: "default",
|
||||
@@ -239,17 +257,40 @@ describe("Codex app-server provider features", () => {
|
||||
},
|
||||
);
|
||||
|
||||
test("rejects unadvertised tiers and non-string values", async () => {
|
||||
const { session } = await createConnectedSession();
|
||||
test.each(["priority", "ultrafast"])("restores %s from providerOptions", async (tier) => {
|
||||
const { session, appServer } = await createConnectedSession(
|
||||
{ model: "future-model", providerOptions: { service_tier: tier } },
|
||||
{
|
||||
models: [
|
||||
{
|
||||
id: "future-model",
|
||||
serviceTiers: [
|
||||
{ id: "priority", name: "Fast", description: "Fast processing" },
|
||||
{ id: "ultrafast", name: "Ultrafast", description: "Ultra processing" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
try {
|
||||
for (const value of ["ultrafast", "bogus", true, null]) {
|
||||
await expect(session.setFeature?.("service_tier", value)).rejects.toThrow(
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({ serviceTier: tier });
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("rejects unadvertised tiers and non-string values", async () => {
|
||||
const { session, appServer } = await createConnectedSession();
|
||||
try {
|
||||
for (const value of ["ultrafast", "bogus"]) {
|
||||
await expect(session.applyOptions?.({ service_tier: value })).rejects.toThrow(
|
||||
"is not available",
|
||||
);
|
||||
}
|
||||
expect(session.features).toContainEqual(
|
||||
expect.objectContaining({ id: "service_tier", value: "default" }),
|
||||
);
|
||||
await expect(session.applyOptions?.({ service_tier: true })).rejects.toThrow();
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({ serviceTier: "default" });
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
@@ -257,7 +298,7 @@ describe("Codex app-server provider features", () => {
|
||||
|
||||
test("switching to a model without the selected tier resets speed", async () => {
|
||||
const { session, appServer } = await createConnectedSession(
|
||||
{ model: "ultra-model", featureValues: { service_tier: "ultrafast" } },
|
||||
{ model: "ultra-model", providerOptions: { service_tier: "ultrafast" } },
|
||||
{
|
||||
models: [
|
||||
{
|
||||
@@ -270,8 +311,14 @@ describe("Codex app-server provider features", () => {
|
||||
);
|
||||
try {
|
||||
await session.setModel("gpt-6.1-sol");
|
||||
expect(session.features).toContainEqual(
|
||||
expect.objectContaining({ id: "service_tier", value: "default" }),
|
||||
expect(session.controls).toContainEqual(
|
||||
expect.objectContaining({
|
||||
key: "service_tier",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
{ value: "priority", label: "Fast" },
|
||||
],
|
||||
}),
|
||||
);
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({ serviceTier: "default" });
|
||||
@@ -280,10 +327,47 @@ describe("Codex app-server provider features", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("maps legacy Fast commands to the catalog's request id", async () => {
|
||||
test("a Fast chosen as `fast` is kept as the catalog's id, so a model with a different Fast id resets it", async () => {
|
||||
const { session, appServer } = await createConnectedSession(
|
||||
{ model: "model-a" },
|
||||
{
|
||||
models: [
|
||||
{
|
||||
id: "model-a",
|
||||
isDefault: true,
|
||||
serviceTiers: [{ id: "priority", name: "Fast", description: "Faster" }],
|
||||
},
|
||||
{
|
||||
id: "model-b",
|
||||
serviceTiers: [{ id: "rapid", name: "Fast", description: "Faster" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
try {
|
||||
await expect(session.applyOptions?.({ service_tier: "fast" })).resolves.toEqual({
|
||||
service_tier: "priority",
|
||||
});
|
||||
|
||||
await session.setModel("model-b");
|
||||
|
||||
// The option the session reports and the tier the turn runs are the same speed.
|
||||
expect(events.filter((event) => event.type === "options_changed")).toEqual([
|
||||
expect.objectContaining({ patch: { service_tier: "default" } }),
|
||||
]);
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({ serviceTier: "default" });
|
||||
} finally {
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("`fast` maps to the catalog's request id", async () => {
|
||||
const { session, appServer } = await createConnectedSession();
|
||||
try {
|
||||
await session.setFeature?.("fast_mode", true);
|
||||
await session.applyOptions?.({ service_tier: "fast" });
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
serviceTier: "priority",
|
||||
@@ -307,13 +391,13 @@ describe("Codex app-server provider features", () => {
|
||||
])("exposes and sends Fast for %s", async (model) => {
|
||||
const { session, appServer } = await createConnectedSession({ model });
|
||||
try {
|
||||
expect(session.features).toContainEqual(
|
||||
expect(session.controls).toContainEqual(
|
||||
expect.objectContaining({
|
||||
id: "service_tier",
|
||||
value: "default",
|
||||
key: "service_tier",
|
||||
defaultValue: "default",
|
||||
}),
|
||||
);
|
||||
await session.setFeature?.("service_tier", "priority");
|
||||
await session.applyOptions?.({ service_tier: "priority" });
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
model,
|
||||
@@ -338,12 +422,13 @@ describe("Codex app-server provider features", () => {
|
||||
])("does not expose or restore Fast for %s", async (model) => {
|
||||
const { session, appServer } = await createConnectedSession({
|
||||
model,
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { service_tier: "fast" },
|
||||
});
|
||||
const fresh = await createConnectedSession({ model });
|
||||
try {
|
||||
expect(session.features.map((feature) => feature.id)).toEqual(["plan_mode"]);
|
||||
await expect(session.setFeature?.("fast_mode", true)).rejects.toThrow(
|
||||
`Codex fast mode is not available for model '${model}'`,
|
||||
expect(session.controls.map((control) => control.key)).toEqual(["plan_mode"]);
|
||||
await expect(fresh.session.applyOptions?.({ service_tier: "fast" })).rejects.toThrow(
|
||||
`Codex speed 'fast' is not available for model '${model}'`,
|
||||
);
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
@@ -351,21 +436,16 @@ describe("Codex app-server provider features", () => {
|
||||
});
|
||||
} finally {
|
||||
await session.close();
|
||||
await fresh.session.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("restores Fast on Astra and preserves it when switching supported models", async () => {
|
||||
const { session, appServer } = await createConnectedSession({
|
||||
model: "gpt-6-astra",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { service_tier: "fast" },
|
||||
});
|
||||
try {
|
||||
expect(session.features).toContainEqual(
|
||||
expect.objectContaining({
|
||||
id: "service_tier",
|
||||
value: "priority",
|
||||
}),
|
||||
);
|
||||
await session.setModel("gpt-5.6-sol");
|
||||
await session.setModel("gpt-6-astra");
|
||||
await session.startTurn("hello");
|
||||
@@ -378,72 +458,33 @@ describe("Codex app-server provider features", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("features returns speed selector and plan toggle when supported", async () => {
|
||||
const { session } = await createConnectedSession();
|
||||
test("controls return the speed selector and plan toggle when supported", async () => {
|
||||
const { session, appServer } = await createConnectedSession();
|
||||
|
||||
expect(session.features).toEqual([
|
||||
speedFeature("default"),
|
||||
{
|
||||
type: "toggle",
|
||||
id: "plan_mode",
|
||||
label: "Plan",
|
||||
description: "Switch Codex into planning-only collaboration mode",
|
||||
tooltip: "Toggle plan mode",
|
||||
icon: "list-todo",
|
||||
value: false,
|
||||
},
|
||||
]);
|
||||
expect(session.controls).toEqual([speedControl(), PLAN_CONTROL]);
|
||||
|
||||
await session.setFeature?.("service_tier", "priority");
|
||||
await session.setFeature?.("plan_mode", true);
|
||||
await session.applyOptions?.({ service_tier: "priority", plan_mode: true });
|
||||
await session.startTurn("hello");
|
||||
|
||||
expect(session.features).toEqual([
|
||||
speedFeature("priority"),
|
||||
{
|
||||
type: "toggle",
|
||||
id: "plan_mode",
|
||||
label: "Plan",
|
||||
description: "Switch Codex into planning-only collaboration mode",
|
||||
tooltip: "Toggle plan mode",
|
||||
icon: "list-todo",
|
||||
value: true,
|
||||
},
|
||||
]);
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
serviceTier: "priority",
|
||||
collaborationMode: expect.objectContaining({ mode: "plan" }),
|
||||
});
|
||||
});
|
||||
|
||||
test("features returns only plan toggle when model does not support fast mode", async () => {
|
||||
test("controls return only the plan toggle when model does not support fast mode", async () => {
|
||||
const { session } = await createConnectedSession({ model: "gpt-3.5-turbo" });
|
||||
|
||||
expect(session.features).toEqual([
|
||||
{
|
||||
type: "toggle",
|
||||
id: "plan_mode",
|
||||
label: "Plan",
|
||||
description: "Switch Codex into planning-only collaboration mode",
|
||||
tooltip: "Toggle plan mode",
|
||||
icon: "list-todo",
|
||||
value: false,
|
||||
},
|
||||
]);
|
||||
expect(session.controls).toEqual([PLAN_CONTROL]);
|
||||
});
|
||||
|
||||
test("constructor ignores restored fast mode when model does not support it", async () => {
|
||||
const { session, appServer } = await createConnectedSession({
|
||||
model: "gpt-3.5-turbo",
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { service_tier: "fast" },
|
||||
});
|
||||
|
||||
expect(session.features).toEqual([
|
||||
{
|
||||
type: "toggle",
|
||||
id: "plan_mode",
|
||||
label: "Plan",
|
||||
description: "Switch Codex into planning-only collaboration mode",
|
||||
tooltip: "Toggle plan mode",
|
||||
icon: "list-todo",
|
||||
value: false,
|
||||
},
|
||||
]);
|
||||
expect(session.controls).toEqual([PLAN_CONTROL]);
|
||||
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
@@ -454,7 +495,7 @@ describe("Codex app-server provider features", () => {
|
||||
test("selecting Fast sends the catalog service tier", async () => {
|
||||
const { session, appServer } = await createConnectedSession();
|
||||
|
||||
await session.setFeature?.("service_tier", "priority");
|
||||
await session.applyOptions?.({ service_tier: "priority" });
|
||||
await session.startTurn("hello");
|
||||
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
@@ -462,12 +503,12 @@ describe("Codex app-server provider features", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("legacy Fast off explicitly selects Normal", async () => {
|
||||
test("selecting Normal after Fast explicitly selects Normal", async () => {
|
||||
const { session, appServer } = await createConnectedSession({
|
||||
featureValues: { fast_mode: true },
|
||||
providerOptions: { service_tier: "fast" },
|
||||
});
|
||||
|
||||
await session.setFeature?.("fast_mode", false);
|
||||
await session.applyOptions?.({ service_tier: "default" });
|
||||
await session.startTurn("hello");
|
||||
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
@@ -475,53 +516,39 @@ describe("Codex app-server provider features", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("setFeature('fast_mode', true) rejects models that do not support fast mode", async () => {
|
||||
test('applyOptions({ service_tier: "fast" }) rejects models that do not support fast mode', async () => {
|
||||
const { session } = await createConnectedSession({ model: "gpt-3.5-turbo" });
|
||||
|
||||
await expect(session.setFeature?.("fast_mode", true)).rejects.toThrow(
|
||||
"Codex fast mode is not available for model 'gpt-3.5-turbo'",
|
||||
await expect(session.applyOptions?.({ service_tier: "fast" })).rejects.toThrow(
|
||||
"Codex speed 'fast' is not available for model 'gpt-3.5-turbo'",
|
||||
);
|
||||
});
|
||||
|
||||
test("setFeature invalidates runtime info", async () => {
|
||||
test("applyOptions invalidates runtime info", async () => {
|
||||
const { session } = await createConnectedSession();
|
||||
|
||||
await expect(session.getRuntimeInfo()).resolves.not.toMatchObject({
|
||||
extra: { collaborationMode: "Plan" },
|
||||
});
|
||||
|
||||
await session.setFeature?.("plan_mode", true);
|
||||
await session.applyOptions?.({ plan_mode: true });
|
||||
|
||||
await expect(session.getRuntimeInfo()).resolves.toMatchObject({
|
||||
extra: { collaborationMode: "Plan" },
|
||||
});
|
||||
});
|
||||
|
||||
test("setFeature throws for unknown feature ids", async () => {
|
||||
const { session } = createSessionHarness();
|
||||
|
||||
await expect(session.setFeature?.("unknown_feature", true)).rejects.toThrow(
|
||||
"Unknown Codex feature: unknown_feature",
|
||||
);
|
||||
});
|
||||
|
||||
test("constructor restores feature flags from config.featureValues", async () => {
|
||||
test("constructor restores composer options from config.providerOptions", async () => {
|
||||
const { session, appServer } = await createConnectedSession({
|
||||
featureValues: { fast_mode: true, plan_mode: true },
|
||||
providerOptions: { service_tier: "fast", plan_mode: true },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
|
||||
expect(session.features).toEqual([
|
||||
speedFeature("priority"),
|
||||
{
|
||||
type: "toggle",
|
||||
id: "plan_mode",
|
||||
label: "Plan",
|
||||
description: "Switch Codex into planning-only collaboration mode",
|
||||
tooltip: "Toggle plan mode",
|
||||
icon: "list-todo",
|
||||
value: true,
|
||||
},
|
||||
]);
|
||||
expect(session.controls).toEqual([speedControl(), PLAN_CONTROL]);
|
||||
// A saved `fast` opens as the model's Fast tier, which the open patch says.
|
||||
expect(session.openOptionsPatch).toEqual({ service_tier: "priority" });
|
||||
expect(events.filter((event) => event.type === "options_changed")).toEqual([]);
|
||||
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
@@ -532,10 +559,36 @@ describe("Codex app-server provider features", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("a patch that sets another option keeps the running sandbox and an explicit speed", async () => {
|
||||
const { session, appServer } = await createConnectedSession({
|
||||
providerOptions: { sandbox_mode: "read-only", service_tier: "default" },
|
||||
});
|
||||
|
||||
await session.applyOptions?.({ plan_mode: true });
|
||||
await session.startTurn("hello");
|
||||
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
serviceTier: "default",
|
||||
sandboxPolicy: expect.objectContaining({ type: "readOnly" }),
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects a live change to the approval policy or sandbox, which the thread fixed when it started", async () => {
|
||||
const { session } = await createConnectedSession({
|
||||
providerOptions: { sandbox_mode: "workspace-write" },
|
||||
});
|
||||
|
||||
await expect(session.applyOptions?.({ sandbox_mode: "read-only" })).rejects.toThrow(
|
||||
/sandbox_mode.*cannot change on a running session/,
|
||||
);
|
||||
// The same value is not a change.
|
||||
await expect(session.applyOptions?.({ sandbox_mode: "workspace-write" })).resolves.toEqual({});
|
||||
});
|
||||
|
||||
test("startTurn includes serviceTier when fast mode is enabled", async () => {
|
||||
const { session, appServer } = await createConnectedSession();
|
||||
|
||||
await session.setFeature?.("service_tier", "priority");
|
||||
await session.applyOptions?.({ service_tier: "priority" });
|
||||
await session.startTurn("hello");
|
||||
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
@@ -543,11 +596,351 @@ describe("Codex app-server provider features", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("opening on a model without the saved tier runs Normal and the open patch says so", async () => {
|
||||
const models = [
|
||||
{ id: "plain", isDefault: true, defaultReasoningEffort: "medium", serviceTiers: [] },
|
||||
];
|
||||
const { session, appServer } = await createConnectedSession(
|
||||
{ model: "plain", providerOptions: { service_tier: "priority" } },
|
||||
{ models },
|
||||
);
|
||||
|
||||
expect(session.openOptionsPatch).toEqual({ service_tier: "default" });
|
||||
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({ serviceTier: "default" });
|
||||
});
|
||||
|
||||
test("a saved service_tier: fast runs as the model's Fast tier and the open patch names that tier", async () => {
|
||||
const { session, appServer } = await createConnectedSession({
|
||||
providerOptions: { service_tier: "fast" },
|
||||
});
|
||||
|
||||
expect(session.openOptionsPatch).toEqual({ service_tier: "priority" });
|
||||
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({ serviceTier: "priority" });
|
||||
});
|
||||
|
||||
test("a live service_tier: fast is returned as the model's Fast tier", async () => {
|
||||
const { session, appServer } = await createConnectedSession();
|
||||
|
||||
await expect(session.applyOptions?.({ service_tier: "fast" })).resolves.toEqual({
|
||||
service_tier: "priority",
|
||||
});
|
||||
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({ serviceTier: "priority" });
|
||||
});
|
||||
|
||||
test("switching to a model without the speed tier says Normal and keeps it so on the way back", async () => {
|
||||
const models = [
|
||||
...TEST_SPEED_MODELS,
|
||||
{ id: "plain", isDefault: false, defaultReasoningEffort: "medium", serviceTiers: [] },
|
||||
];
|
||||
const { session, appServer } = await createConnectedSession(
|
||||
{ model: "gpt-5.4", providerOptions: { service_tier: "priority" } },
|
||||
{ models },
|
||||
);
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
|
||||
await session.setModel?.("plain");
|
||||
await session.setModel?.("gpt-5.4");
|
||||
|
||||
expect(events.filter((event) => event.type === "options_changed")).toEqual([
|
||||
{ type: "options_changed", provider: "codex", patch: { service_tier: "default" } },
|
||||
]);
|
||||
await session.startTurn("hello");
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({ serviceTier: "default" });
|
||||
});
|
||||
|
||||
describe("legacy Fast (fast_mode) saved or requested before service_tier", () => {
|
||||
function createLegacyFastHarness(
|
||||
rawDefaults: Record<string, unknown> = {},
|
||||
providerId = CODEX_PROVIDER,
|
||||
) {
|
||||
// The provider registry converts configured defaults before it merges them.
|
||||
const configDefaults = convertLegacyOptions({
|
||||
provider: CODEX_PROVIDER,
|
||||
options: rawDefaults,
|
||||
});
|
||||
const appServer = createFakeCodexAppServer({
|
||||
"collaborationMode/list": () => ({ data: TEST_COLLABORATION_MODES }),
|
||||
"model/list": () => ({ data: TEST_SPEED_MODELS }),
|
||||
});
|
||||
const logger = createTestLogger();
|
||||
const openSession = async (
|
||||
config: AgentSessionConfig,
|
||||
resumeSessionId: string | null,
|
||||
): Promise<AgentSession> => {
|
||||
const session = new CodexAppServerAgentSession(
|
||||
// The provider registry hands sessions the `config.json` defaults merged into the agent's own options.
|
||||
{
|
||||
...config,
|
||||
provider: CODEX_PROVIDER,
|
||||
providerOptions: { ...configDefaults, ...config.providerOptions },
|
||||
},
|
||||
resumeSessionId ? { sessionId: resumeSessionId } : null,
|
||||
logger,
|
||||
async () => appServer.child,
|
||||
);
|
||||
await session.connect();
|
||||
return session;
|
||||
};
|
||||
const client: AgentClient = {
|
||||
provider: providerId,
|
||||
capabilities: {
|
||||
supportsStreaming: true,
|
||||
supportsSessionPersistence: true,
|
||||
supportsDynamicModes: false,
|
||||
supportsMcpServers: false,
|
||||
supportsReasoningStream: false,
|
||||
supportsToolInvocations: false,
|
||||
},
|
||||
isAvailable: async () => true,
|
||||
fetchCatalog: async () => ({ models: [], modes: [] }),
|
||||
// Stands in for the `config.json` provider defaults the registry wrapper merges in.
|
||||
effectiveOptions: (own) => ({ ...configDefaults, ...own }),
|
||||
createSession: (config) => openSession(config, null),
|
||||
resumeSession: (handle, config) =>
|
||||
openSession(
|
||||
{ ...config, provider: CODEX_PROVIDER } as AgentSessionConfig,
|
||||
handle.sessionId,
|
||||
),
|
||||
};
|
||||
const workdir = mkdtempSync(join(tmpdir(), "codex-legacy-fast-"));
|
||||
const storage = new AgentStorage(join(workdir, "agents"), logger);
|
||||
const manager = new AgentManager({
|
||||
clients: { [providerId]: client },
|
||||
// A custom provider that extends Codex runs on the Codex adapter.
|
||||
providerDefinitions:
|
||||
providerId === CODEX_PROVIDER
|
||||
? {}
|
||||
: { [providerId]: { enabled: true, derivedFromProviderId: CODEX_PROVIDER } },
|
||||
registry: storage,
|
||||
logger,
|
||||
});
|
||||
const turnStarts = () =>
|
||||
appServer
|
||||
.requests()
|
||||
.filter((message) => message.method === "turn/start")
|
||||
.map((message) => message.params);
|
||||
|
||||
async function create(providerOptions?: Record<string, unknown>) {
|
||||
const agent = await manager.createAgent(
|
||||
{
|
||||
provider: providerId,
|
||||
cwd: workdir,
|
||||
model: "gpt-5.4",
|
||||
...(providerOptions ? { providerOptions } : {}),
|
||||
},
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
);
|
||||
return agent.id;
|
||||
}
|
||||
async function resume(providerOptions: Record<string, unknown>) {
|
||||
const agent = await manager.resumeAgentFromPersistence({
|
||||
provider: providerId,
|
||||
sessionId: "thread-1",
|
||||
metadata: { cwd: workdir, model: "gpt-5.4", providerOptions },
|
||||
});
|
||||
return agent.id;
|
||||
}
|
||||
function shownSpeed(agentId: string) {
|
||||
const payload = toAgentPayload(manager.getAgent(agentId)!);
|
||||
const control = payload.controls?.find((candidate) => candidate.key === "service_tier");
|
||||
const choice =
|
||||
control?.type === "select"
|
||||
? control.choices.find((candidate) => candidate.value === payload.options?.service_tier)
|
||||
: undefined;
|
||||
return {
|
||||
options: payload.options,
|
||||
own: manager.getAgent(agentId)?.config.providerOptions,
|
||||
// What a client reading `options` + `controls` selects, and what the legacy `features` show.
|
||||
selected:
|
||||
payload.options?.service_tier === undefined && control?.type === "select"
|
||||
? control.defaultValue
|
||||
: choice?.value,
|
||||
feature: payload.features?.find((feature) => feature.id === "service_tier")?.value,
|
||||
};
|
||||
}
|
||||
async function runTurn(agentId: string, expectedTier: string) {
|
||||
const before = turnStarts().length;
|
||||
await manager.getAgent(agentId)!.session!.startTurn("hello");
|
||||
await vi.waitFor(() => expect(turnStarts()).toHaveLength(before + 1));
|
||||
const turn = turnStarts()[before]!;
|
||||
expect(turn).toMatchObject({ serviceTier: expectedTier });
|
||||
appServer.completeTurn({ threadId: String(turn.threadId) });
|
||||
await vi.waitFor(() => expect(manager.getAgent(agentId)?.lifecycle).toBe("idle"));
|
||||
}
|
||||
return { manager, create, resume, shownSpeed, runTurn };
|
||||
}
|
||||
|
||||
const FAST = { selected: "priority", feature: "priority" };
|
||||
|
||||
test("a saved fast_mode opens as the model's Fast tier and is stored as that tier", async () => {
|
||||
const { manager, create, shownSpeed, runTurn } = createLegacyFastHarness();
|
||||
const agentId = await create({ fast_mode: true });
|
||||
await manager.flush();
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject({
|
||||
options: { service_tier: "priority" },
|
||||
own: { service_tier: "priority" },
|
||||
...FAST,
|
||||
});
|
||||
await runTurn(agentId, "priority");
|
||||
});
|
||||
|
||||
test("is shown as Fast after a stored record is resumed", async () => {
|
||||
const { manager, resume, shownSpeed, runTurn } = createLegacyFastHarness();
|
||||
const agentId = await resume({ fast_mode: true });
|
||||
await manager.flush();
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: { service_tier: "priority" }, ...FAST });
|
||||
await runTurn(agentId, "priority");
|
||||
});
|
||||
|
||||
test("from config.json defaults runs Fast and is shown as Fast", async () => {
|
||||
const { create, shownSpeed, runTurn } = createLegacyFastHarness({ fast_mode: true });
|
||||
const agentId = await create();
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject(FAST);
|
||||
await runTurn(agentId, "priority");
|
||||
});
|
||||
|
||||
test("a saved fast_mode beats a configured service_tier default", async () => {
|
||||
const { manager, resume, shownSpeed, runTurn } = createLegacyFastHarness({
|
||||
service_tier: "default",
|
||||
});
|
||||
const agentId = await resume({ fast_mode: true });
|
||||
await manager.flush();
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: { service_tier: "priority" }, ...FAST });
|
||||
await runTurn(agentId, "priority");
|
||||
});
|
||||
|
||||
test("a provider extending Codex opens a saved fast_mode as Fast", async () => {
|
||||
const { manager, resume, shownSpeed, runTurn } = createLegacyFastHarness({}, "my-codex");
|
||||
const agentId = await resume({ fast_mode: true });
|
||||
await manager.flush();
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: { service_tier: "priority" }, ...FAST });
|
||||
await runTurn(agentId, "priority");
|
||||
});
|
||||
|
||||
test("a provider extending Codex creates with a requested fast_mode and applies a later one", async () => {
|
||||
const { manager, create, shownSpeed, runTurn } = createLegacyFastHarness({}, "my-codex");
|
||||
const agentId = await create({ fast_mode: false });
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: { service_tier: "default" } });
|
||||
|
||||
await manager.setAgentOptions(agentId, { fast_mode: true });
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: { service_tier: "priority" }, ...FAST });
|
||||
await runTurn(agentId, "priority");
|
||||
});
|
||||
|
||||
test("an older client's fast_mode runs Fast at once, and a later service_tier replaces it", async () => {
|
||||
const { manager, create, shownSpeed, runTurn } = createLegacyFastHarness();
|
||||
const agentId = await create();
|
||||
expect(shownSpeed(agentId).selected).toBe("default");
|
||||
|
||||
await manager.setAgentOptions(agentId, { fast_mode: true });
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: { service_tier: "priority" }, ...FAST });
|
||||
await runTurn(agentId, "priority");
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: "default" });
|
||||
expect(shownSpeed(agentId)).toMatchObject({
|
||||
own: { service_tier: "default" },
|
||||
selected: "default",
|
||||
feature: "default",
|
||||
});
|
||||
await runTurn(agentId, "default");
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: "priority" });
|
||||
expect(shownSpeed(agentId)).toMatchObject({ selected: "priority" });
|
||||
await runTurn(agentId, "priority");
|
||||
});
|
||||
|
||||
test("a request carrying both speed keys follows service_tier", async () => {
|
||||
const { manager, create, shownSpeed, runTurn } = createLegacyFastHarness();
|
||||
const agentId = await create({ service_tier: "priority" });
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: "default", fast_mode: true });
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: { service_tier: "default" } });
|
||||
await runTurn(agentId, "default");
|
||||
});
|
||||
|
||||
test.each([
|
||||
[CODEX_PROVIDER, "a requested legacy fast_mode", {}, { fast_mode: true }],
|
||||
["my-codex", "a requested legacy fast_mode", {}, { fast_mode: true }],
|
||||
[CODEX_PROVIDER, "a configured legacy fast_mode", { fast_mode: true }, undefined],
|
||||
[CODEX_PROVIDER, "a configured Fast alias", { service_tier: "fast" }, undefined],
|
||||
])(
|
||||
"draft speed for %s with %s is the one the first turn runs with",
|
||||
async (providerId, _name, configured, requested) => {
|
||||
const drafting = createLegacyFastHarness(configured, providerId);
|
||||
|
||||
const draft = await drafting.manager.listDraftControls({
|
||||
provider: providerId,
|
||||
cwd: tmpdir(),
|
||||
model: "gpt-5.4",
|
||||
...(requested ? { providerOptions: requested } : {}),
|
||||
});
|
||||
const features = featuresFromControls({ controls: draft.controls, options: draft.options });
|
||||
|
||||
expect(draft.options).toEqual({ service_tier: "priority" });
|
||||
expect(draft.controls).toContainEqual(expect.objectContaining({ key: "service_tier" }));
|
||||
expect(features).toContainEqual(
|
||||
expect.objectContaining({ id: "service_tier", value: "priority" }),
|
||||
);
|
||||
// A draft session ends with its app-server; creating runs on a fresh one.
|
||||
const creating = createLegacyFastHarness(configured, providerId);
|
||||
const agentId = await creating.create(requested);
|
||||
await creating.runTurn(agentId, "priority");
|
||||
},
|
||||
);
|
||||
|
||||
test.each([
|
||||
["a string", "false"],
|
||||
["a number", 1],
|
||||
])("a legacy fast_mode that is %s is rejected, not read as Fast", async (_name, value) => {
|
||||
const { manager, create } = createLegacyFastHarness();
|
||||
const agentId = await create({});
|
||||
|
||||
await expect(manager.setAgentOptions(agentId, { fast_mode: value })).rejects.toThrow(
|
||||
/fast_mode must be true, false or null/,
|
||||
);
|
||||
});
|
||||
|
||||
test("an older client turning fast_mode off selects Normal", async () => {
|
||||
const { manager, create, shownSpeed, runTurn } = createLegacyFastHarness();
|
||||
const agentId = await create({ service_tier: "priority" });
|
||||
|
||||
await manager.setAgentOptions(agentId, { fast_mode: false });
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: { service_tier: "default" } });
|
||||
await runTurn(agentId, "default");
|
||||
});
|
||||
|
||||
test("removing the speed returns the agent to Normal", async () => {
|
||||
const { create, manager, shownSpeed } = createLegacyFastHarness();
|
||||
const agentId = await create({ service_tier: "priority" });
|
||||
expect(shownSpeed(agentId)).toMatchObject(FAST);
|
||||
|
||||
await manager.setAgentOptions(agentId, { service_tier: null });
|
||||
|
||||
expect(shownSpeed(agentId)).toMatchObject({ own: undefined, selected: "default" });
|
||||
});
|
||||
});
|
||||
|
||||
test("startTurn logs a sanitized turn/start summary for fast mode observability", async () => {
|
||||
const capture = createCapturedLogger();
|
||||
const prompt = "secret prompt text should not be logged";
|
||||
const { session } = await createConnectedSession(
|
||||
{ featureValues: { fast_mode: true } },
|
||||
{ providerOptions: { service_tier: "fast" } },
|
||||
{ logger: capture.logger },
|
||||
);
|
||||
|
||||
@@ -570,20 +963,10 @@ describe("Codex app-server provider features", () => {
|
||||
test("setModel clears fast mode when switching to an unsupported model", async () => {
|
||||
const { session, appServer } = await createConnectedSession();
|
||||
|
||||
await session.setFeature?.("service_tier", "priority");
|
||||
await session.applyOptions?.({ service_tier: "priority" });
|
||||
await session.setModel("gpt-3.5-turbo");
|
||||
|
||||
expect(session.features).toEqual([
|
||||
{
|
||||
type: "toggle",
|
||||
id: "plan_mode",
|
||||
label: "Plan",
|
||||
description: "Switch Codex into planning-only collaboration mode",
|
||||
tooltip: "Toggle plan mode",
|
||||
icon: "list-todo",
|
||||
value: false,
|
||||
},
|
||||
]);
|
||||
expect(session.controls).toEqual([PLAN_CONTROL]);
|
||||
await session.startTurn("hello");
|
||||
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
@@ -594,7 +977,7 @@ describe("Codex app-server provider features", () => {
|
||||
test("startTurn switches collaboration mode when plan mode is enabled", async () => {
|
||||
const { session, appServer } = await createConnectedSession();
|
||||
|
||||
await session.setFeature?.("plan_mode", true);
|
||||
await session.applyOptions?.({ plan_mode: true });
|
||||
await session.startTurn("hello");
|
||||
|
||||
await expect(appServer.waitForTurnStart()).resolves.toMatchObject({
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ async function withPendingPlan(
|
||||
cwd: workdir,
|
||||
modeId: "auto",
|
||||
model: "gpt-5.4",
|
||||
featureValues: { plan_mode: true },
|
||||
providerOptions: { plan_mode: true },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
@@ -526,7 +526,7 @@ test("idle provider exit preserves a synthetic plan approval across reconnect",
|
||||
cwd: workdir,
|
||||
modeId: "auto",
|
||||
model: "gpt-5.4",
|
||||
featureValues: { plan_mode: true },
|
||||
providerOptions: { plan_mode: true },
|
||||
},
|
||||
undefined,
|
||||
{ workspaceId: undefined },
|
||||
|
||||
@@ -6188,7 +6188,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("emits a synthetic plan approval permission after a successful Codex plan turn", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true, fast_mode: true },
|
||||
providerOptions: { plan_mode: true, service_tier: "fast" },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
@@ -6258,7 +6258,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("does not complete Codex plan timeline cards while plan approval is pending", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true, fast_mode: true },
|
||||
providerOptions: { plan_mode: true, service_tier: "fast" },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
@@ -6304,7 +6304,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("replaces a pending synthetic plan approval when a later plan completes", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true },
|
||||
providerOptions: { plan_mode: true },
|
||||
});
|
||||
|
||||
await asInternals(session).handleNotification("turn/started", {
|
||||
@@ -6337,7 +6337,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("dismisses a pending synthetic plan approval after a new prompt is accepted", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true },
|
||||
providerOptions: { plan_mode: true },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
@@ -6379,7 +6379,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("makes the old plan non-actionable while a new prompt is being prepared", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true },
|
||||
providerOptions: { plan_mode: true },
|
||||
});
|
||||
|
||||
await asInternals(session).handleNotification("turn/started", {
|
||||
@@ -6433,7 +6433,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("does not dismiss a new plan approval emitted while a prompt is being accepted", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true },
|
||||
providerOptions: { plan_mode: true },
|
||||
});
|
||||
|
||||
await asInternals(session).handleNotification("turn/started", {
|
||||
@@ -6483,7 +6483,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("keeps a synthetic plan dismissed when a new prompt is rejected", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true },
|
||||
providerOptions: { plan_mode: true },
|
||||
});
|
||||
|
||||
await asInternals(session).handleNotification("turn/started", {
|
||||
@@ -7107,7 +7107,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("approving a synthetic Codex plan permission disables plan mode, preserves fast mode, and returns follow-up prompt", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true, fast_mode: true },
|
||||
providerOptions: { plan_mode: true, service_tier: "fast" },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
@@ -7138,9 +7138,10 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
expect(asInternals(session).serviceTier).toBe("fast");
|
||||
expect(asInternals(session).planModeEnabled).toBe(false);
|
||||
expect(asInternals(session).config.featureValues).toEqual({
|
||||
plan_mode: false,
|
||||
fast_mode: true,
|
||||
expect(events).toContainEqual({
|
||||
type: "options_changed",
|
||||
provider: "codex",
|
||||
patch: { plan_mode: false },
|
||||
});
|
||||
// The session returns the follow-up prompt instead of calling startTurn directly.
|
||||
// The caller (session/agent-manager) is responsible for sending it through streamAgent.
|
||||
@@ -7161,7 +7162,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("approving a synthetic Codex plan permission keeps fast mode disabled when it started disabled", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true, fast_mode: false },
|
||||
providerOptions: { plan_mode: true, service_tier: "default" },
|
||||
});
|
||||
const events: AgentStreamEvent[] = [];
|
||||
session.subscribe((event) => events.push(event));
|
||||
@@ -7190,11 +7191,12 @@ describe("Codex app-server provider", () => {
|
||||
selectedActionId: "implement",
|
||||
});
|
||||
|
||||
expect(asInternals(session).serviceTier).toBeNull();
|
||||
expect(asInternals(session).serviceTier).toBe("default");
|
||||
expect(asInternals(session).planModeEnabled).toBe(false);
|
||||
expect(asInternals(session).config.featureValues).toEqual({
|
||||
plan_mode: false,
|
||||
fast_mode: false,
|
||||
expect(events).toContainEqual({
|
||||
type: "options_changed",
|
||||
provider: "codex",
|
||||
patch: { plan_mode: false },
|
||||
});
|
||||
expect(result?.followUpPrompt).toEqual(
|
||||
expect.stringContaining("The user approved the plan. Implement it now."),
|
||||
@@ -7203,7 +7205,7 @@ describe("Codex app-server provider", () => {
|
||||
|
||||
test("follow-up implementation turn keeps fast service tier and switches back to code collaboration mode", async () => {
|
||||
const session = createSession({
|
||||
featureValues: { plan_mode: true, fast_mode: true },
|
||||
providerOptions: { plan_mode: true, service_tier: "fast" },
|
||||
});
|
||||
asInternals(session).collaborationModes = [
|
||||
{
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { validateProviderOptions } from "../provider-options.js";
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { applyProviderOptionsPatch } from "../option-controls.js";
|
||||
import { assertChangesAreLive, validateProviderOptions } from "../provider-options.js";
|
||||
import {
|
||||
getAgentStreamEventTurnId,
|
||||
type AgentPermissionAction,
|
||||
type AgentCapabilityFlags,
|
||||
type AgentClient,
|
||||
type AgentCreateSessionOptions,
|
||||
type AgentFeature,
|
||||
type AgentOptionControl,
|
||||
type AgentLaunchContext,
|
||||
type AgentResumeSessionOptions,
|
||||
type AgentMode,
|
||||
@@ -75,7 +77,7 @@ import { createPathEquivalenceMatcher } from "../../../utils/path.js";
|
||||
import { spawnProcess } from "../../../utils/spawn.js";
|
||||
import { extractCodexTerminalSessionId, nonEmptyString } from "./tool-call-mapper-utils.js";
|
||||
import {
|
||||
buildCodexFeatures,
|
||||
buildCodexControls,
|
||||
CodexServiceTierSchema,
|
||||
readCodexServiceTier,
|
||||
type CodexServiceTier,
|
||||
@@ -150,15 +152,6 @@ function isCodexAlreadyUnarchivedError(error: unknown, threadId: string): boolea
|
||||
|
||||
const TURN_START_TIMEOUT_MS = 90 * 1000;
|
||||
const INTERRUPT_TIMEOUT_MS = 2_000;
|
||||
// `turn/interrupt` ends a turn but leaves the shell commands it started running.
|
||||
// Each terminate is bounded by the first constant. A turn start waits for the
|
||||
// interrupted turn's commands to end, at most the interrupt's own bound plus one
|
||||
// terminate's and a margin, so it gives up only when a request outlives its timeout.
|
||||
const INTERRUPTED_TURN_TERMINATE_TIMEOUT_MS = 2_000;
|
||||
const INTERRUPTED_TURN_CLEANUP_WAIT_MS =
|
||||
INTERRUPT_TIMEOUT_MS + INTERRUPTED_TURN_TERMINATE_TIMEOUT_MS + 500;
|
||||
// Turns whose commands are remembered; older turns are forgotten first.
|
||||
const INTERRUPTED_TURN_TRACKED_TURNS = 16;
|
||||
const CODEX_PROVIDER = "codex" as const;
|
||||
// These native provider identities belong to Codex, not to an older custom
|
||||
// Paseo provider. Never include them in a custom provider's legacy import scan.
|
||||
@@ -3438,7 +3431,7 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
private readonly codexHome: string;
|
||||
private currentMode: string;
|
||||
private hasWorkflowModeOverride: boolean;
|
||||
private readonly providerOptions: CodexProviderOptions;
|
||||
private providerOptions: CodexProviderOptions;
|
||||
private resolvedWorkspaceWrite: NonNullable<
|
||||
CodexProviderOptions["sandbox_workspace_write"]
|
||||
> | null = null;
|
||||
@@ -3462,11 +3455,14 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
private threadRollbackAvailable = true;
|
||||
private readonly subscribers = new Set<(event: AgentStreamEvent) => void>();
|
||||
private startupEvents: AgentStreamEvent[] | null = null;
|
||||
/** How the opened session differs from the options it was given; reported at first subscribe. */
|
||||
openOptionsPatch: Record<string, unknown> = {};
|
||||
private nextTurnOrdinal = 0;
|
||||
private activeForegroundTurnId: string | null = null;
|
||||
private activeClientMessageId: string | null = null;
|
||||
private cachedRuntimeInfo: AgentRuntimeInfo | null = null;
|
||||
private serviceTier: string | null = null;
|
||||
/** The tier the options ask for; `serviceTier` is what the current model can honor. */
|
||||
private requestedServiceTier: string | null = null;
|
||||
private speedModels: CodexModel[] = [];
|
||||
private planModeEnabled = false;
|
||||
// History read by rewind or an archived resume, held until streamHistory consumes it.
|
||||
@@ -3485,14 +3481,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
private pendingFileChangeOutputDeltas = new Map<string, string[]>();
|
||||
private pendingAssistantMessageBoundary = false;
|
||||
private terminalCommandByProcessId = new Map<string, string>();
|
||||
// The root thread's still-running command process ids, keyed by the native turn that
|
||||
// started them. Codex's `thread/backgroundTerminals/list` carries no turn, so
|
||||
// `item/started` is the only record of which turn owns a process.
|
||||
private terminalProcessIdsByTurnId = new Map<
|
||||
string,
|
||||
{ processIds: Set<string>; terminatedProcessIds: Set<string>; interruptAccepted: boolean }
|
||||
>();
|
||||
private interruptedTurnCleanup: Promise<void> | null = null;
|
||||
private pendingUnlabeledTerminalInteractions = new Map<
|
||||
string,
|
||||
Array<{ callId: string; stdin: string | null }>
|
||||
@@ -3585,10 +3573,8 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
this.asyncQuestions = new CodexAsyncQuestions(resumeHandle?.metadata?.asyncQuestions);
|
||||
this.codexHome = deps.codexHome ?? resolveCodexHomeDir(process.env);
|
||||
this.config.thinkingOptionId = normalizeCodexThinkingOptionId(this.config.thinkingOptionId);
|
||||
this.serviceTier = readCodexServiceTier(this.config.featureValues);
|
||||
if (this.config.featureValues?.plan_mode) {
|
||||
this.planModeEnabled = true;
|
||||
}
|
||||
this.requestedServiceTier = readCodexServiceTier(this.providerOptions);
|
||||
this.planModeEnabled = this.providerOptions.plan_mode === true;
|
||||
|
||||
if (this.resumeHandle?.sessionId) {
|
||||
this.currentThreadId = this.resumeHandle.sessionId;
|
||||
@@ -3603,11 +3589,9 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
return this.currentThreadId;
|
||||
}
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
return buildCodexFeatures({
|
||||
get controls(): AgentOptionControl[] {
|
||||
return buildCodexControls({
|
||||
serviceTiers: this.currentServiceTiers(),
|
||||
serviceTier: this.serviceTier ?? "default",
|
||||
planModeEnabled: this.planModeEnabled,
|
||||
planModeAvailable: this.hasPlanCollaborationMode(),
|
||||
});
|
||||
}
|
||||
@@ -3667,7 +3651,7 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
|
||||
this.speedModels =
|
||||
CodexModelListResponseSchema.parse(await client.request("model/list", {})).data ?? [];
|
||||
this.reconcileServiceTier();
|
||||
this.normalizeSpeed();
|
||||
await this.loadResolvedWorkspaceWrite();
|
||||
await this.loadCollaborationModes();
|
||||
await this.loadSkills();
|
||||
@@ -3880,24 +3864,34 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
return selectedModel?.serviceTiers ?? [];
|
||||
}
|
||||
|
||||
private reconcileServiceTier(): void {
|
||||
const tiers = this.currentServiceTiers();
|
||||
// COMPAT(codexFastPreference): added in v0.10.0, remove after 2027-03-29 once saved Fast preferences have migrated.
|
||||
if (this.serviceTier === "fast" && !tiers.some((tier) => tier.id === "fast")) {
|
||||
this.serviceTier = tiers.find((tier) => tier.name.toLowerCase() === "fast")?.id ?? null;
|
||||
}
|
||||
if (this.serviceTier !== "default" && !tiers.some((tier) => tier.id === this.serviceTier)) {
|
||||
this.serviceTier = null;
|
||||
}
|
||||
const { fast_mode: _legacyFast, ...values } = this.config.featureValues ?? {};
|
||||
this.config.featureValues = { ...values, service_tier: this.serviceTier ?? "default" };
|
||||
/**
|
||||
* A saved `service_tier: "fast"` runs as the model's Fast tier, and a tier the opening model
|
||||
* lacks runs as Normal; the session says so in `openOptionsPatch`, so the options and the
|
||||
* control agree (as when the model is switched later).
|
||||
*/
|
||||
private normalizeSpeed(): void {
|
||||
const requested = this.requestedServiceTier;
|
||||
const resolved = this.resolveServiceTier(requested);
|
||||
if (requested === resolved) return;
|
||||
const runs = resolved ?? "default";
|
||||
this.providerOptions = { ...this.providerOptions, service_tier: runs };
|
||||
this.requestedServiceTier = runs;
|
||||
this.openOptionsPatch = { service_tier: runs };
|
||||
}
|
||||
|
||||
private applyFeatureValue(featureId: "plan_mode", value: boolean): void {
|
||||
this.config.featureValues = { ...this.config.featureValues, [featureId]: value };
|
||||
this.planModeEnabled = value;
|
||||
this.refreshResolvedCollaborationMode();
|
||||
this.cachedRuntimeInfo = null;
|
||||
private get serviceTier(): string | null {
|
||||
return this.resolveServiceTier(this.requestedServiceTier);
|
||||
}
|
||||
|
||||
private resolveServiceTier(requested: string | null): string | null {
|
||||
// Until the model list arrives there is nothing to check the request against.
|
||||
if (this.speedModels.length === 0 || requested === "default") return requested;
|
||||
const tiers = this.currentServiceTiers();
|
||||
// `fast` names whichever tier the model calls Fast.
|
||||
if (requested === "fast" && !tiers.some((tier) => tier.id === "fast")) {
|
||||
return tiers.find((tier) => tier.name.toLowerCase() === "fast")?.id ?? null;
|
||||
}
|
||||
return tiers.some((tier) => tier.id === requested) ? requested : null;
|
||||
}
|
||||
|
||||
private rememberPlanResult(item: ToolCallTimelineItem): void {
|
||||
@@ -3962,7 +3956,13 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
const planText =
|
||||
typeof params.planText === "string" ? normalizePlanMarkdown(params.planText) : "";
|
||||
|
||||
this.applyFeatureValue("plan_mode", false);
|
||||
this.setPlanMode(false);
|
||||
// The user left plan mode; their options follow so controls and reopened sessions agree.
|
||||
this.emitEvent({
|
||||
type: "options_changed",
|
||||
provider: CODEX_PROVIDER,
|
||||
patch: { plan_mode: false },
|
||||
});
|
||||
|
||||
return buildCodexPlanImplementationPrompt(planText);
|
||||
}
|
||||
@@ -4448,9 +4448,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
hasDeveloperInstructions: turnStart.hasDeveloperInstructions,
|
||||
hasCodexConfig: turnStart.hasCodexConfig,
|
||||
});
|
||||
// The interrupted turn's commands end before this turn begins, so none of them
|
||||
// outlives it into the new turn.
|
||||
await this.waitForInterruptedTurnCleanup();
|
||||
if (pendingStart.cancelRequested) {
|
||||
throw new Error("Codex turn start was interrupted before reaching Codex");
|
||||
}
|
||||
@@ -4665,9 +4662,27 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
|
||||
async setModel(modelId: string | null): Promise<void> {
|
||||
this.config.model = modelId ?? undefined;
|
||||
this.reconcileServiceTier();
|
||||
this.refreshResolvedCollaborationMode();
|
||||
this.cachedRuntimeInfo = null;
|
||||
this.dropUnavailableServiceTier();
|
||||
}
|
||||
|
||||
/**
|
||||
* A speed the new model does not offer turns into Normal and is reported, so choosing a model
|
||||
* that does offer it again does not bring the paid tier back. It is reported as Normal rather
|
||||
* than removed so a configured default cannot fill the old speed back in.
|
||||
*/
|
||||
private dropUnavailableServiceTier(): void {
|
||||
const requested = this.requestedServiceTier;
|
||||
if (requested === null || this.speedModels.length === 0) return;
|
||||
if (this.isServiceTierAvailable(requested)) return;
|
||||
this.requestedServiceTier = "default";
|
||||
this.providerOptions = { ...this.providerOptions, service_tier: "default" };
|
||||
this.emitEvent({
|
||||
type: "options_changed",
|
||||
provider: CODEX_PROVIDER,
|
||||
patch: { service_tier: "default" },
|
||||
});
|
||||
}
|
||||
|
||||
async setThinkingOption(thinkingOptionId: string | null): Promise<void | AgentProviderNotice> {
|
||||
@@ -4679,35 +4694,53 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
}
|
||||
}
|
||||
|
||||
async setFeature(featureId: string, value: unknown): Promise<void> {
|
||||
// COMPAT(codexFastPreference): added in v0.10.0, remove after 2027-03-29 once clients use service_tier.
|
||||
if (featureId === "fast_mode") {
|
||||
const fast = this.currentServiceTiers().find((tier) => tier.name.toLowerCase() === "fast");
|
||||
if (value && !fast)
|
||||
/** Applies only the options the patch sets; the rest of the running options stay as they are. */
|
||||
async applyOptions(options: ProviderOptions): Promise<Record<string, unknown>> {
|
||||
// The approval policy and sandbox are sent when the thread starts, not with each turn.
|
||||
assertChangesAreLive({
|
||||
provider: "codex",
|
||||
patch: options,
|
||||
current: this.providerOptions,
|
||||
live: ["service_tier", "plan_mode"],
|
||||
});
|
||||
const valid =
|
||||
validateProviderOptions(
|
||||
"codex",
|
||||
CodexProviderOptionsSchema,
|
||||
applyProviderOptionsPatch({ options: this.providerOptions, patch: options }),
|
||||
) ?? {};
|
||||
const requested = "service_tier" in options ? readCodexServiceTier(options) : null;
|
||||
let accepted = this.requestedServiceTier;
|
||||
if ("service_tier" in options) {
|
||||
if (requested !== accepted && !this.isServiceTierAvailable(requested)) {
|
||||
throw new Error(
|
||||
`Codex fast mode is not available for model '${this.config.model ?? "default"}'`,
|
||||
);
|
||||
return this.setFeature("service_tier", value ? fast!.id : "default");
|
||||
}
|
||||
if (featureId === "service_tier") {
|
||||
if (
|
||||
typeof value !== "string" ||
|
||||
(value !== "default" && !this.currentServiceTiers().some((tier) => tier.id === value))
|
||||
) {
|
||||
throw new Error(
|
||||
`Codex speed '${String(value)}' is not available for model '${this.config.model ?? "default"}'`,
|
||||
`Codex speed '${String(requested)}' is not available for model '${this.config.model ?? "default"}'`,
|
||||
);
|
||||
}
|
||||
this.serviceTier = value;
|
||||
this.reconcileServiceTier();
|
||||
this.cachedRuntimeInfo = null;
|
||||
return;
|
||||
// The session keeps the catalog's id for the tier, so a later model switch sees what runs.
|
||||
accepted = requested && (this.resolveServiceTier(requested) ?? requested);
|
||||
}
|
||||
if (featureId === "plan_mode") {
|
||||
this.applyFeatureValue("plan_mode", Boolean(value));
|
||||
return;
|
||||
}
|
||||
throw new Error(`Unknown Codex feature: ${featureId}`);
|
||||
this.providerOptions = { ...valid, ...(accepted ? { service_tier: accepted } : {}) };
|
||||
this.requestedServiceTier = accepted || null;
|
||||
if ("plan_mode" in options) this.setPlanMode(options.plan_mode === true);
|
||||
this.cachedRuntimeInfo = null;
|
||||
// The catalog may name the tier differently from the request (`fast` is the Fast tier's id).
|
||||
const tier = this.serviceTier;
|
||||
return tier !== null && requested !== null && tier !== requested ? { service_tier: tier } : {};
|
||||
}
|
||||
|
||||
private isServiceTierAvailable(tier: string | null): boolean {
|
||||
if (tier === null || tier === "default") return true;
|
||||
const tiers = this.currentServiceTiers();
|
||||
const namesFast = tier === "fast" && tiers.some((entry) => entry.name.toLowerCase() === "fast");
|
||||
return namesFast || tiers.some((entry) => entry.id === tier);
|
||||
}
|
||||
|
||||
private setPlanMode(enabled: boolean): void {
|
||||
if (this.planModeEnabled === enabled) return;
|
||||
this.planModeEnabled = enabled;
|
||||
this.refreshResolvedCollaborationMode();
|
||||
this.cachedRuntimeInfo = null;
|
||||
}
|
||||
|
||||
getPendingPermissions(): AgentPermissionRequest[] {
|
||||
@@ -5056,27 +5089,15 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
if (!turnId || (foregroundTurnId && this.activeForegroundTurnId !== foregroundTurnId)) {
|
||||
throw new Error("Cannot interrupt Codex before turn/started identifies the active turn");
|
||||
}
|
||||
const client = this.client;
|
||||
const threadId = this.currentThreadId;
|
||||
const interruptRequest = client.request(
|
||||
"turn/interrupt",
|
||||
{
|
||||
threadId,
|
||||
turnId,
|
||||
},
|
||||
INTERRUPT_TIMEOUT_MS,
|
||||
);
|
||||
// Once Codex accepts the interrupt, end the commands this turn started. Registered
|
||||
// before the await, so a turn start racing this interrupt waits for it. An already-idle
|
||||
// turn was not interrupted, and what it left running stays.
|
||||
this.trackInterruptedTurnCleanup(
|
||||
interruptRequest.then(
|
||||
() => this.endInterruptedTurnProcesses(client, threadId, turnId),
|
||||
() => undefined,
|
||||
),
|
||||
);
|
||||
try {
|
||||
await interruptRequest;
|
||||
await this.client.request(
|
||||
"turn/interrupt",
|
||||
{
|
||||
threadId: this.currentThreadId,
|
||||
turnId,
|
||||
},
|
||||
INTERRUPT_TIMEOUT_MS,
|
||||
);
|
||||
} catch (error) {
|
||||
if (!isCodexAlreadyIdleInterrupt(error)) {
|
||||
throw error;
|
||||
@@ -5117,137 +5138,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
return !this.client.hasPendingRequests();
|
||||
}
|
||||
|
||||
// Remember which turn started a command, so an interrupt ends that turn's commands and
|
||||
// no other turn's. Only the root thread's: a subagent's commands live on its own thread.
|
||||
// A command that starts after its turn's interrupt was accepted is ended as soon as it
|
||||
// is seen.
|
||||
private recordTurnTerminalProcess(
|
||||
parsed: Extract<ParsedCodexNotification, { kind: "item_started" | "item_completed" }>,
|
||||
): void {
|
||||
const processId = parsed.item.processId;
|
||||
if (
|
||||
parsed.source !== "item" ||
|
||||
!parsed.turnId ||
|
||||
!parsed.threadId ||
|
||||
parsed.threadId !== this.currentThreadId ||
|
||||
typeof processId !== "string" ||
|
||||
!processId ||
|
||||
normalizeCodexThreadItemType(
|
||||
typeof parsed.item.type === "string" ? parsed.item.type : undefined,
|
||||
) !== "commandExecution"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const record = this.terminalProcessIdsByTurnId.get(parsed.turnId);
|
||||
if (parsed.kind === "item_completed") {
|
||||
// Only a completed command has exited. A failed one can still be running:
|
||||
// Codex reports an interrupted turn's live command as failed.
|
||||
if (parsed.item.status === "completed") record?.processIds.delete(processId);
|
||||
return;
|
||||
}
|
||||
const current = record ?? this.getTurnTerminalRecord(parsed.turnId);
|
||||
current.processIds.add(processId);
|
||||
if (current.interruptAccepted && this.client) {
|
||||
this.trackInterruptedTurnCleanup(
|
||||
this.endInterruptedTurnProcesses(this.client, parsed.threadId, parsed.turnId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// An accepted interrupt needs a record even before any of its turn's commands is seen:
|
||||
// an `item/started` can still be queued behind an earlier notification's conversion.
|
||||
private getTurnTerminalRecord(turnId: string) {
|
||||
const existing = this.terminalProcessIdsByTurnId.get(turnId);
|
||||
if (existing) return existing;
|
||||
const record = {
|
||||
processIds: new Set<string>(),
|
||||
terminatedProcessIds: new Set<string>(),
|
||||
interruptAccepted: false,
|
||||
};
|
||||
this.terminalProcessIdsByTurnId.set(turnId, record);
|
||||
for (const oldestTurnId of this.terminalProcessIdsByTurnId.keys()) {
|
||||
if (this.terminalProcessIdsByTurnId.size <= INTERRUPTED_TURN_TRACKED_TURNS) break;
|
||||
this.terminalProcessIdsByTurnId.delete(oldestTurnId);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
// A later sweep joins the pending one, so a turn start waits for both.
|
||||
private trackInterruptedTurnCleanup(cleanup: Promise<void>): void {
|
||||
const tracked = Promise.all([this.interruptedTurnCleanup, cleanup])
|
||||
.then(() => undefined)
|
||||
.finally(() => {
|
||||
if (this.interruptedTurnCleanup === tracked) this.interruptedTurnCleanup = null;
|
||||
});
|
||||
this.interruptedTurnCleanup = tracked;
|
||||
}
|
||||
|
||||
// Terminate each process the interrupted turn started, by its own id, once each.
|
||||
// `thread/backgroundTerminals/clean` is never used: it ends every terminal on the thread,
|
||||
// an earlier turn's included. A process already gone answers `terminated: false`. Never
|
||||
// rejects; failures are logged.
|
||||
private async endInterruptedTurnProcesses(
|
||||
client: CodexAppServerClient,
|
||||
threadId: string | null,
|
||||
turnId: string,
|
||||
): Promise<void> {
|
||||
if (!threadId) return;
|
||||
const record = this.getTurnTerminalRecord(turnId);
|
||||
record.interruptAccepted = true;
|
||||
const processIds = [...record.processIds].filter(
|
||||
(processId) => !record.terminatedProcessIds.has(processId),
|
||||
);
|
||||
for (const processId of processIds) record.terminatedProcessIds.add(processId);
|
||||
const logContext = { agentId: this.agentId, provider: CODEX_PROVIDER, threadId, turnId };
|
||||
await Promise.all(
|
||||
processIds.map(async (processId) => {
|
||||
try {
|
||||
const response = await client.request(
|
||||
"thread/backgroundTerminals/terminate",
|
||||
{ threadId, processId },
|
||||
INTERRUPTED_TURN_TERMINATE_TIMEOUT_MS,
|
||||
);
|
||||
this.logger.info(
|
||||
{ ...logContext, processId, terminated: toObjectRecord(response)?.terminated ?? null },
|
||||
"provider.codex.interrupt.terminal_terminated",
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
{ ...logContext, processId, err: error },
|
||||
"provider.codex.interrupt.terminal_terminate_failed",
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// A new turn starts only after every pending sweep of interrupted turns' commands has
|
||||
// ended, or after the bound, whichever is first.
|
||||
private async waitForInterruptedTurnCleanup(): Promise<void> {
|
||||
if (!this.interruptedTurnCleanup) return;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
const timedOut = await Promise.race([
|
||||
(async () => {
|
||||
while (this.interruptedTurnCleanup) await this.interruptedTurnCleanup;
|
||||
return false;
|
||||
})(),
|
||||
new Promise<boolean>((resolve) => {
|
||||
timer = setTimeout(() => resolve(true), INTERRUPTED_TURN_CLEANUP_WAIT_MS);
|
||||
}),
|
||||
]);
|
||||
clearTimeout(timer);
|
||||
if (timedOut) {
|
||||
this.logger.warn(
|
||||
{
|
||||
agentId: this.agentId,
|
||||
provider: CODEX_PROVIDER,
|
||||
waitMs: INTERRUPTED_TURN_CLEANUP_WAIT_MS,
|
||||
},
|
||||
"provider.codex.interrupt.terminal_cleanup_timed_out",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
this.closed = true;
|
||||
this.clearPendingPermissions();
|
||||
@@ -5503,7 +5393,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
private async applyDefaultModelAndThinking(): Promise<string> {
|
||||
const { model, thinkingOptionId } = await this.resolveModelAndThinking();
|
||||
this.config.model = model;
|
||||
this.reconcileServiceTier();
|
||||
this.config.thinkingOptionId = thinkingOptionId;
|
||||
return model;
|
||||
}
|
||||
@@ -5570,7 +5459,8 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
|
||||
private buildCodexInnerConfig(): Record<string, unknown> | null {
|
||||
const innerConfig: Record<string, unknown> = {};
|
||||
Object.assign(innerConfig, this.providerOptions);
|
||||
const { service_tier: _tier, plan_mode: _plan, ...codexConfig } = this.providerOptions;
|
||||
Object.assign(innerConfig, codexConfig);
|
||||
if (this.deps.customCodexConfig) {
|
||||
Object.assign(innerConfig, this.deps.customCodexConfig);
|
||||
}
|
||||
@@ -6372,11 +6262,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
return;
|
||||
}
|
||||
this.completePendingRootCompactions();
|
||||
// What a turn that was not interrupted leaves running, it left on purpose; no later
|
||||
// interrupt may end it.
|
||||
if (parsed.status !== "interrupted" && this.currentTurnId) {
|
||||
this.terminalProcessIdsByTurnId.delete(this.currentTurnId);
|
||||
}
|
||||
if (parsed.status === "failed") {
|
||||
this.emitEvent({
|
||||
type: "turn_failed",
|
||||
@@ -6781,7 +6666,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
private async handleItemCompletedNotification(
|
||||
parsed: Extract<ParsedCodexNotification, { kind: "item_completed" }>,
|
||||
): Promise<void> {
|
||||
this.recordTurnTerminalProcess(parsed);
|
||||
// Codex emits mirrored lifecycle notifications via both `codex/event/item_*`
|
||||
// and canonical `item/*`. Render ordinary items only from the canonical
|
||||
// channel, but accept a legacy-only child announcement so it can establish
|
||||
@@ -6944,7 +6828,6 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
private async handleItemStartedNotification(
|
||||
parsed: Extract<ParsedCodexNotification, { kind: "item_started" }>,
|
||||
): Promise<void> {
|
||||
this.recordTurnTerminalProcess(parsed);
|
||||
if (shouldIgnoreMirroredLifecycleItem(parsed.source, parsed.item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AgentFeature, AgentFeatureToggle } from "../agent-sdk-types.js";
|
||||
import type { AgentOptionControl, AgentOptionToggleControl } from "../agent-sdk-types.js";
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -9,51 +9,47 @@ export const CodexServiceTierSchema = z.object({
|
||||
});
|
||||
export type CodexServiceTier = z.infer<typeof CodexServiceTierSchema>;
|
||||
|
||||
function buildCodexSpeedFeature(tiers: CodexServiceTier[], value: string): AgentFeature[] {
|
||||
function buildCodexSpeedControl(tiers: CodexServiceTier[]): AgentOptionControl[] {
|
||||
if (tiers.length === 0) return [];
|
||||
return [
|
||||
{
|
||||
type: "select",
|
||||
id: "service_tier",
|
||||
key: "service_tier",
|
||||
label: "Speed",
|
||||
description: "Choose processing speed. Faster tiers increase usage.",
|
||||
tooltip: "Select speed",
|
||||
icon: "zap",
|
||||
desktopTrigger: "icon",
|
||||
value,
|
||||
options: [
|
||||
{ id: "default", label: "Normal", isDefault: true },
|
||||
...tiers.map((tier) => ({ id: tier.id, label: tier.name })),
|
||||
defaultValue: "default",
|
||||
choices: [
|
||||
{ value: "default", label: "Normal" },
|
||||
...tiers.map((tier) => ({ value: tier.id, label: tier.name })),
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export const CODEX_PLAN_MODE_FEATURE: Omit<AgentFeatureToggle, "value"> = {
|
||||
export const CODEX_PLAN_MODE_CONTROL: AgentOptionToggleControl = {
|
||||
type: "toggle",
|
||||
id: "plan_mode",
|
||||
key: "plan_mode",
|
||||
label: "Plan",
|
||||
description: "Switch Codex into planning-only collaboration mode",
|
||||
tooltip: "Toggle plan mode",
|
||||
icon: "list-todo",
|
||||
};
|
||||
|
||||
export function buildCodexFeatures(input: {
|
||||
export function buildCodexControls(input: {
|
||||
serviceTiers: CodexServiceTier[];
|
||||
serviceTier: string;
|
||||
planModeEnabled: boolean;
|
||||
planModeAvailable?: boolean;
|
||||
}): AgentFeature[] {
|
||||
const features = buildCodexSpeedFeature(input.serviceTiers, input.serviceTier);
|
||||
}): AgentOptionControl[] {
|
||||
const controls = buildCodexSpeedControl(input.serviceTiers);
|
||||
if (input.planModeAvailable !== false) {
|
||||
features.push({ ...CODEX_PLAN_MODE_FEATURE, value: input.planModeEnabled });
|
||||
controls.push({ ...CODEX_PLAN_MODE_CONTROL });
|
||||
}
|
||||
return features;
|
||||
return controls;
|
||||
}
|
||||
|
||||
export function readCodexServiceTier(values: Record<string, unknown> | undefined): string | null {
|
||||
const tier = values?.service_tier;
|
||||
if (typeof tier === "string") return tier;
|
||||
// COMPAT(codexFastPreference): added in v0.10.0, remove after 2027-03-29 once saved Fast preferences have migrated.
|
||||
return values?.fast_mode ? "fast" : null;
|
||||
export function readCodexServiceTier(options: Record<string, unknown> | undefined): string | null {
|
||||
const tier = options?.service_tier;
|
||||
return typeof tier === "string" ? tier : null;
|
||||
}
|
||||
|
||||
@@ -1,374 +0,0 @@
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
import type { AgentSession } from "../agent-sdk-types.js";
|
||||
import { createTestLogger } from "../../../test-utils/test-logger.js";
|
||||
import { CodexAppServerAgentSession } from "./codex-app-server-agent.js";
|
||||
import {
|
||||
createFakeCodexAppServer,
|
||||
type FakeCodexAppServer,
|
||||
waitForNextEvent,
|
||||
waitForTimelineToolCall,
|
||||
} from "./codex/test-utils/fake-app-server.js";
|
||||
|
||||
const THREAD = "thread-1";
|
||||
const TERMINATE = "thread/backgroundTerminals/terminate";
|
||||
|
||||
type Handler = (params: unknown) => unknown;
|
||||
|
||||
function deferred<T = void>() {
|
||||
let resolve!: (value: T) => void;
|
||||
const promise = new Promise<T>((resolvePromise) => {
|
||||
resolve = resolvePromise;
|
||||
});
|
||||
return { promise, resolve };
|
||||
}
|
||||
|
||||
function paramsOf(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" ? (value as Record<string, unknown>) : {};
|
||||
}
|
||||
|
||||
let sessions: AgentSession[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
for (const session of sessions) await session.close().catch(() => undefined);
|
||||
sessions = [];
|
||||
});
|
||||
|
||||
/**
|
||||
* A Codex app-server whose interrupt ends the turn the way Codex does: an `interrupted`
|
||||
* turn completion, then the response. `terminate` answers per process.
|
||||
*/
|
||||
function createHarness(
|
||||
options: {
|
||||
terminate?: (processId: string) => unknown;
|
||||
interruptResponse?: (completeTurn: () => void) => unknown;
|
||||
} = {},
|
||||
) {
|
||||
const handlers: Record<string, Handler> = {
|
||||
"turn/interrupt": () => {
|
||||
const completeTurn = () =>
|
||||
appServer.completeTurn({ threadId: THREAD, status: "interrupted" });
|
||||
if (options.interruptResponse) return options.interruptResponse(completeTurn);
|
||||
completeTurn();
|
||||
return {};
|
||||
},
|
||||
[TERMINATE]: (params) =>
|
||||
options.terminate?.(String(paramsOf(params).processId)) ?? { terminated: true },
|
||||
};
|
||||
const appServer: FakeCodexAppServer = createFakeCodexAppServer(handlers);
|
||||
const session = new CodexAppServerAgentSession(
|
||||
{
|
||||
provider: "codex",
|
||||
cwd: "/workspace/project",
|
||||
modeId: "auto",
|
||||
model: "gpt-5.4",
|
||||
},
|
||||
null,
|
||||
createTestLogger(),
|
||||
async () => appServer.child,
|
||||
);
|
||||
sessions.push(session);
|
||||
|
||||
function requests(method: string): Record<string, unknown>[] {
|
||||
return appServer
|
||||
.requests()
|
||||
.filter((message) => message.method === method && "id" in message)
|
||||
.map((message) => paramsOf(message.params));
|
||||
}
|
||||
|
||||
function terminated(): string[] {
|
||||
return requests(TERMINATE)
|
||||
.map((params) => String(params.processId))
|
||||
.sort();
|
||||
}
|
||||
|
||||
// Starts a turn and lets Codex identify it as `nativeTurnId`.
|
||||
async function startTurn(prompt: string, nativeTurnId: string): Promise<void> {
|
||||
const before = requests("turn/start").length;
|
||||
const started = session.startTurn(prompt);
|
||||
await vi.waitFor(() => expect(requests("turn/start")).toHaveLength(before + 1), {
|
||||
timeout: 5_000,
|
||||
});
|
||||
const turnStarted = waitForNextEvent(session, "turn_started");
|
||||
appServer.startsTurn({ threadId: THREAD, turnId: nativeTurnId });
|
||||
await started;
|
||||
await turnStarted;
|
||||
}
|
||||
|
||||
async function runsCommand(params: { turnId: string; processId: string }): Promise<void> {
|
||||
const itemId = `exec-${params.processId}`;
|
||||
const shown = waitForTimelineToolCall(session, itemId);
|
||||
appServer.startsTerminalCommand({
|
||||
threadId: THREAD,
|
||||
turnId: params.turnId,
|
||||
itemId,
|
||||
processId: params.processId,
|
||||
command: `sleep ${params.processId}`,
|
||||
});
|
||||
await shown;
|
||||
}
|
||||
|
||||
async function completesTurn(): Promise<void> {
|
||||
const completed = waitForNextEvent(session, "turn_completed");
|
||||
appServer.completeTurn({ threadId: THREAD });
|
||||
await completed;
|
||||
}
|
||||
|
||||
// Interrupts the running turn and waits for the session to report it canceled, as a
|
||||
// caller does before it starts the next turn: Codex notifications are handled in order
|
||||
// but asynchronously, so the interrupt's answer can arrive before the turn has ended.
|
||||
async function interrupts(): Promise<void> {
|
||||
const canceled = waitForNextEvent(session, "turn_canceled");
|
||||
await session.interrupt();
|
||||
await canceled;
|
||||
}
|
||||
|
||||
return {
|
||||
appServer,
|
||||
session,
|
||||
requests,
|
||||
terminated,
|
||||
startTurn,
|
||||
runsCommand,
|
||||
completesTurn,
|
||||
interrupts,
|
||||
};
|
||||
}
|
||||
|
||||
// Turn A leaves a server running on purpose and completes. Turn B starts two
|
||||
// commands, and a subagent on its own thread starts a third, then B is interrupted.
|
||||
async function interruptTurnB(harness: ReturnType<typeof createHarness>): Promise<void> {
|
||||
await harness.startTurn("start a server", "native-A");
|
||||
await harness.runsCommand({ turnId: "native-A", processId: "101" });
|
||||
await harness.completesTurn();
|
||||
|
||||
await harness.startTurn("run two commands", "native-B");
|
||||
await harness.runsCommand({ turnId: "native-B", processId: "201" });
|
||||
// A subagent thread's command shows no row here; the next command's row shows it
|
||||
// was read, because notifications are read in order.
|
||||
harness.appServer.startsTerminalCommand({
|
||||
threadId: "child-thread",
|
||||
turnId: "native-B",
|
||||
itemId: "exec-209",
|
||||
processId: "209",
|
||||
command: "sleep 209",
|
||||
});
|
||||
await harness.runsCommand({ turnId: "native-B", processId: "202" });
|
||||
await harness.interrupts();
|
||||
}
|
||||
|
||||
describe("an interrupted Codex turn's commands end before the next turn", () => {
|
||||
test("terminates exactly the processes the interrupted turn started, by id, and never cleans", async () => {
|
||||
const harness = createHarness();
|
||||
await interruptTurnB(harness);
|
||||
await harness.startTurn("correction", "native-C");
|
||||
|
||||
expect(harness.terminated()).toEqual(["201", "202"]);
|
||||
expect(harness.requests(TERMINATE).every((params) => params.threadId === THREAD)).toBe(true);
|
||||
// `clean` would end every terminal on the thread, an earlier turn's included.
|
||||
expect(
|
||||
harness.appServer
|
||||
.requests()
|
||||
.filter((message) => String(message.method).startsWith("thread/backgroundTerminals/"))
|
||||
.map((message) => message.method),
|
||||
).toEqual([TERMINATE, TERMINATE]);
|
||||
harness.appServer.assertNoErrors();
|
||||
});
|
||||
|
||||
test("leaves the next turn's commands running when Codex starts that turn before acknowledging the interrupt", async () => {
|
||||
const acknowledge = deferred();
|
||||
const harness = createHarness({
|
||||
// Codex ends B, starts a turn of its own (a goal continuation), and only then
|
||||
// answers the interrupt.
|
||||
interruptResponse: (completeTurn) => {
|
||||
completeTurn();
|
||||
return acknowledge.promise.then(() => ({}));
|
||||
},
|
||||
});
|
||||
await harness.startTurn("run two commands", "native-B");
|
||||
await harness.runsCommand({ turnId: "native-B", processId: "201" });
|
||||
await harness.runsCommand({ turnId: "native-B", processId: "202" });
|
||||
const interrupting = harness.session.interrupt();
|
||||
await vi.waitFor(() => expect(harness.requests("turn/interrupt")).toHaveLength(1));
|
||||
const autonomousTurn = waitForNextEvent(harness.session, "turn_started");
|
||||
harness.appServer.startsTurn({ threadId: THREAD, turnId: "native-C" });
|
||||
await autonomousTurn;
|
||||
await harness.runsCommand({ turnId: "native-C", processId: "301" });
|
||||
|
||||
acknowledge.resolve();
|
||||
await interrupting;
|
||||
await vi.waitFor(() => expect(harness.terminated()).toEqual(["201", "202"]));
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
expect(harness.terminated()).toEqual(["201", "202"]);
|
||||
});
|
||||
|
||||
test("sends the next turn/start only after the terminates are answered", async () => {
|
||||
const answer = deferred();
|
||||
const harness = createHarness({
|
||||
terminate: () => answer.promise.then(() => ({ terminated: true })),
|
||||
});
|
||||
await interruptTurnB(harness);
|
||||
const next = harness.startTurn("correction", "native-C");
|
||||
await vi.waitFor(() => expect(harness.terminated()).toEqual(["201", "202"]));
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
expect(harness.requests("turn/start")).toHaveLength(2);
|
||||
|
||||
answer.resolve();
|
||||
await next;
|
||||
expect(harness.requests("turn/start")).toHaveLength(3);
|
||||
});
|
||||
|
||||
test.each(["initial", "late"] as const)(
|
||||
"tracks both cleanup sweeps when the %s answer arrives first",
|
||||
async (answeredFirst) => {
|
||||
const first = deferred();
|
||||
const second = deferred();
|
||||
const harness = createHarness({
|
||||
terminate: (processId) =>
|
||||
(processId === "201" ? first : second).promise.then(() => ({ terminated: true })),
|
||||
});
|
||||
await harness.startTurn("run commands", "native-B");
|
||||
await harness.runsCommand({ turnId: "native-B", processId: "201" });
|
||||
await harness.interrupts();
|
||||
await vi.waitFor(() => expect(harness.terminated()).toEqual(["201"]));
|
||||
const next = harness.startTurn("correction", "native-C");
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
expect(harness.requests("turn/start")).toHaveLength(1);
|
||||
// The next turn is already waiting when another process is announced.
|
||||
harness.appServer.startsTerminalCommand({
|
||||
threadId: THREAD,
|
||||
turnId: "native-B",
|
||||
itemId: "late-202",
|
||||
processId: "202",
|
||||
command: "sleep 202",
|
||||
});
|
||||
harness.appServer.startsTerminalCommand({
|
||||
threadId: THREAD,
|
||||
turnId: "native-B",
|
||||
itemId: "duplicate-202",
|
||||
processId: "202",
|
||||
command: "sleep 202",
|
||||
});
|
||||
await vi.waitFor(() => expect(harness.terminated()).toEqual(["201", "202"]));
|
||||
(answeredFirst === "initial" ? first : second).resolve();
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
expect(harness.requests("turn/start")).toHaveLength(1);
|
||||
(answeredFirst === "initial" ? second : first).resolve();
|
||||
await next;
|
||||
expect(harness.terminated()).toEqual(["201", "202"]);
|
||||
// Accepted state survives the completed sweep and a newer foreground turn.
|
||||
harness.appServer.startsTerminalCommand({
|
||||
threadId: THREAD,
|
||||
turnId: "native-B",
|
||||
itemId: "late-203",
|
||||
processId: "203",
|
||||
command: "sleep 203",
|
||||
});
|
||||
await vi.waitFor(() => expect(harness.terminated()).toEqual(["201", "202", "203"]));
|
||||
harness.appServer.assertNoErrors();
|
||||
},
|
||||
);
|
||||
|
||||
test("keeps the first sweep pending when a late sweep answers before the next start", async () => {
|
||||
const first = deferred();
|
||||
const harness = createHarness({
|
||||
terminate: (processId) =>
|
||||
processId === "201"
|
||||
? first.promise.then(() => ({ terminated: true }))
|
||||
: { terminated: true },
|
||||
});
|
||||
await harness.startTurn("run commands", "native-B");
|
||||
await harness.runsCommand({ turnId: "native-B", processId: "201" });
|
||||
await harness.interrupts();
|
||||
harness.appServer.startsTerminalCommand({
|
||||
threadId: THREAD,
|
||||
turnId: "native-B",
|
||||
itemId: "late-202",
|
||||
processId: "202",
|
||||
command: "sleep 202",
|
||||
});
|
||||
await vi.waitFor(() => expect(harness.terminated()).toEqual(["201", "202"]));
|
||||
const next = harness.startTurn("correction", "native-C");
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
expect(harness.requests("turn/start")).toHaveLength(1);
|
||||
first.resolve();
|
||||
await next;
|
||||
harness.appServer.assertNoErrors();
|
||||
});
|
||||
|
||||
test("forgets completed commands but retains failed commands at interrupt", async () => {
|
||||
const harness = createHarness();
|
||||
await harness.startTurn("run commands", "native-B");
|
||||
for (const processId of ["201", "202"]) {
|
||||
await harness.runsCommand({ turnId: "native-B", processId });
|
||||
harness.appServer.child.stdout.write(
|
||||
JSON.stringify({
|
||||
method: "item/completed",
|
||||
params: {
|
||||
threadId: THREAD,
|
||||
turnId: "native-B",
|
||||
item: {
|
||||
id: `exec-${processId}`,
|
||||
type: "commandExecution",
|
||||
processId,
|
||||
command: `sleep ${processId}`,
|
||||
status: processId === "201" ? "completed" : "failed",
|
||||
exitCode: processId === "201" ? 0 : null,
|
||||
},
|
||||
},
|
||||
}) + "\n",
|
||||
);
|
||||
}
|
||||
// A following command's row is a barrier for both completion handlers.
|
||||
await harness.runsCommand({ turnId: "native-B", processId: "203" });
|
||||
await harness.interrupts();
|
||||
await harness.startTurn("correction", "native-C");
|
||||
expect(harness.terminated()).toEqual(["202", "203"]);
|
||||
harness.appServer.assertNoErrors();
|
||||
});
|
||||
|
||||
test("retains accepted interrupts for only the latest sixteen turns", async () => {
|
||||
const harness = createHarness();
|
||||
for (let index = 0; index < 17; index++) {
|
||||
await harness.startTurn("run a command", `native-${index}`);
|
||||
await harness.interrupts();
|
||||
}
|
||||
await harness.startTurn("correction", "native-current");
|
||||
harness.appServer.startsTerminalCommand({
|
||||
threadId: THREAD,
|
||||
turnId: "native-0",
|
||||
itemId: "evicted-201",
|
||||
processId: "201",
|
||||
command: "sleep 201",
|
||||
});
|
||||
harness.appServer.startsTerminalCommand({
|
||||
threadId: THREAD,
|
||||
turnId: "native-16",
|
||||
itemId: "retained-202",
|
||||
processId: "202",
|
||||
command: "sleep 202",
|
||||
});
|
||||
await harness.runsCommand({ turnId: "native-current", processId: "301" });
|
||||
expect(harness.terminated()).toEqual(["202"]);
|
||||
harness.appServer.assertNoErrors();
|
||||
});
|
||||
|
||||
test("a failing or unanswered terminate does not block or fail the next turn", async () => {
|
||||
const harness = createHarness({
|
||||
// 201 is refused while the next turn waits; 202 is never answered.
|
||||
terminate: (processId) =>
|
||||
processId === "201"
|
||||
? new Promise((resolve) => setTimeout(resolve, 300)).then(() => ({
|
||||
__jsonRpcError: { code: -32600, message: "invalid background terminal process id" },
|
||||
}))
|
||||
: new Promise(() => {}),
|
||||
});
|
||||
await interruptTurnB(harness);
|
||||
const startedAt = Date.now();
|
||||
await harness.startTurn("correction", "native-C");
|
||||
|
||||
expect(Date.now() - startedAt).toBeLessThan(5_000);
|
||||
expect(harness.requests("turn/start")).toHaveLength(3);
|
||||
expect(harness.terminated()).toEqual(["201", "202"]);
|
||||
}, 15_000);
|
||||
});
|
||||
@@ -37,6 +37,9 @@ const NetworkPolicySchema = z
|
||||
// Codex config reference, maintained against Codex CLI 0.143+.
|
||||
export const CodexProviderOptionsSchema = z
|
||||
.object({
|
||||
// Composer controls, not Codex config: the provider reads them and keeps them out of `config`.
|
||||
service_tier: z.string().optional(),
|
||||
plan_mode: z.boolean().optional(),
|
||||
approval_policy: ApprovalPolicySchema.optional(),
|
||||
sandbox_mode: z.enum(["read-only", "workspace-write", "danger-full-access"]).optional(),
|
||||
sandbox_workspace_write: z
|
||||
|
||||
@@ -155,7 +155,7 @@ describe("CursorACPAgentClient model discovery", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("exposes Cursor fast mode through provider features", async () => {
|
||||
test("exposes Cursor fast mode through provider controls", async () => {
|
||||
const client = new TestCursorACPAgentClient({
|
||||
sessionId: "session-1",
|
||||
models: null,
|
||||
@@ -163,43 +163,29 @@ describe("CursorACPAgentClient model discovery", () => {
|
||||
});
|
||||
|
||||
await expect(
|
||||
client.listFeatures({
|
||||
client.listControls({
|
||||
provider: "acp",
|
||||
cwd: "/tmp/cursor",
|
||||
}),
|
||||
).resolves.toEqual([
|
||||
{
|
||||
type: "toggle",
|
||||
id: "auto_accept",
|
||||
key: "auto_accept",
|
||||
label: "Auto Accept",
|
||||
description: "Automatically approves ACP permission prompts.",
|
||||
tooltip: "Auto accept permission prompts",
|
||||
icon: "shield-check",
|
||||
value: false,
|
||||
},
|
||||
{
|
||||
type: "select",
|
||||
id: CURSOR_FAST_FEATURE_OPTION.id,
|
||||
key: CURSOR_FAST_FEATURE_OPTION.id,
|
||||
label: "Fast",
|
||||
description: "Cursor fast mode",
|
||||
tooltip: "Select Cursor fast mode",
|
||||
icon: "zap",
|
||||
value: "false",
|
||||
options: [
|
||||
{
|
||||
id: "false",
|
||||
label: "Off",
|
||||
isDefault: true,
|
||||
description: undefined,
|
||||
metadata: undefined,
|
||||
},
|
||||
{
|
||||
id: "true",
|
||||
label: "Fast",
|
||||
isDefault: false,
|
||||
description: undefined,
|
||||
metadata: undefined,
|
||||
},
|
||||
choices: [
|
||||
{ value: "false", label: "Off" },
|
||||
{ value: "true", label: "Fast" },
|
||||
],
|
||||
},
|
||||
]);
|
||||
@@ -228,7 +214,9 @@ describe("CursorACPAgentClient session start", () => {
|
||||
session: {
|
||||
currentModelId: string;
|
||||
configOptions: SessionConfigOption[];
|
||||
setSessionConfigOption?: () => Promise<{ configOptions: SessionConfigOption[] }>;
|
||||
setSessionConfigOption?: (request: {
|
||||
value: string;
|
||||
}) => Promise<{ configOptions: SessionConfigOption[] }>;
|
||||
} = { currentModelId: "kimi-k3", configOptions: KIMI_K3_CONFIG_OPTIONS },
|
||||
logger = createTestLogger(),
|
||||
): ACPAgentSession {
|
||||
@@ -277,7 +265,7 @@ describe("CursorACPAgentClient session start", () => {
|
||||
// still stored after the draft moved to a model that has no fast variant.
|
||||
const warn = captureWarnings();
|
||||
const session = createCursorSession(
|
||||
{ model: "kimi-k3", featureValues: { [CURSOR_FAST_FEATURE_OPTION.id]: "true" } },
|
||||
{ model: "kimi-k3", providerOptions: { [CURSOR_FAST_FEATURE_OPTION.id]: "true" } },
|
||||
{ currentModelId: "kimi-k3", configOptions: KIMI_K3_CONFIG_OPTIONS },
|
||||
warn.logger,
|
||||
);
|
||||
@@ -295,7 +283,7 @@ describe("CursorACPAgentClient session start", () => {
|
||||
// still listed after the model moves to one that has no fast variant.
|
||||
const warn = captureWarnings();
|
||||
const session = createCursorSession(
|
||||
{ model: "kimi-k3", featureValues: { [CURSOR_FAST_FEATURE_OPTION.id]: "true" } },
|
||||
{ model: "kimi-k3", providerOptions: { [CURSOR_FAST_FEATURE_OPTION.id]: "true" } },
|
||||
{
|
||||
currentModelId: "composer-2.5",
|
||||
configOptions: [fastConfigOption("false"), ...KIMI_K3_CONFIG_OPTIONS],
|
||||
@@ -319,7 +307,7 @@ describe("CursorACPAgentClient session start", () => {
|
||||
|
||||
test("still fails session start when a stored feature write fails for another reason", async () => {
|
||||
const session = createCursorSession(
|
||||
{ model: "kimi-k3", featureValues: { [CURSOR_FAST_FEATURE_OPTION.id]: "true" } },
|
||||
{ model: "kimi-k3", providerOptions: { [CURSOR_FAST_FEATURE_OPTION.id]: "true" } },
|
||||
{
|
||||
currentModelId: "composer-2.5",
|
||||
configOptions: [fastConfigOption("false"), ...KIMI_K3_CONFIG_OPTIONS],
|
||||
@@ -334,16 +322,71 @@ describe("CursorACPAgentClient session start", () => {
|
||||
const session = createCursorSession({ model: "kimi-k3" });
|
||||
await session.initializeNewSession();
|
||||
|
||||
await expect(session.setFeature(CURSOR_FAST_FEATURE_OPTION.id, "true")).rejects.toThrow(
|
||||
await expect(session.applyOptions({ [CURSOR_FAST_FEATURE_OPTION.id]: "true" })).rejects.toThrow(
|
||||
"acp does not expose ACP feature 'fast'",
|
||||
);
|
||||
});
|
||||
|
||||
test("removing auto_accept returns the session to asking for permission", async () => {
|
||||
const session = createCursorSession({ model: "composer-2.5" });
|
||||
await session.initializeNewSession();
|
||||
const request = {
|
||||
sessionId: "session-1",
|
||||
toolCall: { toolCallId: "tool-1", title: "Run command", kind: "execute", status: "pending" },
|
||||
options: [{ optionId: "allow-always", name: "Always allow", kind: "allow_always" }],
|
||||
} as const;
|
||||
|
||||
await session.applyOptions({ auto_accept: true });
|
||||
await expect(session.requestPermission({ ...request })).resolves.toEqual({
|
||||
outcome: { outcome: "selected", optionId: "allow-always" },
|
||||
});
|
||||
await expect(session.applyOptions({ auto_accept: null })).resolves.toEqual({});
|
||||
|
||||
void session.requestPermission({ ...request });
|
||||
await vi.waitFor(() => expect(session.getPendingPermissions()).toHaveLength(1));
|
||||
});
|
||||
|
||||
test("a rejected patch leaves auto_accept as it was", async () => {
|
||||
const session = createCursorSession({ model: "kimi-k3" });
|
||||
await session.initializeNewSession();
|
||||
|
||||
await expect(
|
||||
session.applyOptions({ auto_accept: true, [CURSOR_FAST_FEATURE_OPTION.id]: "true" }),
|
||||
).rejects.toThrow("acp does not expose ACP feature 'fast'");
|
||||
|
||||
void session.requestPermission({
|
||||
sessionId: "session-1",
|
||||
toolCall: { toolCallId: "tool-1", title: "Run command", kind: "execute", status: "pending" },
|
||||
options: [{ optionId: "allow-always", name: "Always allow", kind: "allow_always" }],
|
||||
});
|
||||
await vi.waitFor(() => expect(session.getPendingPermissions()).toHaveLength(1));
|
||||
});
|
||||
|
||||
test("applies only the selects the patch sets", async () => {
|
||||
const setSessionConfigOption = vi.fn(async (request: { value: string }) => ({
|
||||
configOptions: [fastConfigOption(request.value === "true" ? "true" : "false")],
|
||||
}));
|
||||
const session = createCursorSession(
|
||||
{ model: "composer-2.5" },
|
||||
{
|
||||
currentModelId: "composer-2.5",
|
||||
configOptions: [fastConfigOption("false")],
|
||||
setSessionConfigOption,
|
||||
},
|
||||
);
|
||||
await session.initializeNewSession();
|
||||
|
||||
await session.applyOptions({ [CURSOR_FAST_FEATURE_OPTION.id]: "true" });
|
||||
await session.applyOptions({});
|
||||
|
||||
expect(setSessionConfigOption.mock.calls.map(([request]) => request.value)).toEqual(["true"]);
|
||||
});
|
||||
|
||||
test("still fails session start when the provider rejects a write it should accept", async () => {
|
||||
// No model switch, so the session's options came straight from session/new and the
|
||||
// provider disagreeing about a feature it just advertised is a real failure.
|
||||
const session = createCursorSession(
|
||||
{ model: "composer-2.5", featureValues: { [CURSOR_FAST_FEATURE_OPTION.id]: "true" } },
|
||||
{ model: "composer-2.5", providerOptions: { [CURSOR_FAST_FEATURE_OPTION.id]: "true" } },
|
||||
{
|
||||
currentModelId: "composer-2.5",
|
||||
configOptions: [fastConfigOption("false")],
|
||||
|
||||
@@ -68,7 +68,7 @@ describe("MockLoadTestAgentClient", () => {
|
||||
provider: "mock",
|
||||
cwd: process.cwd(),
|
||||
model: "ten-second-stream",
|
||||
featureValues: { mockPromptRejections: 1 },
|
||||
providerOptions: { mockPromptRejections: 1 },
|
||||
});
|
||||
|
||||
await expect(session.startTurn("Reject this prompt.")).rejects.toThrow(
|
||||
@@ -95,7 +95,7 @@ describe("MockLoadTestAgentClient", () => {
|
||||
provider: "mock",
|
||||
cwd: process.cwd(),
|
||||
model: "ten-second-stream",
|
||||
featureValues: {
|
||||
providerOptions: {
|
||||
mockStreamingAssistantResponse: response,
|
||||
mockStreamingAssistantIntervalMs: 20,
|
||||
},
|
||||
@@ -467,7 +467,7 @@ describe("MockLoadTestAgentClient", () => {
|
||||
provider: "mock",
|
||||
cwd: process.cwd(),
|
||||
model: "e2e-fast-stream",
|
||||
featureValues: { mockAssistantResponses: ["First response", ""] },
|
||||
providerOptions: { mockAssistantResponses: ["First response", ""] },
|
||||
});
|
||||
await session.run("Emit a synthetic turn failure.");
|
||||
expect((await session.run("First prompt")).finalText).toBe("First response");
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Logger } from "pino";
|
||||
import type {
|
||||
AgentCapabilityFlags,
|
||||
AgentClient,
|
||||
AgentFeature,
|
||||
AgentOptionControl,
|
||||
AgentLaunchContext,
|
||||
AgentMode,
|
||||
AgentModelDefinition,
|
||||
@@ -787,7 +787,7 @@ function getConfiguredAssistantResponses(value: unknown): string[] {
|
||||
export class MockLoadTestAgentSession implements AgentSession {
|
||||
readonly provider: AgentProvider = MOCK_LOAD_TEST_PROVIDER_ID;
|
||||
readonly capabilities = CAPABILITIES;
|
||||
readonly features: AgentFeature[] = [];
|
||||
readonly controls: AgentOptionControl[] = [];
|
||||
readonly id: string;
|
||||
private readonly usageSessionKey = randomUUID();
|
||||
|
||||
@@ -812,18 +812,18 @@ export class MockLoadTestAgentSession implements AgentSession {
|
||||
this.modeId = options.config.modeId ?? MOCK_LOAD_TEST_MODE_ID;
|
||||
this.modelId = options.config.model ?? MOCK_LOAD_TEST_DEFAULT_MODEL_ID;
|
||||
this.assistantResponse =
|
||||
typeof options.config.featureValues?.mockAssistantResponse === "string"
|
||||
? options.config.featureValues.mockAssistantResponse
|
||||
typeof options.config.providerOptions?.mockAssistantResponse === "string"
|
||||
? options.config.providerOptions.mockAssistantResponse
|
||||
: null;
|
||||
this.assistantResponses = getConfiguredAssistantResponses(
|
||||
options.config.featureValues?.mockAssistantResponses,
|
||||
options.config.providerOptions?.mockAssistantResponses,
|
||||
);
|
||||
this.streamingAssistantResponse =
|
||||
typeof options.config.featureValues?.mockStreamingAssistantResponse === "string"
|
||||
? options.config.featureValues.mockStreamingAssistantResponse
|
||||
typeof options.config.providerOptions?.mockStreamingAssistantResponse === "string"
|
||||
? options.config.providerOptions.mockStreamingAssistantResponse
|
||||
: null;
|
||||
const requestedStreamingInterval =
|
||||
options.config.featureValues?.mockStreamingAssistantIntervalMs;
|
||||
options.config.providerOptions?.mockStreamingAssistantIntervalMs;
|
||||
this.streamingAssistantIntervalMs =
|
||||
typeof requestedStreamingInterval === "number" &&
|
||||
Number.isFinite(requestedStreamingInterval) &&
|
||||
@@ -831,10 +831,10 @@ export class MockLoadTestAgentSession implements AgentSession {
|
||||
? Math.min(requestedStreamingInterval, 1_000)
|
||||
: MOCK_LOAD_TEST_INTERVAL_MS;
|
||||
this.rewindError =
|
||||
typeof options.config.featureValues?.mockRewindError === "string"
|
||||
? options.config.featureValues.mockRewindError
|
||||
typeof options.config.providerOptions?.mockRewindError === "string"
|
||||
? options.config.providerOptions.mockRewindError
|
||||
: null;
|
||||
const requestedPromptRejections = options.config.featureValues?.mockPromptRejections;
|
||||
const requestedPromptRejections = options.config.providerOptions?.mockPromptRejections;
|
||||
this.remainingPromptRejections =
|
||||
typeof requestedPromptRejections === "number" &&
|
||||
Number.isSafeInteger(requestedPromptRejections) &&
|
||||
@@ -842,7 +842,7 @@ export class MockLoadTestAgentSession implements AgentSession {
|
||||
? requestedPromptRejections
|
||||
: 0;
|
||||
this.remainingSteerFailures = getPositiveFeatureInteger(
|
||||
options.config.featureValues?.mockSteerAmbiguousFailures,
|
||||
options.config.providerOptions?.mockSteerAmbiguousFailures,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -613,9 +613,9 @@ describe("OMP agent client and session", () => {
|
||||
expect(omp.requireSession().describePersistence()?.metadata?.model).toBe(
|
||||
"openrouter/google/gemini-3.8-flash",
|
||||
);
|
||||
expect(omp.requireSession().features).toEqual([
|
||||
expect(omp.requireSession().controls).toEqual([
|
||||
expect.objectContaining({
|
||||
value: true,
|
||||
key: "fast_mode",
|
||||
description: expect.stringMatching(/does not apply/i),
|
||||
}),
|
||||
]);
|
||||
@@ -626,18 +626,90 @@ describe("OMP agent client and session", () => {
|
||||
await omp.start({ model: "openrouter/google/gemini-3.8-flash" });
|
||||
const session = omp.requireSession();
|
||||
omp.runtime().fastModeResult = { enabled: true, active: false };
|
||||
await session.setFeature?.("fast_mode", true);
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
expect(omp.runtime().setFastModeRequests).toEqual([true]);
|
||||
expect(session.features).toEqual([
|
||||
expect(session.controls).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "fast_mode",
|
||||
value: true,
|
||||
key: "fast_mode",
|
||||
description: expect.stringMatching(/does not apply to this model/i),
|
||||
tooltip: expect.stringMatching(/does not apply to this model/i),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("applies only the options it is given and leaves the runtime alone otherwise", async () => {
|
||||
const omp = new OmpHarness();
|
||||
await omp.start();
|
||||
const session = omp.requireSession();
|
||||
|
||||
omp.runtime().fastModeResult = { enabled: true, active: true };
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
expect(omp.runtime().setFastModeRequests).toEqual([true]);
|
||||
|
||||
// A patch without the key leaves the runtime alone.
|
||||
await session.applyOptions?.({});
|
||||
expect(omp.runtime().setFastModeRequests).toEqual([true]);
|
||||
});
|
||||
|
||||
test("rejects a live option the creation schema would reject, and sends nothing", async () => {
|
||||
const omp = new OmpHarness();
|
||||
await omp.start();
|
||||
const session = omp.requireSession();
|
||||
|
||||
await expect(session.applyOptions?.({ sandbox_mode: "read-only" })).rejects.toThrow(/omp/i);
|
||||
await expect(session.applyOptions?.({ fast_mode: "yes" })).rejects.toThrow(/omp/i);
|
||||
expect(omp.runtime().setFastModeRequests).toEqual([]);
|
||||
});
|
||||
|
||||
test("a removal turns Fast off, and a Fast the runtime keeps is returned", async () => {
|
||||
const omp = new OmpHarness();
|
||||
await omp.start();
|
||||
const session = omp.requireSession();
|
||||
omp.runtime().fastModeResult = { enabled: true, active: true };
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
|
||||
omp.runtime().fastModeResult = { enabled: false, active: false };
|
||||
await expect(session.applyOptions?.({ fast_mode: null })).resolves.toEqual({});
|
||||
expect(omp.runtime().setFastModeRequests).toEqual([true, false]);
|
||||
|
||||
omp.runtime().fastModeResult = { enabled: false, active: false };
|
||||
await expect(session.applyOptions?.({ fast_mode: true })).resolves.toEqual({
|
||||
fast_mode: false,
|
||||
});
|
||||
expect(omp.eventTypes()).not.toContain("options_changed");
|
||||
});
|
||||
|
||||
test("a session opened without the Fast it was given says so in its open patch", async () => {
|
||||
const omp = new OmpHarness();
|
||||
// The fake runtime answers the open-time Fast request with Fast off.
|
||||
await omp.start({ providerOptions: { fast_mode: true } });
|
||||
|
||||
expect(omp.requireSession().openOptionsPatch).toEqual({ fast_mode: false });
|
||||
expect(omp.eventTypes()).not.toContain("options_changed");
|
||||
});
|
||||
|
||||
test("reports a Fast change the runtime made on its own", async () => {
|
||||
const omp = new OmpHarness();
|
||||
await omp.start();
|
||||
const session = omp.requireSession();
|
||||
omp.runtime().fastModeResult = { enabled: true, active: true };
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
expect(omp.eventTypes()).not.toContain("options_changed");
|
||||
|
||||
omp.runtime().setModelResult = { provider: "openrouter", id: "other/model" };
|
||||
omp.runtime().queueStateReports([
|
||||
{
|
||||
...omp.runtime().state,
|
||||
model: omp.runtime().setModelResult,
|
||||
fastModeEnabled: false,
|
||||
fastModeActive: false,
|
||||
},
|
||||
]);
|
||||
await session.setModel?.("openrouter/other/model");
|
||||
|
||||
expect(omp.eventTypes().filter((type) => type === "options_changed")).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("shows Fast only when OMP reports its state fields", async () => {
|
||||
const omp = new OmpHarness();
|
||||
await omp.start();
|
||||
@@ -649,11 +721,11 @@ describe("OMP agent client and session", () => {
|
||||
} = omp.runtime().state;
|
||||
omp.runtime().state = olderState;
|
||||
await session.getRuntimeInfo();
|
||||
expect(session.features).toEqual([]);
|
||||
await expect(session.setFeature?.("fast_mode", true)).rejects.toThrow(/unavailable/i);
|
||||
expect(session.controls).toEqual([]);
|
||||
await expect(session.applyOptions?.({ fast_mode: true })).rejects.toThrow(/unavailable/i);
|
||||
omp.runtime().state = { ...olderState, fastModeEnabled: false, fastModeActive: false };
|
||||
await session.getRuntimeInfo();
|
||||
expect(session.features).toHaveLength(1);
|
||||
expect(session.controls).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("switching model refreshes whether Fast applies", async () => {
|
||||
@@ -661,8 +733,7 @@ describe("OMP agent client and session", () => {
|
||||
await omp.start({ model: "openrouter/google/gemini-3.8-flash" });
|
||||
const session = omp.requireSession();
|
||||
omp.runtime().fastModeResult = { enabled: true, active: true };
|
||||
await session.setFeature?.("fast_mode", true);
|
||||
expect(session.features).toEqual([expect.objectContaining({ value: true })]);
|
||||
await session.applyOptions?.({ fast_mode: true });
|
||||
|
||||
omp.runtime().setModelResult = { provider: "openrouter", id: "other/model" };
|
||||
omp.runtime().queueStateReports([
|
||||
@@ -674,24 +745,79 @@ describe("OMP agent client and session", () => {
|
||||
},
|
||||
]);
|
||||
await session.setModel?.("openrouter/other/model");
|
||||
expect(session.features).toEqual([
|
||||
expect(session.controls).toEqual([
|
||||
expect.objectContaining({
|
||||
value: true,
|
||||
key: "fast_mode",
|
||||
description: expect.stringMatching(/does not apply/i),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
test("a replacement runtime starts with the Fast the session has now, not the one it opened with", async () => {
|
||||
const omp = new OmpHarness();
|
||||
await omp.start({ modeId: "full", providerOptions: { fast_mode: true } });
|
||||
const session = omp.requireSession();
|
||||
omp.runtime().fastModeResult = { enabled: false, active: false };
|
||||
await session.applyOptions?.({ fast_mode: false });
|
||||
|
||||
await omp.setMode("ask");
|
||||
|
||||
// The approval-mode restart starts a second runtime; it must not turn Fast back on.
|
||||
expect(omp.runtimeLaunches()).toHaveLength(2);
|
||||
expect(omp.runtime().setFastModeRequests).toEqual([]);
|
||||
});
|
||||
|
||||
test("a replacement runtime starts with the Fast the session opened with, not the one it was asked for", async () => {
|
||||
const omp = new OmpHarness();
|
||||
// The fake runtime answers the open-time Fast request with Fast off.
|
||||
await omp.start({ modeId: "full", providerOptions: { fast_mode: true } });
|
||||
expect(omp.requireSession().openOptionsPatch).toEqual({ fast_mode: false });
|
||||
omp.runtime().fastModeResult = { enabled: true, active: true };
|
||||
|
||||
await omp.setMode("ask");
|
||||
|
||||
expect(omp.runtimeLaunches()).toHaveLength(2);
|
||||
expect(omp.runtime().setFastModeRequests).toEqual([]);
|
||||
});
|
||||
|
||||
test("a replacement runtime that refuses the Fast the session had publishes what it accepted", async () => {
|
||||
const omp = new OmpHarness();
|
||||
omp.acceptFastOnNextRuntime();
|
||||
await omp.start({ modeId: "full", providerOptions: { fast_mode: true } });
|
||||
expect(omp.requireSession().openOptionsPatch).toEqual({});
|
||||
|
||||
// The approval-mode restart starts a second runtime, which refuses Fast.
|
||||
await omp.setMode("ask");
|
||||
|
||||
expect(omp.optionsChanges()).toEqual([{ fast_mode: false }]);
|
||||
});
|
||||
|
||||
test("a Fast change the runtime reports when a turn completes is published", async () => {
|
||||
const omp = new OmpHarness();
|
||||
omp.acceptFastOnNextRuntime();
|
||||
await omp.start({ modeId: "full", providerOptions: { fast_mode: true } });
|
||||
omp.runtime().state = { ...omp.runtime().state, fastModeEnabled: false, fastModeActive: false };
|
||||
|
||||
const { completion } = await omp.startPromptUntilProviderIdle("hello", "done", {
|
||||
isStreaming: false,
|
||||
isCompacting: false,
|
||||
});
|
||||
await completion;
|
||||
await omp.requireSession().getRuntimeInfo();
|
||||
|
||||
expect(omp.optionsChanges()).toEqual([{ fast_mode: false }]);
|
||||
});
|
||||
|
||||
test("restores Fast from the initial OMP state on create and resume", async () => {
|
||||
const created = new OmpHarness();
|
||||
await created.start({ featureValues: { fast_mode: true } });
|
||||
await created.start({ providerOptions: { fast_mode: true } });
|
||||
expect(created.runtime().setFastModeRequests).toEqual([true]);
|
||||
expect(created.runtime().getStateRequestCount).toBe(1);
|
||||
|
||||
const resumed = new OmpHarness();
|
||||
await resumed.resume(
|
||||
{ user: { id: "user-1", text: "hello" }, assistant: { id: "assistant-1", text: "hi" } },
|
||||
{ featureValues: { fast_mode: true } },
|
||||
{ providerOptions: { fast_mode: true } },
|
||||
);
|
||||
expect(resumed.runtime().setFastModeRequests).toEqual([true]);
|
||||
expect(resumed.runtime().getStateRequestCount).toBe(1);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ProviderOptions } from "@getpaseo/protocol/agent-types";
|
||||
import { mapCustomMessageToToolCall } from "../custom-message.js";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { existsSync } from "node:fs";
|
||||
@@ -9,7 +10,7 @@ import stripAnsi from "strip-ansi";
|
||||
import {
|
||||
type AgentCapabilityFlags,
|
||||
type AgentClient,
|
||||
type AgentFeature,
|
||||
type AgentOptionControl,
|
||||
type AgentLaunchContext,
|
||||
type AgentMetadata,
|
||||
type AgentMode,
|
||||
@@ -66,9 +67,12 @@ import {
|
||||
resolveOmpLaunchMode,
|
||||
resolveOmpProviderOptions,
|
||||
OMP_MODES,
|
||||
OmpProviderOptionsSchema,
|
||||
type OmpRuntimeOptions,
|
||||
} from "./provider-config.js";
|
||||
export { formatOmpVersionSupport, resolveOmpDiagnosticPaths } from "./provider-config.js";
|
||||
import { applyProviderOptionsPatch } from "../../option-controls.js";
|
||||
import { assertChangesAreLive, validateProviderOptions } from "../../provider-options.js";
|
||||
import { OmpSubagentCardTracker } from "./subagent-card-tracker.js";
|
||||
import { ompSkillPromptUserText, shouldDisplayOmpCustomMessage } from "./custom-message.js";
|
||||
import { getUserMessageText } from "./message-history.js";
|
||||
@@ -750,6 +754,10 @@ export class OmpAgentSession implements AgentSession {
|
||||
this.restartRuntime = options.restartRuntime;
|
||||
this.config = options.config;
|
||||
this.state = options.initialState;
|
||||
this.openOptionsPatch = this.fastModeDifference(options.config.providerOptions?.fast_mode);
|
||||
// A replacement runtime starts from the Fast this one opened with, not the one it was asked for.
|
||||
if (typeof this.openOptionsPatch.fast_mode === "boolean")
|
||||
this.rememberFastMode(this.openOptionsPatch.fast_mode);
|
||||
this.currentModeId = options.currentModeId ?? null;
|
||||
this.logger = options.logger;
|
||||
this.live = options.live ?? true;
|
||||
@@ -804,15 +812,14 @@ export class OmpAgentSession implements AgentSession {
|
||||
return this.state.sessionId;
|
||||
}
|
||||
|
||||
get features(): AgentFeature[] {
|
||||
get controls(): AgentOptionControl[] {
|
||||
if (!hasOmpFastMode(this.state)) return [];
|
||||
return [
|
||||
{
|
||||
type: "toggle",
|
||||
id: "fast_mode",
|
||||
key: "fast_mode",
|
||||
label: "Fast",
|
||||
icon: "zap",
|
||||
value: this.state.fastModeEnabled === true,
|
||||
...(this.state.fastModeEnabled && !this.state.fastModeActive
|
||||
? { description: OMP_FAST_INACTIVE_MESSAGE, tooltip: OMP_FAST_INACTIVE_MESSAGE }
|
||||
: {}),
|
||||
@@ -820,19 +827,50 @@ export class OmpAgentSession implements AgentSession {
|
||||
];
|
||||
}
|
||||
|
||||
async setFeature(featureId: string, value: unknown): Promise<void> {
|
||||
if (featureId !== "fast_mode") throw new Error(`Unknown OMP feature: ${featureId}`);
|
||||
if (typeof value !== "boolean") throw new Error("OMP fast mode requires a boolean");
|
||||
async applyOptions(options: ProviderOptions): Promise<Record<string, unknown>> {
|
||||
assertChangesAreLive({
|
||||
provider: "omp",
|
||||
patch: options,
|
||||
current: this.config.providerOptions,
|
||||
live: ["fast_mode"],
|
||||
});
|
||||
const next = validateProviderOptions(
|
||||
"omp",
|
||||
OmpProviderOptionsSchema,
|
||||
applyProviderOptionsPatch({ options: this.config.providerOptions, patch: options }),
|
||||
);
|
||||
if (options.fast_mode === undefined) return {};
|
||||
const requested = next?.fast_mode ?? false;
|
||||
if (!hasOmpFastMode(this.state)) throw new Error("OMP fast mode is unavailable");
|
||||
const result = await this.runtimeSession.setFastMode(value);
|
||||
this.state = {
|
||||
...this.state,
|
||||
fastModeEnabled: result.enabled,
|
||||
fastModeActive: result.active,
|
||||
};
|
||||
this.config.featureValues = { ...this.config.featureValues, fast_mode: result.enabled };
|
||||
if (requested !== this.state.fastModeEnabled) {
|
||||
const result = await this.runtimeSession.setFastMode(requested);
|
||||
this.state = {
|
||||
...this.state,
|
||||
fastModeEnabled: result.enabled,
|
||||
fastModeActive: result.active,
|
||||
};
|
||||
}
|
||||
if (typeof this.state.fastModeEnabled === "boolean") {
|
||||
this.rememberFastMode(this.state.fastModeEnabled);
|
||||
}
|
||||
return this.fastModeDifference(requested);
|
||||
}
|
||||
|
||||
/** A replacement runtime starts from the Fast the session has now, not the one it opened with. */
|
||||
private rememberFastMode(enabled: boolean): void {
|
||||
this.config.providerOptions = { ...this.config.providerOptions, fast_mode: enabled };
|
||||
}
|
||||
|
||||
/** The option patch when the runtime's fast mode is not what `given` stands for; unset is off. */
|
||||
private fastModeDifference(given: unknown): Record<string, unknown> {
|
||||
if (!hasOmpFastMode(this.state)) return {};
|
||||
const enabled = this.state.fastModeEnabled === true;
|
||||
return (given ?? false) === enabled ? {} : { fast_mode: enabled };
|
||||
}
|
||||
|
||||
/** How the opened session differs from the options it was given. */
|
||||
readonly openOptionsPatch: Record<string, unknown>;
|
||||
|
||||
async run(prompt: AgentPromptInput, options?: AgentRunOptions): Promise<AgentRunResult> {
|
||||
return runProviderTurn({
|
||||
prompt,
|
||||
@@ -1072,7 +1110,7 @@ export class OmpAgentSession implements AgentSession {
|
||||
this.pendingPromptResults.clear();
|
||||
this.runtimeSession = next;
|
||||
this.hostTools = restarted.hostTools;
|
||||
this.state = state;
|
||||
this.installState(state);
|
||||
this.currentModeId = modeId;
|
||||
this.config.modeId = modeId;
|
||||
this.runtimeDead = false;
|
||||
@@ -2210,7 +2248,7 @@ export class OmpAgentSession implements AgentSession {
|
||||
}
|
||||
try {
|
||||
const state = await this.runtimeSession.getState();
|
||||
this.state = state;
|
||||
this.installState(state);
|
||||
if (this.closed || !this.activeTurnStarted || this.currentTurnIdForEvent() !== turnId) {
|
||||
// An interrupt settled this turn while the state check was in flight.
|
||||
return;
|
||||
@@ -2227,7 +2265,22 @@ export class OmpAgentSession implements AgentSession {
|
||||
}
|
||||
|
||||
private async refreshState(): Promise<void> {
|
||||
this.state = await this.runtimeSession.getState();
|
||||
this.installState(await this.runtimeSession.getState());
|
||||
}
|
||||
|
||||
// The runtime owns Fast: whatever it reports is what the session now runs with, so every state
|
||||
// read from the runtime is installed here and a difference is published once.
|
||||
private installState(state: OmpSessionState): void {
|
||||
const before = this.state.fastModeEnabled;
|
||||
this.state = state;
|
||||
if (this.state.fastModeEnabled !== before && typeof this.state.fastModeEnabled === "boolean") {
|
||||
this.rememberFastMode(this.state.fastModeEnabled);
|
||||
this.emit({
|
||||
type: "options_changed",
|
||||
provider: this.provider,
|
||||
patch: { fast_mode: this.state.fastModeEnabled },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async refreshAfterTurn(finalUsage: Promise<void>): Promise<void> {
|
||||
@@ -2295,7 +2348,7 @@ export class OmpAgentClient implements AgentClient {
|
||||
config: AgentSessionConfig,
|
||||
state: OmpSessionState,
|
||||
): Promise<OmpSessionState> {
|
||||
const value = config.featureValues?.fast_mode;
|
||||
const value = config.providerOptions?.fast_mode;
|
||||
if (typeof value !== "boolean" || !hasOmpFastMode(state) || value === state.fastModeEnabled)
|
||||
return state;
|
||||
const result = await runtimeSession.setFastMode(value);
|
||||
@@ -2530,7 +2583,7 @@ export class OmpAgentClient implements AgentClient {
|
||||
}
|
||||
}
|
||||
|
||||
async listFeatures(_config: AgentSessionConfig): Promise<AgentFeature[]> {
|
||||
async listControls(_config: AgentSessionConfig): Promise<AgentOptionControl[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ export { OMP_MODES };
|
||||
|
||||
export const OmpProviderOptionsSchema = z
|
||||
.object({
|
||||
// Composer control, not a runtime option: the session reads it and asks OMP to match.
|
||||
fast_mode: z.boolean().optional(),
|
||||
sessionDir: z.string().min(1).optional(),
|
||||
rpcTimeoutMs: z.number().int().positive().optional(),
|
||||
smolModel: z.string().min(1).optional(),
|
||||
|
||||
@@ -467,6 +467,16 @@ export class OmpHarness {
|
||||
return this.events.map((event) => event.type);
|
||||
}
|
||||
|
||||
acceptFastOnNextRuntime(): void {
|
||||
this.omp.queueSessionSetup((runtime) => {
|
||||
runtime.fastModeResult = { enabled: true, active: true };
|
||||
});
|
||||
}
|
||||
|
||||
optionsChanges(): Record<string, unknown>[] {
|
||||
return this.events.flatMap((event) => (event.type === "options_changed" ? [event.patch] : []));
|
||||
}
|
||||
|
||||
async history(): Promise<AgentTimelineItem[]> {
|
||||
const items: AgentTimelineItem[] = [];
|
||||
for await (const event of this.requireSession().streamHistory()) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { createTestLogger } from "../../../test-utils/test-logger.js";
|
||||
import type { AgentStreamEvent } from "../agent-sdk-types.js";
|
||||
@@ -108,33 +108,22 @@ describe("OpenCode auto_accept feature", () => {
|
||||
expect(modes).toEqual([]);
|
||||
});
|
||||
|
||||
test("lists auto accept as a provider feature", async () => {
|
||||
test("lists auto accept as a provider control", async () => {
|
||||
const { runtime } = mockOpenCodeClient();
|
||||
|
||||
const client = new OpenCodeAgentClient(createTestLogger(), undefined, {
|
||||
serverManager: runtime,
|
||||
createClient: runtime.createClient,
|
||||
});
|
||||
const enabledFeatures = await client.listFeatures({
|
||||
const controls = await client.listControls({
|
||||
provider: "opencode",
|
||||
cwd: "/tmp/project",
|
||||
featureValues: { auto_accept: true },
|
||||
});
|
||||
const legacyFeatures = await client.listFeatures({
|
||||
provider: "opencode",
|
||||
cwd: "/tmp/project",
|
||||
modeId: "full-access",
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
|
||||
expect(enabledFeatures).toEqual([
|
||||
expect.objectContaining({
|
||||
type: "toggle",
|
||||
id: "auto_accept",
|
||||
label: "Auto Accept",
|
||||
value: true,
|
||||
}),
|
||||
expect(controls).toEqual([
|
||||
expect.objectContaining({ type: "toggle", key: "auto_accept", label: "Auto Accept" }),
|
||||
]);
|
||||
expect(legacyFeatures).toEqual([expect.objectContaining({ id: "auto_accept", value: true })]);
|
||||
});
|
||||
|
||||
test("keeps legacy full-access as an alias for build plus auto accept", async () => {
|
||||
@@ -151,7 +140,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
});
|
||||
|
||||
expect(await session.getCurrentMode()).toBe("build");
|
||||
expect(session.features).toEqual([expect.objectContaining({ id: "auto_accept", value: true })]);
|
||||
expect(session.controls).toEqual([expect.objectContaining({ key: "auto_accept" })]);
|
||||
|
||||
await session.run("Implement the change");
|
||||
|
||||
@@ -170,7 +159,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
client.resolveCreateConfig({
|
||||
provider: "opencode",
|
||||
requestedMode: "full-access",
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent: null,
|
||||
unattended: false,
|
||||
availableModes: [
|
||||
@@ -178,7 +167,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
{ id: "plan", label: "Plan" },
|
||||
],
|
||||
}),
|
||||
).toEqual({ modeId: "build", featureValues: { auto_accept: true } });
|
||||
).toEqual({ modeId: "build", providerOptions: { auto_accept: true } });
|
||||
});
|
||||
|
||||
test("inherits unattended callers as auto accept with OpenCode's default agent", () => {
|
||||
@@ -191,7 +180,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
client.resolveCreateConfig({
|
||||
provider: "opencode",
|
||||
requestedMode: undefined,
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent: {
|
||||
provider: "claude",
|
||||
modeId: "bypassPermissions",
|
||||
@@ -203,7 +192,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
{ id: "plan", label: "Plan" },
|
||||
],
|
||||
}),
|
||||
).toEqual({ modeId: undefined, featureValues: { auto_accept: true } });
|
||||
).toEqual({ modeId: undefined, providerOptions: { auto_accept: true } });
|
||||
});
|
||||
|
||||
test("defaults unattended creation without a parent to auto accept with OpenCode's default agent", () => {
|
||||
@@ -213,7 +202,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
client.resolveCreateConfig({
|
||||
provider: "opencode",
|
||||
requestedMode: undefined,
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent: null,
|
||||
unattended: true,
|
||||
availableModes: [
|
||||
@@ -221,7 +210,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
{ id: "plan", label: "Plan" },
|
||||
],
|
||||
}),
|
||||
).toEqual({ modeId: undefined, featureValues: { auto_accept: true } });
|
||||
).toEqual({ modeId: undefined, providerOptions: { auto_accept: true } });
|
||||
});
|
||||
|
||||
test("preserves the selected OpenCode agent when inheriting auto accept from an OpenCode parent", () => {
|
||||
@@ -231,7 +220,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
client.resolveCreateConfig({
|
||||
provider: "opencode",
|
||||
requestedMode: undefined,
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent: {
|
||||
provider: "opencode",
|
||||
modeId: "paseo-custom",
|
||||
@@ -244,7 +233,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
{ id: "paseo-custom", label: "Paseo Custom" },
|
||||
],
|
||||
}),
|
||||
).toEqual({ modeId: "paseo-custom", featureValues: { auto_accept: true } });
|
||||
).toEqual({ modeId: "paseo-custom", providerOptions: { auto_accept: true } });
|
||||
});
|
||||
|
||||
test("inherits auto accept from an OpenCode parent when the child chooses a mode", () => {
|
||||
@@ -254,7 +243,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
client.resolveCreateConfig({
|
||||
provider: "opencode",
|
||||
requestedMode: "base",
|
||||
featureValues: undefined,
|
||||
providerOptions: undefined,
|
||||
parent: {
|
||||
provider: "opencode",
|
||||
modeId: "orchestrator",
|
||||
@@ -267,7 +256,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
{ id: "orchestrator", label: "Orchestrator" },
|
||||
],
|
||||
}),
|
||||
).toEqual({ modeId: "base", featureValues: { auto_accept: true } });
|
||||
).toEqual({ modeId: "base", providerOptions: { auto_accept: true } });
|
||||
});
|
||||
|
||||
test("auto-approves tool permissions when auto accept is enabled", async () => {
|
||||
@@ -283,7 +272,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
const session = await client.createSession({
|
||||
provider: "opencode",
|
||||
cwd: "/tmp/project",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
session.subscribe((event) => receivedEvents.push(event));
|
||||
|
||||
@@ -301,6 +290,72 @@ describe("OpenCode auto_accept feature", () => {
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("rejects a live auto_accept the creation schema would reject, and keeps approving", async () => {
|
||||
const { openCodeClient, runtime } = mockOpenCodeClient({
|
||||
events: [toolPermissionEvent(), idleEvent()],
|
||||
});
|
||||
const client = new OpenCodeAgentClient(createTestLogger(), undefined, {
|
||||
serverManager: runtime,
|
||||
createClient: runtime.createClient,
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "opencode",
|
||||
cwd: "/tmp/project",
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
|
||||
await expect(session.applyOptions?.({ auto_accept: "yes" })).rejects.toThrow(/auto_accept/);
|
||||
await session.run("Run verification");
|
||||
|
||||
expect(openCodeClient.calls.permissionReply).toHaveLength(1);
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("rejects a live permission change the running session cannot apply", async () => {
|
||||
const { runtime } = mockOpenCodeClient({ events: [idleEvent()] });
|
||||
const client = new OpenCodeAgentClient(createTestLogger(), undefined, {
|
||||
serverManager: runtime,
|
||||
createClient: runtime.createClient,
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "opencode",
|
||||
cwd: "/tmp/project",
|
||||
providerOptions: { permission: "allow" },
|
||||
});
|
||||
|
||||
await expect(session.applyOptions?.({ permission: "deny" })).rejects.toThrow(
|
||||
/permission.*cannot change on a running session/,
|
||||
);
|
||||
await expect(
|
||||
session.applyOptions?.({ permission: "allow", auto_accept: true }),
|
||||
).resolves.toBeUndefined();
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("stops auto-approving once auto_accept is removed", async () => {
|
||||
const { openCodeClient, runtime } = mockOpenCodeClient({
|
||||
events: [toolPermissionEvent(), idleEvent()],
|
||||
});
|
||||
|
||||
const client = new OpenCodeAgentClient(createTestLogger(), undefined, {
|
||||
serverManager: runtime,
|
||||
createClient: runtime.createClient,
|
||||
});
|
||||
const session = await client.createSession({
|
||||
provider: "opencode",
|
||||
cwd: "/tmp/project",
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
|
||||
await session.applyOptions?.({ auto_accept: null });
|
||||
await session.startTurn("Run verification");
|
||||
await vi.waitFor(() => expect(session.getPendingPermissions()).toHaveLength(1));
|
||||
|
||||
expect(openCodeClient.calls.permissionReply).toHaveLength(0);
|
||||
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("keeps questions separate from auto accept tool approval", async () => {
|
||||
const { openCodeClient, runtime } = mockOpenCodeClient({
|
||||
events: [questionEvent(), idleEvent()],
|
||||
@@ -314,7 +369,7 @@ describe("OpenCode auto_accept feature", () => {
|
||||
const session = await client.createSession({
|
||||
provider: "opencode",
|
||||
cwd: "/tmp/project",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
session.subscribe((event) => receivedEvents.push(event));
|
||||
|
||||
|
||||
@@ -5274,7 +5274,7 @@ describe("OpenCode provider subagent contract", () => {
|
||||
const parent = await client.createSession({
|
||||
provider: "opencode",
|
||||
cwd: "/workspace/repo",
|
||||
featureValues: { auto_accept: true },
|
||||
providerOptions: { auto_accept: true },
|
||||
});
|
||||
parent.subscribe(() => undefined);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user