token-harness 0.1.19 → 0.1.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "token-harness",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Quota-aware efficiency layer for Claude Code and Codex subscription limits.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/sbom.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "bomFormat": "CycloneDX",
3
3
  "specVersion": "1.5",
4
- "serialNumber": "urn:uuid:fd379d86-ac5b-23d6-ac6a-6b9654496726",
4
+ "serialNumber": "urn:uuid:6a907cd9-4778-ca06-b653-78caf2cf25f0",
5
5
  "version": 1,
6
6
  "metadata": {
7
7
  "component": {
8
8
  "type": "application",
9
9
  "bom-ref": "token-harness",
10
10
  "name": "token-harness",
11
- "version": "0.1.19",
11
+ "version": "0.1.20",
12
12
  "description": "Quota-aware efficiency layer for Claude Code and Codex subscription limits.",
13
13
  "licenses": [
14
14
  {
@@ -20,7 +20,7 @@
20
20
  "hashes": [
21
21
  {
22
22
  "alg": "SHA-256",
23
- "content": "fd379d86ac5b23d6ac6a6b96544967266bf50ee71039397bb7d6a3f3c34373f7"
23
+ "content": "6a907cd94778ca06b65378caf2cf25f060cc82a51168e1cd611f5f58b5e19e55"
24
24
  }
25
25
  ]
26
26
  },
package/token-harness.mjs CHANGED
@@ -10068,7 +10068,7 @@ var TOOL_VERSION;
10068
10068
  var init_version2 = __esm({
10069
10069
  "apps/cli/dist/src/version.js"() {
10070
10070
  "use strict";
10071
- TOOL_VERSION = "0.1.19";
10071
+ TOOL_VERSION = "0.1.20";
10072
10072
  }
10073
10073
  });
10074
10074
 
@@ -32828,21 +32828,31 @@ async function planDirectRtkRelease(input) {
32828
32828
  const admission = admitProviderPackageUpdate(input.providerId, targetText);
32829
32829
  if (admission.state !== "admitted")
32830
32830
  return empty2("unavailable");
32831
- if (input.executables.length !== 1) {
32832
- const detail2 = input.executables.length === 0 ? "no concrete RTK executable path could be resolved" : `${String(input.executables.length)} RTK executable paths resolve: ${input.executables.map((entry) => entry.path).join(", ")}`;
32831
+ if (input.executables.length === 0) {
32833
32832
  return empty2("unavailable", [
32834
32833
  diagnostic({
32835
32834
  severity: "warning",
32836
- code: "rtk-release-target-ambiguous",
32835
+ code: "rtk-release-target-unresolved",
32837
32836
  subject: input.providerId,
32838
- message: `The verified GitHub release update was not planned because ${detail2}`,
32839
- remediation: "Make exactly one intended RTK executable resolve on PATH, then re-run Check for updates; Token Harness will not choose an arbitrary binary to replace"
32837
+ message: "The verified GitHub release update was not planned because no concrete RTK executable path could be resolved",
32838
+ remediation: "Make the intended RTK executable available on PATH, then re-run Check for updates"
32840
32839
  })
32841
32840
  ]);
32842
32841
  }
32843
32842
  const executable = input.executables[0];
32843
+ const shadowedDiagnostics = input.executables.length > 1 ? [
32844
+ diagnostic({
32845
+ severity: "info",
32846
+ code: "rtk-release-shadowed-executables",
32847
+ subject: input.providerId,
32848
+ path: executable?.path ?? null,
32849
+ message: `RTK update will target the active PATH executable ${executable?.path ?? "unknown"}; ${String(input.executables.length - 1)} shadowed RTK executable${input.executables.length === 2 ? "" : "s"} will be left unchanged: ${input.executables.slice(1).map((entry) => entry.path).join(", ")}`,
32850
+ remediation: null
32851
+ })
32852
+ ] : [];
32844
32853
  if (executable === void 0 || executable.kind !== "native") {
32845
32854
  return empty2("unavailable", [
32855
+ ...shadowedDiagnostics,
32846
32856
  diagnostic({
32847
32857
  severity: "warning",
32848
32858
  code: "rtk-release-target-not-native",
@@ -32858,6 +32868,7 @@ async function planDirectRtkRelease(input) {
32858
32868
  const targetPath = await canonicalPath.call(input.fs, executable.path);
32859
32869
  if (targetPath === null) {
32860
32870
  return empty2("unavailable", [
32871
+ ...shadowedDiagnostics,
32861
32872
  diagnostic({
32862
32873
  severity: "warning",
32863
32874
  code: "rtk-release-target-unresolved",
@@ -32875,6 +32886,7 @@ async function planDirectRtkRelease(input) {
32875
32886
  if (queried.status !== "found") {
32876
32887
  return {
32877
32888
  ...empty2("unavailable", [
32889
+ ...shadowedDiagnostics,
32878
32890
  diagnostic({
32879
32891
  severity: "warning",
32880
32892
  code: "rtk-release-fallback-unavailable",
@@ -32899,7 +32911,7 @@ async function planDirectRtkRelease(input) {
32899
32911
  },
32900
32912
  availableVersion: targetText,
32901
32913
  verdict: "upgradable",
32902
- diagnostics: [],
32914
+ diagnostics: shadowedDiagnostics,
32903
32915
  destinations: [RTK_RELEASE_METADATA_DESTINATION]
32904
32916
  };
32905
32917
  }
@@ -37440,20 +37452,149 @@ var init_guided = __esm({
37440
37452
  const data = input;
37441
37453
  const action = String(data["action"]);
37442
37454
  const candidateAction = action === "candidate-setup" || action === "candidate-remove";
37455
+ const routingAction = action === "routing-setup" || action === "routing-remove" || action === "routing-metrics";
37443
37456
  const requestedHarnesses = data["harnesses"];
37444
37457
  const validHarnesses = Array.isArray(requestedHarnesses) && requestedHarnesses.length > 0 && requestedHarnesses.length <= 20 && requestedHarnesses.every((value3) => typeof value3 === "string" && ["claude", "codex"].includes(value3)) && new Set(requestedHarnesses).size === requestedHarnesses.length;
37445
- if (Object.keys(data).some((key) => !["action", "harness", "harnesses", "task", "provider", "candidate"].includes(key)) || ![
37458
+ if (Object.keys(data).some((key) => ![
37459
+ "action",
37460
+ "harness",
37461
+ "harnesses",
37462
+ "task",
37463
+ "provider",
37464
+ "candidate",
37465
+ "routeMode"
37466
+ ].includes(key)) || ![
37446
37467
  "setup",
37447
37468
  "effort",
37448
37469
  "skill",
37449
37470
  "undo",
37450
37471
  "remove",
37451
37472
  "candidate-setup",
37452
- "candidate-remove"
37453
- ].includes(action) || data["harness"] !== void 0 && !["claude", "codex"].includes(String(data["harness"])) || data["harnesses"] !== void 0 && !validHarnesses || data["harnesses"] !== void 0 && action !== "setup" || data["harnesses"] !== void 0 && data["harness"] !== void 0 || data["task"] !== void 0 && !TASKS.has(String(data["task"])) || data["provider"] !== void 0 && !["rtk", "harnesstrim", "mcptoon", "gitnexus", "headroom"].includes(String(data["provider"])) || data["candidate"] !== void 0 && !["mcptoon", "gitnexus"].includes(String(data["candidate"])) || action === "effort" && (data["harness"] === void 0 || data["task"] === void 0) || action === "skill" && data["harness"] === void 0 || action === "remove" && (data["provider"] === void 0 || data["harness"] !== void 0 || data["harnesses"] !== void 0 || data["task"] !== void 0 || data["candidate"] !== void 0) || data["provider"] !== void 0 && action !== "remove" && action !== "setup" || candidateAction && (data["candidate"] === void 0 || data["harness"] === void 0 || data["provider"] !== void 0 || data["task"] !== void 0) || !candidateAction && data["candidate"] !== void 0)
37473
+ "candidate-remove",
37474
+ "routing-setup",
37475
+ "routing-remove",
37476
+ "routing-metrics"
37477
+ ].includes(action) || data["harness"] !== void 0 && !["claude", "codex"].includes(String(data["harness"])) || data["harnesses"] !== void 0 && !validHarnesses || data["harnesses"] !== void 0 && action !== "setup" || data["routeMode"] !== void 0 && !["shadow", "conservative"].includes(String(data["routeMode"])) || data["harnesses"] !== void 0 && data["harness"] !== void 0 || data["task"] !== void 0 && !TASKS.has(String(data["task"])) || data["provider"] !== void 0 && !["rtk", "harnesstrim", "mcptoon", "gitnexus", "headroom"].includes(String(data["provider"])) || data["candidate"] !== void 0 && !["mcptoon", "gitnexus"].includes(String(data["candidate"])) || action === "effort" && (data["harness"] === void 0 || data["task"] === void 0) || action === "skill" && data["harness"] === void 0 || routingAction && data["harness"] === void 0 || action !== "routing-setup" && data["routeMode"] !== void 0 || action === "remove" && (data["provider"] === void 0 || data["harness"] !== void 0 || data["harnesses"] !== void 0 || data["task"] !== void 0 || data["candidate"] !== void 0) || data["provider"] !== void 0 && action !== "remove" && action !== "setup" || candidateAction && (data["candidate"] === void 0 || data["harness"] === void 0 || data["provider"] !== void 0 || data["task"] !== void 0) || !candidateAction && data["candidate"] !== void 0 || routingAction && (data["provider"] !== void 0 || data["candidate"] !== void 0 || data["task"] !== void 0 || data["harnesses"] !== void 0))
37454
37478
  throw new GuideError(400, "Choose a supported agent and action.");
37455
37479
  return this.exclusive(async () => {
37456
37480
  this.approval = null;
37481
+ if (routingAction) {
37482
+ const harness = String(data["harness"]);
37483
+ const mode = data["routeMode"] === "conservative" ? "conservative" : "shadow";
37484
+ if (action === "routing-metrics") {
37485
+ this.record(`Reading local Smart Model Routing decisions for ${name(harness)}. No configuration is changed.`, "working");
37486
+ const result7 = await this.call([
37487
+ "routing",
37488
+ "--route-metrics",
37489
+ "--ccr-usage",
37490
+ "--harness",
37491
+ harness,
37492
+ "--since",
37493
+ "30d"
37494
+ ]);
37495
+ if (result7.exitCode !== 0 || result7.data?.kind !== "metrics") {
37496
+ const message = explainGuideIssue(result7.diagnostics, `Routing activity for ${name(harness)} could not be read. No configuration changed.`);
37497
+ this.record(message, "attention");
37498
+ return {
37499
+ ticket: null,
37500
+ title: "Routing activity needs attention",
37501
+ changes: [],
37502
+ notices: [message],
37503
+ expiresAt: null,
37504
+ network: false,
37505
+ restart: false
37506
+ };
37507
+ }
37508
+ const metrics = result7.data.metrics;
37509
+ const notices2 = [
37510
+ `${String(metrics.retainedDecisionCount)} local routing decision${metrics.retainedDecisionCount === 1 ? "" : "s"} recorded in the last 30 days for ${name(harness)}.`,
37511
+ `Shadow decisions: ${String(metrics.byMode.shadow)}. Conservative route requests: ${String(metrics.routeMutationRequestCount)}.`,
37512
+ `Tiers: simple ${String(metrics.byTier.simple)}, standard ${String(metrics.byTier.standard)}, complex ${String(metrics.byTier.complex)}, critical ${String(metrics.byTier.critical)}.`,
37513
+ "Routing telemetry stores classifier features and model identifiers, not prompt text. Subscription savings remain not measured until paired quality and allowance evidence exists."
37514
+ ];
37515
+ this.record("Routing activity read successfully.", "success");
37516
+ return {
37517
+ ticket: null,
37518
+ title: `Smart Model Routing \xB7 ${name(harness)}`,
37519
+ changes: [],
37520
+ notices: notices2,
37521
+ expiresAt: null,
37522
+ network: false,
37523
+ restart: false
37524
+ };
37525
+ }
37526
+ const removing = action === "routing-remove";
37527
+ this.record(`${removing ? "Reviewing removal of" : "Reviewing"} Smart Model Routing for ${name(harness)}. Nothing has changed yet.`, "working");
37528
+ const args = removing ? ["routing", "--rollback-ccr", "--harness", harness] : ["routing", "--configure-ccr", "--harness", harness, "--route-mode", mode];
37529
+ const result6 = await this.call(args);
37530
+ if (result6.exitCode !== 0 || result6.data === null) {
37531
+ const message = explainGuideIssue(result6.diagnostics, `No safe Smart Model Routing ${removing ? "removal" : "setup"} is available for ${name(harness)}. Nothing was changed.`);
37532
+ this.record(message, "attention");
37533
+ return {
37534
+ ticket: null,
37535
+ title: "No routing change to apply",
37536
+ changes: [],
37537
+ notices: [message],
37538
+ expiresAt: null,
37539
+ network: false,
37540
+ restart: false
37541
+ };
37542
+ }
37543
+ const report = result6.data;
37544
+ const alreadyConfigured = !removing && report.kind === "ccr-configuration" && report.state === "already-configured";
37545
+ const alreadyAbsent = removing && report.kind === "ccr-configuration" && report.state === "already-absent";
37546
+ if (alreadyConfigured || alreadyAbsent) {
37547
+ const message = alreadyConfigured ? `${name(harness)} already has the Token Harness-owned ${mode} routing rule.` : `${name(harness)} has no Token Harness-owned routing rule to remove.`;
37548
+ this.record(message, "success");
37549
+ return {
37550
+ ticket: null,
37551
+ title: alreadyConfigured ? "Routing already configured" : "Routing already absent",
37552
+ changes: [],
37553
+ notices: [message],
37554
+ expiresAt: null,
37555
+ network: false,
37556
+ restart: false
37557
+ };
37558
+ }
37559
+ const ticket = this.random();
37560
+ const expires2 = this.now() + 10 * 6e4;
37561
+ const lifecycle = report.kind === "ccr-lifecycle";
37562
+ const network2 = lifecycle && report.action !== "start";
37563
+ this.approval = {
37564
+ id: ticket,
37565
+ expires: expires2,
37566
+ plans: [],
37567
+ transactionId: null,
37568
+ provider: null,
37569
+ description: `Smart Model Routing ${removing ? "removal" : mode}`,
37570
+ operation: removing ? "routing-rollback" : "routing-configure",
37571
+ network: network2,
37572
+ routingHarness: harness,
37573
+ routingMode: mode
37574
+ };
37575
+ const change = report.kind === "ccr-lifecycle" ? {
37576
+ title: `${name(harness)}: prepare local CCR routing runtime`,
37577
+ files: 0,
37578
+ description: report.action === "install" ? `Install the reviewed CCR ${report.version} CLI inside Token Harness protected local state, start its loopback gateway and verify it. No global CCR package, provider login or native harness endpoint is replaced.` : `Start or update the Token Harness-owned CCR ${report.version} runtime and verify its loopback gateway before any routing rule is configured.`
37579
+ } : {
37580
+ title: `${name(harness)}: ${removing ? "remove" : "configure"} Smart Model Routing`,
37581
+ files: 0,
37582
+ description: removing ? "Remove only the Token Harness-owned CCR rule/profile for this coding agent. Provider credentials and unrelated CCR configuration are left untouched." : mode === "shadow" ? "Install the Token Harness-owned CCR rule in shadow mode. Requests keep their current model; only local routing decisions are recorded." : "Install the conservative opt-in rule. Only high-confidence simple requests may request the already-configured simple model; complex, ambiguous, image and unsafe tool requests pass through unchanged."
37583
+ };
37584
+ this.record("Smart Model Routing preview ready. Waiting for your approval.", "success");
37585
+ return {
37586
+ ticket,
37587
+ title: removing ? `Remove Smart Model Routing for ${name(harness)}?` : `Set up ${mode} Smart Model Routing for ${name(harness)}?`,
37588
+ changes: [change],
37589
+ notices: [
37590
+ lifecycle && !removing ? "CCR runtime preparation and routing-rule configuration are deliberately separate safety stages. After the runtime is ready, open Manage routing again to review the exact rule/profile." : "Token Harness owns only its exact CCR rule/profile and local managed runtime. Provider credentials remain in CCR and are never imported silently.",
37591
+ mode === "shadow" && !removing ? "Shadow mode is the default: it never changes the model selected for a request." : mode === "conservative" && !removing ? "Conservative routing requires TOKEN_HARNESS_ROUTING_SIMPLE_MODEL to name an exact model already configured in CCR. Without that explicit model the preview is refused." : "Removing routing does not uninstall CCR or delete provider credentials."
37592
+ ],
37593
+ expiresAt: new Date(expires2).toISOString(),
37594
+ network: network2,
37595
+ restart: false
37596
+ };
37597
+ }
37457
37598
  if (candidateAction) {
37458
37599
  const candidate = String(data["candidate"]);
37459
37600
  const harness = String(data["harness"]);
@@ -37854,6 +37995,86 @@ var init_guided = __esm({
37854
37995
  appliedPlans: appliedCount
37855
37996
  };
37856
37997
  }
37998
+ if (approval.operation === "routing-configure" || approval.operation === "routing-rollback") {
37999
+ if (approval.routingHarness === void 0 || approval.routingMode === void 0)
38000
+ throw new GuideError(409, "This Smart Model Routing preview is incomplete. Review it again.");
38001
+ const harness = approval.routingHarness;
38002
+ const mode = approval.routingMode;
38003
+ const removing = approval.operation === "routing-rollback";
38004
+ this.record((removing ? "Removing" : "Applying") + " Smart Model Routing for " + name(harness) + ".", "working");
38005
+ let result6;
38006
+ try {
38007
+ result6 = await this.call(removing ? ["routing", "--rollback-ccr", "--harness", harness, "--yes"] : ["routing", "--configure-ccr", "--harness", harness, "--route-mode", mode, "--yes"]);
38008
+ } catch {
38009
+ this.invalidateObservedState();
38010
+ const message = "The Smart Model Routing operation stopped before its final result could be read. No automatic retry was made. Review the local routing state before retrying.";
38011
+ this.record(message, "attention");
38012
+ return {
38013
+ ok: false,
38014
+ title: "Routing result needs checking",
38015
+ messages: [message],
38016
+ appliedPlans: 0
38017
+ };
38018
+ }
38019
+ if (result6.exitCode !== 0 || result6.data === null) {
38020
+ const message = explainGuideIssue(result6.diagnostics, "Smart Model Routing for " + name(harness) + " was not changed. The local CCR runtime, provider model selection or owned rule state no longer matches the preview.");
38021
+ this.invalidateObservedState();
38022
+ this.record(message, "attention");
38023
+ return {
38024
+ ok: false,
38025
+ title: "Routing change was not applied",
38026
+ messages: [message],
38027
+ appliedPlans: 0
38028
+ };
38029
+ }
38030
+ const report = result6.data;
38031
+ this.lastApplied = null;
38032
+ this.invalidateObservedState();
38033
+ if (report.kind === "ccr-lifecycle") {
38034
+ const message = "The Token Harness-owned CCR " + report.version + " runtime is ready and verified on loopback. No routing rule has been assumed from this runtime step. Open Manage routing again to review the exact shadow or conservative rule/profile.";
38035
+ this.record("CCR routing runtime prepared and verified.", "success");
38036
+ return {
38037
+ ok: true,
38038
+ title: "Routing runtime ready",
38039
+ messages: [
38040
+ message,
38041
+ "Provider login/import remains an explicit CCR choice; Token Harness did not change Claude Code or Codex native endpoints."
38042
+ ],
38043
+ appliedPlans: report.state === "already-current" ? 0 : 1
38044
+ };
38045
+ }
38046
+ if (report.kind !== "ccr-configuration") {
38047
+ const message = "The routing command returned an unexpected result shape after approval. No success is being reported; review the local CCR routing state before retrying.";
38048
+ this.record(message, "attention");
38049
+ return {
38050
+ ok: false,
38051
+ title: "Routing result needs checking",
38052
+ messages: [message],
38053
+ appliedPlans: 0
38054
+ };
38055
+ }
38056
+ const changed = report.state === "configured" || report.state === "rolled-back";
38057
+ const messages2 = removing ? [
38058
+ report.state === "already-absent" ? name(harness) + " already had no Token Harness-owned routing rule." : "The Token Harness-owned Smart Model Routing rule/profile for " + name(harness) + " was removed. CCR and provider credentials were left in place."
38059
+ ] : [
38060
+ report.state === "already-configured" ? name(harness) + " already has the Token Harness-owned " + mode + " routing rule." : name(harness) + " Smart Model Routing is configured in " + mode + " mode.",
38061
+ ...mode === "shadow" ? [
38062
+ "Shadow mode records local routing decisions but does not change the request model."
38063
+ ] : [
38064
+ "Conservative mode may request the configured simple model only for high-confidence simple prompts; safety-gated requests pass through unchanged."
38065
+ ],
38066
+ ...report.launchCommand ? ["Launch through the CCR profile to use the rule: " + report.launchCommand] : [
38067
+ "CCR still needs an unambiguous provider/model profile before a routed launch can be verified."
38068
+ ]
38069
+ ];
38070
+ this.record(removing ? "Smart Model Routing rule removed." : "Smart Model Routing configured.", "success");
38071
+ return {
38072
+ ok: true,
38073
+ title: removing ? "Routing removed" : "Smart Model Routing configured",
38074
+ messages: messages2,
38075
+ appliedPlans: changed ? 1 : 0
38076
+ };
38077
+ }
37857
38078
  if (approval.operation === "candidate-apply" || approval.operation === "candidate-uninstall") {
37858
38079
  if (approval.candidate === void 0 || approval.candidateHarness === void 0)
37859
38080
  throw new GuideError(409, "This experimental preview is incomplete. Review it again.");
@@ -38061,6 +38282,7 @@ var init_guided = __esm({
38061
38282
  ];
38062
38283
  const applicationUpgradable = updateResult.data.application?.verdict === "upgradable";
38063
38284
  const blocked = updateResult.data.providers.filter((row2) => row2.verdict === "blocked-unreviewed");
38285
+ const updateWarnings = updateResult.diagnostics.filter((entry) => entry.severity === "warning");
38064
38286
  const messages = [];
38065
38287
  const application = updateResult.data.application;
38066
38288
  if (application?.verdict === "upgradable") {
@@ -38076,9 +38298,15 @@ var init_guided = __esm({
38076
38298
  if (blocked.length > 0) {
38077
38299
  messages.push(...blocked.map((row2) => `${name(row2.providerId)}: ${row2.available ?? "a newer version"} exists, but Token Harness is keeping ${row2.installed ?? "the installed version"} because the target does not meet the provider update prerequisites.`));
38078
38300
  }
38079
- if (available.length === 0 && blocked.length === 0 && application?.verdict === "current") {
38301
+ if (updateWarnings.length > 0) {
38302
+ messages.push(...updateWarnings.map((entry) => {
38303
+ const label = entry.subject === null || entry.subject === void 0 ? "Update check" : name(entry.subject);
38304
+ return label + ": " + entry.message + (entry.remediation === null || entry.remediation === void 0 ? "" : " " + entry.remediation);
38305
+ }));
38306
+ }
38307
+ if (available.length === 0 && blocked.length === 0 && updateWarnings.length === 0 && application?.verdict === "current") {
38080
38308
  messages.push("Token Harness and your managed optimizers are up to date.");
38081
- } else if (available.length === 0 && blocked.length === 0 && application === void 0) {
38309
+ } else if (available.length === 0 && blocked.length === 0 && updateWarnings.length === 0 && application === void 0) {
38082
38310
  messages.push("Your managed optimizers are up to date on their configured channels.");
38083
38311
  }
38084
38312
  let ticket = null;
@@ -38106,10 +38334,10 @@ var init_guided = __esm({
38106
38334
  const stack = this.stackSnapshot();
38107
38335
  if (this.cached !== null)
38108
38336
  this.cached.value = { ...this.cached.value, stack };
38109
- this.record(ticket !== null ? "Token Harness or optimizer update available. Waiting for your approval." : upgradableCount > 0 ? "Update check could not produce an exact install target." : "Token Harness and optimizer update check completed.", "success");
38337
+ this.record(ticket !== null ? "Token Harness or optimizer update available. Waiting for your approval." : upgradableCount > 0 || updateWarnings.length > 0 ? "Update check needs attention." : "Token Harness and optimizer update check completed.", upgradableCount > 0 || updateWarnings.length > 0 ? "attention" : "success");
38110
38338
  return {
38111
38339
  ok: true,
38112
- title: ticket !== null ? "Updates available" : upgradableCount > 0 ? "Update check needs attention" : application?.verdict === "current" ? "Token Harness and optimizers up to date" : "Update check completed",
38340
+ title: ticket !== null ? "Updates available" : upgradableCount > 0 || updateWarnings.length > 0 ? "Update check needs attention" : application?.verdict === "current" ? "Token Harness and optimizers up to date" : "Update check completed",
38113
38341
  messages,
38114
38342
  appliedPlans: 0,
38115
38343
  stack,
@@ -41290,6 +41518,155 @@ var init_guided_product_client = __esm({
41290
41518
  });
41291
41519
  }
41292
41520
 
41521
+
41522
+ function reviewRoutingAction(harness, action, routeMode, run) {
41523
+ const label =
41524
+ action === 'routing-metrics'
41525
+ ? 'Reading routing activity'
41526
+ : action === 'routing-remove'
41527
+ ? 'Reviewing routing removal'
41528
+ : 'Reviewing ' + routeMode + ' routing setup';
41529
+ $('modal-content').replaceChildren(
41530
+ progress(label, 'Nothing changes while Token Harness reads the local routing state.'),
41531
+ );
41532
+ $('modal-actions').replaceChildren(modalClose('Cancel'));
41533
+ setBusy(true, false);
41534
+ ensureSession()
41535
+ .then(() =>
41536
+ request('/api/preview', {
41537
+ action,
41538
+ harness,
41539
+ ...(action === 'routing-setup' ? { routeMode } : {}),
41540
+ }),
41541
+ )
41542
+ .then(data => {
41543
+ if (run !== modalRun || !$('modal').open) return;
41544
+ pendingTicket = data.ticket;
41545
+ $('modal-content').replaceChildren(
41546
+ messageBox(
41547
+ 'Smart Model Routing · ' + agentName(harness),
41548
+ action === 'routing-metrics'
41549
+ ? 'Local classifier and CCR activity only. Prompt text and credentials are not shown.'
41550
+ : action === 'routing-remove'
41551
+ ? 'Only the Token Harness-owned CCR rule/profile is eligible for removal.'
41552
+ : routeMode === 'shadow'
41553
+ ? 'Shadow mode is the safe default: it classifies requests locally and records decisions without changing the selected model.'
41554
+ : 'Conservative mode is opt-in: only high-confidence simple requests may request one already-configured simple model; safety-gated requests pass through unchanged.',
41555
+ ),
41556
+ );
41557
+ for (const change of data.changes || []) {
41558
+ const item = node('article', undefined, 'preview-change');
41559
+ item.append(node('h3', change.title), node('p', change.description));
41560
+ $('modal-content').append(item);
41561
+ }
41562
+ for (const notice of data.notices || [])
41563
+ $('modal-content').append(node('p', notice, 'notice-row'));
41564
+ if (action !== 'routing-metrics')
41565
+ $('modal-content').append(
41566
+ messageBox(
41567
+ 'Safety boundary',
41568
+ 'Token Harness owns only its exact CCR runtime/rule/profile. Provider credentials remain in CCR, native Claude Code/Codex endpoints are not rewritten, and every mutation still requires this explicit approval.',
41569
+ 'safe',
41570
+ ),
41571
+ );
41572
+ $('modal-actions').replaceChildren(modalClose(data.ticket ? 'Cancel' : 'Done'));
41573
+ if (data.ticket)
41574
+ $('modal-actions').append(
41575
+ actionButton(
41576
+ action === 'routing-remove'
41577
+ ? 'Remove managed routing'
41578
+ : routeMode === 'conservative'
41579
+ ? 'Apply conservative routing step'
41580
+ : 'Apply shadow routing step',
41581
+ () => applyTicket(data.ticket),
41582
+ ),
41583
+ );
41584
+ })
41585
+ .catch(error => {
41586
+ if (run !== modalRun) return;
41587
+ $('modal-error').textContent = error.message;
41588
+ $('modal-error').hidden = false;
41589
+ $('modal-actions').replaceChildren(modalClose('Close'));
41590
+ })
41591
+ .finally(() => {
41592
+ if (run === modalRun) setBusy(false, false);
41593
+ loadActivity();
41594
+ });
41595
+ }
41596
+
41597
+ function manageRouting(harness) {
41598
+ if (busy) return;
41599
+ const run = modal('Smart Model Routing · ' + agentName(harness));
41600
+ $('modal-content').append(
41601
+ messageBox(
41602
+ 'Shadow-first routing',
41603
+ 'The classifier runs locally with deterministic heuristics. It needs no paid routing API and no local LLM. The reviewed CCR gateway is used only as the local request-routing surface.',
41604
+ ),
41605
+ messageBox(
41606
+ 'How to use it',
41607
+ 'Start with Shadow. After CCR is prepared, review Shadow again to install the exact rule/profile. Launch the agent through the CCR profile shown after configuration. Conservative mode is optional and requires an exact simple model already configured in CCR.',
41608
+ ),
41609
+ messageBox(
41610
+ 'What is measured',
41611
+ 'Routing decisions are kept separate from optimizer token savings. A cheaper model is not counted as saved quota unless paired quality and allowance evidence proves it.',
41612
+ 'safe',
41613
+ ),
41614
+ );
41615
+ $('modal-actions').append(
41616
+ modalClose('Close'),
41617
+ actionButton(
41618
+ 'View 30-day activity',
41619
+ () => reviewRoutingAction(harness, 'routing-metrics', 'shadow', run),
41620
+ 'secondary',
41621
+ ),
41622
+ actionButton(
41623
+ 'Remove managed rule',
41624
+ () => reviewRoutingAction(harness, 'routing-remove', 'shadow', run),
41625
+ 'secondary',
41626
+ ),
41627
+ actionButton(
41628
+ 'Review conservative setup',
41629
+ () => reviewRoutingAction(harness, 'routing-setup', 'conservative', run),
41630
+ 'secondary',
41631
+ ),
41632
+ actionButton(
41633
+ 'Review shadow setup',
41634
+ () => reviewRoutingAction(harness, 'routing-setup', 'shadow', run),
41635
+ ),
41636
+ );
41637
+ }
41638
+
41639
+ function renderRouting() {
41640
+ const root = $('routing-overview');
41641
+ if (!root) return;
41642
+ root.replaceChildren();
41643
+ const agents = activeAgents();
41644
+ if (!agents.length) {
41645
+ root.append(
41646
+ messageBox(
41647
+ 'No supported coding agent detected',
41648
+ 'Smart Model Routing is available for Claude Code and Codex after the agent is detected.',
41649
+ 'warn',
41650
+ ),
41651
+ );
41652
+ return;
41653
+ }
41654
+ for (const agent of agents) {
41655
+ const row = node('article', undefined, 'maintenance-row');
41656
+ const copy = node('div');
41657
+ copy.append(
41658
+ node('strong', agent.name),
41659
+ node(
41660
+ 'p',
41661
+ 'Optional request routing through a local CCR profile. Shadow mode never changes models; conservative mode is explicit and safety-gated.',
41662
+ 'caption',
41663
+ ),
41664
+ );
41665
+ row.append(copy, actionButton('Manage routing', () => manageRouting(agent.id), 'secondary'));
41666
+ root.append(row);
41667
+ }
41668
+ }
41669
+
41293
41670
  function renderMaintenance() {
41294
41671
  const root = $('maintenance-actions');
41295
41672
  root.replaceChildren();
@@ -41354,6 +41731,7 @@ var init_guided_product_client = __esm({
41354
41731
  renderManagedSetup();
41355
41732
  renderExperimental();
41356
41733
  renderTuning();
41734
+ renderRouting();
41357
41735
  renderMaintenance();
41358
41736
  }
41359
41737
 
@@ -42397,6 +42775,11 @@ ${GUIDE_CANDIDATE_READINESS_JS}`;
42397
42775
  <details class="disclosure"><summary>Remove Token Harness-managed configuration</summary><p class="caption">Removal is reviewed first. Token Harness removes only configuration it owns; installed provider software and user-owned configuration may remain.</p><div id="managed-removal-actions" class="maintenance-list"><p class="caption">Checking managed ownership\u2026</p></div></details>
42398
42776
  </section>
42399
42777
 
42778
+ <section class="setup-step" id="smart-routing">
42779
+ <div class="section-title"><div><h2>Smart Model Routing</h2><p>Optional shadow-first request routing for Claude Code and Codex. Shadow mode observes locally without changing models; conservative routing is an explicit opt-in.</p></div></div>
42780
+ <div id="routing-overview" class="maintenance-list"><p class="empty">Checking supported coding agents\u2026</p></div>
42781
+ </section>
42782
+
42400
42783
  <section class="setup-step" id="maintenance">
42401
42784
  <div class="section-title"><div><h2>Health and updates</h2><p>These are maintenance actions, not onboarding steps. Setup already performs its own safety checks.</p></div></div>
42402
42785
  <div id="maintenance-actions" class="maintenance-list"><p class="empty">Checking\u2026</p></div>