@indigoai-us/hq-cli 5.345.215 → 5.345.218
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/CHANGELOG.md +168 -0
- package/README.md +46 -1
- package/assets/bot-workers/setup/skills/add-a-pack.md +3 -3
- package/assets/scaffold/core/scripts/hq-session.sh +4 -0
- package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
- package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
- package/dist/command-catalog.generated.d.ts +59 -4
- package/dist/command-catalog.generated.js +74 -4
- package/dist/command-help.js +3 -1
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/auth.js +11 -52
- package/dist/commands/bot.js +11 -4
- package/dist/commands/cloud-demote.d.ts +19 -4
- package/dist/commands/cloud-demote.js +85 -12
- package/dist/commands/cloud-provision.d.ts +5 -1
- package/dist/commands/cloud-provision.js +6 -2
- package/dist/commands/cloud.d.ts +37 -1
- package/dist/commands/cloud.js +110 -27
- package/dist/commands/core-hq-session-native.js +3 -0
- package/dist/commands/core.js +1 -0
- package/dist/commands/daemon.js +4 -1
- package/dist/commands/dm.js +7 -0
- package/dist/commands/doctor-usage.d.ts +8 -0
- package/dist/commands/doctor-usage.js +20 -0
- package/dist/commands/doctor.js +7 -1
- package/dist/commands/env.d.ts +18 -0
- package/dist/commands/env.js +82 -0
- package/dist/commands/install-global.js +3 -3
- package/dist/commands/lanes.js +100 -24
- package/dist/commands/logout.d.ts +7 -0
- package/dist/commands/logout.js +41 -34
- package/dist/commands/members.js +1 -1
- package/dist/commands/pack-start-bot.d.ts +1 -1
- package/dist/commands/pack-start-bot.js +2 -2
- package/dist/commands/pkg-update.js +1 -1
- package/dist/commands/sources.d.ts +8 -2
- package/dist/commands/sources.js +65 -9
- package/dist/commands/sync-narrow.js +1 -1
- package/dist/commands/team-sync.js +1 -1
- package/dist/commands/whoami.js +26 -1
- package/dist/data/command-states.json +22 -0
- package/dist/index.js +52 -4
- package/dist/lazy-commands.js +2 -1
- package/dist/lib/anywhere-person-setting.d.ts +2 -0
- package/dist/lib/anywhere-person-setting.js +6 -3
- package/dist/lib/billing/usage-card.d.ts +25 -4
- package/dist/lib/billing/usage-card.js +76 -9
- package/dist/lib/billing/usage-cost.d.ts +3 -3
- package/dist/lib/billing/usage-cost.js +40 -15
- package/dist/lib/billing/usage-only.js +4 -2
- package/dist/lib/billing/usage-rate-card.d.ts +2 -2
- package/dist/lib/billing/usage-rate-card.js +3 -0
- package/dist/lib/bot/fleet-cron.js +93 -6
- package/dist/lib/bot/inflight.d.ts +9 -0
- package/dist/lib/bot/inflight.js +10 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
- package/dist/lib/bot/pack-link.d.ts +2 -2
- package/dist/lib/bot/pack-link.js +2 -2
- package/dist/lib/bot/runtime/grok-acp.d.ts +1 -0
- package/dist/lib/bot/runtime/grok-acp.js +26 -11
- package/dist/lib/bot/runtime/grok.js +1 -1
- package/dist/lib/daemon/flag-monitor.d.ts +8 -0
- package/dist/lib/daemon/flag-monitor.js +17 -6
- package/dist/lib/daemon/flag.d.ts +65 -1
- package/dist/lib/daemon/flag.js +190 -40
- package/dist/lib/daemon/hook-env.d.ts +32 -0
- package/dist/lib/daemon/hook-env.js +51 -0
- package/dist/lib/daemon/ops/policy.js +67 -8
- package/dist/lib/daemon/paths.d.ts +72 -2
- package/dist/lib/daemon/paths.js +154 -3
- package/dist/lib/daemon/run.js +32 -21
- package/dist/lib/daemon/selfcheck.d.ts +22 -0
- package/dist/lib/daemon/selfcheck.js +40 -1
- package/dist/lib/daemon/server.d.ts +3 -1
- package/dist/lib/daemon/server.js +7 -22
- package/dist/lib/daemon/state-file-switch.d.ts +57 -0
- package/dist/lib/daemon/state-file-switch.js +88 -0
- package/dist/lib/daemon/state-file.d.ts +198 -0
- package/dist/lib/daemon/state-file.js +419 -0
- package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
- package/dist/lib/daemon/timed-flag-monitors.js +75 -0
- package/dist/lib/doctor/checks/host-core.d.ts +52 -0
- package/dist/lib/doctor/checks/host-core.js +337 -0
- package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
- package/dist/lib/doctor/checks/replay-recorder.js +261 -0
- package/dist/lib/doctor/checks/sync-runtime.js +3 -3
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/environment/credential-shapes.d.ts +61 -0
- package/dist/lib/environment/credential-shapes.js +333 -0
- package/dist/lib/environment/profile.d.ts +239 -0
- package/dist/lib/environment/profile.js +239 -0
- package/dist/lib/hook-engine/coverage.d.ts +13 -0
- package/dist/lib/hook-engine/coverage.js +124 -0
- package/dist/lib/hook-engine/reconcile.js +300 -94
- package/dist/lib/hook-engine/registration.d.ts +17 -1
- package/dist/lib/hook-engine/registration.js +62 -7
- package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
- package/dist/lib/hot-channels/adapters/slack.js +64 -21
- package/dist/lib/hot-channels/alert.d.ts +2 -0
- package/dist/lib/hot-channels/alert.js +8 -1
- package/dist/lib/hot-channels/contract.d.ts +12 -0
- package/dist/lib/hot-channels/contract.js +7 -0
- package/dist/lib/hot-channels/loop.js +1 -0
- package/dist/lib/hot-channels/run.d.ts +6 -0
- package/dist/lib/hot-channels/run.js +4 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +64 -1
- package/dist/lib/hot-channels/signals-pass.js +21 -49
- package/dist/lib/install/claude-targets.d.ts +12 -1
- package/dist/lib/install/claude-targets.js +70 -5
- package/dist/lib/install/codex-pack-contributions.js +1 -1
- package/dist/lib/install/codex-targets.d.ts +2 -2
- package/dist/lib/install/codex-targets.js +48 -5
- package/dist/lib/install/hook-target.d.ts +4 -1
- package/dist/lib/install/hook-target.js +14 -1
- package/dist/lib/lanes/canonical-host.d.ts +35 -0
- package/dist/lib/lanes/canonical-host.js +65 -0
- package/dist/lib/lanes/host-capacity.d.ts +30 -0
- package/dist/lib/lanes/host-capacity.js +29 -3
- package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
- package/dist/lib/mesh/live/daemon/run.js +5 -2
- package/dist/lib/mesh/live/flush.d.ts +5 -1
- package/dist/lib/mesh/live/flush.js +12 -6
- package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
- package/dist/lib/mesh/live/reporting-privacy.js +56 -1
- package/dist/lib/mesh/live/spool.d.ts +7 -0
- package/dist/lib/mesh/live/spool.js +25 -0
- package/dist/lib/packages/setup-block.d.ts +2 -2
- package/dist/lib/packages/setup-block.js +2 -2
- package/dist/lib/packages/start-bot.d.ts +1 -1
- package/dist/lib/packages/start-bot.js +1 -1
- package/dist/lib/person-setting-cache.d.ts +38 -0
- package/dist/lib/person-setting-cache.js +98 -0
- package/dist/lib/safe-store.d.ts +245 -0
- package/dist/lib/safe-store.js +777 -0
- package/dist/lib/signals/engine.d.ts +29 -2
- package/dist/lib/signals/engine.js +103 -4
- package/dist/lib/signals/reply.js +73 -18
- package/dist/lib/signals/steps/adapters.js +7 -2
- package/dist/lib/signals/steps/extract.d.ts +13 -0
- package/dist/lib/signals/steps/extract.js +84 -4
- package/dist/main.js +47 -4
- package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
- package/dist/types.d.ts +1 -1
- package/dist/utils/auth-expiry.d.ts +8 -0
- package/dist/utils/auth-expiry.js +53 -0
- package/dist/utils/callback-port-busy.d.ts +1 -1
- package/dist/utils/callback-port-busy.js +4 -4
- package/dist/utils/cli-telemetry.d.ts +21 -0
- package/dist/utils/cli-telemetry.js +34 -0
- package/dist/utils/command-usage.d.ts +275 -0
- package/dist/utils/command-usage.js +797 -0
- package/dist/utils/hook-trust.d.ts +7 -0
- package/dist/utils/hook-trust.js +34 -4
- package/dist/utils/host-registration.d.ts +179 -0
- package/dist/utils/host-registration.js +505 -0
- package/dist/utils/resident-package-preload.js +2 -0
- package/package.json +10 -8
- package/scripts/bench-core.mjs +1096 -0
- package/scripts/check-function-manifest.mjs +702 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hq-environment-profile.v1: one profile per place that can do work (the
|
|
3
|
+
* local machine, an Outpost, a MicroVM, a bot, a fleet box), published as a
|
|
4
|
+
* company-scoped view.
|
|
5
|
+
*
|
|
6
|
+
* This module holds the TypeScript shape, and a loader that validates a
|
|
7
|
+
* document against src/schemas/hq-environment-profile.v1.schema.json and
|
|
8
|
+
* refuses any other schema_version. It reads; it does not write a profile and
|
|
9
|
+
* it does not match work to an environment.
|
|
10
|
+
*
|
|
11
|
+
* Failure text never contains a value taken from the document, apart from a
|
|
12
|
+
* shortened schema_version. A rejected field may be holding a credential, so
|
|
13
|
+
* issues carry the path, the rule that failed and at most a property name,
|
|
14
|
+
* and a property name is printed only when it looks like a plain field name.
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import Ajv2020 from "ajv/dist/2020.js";
|
|
20
|
+
import { credentialShapesIn } from "./credential-shapes.js";
|
|
21
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
export const ENVIRONMENT_PROFILE_SCHEMA_VERSION = "hq-environment-profile.v1";
|
|
23
|
+
export const ENVIRONMENT_PROFILE_SCHEMA_ID = "urn:hq:schema:hq-environment-profile:v1";
|
|
24
|
+
export const ENVIRONMENT_PROFILE_SCHEMA_PATH = join(HERE, "..", "..", "schemas", "hq-environment-profile.v1.schema.json");
|
|
25
|
+
const TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-](\d{2}):(\d{2}))$/;
|
|
26
|
+
/** RFC 3339 date-time with a real calendar date and in-range clock fields. */
|
|
27
|
+
export function isRfc3339DateTime(value) {
|
|
28
|
+
const match = TIMESTAMP.exec(value);
|
|
29
|
+
if (!match)
|
|
30
|
+
return false;
|
|
31
|
+
const [year, month, day, hour, minute, second] = match.slice(1, 7).map(Number);
|
|
32
|
+
if (month < 1 || month > 12 || day < 1)
|
|
33
|
+
return false;
|
|
34
|
+
// Day 0 of the next month is the last day of this one.
|
|
35
|
+
const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
36
|
+
if (day > daysInMonth)
|
|
37
|
+
return false;
|
|
38
|
+
// 60 is allowed for a leap second.
|
|
39
|
+
if (hour > 23 || minute > 59 || second > 60)
|
|
40
|
+
return false;
|
|
41
|
+
if (match[9] !== undefined && (Number(match[9]) > 23 || Number(match[10]) > 59))
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/** At most this many issues are listed; the rest are counted. */
|
|
46
|
+
export const ENVIRONMENT_PROFILE_MAX_ISSUES = 100;
|
|
47
|
+
/**
|
|
48
|
+
* Replace every local `#/$defs/...` reference with the schema it names.
|
|
49
|
+
*
|
|
50
|
+
* Ajv compiles a `$ref` that itself contains a `$ref` as a function call, and
|
|
51
|
+
* with allErrors it copies the whole error list after each call. A document
|
|
52
|
+
* with many invalid readings then costs time in the square of their number
|
|
53
|
+
* (16,000 invalid probes took 1.3 s). The schema has no recursive reference,
|
|
54
|
+
* so it can be flattened, and the compiled validator appends errors in place.
|
|
55
|
+
*/
|
|
56
|
+
function inlineLocalRefs(node, defs, depth = 0) {
|
|
57
|
+
if (depth > 32)
|
|
58
|
+
throw new Error("hq-environment-profile.v1 schema has a recursive $ref");
|
|
59
|
+
if (Array.isArray(node))
|
|
60
|
+
return node.map((entry) => inlineLocalRefs(entry, defs, depth));
|
|
61
|
+
if (node === null || typeof node !== "object")
|
|
62
|
+
return node;
|
|
63
|
+
const record = node;
|
|
64
|
+
const out = {};
|
|
65
|
+
for (const [key, value] of Object.entries(record)) {
|
|
66
|
+
if (key === "$ref" || key === "$defs")
|
|
67
|
+
continue;
|
|
68
|
+
out[key] = inlineLocalRefs(value, defs, depth);
|
|
69
|
+
}
|
|
70
|
+
const ref = record.$ref;
|
|
71
|
+
if (typeof ref !== "string")
|
|
72
|
+
return out;
|
|
73
|
+
const name = /^#\/\$defs\/([A-Za-z0-9_]+)$/.exec(ref)?.[1];
|
|
74
|
+
if (!name || !(name in defs))
|
|
75
|
+
throw new Error(`hq-environment-profile.v1 schema has an unresolved $ref ${ref}`);
|
|
76
|
+
const target = inlineLocalRefs(defs[name], defs, depth + 1);
|
|
77
|
+
const siblings = Object.keys(out).filter((key) => key !== "description");
|
|
78
|
+
if (siblings.length === 0)
|
|
79
|
+
return { ...target, ...out };
|
|
80
|
+
const existing = Array.isArray(out.allOf) ? out.allOf : [];
|
|
81
|
+
return { ...out, allOf: [...existing, target] };
|
|
82
|
+
}
|
|
83
|
+
let cachedValidate;
|
|
84
|
+
function validator() {
|
|
85
|
+
if (cachedValidate)
|
|
86
|
+
return cachedValidate;
|
|
87
|
+
const schema = JSON.parse(readFileSync(ENVIRONMENT_PROFILE_SCHEMA_PATH, "utf8"));
|
|
88
|
+
const defs = (schema.$defs ?? {});
|
|
89
|
+
const ajv = new Ajv2020({
|
|
90
|
+
allErrors: true,
|
|
91
|
+
strict: false,
|
|
92
|
+
formats: { "date-time": isRfc3339DateTime },
|
|
93
|
+
});
|
|
94
|
+
cachedValidate = ajv.compile(inlineLocalRefs(schema, defs));
|
|
95
|
+
return cachedValidate;
|
|
96
|
+
}
|
|
97
|
+
/** A short printable form of a string from the document. */
|
|
98
|
+
function printable(value, limit) {
|
|
99
|
+
const short = value.length > limit ? `${value.slice(0, limit)}...` : value;
|
|
100
|
+
return short.replace(/[^\x20-\x7e]/g, "?");
|
|
101
|
+
}
|
|
102
|
+
/** A property name is printed only when it looks like a field name. */
|
|
103
|
+
const PLAIN_FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,40}$/;
|
|
104
|
+
function pointerSegment(key) {
|
|
105
|
+
return key.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Every string in a profile is a name, a label or a sentence about where a
|
|
109
|
+
* value came from. None may hold a credential, so a string or property name
|
|
110
|
+
* shaped like one is an issue. The shape is named; the string is not printed.
|
|
111
|
+
*/
|
|
112
|
+
function credentialIssues(value, at, out) {
|
|
113
|
+
if (typeof value === "string") {
|
|
114
|
+
const shapes = credentialShapesIn(value);
|
|
115
|
+
if (shapes.length > 0)
|
|
116
|
+
out.push({ path: at, message: `holds a string shaped like a credential (${shapes.join(", ")})` });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(value)) {
|
|
120
|
+
value.forEach((entry, index) => credentialIssues(entry, `${at}/${index}`, out));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (value === null || typeof value !== "object")
|
|
124
|
+
return;
|
|
125
|
+
for (const [key, child] of Object.entries(value)) {
|
|
126
|
+
const shapes = credentialShapesIn(key);
|
|
127
|
+
if (shapes.length > 0) {
|
|
128
|
+
out.push({ path: at, message: `has a property name shaped like a credential (${shapes.join(", ")})` });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
credentialIssues(child, `${at}/${pointerSegment(key)}`, out);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** view.company must be one of declared.companies. */
|
|
135
|
+
function companyIssues(value) {
|
|
136
|
+
const view = value.view;
|
|
137
|
+
const declared = value.declared;
|
|
138
|
+
const company = view && typeof view === "object" ? view.company : undefined;
|
|
139
|
+
const companies = declared && typeof declared === "object" ? declared.companies : undefined;
|
|
140
|
+
if (typeof company !== "string" || !Array.isArray(companies))
|
|
141
|
+
return [];
|
|
142
|
+
if (companies.includes(company))
|
|
143
|
+
return [];
|
|
144
|
+
return [{ path: "/view/company", message: "must be one of declared.companies" }];
|
|
145
|
+
}
|
|
146
|
+
function issueFrom(error) {
|
|
147
|
+
// An "if" error only says that the paired "then" failed; the "then" errors
|
|
148
|
+
// carry the path and the rule.
|
|
149
|
+
if (error.keyword === "if")
|
|
150
|
+
return null;
|
|
151
|
+
let message = error.message ?? "is not valid";
|
|
152
|
+
const params = error.params;
|
|
153
|
+
const extra = params.additionalProperty ?? params.unevaluatedProperty;
|
|
154
|
+
if (typeof extra === "string") {
|
|
155
|
+
message = PLAIN_FIELD_NAME.test(extra) && credentialShapesIn(extra).length === 0
|
|
156
|
+
? `must not have property "${extra}"`
|
|
157
|
+
: "must not have an unexpected property";
|
|
158
|
+
}
|
|
159
|
+
else if (error.keyword === "false schema") {
|
|
160
|
+
message = "is not allowed here";
|
|
161
|
+
}
|
|
162
|
+
return { path: error.instancePath, message };
|
|
163
|
+
}
|
|
164
|
+
function failure(code, message, issues = [], omitted = 0) {
|
|
165
|
+
return { ok: false, code, message, issues, issues_omitted: omitted };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Validate a parsed document. The schema_version is checked first, so a
|
|
169
|
+
* document from a later major version is refused by name and is not reported
|
|
170
|
+
* as a list of field errors against the v1 schema.
|
|
171
|
+
*
|
|
172
|
+
* Beyond the schema, two rules are checked here because JSON Schema cannot
|
|
173
|
+
* express them: view.company is one of declared.companies, and no string is
|
|
174
|
+
* shaped like a credential. At most ENVIRONMENT_PROFILE_MAX_ISSUES issues are
|
|
175
|
+
* returned; issues_omitted counts the rest.
|
|
176
|
+
*/
|
|
177
|
+
export function validateEnvironmentProfile(value) {
|
|
178
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
179
|
+
return failure("not_an_object", "an environment profile must be a JSON object");
|
|
180
|
+
}
|
|
181
|
+
const version = value.schema_version;
|
|
182
|
+
if (version === undefined) {
|
|
183
|
+
return failure("missing_schema_version", `schema_version is missing; this CLI reads ${ENVIRONMENT_PROFILE_SCHEMA_VERSION}`);
|
|
184
|
+
}
|
|
185
|
+
if (version !== ENVIRONMENT_PROFILE_SCHEMA_VERSION) {
|
|
186
|
+
const named = typeof version === "string" ? `"${printable(version, 80)}"` : `of type ${typeof version}`;
|
|
187
|
+
return failure("unsupported_schema_version", `unsupported schema_version ${named}; this CLI reads ${ENVIRONMENT_PROFILE_SCHEMA_VERSION}`);
|
|
188
|
+
}
|
|
189
|
+
const validate = validator();
|
|
190
|
+
const schemaValid = validate(value);
|
|
191
|
+
const kept = [];
|
|
192
|
+
const seen = new Set();
|
|
193
|
+
let total = 0;
|
|
194
|
+
const add = (issue) => {
|
|
195
|
+
if (!issue)
|
|
196
|
+
return;
|
|
197
|
+
// Duplicates come from two branches reporting the same rule at the same
|
|
198
|
+
// path, close together, so remembering a bounded number of keys is enough.
|
|
199
|
+
const key = `${issue.path}\u0000${issue.message}`;
|
|
200
|
+
if (seen.has(key))
|
|
201
|
+
return;
|
|
202
|
+
if (seen.size < ENVIRONMENT_PROFILE_MAX_ISSUES * 100)
|
|
203
|
+
seen.add(key);
|
|
204
|
+
total += 1;
|
|
205
|
+
if (kept.length < ENVIRONMENT_PROFILE_MAX_ISSUES)
|
|
206
|
+
kept.push(issue);
|
|
207
|
+
};
|
|
208
|
+
// Rules outside the schema first, so a credential-shaped string is always
|
|
209
|
+
// among the listed issues however many schema errors follow.
|
|
210
|
+
const credentials = [];
|
|
211
|
+
credentialIssues(value, "", credentials);
|
|
212
|
+
for (const issue of credentials)
|
|
213
|
+
add(issue);
|
|
214
|
+
for (const issue of companyIssues(value))
|
|
215
|
+
add(issue);
|
|
216
|
+
if (!schemaValid)
|
|
217
|
+
for (const error of validate.errors ?? [])
|
|
218
|
+
add(issueFrom(error));
|
|
219
|
+
if (total === 0)
|
|
220
|
+
return { ok: true, profile: value };
|
|
221
|
+
kept.sort((a, b) => (a.path === b.path ? a.message.localeCompare(b.message) : a.path < b.path ? -1 : 1));
|
|
222
|
+
const omitted = total - kept.length;
|
|
223
|
+
const count = total === 1 ? "1 issue" : `${total} issues`;
|
|
224
|
+
const listed = omitted > 0 ? `; the first ${kept.length} are listed` : "";
|
|
225
|
+
return failure("invalid", `not a valid ${ENVIRONMENT_PROFILE_SCHEMA_VERSION} document (${count}${listed})`, kept, omitted);
|
|
226
|
+
}
|
|
227
|
+
/** Parse JSON text and validate it. The text is never echoed in a failure. */
|
|
228
|
+
export function parseEnvironmentProfile(text) {
|
|
229
|
+
let value;
|
|
230
|
+
try {
|
|
231
|
+
// A leading UTF-8 byte-order mark is not part of the JSON.
|
|
232
|
+
value = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return failure("invalid_json", "the document is not valid JSON");
|
|
236
|
+
}
|
|
237
|
+
return validateEnvironmentProfile(value);
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CoreNextHost, CoreNextTarget } from '../../utils/host-registration.js';
|
|
2
|
+
/** Stands for the hook list when it cannot be read; never covered. */
|
|
3
|
+
export declare const UNREADABLE = "(the old dispatcher hook list could not be read)";
|
|
4
|
+
/** The hooks the old dispatcher runs for `event` on `host` in this HQ root; null when they cannot be read exactly. */
|
|
5
|
+
export declare function shellHooks(root: string, host: CoreNextHost, event: string): string[] | null;
|
|
6
|
+
/** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
|
|
7
|
+
export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined): string[];
|
|
8
|
+
/**
|
|
9
|
+
* `target` narrowed to the events it covers in full on `host` in this HQ
|
|
10
|
+
* root; null when none is covered (every event stays on the old dispatcher).
|
|
11
|
+
*/
|
|
12
|
+
export declare function forHost(target: CoreNextTarget | null, root: string, host: CoreNextHost): CoreNextTarget | null;
|
|
13
|
+
//# sourceMappingURL=coverage.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coverage gate of the registration switch (hq-core-rust US-017).
|
|
3
|
+
*
|
|
4
|
+
* A switched event's new-core entry replaces the shell registration, so the
|
|
5
|
+
* new core must do everything the old dispatcher does for that event on that
|
|
6
|
+
* host. Both sides come from data, not from a list kept in the CLI:
|
|
7
|
+
*
|
|
8
|
+
* - The old dispatcher's hooks are read from this HQ root, the way
|
|
9
|
+
* `.claude/hooks/master-hook.sh` finds them: every `hook-registry.json`
|
|
10
|
+
* entry for the event (all matchers), and every `*.sh` in
|
|
11
|
+
* `core/hooks/<Event>`, `personal/hooks/<Event>`,
|
|
12
|
+
* `core/packages/<pack>/hooks/<Event>` and `companies/<co>/hooks/<Event>`
|
|
13
|
+
* (any company, since the active one is chosen at run time). Folder hooks
|
|
14
|
+
* are named by their path under the root. `master-hook:<Event>` stands for
|
|
15
|
+
* the dispatcher's own work for the event. On Codex and Grok the adapter's
|
|
16
|
+
* own work (`codex-adapter:<Event>`, `grok-adapter:<Event>`) and every
|
|
17
|
+
* other command `.claude/settings.json` registers for the event
|
|
18
|
+
* (`settings:<command>`) are added, because the adapters run those too.
|
|
19
|
+
* - What the new core does in full is what the installed engine reports in
|
|
20
|
+
* `hq-hook capabilities --json` under `covers`.
|
|
21
|
+
*
|
|
22
|
+
* An event switches only when every old hook is covered. A hook list that
|
|
23
|
+
* cannot be read counts as not covered, and an engine that reports no
|
|
24
|
+
* `covers` covers nothing, so the event stays on the old dispatcher.
|
|
25
|
+
*/
|
|
26
|
+
import * as fs from 'node:fs';
|
|
27
|
+
import * as path from 'node:path';
|
|
28
|
+
import { isCoreNextEntry } from './registration.js';
|
|
29
|
+
/** Stands for the hook list when it cannot be read; never covered. */
|
|
30
|
+
export const UNREADABLE = '(the old dispatcher hook list could not be read)';
|
|
31
|
+
/** Folder hook that master-hook.sh never dispatches (retired; `hq rescue` can leave it on disk). */
|
|
32
|
+
const RETIRED = new Set(['Stop/70-work-mesh-done.sh']);
|
|
33
|
+
function listDir(dir) {
|
|
34
|
+
try {
|
|
35
|
+
return fs.readdirSync(dir).sort();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Absent folder: no hooks there.
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The hooks the old dispatcher runs for `event` on `host` in this HQ root; null when they cannot be read exactly. */
|
|
43
|
+
export function shellHooks(root, host, event) {
|
|
44
|
+
const out = [`master-hook:${event}`];
|
|
45
|
+
let registry;
|
|
46
|
+
try {
|
|
47
|
+
registry = JSON.parse(fs.readFileSync(path.join(root, '.claude', 'hooks', 'hook-registry.json'), 'utf8'));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const hooks = registry?.hooks;
|
|
53
|
+
if (!hooks || typeof hooks !== 'object' || Array.isArray(hooks))
|
|
54
|
+
return null;
|
|
55
|
+
const groups = hooks[event] ?? [];
|
|
56
|
+
if (!Array.isArray(groups))
|
|
57
|
+
return null;
|
|
58
|
+
for (const group of groups) {
|
|
59
|
+
const entries = group?.hooks;
|
|
60
|
+
if (!Array.isArray(entries))
|
|
61
|
+
return null;
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
const id = entry?.id;
|
|
64
|
+
if (typeof id !== 'string' || id === '')
|
|
65
|
+
return null;
|
|
66
|
+
out.push(id);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const folders = [`core/hooks/${event}`, `personal/hooks/${event}`];
|
|
70
|
+
for (const base of ['core/packages', 'companies']) {
|
|
71
|
+
for (const name of listDir(path.join(root, base)))
|
|
72
|
+
folders.push(`${base}/${name}/hooks/${event}`);
|
|
73
|
+
}
|
|
74
|
+
for (const folder of folders) {
|
|
75
|
+
for (const file of listDir(path.join(root, folder))) {
|
|
76
|
+
if (!file.endsWith('.sh'))
|
|
77
|
+
continue;
|
|
78
|
+
if (folder === `core/hooks/${event}` && RETIRED.has(`${event}/${file}`))
|
|
79
|
+
continue;
|
|
80
|
+
out.push(`${folder}/${file}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (host !== 'claude') {
|
|
84
|
+
out.push(`${host}-adapter:${event}`);
|
|
85
|
+
let settings;
|
|
86
|
+
try {
|
|
87
|
+
settings = JSON.parse(fs.readFileSync(path.join(root, '.claude', 'settings.json'), 'utf8'));
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const registered = (settings?.hooks ?? {})[event];
|
|
93
|
+
for (const group of Array.isArray(registered) ? registered : []) {
|
|
94
|
+
for (const entry of Array.isArray(group?.hooks) ? group.hooks : []) {
|
|
95
|
+
const command = entry?.command;
|
|
96
|
+
// HQ's own entry for the event (master-hook, or the Claude Code
|
|
97
|
+
// new-core entry that took its place) is the dispatcher counted above.
|
|
98
|
+
if (typeof command !== 'string' || command.includes('master-hook.sh') || isCoreNextEntry(entry, root))
|
|
99
|
+
continue;
|
|
100
|
+
out.push(`settings:${command}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
|
|
107
|
+
export function uncoveredHooks(root, host, event, covers) {
|
|
108
|
+
const hooks = shellHooks(root, host, event);
|
|
109
|
+
if (!hooks)
|
|
110
|
+
return [UNREADABLE];
|
|
111
|
+
const covered = covers?.[event] ?? [];
|
|
112
|
+
return hooks.filter((hook) => !covered.includes(hook));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* `target` narrowed to the events it covers in full on `host` in this HQ
|
|
116
|
+
* root; null when none is covered (every event stays on the old dispatcher).
|
|
117
|
+
*/
|
|
118
|
+
export function forHost(target, root, host) {
|
|
119
|
+
if (!target)
|
|
120
|
+
return null;
|
|
121
|
+
const events = target.events.filter((event) => uncoveredHooks(root, host, event, target.covers).length === 0);
|
|
122
|
+
return events.length ? { ...target, events } : null;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=coverage.js.map
|