hactl 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +761 -214
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2271,7 +2271,7 @@ async function run(app2, inputs, context) {
|
|
|
2271
2271
|
// package.json
|
|
2272
2272
|
var package_default = {
|
|
2273
2273
|
name: "hactl",
|
|
2274
|
-
version: "0.
|
|
2274
|
+
version: "0.9.0",
|
|
2275
2275
|
description: "Manage Home Assistant instances from the command line",
|
|
2276
2276
|
license: "MIT",
|
|
2277
2277
|
repository: {
|
|
@@ -2492,6 +2492,16 @@ var serializableIssues = (issues) => {
|
|
|
2492
2492
|
issue.message ??= messageOf(issue);
|
|
2493
2493
|
return issues.toJSON ? issues : Object.defineProperty(issues, "toJSON", issuesToJson);
|
|
2494
2494
|
};
|
|
2495
|
+
var FirstIssues = class extends Issues {
|
|
2496
|
+
// read from the prototype, so no errors object lists it among its own keys
|
|
2497
|
+
get failFast() {
|
|
2498
|
+
return true;
|
|
2499
|
+
}
|
|
2500
|
+
_e(...failure) {
|
|
2501
|
+
super._e(...failure);
|
|
2502
|
+
return true;
|
|
2503
|
+
}
|
|
2504
|
+
};
|
|
2495
2505
|
var issueAt = (path, site, data, key) => {
|
|
2496
2506
|
let context = site.v ?? site;
|
|
2497
2507
|
if (key !== void 0) {
|
|
@@ -2511,7 +2521,9 @@ var issueAt = (path, site, data, key) => {
|
|
|
2511
2521
|
context.text?.(issue);
|
|
2512
2522
|
return issue;
|
|
2513
2523
|
};
|
|
2514
|
-
var
|
|
2524
|
+
var isCustomIssue = (issue) => issue._l !== void 0 || false ? false : issue.message !== void 0 && !issue.message.startsWith(messageOf(issue));
|
|
2525
|
+
var codedIssue = (issue) => Object.defineProperty(issue, "_c", { value: 2 });
|
|
2526
|
+
var notedAs = (issue, copy) => false ? labeledIssue(copy, issue._n) : issue._c ? codedIssue(copy) : copy;
|
|
2515
2527
|
var pathOf = (issue) => {
|
|
2516
2528
|
let path = "";
|
|
2517
2529
|
for (const k of issue.path) {
|
|
@@ -2523,10 +2535,85 @@ var issueLineOf = (issue) => {
|
|
|
2523
2535
|
const defaultMessage = true ? messageOf(issue) : void 0;
|
|
2524
2536
|
const message = issue.message ?? (true ? defaultMessage : messageOf(issue));
|
|
2525
2537
|
const path = true ? pathOf(issue) : issue.path.join(".");
|
|
2526
|
-
return
|
|
2538
|
+
return issue._l !== void 0 ? issue._l : false ? labeledPathOf(issue) + message : path ? path + (!(message === "is invalid" && issue.expected === "valid") && !message.startsWith(defaultMessage) ? ": " : " ") + message : message;
|
|
2527
2539
|
};
|
|
2528
2540
|
var messageOf = (issue) => issue.expected !== void 0 ? "must be " + issue.expected + (issue.code === "required" ? " (was missing)" : "") : issue.code === "required" ? "is missing" : "is invalid";
|
|
2529
2541
|
var definedThrown;
|
|
2542
|
+
var writeBranches = (alternatives) => {
|
|
2543
|
+
const unique = [...new Set(alternatives)];
|
|
2544
|
+
if ([...unique].sort().join() === "false,true")
|
|
2545
|
+
return "boolean";
|
|
2546
|
+
const last = unique.pop();
|
|
2547
|
+
return unique.length ? `${unique.join(", ")} or ${last}` : last;
|
|
2548
|
+
};
|
|
2549
|
+
var alternativesOf = (issues) => issues.flatMap(({ code, expected = "valid" }) => issues.length > 1 && /^(req|disc|union)/.test(code) ? expected.split(/(?:, | or )(?=(?:[^"]*"[^"]*")*[^"]*$)/) : [expected]);
|
|
2550
|
+
var writeListed = (errors) => {
|
|
2551
|
+
const atSubject = {};
|
|
2552
|
+
for (const error of errors) {
|
|
2553
|
+
error.message ??= messageOf(error);
|
|
2554
|
+
const subject = false ? labeledPathOf(error) + error._n : pathOf(error);
|
|
2555
|
+
(atSubject[(subject && subject + " ") + "must be "] ??= []).push(error);
|
|
2556
|
+
}
|
|
2557
|
+
return writeBranches(Object.entries(atSubject).map(([subject, same]) => subject + writeBranches(alternativesOf(same))));
|
|
2558
|
+
};
|
|
2559
|
+
var sharedMessageOf = (errors) => {
|
|
2560
|
+
let shared;
|
|
2561
|
+
for (const error of errors) {
|
|
2562
|
+
if (!isCustomIssue(error) || error._c || shared !== void 0 && error.message !== shared)
|
|
2563
|
+
return;
|
|
2564
|
+
shared = error.message;
|
|
2565
|
+
}
|
|
2566
|
+
return shared;
|
|
2567
|
+
};
|
|
2568
|
+
var ListedIssue = class {
|
|
2569
|
+
code = "union";
|
|
2570
|
+
// private, so only what an issue's readers see is its own
|
|
2571
|
+
#line;
|
|
2572
|
+
constructor(path, data, errors, line, expected, message = expected) {
|
|
2573
|
+
this.path = path;
|
|
2574
|
+
this.data = data;
|
|
2575
|
+
this.errors = errors;
|
|
2576
|
+
this.expected = expected;
|
|
2577
|
+
this.message = message;
|
|
2578
|
+
this.#line = line;
|
|
2579
|
+
}
|
|
2580
|
+
get _l() {
|
|
2581
|
+
return this.#line;
|
|
2582
|
+
}
|
|
2583
|
+
};
|
|
2584
|
+
var movedBy = (errors, path) => errors.map((error) => {
|
|
2585
|
+
const moved = { ...error, path: path(error) };
|
|
2586
|
+
return false ? labeledIssue(moved, error._n) : moved;
|
|
2587
|
+
});
|
|
2588
|
+
var writeFromPath = (path, errors, write) => write(path.length ? movedBy(errors, (error) => error.path.slice(path.length)) : errors);
|
|
2589
|
+
var basesIssueOf = (path, data, errors, describe) => {
|
|
2590
|
+
for (const { code, path: at } of errors) {
|
|
2591
|
+
if (code !== "domain" && code !== "proto" && code !== "unit" || at.length !== path.length || at.some((k, i) => k !== path[i]))
|
|
2592
|
+
return;
|
|
2593
|
+
}
|
|
2594
|
+
const expected = describe(errors.map((error) => error.expected));
|
|
2595
|
+
const issue = new ListedIssue(path.slice(), data, [], void 0, expected, messageOf({ expected }));
|
|
2596
|
+
return false ? labeledAlike(issue, errors) : issue;
|
|
2597
|
+
};
|
|
2598
|
+
var listed = (Issue, path, data, errors, write) => {
|
|
2599
|
+
const line = write(errors);
|
|
2600
|
+
const expected = writeFromPath(path, errors, write);
|
|
2601
|
+
const shared = true ? sharedMessageOf(errors) : void 0;
|
|
2602
|
+
return shared === void 0 ? new Issue(path.slice(), data, errors, line, expected) : new Issue(path.slice(), data, errors, void 0, expected, shared);
|
|
2603
|
+
};
|
|
2604
|
+
var issueWriterOf = (write, describeBases) => true ? /* @__PURE__ */ (() => {
|
|
2605
|
+
class RewrittenIssue extends ListedIssue {
|
|
2606
|
+
_m(prefix) {
|
|
2607
|
+
const moved = movedBy(this.errors, (error) => [
|
|
2608
|
+
...prefix,
|
|
2609
|
+
...error.path
|
|
2610
|
+
]);
|
|
2611
|
+
return new RewrittenIssue([...prefix, ...this.path], this.data, moved, this._l === void 0 ? void 0 : write(moved), this.expected, this.message);
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
return (path, data, errors) => basesIssueOf(path, data, errors, describeBases) ?? listed(RewrittenIssue, path, data, errors, write);
|
|
2615
|
+
})() : (path, data, errors) => basesIssueOf(path, data, errors, describeBases) ?? listed(ListedIssue, path, data, errors, write);
|
|
2616
|
+
var listedIssue = /* @__PURE__ */ issueWriterOf(writeListed, writeBranches);
|
|
2530
2617
|
var removedProblemMessage = "problem was removed in 3.0; write message";
|
|
2531
2618
|
var noBranches = [];
|
|
2532
2619
|
var InternalTraversal = class {
|
|
@@ -2650,7 +2737,7 @@ var InternalTraversal = class {
|
|
|
2650
2737
|
target._merge(errors, this.path);
|
|
2651
2738
|
else {
|
|
2652
2739
|
for (const issue of errors._) {
|
|
2653
|
-
target._.push(
|
|
2740
|
+
target._.push(issue._m ? issue._m(this.path) : notedAs(issue, { ...issue, path: [...this.path, ...issue.path] }));
|
|
2654
2741
|
}
|
|
2655
2742
|
}
|
|
2656
2743
|
return target;
|
|
@@ -2768,6 +2855,21 @@ var silentCtx = {
|
|
|
2768
2855
|
};
|
|
2769
2856
|
var callContext;
|
|
2770
2857
|
var onContextRead;
|
|
2858
|
+
var allowsInBranchBy = (ctx, allows, data, node) => {
|
|
2859
|
+
const pathLength = ctx.path.length;
|
|
2860
|
+
const outerAllowRes = ctx.allowRes;
|
|
2861
|
+
ctx.pushBr();
|
|
2862
|
+
try {
|
|
2863
|
+
const allowed = allows.call(node, data, ctx);
|
|
2864
|
+
return ctx.currentBranch.errN === 0 && allowed;
|
|
2865
|
+
} finally {
|
|
2866
|
+
ctx.popBr();
|
|
2867
|
+
if (ctx.path.length !== pathLength)
|
|
2868
|
+
ctx.path.length = pathLength;
|
|
2869
|
+
if (!outerAllowRes)
|
|
2870
|
+
ctx.allowRes = void 0;
|
|
2871
|
+
}
|
|
2872
|
+
};
|
|
2771
2873
|
|
|
2772
2874
|
// node_modules/arktype/out/chunk-PPY3ZT7D.js
|
|
2773
2875
|
var Validator = class {
|
|
@@ -2784,6 +2886,44 @@ var Validator = class {
|
|
|
2784
2886
|
}
|
|
2785
2887
|
};
|
|
2786
2888
|
var siteOf = ((code, description, message) => ({ code, description, x: message }));
|
|
2889
|
+
var failsListed = ((ctx, firsts, data, issueOf) => {
|
|
2890
|
+
const path = true ? ctx._p ?? ctx.path : ctx._p;
|
|
2891
|
+
const errors = [
|
|
2892
|
+
...new Set(firsts.flatMap((first) => first.errors?.length ? first.errors : first))
|
|
2893
|
+
];
|
|
2894
|
+
const issue = issueOf(path, data, errors);
|
|
2895
|
+
if (!ctx._p)
|
|
2896
|
+
ctx.addError(issue);
|
|
2897
|
+
else
|
|
2898
|
+
ctx._.push(issue);
|
|
2899
|
+
return ctx.failFast;
|
|
2900
|
+
});
|
|
2901
|
+
var stops = () => true;
|
|
2902
|
+
var failsBranches = ((ctx, branches, data, issueOf) => {
|
|
2903
|
+
if (!ctx?._e)
|
|
2904
|
+
return true;
|
|
2905
|
+
if (ctx._e === stops) {
|
|
2906
|
+
return !branches.some((branch) => allowsInBranchBy(ctx, branch, data));
|
|
2907
|
+
}
|
|
2908
|
+
const firsts = [];
|
|
2909
|
+
for (const branch of branches) {
|
|
2910
|
+
let first;
|
|
2911
|
+
if (!ctx._p) {
|
|
2912
|
+
ctx.pushBr();
|
|
2913
|
+
branch(data, ctx);
|
|
2914
|
+
first = ctx.popBr().error;
|
|
2915
|
+
} else {
|
|
2916
|
+
const issues = new (false ? Issues : FirstIssues)();
|
|
2917
|
+
issues._p = ctx._p.slice();
|
|
2918
|
+
branch(data, issues);
|
|
2919
|
+
first = issues._[0];
|
|
2920
|
+
}
|
|
2921
|
+
if (!first)
|
|
2922
|
+
return;
|
|
2923
|
+
firsts.push(first);
|
|
2924
|
+
}
|
|
2925
|
+
return failsListed(ctx, firsts, data, issueOf);
|
|
2926
|
+
});
|
|
2787
2927
|
var applyErrors = (apply, data, config, onFail, Ctx) => {
|
|
2788
2928
|
const ctx = new Ctx(data, config);
|
|
2789
2929
|
apply(data, ctx);
|
|
@@ -2837,8 +2977,8 @@ function sethole1sll4ir138426n() {
|
|
|
2837
2977
|
return true;
|
|
2838
2978
|
}
|
|
2839
2979
|
|
|
2840
|
-
// arktype:~arktype/
|
|
2841
|
-
var [intersectionwidg351n2f7o4Validator, intersectionegwyf90w1alu2Validator, intersection6w7z2u03slcwpValidator, intersection1lvjdu61ps4xl0Validator, intersection1kfvut30tftkihValidator, intersection1y5nwst153l9s2Validator, intersection1r95ni81xgl88zValidator, intersection8yr2o71ja81ufValidator,
|
|
2980
|
+
// arktype:~arktype/rv4jgg08c1b48-tm9ovh0ab6yu7
|
|
2981
|
+
var [intersectionwidg351n2f7o4Validator, intersectionegwyf90w1alu2Validator, intersection6w7z2u03slcwpValidator, intersection1lvjdu61ps4xl0Validator, intersection1kfvut30tftkihValidator, intersection1y5nwst153l9s2Validator, intersection1r95ni81xgl88zValidator, intersection8yr2o71ja81ufValidator, intersection1mu7oxs0oq1x2nValidator, intersectionq8a1jl15p5kbrValidator, union214vmt0pwa2fdValidator, intersection17r4na700khzejValidator, intersection1649hnt0ixrxb1Validator, intersection15ttlhb0m0yhovValidator, intersection10qmong0na8e8rValidator, intersection1nv9uj515bs7itValidator, intersection3rk9um0b729ivValidator, intersection1dmk4z81d1f8mlValidator, intersection1tagcym1fnxkeyValidator, intersection1rp35ue1fi65ccValidator, intersection128bswg1yy3khmValidator, intersection1etdk1h0e9wp9wValidator, intersectionax9iml0n3vs6rValidator, intersection1v7qsxg01pq0unValidator, intersection1vhhd710xh4d2c, intersection1r8kxb1yxb7ek, intersectiongn35sl1ajga14] = (
|
|
2842
2982
|
/* @__NOINLINE__ */
|
|
2843
2983
|
(() => {
|
|
2844
2984
|
const create1sex1811cremth2 = (({ 0: allows, 1: apply }) => {
|
|
@@ -2953,6 +3093,35 @@ var [intersectionwidg351n2f7o4Validator, intersectionegwyf90w1alu2Validator, int
|
|
|
2953
3093
|
}
|
|
2954
3094
|
return true;
|
|
2955
3095
|
}
|
|
3096
|
+
function intersection1h3a6wa0xeftl5Allows(data, ctx) {
|
|
3097
|
+
for (; ; ) {
|
|
3098
|
+
if (!(Number.isFinite(data.id) && ("result" in data && !!/* @__NOINLINE__ */
|
|
3099
|
+
intersectionc5cirx0ys2jaeAllows(data.result)))) {
|
|
3100
|
+
break;
|
|
3101
|
+
}
|
|
3102
|
+
return true;
|
|
3103
|
+
}
|
|
3104
|
+
return false;
|
|
3105
|
+
}
|
|
3106
|
+
function intersectionvr1th20rhw85rAllows(data, ctx) {
|
|
3107
|
+
for (; ; ) {
|
|
3108
|
+
if (!(Number.isFinite(data.id) && /* @__NOINLINE__ */
|
|
3109
|
+
intersectionpk5ov80e6ufcoAllows(data.error))) {
|
|
3110
|
+
break;
|
|
3111
|
+
}
|
|
3112
|
+
return true;
|
|
3113
|
+
}
|
|
3114
|
+
return false;
|
|
3115
|
+
}
|
|
3116
|
+
function intersectionle0bi10xzipedAllows(data, ctx) {
|
|
3117
|
+
for (; ; ) {
|
|
3118
|
+
if (!Number.isFinite(data.id)) {
|
|
3119
|
+
break;
|
|
3120
|
+
}
|
|
3121
|
+
return true;
|
|
3122
|
+
}
|
|
3123
|
+
return false;
|
|
3124
|
+
}
|
|
2956
3125
|
function intersection1kfvut30tftkihAllows(data, ctx) {
|
|
2957
3126
|
for (; ; ) {
|
|
2958
3127
|
if (!Array.isArray(data)) {
|
|
@@ -3630,6 +3799,12 @@ var [intersectionwidg351n2f7o4Validator, intersectionegwyf90w1alu2Validator, int
|
|
|
3630
3799
|
}
|
|
3631
3800
|
return false;
|
|
3632
3801
|
}
|
|
3802
|
+
function intersectiont0fgct0m9vuomApply(data, ctx) {
|
|
3803
|
+
return (Number.isFinite(data.id) || !failsKey(ctx, data, "id", "domain", "a number")) && (data.success === false || !failsKey(ctx, data, "success", "unit", "false")) && !ctx._k(intersectionpk5ov80e6ufcoApply, data, "error", "an object");
|
|
3804
|
+
}
|
|
3805
|
+
function intersection9p85a71ewvl3lApply(data, ctx) {
|
|
3806
|
+
return (Number.isFinite(data.id) || !failsKey(ctx, data, "id", "domain", "a number")) && (data.success === true || !failsKey(ctx, data, "success", "unit", "true")) && ("result" in data ? !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "result") : !failsKey(ctx, data, "result", "required", "present"));
|
|
3807
|
+
}
|
|
3633
3808
|
function templateAllows(data, ctx) {
|
|
3634
3809
|
return typeof data === "string" && templateR0.test(data);
|
|
3635
3810
|
}
|
|
@@ -3938,6 +4113,21 @@ var [intersectionwidg351n2f7o4Validator, intersectionegwyf90w1alu2Validator, int
|
|
|
3938
4113
|
}
|
|
3939
4114
|
return !ctx._e(data, "discriminant", "boolean");
|
|
3940
4115
|
}
|
|
4116
|
+
function unionywppdn0x74r6hAllows(data, ctx) {
|
|
4117
|
+
switch (data?.success) {
|
|
4118
|
+
case false:
|
|
4119
|
+
return (
|
|
4120
|
+
/* @__NOINLINE__ */
|
|
4121
|
+
intersectionvr1th20rhw85rAllows(data)
|
|
4122
|
+
);
|
|
4123
|
+
case true:
|
|
4124
|
+
return (
|
|
4125
|
+
/* @__NOINLINE__ */
|
|
4126
|
+
intersection1h3a6wa0xeftl5Allows(data)
|
|
4127
|
+
);
|
|
4128
|
+
}
|
|
4129
|
+
return false;
|
|
4130
|
+
}
|
|
3941
4131
|
function union1c2nms0t1fs1sAllows(data, ctx) {
|
|
3942
4132
|
switch (data?.type) {
|
|
3943
4133
|
case "docker":
|
|
@@ -4090,6 +4280,21 @@ var [intersectionwidg351n2f7o4Validator, intersectionegwyf90w1alu2Validator, int
|
|
|
4090
4280
|
}, function(data, ctx) {
|
|
4091
4281
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4092
4282
|
return (typeof data.error === "string" || !fails0(ctx, data, "error")) && (typeof data.level === "string" || !fails0(ctx, data, "level"));
|
|
4283
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4284
|
+
switch (data) {
|
|
4285
|
+
case null:
|
|
4286
|
+
case void 0:
|
|
4287
|
+
break;
|
|
4288
|
+
default:
|
|
4289
|
+
data.type;
|
|
4290
|
+
if ((data instanceof Object || Object(data) === data) && typeof data.type === "string") {
|
|
4291
|
+
return true;
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
return false;
|
|
4295
|
+
}, function(data, ctx) {
|
|
4296
|
+
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4297
|
+
return typeof data.type === "string" || !fails0(ctx, data, "type");
|
|
4093
4298
|
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4094
4299
|
switch (data) {
|
|
4095
4300
|
case null:
|
|
@@ -4097,17 +4302,47 @@ var [intersectionwidg351n2f7o4Validator, intersectionegwyf90w1alu2Validator, int
|
|
|
4097
4302
|
break;
|
|
4098
4303
|
default:
|
|
4099
4304
|
data.id;
|
|
4100
|
-
if ((data instanceof Object || Object(data) === data) && (
|
|
4101
|
-
intersectionc5cirx0ys2jaeAllows(data.
|
|
4102
|
-
intersectionc5cirx0ys2jaeAllows(data.event)) && (!("error" in data) || !!/* @__NOINLINE__ */
|
|
4103
|
-
intersectionpk5ov80e6ufcoAllows(data.error)))) {
|
|
4305
|
+
if ((data instanceof Object || Object(data) === data) && (Number.isFinite(data.id) && ("event" in data && !!/* @__NOINLINE__ */
|
|
4306
|
+
intersectionc5cirx0ys2jaeAllows(data.event)))) {
|
|
4104
4307
|
return true;
|
|
4105
4308
|
}
|
|
4106
4309
|
}
|
|
4107
4310
|
return false;
|
|
4108
4311
|
}, function(data, ctx) {
|
|
4109
4312
|
if (!isObjectData(data)) return notObjectData(data, ctx);
|
|
4110
|
-
return (
|
|
4313
|
+
return (Number.isFinite(data.id) || !failsKey(ctx, data, "id", "domain", "a number")) && ("event" in data ? !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "event") : !failsKey(ctx, data, "event", "required", "present"));
|
|
4314
|
+
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4315
|
+
switch (data?.type) {
|
|
4316
|
+
case "result":
|
|
4317
|
+
return (
|
|
4318
|
+
/* @__NOINLINE__ */
|
|
4319
|
+
unionywppdn0x74r6hAllows(data)
|
|
4320
|
+
);
|
|
4321
|
+
case "pong":
|
|
4322
|
+
return (
|
|
4323
|
+
/* @__NOINLINE__ */
|
|
4324
|
+
intersectionle0bi10xzipedAllows(data)
|
|
4325
|
+
);
|
|
4326
|
+
}
|
|
4327
|
+
return false;
|
|
4328
|
+
}, function(data, ctx) {
|
|
4329
|
+
switch (data?.type) {
|
|
4330
|
+
case "result": {
|
|
4331
|
+
switch (data?.success) {
|
|
4332
|
+
case false: {
|
|
4333
|
+
return (Number.isFinite(data.id) || !failsKey(ctx, data, "id", "domain", "a number")) && !ctx._k(intersectionpk5ov80e6ufcoApply, data, "error", "an object");
|
|
4334
|
+
}
|
|
4335
|
+
case true: {
|
|
4336
|
+
return (Number.isFinite(data.id) || !failsKey(ctx, data, "id", "domain", "a number")) && ("result" in data ? !ctx._k(intersectionc5cirx0ys2jaeAllows, data, "result") : !failsKey(ctx, data, "result", "required", "present"));
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
return Object(data) === data ? !ctx._k((data2, ctx2) => !ctx2._e(data2, "discriminant", "boolean"), data, "success") : !failsBranches(ctx, [intersectiont0fgct0m9vuomApply, intersection9p85a71ewvl3lApply], data, listedIssue);
|
|
4340
|
+
}
|
|
4341
|
+
case "pong": {
|
|
4342
|
+
return Number.isFinite(data.id) || !failsKey(ctx, data, "id", "domain", "a number");
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
return Object(data) === data ? !ctx._k((data2, ctx2) => !ctx2._e(data2, "discriminant", '"result" or "pong"'), data, "type") : !ctx._e(data, "union", "an object");
|
|
4111
4346
|
}]), create1sex1811cremth2([function(data, ctx) {
|
|
4112
4347
|
switch (data) {
|
|
4113
4348
|
case null:
|
|
@@ -4424,7 +4659,7 @@ var create1sfgs3s1wvt6nb = (({ 0: allows, 1: apply }) => {
|
|
|
4424
4659
|
return validator;
|
|
4425
4660
|
});
|
|
4426
4661
|
|
|
4427
|
-
// arktype:~arktype/
|
|
4662
|
+
// arktype:~arktype/141z4sf0c2cbgh-xin31g1b340jz
|
|
4428
4663
|
var created4;
|
|
4429
4664
|
var factory1 = ((p0, p1) => {
|
|
4430
4665
|
checkHeld(p0);
|
|
@@ -4447,7 +4682,7 @@ var held = (validator, ...inputs) => {
|
|
|
4447
4682
|
// src/errors.ts
|
|
4448
4683
|
var errorMeanings = {
|
|
4449
4684
|
usage_error: "Wrong command, flag or argument",
|
|
4450
|
-
config_error: "A config file is invalid; the message names
|
|
4685
|
+
config_error: "A config file is invalid or unreadable; the message names its path",
|
|
4451
4686
|
context_not_found: "The selected or named context is not defined",
|
|
4452
4687
|
no_context: "No context is selected",
|
|
4453
4688
|
token_missing: "The active context has no stored token",
|
|
@@ -4463,7 +4698,7 @@ var errorMeanings = {
|
|
|
4463
4698
|
config_dir_missing: "The config folder has no readable .HA_VERSION",
|
|
4464
4699
|
not_found: "A named thing does not exist, such as an entity, area, service, app or release",
|
|
4465
4700
|
not_a_binary: "`hactl upgrade` was run from source, not from a release binary",
|
|
4466
|
-
upgrade_not_writable: "`hactl upgrade` cannot
|
|
4701
|
+
upgrade_not_writable: "`hactl upgrade` cannot stage or replace the binary",
|
|
4467
4702
|
download_failed: "The downloaded binary failed its digest or version check"
|
|
4468
4703
|
};
|
|
4469
4704
|
var HactlError = class extends Error {
|
|
@@ -4612,12 +4847,22 @@ var url = /* @__PURE__ */ held(create1sfgs3s1wvt6nb(intersection1vhhd710xh4d2c),
|
|
|
4612
4847
|
if (hasCredentials(value)) {
|
|
4613
4848
|
return context.reject({ expected: "a URL without a user name or password", actual: "" });
|
|
4614
4849
|
}
|
|
4615
|
-
|
|
4850
|
+
if (!intersection1649hnt0ixrxb1Validator.allows(value)) {
|
|
4851
|
+
return context.reject({ expected: "an http or https URL" });
|
|
4852
|
+
}
|
|
4853
|
+
const parsed = new URL(value);
|
|
4854
|
+
if (parsed.username !== "" || parsed.password !== "") {
|
|
4855
|
+
return context.reject({ expected: "a URL without a user name or password", actual: "" });
|
|
4856
|
+
}
|
|
4857
|
+
return !/[?#]/.test(parsed.href) || context.reject({
|
|
4858
|
+
expected: "a base URL without a query or fragment",
|
|
4859
|
+
actual: ""
|
|
4860
|
+
});
|
|
4616
4861
|
}));
|
|
4617
4862
|
var contextDefinition = factory1(url, contextNamePattern);
|
|
4618
4863
|
var contextsFile = /* @__PURE__ */ held(create1sfgs3s1wvt6nb(intersectiongn35sl1ajga14), contextDefinition);
|
|
4619
4864
|
function baseUrl(definition) {
|
|
4620
|
-
return definition.url.replace(/\/+$/, "");
|
|
4865
|
+
return new URL(definition.url).href.replace(/\/+$/, "");
|
|
4621
4866
|
}
|
|
4622
4867
|
async function loadContexts(folder) {
|
|
4623
4868
|
const path = contextsPath(folder);
|
|
@@ -4666,30 +4911,34 @@ import { stat } from "node:fs/promises";
|
|
|
4666
4911
|
import { dirname as dirname2, join as join3 } from "node:path";
|
|
4667
4912
|
var projectFileName = ".hactl.json";
|
|
4668
4913
|
async function findProjectFile(cwd) {
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4914
|
+
for (let folder = cwd; ; folder = dirname2(folder)) {
|
|
4915
|
+
const path = join3(folder, projectFileName);
|
|
4916
|
+
try {
|
|
4917
|
+
if ((await stat(path)).isFile()) {
|
|
4918
|
+
return path;
|
|
4919
|
+
}
|
|
4920
|
+
} catch (exc) {
|
|
4921
|
+
if (!isNotFound(exc)) {
|
|
4922
|
+
throw settingsIoError(path, exc);
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
if (dirname2(folder) === folder) {
|
|
4926
|
+
return void 0;
|
|
4927
|
+
}
|
|
4672
4928
|
}
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
(stats) => stats.isFile(),
|
|
4677
|
-
(exc) => {
|
|
4678
|
-
if (isNotFound(exc)) {
|
|
4679
|
-
return false;
|
|
4680
|
-
}
|
|
4681
|
-
throw exc;
|
|
4682
|
-
}
|
|
4683
|
-
)
|
|
4684
|
-
)
|
|
4685
|
-
);
|
|
4686
|
-
return candidates[isFile.indexOf(true)];
|
|
4929
|
+
}
|
|
4930
|
+
function settingsIoError(path, exc) {
|
|
4931
|
+
return new ConfigError(`${path}: ${exc instanceof Error ? exc.message : String(exc)}`);
|
|
4687
4932
|
}
|
|
4688
4933
|
async function loadSettingsFile(path) {
|
|
4689
|
-
|
|
4934
|
+
try {
|
|
4935
|
+
return await readJsonFile(path, intersection1v7qsxg01pq0unValidator);
|
|
4936
|
+
} catch (exc) {
|
|
4937
|
+
throw exc instanceof ConfigError ? exc : settingsIoError(path, exc);
|
|
4938
|
+
}
|
|
4690
4939
|
}
|
|
4691
|
-
async function loadSelection(environment) {
|
|
4692
|
-
const projectPath = await findProjectFile(environment.cwd);
|
|
4940
|
+
async function loadSelection(environment, planned) {
|
|
4941
|
+
const projectPath = planned?.source === "project" ? planned.path : await findProjectFile(environment.cwd);
|
|
4693
4942
|
const files = [
|
|
4694
4943
|
...projectPath === void 0 ? [] : [{ source: "project", path: projectPath }],
|
|
4695
4944
|
{
|
|
@@ -4698,7 +4947,9 @@ async function loadSelection(environment) {
|
|
|
4698
4947
|
}
|
|
4699
4948
|
];
|
|
4700
4949
|
const names = await Promise.all(
|
|
4701
|
-
files.map(
|
|
4950
|
+
files.map(
|
|
4951
|
+
async (file2) => planned?.source === file2.source ? planned.name : (await loadSettingsFile(file2.path))?.context
|
|
4952
|
+
)
|
|
4702
4953
|
);
|
|
4703
4954
|
const index = names.findIndex((name2) => name2 !== void 0);
|
|
4704
4955
|
const file = files[index];
|
|
@@ -4708,10 +4959,12 @@ async function loadSelection(environment) {
|
|
|
4708
4959
|
async function setGlobalContext(folder, name) {
|
|
4709
4960
|
await writeJsonFile(globalSettingsPath(folder), name === void 0 ? {} : { context: name });
|
|
4710
4961
|
}
|
|
4711
|
-
async function setProjectContext(
|
|
4712
|
-
const path = join3(cwd, projectFileName);
|
|
4962
|
+
async function setProjectContext(environment, name) {
|
|
4963
|
+
const path = join3(environment.cwd, projectFileName);
|
|
4713
4964
|
await loadSettingsFile(path);
|
|
4965
|
+
const selection = await loadSelection(environment, { name, source: "project", path });
|
|
4714
4966
|
await writeJsonFile(path, { context: name }, 438);
|
|
4967
|
+
return selection;
|
|
4715
4968
|
}
|
|
4716
4969
|
async function clearGlobalContext(folder, name) {
|
|
4717
4970
|
if ((await loadSettingsFile(globalSettingsPath(folder)))?.context === name) {
|
|
@@ -4767,11 +5020,25 @@ function runTool(path, args, env, input) {
|
|
|
4767
5020
|
const child = spawn(path, args, { env, stdio: ["pipe", "pipe", "pipe"] });
|
|
4768
5021
|
let stdout = "";
|
|
4769
5022
|
let stderr = "";
|
|
5023
|
+
let stdinError = false;
|
|
4770
5024
|
child.stdout.setEncoding("utf8").on("data", (chunk) => stdout += chunk);
|
|
4771
5025
|
child.stderr.setEncoding("utf8").on("data", (chunk) => stderr += chunk);
|
|
4772
5026
|
child.on("error", reject);
|
|
4773
|
-
child.on("
|
|
4774
|
-
|
|
5027
|
+
child.stdin.on("error", () => {
|
|
5028
|
+
stdinError = true;
|
|
5029
|
+
});
|
|
5030
|
+
child.on("close", (code) => {
|
|
5031
|
+
if (code === 0 && stdinError) {
|
|
5032
|
+
resolve({ code: 1, stdout, stderr: "could not write to the tool stdin" });
|
|
5033
|
+
} else {
|
|
5034
|
+
resolve({ code: code ?? 1, stdout, stderr });
|
|
5035
|
+
}
|
|
5036
|
+
});
|
|
5037
|
+
if (input === void 0) {
|
|
5038
|
+
child.stdin.destroy();
|
|
5039
|
+
} else {
|
|
5040
|
+
child.stdin.end(input);
|
|
5041
|
+
}
|
|
4775
5042
|
});
|
|
4776
5043
|
}
|
|
4777
5044
|
|
|
@@ -4974,10 +5241,7 @@ var connectWebSocket = (url2, events) => {
|
|
|
4974
5241
|
let cause;
|
|
4975
5242
|
const unwatch = watchHandshake(url2, (message) => cause = message);
|
|
4976
5243
|
const socket = new WebSocket(url2);
|
|
4977
|
-
socket.onopen =
|
|
4978
|
-
unwatch();
|
|
4979
|
-
events.opened();
|
|
4980
|
-
};
|
|
5244
|
+
socket.onopen = unwatch;
|
|
4981
5245
|
socket.onmessage = (event) => events.received(String(event.data));
|
|
4982
5246
|
socket.onerror = () => events.closed(cause ?? "connection failed");
|
|
4983
5247
|
socket.onclose = (event) => {
|
|
@@ -5011,6 +5275,70 @@ var keyBegin = new RegExp(`-----BEGIN ${keyLabel}`);
|
|
|
5011
5275
|
var keyEnd = new RegExp(`-----END ${keyLabel}`);
|
|
5012
5276
|
var keyBlock = new RegExp(`-----BEGIN ${keyLabel}[\\s\\S]*?(?:-----END ${keyLabel}|$)`, "g");
|
|
5013
5277
|
var parameter = /([?&#;])([^=&#?;\s"'<>/]+)=([^&#\s"'<>]+)/g;
|
|
5278
|
+
var credentialPath = /\/api\/(?:webhook|tts_proxy)\//g;
|
|
5279
|
+
var wordBoundary = /[\s"'<>]/;
|
|
5280
|
+
function pathCredentialEnd(text5, path, start) {
|
|
5281
|
+
let word = path;
|
|
5282
|
+
while (word > 0 && !wordBoundary.test(text5.charAt(word - 1))) {
|
|
5283
|
+
word--;
|
|
5284
|
+
}
|
|
5285
|
+
const prefix = text5.slice(word, path);
|
|
5286
|
+
const markdown = prefix.lastIndexOf("](");
|
|
5287
|
+
const destination = markdown === -1 ? prefix : prefix.slice(markdown + 2);
|
|
5288
|
+
const queryValue = /[?#][^?#]*=/.test(destination);
|
|
5289
|
+
let depth = 0;
|
|
5290
|
+
for (const [char] of destination.matchAll(/\\.|[()]/g)) {
|
|
5291
|
+
depth += char === "(" ? 1 : char === ")" ? -1 : 0;
|
|
5292
|
+
}
|
|
5293
|
+
for (let i = start; i < text5.length; i++) {
|
|
5294
|
+
const char = text5.charAt(i);
|
|
5295
|
+
if (char === "\\") {
|
|
5296
|
+
let next = i + 1;
|
|
5297
|
+
while (text5.charAt(next) === "\\") {
|
|
5298
|
+
next++;
|
|
5299
|
+
}
|
|
5300
|
+
const escaped = text5.charAt(next);
|
|
5301
|
+
if (/["nrt]/.test(escaped)) {
|
|
5302
|
+
return i;
|
|
5303
|
+
}
|
|
5304
|
+
if (/\s/.test(escaped)) {
|
|
5305
|
+
return next;
|
|
5306
|
+
}
|
|
5307
|
+
i = next;
|
|
5308
|
+
} else if (wordBoundary.test(char) || "/?#".includes(char) || char === "&" && queryValue || char === "," && /\s/.test(text5.charAt(i + 1))) {
|
|
5309
|
+
return i;
|
|
5310
|
+
} else if (markdown !== -1) {
|
|
5311
|
+
if (char === ")" && depth === 0) {
|
|
5312
|
+
return i;
|
|
5313
|
+
}
|
|
5314
|
+
depth += char === "(" ? 1 : char === ")" ? -1 : 0;
|
|
5315
|
+
}
|
|
5316
|
+
}
|
|
5317
|
+
return text5.length;
|
|
5318
|
+
}
|
|
5319
|
+
function redactCredentialPaths(text5, hide) {
|
|
5320
|
+
let redacted2 = "";
|
|
5321
|
+
let cursor = 0;
|
|
5322
|
+
for (const match of text5.matchAll(credentialPath)) {
|
|
5323
|
+
if (match.index < cursor) {
|
|
5324
|
+
continue;
|
|
5325
|
+
}
|
|
5326
|
+
const start = match.index + match[0].length;
|
|
5327
|
+
const end = pathCredentialEnd(text5, match.index, start);
|
|
5328
|
+
if (end > start) {
|
|
5329
|
+
redacted2 += text5.slice(cursor, start) + hide(text5.slice(start, end));
|
|
5330
|
+
cursor = end;
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
return redacted2 + text5.slice(cursor);
|
|
5334
|
+
}
|
|
5335
|
+
function decodeParameterName(name) {
|
|
5336
|
+
try {
|
|
5337
|
+
return decodeURIComponent(name);
|
|
5338
|
+
} catch {
|
|
5339
|
+
return name;
|
|
5340
|
+
}
|
|
5341
|
+
}
|
|
5014
5342
|
function redactString(input, token, found) {
|
|
5015
5343
|
const literal = token?.reveal();
|
|
5016
5344
|
const text5 = literal ? input.replaceAll(literal, hidden) : input;
|
|
@@ -5019,7 +5347,7 @@ function redactString(input, token, found) {
|
|
|
5019
5347
|
return hidden;
|
|
5020
5348
|
};
|
|
5021
5349
|
const hideAfter = (_, start, secret) => `${start}${hide(secret)}`;
|
|
5022
|
-
|
|
5350
|
+
const shaped = text5.replace(keyBlock, hide).replace(/\b(Bearer[ \t]+)([A-Za-z0-9._~+/=-]+)/gi, hideAfter).replace(/eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g, hide).replace(/\bMT:[0-9A-Z.*-]{5,}/g, hide).replace(/(WIFI:(?:(?:\\.|[^\\;\n])*;)*?P:)((?:\\.|[^\\;\n"'])+)/g, hideAfter).replace(
|
|
5023
5351
|
/\b([a-z][a-z0-9+.-]*:\/\/)([^/\s?#"'<>]+)@/gi,
|
|
5024
5352
|
(_, scheme, userinfo) => {
|
|
5025
5353
|
const password = userinfo.slice(userinfo.indexOf(":") + 1);
|
|
@@ -5028,9 +5356,11 @@ function redactString(input, token, found) {
|
|
|
5028
5356
|
}
|
|
5029
5357
|
return `${scheme}${hide(userinfo)}@`;
|
|
5030
5358
|
}
|
|
5031
|
-
)
|
|
5032
|
-
|
|
5033
|
-
const
|
|
5359
|
+
);
|
|
5360
|
+
return redactCredentialPaths(shaped, hide).replace(/(\/bot)(\d+:[A-Za-z0-9_-]+)/g, hideAfter).replace(parameter, (match, separator, name, value) => {
|
|
5361
|
+
const decoded = decodeParameterName(name);
|
|
5362
|
+
const kind = credential(decoded);
|
|
5363
|
+
const secret = kind === "one" || kind === "many" && !isCount(value) || parameterNames.test(normalize(decoded));
|
|
5034
5364
|
return secret ? `${separator}${name}=${hide(value)}` : match;
|
|
5035
5365
|
});
|
|
5036
5366
|
}
|
|
@@ -5169,16 +5499,22 @@ function collectSecrets(states) {
|
|
|
5169
5499
|
return secrets;
|
|
5170
5500
|
}
|
|
5171
5501
|
var minInside = 4;
|
|
5172
|
-
function hideIn(text5, secrets) {
|
|
5502
|
+
function hideIn(text5, secrets, literal) {
|
|
5173
5503
|
if (secrets.has(text5)) {
|
|
5174
5504
|
return hidden;
|
|
5175
5505
|
}
|
|
5176
5506
|
const ranges = [];
|
|
5507
|
+
const find = (secret) => {
|
|
5508
|
+
for (let at = text5.indexOf(secret); at !== -1; at = text5.indexOf(secret, at + 1)) {
|
|
5509
|
+
ranges.push([at, at + secret.length]);
|
|
5510
|
+
}
|
|
5511
|
+
};
|
|
5512
|
+
if (literal) {
|
|
5513
|
+
find(literal);
|
|
5514
|
+
}
|
|
5177
5515
|
for (const secret of secrets) {
|
|
5178
|
-
if (secret.length >= minInside) {
|
|
5179
|
-
|
|
5180
|
-
ranges.push([at, at + secret.length]);
|
|
5181
|
-
}
|
|
5516
|
+
if (secret !== literal && secret.length >= minInside) {
|
|
5517
|
+
find(secret);
|
|
5182
5518
|
}
|
|
5183
5519
|
}
|
|
5184
5520
|
ranges.sort(([a], [b]) => a - b);
|
|
@@ -5192,24 +5528,25 @@ function hideIn(text5, secrets) {
|
|
|
5192
5528
|
}
|
|
5193
5529
|
return result + text5.slice(end);
|
|
5194
5530
|
}
|
|
5195
|
-
function hideSecrets(value, secrets) {
|
|
5531
|
+
function hideSecrets(value, secrets, token) {
|
|
5532
|
+
const literal = token?.reveal();
|
|
5196
5533
|
if (typeof value === "string") {
|
|
5197
|
-
return hideIn(value, secrets);
|
|
5534
|
+
return hideIn(value, secrets, literal);
|
|
5198
5535
|
}
|
|
5199
5536
|
if (typeof value === "number") {
|
|
5200
|
-
const shown = hideIn(String(value), secrets);
|
|
5537
|
+
const shown = hideIn(String(value), secrets, literal);
|
|
5201
5538
|
return shown === String(value) ? value : shown;
|
|
5202
5539
|
}
|
|
5203
5540
|
if (Array.isArray(value)) {
|
|
5204
|
-
return value.map((item) => hideSecrets(item, secrets));
|
|
5541
|
+
return value.map((item) => hideSecrets(item, secrets, token));
|
|
5205
5542
|
}
|
|
5206
5543
|
if (typeof value !== "object" || value === null) {
|
|
5207
5544
|
return value;
|
|
5208
5545
|
}
|
|
5209
5546
|
return Object.fromEntries(
|
|
5210
5547
|
Object.entries(value).map(([key, item]) => [
|
|
5211
|
-
hideIn(key, secrets),
|
|
5212
|
-
hideSecrets(item, secrets)
|
|
5548
|
+
hideIn(key, secrets, literal),
|
|
5549
|
+
hideSecrets(item, secrets, token)
|
|
5213
5550
|
])
|
|
5214
5551
|
);
|
|
5215
5552
|
}
|
|
@@ -5259,13 +5596,23 @@ function createLineRedactor(token) {
|
|
|
5259
5596
|
// src/ssh.ts
|
|
5260
5597
|
var sshFailure = 255;
|
|
5261
5598
|
function sshArgs(target, command5) {
|
|
5262
|
-
return [
|
|
5599
|
+
return [
|
|
5600
|
+
"-o",
|
|
5601
|
+
"BatchMode=yes",
|
|
5602
|
+
"-o",
|
|
5603
|
+
"StrictHostKeyChecking=yes",
|
|
5604
|
+
"-o",
|
|
5605
|
+
"ConnectTimeout=10",
|
|
5606
|
+
"--",
|
|
5607
|
+
target,
|
|
5608
|
+
command5
|
|
5609
|
+
];
|
|
5263
5610
|
}
|
|
5264
5611
|
function createSshRunner(env) {
|
|
5265
5612
|
return async (target, command5) => {
|
|
5266
5613
|
const path = await findOnPath("ssh", env);
|
|
5267
5614
|
if (path === void 0) {
|
|
5268
|
-
throw new SshFailedError(
|
|
5615
|
+
throw new SshFailedError(`ssh to ${target} failed: \`ssh\` was not found on PATH`);
|
|
5269
5616
|
}
|
|
5270
5617
|
return runTool(path, sshArgs(target, command5), env);
|
|
5271
5618
|
};
|
|
@@ -5273,18 +5620,18 @@ function createSshRunner(env) {
|
|
|
5273
5620
|
function shellQuote(value) {
|
|
5274
5621
|
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
5275
5622
|
}
|
|
5276
|
-
async function runRemote(ssh, target, command5) {
|
|
5623
|
+
async function runRemote(ssh, target, command5, token) {
|
|
5277
5624
|
const result = await ssh(target, command5);
|
|
5278
5625
|
if (result.code !== sshFailure) {
|
|
5279
5626
|
return result;
|
|
5280
5627
|
}
|
|
5281
|
-
const reason = redactText(result.stderr.trim().split("\n").at(-1) ?? "");
|
|
5628
|
+
const reason = redactText(result.stderr.trim().split("\n").at(-1) ?? "", token);
|
|
5282
5629
|
const hostKey = /Host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED/.test(
|
|
5283
5630
|
result.stderr
|
|
5284
5631
|
);
|
|
5285
5632
|
throw new SshFailedError(
|
|
5286
5633
|
`ssh to ${target} failed${reason === "" ? "" : `: ${reason}`}`,
|
|
5287
|
-
hostKey ? `
|
|
5634
|
+
hostKey ? `Verify the host key and accept it with \`ssh ${target}\` first.` : `Set up key-based login for \`ssh ${target}\`.`
|
|
5288
5635
|
);
|
|
5289
5636
|
}
|
|
5290
5637
|
|
|
@@ -5383,6 +5730,10 @@ function buildProcessContext() {
|
|
|
5383
5730
|
resolve();
|
|
5384
5731
|
});
|
|
5385
5732
|
}),
|
|
5733
|
+
onInterrupt(listener) {
|
|
5734
|
+
process.on("SIGINT", listener);
|
|
5735
|
+
return () => process.off("SIGINT", listener);
|
|
5736
|
+
},
|
|
5386
5737
|
binary: isSea() ? process.execPath : void 0,
|
|
5387
5738
|
platform: `${process.platform}-${process.arch}`
|
|
5388
5739
|
};
|
|
@@ -5429,7 +5780,13 @@ function openHa(connect, context, token, timeoutMs2 = 1e4) {
|
|
|
5429
5780
|
return timer;
|
|
5430
5781
|
};
|
|
5431
5782
|
const unreachable = (reason) => new UnreachableError(`cannot reach ${url2}: ${reason}`);
|
|
5432
|
-
const notHa2 = () =>
|
|
5783
|
+
const notHa2 = (value) => {
|
|
5784
|
+
const id = typeof value === "object" && value !== null && "id" in value ? value.id : void 0;
|
|
5785
|
+
const command5 = typeof id === "number" ? (pending.get(id) ?? listeners.get(id))?.command : void 0;
|
|
5786
|
+
return new HaError(
|
|
5787
|
+
`${url2} did not answer like Home Assistant${command5 === void 0 ? "" : ` for ${command5}`}`
|
|
5788
|
+
);
|
|
5789
|
+
};
|
|
5433
5790
|
const send = (command5, parameters, listener) => new Promise((resolve, reject) => {
|
|
5434
5791
|
if (finished) {
|
|
5435
5792
|
reject(lost ?? unreachable("the connection is closed"));
|
|
@@ -5458,10 +5815,14 @@ function openHa(connect, context, token, timeoutMs2 = 1e4) {
|
|
|
5458
5815
|
timers.delete(timer);
|
|
5459
5816
|
resolve(result);
|
|
5460
5817
|
},
|
|
5461
|
-
reject
|
|
5818
|
+
reject: (error) => {
|
|
5819
|
+
clearTimeout(timer);
|
|
5820
|
+
timers.delete(timer);
|
|
5821
|
+
reject(error);
|
|
5822
|
+
}
|
|
5462
5823
|
});
|
|
5463
5824
|
if (listener !== void 0) {
|
|
5464
|
-
listeners.set(id, listener);
|
|
5825
|
+
listeners.set(id, { command: command5, listener });
|
|
5465
5826
|
}
|
|
5466
5827
|
socket?.send(JSON.stringify({ ...parameters, id, type: command5 }));
|
|
5467
5828
|
});
|
|
@@ -5513,7 +5874,6 @@ function openHa(connect, context, token, timeoutMs2 = 1e4) {
|
|
|
5513
5874
|
() => fail(unreachable(`no answer within ${timeoutMs2 / 1e3} seconds`))
|
|
5514
5875
|
);
|
|
5515
5876
|
socket = connect(url2, {
|
|
5516
|
-
opened: () => void 0,
|
|
5517
5877
|
closed: (reason) => fail(unreachable(redactText(reason, token))),
|
|
5518
5878
|
received: (data) => {
|
|
5519
5879
|
let parsed;
|
|
@@ -5523,9 +5883,9 @@ function openHa(connect, context, token, timeoutMs2 = 1e4) {
|
|
|
5523
5883
|
fail(notHa2());
|
|
5524
5884
|
return;
|
|
5525
5885
|
}
|
|
5526
|
-
const msg =
|
|
5886
|
+
const msg = intersection1mu7oxs0oq1x2nValidator(parsed);
|
|
5527
5887
|
if (msg instanceof Issues) {
|
|
5528
|
-
fail(notHa2());
|
|
5888
|
+
fail(notHa2(parsed));
|
|
5529
5889
|
return;
|
|
5530
5890
|
}
|
|
5531
5891
|
switch (msg.type) {
|
|
@@ -5545,39 +5905,42 @@ function openHa(connect, context, token, timeoutMs2 = 1e4) {
|
|
|
5545
5905
|
)
|
|
5546
5906
|
);
|
|
5547
5907
|
return;
|
|
5548
|
-
case "pong":
|
|
5549
|
-
const request = msg.id === void 0 ? void 0 : pending.get(msg.id);
|
|
5550
|
-
if (request !== void 0 && msg.id !== void 0) {
|
|
5551
|
-
pending.delete(msg.id);
|
|
5552
|
-
request.resolve(void 0);
|
|
5553
|
-
}
|
|
5554
|
-
return;
|
|
5555
|
-
}
|
|
5908
|
+
case "pong":
|
|
5556
5909
|
case "result": {
|
|
5557
|
-
const
|
|
5558
|
-
if (
|
|
5910
|
+
const reply = union214vmt0pwa2fdValidator(parsed);
|
|
5911
|
+
if (reply instanceof Issues) {
|
|
5912
|
+
fail(notHa2(parsed));
|
|
5913
|
+
return;
|
|
5914
|
+
}
|
|
5915
|
+
const request = pending.get(reply.id);
|
|
5916
|
+
if (request === void 0) {
|
|
5559
5917
|
return;
|
|
5560
5918
|
}
|
|
5561
|
-
pending.delete(
|
|
5562
|
-
if (
|
|
5563
|
-
request.resolve(
|
|
5919
|
+
pending.delete(reply.id);
|
|
5920
|
+
if (reply.type === "pong") {
|
|
5921
|
+
request.resolve(void 0);
|
|
5922
|
+
} else if (reply.success) {
|
|
5923
|
+
request.resolve(reply.result);
|
|
5564
5924
|
} else {
|
|
5565
|
-
const reason = redactText(
|
|
5925
|
+
const reason = redactText(reply.error.message, token);
|
|
5566
5926
|
const error = new HaCommandError(
|
|
5567
5927
|
`${request.command} failed: ${reason}`,
|
|
5568
|
-
|
|
5569
|
-
|
|
5928
|
+
reply.error.code,
|
|
5929
|
+
reply.error.translation_key ?? void 0
|
|
5570
5930
|
);
|
|
5571
5931
|
request.reject(error);
|
|
5572
|
-
fail(error);
|
|
5573
5932
|
}
|
|
5574
5933
|
return;
|
|
5575
5934
|
}
|
|
5576
|
-
case "event":
|
|
5577
|
-
|
|
5578
|
-
|
|
5935
|
+
case "event": {
|
|
5936
|
+
const event = intersectionq8a1jl15p5kbrValidator(parsed);
|
|
5937
|
+
if (event instanceof Issues) {
|
|
5938
|
+
fail(notHa2(parsed));
|
|
5939
|
+
return;
|
|
5579
5940
|
}
|
|
5941
|
+
listeners.get(event.id)?.listener(event.event);
|
|
5580
5942
|
return;
|
|
5943
|
+
}
|
|
5581
5944
|
default:
|
|
5582
5945
|
}
|
|
5583
5946
|
}
|
|
@@ -5590,16 +5953,18 @@ async function withHa(context, use) {
|
|
|
5590
5953
|
const { context: target, token } = await resolveActiveContext(context);
|
|
5591
5954
|
const session = await openHa(context.connect, target, token);
|
|
5592
5955
|
try {
|
|
5593
|
-
return { value: await use(session), token };
|
|
5956
|
+
return { value: await use(session, token), token };
|
|
5594
5957
|
} finally {
|
|
5595
5958
|
session.close();
|
|
5596
5959
|
}
|
|
5597
5960
|
}
|
|
5598
5961
|
var readHa = (context, commands3) => withHa(context, (session) => Promise.all(commands3.map((command5) => session.send(command5))));
|
|
5599
|
-
function parseResult(schema, data, command5) {
|
|
5962
|
+
function parseResult(schema, data, command5, token) {
|
|
5600
5963
|
const result = schema(data);
|
|
5601
5964
|
if (result instanceof Issues) {
|
|
5602
|
-
throw new HaError(
|
|
5965
|
+
throw new HaError(
|
|
5966
|
+
`${command5} returned an unexpected result: ${redactText(result.summary, token)}`
|
|
5967
|
+
);
|
|
5603
5968
|
}
|
|
5604
5969
|
return result;
|
|
5605
5970
|
}
|
|
@@ -5772,24 +6137,52 @@ function buildServiceData(flags) {
|
|
|
5772
6137
|
...Object.fromEntries(Object.entries(targets).filter(([, ids]) => ids !== void 0))
|
|
5773
6138
|
};
|
|
5774
6139
|
}
|
|
5775
|
-
|
|
6140
|
+
function readOnce(session) {
|
|
6141
|
+
const sent = /* @__PURE__ */ new Map();
|
|
6142
|
+
return (command5) => {
|
|
6143
|
+
let result = sent.get(command5);
|
|
6144
|
+
if (result === void 0) {
|
|
6145
|
+
result = session.send(command5);
|
|
6146
|
+
sent.set(command5, result);
|
|
6147
|
+
}
|
|
6148
|
+
return result;
|
|
6149
|
+
};
|
|
6150
|
+
}
|
|
6151
|
+
async function inOrder(promises) {
|
|
6152
|
+
const settled = await Promise.allSettled(promises);
|
|
6153
|
+
const values = [];
|
|
6154
|
+
for (const result of settled) {
|
|
6155
|
+
if (result.status === "rejected") {
|
|
6156
|
+
throw result.reason;
|
|
6157
|
+
}
|
|
6158
|
+
values.push(result.value);
|
|
6159
|
+
}
|
|
6160
|
+
return values;
|
|
6161
|
+
}
|
|
6162
|
+
async function checkTargets(read, flags, token) {
|
|
5776
6163
|
const check2 = (kind, wanted, known) => {
|
|
5777
6164
|
const missing = wanted.find((id) => !known.includes(id));
|
|
5778
6165
|
if (missing !== void 0) {
|
|
5779
6166
|
throw new NotFoundError(`${kind} "${missing}" does not exist`);
|
|
5780
6167
|
}
|
|
5781
6168
|
};
|
|
5782
|
-
const list = async (schema, command5) => parseResult(schema, await
|
|
6169
|
+
const list = async (schema, command5) => parseResult(schema, await read(command5), command5, token);
|
|
5783
6170
|
const entities = (flags.entity ?? []).filter((id) => id !== "all" && id !== "none");
|
|
6171
|
+
const [states, areas, devices, floors, labels] = await inOrder([
|
|
6172
|
+
entities.length > 0 ? list(intersection10qmong0na8e8rValidator, "get_states") : Promise.resolve([]),
|
|
6173
|
+
flags.area !== void 0 ? list(intersection1dmk4z81d1f8mlValidator, "config/area_registry/list") : Promise.resolve([]),
|
|
6174
|
+
flags.device !== void 0 ? list(intersection3rk9um0b729ivValidator, "config/device_registry/list") : Promise.resolve([]),
|
|
6175
|
+
flags.floor !== void 0 ? list(intersection1tagcym1fnxkeyValidator, "config/floor_registry/list") : Promise.resolve([]),
|
|
6176
|
+
flags.label !== void 0 ? list(intersection1rp35ue1fi65ccValidator, "config/label_registry/list") : Promise.resolve([])
|
|
6177
|
+
]);
|
|
5784
6178
|
if (entities.length > 0) {
|
|
5785
|
-
const current =
|
|
6179
|
+
const current = states.map((state) => state.entity_id);
|
|
5786
6180
|
if (!entities.every((id) => current.includes(id))) {
|
|
5787
6181
|
const registry = await list(intersection1nv9uj515bs7itValidator, "config/entity_registry/list");
|
|
5788
6182
|
check2("entity", entities, [...current, ...registry.map((entry) => entry.entity_id)]);
|
|
5789
6183
|
}
|
|
5790
6184
|
}
|
|
5791
6185
|
if (flags.area !== void 0) {
|
|
5792
|
-
const areas = await list(intersection1dmk4z81d1f8mlValidator, "config/area_registry/list");
|
|
5793
6186
|
check2(
|
|
5794
6187
|
"area",
|
|
5795
6188
|
flags.area,
|
|
@@ -5797,7 +6190,6 @@ async function checkTargets(session, flags) {
|
|
|
5797
6190
|
);
|
|
5798
6191
|
}
|
|
5799
6192
|
if (flags.device !== void 0) {
|
|
5800
|
-
const devices = await list(intersection3rk9um0b729ivValidator, "config/device_registry/list");
|
|
5801
6193
|
check2(
|
|
5802
6194
|
"device",
|
|
5803
6195
|
flags.device,
|
|
@@ -5805,7 +6197,6 @@ async function checkTargets(session, flags) {
|
|
|
5805
6197
|
);
|
|
5806
6198
|
}
|
|
5807
6199
|
if (flags.floor !== void 0) {
|
|
5808
|
-
const floors = await list(intersection1tagcym1fnxkeyValidator, "config/floor_registry/list");
|
|
5809
6200
|
check2(
|
|
5810
6201
|
"floor",
|
|
5811
6202
|
flags.floor,
|
|
@@ -5813,7 +6204,6 @@ async function checkTargets(session, flags) {
|
|
|
5813
6204
|
);
|
|
5814
6205
|
}
|
|
5815
6206
|
if (flags.label !== void 0) {
|
|
5816
|
-
const labels = await list(intersection1rp35ue1fi65ccValidator, "config/label_registry/list");
|
|
5817
6207
|
check2(
|
|
5818
6208
|
"label",
|
|
5819
6209
|
flags.label,
|
|
@@ -5821,17 +6211,17 @@ async function checkTargets(session, flags) {
|
|
|
5821
6211
|
);
|
|
5822
6212
|
}
|
|
5823
6213
|
}
|
|
5824
|
-
async function callForResponse(session, { domain, service }, data) {
|
|
6214
|
+
async function callForResponse(session, { domain, service }, data, token) {
|
|
5825
6215
|
const reply = await session.send("call_service", {
|
|
5826
6216
|
domain,
|
|
5827
6217
|
service,
|
|
5828
6218
|
service_data: data,
|
|
5829
6219
|
return_response: true
|
|
5830
6220
|
});
|
|
5831
|
-
return parseResult(intersection17r4na700khzejValidator, reply, "call_service").response;
|
|
6221
|
+
return parseResult(intersection17r4na700khzejValidator, reply, "call_service", token).response;
|
|
5832
6222
|
}
|
|
5833
|
-
async function responseSupport(
|
|
5834
|
-
const all = parseResult(intersection128bswg1yy3khmValidator, await
|
|
6223
|
+
async function responseSupport(read, { domain, service }, token) {
|
|
6224
|
+
const all = parseResult(intersection128bswg1yy3khmValidator, await read("get_services"), "get_services", token);
|
|
5835
6225
|
const inDomain = Object.hasOwn(all, domain) ? all[domain] : void 0;
|
|
5836
6226
|
if (inDomain === void 0 || !Object.hasOwn(inDomain, service)) {
|
|
5837
6227
|
return void 0;
|
|
@@ -5900,7 +6290,7 @@ function changedAttributes(before, after) {
|
|
|
5900
6290
|
[.../* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])].filter((key) => !isDeepStrictEqual(before[key], after[key])).map((key) => [key, after[key] ?? null])
|
|
5901
6291
|
);
|
|
5902
6292
|
}
|
|
5903
|
-
async function targetedEntities(session, domain, data) {
|
|
6293
|
+
async function targetedEntities(session, read, domain, data, token) {
|
|
5904
6294
|
const named = strings(data["entity_id"]);
|
|
5905
6295
|
const everything = named.includes("all");
|
|
5906
6296
|
const ids = named.filter((id) => id !== "all" && id !== "none");
|
|
@@ -5912,10 +6302,10 @@ async function targetedEntities(session, domain, data) {
|
|
|
5912
6302
|
}
|
|
5913
6303
|
const [extracted, states] = await Promise.all([
|
|
5914
6304
|
Object.keys(target).length === 0 ? { referenced_entities: [] } : session.send("extract_from_target", { target }),
|
|
5915
|
-
|
|
6305
|
+
read("get_states")
|
|
5916
6306
|
]);
|
|
5917
6307
|
const members = new Map(
|
|
5918
|
-
parseResult(intersection6w7z2u03slcwpValidator, states, "get_states").map((state) => [
|
|
6308
|
+
parseResult(intersection6w7z2u03slcwpValidator, states, "get_states", token).map((state) => [
|
|
5919
6309
|
state.entity_id,
|
|
5920
6310
|
strings(state.attributes["entity_id"])
|
|
5921
6311
|
])
|
|
@@ -5923,9 +6313,12 @@ async function targetedEntities(session, domain, data) {
|
|
|
5923
6313
|
const inDomain = (id) => domain === "homeassistant" || id.startsWith(`${domain}.`);
|
|
5924
6314
|
const targeted = /* @__PURE__ */ new Set([
|
|
5925
6315
|
...ids,
|
|
5926
|
-
...parseResult(
|
|
5927
|
-
|
|
5928
|
-
|
|
6316
|
+
...parseResult(
|
|
6317
|
+
intersectionegwyf90w1alu2Validator,
|
|
6318
|
+
extracted,
|
|
6319
|
+
"extract_from_target",
|
|
6320
|
+
token
|
|
6321
|
+
).referenced_entities.filter(inDomain),
|
|
5929
6322
|
...everything ? [...members.keys()].filter(inDomain) : []
|
|
5930
6323
|
]);
|
|
5931
6324
|
for (const id of targeted) {
|
|
@@ -5933,22 +6326,31 @@ async function targetedEntities(session, domain, data) {
|
|
|
5933
6326
|
}
|
|
5934
6327
|
return targeted;
|
|
5935
6328
|
}
|
|
5936
|
-
async function
|
|
5937
|
-
const targeted = seconds === 0 ? new Set(strings(data["entity_id"])) : await targetedEntities(session, domain, data);
|
|
6329
|
+
async function logStateChanges(session) {
|
|
5938
6330
|
const events = [];
|
|
6331
|
+
let started = false;
|
|
5939
6332
|
await session.subscribe("state_changed", (event) => {
|
|
5940
6333
|
const change = intersection1lvjdu61ps4xl0Validator(event);
|
|
5941
|
-
if (!(change instanceof Issues)) {
|
|
6334
|
+
if (!(change instanceof Issues) && started) {
|
|
5942
6335
|
events.push(change);
|
|
5943
6336
|
}
|
|
5944
6337
|
});
|
|
6338
|
+
return {
|
|
6339
|
+
start: () => {
|
|
6340
|
+
started = true;
|
|
6341
|
+
},
|
|
6342
|
+
events
|
|
6343
|
+
};
|
|
6344
|
+
}
|
|
6345
|
+
async function callAndWatch(session, { domain, service }, data, seconds, targeted, log, token) {
|
|
6346
|
+
log.start();
|
|
5945
6347
|
const reply = await session.send("call_service", { domain, service, service_data: data });
|
|
5946
|
-
const { context } = parseResult(intersectionwidg351n2f7o4Validator, reply, "call_service");
|
|
6348
|
+
const { context } = parseResult(intersectionwidg351n2f7o4Validator, reply, "call_service", token);
|
|
5947
6349
|
if (seconds > 0) {
|
|
5948
6350
|
await session.wait(Math.min(seconds * 1e3, maxDelayMs));
|
|
5949
6351
|
}
|
|
5950
6352
|
const changed = /* @__PURE__ */ new Map();
|
|
5951
|
-
for (const event of events) {
|
|
6353
|
+
for (const event of log.events) {
|
|
5952
6354
|
const { entity_id: id, old_state: old, new_state: state } = event.data;
|
|
5953
6355
|
if (state !== null && (event.context.id === context.id || targeted.has(id))) {
|
|
5954
6356
|
const before = changed.get(id)?.before ?? old?.attributes ?? {};
|
|
@@ -5984,10 +6386,21 @@ Assistant replies. The whole time is always waited; there is no maximum.
|
|
|
5984
6386
|
A change counts when Home Assistant attributes it to this call or it is on a targeted
|
|
5985
6387
|
entity, including members of targeted groups and scenes. Home Assistant attributes for
|
|
5986
6388
|
5 seconds after commanding a device, so slower changes of untargeted devices are missed.
|
|
6389
|
+
Removed states are ignored. With --wait 0, only explicitly named entities and changes Home
|
|
6390
|
+
Assistant attributes to the call count, even before the reply.
|
|
5987
6391
|
|
|
5988
6392
|
With --response, the response data of a service whose "response" is "optional", such as a
|
|
5989
|
-
script, is printed instead, without waiting. It cannot be combined with --wait.
|
|
5990
|
-
|
|
6393
|
+
script, is printed instead, without waiting. It cannot be combined with --wait.
|
|
6394
|
+
|
|
6395
|
+
With --dry-run, nothing is called. The targets and response requirement are checked as for a
|
|
6396
|
+
real call, but a service not listed by Home Assistant is rejected without calling it.
|
|
6397
|
+
It prints {"service", "data", "entities"}: the service data that would be sent and the
|
|
6398
|
+
entities it targets, including members of targeted groups and scenes, sorted. "data" is left
|
|
6399
|
+
out when empty; [] means no entity is targeted. It cannot be combined with --wait or
|
|
6400
|
+
--response.
|
|
6401
|
+
|
|
6402
|
+
Credentials in any output and in error messages are printed as REDACTED; a secret without a
|
|
6403
|
+
recognizable name or shape cannot be caught.
|
|
5991
6404
|
|
|
5992
6405
|
Home Assistant answers a call when the service is done. After 10 seconds without an answer
|
|
5993
6406
|
the command fails with timeout: the call was sent and may still succeed. This happens with
|
|
@@ -5996,11 +6409,17 @@ returns at once.
|
|
|
5996
6409
|
|
|
5997
6410
|
hactl call light.turn_on --area kitchen --data '{"brightness_pct": 50}'
|
|
5998
6411
|
hactl call cover.open_cover --entity cover.garage --wait 30
|
|
6412
|
+
hactl call light.turn_off --entity all --dry-run
|
|
5999
6413
|
hactl call script.report --response`
|
|
6000
6414
|
},
|
|
6001
6415
|
parameters: {
|
|
6002
6416
|
flags: {
|
|
6003
6417
|
...serviceFlags,
|
|
6418
|
+
dryRun: {
|
|
6419
|
+
kind: "boolean",
|
|
6420
|
+
optional: true,
|
|
6421
|
+
brief: "Print what the call would target without calling it"
|
|
6422
|
+
},
|
|
6004
6423
|
response: {
|
|
6005
6424
|
kind: "boolean",
|
|
6006
6425
|
optional: true,
|
|
@@ -6023,16 +6442,50 @@ returns at once.
|
|
|
6023
6442
|
if (flags.response === true && flags.wait !== void 0) {
|
|
6024
6443
|
throw new UsageError("--wait cannot be combined with --response");
|
|
6025
6444
|
}
|
|
6445
|
+
if (flags.dryRun === true && flags.wait !== void 0) {
|
|
6446
|
+
throw new UsageError("--dry-run cannot be combined with --wait");
|
|
6447
|
+
}
|
|
6448
|
+
if (flags.dryRun === true && flags.response === true) {
|
|
6449
|
+
throw new UsageError("--dry-run cannot be combined with --response");
|
|
6450
|
+
}
|
|
6026
6451
|
const { context, token } = await resolveActiveContext(this);
|
|
6027
6452
|
const data = buildServiceData(flags);
|
|
6028
6453
|
const session = await openHa(this.connect, context, token);
|
|
6454
|
+
const id = `${service.domain}.${service.service}`;
|
|
6029
6455
|
try {
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6456
|
+
const read = readOnce(session);
|
|
6457
|
+
const seconds = flags.wait ?? defaultWaitSeconds;
|
|
6458
|
+
const watching = flags.response !== true && flags.dryRun !== true;
|
|
6459
|
+
const [, , targeted, log] = await inOrder([
|
|
6460
|
+
responseSupport(read, service, token).then((support) => {
|
|
6461
|
+
if (support === "required") {
|
|
6462
|
+
throw new UsageError(`"${id}" only returns data`, `Run it with \`hactl query ${id}\`.`);
|
|
6463
|
+
}
|
|
6464
|
+
if (support === void 0 && flags.dryRun === true) {
|
|
6465
|
+
throw new NotFoundError(`service "${id}" does not exist`);
|
|
6466
|
+
}
|
|
6467
|
+
}),
|
|
6468
|
+
checkTargets(read, flags, token),
|
|
6469
|
+
flags.dryRun === true || watching && seconds > 0 ? targetedEntities(session, read, service.domain, data, token) : Promise.resolve(new Set(strings(data["entity_id"]))),
|
|
6470
|
+
watching ? logStateChanges(session) : Promise.resolve(void 0)
|
|
6471
|
+
]);
|
|
6472
|
+
let output;
|
|
6473
|
+
if (flags.dryRun === true) {
|
|
6474
|
+
const entities = [...targeted].sort();
|
|
6475
|
+
output = { service: id, ...Object.keys(data).length === 0 ? {} : { data }, entities };
|
|
6476
|
+
} else if (flags.response === true) {
|
|
6477
|
+
output = await callForResponse(session, service, data, token);
|
|
6478
|
+
} else {
|
|
6479
|
+
output = await callAndWatch(
|
|
6480
|
+
session,
|
|
6481
|
+
service,
|
|
6482
|
+
data,
|
|
6483
|
+
seconds,
|
|
6484
|
+
targeted,
|
|
6485
|
+
log,
|
|
6486
|
+
token
|
|
6487
|
+
);
|
|
6033
6488
|
}
|
|
6034
|
-
await checkTargets(session, flags);
|
|
6035
|
-
const output = flags.response === true ? await callForResponse(session, service, data) : await callAndWatch(session, service, data, flags.wait ?? defaultWaitSeconds);
|
|
6036
6489
|
printJson(this, redactData(output, token));
|
|
6037
6490
|
} catch (error) {
|
|
6038
6491
|
throw explain(service, error);
|
|
@@ -6139,9 +6592,9 @@ Prints an array of contexts, in the shape \`hactl ctx --help\` describes.`
|
|
|
6139
6592
|
|
|
6140
6593
|
// src/commands/ctx/set.ts
|
|
6141
6594
|
var text3 = (brief, placeholder) => ({ kind: "parsed", parse: String, optional: true, brief, placeholder });
|
|
6142
|
-
function buildInstall(
|
|
6595
|
+
function buildInstall(flags, existing) {
|
|
6143
6596
|
const kind = flags.install ?? existing?.install.type;
|
|
6144
|
-
if (kind === "haos"
|
|
6597
|
+
if (kind === "haos") {
|
|
6145
6598
|
if (flags.container !== void 0) {
|
|
6146
6599
|
throw new UsageError("--container only applies to docker contexts");
|
|
6147
6600
|
}
|
|
@@ -6160,7 +6613,8 @@ var setCommand = buildCommand({
|
|
|
6160
6613
|
|
|
6161
6614
|
Creating requires --url and --install, and --container for docker. Updating changes only
|
|
6162
6615
|
the flags given. Context names use lowercase letters, digits and dashes.
|
|
6163
|
-
--url must
|
|
6616
|
+
--url must be an HTTP or HTTPS base URL, optionally with a path, but without credentials,
|
|
6617
|
+
a query, or a fragment.
|
|
6164
6618
|
Prints the context. Store its token next with \`hactl ctx token-set <name>\`.
|
|
6165
6619
|
|
|
6166
6620
|
hactl ctx set home --url https://ha.example.ts.net --install haos --ssh root@ha.local
|
|
@@ -6199,17 +6653,21 @@ Prints the context. Store its token next with \`hactl ctx token-set <name>\`.
|
|
|
6199
6653
|
const definition = contextDefinition({
|
|
6200
6654
|
name,
|
|
6201
6655
|
url: flags.url ?? existing?.url,
|
|
6202
|
-
install: buildInstall(
|
|
6656
|
+
install: buildInstall(flags, existing),
|
|
6203
6657
|
...ssh === void 0 ? {} : { ssh }
|
|
6204
6658
|
});
|
|
6205
6659
|
if (definition instanceof Issues) {
|
|
6206
6660
|
throw new UsageError(`invalid context "${name}": ${definition.summary}`);
|
|
6207
6661
|
}
|
|
6662
|
+
const selection = await loadSelection(this);
|
|
6208
6663
|
await saveContexts(
|
|
6209
6664
|
folder,
|
|
6210
6665
|
existing === void 0 ? [...contexts, definition] : contexts.map((context) => context.name === name ? definition : context)
|
|
6211
6666
|
);
|
|
6212
|
-
const entry =
|
|
6667
|
+
const entry = contextEntry(definition, {
|
|
6668
|
+
selection,
|
|
6669
|
+
token: await tokenState(this.keychain, name)
|
|
6670
|
+
});
|
|
6213
6671
|
printJson(this, entry);
|
|
6214
6672
|
if (entry.token === "missing") {
|
|
6215
6673
|
this.process.stderr.write(`next: run \`hactl ctx token-set ${name}\`
|
|
@@ -6259,8 +6717,12 @@ Prints the context.`
|
|
|
6259
6717
|
"Paste it at the prompt or pipe it on standard input."
|
|
6260
6718
|
);
|
|
6261
6719
|
}
|
|
6720
|
+
const selection = await loadSelection(this);
|
|
6262
6721
|
await this.keychain.set(name, new Secret(token));
|
|
6263
|
-
printJson(
|
|
6722
|
+
printJson(
|
|
6723
|
+
this,
|
|
6724
|
+
contextEntry(definition, { selection, token: await tokenState(this.keychain, name) })
|
|
6725
|
+
);
|
|
6264
6726
|
}
|
|
6265
6727
|
});
|
|
6266
6728
|
|
|
@@ -6293,12 +6755,17 @@ Prints the context.
|
|
|
6293
6755
|
async func(flags, name) {
|
|
6294
6756
|
const folder = configFolder(this.env, this.homedir);
|
|
6295
6757
|
const definition = requireContext(await loadContexts(folder), name);
|
|
6758
|
+
let selection;
|
|
6296
6759
|
if (flags.project === true) {
|
|
6297
|
-
await setProjectContext(this
|
|
6760
|
+
selection = await setProjectContext(this, name);
|
|
6298
6761
|
} else {
|
|
6762
|
+
selection = await loadSelection(this, {
|
|
6763
|
+
name,
|
|
6764
|
+
source: "global",
|
|
6765
|
+
path: globalSettingsPath(folder)
|
|
6766
|
+
});
|
|
6299
6767
|
await setGlobalContext(folder, name);
|
|
6300
6768
|
}
|
|
6301
|
-
const selection = await loadSelection(this);
|
|
6302
6769
|
if (selection !== void 0 && selection.name !== name) {
|
|
6303
6770
|
this.process.stderr.write(
|
|
6304
6771
|
`warning: "${selection.name}" stays active here because of ${selection.path}
|
|
@@ -6336,7 +6803,7 @@ async function getJson(fetchFn, context, token, path) {
|
|
|
6336
6803
|
} catch (exc) {
|
|
6337
6804
|
const cause = describeCause(exc);
|
|
6338
6805
|
throw new UnreachableError(
|
|
6339
|
-
`cannot reach ${url2}: ${cause}`,
|
|
6806
|
+
`cannot reach ${url2}: ${redactText(cause, token)}`,
|
|
6340
6807
|
/redirect/i.test(cause) ? `Set the final URL with \`hactl ctx set ${context.name} --url <url>\`.` : void 0
|
|
6341
6808
|
);
|
|
6342
6809
|
}
|
|
@@ -6349,8 +6816,14 @@ async function getJson(fetchFn, context, token, path) {
|
|
|
6349
6816
|
if (!response.ok) {
|
|
6350
6817
|
throw new HaError(`GET ${path} returned HTTP ${response.status}`);
|
|
6351
6818
|
}
|
|
6819
|
+
let body;
|
|
6820
|
+
try {
|
|
6821
|
+
body = await response.text();
|
|
6822
|
+
} catch (exc) {
|
|
6823
|
+
throw new UnreachableError(`cannot reach ${url2}: ${describeCause(exc)}`);
|
|
6824
|
+
}
|
|
6352
6825
|
try {
|
|
6353
|
-
return
|
|
6826
|
+
return JSON.parse(body);
|
|
6354
6827
|
} catch {
|
|
6355
6828
|
throw notHa(context, path);
|
|
6356
6829
|
}
|
|
@@ -6378,16 +6851,17 @@ function checkInstall(context, config) {
|
|
|
6378
6851
|
);
|
|
6379
6852
|
}
|
|
6380
6853
|
var versionFile = "/config/.HA_VERSION";
|
|
6381
|
-
async function checkSsh(ssh, context, target) {
|
|
6854
|
+
async function checkSsh(ssh, context, target, token) {
|
|
6382
6855
|
const { install } = context;
|
|
6383
6856
|
if (install.type === "docker") {
|
|
6384
6857
|
const inspect2 = await runRemote(
|
|
6385
6858
|
ssh,
|
|
6386
6859
|
target,
|
|
6387
|
-
`docker inspect -f '{{.State.Running}}' ${shellQuote(install.container)}
|
|
6860
|
+
`docker inspect -f '{{.State.Running}}' ${shellQuote(install.container)}`,
|
|
6861
|
+
token
|
|
6388
6862
|
);
|
|
6389
6863
|
if (inspect2.code !== 0 || inspect2.stdout.trim() !== "true") {
|
|
6390
|
-
const detail = redactText(inspect2.stderr.trim());
|
|
6864
|
+
const detail = redactText(inspect2.stderr.trim(), token);
|
|
6391
6865
|
throw new ContainerNotRunningError(
|
|
6392
6866
|
`container "${install.container}" is not running on ${target}${detail === "" ? "" : `: ${detail}`}`,
|
|
6393
6867
|
`Start it, or fix the name with \`hactl ctx set ${context.name} --container <name>\`.`
|
|
@@ -6396,7 +6870,8 @@ async function checkSsh(ssh, context, target) {
|
|
|
6396
6870
|
const read2 = await runRemote(
|
|
6397
6871
|
ssh,
|
|
6398
6872
|
target,
|
|
6399
|
-
`docker exec ${shellQuote(install.container)} test -r ${versionFile}
|
|
6873
|
+
`docker exec ${shellQuote(install.container)} test -r ${versionFile}`,
|
|
6874
|
+
token
|
|
6400
6875
|
);
|
|
6401
6876
|
if (read2.code !== 0) {
|
|
6402
6877
|
throw new ConfigDirMissingError(
|
|
@@ -6406,7 +6881,7 @@ async function checkSsh(ssh, context, target) {
|
|
|
6406
6881
|
}
|
|
6407
6882
|
return;
|
|
6408
6883
|
}
|
|
6409
|
-
const read = await runRemote(ssh, target, `test -r ${versionFile}
|
|
6884
|
+
const read = await runRemote(ssh, target, `test -r ${versionFile}`, token);
|
|
6410
6885
|
if (read.code !== 0) {
|
|
6411
6886
|
throw new ConfigDirMissingError(
|
|
6412
6887
|
`${target} has no readable ${versionFile}`,
|
|
@@ -6429,9 +6904,9 @@ Prints {"version", "state"} of Home Assistant.`
|
|
|
6429
6904
|
const config = await getConfig(this.fetch, context, token);
|
|
6430
6905
|
checkInstall(context, config);
|
|
6431
6906
|
if (context.ssh !== void 0) {
|
|
6432
|
-
await checkSsh(this.ssh, context, context.ssh);
|
|
6907
|
+
await checkSsh(this.ssh, context, context.ssh, token);
|
|
6433
6908
|
}
|
|
6434
|
-
printJson(this, { version: config.version, state: config.state });
|
|
6909
|
+
printJson(this, redactData({ version: config.version, state: config.state }, token));
|
|
6435
6910
|
}
|
|
6436
6911
|
});
|
|
6437
6912
|
|
|
@@ -6502,7 +6977,7 @@ caught.`
|
|
|
6502
6977
|
} = await readHa(this, [command]);
|
|
6503
6978
|
printItems(
|
|
6504
6979
|
this,
|
|
6505
|
-
toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, registry, command)),
|
|
6980
|
+
toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, registry, command, token)),
|
|
6506
6981
|
id,
|
|
6507
6982
|
"area",
|
|
6508
6983
|
(area) => pick(area, ["id", "name", "floor"]),
|
|
@@ -6518,7 +6993,7 @@ var devicesCommand = buildCommand({
|
|
|
6518
6993
|
brief: "List devices, or show one",
|
|
6519
6994
|
fullDescription: `List devices, or show one
|
|
6520
6995
|
|
|
6521
|
-
Fields: "id", "name", "area", "manufacturer", "model", "integrations". An id adds
|
|
6996
|
+
Fields: "id", "name" when available, "area", "manufacturer", "model", "integrations". An id adds
|
|
6522
6997
|
"labels" and "disabled". An unknown --area is not_found.
|
|
6523
6998
|
Credentials are printed as REDACTED; a secret without a recognizable name or shape cannot be
|
|
6524
6999
|
caught.
|
|
@@ -6535,9 +7010,9 @@ caught.
|
|
|
6535
7010
|
token
|
|
6536
7011
|
} = await readHa(this, commands);
|
|
6537
7012
|
if (flags.area !== void 0) {
|
|
6538
|
-
findById(toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, areas, commands[1])), flags.area, "area");
|
|
7013
|
+
findById(toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, areas, commands[1], token)), flags.area, "area");
|
|
6539
7014
|
}
|
|
6540
|
-
const devices = toDevices(parseResult(intersection3rk9um0b729ivValidator, registry, commands[0])).filter(
|
|
7015
|
+
const devices = toDevices(parseResult(intersection3rk9um0b729ivValidator, registry, commands[0], token)).filter(
|
|
6541
7016
|
(device) => flags.area === void 0 || device.area === flags.area
|
|
6542
7017
|
);
|
|
6543
7018
|
printItems(
|
|
@@ -6565,15 +7040,16 @@ var entitiesCommand = buildCommand({
|
|
|
6565
7040
|
brief: "List entities with a state, or show one",
|
|
6566
7041
|
fullDescription: `List entities with a state, or show one
|
|
6567
7042
|
|
|
6568
|
-
Lists entities that have a state, hidden ones included. --all adds
|
|
6569
|
-
have
|
|
7043
|
+
Lists entities that have a state, hidden ones included. --all adds registry-only entities,
|
|
7044
|
+
which have no "state". Only entities marked disabled have "disabled": true.
|
|
7045
|
+
Filters combine. An unknown --area, --device, --floor
|
|
6570
7046
|
or --label is not_found; a domain without entities gives [].
|
|
6571
7047
|
|
|
6572
7048
|
--floor keeps entities whose "area" is on that floor. --label keeps entities that carry the
|
|
6573
7049
|
label themselves, not through their device or area. A \`hactl call\` targeting a floor or
|
|
6574
7050
|
label can therefore reach other entities than these filters list.
|
|
6575
7051
|
|
|
6576
|
-
Fields: "id", "name", "state", "area", "areaFrom", "device", "integration", "disabled".
|
|
7052
|
+
Fields: "id", "name" when available, "state", "area", "areaFrom", "device", "integration", "disabled".
|
|
6577
7053
|
An id adds "labels", "attributes", "lastChanged" and "hidden". Credentials anywhere in the
|
|
6578
7054
|
output, such as camera access tokens and password states, are printed as REDACTED; a secret
|
|
6579
7055
|
without a recognizable name or shape cannot be caught.
|
|
@@ -6589,16 +7065,16 @@ without a recognizable name or shape cannot be caught.
|
|
|
6589
7065
|
device: filterFlag("Only entities of this device", "id"),
|
|
6590
7066
|
floor: filterFlag("Only entities in an area on this floor", "id"),
|
|
6591
7067
|
label: filterFlag("Only entities with this label", "id"),
|
|
6592
|
-
all: { kind: "boolean", optional: true, brief: "Also list
|
|
7068
|
+
all: { kind: "boolean", optional: true, brief: "Also list registry-only entities" }
|
|
6593
7069
|
},
|
|
6594
7070
|
positional: { kind: "tuple", parameters: [idParameter("Entity id")] }
|
|
6595
7071
|
},
|
|
6596
7072
|
async func(flags, id) {
|
|
6597
7073
|
const { value: results, token } = await readHa(this, commands2);
|
|
6598
|
-
const current = parseResult(intersection10qmong0na8e8rValidator, results[0], commands2[0]);
|
|
6599
|
-
const registry = parseResult(intersection1nv9uj515bs7itValidator, results[1], commands2[1]);
|
|
6600
|
-
const devices = parseResult(intersection3rk9um0b729ivValidator, results[2], commands2[2]);
|
|
6601
|
-
const areas = toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, results[3], commands2[3]));
|
|
7074
|
+
const current = parseResult(intersection10qmong0na8e8rValidator, results[0], commands2[0], token);
|
|
7075
|
+
const registry = parseResult(intersection1nv9uj515bs7itValidator, results[1], commands2[1], token);
|
|
7076
|
+
const devices = parseResult(intersection3rk9um0b729ivValidator, results[2], commands2[2], token);
|
|
7077
|
+
const areas = toAreas(parseResult(intersection1dmk4z81d1f8mlValidator, results[3], commands2[3], token));
|
|
6602
7078
|
const { area, device, floor, label } = flags;
|
|
6603
7079
|
if (area !== void 0) {
|
|
6604
7080
|
findById(areas, area, "area");
|
|
@@ -6607,10 +7083,18 @@ without a recognizable name or shape cannot be caught.
|
|
|
6607
7083
|
findById(toDevices(devices), device, "device");
|
|
6608
7084
|
}
|
|
6609
7085
|
if (floor !== void 0) {
|
|
6610
|
-
findById(
|
|
7086
|
+
findById(
|
|
7087
|
+
toFloors(parseResult(intersection1tagcym1fnxkeyValidator, results[4], commands2[4], token)),
|
|
7088
|
+
floor,
|
|
7089
|
+
"floor"
|
|
7090
|
+
);
|
|
6611
7091
|
}
|
|
6612
7092
|
if (label !== void 0) {
|
|
6613
|
-
findById(
|
|
7093
|
+
findById(
|
|
7094
|
+
toLabels(parseResult(intersection1rp35ue1fi65ccValidator, results[5], commands2[5], token)),
|
|
7095
|
+
label,
|
|
7096
|
+
"label"
|
|
7097
|
+
);
|
|
6614
7098
|
}
|
|
6615
7099
|
const onFloor = new Set(areas.filter((item) => item.floor === floor).map((item) => item.id));
|
|
6616
7100
|
const entities = toEntities(
|
|
@@ -6661,7 +7145,7 @@ caught.`
|
|
|
6661
7145
|
} = await readHa(this, [command2]);
|
|
6662
7146
|
printItems(
|
|
6663
7147
|
this,
|
|
6664
|
-
toFloors(parseResult(intersection1tagcym1fnxkeyValidator, registry, command2)),
|
|
7148
|
+
toFloors(parseResult(intersection1tagcym1fnxkeyValidator, registry, command2, token)),
|
|
6665
7149
|
id,
|
|
6666
7150
|
"floor",
|
|
6667
7151
|
(floor) => pick(floor, ["id", "name", "level"]),
|
|
@@ -6689,7 +7173,7 @@ caught.`
|
|
|
6689
7173
|
} = await readHa(this, [command3]);
|
|
6690
7174
|
printItems(
|
|
6691
7175
|
this,
|
|
6692
|
-
toLabels(parseResult(intersection1rp35ue1fi65ccValidator, registry, command3)),
|
|
7176
|
+
toLabels(parseResult(intersection1rp35ue1fi65ccValidator, registry, command3, token)),
|
|
6693
7177
|
id,
|
|
6694
7178
|
"label",
|
|
6695
7179
|
(label) => pick(label, ["id", "name", "description"]),
|
|
@@ -6701,10 +7185,10 @@ caught.`
|
|
|
6701
7185
|
// src/commands/get/services.ts
|
|
6702
7186
|
var command4 = "get_services";
|
|
6703
7187
|
var translationCommand = "frontend/get_translations";
|
|
6704
|
-
async function serviceTexts(session) {
|
|
7188
|
+
async function serviceTexts(session, token) {
|
|
6705
7189
|
try {
|
|
6706
7190
|
const result = await session.send(translationCommand, { language: "en", category: "services" });
|
|
6707
|
-
return parseResult(intersection1etdk1h0e9wp9wValidator, result, translationCommand).resources;
|
|
7191
|
+
return parseResult(intersection1etdk1h0e9wp9wValidator, result, translationCommand, token).resources;
|
|
6708
7192
|
} catch (error) {
|
|
6709
7193
|
if (error instanceof HaCommandError) {
|
|
6710
7194
|
return {};
|
|
@@ -6743,9 +7227,9 @@ caught.
|
|
|
6743
7227
|
token
|
|
6744
7228
|
} = await withHa(
|
|
6745
7229
|
this,
|
|
6746
|
-
async (session) => [
|
|
7230
|
+
async (session, activeToken) => Promise.all([session.send(command4), serviceTexts(session, activeToken)])
|
|
6747
7231
|
);
|
|
6748
|
-
const all = toServices(parseResult(intersection128bswg1yy3khmValidator, result, command4), texts);
|
|
7232
|
+
const all = toServices(parseResult(intersection128bswg1yy3khmValidator, result, command4, token), texts);
|
|
6749
7233
|
if (id !== void 0 && all.some((service) => service.id.startsWith(`${id}.`))) {
|
|
6750
7234
|
throw new NotFoundError(
|
|
6751
7235
|
`service "${id}" does not exist`,
|
|
@@ -6805,7 +7289,15 @@ function print(context, lines) {
|
|
|
6805
7289
|
}
|
|
6806
7290
|
}
|
|
6807
7291
|
async function coreLog(context, { context: target, token }, flags, closed) {
|
|
6808
|
-
const
|
|
7292
|
+
const connecting = openHa(context.connect, target, token);
|
|
7293
|
+
const session = await Promise.race([connecting, closed]);
|
|
7294
|
+
if (session === void 0) {
|
|
7295
|
+
void connecting.then(
|
|
7296
|
+
(connection) => connection.close(),
|
|
7297
|
+
() => void 0
|
|
7298
|
+
);
|
|
7299
|
+
return;
|
|
7300
|
+
}
|
|
6809
7301
|
const redact = createLineRedactor(token);
|
|
6810
7302
|
let first = true;
|
|
6811
7303
|
let received = () => void 0;
|
|
@@ -6817,7 +7309,7 @@ async function coreLog(context, { context: target, token }, flags, closed) {
|
|
|
6817
7309
|
tail.catch(() => void 0);
|
|
6818
7310
|
const listen = (event) => {
|
|
6819
7311
|
try {
|
|
6820
|
-
const lines = redact(parseResult(intersection1kfvut30tftkihValidator, event, "system_log/subscribe_raw"));
|
|
7312
|
+
const lines = redact(parseResult(intersection1kfvut30tftkihValidator, event, "system_log/subscribe_raw", token));
|
|
6821
7313
|
if (first) {
|
|
6822
7314
|
first = false;
|
|
6823
7315
|
print(context, flags.lines === void 0 ? lines : lines.slice(-flags.lines));
|
|
@@ -6831,18 +7323,20 @@ async function coreLog(context, { context: target, token }, flags, closed) {
|
|
|
6831
7323
|
};
|
|
6832
7324
|
try {
|
|
6833
7325
|
const { integration } = flags;
|
|
6834
|
-
|
|
7326
|
+
const subscribed = session.stream(
|
|
6835
7327
|
"system_log/subscribe_raw",
|
|
6836
7328
|
integration === void 0 ? {} : { integration },
|
|
6837
7329
|
listen
|
|
6838
7330
|
);
|
|
6839
|
-
await Promise.race([
|
|
6840
|
-
|
|
7331
|
+
await Promise.race([subscribed, closed]);
|
|
7332
|
+
const receivedTail = await Promise.race([
|
|
7333
|
+
closed,
|
|
7334
|
+
tail.then(() => true),
|
|
6841
7335
|
session.wait(firstEventMs).then(() => {
|
|
6842
7336
|
throw new HaError("system_log/subscribe_raw sent no log");
|
|
6843
7337
|
})
|
|
6844
7338
|
]);
|
|
6845
|
-
if (flags.follow === true) {
|
|
7339
|
+
if (receivedTail && flags.follow === true) {
|
|
6846
7340
|
session.keepAlive();
|
|
6847
7341
|
await Promise.race([closed, session.lost()]);
|
|
6848
7342
|
}
|
|
@@ -6864,9 +7358,9 @@ function explain2(error, { integration }) {
|
|
|
6864
7358
|
}
|
|
6865
7359
|
return error;
|
|
6866
7360
|
}
|
|
6867
|
-
async function checkApp(session, slug) {
|
|
7361
|
+
async function checkApp(session, slug, token) {
|
|
6868
7362
|
const result = await session.send("supervisor/api", { endpoint: "/addons", method: "get" });
|
|
6869
|
-
const { addons } = parseResult(intersection1y5nwst153l9s2Validator, result, "supervisor/api /addons");
|
|
7363
|
+
const { addons } = parseResult(intersection1y5nwst153l9s2Validator, result, "supervisor/api /addons", token);
|
|
6870
7364
|
if (!addons.some((app2) => app2.slug === slug)) {
|
|
6871
7365
|
throw new NotFoundError(`app "${slug}" is not installed`);
|
|
6872
7366
|
}
|
|
@@ -6877,7 +7371,7 @@ async function openLog(context, { context: target, token }, path) {
|
|
|
6877
7371
|
try {
|
|
6878
7372
|
response = await context.httpStream(url2, { Authorization: `Bearer ${token.reveal()}` });
|
|
6879
7373
|
} catch (error) {
|
|
6880
|
-
throw new UnreachableError(`cannot reach ${url2}: ${causeMessage(error)}`);
|
|
7374
|
+
throw new UnreachableError(`cannot reach ${url2}: ${redactText(causeMessage(error), token)}`);
|
|
6881
7375
|
}
|
|
6882
7376
|
const { status } = response;
|
|
6883
7377
|
if (status >= 200 && status < 300) {
|
|
@@ -6895,27 +7389,55 @@ async function openLog(context, { context: target, token }, path) {
|
|
|
6895
7389
|
}
|
|
6896
7390
|
throw new HaError(`GET ${path} returned HTTP ${status}`);
|
|
6897
7391
|
}
|
|
6898
|
-
async function
|
|
6899
|
-
const { context: target, token } = active;
|
|
7392
|
+
async function checkSupervisor(context, { context: target, token }, source) {
|
|
6900
7393
|
const config = await getConfig(context.fetch, target, token);
|
|
6901
7394
|
if (!config.components.includes("hassio")) {
|
|
6902
7395
|
throw new HaError(`the log of "${source}" needs Supervisor, which this instance does not have`);
|
|
6903
7396
|
}
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
7397
|
+
}
|
|
7398
|
+
async function checkAppOnSession(context, { context: target, token }, source, flags) {
|
|
7399
|
+
const session = await openHa(context.connect, target, token);
|
|
7400
|
+
try {
|
|
7401
|
+
await checkApp(session, source, token);
|
|
7402
|
+
} catch (error) {
|
|
7403
|
+
throw explain2(error, flags);
|
|
7404
|
+
} finally {
|
|
7405
|
+
session.close();
|
|
6913
7406
|
}
|
|
7407
|
+
}
|
|
7408
|
+
async function sourceLog(context, active, source, flags, closed) {
|
|
7409
|
+
const { context: target, token } = active;
|
|
6914
7410
|
const follow = flags.follow === true;
|
|
6915
7411
|
const wanted = flags.lines ?? sourceLines;
|
|
6916
7412
|
const root2 = source === "supervisor" ? "supervisor" : `addons/${encodeURIComponent(source)}`;
|
|
6917
7413
|
const path = `/api/hassio/${root2}/logs${follow ? "/follow" : ""}?lines=${Math.max(wanted, 2)}`;
|
|
6918
|
-
const
|
|
7414
|
+
const opening = openLog(context, active, path);
|
|
7415
|
+
const startup = Promise.allSettled([
|
|
7416
|
+
checkSupervisor(context, active, source),
|
|
7417
|
+
source === "supervisor" ? Promise.resolve() : checkAppOnSession(context, active, source, flags),
|
|
7418
|
+
opening
|
|
7419
|
+
]);
|
|
7420
|
+
const settled = await Promise.race([startup, closed]);
|
|
7421
|
+
if (settled === void 0) {
|
|
7422
|
+
void opening.then(
|
|
7423
|
+
(response2) => response2.close(),
|
|
7424
|
+
() => void 0
|
|
7425
|
+
);
|
|
7426
|
+
return;
|
|
7427
|
+
}
|
|
7428
|
+
const [config, app2, opened] = settled;
|
|
7429
|
+
for (const check2 of [config, app2]) {
|
|
7430
|
+
if (check2.status === "rejected") {
|
|
7431
|
+
if (opened.status === "fulfilled") {
|
|
7432
|
+
opened.value.close();
|
|
7433
|
+
}
|
|
7434
|
+
throw check2.reason;
|
|
7435
|
+
}
|
|
7436
|
+
}
|
|
7437
|
+
if (opened.status === "rejected") {
|
|
7438
|
+
throw opened.reason;
|
|
7439
|
+
}
|
|
7440
|
+
const response = opened.value;
|
|
6919
7441
|
const redact = createLineRedactor(token);
|
|
6920
7442
|
let stopped = false;
|
|
6921
7443
|
void closed.then(() => {
|
|
@@ -6947,7 +7469,7 @@ async function sourceLog(context, active, source, flags, closed) {
|
|
|
6947
7469
|
}
|
|
6948
7470
|
} catch (error) {
|
|
6949
7471
|
if (!stopped) {
|
|
6950
|
-
throw lost(causeMessage(error));
|
|
7472
|
+
throw lost(redactText(causeMessage(error), token));
|
|
6951
7473
|
}
|
|
6952
7474
|
} finally {
|
|
6953
7475
|
response.close();
|
|
@@ -6977,8 +7499,11 @@ settings.
|
|
|
6977
7499
|
Existing lines: Home Assistant offers the last 100 lines of the Core log, or up to 5000 with
|
|
6978
7500
|
--integration, going back only to its last start; a larger --lines prints what there is.
|
|
6979
7501
|
Other sources print 100 lines unless --lines says otherwise.
|
|
7502
|
+
--lines accepts only digits, up to 9007199254740991. Core must send its initial tail
|
|
7503
|
+
within 10 seconds of accepting the subscription, even if the tail is empty.
|
|
7504
|
+
Supervisor and app sources have a 10-second header deadline, but no body deadline.
|
|
6980
7505
|
|
|
6981
|
-
--follow keeps printing new lines and never ends by itself:
|
|
7506
|
+
--follow keeps printing new lines and never ends by itself: press Ctrl+C to exit successfully. When the
|
|
6982
7507
|
connection ends, also because Home Assistant restarts, it fails with unreachable after the
|
|
6983
7508
|
lines already printed; it does not reconnect.
|
|
6984
7509
|
|
|
@@ -7026,8 +7551,16 @@ without a recognizable name or shape is printed.
|
|
|
7026
7551
|
throw new UsageError("--integration only applies to the Core log, without a source");
|
|
7027
7552
|
}
|
|
7028
7553
|
const active = await resolveActiveContext(this);
|
|
7029
|
-
|
|
7030
|
-
|
|
7554
|
+
let stopListening;
|
|
7555
|
+
const closed = flags.follow === true ? Promise.race([
|
|
7556
|
+
this.stdoutClosed(),
|
|
7557
|
+
new Promise((resolve) => stopListening = this.onInterrupt(resolve))
|
|
7558
|
+
]) : this.stdoutClosed();
|
|
7559
|
+
try {
|
|
7560
|
+
await (source === void 0 ? coreLog(this, active, flags, closed) : sourceLog(this, active, source, flags, closed));
|
|
7561
|
+
} finally {
|
|
7562
|
+
stopListening?.();
|
|
7563
|
+
}
|
|
7031
7564
|
}
|
|
7032
7565
|
});
|
|
7033
7566
|
|
|
@@ -7067,18 +7600,22 @@ After 10 seconds without an answer the command fails with timeout.
|
|
|
7067
7600
|
const id = `${service.domain}.${service.service}`;
|
|
7068
7601
|
const session = await openHa(this.connect, context, token);
|
|
7069
7602
|
try {
|
|
7070
|
-
const
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7603
|
+
const read = readOnce(session);
|
|
7604
|
+
await inOrder([
|
|
7605
|
+
responseSupport(read, service, token).then((support) => {
|
|
7606
|
+
if (support === void 0) {
|
|
7607
|
+
throw new NotFoundError(`service "${id}" does not exist`);
|
|
7608
|
+
}
|
|
7609
|
+
if (support !== "required") {
|
|
7610
|
+
throw new UsageError(
|
|
7611
|
+
`"${id}" can change the instance, so query does not run it`,
|
|
7612
|
+
`Run it with \`hactl call ${id}\`.`
|
|
7613
|
+
);
|
|
7614
|
+
}
|
|
7615
|
+
}),
|
|
7616
|
+
checkTargets(read, flags, token)
|
|
7617
|
+
]);
|
|
7618
|
+
printJson(this, redactData(await callForResponse(session, service, data, token), token));
|
|
7082
7619
|
} catch (error) {
|
|
7083
7620
|
throw explain(service, error);
|
|
7084
7621
|
} finally {
|
|
@@ -7125,12 +7662,14 @@ async function render(session, template) {
|
|
|
7125
7662
|
})
|
|
7126
7663
|
]);
|
|
7127
7664
|
}
|
|
7128
|
-
function explain3(error, secrets) {
|
|
7129
|
-
const clean = (message) => redactText(String(hideSecrets(message, secrets)));
|
|
7130
|
-
if (error instanceof
|
|
7665
|
+
function explain3(error, secrets, token) {
|
|
7666
|
+
const clean = (message) => redactText(String(hideSecrets(message, secrets, token)), token);
|
|
7667
|
+
if (error instanceof HaError && /^(?:render_template failed: )?Exceeded maximum execution time of \d+(?:\.\d+)?s\.?$/.test(
|
|
7668
|
+
error.message
|
|
7669
|
+
)) {
|
|
7131
7670
|
return new TimeoutError(`the template did not finish within ${renderSeconds} seconds`);
|
|
7132
7671
|
}
|
|
7133
|
-
return error instanceof HaError ? new HaError(clean(error.message), error.hint) : error;
|
|
7672
|
+
return error instanceof HaError ? new HaError(clean(error.message), error.hint === void 0 ? void 0 : clean(error.hint)) : error;
|
|
7134
7673
|
}
|
|
7135
7674
|
var templateCommand = buildCommand({
|
|
7136
7675
|
docs: {
|
|
@@ -7149,8 +7688,9 @@ not change the exit code. A template that cannot be rendered fails with ha_error
|
|
|
7149
7688
|
that an automation or script would supply, such as trigger, are not defined here: stand in
|
|
7150
7689
|
for them with {% set %}.
|
|
7151
7690
|
|
|
7152
|
-
Home Assistant stops rendering after ${renderSeconds} seconds, which fails with timeout.
|
|
7153
|
-
|
|
7691
|
+
Home Assistant stops rendering after ${renderSeconds} seconds, which fails with timeout. hactl also
|
|
7692
|
+
times out after ${answerMs / 1e3} seconds without a reply or ${answerMs / 1e3} seconds after acknowledgement without a result.
|
|
7693
|
+
An expensive template slows Home Assistant down while it runs.
|
|
7154
7694
|
|
|
7155
7695
|
Values that hactl hides elsewhere, such as password states and camera tokens, are printed as
|
|
7156
7696
|
REDACTED wherever they appear, even inside other words. This guards against accidents, not
|
|
@@ -7180,15 +7720,15 @@ recognizable name or shape cannot be caught.
|
|
|
7180
7720
|
let secrets = /* @__PURE__ */ new Set();
|
|
7181
7721
|
try {
|
|
7182
7722
|
secrets = collectSecrets(
|
|
7183
|
-
parseResult(intersection10qmong0na8e8rValidator, await session.send("get_states"), "get_states")
|
|
7723
|
+
parseResult(intersection10qmong0na8e8rValidator, await session.send("get_states"), "get_states", token)
|
|
7184
7724
|
);
|
|
7185
7725
|
const { result, warnings } = await render(session, template);
|
|
7186
7726
|
for (const warning of warnings) {
|
|
7187
|
-
const text5 = redactText(String(hideSecrets(warning, secrets)), token);
|
|
7727
|
+
const text5 = redactText(String(hideSecrets(warning, secrets, token)), token);
|
|
7188
7728
|
this.process.stderr.write(`warning: ${text5}
|
|
7189
7729
|
`);
|
|
7190
7730
|
}
|
|
7191
|
-
const safe = hideSecrets(result, secrets);
|
|
7731
|
+
const safe = hideSecrets(result, secrets, token);
|
|
7192
7732
|
if (typeof safe !== "string") {
|
|
7193
7733
|
printJson(this, redactData(safe, token));
|
|
7194
7734
|
} else if (safe !== "") {
|
|
@@ -7197,7 +7737,7 @@ recognizable name or shape cannot be caught.
|
|
|
7197
7737
|
`);
|
|
7198
7738
|
}
|
|
7199
7739
|
} catch (error) {
|
|
7200
|
-
throw explain3(error, secrets);
|
|
7740
|
+
throw explain3(error, secrets, token);
|
|
7201
7741
|
} finally {
|
|
7202
7742
|
session.close();
|
|
7203
7743
|
}
|
|
@@ -7211,6 +7751,7 @@ import { dirname as dirname3, join as join5 } from "node:path";
|
|
|
7211
7751
|
var apiBase = "https://api.github.com/repos/houfio/hactl/releases";
|
|
7212
7752
|
var lookupTimeoutMs = 1e4;
|
|
7213
7753
|
var downloadTimeoutMs = 3e5;
|
|
7754
|
+
var writableHint = "Rerun with permission to write there, or reinstall into a folder you own.";
|
|
7214
7755
|
function parseVersion(raw) {
|
|
7215
7756
|
const version2 = raw.startsWith("v") ? raw.slice(1) : raw;
|
|
7216
7757
|
if (!/^\d+\.\d+\.\d+$/.test(version2)) {
|
|
@@ -7276,10 +7817,7 @@ async function upgrade(context, requested) {
|
|
|
7276
7817
|
}
|
|
7277
7818
|
const folder = dirname3(binary);
|
|
7278
7819
|
await access2(folder, constants2.W_OK).catch(() => {
|
|
7279
|
-
throw new UpgradeNotWritableError(
|
|
7280
|
-
`${folder} is not writable`,
|
|
7281
|
-
"Rerun with permission to write there, or reinstall into a folder you own."
|
|
7282
|
-
);
|
|
7820
|
+
throw new UpgradeNotWritableError(`${folder} is not writable`, writableHint);
|
|
7283
7821
|
});
|
|
7284
7822
|
const { version: version2, asset } = await lookup(
|
|
7285
7823
|
context,
|
|
@@ -7308,8 +7846,15 @@ async function upgrade(context, requested) {
|
|
|
7308
7846
|
);
|
|
7309
7847
|
}
|
|
7310
7848
|
await rename2(temp, binary);
|
|
7311
|
-
}
|
|
7312
|
-
await rm2(temp, { force: true });
|
|
7849
|
+
} catch (exc) {
|
|
7850
|
+
await rm2(temp, { force: true }).catch(() => void 0);
|
|
7851
|
+
if (exc instanceof DownloadFailedError) {
|
|
7852
|
+
throw exc;
|
|
7853
|
+
}
|
|
7854
|
+
throw new UpgradeNotWritableError(
|
|
7855
|
+
`cannot replace ${binary}: ${describeCause2(exc)}`,
|
|
7856
|
+
writableHint
|
|
7857
|
+
);
|
|
7313
7858
|
}
|
|
7314
7859
|
return { from, to: version2 };
|
|
7315
7860
|
}
|
|
@@ -7391,7 +7936,9 @@ Set one up first (details in \`hactl ctx --help\`):
|
|
|
7391
7936
|
Then read with \`hactl get\` and \`hactl query\`, act with \`hactl call\` and see what happened with
|
|
7392
7937
|
\`hactl logs\`. Try Jinja with \`hactl template\`.
|
|
7393
7938
|
|
|
7394
|
-
\`get\`, \`logs
|
|
7939
|
+
\`get\`, \`logs\` and \`template\` only read. Use \`call\` for actions that change the instance.
|
|
7940
|
+
\`query\` only calls services Home Assistant marks as requiring a response; it relies on the
|
|
7941
|
+
integration not to change the instance.
|
|
7395
7942
|
\`ctx\` and \`upgrade\` change only this machine.
|
|
7396
7943
|
Every command and group has its own \`--help\` with its behavior, output and examples.
|
|
7397
7944
|
|