From cd1eb066c0ae7abec705422d27c04cfc36d2e45d Mon Sep 17 00:00:00 2001 From: zhoushoujian Date: Fri, 13 Nov 2026 11:12:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(agent):=20=E9=BB=98=E8=AE=A4=E9=81=B5?= =?UTF-8?q?=E5=BE=AA=E5=B7=B2=E9=85=8D=E7=BD=AE=20profile=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=9A=8F=E6=9C=BA=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++-- docs/guide.md | 16 +++--- internal/agentinstall/install.go | 6 +-- internal/agentinstall/install_test.go | 21 ++++++++ skills/offload/SKILL.md | 78 ++++++++------------------- 5 files changed, 58 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index d2d2b2e..3d716a9 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ brief instead of spawning a native subagent. The worker starts with a clean context, so nothing leaks between it and the main conversation, and only its final report comes back. The main agent keeps design decisions and final review. -- **Any model per task:** pick a profile by its `use_for` hint, then override the - model, reasoning effort or fast mode for one run (`-m`, `-effort`, `-fast`). +- **Default profile first:** new runs inherit `OFFLOAD_PROFILE` or the configured + default; explicit per-run overrides remain available when requested or required. - **Two backends:** Codex CLI and Claude Code with Anthropic-compatible gateways. - **Named profiles:** a model, provider or managed Codex account, with an optional hint about which tasks it suits. - **Persistent sessions:** resume related work and inspect previous reports. @@ -82,9 +82,9 @@ backup. Only Codex's file credential store is supported (verified with Codex CLI 0.167.0). Sharing the file does not serialize concurrent network token refreshes; avoid refreshing the same account concurrently in multiple clients. -The [agent skill](skills/offload/SKILL.md) explains random account selection and -bounded failover on quota errors. This selection happens in the supervising -agent; a CLI call without `-p` still uses the configured default. +The [agent skill](skills/offload/SKILL.md) tells supervising agents to omit `-p` +and use the active default. Compatible account fallbacks are used only when the +user requests or authorizes them; quota errors never trigger silent rotation. [Account setup and routing details →](docs/guide.md#managed-codex-accounts) ## Agent integration diff --git a/docs/guide.md b/docs/guide.md index 484bb5c..dbad77a 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -93,7 +93,7 @@ OFFLOAD_PROFILE=deepseek offload -d /absolute/path/app "Find retry entry points, #### Disable or delete a profile -Disable a profile to keep it but stop every use of it. A disabled profile is skipped for default and pool selection, reports `"disabled": true` and `"available": false` in `offload profiles --json`, and any run on it fails before a worker starts, including `-p`, `OFFLOAD_PROFILE`, resumes and scheduled runs. The configured default cannot be disabled; choose another default first. +Disable a profile to keep it but stop every use of it. A disabled profile is skipped for default selection, reports `"disabled": true` and `"available": false` in `offload profiles --json`, and any run on it fails before a worker starts, including `-p`, `OFFLOAD_PROFILE`, resumes and scheduled runs. The configured default cannot be disabled; choose another default first. ```sh offload profile disable codex-old @@ -108,7 +108,7 @@ offload profile delete codex-old --account # also remove its managed Codex acc `-m` overrides the selected profile's model for that run. `-effort ` overrides its reasoning effort (`low`, `medium`, `high`, `xhigh`, `max`; Codex also accepts `ultra`). On Codex profiles, `-fast` selects the priority service tier and `-fast=false` the default tier; Claude profiles reject `-fast`. Overrides apply to that run only, including a resume, and never change the saved profile. -A profile may carry an optional `use_for` hint (up to 300 characters, one line), such as "frontend/UI work" or "bulk log reading". `offload profiles --json` returns it so agents can choose a profile by task, the way they would choose a subagent's model. Set it in the macOS profile editor or with `offload profile save --json`: +A profile may carry optional descriptive `use_for` metadata (up to 300 characters, one line), such as "frontend/UI work" or "bulk log reading". `offload profiles --json` returns it for user context, but installed agent guidance does not let it override a usable active default. Set it in the macOS profile editor or with `offload profile save --json`: ```sh offload profile save --json <<'JSON' @@ -206,7 +206,7 @@ Codex's current skill locations are documented in [Build skills](https://learn.c ### Main agent and subagent workflow -The installed policy positions offload as the replacement for native subagents: for any clearly specified task that does not need the conversation, the main agent runs offload with a self-contained brief instead of spawning a subagent, picks the profile by its `use_for` hint, and overrides model, effort or fast mode per run. A native subagent remains only for work that needs the forked conversation or host-only tools (browser, MCP or app tools), and as the Codex result waiter. The policy also asks main agents and native subagents to actually invoke offload before doing substantial bounded supporting work themselves, according to the active delegation mode. In **proactive** mode this includes bounded implementation once the design is decided; in **basic** mode it mainly covers research, localization, summaries, and bounded mechanical edits, without proactively handing off a whole feature's implementation. In both modes, the main agent owns requirements, architecture/design, tradeoffs, task decomposition, and final review/acceptance. If a worker finds the design, scope, or architecture needs to change, it reports findings/options back instead of redesigning on its own. Call the CLI directly and avoid duplicating work an active worker is already doing. Run parallel slices as several background offload runs, and an independent review on a different profile. When a native subagent is still used, it can launch the external worker: +The installed policy positions offload as the replacement for native subagents: for any clearly specified task that does not need the conversation, the main agent runs offload with a self-contained brief instead of spawning a subagent. New runs normally omit profile/model/effort/tier flags and inherit `OFFLOAD_PROFILE` or the configured default; `use_for` is descriptive only. Overrides require an explicit user request, concrete task incompatibility, or verified default failure with an authorized compatible fallback, and the agent states the reason. It never randomly rotates accounts, silently changes provider/model, or automatically enables or edits an unavailable default. A native subagent remains only for work that needs the forked conversation or host-only tools (browser, MCP or app tools), and as the Codex result waiter. The policy also asks main agents and native subagents to actually invoke offload before doing substantial bounded supporting work themselves, according to the active delegation mode. In **proactive** mode this includes bounded implementation once the design is decided; in **basic** mode it mainly covers research, localization, summaries, and bounded mechanical edits, without proactively handing off a whole feature's implementation. In both modes, the main agent owns requirements, architecture/design, tradeoffs, task decomposition, and final review/acceptance. If a worker finds the design, scope, or architecture needs to change, it reports findings/options back instead of redesigning on its own. Call the CLI directly and avoid duplicating work an active worker is already doing. Run parallel slices as several background offload runs. Independent review starts a fresh session on the default; a different profile/model is used only when explicitly requested or concretely required. When a native subagent is still used, it can launch the external worker: ```text Main agent → optional native subagent → offload → selected Claude/Codex profile @@ -930,11 +930,11 @@ sign-in when both the original installation and offload will remain active. Profiles with no account selection continue to use the system Codex account. Managed runs isolate authentication, session/model lookup and usage accounting. Resume keeps the recorded account and home even after profile edits. This -version provides explicit account selection. The bundled agent skill also explains -how an agent can choose a random compatible account when none is specified and -try another account on confirmed quota/capacity failures. Selection and bounded -failover are performed by the supervising agent using `-p`; the CLI itself still -uses the configured default when `-p` is omitted. Resumes stay bound to their +version provides explicit account selection. The bundled agent skill tells agents +to omit `-p` when no account is specified, so `OFFLOAD_PROFILE` or the configured +default remains authoritative. A compatible fallback account is selected only +when the user requests or authorizes it after a concrete incompatibility or verified +failure; there is no random or proactive rotation. Resumes stay bound to their original account, so switching accounts starts a new session and must account for any partial effects. Managed homes start with Codex defaults and do not copy the system home's skills, MCP configuration or other settings. diff --git a/internal/agentinstall/install.go b/internal/agentinstall/install.go index 72a4e6a..d1cb3d3 100644 --- a/internal/agentinstall/install.go +++ b/internal/agentinstall/install.go @@ -43,11 +43,11 @@ const offloadAgentPolicy = offloadPolicyBegin + ` ` + offloadPolicyEnd // subagentPolicy positions offload as the replacement for native subagents in both modes. -const subagentPolicy = `- Use offload in place of a native subagent for any clearly specified task that does not need your conversation: research, localization, review, implementation slices, checks. The worker starts with a clean context, so nothing from your conversation leaks in or out, and you choose its model per task. Parallel work means several background offload runs; an independent review means an offload run on another profile. Keep a native subagent only when the task needs your forked conversation, needs host-only tools the worker lacks (browser, MCP or app tools), or is the Codex result waiter. -- Choose the worker like a subagent: read offload profiles --json, skip profiles that are unavailable or disabled, pick the one whose use_for hint fits the task (else the configured default), and override per run with -m , -effort and, on Codex profiles only, -fast or -fast=false. Overrides affect only that run and never change the saved profile. Do not invent profile names.` +const subagentPolicy = `- Use offload in place of a native subagent for any clearly specified task that does not need your conversation: research, localization, review, implementation slices, checks. The worker starts with a clean context, so nothing from your conversation leaks in or out. Parallel work means several background offload runs. Independent review starts a fresh session on the active default; use a different profile/model only when explicitly requested or concretely required for independence, and state why. Keep a native subagent only when the task needs your forked conversation, needs host-only tools the worker lacks (browser, MCP or app tools), or is the Codex result waiter. +- For new runs, normally omit -p, -m, -effort and -fast so offload inherits an explicit OFFLOAD_PROFILE or the configured default and its settings. The use_for field is descriptive metadata and must not override a usable default. Never randomly choose or proactively rotate profiles/accounts, and never silently change provider, model, effort or tier. Override only for an explicit user request, a concrete task incompatibility, or a verified default failure with a user-authorized compatible fallback; explain the reason. If the default is unavailable or disabled, report the concrete failure instead of testing, enabling, editing or replacing it automatically. Do not invent profile names.` // sessionReusePolicy is shared by both modes so the installed workflow stays identical. -const sessionReusePolicy = `- Reuse one worker session for related work: investigation, implementation, and review corrections of the same task or slice should use offload -r (it keeps the original profile and directory). Each follow-up still states the current corrections and acceptance criteria, because backend compaction means history is not unlimited or verbatim. Start a new session for unrelated tasks, a different directory or profile, or stale context; do not reuse one session for every task. Never send overlapping runs to one session. Inspect an interrupted run (offload show , git diff) before continuing, and keep its partial edits. If the session's profile no longer exists, restore it or start a new session with -p; offload never switches providers silently. +const sessionReusePolicy = `- Reuse one worker session for related work: investigation, implementation, and review corrections of the same task or slice should use offload -r without selection overrides (it keeps the original profile/account and directory). Each follow-up still states the current corrections and acceptance criteria, because backend compaction means history is not unlimited or verbatim. Start a new session for unrelated tasks, a different explicitly requested/required profile, or stale context; do not reuse one session for every task. Never send overlapping runs to one session. Inspect an interrupted run (offload show , git diff) before continuing, and keep its partial edits. If the session's profile no longer exists, restore it or start a user-authorized new session with -p; offload never switches providers silently. - Dispatch is parallel work: the offload command blocks until its worker ends, so start it in the background and keep doing independent work (not the worker's files, not anything that needs its result) instead of waiting; collect its exit status and report before relying on it. In Claude Code, Bash run_in_background notifies you when it exits. In Codex, start the run inside a waiter subagent (spawn_agent, fork_turns "none", cheapest model, low effort; it cannot reach a run you started yourself) that keeps the exec session_id, waits on it with 30-second waits, never guesses an id or relaunches, recovers a lost handle with offload status and offload show, and returns stdout verbatim; its final answer arrives automatically at your next tool call, so call wait_agent only when nothing independent is left. - Cut parent polling: run long workers in the background and wait with offload watch -t under the host's completion or monitor facility, rather than repeated short status checks; without one, use a few long bounded waits. STALLED, LOST, timeout, and failures still surface, and waiting must not open or control the user's desktop. Delegate a coherent slice and then inspect targeted evidence or diffs and run scoped checks instead of repeating the worker's investigation. Ask for compact reports (outcome, changed files or key references, checks, unresolved issues); offload show has the full history.` diff --git a/internal/agentinstall/install_test.go b/internal/agentinstall/install_test.go index 1f394c4..244766c 100644 --- a/internal/agentinstall/install_test.go +++ b/internal/agentinstall/install_test.go @@ -394,3 +394,24 @@ func TestSessionReuseWorkflowAgreesAcrossPolicySkillAndGuide(t *testing.T) { t.Error("both modes must carry the shared session reuse policy") } } + +func TestDefaultProfileFirstGuidanceAcrossModesAndEmbeddedSkill(t *testing.T) { + docs := map[string]string{ + "skill": string(skills.Offload), + "policy-basic": policyForMode(config.ModeBasic), + "policy-proactive": policyForMode(config.ModeProactive), + } + for name, doc := range docs { + doc = strings.ReplaceAll(doc, "`", "") + for _, want := range []string{"omit -p", "OFFLOAD_PROFILE", "configured default", "use_for", "descriptive", "explicit user request", "concrete task incompatibility", "verified default failure", "user-authorized compatible fallback", "Never randomly", "never silently change", "unavailable or disabled", "without selection overrides", "original profile/account"} { + if !strings.Contains(doc, want) { + t.Errorf("%s missing default-first boundary %q", name, want) + } + } + for _, forbidden := range []string{"pick the one whose use_for", "agent-selected random", "may randomly choose", "shuffled order", "independent review means an offload run on another profile"} { + if strings.Contains(doc, forbidden) { + t.Errorf("%s contains obsolete profile-selection guidance %q", name, forbidden) + } + } + } +} diff --git a/skills/offload/SKILL.md b/skills/offload/SKILL.md index 850c2fd..d6f6c3a 100644 --- a/skills/offload/SKILL.md +++ b/skills/offload/SKILL.md @@ -1,6 +1,6 @@ --- name: offload -description: Use the offload CLI in place of a native subagent for clearly specified tasks that do not need the conversation, choosing the model, reasoning effort and fast mode per task. Follows the active delegation mode (basic or proactive). Supports explicit account profiles and agent-selected random account-pool routing with bounded quota failover. Both modes keep design decisions and final acceptance with the supervising agent; proactive mode additionally delegates bounded feature/bugfix implementation once the design is decided. +description: Use the offload CLI in place of a native subagent for clearly specified tasks that do not need the conversation, inheriting OFFLOAD_PROFILE or the configured default unless the user requests an override, the task is concretely incompatible, or an authorized fallback follows a verified failure. Follows the active delegation mode (basic or proactive). Both modes keep design decisions and final acceptance with the supervising agent; proactive mode additionally delegates bounded feature/bugfix implementation once the design is decided. --- # offload @@ -21,73 +21,42 @@ For Claude profiles, the CLI starts an external `claude -p --bare` worker on the ## Use offload instead of a native subagent -Treat an offload run as a subagent that starts with a clean context and runs on the model you choose. Whenever you would spawn a native subagent for a clearly specified task that does not need your conversation, such as research, code localization, a review, an implementation slice or a check, use offload instead. Nothing from your conversation leaks into the worker, and only its final report comes back into yours. +Treat an offload run as a subagent that starts with a clean context and normally runs on the active default profile. Whenever you would spawn a native subagent for a clearly specified task that does not need your conversation, such as research, code localization, a review, an implementation slice or a check, use offload instead. Nothing from your conversation leaks into the worker, and only its final report comes back into yours. - **Parallel work:** start several offload runs in the background, one per independent slice, instead of several native subagents. -- **Independent review:** run the review on a different profile or model from the one that wrote the change. +- **Independent review:** start a fresh session on the active default profile. Use a different profile or model only when the user explicitly requests it or independence requires a concretely different provider/model, and state that reason. - **Keep a native subagent only** when the task needs your forked conversation, needs host-only tools the worker lacks (browser, MCP or app tools), or is the Codex result waiter (see Follow a running worker). Because the worker cannot see your conversation, its brief must stand alone: absolute `-d`, objective, decided design, allowed files, checks and report format (see Assign a bounded task). -## Choose the profile and settings per task +## Use the active default profile first -Pick the worker the way you would pick a subagent's model: +For a new run, normally omit `-p`, `-m`, `-effort`, and `-fast`. A bare `offload "task"` inherits an explicit `OFFLOAD_PROFILE` first, then the configured default and that profile's model, reasoning effort, and service tier. -1. Run `offload profiles --json`. Each profile shows its `backend`, `model`, `reasoning_effort`, `service_tier`, availability and an optional `use_for` hint written by the user, such as "frontend/UI work" or "bulk log reading". -2. Choose the available profile (`available: true`, so not failed or disabled) whose `use_for` fits the task. When no hint fits, use the configured default, or the account-pool rules below for interchangeable Codex accounts. A profile the user names always wins. -3. Override settings for this run only when the task needs it: +Use `offload profiles --json` to inspect the active selection or diagnose a failure, not to rotate among usable profiles. Its optional `use_for` field is descriptive metadata; it must not override a usable active default. Never randomly choose or proactively rotate profiles or accounts, and never silently change provider, model, effort, or tier. + +Override only for an explicit user request, a concrete task incompatibility, or a verified default failure with a user-authorized compatible fallback. Explain the reason whenever you override: + + - `-p ` selects an explicit profile for the run. - `-m ` replaces the profile's model. - `-effort ` sets reasoning effort: `low`, `medium`, `high`, `xhigh`, `max` on both backends, plus `ultra` on Codex. Use a lower effort for lookups and summaries and a higher one for tricky debugging or design-sensitive implementation. - `-fast` uses the fast (priority) service tier and `-fast=false` the default tier. Codex profiles only; a Claude profile rejects it. -Overrides apply to that run, including a `-r` resume, and never change the saved profile. Users set `use_for` in the App's profile editor or with `offload profile save --json` (`{"name": "...", "use_for": "..."}`). +Overrides apply to that run and never change the saved profile. A known `-r` resume runs without selection overrides and retains its original profile/account identity by default; do not migrate it. If a different profile/account is required, start a new session and carry forward only the task and verified findings. Users set descriptive `use_for` metadata in the App's profile editor or with `offload profile save --json` (`{"name": "...", "use_for": "..."}`). -## Account pool: choose a profile before dispatch +## Compatible accounts and authorized fallback -A pool is the set of compatible, configured account profiles, not a shared login. -Each managed Codex profile has a `codex_account`; choosing `-p ` selects that -account's private home, credentials and sessions. Discover names with -`offload profiles --json`; never invent profile names or read tokens to select one. +Each managed Codex profile has a `codex_account`; an explicitly authorized `-p ` selects that account's private home, credentials and sessions. Discover names with `offload profiles --json`; never invent profile names or read tokens to select one. - If the user names a profile/account, use it. If the user authorizes several, - choose only among those. Respect an explicit `OFFLOAD_PROFILE` unless pool - selection was requested. Preserve requested backend, model, tier and tool + choose only among those. Respect an explicit `OFFLOAD_PROFILE`. Preserve + requested backend, model, tier and tool restrictions; do not silently substitute Claude for Codex or change models. -- If the user leaves the account unspecified, the supervising agent may randomly - choose a compatible managed Codex profile and pass its name with `-p`. - Deduplicate candidates by `codex_account`, so aliases/profiles for the same - account do not get extra weight. Shuffle candidates once per independent task. - If there are no managed candidates, use the configured default normally. -- This randomness is **agent-side selection**: a bare `offload "task"` still uses - `OFFLOAD_PROFILE` or the saved default. The CLI has no automatic pool scheduler. - Do not change the saved default merely to dispatch one task. -- Profiles with `"available": false` (see `unavailable_reason` and `unavailable_at`) failed with an unrecoverable error such as bad credentials, exhausted quota or a missing model. Never pick them at random and never use them as the default; run `offload profile test ` to re-test one, which restores it on success. An explicit `-p` still runs the named profile. +- If the user leaves the account unspecified, omit `-p` and use the active default. + Do not proactively distribute work across accounts or rotate profiles. +- Profiles with `"available": false` (see `unavailable_reason` and `unavailable_at`) failed with an unrecoverable error such as bad credentials, exhausted quota or a missing model. If the active default is unavailable or disabled, report the concrete failure unless the user authorizes a compatible fallback. Do not automatically test, enable, edit, or replace it. - Profiles with `"disabled": true` were switched off by the user and also report `"available": false`. Never choose them; every run on one fails, including an explicit `-p` or a resume. Only the user re-enables them (`offload profile enable `), so do not enable, delete or edit profiles on your own. -- The profile catalog proves configuration, not remaining quota. Exclude accounts - already known to be exhausted until their reported reset, and accounts with - unresolved authentication errors. Treat an untested account as unknown, not - confirmed available; the real task determines availability. Do not send paid - quota probes before every dispatch. - -For a Codex task without an account preference, this discovery command returns -one random profile per managed account (filter for the task's requested settings -before dispatch): - -```sh -offload profiles --json | python3 -c ' -import json, random, sys -profiles = json.load(sys.stdin)["profiles"] -random.SystemRandom().shuffle(profiles) -seen = set() -for p in profiles: - account = p.get("codex_account") - if p["backend"] == "codex" and account and p.get("available", True) and account not in seen: - seen.add(account) - print(p["name"]) -' -# Choose a compatible candidate from that order, then: -offload -p -json -d /absolute/path "bounded task" -``` +- The profile catalog proves configuration, not remaining quota. Do not send paid quota probes before every dispatch. ### Quota and capacity failover @@ -99,11 +68,7 @@ the provider error too. A successful report mentioning limits is not a failure. Authentication failures need reauthentication; syntax, permission and task failures are not reasons to rotate accounts. -When quota/capacity blocks a task and the user has not restricted it to one account, -select the next compatible account from the shuffled order. Try each account at -most once for that task; stop when one succeeds or all candidates are exhausted. -Remember reported reset times and skip exhausted accounts during the current work. -Do not assume quota exhaustion means another model on the same account is usable. +When quota/capacity blocks the active default, report the concrete failure. Retry on a compatible account only when the user has already authorized fallback accounts or explicitly requests one after the failure. Preserve the requested provider/model/tier and try only authorized compatible profiles, at most once each for that task. Do not assume quota exhaustion means another model on the same account is usable. A different account requires a **new session** with `-p `, not `-r `. Carry forward the objective and verified findings. Before @@ -111,8 +76,7 @@ retrying, inspect the failed run and any partial effects. Read-only tasks can usually be retried; for writes or external actions, identify completed effects and dispatch only the remaining work. If the outcome is uncertain, report the blocker rather than replaying the task. Never rerun a completed external mutation. -If a single account was explicitly required, report its quota failure and obtain -an alternative account choice instead of silently switching. +If fallback was not authorized, obtain an alternative account choice instead of silently switching. Report attempted profiles, account names, sessions, failure/reset evidence and final result. Keep failed attempts in history; do not present a fallback's success