@indigoai-us/hq-cli 5.345.214 → 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 +93 -0
- package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
- package/dist/command-catalog.generated.d.ts +180 -13
- package/dist/command-catalog.generated.js +221 -13
- package/dist/commands/agents.d.ts +51 -1
- package/dist/commands/agents.js +154 -2
- package/dist/commands/bot-jobs.d.ts +2 -15
- package/dist/commands/bot-jobs.js +2 -94
- package/dist/commands/bot-runtime.d.ts +46 -5
- package/dist/commands/bot-runtime.js +228 -18
- package/dist/commands/bot.d.ts +16 -9
- package/dist/commands/bot.js +231 -55
- package/dist/commands/capacity.d.ts +4 -1
- package/dist/commands/capacity.js +46 -10
- package/dist/commands/cloud.d.ts +66 -13
- package/dist/commands/cloud.js +121 -40
- package/dist/commands/company-restore.d.ts +23 -0
- package/dist/commands/company-restore.js +128 -0
- package/dist/commands/company.js +2 -0
- 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-connect.d.ts +10 -3
- package/dist/commands/integrations-connect.js +87 -13
- package/dist/commands/integrations-import.js +124 -12
- package/dist/commands/lanes.js +28 -11
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +60 -35
- package/dist/commands/sources.js +6 -0
- package/dist/commands/storage-offload.d.ts +12 -0
- package/dist/commands/storage-offload.js +41 -3
- package/dist/commands/sync-held.js +5 -2
- package/dist/commands/sync-mode.js +5 -0
- package/dist/commands/whoami.js +4 -0
- package/dist/lazy-commands.js +3 -5
- package/dist/lib/bot/config.d.ts +1 -0
- package/dist/lib/bot/config.js +10 -0
- package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
- package/dist/lib/bot/eventbridge-cron.js +104 -0
- 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/fleet-local.d.ts +33 -1
- package/dist/lib/bot/fleet-local.js +215 -31
- package/dist/lib/bot/fleet-python.d.ts +3 -0
- package/dist/lib/bot/fleet-python.js +34 -4
- package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
- package/dist/lib/bot/fleet-runtime-sources.js +30 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
- package/dist/lib/bot/legacy-provider-login.js +19 -2
- package/dist/lib/bot/probe.js +7 -1
- package/dist/lib/bot/prompt.js +1 -1
- package/dist/lib/bot/readiness.d.ts +8 -0
- package/dist/lib/bot/readiness.js +17 -3
- 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-auth.d.ts +30 -0
- package/dist/lib/bot/runtime-auth.js +94 -3
- package/dist/lib/bot/runtime-failure.d.ts +23 -0
- package/dist/lib/bot/runtime-failure.js +43 -1
- package/dist/lib/bot/status.d.ts +2 -0
- 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/collectors/grok-refresh.d.ts +80 -0
- package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
- package/dist/lib/capacity/collectors/grok.d.ts +5 -0
- package/dist/lib/capacity/collectors/grok.js +56 -5
- 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/catalog.js +11 -1
- 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/db/sqlite-binding.d.ts +1 -0
- package/dist/lib/db/sqlite-binding.js +1 -1
- package/dist/lib/delivery/admission.d.ts +86 -0
- package/dist/lib/delivery/admission.js +148 -0
- package/dist/lib/delivery/artifacts.d.ts +105 -0
- package/dist/lib/delivery/artifacts.js +567 -0
- package/dist/lib/delivery/attempt-id.d.ts +13 -0
- package/dist/lib/delivery/attempt-id.js +16 -0
- package/dist/lib/delivery/backup.d.ts +78 -0
- package/dist/lib/delivery/backup.js +343 -0
- package/dist/lib/delivery/cache.d.ts +29 -0
- package/dist/lib/delivery/cache.js +33 -0
- package/dist/lib/delivery/contracts.d.ts +142 -0
- package/dist/lib/delivery/contracts.js +289 -0
- package/dist/lib/delivery/credentials.d.ts +54 -0
- package/dist/lib/delivery/credentials.js +119 -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 +146 -0
- package/dist/lib/delivery/enrollment.js +460 -0
- package/dist/lib/delivery/escalations.d.ts +51 -0
- package/dist/lib/delivery/escalations.js +60 -0
- package/dist/lib/delivery/identity.d.ts +25 -0
- package/dist/lib/delivery/identity.js +82 -0
- package/dist/lib/delivery/inbox.d.ts +116 -0
- package/dist/lib/delivery/inbox.js +260 -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 +255 -0
- package/dist/lib/delivery/migrations.js +823 -0
- package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
- package/dist/lib/delivery/mqtt-adapter.js +242 -0
- package/dist/lib/delivery/mqtt.d.ts +63 -0
- package/dist/lib/delivery/mqtt.js +119 -0
- package/dist/lib/delivery/outbox.d.ts +95 -0
- package/dist/lib/delivery/outbox.js +187 -0
- package/dist/lib/delivery/provenance.d.ts +129 -0
- package/dist/lib/delivery/provenance.js +93 -0
- package/dist/lib/delivery/reconciler.d.ts +215 -0
- package/dist/lib/delivery/reconciler.js +703 -0
- package/dist/lib/delivery/restore.d.ts +35 -0
- package/dist/lib/delivery/restore.js +134 -0
- 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 +163 -0
- package/dist/lib/delivery/store.js +944 -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-job-helper.d.ts +103 -0
- package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
- package/dist/lib/delivery/workers/macos.d.ts +191 -0
- package/dist/lib/delivery/workers/macos.js +943 -0
- package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
- package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
- 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 +251 -0
- package/dist/lib/delivery/workers/windows.js +594 -0
- 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/install/provider-wrappers.d.ts +2 -0
- package/dist/lib/install/provider-wrappers.js +68 -3
- 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/cognito-callback-port.d.ts +14 -0
- package/dist/utils/cognito-callback-port.js +24 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/deleted-company-notice.d.ts +59 -0
- package/dist/utils/deleted-company-notice.js +156 -0
- package/dist/utils/files-browse-acl.js +1 -1
- package/dist/utils/login-browser.d.ts +1 -1
- package/dist/utils/login-browser.js +7 -5
- package/dist/utils/resident-package-preload.js +30 -15
- package/dist/utils/vault-api.js +7 -0
- package/package.json +7 -7
|
@@ -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
|
|
@@ -65,7 +65,9 @@ export declare function connectScopeFromOptions(opts: Pick<ConnectOptions, "pers
|
|
|
65
65
|
* than fall through to a default.
|
|
66
66
|
*/
|
|
67
67
|
export declare function assertAuthMode(value: string | undefined): void;
|
|
68
|
-
/**
|
|
68
|
+
/** True when hq-pro refuses to send a key in this (token-valid) header name. */
|
|
69
|
+
export declare function isDeniedAuthHeader(name: string): boolean;
|
|
70
|
+
/** RFC 7230 token, at most 64 characters, and not on hq-pro's denylist. */
|
|
69
71
|
export declare function assertAuthHeader(value: string | undefined): void;
|
|
70
72
|
/** Single-quote a value for a copy-pasteable shell command. */
|
|
71
73
|
export declare function shellQuote(value: string): string;
|
|
@@ -79,9 +81,14 @@ export declare function shellQuote(value: string): string;
|
|
|
79
81
|
* HQ-PRO-5QF: a key pasted from a doc or chat often arrives wrapped across
|
|
80
82
|
* lines or with a tab, and sometimes with smart quotes. hq-pro sends the key
|
|
81
83
|
* in an HTTP header, which can't carry those characters. Trim the ends, drop
|
|
82
|
-
* inner line breaks and tabs, and refuse anything else outside visible ASCII
|
|
83
|
-
* (an inner space is left for hq-pro to judge, since HTTP Basic allows it).
|
|
84
|
+
* inner line breaks and tabs, and refuse anything else outside visible ASCII.
|
|
84
85
|
* The message never echoes the key.
|
|
86
|
+
*
|
|
87
|
+
* feedback_950d8abe: this is hq-pro's rule for every key the CLI sends. The
|
|
88
|
+
* CLI sends a key as Bearer or in a custom header (--auth-header), never as an
|
|
89
|
+
* HTTP Basic password, and hq-pro accepts only visible ASCII (0x21-0x7E) for
|
|
90
|
+
* those. An inner space used to pass here and come back from hq-pro as a 400
|
|
91
|
+
* DIRECT_MCP_INVALID_API_KEY_CHARACTERS.
|
|
85
92
|
*/
|
|
86
93
|
export declare const API_KEY_UNSENDABLE_MESSAGE = "The key contains a character that can't be sent. Copy it again and paste only the key.";
|
|
87
94
|
export declare function normalizePastedApiKey(raw: string): string;
|
|
@@ -235,18 +235,87 @@ export function assertAuthMode(value) {
|
|
|
235
235
|
throw new IntegrationsCliError("--auth must be none, key, or oauth.", { expected: true });
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
/**
|
|
238
|
+
/**
|
|
239
|
+
* feedback_950d8abe: hq-pro's save-time rule for a custom key header
|
|
240
|
+
* (src/integration-factory/api-key-characters.ts). Kept identical so the CLI
|
|
241
|
+
* never sends a header name hq-pro refuses with DIRECT_MCP_INVALID_AUTH_SCHEME,
|
|
242
|
+
* and never refuses one hq-pro accepts. Authorization is allowed: a header
|
|
243
|
+
* placement named Authorization is the one way to send a raw key with no
|
|
244
|
+
* prefix.
|
|
245
|
+
*/
|
|
246
|
+
const MAX_AUTH_HEADER_LENGTH = 64;
|
|
247
|
+
const DENIED_AUTH_HEADER_NAMES = new Set([
|
|
248
|
+
// hop-by-hop, framing and request target
|
|
249
|
+
"connection",
|
|
250
|
+
"keep-alive",
|
|
251
|
+
"proxy-connection",
|
|
252
|
+
"te",
|
|
253
|
+
"trailer",
|
|
254
|
+
"transfer-encoding",
|
|
255
|
+
"upgrade",
|
|
256
|
+
"http2-settings",
|
|
257
|
+
"content-length",
|
|
258
|
+
"expect",
|
|
259
|
+
"host",
|
|
260
|
+
"content-encoding",
|
|
261
|
+
// cookies, auth challenges, forwarding and client-IP headers
|
|
262
|
+
"cookie",
|
|
263
|
+
"set-cookie",
|
|
264
|
+
"www-authenticate",
|
|
265
|
+
"proxy-authorization",
|
|
266
|
+
"proxy-authenticate",
|
|
267
|
+
"forwarded",
|
|
268
|
+
"via",
|
|
269
|
+
"x-real-ip",
|
|
270
|
+
"true-client-ip",
|
|
271
|
+
"cf-connecting-ip",
|
|
272
|
+
"x-original-url",
|
|
273
|
+
// set by HQ's MCP client itself
|
|
274
|
+
"accept",
|
|
275
|
+
"accept-encoding",
|
|
276
|
+
"content-type",
|
|
277
|
+
"user-agent",
|
|
278
|
+
"mcp-protocol-version",
|
|
279
|
+
"mcp-session-id",
|
|
280
|
+
"last-event-id",
|
|
281
|
+
]);
|
|
282
|
+
/** Case-insensitive prefixes: any Proxy-* (also listed by name above) and every X-Forwarded-*. */
|
|
283
|
+
const DENIED_AUTH_HEADER_PREFIXES = ["proxy-", "x-forwarded-"];
|
|
284
|
+
/** True when hq-pro refuses to send a key in this (token-valid) header name. */
|
|
285
|
+
export function isDeniedAuthHeader(name) {
|
|
286
|
+
const lower = name.toLowerCase();
|
|
287
|
+
return (DENIED_AUTH_HEADER_NAMES.has(lower) ||
|
|
288
|
+
DENIED_AUTH_HEADER_PREFIXES.some((prefix) => lower.startsWith(prefix)));
|
|
289
|
+
}
|
|
290
|
+
/** RFC 7230 token, at most 64 characters, and not on hq-pro's denylist. */
|
|
239
291
|
export function assertAuthHeader(value) {
|
|
240
|
-
if (value
|
|
292
|
+
if (value === undefined)
|
|
293
|
+
return;
|
|
294
|
+
if (!/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(value)) {
|
|
241
295
|
throw new IntegrationsCliError("--auth-header must be a non-empty HTTP header name using RFC 7230 token characters.", { expected: true });
|
|
242
296
|
}
|
|
297
|
+
if (isDeniedAuthHeader(value)) {
|
|
298
|
+
throw new IntegrationsCliError(`HQ can't send a key in the ${value} header. Use the header name from the app's docs, such as X-API-Key.`, { expected: true });
|
|
299
|
+
}
|
|
300
|
+
if (value.length > MAX_AUTH_HEADER_LENGTH) {
|
|
301
|
+
throw new IntegrationsCliError(`--auth-header can be up to ${MAX_AUTH_HEADER_LENGTH} characters.`, { expected: true });
|
|
302
|
+
}
|
|
243
303
|
}
|
|
244
304
|
/** Single-quote a value for a copy-pasteable shell command. */
|
|
245
305
|
export function shellQuote(value) {
|
|
246
306
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
247
307
|
}
|
|
248
|
-
/**
|
|
249
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Read a secret from stdin, without echoing or trailing-newline noise.
|
|
310
|
+
*
|
|
311
|
+
* When stdin is a terminal, a bare read waits in silence and looks frozen
|
|
312
|
+
* (feedback_86a49a5c). In that case print a one-line prompt to stderr and read
|
|
313
|
+
* with echo off. Piped stdin keeps the silent read.
|
|
314
|
+
*/
|
|
315
|
+
function readStdin(promptLabel) {
|
|
316
|
+
if (process.stdin.isTTY) {
|
|
317
|
+
return promptForKey(`${promptLabel}, then press Enter (input is hidden)`, process.stderr);
|
|
318
|
+
}
|
|
250
319
|
return new Promise((resolve, reject) => {
|
|
251
320
|
let data = "";
|
|
252
321
|
process.stdin.setEncoding("utf8");
|
|
@@ -263,9 +332,9 @@ function readStdin() {
|
|
|
263
332
|
* reach argv (shell history, `ps` output) unless the caller insists via
|
|
264
333
|
* `--token`.
|
|
265
334
|
*/
|
|
266
|
-
function promptForKey(label) {
|
|
335
|
+
function promptForKey(label, out = process.stdout) {
|
|
267
336
|
return new Promise((resolve, reject) => {
|
|
268
|
-
|
|
337
|
+
out.write(`${label}: `);
|
|
269
338
|
if (process.stdin.isTTY)
|
|
270
339
|
process.stdin.setRawMode(true);
|
|
271
340
|
process.stdin.setEncoding("utf8");
|
|
@@ -281,13 +350,13 @@ function promptForKey(label) {
|
|
|
281
350
|
const codePoint = ch.codePointAt(0);
|
|
282
351
|
if (ch === "\n" || ch === "\r" || codePoint === 4) {
|
|
283
352
|
cleanup();
|
|
284
|
-
|
|
353
|
+
out.write("\n");
|
|
285
354
|
resolve(value);
|
|
286
355
|
return;
|
|
287
356
|
}
|
|
288
357
|
if (codePoint === 3) {
|
|
289
358
|
cleanup();
|
|
290
|
-
|
|
359
|
+
out.write("\n");
|
|
291
360
|
reject(new IntegrationsCliError("Cancelled.", { expected: true }));
|
|
292
361
|
return;
|
|
293
362
|
}
|
|
@@ -312,21 +381,26 @@ function promptForKey(label) {
|
|
|
312
381
|
* HQ-PRO-5QF: a key pasted from a doc or chat often arrives wrapped across
|
|
313
382
|
* lines or with a tab, and sometimes with smart quotes. hq-pro sends the key
|
|
314
383
|
* in an HTTP header, which can't carry those characters. Trim the ends, drop
|
|
315
|
-
* inner line breaks and tabs, and refuse anything else outside visible ASCII
|
|
316
|
-
* (an inner space is left for hq-pro to judge, since HTTP Basic allows it).
|
|
384
|
+
* inner line breaks and tabs, and refuse anything else outside visible ASCII.
|
|
317
385
|
* The message never echoes the key.
|
|
386
|
+
*
|
|
387
|
+
* feedback_950d8abe: this is hq-pro's rule for every key the CLI sends. The
|
|
388
|
+
* CLI sends a key as Bearer or in a custom header (--auth-header), never as an
|
|
389
|
+
* HTTP Basic password, and hq-pro accepts only visible ASCII (0x21-0x7E) for
|
|
390
|
+
* those. An inner space used to pass here and come back from hq-pro as a 400
|
|
391
|
+
* DIRECT_MCP_INVALID_API_KEY_CHARACTERS.
|
|
318
392
|
*/
|
|
319
393
|
export const API_KEY_UNSENDABLE_MESSAGE = "The key contains a character that can't be sent. Copy it again and paste only the key.";
|
|
320
394
|
export function normalizePastedApiKey(raw) {
|
|
321
395
|
const cleaned = raw.trim().replace(/[\r\n\t]+/g, "");
|
|
322
|
-
if (!/^[\
|
|
396
|
+
if (!/^[\x21-\x7e]*$/.test(cleaned)) {
|
|
323
397
|
throw new IntegrationsCliError(API_KEY_UNSENDABLE_MESSAGE, { expected: true });
|
|
324
398
|
}
|
|
325
399
|
return cleaned;
|
|
326
400
|
}
|
|
327
401
|
async function resolveKey(opts, appLabel) {
|
|
328
402
|
if (opts.tokenStdin) {
|
|
329
|
-
const piped = normalizePastedApiKey(await readStdin());
|
|
403
|
+
const piped = normalizePastedApiKey(await readStdin("Paste the API key"));
|
|
330
404
|
if (!piped) {
|
|
331
405
|
throw new IntegrationsCliError("--token-stdin was set but stdin was empty.", {
|
|
332
406
|
expected: true,
|
|
@@ -1051,7 +1125,7 @@ async function resolveUserOAuthClient(opts, appLabel) {
|
|
|
1051
1125
|
if (!clientId)
|
|
1052
1126
|
return null;
|
|
1053
1127
|
if (opts.clientSecretStdin) {
|
|
1054
|
-
const piped = (await readStdin()).trim();
|
|
1128
|
+
const piped = (await readStdin("Paste the client secret")).trim();
|
|
1055
1129
|
if (!piped) {
|
|
1056
1130
|
throw new IntegrationsCliError("--client-secret-stdin was set but stdin was empty.", { expected: true });
|
|
1057
1131
|
}
|