token-harness 0.1.13 → 0.1.14

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.13",
3
+ "version": "0.1.14",
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:f53f4600-4e02-4fbe-462d-286326adfd0b",
4
+ "serialNumber": "urn:uuid:8840bbd7-fcea-b78f-b033-a40bef562512",
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.13",
11
+ "version": "0.1.14",
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": "f53f46004e024fbe462d286326adfd0be1a2e5d5c2678346e1e2e7e39bce853b"
23
+ "content": "8840bbd7fceab78fb033a40bef5625123772648c48cb4fea73b39020b714e9cf"
24
24
  }
25
25
  ]
26
26
  },
package/token-harness.mjs CHANGED
@@ -9387,7 +9387,7 @@ var TOOL_VERSION;
9387
9387
  var init_version2 = __esm({
9388
9388
  "apps/cli/dist/src/version.js"() {
9389
9389
  "use strict";
9390
- TOOL_VERSION = "0.1.13";
9390
+ TOOL_VERSION = "0.1.14";
9391
9391
  }
9392
9392
  });
9393
9393
 
@@ -32753,30 +32753,43 @@ var init_guided = __esm({
32753
32753
  let network = false;
32754
32754
  for (const agent of selected) {
32755
32755
  this.record(`Preparing supported changes for ${name(agent.harnessId)}. No settings changed.`, "working");
32756
- const args = ["plan", "--harness", agent.harnessId];
32757
- if (data["action"] === "setup" && data["provider"] !== void 0)
32758
- args.push("--provider", String(data["provider"]));
32759
- if (data["action"] === "skill") {
32760
- args.push("--provider", "none", "--agent-skill");
32761
- } else if (data["action"] === "effort")
32762
- args.push("--provider", "none", "--native-policy", "--task", String(data["task"]), "--profile", data["task"] === "mechanical" ? "economy" : data["task"] === "standard" ? "balanced" : "quality");
32763
- const result6 = await this.call(args);
32764
- const report = result6.data;
32765
- if (report === null || result6.exitCode !== 0 || report.conflicts.length > 0 || report.actions.length === 0 || !report.persisted || report.planId === null) {
32766
- notices.push(`${name(agent.harnessId)}: ${explainGuideIssue(result6.diagnostics, data["action"] === "effort" ? "No supported preference change is needed or available. Your current preference is kept." : data["action"] === "skill" ? "In-session guidance is already present, or an existing user-owned skill location was left untouched." : "No safe setup change is available. The integration may already be configured, or a required provider is not installed.")}`);
32767
- continue;
32768
- }
32769
- plans.push(report.planId);
32770
- if (data["action"] === "skill") {
32771
- changes.push({
32772
- title: `${name(agent.harnessId)}: enable in-session guidance`,
32773
- description: "Installs one reviewed Token Harness Agent Skill in the standard user skill directory. It does not change model, login, billing, hooks, trust, or the current conversation.",
32774
- files: 1
32775
- });
32756
+ const setupProviders = [];
32757
+ if (data["action"] === "setup" && data["harness"] !== void 0) {
32758
+ if (data["provider"] === void 0) {
32759
+ setupProviders.push("rtk", "harnesstrim");
32760
+ } else {
32761
+ setupProviders.push(String(data["provider"]));
32762
+ }
32776
32763
  } else {
32777
- changes.push(...report.actions.map((action2) => describeChange(action2, agent.harnessId)));
32764
+ setupProviders.push(null);
32765
+ }
32766
+ for (const setupProvider of setupProviders) {
32767
+ const args = ["plan", "--harness", agent.harnessId];
32768
+ if (setupProvider !== null)
32769
+ args.push("--provider", setupProvider);
32770
+ if (data["action"] === "skill") {
32771
+ args.push("--provider", "none", "--agent-skill");
32772
+ } else if (data["action"] === "effort")
32773
+ args.push("--provider", "none", "--native-policy", "--task", String(data["task"]), "--profile", data["task"] === "mechanical" ? "economy" : data["task"] === "standard" ? "balanced" : "quality");
32774
+ const result6 = await this.call(args);
32775
+ const report = result6.data;
32776
+ if (report === null || result6.exitCode !== 0 || report.conflicts.length > 0 || report.actions.length === 0 || !report.persisted || report.planId === null) {
32777
+ const subject = setupProvider !== null ? `${name(agent.harnessId)} \xB7 ${name(setupProvider)}` : name(agent.harnessId);
32778
+ notices.push(`${subject}: ${explainGuideIssue(result6.diagnostics, data["action"] === "effort" ? "No supported preference change is needed or available. Your current preference is kept." : data["action"] === "skill" ? "In-session guidance is already present, or an existing user-owned skill location was left untouched." : "No safe setup change is available. The integration may already be configured, or a required provider is not installed.")}`);
32779
+ continue;
32780
+ }
32781
+ plans.push(report.planId);
32782
+ if (data["action"] === "skill") {
32783
+ changes.push({
32784
+ title: `${name(agent.harnessId)}: enable in-session guidance`,
32785
+ description: "Installs one reviewed Token Harness Agent Skill in the standard user skill directory. It does not change model, login, billing, hooks, trust, or the current conversation.",
32786
+ files: 1
32787
+ });
32788
+ } else {
32789
+ changes.push(...report.actions.map((action2) => describeChange(action2, agent.harnessId)));
32790
+ }
32791
+ network ||= report.network.length > 0;
32778
32792
  }
32779
- network ||= report.network.length > 0;
32780
32793
  }
32781
32794
  if (selected.length === 0)
32782
32795
  notices.push("No supported coding agent was found. Install and sign in to Claude Code or Codex, then refresh.");
@@ -34840,9 +34853,20 @@ var init_guided_capabilities_client = __esm({
34840
34853
  return data;
34841
34854
  }
34842
34855
 
34843
- function markStale() {
34844
- $('stale-state').hidden = false;
34845
- $('stale-state').textContent = 'A reviewed change was applied. Displayed status is the previous state until you choose Refresh.';
34856
+ async function waitForAutomaticRefresh() {
34857
+ $('stale-state').hidden = true;
34858
+ $('stale-state').textContent = '';
34859
+ const spinner = $('reading-spinner');
34860
+ const refresh = $('refresh');
34861
+ let observedRefresh = false;
34862
+ refresh.click();
34863
+ const deadline = Date.now() + 120000;
34864
+ while (Date.now() < deadline) {
34865
+ if (!spinner.hidden) observedRefresh = true;
34866
+ if (observedRefresh && spinner.hidden) return;
34867
+ await new Promise(resolve => setTimeout(resolve, 100));
34868
+ }
34869
+ throw new Error('The latest setup state could not be read automatically.');
34846
34870
  }
34847
34871
 
34848
34872
  async function applyTicket(ticket, title) {
@@ -34855,11 +34879,33 @@ var init_guided_capabilities_client = __esm({
34855
34879
  const result = await request('/api/apply', { ticket });
34856
34880
  if (activeRun !== runId) return;
34857
34881
  $('modal-title').textContent = result.ok ? title : 'Change needs attention';
34858
- $('modal-content').replaceChildren(message(result.ok ? 'Completed' : 'Needs attention', (result.messages || []).join(' ') || 'The transaction finished.', result.ok ? 'safe' : 'warn'));
34859
- if (result.ok) markStale();
34882
+ $('modal-content').replaceChildren(
34883
+ message(
34884
+ result.ok ? 'Applied' : 'Needs attention',
34885
+ (result.messages || []).join(' ') || 'The transaction finished.',
34886
+ result.ok ? 'safe' : 'warn',
34887
+ ),
34888
+ progress(
34889
+ 'Refreshing the current setup',
34890
+ 'Please wait while Token Harness re-reads the latest agent and optimizer state.',
34891
+ ),
34892
+ );
34893
+ $('modal-actions').replaceChildren(closeButton('Refreshing…', true));
34894
+ await waitForAutomaticRefresh();
34895
+ if (activeRun !== runId) return;
34896
+ $('modal-content').replaceChildren(
34897
+ message(
34898
+ result.ok ? 'Completed and refreshed' : 'Action finished; status refreshed',
34899
+ (result.messages || []).join(' ') || 'The latest setup state is now displayed.',
34900
+ result.ok ? 'safe' : 'warn',
34901
+ ),
34902
+ );
34860
34903
  $('modal-actions').replaceChildren(closeButton('Done'));
34861
34904
  } catch (error) {
34862
34905
  if (activeRun !== runId) return;
34906
+ $('stale-state').hidden = false;
34907
+ $('stale-state').textContent =
34908
+ 'The action finished, but Token Harness could not automatically refresh the latest setup state.';
34863
34909
  $('modal-error').textContent = error.message;
34864
34910
  $('modal-error').hidden = false;
34865
34911
  $('modal-actions').replaceChildren(closeButton('Close'));
@@ -34881,14 +34927,22 @@ var init_guided_capabilities_client = __esm({
34881
34927
  const data = await request('/api/preview', body);
34882
34928
  if (activeRun !== runId || !$('modal').open) return;
34883
34929
  $('modal-content').replaceChildren();
34884
- if (!(data.changes || []).length)
34885
- $('modal-content').append(message('No managed change proposed', (data.notices || []).join(' ') || 'Nothing needs to be changed.'));
34886
- for (const change of data.changes || []) {
34887
- const item = node('article', undefined, 'preview-change');
34888
- item.append(node('h3', change.title), node('p', change.description));
34889
- $('modal-content').append(item);
34890
- }
34891
- for (const notice of data.notices || []) $('modal-content').append(node('p', notice, 'notice-row'));
34930
+ if (!(data.changes || []).length) {
34931
+ $('modal-content').append(
34932
+ message(
34933
+ 'No managed change proposed',
34934
+ (data.notices || []).join(' ') || 'Nothing needs to be changed.',
34935
+ ),
34936
+ );
34937
+ } else {
34938
+ for (const change of data.changes || []) {
34939
+ const item = node('article', undefined, 'preview-change');
34940
+ item.append(node('h3', change.title), node('p', change.description));
34941
+ $('modal-content').append(item);
34942
+ }
34943
+ for (const notice of data.notices || [])
34944
+ $('modal-content').append(node('p', notice, 'notice-row'));
34945
+ }
34892
34946
  $('modal-content').append(message('Safety', 'Only Token Harness-owned changes can be applied or removed. User-owned provider installations and unrelated configuration are left untouched.', 'safe'));
34893
34947
  $('modal-actions').replaceChildren(closeButton(data.ticket ? 'Cancel' : 'Done'));
34894
34948
  if (data.ticket)
@@ -35512,17 +35566,25 @@ var init_guided_product_client = __esm({
35512
35566
  }
35513
35567
 
35514
35568
  const actions = node('div', undefined, 'inline-actions');
35515
- if (info.optional) {
35516
- for (const agent of activeAgents()) {
35517
- if (!providerSupportsAgent(id, agent.id)) continue;
35518
- if (!component?.configuredHarnesses?.includes(agent.id))
35519
- actions.append(
35520
- actionButton(
35521
- 'Set up for ' + agent.name,
35522
- () => reviewSetup(agent.id, id),
35523
- 'secondary',
35524
- ),
35525
- );
35569
+ for (const agent of activeAgents()) {
35570
+ if (!providerSupportsAgent(id, agent.id)) continue;
35571
+ if (component?.configuredHarnesses?.includes(agent.id)) continue;
35572
+ if (info.optional) {
35573
+ actions.append(
35574
+ actionButton(
35575
+ 'Set up for ' + agent.name,
35576
+ () => reviewSetup(agent.id, id),
35577
+ 'secondary',
35578
+ ),
35579
+ );
35580
+ } else {
35581
+ actions.append(
35582
+ actionButton(
35583
+ component?.installed ? 'Connect to ' + agent.name : 'Set up for ' + agent.name,
35584
+ () => reviewSetup(agent.id, id),
35585
+ 'secondary',
35586
+ ),
35587
+ );
35526
35588
  }
35527
35589
  }
35528
35590
  if (component?.update === 'available')
@@ -35636,7 +35698,7 @@ var init_guided_product_client = __esm({
35636
35698
  : 'This approval covers only RTK + HarnessTrim for ' + agent.name + '. Optional optimizers stay separate.',
35637
35699
  ),
35638
35700
  );
35639
- if (!data.changes.length)
35701
+ if (!data.changes.length) {
35640
35702
  $('modal-content').append(
35641
35703
  messageBox(
35642
35704
  'No setup change available',
@@ -35644,12 +35706,14 @@ var init_guided_product_client = __esm({
35644
35706
  'This setup is already complete, or a prerequisite/version prevents Token Harness from changing it safely.',
35645
35707
  ),
35646
35708
  );
35647
- for (const change of data.changes) {
35648
- const item = node('article', undefined, 'preview-change');
35649
- item.append(node('h3', change.title), node('p', change.description));
35650
- $('modal-content').append(item);
35709
+ } else {
35710
+ for (const change of data.changes) {
35711
+ const item = node('article', undefined, 'preview-change');
35712
+ item.append(node('h3', change.title), node('p', change.description));
35713
+ $('modal-content').append(item);
35714
+ }
35715
+ for (const notice of data.notices || []) $('modal-content').append(node('p', notice, 'notice-row'));
35651
35716
  }
35652
- for (const notice of data.notices || []) $('modal-content').append(node('p', notice, 'notice-row'));
35653
35717
  $('modal-content').append(messageBox('Safety', 'Apply uses the existing transactional engine with backups, compatibility checks, ownership checks and rollback. Unsupported versions are not forced.', 'safe'));
35654
35718
  $('modal-actions').replaceChildren(modalClose(data.ticket ? 'Cancel' : 'Done'));
35655
35719
  if (data.ticket)
@@ -35667,6 +35731,18 @@ var init_guided_product_client = __esm({
35667
35731
  });
35668
35732
  }
35669
35733
 
35734
+ async function refreshOverviewAfterMutation(message = 'Refreshing setup after the approved change…') {
35735
+ setStatus(message, true);
35736
+ $('stale-state').hidden = true;
35737
+ $('stale-state').textContent = '';
35738
+ const period = $('period').value;
35739
+ current = await request('/api/overview?period=' + encodeURIComponent(period) + '&refresh=1');
35740
+ periodCache.set(period, current);
35741
+ render();
35742
+ await loadActivity();
35743
+ setStatus('Updated at ' + new Date(current.generatedAt).toLocaleTimeString() + '.', false);
35744
+ }
35745
+
35670
35746
  async function applyTicket(ticket) {
35671
35747
  if (!ticket || busy) return;
35672
35748
  const run = modalRun;
@@ -35678,12 +35754,39 @@ var init_guided_product_client = __esm({
35678
35754
  const result = await request('/api/apply', { ticket });
35679
35755
  if (run !== modalRun) return;
35680
35756
  $('modal-title').textContent = result.title || (result.ok ? 'Setup completed' : 'Setup needs attention');
35681
- $('modal-content').replaceChildren(messageBox(result.ok ? 'Completed' : 'Needs attention', (result.messages || []).join(' '), result.ok ? 'safe' : 'warn'));
35682
- $('modal-content').append(node('p', 'The dashboard is now marked as previous state. Choose Refresh when you want to re-read the complete setup.', 'caption'));
35683
- $('stale-state').hidden = false;
35684
- $('stale-state').textContent = 'A setup change was applied. Displayed status is the previous state until you choose Refresh.';
35757
+ $('modal-content').replaceChildren(
35758
+ messageBox(result.ok ? 'Applied' : 'Needs attention', (result.messages || []).join(' '), result.ok ? 'safe' : 'warn'),
35759
+ progress('Refreshing the current setup', 'Please wait while Token Harness re-reads agents, optimizer connections and health after the change.'),
35760
+ );
35761
+ $('modal-actions').replaceChildren(modalClose('Refreshing…', true));
35762
+ try {
35763
+ await refreshOverviewAfterMutation('Applying the new configuration and refreshing status…');
35764
+ if (run !== modalRun) return;
35765
+ $('modal-content').replaceChildren(
35766
+ messageBox(
35767
+ result.ok ? 'Completed and refreshed' : 'Action finished; status refreshed',
35768
+ (result.messages || []).join(' ') || 'The latest setup state is now shown on the dashboard.',
35769
+ result.ok ? 'safe' : 'warn',
35770
+ ),
35771
+ );
35772
+ } catch (refreshError) {
35773
+ if (run !== modalRun) return;
35774
+ $('stale-state').hidden = false;
35775
+ $('stale-state').textContent = 'The action finished, but Token Harness could not automatically refresh the latest setup state.';
35776
+ $('modal-content').replaceChildren(
35777
+ messageBox(
35778
+ result.ok ? 'Change applied' : 'Action finished',
35779
+ (result.messages || []).join(' ') || 'The action completed.',
35780
+ result.ok ? 'safe' : 'warn',
35781
+ ),
35782
+ messageBox(
35783
+ 'Automatic refresh failed',
35784
+ refreshError.message || 'The latest setup state could not be read automatically. Use Refresh to retry the status check.',
35785
+ 'warn',
35786
+ ),
35787
+ );
35788
+ }
35685
35789
  $('modal-actions').replaceChildren(modalClose('Done'));
35686
- loadActivity();
35687
35790
  } catch (error) {
35688
35791
  if (run !== modalRun) return;
35689
35792
  $('modal-error').textContent = error.message;