@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,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential shapes in environment profile text.
|
|
3
|
+
*
|
|
4
|
+
* What counts as a credential is decided by SECRET_PATTERNS in
|
|
5
|
+
* src/lib/core-utils/secret-patterns.ts, the list `hq core secret-scan` uses.
|
|
6
|
+
* This module does not keep a second set of shapes. It applies the shared
|
|
7
|
+
* expressions, unchanged, to bounded windows of the text, so that:
|
|
8
|
+
*
|
|
9
|
+
* - the result for a string is the result the shared list gives for it
|
|
10
|
+
* (`sharedShapesIn`, checked against `matchingSecretPatterns` in
|
|
11
|
+
* credential-equivalence.test.ts), and
|
|
12
|
+
* - the time is linear in the length of the string. Applied to one long
|
|
13
|
+
* string as a whole, the JWT expression restarts at every candidate and
|
|
14
|
+
* rescans to the end, which took 29 s for a 320 KB note.
|
|
15
|
+
*
|
|
16
|
+
* Windows.
|
|
17
|
+
*
|
|
18
|
+
* - Every expression except JWT is run on consecutive chunks of CHUNK
|
|
19
|
+
* characters that overlap by OVERLAP. A match of any of those expressions
|
|
20
|
+
* has a shortest form of at most 41 characters from its start (a prefix
|
|
21
|
+
* and a minimum count), so every match start lies in a chunk that holds
|
|
22
|
+
* that shortest form. The cost of one chunk is bounded by its size.
|
|
23
|
+
* - A JWT match is three dot-separated runs of [A-Za-z0-9_-]. Only the
|
|
24
|
+
* minimum counts (20, 20, 10) matter to the expression, so a long run can
|
|
25
|
+
* be cut after 64 characters without changing the answer. Each window is
|
|
26
|
+
* one piece of a first segment (at most 320 characters), the first 64
|
|
27
|
+
* characters of the next segment and the first 64 of the one after.
|
|
28
|
+
*
|
|
29
|
+
* Exemptions. Profile text is sentences, hostnames and labels, and a match
|
|
30
|
+
* rejects the profile. Three exemptions accept ordinary text that matches the
|
|
31
|
+
* shared list: a Slack prefix named in a sentence, a host name that starts
|
|
32
|
+
* with the key prefix letters, and an Authorization header followed by a
|
|
33
|
+
* secret's NAME. Each fails closed: it reads the whole white-space-delimited
|
|
34
|
+
* token and accepts only a closed form. Nothing else the shared list rejects
|
|
35
|
+
* is accepted here, and some ordinary text is rejected as the price of that.
|
|
36
|
+
*
|
|
37
|
+
* There is no exemption for a private key header. Any string that holds a
|
|
38
|
+
* BEGIN ... PRIVATE KEY line is rejected, as on main, with or without key
|
|
39
|
+
* material after it, because the body can sit in another string of the same
|
|
40
|
+
* profile. To mention a key in a profile, name its type in words.
|
|
41
|
+
*
|
|
42
|
+
* One rule is added to the shared list: a URL with an inline password.
|
|
43
|
+
*/
|
|
44
|
+
import { SECRET_PATTERN_BOUNDARY, SECRET_PATTERNS } from "../core-utils/secret-patterns.js";
|
|
45
|
+
const URL_PASSWORD = "URL with an inline password";
|
|
46
|
+
const CHUNK = 4096;
|
|
47
|
+
const OVERLAP = 256;
|
|
48
|
+
const JWT_NAME = "JWT";
|
|
49
|
+
const JWT_PIECE = 256;
|
|
50
|
+
const JWT_EXTENSION = 64;
|
|
51
|
+
const JWT_SEGMENT_CAP = 64;
|
|
52
|
+
// "(^|[^a-zA-Z0-9])" without the start-of-text alternative.
|
|
53
|
+
const BOUNDARY_CHARACTER = SECRET_PATTERN_BOUNDARY.replace("^|", "");
|
|
54
|
+
const COMPILED = SECRET_PATTERNS.map(({ pattern, name }) => ({
|
|
55
|
+
name,
|
|
56
|
+
whole: new RegExp(`${SECRET_PATTERN_BOUNDARY}${pattern}`),
|
|
57
|
+
first: new RegExp(`${SECRET_PATTERN_BOUNDARY}(?:${pattern})`, "g"),
|
|
58
|
+
later: new RegExp(`${BOUNDARY_CHARACTER}(?:${pattern})`, "g"),
|
|
59
|
+
afterCharacter: new RegExp(`${BOUNDARY_CHARACTER}(?:${pattern})`),
|
|
60
|
+
}));
|
|
61
|
+
/**
|
|
62
|
+
* Call `visit` with the start and end of each match of one shared expression,
|
|
63
|
+
* found chunk by chunk. `start` is the first character of the token, after the
|
|
64
|
+
* boundary character. Stops when `visit` returns true and returns true.
|
|
65
|
+
*/
|
|
66
|
+
function someChunkedMatch(shape, text, visit) {
|
|
67
|
+
for (let from = 0;; from += CHUNK - OVERLAP) {
|
|
68
|
+
const expression = from === 0 ? shape.first : shape.later;
|
|
69
|
+
// A later chunk begins one character early so its first position has a real boundary character.
|
|
70
|
+
const base = from === 0 ? 0 : from - 1;
|
|
71
|
+
const chunk = text.slice(base, from + CHUNK);
|
|
72
|
+
expression.lastIndex = 0;
|
|
73
|
+
for (let match = expression.exec(chunk); match !== null; match = expression.exec(chunk)) {
|
|
74
|
+
const boundary = match[1]?.length ?? 0;
|
|
75
|
+
if (visit(base + match.index + boundary, base + match.index + match[0].length))
|
|
76
|
+
return true;
|
|
77
|
+
if (match[0].length === 0)
|
|
78
|
+
expression.lastIndex += 1;
|
|
79
|
+
}
|
|
80
|
+
if (from + CHUNK >= text.length)
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const isDigit = (c) => c >= 48 && c <= 57;
|
|
85
|
+
const isUpper = (c) => c >= 65 && c <= 90;
|
|
86
|
+
const isLower = (c) => c >= 97 && c <= 122;
|
|
87
|
+
const isAlnum = (c) => isDigit(c) || isUpper(c) || isLower(c);
|
|
88
|
+
const DOT = 46;
|
|
89
|
+
const DASH = 45;
|
|
90
|
+
const UNDERSCORE = 95;
|
|
91
|
+
const isJwtSegmentCharacter = (c) => isAlnum(c) || c === UNDERSCORE || c === DASH;
|
|
92
|
+
/** Whether the shared JWT expression matches anywhere in `text`, using bounded windows. */
|
|
93
|
+
function jwtPresent(shape, text) {
|
|
94
|
+
let at = 0;
|
|
95
|
+
while (at < text.length) {
|
|
96
|
+
// One maximal run of JWT characters and dots.
|
|
97
|
+
while (at < text.length && !isJwtSegmentCharacter(text.charCodeAt(at)) && text.charCodeAt(at) !== DOT)
|
|
98
|
+
at += 1;
|
|
99
|
+
const runStart = at;
|
|
100
|
+
const segments = [];
|
|
101
|
+
let segmentStart = at;
|
|
102
|
+
for (; at < text.length; at += 1) {
|
|
103
|
+
const c = text.charCodeAt(at);
|
|
104
|
+
if (c === DOT) {
|
|
105
|
+
segments.push([segmentStart, at]);
|
|
106
|
+
segmentStart = at + 1;
|
|
107
|
+
}
|
|
108
|
+
else if (!isJwtSegmentCharacter(c))
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (at > runStart)
|
|
112
|
+
segments.push([segmentStart, at]);
|
|
113
|
+
// The expression has two literal dots, so a match needs two segments after its first.
|
|
114
|
+
for (let index = 0; index + 2 < segments.length; index += 1) {
|
|
115
|
+
const [firstStart, firstEnd] = segments[index];
|
|
116
|
+
const [secondStart, secondEnd] = segments[index + 1];
|
|
117
|
+
const [thirdStart, thirdEnd] = segments[index + 2];
|
|
118
|
+
const tail = `.${text.slice(secondStart, Math.min(secondEnd, secondStart + JWT_SEGMENT_CAP))}.${text.slice(thirdStart, Math.min(thirdEnd, thirdStart + JWT_SEGMENT_CAP))}`;
|
|
119
|
+
for (let piece = firstStart; piece < firstEnd; piece += JWT_PIECE) {
|
|
120
|
+
const before = piece > 0 ? text[piece - 1] : "";
|
|
121
|
+
const window = before + text.slice(piece, Math.min(firstEnd, piece + JWT_PIECE + JWT_EXTENSION)) + tail;
|
|
122
|
+
// With a character in front, the start of the window is not the start of the text.
|
|
123
|
+
if ((before === "" ? shape.whole : shape.afterCharacter).test(window))
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
/** Read the run of characters satisfying `inClass` from `from`, at most `cap` characters. null when the run is longer. */
|
|
131
|
+
function runFrom(text, from, inClass, cap) {
|
|
132
|
+
let end = from;
|
|
133
|
+
while (end < text.length && end - from <= cap && inClass(text.charCodeAt(end)))
|
|
134
|
+
end += 1;
|
|
135
|
+
return end - from > cap ? null : text.slice(from, end);
|
|
136
|
+
}
|
|
137
|
+
/*
|
|
138
|
+
* Exemptions fail closed. Each one is decided on the whole white-space
|
|
139
|
+
* delimited token the match starts and accepts only a closed form. Anything
|
|
140
|
+
* else the shared list rejects is rejected, at the cost of some ordinary text
|
|
141
|
+
* being rejected too.
|
|
142
|
+
*/
|
|
143
|
+
const CLOSERS = ".,;\"')`";
|
|
144
|
+
/**
|
|
145
|
+
* The text from `start` to the next white space or the end, without one
|
|
146
|
+
* closing punctuation mark at its very end. null when it is longer than 255
|
|
147
|
+
* characters. Punctuation anywhere else stays in the token, so "joined to more
|
|
148
|
+
* characters" is always visible to the rule that reads it.
|
|
149
|
+
*/
|
|
150
|
+
function tokenFrom(text, start) {
|
|
151
|
+
let end = start;
|
|
152
|
+
while (end < text.length && end - start <= 255 && text.charCodeAt(end) > 32)
|
|
153
|
+
end += 1;
|
|
154
|
+
if (end - start > 255)
|
|
155
|
+
return null;
|
|
156
|
+
const token = text.slice(start, end);
|
|
157
|
+
return token.length > 1 && CLOSERS.includes(token[token.length - 1]) ? token.slice(0, -1) : token;
|
|
158
|
+
}
|
|
159
|
+
const SLACK_PROSE_WORDS = new Set([
|
|
160
|
+
"style", "styled", "prefix", "prefixed", "type", "typed", "token", "tokens", "format", "kind", "like", "shaped", "based", "family",
|
|
161
|
+
]);
|
|
162
|
+
/**
|
|
163
|
+
* Exemption 1. A sentence that names a Slack token prefix, such as the prefix,
|
|
164
|
+
* a hyphen and the word "style". Exempt only when the whole token is the
|
|
165
|
+
* prefix, a hyphen and one word from a closed list.
|
|
166
|
+
*/
|
|
167
|
+
function slackPrefixInProse(text, start) {
|
|
168
|
+
const token = tokenFrom(text, start);
|
|
169
|
+
return token !== null && SLACK_PROSE_WORDS.has(token.slice(5));
|
|
170
|
+
}
|
|
171
|
+
const HOST_SUFFIXES = new Set([
|
|
172
|
+
"example", "internal", "local", "localhost", "test", "invalid", "lan", "corp", "arpa", "svc",
|
|
173
|
+
"com", "net", "org", "io", "dev", "ai", "co", "app", "cloud",
|
|
174
|
+
]);
|
|
175
|
+
/**
|
|
176
|
+
* Exemptions 2 and 3. A host name that starts with the letters and hyphen of
|
|
177
|
+
* the OpenAI key prefix, in free text or in an identifier field such as
|
|
178
|
+
* declared.aliases. Exempt only when the whole token is a dotted host name in
|
|
179
|
+
* lower case whose last label is in a closed list of suffixes, with at least
|
|
180
|
+
* two plain words and no piece that could be key material: letters only up to
|
|
181
|
+
* 15 characters, digits only up to 5, letters and digits mixed up to 8.
|
|
182
|
+
*
|
|
183
|
+
* Known limit: material deliberately shaped as such a host name and ending in
|
|
184
|
+
* a listed suffix is accepted, for example the prefix, two random 15-letter
|
|
185
|
+
* pieces and ".com". No key format is written that way. The behaviour is
|
|
186
|
+
* pinned by a test named as a known limit in credential-exemptions.test.ts.
|
|
187
|
+
*/
|
|
188
|
+
function hostnameWithKeyPrefix(text, start) {
|
|
189
|
+
const token = tokenFrom(text, start);
|
|
190
|
+
if (token === null || !/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(token))
|
|
191
|
+
return false;
|
|
192
|
+
const labels = token.split(".");
|
|
193
|
+
if (labels.length < 2 || !HOST_SUFFIXES.has(labels[labels.length - 1]))
|
|
194
|
+
return false;
|
|
195
|
+
let words = 0;
|
|
196
|
+
for (const piece of token.split(/[.-]/).slice(1)) {
|
|
197
|
+
const letters = /[a-z]/.test(piece);
|
|
198
|
+
const digits = /[0-9]/.test(piece);
|
|
199
|
+
if (piece.length > (letters && digits ? 8 : letters ? 15 : 5))
|
|
200
|
+
return false;
|
|
201
|
+
if (letters && !digits && piece.length >= 3)
|
|
202
|
+
words += 1;
|
|
203
|
+
}
|
|
204
|
+
return words >= 2;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Exemption 4. An Authorization header whose value is a secret's NAME and not
|
|
208
|
+
* a value. Exempt only when the whole token after the scheme word is upper
|
|
209
|
+
* snake case: capitals, digits and underscores, starting with a letter, with
|
|
210
|
+
* at least one underscore, at most 64 characters, and every piece between
|
|
211
|
+
* underscores either at most 4 characters or holding a letter from G to Z and
|
|
212
|
+
* at most 24 characters. Hex with underscores is therefore not a NAME. A NAME
|
|
213
|
+
* joined to anything (plus, slash, equals, dot, hyphen, colon, more
|
|
214
|
+
* characters) is not exempt, because the token is read up to white space.
|
|
215
|
+
*
|
|
216
|
+
* Known limit: material deliberately written as upper snake case with pieces
|
|
217
|
+
* that fit this rule is accepted, for example 32 upper-case hex in groups of
|
|
218
|
+
* four joined by underscores. No token format is written that way. The
|
|
219
|
+
* behaviour is pinned by a test named as a known limit in
|
|
220
|
+
* credential-exemptions.test.ts.
|
|
221
|
+
*
|
|
222
|
+
* There is no placeholder list. A header followed by a lower-case placeholder
|
|
223
|
+
* of hyphen-joined words was exempt in an earlier version; it cannot be told
|
|
224
|
+
* from token material without guessing, so it is rejected.
|
|
225
|
+
*/
|
|
226
|
+
function bearerSecretName(text, start) {
|
|
227
|
+
const token = tokenFrom(text, start + "Bearer ".length);
|
|
228
|
+
if (token === null || token.length > 64 || !/^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/.test(token))
|
|
229
|
+
return false;
|
|
230
|
+
return token.split("_").every((piece) => piece.length <= 4 || (piece.length <= 24 && /[G-Z]/.test(piece)));
|
|
231
|
+
}
|
|
232
|
+
const EXEMPTIONS = {
|
|
233
|
+
"Slack token": slackPrefixInProse,
|
|
234
|
+
"OpenAI/Stripe key": hostnameWithKeyPrefix,
|
|
235
|
+
"Bearer token": bearerSecretName,
|
|
236
|
+
};
|
|
237
|
+
const isHostCharacter = (c) => isAlnum(c) || c === DOT || c === DASH;
|
|
238
|
+
/** Whether a host-like name starts at `from`: letters, digits, dots and hyphens, with a dot, or "localhost". */
|
|
239
|
+
function hostAt(text, from) {
|
|
240
|
+
const host = runFrom(text, from, isHostCharacter, 253);
|
|
241
|
+
if (host === null)
|
|
242
|
+
return true;
|
|
243
|
+
return host === "localhost" || (host.length >= 3 && host.includes(".") && isAlnum(host.charCodeAt(0)));
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* scheme://user:password@host, including an empty user name. A user name
|
|
247
|
+
* alone, a port, and a colon or at-sign in the path or query are not
|
|
248
|
+
* passwords.
|
|
249
|
+
*
|
|
250
|
+
* The authority normally ends at a slash, question mark, hash, comma, space,
|
|
251
|
+
* quote or angle bracket. A password may itself contain one of those. So when
|
|
252
|
+
* the text up to that point has a colon that is not followed by a port
|
|
253
|
+
* number, the scan looks up to 128 characters further for an at-sign followed
|
|
254
|
+
* by a host name, and allows at most one space on the way, so that a sentence
|
|
255
|
+
* with an email address later in it is not taken for a password.
|
|
256
|
+
*
|
|
257
|
+
* Not covered: a URL with no scheme (two slashes alone), and a token used as
|
|
258
|
+
* the user name with no colon, which is reported only when it has a shape
|
|
259
|
+
* from the shared list.
|
|
260
|
+
*/
|
|
261
|
+
function urlWithPassword(text) {
|
|
262
|
+
for (let at = text.indexOf("://"); at !== -1; at = text.indexOf("://", at + 3)) {
|
|
263
|
+
const start = at + 3;
|
|
264
|
+
let end = start;
|
|
265
|
+
let colon = -1;
|
|
266
|
+
let lastAt = -1;
|
|
267
|
+
for (; end < text.length; end += 1) {
|
|
268
|
+
const c = text.charCodeAt(end);
|
|
269
|
+
if (c === 47 || c === 63 || c === 35 || c === 44 || c <= 32 || c === 34 || c === 39 || c === 60 || c === 62)
|
|
270
|
+
break;
|
|
271
|
+
if (c === 58 && colon === -1)
|
|
272
|
+
colon = end;
|
|
273
|
+
if (c === 64)
|
|
274
|
+
lastAt = end;
|
|
275
|
+
}
|
|
276
|
+
if (lastAt !== -1) {
|
|
277
|
+
// user:password@host inside the authority. The password is not empty.
|
|
278
|
+
if (colon !== -1 && colon < lastAt - 1)
|
|
279
|
+
return true;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (colon === -1 || text.charCodeAt(start) === 91)
|
|
283
|
+
continue; // no colon, or an IPv6 literal
|
|
284
|
+
const afterColon = text.slice(colon + 1, end);
|
|
285
|
+
if (afterColon === "" || /^[0-9]{1,5}$/.test(afterColon))
|
|
286
|
+
continue; // nothing, or a port
|
|
287
|
+
let spaces = 0;
|
|
288
|
+
const limit = Math.min(text.length, colon + 1 + 128);
|
|
289
|
+
for (let index = end; index < limit; index += 1) {
|
|
290
|
+
const c = text.charCodeAt(index);
|
|
291
|
+
if (c === 10 || c === 13)
|
|
292
|
+
break;
|
|
293
|
+
if (c === 32 && (spaces += 1) > 1)
|
|
294
|
+
break;
|
|
295
|
+
if (c === 64) {
|
|
296
|
+
if (hostAt(text, index + 1))
|
|
297
|
+
return true;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
export const CREDENTIAL_SHAPE_NAMES = [...COMPILED.map((shape) => shape.name), URL_PASSWORD];
|
|
305
|
+
function sharedShapePresent(shape, text, withExemptions) {
|
|
306
|
+
if (shape.name === JWT_NAME)
|
|
307
|
+
return jwtPresent(shape, text);
|
|
308
|
+
const exempt = withExemptions ? EXEMPTIONS[shape.name] : undefined;
|
|
309
|
+
if (!exempt)
|
|
310
|
+
return someChunkedMatch(shape, text, () => true);
|
|
311
|
+
return someChunkedMatch(shape, text, (start, end) => !exempt(text, start, end));
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* The shared shape names that match `text`, in the shared list's order: the
|
|
315
|
+
* same answer as `matchingSecretPatterns(text)`, computed on bounded windows.
|
|
316
|
+
*/
|
|
317
|
+
export function sharedShapesIn(text) {
|
|
318
|
+
return COMPILED.filter((shape) => sharedShapePresent(shape, text, false)).map((shape) => shape.name);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* The credential shapes present in `text` for the profile loader: the shared
|
|
322
|
+
* shapes, less the six ordinary-text exemptions, plus a URL with an inline
|
|
323
|
+
* password. Returns names, never the matched text.
|
|
324
|
+
*/
|
|
325
|
+
export function credentialShapesIn(text) {
|
|
326
|
+
if (text.length < 6)
|
|
327
|
+
return [];
|
|
328
|
+
const found = COMPILED.filter((shape) => sharedShapePresent(shape, text, true)).map((shape) => shape.name);
|
|
329
|
+
if (urlWithPassword(text))
|
|
330
|
+
found.push(URL_PASSWORD);
|
|
331
|
+
return found;
|
|
332
|
+
}
|
|
333
|
+
//# sourceMappingURL=credential-shapes.js.map
|
|
@@ -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 type { Availability } from "../capacity/available.js";
|
|
17
|
+
export declare const ENVIRONMENT_PROFILE_SCHEMA_VERSION = "hq-environment-profile.v1";
|
|
18
|
+
export declare const ENVIRONMENT_PROFILE_SCHEMA_ID = "urn:hq:schema:hq-environment-profile:v1";
|
|
19
|
+
export declare const ENVIRONMENT_PROFILE_SCHEMA_PATH: string;
|
|
20
|
+
export type EnvironmentKind = "local" | "outpost" | "microvm" | "bot" | "fleet-box";
|
|
21
|
+
export type EnvironmentState = "running" | "template" | "stopped";
|
|
22
|
+
export type EnvironmentEngine = "claude" | "codex" | "grok";
|
|
23
|
+
export type EnvironmentDispatchMethod = "lane-local" | "lane-ssm" | "lane-endpoint" | "dm" | "fleet-task";
|
|
24
|
+
export interface EnvironmentProvenance {
|
|
25
|
+
source: string;
|
|
26
|
+
/** true only when read from the live system at observed time. */
|
|
27
|
+
verified: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface EnvironmentTaint {
|
|
30
|
+
/** key:value; work tolerates it by listing the same string. */
|
|
31
|
+
key: string;
|
|
32
|
+
effect: "no-place" | "prefer-not";
|
|
33
|
+
reason: string;
|
|
34
|
+
}
|
|
35
|
+
export interface EnvironmentImage {
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
/** Registry or snapshot reference; null when the image is not built yet. */
|
|
39
|
+
ref: string | null;
|
|
40
|
+
contents?: string[];
|
|
41
|
+
}
|
|
42
|
+
export interface EnvironmentDeclared {
|
|
43
|
+
kind: EnvironmentKind;
|
|
44
|
+
/** kind:native-id. */
|
|
45
|
+
id: string;
|
|
46
|
+
aliases?: string[];
|
|
47
|
+
/** Companies this environment may do work for. */
|
|
48
|
+
companies: string[];
|
|
49
|
+
state: EnvironmentState;
|
|
50
|
+
lifecycle: {
|
|
51
|
+
type: "persistent" | "ephemeral";
|
|
52
|
+
/** 0 for a running environment; null when unknown. */
|
|
53
|
+
start_seconds_estimate: number | null;
|
|
54
|
+
provenance?: EnvironmentProvenance;
|
|
55
|
+
};
|
|
56
|
+
limits: {
|
|
57
|
+
vcpu?: number | null;
|
|
58
|
+
memory_mb?: number | null;
|
|
59
|
+
disk_gb?: number | null;
|
|
60
|
+
max_concurrent?: number | null;
|
|
61
|
+
/** Hard ceiling on one run. null means no ceiling. */
|
|
62
|
+
max_run_seconds: number | null;
|
|
63
|
+
workspace_survives: boolean;
|
|
64
|
+
provenance?: EnvironmentProvenance;
|
|
65
|
+
};
|
|
66
|
+
/** key:value labels, for example os:macos, tool:git, engine:claude. */
|
|
67
|
+
labels: string[];
|
|
68
|
+
image?: EnvironmentImage | null;
|
|
69
|
+
dispatch: {
|
|
70
|
+
method: EnvironmentDispatchMethod;
|
|
71
|
+
target?: string;
|
|
72
|
+
/** false when the method is proposed and not built. */
|
|
73
|
+
exists_today: boolean;
|
|
74
|
+
};
|
|
75
|
+
cost: {
|
|
76
|
+
model: "owned" | "fixed" | "metered";
|
|
77
|
+
marginal_usd_per_hour: number | null;
|
|
78
|
+
fixed_usd_per_month?: number | null;
|
|
79
|
+
suspend_usd_per_hour?: number | null;
|
|
80
|
+
basis?: string;
|
|
81
|
+
provenance: EnvironmentProvenance;
|
|
82
|
+
};
|
|
83
|
+
taints: EnvironmentTaint[];
|
|
84
|
+
}
|
|
85
|
+
/** Carried by every reading. */
|
|
86
|
+
export interface EnvironmentReadingMeta {
|
|
87
|
+
/** RFC 3339 date-time. */
|
|
88
|
+
observed_at: string;
|
|
89
|
+
ttl_seconds: number;
|
|
90
|
+
source: string;
|
|
91
|
+
}
|
|
92
|
+
export interface EnvironmentComputeReading extends EnvironmentReadingMeta {
|
|
93
|
+
vcpu_online: number;
|
|
94
|
+
load_1m?: number | null;
|
|
95
|
+
load_per_vcpu?: number | null;
|
|
96
|
+
mem_total_mb?: number;
|
|
97
|
+
mem_available_mb: number;
|
|
98
|
+
disk_total_gb?: number;
|
|
99
|
+
disk_free_gb: number;
|
|
100
|
+
}
|
|
101
|
+
export interface EnvironmentSlotsReading extends EnvironmentReadingMeta {
|
|
102
|
+
host_ref: {
|
|
103
|
+
kind: string;
|
|
104
|
+
id: string;
|
|
105
|
+
};
|
|
106
|
+
providers: Array<{
|
|
107
|
+
engine: EnvironmentEngine;
|
|
108
|
+
max_running: number;
|
|
109
|
+
max_queued?: number;
|
|
110
|
+
running: number;
|
|
111
|
+
queued: number;
|
|
112
|
+
}>;
|
|
113
|
+
queued_lanes?: number;
|
|
114
|
+
}
|
|
115
|
+
export interface EnvironmentAccountReading extends EnvironmentReadingMeta {
|
|
116
|
+
engine: EnvironmentEngine;
|
|
117
|
+
/** Lane-config account label. */
|
|
118
|
+
account_id: string;
|
|
119
|
+
provider_account_id?: string | null;
|
|
120
|
+
provider_account_join_verified?: boolean;
|
|
121
|
+
/** Company slug, "personal" or "unknown". */
|
|
122
|
+
owning_company: string;
|
|
123
|
+
owning_company_source?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Who holds the login. An owner-held login may be used for any of the
|
|
126
|
+
* owner's businesses, so owning_company is a reporting and ranking input
|
|
127
|
+
* for it and not a filter. A login held by another person is never an
|
|
128
|
+
* account; it is an EnvironmentForeignAccount.
|
|
129
|
+
*/
|
|
130
|
+
holder: "owner" | "unknown";
|
|
131
|
+
holder_source?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Whether work may be paired with this login. true only when holder is
|
|
134
|
+
* "owner", enabled is true and signed_in is true.
|
|
135
|
+
*/
|
|
136
|
+
usable: boolean;
|
|
137
|
+
/** Companies the owner explicitly designated; a record, not a limit. */
|
|
138
|
+
usable_for_companies?: string[];
|
|
139
|
+
enabled: boolean;
|
|
140
|
+
/** null when sources disagree or no reading exists. */
|
|
141
|
+
signed_in: boolean | null;
|
|
142
|
+
sign_in_evidence?: string[];
|
|
143
|
+
slots?: {
|
|
144
|
+
max_running?: number;
|
|
145
|
+
running?: number;
|
|
146
|
+
queued?: number;
|
|
147
|
+
quota_held?: boolean;
|
|
148
|
+
};
|
|
149
|
+
room: {
|
|
150
|
+
left_percent: number | null;
|
|
151
|
+
/** The hq-available-ai.v1 word, unchanged; null when there is no reading. */
|
|
152
|
+
availability: Availability | null;
|
|
153
|
+
back_at?: string | null;
|
|
154
|
+
tranche?: string;
|
|
155
|
+
usage_ref?: string | null;
|
|
156
|
+
observed_at: string | null;
|
|
157
|
+
ttl_seconds: number;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A login held by a person other than the owner: its existence, engine and
|
|
162
|
+
* holder only. It has no account id and is never paired with work.
|
|
163
|
+
*/
|
|
164
|
+
export interface EnvironmentForeignAccount {
|
|
165
|
+
engine: EnvironmentEngine;
|
|
166
|
+
/** "other", or "other:<person-slug>" when the person is known. */
|
|
167
|
+
holder: string;
|
|
168
|
+
observed_at: string;
|
|
169
|
+
ttl_seconds: number;
|
|
170
|
+
source: string;
|
|
171
|
+
}
|
|
172
|
+
export interface EnvironmentAccessProbe extends EnvironmentReadingMeta {
|
|
173
|
+
/** kind:name, for example secret:NAME or repo:hq-pro. A name, never a value. */
|
|
174
|
+
name: string;
|
|
175
|
+
result: "pass" | "fail" | "unknown";
|
|
176
|
+
/** What the probe proves. */
|
|
177
|
+
checks: string;
|
|
178
|
+
}
|
|
179
|
+
export interface EnvironmentBaseReadiness extends EnvironmentReadingMeta {
|
|
180
|
+
result: "ready" | "degraded" | "not-ready" | "unknown";
|
|
181
|
+
document_ref?: string | null;
|
|
182
|
+
}
|
|
183
|
+
export interface EnvironmentReadings {
|
|
184
|
+
compute?: EnvironmentComputeReading;
|
|
185
|
+
slots?: EnvironmentSlotsReading;
|
|
186
|
+
accounts: EnvironmentAccountReading[];
|
|
187
|
+
foreign_accounts: EnvironmentForeignAccount[];
|
|
188
|
+
access: EnvironmentAccessProbe[];
|
|
189
|
+
base_readiness?: EnvironmentBaseReadiness;
|
|
190
|
+
}
|
|
191
|
+
export interface EnvironmentProfile {
|
|
192
|
+
schema_version: typeof ENVIRONMENT_PROFILE_SCHEMA_VERSION;
|
|
193
|
+
view: {
|
|
194
|
+
company: string;
|
|
195
|
+
generated_at: string;
|
|
196
|
+
generated_by: string;
|
|
197
|
+
};
|
|
198
|
+
declared: EnvironmentDeclared;
|
|
199
|
+
readings: EnvironmentReadings;
|
|
200
|
+
notes?: string[];
|
|
201
|
+
}
|
|
202
|
+
export interface EnvironmentProfileIssue {
|
|
203
|
+
/** JSON pointer into the document; "" is the document itself. */
|
|
204
|
+
path: string;
|
|
205
|
+
message: string;
|
|
206
|
+
}
|
|
207
|
+
export type EnvironmentProfileFailureCode = "invalid_json" | "not_an_object" | "missing_schema_version" | "unsupported_schema_version" | "invalid";
|
|
208
|
+
export interface EnvironmentProfileSuccess {
|
|
209
|
+
ok: true;
|
|
210
|
+
profile: EnvironmentProfile;
|
|
211
|
+
}
|
|
212
|
+
export interface EnvironmentProfileFailure {
|
|
213
|
+
ok: false;
|
|
214
|
+
code: EnvironmentProfileFailureCode;
|
|
215
|
+
message: string;
|
|
216
|
+
/** At most ENVIRONMENT_PROFILE_MAX_ISSUES entries. */
|
|
217
|
+
issues: EnvironmentProfileIssue[];
|
|
218
|
+
/** How many further issues were found and not listed. */
|
|
219
|
+
issues_omitted: number;
|
|
220
|
+
}
|
|
221
|
+
export type EnvironmentProfileResult = EnvironmentProfileSuccess | EnvironmentProfileFailure;
|
|
222
|
+
/** RFC 3339 date-time with a real calendar date and in-range clock fields. */
|
|
223
|
+
export declare function isRfc3339DateTime(value: string): boolean;
|
|
224
|
+
/** At most this many issues are listed; the rest are counted. */
|
|
225
|
+
export declare const ENVIRONMENT_PROFILE_MAX_ISSUES = 100;
|
|
226
|
+
/**
|
|
227
|
+
* Validate a parsed document. The schema_version is checked first, so a
|
|
228
|
+
* document from a later major version is refused by name and is not reported
|
|
229
|
+
* as a list of field errors against the v1 schema.
|
|
230
|
+
*
|
|
231
|
+
* Beyond the schema, two rules are checked here because JSON Schema cannot
|
|
232
|
+
* express them: view.company is one of declared.companies, and no string is
|
|
233
|
+
* shaped like a credential. At most ENVIRONMENT_PROFILE_MAX_ISSUES issues are
|
|
234
|
+
* returned; issues_omitted counts the rest.
|
|
235
|
+
*/
|
|
236
|
+
export declare function validateEnvironmentProfile(value: unknown): EnvironmentProfileResult;
|
|
237
|
+
/** Parse JSON text and validate it. The text is never echoed in a failure. */
|
|
238
|
+
export declare function parseEnvironmentProfile(text: string): EnvironmentProfileResult;
|
|
239
|
+
//# sourceMappingURL=profile.d.ts.map
|