@indigoai-us/hq-cli 5.115.5 → 5.116.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/command-catalog.generated.d.ts +162 -2
  3. package/dist/command-catalog.generated.js +205 -2
  4. package/dist/command-registration-plan.d.ts +6 -0
  5. package/dist/command-registration-plan.js +1 -0
  6. package/dist/commands/agent-enroll.d.ts +105 -0
  7. package/dist/commands/agent-enroll.js +273 -0
  8. package/dist/commands/agent-kit.d.ts +53 -0
  9. package/dist/commands/agent-kit.js +260 -0
  10. package/dist/commands/agent-mcp.d.ts +22 -0
  11. package/dist/commands/agent-mcp.js +104 -0
  12. package/dist/commands/agent-probe.d.ts +71 -0
  13. package/dist/commands/agent-probe.js +294 -0
  14. package/dist/commands/agent.d.ts +12 -0
  15. package/dist/commands/agent.js +23 -0
  16. package/dist/commands/agents.d.ts +27 -0
  17. package/dist/commands/agents.js +280 -6
  18. package/dist/commands/secrets.js +17 -5
  19. package/dist/lib/agent-kit/creds.d.ts +60 -0
  20. package/dist/lib/agent-kit/creds.js +123 -0
  21. package/dist/lib/agent-kit/kit-config.d.ts +29 -0
  22. package/dist/lib/agent-kit/kit-config.js +54 -0
  23. package/dist/lib/agent-kit/log.d.ts +17 -0
  24. package/dist/lib/agent-kit/log.js +46 -0
  25. package/dist/lib/agent-kit/mcp/jsonrpc.d.ts +84 -0
  26. package/dist/lib/agent-kit/mcp/jsonrpc.js +164 -0
  27. package/dist/lib/agent-kit/mcp/tools.d.ts +45 -0
  28. package/dist/lib/agent-kit/mcp/tools.js +280 -0
  29. package/dist/lib/agent-kit/paths.d.ts +42 -0
  30. package/dist/lib/agent-kit/paths.js +56 -0
  31. package/dist/lib/agent-kit/run/heartbeat.d.ts +52 -0
  32. package/dist/lib/agent-kit/run/heartbeat.js +97 -0
  33. package/dist/lib/agent-kit/run/inbox.d.ts +59 -0
  34. package/dist/lib/agent-kit/run/inbox.js +152 -0
  35. package/dist/lib/agent-kit/run/mesh-listener.d.ts +58 -0
  36. package/dist/lib/agent-kit/run/mesh-listener.js +193 -0
  37. package/dist/lib/agent-kit/run/sync.d.ts +33 -0
  38. package/dist/lib/agent-kit/run/sync.js +58 -0
  39. package/dist/lib/agent-kit/services.d.ts +21 -0
  40. package/dist/lib/agent-kit/services.js +46 -0
  41. package/dist/lib/agent-kit/skills.d.ts +18 -0
  42. package/dist/lib/agent-kit/skills.js +149 -0
  43. package/dist/lib/doctor/checks/sync-health.d.ts +19 -0
  44. package/dist/lib/doctor/checks/sync-health.js +55 -2
  45. package/dist/lib/doctor/fix/apply.d.ts +43 -6
  46. package/dist/lib/doctor/fix/apply.js +116 -18
  47. package/dist/lib/doctor/fix/remediation.d.ts +8 -3
  48. package/dist/lib/doctor/fix/remediation.js +21 -2
  49. package/dist/lib/scan-packages/index.js +158 -1
  50. package/dist/lib/service-manager/index.d.ts +43 -0
  51. package/dist/lib/service-manager/index.js +114 -0
  52. package/dist/lib/service-manager/launchd.d.ts +23 -0
  53. package/dist/lib/service-manager/launchd.js +81 -0
  54. package/dist/lib/service-manager/systemd.d.ts +19 -0
  55. package/dist/lib/service-manager/systemd.js +72 -0
  56. package/dist/lib/service-manager/types.d.ts +32 -0
  57. package/dist/lib/service-manager/types.js +26 -0
  58. package/dist/utils/self-update.js +2 -30
  59. package/dist/utils/update-command-supervisor.cjs +194 -0
  60. package/dist/utils/version-gate.d.ts +18 -0
  61. package/dist/utils/version-gate.js +126 -7
  62. package/package.json +2 -2
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Kit service: work-mesh doorbell listener.
3
+ *
4
+ * Policy hq-work-mesh-source-of-truth: the work mesh (REST) is the source of
5
+ * truth; MQTT carries IDS-ONLY doorbells on the agent's personal topics
6
+ * `hq/{agt_*}/{dm,work,sessions,notifications}`. This listener is the cache
7
+ * writer: on any doorbell it refetches through the REST API into
8
+ * ~/.hq/work-mesh/cache (warmMeshConversationCache) — message bodies are
9
+ * never taken from MQTT. A periodic refresh covers missed doorbells.
10
+ *
11
+ * Credentials come from the same contract-3 vend the mesh daemon uses
12
+ * (POST /v1/realtime/credentials); the WSS URL is SigV4-presigned. The
13
+ * connection is rebuilt before the vended credentials expire. `component-mesh`
14
+ * is stamped ok while subscribed and refreshing, error otherwise.
15
+ */
16
+ import mqtt from "mqtt";
17
+ import { warmMeshConversationCache } from "../../mesh/api.js";
18
+ import { createContract3Fetcher, MQTT_KEEPALIVE_SECONDS, renewalDelayMs, } from "../../mesh/live/daemon/credentials.js";
19
+ import { presignIotWssUrl } from "../../mesh/live/daemon/presign.js";
20
+ import { writeComponentStatus } from "../creds.js";
21
+ export const DOORBELL_KINDS = ["dm", "work", "sessions", "notifications"];
22
+ export const DOORBELL_DEBOUNCE_MS = 2_000;
23
+ export const RECONNECT_BASE_MS = 1_000;
24
+ export const RECONNECT_MAX_MS = 60_000;
25
+ export function doorbellTopics(actorUid) {
26
+ return DOORBELL_KINDS.map((k) => `hq/${actorUid}/${k}`);
27
+ }
28
+ function backoff(attempt, random) {
29
+ const cap = Math.min(RECONNECT_MAX_MS, RECONNECT_BASE_MS * 2 ** attempt);
30
+ return Math.max(RECONNECT_BASE_MS, Math.floor(random() * cap));
31
+ }
32
+ export async function startMeshListener(deps) {
33
+ const now = deps.now ?? (() => new Date());
34
+ const random = deps.random ?? Math.random;
35
+ const setT = deps.setTimeout ?? ((fn, ms) => setTimeout(fn, ms));
36
+ const clearT = deps.clearTimeout ?? ((h) => clearTimeout(h));
37
+ const connect = deps.connect ?? ((url, opts) => mqtt.connect(url, opts));
38
+ const refetch = deps.refetch ?? ((token, uid) => warmMeshConversationCache(token, uid));
39
+ const fetchCredentials = deps.fetchCredentials ??
40
+ (async () => {
41
+ const token = await deps.getToken();
42
+ return createContract3Fetcher({ token, baseUrl: deps.apiBaseUrl })();
43
+ });
44
+ let state = "idle";
45
+ let client = null;
46
+ let stopped = false;
47
+ let attempt = 0;
48
+ let debounce = null;
49
+ let renewal = null;
50
+ let periodic = null;
51
+ let refetching = null;
52
+ let pendingReason = null;
53
+ const doRefetch = async (reason) => {
54
+ if (refetching) {
55
+ pendingReason = reason;
56
+ return refetching;
57
+ }
58
+ refetching = (async () => {
59
+ try {
60
+ const token = await deps.getToken();
61
+ await refetch(token, deps.agentUid);
62
+ writeComponentStatus(deps.paths, "mesh", state === "subscribed" ? "ok" : "error");
63
+ deps.log("info", `cache refetched (${reason})`);
64
+ }
65
+ catch (err) {
66
+ writeComponentStatus(deps.paths, "mesh", "error");
67
+ deps.log("error", `refetch failed (${reason}): ${err instanceof Error ? err.message : String(err)}`);
68
+ }
69
+ finally {
70
+ refetching = null;
71
+ }
72
+ if (pendingReason) {
73
+ const next = pendingReason;
74
+ pendingReason = null;
75
+ await doRefetch(next);
76
+ }
77
+ })();
78
+ return refetching;
79
+ };
80
+ const ring = (topic) => {
81
+ if (debounce)
82
+ clearT(debounce);
83
+ debounce = setT(() => {
84
+ debounce = null;
85
+ void doRefetch(`doorbell ${topic}`);
86
+ }, DOORBELL_DEBOUNCE_MS);
87
+ };
88
+ const schedulePeriodic = () => {
89
+ if (periodic)
90
+ clearT(periodic);
91
+ periodic = setT(() => {
92
+ periodic = null;
93
+ void doRefetch("periodic").then(schedulePeriodic);
94
+ }, deps.refreshMs);
95
+ };
96
+ const scheduleReconnect = () => {
97
+ if (stopped)
98
+ return;
99
+ const delay = backoff(attempt, random);
100
+ attempt += 1;
101
+ deps.log("warn", `mqtt reconnect in ${delay}ms (attempt ${attempt})`);
102
+ setT(() => void connectOnce(), delay);
103
+ };
104
+ const connectOnce = async () => {
105
+ if (stopped)
106
+ return;
107
+ state = "connecting";
108
+ let bundle;
109
+ try {
110
+ bundle = await fetchCredentials();
111
+ if (bundle.actorUid !== deps.agentUid) {
112
+ throw new Error(`realtime vend is for ${bundle.actorUid}, expected ${deps.agentUid}`);
113
+ }
114
+ }
115
+ catch (err) {
116
+ writeComponentStatus(deps.paths, "mesh", "error");
117
+ deps.log("error", `credential vend failed: ${err instanceof Error ? err.message : String(err)}`);
118
+ scheduleReconnect();
119
+ return;
120
+ }
121
+ const url = presignIotWssUrl(bundle.credentials, bundle.iotEndpoint, bundle.region, now());
122
+ const c = connect(url, {
123
+ clientId: bundle.clientId,
124
+ keepalive: MQTT_KEEPALIVE_SECONDS,
125
+ clean: true,
126
+ reconnectPeriod: 0,
127
+ protocolVersion: 4,
128
+ });
129
+ client = c;
130
+ let settled = false;
131
+ c.on("connect", () => {
132
+ c.subscribe(doorbellTopics(bundle.actorUid), { qos: 1 }, (err) => {
133
+ if (err) {
134
+ deps.log("error", `subscribe failed: ${err.message}`);
135
+ c.end(true);
136
+ return;
137
+ }
138
+ settled = true;
139
+ attempt = 0;
140
+ state = "subscribed";
141
+ writeComponentStatus(deps.paths, "mesh", "ok");
142
+ deps.log("info", `subscribed to ${doorbellTopics(bundle.actorUid).length} doorbell topics`);
143
+ void doRefetch("connect");
144
+ if (renewal)
145
+ clearT(renewal);
146
+ renewal = setT(() => {
147
+ deps.log("info", "renewing realtime credentials");
148
+ c.end(true);
149
+ }, renewalDelayMs(now().getTime(), bundle.expiresAt));
150
+ });
151
+ });
152
+ c.on("message", (topic) => {
153
+ // Ids-only doorbell: the payload is never parsed for content.
154
+ ring(topic);
155
+ });
156
+ c.on("error", (err) => {
157
+ deps.log("warn", `mqtt error: ${err.message}`);
158
+ });
159
+ c.on("close", () => {
160
+ if (client !== c)
161
+ return;
162
+ client = null;
163
+ const wasSubscribed = state === "subscribed";
164
+ state = stopped ? "closed" : "idle";
165
+ writeComponentStatus(deps.paths, "mesh", "error");
166
+ if (!settled || !wasSubscribed)
167
+ deps.log("warn", "mqtt closed before subscribe settled");
168
+ scheduleReconnect();
169
+ });
170
+ };
171
+ schedulePeriodic();
172
+ await connectOnce();
173
+ return {
174
+ stop: async () => {
175
+ stopped = true;
176
+ state = "closed";
177
+ if (debounce)
178
+ clearT(debounce);
179
+ if (renewal)
180
+ clearT(renewal);
181
+ if (periodic)
182
+ clearT(periodic);
183
+ const c = client;
184
+ client = null;
185
+ if (c)
186
+ await new Promise((r) => c.end(true, undefined, () => r()));
187
+ },
188
+ refetchNow: doRefetch,
189
+ ring,
190
+ state: () => state,
191
+ };
192
+ }
193
+ //# sourceMappingURL=mesh-listener.js.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Kit service: company vault sync loop.
3
+ *
4
+ * Mirrors the hosted box's hq-agent-sync.service, which runs hq-cloud's
5
+ * `hq-sync-runner --companies --direction both --on-conflict keep` on a
6
+ * loop and writes `component-sync`. Here the equivalent is the CLI's own
7
+ * `hq sync pull --all --on-conflict keep --hq-root <kit hqRoot>`, run as a
8
+ * child of the same node + hq binary this service was launched with, so the
9
+ * machine identity, creds path and version are exactly the service's own.
10
+ *
11
+ * Honest health: exit 0 = ok, anything else = error (the heartbeat turns a
12
+ * stale stamp into error on its own).
13
+ */
14
+ import type { KitLogger } from "../log.js";
15
+ import type { AgentKitPaths } from "../paths.js";
16
+ export interface SyncRunDeps {
17
+ paths: AgentKitPaths;
18
+ hqRoot: string;
19
+ intervalMs: number;
20
+ log: KitLogger;
21
+ nodeBinary?: string;
22
+ hqBinary?: string;
23
+ /** Injected child runner (tests). Resolves with the exit code. */
24
+ runPull?: (args: string[]) => Promise<number>;
25
+ sleep?: (ms: number) => Promise<void>;
26
+ /** Stop after this many passes (tests); default runs forever. */
27
+ maxPasses?: number;
28
+ }
29
+ export declare function syncPullArgs(hqRoot: string): string[];
30
+ export declare function defaultRunPull(nodeBinary: string, hqBinary: string, env: NodeJS.ProcessEnv): (args: string[]) => Promise<number>;
31
+ export declare function runSyncOnce(deps: SyncRunDeps): Promise<boolean>;
32
+ export declare function runSyncLoop(deps: SyncRunDeps): Promise<void>;
33
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Kit service: company vault sync loop.
3
+ *
4
+ * Mirrors the hosted box's hq-agent-sync.service, which runs hq-cloud's
5
+ * `hq-sync-runner --companies --direction both --on-conflict keep` on a
6
+ * loop and writes `component-sync`. Here the equivalent is the CLI's own
7
+ * `hq sync pull --all --on-conflict keep --hq-root <kit hqRoot>`, run as a
8
+ * child of the same node + hq binary this service was launched with, so the
9
+ * machine identity, creds path and version are exactly the service's own.
10
+ *
11
+ * Honest health: exit 0 = ok, anything else = error (the heartbeat turns a
12
+ * stale stamp into error on its own).
13
+ */
14
+ import { spawn } from "node:child_process";
15
+ import { writeComponentStatus } from "../creds.js";
16
+ export function syncPullArgs(hqRoot) {
17
+ return ["sync", "pull", "--all", "--on-conflict", "keep", "--hq-root", hqRoot];
18
+ }
19
+ export function defaultRunPull(nodeBinary, hqBinary, env) {
20
+ return (args) => new Promise((resolve) => {
21
+ const child = spawn(nodeBinary, [hqBinary, ...args], {
22
+ env,
23
+ stdio: ["ignore", "inherit", "inherit"],
24
+ });
25
+ child.on("error", () => resolve(127));
26
+ child.on("exit", (code) => resolve(code ?? 1));
27
+ });
28
+ }
29
+ export async function runSyncOnce(deps) {
30
+ const runPull = deps.runPull ??
31
+ defaultRunPull(deps.nodeBinary ?? process.execPath, deps.hqBinary ?? process.argv[1], process.env);
32
+ const args = syncPullArgs(deps.hqRoot);
33
+ deps.log("info", `sync start hq-root=${deps.hqRoot}`);
34
+ let code;
35
+ try {
36
+ code = await runPull(args);
37
+ }
38
+ catch (err) {
39
+ deps.log("error", `sync spawn failed: ${err instanceof Error ? err.message : String(err)}`);
40
+ code = 1;
41
+ }
42
+ const ok = code === 0;
43
+ writeComponentStatus(deps.paths, "sync", ok ? "ok" : "error");
44
+ deps.log(ok ? "info" : "error", `sync ${ok ? "ok" : `failed exit=${code}`}`);
45
+ return ok;
46
+ }
47
+ export async function runSyncLoop(deps) {
48
+ const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
49
+ let passes = 0;
50
+ for (;;) {
51
+ await runSyncOnce(deps);
52
+ passes += 1;
53
+ if (deps.maxPasses !== undefined && passes >= deps.maxPasses)
54
+ return;
55
+ await sleep(deps.intervalMs);
56
+ }
57
+ }
58
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The four kit services and how each is launched. Every unit runs
3
+ * `node hq agent kit run <service>`; the service reads kit.json and the
4
+ * machine-creds file itself, so the units carry paths and nothing else.
5
+ */
6
+ import type { ServiceSpec } from "../service-manager/types.js";
7
+ import type { AgentKitPaths } from "./paths.js";
8
+ export type KitService = "sync" | "mesh" | "inbox" | "heartbeat";
9
+ export declare const KIT_SERVICES: readonly KitService[];
10
+ export declare const KIT_LABEL_PREFIX = "ai.getindigo.hq-agent";
11
+ export declare function isKitService(value: string): value is KitService;
12
+ /**
13
+ * Environment every service inherits. HQ_MACHINE_CREDS_FILE pins hq-cloud's
14
+ * mint to the kit's creds file; HQ_REQUIRE_MACHINE_IDENTITY makes a missing
15
+ * file a loud error instead of a browser-login hang; HQ_AGENT_DIR keeps a
16
+ * relocated kit consistent across restarts.
17
+ */
18
+ export declare function kitServiceEnv(paths: AgentKitPaths): Record<string, string>;
19
+ export declare function kitServiceSpec(service: KitService, paths: AgentKitPaths): ServiceSpec;
20
+ export declare function kitServiceSpecs(paths: AgentKitPaths): ServiceSpec[];
21
+ //# sourceMappingURL=services.d.ts.map
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The four kit services and how each is launched. Every unit runs
3
+ * `node hq agent kit run <service>`; the service reads kit.json and the
4
+ * machine-creds file itself, so the units carry paths and nothing else.
5
+ */
6
+ import { serviceLogPath } from "./paths.js";
7
+ export const KIT_SERVICES = ["sync", "mesh", "inbox", "heartbeat"];
8
+ export const KIT_LABEL_PREFIX = "ai.getindigo.hq-agent";
9
+ export function isKitService(value) {
10
+ return KIT_SERVICES.includes(value);
11
+ }
12
+ const DESCRIPTIONS = {
13
+ sync: "HQ agent kit: company vault sync loop",
14
+ mesh: "HQ agent kit: work-mesh doorbell listener",
15
+ inbox: "HQ agent kit: inbox poller",
16
+ heartbeat: "HQ agent kit: heartbeat reporter",
17
+ };
18
+ /**
19
+ * Environment every service inherits. HQ_MACHINE_CREDS_FILE pins hq-cloud's
20
+ * mint to the kit's creds file; HQ_REQUIRE_MACHINE_IDENTITY makes a missing
21
+ * file a loud error instead of a browser-login hang; HQ_AGENT_DIR keeps a
22
+ * relocated kit consistent across restarts.
23
+ */
24
+ export function kitServiceEnv(paths) {
25
+ return {
26
+ HQ_AGENT_DIR: paths.agentDir,
27
+ HQ_MACHINE_CREDS_FILE: paths.machineCredsPath,
28
+ HQ_REQUIRE_MACHINE_IDENTITY: "1",
29
+ };
30
+ }
31
+ export function kitServiceSpec(service, paths) {
32
+ return {
33
+ name: service,
34
+ label: `${KIT_LABEL_PREFIX}.${service}`,
35
+ description: DESCRIPTIONS[service],
36
+ args: ["agent", "kit", "run", service],
37
+ logPath: serviceLogPath(paths, service),
38
+ workingDir: paths.agentDir,
39
+ env: kitServiceEnv(paths),
40
+ restartSec: 10,
41
+ };
42
+ }
43
+ export function kitServiceSpecs(paths) {
44
+ return KIT_SERVICES.map((s) => kitServiceSpec(s, paths));
45
+ }
46
+ //# sourceMappingURL=services.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The skills directory the kit ships to ~/.hq-agent/skills/<name>/SKILL.md.
3
+ *
4
+ * agentskills.io format: YAML frontmatter with `name` and `description`, then
5
+ * markdown the bot's framework loads as an instruction. Each skill drives
6
+ * the `hq` CLI, which authenticates as the machine identity on its own, so
7
+ * no skill ever embeds or asks for a token or secret value.
8
+ */
9
+ import type { AgentKitPaths } from "./paths.js";
10
+ export interface KitSkill {
11
+ name: string;
12
+ description: string;
13
+ body: string;
14
+ }
15
+ export declare const KIT_SKILLS: readonly KitSkill[];
16
+ export declare function renderSkillMarkdown(skill: KitSkill): string;
17
+ export declare function writeKitSkills(paths: Pick<AgentKitPaths, "skillsDir">): string[];
18
+ //# sourceMappingURL=skills.d.ts.map
@@ -0,0 +1,149 @@
1
+ /**
2
+ * The skills directory the kit ships to ~/.hq-agent/skills/<name>/SKILL.md.
3
+ *
4
+ * agentskills.io format: YAML frontmatter with `name` and `description`, then
5
+ * markdown the bot's framework loads as an instruction. Each skill drives
6
+ * the `hq` CLI, which authenticates as the machine identity on its own, so
7
+ * no skill ever embeds or asks for a token or secret value.
8
+ */
9
+ import * as fs from "node:fs";
10
+ import * as path from "node:path";
11
+ export const KIT_SKILLS = [
12
+ {
13
+ name: "dm",
14
+ description: "Send and read HQ direct messages and channel messages as this agent using the hq CLI.",
15
+ body: `# HQ direct messages
16
+
17
+ Use the \`hq dm\` command to talk to teammates (people and other agents) in HQ.
18
+ The CLI authenticates as this agent automatically — never ask for a token.
19
+
20
+ ## Send
21
+
22
+ \`\`\`bash
23
+ hq dm <email-or-uid> "message text" # 1:1 to a person (prs_…) or agent (agt_…)
24
+ hq dm <uid1>,<uid2> "message text" # group DM
25
+ hq dm '#channel-name' "message text" # channel
26
+ \`\`\`
27
+
28
+ ## Read
29
+
30
+ \`\`\`bash
31
+ hq dm inbox --unread # unread DMs addressed to you
32
+ hq dm thread <email-or-uid> # the 1:1 conversation
33
+ hq dm inbox --mark-read # mark what you have read
34
+ hq dm channel <name> # read a channel
35
+ \`\`\`
36
+
37
+ New inbound messages are also mirrored by the kit's inbox poller to
38
+ \`~/.hq-agent/inbox/<id>.json\` (and \`inbox.jsonl\`) — check there when
39
+ you are asked whether anyone has messaged you.
40
+
41
+ ## Rules
42
+
43
+ - Reply in the same thread you were messaged in.
44
+ - Keep messages short; link to files in the vault instead of pasting them.
45
+ - Never include secrets or credentials in a message.
46
+ `,
47
+ },
48
+ {
49
+ name: "search",
50
+ description: "Search the company vault (documents, knowledge, meeting notes) with the hq CLI's local index.",
51
+ body: `# HQ search
52
+
53
+ The company vault is synced to the kit's HQ root (see \`~/.hq-agent/kit.json\`,
54
+ \`hqRoot\`). Search it with:
55
+
56
+ \`\`\`bash
57
+ hq search "<query>" # ranked results across the synced vault
58
+ hq search "<query>" --mode hybrid # keyword + semantic
59
+ hq search "<query>" --json # machine-readable
60
+ hq files search "<query>" --company <slug> # server-side vault search (no local index needed)
61
+ \`\`\`
62
+
63
+ If results look stale, the sync loop may not have run yet:
64
+ \`hq sync pull --all --on-conflict keep --hq-root <hqRoot>\` pulls now.
65
+
66
+ Cite the file path of anything you quote so a teammate can open it.
67
+ `,
68
+ },
69
+ {
70
+ name: "files",
71
+ description: "Read, list and write files in the company vault through the hq CLI (hq files).",
72
+ body: `# HQ vault files
73
+
74
+ \`\`\`bash
75
+ hq files browse companies/<slug>/<folder> # list a vault folder without syncing it
76
+ hq files cat companies/<slug>/<file> # print one file
77
+ hq files get companies/<slug>/<file> # fetch one file into the local HQ tree
78
+ hq files share companies/<slug>/<path> # share a path with a teammate
79
+ hq files versions companies/<slug>/<file> # version history
80
+ \`\`\`
81
+
82
+ Paths are vault-relative and start with \`companies/<slug>/\`. The synced copy
83
+ lives under the kit's HQ root (\`~/.hq-agent/kit.json\` → \`hqRoot\`); edit files
84
+ there and run \`hq sync push --hq-root <hqRoot>\` to publish. Writes are
85
+ audited under this agent's identity — only write where you were asked to,
86
+ and prefer creating a new file over overwriting one you did not author.
87
+ `,
88
+ },
89
+ {
90
+ name: "secrets-exec",
91
+ description: "Run a command with company secrets injected as environment variables, without ever printing them.",
92
+ body: `# Run with HQ secrets
93
+
94
+ Secrets never appear in chat, logs or files. Inject them into a child
95
+ process instead:
96
+
97
+ \`\`\`bash
98
+ hq secrets list # names only, never values
99
+ hq secrets exec --only <NAME>[,<NAME>] -- <cmd> # run <cmd> with those vars set
100
+ hq run <script> # run a vault script with its declared secrets
101
+ \`\`\`
102
+
103
+ Rules:
104
+
105
+ - Never \`echo\`, \`printenv\` or otherwise print a secret, even to "check" it.
106
+ - Request the narrowest \`--only\` set the command needs.
107
+ - If a secret is missing, say which NAME is missing and ask a human admin to
108
+ add it with \`hq secrets set\` — do not ask for the value in chat.
109
+ `,
110
+ },
111
+ {
112
+ name: "work-mesh-status",
113
+ description: "Report and update this agent's live work status and read the team's work mesh via the hq CLI.",
114
+ body: `# Work mesh status
115
+
116
+ The work mesh is HQ's live board of who is working on what. It is the source
117
+ of truth for project stories and active sessions; the kit's listener keeps a
118
+ local cache under \`~/.hq/work-mesh/cache/\`.
119
+
120
+ \`\`\`bash
121
+ hq mesh session status --company <slug> # who is working on what right now
122
+ hq mesh start --company <slug> --project <slug> --summary "<what you are starting>"
123
+ hq mesh progress --company <slug> --project <slug> --summary "<what changed>"
124
+ hq mesh blocked --company <slug> --project <slug> --summary "<what blocks you>"
125
+ hq mesh done --company <slug> --project <slug> --summary "<what you finished>"
126
+ hq mesh note --company <slug> --project <slug> --summary "<short note>"
127
+ \`\`\`
128
+
129
+ Post \`start\` when you pick up a piece of work and \`done\` when you finish it.
130
+ Keep entries to one line. Presence (online / stale / offline) is derived
131
+ from the kit heartbeat automatically — you do not need to report it.
132
+ `,
133
+ },
134
+ ];
135
+ export function renderSkillMarkdown(skill) {
136
+ return `---\nname: ${skill.name}\ndescription: ${JSON.stringify(skill.description)}\n---\n\n${skill.body}`;
137
+ }
138
+ export function writeKitSkills(paths) {
139
+ const written = [];
140
+ for (const skill of KIT_SKILLS) {
141
+ const dir = path.join(paths.skillsDir, skill.name);
142
+ fs.mkdirSync(dir, { recursive: true, mode: 0o755 });
143
+ const dest = path.join(dir, "SKILL.md");
144
+ fs.writeFileSync(dest, renderSkillMarkdown(skill), { mode: 0o644 });
145
+ written.push(dest);
146
+ }
147
+ return written;
148
+ }
149
+ //# sourceMappingURL=skills.js.map
@@ -91,7 +91,26 @@ export interface SyncHealthDeps {
91
91
  * scope that is fine.
92
92
  */
93
93
  unresolvedScopes?: (journals: readonly SyncJournalSummary[]) => readonly string[];
94
+ /**
95
+ * Whether a company slug has a local `companies/<slug>` directory in the HQ
96
+ * tree. Leftover journal shards for companies this machine does not keep
97
+ * locally are NA, not WARN — a journal without a tree is not a corroborated
98
+ * unhealthy-sync signal, and `hq doctor --fix` has nothing local to refresh.
99
+ */
100
+ localCompanyExists?: (slug: string) => boolean;
94
101
  }
