Repository navigation
Read an unknown plan as beta #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -295,7 +295,14 @@ def _from_value_expr(base: str, var: str, enums: set[str], objects: set[str]) -> | |||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def _emit_enum(name: str, schema: dict) -> str: | ||||||||||||
| values = schema["enum"] | ||||||||||||
| values = list(schema["enum"]) | ||||||||||||
| # The server's CliPlan is still only "beta". A released CLI that rejects | ||||||||||||
| # any other string fails login the moment the api sends a coding-plan | ||||||||||||
| # value. This client knows "coding_plan" and reads every other string as | ||||||||||||
| # beta, so the next plan name does not break this build. | ||||||||||||
| tolerant = name == "CliPlan" | ||||||||||||
| if tolerant and "coding_plan" not in values: | ||||||||||||
| values.append("coding_plan") | ||||||||||||
| variants = [(v, _enum_variant(v)) for v in values] | ||||||||||||
|
|
||||||||||||
| lines = ["#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]"] | ||||||||||||
|
|
@@ -315,14 +322,19 @@ def _emit_enum(name: str, schema: dict) -> str: | |||||||||||
| lines.append(" }") | ||||||||||||
| lines.append("") | ||||||||||||
| # Rejects an unknown value rather than silently defaulting -- the same | ||||||||||||
| # posture as the from_json this replaces. | ||||||||||||
| # posture as the from_json this replaces. CliPlan is the exception: an | ||||||||||||
| # unknown plan is beta, so a plan name this build does not know yet still | ||||||||||||
| # parses the grant, the identity, and the login poll. | ||||||||||||
| lines.append(" pub fn parse(raw: &str) -> Result<Self, String> {") | ||||||||||||
| lines.append(" match raw {") | ||||||||||||
| for v, variant in variants: | ||||||||||||
| lines.append(f' "{v}" => Ok({name}::{variant}),') | ||||||||||||
| lines.append( | ||||||||||||
| f' other => Err(format!("unknown {name}: {{other}}")),' | ||||||||||||
| ) | ||||||||||||
| if tolerant: | ||||||||||||
| lines.append(f" _other => Ok({name}::{variants[0][1]}),") | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Select the beta fallback independently of enum order. If Emit
|
||||||||||||
| lines.append(f" _other => Ok({name}::{variants[0][1]}),") | |
| beta = dict(variants).get("beta") | |
| if beta is None: | |
| raise SystemExit("CliPlan must list beta: unknown plans parse as beta") | |
| lines.append(f" _other => Ok({name}::{beta}),") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,39 @@ use crate::cli_formatter::{cli_color, color_output_enabled, examples_footer, Exa | |
| use crate::config::preferences::{self, DefaultModelSource}; | ||
| use crate::io::output as out; | ||
|
|
||
| /// The one model a coding-plan account's keyed list names, when the server | ||
| /// has cut that list to a single id. A longer list is left alone: the CLI | ||
| /// does not filter it and does not hardcode a model id. | ||
| fn coding_plan_model() -> Option<String> { | ||
| let credentials = crate::account::load().ok()?; | ||
| if credentials.plan != crate::account::console_contract::CliPlan::KCodingPlan.as_str() | ||
| || !credentials.signed_in() | ||
| { | ||
| return None; | ||
| } | ||
| let console = crate::account::ConsoleClient::default(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Prompt for AI agents |
||
| let (result, models, _) = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This blocking Prompt for AI agents |
||
| console.fetch_models(&credentials.console_url, &credentials.access_token); | ||
|
Comment on lines
+21
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refresh the session before the coding-plan model lookup.
For a signed-in coding-plan account with an expired access token, a launch without
|
||
| if result != crate::account::IdentityResult::Ok || models.len() != 1 { | ||
| return None; | ||
| } | ||
| let id = models.into_iter().next()?.id; | ||
| if !crate::harness::model_id_is_safe(&id) { | ||
| return None; | ||
| } | ||
| Some(id) | ||
| } | ||
|
|
||
| /// The model a harness launch should use: `explicit_model` when given, else the | ||
| /// effective default (env, file, then the built-in id — see config::preferences). | ||
| /// single model on a coding-plan account, else the effective default (env, | ||
| /// file, then the built-in id — see config::preferences). | ||
| /// Prints a blue notice when a default fills in for an omitted `-m`. | ||
| pub fn resolve_default_model(explicit_model: &str, no_color: bool) -> String { | ||
| let effective = preferences::resolve_model(explicit_model); | ||
| let effective = if explicit_model.is_empty() { | ||
| coding_plan_model().unwrap_or_else(|| preferences::resolve_model(explicit_model)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make If a coding-plan account returns only Share effective-default selection with the inspection command and report the correct source. Preserve preferences reporting when no coding-plan model is selected.
|
||
| } else { | ||
| preferences::resolve_model(explicit_model) | ||
| }; | ||
| // Announce only when a default filled in for an omitted -m, so the launch | ||
| // never silently picks a model the reader did not name. Blue, so it reads | ||
| // as a notice rather than an error or an ordinary status line. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -109,6 +109,9 @@ pub(crate) fn refresh_session( | |||||||||
| } else { | ||||||||||
| 3600 | ||||||||||
| }; | ||||||||||
| if !grant.plan.is_empty() { | ||||||||||
| credentials.plan = grant.plan; | ||||||||||
| } | ||||||||||
|
Comment on lines
+112
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: This Prompt for AI agents
Suggested change
|
||||||||||
| account::save(credentials).map_err(|message| SessionError { | ||||||||||
| message, | ||||||||||
| unverified: false, | ||||||||||
|
|
@@ -152,6 +155,13 @@ pub fn verify_cloud_session( | |||||||||
| unverified: result == account::IdentityResult::Unavailable, | ||||||||||
| }); | ||||||||||
| } | ||||||||||
| // The plan is read on the next launch. Saving it here means a coding-plan | ||||||||||
| // subscription shows up without another login. A failed save leaves the | ||||||||||
| // session usable; the plan stays what it was. | ||||||||||
| if credentials.plan != identity.plan { | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The new plan persistence in Prompt for AI agents |
||||||||||
| credentials.plan = identity.plan; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This updates the saved plan only after the launch has already selected its default model. A newly upgraded coding-plan account therefore uses the ordinary default on its first launch; verify or refresh the plan before resolving the omitted model, then use that plan for the same launch. Prompt for AI agents |
||||||||||
| let _ = account::save(credentials); | ||||||||||
| } | ||||||||||
| Ok(identity.email) | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3:
coding_planis hardcoded here rather than coming from the contract. The pinnedCliPlanenum still lists onlybeta, so the generated binding defines a variant the contract does not. AGENTS.md treats the contract as the source of truth, andmerge_legacyis the existing path for values the pinned contract lacks. Carrycoding_planthrough the contract or the legacy merge instead.Prompt for AI agents