@indigoai-us/hq-cli 5.68.2 → 5.70.0
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 +30 -0
- package/dist/commands/channels.js +6 -3
- package/dist/commands/dm.d.ts +76 -0
- package/dist/commands/dm.js +317 -3
- package/dist/commands/outposts.d.ts +16 -1
- package/dist/commands/outposts.js +230 -3
- package/dist/main.js +6 -2
- package/dist/utils/cli-telemetry.d.ts +6 -0
- package/dist/utils/cli-telemetry.js +60 -0
- package/dist/utils/cognito-session.d.ts +2 -1
- package/dist/utils/cognito-session.js +5 -2
- package/dist/utils/vault-api.d.ts +1 -0
- package/dist/utils/vault-api.js +3 -2
- package/package.json +1 -1
- package/src/commands/channels.ts +4 -1
- package/src/commands/dm.test.ts +265 -0
- package/src/commands/dm.ts +449 -1
- package/src/commands/outposts-self-deploy.test.ts +243 -0
- package/src/commands/outposts.ts +346 -1
- package/src/main.ts +5 -0
- package/src/utils/cli-telemetry.test.ts +153 -0
- package/src/utils/cli-telemetry.ts +61 -0
- package/src/utils/cognito-session.ts +4 -0
- package/src/utils/vault-api.test.ts +18 -0
- package/src/utils/vault-api.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.70.0]
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **Read DMs from the CLI.** `hq dm` gained a receive side, wired to the notify
|
|
10
|
+
read endpoints that already back the HQ Sync menubar:
|
|
11
|
+
- `hq dm inbox` — list your incoming direct messages, with `--unread`,
|
|
12
|
+
`--limit`, `--json`, and `--mark-read`.
|
|
13
|
+
- `hq dm thread <person>` (alias `read`) — the two-way 1:1 conversation with a
|
|
14
|
+
person by email, personUid, or agentUid, read oldest-first. Marks their
|
|
15
|
+
messages read unless `--no-ack`. Reading by email uses the notify thread
|
|
16
|
+
endpoint's new `withEmail` resolution (requires the matching hq-pro deploy).
|
|
17
|
+
- `hq dm channel <name|#name|id>` (alias `history`) — channel and group-DM
|
|
18
|
+
message history, with `--mark-read` to advance your read cursor.
|
|
19
|
+
- **`hq channels` now shows each group DM's channel id**, so unnamed group DMs
|
|
20
|
+
are addressable for reading with `hq dm channel <id>`.
|
|
21
|
+
|
|
22
|
+
## [5.69.0]
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- **`hq outposts self-deploy` (hidden).** Run on an existing Amazon Linux 2023
|
|
27
|
+
x86_64 EC2 by a logged-in user to make that box behave like an HQ outpost
|
|
28
|
+
locally: it materializes the HQ kernel (`hq rescue`) and installs the
|
|
29
|
+
`outpost-sync.service` (`hq-sync-runner --companies --watch`) so the box
|
|
30
|
+
continuously syncs all your company vaults. It is entirely client-side — it
|
|
31
|
+
makes no calls to hq-pro, registers no outpost row, and is not reported to or
|
|
32
|
+
managed by the control plane (no console entry, no metering). Gated by a
|
|
33
|
+
preflight (OS/arch/systemd/root/login) and a confirmation prompt (`--yes`).
|
|
34
|
+
|
|
5
35
|
## [5.68.1]
|
|
6
36
|
|
|
7
37
|
### Fixed
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="fe48059a-56b5-5f50-8ebf-b5fbbe1aa432")}catch(e){}}();
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { ensureCognitoToken } from "../utils/cognito-session.js";
|
|
5
5
|
import { vaultApiFetch } from "../utils/vault-api.js";
|
|
@@ -18,7 +18,10 @@ export function describeChannel(c) {
|
|
|
18
18
|
const who = names.length > 0
|
|
19
19
|
? names.join(", ")
|
|
20
20
|
: `${c.memberCount ?? "?"}-person group`;
|
|
21
|
-
|
|
21
|
+
// Group DMs are unnamed, so their channel id is the only way to address them
|
|
22
|
+
// for reading (`hq dm channel <id>`). Surface it so it can be copied.
|
|
23
|
+
const readHint = chalk.dim(`— hq dm channel ${c.channelId}`);
|
|
24
|
+
return `${who} ${chalk.dim("(group DM)")} ${readHint}`;
|
|
22
25
|
}
|
|
23
26
|
const slug = c.slug ?? (c.name ? channelSlug(c.name) : "");
|
|
24
27
|
const scopeTag = c.scope ? chalk.dim(`(${c.scope})`) : "";
|
|
@@ -75,4 +78,4 @@ export function registerChannelsCommand(program) {
|
|
|
75
78
|
});
|
|
76
79
|
}
|
|
77
80
|
//# sourceMappingURL=channels.js.map
|
|
78
|
-
//# debugId=
|
|
81
|
+
//# debugId=fe48059a-56b5-5f50-8ebf-b5fbbe1aa432
|
package/dist/commands/dm.d.ts
CHANGED
|
@@ -119,5 +119,81 @@ export declare function buildConnectionActionBody(identifier: string, matched: C
|
|
|
119
119
|
} | {
|
|
120
120
|
withEmail: string;
|
|
121
121
|
};
|
|
122
|
+
/** One incoming DM as returned by GET /v1/notify/inbox. */
|
|
123
|
+
export interface DmInboxEvent {
|
|
124
|
+
eventId: string;
|
|
125
|
+
fromPersonUid?: string;
|
|
126
|
+
fromEmail?: string;
|
|
127
|
+
fromDisplayName?: string;
|
|
128
|
+
body: string;
|
|
129
|
+
createdAt: string;
|
|
130
|
+
details?: string;
|
|
131
|
+
prompt?: string;
|
|
132
|
+
acknowledgedAt?: string;
|
|
133
|
+
}
|
|
134
|
+
/** One message in a 1:1 thread as returned by GET /v1/notify/thread. */
|
|
135
|
+
export interface DmThreadMessage {
|
|
136
|
+
eventId: string;
|
|
137
|
+
fromPersonUid?: string;
|
|
138
|
+
fromEmail?: string;
|
|
139
|
+
fromDisplayName?: string;
|
|
140
|
+
body: string;
|
|
141
|
+
createdAt: string;
|
|
142
|
+
direction: "in" | "out";
|
|
143
|
+
details?: string;
|
|
144
|
+
prompt?: string;
|
|
145
|
+
}
|
|
146
|
+
/** One channel/group message from GET /v1/notify/channels/{id}/messages. */
|
|
147
|
+
export interface ChannelMessageItem {
|
|
148
|
+
eventId?: string;
|
|
149
|
+
messageId?: string;
|
|
150
|
+
fromPersonUid?: string;
|
|
151
|
+
fromEmail?: string;
|
|
152
|
+
fromDisplayName?: string;
|
|
153
|
+
body: string;
|
|
154
|
+
createdAt: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Human label for a message sender — display name, else email, else uid. Pure →
|
|
158
|
+
* unit-testable.
|
|
159
|
+
*/
|
|
160
|
+
export declare function senderLabel(m: {
|
|
161
|
+
fromDisplayName?: string;
|
|
162
|
+
fromEmail?: string;
|
|
163
|
+
fromPersonUid?: string;
|
|
164
|
+
}): string;
|
|
165
|
+
/**
|
|
166
|
+
* Render an ISO timestamp as a compact relative age ("3m ago", "2h ago",
|
|
167
|
+
* "5d ago"), falling back to a YYYY-MM-DD date for anything older than a week or
|
|
168
|
+
* an unparseable input. `nowMs` is injected so the formatting is unit-testable.
|
|
169
|
+
* Pure.
|
|
170
|
+
*/
|
|
171
|
+
export declare function formatRelativeTime(iso: string, nowMs: number): string;
|
|
172
|
+
/** A DM is unread until the recipient acks it. Pure. */
|
|
173
|
+
export declare function isUnread(e: {
|
|
174
|
+
acknowledgedAt?: string;
|
|
175
|
+
}): boolean;
|
|
176
|
+
/** Event ids of the unread messages in a fetched inbox page. Pure. */
|
|
177
|
+
export declare function unreadEventIds(events: DmInboxEvent[]): string[];
|
|
178
|
+
/** Keep only the unread messages. Pure. */
|
|
179
|
+
export declare function filterUnread(events: DmInboxEvent[]): DmInboxEvent[];
|
|
180
|
+
/**
|
|
181
|
+
* Collapse a message body to a single trimmed line for list rendering, capped
|
|
182
|
+
* so one row stays readable. Pure.
|
|
183
|
+
*/
|
|
184
|
+
export declare function firstLine(body: string, max?: number): string;
|
|
185
|
+
/**
|
|
186
|
+
* Turn a person identifier into the query the thread endpoint expects. An email
|
|
187
|
+
* rides `withEmail` (server resolves it); a prs_/agt_ uid rides `withPersonUid`.
|
|
188
|
+
* A bare name is rejected — resolve it first with `hq people resolve`. Pure →
|
|
189
|
+
* unit-testable. Throws with a user-facing message on an invalid identifier.
|
|
190
|
+
*/
|
|
191
|
+
export declare function buildThreadQuery(identifier: string): Record<string, string>;
|
|
192
|
+
/** Render one inbox row (marker · age · sender · first line of body). */
|
|
193
|
+
export declare function formatInboxEvent(e: DmInboxEvent, nowMs: number): string;
|
|
194
|
+
/** Render one 1:1 thread line, tagged by direction. */
|
|
195
|
+
export declare function formatThreadMessage(m: DmThreadMessage, nowMs: number): string;
|
|
196
|
+
/** Render one channel/group message line. */
|
|
197
|
+
export declare function formatChannelMessage(m: ChannelMessageItem, nowMs: number): string;
|
|
122
198
|
export declare function registerDmCommand(program: Command): void;
|
|
123
199
|
//# sourceMappingURL=dm.d.ts.map
|
package/dist/commands/dm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8ba6c13e-f0d4-58c7-a62e-eede4fb7873f")}catch(e){}}();
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import { ensureCognitoToken } from "../utils/cognito-session.js";
|
|
@@ -497,10 +497,294 @@ async function runDmRequests() {
|
|
|
497
497
|
process.exit(1);
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
|
+
/**
|
|
501
|
+
* Human label for a message sender — display name, else email, else uid. Pure →
|
|
502
|
+
* unit-testable.
|
|
503
|
+
*/
|
|
504
|
+
export function senderLabel(m) {
|
|
505
|
+
return (m.fromDisplayName?.trim() ||
|
|
506
|
+
m.fromEmail?.trim() ||
|
|
507
|
+
m.fromPersonUid?.trim() ||
|
|
508
|
+
"unknown");
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Render an ISO timestamp as a compact relative age ("3m ago", "2h ago",
|
|
512
|
+
* "5d ago"), falling back to a YYYY-MM-DD date for anything older than a week or
|
|
513
|
+
* an unparseable input. `nowMs` is injected so the formatting is unit-testable.
|
|
514
|
+
* Pure.
|
|
515
|
+
*/
|
|
516
|
+
export function formatRelativeTime(iso, nowMs) {
|
|
517
|
+
const t = new Date(iso).getTime();
|
|
518
|
+
if (isNaN(t))
|
|
519
|
+
return iso;
|
|
520
|
+
const diff = nowMs - t;
|
|
521
|
+
if (diff < 60_000)
|
|
522
|
+
return "just now";
|
|
523
|
+
const mins = Math.floor(diff / 60_000);
|
|
524
|
+
if (mins < 60)
|
|
525
|
+
return `${mins}m ago`;
|
|
526
|
+
const hours = Math.floor(mins / 60);
|
|
527
|
+
if (hours < 24)
|
|
528
|
+
return `${hours}h ago`;
|
|
529
|
+
const days = Math.floor(hours / 24);
|
|
530
|
+
if (days < 7)
|
|
531
|
+
return `${days}d ago`;
|
|
532
|
+
return new Date(t).toISOString().slice(0, 10);
|
|
533
|
+
}
|
|
534
|
+
/** A DM is unread until the recipient acks it. Pure. */
|
|
535
|
+
export function isUnread(e) {
|
|
536
|
+
return !e.acknowledgedAt;
|
|
537
|
+
}
|
|
538
|
+
/** Event ids of the unread messages in a fetched inbox page. Pure. */
|
|
539
|
+
export function unreadEventIds(events) {
|
|
540
|
+
return events
|
|
541
|
+
.filter(isUnread)
|
|
542
|
+
.map((e) => e.eventId)
|
|
543
|
+
.filter((id) => typeof id === "string" && id.length > 0);
|
|
544
|
+
}
|
|
545
|
+
/** Keep only the unread messages. Pure. */
|
|
546
|
+
export function filterUnread(events) {
|
|
547
|
+
return events.filter(isUnread);
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Collapse a message body to a single trimmed line for list rendering, capped
|
|
551
|
+
* so one row stays readable. Pure.
|
|
552
|
+
*/
|
|
553
|
+
export function firstLine(body, max = 240) {
|
|
554
|
+
const oneLine = (body ?? "").replace(/\s+/g, " ").trim();
|
|
555
|
+
if (oneLine.length <= max)
|
|
556
|
+
return oneLine;
|
|
557
|
+
return oneLine.slice(0, max - 1) + "…";
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Turn a person identifier into the query the thread endpoint expects. An email
|
|
561
|
+
* rides `withEmail` (server resolves it); a prs_/agt_ uid rides `withPersonUid`.
|
|
562
|
+
* A bare name is rejected — resolve it first with `hq people resolve`. Pure →
|
|
563
|
+
* unit-testable. Throws with a user-facing message on an invalid identifier.
|
|
564
|
+
*/
|
|
565
|
+
export function buildThreadQuery(identifier) {
|
|
566
|
+
const rcpt = detectRecipient(identifier);
|
|
567
|
+
if (!rcpt) {
|
|
568
|
+
throw new Error(`Invalid person '${identifier}': pass an email or a personUid/agentUid (prs_… / agt_…). Resolve a name first with \`hq people resolve\`.`);
|
|
569
|
+
}
|
|
570
|
+
if (rcpt.toEmail)
|
|
571
|
+
return { withEmail: rcpt.toEmail };
|
|
572
|
+
return { withPersonUid: rcpt.toPersonUid };
|
|
573
|
+
}
|
|
574
|
+
/** Render one inbox row (marker · age · sender · first line of body). */
|
|
575
|
+
export function formatInboxEvent(e, nowMs) {
|
|
576
|
+
const marker = isUnread(e) ? chalk.cyan("●") : " ";
|
|
577
|
+
const when = chalk.dim(formatRelativeTime(e.createdAt, nowMs));
|
|
578
|
+
const who = chalk.bold(senderLabel(e));
|
|
579
|
+
const email = e.fromEmail && e.fromDisplayName ? chalk.dim(` <${e.fromEmail}>`) : "";
|
|
580
|
+
return `${marker} ${when} ${who}${email}\n ${firstLine(e.body)}`;
|
|
581
|
+
}
|
|
582
|
+
/** Render one 1:1 thread line, tagged by direction. */
|
|
583
|
+
export function formatThreadMessage(m, nowMs) {
|
|
584
|
+
const arrow = m.direction === "out" ? chalk.dim("→") : chalk.cyan("←");
|
|
585
|
+
const who = m.direction === "out" ? "you" : senderLabel(m);
|
|
586
|
+
const when = chalk.dim(formatRelativeTime(m.createdAt, nowMs));
|
|
587
|
+
return `${arrow} ${chalk.bold(who)} ${when}\n ${firstLine(m.body)}`;
|
|
588
|
+
}
|
|
589
|
+
/** Render one channel/group message line. */
|
|
590
|
+
export function formatChannelMessage(m, nowMs) {
|
|
591
|
+
const who = chalk.bold(senderLabel(m));
|
|
592
|
+
const when = chalk.dim(formatRelativeTime(m.createdAt, nowMs));
|
|
593
|
+
return `${who} ${when}\n ${firstLine(m.body)}`;
|
|
594
|
+
}
|
|
595
|
+
/** POST /v1/notify/inbox/ack — idempotently mark messages read. */
|
|
596
|
+
async function ackEvents(token, eventIds) {
|
|
597
|
+
if (eventIds.length === 0)
|
|
598
|
+
return;
|
|
599
|
+
const res = await vaultApiFetch({
|
|
600
|
+
token,
|
|
601
|
+
path: "/v1/notify/inbox/ack",
|
|
602
|
+
method: "POST",
|
|
603
|
+
body: { eventIds },
|
|
604
|
+
});
|
|
605
|
+
if (!res.ok) {
|
|
606
|
+
const err = (await res.json().catch(() => ({})));
|
|
607
|
+
throw new Error(friendlyDmError(res.status, err.code, err.error ?? err.message ?? res.statusText));
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
async function runDmInbox(opts) {
|
|
611
|
+
try {
|
|
612
|
+
const token = await ensureCognitoToken();
|
|
613
|
+
const query = {};
|
|
614
|
+
if (opts.limit)
|
|
615
|
+
query.limit = opts.limit;
|
|
616
|
+
const res = await vaultApiFetch({ token, path: "/v1/notify/inbox", query });
|
|
617
|
+
if (!res.ok) {
|
|
618
|
+
const err = (await res.json().catch(() => ({})));
|
|
619
|
+
console.error(chalk.red(friendlyDmError(res.status, err.code, err.error ?? err.message ?? res.statusText)));
|
|
620
|
+
process.exit(1);
|
|
621
|
+
}
|
|
622
|
+
const data = (await res.json());
|
|
623
|
+
const all = data.events ?? [];
|
|
624
|
+
const shown = opts.unread ? filterUnread(all) : all;
|
|
625
|
+
if (opts.json) {
|
|
626
|
+
console.log(JSON.stringify(shown, null, 2));
|
|
627
|
+
}
|
|
628
|
+
else if (shown.length === 0) {
|
|
629
|
+
console.log(chalk.dim(opts.unread ? "No unread messages." : "No messages yet."));
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
const unreadCount = filterUnread(all).length;
|
|
633
|
+
const suffix = unreadCount > 0 ? ` (${unreadCount} unread)` : "";
|
|
634
|
+
console.log(chalk.green(`${shown.length} message${shown.length === 1 ? "" : "s"}${suffix}:`));
|
|
635
|
+
const now = Date.now();
|
|
636
|
+
for (const e of shown)
|
|
637
|
+
console.log(`\n${formatInboxEvent(e, now)}`);
|
|
638
|
+
if (data.nextCursor) {
|
|
639
|
+
console.log(chalk.dim("\nMore messages available — raise --limit to see them."));
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
// Ack every unread message on the fetched page (not just the filtered view).
|
|
643
|
+
if (opts.markRead) {
|
|
644
|
+
const ids = unreadEventIds(all);
|
|
645
|
+
await ackEvents(token, ids);
|
|
646
|
+
if (!opts.json && ids.length > 0) {
|
|
647
|
+
console.log(chalk.dim(`\nMarked ${ids.length} read.`));
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
catch (err) {
|
|
652
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
653
|
+
process.exit(1);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
async function runDmThread(identifier, opts) {
|
|
657
|
+
try {
|
|
658
|
+
const query = buildThreadQuery(identifier);
|
|
659
|
+
if (opts.limit)
|
|
660
|
+
query.limit = opts.limit;
|
|
661
|
+
const token = await ensureCognitoToken();
|
|
662
|
+
const res = await vaultApiFetch({
|
|
663
|
+
token,
|
|
664
|
+
path: "/v1/notify/thread",
|
|
665
|
+
query,
|
|
666
|
+
});
|
|
667
|
+
if (!res.ok) {
|
|
668
|
+
const err = (await res.json().catch(() => ({})));
|
|
669
|
+
console.error(chalk.red(friendlyDmError(res.status, err.code, err.error ?? err.message ?? res.statusText)));
|
|
670
|
+
process.exit(1);
|
|
671
|
+
}
|
|
672
|
+
const data = (await res.json());
|
|
673
|
+
const messages = data.messages ?? [];
|
|
674
|
+
// The server returns newest-first; read a conversation oldest-first.
|
|
675
|
+
const ordered = [...messages].reverse();
|
|
676
|
+
if (opts.json) {
|
|
677
|
+
console.log(JSON.stringify(ordered, null, 2));
|
|
678
|
+
}
|
|
679
|
+
else if (ordered.length === 0) {
|
|
680
|
+
console.log(chalk.dim(`No messages with ${identifier} yet.`));
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
console.log(chalk.green(`${ordered.length} message${ordered.length === 1 ? "" : "s"} with ${identifier}:`));
|
|
684
|
+
const now = Date.now();
|
|
685
|
+
for (const m of ordered)
|
|
686
|
+
console.log(`\n${formatThreadMessage(m, now)}`);
|
|
687
|
+
}
|
|
688
|
+
// Mark the incoming messages read unless the caller opted out. Best-effort:
|
|
689
|
+
// a read is a side effect, not the point of the command, so an ack failure
|
|
690
|
+
// is surfaced but does not fail the read.
|
|
691
|
+
if (opts.ack !== false) {
|
|
692
|
+
const inIds = messages
|
|
693
|
+
.filter((m) => m.direction === "in")
|
|
694
|
+
.map((m) => m.eventId)
|
|
695
|
+
.filter((id) => typeof id === "string" && id.length > 0);
|
|
696
|
+
try {
|
|
697
|
+
await ackEvents(token, inIds);
|
|
698
|
+
}
|
|
699
|
+
catch (ackErr) {
|
|
700
|
+
console.error(chalk.dim(`(could not mark read: ${ackErr instanceof Error ? ackErr.message : String(ackErr)})`));
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
catch (err) {
|
|
705
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
706
|
+
process.exit(1);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Resolve a `hq dm channel <target>` argument to a channelId. Accepts a channel
|
|
711
|
+
* name (bare or `#name`) resolved against the caller's channels, or a raw
|
|
712
|
+
* channelId (the only way to address an unnamed group DM — copy it from
|
|
713
|
+
* `hq channels`). Throws a user-facing message when nothing matches or a name is
|
|
714
|
+
* ambiguous.
|
|
715
|
+
*/
|
|
716
|
+
async function resolveChannelId(token, target) {
|
|
717
|
+
const raw = target.trim().replace(/^#/, "");
|
|
718
|
+
if (!raw)
|
|
719
|
+
throw new Error("A channel name or id is required.");
|
|
720
|
+
const channels = await fetchChannels(token);
|
|
721
|
+
const named = matchChannelsByName(channels, raw);
|
|
722
|
+
if (named.length === 1)
|
|
723
|
+
return named[0].channelId;
|
|
724
|
+
if (named.length > 1) {
|
|
725
|
+
throw new Error(`'${raw}' matches ${named.length} channels — pass the channel id instead (see \`hq channels\`).`);
|
|
726
|
+
}
|
|
727
|
+
const byId = channels.find((c) => c.channelId === raw);
|
|
728
|
+
if (byId)
|
|
729
|
+
return byId.channelId;
|
|
730
|
+
throw new Error(`No channel named or with id '${raw}' — run \`hq channels\` to see yours.`);
|
|
731
|
+
}
|
|
732
|
+
async function runDmChannel(target, opts) {
|
|
733
|
+
try {
|
|
734
|
+
const token = await ensureCognitoToken();
|
|
735
|
+
const channelId = await resolveChannelId(token, target);
|
|
736
|
+
const query = {};
|
|
737
|
+
if (opts.limit)
|
|
738
|
+
query.limit = opts.limit;
|
|
739
|
+
const res = await vaultApiFetch({
|
|
740
|
+
token,
|
|
741
|
+
path: `/v1/notify/channels/${encodeURIComponent(channelId)}/messages`,
|
|
742
|
+
query,
|
|
743
|
+
});
|
|
744
|
+
if (!res.ok) {
|
|
745
|
+
const err = (await res.json().catch(() => ({})));
|
|
746
|
+
console.error(chalk.red(friendlyDmError(res.status, err.code, err.error ?? err.message ?? res.statusText)));
|
|
747
|
+
process.exit(1);
|
|
748
|
+
}
|
|
749
|
+
const data = (await res.json());
|
|
750
|
+
const messages = data.messages ?? [];
|
|
751
|
+
const ordered = [...messages].reverse(); // oldest-first for reading
|
|
752
|
+
if (opts.json) {
|
|
753
|
+
console.log(JSON.stringify(ordered, null, 2));
|
|
754
|
+
}
|
|
755
|
+
else if (ordered.length === 0) {
|
|
756
|
+
console.log(chalk.dim("No messages in this channel yet."));
|
|
757
|
+
}
|
|
758
|
+
else {
|
|
759
|
+
console.log(chalk.green(`${ordered.length} message${ordered.length === 1 ? "" : "s"}:`));
|
|
760
|
+
const now = Date.now();
|
|
761
|
+
for (const m of ordered)
|
|
762
|
+
console.log(`\n${formatChannelMessage(m, now)}`);
|
|
763
|
+
}
|
|
764
|
+
if (opts.markRead) {
|
|
765
|
+
// messages are newest-first from the server; advance the read cursor to
|
|
766
|
+
// the newest one we saw.
|
|
767
|
+
const newest = messages[0]?.createdAt;
|
|
768
|
+
const readRes = await vaultApiFetch({
|
|
769
|
+
token,
|
|
770
|
+
path: `/v1/notify/channels/${encodeURIComponent(channelId)}/read`,
|
|
771
|
+
method: "POST",
|
|
772
|
+
body: newest ? { lastReadAt: newest } : {},
|
|
773
|
+
});
|
|
774
|
+
if (!opts.json && readRes.ok) {
|
|
775
|
+
console.log(chalk.dim("\nMarked read."));
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
catch (err) {
|
|
780
|
+
console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
|
|
781
|
+
process.exit(1);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
500
784
|
export function registerDmCommand(program) {
|
|
501
785
|
const dm = program
|
|
502
786
|
.command("dm")
|
|
503
|
-
.description("Send
|
|
787
|
+
.description("Send and read direct messages, and manage connection requests.");
|
|
504
788
|
dm
|
|
505
789
|
.command("send [recipient] [message]", { isDefault: true, hidden: true })
|
|
506
790
|
.description('Send a direct message. RECIPIENT can be a person (email, personUid, or agentUid), a GROUP DM (comma-separated: "a@x.com,b@y.com"), or one of your DM CHANNELS by name — bare (hq dm vyg-dev "hi"), hash form (hq dm "#vyg-dev" "hi"), or via --channel (hq dm --channel vyg-dev "hi"). A person receives a DM as an HQ Sync notification; an agent receives it in its durable box inbox. If you aren\'t connected yet, it sends a connection request that holds your message. See your channels with `hq channels`.')
|
|
@@ -514,6 +798,36 @@ export function registerDmCommand(program) {
|
|
|
514
798
|
.action(async (recipient, message, opts) => {
|
|
515
799
|
await runDmSend(recipient, message, opts);
|
|
516
800
|
});
|
|
801
|
+
dm
|
|
802
|
+
.command("inbox")
|
|
803
|
+
.description("List your recent incoming direct messages.")
|
|
804
|
+
.option("--limit <n>", "Max messages to fetch (server-capped)")
|
|
805
|
+
.option("--unread", "Show only unread messages")
|
|
806
|
+
.option("--mark-read", "Mark the fetched messages as read after listing")
|
|
807
|
+
.option("--json", "Output raw JSON instead of a list")
|
|
808
|
+
.action(async (opts) => {
|
|
809
|
+
await runDmInbox(opts);
|
|
810
|
+
});
|
|
811
|
+
dm
|
|
812
|
+
.command("thread <person>")
|
|
813
|
+
.alias("read")
|
|
814
|
+
.description("Show your two-way conversation with a person (email, personUid, or agentUid). Reads oldest-first and marks their messages read unless --no-ack.")
|
|
815
|
+
.option("--limit <n>", "Max messages to fetch (server-capped)")
|
|
816
|
+
.option("--no-ack", "Do not mark the incoming messages as read")
|
|
817
|
+
.option("--json", "Output raw JSON instead of a transcript")
|
|
818
|
+
.action(async (person, opts) => {
|
|
819
|
+
await runDmThread(person, opts);
|
|
820
|
+
});
|
|
821
|
+
dm
|
|
822
|
+
.command("channel <target>")
|
|
823
|
+
.alias("history")
|
|
824
|
+
.description("Show recent messages in a DM channel or group DM — by name, #name, or a channel id from `hq channels`.")
|
|
825
|
+
.option("--limit <n>", "Max messages to fetch (server-capped)")
|
|
826
|
+
.option("--mark-read", "Advance your read marker to the newest message")
|
|
827
|
+
.option("--json", "Output raw JSON instead of a transcript")
|
|
828
|
+
.action(async (target, opts) => {
|
|
829
|
+
await runDmChannel(target, opts);
|
|
830
|
+
});
|
|
517
831
|
dm
|
|
518
832
|
.command("requests")
|
|
519
833
|
.description("List your pending incoming connection requests.")
|
|
@@ -540,4 +854,4 @@ export function registerDmCommand(program) {
|
|
|
540
854
|
});
|
|
541
855
|
}
|
|
542
856
|
//# sourceMappingURL=dm.js.map
|
|
543
|
-
//# debugId=
|
|
857
|
+
//# debugId=8ba6c13e-f0d4-58c7-a62e-eede4fb7873f
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* and status routes that exist. Renaming an Outpost is not a backend capability.
|
|
22
22
|
*/
|
|
23
23
|
import { Command } from "commander";
|
|
24
|
+
import { spawnSync } from "node:child_process";
|
|
24
25
|
import { type BillingErrorPayload } from "../utils/billing-gate.js";
|
|
25
26
|
/** A non-2xx from the `/outpost/*` control plane. Carries status + `step`. */
|
|
26
27
|
export declare class OutpostHttpError extends Error {
|
|
@@ -137,5 +138,19 @@ export declare function execViaSsh(access: OutpostSshAccess, command: string): {
|
|
|
137
138
|
exitCode: number | null;
|
|
138
139
|
error?: string;
|
|
139
140
|
};
|
|
140
|
-
|
|
141
|
+
/** The small local-environment surface used by `outposts self-deploy`. */
|
|
142
|
+
export interface SelfDeployDependencies {
|
|
143
|
+
spawnSync: (command: string, args: string[], options?: Parameters<typeof spawnSync>[2]) => ReturnType<typeof spawnSync>;
|
|
144
|
+
readTextFile: (file: string) => string;
|
|
145
|
+
loadCachedTokens: () => {
|
|
146
|
+
refreshToken?: string;
|
|
147
|
+
idToken?: string;
|
|
148
|
+
} | undefined;
|
|
149
|
+
getUid: () => number | undefined;
|
|
150
|
+
isStdinTty: () => boolean;
|
|
151
|
+
confirm: () => Promise<boolean>;
|
|
152
|
+
defaultHqRoot: () => string;
|
|
153
|
+
invokingUser: () => string;
|
|
154
|
+
}
|
|
155
|
+
export declare function registerOutpostsCommand(program: Command, selfDeployOverrides?: Partial<SelfDeployDependencies>): void;
|
|
141
156
|
//# sourceMappingURL=outposts.d.ts.map
|