102
+ /**
103
+ * True when `slug` is a filesystem-safe company folder name. Rejects empty
104
+ * values, path separators, and `..` so a journal slug cannot be used to probe
105
+ * outside `companies/`.
106
+ */
107
+ export declare function isSafeCompanySlug(slug: string): boolean;
108
+ /** True when `hqRoot/companies/<slug>` exists as a directory. Never throws. */
109
+ export declare function defaultLocalCompanyExists(hqRoot: string, slug: string): boolean;
110
+ /** True when this journal slug names a company rather than the personal tree. */
111
+ export declare function isCompanyJournalSlug(slug: string): boolean;
112
+ /** Company slug from a `sync.journal.<slug>` check id, or null if not one. */
113
+ export declare function journalSlugFromCheckId(checkId: string): string | null;
95
114
  /** The versions/sync check family. Registered in `createDefaultRegistry`. */
96
115
  export declare const syncHealthFamily: CheckFamily;
97
116
  /** Run every versions/sync check. A thrown check degrades to UNKNOWN. */
@@ -47,14 +47,35 @@ export const STALE_JOURNAL_THRESHOLD_MS = 7 * 24 * 60 * 60 * 1000;
47
47
  /** The offline update cache written by the check-hq-update SessionStart hook. */
48
48
  export const UPDATE_CACHE_RELPATH = path.join("workspace", ".hq-update-check", "last-check.json");
