@indigoai-us/hq-cli 5.345.215-beta.0 → 5.345.215
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 +65 -1
- package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
- package/dist/command-catalog.generated.d.ts +46 -6
- package/dist/command-catalog.generated.js +53 -6
- package/dist/commands/bot.js +64 -6
- package/dist/commands/capacity.d.ts +4 -1
- package/dist/commands/capacity.js +46 -10
- package/dist/commands/cloud.js +1 -1
- package/dist/commands/core-delegate-w1b.js +15 -1
- package/dist/commands/core-policy.js +67 -8
- package/dist/commands/daemon.js +5 -0
- package/dist/commands/files-browse.d.ts +11 -4
- package/dist/commands/files-browse.js +21 -4
- package/dist/commands/files.d.ts +1 -1
- package/dist/commands/files.js +25 -11
- package/dist/commands/integrations-auth-rules.d.ts +27 -0
- package/dist/commands/integrations-auth-rules.js +79 -0
- package/dist/commands/integrations-import.js +124 -12
- package/dist/commands/lanes.js +2 -2
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +60 -35
- package/dist/commands/sync-held.js +5 -2
- package/dist/lazy-commands.js +3 -5
- package/dist/lib/bot/fleet-cron.d.ts +8 -0
- package/dist/lib/bot/fleet-cron.js +35 -3
- package/dist/lib/bot/fleet-daemon.d.ts +46 -0
- package/dist/lib/bot/fleet-daemon.js +99 -1
- package/dist/lib/bot/probe.js +7 -1
- package/dist/lib/bot/run.js +20 -1
- package/dist/lib/bot/runtime/codex.js +1 -1
- package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
- package/dist/lib/bot/runtime/grok-acp.js +6 -3
- package/dist/lib/bot/runtime/index.js +19 -9
- package/dist/lib/bot/runtime/messages-stream.js +2 -2
- package/dist/lib/bot/runtime/types.d.ts +15 -0
- package/dist/lib/bot/runtime/types.js +9 -0
- package/dist/lib/bot/runtime-failure.d.ts +23 -0
- package/dist/lib/bot/runtime-failure.js +43 -1
- package/dist/lib/capacity/accounts.d.ts +8 -0
- package/dist/lib/capacity/accounts.js +19 -0
- package/dist/lib/capacity/available.d.ts +154 -0
- package/dist/lib/capacity/available.js +905 -0
- package/dist/lib/capacity/codex-availability.d.ts +14 -1
- package/dist/lib/capacity/codex-availability.js +26 -1
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
- package/dist/lib/capacity/collectors/codex.js +10 -7
- package/dist/lib/capacity/ledger.d.ts +37 -1
- package/dist/lib/capacity/ledger.js +207 -30
- package/dist/lib/capacity/project.d.ts +26 -0
- package/dist/lib/capacity/project.js +137 -8
- package/dist/lib/capacity/refusal-rows.d.ts +31 -0
- package/dist/lib/capacity/refusal-rows.js +61 -0
- package/dist/lib/capacity/refusal.d.ts +53 -2
- package/dist/lib/capacity/refusal.js +284 -65
- package/dist/lib/capacity/route.js +46 -11
- package/dist/lib/capacity/widget.d.ts +12 -1
- package/dist/lib/capacity/widget.js +91 -3
- package/dist/lib/daemon/resolver.d.ts +2 -0
- package/dist/lib/daemon/resolver.js +3 -0
- package/dist/lib/daemon/run.d.ts +9 -0
- package/dist/lib/daemon/run.js +54 -1
- package/dist/lib/daemon/server.d.ts +2 -0
- package/dist/lib/daemon/server.js +10 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
- package/dist/lib/daemon/tcc-eperm.js +310 -0
- package/dist/lib/delivery/admission.d.ts +86 -0
- package/dist/lib/delivery/admission.js +148 -0
- package/dist/lib/delivery/artifacts.d.ts +7 -1
- package/dist/lib/delivery/artifacts.js +29 -10
- package/dist/lib/delivery/attempt-id.d.ts +13 -0
- package/dist/lib/delivery/attempt-id.js +16 -0
- package/dist/lib/delivery/disposable-target.d.ts +42 -0
- package/dist/lib/delivery/disposable-target.js +111 -0
- package/dist/lib/delivery/effects.d.ts +136 -0
- package/dist/lib/delivery/effects.js +541 -0
- package/dist/lib/delivery/enrollment.d.ts +21 -17
- package/dist/lib/delivery/enrollment.js +83 -5
- package/dist/lib/delivery/escalations.d.ts +51 -0
- package/dist/lib/delivery/escalations.js +60 -0
- package/dist/lib/delivery/lease.d.ts +80 -0
- package/dist/lib/delivery/lease.js +134 -0
- package/dist/lib/delivery/migrations.d.ts +120 -4
- package/dist/lib/delivery/migrations.js +215 -15
- package/dist/lib/delivery/mqtt.d.ts +2 -0
- package/dist/lib/delivery/mqtt.js +7 -0
- package/dist/lib/delivery/reconciler.d.ts +65 -1
- package/dist/lib/delivery/reconciler.js +224 -13
- package/dist/lib/delivery/rpc/client.d.ts +22 -0
- package/dist/lib/delivery/rpc/client.js +159 -0
- package/dist/lib/delivery/rpc/port.d.ts +40 -0
- package/dist/lib/delivery/rpc/port.js +16 -0
- package/dist/lib/delivery/rpc/server.d.ts +30 -0
- package/dist/lib/delivery/rpc/server.js +205 -0
- package/dist/lib/delivery/rpc/wire.d.ts +85 -0
- package/dist/lib/delivery/rpc/wire.js +143 -0
- package/dist/lib/delivery/store.d.ts +2 -0
- package/dist/lib/delivery/store.js +4 -0
- package/dist/lib/delivery/windows-service-install.d.ts +262 -0
- package/dist/lib/delivery/windows-service-install.js +892 -0
- package/dist/lib/delivery/workers/macos.d.ts +16 -1
- package/dist/lib/delivery/workers/macos.js +54 -12
- package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
- package/dist/lib/delivery/workers/windows-service-live.js +711 -0
- package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
- package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
- package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
- package/dist/lib/delivery/workers/windows-service.js +584 -0
- package/dist/lib/delivery/workers/windows.d.ts +32 -22
- package/dist/lib/delivery/workers/windows.js +50 -64
- package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
- package/dist/lib/hot-channels/adapters/meetings.js +36 -3
- package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
- package/dist/lib/hot-channels/signals-pass.js +71 -2
- package/dist/lib/hot-channels/signals-redo.js +10 -2
- package/dist/lib/lanes/watcher.js +35 -0
- package/dist/lib/signals/steps/extract.js +40 -4
- package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
- package/dist/utils/catalog-runtime-paths.d.ts +34 -0
- package/dist/utils/catalog-runtime-paths.js +53 -0
- package/dist/utils/files-browse-acl.js +1 -1
- package/package.json +7 -7
- package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
- package/dist/lib/delivery/workers/windows-boundary.js +0 -693
|
@@ -4,12 +4,12 @@ import * as fs from "node:fs";
|
|
|
4
4
|
import * as os from "node:os";
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
import * as readline from "node:readline";
|
|
7
|
-
import { LedgerCorrupt, LedgerMissing, READING_SOURCES, capacityOptionsFromEnv, capacityRoot, nowViewJsonSchema, readCollectorMark, readLedgerEvents,
|
|
7
|
+
import { LedgerCorrupt, LedgerMissing, READING_SOURCES, capacityOptionsFromEnv, capacityRoot, nowViewJsonSchema, readCollectorMark, readLedgerEvents, rebuildNow, redactProviderTokens, setCollectorEnabled, readCurrentNow, } from "../lib/capacity/ledger.js";
|
|
8
8
|
import { listCapacityAccounts, registryAccountIds } from "../lib/capacity/accounts.js";
|
|
9
9
|
import { claudeIdentityKeys, readClaudeRefreshLast } from "../lib/capacity/collectors/claude-oauth.js";
|
|
10
10
|
import { projectCapacityView } from "../lib/capacity/project.js";
|
|
11
11
|
import { capacityViewAge } from "../lib/capacity/freshness.js";
|
|
12
|
-
import { capacityWidgetTimeZone, renderCapacityWidget } from "../lib/capacity/widget.js";
|
|
12
|
+
import { accountScopeName, bankedResets, capacityWidgetTimeZone, renderCapacityWidget, resetGrantName } from "../lib/capacity/widget.js";
|
|
13
13
|
import { resolveLanesHqRoot } from "../lib/lanes/hq-root.js";
|
|
14
14
|
import { loadLanesConfig } from "../lib/lanes/config.js";
|
|
15
15
|
import { readAllLanes } from "../lib/lanes/store.js";
|
|
@@ -120,7 +120,11 @@ export function formatCapacityTable(view, nowMs, accounts = []) {
|
|
|
120
120
|
&& account.limits.some((limit) => limit.state === "exhausted")
|
|
121
121
|
&& hasCodexCreditRoom(account.limits, nowMs)
|
|
122
122
|
? " — usable on Codex credits (ranked last)" : "";
|
|
123
|
-
|
|
123
|
+
const banked = bankedResets(account, nowMs);
|
|
124
|
+
const resetNote = banked.length === 0
|
|
125
|
+
? ""
|
|
126
|
+
: `\nresets banked: ${banked.map((credit) => `${(credit.remaining ?? 1) > 1 ? `${credit.remaining} x ` : ""}${resetGrantName(credit, accountScopeName(account))}${credit.expiresAt === null ? "" : ` (expires ${new Date(credit.expiresAt).toISOString().slice(0, 10)})`}`).join("; ")}`;
|
|
127
|
+
return `${title}${creditNote}\n${formatLimitTable(account.limits, nowMs)}${resetNote}`;
|
|
124
128
|
});
|
|
125
129
|
return [head, ...blocks].join("\n");
|
|
126
130
|
}).join("\n\n");
|
|
@@ -296,7 +300,7 @@ function formatSignedSpan(ms) {
|
|
|
296
300
|
const span = formatSpan(Math.floor(Math.abs(ms) / 1000));
|
|
297
301
|
return ms < 0 ? `-${span}` : span;
|
|
298
302
|
}
|
|
299
|
-
export function registerCapacityCommand(program) {
|
|
303
|
+
export function registerCapacityCommand(program, deps = {}) {
|
|
300
304
|
const capacity = program
|
|
301
305
|
.command("capacity")
|
|
302
306
|
.description("Show provider capacity from the local ledger (read-only; enable, login, and ingest write to it)")
|
|
@@ -359,6 +363,36 @@ export function registerCapacityCommand(program) {
|
|
|
359
363
|
process.exitCode = 1;
|
|
360
364
|
});
|
|
361
365
|
});
|
|
366
|
+
capacity
|
|
367
|
+
.command("available")
|
|
368
|
+
.description("What AI can run now, as one token-free hq-available-ai.v1 document (read-only; a stale view starts one background read)")
|
|
369
|
+
.option("--json", "Print the document as JSON")
|
|
370
|
+
.option("--fresh", "Start a read and wait for it, at most 3 seconds")
|
|
371
|
+
.option("--include-other", "Also list capacity-only accounts, each with its organization")
|
|
372
|
+
.action(async (_opts, command) => {
|
|
373
|
+
const opts = command.optsWithGlobals();
|
|
374
|
+
const { readAvailable, formatAvailableText } = await import("../lib/capacity/available.js");
|
|
375
|
+
const document = await readAvailable({ options: capacityOptionsFromEnv(), includeOther: opts.includeOther, fresh: opts.fresh }, deps.available);
|
|
376
|
+
console.log(opts.json ? JSON.stringify(document, null, 2) : formatAvailableText(document));
|
|
377
|
+
});
|
|
378
|
+
capacity
|
|
379
|
+
.command("collect-once", { hidden: true })
|
|
380
|
+
.description("One capacity read, started in the background by hq capacity available")
|
|
381
|
+
.action(async () => {
|
|
382
|
+
const { COLLECT_TOKEN_ENV, releaseCollectMark } = await import("../lib/capacity/available.js");
|
|
383
|
+
try {
|
|
384
|
+
const { collectCapacityOnce } = await import("../lib/capacity/collect.js");
|
|
385
|
+
await collectCapacityOnce({ env: process.env, hqRoot: process.env.HQ_ROOT });
|
|
386
|
+
}
|
|
387
|
+
catch {
|
|
388
|
+
// Failure classes stay in hq capacity doctor and logs.
|
|
389
|
+
}
|
|
390
|
+
finally {
|
|
391
|
+
// Free this collect's own single-flight mark, so the next read starts a
|
|
392
|
+
// collect at once. A mark a later collect holds is left alone.
|
|
393
|
+
releaseCollectMark(capacityOptionsFromEnv(), process.env[COLLECT_TOKEN_ENV]);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
362
396
|
capacity
|
|
363
397
|
.command("route")
|
|
364
398
|
.description("Pick the account with the most capacity for a new lane (read-only; port of boss-route)")
|
|
@@ -475,11 +509,11 @@ export function registerCapacityCommand(program) {
|
|
|
475
509
|
});
|
|
476
510
|
ingest
|
|
477
511
|
.command("refusal")
|
|
478
|
-
.description("Record a classified provider
|
|
512
|
+
.description("Record a classified provider refusal as a hold on one named account")
|
|
479
513
|
.option("--provider <name>", "claude, codex, or grok")
|
|
480
|
-
.option("--limit-id <id>", "
|
|
481
|
-
.option("--resets-at <when>", "UTC timestamp or epoch when
|
|
482
|
-
.option("--account <hash>", "Hashed account id
|
|
514
|
+
.option("--limit-id <id>", "The account's limit this refusal is about; without it the refusal claims no window")
|
|
515
|
+
.option("--resets-at <when>", "UTC timestamp or epoch when the hold ends")
|
|
516
|
+
.option("--account <hash>", "Hashed account id of the account that refused. Required unless --limit-id names a limit exactly one account has")
|
|
483
517
|
.option("--json", "Print the recorded limit as JSON")
|
|
484
518
|
.addHelpText("after", `\n${REFUSAL_HELP}\n`)
|
|
485
519
|
.action((opts, command) => {
|
|
@@ -494,7 +528,9 @@ export function registerCapacityCommand(program) {
|
|
|
494
528
|
console.log(JSON.stringify(record, null, 2));
|
|
495
529
|
return;
|
|
496
530
|
}
|
|
497
|
-
console.log(
|
|
531
|
+
console.log(record.inForce
|
|
532
|
+
? `Recorded refusal for ${record.provider} ${record.limitId}; state ${record.state}.`
|
|
533
|
+
: `Recorded refusal for ${record.provider} ${record.limitId}; the hold is not in force: its reset has passed or a newer reading answers it.`);
|
|
498
534
|
});
|
|
499
535
|
});
|
|
500
536
|
capacity
|
|
@@ -741,7 +777,7 @@ function runCli(action) {
|
|
|
741
777
|
}
|
|
742
778
|
function loadNow(options) {
|
|
743
779
|
try {
|
|
744
|
-
return
|
|
780
|
+
return readCurrentNow(options);
|
|
745
781
|
}
|
|
746
782
|
catch (err) {
|
|
747
783
|
if (!(err instanceof LedgerCorrupt))
|
package/dist/commands/cloud.js
CHANGED
|
@@ -533,7 +533,7 @@ export function identityHeldLines(count, notice) {
|
|
|
533
533
|
return [];
|
|
534
534
|
return [
|
|
535
535
|
`⚠ ${count} file(s) were NOT uploaded: uploads for this company are held on this computer ` +
|
|
536
|
-
`
|
|
536
|
+
`until you confirm they belong to the signed-in account. Run \`hq sync held\` to see what is held, then ` +
|
|
537
537
|
`\`hq sync release-held\` to upload it.`,
|
|
538
538
|
];
|
|
539
539
|
}
|
|
@@ -140,12 +140,26 @@ function groupMemberIds(output) {
|
|
|
140
140
|
return lines.slice(header + 1).filter((line) => line.trim() !== "")
|
|
141
141
|
.map((line) => line.trim().split(/\s{2,}/, 1)[0] ?? "");
|
|
142
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Creator-row ACL label in any hq-cli wording: bare "creator access", the older
|
|
145
|
+
* "creator access — creator-only", or "creator access (<note>)". The listing
|
|
146
|
+
* comes from the `hq` on PATH, which can be older or newer than this build, so
|
|
147
|
+
* matching only this build's label would fail creator rows from another
|
|
148
|
+
* version. Mirrors the creator alternative in hq-delegate-verify.sh.
|
|
149
|
+
*/
|
|
150
|
+
const CREATOR_ACL_LABEL = / (creator access(?: — creator-only| \([^()]*\))?)$/;
|
|
151
|
+
function trailingAclLabel(row, aclLabels) {
|
|
152
|
+
const creator = CREATOR_ACL_LABEL.exec(row)?.[1];
|
|
153
|
+
if (creator)
|
|
154
|
+
return creator;
|
|
155
|
+
return aclLabels.find((label) => row.endsWith(label));
|
|
156
|
+
}
|
|
143
157
|
function browseContainsExactKey(listing, expected) {
|
|
144
158
|
const lines = listing.split(/\r?\n/);
|
|
145
159
|
const aclLabels = Object.values(ACL_SOURCE_DISPLAY_LABELS);
|
|
146
160
|
return lines.slice(2).some((line) => {
|
|
147
161
|
const row = stripAnsiSequences(line).trimEnd();
|
|
148
|
-
const acl =
|
|
162
|
+
const acl = trailingAclLabel(row, aclLabels);
|
|
149
163
|
if (!acl)
|
|
150
164
|
return false;
|
|
151
165
|
const beforeAcl = row.slice(0, -acl.length).trimEnd();
|
|
@@ -57,7 +57,8 @@ const RETIRE_HELP = [
|
|
|
57
57
|
'# trigger loader, the company-bind digest, the age report.',
|
|
58
58
|
'#',
|
|
59
59
|
'# Usage:',
|
|
60
|
-
'# policy-retire.sh <slug-or-path> --reason "<why>" [--by <who>]',
|
|
60
|
+
'# policy-retire.sh <slug-or-path> --reason "<why>" --evidence "<block log path, incident ref or ledger entry>" [--by <who>]',
|
|
61
|
+
'# (--evidence is required: a rule is not retired on guesswork; it is recorded as retired_evidence:)',
|
|
61
62
|
'# policy-retire.sh <slug-or-path> --restore',
|
|
62
63
|
'# policy-retire.sh --from-report <age-report.json> --class <never-fired|dormant|stale-refs|single-incident-old> --reason "<why>" [--yes]',
|
|
63
64
|
'# policy-retire.sh --auto [--dir <policies-dir>]... [--classes a,b] [--report-dir <dir>] [--dry-run]',
|
|
@@ -562,6 +563,15 @@ export function runPolicyAgeReport(args, root, env = process.env, nowEpoch = Mat
|
|
|
562
563
|
export function runPolicyFrontmatter(args, cwd, env = process.env, platform = process.platform) {
|
|
563
564
|
return runPolicyFrontmatterImpl(args, cwd, env.PATH, platform);
|
|
564
565
|
}
|
|
566
|
+
// The default --by is a session id or user name, which is not always a safe bare YAML scalar
|
|
567
|
+
// (UUIDs often start with a digit). Normalize it so the default always passes invalidRetiredBy.
|
|
568
|
+
// An explicit --by is never normalized; it is validated as typed.
|
|
569
|
+
function defaultRetiredBy(env) {
|
|
570
|
+
const raw = env.HQ_SESSION_ID || env.USER || 'unknown';
|
|
571
|
+
const cleaned = raw.replace(/[^A-Za-z0-9._@-]/g, '-');
|
|
572
|
+
const prefixed = /^[A-Za-z_]/.test(cleaned) ? cleaned : `sess-${cleaned}`;
|
|
573
|
+
return invalidRetiredBy(prefixed) === undefined ? prefixed : `sess-${prefixed}`;
|
|
574
|
+
}
|
|
565
575
|
function parseRetireOptions(args, scriptPath, env) {
|
|
566
576
|
const value = {
|
|
567
577
|
auto: false,
|
|
@@ -570,7 +580,8 @@ function parseRetireOptions(args, scriptPath, env) {
|
|
|
570
580
|
reportDir: '',
|
|
571
581
|
classes: '',
|
|
572
582
|
reason: '',
|
|
573
|
-
|
|
583
|
+
evidence: '',
|
|
584
|
+
by: defaultRetiredBy(env),
|
|
574
585
|
restore: false,
|
|
575
586
|
report: '',
|
|
576
587
|
className: '',
|
|
@@ -582,6 +593,7 @@ function parseRetireOptions(args, scriptPath, env) {
|
|
|
582
593
|
['--report-dir', 'reportDir'],
|
|
583
594
|
['--classes', 'classes'],
|
|
584
595
|
['--reason', 'reason'],
|
|
596
|
+
['--evidence', 'evidence'],
|
|
585
597
|
['--by', 'by'],
|
|
586
598
|
['--from-report', 'report'],
|
|
587
599
|
['--class', 'className'],
|
|
@@ -618,6 +630,7 @@ function parseRetireOptions(args, scriptPath, env) {
|
|
|
618
630
|
'--report-dir': 45,
|
|
619
631
|
'--classes': 46,
|
|
620
632
|
'--reason': 47,
|
|
633
|
+
'--evidence': 47,
|
|
621
634
|
'--by': 48,
|
|
622
635
|
'--from-report': 50,
|
|
623
636
|
'--class': 51,
|
|
@@ -659,7 +672,20 @@ function awkRecords(content) {
|
|
|
659
672
|
}
|
|
660
673
|
return records;
|
|
661
674
|
}
|
|
662
|
-
function
|
|
675
|
+
function yamlDoubleQuoted(value) {
|
|
676
|
+
return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
677
|
+
}
|
|
678
|
+
// eslint-disable-next-line no-control-regex
|
|
679
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/;
|
|
680
|
+
// retired_by is written as a bare YAML scalar, so it is limited to characters that
|
|
681
|
+
// cannot change how the line parses, and to values YAML would not read as null, bool,
|
|
682
|
+
// number or date (so the first character must be a letter or underscore).
|
|
683
|
+
function invalidRetiredBy(by) {
|
|
684
|
+
if (/^[A-Za-z_][A-Za-z0-9._@-]*$/.test(by) && !/^(null|true|false|yes|no|on|off|y|n)$/i.test(by))
|
|
685
|
+
return undefined;
|
|
686
|
+
return 'policy-retire: --by must be a plain id (letters, digits, ".", "_", "@", "-"; starting with a letter or "_" so YAML cannot read it as a number or date; not a YAML keyword such as null or true)\n';
|
|
687
|
+
}
|
|
688
|
+
function rewriteStatus(content, status, reason, by, now, evidence = '') {
|
|
663
689
|
const output = [];
|
|
664
690
|
let depth = 0;
|
|
665
691
|
let done = false;
|
|
@@ -669,20 +695,20 @@ function rewriteStatus(content, status, reason, by, now) {
|
|
|
669
695
|
depth += 1;
|
|
670
696
|
if (depth === 2 && !done) {
|
|
671
697
|
if (status === 'retired') {
|
|
672
|
-
output.push(Buffer.from(`status: retired\nretired_at: ${now.toISOString().replace(/\.\d{3}Z$/, 'Z')}\nretired_by: ${by}\nretired_reason:
|
|
698
|
+
output.push(Buffer.from(`status: retired\nretired_at: ${now.toISOString().replace(/\.\d{3}Z$/, 'Z')}\nretired_by: ${by}\nretired_reason: ${yamlDoubleQuoted(reason)}\n${evidence ? `retired_evidence: ${yamlDoubleQuoted(evidence)}\n` : ''}`));
|
|
673
699
|
}
|
|
674
700
|
done = true;
|
|
675
701
|
}
|
|
676
702
|
output.push(record, Buffer.from('\n'));
|
|
677
703
|
continue;
|
|
678
704
|
}
|
|
679
|
-
if (depth === 1 && /^(status|retired_at|retired_by|retired_reason):/.test(line))
|
|
705
|
+
if (depth === 1 && /^(status|retired_at|retired_by|retired_reason|retired_evidence):/.test(line))
|
|
680
706
|
continue;
|
|
681
707
|
output.push(record, Buffer.from('\n'));
|
|
682
708
|
}
|
|
683
709
|
return Buffer.concat(output);
|
|
684
710
|
}
|
|
685
|
-
function setPolicyStatus(filePath, status, reason, by, env, now, cwd = process.cwd(), validatePolicy = policyValidatorDiagnostic) {
|
|
711
|
+
function setPolicyStatus(filePath, status, reason, by, env, now, cwd = process.cwd(), validatePolicy = policyValidatorDiagnostic, evidence = '') {
|
|
686
712
|
const resolvedPath = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
687
713
|
let content;
|
|
688
714
|
try {
|
|
@@ -707,7 +733,7 @@ function setPolicyStatus(filePath, status, reason, by, env, now, cwd = process.c
|
|
|
707
733
|
};
|
|
708
734
|
}
|
|
709
735
|
const tempPath = `${resolvedPath}.tmp`;
|
|
710
|
-
fs.writeFileSync(tempPath, rewriteStatus(content, status, reason, by, now), { mode: 0o666 });
|
|
736
|
+
fs.writeFileSync(tempPath, rewriteStatus(content, status, reason, by, now, evidence), { mode: 0o666 });
|
|
711
737
|
fs.renameSync(tempPath, filePath);
|
|
712
738
|
return { ok: true };
|
|
713
739
|
}
|
|
@@ -926,6 +952,9 @@ function autoRetire(options, root, cwd, env, now) {
|
|
|
926
952
|
function fromReport(options, root, cwd, env, now) {
|
|
927
953
|
if (!options.className || !options.reason)
|
|
928
954
|
return policyResult(2, '', '--from-report needs --class and --reason\n');
|
|
955
|
+
const byError = invalidRetiredBy(options.by);
|
|
956
|
+
if (byError)
|
|
957
|
+
return policyResult(2, '', byError);
|
|
929
958
|
const reportPath = path.isAbsolute(options.report) ? options.report : path.resolve(cwd, options.report);
|
|
930
959
|
let reportText;
|
|
931
960
|
try {
|
|
@@ -1003,6 +1032,20 @@ export function runPolicyRetire(args, root, cwd, env = process.env, now = new Da
|
|
|
1003
1032
|
if (parsed.kind === 'error')
|
|
1004
1033
|
return parsed.result;
|
|
1005
1034
|
const options = parsed.value;
|
|
1035
|
+
// Gate --by before any file I/O on every path that writes it (retire, --from-report, --auto).
|
|
1036
|
+
// --restore writes status: active and no retired_by, so it is not gated.
|
|
1037
|
+
if (!options.restore) {
|
|
1038
|
+
const byGate = invalidRetiredBy(options.by);
|
|
1039
|
+
if (byGate)
|
|
1040
|
+
return policyResult(2, '', byGate);
|
|
1041
|
+
// --reason and --evidence become frontmatter lines on every write path
|
|
1042
|
+
// (single target, --from-report, --auto), so check them before any of them runs.
|
|
1043
|
+
for (const [flag, text] of [['--reason', options.reason], ['--evidence', options.evidence.trim()]]) {
|
|
1044
|
+
if (text && CONTROL_CHARACTERS.test(text)) {
|
|
1045
|
+
return policyResult(2, '', `policy-retire: ${flag} must be a single line without control characters (newlines, tabs or escape codes)\n`);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1006
1049
|
if (options.auto)
|
|
1007
1050
|
return autoRetire(options, root, cwd, env, now);
|
|
1008
1051
|
if (options.report)
|
|
@@ -1020,7 +1063,23 @@ export function runPolicyRetire(args, root, cwd, env = process.env, now = new Da
|
|
|
1020
1063
|
}
|
|
1021
1064
|
if (!options.reason)
|
|
1022
1065
|
return policyResult(2, '', 'policy-retire: --reason is required\n');
|
|
1023
|
-
|
|
1066
|
+
// A manual retirement needs saved evidence (block log, incident ref, ledger entry) so a
|
|
1067
|
+
// rule is not retired on guesswork. garden-policy-pass already derives its evidence from
|
|
1068
|
+
// the age report and states it in --reason, so it is the one caller exempt from the flag.
|
|
1069
|
+
// The exemption is keyed on the --by string, which anyone can type; it is not an identity check.
|
|
1070
|
+
const evidence = options.evidence.trim();
|
|
1071
|
+
if (!evidence && options.by !== 'garden-policy-pass') {
|
|
1072
|
+
return policyResult(2, '', 'policy-retire: --evidence is required: name the saved evidence (block log path, incident ref or ledger entry) for retiring this rule\n');
|
|
1073
|
+
}
|
|
1074
|
+
const byError = invalidRetiredBy(options.by);
|
|
1075
|
+
if (byError)
|
|
1076
|
+
return policyResult(2, '', byError);
|
|
1077
|
+
for (const [flag, text] of [['--reason', options.reason], ['--evidence', evidence]]) {
|
|
1078
|
+
if (CONTROL_CHARACTERS.test(text)) {
|
|
1079
|
+
return policyResult(2, '', `policy-retire: ${flag} must be a single line without control characters (newlines, tabs or escape codes)\n`);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
const updated = setPolicyStatus(file, 'retired', options.reason, options.by, env, now, cwd, dependencies.validatePolicy, evidence);
|
|
1024
1083
|
if (!updated.ok)
|
|
1025
1084
|
return policyResult(1, '', updated.error);
|
|
1026
1085
|
return policyResult(0, `policy-retire: retired ${displayPolicyPath(file, root)} — ${options.reason}\n`);
|
package/dist/commands/daemon.js
CHANGED
|
@@ -27,6 +27,7 @@ import { daemonUnitInstalled } from "../lib/daemon/handoff.js";
|
|
|
27
27
|
import { adoptLegacyUnits, readAdoptedUnits, restoreLegacyUnits } from "../lib/daemon/migrate.js";
|
|
28
28
|
import { DAEMON_ALIVE_WAIT_MS, ROOT_REFUSAL, SYSTEM_UNIT_DIR, WINDOWS_START_WAIT_MS, waitForLiveDaemon, daemonRootRefusal, installDaemonUnit, installScopeFor, classifyWindowsTask, daemonServiceStatus, describeSupervision, legacyWindowsTask, startDaemonUnit, readWindowsSid, uninstallDaemonUnit, windowsInteractiveSession, windowsTaskName, } from "../lib/daemon/install.js";
|
|
29
29
|
import { PLIST_REFRESH_MARKER } from "../lib/daemon/plist-refresh.js";
|
|
30
|
+
import { FILES_ACCESS_NEEDED_MESSAGE, filesAccessNeeded } from "../lib/daemon/tcc-eperm.js";
|
|
30
31
|
import { describeLegacyUnit, findLegacyUnits } from "../lib/daemon/legacy.js";
|
|
31
32
|
import { isDaemonProcess, liveDaemonLock, runningDaemonPid } from "../lib/daemon/lock.js";
|
|
32
33
|
import { bundledHqCloud, managedHqCloud, managedHqCloudRoot, readHqCloudCopy, readHqCloudUpdateState } from "../lib/daemon/hq-cloud.js";
|
|
@@ -513,6 +514,10 @@ function statusWarnings(service, paths) {
|
|
|
513
514
|
if (warnings.length > 0 && fs.existsSync(path.join(paths.root, PLIST_REFRESH_MARKER))) {
|
|
514
515
|
warnings.push(`The daemon tried to rewrite it automatically and did not finish. See: ${path.join(paths.root, "logs", "plist-refresh.log")}`);
|
|
515
516
|
}
|
|
517
|
+
// Written by a daemon that macOS keeps refusing under the HQ root (tcc-eperm.ts).
|
|
518
|
+
// A stopped daemon's marker is stale: the next daemon clears it on start.
|
|
519
|
+
if (service.daemonPid !== null && filesAccessNeeded(paths.root))
|
|
520
|
+
warnings.push(FILES_ACCESS_NEEDED_MESSAGE);
|
|
516
521
|
return warnings;
|
|
517
522
|
}
|
|
518
523
|
async function runStatus(d, opts) {
|
|
@@ -111,10 +111,14 @@ export type CompanyBrowseClientFactory = (input: {
|
|
|
111
111
|
companyUid: string;
|
|
112
112
|
}) => FilesBrowseS3Client;
|
|
113
113
|
/**
|
|
114
|
-
* ACL provenance for a single listed key
|
|
114
|
+
* ACL provenance for a single listed key: how the CALLER can read it, not
|
|
115
|
+
* who else can.
|
|
115
116
|
* - `shared-with-you`: an explicit grant the caller holds covers the key.
|
|
116
|
-
* - `creator`:
|
|
117
|
-
* key
|
|
117
|
+
* - `creator`: the caller's creator grant (or its folder marker) covers the
|
|
118
|
+
* key and none of the caller's shared grants does; this is explicit
|
|
119
|
+
* creator access, not an owner/admin role bypass. It does not mean the
|
|
120
|
+
* caller is the only reader: browse sees only the caller's own grants,
|
|
121
|
+
* so other members' grants on the same key are not visible here.
|
|
118
122
|
* - `role-bypass`: the caller has no covering explicit grant, but
|
|
119
123
|
* owner/admin role widened the browse-vend policy to include it.
|
|
120
124
|
* - `personal-vault`: the key lives in the caller's own person-entity
|
|
@@ -154,7 +158,10 @@ export declare function toBucketRelative(pathOrPrefix: string, slug: string): st
|
|
|
154
158
|
export declare function toCompanyAnchored(bucketRelKey: string, slug: string): string;
|
|
155
159
|
/**
|
|
156
160
|
* Classify a single company-relative S3 key against the caller's
|
|
157
|
-
* raw explicit-grant patterns
|
|
161
|
+
* raw explicit-grant patterns (the caller's own grants only, so the result
|
|
162
|
+
* says how the caller can read the key, not who else can). When several of
|
|
163
|
+
* the caller's grants cover the key, a shared grant beats a creator grant
|
|
164
|
+
* regardless of order. `foo/*` covers all keys below `foo/`, while
|
|
158
165
|
* `foo/` is the private folder itself and never covers a child key. Otherwise
|
|
159
166
|
* the key is visible only via the owner/admin role-bypass the `/sts/vend`
|
|
160
167
|
* policy applied. An empty-string prefix is a company-wide grant and matches
|
|
@@ -100,7 +100,10 @@ export function toCompanyAnchored(bucketRelKey, slug) {
|
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Classify a single company-relative S3 key against the caller's
|
|
103
|
-
* raw explicit-grant patterns
|
|
103
|
+
* raw explicit-grant patterns (the caller's own grants only, so the result
|
|
104
|
+
* says how the caller can read the key, not who else can). When several of
|
|
105
|
+
* the caller's grants cover the key, a shared grant beats a creator grant
|
|
106
|
+
* regardless of order. `foo/*` covers all keys below `foo/`, while
|
|
104
107
|
* `foo/` is the private folder itself and never covers a child key. Otherwise
|
|
105
108
|
* the key is visible only via the owner/admin role-bypass the `/sts/vend`
|
|
106
109
|
* policy applied. An empty-string prefix is a company-wide grant and matches
|
|
@@ -114,25 +117,39 @@ export function classifyAclSource(bucketRelKey, grantPatterns) {
|
|
|
114
117
|
const normalized = grantPatterns.map((entry) => typeof entry === "string"
|
|
115
118
|
? { pattern: entry, source: undefined }
|
|
116
119
|
: entry);
|
|
120
|
+
// A creator match does not end the scan: the caller can hold both a
|
|
121
|
+
// creator grant on the key and a shared grant (person, group, email or
|
|
122
|
+
// open) that covers it, and the server does not order them. The shared
|
|
123
|
+
// grant wins, so a team-readable file is not labelled as creator access
|
|
124
|
+
// just because its creator grant came first (feedback 10ed97a5).
|
|
125
|
+
let creatorMatch = false;
|
|
117
126
|
for (const entry of normalized) {
|
|
118
127
|
const pattern = entry.pattern;
|
|
119
128
|
if (pattern === "" || pattern === "*")
|
|
120
129
|
return "shared-with-you";
|
|
121
130
|
if (pattern.endsWith("/*")) {
|
|
122
131
|
if (bucketRelKey.startsWith(pattern.slice(0, -1))) {
|
|
123
|
-
|
|
132
|
+
if (entry.source !== "creator")
|
|
133
|
+
return "shared-with-you";
|
|
134
|
+
creatorMatch = true;
|
|
124
135
|
}
|
|
125
136
|
continue;
|
|
126
137
|
}
|
|
127
138
|
if (isPrivateFolderPattern(pattern)) {
|
|
128
|
-
|
|
139
|
+
// Keep the existing precedence: a creator match seen earlier still
|
|
140
|
+
// wins over a later private-folder row for the same key.
|
|
141
|
+
if (bucketRelKey === pattern && !creatorMatch)
|
|
129
142
|
return "private-folder";
|
|
130
143
|
continue;
|
|
131
144
|
}
|
|
132
145
|
if (bucketRelKey === pattern) {
|
|
133
|
-
|
|
146
|
+
if (entry.source !== "creator")
|
|
147
|
+
return "shared-with-you";
|
|
148
|
+
creatorMatch = true;
|
|
134
149
|
}
|
|
135
150
|
}
|
|
151
|
+
if (creatorMatch)
|
|
152
|
+
return "creator";
|
|
136
153
|
// The server can expose a creator-owned child row without returning the
|
|
137
154
|
// creator's original `foo/` row. Keep the zero-byte `foo/` marker visible
|
|
138
155
|
// and label it as creator access when a creator grant is underneath it.
|
package/dist/commands/files.d.ts
CHANGED
|
@@ -324,7 +324,7 @@ export declare function runFilesPurge(params: {
|
|
|
324
324
|
confirm?: ConfirmFn;
|
|
325
325
|
now?: () => Date;
|
|
326
326
|
}): Promise<FilesPurgeResult | undefined>;
|
|
327
|
-
/** Cancel a scheduled purge (hq-pro action "
|
|
327
|
+
/** Cancel a scheduled purge (hq-pro action "cancel_purge"). */
|
|
328
328
|
export declare function runFilesPurgeCancel(params: {
|
|
329
329
|
key: string;
|
|
330
330
|
versionId: string;
|
package/dist/commands/files.js
CHANGED
|
@@ -1926,7 +1926,7 @@ async function postPurgeAction(params, action) {
|
|
|
1926
1926
|
if (!res.ok) {
|
|
1927
1927
|
const errBody = (await res.json().catch(() => ({})));
|
|
1928
1928
|
const err = new FilesRecoveryHttpError(res.status, errBody.message ?? errBody.error ?? res.statusText, errBody.code);
|
|
1929
|
-
if (action === "
|
|
1929
|
+
if (action === "cancel_purge" && res.status === 400) {
|
|
1930
1930
|
throw new Error("The server rejected the cancellation: " + err.message + ". If the server predates the 7-day purge window it cannot cancel. Check `hq files versions` to see whether the version still exists.");
|
|
1931
1931
|
}
|
|
1932
1932
|
throw new Error(formatFilesRecoveryError(err, params.key));
|
|
@@ -1960,11 +1960,19 @@ export async function runFilesPurge(params, deps = {}) {
|
|
|
1960
1960
|
}
|
|
1961
1961
|
const data = await postPurgeAction(params, "purge");
|
|
1962
1962
|
const key = typeof data.key === "string" ? data.key : params.key;
|
|
1963
|
-
|
|
1963
|
+
// hq-pro answers a scheduled purge with `purged: false`, `purgeScheduled:
|
|
1964
|
+
// true`, `status: "pending_purge"` and echoes the target as `purgedVersionId`.
|
|
1965
|
+
// Older builds said `status: "scheduled"` / `scheduled: true` with
|
|
1966
|
+
// `purgeVersionId`. Any of these means the version still exists.
|
|
1967
|
+
const saysScheduled = data.status === "scheduled" ||
|
|
1968
|
+
data.status === "pending_purge" ||
|
|
1969
|
+
data.scheduled === true ||
|
|
1970
|
+
data.purgeScheduled === true;
|
|
1971
|
+
const echoedVersionId = data.purgeVersionId ?? data.purgedVersionId;
|
|
1964
1972
|
const scheduled = saysScheduled &&
|
|
1965
1973
|
typeof data.purgeAt === "string" &&
|
|
1966
1974
|
!Number.isNaN(new Date(data.purgeAt).getTime()) &&
|
|
1967
|
-
|
|
1975
|
+
echoedVersionId === params.versionId;
|
|
1968
1976
|
if (saysScheduled && !scheduled) {
|
|
1969
1977
|
// The server says something is scheduled but the response is incomplete.
|
|
1970
1978
|
// Do not report "nothing happened": a deletion may be pending.
|
|
@@ -1973,27 +1981,33 @@ export async function runFilesPurge(params, deps = {}) {
|
|
|
1973
1981
|
}
|
|
1974
1982
|
if (scheduled) {
|
|
1975
1983
|
const purgeAt = data.purgeAt;
|
|
1976
|
-
console.log(chalk.green("Version '" + params.versionId + "' of '" + key + "'
|
|
1977
|
-
formatPurgeDate(purgeAt) + ". It can be cancelled
|
|
1984
|
+
console.log(chalk.green("Version '" + params.versionId + "' of '" + key + "' is scheduled for deletion on " +
|
|
1985
|
+
formatPurgeDate(purgeAt) + ". It stays listed and readable until then, and the purge can be cancelled with:"));
|
|
1978
1986
|
console.log(chalk.dim(" " + formatPurgeCancelCommand(params)));
|
|
1979
1987
|
return { key, versionId: params.versionId, status: "scheduled", purgeAt };
|
|
1980
1988
|
}
|
|
1981
|
-
// Older server: it purged at once and echoes purgedVersionId.
|
|
1982
|
-
|
|
1989
|
+
// Older server: it purged at once and echoes purgedVersionId. Only reached
|
|
1990
|
+
// with no scheduled signal and `purged` not explicitly false.
|
|
1991
|
+
if (data.purged !== false && data.purgedVersionId === params.versionId) {
|
|
1983
1992
|
console.log(chalk.yellow("The server deleted version '" + params.versionId + "' of '" + key +
|
|
1984
1993
|
"' immediately (it does not support the 7-day purge window yet). This cannot be cancelled."));
|
|
1985
1994
|
return { key, versionId: params.versionId, status: "purged" };
|
|
1986
1995
|
}
|
|
1987
1996
|
throw new Error("The server did not confirm the purge (it may not support purge yet). Check `hq files versions` before retrying.");
|
|
1988
1997
|
}
|
|
1989
|
-
/** Cancel a scheduled purge (hq-pro action "
|
|
1998
|
+
/** Cancel a scheduled purge (hq-pro action "cancel_purge"). */
|
|
1990
1999
|
export async function runFilesPurgeCancel(params) {
|
|
1991
2000
|
assertExactRecoveryKey(params.key);
|
|
1992
2001
|
assertPurgeVersionId(params.versionId);
|
|
1993
|
-
const data = await postPurgeAction(params, "
|
|
2002
|
+
const data = await postPurgeAction(params, "cancel_purge");
|
|
1994
2003
|
const key = typeof data.key === "string" ? data.key : params.key;
|
|
1995
|
-
|
|
1996
|
-
|
|
2004
|
+
// hq-pro answers a cancel with `purgeCancelled: true`, `status: "kept"` and
|
|
2005
|
+
// `versionId`; older builds said `status: "cancelled"` with `purgeVersionId`.
|
|
2006
|
+
const confirmed = (data.status === "cancelled" ||
|
|
2007
|
+
data.status === "kept" ||
|
|
2008
|
+
data.cancelled === true ||
|
|
2009
|
+
data.purgeCancelled === true) &&
|
|
2010
|
+
(data.purgeVersionId ?? data.versionId) === params.versionId;
|
|
1997
2011
|
if (!confirmed) {
|
|
1998
2012
|
throw new Error("The server did not confirm the cancellation (it may not support the 7-day purge window yet). Check `hq files versions` to see whether the version still exists.");
|
|
1999
2013
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* feedback_950d8abe: hq-pro's save-time rules for an API key and the header it
|
|
3
|
+
* is sent in (hq-pro src/integration-factory/api-key-characters.ts). The CLI
|
|
4
|
+
* applies the same rules before it sends a key, so a key or header name hq-pro
|
|
5
|
+
* would refuse with a 400 is caught locally with a plain message, and one
|
|
6
|
+
* hq-pro accepts is never refused here.
|
|
7
|
+
*
|
|
8
|
+
* Nothing in this module echoes a key or any part of it.
|
|
9
|
+
*/
|
|
10
|
+
/** hq-pro stores a custom key header name of at most this many characters. */
|
|
11
|
+
export declare const MAX_AUTH_HEADER_LENGTH = 64;
|
|
12
|
+
/**
|
|
13
|
+
* True when hq-pro refuses to send a key in this (token-valid) header name.
|
|
14
|
+
* Authorization is allowed: a header placement named Authorization is the one
|
|
15
|
+
* way to send a raw key with no prefix.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isDeniedAuthHeader(name: string): boolean;
|
|
18
|
+
export type AuthHeaderProblem = "invalid" | "denied" | "too-long";
|
|
19
|
+
/** Why hq-pro would refuse this custom key header name, or null when it is accepted. */
|
|
20
|
+
export declare function authHeaderProblem(name: string): AuthHeaderProblem | null;
|
|
21
|
+
/**
|
|
22
|
+
* hq-pro's rule for a Bearer, prefix or custom-header key: visible ASCII only
|
|
23
|
+
* (0x21-0x7E), so no inner space. An HTTP Basic password is base64 encoded
|
|
24
|
+
* before it is sent and has its own, looser rule on hq-pro.
|
|
25
|
+
*/
|
|
26
|
+
export declare function apiKeyIsSendable(key: string): boolean;
|
|
27
|
+
//# sourceMappingURL=integrations-auth-rules.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* feedback_950d8abe: hq-pro's save-time rules for an API key and the header it
|
|
3
|
+
* is sent in (hq-pro src/integration-factory/api-key-characters.ts). The CLI
|
|
4
|
+
* applies the same rules before it sends a key, so a key or header name hq-pro
|
|
5
|
+
* would refuse with a 400 is caught locally with a plain message, and one
|
|
6
|
+
* hq-pro accepts is never refused here.
|
|
7
|
+
*
|
|
8
|
+
* Nothing in this module echoes a key or any part of it.
|
|
9
|
+
*/
|
|
10
|
+
/** hq-pro stores a custom key header name of at most this many characters. */
|
|
11
|
+
export const MAX_AUTH_HEADER_LENGTH = 64;
|
|
12
|
+
/** RFC 7230 token characters accepted for an HTTP field name. */
|
|
13
|
+
const HEADER_NAME_TOKEN = /^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/;
|
|
14
|
+
const DENIED_AUTH_HEADER_NAMES = new Set([
|
|
15
|
+
// hop-by-hop, framing and request target
|
|
16
|
+
"connection",
|
|
17
|
+
"keep-alive",
|
|
18
|
+
"proxy-connection",
|
|
19
|
+
"proxy-authorization",
|
|
20
|
+
"proxy-authenticate",
|
|
21
|
+
"te",
|
|
22
|
+
"trailer",
|
|
23
|
+
"transfer-encoding",
|
|
24
|
+
"upgrade",
|
|
25
|
+
"http2-settings",
|
|
26
|
+
"content-length",
|
|
27
|
+
"expect",
|
|
28
|
+
"host",
|
|
29
|
+
"content-encoding",
|
|
30
|
+
// cookies, auth challenges, forwarding and client-IP headers
|
|
31
|
+
"cookie",
|
|
32
|
+
"set-cookie",
|
|
33
|
+
"www-authenticate",
|
|
34
|
+
"forwarded",
|
|
35
|
+
"via",
|
|
36
|
+
"x-real-ip",
|
|
37
|
+
"true-client-ip",
|
|
38
|
+
"cf-connecting-ip",
|
|
39
|
+
"x-original-url",
|
|
40
|
+
// set by HQ's MCP client itself
|
|
41
|
+
"accept",
|
|
42
|
+
"accept-encoding",
|
|
43
|
+
"content-type",
|
|
44
|
+
"user-agent",
|
|
45
|
+
"mcp-protocol-version",
|
|
46
|
+
"mcp-session-id",
|
|
47
|
+
"last-event-id",
|
|
48
|
+
]);
|
|
49
|
+
/** Case-insensitive: Proxy-Authorization, Proxy-Authenticate, every X-Forwarded-*. */
|
|
50
|
+
const DENIED_AUTH_HEADER_PREFIXES = ["proxy-", "x-forwarded-"];
|
|
51
|
+
/**
|
|
52
|
+
* True when hq-pro refuses to send a key in this (token-valid) header name.
|
|
53
|
+
* Authorization is allowed: a header placement named Authorization is the one
|
|
54
|
+
* way to send a raw key with no prefix.
|
|
55
|
+
*/
|
|
56
|
+
export function isDeniedAuthHeader(name) {
|
|
57
|
+
const lower = name.toLowerCase();
|
|
58
|
+
return (DENIED_AUTH_HEADER_NAMES.has(lower) ||
|
|
59
|
+
DENIED_AUTH_HEADER_PREFIXES.some((prefix) => lower.startsWith(prefix)));
|
|
60
|
+
}
|
|
61
|
+
/** Why hq-pro would refuse this custom key header name, or null when it is accepted. */
|
|
62
|
+
export function authHeaderProblem(name) {
|
|
63
|
+
if (!HEADER_NAME_TOKEN.test(name))
|
|
64
|
+
return "invalid";
|
|
65
|
+
if (isDeniedAuthHeader(name))
|
|
66
|
+
return "denied";
|
|
67
|
+
if (name.length > MAX_AUTH_HEADER_LENGTH)
|
|
68
|
+
return "too-long";
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* hq-pro's rule for a Bearer, prefix or custom-header key: visible ASCII only
|
|
73
|
+
* (0x21-0x7E), so no inner space. An HTTP Basic password is base64 encoded
|
|
74
|
+
* before it is sent and has its own, looser rule on hq-pro.
|
|
75
|
+
*/
|
|
76
|
+
export function apiKeyIsSendable(key) {
|
|
77
|
+
return /^[\x21-\x7e]+$/.test(key);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=integrations-auth-rules.js.map
|