token-harness 0.1.6 → 0.1.7
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 +154 -735
- package/package.json +1 -1
- package/sbom.json +3 -3
- package/token-harness.mjs +1431 -466
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.7";
|
|
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
|
|
|
@@ -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,118 +17444,484 @@ 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
|
|
17412
|
-
}
|
|
17413
|
-
function upgradeAction(input) {
|
|
17414
|
-
const digest = digestText(`${input.providerId} update ${input.channel} ${input.target}`);
|
|
17415
|
-
return {
|
|
17416
|
-
kind: "package-manager-install",
|
|
17417
|
-
id: digest.slice(digest.indexOf(":") + 1, digest.indexOf(":") + 9),
|
|
17418
|
-
// The same class the install action uses, for the same reason: an installed package is not
|
|
17419
|
-
// reversed by restoring a file.
|
|
17420
|
-
riskClass: "delegated",
|
|
17421
|
-
requiresNetwork: input.requiresNetwork,
|
|
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
|
-
};
|
|
17567
|
+
return managed;
|
|
17447
17568
|
}
|
|
17448
|
-
async function
|
|
17449
|
-
const
|
|
17450
|
-
|
|
17451
|
-
|
|
17452
|
-
|
|
17453
|
-
|
|
17454
|
-
|
|
17455
|
-
|
|
17456
|
-
data: statusForExitCode(exitCode) === "error" ? null : data,
|
|
17457
|
-
diagnostics
|
|
17458
|
-
});
|
|
17459
|
-
if (context.adapters === null) {
|
|
17460
|
-
diagnostics.push(diagnostic({
|
|
17461
|
-
severity: "error",
|
|
17462
|
-
code: "unsupported-environment",
|
|
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);
|
|
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 [];
|
|
17467
17577
|
}
|
|
17468
|
-
|
|
17469
|
-
|
|
17470
|
-
const
|
|
17471
|
-
|
|
17472
|
-
|
|
17473
|
-
const
|
|
17474
|
-
|
|
17475
|
-
|
|
17476
|
-
|
|
17477
|
-
|
|
17578
|
+
}
|
|
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();
|
|
17594
|
+
}
|
|
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
|
+
if (doctor.exitCode !== EXIT_CODES.ok || baseDoctor.problemCount > 0) {
|
|
17640
|
+
return commandResult({
|
|
17641
|
+
command: "setup",
|
|
17642
|
+
exitCode: EXIT_CODES["problems-found"],
|
|
17643
|
+
data: {
|
|
17644
|
+
stage: "attention",
|
|
17645
|
+
changed: false,
|
|
17646
|
+
doctor: baseDoctor,
|
|
17647
|
+
plan: null,
|
|
17648
|
+
apply: null,
|
|
17649
|
+
verify: null,
|
|
17650
|
+
budget: null,
|
|
17651
|
+
nextStep: {
|
|
17652
|
+
command: "token-harness doctor --verbose",
|
|
17653
|
+
description: "Review the detected problem before changing configuration."
|
|
17654
|
+
}
|
|
17655
|
+
},
|
|
17656
|
+
diagnostics: doctor.diagnostics
|
|
17657
|
+
});
|
|
17658
|
+
}
|
|
17659
|
+
const presentIds = new Set(detectedHarnesses.map((harness) => harness.harnessId));
|
|
17660
|
+
const hasActiveProvider = baseDoctor.providers.some((provider) => provider.state === "configured" && provider.configuredHarnesses.some((harness) => presentIds.has(harness)));
|
|
17661
|
+
if (hasActiveProvider) {
|
|
17662
|
+
const activeHarness = context.harness ?? detectedHarnesses.find((harness) => baseDoctor.providers.some((provider) => provider.configuredHarnesses.includes(harness.harnessId)))?.harnessId ?? null;
|
|
17663
|
+
const observationContext = { ...context, harness: activeHarness };
|
|
17664
|
+
const [verify9, budget2] = await Promise.all([
|
|
17665
|
+
operations.verify(observationContext),
|
|
17666
|
+
operations.budget(observationContext)
|
|
17667
|
+
]);
|
|
17668
|
+
const healthy2 = verify9.data?.healthyAtDeclaredTier === true;
|
|
17669
|
+
return commandResult({
|
|
17670
|
+
command: "setup",
|
|
17671
|
+
exitCode: healthy2 ? EXIT_CODES.ok : EXIT_CODES["problems-found"],
|
|
17672
|
+
data: {
|
|
17673
|
+
stage: healthy2 ? "ready" : "attention",
|
|
17674
|
+
changed: false,
|
|
17675
|
+
doctor: baseDoctor,
|
|
17676
|
+
plan: null,
|
|
17677
|
+
apply: null,
|
|
17678
|
+
verify: verify9.data,
|
|
17679
|
+
budget: budget2.data,
|
|
17680
|
+
nextStep: healthy2 ? {
|
|
17681
|
+
command: "token-harness ui",
|
|
17682
|
+
description: "Open the dashboard to see status, allowance, and advice."
|
|
17683
|
+
} : {
|
|
17684
|
+
command: "token-harness verify --verbose",
|
|
17685
|
+
description: "Review the failed integration check."
|
|
17686
|
+
}
|
|
17687
|
+
},
|
|
17688
|
+
diagnostics: uniqueDiagnostics([doctor.diagnostics, verify9.diagnostics, budget2.diagnostics])
|
|
17689
|
+
});
|
|
17690
|
+
}
|
|
17691
|
+
const preferredHarness = context.harness ?? detectedHarnesses.find((harness) => harness.harnessId === "codex")?.harnessId ?? detectedHarnesses[0]?.harnessId ?? null;
|
|
17692
|
+
const setupContext = { ...context, harness: preferredHarness };
|
|
17693
|
+
const plan3 = await operations.plan(setupContext);
|
|
17694
|
+
if (plan3.data === null || plan3.exitCode !== EXIT_CODES.ok || plan3.data.actions.length === 0 || !plan3.data.persisted) {
|
|
17695
|
+
return commandResult({
|
|
17696
|
+
command: "setup",
|
|
17697
|
+
exitCode: plan3.exitCode === EXIT_CODES.ok ? EXIT_CODES["problems-found"] : plan3.exitCode,
|
|
17698
|
+
data: {
|
|
17699
|
+
stage: "attention",
|
|
17700
|
+
changed: false,
|
|
17701
|
+
doctor: baseDoctor,
|
|
17702
|
+
plan: plan3.data,
|
|
17703
|
+
apply: null,
|
|
17704
|
+
verify: null,
|
|
17705
|
+
budget: null,
|
|
17706
|
+
nextStep: {
|
|
17707
|
+
command: "token-harness plan --verbose",
|
|
17708
|
+
description: "Review why no safe automatic configuration is available."
|
|
17709
|
+
}
|
|
17710
|
+
},
|
|
17711
|
+
diagnostics: uniqueDiagnostics([doctor.diagnostics, plan3.diagnostics])
|
|
17712
|
+
});
|
|
17713
|
+
}
|
|
17714
|
+
if (!context.confirmed) {
|
|
17715
|
+
return commandResult({
|
|
17716
|
+
command: "setup",
|
|
17717
|
+
exitCode: EXIT_CODES.ok,
|
|
17718
|
+
data: {
|
|
17719
|
+
stage: "ready-to-configure",
|
|
17720
|
+
changed: false,
|
|
17721
|
+
doctor: baseDoctor,
|
|
17722
|
+
plan: plan3.data,
|
|
17723
|
+
apply: null,
|
|
17724
|
+
verify: null,
|
|
17725
|
+
budget: null,
|
|
17726
|
+
nextStep: {
|
|
17727
|
+
command: "token-harness setup --yes",
|
|
17728
|
+
description: "Apply the reviewed, reversible configuration."
|
|
17729
|
+
}
|
|
17730
|
+
},
|
|
17731
|
+
diagnostics: uniqueDiagnostics([doctor.diagnostics, plan3.diagnostics])
|
|
17732
|
+
});
|
|
17733
|
+
}
|
|
17734
|
+
const applied = await operations.apply({
|
|
17735
|
+
...setupContext,
|
|
17736
|
+
planId: plan3.data.planId,
|
|
17737
|
+
confirmed: true
|
|
17738
|
+
});
|
|
17739
|
+
if (applied.data?.outcome !== "committed" && applied.data?.outcome !== "nothing-to-do") {
|
|
17740
|
+
return commandResult({
|
|
17741
|
+
command: "setup",
|
|
17742
|
+
exitCode: applied.exitCode,
|
|
17743
|
+
data: {
|
|
17744
|
+
stage: "attention",
|
|
17745
|
+
changed: false,
|
|
17746
|
+
doctor: baseDoctor,
|
|
17747
|
+
plan: plan3.data,
|
|
17748
|
+
apply: applied.data,
|
|
17749
|
+
verify: null,
|
|
17750
|
+
budget: null,
|
|
17751
|
+
nextStep: {
|
|
17752
|
+
command: "token-harness verify --verbose",
|
|
17753
|
+
description: "Review the configuration result before continuing."
|
|
17754
|
+
}
|
|
17755
|
+
},
|
|
17756
|
+
diagnostics: uniqueDiagnostics([doctor.diagnostics, plan3.diagnostics, applied.diagnostics])
|
|
17757
|
+
});
|
|
17758
|
+
}
|
|
17759
|
+
const [verify8, budget] = await Promise.all([
|
|
17760
|
+
operations.verify(setupContext),
|
|
17761
|
+
operations.budget(setupContext)
|
|
17762
|
+
]);
|
|
17763
|
+
const healthy = verify8.data?.healthyAtDeclaredTier === true;
|
|
17764
|
+
const changed = applied.data?.results.some((result2) => result2.status === "applied") === true;
|
|
17765
|
+
return commandResult({
|
|
17766
|
+
command: "setup",
|
|
17767
|
+
exitCode: healthy ? EXIT_CODES.ok : EXIT_CODES["problems-found"],
|
|
17768
|
+
data: {
|
|
17769
|
+
stage: healthy ? "ready" : "attention",
|
|
17770
|
+
changed,
|
|
17771
|
+
doctor: baseDoctor,
|
|
17772
|
+
plan: plan3.data,
|
|
17773
|
+
apply: applied.data,
|
|
17774
|
+
verify: verify8.data,
|
|
17775
|
+
budget: budget.data,
|
|
17776
|
+
nextStep: healthy ? {
|
|
17777
|
+
command: "token-harness ui",
|
|
17778
|
+
description: "Open the dashboard to see status, allowance, and advice."
|
|
17779
|
+
} : {
|
|
17780
|
+
command: "token-harness verify --verbose",
|
|
17781
|
+
description: "Review the failed integration check."
|
|
17782
|
+
}
|
|
17783
|
+
},
|
|
17784
|
+
diagnostics: uniqueDiagnostics([
|
|
17785
|
+
doctor.diagnostics,
|
|
17786
|
+
plan3.diagnostics,
|
|
17787
|
+
applied.diagnostics,
|
|
17788
|
+
verify8.diagnostics,
|
|
17789
|
+
budget.diagnostics
|
|
17790
|
+
])
|
|
17791
|
+
});
|
|
17792
|
+
}
|
|
17793
|
+
var DEFAULT_OPERATIONS;
|
|
17794
|
+
var init_setup2 = __esm({
|
|
17795
|
+
"apps/cli/dist/src/commands/setup.js"() {
|
|
17796
|
+
"use strict";
|
|
17797
|
+
init_src();
|
|
17798
|
+
init_apply();
|
|
17799
|
+
init_budget2();
|
|
17800
|
+
init_doctor();
|
|
17801
|
+
init_plan2();
|
|
17802
|
+
init_verify();
|
|
17803
|
+
DEFAULT_OPERATIONS = {
|
|
17804
|
+
doctor: runDoctor,
|
|
17805
|
+
plan: runPlan,
|
|
17806
|
+
apply: runApply,
|
|
17807
|
+
verify: runVerify,
|
|
17808
|
+
budget: runBudget
|
|
17809
|
+
};
|
|
17810
|
+
}
|
|
17811
|
+
});
|
|
17812
|
+
|
|
17813
|
+
// apps/cli/dist/src/commands/update.js
|
|
17814
|
+
function transactionIdFor2(seed, at) {
|
|
17815
|
+
const digest = digestText(`${seed} ${at}`);
|
|
17816
|
+
return digest.slice(digest.indexOf(":") + 1, digest.indexOf(":") + 13);
|
|
17817
|
+
}
|
|
17818
|
+
function emptyExecution(outcome2) {
|
|
17819
|
+
return {
|
|
17820
|
+
planId: null,
|
|
17821
|
+
transactionId: null,
|
|
17822
|
+
fromStoredPlan: false,
|
|
17823
|
+
outcome: outcome2,
|
|
17824
|
+
results: [],
|
|
17825
|
+
unrestored: [],
|
|
17826
|
+
receiptId: null
|
|
17827
|
+
};
|
|
17828
|
+
}
|
|
17829
|
+
async function managedIntegrations(context) {
|
|
17830
|
+
const empty2 = { integrations: [], legacyOwnershipUnknown: false };
|
|
17831
|
+
if (context.adapters === null || context.stateRoot === null)
|
|
17832
|
+
return empty2;
|
|
17833
|
+
const journalRoot = context.adapters.fs.join(context.stateRoot, "journals");
|
|
17834
|
+
if (await context.adapters.fs.stat(journalRoot) === null)
|
|
17835
|
+
return empty2;
|
|
17836
|
+
const store = new FileJournalStore({
|
|
17837
|
+
fs: context.adapters.fs,
|
|
17838
|
+
journalRoot,
|
|
17839
|
+
backupRoot: context.adapters.fs.join(context.stateRoot, "backups")
|
|
17840
|
+
});
|
|
17841
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17842
|
+
const result2 = [];
|
|
17843
|
+
let legacyOwnershipUnknown = false;
|
|
17844
|
+
for (const journal of await store.list()) {
|
|
17845
|
+
if (journal.outcome !== "committed")
|
|
17846
|
+
continue;
|
|
17847
|
+
if (journal.managedIntegrations === void 0 && journal.ownership.length > 0) {
|
|
17848
|
+
legacyOwnershipUnknown = true;
|
|
17849
|
+
}
|
|
17850
|
+
for (const integration of journal.managedIntegrations ?? []) {
|
|
17851
|
+
const key = `${integration.providerId}\0${integration.harnessId}`;
|
|
17852
|
+
if (seen.has(key))
|
|
17853
|
+
continue;
|
|
17854
|
+
seen.add(key);
|
|
17855
|
+
result2.push(integration);
|
|
17856
|
+
}
|
|
17857
|
+
}
|
|
17858
|
+
return { integrations: result2, legacyOwnershipUnknown };
|
|
17859
|
+
}
|
|
17860
|
+
function upgradeAction(input) {
|
|
17861
|
+
const digest = digestText(`${input.providerId} update ${input.channel} ${input.target}`);
|
|
17862
|
+
return {
|
|
17863
|
+
kind: "package-manager-install",
|
|
17864
|
+
id: digest.slice(digest.indexOf(":") + 1, digest.indexOf(":") + 9),
|
|
17865
|
+
// The same class the install action uses, for the same reason: an installed package is not
|
|
17866
|
+
// reversed by restoring a file.
|
|
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
|
+
/**
|
|
17878
|
+
* `package-inventory` where the channel can report what is installed, `none` otherwise.
|
|
17879
|
+
*
|
|
17880
|
+
* An update replaces a binary. Rolling the transaction back restores files and leaves the new
|
|
17881
|
+
* version in place, so the executor's receipt is not boilerplate here — it is the difference
|
|
17882
|
+
* between the machine being restored and the *configuration* being restored. With an
|
|
17883
|
+
* inventory-capturing channel the rollback also reinstalls the previous version, and the
|
|
17884
|
+
* receipt says per package whether that reinstall took.
|
|
17885
|
+
*/
|
|
17886
|
+
rollbackData: channelCanReportInventory(input.channel) ? "package-inventory" : "none",
|
|
17887
|
+
explanation: `Update ${input.packageName} from ${input.installed} to ${input.target} through ${input.channel}`,
|
|
17888
|
+
packageManager: input.channel,
|
|
17889
|
+
packageName: input.packageName,
|
|
17890
|
+
// Pinned to the exact version the channel reported, not left open. An unpinned upgrade would
|
|
17891
|
+
// install whatever is newest at execution time, which is not the version the dry run showed.
|
|
17892
|
+
version: input.target
|
|
17893
|
+
};
|
|
17894
|
+
}
|
|
17895
|
+
async function runUpdate(context) {
|
|
17896
|
+
const diagnostics = [];
|
|
17897
|
+
const report = { providers: [], network: [], execution: null };
|
|
17898
|
+
const finish3 = (exitCode, data) => commandResult({
|
|
17899
|
+
command: "update",
|
|
17900
|
+
exitCode,
|
|
17901
|
+
// RFC 0006: `data` is null when the status is `error`, and the human renderer must read the
|
|
17902
|
+
// same object it serializes — the defect `apply` already had to fix.
|
|
17903
|
+
data: statusForExitCode(exitCode) === "error" ? null : data,
|
|
17904
|
+
diagnostics
|
|
17905
|
+
});
|
|
17906
|
+
if (context.adapters === null) {
|
|
17907
|
+
diagnostics.push(diagnostic({
|
|
17908
|
+
severity: "error",
|
|
17909
|
+
code: "unsupported-environment",
|
|
17910
|
+
message: "No platform adapters are available, so no channel can be consulted",
|
|
17911
|
+
remediation: null
|
|
17912
|
+
}));
|
|
17913
|
+
return finish3(EXIT_CODES["unsupported-environment"], null);
|
|
17914
|
+
}
|
|
17915
|
+
const adapters = context.adapters;
|
|
17916
|
+
const providerAdapters = listProviderAdapters().filter((adapter) => context.provider === null || adapter.manifest.id === context.provider);
|
|
17917
|
+
const managedState = await managedIntegrations(context);
|
|
17918
|
+
const managed = managedState.integrations;
|
|
17919
|
+
const managedHarnessIds = new Set(managed.map((entry) => entry.harnessId));
|
|
17920
|
+
const harnessVersions = /* @__PURE__ */ new Map();
|
|
17921
|
+
if (managedHarnessIds.size > 0) {
|
|
17922
|
+
const harnessContext = {
|
|
17923
|
+
fs: adapters.fs,
|
|
17924
|
+
runner: adapters.runner,
|
|
17478
17925
|
facts: context.platform,
|
|
17479
17926
|
paths: adapters.paths,
|
|
17480
17927
|
projectRoot: context.projectRoot
|
|
@@ -17654,210 +18101,60 @@ async function runUpdate(context) {
|
|
|
17654
18101
|
}));
|
|
17655
18102
|
return finish3(EXIT_CODES["unsupported-environment"], null);
|
|
17656
18103
|
}
|
|
17657
|
-
const fs = adapters.fs;
|
|
17658
|
-
const startedAt = context.now();
|
|
17659
|
-
const transactionId = transactionIdFor2(actions.map((action) => action.id).join(" "), startedAt);
|
|
17660
|
-
const creation = TransactionSnapshotStore.create({
|
|
17661
|
-
fs,
|
|
17662
|
-
backupRoot: fs.join(context.stateRoot, "backups"),
|
|
17663
|
-
transactionId,
|
|
17664
|
-
projectRoot: context.projectRoot,
|
|
17665
|
-
now: context.now
|
|
17666
|
-
});
|
|
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 [];
|
|
18104
|
+
const fs = adapters.fs;
|
|
18105
|
+
const startedAt = context.now();
|
|
18106
|
+
const transactionId = transactionIdFor2(actions.map((action) => action.id).join(" "), startedAt);
|
|
18107
|
+
const creation = TransactionSnapshotStore.create({
|
|
18108
|
+
fs,
|
|
18109
|
+
backupRoot: fs.join(context.stateRoot, "backups"),
|
|
18110
|
+
transactionId,
|
|
18111
|
+
projectRoot: context.projectRoot,
|
|
18112
|
+
now: context.now
|
|
18113
|
+
});
|
|
18114
|
+
if (!creation.ok) {
|
|
18115
|
+
diagnostics.push(...creation.diagnostics);
|
|
18116
|
+
return finish3(EXIT_CODES["unsupported-environment"], null);
|
|
17844
18117
|
}
|
|
18118
|
+
const transaction = await executeTransaction({
|
|
18119
|
+
transactionId,
|
|
18120
|
+
planId: null,
|
|
18121
|
+
projectId: adapters.projectIdFor(context.projectRoot),
|
|
18122
|
+
projectRoot: context.projectRoot,
|
|
18123
|
+
actions,
|
|
18124
|
+
fs,
|
|
18125
|
+
snapshots: creation.store,
|
|
18126
|
+
journal: new FileJournalStore({
|
|
18127
|
+
fs,
|
|
18128
|
+
journalRoot: fs.join(context.stateRoot, "journals"),
|
|
18129
|
+
backupRoot: fs.join(context.stateRoot, "backups")
|
|
18130
|
+
}),
|
|
18131
|
+
runner: adapters.runner,
|
|
18132
|
+
now: context.now
|
|
18133
|
+
});
|
|
18134
|
+
diagnostics.push(...transaction.diagnostics);
|
|
18135
|
+
report.execution = {
|
|
18136
|
+
planId: null,
|
|
18137
|
+
transactionId,
|
|
18138
|
+
fromStoredPlan: false,
|
|
18139
|
+
// Mapped the way `apply` maps it: `in-progress` is not a terminal outcome a report may
|
|
18140
|
+
// carry, and anything that is not one of the three known ends is a rejection.
|
|
18141
|
+
outcome: transaction.journal.outcome === "committed" ? "committed" : transaction.journal.outcome === "rolled-back" ? "rolled-back" : transaction.journal.outcome === "dirty" ? "dirty" : "rejected",
|
|
18142
|
+
results: transaction.journal.entries.map((entry) => ({
|
|
18143
|
+
actionId: entry.actionId,
|
|
18144
|
+
kind: entry.kind,
|
|
18145
|
+
status: entry.status,
|
|
18146
|
+
path: null
|
|
18147
|
+
})),
|
|
18148
|
+
unrestored: transaction.unrestored,
|
|
18149
|
+
receiptId: transaction.journal.outcome === "committed" ? transactionId : null
|
|
18150
|
+
};
|
|
18151
|
+
return finish3(transaction.exitCode, report);
|
|
17845
18152
|
}
|
|
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"() {
|
|
18153
|
+
var init_update = __esm({
|
|
18154
|
+
"apps/cli/dist/src/commands/update.js"() {
|
|
17858
18155
|
"use strict";
|
|
17859
|
-
init_src3();
|
|
17860
18156
|
init_src();
|
|
18157
|
+
init_src3();
|
|
17861
18158
|
}
|
|
17862
18159
|
});
|
|
17863
18160
|
|
|
@@ -18430,9 +18727,11 @@ function renderDoctorReport(report, context) {
|
|
|
18430
18727
|
lines.push(...notable);
|
|
18431
18728
|
}
|
|
18432
18729
|
const unwired = report.providers.filter((provider) => provider.state !== "absent" && provider.configuredHarnesses.length === 0);
|
|
18730
|
+
const installedProviders = report.providers.some((provider) => provider.state !== "absent");
|
|
18433
18731
|
lines.push("");
|
|
18434
18732
|
lines.push("NEXT");
|
|
18435
18733
|
const suggestions = report.providers.every((provider) => provider.state === "absent") || unwired.length > 0 ? [["token-harness plan", "see what would change \u2014 writes nothing"]] : [
|
|
18734
|
+
...installedProviders ? [["token-harness update", "check RTK/HarnessTrim for newer versions"]] : [],
|
|
18436
18735
|
["token-harness verify", "check the pipeline actually intercepts"],
|
|
18437
18736
|
["token-harness metrics --since 7d", "see what it saved"]
|
|
18438
18737
|
];
|
|
@@ -19096,6 +19395,316 @@ var init_verify2 = __esm({
|
|
|
19096
19395
|
}
|
|
19097
19396
|
});
|
|
19098
19397
|
|
|
19398
|
+
// apps/cli/dist/src/render/simple.js
|
|
19399
|
+
function title(state) {
|
|
19400
|
+
return [`TOKEN HARNESS - ${state.toUpperCase()}`, ""];
|
|
19401
|
+
}
|
|
19402
|
+
function next(command, description) {
|
|
19403
|
+
return [
|
|
19404
|
+
"",
|
|
19405
|
+
"NEXT STEP",
|
|
19406
|
+
command === null ? ` ${truncate(description, MAX_WIDTH - 2)}` : ` ${command}`,
|
|
19407
|
+
...command === null ? [] : [` ${truncate(description, MAX_WIDTH - 2)}`]
|
|
19408
|
+
];
|
|
19409
|
+
}
|
|
19410
|
+
function changeLine(changed, detail2) {
|
|
19411
|
+
return [
|
|
19412
|
+
"",
|
|
19413
|
+
"CHANGES",
|
|
19414
|
+
` ${changed ? detail2 ?? "Configuration changed." : "Nothing changed."}`
|
|
19415
|
+
];
|
|
19416
|
+
}
|
|
19417
|
+
function harnessName(id) {
|
|
19418
|
+
if (id === "claude")
|
|
19419
|
+
return "Claude Code";
|
|
19420
|
+
if (id === "codex")
|
|
19421
|
+
return "Codex";
|
|
19422
|
+
if (id === "opencode")
|
|
19423
|
+
return "OpenCode";
|
|
19424
|
+
return id;
|
|
19425
|
+
}
|
|
19426
|
+
function renderSimpleDoctor(report) {
|
|
19427
|
+
const present = report.harnesses.filter((item) => item.state !== "absent");
|
|
19428
|
+
const active = report.providers.filter((item) => item.state === "configured" && item.configuredHarnesses.length > 0);
|
|
19429
|
+
const state = report.problemCount > 0 ? "attention needed" : present.length > 0 ? "ready" : "setup needed";
|
|
19430
|
+
const lines = [...title(state), "WHAT WORKS"];
|
|
19431
|
+
if (present.length === 0)
|
|
19432
|
+
lines.push(" No supported coding harness was found.");
|
|
19433
|
+
for (const item of report.harnesses) {
|
|
19434
|
+
const stateText = item.state === "absent" ? "not found" : item.state;
|
|
19435
|
+
lines.push(` ${harnessName(item.harnessId)}: ${stateText}${item.version ? ` (${item.version})` : ""}`);
|
|
19436
|
+
}
|
|
19437
|
+
if (report.providers.length === 0)
|
|
19438
|
+
lines.push(" Providers: none detected");
|
|
19439
|
+
for (const item of report.providers) {
|
|
19440
|
+
const connected = item.configuredHarnesses.map(harnessName).join(", ");
|
|
19441
|
+
lines.push(truncate(` ${item.providerId}: ${connected === "" ? item.state : `active on ${connected}`}`, MAX_WIDTH));
|
|
19442
|
+
}
|
|
19443
|
+
lines.push(...changeLine(false));
|
|
19444
|
+
if (report.problemCount > 0) {
|
|
19445
|
+
lines.push(...next("token-harness doctor --verbose", "Review the technical findings."));
|
|
19446
|
+
} else if (present.length === 0 || active.length === 0) {
|
|
19447
|
+
lines.push(...next("token-harness setup", "Finish the guided setup."));
|
|
19448
|
+
} else {
|
|
19449
|
+
lines.push(...next("token-harness ui", "Open the dashboard."));
|
|
19450
|
+
}
|
|
19451
|
+
return document(lines);
|
|
19452
|
+
}
|
|
19453
|
+
function renderSimpleSetup(report, context) {
|
|
19454
|
+
const state = report.stage === "ready" ? "ready" : report.stage === "attention" ? "attention needed" : "setup needed";
|
|
19455
|
+
const lines = [...title(state), "DETECTED"];
|
|
19456
|
+
const harnesses = report.doctor.harnesses.filter((item) => item.state !== "absent");
|
|
19457
|
+
if (harnesses.length === 0)
|
|
19458
|
+
lines.push(" Claude Code/Codex: not found");
|
|
19459
|
+
for (const item of harnesses) {
|
|
19460
|
+
lines.push(` ${harnessName(item.harnessId)}: ${item.state}${item.version ? ` (${item.version})` : ""}`);
|
|
19461
|
+
}
|
|
19462
|
+
const active = report.doctor.providers.filter((item) => item.configuredHarnesses.length > 0);
|
|
19463
|
+
if (active.length === 0)
|
|
19464
|
+
lines.push(" Optimization provider: not active");
|
|
19465
|
+
for (const provider of active) {
|
|
19466
|
+
lines.push(truncate(` ${provider.providerId}: active on ${provider.configuredHarnesses.map(harnessName).join(", ")}`, MAX_WIDTH));
|
|
19467
|
+
}
|
|
19468
|
+
if (report.plan !== null && report.apply === null && report.plan.actions.length > 0) {
|
|
19469
|
+
lines.push("", "SAFE PLAN");
|
|
19470
|
+
for (const action of report.plan.actions) {
|
|
19471
|
+
const path = primaryActionPath(action);
|
|
19472
|
+
lines.push(truncate(` ${actionLabel(action.kind)}${path === null ? "" : ` - ${displayPath(path, context.home)}`}`, MAX_WIDTH));
|
|
19473
|
+
}
|
|
19474
|
+
}
|
|
19475
|
+
lines.push(...changeLine(report.changed, report.apply?.results.some((item) => item.status === "applied") ? "Safe configuration applied and checked." : void 0));
|
|
19476
|
+
lines.push(...next(report.nextStep.command, report.nextStep.description));
|
|
19477
|
+
return document(lines);
|
|
19478
|
+
}
|
|
19479
|
+
function renderVerboseSetup(report, context) {
|
|
19480
|
+
const lines = ["SETUP TECHNICAL DETAILS", "", "DETECTION"];
|
|
19481
|
+
for (const harness of report.doctor.harnesses) {
|
|
19482
|
+
lines.push(truncate(` ${harness.harnessId}: state ${harness.state}, version ${harness.version ?? "unknown"}, verdict ${harness.versionVerdict ?? "unknown"}`, MAX_WIDTH));
|
|
19483
|
+
if (harness.configPath !== null)
|
|
19484
|
+
lines.push(truncate(` config ${displayPath(harness.configPath, context.home)}`, MAX_WIDTH));
|
|
19485
|
+
}
|
|
19486
|
+
for (const provider of report.doctor.providers) {
|
|
19487
|
+
lines.push(truncate(` ${provider.providerId}: state ${provider.state}, version ${provider.version ?? "unknown"}, wired ${provider.configuredHarnesses.join(", ") || "none"}`, MAX_WIDTH));
|
|
19488
|
+
}
|
|
19489
|
+
if (report.plan !== null) {
|
|
19490
|
+
lines.push("", `PLAN ${report.plan.planId ?? "not produced"}`);
|
|
19491
|
+
lines.push(` persisted: ${String(report.plan.persisted)}`);
|
|
19492
|
+
lines.push(` actions: ${report.plan.actions.length}`);
|
|
19493
|
+
lines.push(` conflicts: ${report.plan.conflicts.length}`);
|
|
19494
|
+
for (const action of report.plan.actions) {
|
|
19495
|
+
lines.push(truncate(` ${action.id}: ${action.kind} - ${action.explanation}`, MAX_WIDTH));
|
|
19496
|
+
}
|
|
19497
|
+
}
|
|
19498
|
+
if (report.apply !== null) {
|
|
19499
|
+
lines.push("", `TRANSACTION ${report.apply.transactionId ?? "none"}`);
|
|
19500
|
+
lines.push(` outcome: ${report.apply.outcome}`);
|
|
19501
|
+
for (const result2 of report.apply.results) {
|
|
19502
|
+
lines.push(truncate(` ${result2.actionId}: ${result2.status}`, MAX_WIDTH));
|
|
19503
|
+
}
|
|
19504
|
+
}
|
|
19505
|
+
if (report.verify !== null) {
|
|
19506
|
+
lines.push("", "VERIFICATION");
|
|
19507
|
+
lines.push(` healthy at declared tier: ${String(report.verify.healthyAtDeclaredTier)}`);
|
|
19508
|
+
for (const result2 of report.verify.results) {
|
|
19509
|
+
lines.push(` ${result2.providerId} on ${result2.harnessId}: ${result2.status}`);
|
|
19510
|
+
for (const check of result2.checks) {
|
|
19511
|
+
lines.push(truncate(` ${check.id}: ${check.status} - ${check.summary}`, MAX_WIDTH));
|
|
19512
|
+
}
|
|
19513
|
+
}
|
|
19514
|
+
}
|
|
19515
|
+
if (report.budget !== null) {
|
|
19516
|
+
lines.push("", "ALLOWANCE SOURCES");
|
|
19517
|
+
for (const harness of report.budget.harnesses) {
|
|
19518
|
+
if (harness.windows.length === 0)
|
|
19519
|
+
lines.push(` ${harness.harnessId}: ${harness.state}`);
|
|
19520
|
+
for (const window of harness.windows) {
|
|
19521
|
+
lines.push(truncate(` ${harness.harnessId}/${window.scope}: ${window.source}, ${window.confidence}`, MAX_WIDTH));
|
|
19522
|
+
}
|
|
19523
|
+
}
|
|
19524
|
+
}
|
|
19525
|
+
lines.push("", ...renderSimpleSetup(report, context).trimEnd().split("\n"));
|
|
19526
|
+
return document(lines);
|
|
19527
|
+
}
|
|
19528
|
+
function formatReset(resetsAt) {
|
|
19529
|
+
return resetsAt === null ? "reset unknown" : `resets ${resetsAt}`;
|
|
19530
|
+
}
|
|
19531
|
+
function renderSimpleBudget(report) {
|
|
19532
|
+
const observed = report.harnesses.filter((item) => item.state === "observed");
|
|
19533
|
+
const lines = [
|
|
19534
|
+
...title(observed.length > 0 ? "allowance available" : "allowance unavailable"),
|
|
19535
|
+
"ALLOWANCE"
|
|
19536
|
+
];
|
|
19537
|
+
for (const harness of report.harnesses) {
|
|
19538
|
+
if (harness.windows.length === 0) {
|
|
19539
|
+
lines.push(` ${harnessName(harness.harnessId)}: ${harness.state}`);
|
|
19540
|
+
continue;
|
|
19541
|
+
}
|
|
19542
|
+
for (const window of harness.windows) {
|
|
19543
|
+
const label = window.bucketName ?? window.scope;
|
|
19544
|
+
const remaining = window.remainingPercent === null ? "unknown" : `${window.remainingPercent}% left`;
|
|
19545
|
+
lines.push(truncate(` ${harnessName(harness.harnessId)} ${label}: ${remaining}, ${formatReset(window.resetsAt)}`, MAX_WIDTH));
|
|
19546
|
+
}
|
|
19547
|
+
}
|
|
19548
|
+
lines.push(...changeLine(false));
|
|
19549
|
+
lines.push(...next(observed.length > 0 ? "token-harness optimize" : "token-harness setup", observed.length > 0 ? "See the best action for the current allowance." : "Check the local installation and connections."));
|
|
19550
|
+
return document(lines);
|
|
19551
|
+
}
|
|
19552
|
+
function renderSimpleContext(report) {
|
|
19553
|
+
const lines = [...title("context checked"), "CONTEXT"];
|
|
19554
|
+
lines.push(` Instruction files: ${report.instructions.length}`);
|
|
19555
|
+
lines.push(` Known loaded instructions: ${formatCount(report.knownLoadedInstructionBytes)} bytes`);
|
|
19556
|
+
for (const harness of report.harnesses) {
|
|
19557
|
+
lines.push(truncate(` ${harnessName(harness.harnessId)}: ${harness.state}, model ${harness.model ?? "unknown"}, ${harness.mcpServers.length} MCP servers`, MAX_WIDTH));
|
|
19558
|
+
}
|
|
19559
|
+
lines.push(...changeLine(false));
|
|
19560
|
+
lines.push(...next("token-harness optimize", "Turn these observations into one recommendation."));
|
|
19561
|
+
return document(lines);
|
|
19562
|
+
}
|
|
19563
|
+
function renderSimpleMcp(report) {
|
|
19564
|
+
const attention = report.harnesses.some((harness) => harness.assessments.some((item) => item.usability === "attention"));
|
|
19565
|
+
const lines = [...title(attention ? "attention needed" : "mcp checked"), "MCP"];
|
|
19566
|
+
for (const harness of report.harnesses) {
|
|
19567
|
+
lines.push(` ${harnessName(harness.harnessId)}: ${harness.servers.length} servers, ${harness.knownToolCount} known tools`);
|
|
19568
|
+
}
|
|
19569
|
+
lines.push(...changeLine(false));
|
|
19570
|
+
lines.push(...next(attention ? "token-harness mcp --verbose" : "token-harness optimize", attention ? "Review the server that needs attention." : "See whether context can be simplified."));
|
|
19571
|
+
return document(lines);
|
|
19572
|
+
}
|
|
19573
|
+
function renderSimpleOptimize(report) {
|
|
19574
|
+
const advice = report.harnesses.filter((item) => item.state !== "absent");
|
|
19575
|
+
const lines = [
|
|
19576
|
+
...title(advice.length > 0 ? "recommendation ready" : "setup needed"),
|
|
19577
|
+
"RECOMMENDATION"
|
|
19578
|
+
];
|
|
19579
|
+
if (advice.length === 0)
|
|
19580
|
+
lines.push(" No supported harness could be assessed.");
|
|
19581
|
+
for (const harness of advice) {
|
|
19582
|
+
const recommendation = harness.recommendations.find((item) => item.priority === "first") ?? harness.recommendations[0];
|
|
19583
|
+
lines.push(truncate(` ${harnessName(harness.harnessId)}: ${recommendation?.action ?? "No change recommended."}`, MAX_WIDTH));
|
|
19584
|
+
const evidence2 = recommendation?.evidence[0]?.summary;
|
|
19585
|
+
if (evidence2)
|
|
19586
|
+
lines.push(truncate(` Why: ${evidence2}`, MAX_WIDTH));
|
|
19587
|
+
}
|
|
19588
|
+
lines.push(...changeLine(false));
|
|
19589
|
+
const canPlan = advice.some((item) => item.recommendedEffort !== item.currentEffort || item.recommendedVerbosity !== item.currentVerbosity);
|
|
19590
|
+
lines.push(...next(canPlan ? "token-harness plan --native-policy" : "token-harness ui", canPlan ? "Review the reversible recommended policy change." : "Keep the dashboard open for the next decision."));
|
|
19591
|
+
return document(lines);
|
|
19592
|
+
}
|
|
19593
|
+
function renderSimplePlan(report, context) {
|
|
19594
|
+
const lines = [
|
|
19595
|
+
...title(report.conflicts.length > 0 ? "blocked" : report.actions.length > 0 ? "plan ready" : "already configured")
|
|
19596
|
+
];
|
|
19597
|
+
if (report.conflicts.length > 0) {
|
|
19598
|
+
lines.push("BLOCKED BY");
|
|
19599
|
+
for (const conflict of report.conflicts)
|
|
19600
|
+
lines.push(truncate(` ${conflict.code}: ${conflict.detail[0] ?? conflict.scope}`, MAX_WIDTH));
|
|
19601
|
+
} else {
|
|
19602
|
+
lines.push("WOULD CHANGE");
|
|
19603
|
+
if (report.actions.length === 0)
|
|
19604
|
+
lines.push(" Nothing.");
|
|
19605
|
+
for (const action of report.actions) {
|
|
19606
|
+
const path = primaryActionPath(action);
|
|
19607
|
+
const shownPath = path === null ? "" : ` - ${truncatePath(displayPath(path, context.home), 34)}`;
|
|
19608
|
+
lines.push(truncate(` ${actionLabel(action.kind)}${shownPath}`, MAX_WIDTH));
|
|
19609
|
+
}
|
|
19610
|
+
lines.push(` Network: ${report.network.length === 0 ? "none" : report.network.join(", ")}`);
|
|
19611
|
+
lines.push(` Backups: ${report.backups.files}`);
|
|
19612
|
+
}
|
|
19613
|
+
lines.push(...changeLine(false));
|
|
19614
|
+
if (report.conflicts.length > 0)
|
|
19615
|
+
lines.push(...next("token-harness plan --verbose", "Review the conflict and its safe resolution."));
|
|
19616
|
+
else if (report.actions.length > 0 && report.persisted && report.planId !== null)
|
|
19617
|
+
lines.push(...next(`token-harness apply --plan ${report.planId} --yes`, "Apply exactly this stored plan."));
|
|
19618
|
+
else if (report.actions.length === 0)
|
|
19619
|
+
lines.push(...next("token-harness setup", "Check detection and finish guided setup."));
|
|
19620
|
+
else
|
|
19621
|
+
lines.push(...next("token-harness ui", "Open the dashboard."));
|
|
19622
|
+
return document(lines);
|
|
19623
|
+
}
|
|
19624
|
+
function renderSimpleApply(report, command) {
|
|
19625
|
+
const changed = report.outcome === "committed" && report.results.some((item) => item.status === "applied");
|
|
19626
|
+
const okay = report.outcome === "committed" || report.outcome === "nothing-to-do";
|
|
19627
|
+
const lines = [...title(okay ? "complete" : report.outcome), "RESULT"];
|
|
19628
|
+
const appliedCount = report.results.filter((item) => item.status === "applied").length;
|
|
19629
|
+
lines.push(` ${appliedCount} actions applied`);
|
|
19630
|
+
if (command === "uninstall" && report.outcome === "committed" && appliedCount === 0) {
|
|
19631
|
+
lines.push(" Removed nothing: no owned entry was recognised.");
|
|
19632
|
+
}
|
|
19633
|
+
lines.push(` Transaction: ${report.transactionId ?? "none"}`);
|
|
19634
|
+
lines.push(...changeLine(changed, command === "uninstall" ? "Owned configuration removed." : command === "rollback" ? "Previous configuration restored." : "Configuration applied and committed."));
|
|
19635
|
+
const confirmationCommand = command === "apply" && report.planId !== null ? `token-harness apply --plan ${report.planId} --yes` : `token-harness ${command} --yes`;
|
|
19636
|
+
lines.push(...next(okay ? "token-harness verify" : report.outcome === "confirmation-required" ? confirmationCommand : `token-harness ${command} --verbose`, okay ? "Check that the integration works." : report.outcome === "confirmation-required" ? "Apply the reviewed change." : "Review the technical result."));
|
|
19637
|
+
return document(lines);
|
|
19638
|
+
}
|
|
19639
|
+
function renderSimpleVerify(report) {
|
|
19640
|
+
const lines = [
|
|
19641
|
+
...title(report.healthyAtDeclaredTier ? "working" : "attention needed"),
|
|
19642
|
+
"INTEGRATIONS"
|
|
19643
|
+
];
|
|
19644
|
+
if (report.results.length === 0)
|
|
19645
|
+
lines.push(" Nothing is configured to verify yet.");
|
|
19646
|
+
for (const item of report.results)
|
|
19647
|
+
lines.push(truncate(` ${item.providerId} on ${harnessName(item.harnessId)}: ${item.status}`, MAX_WIDTH));
|
|
19648
|
+
lines.push(...changeLine(false));
|
|
19649
|
+
lines.push(...next(report.healthyAtDeclaredTier ? "token-harness ui" : "token-harness verify --verbose", report.healthyAtDeclaredTier ? "Open the dashboard." : "Review the failed check and suggested fix."));
|
|
19650
|
+
return document(lines);
|
|
19651
|
+
}
|
|
19652
|
+
function renderSimpleStatus(report) {
|
|
19653
|
+
const lines = [...title(report.problemCount === 0 ? "healthy" : "attention needed"), "ACTIVE"];
|
|
19654
|
+
if (report.pipelines.length === 0)
|
|
19655
|
+
lines.push(" No Token Harness pipeline is active.");
|
|
19656
|
+
for (const pipeline of report.pipelines) {
|
|
19657
|
+
const providers = [...new Set(pipeline.owners.map((owner) => owner.owner))];
|
|
19658
|
+
lines.push(truncate(` ${harnessName(pipeline.harness)}: ${providers.join(" -> ") || "no provider"}`, MAX_WIDTH));
|
|
19659
|
+
}
|
|
19660
|
+
lines.push(` Drift: ${report.drift.length === 0 ? "none" : report.drift.length}`);
|
|
19661
|
+
lines.push(...changeLine(false));
|
|
19662
|
+
lines.push(...next(report.problemCount === 0 ? report.pipelines.length === 0 ? "token-harness setup" : "token-harness ui" : "token-harness status --verbose", report.problemCount === 0 ? report.pipelines.length === 0 ? "Finish the guided setup." : "Open the dashboard." : "Review the drift before making changes."));
|
|
19663
|
+
return document(lines);
|
|
19664
|
+
}
|
|
19665
|
+
function renderSimpleMetrics(report) {
|
|
19666
|
+
const lines = [...title("savings checked"), "SAVINGS"];
|
|
19667
|
+
const measured = report.classes.filter((item) => item.saved !== null);
|
|
19668
|
+
if (measured.length === 0)
|
|
19669
|
+
lines.push(" No comparable savings recorded yet.");
|
|
19670
|
+
for (const item of measured)
|
|
19671
|
+
lines.push(` ${item.class}: ${formatCount(item.saved ?? 0)} ${item.unit ?? ""} saved`);
|
|
19672
|
+
lines.push(` Errors: ${report.errors}`);
|
|
19673
|
+
lines.push(...changeLine(false));
|
|
19674
|
+
lines.push(...next("token-harness optimize", "Get the next evidence-based recommendation."));
|
|
19675
|
+
return document(lines);
|
|
19676
|
+
}
|
|
19677
|
+
function renderSimpleHistory(report) {
|
|
19678
|
+
const lines = [...title("history checked"), "LOCAL USAGE"];
|
|
19679
|
+
if (report.harnesses.length === 0)
|
|
19680
|
+
lines.push(` ${report.source.name}: ${report.source.state}`);
|
|
19681
|
+
for (const item of report.harnesses)
|
|
19682
|
+
lines.push(` ${harnessName(item.harnessId)}: ${formatCount(item.totalTokens)} tokens, trend ${item.burnTrend.state}`);
|
|
19683
|
+
lines.push(...changeLine(false));
|
|
19684
|
+
lines.push(...next("token-harness optimize", "Use the history in the next recommendation."));
|
|
19685
|
+
return document(lines);
|
|
19686
|
+
}
|
|
19687
|
+
function renderSimpleUpdate(report) {
|
|
19688
|
+
const execution = report.execution;
|
|
19689
|
+
const changed = execution?.outcome === "committed" && execution.results.some((item) => item.status === "applied");
|
|
19690
|
+
const lines = [...title(changed ? "updated" : "update checked"), "PROVIDERS"];
|
|
19691
|
+
if (report.providers.length === 0)
|
|
19692
|
+
lines.push(" No provider was detected.");
|
|
19693
|
+
for (const item of report.providers)
|
|
19694
|
+
lines.push(truncate(` ${item.providerId}: ${item.verdict}`, MAX_WIDTH));
|
|
19695
|
+
lines.push(...changeLine(changed, "Provider update applied."));
|
|
19696
|
+
const pending = report.providers.some((item) => item.verdict === "upgradable");
|
|
19697
|
+
lines.push(...next(pending && execution?.outcome === "confirmation-required" ? "token-harness update --yes" : "token-harness verify", pending && execution?.outcome === "confirmation-required" ? "Apply the reviewed provider update." : "Check that integrations still work."));
|
|
19698
|
+
return document(lines);
|
|
19699
|
+
}
|
|
19700
|
+
var init_simple = __esm({
|
|
19701
|
+
"apps/cli/dist/src/render/simple.js"() {
|
|
19702
|
+
"use strict";
|
|
19703
|
+
init_src();
|
|
19704
|
+
init_layout();
|
|
19705
|
+
}
|
|
19706
|
+
});
|
|
19707
|
+
|
|
19099
19708
|
// apps/cli/dist/src/render/index.js
|
|
19100
19709
|
function planRendering(report, result2, context) {
|
|
19101
19710
|
const conflictCodes = new Set(report.conflicts.map((conflict) => conflict.code));
|
|
@@ -19104,6 +19713,13 @@ function planRendering(report, result2, context) {
|
|
|
19104
19713
|
stderrDiagnostics: result2.diagnostics.filter((entry) => !conflictCodes.has(entry.code))
|
|
19105
19714
|
};
|
|
19106
19715
|
}
|
|
19716
|
+
function planRenderingSimple(report, result2, context) {
|
|
19717
|
+
const conflictCodes = new Set(report.conflicts.map((conflict) => conflict.code));
|
|
19718
|
+
return {
|
|
19719
|
+
report: renderSimplePlan(report, context),
|
|
19720
|
+
stderrDiagnostics: result2.diagnostics.filter((entry) => !conflictCodes.has(entry.code))
|
|
19721
|
+
};
|
|
19722
|
+
}
|
|
19107
19723
|
function renderHuman(result2, context) {
|
|
19108
19724
|
const data = result2.data;
|
|
19109
19725
|
if (data === null)
|
|
@@ -19112,11 +19728,45 @@ function renderHuman(result2, context) {
|
|
|
19112
19728
|
report,
|
|
19113
19729
|
stderrDiagnostics: result2.diagnostics
|
|
19114
19730
|
});
|
|
19731
|
+
if (context.verbose !== true) {
|
|
19732
|
+
switch (result2.command) {
|
|
19733
|
+
case "apply":
|
|
19734
|
+
case "rollback":
|
|
19735
|
+
case "uninstall":
|
|
19736
|
+
return plain(renderSimpleApply(data, result2.command));
|
|
19737
|
+
case "budget":
|
|
19738
|
+
return plain(renderSimpleBudget(data));
|
|
19739
|
+
case "context":
|
|
19740
|
+
return plain(renderSimpleContext(data));
|
|
19741
|
+
case "doctor":
|
|
19742
|
+
return plain(renderSimpleDoctor(data));
|
|
19743
|
+
case "history":
|
|
19744
|
+
return plain(renderSimpleHistory(data));
|
|
19745
|
+
case "mcp":
|
|
19746
|
+
return plain(renderSimpleMcp(data));
|
|
19747
|
+
case "metrics":
|
|
19748
|
+
return plain(renderSimpleMetrics(data));
|
|
19749
|
+
case "optimize":
|
|
19750
|
+
return plain(renderSimpleOptimize(data));
|
|
19751
|
+
case "plan":
|
|
19752
|
+
return planRenderingSimple(data, result2, context);
|
|
19753
|
+
case "setup":
|
|
19754
|
+
return plain(renderSimpleSetup(data, context));
|
|
19755
|
+
case "status":
|
|
19756
|
+
return plain(renderSimpleStatus(data));
|
|
19757
|
+
case "update":
|
|
19758
|
+
return plain(renderSimpleUpdate(data));
|
|
19759
|
+
case "verify":
|
|
19760
|
+
return plain(renderSimpleVerify(data));
|
|
19761
|
+
}
|
|
19762
|
+
}
|
|
19115
19763
|
switch (result2.command) {
|
|
19116
19764
|
case "apply":
|
|
19117
19765
|
case "rollback":
|
|
19118
19766
|
case "uninstall":
|
|
19119
19767
|
return plain(renderApplyReport(data, context, result2.command));
|
|
19768
|
+
case "setup":
|
|
19769
|
+
return plain(renderVerboseSetup(data, context));
|
|
19120
19770
|
case "benchmark":
|
|
19121
19771
|
return plain(renderBenchmarkReport(data, context));
|
|
19122
19772
|
case "benchmark-matrix":
|
|
@@ -19169,6 +19819,7 @@ var init_render = __esm({
|
|
|
19169
19819
|
init_status2();
|
|
19170
19820
|
init_update2();
|
|
19171
19821
|
init_verify2();
|
|
19822
|
+
init_simple();
|
|
19172
19823
|
init_layout();
|
|
19173
19824
|
}
|
|
19174
19825
|
});
|
|
@@ -19181,81 +19832,65 @@ var ROOT_USAGE, COMMAND_USAGE;
|
|
|
19181
19832
|
var init_usage = __esm({
|
|
19182
19833
|
"apps/cli/dist/src/usage.js"() {
|
|
19183
19834
|
"use strict";
|
|
19184
|
-
ROOT_USAGE = `token-harness \u2014
|
|
19835
|
+
ROOT_USAGE = `token-harness \u2014 simple Claude Code and Codex efficiency
|
|
19185
19836
|
|
|
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
|
|
19837
|
+
New here? Run one command
|
|
19838
|
+
token-harness setup
|
|
19201
19839
|
|
|
19202
|
-
|
|
19840
|
+
It detects what is installed, checks what works, and prepares only supported
|
|
19841
|
+
changes. It ends with one next step. Nothing changes without an explicit
|
|
19842
|
+
--yes.
|
|
19203
19843
|
|
|
19204
19844
|
Usage
|
|
19205
19845
|
token-harness <command> [flags]
|
|
19206
|
-
token-harness help <command>
|
|
19207
19846
|
|
|
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
|
|
19847
|
+
Everyday commands
|
|
19848
|
+
setup Guided detection, safe configuration, and verification
|
|
19849
|
+
ui Open the local dashboard in your browser
|
|
19850
|
+
optimize Show the best evidence-based action for the current task
|
|
19851
|
+
status Show active harnesses, providers, and configuration health
|
|
19230
19852
|
|
|
19231
|
-
|
|
19232
|
-
|
|
19853
|
+
Advanced commands
|
|
19854
|
+
doctor Full installation and connection check
|
|
19855
|
+
budget Claude/Codex subscription usage windows
|
|
19856
|
+
context Instruction, model, and context-cost observations
|
|
19857
|
+
mcp MCP server and tool inventory
|
|
19858
|
+
history Local usage history through an installed ccusage
|
|
19859
|
+
plan Prepare an exact, reversible change without applying it
|
|
19860
|
+
apply Apply a reviewed plan
|
|
19861
|
+
verify Check that configured integrations work
|
|
19862
|
+
metrics Show measured savings
|
|
19863
|
+
update Check or update installed providers
|
|
19864
|
+
rollback Restore the previous configuration
|
|
19865
|
+
uninstall Remove only configuration Token Harness owns
|
|
19866
|
+
benchmark, benchmark-start, benchmark-finish, benchmark-matrix
|
|
19867
|
+
Compare real task results for advanced evaluation
|
|
19868
|
+
|
|
19869
|
+
Useful flags
|
|
19870
|
+
--verbose Show technical details instead of the short summary
|
|
19871
|
+
--json Emit the complete machine-readable result
|
|
19872
|
+
--yes Confirm a configuration-changing operation
|
|
19233
19873
|
--harness <id> Restrict the operation to one harness
|
|
19234
19874
|
--provider <id> Restrict the operation to one provider
|
|
19235
19875
|
--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
|
|
19876
|
+
--help Show help for a command
|
|
19877
|
+
--version Print the version
|
|
19253
19878
|
|
|
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.`;
|
|
19879
|
+
Run token-harness <command> --help for advanced flags and safety details.`;
|
|
19258
19880
|
COMMAND_USAGE = {
|
|
19881
|
+
setup: `token-harness setup \u2014 guided onboarding in one command
|
|
19882
|
+
|
|
19883
|
+
Usage
|
|
19884
|
+
token-harness setup [--yes] [--verbose] [--json] [--project <dir>]
|
|
19885
|
+
|
|
19886
|
+
Without --yes, setup detects Claude Code/Codex, checks existing providers, and
|
|
19887
|
+
prepares any supported reversible configuration. It changes no harness/provider
|
|
19888
|
+
configuration and ends with one next step.
|
|
19889
|
+
|
|
19890
|
+
Run the suggested token-harness setup --yes only after reviewing the short plan.
|
|
19891
|
+
It applies that stored plan transactionally, verifies the result, reads allowance
|
|
19892
|
+
when available, and points to the local dashboard. Token Harness never installs
|
|
19893
|
+
Claude Code or Codex and never spends model quota during setup.`,
|
|
19259
19894
|
"benchmark-start": `token-harness benchmark-start \u2014 snapshot one task before it runs
|
|
19260
19895
|
|
|
19261
19896
|
Usage
|
|
@@ -19560,14 +20195,14 @@ function formatDiagnostics(diagnostics) {
|
|
|
19560
20195
|
if (errors.length === 0 && warnings.length === 0)
|
|
19561
20196
|
return "";
|
|
19562
20197
|
const lines = [];
|
|
19563
|
-
for (const [
|
|
20198
|
+
for (const [title2, group] of [
|
|
19564
20199
|
["ERRORS", errors],
|
|
19565
20200
|
["WARNINGS", warnings]
|
|
19566
20201
|
]) {
|
|
19567
20202
|
if (group.length === 0)
|
|
19568
20203
|
continue;
|
|
19569
20204
|
lines.push("");
|
|
19570
|
-
lines.push(
|
|
20205
|
+
lines.push(title2);
|
|
19571
20206
|
for (const entry of group)
|
|
19572
20207
|
lines.push(diagnosticLine(entry));
|
|
19573
20208
|
}
|
|
@@ -19649,6 +20284,7 @@ async function run(options) {
|
|
|
19649
20284
|
const renderContext = {
|
|
19650
20285
|
toolVersion,
|
|
19651
20286
|
home: options.home,
|
|
20287
|
+
verbose: false,
|
|
19652
20288
|
decorate: shouldDecorate({
|
|
19653
20289
|
stdoutIsTty: options.stdoutIsTty ?? false,
|
|
19654
20290
|
noColor: env["NO_COLOR"] !== void 0,
|
|
@@ -19688,6 +20324,7 @@ async function run(options) {
|
|
|
19688
20324
|
diagnostics: invocation.diagnostics
|
|
19689
20325
|
}), options, renderContext, json);
|
|
19690
20326
|
}
|
|
20327
|
+
renderContext.verbose = invocation.options.verbose;
|
|
19691
20328
|
const environmentDiagnostics = options.environmentDiagnostics ?? [];
|
|
19692
20329
|
if (environmentDiagnostics.some((entry) => entry.severity === "error")) {
|
|
19693
20330
|
return emit(commandResult({
|
|
@@ -19762,6 +20399,7 @@ var init_run = __esm({
|
|
|
19762
20399
|
init_optimize();
|
|
19763
20400
|
init_plan2();
|
|
19764
20401
|
init_rollback();
|
|
20402
|
+
init_setup2();
|
|
19765
20403
|
init_status();
|
|
19766
20404
|
init_update();
|
|
19767
20405
|
init_verify();
|
|
@@ -19783,6 +20421,7 @@ var init_run = __esm({
|
|
|
19783
20421
|
optimize: runOptimize,
|
|
19784
20422
|
plan: runPlan,
|
|
19785
20423
|
rollback: runRollback,
|
|
20424
|
+
setup: runSetup,
|
|
19786
20425
|
status: runStatus,
|
|
19787
20426
|
uninstall: runUninstall,
|
|
19788
20427
|
update: runUpdate,
|
|
@@ -19792,12 +20431,156 @@ var init_run = __esm({
|
|
|
19792
20431
|
}
|
|
19793
20432
|
});
|
|
19794
20433
|
|
|
20434
|
+
// apps/cli/dist/src/ui.js
|
|
20435
|
+
function parseUiArgs(argv2) {
|
|
20436
|
+
const options = { help: false, json: false, open: true, port: 0 };
|
|
20437
|
+
for (let index = 0; index < argv2.length; index += 1) {
|
|
20438
|
+
const token = argv2[index];
|
|
20439
|
+
if (token === "--help")
|
|
20440
|
+
options.help = true;
|
|
20441
|
+
else if (token === "--json")
|
|
20442
|
+
options.json = true;
|
|
20443
|
+
else if (token === "--no-open")
|
|
20444
|
+
options.open = false;
|
|
20445
|
+
else if (token === "--port") {
|
|
20446
|
+
const raw = argv2[index + 1];
|
|
20447
|
+
const port = Number(raw);
|
|
20448
|
+
if (raw === void 0 || !Number.isInteger(port) || port < 1 || port > 65535) {
|
|
20449
|
+
return { ok: false, message: "--port requires an integer from 1 to 65535" };
|
|
20450
|
+
}
|
|
20451
|
+
options.port = port;
|
|
20452
|
+
index += 1;
|
|
20453
|
+
} else {
|
|
20454
|
+
return { ok: false, message: `Unknown ui option ${JSON.stringify(token)}` };
|
|
20455
|
+
}
|
|
20456
|
+
}
|
|
20457
|
+
return { ok: true, options };
|
|
20458
|
+
}
|
|
20459
|
+
function nameOf(id) {
|
|
20460
|
+
if (id === "claude")
|
|
20461
|
+
return "Claude Code";
|
|
20462
|
+
if (id === "codex")
|
|
20463
|
+
return "Codex";
|
|
20464
|
+
if (id === "opencode")
|
|
20465
|
+
return "OpenCode";
|
|
20466
|
+
return id;
|
|
20467
|
+
}
|
|
20468
|
+
function buildDashboardModel(input) {
|
|
20469
|
+
const present = input.doctor.harnesses.filter((item) => item.state !== "absent");
|
|
20470
|
+
const configured = input.doctor.providers.filter((item) => item.state === "configured" && item.configuredHarnesses.length > 0);
|
|
20471
|
+
const hasProblems = input.doctor.problemCount > 0 || input.status.problemCount > 0;
|
|
20472
|
+
const state = hasProblems ? "attention" : present.length === 0 || configured.length === 0 ? "setup-needed" : "ready";
|
|
20473
|
+
const recommendation = input.optimize.harnesses.flatMap((harness) => harness.recommendations.map((item) => ({
|
|
20474
|
+
harness: harness.harnessId,
|
|
20475
|
+
priority: item.priority,
|
|
20476
|
+
action: item.action,
|
|
20477
|
+
reason: item.evidence[0]?.summary ?? null
|
|
20478
|
+
}))).sort((left, right) => {
|
|
20479
|
+
const rank = { first: 0, next: 1, optional: 2 };
|
|
20480
|
+
return rank[left.priority] - rank[right.priority];
|
|
20481
|
+
})[0];
|
|
20482
|
+
const nextStep = state === "setup-needed" ? { command: "token-harness setup", description: "Finish the guided setup." } : state === "attention" ? {
|
|
20483
|
+
command: "token-harness doctor --verbose",
|
|
20484
|
+
description: "Review the detected problem before changing anything."
|
|
20485
|
+
} : {
|
|
20486
|
+
command: "token-harness optimize",
|
|
20487
|
+
description: "Refresh advice for the task you are about to start."
|
|
20488
|
+
};
|
|
20489
|
+
return {
|
|
20490
|
+
generatedAt: input.generatedAt,
|
|
20491
|
+
state,
|
|
20492
|
+
headline: state === "ready" ? "Your coding harnesses are connected." : state === "attention" ? "One or more checks need attention." : "Finish setup to activate Token Harness.",
|
|
20493
|
+
harnesses: input.doctor.harnesses.map((harness) => {
|
|
20494
|
+
const budget = input.budget.harnesses.find((item) => item.harnessId === harness.harnessId);
|
|
20495
|
+
return {
|
|
20496
|
+
id: harness.harnessId,
|
|
20497
|
+
name: nameOf(harness.harnessId),
|
|
20498
|
+
state: harness.state,
|
|
20499
|
+
version: harness.version,
|
|
20500
|
+
providers: input.doctor.providers.filter((provider) => provider.configuredHarnesses.includes(harness.harnessId)).map((provider) => provider.providerId),
|
|
20501
|
+
allowance: (budget?.windows ?? []).map((window) => ({
|
|
20502
|
+
label: window.bucketName ?? window.scope,
|
|
20503
|
+
remainingPercent: window.remainingPercent,
|
|
20504
|
+
resetsAt: window.resetsAt,
|
|
20505
|
+
confidence: window.confidence
|
|
20506
|
+
}))
|
|
20507
|
+
};
|
|
20508
|
+
}),
|
|
20509
|
+
providers: input.doctor.providers.map((provider) => ({
|
|
20510
|
+
id: provider.providerId,
|
|
20511
|
+
state: provider.state,
|
|
20512
|
+
harnesses: provider.configuredHarnesses.map(nameOf)
|
|
20513
|
+
})),
|
|
20514
|
+
recommendation: recommendation === void 0 ? null : {
|
|
20515
|
+
action: `${nameOf(recommendation.harness)}: ${recommendation.action}`,
|
|
20516
|
+
reason: recommendation.reason
|
|
20517
|
+
},
|
|
20518
|
+
nextStep
|
|
20519
|
+
};
|
|
20520
|
+
}
|
|
20521
|
+
function uiAsset(path, model) {
|
|
20522
|
+
if (path === "/")
|
|
20523
|
+
return { status: 200, contentType: "text/html; charset=utf-8", body: DASHBOARD_HTML };
|
|
20524
|
+
if (path === "/app.css")
|
|
20525
|
+
return { status: 200, contentType: "text/css; charset=utf-8", body: DASHBOARD_CSS };
|
|
20526
|
+
if (path === "/app.js")
|
|
20527
|
+
return { status: 200, contentType: "text/javascript; charset=utf-8", body: DASHBOARD_JS };
|
|
20528
|
+
if (path === "/api/status")
|
|
20529
|
+
return {
|
|
20530
|
+
status: 200,
|
|
20531
|
+
contentType: "application/json; charset=utf-8",
|
|
20532
|
+
body: JSON.stringify(model)
|
|
20533
|
+
};
|
|
20534
|
+
return { status: 404, contentType: "text/plain; charset=utf-8", body: "Not found\n" };
|
|
20535
|
+
}
|
|
20536
|
+
var UI_USAGE, DASHBOARD_HTML, DASHBOARD_CSS, DASHBOARD_JS;
|
|
20537
|
+
var init_ui = __esm({
|
|
20538
|
+
"apps/cli/dist/src/ui.js"() {
|
|
20539
|
+
"use strict";
|
|
20540
|
+
UI_USAGE = `token-harness ui \u2014 open a simple local dashboard
|
|
20541
|
+
|
|
20542
|
+
Usage
|
|
20543
|
+
token-harness ui [--no-open] [--port <number>] [--json]
|
|
20544
|
+
|
|
20545
|
+
The dashboard listens only on 127.0.0.1 and reads the same reports as the CLI.
|
|
20546
|
+
It does not send data anywhere and cannot change configuration. Close it with
|
|
20547
|
+
Ctrl+C. Use --json for one complete dashboard snapshot without starting a server.`;
|
|
20548
|
+
DASHBOARD_HTML = `<!doctype html>
|
|
20549
|
+
<html lang="en">
|
|
20550
|
+
<head>
|
|
20551
|
+
<meta charset="utf-8">
|
|
20552
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
20553
|
+
<meta name="color-scheme" content="dark">
|
|
20554
|
+
<title>Token Harness</title>
|
|
20555
|
+
<link rel="stylesheet" href="/app.css">
|
|
20556
|
+
</head>
|
|
20557
|
+
<body>
|
|
20558
|
+
<a class="skip" href="#main">Skip to dashboard</a>
|
|
20559
|
+
<header><div class="brand"><span class="mark">TH</span><span>Token Harness</span></div><button id="refresh" type="button">Refresh</button></header>
|
|
20560
|
+
<main id="main">
|
|
20561
|
+
<section class="hero" aria-labelledby="headline"><p class="eyebrow">LOCAL STATUS</p><h1 id="headline">Checking your harnesses...</h1><p id="updated" class="muted" aria-live="polite"></p></section>
|
|
20562
|
+
<section id="harnesses" class="grid" aria-label="Harness status"></section>
|
|
20563
|
+
<section class="panel recommendation"><p class="eyebrow">RECOMMENDATION</p><h2 id="recommendation">Waiting for observations...</h2><p id="reason" class="muted"></p></section>
|
|
20564
|
+
<section class="panel next"><div><p class="eyebrow">NEXT STEP</p><code id="command">token-harness setup</code><p id="description" class="muted"></p></div><button id="copy" type="button">Copy command</button></section>
|
|
20565
|
+
<section class="panel"><p class="eyebrow">PROVIDERS</p><div id="providers" class="provider-list"></div></section>
|
|
20566
|
+
<p id="error" class="error" role="alert"></p>
|
|
20567
|
+
</main>
|
|
20568
|
+
<footer>Private by design. Served only from this computer.</footer>
|
|
20569
|
+
<script src="/app.js" defer></script>
|
|
20570
|
+
</body>
|
|
20571
|
+
</html>`;
|
|
20572
|
+
DASHBOARD_CSS = `:root{font-family:Inter,ui-sans-serif,system-ui,-apple-system,sans-serif;color:#f8fafc;background:#0f172a;font-synthesis:none}*{box-sizing:border-box}body{margin:0;min-height:100vh;background:radial-gradient(circle at 90% 0,#172554 0,transparent 32rem),#0f172a}button{min-height:44px;border:1px solid #475569;border-radius:10px;background:#1e293b;color:#f8fafc;padding:0 1rem;font:inherit;font-weight:700;cursor:pointer}button:hover{background:#334155}button:focus-visible,a:focus-visible{outline:3px solid #38bdf8;outline-offset:3px}.skip{position:absolute;left:-999px;top:1rem;color:#fff}.skip:focus{left:1rem}header,main,footer{width:min(1120px,calc(100% - 2rem));margin-inline:auto}header{height:76px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid #334155}.brand{display:flex;align-items:center;gap:.75rem;font-weight:800}.mark{display:grid;place-items:center;width:38px;height:38px;border-radius:10px;background:#22c55e;color:#052e16;font:800 14px ui-monospace,monospace}.hero{padding:4.5rem 0 2rem}.eyebrow{margin:0 0 .65rem;color:#22c55e;font:700 .75rem ui-monospace,monospace;letter-spacing:.12em}.hero h1{max-width:760px;margin:0 0 .8rem;font-size:clamp(2rem,5vw,4.4rem);line-height:1.02;letter-spacing:-.045em}.muted{color:#94a3b8;line-height:1.6}.grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem}.panel,.card{border:1px solid #334155;border-radius:16px;background:#172033;padding:1.4rem;box-shadow:0 16px 40px #02061733}.card-top,.next{display:flex;align-items:flex-start;justify-content:space-between;gap:1rem}.badge{border-radius:999px;padding:.35rem .65rem;background:#334155;color:#cbd5e1;font:700 .72rem ui-monospace,monospace}.badge.ready{background:#14532d;color:#bbf7d0}.badge.attention{background:#713f12;color:#fef3c7}.card h2,.panel h2{margin:.15rem 0;font-size:1.25rem}.meta{margin:.35rem 0 1.2rem;color:#94a3b8}.quota{margin-top:1rem}.quota-row{display:flex;justify-content:space-between;gap:1rem;margin-bottom:.45rem;font-size:.9rem}.quota-meta{margin:.45rem 0 0;color:#64748b;font-size:.78rem}.track{height:8px;border-radius:999px;background:#334155;overflow:hidden}.fill{height:100%;background:#22c55e;border-radius:inherit}.recommendation{margin-top:1rem}.next{margin-top:1rem;align-items:center}.next code{display:block;color:#e2e8f0;font-size:1rem;overflow-wrap:anywhere}.provider-list{display:flex;flex-wrap:wrap;gap:.65rem}.provider{border:1px solid #475569;border-radius:10px;padding:.65rem .8rem;color:#cbd5e1}.panel{margin-top:1rem}.error{color:#fecaca}.empty{color:#94a3b8}footer{padding:2.5rem 0;color:#64748b;font-size:.85rem}@media(max-width:720px){.grid{grid-template-columns:1fr}.hero{padding-top:3rem}.next{align-items:stretch;flex-direction:column}.next button{width:100%}}@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important}}`;
|
|
20573
|
+
DASHBOARD_JS = `const byId=(id)=>document.getElementById(id);const text=(id,value)=>{byId(id).textContent=value};function badgeState(state){return state==='configured'||state==='detected'?'ready':state==='broken'?'attention':''}function render(model){text('headline',model.headline);text('updated','Updated '+new Date(model.generatedAt).toLocaleString());const harnesses=byId('harnesses');harnesses.replaceChildren();for(const item of model.harnesses){const card=document.createElement('article');card.className='card';const top=document.createElement('div');top.className='card-top';const heading=document.createElement('h2');heading.textContent=item.name;const badge=document.createElement('span');badge.className='badge '+badgeState(item.state);badge.textContent=item.state;top.append(heading,badge);card.append(top);const meta=document.createElement('p');meta.className='meta';meta.textContent=(item.version?'Version '+item.version+' \xB7 ':'')+(item.providers.length?item.providers.join(', ')+' active':'no provider active');card.append(meta);if(item.allowance.length===0){const empty=document.createElement('p');empty.className='empty';empty.textContent='Allowance unavailable';card.append(empty)}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 reset=document.createElement('p');reset.className='quota-meta';reset.textContent=(quota.resetsAt?'Resets '+new Date(quota.resetsAt).toLocaleString():'Reset unknown')+' \xB7 '+quota.confidence;box.append(row,track,reset);card.append(box)}harnesses.append(card)}text('recommendation',model.recommendation?model.recommendation.action:'No recommendation yet.');text('reason',model.recommendation?.reason||'More observations are needed before Token Harness recommends a change.');text('command',model.nextStep.command);text('description',model.nextStep.description);const providers=byId('providers');providers.replaceChildren();if(model.providers.length===0){const empty=document.createElement('span');empty.className='empty';empty.textContent='No provider detected';providers.append(empty)}for(const item of model.providers){const node=document.createElement('span');node.className='provider';node.textContent=item.id+' \xB7 '+(item.harnesses.length?'active on '+item.harnesses.join(', '):item.state);providers.append(node)}text('error','')}async function load(){byId('refresh').disabled=true;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){text('error',error instanceof Error?error.message:String(error))}finally{byId('refresh').disabled=false}}byId('refresh').addEventListener('click',load);byId('copy').addEventListener('click',async()=>{await navigator.clipboard.writeText(byId('command').textContent||'');text('updated','Command copied')});load();setInterval(()=>{if(!document.hidden)load()},30000);`;
|
|
20574
|
+
}
|
|
20575
|
+
});
|
|
20576
|
+
|
|
19795
20577
|
// apps/cli/dist/src/main.js
|
|
19796
20578
|
var main_exports = {};
|
|
19797
20579
|
__export(main_exports, {
|
|
19798
20580
|
main: () => main
|
|
19799
20581
|
});
|
|
19800
20582
|
import process5 from "node:process";
|
|
20583
|
+
import { createServer } from "node:http";
|
|
19801
20584
|
async function runAsDatabaseReader(argv2) {
|
|
19802
20585
|
if (argv2[0] !== SQLITE_CHILD_FLAG)
|
|
19803
20586
|
return false;
|
|
@@ -19815,15 +20598,24 @@ async function runAsDatabaseReader(argv2) {
|
|
|
19815
20598
|
async function main(argv2) {
|
|
19816
20599
|
if (await runAsDatabaseReader(argv2))
|
|
19817
20600
|
return;
|
|
20601
|
+
const uiInvocation = argv2[0] === "ui" ? parseUiArgs(argv2.slice(1)) : null;
|
|
20602
|
+
if (uiInvocation !== null && !uiInvocation.ok) {
|
|
20603
|
+
process5.stderr.write(`${uiInvocation.message}
|
|
20604
|
+
Run token-harness ui --help for usage.
|
|
20605
|
+
`);
|
|
20606
|
+
process5.exitCode = EXIT_CODES["usage-error"];
|
|
20607
|
+
return;
|
|
20608
|
+
}
|
|
20609
|
+
if (uiInvocation?.ok === true && uiInvocation.options.help) {
|
|
20610
|
+
process5.stdout.write(`${UI_USAGE}
|
|
20611
|
+
`);
|
|
20612
|
+
process5.exitCode = EXIT_CODES.ok;
|
|
20613
|
+
return;
|
|
20614
|
+
}
|
|
19818
20615
|
const resolution = resolveHostEnvironment();
|
|
19819
20616
|
const fs = resolution.ok ? new NodeFileSystem(resolution.environment.facts) : null;
|
|
19820
20617
|
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
|
-
},
|
|
20618
|
+
const baseOptions = {
|
|
19827
20619
|
// On failure `facts` is null only when the operating system itself is
|
|
19828
20620
|
// unsupported. An unresolvable state directory still has honest facts to
|
|
19829
20621
|
// report, and `run` uses them for the runtime-floor check before refusing.
|
|
@@ -19872,15 +20664,188 @@ async function main(argv2) {
|
|
|
19872
20664
|
}) : null,
|
|
19873
20665
|
env: process5.env,
|
|
19874
20666
|
stdoutIsTty: process5.stdout.isTTY === true
|
|
20667
|
+
};
|
|
20668
|
+
if (uiInvocation?.ok === true) {
|
|
20669
|
+
process5.exitCode = await runUi(uiInvocation.options, baseOptions);
|
|
20670
|
+
return;
|
|
20671
|
+
}
|
|
20672
|
+
const exitCode = await run({
|
|
20673
|
+
...baseOptions,
|
|
20674
|
+
argv: argv2,
|
|
20675
|
+
streams: {
|
|
20676
|
+
out: (text3) => process5.stdout.write(text3),
|
|
20677
|
+
err: (text3) => process5.stderr.write(text3)
|
|
20678
|
+
}
|
|
19875
20679
|
});
|
|
19876
20680
|
process5.exitCode = exitCode;
|
|
19877
20681
|
}
|
|
20682
|
+
async function readJsonReport(command, baseOptions) {
|
|
20683
|
+
let stdout = "";
|
|
20684
|
+
let stderr = "";
|
|
20685
|
+
const exitCode = await run({
|
|
20686
|
+
...baseOptions,
|
|
20687
|
+
argv: [command, "--json"],
|
|
20688
|
+
streams: {
|
|
20689
|
+
out: (text3) => {
|
|
20690
|
+
stdout += text3;
|
|
20691
|
+
},
|
|
20692
|
+
err: (text3) => {
|
|
20693
|
+
stderr += text3;
|
|
20694
|
+
}
|
|
20695
|
+
}
|
|
20696
|
+
});
|
|
20697
|
+
let envelope;
|
|
20698
|
+
try {
|
|
20699
|
+
envelope = JSON.parse(stdout);
|
|
20700
|
+
} catch {
|
|
20701
|
+
throw new Error(stderr.trim() || `${command} did not return a valid report`);
|
|
20702
|
+
}
|
|
20703
|
+
if (envelope.data === null) {
|
|
20704
|
+
throw new Error(envelope.diagnostics[0]?.message ?? `${command} could not inspect this computer`);
|
|
20705
|
+
}
|
|
20706
|
+
return { exitCode, data: envelope.data };
|
|
20707
|
+
}
|
|
20708
|
+
async function collectDashboard(baseOptions) {
|
|
20709
|
+
const [doctor, status, budget, optimize] = await Promise.all([
|
|
20710
|
+
readJsonReport("doctor", baseOptions),
|
|
20711
|
+
readJsonReport("status", baseOptions),
|
|
20712
|
+
readJsonReport("budget", baseOptions),
|
|
20713
|
+
readJsonReport("optimize", baseOptions)
|
|
20714
|
+
]);
|
|
20715
|
+
return buildDashboardModel({
|
|
20716
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
20717
|
+
doctor: doctor.data,
|
|
20718
|
+
status: status.data,
|
|
20719
|
+
budget: budget.data,
|
|
20720
|
+
optimize: optimize.data
|
|
20721
|
+
});
|
|
20722
|
+
}
|
|
20723
|
+
async function openDashboard(url, baseOptions) {
|
|
20724
|
+
const adapters = baseOptions.adapters;
|
|
20725
|
+
const platform = baseOptions.platform;
|
|
20726
|
+
if (adapters === null || adapters === void 0 || platform === null)
|
|
20727
|
+
return false;
|
|
20728
|
+
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] };
|
|
20729
|
+
const result2 = await adapters.runner.run({
|
|
20730
|
+
...request,
|
|
20731
|
+
cwd: baseOptions.cwd,
|
|
20732
|
+
env: Object.fromEntries(["DISPLAY", "WAYLAND_DISPLAY", "XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS"].flatMap((name) => process5.env[name] === void 0 ? [] : [[name, process5.env[name]]])),
|
|
20733
|
+
timeoutMs: 5e3,
|
|
20734
|
+
maxOutputBytes: 4096
|
|
20735
|
+
});
|
|
20736
|
+
return result2.failure === null && result2.exitCode === 0;
|
|
20737
|
+
}
|
|
20738
|
+
async function runUi(options, baseOptions) {
|
|
20739
|
+
let initial;
|
|
20740
|
+
try {
|
|
20741
|
+
initial = await collectDashboard(baseOptions);
|
|
20742
|
+
} catch (error) {
|
|
20743
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
20744
|
+
if (options.json) {
|
|
20745
|
+
process5.stdout.write(serializeEnvelope(toEnvelope(commandResult({
|
|
20746
|
+
command: "ui",
|
|
20747
|
+
exitCode: EXIT_CODES["unsupported-environment"],
|
|
20748
|
+
diagnostics: [
|
|
20749
|
+
diagnostic({
|
|
20750
|
+
severity: "error",
|
|
20751
|
+
code: "dashboard-unavailable",
|
|
20752
|
+
message,
|
|
20753
|
+
remediation: "Run token-harness doctor --verbose"
|
|
20754
|
+
})
|
|
20755
|
+
]
|
|
20756
|
+
}), TOOL_VERSION)));
|
|
20757
|
+
} else {
|
|
20758
|
+
process5.stderr.write(`Token Harness dashboard could not start: ${message}
|
|
20759
|
+
`);
|
|
20760
|
+
}
|
|
20761
|
+
return EXIT_CODES["unsupported-environment"];
|
|
20762
|
+
}
|
|
20763
|
+
if (options.json) {
|
|
20764
|
+
const exitCode = initial.state === "attention" ? EXIT_CODES["problems-found"] : EXIT_CODES.ok;
|
|
20765
|
+
process5.stdout.write(serializeEnvelope(toEnvelope(commandResult({ command: "ui", exitCode, data: initial }), TOOL_VERSION)));
|
|
20766
|
+
return exitCode;
|
|
20767
|
+
}
|
|
20768
|
+
let cached = initial;
|
|
20769
|
+
let cachedAt = Date.now();
|
|
20770
|
+
const server = createServer(async (request, response) => {
|
|
20771
|
+
const host = request.headers.host ?? "";
|
|
20772
|
+
const sameSite = request.headers["sec-fetch-site"] !== "cross-site";
|
|
20773
|
+
const localHost = host.startsWith("127.0.0.1:") || host.startsWith("localhost:");
|
|
20774
|
+
if (!sameSite || !localHost) {
|
|
20775
|
+
response.writeHead(403, { ...UI_SECURITY_HEADERS, "Content-Type": "text/plain" });
|
|
20776
|
+
response.end("Forbidden\n");
|
|
20777
|
+
return;
|
|
20778
|
+
}
|
|
20779
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
20780
|
+
response.writeHead(405, {
|
|
20781
|
+
...UI_SECURITY_HEADERS,
|
|
20782
|
+
Allow: "GET, HEAD",
|
|
20783
|
+
"Content-Type": "text/plain"
|
|
20784
|
+
});
|
|
20785
|
+
response.end("Method not allowed\n");
|
|
20786
|
+
return;
|
|
20787
|
+
}
|
|
20788
|
+
let model = cached;
|
|
20789
|
+
if (request.url === "/api/status") {
|
|
20790
|
+
if (Date.now() - cachedAt > 5e3) {
|
|
20791
|
+
try {
|
|
20792
|
+
cached = await collectDashboard(baseOptions);
|
|
20793
|
+
cachedAt = Date.now();
|
|
20794
|
+
model = cached;
|
|
20795
|
+
} catch {
|
|
20796
|
+
response.writeHead(503, {
|
|
20797
|
+
...UI_SECURITY_HEADERS,
|
|
20798
|
+
"Content-Type": "application/json; charset=utf-8"
|
|
20799
|
+
});
|
|
20800
|
+
response.end('{"error":"Dashboard data is temporarily unavailable"}');
|
|
20801
|
+
return;
|
|
20802
|
+
}
|
|
20803
|
+
}
|
|
20804
|
+
}
|
|
20805
|
+
const asset = uiAsset(request.url ?? "/", model);
|
|
20806
|
+
response.writeHead(asset.status, {
|
|
20807
|
+
...UI_SECURITY_HEADERS,
|
|
20808
|
+
"Content-Type": asset.contentType
|
|
20809
|
+
});
|
|
20810
|
+
response.end(request.method === "HEAD" ? void 0 : asset.body);
|
|
20811
|
+
});
|
|
20812
|
+
try {
|
|
20813
|
+
await new Promise((resolve, reject) => {
|
|
20814
|
+
server.once("error", reject);
|
|
20815
|
+
server.listen(options.port, "127.0.0.1", () => resolve());
|
|
20816
|
+
});
|
|
20817
|
+
} catch (error) {
|
|
20818
|
+
process5.stderr.write(`Token Harness dashboard could not listen locally: ${error instanceof Error ? error.message : String(error)}
|
|
20819
|
+
`);
|
|
20820
|
+
return EXIT_CODES["internal-error"];
|
|
20821
|
+
}
|
|
20822
|
+
const address = server.address();
|
|
20823
|
+
const port = typeof address === "object" && address !== null ? address.port : options.port;
|
|
20824
|
+
const url = `http://127.0.0.1:${port}/`;
|
|
20825
|
+
process5.stdout.write(`Token Harness dashboard is ready: ${url}
|
|
20826
|
+
Close it with Ctrl+C.
|
|
20827
|
+
`);
|
|
20828
|
+
if (options.open && !await openDashboard(url, baseOptions)) {
|
|
20829
|
+
process5.stdout.write(`Open this address in your browser: ${url}
|
|
20830
|
+
`);
|
|
20831
|
+
}
|
|
20832
|
+
return EXIT_CODES.ok;
|
|
20833
|
+
}
|
|
20834
|
+
var UI_SECURITY_HEADERS;
|
|
19878
20835
|
var init_main = __esm({
|
|
19879
20836
|
"apps/cli/dist/src/main.js"() {
|
|
19880
20837
|
"use strict";
|
|
19881
20838
|
init_src();
|
|
19882
20839
|
init_src2();
|
|
19883
20840
|
init_run();
|
|
20841
|
+
init_ui();
|
|
20842
|
+
init_version2();
|
|
20843
|
+
UI_SECURITY_HEADERS = {
|
|
20844
|
+
"Cache-Control": "no-store",
|
|
20845
|
+
"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'",
|
|
20846
|
+
"Referrer-Policy": "no-referrer",
|
|
20847
|
+
"X-Content-Type-Options": "nosniff"
|
|
20848
|
+
};
|
|
19884
20849
|
}
|
|
19885
20850
|
});
|
|
19886
20851
|
|