49
49
  /** Fill in the optional dependencies so call sites never branch on undefined. */
50
- function withDefaults(deps) {
50
+ function withDefaults(deps, hqRoot) {
51
51
  return {
52
52
  ...deps,
53
53
  manifestStatuses: deps.manifestStatuses ?? defaultManifestStatuses,
54
54
  manifestAvailable: deps.manifestAvailable ?? (() => loadManifestExports() !== null),
55
55
  unresolvedScopes: deps.unresolvedScopes ?? defaultUnresolvedScopes,
56
+ localCompanyExists: deps.localCompanyExists ??
57
+ ((slug) => defaultLocalCompanyExists(hqRoot, slug)),
56
58
  };
57
59
  }
60
+ /**
61
+ * True when `slug` is a filesystem-safe company folder name. Rejects empty
62
+ * values, path separators, and `..` so a journal slug cannot be used to probe
63
+ * outside `companies/`.
64
+ */
65
+ export function isSafeCompanySlug(slug) {
66
+ return /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(slug);
67
+ }
68
+ /** True when `hqRoot/companies/<slug>` exists as a directory. Never throws. */
69
+ export function defaultLocalCompanyExists(hqRoot, slug) {
70
+ if (!isSafeCompanySlug(slug))
71
+ return false;
72
+ try {
73
+ return fs.statSync(path.join(hqRoot, "companies", slug)).isDirectory();
74
+ }
75
+ catch {
76
+ return false;
77
+ }
78
+ }
58
79
  /**
59
80
  * Company journal shards are unresolvable by the default collector: the
60
81
  * snapshot store keys company scopes by `companyUid`, which `listJournals()`
@@ -146,6 +167,15 @@ const NON_COMPANY_JOURNAL_SLUGS = new Set([
146
167
  PERSONAL_SCOPE_SLUG,
147
168
  PERSONAL_VAULT_SCOPE_SLUG,
148
169
  ]);
170
+ /** True when this journal slug names a company rather than the personal tree. */
171
+ export function isCompanyJournalSlug(slug) {
172
+ return !NON_COMPANY_JOURNAL_SLUGS.has(slug);
173
+ }
174
+ /** Company slug from a `sync.journal.<slug>` check id, or null if not one. */
175
+ export function journalSlugFromCheckId(checkId) {
176
+ const match = /^sync\.journal\.(.+)$/.exec(checkId);
177
+ return match ? match[1] : null;
178
+ }
149
179
  /** The versions/sync check family. Registered in `createDefaultRegistry`. */
150
180
  export const syncHealthFamily = {
151
181
  id: SYNC_FAMILY_ID,
@@ -154,7 +184,7 @@ export const syncHealthFamily = {
154
184
  };
155
185
  /** Run every versions/sync check. A thrown check degrades to UNKNOWN. */
156
186
  export function checkSyncHealth(context, rawDeps = DEFAULT_DEPS) {
157
- const deps = withDefaults(rawDeps);
187
+ const deps = withDefaults(rawDeps, context.hqRoot);
158
188
  try {
159
189
  return [
160
190
  ...versionResults(context, deps),
@@ -325,6 +355,29 @@ function journalResults(deps, journals) {
325
355
  return journals.map((entry) => {
326
356
  const lastSync = entry.journal?.lastSync;
327
357
  const checkId = `sync.journal.${entry.slug}`;
358
+ // A company journal without a local tree is leftover membership state,
359
+ // not a live sync target. WARN would make `hq doctor --fix` look like it
360
+ // failed to repair something it was never going to touch (US-015 health
361
+ // hook files remaining FAIL/WARN after the safe repair pass).
362
+ if (isCompanyJournalSlug(entry.slug)) {
363
+ let local;
364
+ try {
365
+ local = deps.localCompanyExists(entry.slug);
366
+ }
367
+ catch {
368
+ // Existence probe failed: fall through to the staleness check rather
369
+ // than hiding a possibly-live company behind NA.
370
+ local = true;
371
+ }
372
+ if (!local) {
373
+ return {
374
+ status: "NA",
375
+ checkId,
376
+ target: entry.path,
377
+ message: `Sync journal '${entry.slug}' is unused on this machine — there is no companies/${entry.slug} directory, so this journal is not a live sync target.`,
378
+ };
379
+ }
380
+ }
328
381
  if (typeof lastSync !== "string" || lastSync.length === 0) {
329
382
  return {
330
383
  status: "WARN",