token-harness 0.1.6 → 0.1.8
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/README.md +200 -714
- package/package.json +1 -1
- package/sbom.json +3 -3
- package/token-harness.mjs +1593 -483
package/token-harness.mjs
CHANGED
|
@@ -1462,10 +1462,10 @@ function truncateUtf8(value3, maxBytes) {
|
|
|
1462
1462
|
}
|
|
1463
1463
|
return `${value3.slice(0, low).trimEnd()}${suffix}`;
|
|
1464
1464
|
}
|
|
1465
|
-
function renderList(
|
|
1465
|
+
function renderList(title2, values, omitted) {
|
|
1466
1466
|
if (values.length === 0 && omitted === 0)
|
|
1467
1467
|
return [];
|
|
1468
|
-
const lines = [`## ${
|
|
1468
|
+
const lines = [`## ${title2}`];
|
|
1469
1469
|
for (const value3 of values)
|
|
1470
1470
|
lines.push(`- ${value3}`);
|
|
1471
1471
|
if (omitted > 0)
|
|
@@ -1879,6 +1879,26 @@ var init_compatibility_rows = __esm({
|
|
|
1879
1879
|
fixture: "tests/fixtures/rows/rtk-claude-windows",
|
|
1880
1880
|
verificationTier: "canary"
|
|
1881
1881
|
},
|
|
1882
|
+
{
|
|
1883
|
+
harness: "claude",
|
|
1884
|
+
harnessVersion: { minimum: "2.1.251", maximum: "2.1.251" },
|
|
1885
|
+
provider: "rtk",
|
|
1886
|
+
providerVersion: "0.44.0",
|
|
1887
|
+
platform: { os: "windows", wsl: false, supported: true, limitation: null },
|
|
1888
|
+
configSchema: "claude-settings-json-hooks-powershell",
|
|
1889
|
+
fixture: "tests/fixtures/rows/rtk-claude-windows-2.1.251-0.44.0",
|
|
1890
|
+
verificationTier: "canary"
|
|
1891
|
+
},
|
|
1892
|
+
{
|
|
1893
|
+
harness: "claude",
|
|
1894
|
+
harnessVersion: { minimum: "2.1.251", maximum: "2.1.251" },
|
|
1895
|
+
provider: "rtk",
|
|
1896
|
+
providerVersion: "0.48.0",
|
|
1897
|
+
platform: { os: "windows", wsl: false, supported: true, limitation: null },
|
|
1898
|
+
configSchema: "claude-settings-json-hooks-powershell",
|
|
1899
|
+
fixture: "tests/fixtures/rows/rtk-claude-windows-2.1.251-0.48.0",
|
|
1900
|
+
verificationTier: "canary"
|
|
1901
|
+
},
|
|
1882
1902
|
{
|
|
1883
1903
|
harness: "claude",
|
|
1884
1904
|
harnessVersion: { minimum: "2.1.220", maximum: "2.1.220" },
|
|
@@ -2223,6 +2243,13 @@ var init_reports = __esm({
|
|
|
2223
2243
|
}
|
|
2224
2244
|
});
|
|
2225
2245
|
|
|
2246
|
+
// packages/core/dist/src/domain/setup.js
|
|
2247
|
+
var init_setup = __esm({
|
|
2248
|
+
"packages/core/dist/src/domain/setup.js"() {
|
|
2249
|
+
"use strict";
|
|
2250
|
+
}
|
|
2251
|
+
});
|
|
2252
|
+
|
|
2226
2253
|
// packages/core/dist/src/domain/verification.js
|
|
2227
2254
|
function contributesToProblems(check) {
|
|
2228
2255
|
return check.status === "fail";
|
|
@@ -2827,9 +2854,9 @@ function providerRemovalOrder(ownership, candidates) {
|
|
|
2827
2854
|
break;
|
|
2828
2855
|
ordered.push(provider);
|
|
2829
2856
|
for (const dependent of [...edges.get(provider) ?? []].sort((left, right) => left.localeCompare(right))) {
|
|
2830
|
-
const
|
|
2831
|
-
indegree.set(dependent,
|
|
2832
|
-
if (
|
|
2857
|
+
const next2 = (indegree.get(dependent) ?? 0) - 1;
|
|
2858
|
+
indegree.set(dependent, next2);
|
|
2859
|
+
if (next2 === 0) {
|
|
2833
2860
|
ready.push(dependent);
|
|
2834
2861
|
ready.sort((left, right) => left.localeCompare(right));
|
|
2835
2862
|
}
|
|
@@ -4298,10 +4325,10 @@ function parseJsonPointer(pointer) {
|
|
|
4298
4325
|
for (let index = 0; index < pointer.length; index += 1) {
|
|
4299
4326
|
const char = pointer[index];
|
|
4300
4327
|
if (char === "\\") {
|
|
4301
|
-
const
|
|
4302
|
-
if (
|
|
4328
|
+
const next2 = pointer[index + 1];
|
|
4329
|
+
if (next2 !== "." && next2 !== "\\")
|
|
4303
4330
|
return null;
|
|
4304
|
-
current +=
|
|
4331
|
+
current += next2;
|
|
4305
4332
|
index += 1;
|
|
4306
4333
|
continue;
|
|
4307
4334
|
}
|
|
@@ -4416,13 +4443,13 @@ function ensureParent(document2, segments) {
|
|
|
4416
4443
|
if (!isJsonObject(current)) {
|
|
4417
4444
|
return { ok: false, reason: `\`${segments.slice(0, index).join(".")}\` is not an object` };
|
|
4418
4445
|
}
|
|
4419
|
-
const
|
|
4420
|
-
if (
|
|
4446
|
+
const next2 = current[segment];
|
|
4447
|
+
if (next2 === void 0) {
|
|
4421
4448
|
current[segment] = {};
|
|
4422
4449
|
current = current[segment];
|
|
4423
4450
|
continue;
|
|
4424
4451
|
}
|
|
4425
|
-
current =
|
|
4452
|
+
current = next2;
|
|
4426
4453
|
}
|
|
4427
4454
|
if (!isJsonObject(current)) {
|
|
4428
4455
|
return { ok: false, reason: `\`${segments.slice(0, -1).join(".")}\` is not an object` };
|
|
@@ -4650,31 +4677,31 @@ function upsertMarkerBlock(input) {
|
|
|
4650
4677
|
if (lookup.block.body === bodyText) {
|
|
4651
4678
|
return { ok: true, text: input.text, bodyDigest: lookup.block.bodyDigest, changed: false };
|
|
4652
4679
|
}
|
|
4653
|
-
const
|
|
4680
|
+
const next3 = [
|
|
4654
4681
|
...lines.slice(0, lookup.block.beginLine + 1),
|
|
4655
4682
|
...bodyLines,
|
|
4656
4683
|
...lines.slice(lookup.block.endLine)
|
|
4657
4684
|
];
|
|
4658
4685
|
return {
|
|
4659
4686
|
ok: true,
|
|
4660
|
-
text: `${hasBom ? BOM2 : ""}${joinLines(
|
|
4687
|
+
text: `${hasBom ? BOM2 : ""}${joinLines(next3)}`,
|
|
4661
4688
|
bodyDigest: digestText(bodyText),
|
|
4662
4689
|
changed: true
|
|
4663
4690
|
};
|
|
4664
4691
|
}
|
|
4665
|
-
const
|
|
4666
|
-
const trailing =
|
|
4667
|
-
const last =
|
|
4692
|
+
const next2 = lines.map((line) => ({ ...line }));
|
|
4693
|
+
const trailing = next2.length === 0 ? eol : next2[next2.length - 1]?.eol ?? eol;
|
|
4694
|
+
const last = next2[next2.length - 1];
|
|
4668
4695
|
if (last !== void 0 && last.eol === "")
|
|
4669
4696
|
last.eol = eol;
|
|
4670
|
-
if (
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4697
|
+
if (next2.length > 0)
|
|
4698
|
+
next2.push({ text: "", eol });
|
|
4699
|
+
next2.push({ text: fenceLine(input.fence.begin, input.syntax), eol });
|
|
4700
|
+
next2.push(...bodyLines);
|
|
4701
|
+
next2.push({ text: fenceLine(input.fence.end, input.syntax), eol: trailing });
|
|
4675
4702
|
return {
|
|
4676
4703
|
ok: true,
|
|
4677
|
-
text: `${hasBom ? BOM2 : ""}${joinLines(
|
|
4704
|
+
text: `${hasBom ? BOM2 : ""}${joinLines(next2)}`,
|
|
4678
4705
|
bodyDigest: digestText(bodyText),
|
|
4679
4706
|
changed: true
|
|
4680
4707
|
};
|
|
@@ -6205,8 +6232,8 @@ function withoutTrailingCommas(text3) {
|
|
|
6205
6232
|
let cursor = index + 1;
|
|
6206
6233
|
while (cursor < text3.length && /\s/.test(text3[cursor]))
|
|
6207
6234
|
cursor += 1;
|
|
6208
|
-
const
|
|
6209
|
-
if (
|
|
6235
|
+
const next2 = text3[cursor];
|
|
6236
|
+
if (next2 === "}" || next2 === "]") {
|
|
6210
6237
|
result2 += text3.slice(index + 1, cursor);
|
|
6211
6238
|
index = cursor;
|
|
6212
6239
|
continue;
|
|
@@ -6468,6 +6495,14 @@ var init_snapshots = __esm({
|
|
|
6468
6495
|
function terminal(status) {
|
|
6469
6496
|
return status !== "applied" && status !== "already-satisfied";
|
|
6470
6497
|
}
|
|
6498
|
+
function initialSnapshots(snapshots) {
|
|
6499
|
+
const firstByPath = /* @__PURE__ */ new Map();
|
|
6500
|
+
for (const snapshot of snapshots) {
|
|
6501
|
+
if (!firstByPath.has(snapshot.path))
|
|
6502
|
+
firstByPath.set(snapshot.path, snapshot);
|
|
6503
|
+
}
|
|
6504
|
+
return [...firstByPath.values()];
|
|
6505
|
+
}
|
|
6471
6506
|
async function verifyRestoration(fs, snapshots) {
|
|
6472
6507
|
const unrestored = [];
|
|
6473
6508
|
for (const snapshot of snapshots) {
|
|
@@ -6556,7 +6591,7 @@ async function executeTransaction(request) {
|
|
|
6556
6591
|
};
|
|
6557
6592
|
const rollback = async (cause) => {
|
|
6558
6593
|
diagnostics.push(...cause);
|
|
6559
|
-
const snapshots = request.snapshots.captured;
|
|
6594
|
+
const snapshots = initialSnapshots(request.snapshots.captured);
|
|
6560
6595
|
let restoreError = null;
|
|
6561
6596
|
try {
|
|
6562
6597
|
await request.snapshots.restoreAll(snapshots);
|
|
@@ -6690,7 +6725,7 @@ async function rollbackTransaction(request) {
|
|
|
6690
6725
|
]
|
|
6691
6726
|
};
|
|
6692
6727
|
}
|
|
6693
|
-
const snapshots = journal.entries.flatMap((entry) => entry.snapshots);
|
|
6728
|
+
const snapshots = initialSnapshots(journal.entries.flatMap((entry) => entry.snapshots));
|
|
6694
6729
|
const diagnostics = [];
|
|
6695
6730
|
let restoreError = null;
|
|
6696
6731
|
try {
|
|
@@ -6793,6 +6828,7 @@ var init_src = __esm({
|
|
|
6793
6828
|
init_process();
|
|
6794
6829
|
init_redaction();
|
|
6795
6830
|
init_reports();
|
|
6831
|
+
init_setup();
|
|
6796
6832
|
init_verification();
|
|
6797
6833
|
init_version();
|
|
6798
6834
|
init_envelope();
|
|
@@ -6831,7 +6867,7 @@ var TOOL_VERSION;
|
|
|
6831
6867
|
var init_version2 = __esm({
|
|
6832
6868
|
"apps/cli/dist/src/version.js"() {
|
|
6833
6869
|
"use strict";
|
|
6834
|
-
TOOL_VERSION = "0.1.
|
|
6870
|
+
TOOL_VERSION = "0.1.8";
|
|
6835
6871
|
}
|
|
6836
6872
|
});
|
|
6837
6873
|
|
|
@@ -6847,10 +6883,10 @@ function parseValue(argv2, index) {
|
|
|
6847
6883
|
const value3 = token.slice(equals + 1);
|
|
6848
6884
|
return { value: value3 === "" ? null : value3, consumed: 0 };
|
|
6849
6885
|
}
|
|
6850
|
-
const
|
|
6851
|
-
if (
|
|
6886
|
+
const next2 = argv2[index + 1];
|
|
6887
|
+
if (next2 === void 0 || next2.startsWith("-"))
|
|
6852
6888
|
return { value: null, consumed: 0 };
|
|
6853
|
-
return { value:
|
|
6889
|
+
return { value: next2, consumed: 1 };
|
|
6854
6890
|
}
|
|
6855
6891
|
function parseArgs(argv2) {
|
|
6856
6892
|
const args = {
|
|
@@ -7112,19 +7148,19 @@ function parse(argv2) {
|
|
|
7112
7148
|
continue;
|
|
7113
7149
|
}
|
|
7114
7150
|
const inline = equals >= 0 ? token.slice(equals + 1) : null;
|
|
7115
|
-
const
|
|
7116
|
-
if (
|
|
7151
|
+
const next2 = inline ?? argv2[index + 1] ?? null;
|
|
7152
|
+
if (next2 === null || next2 === "" || inline === null && next2.startsWith("-")) {
|
|
7117
7153
|
errors.push(`${name} requires a value`);
|
|
7118
7154
|
continue;
|
|
7119
7155
|
}
|
|
7120
7156
|
if (inline === null)
|
|
7121
7157
|
index += 1;
|
|
7122
7158
|
if (name === "--benchmark-id")
|
|
7123
|
-
args.benchmarkId =
|
|
7159
|
+
args.benchmarkId = next2;
|
|
7124
7160
|
else if (name === "--handoff-file")
|
|
7125
|
-
args.handoffFile =
|
|
7161
|
+
args.handoffFile = next2;
|
|
7126
7162
|
else {
|
|
7127
|
-
const parsed = Number(
|
|
7163
|
+
const parsed = Number(next2);
|
|
7128
7164
|
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
7129
7165
|
errors.push("--max-handoff-bytes must be a positive integer");
|
|
7130
7166
|
} else {
|
|
@@ -8790,19 +8826,19 @@ function parse2(argv2) {
|
|
|
8790
8826
|
continue;
|
|
8791
8827
|
}
|
|
8792
8828
|
const inline = equals >= 0 ? token.slice(equals + 1) : null;
|
|
8793
|
-
const
|
|
8794
|
-
if (
|
|
8829
|
+
const next2 = inline ?? argv2[index + 1] ?? null;
|
|
8830
|
+
if (next2 === null || next2 === "" || inline === null && next2.startsWith("-")) {
|
|
8795
8831
|
errors.push(`${name} requires a value`);
|
|
8796
8832
|
continue;
|
|
8797
8833
|
}
|
|
8798
8834
|
if (inline === null)
|
|
8799
8835
|
index += 1;
|
|
8800
8836
|
if (name === "--benchmark-id")
|
|
8801
|
-
args.benchmarkId =
|
|
8837
|
+
args.benchmarkId = next2;
|
|
8802
8838
|
else if (name === "--handoff-file")
|
|
8803
|
-
args.handoffFile =
|
|
8839
|
+
args.handoffFile = next2;
|
|
8804
8840
|
else {
|
|
8805
|
-
const parsed = Number(
|
|
8841
|
+
const parsed = Number(next2);
|
|
8806
8842
|
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
8807
8843
|
errors.push("--max-handoff-bytes must be a positive integer");
|
|
8808
8844
|
} else {
|
|
@@ -8960,10 +8996,10 @@ function valueAt(argv2, index) {
|
|
|
8960
8996
|
const value3 = token.slice(equals + 1);
|
|
8961
8997
|
return { value: value3.length > 0 ? value3 : null, consumed: 0 };
|
|
8962
8998
|
}
|
|
8963
|
-
const
|
|
8964
|
-
if (
|
|
8999
|
+
const next2 = argv2[index + 1];
|
|
9000
|
+
if (next2 === void 0 || next2.startsWith("-"))
|
|
8965
9001
|
return { value: null, consumed: 0 };
|
|
8966
|
-
return { value:
|
|
9002
|
+
return { value: next2, consumed: 1 };
|
|
8967
9003
|
}
|
|
8968
9004
|
function parseInteger(name, value3, minimum, diagnostics) {
|
|
8969
9005
|
const parsed = Number(value3);
|
|
@@ -11690,24 +11726,27 @@ async function verify5(context) {
|
|
|
11690
11726
|
},
|
|
11691
11727
|
{
|
|
11692
11728
|
id: "module-installed",
|
|
11693
|
-
|
|
11694
|
-
|
|
11729
|
+
// The HarnessTrim extension is optional. `verify` answers whether existing integrations are
|
|
11730
|
+
// healthy; it must not turn an installed Pi executable into a warning merely because the
|
|
11731
|
+
// user never chose to integrate HarnessTrim with it.
|
|
11732
|
+
status: module ? "pass" : "not-exercised",
|
|
11733
|
+
summary: module ? "HarnessTrim extension module is installed" : "HarnessTrim is not configured on Pi, so there is no Pi integration to verify",
|
|
11695
11734
|
achievedTier: module ? "config-only" : null,
|
|
11696
11735
|
evidence: [],
|
|
11697
|
-
remediation:
|
|
11736
|
+
remediation: null
|
|
11698
11737
|
},
|
|
11699
11738
|
{
|
|
11700
11739
|
id: "mode-unreadable",
|
|
11701
|
-
status: "info",
|
|
11702
|
-
summary: "The effective reduction mode (HARNESSTRIM_MODE) defaults to dryrun and is not observable from the extension alone",
|
|
11740
|
+
status: module ? "info" : "pass",
|
|
11741
|
+
summary: module ? "The effective reduction mode (HARNESSTRIM_MODE) defaults to dryrun and is not observable from the extension alone" : "no HarnessTrim Pi mode applies because no extension is configured",
|
|
11703
11742
|
achievedTier: null,
|
|
11704
11743
|
evidence: [],
|
|
11705
11744
|
remediation: null
|
|
11706
11745
|
},
|
|
11707
11746
|
{
|
|
11708
11747
|
id: "canary-intercepted",
|
|
11709
|
-
status: "not-exercised",
|
|
11710
|
-
summary: "Pi exposes no independent receipt; HarnessTrim telemetry is verified by the provider adapter",
|
|
11748
|
+
status: module ? "not-exercised" : "pass",
|
|
11749
|
+
summary: module ? "Pi exposes no independent receipt; HarnessTrim telemetry is verified by the provider adapter" : "no HarnessTrim Pi canary applies because no extension is configured",
|
|
11711
11750
|
achievedTier: null,
|
|
11712
11751
|
evidence: [],
|
|
11713
11752
|
remediation: null
|
|
@@ -12768,6 +12807,15 @@ function hookEntryFor(harnessId2, matcher) {
|
|
|
12768
12807
|
hooks: [{ type: "command", command: `${RTK_HOOK_COMMAND_PREFIX} ${harnessId2}` }]
|
|
12769
12808
|
};
|
|
12770
12809
|
}
|
|
12810
|
+
function matcherCoversFamily2(matcher, family) {
|
|
12811
|
+
if (matcher === family)
|
|
12812
|
+
return true;
|
|
12813
|
+
try {
|
|
12814
|
+
return new RegExp(matcher).test(family);
|
|
12815
|
+
} catch {
|
|
12816
|
+
return false;
|
|
12817
|
+
}
|
|
12818
|
+
}
|
|
12771
12819
|
function planTargets(context, request) {
|
|
12772
12820
|
const targets = /* @__PURE__ */ new Map();
|
|
12773
12821
|
for (const owned of request.ownership) {
|
|
@@ -12787,12 +12835,32 @@ function planTargets(context, request) {
|
|
|
12787
12835
|
const key = `${configPath}\0${point.eventName}\0${owned.scope.toolFamily}`;
|
|
12788
12836
|
if (targets.has(key))
|
|
12789
12837
|
continue;
|
|
12790
|
-
targets.set(key, {
|
|
12838
|
+
targets.set(key, {
|
|
12839
|
+
scope: owned.scope,
|
|
12840
|
+
harness,
|
|
12841
|
+
eventName: point.eventName,
|
|
12842
|
+
configPath
|
|
12843
|
+
});
|
|
12844
|
+
}
|
|
12845
|
+
if (context.facts.os === "windows") {
|
|
12846
|
+
for (const target of [...targets.values()]) {
|
|
12847
|
+
if (target.harness.id !== CLAUDE3 || target.scope.toolFamily !== BASH)
|
|
12848
|
+
continue;
|
|
12849
|
+
if (!target.harness.toolFamilies.some((family) => family.id === POWERSHELL))
|
|
12850
|
+
continue;
|
|
12851
|
+
const key = `${target.configPath}\0${target.eventName}\0${POWERSHELL}`;
|
|
12852
|
+
if (targets.has(key))
|
|
12853
|
+
continue;
|
|
12854
|
+
targets.set(key, {
|
|
12855
|
+
...target,
|
|
12856
|
+
scope: { ...target.scope, toolFamily: POWERSHELL }
|
|
12857
|
+
});
|
|
12858
|
+
}
|
|
12791
12859
|
}
|
|
12792
12860
|
return [...targets.values()];
|
|
12793
12861
|
}
|
|
12794
|
-
function alreadyRegistered(context, target, identifies) {
|
|
12795
|
-
return context.harnessConfigs.some((config) => config.harnessId === target.harness.id && config.configPath === target.configPath && config.interceptionPoints.includes(target.scope.interceptionPoint) && config.matchers.
|
|
12862
|
+
function alreadyRegistered(context, target, identifies, allowRegexCoverage) {
|
|
12863
|
+
return context.harnessConfigs.some((config) => config.harnessId === target.harness.id && config.configPath === target.configPath && config.interceptionPoints.includes(target.scope.interceptionPoint) && config.matchers.some((matcher) => allowRegexCoverage ? matcherCoversFamily2(matcher, target.scope.toolFamily) : matcher === target.scope.toolFamily) && config.commands.some((command) => identifies(command)));
|
|
12796
12864
|
}
|
|
12797
12865
|
function deterministicId(parts) {
|
|
12798
12866
|
const digest = digestText(parts.join("\0"));
|
|
@@ -12930,7 +12998,7 @@ function buildRtkPlan(input) {
|
|
|
12930
12998
|
const targetHarnesses = [...new Set(targets.map((target) => target.harness.id))];
|
|
12931
12999
|
if (request.desiredState === "absent") {
|
|
12932
13000
|
for (const target of targets) {
|
|
12933
|
-
if (!alreadyRegistered(context, target, input.identifiesCommand))
|
|
13001
|
+
if (!alreadyRegistered(context, target, input.identifiesCommand, false))
|
|
12934
13002
|
continue;
|
|
12935
13003
|
actions.push(removalAction(target, hookEntryFor(target.harness.id, target.scope.toolFamily)));
|
|
12936
13004
|
}
|
|
@@ -12947,7 +13015,7 @@ function buildRtkPlan(input) {
|
|
|
12947
13015
|
actions.push(install);
|
|
12948
13016
|
}
|
|
12949
13017
|
for (const target of targets) {
|
|
12950
|
-
if (alreadyRegistered(context, target, input.identifiesCommand))
|
|
13018
|
+
if (alreadyRegistered(context, target, input.identifiesCommand, true))
|
|
12951
13019
|
continue;
|
|
12952
13020
|
actions.push(hookAction(target, hookEntryFor(target.harness.id, target.scope.toolFamily)));
|
|
12953
13021
|
}
|
|
@@ -12958,13 +13026,16 @@ function buildRtkPlan(input) {
|
|
|
12958
13026
|
targetHarnesses: actions.length === 0 ? [] : targetHarnesses
|
|
12959
13027
|
};
|
|
12960
13028
|
}
|
|
12961
|
-
var RTK_HOOK_COMMAND_PREFIX, HOOK_LIST_HARNESSES;
|
|
13029
|
+
var RTK_HOOK_COMMAND_PREFIX, HOOK_LIST_HARNESSES, CLAUDE3, BASH, POWERSHELL;
|
|
12962
13030
|
var init_rtk_plan = __esm({
|
|
12963
13031
|
"packages/adapters/dist/src/providers/rtk-plan.js"() {
|
|
12964
13032
|
"use strict";
|
|
12965
13033
|
init_src();
|
|
12966
13034
|
RTK_HOOK_COMMAND_PREFIX = "rtk hook";
|
|
12967
13035
|
HOOK_LIST_HARNESSES = /* @__PURE__ */ new Set(["claude"]);
|
|
13036
|
+
CLAUDE3 = "claude";
|
|
13037
|
+
BASH = "Bash";
|
|
13038
|
+
POWERSHELL = "PowerShell";
|
|
12968
13039
|
}
|
|
12969
13040
|
});
|
|
12970
13041
|
|
|
@@ -13158,7 +13229,7 @@ async function detect7(context) {
|
|
|
13158
13229
|
* module `rtk init -g --opencode` installs globally, which this build has no action for. Saying
|
|
13159
13230
|
* so here is what stops the resolver assigning a scope nothing can produce.
|
|
13160
13231
|
*/
|
|
13161
|
-
assignableHarnesses: [
|
|
13232
|
+
assignableHarnesses: [CLAUDE4],
|
|
13162
13233
|
evidence: evidenceItems,
|
|
13163
13234
|
warnings
|
|
13164
13235
|
};
|
|
@@ -13477,14 +13548,14 @@ async function plan2(context, request) {
|
|
|
13477
13548
|
installationChannels: MANIFEST7.installationChannels
|
|
13478
13549
|
});
|
|
13479
13550
|
}
|
|
13480
|
-
var RTK2,
|
|
13551
|
+
var RTK2, CLAUDE4, OPENCODE3, MANIFEST7, TESTED_VERSIONS2, VERSION_PATTERN7, HOOK_COMMAND_PATTERN2, PLUGIN_MODULE_PATTERN3, STALE_RECEIPT_DAYS, HISTORY_QUERY, GENERATION_QUERY, IMPORT_BATCH_SIZE, SOURCE_LABEL, rtkAdapter;
|
|
13481
13552
|
var init_rtk = __esm({
|
|
13482
13553
|
"packages/adapters/dist/src/providers/rtk.js"() {
|
|
13483
13554
|
"use strict";
|
|
13484
13555
|
init_src();
|
|
13485
13556
|
init_rtk_plan();
|
|
13486
13557
|
RTK2 = providerId("rtk");
|
|
13487
|
-
|
|
13558
|
+
CLAUDE4 = harnessId("claude");
|
|
13488
13559
|
OPENCODE3 = harnessId("opencode");
|
|
13489
13560
|
MANIFEST7 = {
|
|
13490
13561
|
schemaVersion: MANIFEST_SCHEMA_VERSION,
|
|
@@ -13498,31 +13569,26 @@ var init_rtk = __esm({
|
|
|
13498
13569
|
{
|
|
13499
13570
|
capability: "shell.command.rewrite",
|
|
13500
13571
|
mode: "exclusive",
|
|
13501
|
-
harnesses: [
|
|
13502
|
-
// The surface
|
|
13503
|
-
//
|
|
13504
|
-
//
|
|
13505
|
-
// reports as `tool-family-not-covered`. Claiming it here would make the resolver
|
|
13506
|
-
// hand RTK a scope it demonstrably does not serve.
|
|
13572
|
+
harnesses: [CLAUDE4],
|
|
13573
|
+
// The portable resolver surface remains Bash. Windows PowerShell coverage is added by
|
|
13574
|
+
// the planner only on Windows, because ProviderManifest capabilities are not platform-scoped.
|
|
13575
|
+
// The native processor and that Windows-only plan path are covered by the live fixture below.
|
|
13507
13576
|
surfaces: [{ toolFamily: "Bash", interceptionPoint: "pre-tool-use" }],
|
|
13508
|
-
// RFC 0003 §Rule wants the evidence recorded at a version. The reference is the
|
|
13509
|
-
// hook the Phase 2.5 spike read, not a line of RTK's source: what was demonstrated
|
|
13510
|
-
// is that the harness routes commands through it, which is the claim being made.
|
|
13511
13577
|
evidence: {
|
|
13512
|
-
sourceReference: "
|
|
13513
|
-
upstreamVersion: "0.
|
|
13578
|
+
sourceReference: "tests/fixtures/rows/rtk-claude-windows-2.1.251-0.48.0/README.md",
|
|
13579
|
+
upstreamVersion: "0.48.0"
|
|
13514
13580
|
}
|
|
13515
13581
|
},
|
|
13516
13582
|
{
|
|
13517
13583
|
capability: "shell.output.reduce",
|
|
13518
13584
|
mode: "exclusive",
|
|
13519
|
-
harnesses: [
|
|
13520
|
-
// Same surface
|
|
13521
|
-
//
|
|
13585
|
+
harnesses: [CLAUDE4],
|
|
13586
|
+
// Same portable Bash surface. On Windows the planner adds PowerShell as a platform-only
|
|
13587
|
+
// companion matcher; the live fixture below proves the same native processor handles both.
|
|
13522
13588
|
surfaces: [{ toolFamily: "Bash", interceptionPoint: "pre-tool-use" }],
|
|
13523
13589
|
evidence: {
|
|
13524
|
-
sourceReference: "
|
|
13525
|
-
upstreamVersion: "0.
|
|
13590
|
+
sourceReference: "tests/fixtures/rows/rtk-claude-windows-2.1.251-0.48.0/README.md",
|
|
13591
|
+
upstreamVersion: "0.48.0"
|
|
13526
13592
|
}
|
|
13527
13593
|
},
|
|
13528
13594
|
/**
|
|
@@ -13577,8 +13643,8 @@ var init_rtk = __esm({
|
|
|
13577
13643
|
],
|
|
13578
13644
|
harnesses: [
|
|
13579
13645
|
{
|
|
13580
|
-
harness:
|
|
13581
|
-
testedVersions: { minimum: "2.0.0", maximum: "2.1.
|
|
13646
|
+
harness: CLAUDE4,
|
|
13647
|
+
testedVersions: { minimum: "2.0.0", maximum: "2.1.251" },
|
|
13582
13648
|
verificationTier: "canary"
|
|
13583
13649
|
},
|
|
13584
13650
|
{
|
|
@@ -13648,7 +13714,7 @@ var init_rtk = __esm({
|
|
|
13648
13714
|
},
|
|
13649
13715
|
delegatedInstallReviews: null
|
|
13650
13716
|
};
|
|
13651
|
-
TESTED_VERSIONS2 = { minimum: "0.
|
|
13717
|
+
TESTED_VERSIONS2 = { minimum: "0.44.0", maximum: "0.48.0" };
|
|
13652
13718
|
VERSION_PATTERN7 = /(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)/;
|
|
13653
13719
|
HOOK_COMMAND_PATTERN2 = /(^|[\\/\s"'])rtk(\.exe)?([\s"']|$)/i;
|
|
13654
13720
|
PLUGIN_MODULE_PATTERN3 = /(^|[\\/])rtk\.(ts|js|mjs|cjs|mts|cts)$/i;
|
|
@@ -13679,7 +13745,7 @@ var init_contract2 = __esm({
|
|
|
13679
13745
|
function listProviderAdapters() {
|
|
13680
13746
|
return PROVIDER_ADAPTERS;
|
|
13681
13747
|
}
|
|
13682
|
-
var PROVIDER_ADAPTERS;
|
|
13748
|
+
var cliHarnessTrimAdapter, PROVIDER_ADAPTERS;
|
|
13683
13749
|
var init_providers = __esm({
|
|
13684
13750
|
"packages/adapters/dist/src/providers/index.js"() {
|
|
13685
13751
|
"use strict";
|
|
@@ -13688,7 +13754,18 @@ var init_providers = __esm({
|
|
|
13688
13754
|
init_contract2();
|
|
13689
13755
|
init_rtk();
|
|
13690
13756
|
init_harnesstrim();
|
|
13691
|
-
|
|
13757
|
+
cliHarnessTrimAdapter = {
|
|
13758
|
+
...harnesstrimAdapter,
|
|
13759
|
+
plansWithoutOwnership: false,
|
|
13760
|
+
plan: (context, request) => {
|
|
13761
|
+
const ownedHarnesses = new Set(request.ownership.map((entry) => entry.scope.harness));
|
|
13762
|
+
return harnesstrimAdapter.plan(context, {
|
|
13763
|
+
...request,
|
|
13764
|
+
harnesses: request.harnesses.filter((harness) => ownedHarnesses.has(harness.id))
|
|
13765
|
+
});
|
|
13766
|
+
}
|
|
13767
|
+
};
|
|
13768
|
+
PROVIDER_ADAPTERS = [rtkAdapter, cliHarnessTrimAdapter];
|
|
13692
13769
|
}
|
|
13693
13770
|
});
|
|
13694
13771
|
|
|
@@ -13787,15 +13864,15 @@ async function runBudget(context) {
|
|
|
13787
13864
|
diagnostics: report.harnesses.flatMap((item) => item.diagnostics)
|
|
13788
13865
|
});
|
|
13789
13866
|
}
|
|
13790
|
-
var
|
|
13867
|
+
var CLAUDE5, CODEX3, BUDGET_HARNESSES;
|
|
13791
13868
|
var init_budget2 = __esm({
|
|
13792
13869
|
"apps/cli/dist/src/commands/budget.js"() {
|
|
13793
13870
|
"use strict";
|
|
13794
13871
|
init_src3();
|
|
13795
13872
|
init_src();
|
|
13796
|
-
|
|
13873
|
+
CLAUDE5 = harnessId("claude");
|
|
13797
13874
|
CODEX3 = harnessId("codex");
|
|
13798
|
-
BUDGET_HARNESSES = /* @__PURE__ */ new Set([
|
|
13875
|
+
BUDGET_HARNESSES = /* @__PURE__ */ new Set([CLAUDE5, CODEX3]);
|
|
13799
13876
|
}
|
|
13800
13877
|
});
|
|
13801
13878
|
|
|
@@ -14048,6 +14125,7 @@ function parseArgv(argv2, plannedCommands = PLANNED_COMMANDS) {
|
|
|
14048
14125
|
profile: null,
|
|
14049
14126
|
reservePercent: null,
|
|
14050
14127
|
nativePolicy: false,
|
|
14128
|
+
verbose: false,
|
|
14051
14129
|
yes: false
|
|
14052
14130
|
};
|
|
14053
14131
|
let command = null;
|
|
@@ -14083,6 +14161,8 @@ function parseArgv(argv2, plannedCommands = PLANNED_COMMANDS) {
|
|
|
14083
14161
|
options.yes = true;
|
|
14084
14162
|
if (name === "--native-policy")
|
|
14085
14163
|
options.nativePolicy = true;
|
|
14164
|
+
if (name === "--verbose")
|
|
14165
|
+
options.verbose = true;
|
|
14086
14166
|
continue;
|
|
14087
14167
|
}
|
|
14088
14168
|
if (!VALUE_FLAGS.has(name)) {
|
|
@@ -14096,8 +14176,8 @@ function parseArgv(argv2, plannedCommands = PLANNED_COMMANDS) {
|
|
|
14096
14176
|
}
|
|
14097
14177
|
let value3 = inlineValue;
|
|
14098
14178
|
if (value3 === null) {
|
|
14099
|
-
const
|
|
14100
|
-
if (
|
|
14179
|
+
const next2 = argv2[index + 1];
|
|
14180
|
+
if (next2 === void 0 || next2.startsWith("-")) {
|
|
14101
14181
|
diagnostics.push(diagnostic({
|
|
14102
14182
|
severity: "error",
|
|
14103
14183
|
code: "flag-missing-value",
|
|
@@ -14106,7 +14186,7 @@ function parseArgv(argv2, plannedCommands = PLANNED_COMMANDS) {
|
|
|
14106
14186
|
}));
|
|
14107
14187
|
continue;
|
|
14108
14188
|
}
|
|
14109
|
-
value3 =
|
|
14189
|
+
value3 = next2;
|
|
14110
14190
|
index += 1;
|
|
14111
14191
|
}
|
|
14112
14192
|
if (value3 === "") {
|
|
@@ -14324,6 +14404,7 @@ var init_argv = __esm({
|
|
|
14324
14404
|
"optimize",
|
|
14325
14405
|
"plan",
|
|
14326
14406
|
"rollback",
|
|
14407
|
+
"setup",
|
|
14327
14408
|
"status",
|
|
14328
14409
|
"uninstall",
|
|
14329
14410
|
"update",
|
|
@@ -14348,7 +14429,7 @@ var init_argv = __esm({
|
|
|
14348
14429
|
"--profile",
|
|
14349
14430
|
"--reserve"
|
|
14350
14431
|
]);
|
|
14351
|
-
BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["--json", "--native-policy", "--yes"]);
|
|
14432
|
+
BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["--json", "--native-policy", "--verbose", "--yes"]);
|
|
14352
14433
|
}
|
|
14353
14434
|
});
|
|
14354
14435
|
|
|
@@ -14494,7 +14575,7 @@ async function claudeInstructionFiles(context) {
|
|
|
14494
14575
|
const results = [];
|
|
14495
14576
|
for (const candidate of candidates) {
|
|
14496
14577
|
const item = await fileObservation(context, {
|
|
14497
|
-
harnessId:
|
|
14578
|
+
harnessId: CLAUDE6,
|
|
14498
14579
|
path: candidate.path,
|
|
14499
14580
|
scope: candidate.scope,
|
|
14500
14581
|
loadedBytes: null
|
|
@@ -14565,7 +14646,7 @@ async function runContext(context) {
|
|
|
14565
14646
|
if (codex !== void 0 && codex.state !== "absent") {
|
|
14566
14647
|
report.instructions.push(...await codexInstructionFiles(context, codex));
|
|
14567
14648
|
}
|
|
14568
|
-
const claude = report.harnesses.find((item) => item.harnessId ===
|
|
14649
|
+
const claude = report.harnesses.find((item) => item.harnessId === CLAUDE6);
|
|
14569
14650
|
if (claude !== void 0 && claude.state !== "absent") {
|
|
14570
14651
|
report.instructions.push(...await claudeInstructionFiles(context));
|
|
14571
14652
|
}
|
|
@@ -14611,15 +14692,15 @@ async function runContext(context) {
|
|
|
14611
14692
|
diagnostics: [...report.harnesses.flatMap((item) => item.diagnostics), ...hierarchyDiagnostics]
|
|
14612
14693
|
});
|
|
14613
14694
|
}
|
|
14614
|
-
var
|
|
14695
|
+
var CLAUDE6, CODEX4, CONTEXT_HARNESSES;
|
|
14615
14696
|
var init_context_cost2 = __esm({
|
|
14616
14697
|
"apps/cli/dist/src/commands/context-cost.js"() {
|
|
14617
14698
|
"use strict";
|
|
14618
14699
|
init_src3();
|
|
14619
14700
|
init_src();
|
|
14620
|
-
|
|
14701
|
+
CLAUDE6 = harnessId("claude");
|
|
14621
14702
|
CODEX4 = harnessId("codex");
|
|
14622
|
-
CONTEXT_HARNESSES = /* @__PURE__ */ new Set([
|
|
14703
|
+
CONTEXT_HARNESSES = /* @__PURE__ */ new Set([CLAUDE6, CODEX4]);
|
|
14623
14704
|
}
|
|
14624
14705
|
});
|
|
14625
14706
|
|
|
@@ -14640,7 +14721,7 @@ function stringArray(value3) {
|
|
|
14640
14721
|
return array(value3).filter((item) => typeof item === "string");
|
|
14641
14722
|
}
|
|
14642
14723
|
function normalizedHarness(value3) {
|
|
14643
|
-
return value3 === "claude" ?
|
|
14724
|
+
return value3 === "claude" ? CLAUDE7 : value3 === "codex" ? CODEX5 : null;
|
|
14644
14725
|
}
|
|
14645
14726
|
function totals(row2) {
|
|
14646
14727
|
const inputTokens = number(row2["inputTokens"]);
|
|
@@ -14948,7 +15029,7 @@ async function runHistory(context) {
|
|
|
14948
15029
|
const filterHarness = context.harness;
|
|
14949
15030
|
const daily = dailyRows(payload).filter((row2) => filterHarness === null || row2.harnessId === filterHarness).sort((left, right) => left.period.localeCompare(right.period));
|
|
14950
15031
|
const sessions = sessionRows(payload).filter((row2) => filterHarness === null || row2.harnessId === filterHarness).sort((left, right) => (left.lastActivity ?? "").localeCompare(right.lastActivity ?? ""));
|
|
14951
|
-
const harnesses = [
|
|
15032
|
+
const harnesses = [CLAUDE7, CODEX5].filter((harness) => filterHarness === null || harness === filterHarness).map((harness) => summarize(harness, daily, sessions, context.now()));
|
|
14952
15033
|
const report = {
|
|
14953
15034
|
...blankReport(context, window.windowStart, window.windowEnd, "available", version3, []),
|
|
14954
15035
|
daily,
|
|
@@ -14961,15 +15042,15 @@ async function runHistory(context) {
|
|
|
14961
15042
|
data: report
|
|
14962
15043
|
});
|
|
14963
15044
|
}
|
|
14964
|
-
var SUPPORTED_CCUSAGE_MAJOR,
|
|
15045
|
+
var SUPPORTED_CCUSAGE_MAJOR, CLAUDE7, CODEX5, HISTORY_HARNESSES;
|
|
14965
15046
|
var init_history2 = __esm({
|
|
14966
15047
|
"apps/cli/dist/src/commands/history.js"() {
|
|
14967
15048
|
"use strict";
|
|
14968
15049
|
init_src();
|
|
14969
15050
|
SUPPORTED_CCUSAGE_MAJOR = 20;
|
|
14970
|
-
|
|
15051
|
+
CLAUDE7 = harnessId("claude");
|
|
14971
15052
|
CODEX5 = harnessId("codex");
|
|
14972
|
-
HISTORY_HARNESSES = /* @__PURE__ */ new Set([
|
|
15053
|
+
HISTORY_HARNESSES = /* @__PURE__ */ new Set([CLAUDE7, CODEX5]);
|
|
14973
15054
|
}
|
|
14974
15055
|
});
|
|
14975
15056
|
|
|
@@ -14993,7 +15074,7 @@ function contextEvidence(context, harness) {
|
|
|
14993
15074
|
const hasUnknownTools = harness.mcpServers.some((server) => server.toolCount === null);
|
|
14994
15075
|
const evidence2 = [];
|
|
14995
15076
|
let score = 0;
|
|
14996
|
-
if (harness.projectDocMaxBytes !== null && harness.projectDocMaxBytes > 0) {
|
|
15077
|
+
if (harness.projectDocMaxBytes !== null && harness.projectDocMaxBytes > 0 && instructionBytes > 0) {
|
|
14997
15078
|
const ratio = instructionBytes / harness.projectDocMaxBytes;
|
|
14998
15079
|
if (ratio >= 0.75)
|
|
14999
15080
|
score = Math.max(score, 2);
|
|
@@ -16473,7 +16554,7 @@ async function runBenchmarkFinish(context) {
|
|
|
16473
16554
|
diagnostics: [...budgetResult.diagnostics, ...historyResult.diagnostics]
|
|
16474
16555
|
});
|
|
16475
16556
|
}
|
|
16476
|
-
var
|
|
16557
|
+
var CLAUDE8, CODEX7, CAPTURE_HARNESSES;
|
|
16477
16558
|
var init_benchmark_capture = __esm({
|
|
16478
16559
|
"apps/cli/dist/src/commands/benchmark-capture.js"() {
|
|
16479
16560
|
"use strict";
|
|
@@ -16481,9 +16562,9 @@ var init_benchmark_capture = __esm({
|
|
|
16481
16562
|
init_budget2();
|
|
16482
16563
|
init_context_cost2();
|
|
16483
16564
|
init_history2();
|
|
16484
|
-
|
|
16565
|
+
CLAUDE8 = harnessId("claude");
|
|
16485
16566
|
CODEX7 = harnessId("codex");
|
|
16486
|
-
CAPTURE_HARNESSES = /* @__PURE__ */ new Set([
|
|
16567
|
+
CAPTURE_HARNESSES = /* @__PURE__ */ new Set([CLAUDE8, CODEX7]);
|
|
16487
16568
|
}
|
|
16488
16569
|
});
|
|
16489
16570
|
|
|
@@ -17363,129 +17444,486 @@ var init_rollback = __esm({
|
|
|
17363
17444
|
}
|
|
17364
17445
|
});
|
|
17365
17446
|
|
|
17366
|
-
// apps/cli/dist/src/commands/
|
|
17367
|
-
function
|
|
17368
|
-
const
|
|
17369
|
-
|
|
17370
|
-
|
|
17371
|
-
|
|
17372
|
-
|
|
17373
|
-
|
|
17374
|
-
|
|
17375
|
-
|
|
17376
|
-
|
|
17377
|
-
|
|
17378
|
-
|
|
17379
|
-
|
|
17447
|
+
// apps/cli/dist/src/commands/verify.js
|
|
17448
|
+
async function runVerify(context) {
|
|
17449
|
+
const diagnostics = [];
|
|
17450
|
+
const results = [];
|
|
17451
|
+
if (context.adapters === null) {
|
|
17452
|
+
return commandResult({
|
|
17453
|
+
command: "verify",
|
|
17454
|
+
exitCode: EXIT_CODES.ok,
|
|
17455
|
+
data: { receiptId: null, appliedAt: null, results: [], healthyAtDeclaredTier: true },
|
|
17456
|
+
diagnostics: [
|
|
17457
|
+
diagnostic({
|
|
17458
|
+
severity: "info",
|
|
17459
|
+
code: "nothing-to-verify",
|
|
17460
|
+
message: "No harness was inspected, so there is nothing to verify",
|
|
17461
|
+
remediation: null
|
|
17462
|
+
})
|
|
17463
|
+
]
|
|
17464
|
+
});
|
|
17465
|
+
}
|
|
17466
|
+
const detectionContext = {
|
|
17467
|
+
fs: context.adapters.fs,
|
|
17468
|
+
runner: context.adapters.runner,
|
|
17469
|
+
facts: context.platform,
|
|
17470
|
+
paths: context.adapters.paths,
|
|
17471
|
+
projectRoot: context.projectRoot
|
|
17472
|
+
};
|
|
17473
|
+
const harnessConfigs = [];
|
|
17474
|
+
const presentHarnesses = [];
|
|
17475
|
+
for (const adapter of listHarnessAdapters()) {
|
|
17476
|
+
if (context.harness !== null && adapter.manifest.id !== context.harness)
|
|
17477
|
+
continue;
|
|
17478
|
+
const detection = await adapter.detect(detectionContext);
|
|
17479
|
+
if (detection.state === "absent")
|
|
17480
|
+
continue;
|
|
17481
|
+
presentHarnesses.push(adapter.manifest.id);
|
|
17482
|
+
const verification = await adapter.verify(detectionContext);
|
|
17483
|
+
for (const check of verification.checks) {
|
|
17484
|
+
if (check.status === "pass")
|
|
17485
|
+
continue;
|
|
17486
|
+
diagnostics.push(diagnostic({
|
|
17487
|
+
severity: check.status === "fail" ? "warning" : "info",
|
|
17488
|
+
code: `harness-${check.id}`,
|
|
17489
|
+
message: `${adapter.manifest.displayName}: ${check.summary}`,
|
|
17490
|
+
remediation: check.remediation
|
|
17491
|
+
}));
|
|
17492
|
+
}
|
|
17493
|
+
const inspection = await adapter.inspect(detectionContext);
|
|
17494
|
+
harnessConfigs.push(...inspection.summaries);
|
|
17495
|
+
diagnostics.push(...inspection.diagnostics);
|
|
17496
|
+
}
|
|
17497
|
+
const managedIntegrations2 = await readManagedIntegrations(context);
|
|
17498
|
+
const providerContext = {
|
|
17499
|
+
...detectionContext,
|
|
17500
|
+
harnessConfigs,
|
|
17501
|
+
now: context.now,
|
|
17502
|
+
localDatabase: context.adapters.localDatabase,
|
|
17503
|
+
projectIdFor: context.adapters.projectIdFor
|
|
17504
|
+
};
|
|
17505
|
+
for (const adapter of listProviderAdapters()) {
|
|
17506
|
+
if (context.provider !== null && adapter.manifest.id !== context.provider)
|
|
17507
|
+
continue;
|
|
17508
|
+
const detection = await adapter.detect(providerContext);
|
|
17509
|
+
if (detection.state === "absent")
|
|
17510
|
+
continue;
|
|
17511
|
+
const verification = await adapter.verify(providerContext);
|
|
17512
|
+
diagnostics.push(...verification.diagnostics);
|
|
17513
|
+
const harnesses = detection.configuredHarnesses.length > 0 ? detection.configuredHarnesses : (
|
|
17514
|
+
// Installed but wired to nothing: still worth a row, on every present harness, because
|
|
17515
|
+
// "installed and not connected here" is the finding.
|
|
17516
|
+
presentHarnesses
|
|
17517
|
+
);
|
|
17518
|
+
for (const harnessId2 of harnesses) {
|
|
17519
|
+
const declaredTier = adapter.manifest.harnesses.find((entry) => entry.harness === harnessId2)?.verificationTier ?? verification.declaredTier;
|
|
17520
|
+
results.push({
|
|
17521
|
+
providerId: adapter.manifest.id,
|
|
17522
|
+
harnessId: harnessId2,
|
|
17523
|
+
status: statusFor(verification.achievedTier, declaredTier),
|
|
17524
|
+
declaredTier,
|
|
17525
|
+
managedByTokenHarness: managedIntegrations2.has(`${adapter.manifest.id}\0${harnessId2}`),
|
|
17526
|
+
providerManagedByTokenHarness: detection.managedByTokenHarness,
|
|
17527
|
+
checks: verification.checks
|
|
17528
|
+
});
|
|
17529
|
+
}
|
|
17530
|
+
}
|
|
17531
|
+
const receipts = context.metrics === null ? [] : await readReceipts(context);
|
|
17532
|
+
const latest = receipts[0] ?? null;
|
|
17533
|
+
const failures = results.flatMap((result2) => result2.checks.filter(contributesToProblems));
|
|
17534
|
+
const report = {
|
|
17535
|
+
receiptId: latest?.receiptId ?? null,
|
|
17536
|
+
appliedAt: latest?.appliedAt ?? null,
|
|
17537
|
+
results,
|
|
17538
|
+
healthyAtDeclaredTier: failures.length === 0
|
|
17380
17539
|
};
|
|
17540
|
+
return commandResult({
|
|
17541
|
+
command: "verify",
|
|
17542
|
+
exitCode: failures.length === 0 ? EXIT_CODES.ok : EXIT_CODES["problems-found"],
|
|
17543
|
+
data: report,
|
|
17544
|
+
diagnostics
|
|
17545
|
+
});
|
|
17381
17546
|
}
|
|
17382
|
-
async function
|
|
17383
|
-
const
|
|
17547
|
+
async function readManagedIntegrations(context) {
|
|
17548
|
+
const managed = /* @__PURE__ */ new Set();
|
|
17384
17549
|
if (context.adapters === null || context.stateRoot === null)
|
|
17385
|
-
return
|
|
17550
|
+
return managed;
|
|
17386
17551
|
const journalRoot = context.adapters.fs.join(context.stateRoot, "journals");
|
|
17387
17552
|
if (await context.adapters.fs.stat(journalRoot) === null)
|
|
17388
|
-
return
|
|
17553
|
+
return managed;
|
|
17554
|
+
const projectId = context.adapters.projectIdFor(context.projectRoot);
|
|
17389
17555
|
const store = new FileJournalStore({
|
|
17390
17556
|
fs: context.adapters.fs,
|
|
17391
17557
|
journalRoot,
|
|
17392
17558
|
backupRoot: context.adapters.fs.join(context.stateRoot, "backups")
|
|
17393
17559
|
});
|
|
17394
|
-
const seen = /* @__PURE__ */ new Set();
|
|
17395
|
-
const result2 = [];
|
|
17396
|
-
let legacyOwnershipUnknown = false;
|
|
17397
17560
|
for (const journal of await store.list()) {
|
|
17398
|
-
if (journal.outcome !== "committed")
|
|
17561
|
+
if (journal.outcome !== "committed" || journal.projectId !== projectId)
|
|
17399
17562
|
continue;
|
|
17400
|
-
if (journal.managedIntegrations === void 0 && journal.ownership.length > 0) {
|
|
17401
|
-
legacyOwnershipUnknown = true;
|
|
17402
|
-
}
|
|
17403
17563
|
for (const integration of journal.managedIntegrations ?? []) {
|
|
17404
|
-
|
|
17405
|
-
if (seen.has(key))
|
|
17406
|
-
continue;
|
|
17407
|
-
seen.add(key);
|
|
17408
|
-
result2.push(integration);
|
|
17564
|
+
managed.add(`${integration.providerId}\0${integration.harnessId}`);
|
|
17409
17565
|
}
|
|
17410
17566
|
}
|
|
17411
|
-
return
|
|
17567
|
+
return managed;
|
|
17412
17568
|
}
|
|
17413
|
-
function
|
|
17414
|
-
const
|
|
17415
|
-
|
|
17416
|
-
|
|
17417
|
-
|
|
17418
|
-
|
|
17419
|
-
|
|
17420
|
-
|
|
17421
|
-
|
|
17422
|
-
requiresElevation: input.requiresElevation,
|
|
17423
|
-
affectedPaths: [],
|
|
17424
|
-
affectedProcesses: [input.channel],
|
|
17425
|
-
preconditions: [
|
|
17426
|
-
`${input.channel} is available on this machine`,
|
|
17427
|
-
`${input.packageName} is installed at ${input.installed}`
|
|
17428
|
-
],
|
|
17429
|
-
postconditions: [`${input.packageName} reports ${input.target}`],
|
|
17430
|
-
/**
|
|
17431
|
-
* `package-inventory` where the channel can report what is installed, `none` otherwise.
|
|
17432
|
-
*
|
|
17433
|
-
* An update replaces a binary. Rolling the transaction back restores files and leaves the new
|
|
17434
|
-
* version in place, so the executor's receipt is not boilerplate here — it is the difference
|
|
17435
|
-
* between the machine being restored and the *configuration* being restored. With an
|
|
17436
|
-
* inventory-capturing channel the rollback also reinstalls the previous version, and the
|
|
17437
|
-
* receipt says per package whether that reinstall took.
|
|
17438
|
-
*/
|
|
17439
|
-
rollbackData: channelCanReportInventory(input.channel) ? "package-inventory" : "none",
|
|
17440
|
-
explanation: `Update ${input.packageName} from ${input.installed} to ${input.target} through ${input.channel}`,
|
|
17441
|
-
packageManager: input.channel,
|
|
17442
|
-
packageName: input.packageName,
|
|
17443
|
-
// Pinned to the exact version the channel reported, not left open. An unpinned upgrade would
|
|
17444
|
-
// install whatever is newest at execution time, which is not the version the dry run showed.
|
|
17445
|
-
version: input.target
|
|
17446
|
-
};
|
|
17569
|
+
async function readReceipts(context) {
|
|
17570
|
+
const store = context.metrics;
|
|
17571
|
+
if (store?.listReceipts === void 0)
|
|
17572
|
+
return [];
|
|
17573
|
+
try {
|
|
17574
|
+
return await store.listReceipts();
|
|
17575
|
+
} catch {
|
|
17576
|
+
return [];
|
|
17577
|
+
}
|
|
17447
17578
|
}
|
|
17448
|
-
|
|
17449
|
-
const
|
|
17450
|
-
|
|
17451
|
-
|
|
17452
|
-
|
|
17453
|
-
|
|
17454
|
-
|
|
17455
|
-
|
|
17456
|
-
|
|
17457
|
-
|
|
17458
|
-
|
|
17459
|
-
|
|
17460
|
-
|
|
17461
|
-
|
|
17462
|
-
|
|
17463
|
-
message: "No platform adapters are available, so no channel can be consulted",
|
|
17464
|
-
remediation: null
|
|
17465
|
-
}));
|
|
17466
|
-
return finish3(EXIT_CODES["unsupported-environment"], null);
|
|
17579
|
+
function statusFor(achieved, declared) {
|
|
17580
|
+
const order = ["presence", "config-only", "canary", "live-receipt"];
|
|
17581
|
+
if (achieved === null)
|
|
17582
|
+
return "not-applicable";
|
|
17583
|
+
const reached = order.indexOf(achieved);
|
|
17584
|
+
const promised = order.indexOf(declared);
|
|
17585
|
+
if (reached < 0 || promised < 0)
|
|
17586
|
+
return "not-applicable";
|
|
17587
|
+
return reached >= promised ? "healthy" : "degraded";
|
|
17588
|
+
}
|
|
17589
|
+
var init_verify = __esm({
|
|
17590
|
+
"apps/cli/dist/src/commands/verify.js"() {
|
|
17591
|
+
"use strict";
|
|
17592
|
+
init_src3();
|
|
17593
|
+
init_src();
|
|
17467
17594
|
}
|
|
17468
|
-
|
|
17469
|
-
|
|
17470
|
-
|
|
17471
|
-
|
|
17472
|
-
const
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
|
|
17476
|
-
|
|
17477
|
-
|
|
17478
|
-
|
|
17479
|
-
|
|
17480
|
-
|
|
17595
|
+
});
|
|
17596
|
+
|
|
17597
|
+
// apps/cli/dist/src/commands/setup.js
|
|
17598
|
+
function uniqueDiagnostics(groups) {
|
|
17599
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17600
|
+
return groups.flatMap((group) => group.filter((entry) => {
|
|
17601
|
+
const key = `${entry.severity}\0${entry.code}\0${entry.message}`;
|
|
17602
|
+
if (seen.has(key))
|
|
17603
|
+
return false;
|
|
17604
|
+
seen.add(key);
|
|
17605
|
+
return true;
|
|
17606
|
+
}));
|
|
17607
|
+
}
|
|
17608
|
+
async function runSetup(context, operations = DEFAULT_OPERATIONS) {
|
|
17609
|
+
const doctor = await operations.doctor(context);
|
|
17610
|
+
const detectedHarnesses = (doctor.data?.harnesses ?? []).filter((harness) => harness.state !== "absent" && (context.harness !== null ? harness.harnessId === context.harness : harness.harnessId === "claude" || harness.harnessId === "codex"));
|
|
17611
|
+
const baseDoctor = doctor.data;
|
|
17612
|
+
if (baseDoctor === null) {
|
|
17613
|
+
return commandResult({
|
|
17614
|
+
command: "setup",
|
|
17615
|
+
exitCode: doctor.exitCode,
|
|
17616
|
+
diagnostics: doctor.diagnostics
|
|
17617
|
+
});
|
|
17618
|
+
}
|
|
17619
|
+
if (detectedHarnesses.length === 0) {
|
|
17620
|
+
return commandResult({
|
|
17621
|
+
command: "setup",
|
|
17622
|
+
exitCode: EXIT_CODES.ok,
|
|
17623
|
+
data: {
|
|
17624
|
+
stage: "needs-harness",
|
|
17625
|
+
changed: false,
|
|
17626
|
+
doctor: baseDoctor,
|
|
17627
|
+
plan: null,
|
|
17628
|
+
apply: null,
|
|
17629
|
+
verify: null,
|
|
17630
|
+
budget: null,
|
|
17631
|
+
nextStep: {
|
|
17632
|
+
command: null,
|
|
17633
|
+
description: "Install and sign in to Claude Code or Codex, then run setup again."
|
|
17634
|
+
}
|
|
17635
|
+
},
|
|
17636
|
+
diagnostics: doctor.diagnostics
|
|
17637
|
+
});
|
|
17638
|
+
}
|
|
17639
|
+
const setupHarnessIds = new Set(detectedHarnesses.map((harness) => harness.harnessId));
|
|
17640
|
+
const hasBrokenSetupIntegration = detectedHarnesses.some((harness) => harness.state === "broken") || baseDoctor.providers.some((provider) => provider.state === "broken" && provider.configuredHarnesses.some((harness) => setupHarnessIds.has(harness)));
|
|
17641
|
+
if (hasBrokenSetupIntegration) {
|
|
17642
|
+
return commandResult({
|
|
17643
|
+
command: "setup",
|
|
17644
|
+
exitCode: EXIT_CODES["problems-found"],
|
|
17645
|
+
data: {
|
|
17646
|
+
stage: "attention",
|
|
17647
|
+
changed: false,
|
|
17648
|
+
doctor: baseDoctor,
|
|
17649
|
+
plan: null,
|
|
17650
|
+
apply: null,
|
|
17651
|
+
verify: null,
|
|
17652
|
+
budget: null,
|
|
17653
|
+
nextStep: {
|
|
17654
|
+
command: "token-harness doctor --verbose",
|
|
17655
|
+
description: "Review the broken active integration before changing configuration."
|
|
17656
|
+
}
|
|
17657
|
+
},
|
|
17658
|
+
diagnostics: doctor.diagnostics
|
|
17659
|
+
});
|
|
17660
|
+
}
|
|
17661
|
+
const presentIds = new Set(detectedHarnesses.map((harness) => harness.harnessId));
|
|
17662
|
+
const hasActiveProvider = baseDoctor.providers.some((provider) => provider.state === "configured" && provider.configuredHarnesses.some((harness) => presentIds.has(harness)));
|
|
17663
|
+
if (hasActiveProvider) {
|
|
17664
|
+
const activeHarness = context.harness ?? detectedHarnesses.find((harness) => baseDoctor.providers.some((provider) => provider.configuredHarnesses.includes(harness.harnessId)))?.harnessId ?? null;
|
|
17665
|
+
const observationContext = { ...context, harness: activeHarness };
|
|
17666
|
+
const [verify9, budget2] = await Promise.all([
|
|
17667
|
+
operations.verify(observationContext),
|
|
17668
|
+
operations.budget(observationContext)
|
|
17669
|
+
]);
|
|
17670
|
+
const healthy2 = verify9.data?.healthyAtDeclaredTier === true;
|
|
17671
|
+
return commandResult({
|
|
17672
|
+
command: "setup",
|
|
17673
|
+
exitCode: healthy2 ? EXIT_CODES.ok : EXIT_CODES["problems-found"],
|
|
17674
|
+
data: {
|
|
17675
|
+
stage: healthy2 ? "ready" : "attention",
|
|
17676
|
+
changed: false,
|
|
17677
|
+
doctor: baseDoctor,
|
|
17678
|
+
plan: null,
|
|
17679
|
+
apply: null,
|
|
17680
|
+
verify: verify9.data,
|
|
17681
|
+
budget: budget2.data,
|
|
17682
|
+
nextStep: healthy2 ? {
|
|
17683
|
+
command: "token-harness ui",
|
|
17684
|
+
description: "Open the dashboard once to review status; then use your coding agent normally."
|
|
17685
|
+
} : {
|
|
17686
|
+
command: "token-harness verify --verbose",
|
|
17687
|
+
description: "Review the failed integration check."
|
|
17688
|
+
}
|
|
17689
|
+
},
|
|
17690
|
+
diagnostics: uniqueDiagnostics([doctor.diagnostics, verify9.diagnostics, budget2.diagnostics])
|
|
17691
|
+
});
|
|
17692
|
+
}
|
|
17693
|
+
const preferredHarness = context.harness ?? detectedHarnesses.find((harness) => harness.harnessId === "codex")?.harnessId ?? detectedHarnesses[0]?.harnessId ?? null;
|
|
17694
|
+
const setupContext = { ...context, harness: preferredHarness };
|
|
17695
|
+
const plan3 = await operations.plan(setupContext);
|
|
17696
|
+
if (plan3.data === null || plan3.exitCode !== EXIT_CODES.ok || plan3.data.actions.length === 0 || !plan3.data.persisted) {
|
|
17697
|
+
return commandResult({
|
|
17698
|
+
command: "setup",
|
|
17699
|
+
exitCode: plan3.exitCode === EXIT_CODES.ok ? EXIT_CODES["problems-found"] : plan3.exitCode,
|
|
17700
|
+
data: {
|
|
17701
|
+
stage: "attention",
|
|
17702
|
+
changed: false,
|
|
17703
|
+
doctor: baseDoctor,
|
|
17704
|
+
plan: plan3.data,
|
|
17705
|
+
apply: null,
|
|
17706
|
+
verify: null,
|
|
17707
|
+
budget: null,
|
|
17708
|
+
nextStep: {
|
|
17709
|
+
command: "token-harness plan --verbose",
|
|
17710
|
+
description: "Review why no safe automatic configuration is available."
|
|
17711
|
+
}
|
|
17712
|
+
},
|
|
17713
|
+
diagnostics: uniqueDiagnostics([doctor.diagnostics, plan3.diagnostics])
|
|
17714
|
+
});
|
|
17715
|
+
}
|
|
17716
|
+
if (!context.confirmed) {
|
|
17717
|
+
return commandResult({
|
|
17718
|
+
command: "setup",
|
|
17719
|
+
exitCode: EXIT_CODES.ok,
|
|
17720
|
+
data: {
|
|
17721
|
+
stage: "ready-to-configure",
|
|
17722
|
+
changed: false,
|
|
17723
|
+
doctor: baseDoctor,
|
|
17724
|
+
plan: plan3.data,
|
|
17725
|
+
apply: null,
|
|
17726
|
+
verify: null,
|
|
17727
|
+
budget: null,
|
|
17728
|
+
nextStep: {
|
|
17729
|
+
command: "token-harness setup --yes",
|
|
17730
|
+
description: "Apply the reviewed, reversible configuration."
|
|
17731
|
+
}
|
|
17732
|
+
},
|
|
17733
|
+
diagnostics: uniqueDiagnostics([doctor.diagnostics, plan3.diagnostics])
|
|
17734
|
+
});
|
|
17735
|
+
}
|
|
17736
|
+
const applied = await operations.apply({
|
|
17737
|
+
...setupContext,
|
|
17738
|
+
planId: plan3.data.planId,
|
|
17739
|
+
confirmed: true
|
|
17740
|
+
});
|
|
17741
|
+
if (applied.data?.outcome !== "committed" && applied.data?.outcome !== "nothing-to-do") {
|
|
17742
|
+
return commandResult({
|
|
17743
|
+
command: "setup",
|
|
17744
|
+
exitCode: applied.exitCode,
|
|
17745
|
+
data: {
|
|
17746
|
+
stage: "attention",
|
|
17747
|
+
changed: false,
|
|
17748
|
+
doctor: baseDoctor,
|
|
17749
|
+
plan: plan3.data,
|
|
17750
|
+
apply: applied.data,
|
|
17751
|
+
verify: null,
|
|
17752
|
+
budget: null,
|
|
17753
|
+
nextStep: {
|
|
17754
|
+
command: "token-harness verify --verbose",
|
|
17755
|
+
description: "Review the configuration result before continuing."
|
|
17756
|
+
}
|
|
17757
|
+
},
|
|
17758
|
+
diagnostics: uniqueDiagnostics([doctor.diagnostics, plan3.diagnostics, applied.diagnostics])
|
|
17759
|
+
});
|
|
17760
|
+
}
|
|
17761
|
+
const [verify8, budget] = await Promise.all([
|
|
17762
|
+
operations.verify(setupContext),
|
|
17763
|
+
operations.budget(setupContext)
|
|
17764
|
+
]);
|
|
17765
|
+
const healthy = verify8.data?.healthyAtDeclaredTier === true;
|
|
17766
|
+
const changed = applied.data?.results.some((result2) => result2.status === "applied") === true;
|
|
17767
|
+
return commandResult({
|
|
17768
|
+
command: "setup",
|
|
17769
|
+
exitCode: healthy ? EXIT_CODES.ok : EXIT_CODES["problems-found"],
|
|
17770
|
+
data: {
|
|
17771
|
+
stage: healthy ? "ready" : "attention",
|
|
17772
|
+
changed,
|
|
17773
|
+
doctor: baseDoctor,
|
|
17774
|
+
plan: plan3.data,
|
|
17775
|
+
apply: applied.data,
|
|
17776
|
+
verify: verify8.data,
|
|
17777
|
+
budget: budget.data,
|
|
17778
|
+
nextStep: healthy ? {
|
|
17779
|
+
command: "token-harness ui",
|
|
17780
|
+
description: "Open the dashboard once to review status; then use your coding agent normally."
|
|
17781
|
+
} : {
|
|
17782
|
+
command: "token-harness verify --verbose",
|
|
17783
|
+
description: "Review the failed integration check."
|
|
17784
|
+
}
|
|
17785
|
+
},
|
|
17786
|
+
diagnostics: uniqueDiagnostics([
|
|
17787
|
+
doctor.diagnostics,
|
|
17788
|
+
plan3.diagnostics,
|
|
17789
|
+
applied.diagnostics,
|
|
17790
|
+
verify8.diagnostics,
|
|
17791
|
+
budget.diagnostics
|
|
17792
|
+
])
|
|
17793
|
+
});
|
|
17794
|
+
}
|
|
17795
|
+
var DEFAULT_OPERATIONS;
|
|
17796
|
+
var init_setup2 = __esm({
|
|
17797
|
+
"apps/cli/dist/src/commands/setup.js"() {
|
|
17798
|
+
"use strict";
|
|
17799
|
+
init_src();
|
|
17800
|
+
init_apply();
|
|
17801
|
+
init_budget2();
|
|
17802
|
+
init_doctor();
|
|
17803
|
+
init_plan2();
|
|
17804
|
+
init_verify();
|
|
17805
|
+
DEFAULT_OPERATIONS = {
|
|
17806
|
+
doctor: runDoctor,
|
|
17807
|
+
plan: runPlan,
|
|
17808
|
+
apply: runApply,
|
|
17809
|
+
verify: runVerify,
|
|
17810
|
+
budget: runBudget
|
|
17481
17811
|
};
|
|
17482
|
-
|
|
17483
|
-
|
|
17812
|
+
}
|
|
17813
|
+
});
|
|
17814
|
+
|
|
17815
|
+
// apps/cli/dist/src/commands/update.js
|
|
17816
|
+
function transactionIdFor2(seed, at) {
|
|
17817
|
+
const digest = digestText(`${seed} ${at}`);
|
|
17818
|
+
return digest.slice(digest.indexOf(":") + 1, digest.indexOf(":") + 13);
|
|
17819
|
+
}
|
|
17820
|
+
function emptyExecution(outcome2) {
|
|
17821
|
+
return {
|
|
17822
|
+
planId: null,
|
|
17823
|
+
transactionId: null,
|
|
17824
|
+
fromStoredPlan: false,
|
|
17825
|
+
outcome: outcome2,
|
|
17826
|
+
results: [],
|
|
17827
|
+
unrestored: [],
|
|
17828
|
+
receiptId: null
|
|
17829
|
+
};
|
|
17830
|
+
}
|
|
17831
|
+
async function managedIntegrations(context) {
|
|
17832
|
+
const empty2 = { integrations: [], legacyOwnershipUnknown: false };
|
|
17833
|
+
if (context.adapters === null || context.stateRoot === null)
|
|
17834
|
+
return empty2;
|
|
17835
|
+
const journalRoot = context.adapters.fs.join(context.stateRoot, "journals");
|
|
17836
|
+
if (await context.adapters.fs.stat(journalRoot) === null)
|
|
17837
|
+
return empty2;
|
|
17838
|
+
const store = new FileJournalStore({
|
|
17839
|
+
fs: context.adapters.fs,
|
|
17840
|
+
journalRoot,
|
|
17841
|
+
backupRoot: context.adapters.fs.join(context.stateRoot, "backups")
|
|
17842
|
+
});
|
|
17843
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17844
|
+
const result2 = [];
|
|
17845
|
+
let legacyOwnershipUnknown = false;
|
|
17846
|
+
for (const journal of await store.list()) {
|
|
17847
|
+
if (journal.outcome !== "committed")
|
|
17848
|
+
continue;
|
|
17849
|
+
if (journal.managedIntegrations === void 0 && journal.ownership.length > 0) {
|
|
17850
|
+
legacyOwnershipUnknown = true;
|
|
17851
|
+
}
|
|
17852
|
+
for (const integration of journal.managedIntegrations ?? []) {
|
|
17853
|
+
const key = `${integration.providerId}\0${integration.harnessId}`;
|
|
17854
|
+
if (seen.has(key))
|
|
17484
17855
|
continue;
|
|
17485
|
-
|
|
17486
|
-
|
|
17856
|
+
seen.add(key);
|
|
17857
|
+
result2.push(integration);
|
|
17487
17858
|
}
|
|
17488
17859
|
}
|
|
17860
|
+
return { integrations: result2, legacyOwnershipUnknown };
|
|
17861
|
+
}
|
|
17862
|
+
function upgradeAction(input) {
|
|
17863
|
+
const digest = digestText(`${input.providerId} update ${input.channel} ${input.target}`);
|
|
17864
|
+
return {
|
|
17865
|
+
kind: "package-manager-install",
|
|
17866
|
+
id: digest.slice(digest.indexOf(":") + 1, digest.indexOf(":") + 9),
|
|
17867
|
+
riskClass: "delegated",
|
|
17868
|
+
requiresNetwork: input.requiresNetwork,
|
|
17869
|
+
requiresElevation: input.requiresElevation,
|
|
17870
|
+
affectedPaths: [],
|
|
17871
|
+
affectedProcesses: [input.channel],
|
|
17872
|
+
preconditions: [
|
|
17873
|
+
`${input.channel} is available on this machine`,
|
|
17874
|
+
`${input.packageName} is installed at ${input.installed}`
|
|
17875
|
+
],
|
|
17876
|
+
postconditions: [`${input.packageName} reports ${input.target}`],
|
|
17877
|
+
rollbackData: channelCanReportInventory(input.channel) ? "package-inventory" : "none",
|
|
17878
|
+
explanation: `Update ${input.packageName} from ${input.installed} to ${input.target} through ${input.channel}`,
|
|
17879
|
+
packageManager: input.channel,
|
|
17880
|
+
packageName: input.packageName,
|
|
17881
|
+
version: input.target
|
|
17882
|
+
};
|
|
17883
|
+
}
|
|
17884
|
+
async function runUpdate(context) {
|
|
17885
|
+
const diagnostics = [];
|
|
17886
|
+
const report = { providers: [], network: [], execution: null };
|
|
17887
|
+
const finish3 = (exitCode, data) => commandResult({
|
|
17888
|
+
command: "update",
|
|
17889
|
+
exitCode,
|
|
17890
|
+
data: statusForExitCode(exitCode) === "error" ? null : data,
|
|
17891
|
+
diagnostics
|
|
17892
|
+
});
|
|
17893
|
+
if (context.adapters === null) {
|
|
17894
|
+
diagnostics.push(diagnostic({
|
|
17895
|
+
severity: "error",
|
|
17896
|
+
code: "unsupported-environment",
|
|
17897
|
+
message: "No platform adapters are available, so no channel can be consulted",
|
|
17898
|
+
remediation: null
|
|
17899
|
+
}));
|
|
17900
|
+
return finish3(EXIT_CODES["unsupported-environment"], null);
|
|
17901
|
+
}
|
|
17902
|
+
const adapters = context.adapters;
|
|
17903
|
+
const providerAdapters = listProviderAdapters().filter((adapter) => context.provider === null || adapter.manifest.id === context.provider);
|
|
17904
|
+
const managedState = await managedIntegrations(context);
|
|
17905
|
+
const managed = managedState.integrations;
|
|
17906
|
+
const harnessAdapters = listHarnessAdapters();
|
|
17907
|
+
const managedHarnessIds = new Set(managed.map((entry) => entry.harnessId));
|
|
17908
|
+
if (managedState.legacyOwnershipUnknown) {
|
|
17909
|
+
for (const harness of harnessAdapters)
|
|
17910
|
+
managedHarnessIds.add(harness.manifest.id);
|
|
17911
|
+
}
|
|
17912
|
+
const harnessContext = {
|
|
17913
|
+
fs: adapters.fs,
|
|
17914
|
+
runner: adapters.runner,
|
|
17915
|
+
facts: context.platform,
|
|
17916
|
+
paths: adapters.paths,
|
|
17917
|
+
projectRoot: context.projectRoot
|
|
17918
|
+
};
|
|
17919
|
+
const harnessVersions = /* @__PURE__ */ new Map();
|
|
17920
|
+
for (const harness of harnessAdapters) {
|
|
17921
|
+
if (!managedHarnessIds.has(harness.manifest.id))
|
|
17922
|
+
continue;
|
|
17923
|
+
const detection = await harness.detect(harnessContext);
|
|
17924
|
+
harnessVersions.set(harness.manifest.id, detection.version);
|
|
17925
|
+
}
|
|
17926
|
+
const recoveryHarnessConfigs = managedState.legacyOwnershipUnknown ? (await Promise.all(harnessAdapters.map(async (harness) => (await harness.inspect(harnessContext)).summaries))).flat() : [];
|
|
17489
17927
|
const pins = context.stateRoot === null ? { pins: /* @__PURE__ */ new Map(), unhonoredProjectPinPath: null, diagnostics: [] } : await readPins({
|
|
17490
17928
|
fs: adapters.fs,
|
|
17491
17929
|
stateRoot: context.stateRoot,
|
|
@@ -17498,7 +17936,7 @@ async function runUpdate(context) {
|
|
|
17498
17936
|
facts: context.platform,
|
|
17499
17937
|
paths: adapters.paths,
|
|
17500
17938
|
projectRoot: context.projectRoot,
|
|
17501
|
-
harnessConfigs:
|
|
17939
|
+
harnessConfigs: recoveryHarnessConfigs,
|
|
17502
17940
|
now: context.now,
|
|
17503
17941
|
localDatabase: adapters.localDatabase,
|
|
17504
17942
|
projectIdFor: adapters.projectIdFor
|
|
@@ -17561,22 +17999,18 @@ async function runUpdate(context) {
|
|
|
17561
17999
|
report.providers.push(row2);
|
|
17562
18000
|
continue;
|
|
17563
18001
|
}
|
|
17564
|
-
const
|
|
17565
|
-
let updateAdmitted = !managedState.legacyOwnershipUnknown;
|
|
18002
|
+
const compatibilityHarnessIds = new Set(managed.filter((entry) => entry.providerId === adapter.manifest.id).map((entry) => entry.harnessId));
|
|
17566
18003
|
if (managedState.legacyOwnershipUnknown) {
|
|
17567
|
-
|
|
17568
|
-
|
|
17569
|
-
target: query.version,
|
|
17570
|
-
harnessId: "legacy-owned-state",
|
|
17571
|
-
missing: "a committed pre-attribution journal owns configuration but does not identify its provider and harness"
|
|
17572
|
-
});
|
|
18004
|
+
for (const harnessId2 of detection.configuredHarnesses)
|
|
18005
|
+
compatibilityHarnessIds.add(harnessId2);
|
|
17573
18006
|
}
|
|
17574
|
-
|
|
18007
|
+
let updateAdmitted = true;
|
|
18008
|
+
for (const harnessId2 of compatibilityHarnessIds) {
|
|
17575
18009
|
const admission = admitManagedMutation(context.compatibilityRows ?? COMPATIBILITY_ROWS, {
|
|
17576
18010
|
provider: adapter.manifest.id,
|
|
17577
18011
|
providerVersion: query.version,
|
|
17578
|
-
harness:
|
|
17579
|
-
harnessVersion: harnessVersions.get(
|
|
18012
|
+
harness: harnessId2,
|
|
18013
|
+
harnessVersion: harnessVersions.get(harnessId2) ?? null,
|
|
17580
18014
|
os: context.platform.os,
|
|
17581
18015
|
wsl: context.platform.isWsl
|
|
17582
18016
|
});
|
|
@@ -17585,8 +18019,9 @@ async function runUpdate(context) {
|
|
|
17585
18019
|
updateAdmitted = false;
|
|
17586
18020
|
blockedUpdates.push({
|
|
17587
18021
|
providerId: adapter.manifest.id,
|
|
18022
|
+
installed: detection.version,
|
|
17588
18023
|
target: query.version,
|
|
17589
|
-
harnessId:
|
|
18024
|
+
harnessId: harnessId2,
|
|
17590
18025
|
missing: admission.missing
|
|
17591
18026
|
});
|
|
17592
18027
|
}
|
|
@@ -17608,20 +18043,25 @@ async function runUpdate(context) {
|
|
|
17608
18043
|
}));
|
|
17609
18044
|
}
|
|
17610
18045
|
report.network = [...destinations].sort();
|
|
17611
|
-
const blockedIsOutcome = blockedUpdates.length > 0 && actions.length === 0;
|
|
17612
18046
|
for (const blocked of blockedUpdates) {
|
|
17613
18047
|
diagnostics.push(diagnostic({
|
|
17614
|
-
severity:
|
|
18048
|
+
severity: "info",
|
|
17615
18049
|
code: "managed-update-blocked",
|
|
17616
|
-
message:
|
|
17617
|
-
remediation: "
|
|
18050
|
+
message: `${blocked.providerId} ${blocked.target} is available but is not validated for ${blocked.harnessId}; keeping ${blocked.installed ?? "the installed version"}`,
|
|
18051
|
+
remediation: "No action is required; Token Harness will allow the update after this combination has reviewed compatibility evidence"
|
|
18052
|
+
}));
|
|
18053
|
+
diagnostics.push(diagnostic({
|
|
18054
|
+
severity: "info",
|
|
18055
|
+
code: "managed-update-blocked-detail",
|
|
18056
|
+
message: `${blocked.providerId} ${blocked.target} compatibility evidence is missing: ${blocked.missing}`,
|
|
18057
|
+
remediation: null
|
|
17618
18058
|
}));
|
|
17619
18059
|
}
|
|
17620
18060
|
if (pins.unhonoredProjectPinPath !== null) {
|
|
17621
18061
|
}
|
|
17622
18062
|
if (actions.length === 0 && blockedUpdates.length > 0) {
|
|
17623
|
-
report.execution = emptyExecution("
|
|
17624
|
-
return finish3(EXIT_CODES
|
|
18063
|
+
report.execution = emptyExecution("nothing-to-do");
|
|
18064
|
+
return finish3(EXIT_CODES.ok, report);
|
|
17625
18065
|
}
|
|
17626
18066
|
if (actions.length === 0) {
|
|
17627
18067
|
report.execution = emptyExecution("nothing-to-do");
|
|
@@ -17638,7 +18078,6 @@ async function runUpdate(context) {
|
|
|
17638
18078
|
diagnostics.push(diagnostic({
|
|
17639
18079
|
severity: "error",
|
|
17640
18080
|
code: "confirmation-required",
|
|
17641
|
-
// In the message and not only in `data`: exit 8 is an `error` status, so `data` is null.
|
|
17642
18081
|
message: `Would update ${summary}`,
|
|
17643
18082
|
remediation: "Re-run with `--yes` to apply it"
|
|
17644
18083
|
}));
|
|
@@ -17664,200 +18103,48 @@ async function runUpdate(context) {
|
|
|
17664
18103
|
projectRoot: context.projectRoot,
|
|
17665
18104
|
now: context.now
|
|
17666
18105
|
});
|
|
17667
|
-
if (!creation.ok) {
|
|
17668
|
-
diagnostics.push(...creation.diagnostics);
|
|
17669
|
-
return finish3(EXIT_CODES["unsupported-environment"], null);
|
|
17670
|
-
}
|
|
17671
|
-
const transaction = await executeTransaction({
|
|
17672
|
-
transactionId,
|
|
17673
|
-
planId: null,
|
|
17674
|
-
projectId: adapters.projectIdFor(context.projectRoot),
|
|
17675
|
-
projectRoot: context.projectRoot,
|
|
17676
|
-
actions,
|
|
17677
|
-
fs,
|
|
17678
|
-
snapshots: creation.store,
|
|
17679
|
-
journal: new FileJournalStore({
|
|
17680
|
-
fs,
|
|
17681
|
-
journalRoot: fs.join(context.stateRoot, "journals"),
|
|
17682
|
-
backupRoot: fs.join(context.stateRoot, "backups")
|
|
17683
|
-
}),
|
|
17684
|
-
runner: adapters.runner,
|
|
17685
|
-
now: context.now
|
|
17686
|
-
});
|
|
17687
|
-
diagnostics.push(...transaction.diagnostics);
|
|
17688
|
-
report.execution = {
|
|
17689
|
-
planId: null,
|
|
17690
|
-
transactionId,
|
|
17691
|
-
fromStoredPlan: false,
|
|
17692
|
-
// Mapped the way `apply` maps it: `in-progress` is not a terminal outcome a report may
|
|
17693
|
-
// carry, and anything that is not one of the three known ends is a rejection.
|
|
17694
|
-
outcome: transaction.journal.outcome === "committed" ? "committed" : transaction.journal.outcome === "rolled-back" ? "rolled-back" : transaction.journal.outcome === "dirty" ? "dirty" : "rejected",
|
|
17695
|
-
results: transaction.journal.entries.map((entry) => ({
|
|
17696
|
-
actionId: entry.actionId,
|
|
17697
|
-
kind: entry.kind,
|
|
17698
|
-
status: entry.status,
|
|
17699
|
-
path: null
|
|
17700
|
-
})),
|
|
17701
|
-
unrestored: transaction.unrestored,
|
|
17702
|
-
receiptId: transaction.journal.outcome === "committed" ? transactionId : null
|
|
17703
|
-
};
|
|
17704
|
-
return finish3(transaction.exitCode, report);
|
|
17705
|
-
}
|
|
17706
|
-
var init_update = __esm({
|
|
17707
|
-
"apps/cli/dist/src/commands/update.js"() {
|
|
17708
|
-
"use strict";
|
|
17709
|
-
init_src();
|
|
17710
|
-
init_src3();
|
|
17711
|
-
}
|
|
17712
|
-
});
|
|
17713
|
-
|
|
17714
|
-
// apps/cli/dist/src/commands/verify.js
|
|
17715
|
-
async function runVerify(context) {
|
|
17716
|
-
const diagnostics = [];
|
|
17717
|
-
const results = [];
|
|
17718
|
-
if (context.adapters === null) {
|
|
17719
|
-
return commandResult({
|
|
17720
|
-
command: "verify",
|
|
17721
|
-
exitCode: EXIT_CODES.ok,
|
|
17722
|
-
data: { receiptId: null, appliedAt: null, results: [], healthyAtDeclaredTier: true },
|
|
17723
|
-
diagnostics: [
|
|
17724
|
-
diagnostic({
|
|
17725
|
-
severity: "info",
|
|
17726
|
-
code: "nothing-to-verify",
|
|
17727
|
-
message: "No harness was inspected, so there is nothing to verify",
|
|
17728
|
-
remediation: null
|
|
17729
|
-
})
|
|
17730
|
-
]
|
|
17731
|
-
});
|
|
17732
|
-
}
|
|
17733
|
-
const detectionContext = {
|
|
17734
|
-
fs: context.adapters.fs,
|
|
17735
|
-
runner: context.adapters.runner,
|
|
17736
|
-
facts: context.platform,
|
|
17737
|
-
paths: context.adapters.paths,
|
|
17738
|
-
projectRoot: context.projectRoot
|
|
17739
|
-
};
|
|
17740
|
-
const harnessConfigs = [];
|
|
17741
|
-
const presentHarnesses = [];
|
|
17742
|
-
for (const adapter of listHarnessAdapters()) {
|
|
17743
|
-
if (context.harness !== null && adapter.manifest.id !== context.harness)
|
|
17744
|
-
continue;
|
|
17745
|
-
const detection = await adapter.detect(detectionContext);
|
|
17746
|
-
if (detection.state === "absent")
|
|
17747
|
-
continue;
|
|
17748
|
-
presentHarnesses.push(adapter.manifest.id);
|
|
17749
|
-
const verification = await adapter.verify(detectionContext);
|
|
17750
|
-
for (const check of verification.checks) {
|
|
17751
|
-
if (check.status === "pass")
|
|
17752
|
-
continue;
|
|
17753
|
-
diagnostics.push(diagnostic({
|
|
17754
|
-
severity: check.status === "fail" ? "warning" : "info",
|
|
17755
|
-
code: `harness-${check.id}`,
|
|
17756
|
-
message: `${adapter.manifest.displayName}: ${check.summary}`,
|
|
17757
|
-
remediation: check.remediation
|
|
17758
|
-
}));
|
|
17759
|
-
}
|
|
17760
|
-
const inspection = await adapter.inspect(detectionContext);
|
|
17761
|
-
harnessConfigs.push(...inspection.summaries);
|
|
17762
|
-
diagnostics.push(...inspection.diagnostics);
|
|
17763
|
-
}
|
|
17764
|
-
const managedIntegrations2 = await readManagedIntegrations(context);
|
|
17765
|
-
const providerContext = {
|
|
17766
|
-
...detectionContext,
|
|
17767
|
-
harnessConfigs,
|
|
17768
|
-
now: context.now,
|
|
17769
|
-
localDatabase: context.adapters.localDatabase,
|
|
17770
|
-
projectIdFor: context.adapters.projectIdFor
|
|
17771
|
-
};
|
|
17772
|
-
for (const adapter of listProviderAdapters()) {
|
|
17773
|
-
if (context.provider !== null && adapter.manifest.id !== context.provider)
|
|
17774
|
-
continue;
|
|
17775
|
-
const detection = await adapter.detect(providerContext);
|
|
17776
|
-
if (detection.state === "absent")
|
|
17777
|
-
continue;
|
|
17778
|
-
const verification = await adapter.verify(providerContext);
|
|
17779
|
-
diagnostics.push(...verification.diagnostics);
|
|
17780
|
-
const harnesses = detection.configuredHarnesses.length > 0 ? detection.configuredHarnesses : (
|
|
17781
|
-
// Installed but wired to nothing: still worth a row, on every present harness, because
|
|
17782
|
-
// "installed and not connected here" is the finding.
|
|
17783
|
-
presentHarnesses
|
|
17784
|
-
);
|
|
17785
|
-
for (const harnessId2 of harnesses) {
|
|
17786
|
-
const declaredTier = adapter.manifest.harnesses.find((entry) => entry.harness === harnessId2)?.verificationTier ?? verification.declaredTier;
|
|
17787
|
-
results.push({
|
|
17788
|
-
providerId: adapter.manifest.id,
|
|
17789
|
-
harnessId: harnessId2,
|
|
17790
|
-
status: statusFor(verification.achievedTier, declaredTier),
|
|
17791
|
-
declaredTier,
|
|
17792
|
-
managedByTokenHarness: managedIntegrations2.has(`${adapter.manifest.id}\0${harnessId2}`),
|
|
17793
|
-
providerManagedByTokenHarness: detection.managedByTokenHarness,
|
|
17794
|
-
checks: verification.checks
|
|
17795
|
-
});
|
|
17796
|
-
}
|
|
17797
|
-
}
|
|
17798
|
-
const receipts = context.metrics === null ? [] : await readReceipts(context);
|
|
17799
|
-
const latest = receipts[0] ?? null;
|
|
17800
|
-
const failures = results.flatMap((result2) => result2.checks.filter(contributesToProblems));
|
|
17801
|
-
const report = {
|
|
17802
|
-
receiptId: latest?.receiptId ?? null,
|
|
17803
|
-
appliedAt: latest?.appliedAt ?? null,
|
|
17804
|
-
results,
|
|
17805
|
-
healthyAtDeclaredTier: failures.length === 0
|
|
17806
|
-
};
|
|
17807
|
-
return commandResult({
|
|
17808
|
-
command: "verify",
|
|
17809
|
-
exitCode: failures.length === 0 ? EXIT_CODES.ok : EXIT_CODES["problems-found"],
|
|
17810
|
-
data: report,
|
|
17811
|
-
diagnostics
|
|
17812
|
-
});
|
|
17813
|
-
}
|
|
17814
|
-
async function readManagedIntegrations(context) {
|
|
17815
|
-
const managed = /* @__PURE__ */ new Set();
|
|
17816
|
-
if (context.adapters === null || context.stateRoot === null)
|
|
17817
|
-
return managed;
|
|
17818
|
-
const journalRoot = context.adapters.fs.join(context.stateRoot, "journals");
|
|
17819
|
-
if (await context.adapters.fs.stat(journalRoot) === null)
|
|
17820
|
-
return managed;
|
|
17821
|
-
const projectId = context.adapters.projectIdFor(context.projectRoot);
|
|
17822
|
-
const store = new FileJournalStore({
|
|
17823
|
-
fs: context.adapters.fs,
|
|
17824
|
-
journalRoot,
|
|
17825
|
-
backupRoot: context.adapters.fs.join(context.stateRoot, "backups")
|
|
17826
|
-
});
|
|
17827
|
-
for (const journal of await store.list()) {
|
|
17828
|
-
if (journal.outcome !== "committed" || journal.projectId !== projectId)
|
|
17829
|
-
continue;
|
|
17830
|
-
for (const integration of journal.managedIntegrations ?? []) {
|
|
17831
|
-
managed.add(`${integration.providerId}\0${integration.harnessId}`);
|
|
17832
|
-
}
|
|
17833
|
-
}
|
|
17834
|
-
return managed;
|
|
17835
|
-
}
|
|
17836
|
-
async function readReceipts(context) {
|
|
17837
|
-
const store = context.metrics;
|
|
17838
|
-
if (store?.listReceipts === void 0)
|
|
17839
|
-
return [];
|
|
17840
|
-
try {
|
|
17841
|
-
return await store.listReceipts();
|
|
17842
|
-
} catch {
|
|
17843
|
-
return [];
|
|
18106
|
+
if (!creation.ok) {
|
|
18107
|
+
diagnostics.push(...creation.diagnostics);
|
|
18108
|
+
return finish3(EXIT_CODES["unsupported-environment"], null);
|
|
17844
18109
|
}
|
|
18110
|
+
const transaction = await executeTransaction({
|
|
18111
|
+
transactionId,
|
|
18112
|
+
planId: null,
|
|
18113
|
+
projectId: adapters.projectIdFor(context.projectRoot),
|
|
18114
|
+
projectRoot: context.projectRoot,
|
|
18115
|
+
actions,
|
|
18116
|
+
fs,
|
|
18117
|
+
snapshots: creation.store,
|
|
18118
|
+
journal: new FileJournalStore({
|
|
18119
|
+
fs,
|
|
18120
|
+
journalRoot: fs.join(context.stateRoot, "journals"),
|
|
18121
|
+
backupRoot: fs.join(context.stateRoot, "backups")
|
|
18122
|
+
}),
|
|
18123
|
+
runner: adapters.runner,
|
|
18124
|
+
now: context.now
|
|
18125
|
+
});
|
|
18126
|
+
diagnostics.push(...transaction.diagnostics);
|
|
18127
|
+
report.execution = {
|
|
18128
|
+
planId: null,
|
|
18129
|
+
transactionId,
|
|
18130
|
+
fromStoredPlan: false,
|
|
18131
|
+
outcome: transaction.journal.outcome === "committed" ? "committed" : transaction.journal.outcome === "rolled-back" ? "rolled-back" : transaction.journal.outcome === "dirty" ? "dirty" : "rejected",
|
|
18132
|
+
results: transaction.journal.entries.map((entry) => ({
|
|
18133
|
+
actionId: entry.actionId,
|
|
18134
|
+
kind: entry.kind,
|
|
18135
|
+
status: entry.status,
|
|
18136
|
+
path: null
|
|
18137
|
+
})),
|
|
18138
|
+
unrestored: transaction.unrestored,
|
|
18139
|
+
receiptId: transaction.journal.outcome === "committed" ? transactionId : null
|
|
18140
|
+
};
|
|
18141
|
+
return finish3(transaction.exitCode, report);
|
|
17845
18142
|
}
|
|
17846
|
-
|
|
17847
|
-
|
|
17848
|
-
if (achieved === null)
|
|
17849
|
-
return "not-applicable";
|
|
17850
|
-
const reached = order.indexOf(achieved);
|
|
17851
|
-
const promised = order.indexOf(declared);
|
|
17852
|
-
if (reached < 0 || promised < 0)
|
|
17853
|
-
return "not-applicable";
|
|
17854
|
-
return reached >= promised ? "healthy" : "degraded";
|
|
17855
|
-
}
|
|
17856
|
-
var init_verify = __esm({
|
|
17857
|
-
"apps/cli/dist/src/commands/verify.js"() {
|
|
18143
|
+
var init_update = __esm({
|
|
18144
|
+
"apps/cli/dist/src/commands/update.js"() {
|
|
17858
18145
|
"use strict";
|
|
17859
|
-
init_src3();
|
|
17860
18146
|
init_src();
|
|
18147
|
+
init_src3();
|
|
17861
18148
|
}
|
|
17862
18149
|
});
|
|
17863
18150
|
|
|
@@ -18430,9 +18717,11 @@ function renderDoctorReport(report, context) {
|
|
|
18430
18717
|
lines.push(...notable);
|
|
18431
18718
|
}
|
|
18432
18719
|
const unwired = report.providers.filter((provider) => provider.state !== "absent" && provider.configuredHarnesses.length === 0);
|
|
18720
|
+
const installedProviders = report.providers.some((provider) => provider.state !== "absent");
|
|
18433
18721
|
lines.push("");
|
|
18434
18722
|
lines.push("NEXT");
|
|
18435
18723
|
const suggestions = report.providers.every((provider) => provider.state === "absent") || unwired.length > 0 ? [["token-harness plan", "see what would change \u2014 writes nothing"]] : [
|
|
18724
|
+
...installedProviders ? [["token-harness update", "check RTK/HarnessTrim for newer versions"]] : [],
|
|
18436
18725
|
["token-harness verify", "check the pipeline actually intercepts"],
|
|
18437
18726
|
["token-harness metrics --since 7d", "see what it saved"]
|
|
18438
18727
|
];
|
|
@@ -19096,6 +19385,355 @@ var init_verify2 = __esm({
|
|
|
19096
19385
|
}
|
|
19097
19386
|
});
|
|
19098
19387
|
|
|
19388
|
+
// apps/cli/dist/src/render/simple.js
|
|
19389
|
+
function title(state) {
|
|
19390
|
+
return [`TOKEN HARNESS - ${state.toUpperCase()}`, ""];
|
|
19391
|
+
}
|
|
19392
|
+
function next(command, description) {
|
|
19393
|
+
return [
|
|
19394
|
+
"",
|
|
19395
|
+
"NEXT STEP",
|
|
19396
|
+
command === null ? ` ${truncate(description, MAX_WIDTH - 2)}` : ` ${command}`,
|
|
19397
|
+
...command === null ? [] : [` ${truncate(description, MAX_WIDTH - 2)}`]
|
|
19398
|
+
];
|
|
19399
|
+
}
|
|
19400
|
+
function changeLine(changed, detail2) {
|
|
19401
|
+
return [
|
|
19402
|
+
"",
|
|
19403
|
+
"CHANGES",
|
|
19404
|
+
` ${changed ? detail2 ?? "Configuration changed." : "Nothing changed."}`
|
|
19405
|
+
];
|
|
19406
|
+
}
|
|
19407
|
+
function harnessName(id) {
|
|
19408
|
+
if (id === "claude")
|
|
19409
|
+
return "Claude Code";
|
|
19410
|
+
if (id === "codex")
|
|
19411
|
+
return "Codex";
|
|
19412
|
+
if (id === "opencode")
|
|
19413
|
+
return "OpenCode";
|
|
19414
|
+
if (id === "pi")
|
|
19415
|
+
return "Pi";
|
|
19416
|
+
if (id === "hermes")
|
|
19417
|
+
return "Hermes";
|
|
19418
|
+
return id;
|
|
19419
|
+
}
|
|
19420
|
+
function providerName(id) {
|
|
19421
|
+
if (id === "rtk")
|
|
19422
|
+
return "RTK";
|
|
19423
|
+
if (id === "harnesstrim")
|
|
19424
|
+
return "HarnessTrim";
|
|
19425
|
+
return id;
|
|
19426
|
+
}
|
|
19427
|
+
function normalWork() {
|
|
19428
|
+
return "Use your coding agent normally; configured optimizers run automatically.";
|
|
19429
|
+
}
|
|
19430
|
+
function usefulEvidence(evidence2) {
|
|
19431
|
+
const useful = evidence2.find((item) => !/^0B known loaded of /i.test(item.summary) && !/^0 MCP servers/i.test(item.summary) && !/^0B of instruction candidates/i.test(item.summary));
|
|
19432
|
+
return useful?.summary ?? evidence2[0]?.summary ?? null;
|
|
19433
|
+
}
|
|
19434
|
+
function renderSimpleDoctor(report) {
|
|
19435
|
+
const present = report.harnesses.filter((item) => item.state !== "absent");
|
|
19436
|
+
const active = report.providers.filter((item) => item.state === "configured" && item.configuredHarnesses.length > 0);
|
|
19437
|
+
const broken = present.some((item) => item.state === "broken") || report.providers.some((item) => item.state === "broken");
|
|
19438
|
+
const newerThanTested = [...present, ...report.providers].some((item) => item.versionVerdict === "unknown-newer");
|
|
19439
|
+
const state = broken ? "attention needed" : newerThanTested ? "ready with limitations" : present.length > 0 ? "ready" : "setup needed";
|
|
19440
|
+
const lines = [...title(state), "WHAT WORKS"];
|
|
19441
|
+
if (present.length === 0)
|
|
19442
|
+
lines.push(" No supported coding harness was found.");
|
|
19443
|
+
for (const item of present) {
|
|
19444
|
+
lines.push(` ${harnessName(item.harnessId)}: ${item.state}${item.version ? ` (${item.version})` : ""}`);
|
|
19445
|
+
}
|
|
19446
|
+
if (active.length === 0)
|
|
19447
|
+
lines.push(" Optimization provider: none active");
|
|
19448
|
+
for (const item of active) {
|
|
19449
|
+
const connected = item.configuredHarnesses.map(harnessName).join(", ");
|
|
19450
|
+
lines.push(truncate(` ${providerName(item.providerId)}: active on ${connected}`, MAX_WIDTH));
|
|
19451
|
+
}
|
|
19452
|
+
lines.push(...changeLine(false));
|
|
19453
|
+
if (broken) {
|
|
19454
|
+
lines.push(...next("token-harness doctor --verbose", "Review the integration that needs attention."));
|
|
19455
|
+
} else if (present.length === 0 || active.length === 0) {
|
|
19456
|
+
lines.push(...next("token-harness setup", "Finish the guided setup."));
|
|
19457
|
+
} else if (newerThanTested) {
|
|
19458
|
+
lines.push(...next("token-harness verify", "You can keep working; verify the active integrations when convenient."));
|
|
19459
|
+
} else {
|
|
19460
|
+
lines.push(...next(null, normalWork()));
|
|
19461
|
+
}
|
|
19462
|
+
return document(lines);
|
|
19463
|
+
}
|
|
19464
|
+
function renderSimpleSetup(report, context) {
|
|
19465
|
+
const state = report.stage === "ready" ? "ready" : report.stage === "attention" ? "attention needed" : "setup needed";
|
|
19466
|
+
const lines = [...title(state), "DETECTED"];
|
|
19467
|
+
const harnesses = report.doctor.harnesses.filter((item) => item.state !== "absent");
|
|
19468
|
+
if (harnesses.length === 0)
|
|
19469
|
+
lines.push(" Claude Code/Codex: not found");
|
|
19470
|
+
for (const item of harnesses) {
|
|
19471
|
+
lines.push(` ${harnessName(item.harnessId)}: ${item.state}${item.version ? ` (${item.version})` : ""}`);
|
|
19472
|
+
}
|
|
19473
|
+
const active = report.doctor.providers.filter((item) => item.configuredHarnesses.length > 0);
|
|
19474
|
+
if (active.length === 0)
|
|
19475
|
+
lines.push(" Optimization provider: not active");
|
|
19476
|
+
for (const provider of active) {
|
|
19477
|
+
lines.push(truncate(` ${providerName(provider.providerId)}: active on ${provider.configuredHarnesses.map(harnessName).join(", ")}`, MAX_WIDTH));
|
|
19478
|
+
}
|
|
19479
|
+
if (report.plan !== null && report.apply === null && report.plan.actions.length > 0) {
|
|
19480
|
+
lines.push("", "SAFE PLAN");
|
|
19481
|
+
for (const action of report.plan.actions) {
|
|
19482
|
+
const path = primaryActionPath(action);
|
|
19483
|
+
lines.push(truncate(` ${actionLabel(action.kind)}${path === null ? "" : ` - ${displayPath(path, context.home)}`}`, MAX_WIDTH));
|
|
19484
|
+
}
|
|
19485
|
+
}
|
|
19486
|
+
lines.push(...changeLine(report.changed, report.apply?.results.some((item) => item.status === "applied") ? "Safe configuration applied and checked." : void 0));
|
|
19487
|
+
lines.push(...next(report.nextStep.command, report.stage === "ready" && report.nextStep.command === "token-harness ui" ? "Open the dashboard once to review status; after that use your coding agent normally." : report.nextStep.description));
|
|
19488
|
+
return document(lines);
|
|
19489
|
+
}
|
|
19490
|
+
function renderVerboseSetup(report, context) {
|
|
19491
|
+
const lines = ["SETUP TECHNICAL DETAILS", "", "DETECTION"];
|
|
19492
|
+
for (const harness of report.doctor.harnesses) {
|
|
19493
|
+
lines.push(truncate(` ${harness.harnessId}: state ${harness.state}, version ${harness.version ?? "unknown"}, verdict ${harness.versionVerdict ?? "unknown"}`, MAX_WIDTH));
|
|
19494
|
+
if (harness.configPath !== null)
|
|
19495
|
+
lines.push(truncate(` config ${displayPath(harness.configPath, context.home)}`, MAX_WIDTH));
|
|
19496
|
+
}
|
|
19497
|
+
for (const provider of report.doctor.providers) {
|
|
19498
|
+
lines.push(truncate(` ${provider.providerId}: state ${provider.state}, version ${provider.version ?? "unknown"}, wired ${provider.configuredHarnesses.join(", ") || "none"}`, MAX_WIDTH));
|
|
19499
|
+
}
|
|
19500
|
+
if (report.plan !== null) {
|
|
19501
|
+
lines.push("", `PLAN ${report.plan.planId ?? "not produced"}`);
|
|
19502
|
+
lines.push(` persisted: ${String(report.plan.persisted)}`);
|
|
19503
|
+
lines.push(` actions: ${report.plan.actions.length}`);
|
|
19504
|
+
lines.push(` conflicts: ${report.plan.conflicts.length}`);
|
|
19505
|
+
for (const action of report.plan.actions) {
|
|
19506
|
+
lines.push(truncate(` ${action.id}: ${action.kind} - ${action.explanation}`, MAX_WIDTH));
|
|
19507
|
+
}
|
|
19508
|
+
}
|
|
19509
|
+
if (report.apply !== null) {
|
|
19510
|
+
lines.push("", `TRANSACTION ${report.apply.transactionId ?? "none"}`);
|
|
19511
|
+
lines.push(` outcome: ${report.apply.outcome}`);
|
|
19512
|
+
for (const result2 of report.apply.results) {
|
|
19513
|
+
lines.push(truncate(` ${result2.actionId}: ${result2.status}`, MAX_WIDTH));
|
|
19514
|
+
}
|
|
19515
|
+
}
|
|
19516
|
+
if (report.verify !== null) {
|
|
19517
|
+
lines.push("", "VERIFICATION");
|
|
19518
|
+
lines.push(` healthy at declared tier: ${String(report.verify.healthyAtDeclaredTier)}`);
|
|
19519
|
+
for (const result2 of report.verify.results) {
|
|
19520
|
+
lines.push(` ${result2.providerId} on ${result2.harnessId}: ${result2.status}`);
|
|
19521
|
+
for (const check of result2.checks) {
|
|
19522
|
+
lines.push(truncate(` ${check.id}: ${check.status} - ${check.summary}`, MAX_WIDTH));
|
|
19523
|
+
}
|
|
19524
|
+
}
|
|
19525
|
+
}
|
|
19526
|
+
if (report.budget !== null) {
|
|
19527
|
+
lines.push("", "ALLOWANCE SOURCES");
|
|
19528
|
+
for (const harness of report.budget.harnesses) {
|
|
19529
|
+
if (harness.windows.length === 0)
|
|
19530
|
+
lines.push(` ${harness.harnessId}: ${harness.state}`);
|
|
19531
|
+
for (const window of harness.windows) {
|
|
19532
|
+
lines.push(truncate(` ${harness.harnessId}/${window.scope}: ${window.source}, ${window.confidence}`, MAX_WIDTH));
|
|
19533
|
+
}
|
|
19534
|
+
}
|
|
19535
|
+
}
|
|
19536
|
+
lines.push("", ...renderSimpleSetup(report, context).trimEnd().split("\n"));
|
|
19537
|
+
return document(lines);
|
|
19538
|
+
}
|
|
19539
|
+
function formatReset(resetsAt) {
|
|
19540
|
+
return resetsAt === null ? "reset unknown" : `resets ${resetsAt}`;
|
|
19541
|
+
}
|
|
19542
|
+
function renderSimpleBudget(report) {
|
|
19543
|
+
const observed = report.harnesses.filter((item) => item.state === "observed");
|
|
19544
|
+
const lines = [
|
|
19545
|
+
...title(observed.length > 0 ? "allowance available" : "allowance unavailable"),
|
|
19546
|
+
"ALLOWANCE"
|
|
19547
|
+
];
|
|
19548
|
+
for (const harness of report.harnesses) {
|
|
19549
|
+
if (harness.windows.length === 0) {
|
|
19550
|
+
lines.push(` ${harnessName(harness.harnessId)}: ${harness.state}`);
|
|
19551
|
+
continue;
|
|
19552
|
+
}
|
|
19553
|
+
for (const window of harness.windows) {
|
|
19554
|
+
const label = window.bucketName ?? window.scope;
|
|
19555
|
+
const remaining = window.remainingPercent === null ? "unknown" : `${window.remainingPercent}% left`;
|
|
19556
|
+
lines.push(truncate(` ${harnessName(harness.harnessId)} ${label}: ${remaining}, ${formatReset(window.resetsAt)}`, MAX_WIDTH));
|
|
19557
|
+
}
|
|
19558
|
+
}
|
|
19559
|
+
lines.push(...changeLine(false));
|
|
19560
|
+
lines.push(...next(observed.length > 0 ? "token-harness optimize" : "token-harness setup", observed.length > 0 ? "Get advice for the task you are about to start." : "Check the local installation and connections."));
|
|
19561
|
+
return document(lines);
|
|
19562
|
+
}
|
|
19563
|
+
function renderSimpleContext(report) {
|
|
19564
|
+
const lines = [...title("context checked"), "CONTEXT"];
|
|
19565
|
+
lines.push(` Instruction files: ${report.instructions.length}`);
|
|
19566
|
+
lines.push(` Known loaded instructions: ${formatCount(report.knownLoadedInstructionBytes)} bytes`);
|
|
19567
|
+
for (const harness of report.harnesses) {
|
|
19568
|
+
lines.push(truncate(` ${harnessName(harness.harnessId)}: ${harness.state}, model ${harness.model ?? "unknown"}, ${harness.mcpServers.length} MCP servers`, MAX_WIDTH));
|
|
19569
|
+
}
|
|
19570
|
+
lines.push(...changeLine(false));
|
|
19571
|
+
lines.push(...next("token-harness optimize", "Turn these observations into one recommendation."));
|
|
19572
|
+
return document(lines);
|
|
19573
|
+
}
|
|
19574
|
+
function renderSimpleMcp(report) {
|
|
19575
|
+
const attention = report.harnesses.some((harness) => harness.assessments.some((item) => item.usability === "attention"));
|
|
19576
|
+
const lines = [...title(attention ? "attention needed" : "mcp checked"), "MCP"];
|
|
19577
|
+
for (const harness of report.harnesses) {
|
|
19578
|
+
lines.push(` ${harnessName(harness.harnessId)}: ${harness.servers.length} servers, ${harness.knownToolCount} known tools`);
|
|
19579
|
+
}
|
|
19580
|
+
lines.push(...changeLine(false));
|
|
19581
|
+
lines.push(...next(attention ? "token-harness mcp --verbose" : "token-harness optimize", attention ? "Review the server that needs attention." : "See whether context can be simplified for the next task."));
|
|
19582
|
+
return document(lines);
|
|
19583
|
+
}
|
|
19584
|
+
function renderSimpleOptimize(report) {
|
|
19585
|
+
const advice = report.harnesses.filter((item) => item.state !== "absent");
|
|
19586
|
+
const lines = [
|
|
19587
|
+
...title(advice.length > 0 ? "recommendation ready" : "setup needed"),
|
|
19588
|
+
"RECOMMENDATION"
|
|
19589
|
+
];
|
|
19590
|
+
if (advice.length === 0)
|
|
19591
|
+
lines.push(" No supported harness could be assessed.");
|
|
19592
|
+
for (const harness of advice) {
|
|
19593
|
+
const recommendation = harness.recommendations.find((item) => item.priority === "first") ?? harness.recommendations.find((item) => item.priority === "next");
|
|
19594
|
+
lines.push(truncate(` ${harnessName(harness.harnessId)}: ${recommendation?.action ?? "No change recommended."}`, MAX_WIDTH));
|
|
19595
|
+
const evidence2 = recommendation === void 0 ? null : usefulEvidence(recommendation.evidence);
|
|
19596
|
+
if (evidence2)
|
|
19597
|
+
lines.push(truncate(` Why: ${evidence2}`, MAX_WIDTH));
|
|
19598
|
+
}
|
|
19599
|
+
lines.push(...changeLine(false));
|
|
19600
|
+
const canPlan = advice.some((item) => item.recommendedEffort !== item.currentEffort || item.recommendedVerbosity !== item.currentVerbosity);
|
|
19601
|
+
lines.push(...next(canPlan ? "token-harness plan --native-policy" : null, canPlan ? "Review the reversible recommended policy change." : "No change is required now. " + normalWork()));
|
|
19602
|
+
return document(lines);
|
|
19603
|
+
}
|
|
19604
|
+
function renderSimplePlan(report, context) {
|
|
19605
|
+
const lines = [
|
|
19606
|
+
...title(report.conflicts.length > 0 ? "blocked" : report.actions.length > 0 ? "plan ready" : "already configured")
|
|
19607
|
+
];
|
|
19608
|
+
if (report.conflicts.length > 0) {
|
|
19609
|
+
lines.push("BLOCKED BY");
|
|
19610
|
+
for (const conflict of report.conflicts)
|
|
19611
|
+
lines.push(truncate(` ${conflict.code}: ${conflict.detail[0] ?? conflict.scope}`, MAX_WIDTH));
|
|
19612
|
+
} else {
|
|
19613
|
+
lines.push("WOULD CHANGE");
|
|
19614
|
+
if (report.actions.length === 0)
|
|
19615
|
+
lines.push(" Nothing.");
|
|
19616
|
+
for (const action of report.actions) {
|
|
19617
|
+
const path = primaryActionPath(action);
|
|
19618
|
+
const shownPath = path === null ? "" : ` - ${truncatePath(displayPath(path, context.home), 34)}`;
|
|
19619
|
+
lines.push(truncate(` ${actionLabel(action.kind)}${shownPath}`, MAX_WIDTH));
|
|
19620
|
+
}
|
|
19621
|
+
lines.push(` Network: ${report.network.length === 0 ? "none" : report.network.join(", ")}`);
|
|
19622
|
+
lines.push(` Backups: ${report.backups.files}`);
|
|
19623
|
+
}
|
|
19624
|
+
lines.push(...changeLine(false));
|
|
19625
|
+
if (report.conflicts.length > 0)
|
|
19626
|
+
lines.push(...next("token-harness plan --verbose", "Review the conflict and its safe resolution."));
|
|
19627
|
+
else if (report.actions.length > 0 && report.persisted && report.planId !== null)
|
|
19628
|
+
lines.push(...next(`token-harness apply --plan ${report.planId} --yes`, "Apply exactly this stored plan."));
|
|
19629
|
+
else if (report.actions.length === 0)
|
|
19630
|
+
lines.push(...report.pipelineId === null ? next("token-harness setup", "Check detection and finish guided setup.") : next(null, normalWork()));
|
|
19631
|
+
else
|
|
19632
|
+
lines.push(...next("token-harness ui", "Open the dashboard to review the current state."));
|
|
19633
|
+
return document(lines);
|
|
19634
|
+
}
|
|
19635
|
+
function renderSimpleApply(report, command) {
|
|
19636
|
+
const changed = report.outcome === "committed" && report.results.some((item) => item.status === "applied");
|
|
19637
|
+
const okay = report.outcome === "committed" || report.outcome === "nothing-to-do";
|
|
19638
|
+
const lines = [...title(okay ? "complete" : report.outcome), "RESULT"];
|
|
19639
|
+
const appliedCount = report.results.filter((item) => item.status === "applied").length;
|
|
19640
|
+
lines.push(` ${appliedCount} actions applied`);
|
|
19641
|
+
if (command === "uninstall" && report.outcome === "committed" && appliedCount === 0) {
|
|
19642
|
+
lines.push(" Removed nothing: no owned entry was recognised.");
|
|
19643
|
+
}
|
|
19644
|
+
lines.push(` Transaction: ${report.transactionId ?? "none"}`);
|
|
19645
|
+
lines.push(...changeLine(changed, command === "uninstall" ? "Owned configuration removed." : command === "rollback" ? "Previous configuration restored." : "Configuration applied and committed."));
|
|
19646
|
+
const confirmationCommand = command === "apply" && report.planId !== null ? `token-harness apply --plan ${report.planId} --yes` : `token-harness ${command} --yes`;
|
|
19647
|
+
lines.push(...next(okay ? "token-harness verify" : report.outcome === "confirmation-required" ? confirmationCommand : `token-harness ${command} --verbose`, okay ? "Check that the integration works; a successful verify is the end of setup." : report.outcome === "confirmation-required" ? "Apply the reviewed change." : "Review the technical result."));
|
|
19648
|
+
return document(lines);
|
|
19649
|
+
}
|
|
19650
|
+
function renderSimpleVerify(report) {
|
|
19651
|
+
const lines = [
|
|
19652
|
+
...title(report.healthyAtDeclaredTier ? "working" : "attention needed"),
|
|
19653
|
+
"INTEGRATIONS"
|
|
19654
|
+
];
|
|
19655
|
+
if (report.results.length === 0)
|
|
19656
|
+
lines.push(" Nothing is configured to verify yet.");
|
|
19657
|
+
for (const item of report.results)
|
|
19658
|
+
lines.push(truncate(` ${providerName(item.providerId)} on ${harnessName(item.harnessId)}: ${item.status}`, MAX_WIDTH));
|
|
19659
|
+
lines.push(...changeLine(false));
|
|
19660
|
+
lines.push(...next(report.healthyAtDeclaredTier ? null : "token-harness verify --verbose", report.healthyAtDeclaredTier ? normalWork() : "Review the failed check and suggested fix."));
|
|
19661
|
+
return document(lines);
|
|
19662
|
+
}
|
|
19663
|
+
function renderSimpleStatus(report) {
|
|
19664
|
+
const lines = [...title(report.problemCount === 0 ? "healthy" : "attention needed"), "ACTIVE"];
|
|
19665
|
+
if (report.pipelines.length === 0)
|
|
19666
|
+
lines.push(" No Token Harness pipeline is active.");
|
|
19667
|
+
for (const pipeline of report.pipelines) {
|
|
19668
|
+
const providers = [...new Set(pipeline.owners.map((owner) => owner.owner))];
|
|
19669
|
+
lines.push(truncate(` ${harnessName(pipeline.harness)}: ${providers.map(providerName).join(" -> ") || "no provider"}`, MAX_WIDTH));
|
|
19670
|
+
}
|
|
19671
|
+
lines.push(` Drift: ${report.drift.length === 0 ? "none" : report.drift.length}`);
|
|
19672
|
+
lines.push(...changeLine(false));
|
|
19673
|
+
lines.push(...next(report.problemCount === 0 ? report.pipelines.length === 0 ? "token-harness setup" : null : "token-harness status --verbose", report.problemCount === 0 ? report.pipelines.length === 0 ? "Finish the guided setup." : normalWork() : "Review the drift before making changes."));
|
|
19674
|
+
return document(lines);
|
|
19675
|
+
}
|
|
19676
|
+
function renderSimpleMetrics(report) {
|
|
19677
|
+
const lines = [...title("savings checked"), "SAVINGS"];
|
|
19678
|
+
const measured = report.classes.filter((item) => item.saved !== null);
|
|
19679
|
+
if (measured.length === 0)
|
|
19680
|
+
lines.push(" No comparable savings recorded yet.");
|
|
19681
|
+
for (const item of measured)
|
|
19682
|
+
lines.push(` ${item.class}: ${formatCount(item.saved ?? 0)} ${item.unit ?? ""} saved`);
|
|
19683
|
+
lines.push(` Errors: ${report.errors}`);
|
|
19684
|
+
lines.push(...changeLine(false));
|
|
19685
|
+
lines.push(...next(null, "Measurement is complete. Use optimize before a task only when you want fresh advice."));
|
|
19686
|
+
return document(lines);
|
|
19687
|
+
}
|
|
19688
|
+
function renderSimpleHistory(report) {
|
|
19689
|
+
const lines = [...title("history checked"), "LOCAL USAGE"];
|
|
19690
|
+
if (report.harnesses.length === 0)
|
|
19691
|
+
lines.push(` ${report.source.name}: ${report.source.state}`);
|
|
19692
|
+
for (const item of report.harnesses)
|
|
19693
|
+
lines.push(` ${harnessName(item.harnessId)}: ${formatCount(item.totalTokens)} tokens, trend ${item.burnTrend.state}`);
|
|
19694
|
+
lines.push(...changeLine(false));
|
|
19695
|
+
lines.push(...next(null, "History is informational. Run token-harness optimize when you want task-specific advice."));
|
|
19696
|
+
return document(lines);
|
|
19697
|
+
}
|
|
19698
|
+
function updateStatus(item) {
|
|
19699
|
+
if (item.verdict === "current")
|
|
19700
|
+
return `${item.installed ?? "installed"} is current`;
|
|
19701
|
+
if (item.verdict === "pinned")
|
|
19702
|
+
return `kept at ${item.pin ?? item.installed ?? "installed"} (pinned)`;
|
|
19703
|
+
if (item.verdict === "blocked-unreviewed")
|
|
19704
|
+
return `${item.available ?? "newer version"} available; keeping ${item.installed ?? "installed"} until validated`;
|
|
19705
|
+
if (item.verdict === "upgradable")
|
|
19706
|
+
return `${item.installed ?? "installed"} -> ${item.available ?? "newer version"} ready`;
|
|
19707
|
+
if (item.verdict === "not-installed")
|
|
19708
|
+
return "not installed";
|
|
19709
|
+
if (item.verdict === "no-channel")
|
|
19710
|
+
return "installed; no supported update channel";
|
|
19711
|
+
if (item.verdict === "unavailable")
|
|
19712
|
+
return "installed; update check unavailable";
|
|
19713
|
+
return "installed; update status unknown";
|
|
19714
|
+
}
|
|
19715
|
+
function renderSimpleUpdate(report) {
|
|
19716
|
+
const execution = report.execution;
|
|
19717
|
+
const changed = execution?.outcome === "committed" && execution.results.some((item) => item.status === "applied");
|
|
19718
|
+
const lines = [...title(changed ? "updated" : "update checked"), "PROVIDERS"];
|
|
19719
|
+
if (report.providers.length === 0)
|
|
19720
|
+
lines.push(" No provider was detected.");
|
|
19721
|
+
for (const item of report.providers)
|
|
19722
|
+
lines.push(truncate(` ${providerName(item.providerId)}: ${updateStatus(item)}`, MAX_WIDTH));
|
|
19723
|
+
lines.push(...changeLine(changed, "Provider update applied."));
|
|
19724
|
+
const pending = report.providers.some((item) => item.verdict === "upgradable");
|
|
19725
|
+
const deferred = report.providers.some((item) => item.verdict === "blocked-unreviewed");
|
|
19726
|
+
lines.push(...next(pending && execution?.outcome === "confirmation-required" ? "token-harness update --yes" : changed ? "token-harness verify" : null, pending && execution?.outcome === "confirmation-required" ? "Apply the reviewed provider update." : changed ? "Check that the updated integrations still work." : deferred ? "No action required. The installed versions stay active until newer ones are validated." : normalWork()));
|
|
19727
|
+
return document(lines);
|
|
19728
|
+
}
|
|
19729
|
+
var init_simple = __esm({
|
|
19730
|
+
"apps/cli/dist/src/render/simple.js"() {
|
|
19731
|
+
"use strict";
|
|
19732
|
+
init_src();
|
|
19733
|
+
init_layout();
|
|
19734
|
+
}
|
|
19735
|
+
});
|
|
19736
|
+
|
|
19099
19737
|
// apps/cli/dist/src/render/index.js
|
|
19100
19738
|
function planRendering(report, result2, context) {
|
|
19101
19739
|
const conflictCodes = new Set(report.conflicts.map((conflict) => conflict.code));
|
|
@@ -19104,6 +19742,13 @@ function planRendering(report, result2, context) {
|
|
|
19104
19742
|
stderrDiagnostics: result2.diagnostics.filter((entry) => !conflictCodes.has(entry.code))
|
|
19105
19743
|
};
|
|
19106
19744
|
}
|
|
19745
|
+
function planRenderingSimple(report, result2, context) {
|
|
19746
|
+
const conflictCodes = new Set(report.conflicts.map((conflict) => conflict.code));
|
|
19747
|
+
return {
|
|
19748
|
+
report: renderSimplePlan(report, context),
|
|
19749
|
+
stderrDiagnostics: result2.diagnostics.filter((entry) => !conflictCodes.has(entry.code))
|
|
19750
|
+
};
|
|
19751
|
+
}
|
|
19107
19752
|
function renderHuman(result2, context) {
|
|
19108
19753
|
const data = result2.data;
|
|
19109
19754
|
if (data === null)
|
|
@@ -19112,11 +19757,45 @@ function renderHuman(result2, context) {
|
|
|
19112
19757
|
report,
|
|
19113
19758
|
stderrDiagnostics: result2.diagnostics
|
|
19114
19759
|
});
|
|
19760
|
+
if (context.verbose !== true) {
|
|
19761
|
+
switch (result2.command) {
|
|
19762
|
+
case "apply":
|
|
19763
|
+
case "rollback":
|
|
19764
|
+
case "uninstall":
|
|
19765
|
+
return plain(renderSimpleApply(data, result2.command));
|
|
19766
|
+
case "budget":
|
|
19767
|
+
return plain(renderSimpleBudget(data));
|
|
19768
|
+
case "context":
|
|
19769
|
+
return plain(renderSimpleContext(data));
|
|
19770
|
+
case "doctor":
|
|
19771
|
+
return plain(renderSimpleDoctor(data));
|
|
19772
|
+
case "history":
|
|
19773
|
+
return plain(renderSimpleHistory(data));
|
|
19774
|
+
case "mcp":
|
|
19775
|
+
return plain(renderSimpleMcp(data));
|
|
19776
|
+
case "metrics":
|
|
19777
|
+
return plain(renderSimpleMetrics(data));
|
|
19778
|
+
case "optimize":
|
|
19779
|
+
return plain(renderSimpleOptimize(data));
|
|
19780
|
+
case "plan":
|
|
19781
|
+
return planRenderingSimple(data, result2, context);
|
|
19782
|
+
case "setup":
|
|
19783
|
+
return plain(renderSimpleSetup(data, context));
|
|
19784
|
+
case "status":
|
|
19785
|
+
return plain(renderSimpleStatus(data));
|
|
19786
|
+
case "update":
|
|
19787
|
+
return plain(renderSimpleUpdate(data));
|
|
19788
|
+
case "verify":
|
|
19789
|
+
return plain(renderSimpleVerify(data));
|
|
19790
|
+
}
|
|
19791
|
+
}
|
|
19115
19792
|
switch (result2.command) {
|
|
19116
19793
|
case "apply":
|
|
19117
19794
|
case "rollback":
|
|
19118
19795
|
case "uninstall":
|
|
19119
19796
|
return plain(renderApplyReport(data, context, result2.command));
|
|
19797
|
+
case "setup":
|
|
19798
|
+
return plain(renderVerboseSetup(data, context));
|
|
19120
19799
|
case "benchmark":
|
|
19121
19800
|
return plain(renderBenchmarkReport(data, context));
|
|
19122
19801
|
case "benchmark-matrix":
|
|
@@ -19169,6 +19848,7 @@ var init_render = __esm({
|
|
|
19169
19848
|
init_status2();
|
|
19170
19849
|
init_update2();
|
|
19171
19850
|
init_verify2();
|
|
19851
|
+
init_simple();
|
|
19172
19852
|
init_layout();
|
|
19173
19853
|
}
|
|
19174
19854
|
});
|
|
@@ -19181,81 +19861,65 @@ var ROOT_USAGE, COMMAND_USAGE;
|
|
|
19181
19861
|
var init_usage = __esm({
|
|
19182
19862
|
"apps/cli/dist/src/usage.js"() {
|
|
19183
19863
|
"use strict";
|
|
19184
|
-
ROOT_USAGE = `token-harness \u2014
|
|
19864
|
+
ROOT_USAGE = `token-harness \u2014 simple Claude Code and Codex efficiency
|
|
19185
19865
|
|
|
19186
|
-
|
|
19187
|
-
|
|
19188
|
-
2 token-harness budget quota remaining writes nothing
|
|
19189
|
-
3 token-harness context static context cost writes nothing
|
|
19190
|
-
4 token-harness mcp MCP audit writes nothing
|
|
19191
|
-
5 token-harness history local usage history writes nothing
|
|
19192
|
-
6 token-harness optimize quota-aware advice writes nothing
|
|
19193
|
-
7 token-harness plan what would change writes nothing
|
|
19194
|
-
8 token-harness apply --yes make those changes WRITES
|
|
19195
|
-
9 token-harness verify is it actually intercepting writes nothing
|
|
19196
|
-
10 token-harness metrics what it saved writes nothing
|
|
19197
|
-
11 token-harness benchmark compare paired task receipts writes nothing
|
|
19198
|
-
12 token-harness benchmark-start snapshot task start writes state
|
|
19199
|
-
13 token-harness benchmark-finish close task receipt writes state
|
|
19200
|
-
14 token-harness benchmark-matrix aggregate empirical pairs writes nothing
|
|
19866
|
+
New here? Run one command
|
|
19867
|
+
token-harness setup
|
|
19201
19868
|
|
|
19202
|
-
|
|
19869
|
+
It detects what is installed, checks what works, and prepares only supported
|
|
19870
|
+
changes. It ends with one next step. Nothing changes without an explicit
|
|
19871
|
+
--yes.
|
|
19203
19872
|
|
|
19204
19873
|
Usage
|
|
19205
19874
|
token-harness <command> [flags]
|
|
19206
|
-
token-harness help <command>
|
|
19207
19875
|
|
|
19208
|
-
|
|
19209
|
-
|
|
19210
|
-
|
|
19211
|
-
|
|
19212
|
-
|
|
19213
|
-
history Read local Claude/Codex usage history through ccusage
|
|
19214
|
-
plan Compute what would change, file by file. Changes nothing
|
|
19215
|
-
apply Run that plan inside a transaction that can be rolled back
|
|
19216
|
-
verify Check the pipeline actually intercepts, at its declared tier
|
|
19217
|
-
metrics Report what was saved, labelled with how it was measured
|
|
19218
|
-
benchmark Compare baseline/optimized task receipts with quality gates
|
|
19219
|
-
benchmark-start
|
|
19220
|
-
Snapshot quota/policy before one benchmark task into local state
|
|
19221
|
-
benchmark-finish
|
|
19222
|
-
Close that capture with quota-after and an explicit quality gate
|
|
19223
|
-
benchmark-matrix
|
|
19224
|
-
Aggregate complete local pairs by class and evidence
|
|
19225
|
-
optimize Combine quota and context evidence into read-only policy advice
|
|
19226
|
-
status Report applied pipelines, drift, and importer modes
|
|
19227
|
-
update Update installed providers to what their channel offers
|
|
19228
|
-
rollback Restore the files a transaction changed, as they were before
|
|
19229
|
-
uninstall Remove what Token Harness set up, leaving everything else
|
|
19876
|
+
Everyday commands
|
|
19877
|
+
setup Guided detection, safe configuration, and verification
|
|
19878
|
+
ui Open the local dashboard in your browser
|
|
19879
|
+
optimize Show the best evidence-based action for the current task
|
|
19880
|
+
status Show active harnesses, providers, and configuration health
|
|
19230
19881
|
|
|
19231
|
-
|
|
19232
|
-
|
|
19882
|
+
Advanced commands
|
|
19883
|
+
doctor Full installation and connection check
|
|
19884
|
+
budget Claude/Codex subscription usage windows
|
|
19885
|
+
context Instruction, model, and context-cost observations
|
|
19886
|
+
mcp MCP server and tool inventory
|
|
19887
|
+
history Local usage history through an installed ccusage
|
|
19888
|
+
plan Prepare an exact, reversible change without applying it
|
|
19889
|
+
apply Apply a reviewed plan
|
|
19890
|
+
verify Check that configured integrations work
|
|
19891
|
+
metrics Show measured savings
|
|
19892
|
+
update Check or update installed providers
|
|
19893
|
+
rollback Restore the previous configuration
|
|
19894
|
+
uninstall Remove only configuration Token Harness owns
|
|
19895
|
+
benchmark, benchmark-start, benchmark-finish, benchmark-matrix
|
|
19896
|
+
Compare real task results for advanced evaluation
|
|
19897
|
+
|
|
19898
|
+
Useful flags
|
|
19899
|
+
--verbose Show technical details instead of the short summary
|
|
19900
|
+
--json Emit the complete machine-readable result
|
|
19901
|
+
--yes Confirm a configuration-changing operation
|
|
19233
19902
|
--harness <id> Restrict the operation to one harness
|
|
19234
19903
|
--provider <id> Restrict the operation to one provider
|
|
19235
19904
|
--project <dir> Use that project instead of the current directory
|
|
19236
|
-
--
|
|
19237
|
-
--
|
|
19238
|
-
--plan <id> Apply a previously computed plan by id
|
|
19239
|
-
--baseline <file> Baseline task benchmark receipt JSON
|
|
19240
|
-
--optimized <file> Optimized task benchmark receipt JSON
|
|
19241
|
-
--benchmark-id <id> Safe local id for benchmark start/finish
|
|
19242
|
-
--variant <name> Benchmark variant: baseline or optimized
|
|
19243
|
-
--quality <result> Finish quality gate: passed or failed
|
|
19244
|
-
--attempts <count> Total attempts used to complete the task
|
|
19245
|
-
--failed-attempts <n> Failed attempts before the final outcome
|
|
19246
|
-
--task <class> Optimizer task: mechanical, standard, hard, critical
|
|
19247
|
-
--profile <name> Optimizer profile: economy, balanced, quality, custom
|
|
19248
|
-
--reserve <percent> Keep this percent of observed allowance in reserve
|
|
19249
|
-
--native-policy Add reversible native Codex policy edits to plan
|
|
19250
|
-
--yes Grant the confirmation a mutating command requires
|
|
19251
|
-
--version Print the version and exit 0
|
|
19252
|
-
--help Print usage and exit 0
|
|
19905
|
+
--help Show help for a command
|
|
19906
|
+
--version Print the version
|
|
19253
19907
|
|
|
19254
|
-
|
|
19255
|
-
configuration, and none of them do without --yes. Metrics and benchmark
|
|
19256
|
-
capture may write only Token Harness's own local state. Exit codes and JSON
|
|
19257
|
-
are specified in RFC 0006.`;
|
|
19908
|
+
Run token-harness <command> --help for advanced flags and safety details.`;
|
|
19258
19909
|
COMMAND_USAGE = {
|
|
19910
|
+
setup: `token-harness setup \u2014 guided onboarding in one command
|
|
19911
|
+
|
|
19912
|
+
Usage
|
|
19913
|
+
token-harness setup [--yes] [--verbose] [--json] [--project <dir>]
|
|
19914
|
+
|
|
19915
|
+
Without --yes, setup detects Claude Code/Codex, checks existing providers, and
|
|
19916
|
+
prepares any supported reversible configuration. It changes no harness/provider
|
|
19917
|
+
configuration and ends with one next step.
|
|
19918
|
+
|
|
19919
|
+
Run the suggested token-harness setup --yes only after reviewing the short plan.
|
|
19920
|
+
It applies that stored plan transactionally, verifies the result, reads allowance
|
|
19921
|
+
when available, and points to the local dashboard. Token Harness never installs
|
|
19922
|
+
Claude Code or Codex and never spends model quota during setup.`,
|
|
19259
19923
|
"benchmark-start": `token-harness benchmark-start \u2014 snapshot one task before it runs
|
|
19260
19924
|
|
|
19261
19925
|
Usage
|
|
@@ -19560,14 +20224,14 @@ function formatDiagnostics(diagnostics) {
|
|
|
19560
20224
|
if (errors.length === 0 && warnings.length === 0)
|
|
19561
20225
|
return "";
|
|
19562
20226
|
const lines = [];
|
|
19563
|
-
for (const [
|
|
20227
|
+
for (const [title2, group] of [
|
|
19564
20228
|
["ERRORS", errors],
|
|
19565
20229
|
["WARNINGS", warnings]
|
|
19566
20230
|
]) {
|
|
19567
20231
|
if (group.length === 0)
|
|
19568
20232
|
continue;
|
|
19569
20233
|
lines.push("");
|
|
19570
|
-
lines.push(
|
|
20234
|
+
lines.push(title2);
|
|
19571
20235
|
for (const entry of group)
|
|
19572
20236
|
lines.push(diagnosticLine(entry));
|
|
19573
20237
|
}
|
|
@@ -19649,6 +20313,7 @@ async function run(options) {
|
|
|
19649
20313
|
const renderContext = {
|
|
19650
20314
|
toolVersion,
|
|
19651
20315
|
home: options.home,
|
|
20316
|
+
verbose: false,
|
|
19652
20317
|
decorate: shouldDecorate({
|
|
19653
20318
|
stdoutIsTty: options.stdoutIsTty ?? false,
|
|
19654
20319
|
noColor: env["NO_COLOR"] !== void 0,
|
|
@@ -19688,6 +20353,7 @@ async function run(options) {
|
|
|
19688
20353
|
diagnostics: invocation.diagnostics
|
|
19689
20354
|
}), options, renderContext, json);
|
|
19690
20355
|
}
|
|
20356
|
+
renderContext.verbose = invocation.options.verbose;
|
|
19691
20357
|
const environmentDiagnostics = options.environmentDiagnostics ?? [];
|
|
19692
20358
|
if (environmentDiagnostics.some((entry) => entry.severity === "error")) {
|
|
19693
20359
|
return emit(commandResult({
|
|
@@ -19762,6 +20428,7 @@ var init_run = __esm({
|
|
|
19762
20428
|
init_optimize();
|
|
19763
20429
|
init_plan2();
|
|
19764
20430
|
init_rollback();
|
|
20431
|
+
init_setup2();
|
|
19765
20432
|
init_status();
|
|
19766
20433
|
init_update();
|
|
19767
20434
|
init_verify();
|
|
@@ -19783,6 +20450,7 @@ var init_run = __esm({
|
|
|
19783
20450
|
optimize: runOptimize,
|
|
19784
20451
|
plan: runPlan,
|
|
19785
20452
|
rollback: runRollback,
|
|
20453
|
+
setup: runSetup,
|
|
19786
20454
|
status: runStatus,
|
|
19787
20455
|
uninstall: runUninstall,
|
|
19788
20456
|
update: runUpdate,
|
|
@@ -19792,12 +20460,272 @@ var init_run = __esm({
|
|
|
19792
20460
|
}
|
|
19793
20461
|
});
|
|
19794
20462
|
|
|
20463
|
+
// apps/cli/dist/src/ui.js
|
|
20464
|
+
function parseUiArgs(argv2) {
|
|
20465
|
+
const options = { help: false, json: false, open: true, port: 0 };
|
|
20466
|
+
for (let index = 0; index < argv2.length; index += 1) {
|
|
20467
|
+
const token = argv2[index];
|
|
20468
|
+
if (token === "--help")
|
|
20469
|
+
options.help = true;
|
|
20470
|
+
else if (token === "--json")
|
|
20471
|
+
options.json = true;
|
|
20472
|
+
else if (token === "--no-open")
|
|
20473
|
+
options.open = false;
|
|
20474
|
+
else if (token === "--port") {
|
|
20475
|
+
const raw = argv2[index + 1];
|
|
20476
|
+
const port = Number(raw);
|
|
20477
|
+
if (raw === void 0 || !Number.isInteger(port) || port < 1 || port > 65535) {
|
|
20478
|
+
return { ok: false, message: "--port requires an integer from 1 to 65535" };
|
|
20479
|
+
}
|
|
20480
|
+
options.port = port;
|
|
20481
|
+
index += 1;
|
|
20482
|
+
} else {
|
|
20483
|
+
return { ok: false, message: `Unknown ui option ${JSON.stringify(token)}` };
|
|
20484
|
+
}
|
|
20485
|
+
}
|
|
20486
|
+
return { ok: true, options };
|
|
20487
|
+
}
|
|
20488
|
+
function nameOf(id) {
|
|
20489
|
+
if (id === "claude")
|
|
20490
|
+
return "Claude Code";
|
|
20491
|
+
if (id === "codex")
|
|
20492
|
+
return "Codex";
|
|
20493
|
+
if (id === "opencode")
|
|
20494
|
+
return "OpenCode";
|
|
20495
|
+
if (id === "pi")
|
|
20496
|
+
return "Pi";
|
|
20497
|
+
if (id === "hermes")
|
|
20498
|
+
return "Hermes";
|
|
20499
|
+
return id;
|
|
20500
|
+
}
|
|
20501
|
+
function providerName2(id) {
|
|
20502
|
+
if (id === "harnesstrim")
|
|
20503
|
+
return "HarnessTrim";
|
|
20504
|
+
if (id === "rtk")
|
|
20505
|
+
return "RTK";
|
|
20506
|
+
return id;
|
|
20507
|
+
}
|
|
20508
|
+
function usefulReason(evidence2) {
|
|
20509
|
+
const useful = evidence2.find((item) => !/^0B known loaded of /i.test(item.summary) && !/^0 MCP servers/i.test(item.summary) && !/^0B of instruction candidates/i.test(item.summary));
|
|
20510
|
+
return useful?.summary ?? evidence2[0]?.summary ?? null;
|
|
20511
|
+
}
|
|
20512
|
+
function buildDashboardModel(input) {
|
|
20513
|
+
const present = input.doctor.harnesses.filter((item) => item.state !== "absent");
|
|
20514
|
+
const connectedProviders = input.doctor.providers.filter((item) => item.configuredHarnesses.length > 0);
|
|
20515
|
+
const configuredProviders = connectedProviders.filter((item) => item.state === "configured");
|
|
20516
|
+
const relevantHarnessIds = /* @__PURE__ */ new Set();
|
|
20517
|
+
for (const provider of connectedProviders) {
|
|
20518
|
+
for (const harness of provider.configuredHarnesses)
|
|
20519
|
+
relevantHarnessIds.add(harness);
|
|
20520
|
+
}
|
|
20521
|
+
for (const item of input.budget.harnesses) {
|
|
20522
|
+
if (item.windows.length > 0)
|
|
20523
|
+
relevantHarnessIds.add(item.harnessId);
|
|
20524
|
+
}
|
|
20525
|
+
for (const pipeline of input.status.pipelines)
|
|
20526
|
+
relevantHarnessIds.add(pipeline.harness);
|
|
20527
|
+
const relevantHarnesses = present.filter((harness) => relevantHarnessIds.has(harness.harnessId));
|
|
20528
|
+
const broken = relevantHarnesses.some((item) => item.state === "broken") || connectedProviders.some((item) => item.state === "broken");
|
|
20529
|
+
const newerThanTested = relevantHarnesses.some((item) => item.versionVerdict === "unknown-newer") || connectedProviders.some((item) => item.versionVerdict === "unknown-newer");
|
|
20530
|
+
const state = present.length === 0 ? "setup-needed" : broken || input.status.problemCount > 0 ? "action-needed" : configuredProviders.length === 0 ? "setup-needed" : newerThanTested ? "limited" : "ready";
|
|
20531
|
+
const rankedRecommendations = input.optimize.harnesses.filter((harness) => harness.state !== "absent" && relevantHarnessIds.has(harness.harnessId)).flatMap((harness) => harness.recommendations.map((item) => ({
|
|
20532
|
+
harness: harness.harnessId,
|
|
20533
|
+
priority: item.priority,
|
|
20534
|
+
action: item.action,
|
|
20535
|
+
reason: usefulReason(item.evidence)
|
|
20536
|
+
}))).sort((left, right) => {
|
|
20537
|
+
const rank = { first: 0, next: 1, optional: 2 };
|
|
20538
|
+
return rank[left.priority] - rank[right.priority];
|
|
20539
|
+
});
|
|
20540
|
+
const recommendation = rankedRecommendations.find((item) => item.priority !== "optional");
|
|
20541
|
+
const harnesses = relevantHarnesses.map((harness) => {
|
|
20542
|
+
const providerIds = configuredProviders.filter((provider) => provider.configuredHarnesses.includes(harness.harnessId)).map((provider) => provider.providerId);
|
|
20543
|
+
const budget = input.budget.harnesses.find((item) => item.harnessId === harness.harnessId);
|
|
20544
|
+
const health = harness.state === "broken" ? "attention" : harness.versionVerdict === "unknown-newer" ? "limited" : "active";
|
|
20545
|
+
const statusLabel = health === "attention" ? "Needs attention" : health === "limited" ? "Works \xB7 newer than tested" : providerIds.length > 0 ? "Optimized" : "Available";
|
|
20546
|
+
return {
|
|
20547
|
+
id: harness.harnessId,
|
|
20548
|
+
name: nameOf(harness.harnessId),
|
|
20549
|
+
health,
|
|
20550
|
+
statusLabel,
|
|
20551
|
+
version: harness.version,
|
|
20552
|
+
providers: providerIds.map(providerName2),
|
|
20553
|
+
allowance: (budget?.windows ?? []).map((window) => ({
|
|
20554
|
+
label: window.bucketName ?? window.scope,
|
|
20555
|
+
remainingPercent: window.remainingPercent,
|
|
20556
|
+
resetsAt: window.resetsAt,
|
|
20557
|
+
confidence: window.confidence
|
|
20558
|
+
}))
|
|
20559
|
+
};
|
|
20560
|
+
});
|
|
20561
|
+
const otherHarnesses = present.filter((harness) => !relevantHarnessIds.has(harness.harnessId)).map((harness) => ({ name: nameOf(harness.harnessId), version: harness.version }));
|
|
20562
|
+
const providers = configuredProviders.map((provider) => ({
|
|
20563
|
+
id: provider.providerId,
|
|
20564
|
+
name: providerName2(provider.providerId),
|
|
20565
|
+
harnesses: provider.configuredHarnesses.map(nameOf)
|
|
20566
|
+
}));
|
|
20567
|
+
const copy = state === "ready" ? {
|
|
20568
|
+
statusLabel: "READY",
|
|
20569
|
+
headline: "Everything important is connected.",
|
|
20570
|
+
summary: "Token Harness is already active through your configured integrations. This dashboard is for status and guidance; it is not a launcher.",
|
|
20571
|
+
nextStep: {
|
|
20572
|
+
command: null,
|
|
20573
|
+
title: "Use your coding agent normally",
|
|
20574
|
+
description: "Open Claude Code, Codex, or OpenCode exactly as you normally do. RTK and HarnessTrim run automatically where they are configured."
|
|
20575
|
+
}
|
|
20576
|
+
} : state === "limited" ? {
|
|
20577
|
+
statusLabel: "READY WITH LIMITATIONS",
|
|
20578
|
+
headline: "You can keep working.",
|
|
20579
|
+
summary: "An active integration uses a version newer than the tested range. Token Harness will keep working read-only and stay conservative about changes.",
|
|
20580
|
+
nextStep: {
|
|
20581
|
+
command: "token-harness verify",
|
|
20582
|
+
title: "Verify the active integrations",
|
|
20583
|
+
description: "Keep using your coding agents normally. Run this check when you want evidence that the configured interception still works."
|
|
20584
|
+
}
|
|
20585
|
+
} : state === "action-needed" ? {
|
|
20586
|
+
statusLabel: "ACTION NEEDED",
|
|
20587
|
+
headline: "One active integration needs attention.",
|
|
20588
|
+
summary: "Do not change providers yet. Review the live pipeline or configuration issue first; your other working integrations can remain untouched.",
|
|
20589
|
+
nextStep: {
|
|
20590
|
+
command: input.status.problemCount > 0 ? "token-harness status --verbose" : "token-harness doctor --verbose",
|
|
20591
|
+
title: "Review the specific problem",
|
|
20592
|
+
description: "The detailed command is only for the integration that needs attention. It is not part of the normal daily workflow."
|
|
20593
|
+
}
|
|
20594
|
+
} : {
|
|
20595
|
+
statusLabel: "SETUP NEEDED",
|
|
20596
|
+
headline: "Finish the one-time setup.",
|
|
20597
|
+
summary: "A supported coding agent was not found with an active optimization provider yet.",
|
|
20598
|
+
nextStep: {
|
|
20599
|
+
command: "token-harness setup",
|
|
20600
|
+
title: "Continue guided setup",
|
|
20601
|
+
description: "Token Harness will detect what is available and propose only supported changes."
|
|
20602
|
+
}
|
|
20603
|
+
};
|
|
20604
|
+
return {
|
|
20605
|
+
generatedAt: input.generatedAt,
|
|
20606
|
+
state,
|
|
20607
|
+
statusLabel: copy.statusLabel,
|
|
20608
|
+
headline: copy.headline,
|
|
20609
|
+
summary: copy.summary,
|
|
20610
|
+
harnesses,
|
|
20611
|
+
otherHarnesses,
|
|
20612
|
+
providers,
|
|
20613
|
+
recommendation: recommendation === void 0 ? null : {
|
|
20614
|
+
action: `${nameOf(recommendation.harness)}: ${recommendation.action}`,
|
|
20615
|
+
reason: recommendation.reason
|
|
20616
|
+
},
|
|
20617
|
+
nextStep: copy.nextStep
|
|
20618
|
+
};
|
|
20619
|
+
}
|
|
20620
|
+
function uiAsset(path, model) {
|
|
20621
|
+
if (path === "/")
|
|
20622
|
+
return { status: 200, contentType: "text/html; charset=utf-8", body: DASHBOARD_HTML };
|
|
20623
|
+
if (path === "/app.css")
|
|
20624
|
+
return { status: 200, contentType: "text/css; charset=utf-8", body: DASHBOARD_CSS };
|
|
20625
|
+
if (path === "/app.js")
|
|
20626
|
+
return { status: 200, contentType: "text/javascript; charset=utf-8", body: DASHBOARD_JS };
|
|
20627
|
+
if (path === "/api/status")
|
|
20628
|
+
return {
|
|
20629
|
+
status: 200,
|
|
20630
|
+
contentType: "application/json; charset=utf-8",
|
|
20631
|
+
body: JSON.stringify(model)
|
|
20632
|
+
};
|
|
20633
|
+
return { status: 404, contentType: "text/plain; charset=utf-8", body: "Not found\n" };
|
|
20634
|
+
}
|
|
20635
|
+
var UI_USAGE, DASHBOARD_HTML, DASHBOARD_CSS, DASHBOARD_JS;
|
|
20636
|
+
var init_ui = __esm({
|
|
20637
|
+
"apps/cli/dist/src/ui.js"() {
|
|
20638
|
+
"use strict";
|
|
20639
|
+
UI_USAGE = `token-harness ui \u2014 open the local status and guidance dashboard
|
|
20640
|
+
|
|
20641
|
+
Usage
|
|
20642
|
+
token-harness ui [--no-open] [--port <number>] [--json]
|
|
20643
|
+
|
|
20644
|
+
The dashboard listens only on 127.0.0.1 and is read-only.
|
|
20645
|
+
It does not send data anywhere and cannot change configuration.
|
|
20646
|
+
It shows what is active, what needs attention, and what to do next. When the setup is ready,
|
|
20647
|
+
keep using Claude Code, Codex, or OpenCode normally \u2014 Token Harness does not replace their
|
|
20648
|
+
launch commands. Close the local dashboard server with Ctrl+C.`;
|
|
20649
|
+
DASHBOARD_HTML = `<!doctype html>
|
|
20650
|
+
<html lang="en">
|
|
20651
|
+
<head>
|
|
20652
|
+
<meta charset="utf-8">
|
|
20653
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
20654
|
+
<meta name="color-scheme" content="light dark">
|
|
20655
|
+
<title>Token Harness</title>
|
|
20656
|
+
<link rel="stylesheet" href="/app.css">
|
|
20657
|
+
</head>
|
|
20658
|
+
<body>
|
|
20659
|
+
<a class="skip" href="#main">Skip to dashboard</a>
|
|
20660
|
+
<header class="topbar">
|
|
20661
|
+
<div class="brand"><span class="mark" aria-hidden="true">TH</span><span>Token Harness</span></div>
|
|
20662
|
+
<button id="refresh" class="secondary-button" type="button">Refresh</button>
|
|
20663
|
+
</header>
|
|
20664
|
+
<main id="main">
|
|
20665
|
+
<section class="hero" aria-labelledby="headline">
|
|
20666
|
+
<div id="status" class="status-chip">CHECKING</div>
|
|
20667
|
+
<h1 id="headline">Checking your setup...</h1>
|
|
20668
|
+
<p id="summary" class="hero-copy">Reading local status and guidance.</p>
|
|
20669
|
+
<p id="updated" class="timestamp" aria-live="polite"></p>
|
|
20670
|
+
</section>
|
|
20671
|
+
|
|
20672
|
+
<section class="action-card" aria-labelledby="next-title">
|
|
20673
|
+
<div class="action-copy">
|
|
20674
|
+
<p class="eyebrow">WHAT TO DO NOW</p>
|
|
20675
|
+
<h2 id="next-title">Checking the next step...</h2>
|
|
20676
|
+
<p id="description" class="supporting"></p>
|
|
20677
|
+
</div>
|
|
20678
|
+
<div id="command-row" class="command-row" hidden>
|
|
20679
|
+
<code id="command"></code>
|
|
20680
|
+
<button id="copy" class="primary-button" type="button">Copy command</button>
|
|
20681
|
+
</div>
|
|
20682
|
+
</section>
|
|
20683
|
+
|
|
20684
|
+
<section class="section" aria-labelledby="active-title">
|
|
20685
|
+
<div class="section-heading">
|
|
20686
|
+
<div><p class="eyebrow">ACTIVE SETUP</p><h2 id="active-title">What is working</h2></div>
|
|
20687
|
+
<p class="section-note">Only active or relevant tools are shown here.</p>
|
|
20688
|
+
</div>
|
|
20689
|
+
<div id="harnesses" class="harness-grid" aria-live="polite"></div>
|
|
20690
|
+
</section>
|
|
20691
|
+
|
|
20692
|
+
<section id="recommendation-panel" class="recommendation-card" aria-labelledby="recommendation-title" hidden>
|
|
20693
|
+
<p class="eyebrow">USEFUL NOW</p>
|
|
20694
|
+
<h2 id="recommendation-title">Recommendation</h2>
|
|
20695
|
+
<p id="recommendation" class="recommendation-action"></p>
|
|
20696
|
+
<p id="reason" class="supporting"></p>
|
|
20697
|
+
</section>
|
|
20698
|
+
|
|
20699
|
+
<section id="providers-panel" class="compact-panel" aria-labelledby="providers-title" hidden>
|
|
20700
|
+
<div><p class="eyebrow">ACTIVE OPTIMIZERS</p><h2 id="providers-title">Providers</h2></div>
|
|
20701
|
+
<ul id="providers" class="provider-list"></ul>
|
|
20702
|
+
</section>
|
|
20703
|
+
|
|
20704
|
+
<details id="other-panel" class="details-panel" hidden>
|
|
20705
|
+
<summary id="other-summary">Other detected tools</summary>
|
|
20706
|
+
<ul id="other-harnesses" class="secondary-list"></ul>
|
|
20707
|
+
</details>
|
|
20708
|
+
|
|
20709
|
+
<p id="error" class="error" role="alert"></p>
|
|
20710
|
+
</main>
|
|
20711
|
+
<footer>
|
|
20712
|
+
<strong>Local and read-only.</strong> You can close this page whenever you want. Configured optimizers keep working through their normal harness integrations.
|
|
20713
|
+
</footer>
|
|
20714
|
+
<script src="/app.js" defer></script>
|
|
20715
|
+
</body>
|
|
20716
|
+
</html>`;
|
|
20717
|
+
DASHBOARD_CSS = `:root{font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;font-synthesis:none;--bg:#f6f8fb;--surface:#ffffff;--surface-2:#f1f5f9;--text:#111827;--muted:#5b6472;--subtle:#7b8492;--border:#dce2ea;--accent:#0f766e;--accent-strong:#115e59;--accent-soft:#ccfbf1;--warning:#92400e;--warning-soft:#fef3c7;--danger:#b42318;--danger-soft:#fee4e2;--shadow:0 14px 34px rgba(15,23,42,.08);--focus:#2563eb}*{box-sizing:border-box}html{background:var(--bg)}body{margin:0;min-height:100vh;background:linear-gradient(180deg,rgba(15,118,110,.045),transparent 240px),var(--bg);color:var(--text);font-size:16px;line-height:1.5}button{font:inherit}button:focus-visible,a:focus-visible,summary:focus-visible{outline:3px solid var(--focus);outline-offset:3px}.skip{position:absolute;left:-999px;top:1rem;z-index:10;background:var(--text);color:var(--surface);padding:.6rem .8rem;border-radius:8px}.skip:focus{left:1rem}.topbar,main,footer{width:min(1040px,calc(100% - 32px));margin-inline:auto}.topbar{height:68px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--border)}.brand{display:flex;align-items:center;gap:.7rem;font-weight:800;letter-spacing:-.01em}.mark{display:grid;place-items:center;width:36px;height:36px;border-radius:10px;background:var(--accent);color:#fff;font:800 13px ui-monospace,SFMono-Regular,Consolas,monospace}.secondary-button,.primary-button{min-height:44px;border-radius:10px;padding:0 1rem;font-weight:750;cursor:pointer}.secondary-button{border:1px solid var(--border);background:var(--surface);color:var(--text)}.secondary-button:hover{background:var(--surface-2)}.primary-button{border:1px solid var(--accent-strong);background:var(--accent);color:#fff}.primary-button:hover{background:var(--accent-strong)}button:disabled{cursor:wait;opacity:.62}.hero{padding:54px 0 28px;max-width:780px}.status-chip{display:inline-flex;align-items:center;min-height:28px;padding:0 .65rem;border-radius:999px;background:var(--accent-soft);color:var(--accent-strong);font-size:.76rem;font-weight:850;letter-spacing:.08em}.status-chip.limited{background:var(--warning-soft);color:var(--warning)}.status-chip.action-needed{background:var(--danger-soft);color:var(--danger)}.status-chip.setup-needed{background:var(--surface-2);color:var(--muted)}.hero h1{margin:14px 0 10px;font-size:clamp(2.05rem,5vw,3.65rem);line-height:1.04;letter-spacing:-.045em}.hero-copy{margin:0;max-width:720px;color:var(--muted);font-size:1.08rem}.timestamp{margin:12px 0 0;color:var(--subtle);font-size:.82rem}.action-card{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:24px;align-items:center;padding:24px;border:1px solid color-mix(in srgb,var(--accent) 28%,var(--border));border-radius:18px;background:var(--surface);box-shadow:var(--shadow)}.eyebrow{margin:0 0 6px;color:var(--accent-strong);font-size:.72rem;font-weight:850;letter-spacing:.11em}.action-card h2,.section h2,.recommendation-card h2,.compact-panel h2{margin:0;font-size:1.18rem;letter-spacing:-.015em}.supporting{margin:7px 0 0;color:var(--muted)}.command-row{display:flex;align-items:center;gap:10px;max-width:100%}.command-row code{display:block;max-width:440px;padding:12px 14px;border:1px solid var(--border);border-radius:10px;background:var(--surface-2);color:var(--text);font:650 .88rem ui-monospace,SFMono-Regular,Consolas,monospace;overflow-wrap:anywhere}.section{padding-top:34px}.section-heading{display:flex;align-items:end;justify-content:space-between;gap:24px;margin-bottom:14px}.section-note{margin:0;color:var(--subtle);font-size:.86rem}.harness-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,300px),1fr));gap:12px}.harness-card{min-width:0;padding:18px;border:1px solid var(--border);border-radius:16px;background:var(--surface)}.harness-top{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}.harness-card h3{margin:0;font-size:1.06rem}.health{display:inline-flex;align-items:center;gap:7px;flex:0 0 auto;color:var(--accent-strong);font-size:.76rem;font-weight:800}.health::before{content:"";width:8px;height:8px;border-radius:50%;background:var(--accent)}.health.limited{color:var(--warning)}.health.limited::before{background:var(--warning)}.health.attention{color:var(--danger)}.health.attention::before{background:var(--danger)}.harness-meta{margin:5px 0 0;color:var(--muted);font-size:.86rem}.provider-line{margin:13px 0 0;font-size:.9rem}.provider-line strong{font-weight:800}.allowance{margin-top:16px;padding-top:14px;border-top:1px solid var(--border)}.quota{margin-top:12px}.quota:first-child{margin-top:0}.quota-row{display:flex;justify-content:space-between;gap:16px;margin-bottom:6px;font-size:.88rem}.quota-row strong{font-variant-numeric:tabular-nums}.track{height:7px;border-radius:999px;background:var(--surface-2);overflow:hidden}.fill{height:100%;border-radius:inherit;background:var(--accent)}.quota-meta{margin:5px 0 0;color:var(--subtle);font-size:.76rem}.no-allowance{margin:14px 0 0;color:var(--subtle);font-size:.82rem}.recommendation-card,.compact-panel,.details-panel{margin-top:14px;border:1px solid var(--border);border-radius:16px;background:var(--surface)}.recommendation-card{padding:20px}.recommendation-action{margin:9px 0 0;font-weight:760}.compact-panel{display:flex;align-items:center;justify-content:space-between;gap:20px;padding:16px 18px}.provider-list,.secondary-list{margin:0;padding:0;list-style:none}.provider-list{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px}.provider-list li{padding:7px 9px;border:1px solid var(--border);border-radius:9px;background:var(--surface-2);font-size:.82rem}.details-panel{padding:0 16px}.details-panel summary{min-height:48px;display:flex;align-items:center;cursor:pointer;color:var(--muted);font-weight:750}.secondary-list{padding:0 0 14px}.secondary-list li{padding:7px 0;border-top:1px solid var(--border);color:var(--muted);font-size:.86rem}.error{color:var(--danger);font-weight:700}footer{padding:28px 0 42px;color:var(--subtle);font-size:.82rem}footer strong{color:var(--muted)}[hidden]{display:none!important}@media(prefers-color-scheme:dark){:root{--bg:#0b1118;--surface:#111923;--surface-2:#17212d;--text:#f3f6fa;--muted:#b2bdc9;--subtle:#8996a4;--border:#273443;--accent:#2dd4bf;--accent-strong:#99f6e4;--accent-soft:#123d39;--warning:#fbbf24;--warning-soft:#422f12;--danger:#ff8a80;--danger-soft:#44201f;--shadow:0 16px 38px rgba(0,0,0,.22);--focus:#60a5fa}.primary-button{color:#062a27}.mark{color:#062a27}.action-card{border-color:#28514d}}@media(max-width:760px){.topbar,main,footer{width:min(100% - 24px,1040px)}.hero{padding:38px 0 22px}.action-card{grid-template-columns:1fr;gap:16px;padding:19px}.command-row{align-items:stretch;flex-direction:column}.command-row code{max-width:none}.command-row .primary-button{width:100%}.section{padding-top:28px}.section-heading{align-items:flex-start;flex-direction:column;gap:3px}.compact-panel{align-items:flex-start;flex-direction:column}.provider-list{justify-content:flex-start}.topbar{height:62px}}@media(max-width:390px){.hero h1{font-size:2rem}.harness-card{padding:15px}.harness-top{align-items:flex-start;flex-direction:column;gap:6px}}@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important;transition:none!important;animation:none!important}}`;
|
|
20718
|
+
DASHBOARD_JS = `const byId=(id)=>document.getElementById(id);const setText=(id,value)=>{const node=byId(id);if(node)node.textContent=value};function formatReset(value){return value?'Resets '+new Date(value).toLocaleString():'Reset time unavailable'}function renderHarness(item){const card=document.createElement('article');card.className='harness-card';const top=document.createElement('div');top.className='harness-top';const title=document.createElement('h3');title.textContent=item.name;const health=document.createElement('span');health.className='health '+item.health;health.textContent=item.statusLabel;top.append(title,health);card.append(top);const meta=document.createElement('p');meta.className='harness-meta';meta.textContent=item.version?'Version '+item.version:'Version unavailable';card.append(meta);if(item.providers.length){const provider=document.createElement('p');provider.className='provider-line';const strong=document.createElement('strong');strong.textContent=item.providers.join(', ');provider.append(strong,document.createTextNode(' active automatically'));card.append(provider)}if(item.allowance.length){const allowance=document.createElement('div');allowance.className='allowance';for(const quota of item.allowance){const box=document.createElement('div');box.className='quota';const row=document.createElement('div');row.className='quota-row';const label=document.createElement('span');label.textContent=quota.label;const value=document.createElement('strong');value.textContent=quota.remainingPercent===null?'Unknown':quota.remainingPercent+'% left';row.append(label,value);const track=document.createElement('div');track.className='track';track.setAttribute('role','progressbar');track.setAttribute('aria-label',item.name+' '+quota.label);track.setAttribute('aria-valuemin','0');track.setAttribute('aria-valuemax','100');if(quota.remainingPercent!==null){track.setAttribute('aria-valuenow',String(quota.remainingPercent));track.setAttribute('aria-valuetext',quota.remainingPercent+'% remaining')}const fill=document.createElement('div');fill.className='fill';fill.style.width=(quota.remainingPercent===null?0:Math.max(0,Math.min(100,quota.remainingPercent)))+'%';track.append(fill);const detail=document.createElement('p');detail.className='quota-meta';detail.textContent=formatReset(quota.resetsAt)+(quota.confidence==='authoritative'?' \xB7 verified allowance':' \xB7 '+quota.confidence);box.append(row,track,detail);allowance.append(box)}card.append(allowance)}else{const empty=document.createElement('p');empty.className='no-allowance';empty.textContent='Allowance data is not available for this harness.';card.append(empty)}return card}function render(model){document.body.dataset.state=model.state;const status=byId('status');status.textContent=model.statusLabel;status.className='status-chip '+model.state;setText('headline',model.headline);setText('summary',model.summary);setText('updated','Updated '+new Date(model.generatedAt).toLocaleString());setText('next-title',model.nextStep.title);setText('description',model.nextStep.description);const commandRow=byId('command-row');if(model.nextStep.command){setText('command',model.nextStep.command);commandRow.hidden=false}else{setText('command','');commandRow.hidden=true}const harnesses=byId('harnesses');harnesses.replaceChildren();if(model.harnesses.length===0){const empty=document.createElement('p');empty.className='supporting';empty.textContent='No active optimized harness is available yet.';harnesses.append(empty)}for(const item of model.harnesses)harnesses.append(renderHarness(item));const recommendationPanel=byId('recommendation-panel');if(model.recommendation){setText('recommendation',model.recommendation.action);setText('reason',model.recommendation.reason||'This recommendation is based on the currently observable local signals.');recommendationPanel.hidden=false}else{recommendationPanel.hidden=true}const providersPanel=byId('providers-panel');const providers=byId('providers');providers.replaceChildren();if(model.providers.length){for(const item of model.providers){const node=document.createElement('li');node.textContent=item.name+' \xB7 '+item.harnesses.join(', ');providers.append(node)}providersPanel.hidden=false}else{providersPanel.hidden=true}const otherPanel=byId('other-panel');const other=byId('other-harnesses');other.replaceChildren();if(model.otherHarnesses.length){setText('other-summary','Other detected tools ('+model.otherHarnesses.length+')');for(const item of model.otherHarnesses){const node=document.createElement('li');node.textContent=item.name+(item.version?' \xB7 '+item.version:'')+' \xB7 detected, not active in the optimized setup';other.append(node)}otherPanel.hidden=false}else{otherPanel.hidden=true}setText('error','')}async function load(){const refresh=byId('refresh');refresh.disabled=true;refresh.textContent='Refreshing\u2026';try{const response=await fetch('/api/status',{cache:'no-store'});if(!response.ok)throw new Error('Dashboard data is unavailable');render(await response.json())}catch(error){setText('error',error instanceof Error?error.message:String(error))}finally{refresh.disabled=false;refresh.textContent='Refresh'}}byId('refresh').addEventListener('click',load);byId('copy').addEventListener('click',async()=>{const command=byId('command').textContent||'';try{await navigator.clipboard.writeText(command);setText('updated','Command copied')}catch{setText('updated','Copy unavailable \u2014 select the command manually')}});load();setInterval(()=>{if(!document.hidden)load()},30000);`;
|
|
20719
|
+
}
|
|
20720
|
+
});
|
|
20721
|
+
|
|
19795
20722
|
// apps/cli/dist/src/main.js
|
|
19796
20723
|
var main_exports = {};
|
|
19797
20724
|
__export(main_exports, {
|
|
19798
20725
|
main: () => main
|
|
19799
20726
|
});
|
|
19800
20727
|
import process5 from "node:process";
|
|
20728
|
+
import { createServer } from "node:http";
|
|
19801
20729
|
async function runAsDatabaseReader(argv2) {
|
|
19802
20730
|
if (argv2[0] !== SQLITE_CHILD_FLAG)
|
|
19803
20731
|
return false;
|
|
@@ -19815,15 +20743,24 @@ async function runAsDatabaseReader(argv2) {
|
|
|
19815
20743
|
async function main(argv2) {
|
|
19816
20744
|
if (await runAsDatabaseReader(argv2))
|
|
19817
20745
|
return;
|
|
20746
|
+
const uiInvocation = argv2[0] === "ui" ? parseUiArgs(argv2.slice(1)) : null;
|
|
20747
|
+
if (uiInvocation !== null && !uiInvocation.ok) {
|
|
20748
|
+
process5.stderr.write(`${uiInvocation.message}
|
|
20749
|
+
Run token-harness ui --help for usage.
|
|
20750
|
+
`);
|
|
20751
|
+
process5.exitCode = EXIT_CODES["usage-error"];
|
|
20752
|
+
return;
|
|
20753
|
+
}
|
|
20754
|
+
if (uiInvocation?.ok === true && uiInvocation.options.help) {
|
|
20755
|
+
process5.stdout.write(`${UI_USAGE}
|
|
20756
|
+
`);
|
|
20757
|
+
process5.exitCode = EXIT_CODES.ok;
|
|
20758
|
+
return;
|
|
20759
|
+
}
|
|
19818
20760
|
const resolution = resolveHostEnvironment();
|
|
19819
20761
|
const fs = resolution.ok ? new NodeFileSystem(resolution.environment.facts) : null;
|
|
19820
20762
|
const attribution = resolution.ok && fs !== null ? await resolveAttributionSalt(fs, resolution.environment.paths.state) : { salt: null, diagnostics: [] };
|
|
19821
|
-
const
|
|
19822
|
-
argv: argv2,
|
|
19823
|
-
streams: {
|
|
19824
|
-
out: (text3) => process5.stdout.write(text3),
|
|
19825
|
-
err: (text3) => process5.stderr.write(text3)
|
|
19826
|
-
},
|
|
20763
|
+
const baseOptions = {
|
|
19827
20764
|
// On failure `facts` is null only when the operating system itself is
|
|
19828
20765
|
// unsupported. An unresolvable state directory still has honest facts to
|
|
19829
20766
|
// report, and `run` uses them for the runtime-floor check before refusing.
|
|
@@ -19872,15 +20809,188 @@ async function main(argv2) {
|
|
|
19872
20809
|
}) : null,
|
|
19873
20810
|
env: process5.env,
|
|
19874
20811
|
stdoutIsTty: process5.stdout.isTTY === true
|
|
20812
|
+
};
|
|
20813
|
+
if (uiInvocation?.ok === true) {
|
|
20814
|
+
process5.exitCode = await runUi(uiInvocation.options, baseOptions);
|
|
20815
|
+
return;
|
|
20816
|
+
}
|
|
20817
|
+
const exitCode = await run({
|
|
20818
|
+
...baseOptions,
|
|
20819
|
+
argv: argv2,
|
|
20820
|
+
streams: {
|
|
20821
|
+
out: (text3) => process5.stdout.write(text3),
|
|
20822
|
+
err: (text3) => process5.stderr.write(text3)
|
|
20823
|
+
}
|
|
19875
20824
|
});
|
|
19876
20825
|
process5.exitCode = exitCode;
|
|
19877
20826
|
}
|
|
20827
|
+
async function readJsonReport(command, baseOptions) {
|
|
20828
|
+
let stdout = "";
|
|
20829
|
+
let stderr = "";
|
|
20830
|
+
const exitCode = await run({
|
|
20831
|
+
...baseOptions,
|
|
20832
|
+
argv: [command, "--json"],
|
|
20833
|
+
streams: {
|
|
20834
|
+
out: (text3) => {
|
|
20835
|
+
stdout += text3;
|
|
20836
|
+
},
|
|
20837
|
+
err: (text3) => {
|
|
20838
|
+
stderr += text3;
|
|
20839
|
+
}
|
|
20840
|
+
}
|
|
20841
|
+
});
|
|
20842
|
+
let envelope;
|
|
20843
|
+
try {
|
|
20844
|
+
envelope = JSON.parse(stdout);
|
|
20845
|
+
} catch {
|
|
20846
|
+
throw new Error(stderr.trim() || `${command} did not return a valid report`);
|
|
20847
|
+
}
|
|
20848
|
+
if (envelope.data === null) {
|
|
20849
|
+
throw new Error(envelope.diagnostics[0]?.message ?? `${command} could not inspect this computer`);
|
|
20850
|
+
}
|
|
20851
|
+
return { exitCode, data: envelope.data };
|
|
20852
|
+
}
|
|
20853
|
+
async function collectDashboard(baseOptions) {
|
|
20854
|
+
const [doctor, status, budget, optimize] = await Promise.all([
|
|
20855
|
+
readJsonReport("doctor", baseOptions),
|
|
20856
|
+
readJsonReport("status", baseOptions),
|
|
20857
|
+
readJsonReport("budget", baseOptions),
|
|
20858
|
+
readJsonReport("optimize", baseOptions)
|
|
20859
|
+
]);
|
|
20860
|
+
return buildDashboardModel({
|
|
20861
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
20862
|
+
doctor: doctor.data,
|
|
20863
|
+
status: status.data,
|
|
20864
|
+
budget: budget.data,
|
|
20865
|
+
optimize: optimize.data
|
|
20866
|
+
});
|
|
20867
|
+
}
|
|
20868
|
+
async function openDashboard(url, baseOptions) {
|
|
20869
|
+
const adapters = baseOptions.adapters;
|
|
20870
|
+
const platform = baseOptions.platform;
|
|
20871
|
+
if (adapters === null || adapters === void 0 || platform === null)
|
|
20872
|
+
return false;
|
|
20873
|
+
const request = platform.os === "windows" ? { executable: "rundll32.exe", args: ["url.dll,FileProtocolHandler", url] } : platform.os === "macos" ? { executable: "open", args: [url] } : { executable: "xdg-open", args: [url] };
|
|
20874
|
+
const result2 = await adapters.runner.run({
|
|
20875
|
+
...request,
|
|
20876
|
+
cwd: baseOptions.cwd,
|
|
20877
|
+
env: Object.fromEntries(["DISPLAY", "WAYLAND_DISPLAY", "XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS"].flatMap((name) => process5.env[name] === void 0 ? [] : [[name, process5.env[name]]])),
|
|
20878
|
+
timeoutMs: 5e3,
|
|
20879
|
+
maxOutputBytes: 4096
|
|
20880
|
+
});
|
|
20881
|
+
return result2.failure === null && result2.exitCode === 0;
|
|
20882
|
+
}
|
|
20883
|
+
async function runUi(options, baseOptions) {
|
|
20884
|
+
let initial;
|
|
20885
|
+
try {
|
|
20886
|
+
initial = await collectDashboard(baseOptions);
|
|
20887
|
+
} catch (error) {
|
|
20888
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
20889
|
+
if (options.json) {
|
|
20890
|
+
process5.stdout.write(serializeEnvelope(toEnvelope(commandResult({
|
|
20891
|
+
command: "ui",
|
|
20892
|
+
exitCode: EXIT_CODES["unsupported-environment"],
|
|
20893
|
+
diagnostics: [
|
|
20894
|
+
diagnostic({
|
|
20895
|
+
severity: "error",
|
|
20896
|
+
code: "dashboard-unavailable",
|
|
20897
|
+
message,
|
|
20898
|
+
remediation: "Run token-harness doctor --verbose"
|
|
20899
|
+
})
|
|
20900
|
+
]
|
|
20901
|
+
}), TOOL_VERSION)));
|
|
20902
|
+
} else {
|
|
20903
|
+
process5.stderr.write(`Token Harness dashboard could not start: ${message}
|
|
20904
|
+
`);
|
|
20905
|
+
}
|
|
20906
|
+
return EXIT_CODES["unsupported-environment"];
|
|
20907
|
+
}
|
|
20908
|
+
if (options.json) {
|
|
20909
|
+
const exitCode = initial.state === "action-needed" ? EXIT_CODES["problems-found"] : EXIT_CODES.ok;
|
|
20910
|
+
process5.stdout.write(serializeEnvelope(toEnvelope(commandResult({ command: "ui", exitCode, data: initial }), TOOL_VERSION)));
|
|
20911
|
+
return exitCode;
|
|
20912
|
+
}
|
|
20913
|
+
let cached = initial;
|
|
20914
|
+
let cachedAt = Date.now();
|
|
20915
|
+
const server = createServer(async (request, response) => {
|
|
20916
|
+
const host = request.headers.host ?? "";
|
|
20917
|
+
const sameSite = request.headers["sec-fetch-site"] !== "cross-site";
|
|
20918
|
+
const localHost = host.startsWith("127.0.0.1:") || host.startsWith("localhost:");
|
|
20919
|
+
if (!sameSite || !localHost) {
|
|
20920
|
+
response.writeHead(403, { ...UI_SECURITY_HEADERS, "Content-Type": "text/plain" });
|
|
20921
|
+
response.end("Forbidden\n");
|
|
20922
|
+
return;
|
|
20923
|
+
}
|
|
20924
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
20925
|
+
response.writeHead(405, {
|
|
20926
|
+
...UI_SECURITY_HEADERS,
|
|
20927
|
+
Allow: "GET, HEAD",
|
|
20928
|
+
"Content-Type": "text/plain"
|
|
20929
|
+
});
|
|
20930
|
+
response.end("Method not allowed\n");
|
|
20931
|
+
return;
|
|
20932
|
+
}
|
|
20933
|
+
let model = cached;
|
|
20934
|
+
if (request.url === "/api/status") {
|
|
20935
|
+
if (Date.now() - cachedAt > 5e3) {
|
|
20936
|
+
try {
|
|
20937
|
+
cached = await collectDashboard(baseOptions);
|
|
20938
|
+
cachedAt = Date.now();
|
|
20939
|
+
model = cached;
|
|
20940
|
+
} catch {
|
|
20941
|
+
response.writeHead(503, {
|
|
20942
|
+
...UI_SECURITY_HEADERS,
|
|
20943
|
+
"Content-Type": "application/json; charset=utf-8"
|
|
20944
|
+
});
|
|
20945
|
+
response.end('{"error":"Dashboard data is temporarily unavailable"}');
|
|
20946
|
+
return;
|
|
20947
|
+
}
|
|
20948
|
+
}
|
|
20949
|
+
}
|
|
20950
|
+
const asset = uiAsset(request.url ?? "/", model);
|
|
20951
|
+
response.writeHead(asset.status, {
|
|
20952
|
+
...UI_SECURITY_HEADERS,
|
|
20953
|
+
"Content-Type": asset.contentType
|
|
20954
|
+
});
|
|
20955
|
+
response.end(request.method === "HEAD" ? void 0 : asset.body);
|
|
20956
|
+
});
|
|
20957
|
+
try {
|
|
20958
|
+
await new Promise((resolve, reject) => {
|
|
20959
|
+
server.once("error", reject);
|
|
20960
|
+
server.listen(options.port, "127.0.0.1", () => resolve());
|
|
20961
|
+
});
|
|
20962
|
+
} catch (error) {
|
|
20963
|
+
process5.stderr.write(`Token Harness dashboard could not listen locally: ${error instanceof Error ? error.message : String(error)}
|
|
20964
|
+
`);
|
|
20965
|
+
return EXIT_CODES["internal-error"];
|
|
20966
|
+
}
|
|
20967
|
+
const address = server.address();
|
|
20968
|
+
const port = typeof address === "object" && address !== null ? address.port : options.port;
|
|
20969
|
+
const url = `http://127.0.0.1:${port}/`;
|
|
20970
|
+
process5.stdout.write(`Token Harness dashboard is ready: ${url}
|
|
20971
|
+
Close it with Ctrl+C.
|
|
20972
|
+
`);
|
|
20973
|
+
if (options.open && !await openDashboard(url, baseOptions)) {
|
|
20974
|
+
process5.stdout.write(`Open this address in your browser: ${url}
|
|
20975
|
+
`);
|
|
20976
|
+
}
|
|
20977
|
+
return EXIT_CODES.ok;
|
|
20978
|
+
}
|
|
20979
|
+
var UI_SECURITY_HEADERS;
|
|
19878
20980
|
var init_main = __esm({
|
|
19879
20981
|
"apps/cli/dist/src/main.js"() {
|
|
19880
20982
|
"use strict";
|
|
19881
20983
|
init_src();
|
|
19882
20984
|
init_src2();
|
|
19883
20985
|
init_run();
|
|
20986
|
+
init_ui();
|
|
20987
|
+
init_version2();
|
|
20988
|
+
UI_SECURITY_HEADERS = {
|
|
20989
|
+
"Cache-Control": "no-store",
|
|
20990
|
+
"Content-Security-Policy": "default-src 'self'; script-src 'self'; style-src 'self'; connect-src 'self'; img-src 'self' data:; object-src 'none'; base-uri 'none'; frame-ancestors 'none'",
|
|
20991
|
+
"Referrer-Policy": "no-referrer",
|
|
20992
|
+
"X-Content-Type-Options": "nosniff"
|
|
20993
|
+
};
|
|
19884
20994
|
}
|
|
19885
20995
|
});
|
|
19886
20996
|
|