@indigoai-us/hq-cli 5.345.208 → 5.345.211
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 +106 -0
- package/assets/scaffold/core/scripts/derive-trigger-facts.sh +22 -3
- package/assets/scaffold/core/scripts/lib/trigger-fact-text.awk +152 -41
- package/dist/command-catalog.generated.d.ts +33 -8
- package/dist/command-catalog.generated.js +40 -8
- package/dist/command-registration-plan.d.ts +2 -2
- package/dist/command-registration-plan.js +1 -1
- package/dist/commands/access.js +11 -5
- package/dist/commands/agents.d.ts +8 -0
- package/dist/commands/agents.js +5 -0
- package/dist/commands/bot.d.ts +8 -0
- package/dist/commands/bot.js +67 -7
- package/dist/commands/channels.js +4 -0
- package/dist/commands/cloud.d.ts +83 -2
- package/dist/commands/cloud.js +161 -31
- package/dist/commands/company.d.ts +9 -0
- package/dist/commands/company.js +44 -14
- package/dist/commands/core-checkpoint-native.js +21 -0
- package/dist/commands/core-derive-trigger-facts-native.d.ts +1 -0
- package/dist/commands/core-derive-trigger-facts-native.js +75 -14
- package/dist/commands/core-generate-workers-registry-fast.d.ts +1 -1
- package/dist/commands/core-generate-workers-registry-fast.js +7 -1
- package/dist/commands/core-job-run-native.d.ts +8 -0
- package/dist/commands/core-job-run-native.js +11 -3
- package/dist/commands/core-jobs-native.js +1 -1
- package/dist/commands/core-register-project-native.js +31 -1
- package/dist/commands/core-scan-packages-fast.d.ts +1 -1
- package/dist/commands/core-scan-packages-fast.js +8 -1
- package/dist/commands/core-work-mesh-bind-trusted-native.d.ts +14 -2
- package/dist/commands/core-work-mesh-bind-trusted-native.js +62 -8
- package/dist/commands/core.js +12 -3
- package/dist/commands/dm-attach.d.ts +10 -0
- package/dist/commands/dm-attach.js +33 -5
- package/dist/commands/integrations-connect.d.ts +16 -0
- package/dist/commands/integrations-connect.js +70 -6
- package/dist/commands/lanes-session-start.d.ts +17 -0
- package/dist/commands/lanes-session-start.js +281 -13
- package/dist/commands/lanes-watch.js +11 -3
- package/dist/commands/lanes.d.ts +4 -0
- package/dist/commands/lanes.js +95 -22
- package/dist/commands/library.d.ts +10 -0
- package/dist/commands/library.js +30 -3
- package/dist/commands/meetings.d.ts +42 -0
- package/dist/commands/meetings.js +157 -12
- package/dist/commands/mesh.js +3 -0
- package/dist/commands/monitor.d.ts +6 -0
- package/dist/commands/monitor.js +29 -19
- package/dist/commands/onboard.js +8 -1
- package/dist/commands/sources.js +7 -3
- package/dist/index.js +9 -0
- package/dist/lanes-monitor-check-argv.d.ts +1 -1
- package/dist/lanes-monitor-check-argv.js +2 -2
- package/dist/lanes-session-start-argv.d.ts +4 -1
- package/dist/lanes-session-start-argv.js +5 -2
- package/dist/lib/bot/fleet-daemon.d.ts +101 -0
- package/dist/lib/bot/fleet-daemon.js +227 -0
- package/dist/lib/bot/fleet-local.d.ts +26 -0
- package/dist/lib/bot/fleet-local.js +51 -2
- package/dist/lib/bot/index.d.ts +1 -0
- package/dist/lib/bot/index.js +1 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +4 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +8 -1
- package/dist/lib/bot/log.js +3 -1
- package/dist/lib/bot/probe.js +2 -0
- package/dist/lib/bot/run.js +28 -3
- package/dist/lib/bot/runtime-failure.d.ts +4 -2
- package/dist/lib/bot/runtime-failure.js +9 -1
- package/dist/lib/bot/status.d.ts +17 -0
- package/dist/lib/bot/status.js +53 -2
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +5 -5
- package/dist/lib/capacity/collectors/claude-oauth.js +6 -6
- package/dist/lib/core-utils/native-scaffold-help.d.ts +16 -0
- package/dist/lib/core-utils/native-scaffold-help.js +26 -0
- package/dist/lib/core-utils/session-company.d.ts +25 -8
- package/dist/lib/core-utils/session-company.js +59 -17
- package/dist/lib/daemon/catalog.d.ts +34 -1
- package/dist/lib/daemon/catalog.js +42 -3
- package/dist/lib/daemon/run.d.ts +5 -4
- package/dist/lib/daemon/run.js +40 -16
- package/dist/lib/daemon/server.js +26 -7
- package/dist/lib/daemon/supervisor.d.ts +2 -0
- package/dist/lib/daemon/supervisor.js +60 -1
- package/dist/lib/daemon/tools.js +17 -1
- package/dist/lib/db/sqlite-binding.js +2 -1
- package/dist/lib/doctor/checks/bots.d.ts +2 -0
- package/dist/lib/doctor/checks/bots.js +11 -0
- package/dist/lib/doctor/checks/runtime-health.js +3 -2
- package/dist/lib/doctor/checks/work-context.js +5 -2
- package/dist/lib/hook-engine/resolve.d.ts +1 -1
- package/dist/lib/hook-engine/resolve.js +4 -1
- package/dist/lib/hot-channels/adapters/meeting-providers.d.ts +2 -0
- package/dist/lib/hot-channels/adapters/meeting-providers.js +13 -2
- package/dist/lib/lanes/index.d.ts +1 -1
- package/dist/lib/lanes/index.js +1 -1
- package/dist/lib/lanes/monitor.d.ts +14 -0
- package/dist/lib/lanes/monitor.js +51 -10
- package/dist/lib/lanes/outpost-dispatch.d.ts +3 -0
- package/dist/lib/lanes/outpost-dispatch.js +1 -0
- package/dist/lib/lanes/store.d.ts +1 -1
- package/dist/lib/lanes/store.js +2 -1
- package/dist/lib/mesh/client.js +7 -1
- package/dist/lib/mesh/live/backfill-held.d.ts +3 -0
- package/dist/lib/mesh/live/backfill-held.js +167 -7
- package/dist/lib/mesh/live/flush.d.ts +7 -0
- package/dist/lib/mesh/live/flush.js +10 -1
- package/dist/lib/monitor.d.ts +9 -0
- package/dist/lib/monitor.js +33 -7
- package/dist/lib/onboarding/orchestrator.js +269 -132
- package/dist/lib/onboarding/types.d.ts +2 -0
- package/dist/lib/scaffold-cli-floor.js +2 -1
- package/dist/lib/signals/failure-alert.js +3 -1
- package/dist/lib/sync-core/reconcile.js +15 -11
- package/dist/lib/work-context/organize.d.ts +6 -0
- package/dist/lib/work-context/organize.js +28 -0
- package/dist/lib/work-context/paths.d.ts +9 -0
- package/dist/lib/work-context/paths.js +15 -0
- package/dist/lib/work-context/prd-sync.js +2 -1
- package/dist/runners-alias.d.ts +54 -0
- package/dist/runners-alias.js +86 -0
- package/dist/utils/install-tree-torn.js +5 -3
- package/dist/utils/npm-install-flags.d.ts +27 -0
- package/dist/utils/npm-install-flags.js +68 -0
- package/dist/utils/package-use-lease.js +1 -1
- package/dist/utils/qmd-native-binding-error.js +2 -1
- package/dist/utils/self-update.js +2 -1
- package/dist/utils/staged-install.js +2 -1
- package/dist/utils/staged-npm-install.js +2 -1
- package/dist/utils/upload-author.d.ts +2 -1
- package/dist/utils/upload-author.js +9 -5
- package/dist/utils/version-check.js +2 -1
- package/dist/utils/version-gate.js +7 -6
- package/package.json +7 -7
- package/scripts/install-hook-engine.mjs +7 -3
|
@@ -271,7 +271,52 @@ function emptyPayload() {
|
|
|
271
271
|
cwd: "", sessionId: "", transcriptPath: "",
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
|
-
|
|
274
|
+
// `pull request #?[0-9]+ [\s\S]* merged`, without the backtracking regex: V8
|
|
275
|
+
// retries `[\s\S]*` to the end of the text from every "pull request <n> ", so
|
|
276
|
+
// an output with many of them cost size times count. The earliest prefix
|
|
277
|
+
// leaves the most text for " merged", so it alone decides the match.
|
|
278
|
+
function pullRequestMerged(text) {
|
|
279
|
+
const prefix = /pull request #?[0-9]+ /.exec(text);
|
|
280
|
+
return prefix !== null && text.includes(" merged", prefix.index + prefix[0].length);
|
|
281
|
+
}
|
|
282
|
+
// `-----begin[a-z -]*private key`, without the backtracking regex: V8 rescans
|
|
283
|
+
// the [a-z -] run after every "-----begin" in it. Every "-----begin" in one
|
|
284
|
+
// run can reach the same bytes, so only the first in each run is checked.
|
|
285
|
+
function pemPrivateKeyHeader(text) {
|
|
286
|
+
const outsideRun = /[^a-z -]/g;
|
|
287
|
+
let from = 0;
|
|
288
|
+
for (;;) {
|
|
289
|
+
const start = text.indexOf("-----begin", from);
|
|
290
|
+
if (start < 0)
|
|
291
|
+
return false;
|
|
292
|
+
const body = start + "-----begin".length;
|
|
293
|
+
outsideRun.lastIndex = body;
|
|
294
|
+
const end = outsideRun.exec(text)?.index ?? text.length;
|
|
295
|
+
if (text.slice(body, end).includes("private key"))
|
|
296
|
+
return true;
|
|
297
|
+
from = end;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// File references, as `text.matchAll(/\.?[a-z0-9_][a-z0-9_./-]*\.[a-z][a-z0-9]+/g)`
|
|
301
|
+
// would find them. A reference holds only [a-z0-9_./-] bytes, so each run of
|
|
302
|
+
// those bytes is scanned on its own, and only up to the end of its last
|
|
303
|
+
// `.<letter><alnum>` extension: no match can end later. Without that cut, V8
|
|
304
|
+
// retries the pattern from every start in a long run with no extension (a hex
|
|
305
|
+
// blob, say) to the end of the run, which is quadratic in the run's length.
|
|
306
|
+
function fileReferences(text) {
|
|
307
|
+
const references = [];
|
|
308
|
+
for (const run of text.matchAll(/[a-z0-9_./-]+/g)) {
|
|
309
|
+
let end = 0;
|
|
310
|
+
for (const extension of run[0].matchAll(/\.[a-z][a-z0-9]+/g))
|
|
311
|
+
end = extension.index + extension[0].length;
|
|
312
|
+
if (end === 0)
|
|
313
|
+
continue;
|
|
314
|
+
for (const match of run[0].slice(0, end).matchAll(/\.?[a-z0-9_][a-z0-9_./-]*\.[a-z][a-z0-9]+/g))
|
|
315
|
+
references.push(match[0]);
|
|
316
|
+
}
|
|
317
|
+
return references;
|
|
318
|
+
}
|
|
319
|
+
export function matchTextFacts(rawText, env) {
|
|
275
320
|
const text = localeLower(rawText, env);
|
|
276
321
|
const facts = [];
|
|
277
322
|
const words = /[a-z][a-z0-9_-]+/g;
|
|
@@ -288,19 +333,18 @@ function matchTextFacts(rawText, env) {
|
|
|
288
333
|
/(^|[^a-z0-9])akia[a-z0-9][a-z0-9]/.test(text) ||
|
|
289
334
|
/(^|[^a-z0-9])xox[bpsa]-[a-z0-9]/.test(text) ||
|
|
290
335
|
/(^|[^a-z0-9])glpat-[a-z0-9]/.test(text) ||
|
|
291
|
-
|
|
336
|
+
pemPrivateKeyHeader(text) ||
|
|
292
337
|
/(^|[^a-z0-9])bearer [a-z0-9._-][a-z0-9._-][a-z0-9._-]/.test(text)) {
|
|
293
338
|
facts.push("apikey", "secret");
|
|
294
339
|
}
|
|
295
340
|
if (/successfully (merged|deployed|pushed|published|created)/.test(text) ||
|
|
296
341
|
/(deployment|deploy|build|release) (complete|completed|succeeded|ready)/.test(text) ||
|
|
297
342
|
/merged pull request/.test(text) ||
|
|
298
|
-
|
|
343
|
+
pullRequestMerged(text)) {
|
|
299
344
|
facts.push("completed");
|
|
300
345
|
}
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
const filename = match[0].slice(match[0].lastIndexOf("/") + 1);
|
|
346
|
+
for (const reference of fileReferences(text)) {
|
|
347
|
+
const filename = reference.slice(reference.lastIndexOf("/") + 1);
|
|
304
348
|
const dot = filename.lastIndexOf(".");
|
|
305
349
|
facts.push(`.${filename.slice(dot + 1)}`, filename);
|
|
306
350
|
}
|
|
@@ -310,6 +354,12 @@ function matchTextFacts(rawText, env) {
|
|
|
310
354
|
}
|
|
311
355
|
return facts;
|
|
312
356
|
}
|
|
357
|
+
// Appends one by one: `facts.push(...list)` passes every fact as an argument
|
|
358
|
+
// and overflows the call stack once a large text yields ~100k facts.
|
|
359
|
+
function pushTextFacts(facts, text, env) {
|
|
360
|
+
for (const fact of matchTextFacts(text, env))
|
|
361
|
+
facts.push(fact);
|
|
362
|
+
}
|
|
313
363
|
function isSharedBranch(branch, env) {
|
|
314
364
|
const value = localeLower(branch, env);
|
|
315
365
|
return /(^|[^a-z0-9_])(main|master|staging|production)([^a-z0-9_]|$)/.test(value) || /release\//.test(value);
|
|
@@ -453,11 +503,15 @@ function computeOutput(options) {
|
|
|
453
503
|
throw new ShellFallbackRequired("unsupported argv");
|
|
454
504
|
const event = args[0] ?? "";
|
|
455
505
|
const withAssistantIntent = args[1] === "--with-assistant-intent";
|
|
456
|
-
|
|
506
|
+
const withCommandFacts = args[1] === "--with-command-facts";
|
|
507
|
+
if (args.length === 2 && !withAssistantIntent && !withCommandFacts)
|
|
457
508
|
throw new ShellFallbackRequired("unsupported argv");
|
|
458
509
|
// The shell accepts unknown event names and emits the baseline `always`
|
|
459
510
|
// fact (plus any static session facts); it does not validate the event.
|
|
460
511
|
const paired = withAssistantIntent && (event === "PreToolUse" || event === "UserPromptSubmit");
|
|
512
|
+
// PostToolUse with its command facts (the PreToolUse set of the same
|
|
513
|
+
// payload) in one call, so the policy hook needs one launch (feedback_45868a9c).
|
|
514
|
+
const pairedCommand = withCommandFacts && event === "PostToolUse";
|
|
461
515
|
const env = effectiveEnvironment(options);
|
|
462
516
|
const initialEnv = { ...process.env, ...(options.env ?? {}) };
|
|
463
517
|
const jqAvailable = options.jqAvailable ?? commandOnPath("jq", env);
|
|
@@ -469,28 +523,30 @@ function computeOutput(options) {
|
|
|
469
523
|
payload = parsePayload(options.stdin || "{}");
|
|
470
524
|
const payloadCwd = payload.cwd || env.CLAUDE_PROJECT_DIR || options.cwd;
|
|
471
525
|
const company = resolveCompanyFact(payload.cwd, payload.sessionId, options.hqRoot, options.cwd, env);
|
|
526
|
+
// Both records of a paired call read the same cwd, so the branch is read once.
|
|
527
|
+
let cwdBranch;
|
|
472
528
|
const derive = (kind) => {
|
|
473
529
|
const facts = ["always"];
|
|
474
530
|
let branch = "";
|
|
475
531
|
if (kind === "PreToolUse" || kind === "PostToolUse") {
|
|
476
532
|
if (payload.tool === "Bash") {
|
|
477
533
|
if (kind === "PreToolUse") {
|
|
478
|
-
facts
|
|
534
|
+
pushTextFacts(facts, payload.command, env);
|
|
479
535
|
if (payload.runInBackground === "true")
|
|
480
536
|
facts.push("run_in_background");
|
|
481
537
|
}
|
|
482
538
|
else
|
|
483
|
-
facts
|
|
539
|
+
pushTextFacts(facts, payload.toolResponse, env);
|
|
484
540
|
}
|
|
485
541
|
else if (payload.tool !== "") {
|
|
486
542
|
if (kind === "PreToolUse")
|
|
487
543
|
facts.push(localeLower(payload.tool, env));
|
|
488
544
|
else
|
|
489
|
-
facts
|
|
545
|
+
pushTextFacts(facts, payload.toolResponse, env);
|
|
490
546
|
}
|
|
491
547
|
}
|
|
492
548
|
else if (kind === "UserPromptSubmit") {
|
|
493
|
-
facts
|
|
549
|
+
pushTextFacts(facts, payload.prompt, env);
|
|
494
550
|
}
|
|
495
551
|
if (company)
|
|
496
552
|
facts.push("company");
|
|
@@ -500,7 +556,7 @@ function computeOutput(options) {
|
|
|
500
556
|
if (fs.statSync(payload.transcriptPath).isFile()) {
|
|
501
557
|
const lookback = transcriptAssistantText(payload.transcriptPath);
|
|
502
558
|
if (lookback)
|
|
503
|
-
facts
|
|
559
|
+
pushTextFacts(facts, lookback, env);
|
|
504
560
|
}
|
|
505
561
|
}
|
|
506
562
|
catch (error) {
|
|
@@ -518,12 +574,17 @@ function computeOutput(options) {
|
|
|
518
574
|
const shellCwd = usesPwdFallback ? payloadCwd.replaceAll("\\", "/") : payloadCwd;
|
|
519
575
|
if (shellCwd.includes("repos/public/") || shellCwd.includes("repos/private/"))
|
|
520
576
|
facts.push("repo");
|
|
521
|
-
|
|
577
|
+
cwdBranch ??= options.gitBranch ?? readBranch(payloadCwd, env);
|
|
578
|
+
branch = cwdBranch;
|
|
522
579
|
}
|
|
523
580
|
return normalizeFacts(facts, branch, options.cwd, env);
|
|
524
581
|
};
|
|
525
582
|
const primary = derive(event);
|
|
526
|
-
|
|
583
|
+
if (paired)
|
|
584
|
+
return `${primary}\n${derive("AssistantIntent")}\n`;
|
|
585
|
+
if (pairedCommand)
|
|
586
|
+
return `${primary}\n${derive("PreToolUse")}\n`;
|
|
587
|
+
return `${primary}\n`;
|
|
527
588
|
}
|
|
528
589
|
function shellFallback(options) {
|
|
529
590
|
const env = { ...process.env, ...(options.env ?? {}) };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function runGenerateWorkersRegistryFast(
|
|
1
|
+
export declare function runGenerateWorkersRegistryFast(args: string[], _stdin: string, _cwd: string, hqRoot?: string): number;
|
|
2
2
|
//# sourceMappingURL=core-generate-workers-registry-fast.d.ts.map
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { generateWorkersRegistry } from "../lib/workers-registry/index.js";
|
|
2
|
-
|
|
2
|
+
import { GENERATE_WORKERS_REGISTRY_SUMMARY, isNativeScaffoldHelpRequest, nativeScaffoldUsage, } from "../lib/core-utils/native-scaffold-help.js";
|
|
3
|
+
export function runGenerateWorkersRegistryFast(args, _stdin, _cwd, hqRoot) {
|
|
4
|
+
// `--help` must not regenerate registry.yaml (feedback_83ae2e72).
|
|
5
|
+
if (isNativeScaffoldHelpRequest(args)) {
|
|
6
|
+
process.stdout.write(nativeScaffoldUsage("generate-workers-registry", GENERATE_WORKERS_REGISTRY_SUMMARY));
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
3
9
|
return generateWorkersRegistry(hqRoot ?? process.cwd()).status;
|
|
4
10
|
}
|
|
5
11
|
//# sourceMappingURL=core-generate-workers-registry-fast.js.map
|
|
@@ -42,6 +42,14 @@ export type JobRunDependencies = {
|
|
|
42
42
|
export declare function spawnProcess(request: ProcessRequest): Promise<ProcessResult>;
|
|
43
43
|
/** Holds the same kernel flock(2) lock used by the shell companion. */
|
|
44
44
|
export declare function acquireFlock(file: string, env?: NodeJS.ProcessEnv): Promise<LockLease>;
|
|
45
|
+
/**
|
|
46
|
+
* feedback_65ee9e51: a scheduled job runs with nobody watching, so any `hq sync`
|
|
47
|
+
* it starts (the agent's own tool calls, remediation pulls) must not delete a
|
|
48
|
+
* file another member created. hq-cloud reads this variable.
|
|
49
|
+
*/
|
|
50
|
+
export declare const JOB_UNATTENDED_SYNC_ENV: {
|
|
51
|
+
readonly HQ_SYNC_UNATTENDED: "1";
|
|
52
|
+
};
|
|
45
53
|
export declare function runJob(argv: string[], hqRootOverride?: string, injected?: Partial<JobRunDependencies>): Promise<number>;
|
|
46
54
|
export declare function registerCoreJobRunCommand(job: Command): void;
|
|
47
55
|
export {};
|
|
@@ -933,7 +933,9 @@ async function runRemoteClaude(jobId, runtime, prompt, runCwd, timeoutSeconds, s
|
|
|
933
933
|
}
|
|
934
934
|
deps.appendFile(logFile, `surface=remote remote_name=${remoteName} tmux_session=${session} done_file=${doneFile}\n`);
|
|
935
935
|
const remoteArgs = ["--remote-control", remoteName, "--permission-mode", "bypassPermissions", "--dangerously-skip-permissions", remotePrompt];
|
|
936
|
-
|
|
936
|
+
// An already-running tmux server does not pass our env to the pane, so the
|
|
937
|
+
// unattended-sync marker rides on the command itself.
|
|
938
|
+
const tmuxCommand = `HQ_SYNC_UNATTENDED=1 ${[process.execPath, REMOTE_LAUNCHER, exitFile, ...remoteArgs].map(bashPrintfQuote).join(" ")}`;
|
|
937
939
|
const tmuxEnv = deps.env.HQ_JOB_RUN_STUBS === "1"
|
|
938
940
|
? { ...deps.env, HQ_JOB_RUN_REMOTE_DONE_FILE: doneFile, HQ_JOB_RUN_REMOTE_EXIT_FILE: exitFile }
|
|
939
941
|
: deps.env;
|
|
@@ -1052,9 +1054,15 @@ async function recordSkip(jobId, jobName, runtime, skipReason, failureClass, act
|
|
|
1052
1054
|
void logDir;
|
|
1053
1055
|
return 0;
|
|
1054
1056
|
}
|
|
1057
|
+
/**
|
|
1058
|
+
* feedback_65ee9e51: a scheduled job runs with nobody watching, so any `hq sync`
|
|
1059
|
+
* it starts (the agent's own tool calls, remediation pulls) must not delete a
|
|
1060
|
+
* file another member created. hq-cloud reads this variable.
|
|
1061
|
+
*/
|
|
1062
|
+
export const JOB_UNATTENDED_SYNC_ENV = { HQ_SYNC_UNATTENDED: "1" };
|
|
1055
1063
|
export async function runJob(argv, hqRootOverride, injected) {
|
|
1056
|
-
const env = injected?.env ?? process.env;
|
|
1057
|
-
const deps = { ...defaultDependencies(env), ...injected };
|
|
1064
|
+
const env = { ...(injected?.env ?? process.env), ...JOB_UNATTENDED_SYNC_ENV };
|
|
1065
|
+
const deps = { ...defaultDependencies(env), ...injected, env };
|
|
1058
1066
|
const args = parseArgs(argv);
|
|
1059
1067
|
if (args.help) {
|
|
1060
1068
|
emitUsage();
|
|
@@ -769,7 +769,7 @@ function systemdQuote(value) {
|
|
|
769
769
|
function serviceUnit(root, id) {
|
|
770
770
|
const pathValue = systemdQuote(`PATH=${servicePathValue()}`);
|
|
771
771
|
const runner = path.resolve(root, "core/scripts/hq-job-run.sh");
|
|
772
|
-
return `# Generated by outpost-jobs-reconcile.sh — disposable derived state. Do not edit.\n[Unit]\nDescription=HQ Outpost scheduled job: ${id}\nDocumentation=file://${root}/core/knowledge/public/hq-core/outpost-jobs-spec.md\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nType=oneshot\nEnvironment=HQ_ROOT=${root}\nEnvironment=${pathValue}\nExecStart=${runner} --hq-root ${root} --job-id ${id}\nNice=10\n\n[Install]\nWantedBy=default.target\n`;
|
|
772
|
+
return `# Generated by outpost-jobs-reconcile.sh — disposable derived state. Do not edit.\n[Unit]\nDescription=HQ Outpost scheduled job: ${id}\nDocumentation=file://${root}/core/knowledge/public/hq-core/outpost-jobs-spec.md\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\nType=oneshot\nEnvironment=HQ_ROOT=${root}\nEnvironment=${pathValue}\nEnvironment=HQ_SYNC_UNATTENDED=1\nExecStart=${runner} --hq-root ${root} --job-id ${id}\nNice=10\n\n[Install]\nWantedBy=default.target\n`;
|
|
773
773
|
}
|
|
774
774
|
function timerUnit(id, onCalendar, randomize, root) {
|
|
775
775
|
return `# Generated by outpost-jobs-reconcile.sh — disposable derived state. Do not edit.\n[Unit]\nDescription=HQ Outpost scheduled job timer: ${id}\nDocumentation=file://${root}/core/knowledge/public/hq-core/outpost-jobs-spec.md\n\n[Timer]\nOnCalendar=${onCalendar}\nPersistent=true\nRandomizedDelaySec=${randomize}\nUnit=hq-job-${id}.service\n\n[Install]\nWantedBy=timers.target\n`;
|
|
@@ -168,10 +168,38 @@ function markPending(company, project, deps) {
|
|
|
168
168
|
}
|
|
169
169
|
atomicJqWrite(board, document, deps, true);
|
|
170
170
|
}
|
|
171
|
+
// Refuse when more than one Board entry matches the project being registered.
|
|
172
|
+
// Updating every match used to keep a duplicate id alive on the board
|
|
173
|
+
// (feedback_2b8e4bc8). Mirrors refuse_ambiguous_board_match in
|
|
174
|
+
// core/scripts/register-project.sh, which prints the same message.
|
|
175
|
+
function ambiguousBoardMatch(company, project, deps, matches) {
|
|
176
|
+
const board = boardPath(company, deps);
|
|
177
|
+
if (!deps.fs.existsSync(board))
|
|
178
|
+
return null;
|
|
179
|
+
let rows;
|
|
180
|
+
// The shell skips the check when jq cannot read the board; later steps report that error.
|
|
181
|
+
try {
|
|
182
|
+
rows = projectRows(boardData(company, board, deps));
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const ids = rows.filter(matches)
|
|
188
|
+
.map((row) => (row.id === null || row.id === undefined || row.id === false ? "(no id)" : typeof row.id === "string" ? row.id : JSON.stringify(row.id)).replace(/\r/gu, ""))
|
|
189
|
+
.filter((id) => id !== "");
|
|
190
|
+
if (ids.length <= 1)
|
|
191
|
+
return null;
|
|
192
|
+
return errorResult(`registration refused: ${ids.length} Board entries in companies/${company}/board.json match ${project} (ids: ${ids.join(", ")}). Remove or renumber the duplicates so one entry remains, then re-run. \`bash core/scripts/board-project-id.sh check ${company}\` lists every duplicate id.`);
|
|
193
|
+
}
|
|
171
194
|
function ensureOne(company, project, deps) {
|
|
172
195
|
const prd = path.join(deps.root, "companies", company, "projects", project, "prd.json");
|
|
196
|
+
const meshProject = meshProjectIdForPrd(company, project, deps);
|
|
173
197
|
if (!deps.fs.existsSync(prd))
|
|
174
198
|
return errorResult(`registration incomplete: missing ${prd}`);
|
|
199
|
+
const prdRel = `companies/${company}/projects/${project}/prd.json`;
|
|
200
|
+
const ambiguous = ambiguousBoardMatch(company, project, deps, (row) => matchesProject(row, project, prdRel, meshProject));
|
|
201
|
+
if (ambiguous)
|
|
202
|
+
return ambiguous;
|
|
175
203
|
if (!runHelpProbe(deps)) {
|
|
176
204
|
try {
|
|
177
205
|
markPending(company, project, deps);
|
|
@@ -179,7 +207,6 @@ function ensureOne(company, project, deps) {
|
|
|
179
207
|
catch { /* legacy jq/write errors remain a failed registration */ }
|
|
180
208
|
return errorResult(`hq-cli ${MIN_HQ_CLI} or newer is required; ${company}/${project} stays local until then`);
|
|
181
209
|
}
|
|
182
|
-
const meshProject = meshProjectIdForPrd(company, project, deps);
|
|
183
210
|
// The shell builds this argument from its raw HQ_ROOT plus POSIX separators.
|
|
184
211
|
// On Git Bash that preserves a Win32 drive prefix and appends `/companies/...`.
|
|
185
212
|
const hqPrd = process.platform === "win32"
|
|
@@ -248,6 +275,9 @@ function registerBrainstorm(company, project, deps) {
|
|
|
248
275
|
const board = boardPath(company, deps);
|
|
249
276
|
if (!deps.fs.existsSync(board))
|
|
250
277
|
return errorResult(`registration incomplete: missing ${board}`);
|
|
278
|
+
const ambiguous = ambiguousBoardMatch(company, project, deps, (item) => item.id === project || item.mesh_project_id === project);
|
|
279
|
+
if (ambiguous)
|
|
280
|
+
return ambiguous;
|
|
251
281
|
const document = boardData(company, board, deps);
|
|
252
282
|
const row = projectRows(document).find((item) => item.id === project || item.mesh_project_id === project);
|
|
253
283
|
const title = jqString(jqOr(asRecord(row)?.title, ""));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function runScanPackagesFast(
|
|
1
|
+
export declare function runScanPackagesFast(args: string[], _stdin: string, _cwd: string, hqRoot?: string): number;
|
|
2
2
|
//# sourceMappingURL=core-scan-packages-fast.d.ts.map
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { scanPackages } from "../lib/scan-packages/index.js";
|
|
2
|
-
|
|
2
|
+
import { isNativeScaffoldHelpRequest, nativeScaffoldUsage, SCAN_PACKAGES_SUMMARY, } from "../lib/core-utils/native-scaffold-help.js";
|
|
3
|
+
export function runScanPackagesFast(args, _stdin, _cwd, hqRoot) {
|
|
4
|
+
// `--help` used to run the scan (and re-create pack links) because neither
|
|
5
|
+
// route looked at its arguments (feedback_83ae2e72).
|
|
6
|
+
if (isNativeScaffoldHelpRequest(args)) {
|
|
7
|
+
process.stdout.write(nativeScaffoldUsage("scan-packages", SCAN_PACKAGES_SUMMARY));
|
|
8
|
+
return 0;
|
|
9
|
+
}
|
|
3
10
|
return scanPackages(hqRoot ?? process.cwd(), { quiet: process.env.HQ_SCAN_QUIET === "1" }).status;
|
|
4
11
|
}
|
|
5
12
|
//# sourceMappingURL=core-scan-packages-fast.js.map
|
|
@@ -21,9 +21,9 @@ export type WorkMeshBindDeps = {
|
|
|
21
21
|
stdout: string;
|
|
22
22
|
stderr: string;
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
/** Starts `hq <args>` detached; removes `removeAfterExit` once that process exits. */
|
|
25
|
+
spawnHq: (args: string[], env: NodeJS.ProcessEnv, removeAfterExit?: string) => void;
|
|
25
26
|
pid: number;
|
|
26
|
-
tmpDir: string;
|
|
27
27
|
ulid: (now: Date) => string;
|
|
28
28
|
};
|
|
29
29
|
export declare const createWorkMeshBindDeps: (root: string, cwd: string, env: NodeJS.ProcessEnv, now: () => Date, daemonWarningEnabled?: boolean) => WorkMeshBindDeps;
|
|
@@ -33,6 +33,10 @@ type DetachedSpawnOptions = {
|
|
|
33
33
|
env: NodeJS.ProcessEnv;
|
|
34
34
|
platform?: NodeJS.Platform;
|
|
35
35
|
existsSync?: (candidate: string) => boolean;
|
|
36
|
+
/** File to delete after the hq process exits (the observation it reads). */
|
|
37
|
+
removeAfterExit?: string;
|
|
38
|
+
/** Node binary for the wait-then-remove wrapper; defaults to process.execPath. */
|
|
39
|
+
execPath?: string;
|
|
36
40
|
spawnProcess?: (command: string, args: string[], options: {
|
|
37
41
|
cwd: string;
|
|
38
42
|
env: NodeJS.ProcessEnv;
|
|
@@ -40,10 +44,18 @@ type DetachedSpawnOptions = {
|
|
|
40
44
|
stdio: "ignore";
|
|
41
45
|
shell: boolean;
|
|
42
46
|
windowsVerbatimArguments?: boolean;
|
|
47
|
+
windowsHide?: boolean;
|
|
43
48
|
}) => {
|
|
44
49
|
unref: () => void;
|
|
50
|
+
on?: (event: "error", listener: () => void) => unknown;
|
|
45
51
|
};
|
|
46
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Detached wrapper: runs the planned hq command, waits for it to exit, then
|
|
55
|
+
* removes the observation file it read. Mirrors the shell script's
|
|
56
|
+
* `nohup bash -c '"$1" mesh context reconcile ...; rm -f -- "$2"'`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const WORK_MESH_RECONCILE_REMOVE_WRAPPER: string;
|
|
47
59
|
export declare function spawnWorkMeshHqDetached(args: string[], options: DetachedSpawnOptions): void;
|
|
48
60
|
/**
|
|
49
61
|
* Resolve the bind session. Only a session id the caller owns (the process env)
|
|
@@ -19,7 +19,7 @@ ROOT="\${HQ_ROOT:-\${CLAUDE_PROJECT_DIR:-}}"
|
|
|
19
19
|
if [ -z "$ROOT" ]; then
|
|
20
20
|
`;
|
|
21
21
|
export const createWorkMeshBindDeps = (root, cwd, env, now, daemonWarningEnabled = false) => ({
|
|
22
|
-
root, cwd, env, now, fs, pid: process.pid,
|
|
22
|
+
root, cwd, env, now, fs, pid: process.pid, ulid: (date) => generateUlid(date.getTime()),
|
|
23
23
|
daemonWarningEnabled: daemonWarningEnabled
|
|
24
24
|
&& Boolean(env.HQ_FLAGS_API_URL?.trim())
|
|
25
25
|
&& /^cmp_[A-Za-z0-9]{3,128}$/.test(env.HQ_COMPANY_UID?.trim() ?? ""),
|
|
@@ -50,12 +50,26 @@ export const createWorkMeshBindDeps = (root, cwd, env, now, daemonWarningEnabled
|
|
|
50
50
|
const result = spawnSync("bash", [path.join(scriptRoot, "core/scripts/hq-session.sh"), ...args], { cwd, env: childEnv, encoding: "utf8" });
|
|
51
51
|
return { code: result.status ?? 127, stdout: result.stdout ?? "", stderr: result.stderr ?? (result.error ? `${result.error.message}\n` : "") };
|
|
52
52
|
},
|
|
53
|
-
spawnHq: (args, childEnv) => spawnWorkMeshHqDetached(args, {
|
|
53
|
+
spawnHq: (args, childEnv, removeAfterExit) => spawnWorkMeshHqDetached(args, {
|
|
54
54
|
cwd,
|
|
55
55
|
root,
|
|
56
56
|
env: childEnv,
|
|
57
|
+
...(removeAfterExit ? { removeAfterExit } : {}),
|
|
57
58
|
}),
|
|
58
59
|
});
|
|
60
|
+
/**
|
|
61
|
+
* Detached wrapper: runs the planned hq command, waits for it to exit, then
|
|
62
|
+
* removes the observation file it read. Mirrors the shell script's
|
|
63
|
+
* `nohup bash -c '"$1" mesh context reconcile ...; rm -f -- "$2"'`.
|
|
64
|
+
*/
|
|
65
|
+
export const WORK_MESH_RECONCILE_REMOVE_WRAPPER = [
|
|
66
|
+
"const cp=require('node:child_process'),fs=require('node:fs');",
|
|
67
|
+
"const [spec,file]=process.argv.slice(1);",
|
|
68
|
+
"let done=false;const remove=()=>{if(done)return;done=true;try{fs.rmSync(file,{force:true})}catch{}};",
|
|
69
|
+
"try{const p=JSON.parse(spec);",
|
|
70
|
+
"const child=cp.spawn(p.cmd,p.args,{cwd:p.cwd,env:process.env,stdio:'ignore',shell:p.shell,windowsHide:true,windowsVerbatimArguments:p.windowsVerbatimArguments===true});",
|
|
71
|
+
"child.on('error',remove);child.on('exit',remove)}catch{remove()}",
|
|
72
|
+
].join("");
|
|
59
73
|
export function spawnWorkMeshHqDetached(args, options) {
|
|
60
74
|
const platform = options.platform ?? process.platform;
|
|
61
75
|
const childEnv = { ...options.env, HQ_ROOT: options.root };
|
|
@@ -63,6 +77,28 @@ export function spawnWorkMeshHqDetached(args, options) {
|
|
|
63
77
|
? resolveWindowsExecutable("hq", childEnv, options.existsSync ?? fs.existsSync, options.cwd) ?? "hq"
|
|
64
78
|
: "hq";
|
|
65
79
|
const plan = planResolvedCommandSpawn(executable, args, childEnv, platform);
|
|
80
|
+
if (options.removeAfterExit) {
|
|
81
|
+
const spec = JSON.stringify({
|
|
82
|
+
cmd: plan.cmd,
|
|
83
|
+
args: plan.args,
|
|
84
|
+
cwd: options.cwd,
|
|
85
|
+
shell: plan.shell,
|
|
86
|
+
windowsVerbatimArguments: plan.windowsVerbatimArguments === true,
|
|
87
|
+
});
|
|
88
|
+
const wrapper = (options.spawnProcess ?? spawn)(options.execPath ?? process.execPath, ["--input-type=commonjs", "-e", WORK_MESH_RECONCILE_REMOVE_WRAPPER, spec, options.removeAfterExit], {
|
|
89
|
+
cwd: options.cwd,
|
|
90
|
+
env: childEnv,
|
|
91
|
+
detached: true,
|
|
92
|
+
stdio: "ignore",
|
|
93
|
+
shell: false,
|
|
94
|
+
windowsHide: true,
|
|
95
|
+
});
|
|
96
|
+
// A failed wrapper start must not throw in this process; the SessionStart
|
|
97
|
+
// hook's age sweep removes the observation it leaves.
|
|
98
|
+
wrapper.on?.("error", () => { });
|
|
99
|
+
wrapper.unref();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
66
102
|
const child = (options.spawnProcess ?? spawn)(plan.cmd, plan.args, {
|
|
67
103
|
cwd: options.cwd,
|
|
68
104
|
env: childEnv,
|
|
@@ -216,12 +252,21 @@ export function runWorkMeshBindTrusted(args, deps) {
|
|
|
216
252
|
trusted.authority = "trusted";
|
|
217
253
|
observation.trustedContext = trusted;
|
|
218
254
|
}
|
|
219
|
-
|
|
255
|
+
// Observations live under the HQ root's workspace/, not the system temp
|
|
256
|
+
// folder (on Windows that is the user's Temp, which nothing cleans). The
|
|
257
|
+
// SessionStart hook's age sweep removes any that a crashed run leaves.
|
|
258
|
+
const scratchRoot = path.join(root, "workspace", "tmp", "work-mesh");
|
|
259
|
+
const directory = path.join(scratchRoot, "obs");
|
|
220
260
|
try {
|
|
221
|
-
deps.fs.mkdirSync(directory, { recursive: true
|
|
222
|
-
|
|
261
|
+
deps.fs.mkdirSync(directory, { recursive: true });
|
|
262
|
+
}
|
|
263
|
+
catch { /* legacy mkdir -p is best effort */ }
|
|
264
|
+
for (const folder of [scratchRoot, directory]) {
|
|
265
|
+
try {
|
|
266
|
+
deps.fs.chmodSync(folder, 0o700);
|
|
267
|
+
}
|
|
268
|
+
catch { /* legacy chmod is best effort */ }
|
|
223
269
|
}
|
|
224
|
-
catch { /* legacy mkdir/chmod are best effort */ }
|
|
225
270
|
const observationFile = path.join(directory, `${sid}.bind.${deps.pid}.json`);
|
|
226
271
|
try {
|
|
227
272
|
deps.fs.writeFileSync(observationFile, `${workMeshObservationJson(observation)}\n`);
|
|
@@ -250,8 +295,17 @@ export function runWorkMeshBindTrusted(args, deps) {
|
|
|
250
295
|
catch { /* the shell's jq test fails quiet on invalid status JSON */ }
|
|
251
296
|
}
|
|
252
297
|
}
|
|
253
|
-
if (hasExecutable(deps, "hq")
|
|
254
|
-
|
|
298
|
+
if (!hasExecutable(deps, "hq")) {
|
|
299
|
+
// No reader: the observation would never be consumed.
|
|
300
|
+
try {
|
|
301
|
+
deps.fs.rmSync(observationFile, { force: true });
|
|
302
|
+
}
|
|
303
|
+
catch { /* legacy rm -f is best effort */ }
|
|
304
|
+
stderr += "Work Mesh reconcile skipped: hq CLI not found on PATH.\n";
|
|
305
|
+
return { code: 0, stdout: output.join(""), stderr };
|
|
306
|
+
}
|
|
307
|
+
if (deps.fs.existsSync(observationFile)) {
|
|
308
|
+
deps.spawnHq(["mesh", "context", "reconcile", "--observation-file", observationFile, "--machine"], childEnv, observationFile);
|
|
255
309
|
}
|
|
256
310
|
return { code: 0, stdout: output.join(""), stderr };
|
|
257
311
|
}
|
package/dist/commands/core.js
CHANGED
|
@@ -60,6 +60,7 @@ import { CompanyIndexUserError, renderIndexTarget } from "../lib/index-render/in
|
|
|
60
60
|
import { planScopedRebuild, SESSION_SCOPE_HELP } from "../lib/index-render/session-scope.js";
|
|
61
61
|
import { generateWorkersRegistry } from "../lib/workers-registry/index.js";
|
|
62
62
|
import { scanPackages } from "../lib/scan-packages/index.js";
|
|
63
|
+
import { GENERATE_WORKERS_REGISTRY_SUMMARY, isNativeScaffoldHelpRequest, nativeScaffoldUsage, SCAN_PACKAGES_SUMMARY, } from "../lib/core-utils/native-scaffold-help.js";
|
|
63
64
|
import { detectStaleCorePolicyMirror } from "../lib/core-utils/detect-stale-core-policy-mirror.js";
|
|
64
65
|
import { summarizeHqStatus } from "../lib/core-utils/hq-status-summary.js";
|
|
65
66
|
import { ontologyReadmeDrift } from "../lib/core-utils/ontology-readme-drift.js";
|
|
@@ -114,13 +115,13 @@ export const NATIVE_SCAFFOLD_COMMANDS = [
|
|
|
114
115
|
name: "generate-workers-registry",
|
|
115
116
|
asset: "core/scripts/generate-workers-registry.sh",
|
|
116
117
|
root: "live",
|
|
117
|
-
summary:
|
|
118
|
+
summary: GENERATE_WORKERS_REGISTRY_SUMMARY,
|
|
118
119
|
},
|
|
119
120
|
{
|
|
120
121
|
name: "scan-packages",
|
|
121
122
|
asset: "core/scripts/scan-packages.sh",
|
|
122
123
|
root: "live",
|
|
123
|
-
summary:
|
|
124
|
+
summary: SCAN_PACKAGES_SUMMARY,
|
|
124
125
|
},
|
|
125
126
|
];
|
|
126
127
|
/**
|
|
@@ -574,7 +575,15 @@ export function registerCoreCommands(program) {
|
|
|
574
575
|
.allowExcessArguments()
|
|
575
576
|
.helpOption(false)
|
|
576
577
|
.argument("[args...]", "arguments accepted for shell ABI compatibility")
|
|
577
|
-
.action(() => {
|
|
578
|
+
.action((args = [], _opts, cmd) => {
|
|
579
|
+
// helpOption(false) keeps shell-ABI flags flowing through, so `--help`
|
|
580
|
+
// must be caught here or it runs the command (feedback_83ae2e72).
|
|
581
|
+
// `cmd.args` keeps unknown flags in order, as runCommand below relies on.
|
|
582
|
+
const operands = cmd.args.length > 0 ? cmd.args : args;
|
|
583
|
+
if (isNativeScaffoldHelpRequest(operands)) {
|
|
584
|
+
process.stdout.write(nativeScaffoldUsage(entry.name, entry.summary));
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
578
587
|
const scope = core.opts();
|
|
579
588
|
const hqRoot = resolveLiveRoot({ hqRoot: scope.hqRoot });
|
|
580
589
|
const result = entry.name === "generate-workers-registry"
|
|
@@ -56,6 +56,16 @@ export declare function buildChatAttachmentKey(args: {
|
|
|
56
56
|
name: string;
|
|
57
57
|
now: Date;
|
|
58
58
|
}): string;
|
|
59
|
+
/**
|
|
60
|
+
* SHA-256 of the bytes that will be PUT. hq-pro signs `x-amz-checksum-sha256`
|
|
61
|
+
* only when `checksumSha256` (base64) matches `hq-content-sha256` (hex). Vault
|
|
62
|
+
* buckets use S3 Object Lock, which refuses a PUT without that signed checksum
|
|
63
|
+
* ("Content-MD5 OR x-amz-checksum- HTTP header is required").
|
|
64
|
+
*/
|
|
65
|
+
export declare function attachmentPutIntegrity(bytes: Buffer): {
|
|
66
|
+
checksumSha256: string;
|
|
67
|
+
contentSha256: string;
|
|
68
|
+
};
|
|
59
69
|
/**
|
|
60
70
|
* Check every `--attach` path before anything touches the network: it must
|
|
61
71
|
* exist, be a regular file, and fit the server cap; at most five per message.
|
|
@@ -18,11 +18,13 @@
|
|
|
18
18
|
*
|
|
19
19
|
* Network is injected (`presign`, `put`) so the sequence is unit-testable.
|
|
20
20
|
*/
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
21
22
|
import { readFileSync, statSync } from "node:fs";
|
|
22
23
|
import { Readable } from "node:stream";
|
|
23
24
|
import path from "node:path";
|
|
24
25
|
import { vaultApiFetch } from "../utils/vault-api.js";
|
|
25
26
|
import { contentTypeFor, streamPut } from "./library-add.js";
|
|
27
|
+
import { CONTENT_SHA256_METADATA_KEY } from "./storage-offload.js";
|
|
26
28
|
export const MAX_DM_ATTACHMENTS = 5;
|
|
27
29
|
export const MAX_DM_ATTACHMENT_BYTES = 25 * 1024 * 1024;
|
|
28
30
|
/** Reduce a local file name to one safe path component (mirrors the desktop app). */
|
|
@@ -56,6 +58,19 @@ function formatBytes(n) {
|
|
|
56
58
|
return `${(n / 1024).toFixed(1)} KB`;
|
|
57
59
|
return `${n} B`;
|
|
58
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* SHA-256 of the bytes that will be PUT. hq-pro signs `x-amz-checksum-sha256`
|
|
63
|
+
* only when `checksumSha256` (base64) matches `hq-content-sha256` (hex). Vault
|
|
64
|
+
* buckets use S3 Object Lock, which refuses a PUT without that signed checksum
|
|
65
|
+
* ("Content-MD5 OR x-amz-checksum- HTTP header is required").
|
|
66
|
+
*/
|
|
67
|
+
export function attachmentPutIntegrity(bytes) {
|
|
68
|
+
const contentSha256 = createHash("sha256").update(bytes).digest("hex");
|
|
69
|
+
return {
|
|
70
|
+
contentSha256,
|
|
71
|
+
checksumSha256: Buffer.from(contentSha256, "hex").toString("base64"),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
59
74
|
/**
|
|
60
75
|
* Check every `--attach` path before anything touches the network: it must
|
|
61
76
|
* exist, be a regular file, and fit the server cap; at most five per message.
|
|
@@ -113,13 +128,26 @@ export async function uploadDmAttachments(args) {
|
|
|
113
128
|
const now = args.now ?? new Date();
|
|
114
129
|
if (args.files.length === 0)
|
|
115
130
|
return [];
|
|
116
|
-
const planned = args.files.map((file) =>
|
|
117
|
-
file
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
const planned = args.files.map((file) => {
|
|
132
|
+
const bytes = readFileSync(file.path);
|
|
133
|
+
if (bytes.length > MAX_DM_ATTACHMENT_BYTES) {
|
|
134
|
+
throw new Error(`Attachment too large: ${file.path} grew past the 25 MB limit after it was checked.`);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
file,
|
|
138
|
+
key: buildChatAttachmentKey({ target: args.target, name: file.name, now }),
|
|
139
|
+
integrity: attachmentPutIntegrity(bytes),
|
|
140
|
+
};
|
|
141
|
+
});
|
|
120
142
|
const res = await deps.presign(args.token, {
|
|
121
143
|
company: args.scopeUid,
|
|
122
|
-
keys: planned.map((p) => ({
|
|
144
|
+
keys: planned.map((p) => ({
|
|
145
|
+
key: p.key,
|
|
146
|
+
op: "put",
|
|
147
|
+
contentType: p.file.contentType,
|
|
148
|
+
checksumSha256: p.integrity.checksumSha256,
|
|
149
|
+
metadata: { [CONTENT_SHA256_METADATA_KEY]: p.integrity.contentSha256 },
|
|
150
|
+
})),
|
|
123
151
|
});
|
|
124
152
|
if (!res.ok) {
|
|
125
153
|
const err = (await res.json().catch(() => ({})));
|
|
@@ -69,6 +69,22 @@ export declare function assertAuthMode(value: string | undefined): void;
|
|
|
69
69
|
export declare function assertAuthHeader(value: string | undefined): void;
|
|
70
70
|
/** Single-quote a value for a copy-pasteable shell command. */
|
|
71
71
|
export declare function shellQuote(value: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Resolve the API key for a key-authenticated app, in descending order of how
|
|
74
|
+
* safe the source is: piped stdin, a hidden prompt, then the explicit
|
|
75
|
+
* `--token` flag. Refuses rather than connecting credential-less when there is
|
|
76
|
+
* nobody to ask.
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
* HQ-PRO-5QF: a key pasted from a doc or chat often arrives wrapped across
|
|
80
|
+
* lines or with a tab, and sometimes with smart quotes. hq-pro sends the key
|
|
81
|
+
* 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
|
+
* The message never echoes the key.
|
|
85
|
+
*/
|
|
86
|
+
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
|
+
export declare function normalizePastedApiKey(raw: string): string;
|
|
72
88
|
/** Everything the connect verbs need to name one app to hq-pro. */
|
|
73
89
|
interface ConnectTarget {
|
|
74
90
|
/** Install/OAuth identity fields, exactly as hq-pro expects them. */
|