t3-auto-build 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/probe.mjs CHANGED
@@ -4,10 +4,10 @@ import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import { isDeepStrictEqual } from 'node:util';
6
6
  import {
7
- CONFIG_FILE, COOLDOWN_FILE, cliModelId, effectiveAllowlist, isBanned, isObject, isStringList, normalizeName,
8
- readJson, run, which as findOnPath,
7
+ canonicalProvider, CONFIG_FILE, COOLDOWN_FILE, cliModelId, effectiveAllowlist, isBanned, isObject, isStringList,
8
+ readJson, resolveTarget, run, which as findOnPath,
9
9
  } from '../hooks/_shared.mjs';
10
- import { parseRateLimit, readCooldowns, writeCooldowns } from '../hooks/_quota.mjs';
10
+ import { isLocked, parseRateLimit, readCooldowns, writeCooldowns } from '../hooks/_quota.mjs';
11
11
  import { HEAVY_MODELS } from './detect.mjs';
12
12
  import { CliError, PACKAGE_ROOT } from './paths.mjs';
13
13
  import { completeConfig, configProblem, syncConfig } from './install.mjs';
@@ -79,21 +79,42 @@ const wantedProviders = (providers) => {
79
79
  function cooldownFor(provider, model, id, text, config, now) {
80
80
  const tier = config.tiers?.[provider];
81
81
  const limit = parseRateLimit(text, { now, sharing: tier?.sharing, resetDay: tier?.resetDay });
82
+ const target = resolveTarget({ providers: [provider], model }, config);
82
83
  let { scope } = limit;
83
- // A heavy-tier lock would not cover a light model that was just refused, so lock that model itself.
84
- const heavy = isStringList(tier?.heavyModels) ? tier.heavyModels : HEAVY_MODELS[provider];
85
- if (scope === 'tier' && !heavy.some((name) => normalizeName(name) === normalizeName(model))) scope = 'model';
86
- const key = { model: `model:${id}`, provider: `provider:${provider}`, tier: `tier:${provider}:heavy` }[scope];
84
+ let pool = 'heavy';
85
+ if (target.pool !== 'standard') {
86
+ // A capped pool has its own quota: its limit must not lock the rest of the provider.
87
+ pool = target.pool;
88
+ if (scope !== 'model') scope = 'tier';
89
+ } else if (scope === 'tier') {
90
+ // A heavy-tier lock would not cover a light model that was just refused, so lock that model itself.
91
+ const heavy = { [`tier:${provider}:heavy`]: { until: limit.until } };
92
+ if (!isLocked(heavy, { provider, model, config }, now)) scope = 'model';
93
+ }
94
+ // A v2 entry names the hosting that refused, so the same model hosted elsewhere stays usable.
95
+ const modelKey = target.entry ? `model:${provider}:${id}` : `model:${id}`;
96
+ const key = { model: modelKey, provider: `provider:${provider}`, tier: `tier:${provider}:${pool}` }[scope];
87
97
  const entry = {
88
98
  scope, window: limit.window, until: limit.until, reason: `rate limited (${limit.window})`, source: 'probe',
89
- ...(scope === 'tier' && { tier: 'heavy' }),
99
+ ...(scope === 'tier' && { tier: pool }),
90
100
  };
91
101
  return { key, entry };
92
102
  }
93
103
 
94
- /** Probes each candidate model in turn. candidates: { providerKey: [display names] }, default config.allowlist. */
104
+ /** Why a model is left unprobed (its quota is not to be spent), else null. */
105
+ function skipReason(provider, model, config, pools, probeScarce) {
106
+ const { pool, scarceQuota } = resolveTarget({ providers: [provider], model }, config);
107
+ if (scarceQuota && !probeScarce) return 'skipped: scarce quota (use --probe-scarce)';
108
+ return pools && !pools.includes(pool) ? 'skipped: pool not selected' : null;
109
+ }
110
+
111
+ /**
112
+ * Probes each candidate model in turn. candidates: { providerKey: [display names] }, default config.allowlist.
113
+ * pools limits probing to those pools; scarceQuota models are reported as skipped unless probeScarce.
114
+ */
95
115
  export async function probeModels({
96
- config, candidates, providers, runner, which = findOnPath, now = Date.now(), log = () => {},
116
+ config, candidates, providers, runner, which = findOnPath, now = Date.now(), log = () => {}, pools,
117
+ probeScarce = false,
97
118
  } = {}) {
98
119
  const exec = runner ?? createRunner(which);
99
120
  const wanted = wantedProviders(providers);
@@ -105,7 +126,10 @@ export async function probeModels({
105
126
  for (const model of models) {
106
127
  if (isBanned(model, config.bannedModels ?? [])) continue;
107
128
  let outcome;
108
- if (!Object.hasOwn(PROBES, name)) {
129
+ const skip = skipReason(name, model, config, pools, probeScarce);
130
+ if (skip) {
131
+ outcome = { state: 'unavailable', reason: skip, skipped: true };
132
+ } else if (!Object.hasOwn(PROBES, name)) {
109
133
  outcome = { state: 'unavailable', reason: 'probe not supported' };
110
134
  } else if (providerLimited) {
111
135
  outcome = { state: 'rate-limited', reason: 'skipped: provider is rate limited', skipped: true };
@@ -186,6 +210,13 @@ function applyResults(config, preset, results) {
186
210
  }
187
211
  const planRestricted = Object.fromEntries(Object.entries(restricted).filter(([, models]) => models.length > 0));
188
212
  const next = { ...config, allowlist };
213
+ if (config.schemaVersion === 2) {
214
+ // v2 restrictions are only added here, never lifted by a probe (tier-derived ones must stay).
215
+ const refs = Object.entries(planRestricted)
216
+ .flatMap(([provider, models]) => models.map((m) => `${canonicalProvider(provider) ?? provider.toLowerCase()}:${m}`));
217
+ next.planRestrictedModels = [...new Set([...(config.planRestrictedModels ?? []), ...refs])];
218
+ return { next, planRestricted };
219
+ }
189
220
  if (config.planRestricted !== undefined || Object.keys(planRestricted).length > 0) next.planRestricted = planRestricted;
190
221
  return { next, planRestricted };
191
222
  }
@@ -206,7 +237,7 @@ function backfillLadders(next, preset) {
206
237
  /** Probes the candidate models of <target>'s config and persists the allowlist, cooldowns and SKILL.md. */
207
238
  export async function syncModels(target, {
208
239
  providers, dryRun = false, yes = false, force = false, runner, which, now = Date.now(), log = console.log,
209
- confirm = async () => false, syncFiles = syncConfig,
240
+ confirm = async () => false, syncFiles = syncConfig, probeScarce = false,
210
241
  } = {}) {
211
242
  const config = readConfig(path.join(target, CONFIG_FILE));
212
243
  const presetName = ['claude-codex', 'claude-only'].includes(config.preset) ? config.preset : 'tri-provider';
@@ -215,9 +246,12 @@ export async function syncModels(target, {
215
246
  // Checked before probing, so quota is not spent on a config that cannot be saved.
216
247
  const problem = configProblem(completeConfig(config));
217
248
  if (problem) throw new CliError(`${CONFIG_FILE}: ${problem}`);
218
- const candidates = mergeModelMaps(config.allowlist ?? preset.allowlist, config.planRestricted, preset.allowlist);
249
+ // v2 allowlists are bound to the subscription tier, so the preset roster is never merged in.
250
+ const candidates = config.schemaVersion === 2
251
+ ? mergeModelMaps(config.allowlist)
252
+ : mergeModelMaps(config.allowlist ?? preset.allowlist, config.planRestricted, preset.allowlist);
219
253
  const { results } = await probeModels({
220
- config: { ...config, bannedModels }, candidates, providers, runner, which, now, log,
254
+ config: { ...config, bannedModels }, candidates, providers, runner, which, now, log, probeScarce,
221
255
  });
222
256
 
223
257
  const { next, planRestricted } = applyResults(config, preset, results);
package/lib/prompt.mjs CHANGED
@@ -1,13 +1,45 @@
1
1
  import path from 'node:path';
2
2
  import readline from 'node:readline/promises';
3
- import { CONFIG_FILE, isObject, readJson } from '../hooks/_shared.mjs';
3
+ import { CONFIG_FILE, isObject, isV2, readJson } from '../hooks/_shared.mjs';
4
4
  import { detect as detectProviders, parseTiers } from './detect.mjs';
5
5
  import { MODULES, readManifest } from './manifest.mjs';
6
- import { PRESETS, completeConfig } from './install.mjs';
6
+ import { ASSUMED_TIERS, PRESETS, completeConfig } from './install.mjs';
7
7
  import { CliError } from './paths.mjs';
8
+ import { CATALOG, PROVIDERS } from './plans.mjs';
8
9
 
9
10
  const MODULE_LABELS = { full: 'Full Suite', 'auto-build': '/auto-build Only', core: 'Core Discipline + Commands' };
10
11
  const PLAN_NAMES = { claude: 'pro|max', codex: 'plus|pro', antigravity: 'standard|ultra' };
12
+ export const TIER_FLAGS = { claude: '--claude-tier', codex: '--codex-tier', antigravity: '--antigravity-tier' };
13
+
14
+ /** A saved config carries no warnings, so they come from the catalog. */
15
+ const catalogWarnings = (config) => PROVIDERS.flatMap((provider) => {
16
+ const id = config.subscriptions?.[provider] ?? 'none';
17
+ const tier = CATALOG[provider][id];
18
+ if (!tier?.warning || id === 'none') return [];
19
+ const excluded = tier.usageBilled && !config.allowUsageCredits
20
+ ? [`${provider} ${id}: models excluded; pass --allow-usage-credits to use them`] : [];
21
+ return [`${provider} ${id}: ${tier.warning}`, ...excluded];
22
+ });
23
+
24
+ /** Plain text overview of a resolveTiers() result or a v2 config, shown before it is written. */
25
+ export function summaryTable(resolved) {
26
+ const names = (models) => models.map((m) => m.model).join(', ') || '-';
27
+ const rows = [['provider', 'tier', 'CLI', 'models (standard)', 'scarce overflow', 'max parallel']];
28
+ for (const provider of PROVIDERS) {
29
+ const id = resolved.subscriptions?.[provider] ?? 'none';
30
+ const tier = CATALOG[provider][id];
31
+ const models = (resolved.models ?? []).filter((m) => m.provider === provider);
32
+ rows.push([provider, id, tier?.cliSupported ? 'yes' : 'no', names(models.filter((m) => !m.scarceQuota)),
33
+ names(models.filter((m) => m.scarceQuota)), String(models.length ? tier?.maxParallelBuilders ?? 0 : 0)]);
34
+ }
35
+ const widths = rows[0].map((_, i) => Math.max(...rows.map((row) => row[i].length)));
36
+ const lines = rows.map((row) => row.map((cell, i) => cell.padEnd(widths[i])).join(' | ').trimEnd());
37
+ lines.push(`parent: ${resolved.parent ? `${resolved.parent.model} (${resolved.parent.effort})` : 'none'}`);
38
+ lines.push(`max parallel builders: ${resolved.maxParallelBuilders ?? 0}`);
39
+ const warnings = (resolved.warnings ?? catalogWarnings(resolved)).filter((text) => !/^\w+ none:/.test(text));
40
+ lines.push(...warnings.map((text) => `warning: ${text}`));
41
+ return lines.join('\n');
42
+ }
11
43
 
12
44
  /** parseTiers, with a bad value reported as a usage error. */
13
45
  export function parseTierSpec(spec) {
@@ -49,8 +81,18 @@ export async function initPrompts(target, options, { detect = detectProviders, i
49
81
  providers: Object.keys(found.providers).filter((name) => found.providers[name].binary),
50
82
  tiers: isObject(complete.tiers) ? complete.tiers : {},
51
83
  };
84
+ const v2 = isV2(config);
85
+ // Default tier per provider. null (v1 config) keeps that config unless a tier is typed.
86
+ current.subscriptions = Object.fromEntries(PROVIDERS.map((provider) => {
87
+ if (v2) return [provider, config.subscriptions?.[provider] ?? 'none'];
88
+ if (config) return [provider, null];
89
+ return [provider, found.providers[provider]?.binary ? ASSUMED_TIERS[provider] : 'none'];
90
+ }));
91
+ current.v2 = v2;
92
+ current.parent = config?.parent?.model;
93
+ current.allowUsageCredits = config?.allowUsageCredits;
52
94
  const answers = await promptOptions(options, current, input, output);
53
- if (!config && (answers.modules ?? current.modules) !== 'core') answers.preset ??= found.preset;
95
+ if (!config && (answers.modules ?? current.modules) !== 'core' && !tiered(answers, v2)) answers.preset ??= found.preset;
54
96
  return answers;
55
97
  }
56
98
 
@@ -70,6 +112,38 @@ export function parsePercent(value) {
70
112
  return percent;
71
113
  }
72
114
 
115
+ /** True when subscription tiers, not a preset, decide the providers. */
116
+ const tiered = (answers, v2) => v2 || PROVIDERS.some((provider) => {
117
+ const tier = answers[`${provider}Tier`] ?? answers.subscriptions?.[provider];
118
+ return tier !== undefined && tier !== 'none';
119
+ });
120
+
121
+ /** One tier question per provider without a flag, then the parent when the Claude tier offers a choice. */
122
+ async function askTiers(options, current, answers, ask, output) {
123
+ const subscriptions = {};
124
+ for (const provider of PROVIDERS) {
125
+ let tier = options[`${provider}Tier`];
126
+ if (tier === undefined) {
127
+ const ids = Object.keys(CATALOG[provider]);
128
+ const kept = current.subscriptions[provider];
129
+ const reply = await ask(`${provider} subscription tier (${ids.join(', ')}) [${kept ?? 'keep'}]: `);
130
+ tier = reply ? parseChoice(reply, ids, `${provider} tier`) : kept;
131
+ }
132
+ if (tier !== null) subscriptions[provider] = tier;
133
+ const chosen = CATALOG[provider][tier];
134
+ if (tier !== 'none' && chosen?.warning) output.write(`warning: ${provider} ${tier}: ${chosen.warning}\n`);
135
+ }
136
+ answers.subscriptions = subscriptions;
137
+
138
+ const claude = CATALOG.claude[options.claudeTier ?? subscriptions.claude];
139
+ const usable = claude && (!claude.usageBilled || (options.allowUsageCredits ?? current.allowUsageCredits));
140
+ if (options.parent === undefined && usable && claude.parentOptions.length > 1) {
141
+ const kept = claude.parentOptions.includes(current.parent) ? current.parent : claude.parentDefault.model;
142
+ const reply = await ask(`Parent model (${claude.parentOptions.join(', ')}) [${kept}]: `);
143
+ if (reply) answers.parent = parseChoice(reply, claude.parentOptions, 'parent');
144
+ }
145
+ }
146
+
73
147
  /** Ask for whatever the flags left open. Enter keeps the current value (answer stays undefined). */
74
148
  export async function promptOptions(options, current, input = process.stdin, output = process.stdout) {
75
149
  const rl = readline.createInterface({ input, output, terminal: false });
@@ -88,7 +162,10 @@ export async function promptOptions(options, current, input = process.stdin, out
88
162
  if (reply) answers.modules = parseChoice(reply, MODULES, 'modules');
89
163
  }
90
164
  if ((answers.modules ?? current.modules) === 'core') return answers;
91
- if (answers.preset === undefined) {
165
+ const subscriptionMode = current.subscriptions !== undefined && options.tiers === undefined;
166
+ if (subscriptionMode) await askTiers(options, current, answers, ask, output);
167
+ // Subscription tiers decide the providers, so a preset is only asked without them.
168
+ if (answers.preset === undefined && !(subscriptionMode && tiered(answers, current.v2))) {
92
169
  const reply = await ask(`Preset:\n${numbered(PRESETS)}\nChoose [${current.preset}]: `);
93
170
  if (reply) answers.preset = parseChoice(reply, PRESETS, 'preset');
94
171
  }
@@ -98,7 +175,7 @@ export async function promptOptions(options, current, input = process.stdin, out
98
175
  const reply = await ask(`Auto-compaction threshold, percent 1-100 [${current.compaction}]: `);
99
176
  if (reply) answers.compaction = parsePercent(reply);
100
177
  }
101
- if (options.tiers === undefined) {
178
+ if (options.tiers === undefined && !subscriptionMode) {
102
179
  for (const provider of current.providers ?? []) {
103
180
  const kept = current.tiers?.[provider]?.plan ?? 'skip';
104
181
  const plan = await ask(`${provider} subscription tier (${PLAN_NAMES[provider]}) [${kept}]: `);
package/lib/quota.mjs CHANGED
@@ -2,10 +2,11 @@
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import {
5
- COOLDOWN_FILE, cliModelId, inferProvider, loadConfig, modelKeys, normalizeModel, which as findOnPath,
5
+ COOLDOWN_FILE, canonicalProvider, cliModelId, inferProvider, loadConfig, modelKeys, normalizeModel, which as findOnPath,
6
6
  } from '../hooks/_shared.mjs';
7
- import { isLocked, parseRateLimit, prune, readCooldowns, writeCooldowns } from '../hooks/_quota.mjs';
7
+ import { isLocked, parseRateLimit, prune, readCooldowns, SCARCE_POOL, writeCooldowns } from '../hooks/_quota.mjs';
8
8
  import { HEAVY_MODELS } from './detect.mjs';
9
+ import { POOLS } from './plans.mjs';
9
10
  import { CliError } from './paths.mjs';
10
11
  import { createRunner } from './probe.mjs';
11
12
 
@@ -29,7 +30,16 @@ function load(target, onInvalid) {
29
30
  function resolveSubject(subject, config) {
30
31
  const text = String(subject ?? '').trim();
31
32
  const lower = text.toLowerCase();
32
- if (isProvider(lower)) return { provider: lower };
33
+ const qualified = text.match(/^([^:]+):([^:]+)$/);
34
+ if (qualified) {
35
+ const provider = canonicalProvider(qualified[1]);
36
+ if (!provider) throw new CliError(`unknown provider "${clean(qualified[1])}"`, 2);
37
+ const model = normalizeModel(qualified[2]);
38
+ if (!model.trim()) throw new CliError(`unknown provider or model "${clean(text)}"`, 2);
39
+ return { provider, model, id: cliModelId(provider, model, config), qualified: true };
40
+ }
41
+ const canonical = canonicalProvider(lower);
42
+ if (canonical && !inferProvider(text)) return { provider: canonical };
33
43
  const model = normalizeModel(text);
34
44
  const wanted = modelKeys(model, config);
35
45
  const known = [...Object.values(config.allowlist).flat(), ...Object.keys(config.modelIds ?? {})]
@@ -37,7 +47,15 @@ function resolveSubject(subject, config) {
37
47
  if (!text || (!known && !inferProvider(model))) {
38
48
  throw new CliError(`unknown provider or model "${clean(text)}"; use ${Object.keys(HEAVY_MODELS).join(', ')} or a model name`, 2);
39
49
  }
40
- return { model, id: cliModelId(inferProvider(model), model, config) };
50
+ return { model, id: cliModelId(inferProvider(model), model, config), qualified: false };
51
+ }
52
+
53
+ function poolName(pool) {
54
+ const value = String(pool ?? '').trim().toLowerCase();
55
+ if (!value || (!POOLS.includes(value) && !/^[a-z0-9-]+$/.test(value))) {
56
+ throw new CliError(`invalid pool "${clean(pool)}"; use a pool name containing lowercase letters, digits or hyphens`, 2);
57
+ }
58
+ return value;
41
59
  }
42
60
 
43
61
  const UNIT_MS = { w: 604_800_000, d: 86_400_000, h: 3_600_000, m: 60_000 };
@@ -61,24 +79,37 @@ function parseUntil(value, now) {
61
79
  }
62
80
 
63
81
  /** Locks a provider or model for a window (default burst) or until a given time. */
64
- export function quotaSet(target, subject, { window, until, reason, now = Date.now(), log = console.log } = {}) {
82
+ export function quotaSet(target, subject, { window, until, reason, pool, heavy = false, now = Date.now(), log = console.log } = {}) {
65
83
  if (window !== undefined && until !== undefined) throw new CliError('give a window or --until, not both', 2);
84
+ if (pool !== undefined && heavy) throw new CliError('give --pool or --heavy, not both', 2);
66
85
  const span = until === undefined ? window ?? 'burst' : 'custom';
67
86
  if (span !== 'custom' && !QUOTA_WINDOWS.includes(span)) throw new CliError(`unknown window "${clean(span)}"`, 2);
68
87
  const config = loadConfig(target);
69
- const { provider, id } = resolveSubject(subject, config);
88
+ const targetRef = resolveSubject(subject, config);
89
+ const { provider, id, model } = targetRef;
90
+ const host = provider ?? inferProvider(model);
91
+ if ((pool !== undefined || heavy) && !host) throw new CliError(`cannot determine provider for "${clean(subject)}"`, 2);
70
92
  const tier = config.tiers?.[provider ?? inferProvider(id)];
71
93
  const limit = span === 'custom'
72
94
  ? { until: new Date(parseUntil(until, now)).toISOString() }
73
95
  : parseRateLimit({ burst: '', '5h': '5h limit', weekly: 'weekly limit' }[span], {
74
96
  now, sharing: tier?.sharing, resetDay: tier?.resetDay,
75
97
  });
76
- let scope = provider ? 'provider' : 'model';
77
- if (provider && span === '5h' && limit.scope === 'tier') scope = 'tier';
78
- const key = { model: `model:${id}`, provider: `provider:${provider}`, tier: `tier:${provider}:heavy` }[scope];
98
+ let scope = provider && !model ? 'provider' : 'model';
99
+ let poolKey;
100
+ if (pool !== undefined) {
101
+ scope = 'tier';
102
+ poolKey = poolName(pool);
103
+ } else if (heavy || (provider && !model && span === '5h' && limit.scope === 'tier')) {
104
+ scope = 'tier';
105
+ poolKey = SCARCE_POOL[host];
106
+ }
107
+ const key = scope === 'tier' ? `tier:${host}:${poolKey}`
108
+ : scope === 'provider' ? `provider:${provider}`
109
+ : targetRef.qualified ? `model:${provider}:${id}` : `model:${id}`;
79
110
  const entry = {
80
111
  scope, window: span, until: limit.until, reason: reason ?? `manual lock (${span})`, source: 'manual',
81
- ...(scope === 'tier' && { tier: 'heavy' }),
112
+ ...(scope === 'tier' && { tier: poolKey }),
82
113
  };
83
114
  writeCooldowns(cooldownPath(target), { ...prune(load(target), now).kept, [key]: entry });
84
115
  log(`locked ${key} until ${entry.until} (${span})`);
@@ -117,7 +148,8 @@ export function quotaClear(target, subject, { log = console.log } = {}) {
117
148
  return null;
118
149
  }
119
150
  const config = loadConfig(target);
120
- const { provider, model } = resolveSubject(subject, config);
151
+ const targetRef = resolveSubject(subject, config);
152
+ const { provider, model, qualified } = targetRef;
121
153
  const bad = [];
122
154
  const data = load(target, (key) => bad.push(key));
123
155
  // A malformed entry has no usable fields, so it is matched by its key alone.
@@ -126,9 +158,14 @@ export function quotaClear(target, subject, { log = console.log } = {}) {
126
158
  until: '9999-01-01T00:00:00Z',
127
159
  }]);
128
160
  const removed = [...Object.entries(data), ...stubs].filter(([key, entry]) => {
129
- if (provider && entry.scope === 'tier') return key.toLowerCase() === `tier:${provider}:heavy`;
161
+ if (provider && !model && entry.scope === 'tier') return key.toLowerCase().startsWith(`tier:${provider}:`);
162
+ if (provider && !model && entry.scope === 'provider') return key.toLowerCase() === `provider:${provider}`;
163
+ if (model && entry.scope === 'tier') return false;
164
+ if (model && entry.scope === 'model' && qualified) {
165
+ return key.toLowerCase() === `model:${provider}:${targetRef.id}` || key.toLowerCase() === `model:${targetRef.id}`;
166
+ }
130
167
  // Time 0 makes isLocked match expired entries too.
131
- return entry.scope === (provider ? 'provider' : 'model')
168
+ return entry.scope === (provider && !model ? 'provider' : 'model')
132
169
  && isLocked({ [key]: entry }, { provider, model, config }, 0) !== null;
133
170
  }).map(([key]) => key);
134
171
  for (const key of removed) delete data[key];
@@ -177,11 +214,13 @@ export async function quotaCheck(target, { providers, runner, which = findOnPath
177
214
  const tier = config.tiers?.[provider];
178
215
  const limit = parseRateLimit(`${line}${reset}`, { now, sharing: tier?.sharing, resetDay: tier?.resetDay });
179
216
  const scope = limit.scope === 'tier' ? 'tier' : 'provider';
180
- const key = scope === 'tier' ? `tier:${provider}:heavy` : `provider:${provider}`;
217
+ // v2 locks only the scarce pool; v1 keeps the legacy heavy key its heavyModels lists rely on.
218
+ const pool = config.schemaVersion === 2 ? SCARCE_POOL[provider] ?? 'heavy' : 'heavy';
219
+ const key = scope === 'tier' ? `tier:${provider}:${pool}` : `provider:${provider}`;
181
220
  if (Date.parse(found[key]?.until) >= Date.parse(limit.until)) return;
182
221
  found[key] = {
183
222
  scope, window: limit.window, until: limit.until, reason: `usage exhausted (${limit.window})`, source: 'probe',
184
- ...(scope === 'tier' && { tier: 'heavy' }),
223
+ ...(scope === 'tier' && { tier: pool }),
185
224
  };
186
225
  });
187
226
  if (Object.keys(found).length === 0) {
package/lib/render.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { CONFIG_FILE, COOLDOWN_FILE, displayPath, effectiveAllowlist } from '../hooks/_shared.mjs';
1
+ import { AVAILABILITY_FILE, CONFIG_FILE, COOLDOWN_FILE, RETIRED_MODELS, canonicalProvider, displayPath, effectiveAllowlist, inferProvider, normalizeName } from '../hooks/_shared.mjs';
2
2
  import { CliError } from './paths.mjs';
3
3
 
4
4
  export const LADDERS = ['tier1', 'commandRunner', 'builderA', 'testerA', 'auditorA', 'builderB', 'testerB', 'auditorB', 'architect', 'dualAudit'];
@@ -17,16 +17,30 @@ const code = (text) => `\`${text}\``;
17
17
  /** Render SKILL.md from the config. Banned or non-allowlisted ladder entries are dropped. */
18
18
  export function renderSkill(template, config, configDir) {
19
19
  const groups = effectiveAllowlist(config);
20
- const allowed = new Map(groups.flatMap(([, models]) => models).map((model) => [model.toLowerCase(), model]));
20
+ const allowedByProvider = new Map(groups.map(([provider, models]) => [canonicalProvider(provider), new Map(models.map((model) => [normalizeName(model), model]))]));
21
+ const allowed = new Map(groups.flatMap(([, models]) => models).map((model) => [normalizeName(model), model]));
21
22
  if (allowed.size === 0) throw new CliError('the allowlist is empty after removing banned models');
22
23
 
23
24
  const ladders = Object.fromEntries(
24
25
  LADDERS.map((name) => {
25
26
  const entries = (config.ladders[name] ?? []).flatMap((entry) => {
26
27
  const [model, effort] = entry.split('@');
27
- const known = allowed.get(model.trim().toLowerCase());
28
+ const trimmed = model.trim();
29
+ const colon = trimmed.indexOf(':');
30
+ if (colon >= 0) {
31
+ const prefix = trimmed.slice(0, colon);
32
+ const provider = canonicalProvider(prefix);
33
+ const known = provider ? allowedByProvider.get(provider)?.get(normalizeName(trimmed.slice(colon + 1))) : null;
34
+ return known ? [{ model: `${prefix}:${known}`, effort }] : [];
35
+ }
36
+ const known = allowed.get(normalizeName(trimmed));
28
37
  return known ? [{ model: known, effort }] : [];
29
38
  });
39
+ const scarce = (item) => config.models?.some((model) => model.provider === (item.model.includes(':')
40
+ ? canonicalProvider(item.model.slice(0, item.model.indexOf(':'))) : inferProvider(item.model))
41
+ && normalizeName(model.model) === normalizeName(item.model.includes(':') ? item.model.slice(item.model.indexOf(':') + 1) : item.model)
42
+ && model.scarceQuota);
43
+ entries.sort((a, b) => Number(scarce(a)) - Number(scarce(b)));
30
44
  if (entries.length === 0) {
31
45
  throw new CliError(`ladder "${name}" has no model left after removing banned and non-allowlisted entries; edit ${CONFIG_FILE}`);
32
46
  }
@@ -35,7 +49,7 @@ export function renderSkill(template, config, configDir) {
35
49
  );
36
50
  const describe = ({ model, effort }) => `${code(model)}${effort ? ` (${code(effort)})` : ''}`;
37
51
  const duals = ladders.dualAudit.map(describe);
38
- const defaultModel = allowed.get(config.defaultModel.toLowerCase()) ?? ladders.builderA[0].model;
52
+ const defaultModel = allowed.get(normalizeName(config.defaultModel ?? '')) ?? ladders.builderA[0].model;
39
53
  const flags = groups.map(([provider, models]) => ({ flag: `--${provider.toLowerCase().replace(/\s+/g, '-')}-only`, provider, models }));
40
54
 
41
55
  return fillTemplate(template, {
@@ -55,5 +69,12 @@ export function renderSkill(template, config, configDir) {
55
69
  dualAuditRun: duals.length > 1 ? `Run ${duals.join(' AND ')} in parallel` : `Run ${duals[0]}`,
56
70
  cooldownsPath: displayPath(configDir, COOLDOWN_FILE),
57
71
  configPath: displayPath(configDir, CONFIG_FILE),
72
+ maxParallelBuilders: config.maxParallelBuilders ?? 2,
73
+ availabilityPath: displayPath(configDir, AVAILABILITY_FILE),
74
+ subscriptionSummary: config.subscriptions
75
+ ? Object.entries(config.subscriptions).map(([provider, tier]) => `${provider}: ${tier}`).join(', ')
76
+ : 'legacy v1 config (run t3-auto-build upgrade)',
77
+ scarceModels: config.models?.filter((model) => model.scarceQuota).map((model) => `${model.provider}:${model.model}`).join(', ') || 'none',
78
+ retiredModels: [...new Set([...RETIRED_MODELS, ...(config.retiredModels ?? [])])].join(', '),
58
79
  });
59
80
  }
package/lib/settings.mjs CHANGED
@@ -3,6 +3,7 @@ import path from 'node:path';
3
3
  import { isDeepStrictEqual } from 'node:util';
4
4
  import { isObject, parseJson } from '../hooks/_shared.mjs';
5
5
  import { CliError } from './paths.mjs';
6
+ import { PARENTS } from './plans.mjs';
6
7
 
7
8
  export const ENV_NAME = 'CLAUDE_AUTOCOMPACT_PCT_OVERRIDE';
8
9
  export const HOOKS_DIR = 'hooks/t3-auto-build';
@@ -84,7 +85,42 @@ const desiredEntries = (target) =>
84
85
  HOOKS.map(({ event, matcher, script }) => ({ event, matcher, hook: { type: 'command', command: hookCommand(target, script) } }));
85
86
 
86
87
  /** Returns { data, env }: new settings plus the manifest record needed to undo the env change. */
87
- export function mergeSettings(current, target, percent, previous) {
88
+ const restoreManagedSettings = (data, records = {}) => {
89
+ for (const [key, record] of Object.entries(records)) {
90
+ if (!record || data[key] !== record.installed) continue;
91
+ if (record.had) data[key] = record.prior;
92
+ else delete data[key];
93
+ }
94
+ };
95
+
96
+ function mergeParentSettings(data, parent, previous = {}) {
97
+ const priorRecords = previous.settings ?? {};
98
+ if (!parent) {
99
+ restoreManagedSettings(data, priorRecords);
100
+ return {};
101
+ }
102
+ const desired = { model: PARENTS[parent.model], effortLevel: parent.effort };
103
+ const records = {};
104
+ for (const [key, value] of Object.entries(desired)) {
105
+ if (typeof value !== 'string') continue;
106
+ const prior = priorRecords[key];
107
+ const had = Object.prototype.hasOwnProperty.call(data, key);
108
+ const current = data[key];
109
+ if (!had || (prior && current === prior.installed)) {
110
+ records[key] = prior
111
+ ? { ...prior, installed: value }
112
+ : { had: false, prior: null, installed: value };
113
+ data[key] = value;
114
+ } else if (prior) {
115
+ // Preserve the original record so uninstall still recognizes ownership if the value is restored.
116
+ records[key] = prior;
117
+ }
118
+ }
119
+ return records;
120
+ }
121
+
122
+ /** Returns { data, env }: manifest env stores both the prior env value and managed parent setting values. */
123
+ export function mergeSettings(current, target, percent, previous, parent) {
88
124
  const data = structuredClone(current);
89
125
  const desired = desiredEntries(target);
90
126
  const present = taggedHooks(data);
@@ -103,12 +139,16 @@ export function mergeSettings(current, target, percent, previous) {
103
139
  ? { ...previous, installed }
104
140
  : { had, prior: had ? data.env[ENV_NAME] : null, createdEnv: data.env === undefined, installed };
105
141
  data.env = { ...data.env, [ENV_NAME]: installed };
142
+ const parentSettings = mergeParentSettings(data, parent, previous);
143
+ if (Object.keys(parentSettings).length) env.settings = parentSettings;
144
+ else delete env.settings;
106
145
  return { data, env };
107
146
  }
108
147
 
109
148
  export function unmergeSettings(current, env) {
110
149
  const data = structuredClone(current);
111
150
  removeTagged(data);
151
+ restoreManagedSettings(data, env?.settings);
112
152
  if (env && data.env?.[ENV_NAME] === env.installed) {
113
153
  if (env.had) data.env[ENV_NAME] = env.prior;
114
154
  else delete data.env[ENV_NAME];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "t3-auto-build",
3
- "version": "1.0.1",
4
- "description": "Cross-platform installer and $auto-build orchestration suite for T3 Code.",
3
+ "version": "2.0.0",
4
+ "description": "Cross-platform installer and $auto-build orchestration suite for T3 Code: subscription-aware cross-provider routing with quota and availability tracking.",
5
5
  "keywords": [
6
6
  "claude-code",
7
7
  "t3-code",
@@ -10,7 +10,13 @@
10
10
  "hooks",
11
11
  "cli",
12
12
  "codex",
13
- "gemini"
13
+ "gemini",
14
+ "antigravity",
15
+ "subscription",
16
+ "quota",
17
+ "availability",
18
+ "cross-provider",
19
+ "model-routing"
14
20
  ],
15
21
  "homepage": "https://github.com/mirceas94/t3-auto-build#readme",
16
22
  "bugs": {
@@ -30,13 +36,14 @@
30
36
  "core",
31
37
  "presets",
32
38
  "skills",
33
- "hooks"
39
+ "hooks",
40
+ "CHANGELOG.md"
34
41
  ],
35
42
  "scripts": {
36
43
  "test": "node --test"
37
44
  },
38
45
  "engines": {
39
- "node": ">=18"
46
+ "node": ">=18.18.0"
40
47
  },
41
48
  "license": "MIT"
42
49
  }
@@ -2,9 +2,9 @@
2
2
  "preset": "claude-codex",
3
3
  "allowlist": {
4
4
  "Codex": [
5
- "gpt-5.6-luna",
6
- "gpt-5.6-terra",
7
- "gpt-6-luna"
5
+ "gpt-6-luna",
6
+ "gpt-6.1-terra",
7
+ "gpt-6.1-sol"
8
8
  ],
9
9
  "Claude": [
10
10
  "Claude Haiku 5.5",
@@ -12,20 +12,68 @@
12
12
  "Claude Opus 5.5"
13
13
  ]
14
14
  },
15
- "bannedModels": ["Argon", "Fable/Mythos"],
15
+ "bannedModels": [],
16
16
  "defaultModel": "Claude Sonnet 5.5",
17
17
  "defaultEffort": "medium",
18
18
  "compactionThreshold": 35,
19
19
  "ladders": {
20
- "tier1": ["gpt-5.6-luna", "gpt-5.6-terra", "gpt-6-luna", "Claude Haiku 5.5", "Claude Sonnet 5.5"],
21
- "commandRunner": ["gpt-6-luna", "gpt-5.6-terra", "Claude Sonnet 5.5", "gpt-5.6-luna", "Claude Haiku 5.5"],
22
- "builderA": ["Claude Sonnet 5.5", "gpt-6-luna", "Claude Opus 5.5@medium", "gpt-5.6-terra@high", "gpt-5.6-luna@high"],
23
- "testerA": ["Claude Sonnet 5.5", "gpt-6-luna", "Claude Opus 5.5@medium"],
24
- "auditorA": ["Claude Opus 5.5", "Claude Sonnet 5.5@high", "gpt-6-luna@high"],
25
- "builderB": ["Claude Sonnet 5.5", "gpt-6-luna", "Claude Opus 5.5@medium", "gpt-5.6-terra@high", "gpt-5.6-luna@high"],
26
- "testerB": ["gpt-6-luna", "Claude Sonnet 5.5", "Claude Opus 5.5@medium"],
27
- "auditorB": ["Claude Opus 5.5", "gpt-6-luna@high", "Claude Sonnet 5.5@high"],
28
- "architect": ["Claude Opus 5.5@high", "Claude Sonnet 5.5@high", "gpt-6-luna@high", "gpt-5.6-terra@high"],
29
- "dualAudit": ["Claude Opus 5.5@high", "gpt-6-luna@high"]
20
+ "tier1": [
21
+ "gpt-6.1-sol",
22
+ "gpt-6.1-terra",
23
+ "gpt-6-luna",
24
+ "Claude Haiku 5.5",
25
+ "Claude Sonnet 5.5"
26
+ ],
27
+ "commandRunner": [
28
+ "gpt-6-luna",
29
+ "gpt-6.1-terra",
30
+ "Claude Sonnet 5.5",
31
+ "gpt-6.1-sol",
32
+ "Claude Haiku 5.5"
33
+ ],
34
+ "builderA": [
35
+ "Claude Sonnet 5.5",
36
+ "gpt-6-luna",
37
+ "Claude Opus 5.5@medium",
38
+ "gpt-6.1-terra@high",
39
+ "gpt-6.1-sol@high"
40
+ ],
41
+ "testerA": [
42
+ "Claude Sonnet 5.5",
43
+ "gpt-6-luna",
44
+ "Claude Opus 5.5@medium"
45
+ ],
46
+ "auditorA": [
47
+ "Claude Opus 5.5",
48
+ "Claude Sonnet 5.5@high",
49
+ "gpt-6-luna@high"
50
+ ],
51
+ "builderB": [
52
+ "Claude Sonnet 5.5",
53
+ "gpt-6-luna",
54
+ "Claude Opus 5.5@medium",
55
+ "gpt-6.1-terra@high",
56
+ "gpt-6.1-sol@high"
57
+ ],
58
+ "testerB": [
59
+ "gpt-6-luna",
60
+ "Claude Sonnet 5.5",
61
+ "Claude Opus 5.5@medium"
62
+ ],
63
+ "auditorB": [
64
+ "Claude Opus 5.5",
65
+ "gpt-6-luna@high",
66
+ "Claude Sonnet 5.5@high"
67
+ ],
68
+ "architect": [
69
+ "Claude Opus 5.5@high",
70
+ "Claude Sonnet 5.5@high",
71
+ "gpt-6-luna@high",
72
+ "gpt-6.1-terra@high"
73
+ ],
74
+ "dualAudit": [
75
+ "Claude Opus 5.5@high",
76
+ "gpt-6-luna@high"
77
+ ]
30
78
  }
31
79
  }