@indigoai-us/hq-cli 5.61.0 → 5.62.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/dist/commands/agents.d.ts +109 -0
- package/dist/commands/agents.js +385 -0
- package/dist/commands/db-migrate.d.ts +6 -0
- package/dist/commands/db-migrate.js +42 -0
- package/dist/commands/db-provision.d.ts +15 -0
- package/dist/commands/db-provision.js +78 -0
- package/dist/commands/db-sql.d.ts +9 -0
- package/dist/commands/db-sql.js +81 -0
- package/dist/commands/db-status.d.ts +7 -0
- package/dist/commands/db-status.js +70 -0
- package/dist/commands/db.d.ts +9 -0
- package/dist/commands/db.js +23 -0
- package/dist/commands/integrations.d.ts +78 -0
- package/dist/commands/integrations.js +309 -0
- package/dist/commands/members.js +4 -4
- package/dist/commands/outposts.d.ts +60 -0
- package/dist/commands/outposts.js +255 -0
- package/dist/commands/secrets.d.ts +8 -0
- package/dist/commands/secrets.js +23 -8
- package/dist/commands/skill.d.ts +153 -0
- package/dist/commands/skill.js +593 -0
- package/dist/commands/workers.d.ts +48 -0
- package/dist/commands/workers.js +229 -0
- package/dist/lib/db/control-plane.d.ts +45 -0
- package/dist/lib/db/control-plane.js +81 -0
- package/dist/lib/db/local.d.ts +49 -0
- package/dist/lib/db/local.js +106 -0
- package/dist/lib/db/migrate.d.ts +41 -0
- package/dist/lib/db/migrate.js +104 -0
- package/dist/lib/db/paths.d.ts +56 -0
- package/dist/lib/db/paths.js +103 -0
- package/dist/lib/db/remote-engine.d.ts +58 -0
- package/dist/lib/db/remote-engine.js +90 -0
- package/dist/lib/db/remote-sql.d.ts +22 -0
- package/dist/lib/db/remote-sql.js +39 -0
- package/dist/lib/db/sql.d.ts +49 -0
- package/dist/lib/db/sql.js +132 -0
- package/dist/main.js +27 -2
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/sandbox-runner-client.js +3 -3
- package/package.json +9 -1
- package/pnpm-workspace.yaml +2 -0
- package/src/commands/agents.test.ts +297 -0
- package/src/commands/agents.ts +561 -0
- package/src/commands/db-migrate.ts +55 -0
- package/src/commands/db-provision.ts +102 -0
- package/src/commands/db-sql.ts +124 -0
- package/src/commands/db-status.ts +100 -0
- package/src/commands/db.ts +26 -0
- package/src/commands/integrations.test.ts +284 -0
- package/src/commands/integrations.ts +438 -0
- package/src/commands/members.ts +2 -2
- package/src/commands/outposts.test.ts +177 -0
- package/src/commands/outposts.ts +338 -0
- package/src/commands/secrets.parse-destination.test.ts +38 -0
- package/src/commands/secrets.test.ts +24 -0
- package/src/commands/secrets.ts +30 -10
- package/src/commands/skill.test.ts +770 -0
- package/src/commands/skill.ts +796 -0
- package/src/commands/workers.test.ts +158 -0
- package/src/commands/workers.ts +298 -0
- package/src/lib/db/control-plane.test.ts +59 -0
- package/src/lib/db/control-plane.ts +113 -0
- package/src/lib/db/local.test.ts +81 -0
- package/src/lib/db/local.ts +148 -0
- package/src/lib/db/migrate.test.ts +133 -0
- package/src/lib/db/migrate.ts +137 -0
- package/src/lib/db/paths.test.ts +112 -0
- package/src/lib/db/paths.ts +128 -0
- package/src/lib/db/remote-engine.test.ts +44 -0
- package/src/lib/db/remote-engine.ts +148 -0
- package/src/lib/db/remote-sql.test.ts +32 -0
- package/src/lib/db/remote-sql.ts +62 -0
- package/src/lib/db/sql.test.ts +106 -0
- package/src/lib/db/sql.ts +192 -0
- package/src/main.ts +31 -0
- package/src/utils/cognito-session.ts +1 -1
- package/src/utils/sandbox-runner-client.ts +1 -1
- package/test/commands/db-tenant-isolation.test.ts +94 -0
- package/test/commands/db.test.ts +85 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault database path conventions (C1 local tier).
|
|
3
|
+
*
|
|
4
|
+
* Canonical layout (locked by vault-databases PRD):
|
|
5
|
+
* ~/.hq/db/{companySlug}/vault.db
|
|
6
|
+
*
|
|
7
|
+
* Binary DB files are machine-local. They must never live under companies/
|
|
8
|
+
* so hq-sync / git cannot treat them as vault text. Migrations remain vault
|
|
9
|
+
* text at companies/{co}/db/migrations/*.sql (handled by migrate stories).
|
|
10
|
+
*/
|
|
11
|
+
/** Default filename for the per-company local vault SQLite file. */
|
|
12
|
+
export declare const LOCAL_VAULT_DB_FILENAME = "vault.db";
|
|
13
|
+
/**
|
|
14
|
+
* Glob-style ignore patterns for binary / local DB artifacts.
|
|
15
|
+
* Apply in gitignore and hq-sync ignore configuration for any tree that
|
|
16
|
+
* might accidentally host these files. Primary storage is under ~/.hq/db/
|
|
17
|
+
* (outside the vault), but skills must still ignore stray `*.db` / `.data/`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const LOCAL_DB_IGNORE_PATTERNS: readonly string[];
|
|
20
|
+
export interface LocalDbPathEnv {
|
|
21
|
+
/** Override home directory (tests inject temp dirs). Defaults to os.homedir(). */
|
|
22
|
+
home?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the machine-local root that holds all company vault DBs:
|
|
26
|
+
* `{home}/.hq/db`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveLocalDbRoot(env?: LocalDbPathEnv): string;
|
|
29
|
+
/**
|
|
30
|
+
* Normalize and validate a company slug used in the local path.
|
|
31
|
+
* Tenant isolation still requires HQ identity/membership at the command layer;
|
|
32
|
+
* this only rejects empty / path-traversal slugs so we never open arbitrary paths.
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizeCompanySlugForLocalDb(companySlug: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Canonical path for a company's local vault SQLite file:
|
|
37
|
+
* `~/.hq/db/{companySlug}/vault.db`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveLocalDbPath(companySlug: string, env?: LocalDbPathEnv): string;
|
|
40
|
+
/**
|
|
41
|
+
* Directory that contains the company's vault.db (and WAL side files).
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveLocalDbDir(companySlug: string, env?: LocalDbPathEnv): string;
|
|
44
|
+
/**
|
|
45
|
+
* Ensure the company local DB directory exists and is writable.
|
|
46
|
+
* Creates parent directories recursively. Does not create the .db file
|
|
47
|
+
* and does not write secrets into the tree.
|
|
48
|
+
*
|
|
49
|
+
* @returns absolute path of the directory
|
|
50
|
+
*/
|
|
51
|
+
export declare function ensureLocalDbDir(companySlug: string, env?: LocalDbPathEnv): string;
|
|
52
|
+
/**
|
|
53
|
+
* Human-readable documentation of ignore rules for operators and agents.
|
|
54
|
+
*/
|
|
55
|
+
export declare function describeLocalDbIgnoreRules(): string;
|
|
56
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault database path conventions (C1 local tier).
|
|
3
|
+
*
|
|
4
|
+
* Canonical layout (locked by vault-databases PRD):
|
|
5
|
+
* ~/.hq/db/{companySlug}/vault.db
|
|
6
|
+
*
|
|
7
|
+
* Binary DB files are machine-local. They must never live under companies/
|
|
8
|
+
* so hq-sync / git cannot treat them as vault text. Migrations remain vault
|
|
9
|
+
* text at companies/{co}/db/migrations/*.sql (handled by migrate stories).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
!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]="92e78769-940e-5fc9-a47e-7fbcc4415a3b")}catch(e){}}();
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import os from "node:os";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
/** Default filename for the per-company local vault SQLite file. */
|
|
17
|
+
export const LOCAL_VAULT_DB_FILENAME = "vault.db";
|
|
18
|
+
/**
|
|
19
|
+
* Glob-style ignore patterns for binary / local DB artifacts.
|
|
20
|
+
* Apply in gitignore and hq-sync ignore configuration for any tree that
|
|
21
|
+
* might accidentally host these files. Primary storage is under ~/.hq/db/
|
|
22
|
+
* (outside the vault), but skills must still ignore stray `*.db` / `.data/`.
|
|
23
|
+
*/
|
|
24
|
+
export const LOCAL_DB_IGNORE_PATTERNS = [
|
|
25
|
+
"**/*.db",
|
|
26
|
+
"**/*.db-wal",
|
|
27
|
+
"**/*.db-shm",
|
|
28
|
+
"**/*.db-journal",
|
|
29
|
+
"**/.data/**",
|
|
30
|
+
// Explicit machine-local root (if a tool ever materializes a relative copy)
|
|
31
|
+
"**/.hq/db/**",
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Resolve the machine-local root that holds all company vault DBs:
|
|
35
|
+
* `{home}/.hq/db`.
|
|
36
|
+
*/
|
|
37
|
+
export function resolveLocalDbRoot(env) {
|
|
38
|
+
const home = (env?.home ?? os.homedir()).trim();
|
|
39
|
+
if (!home) {
|
|
40
|
+
throw new Error("cannot resolve local DB root: home directory is empty (set home or os.homedir())");
|
|
41
|
+
}
|
|
42
|
+
return path.join(home, ".hq", "db");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Normalize and validate a company slug used in the local path.
|
|
46
|
+
* Tenant isolation still requires HQ identity/membership at the command layer;
|
|
47
|
+
* this only rejects empty / path-traversal slugs so we never open arbitrary paths.
|
|
48
|
+
*/
|
|
49
|
+
export function normalizeCompanySlugForLocalDb(companySlug) {
|
|
50
|
+
const slug = companySlug.trim().toLowerCase();
|
|
51
|
+
if (!slug) {
|
|
52
|
+
throw new Error("company slug is required for local DB path resolution");
|
|
53
|
+
}
|
|
54
|
+
if (slug.includes("/") ||
|
|
55
|
+
slug.includes("\\") ||
|
|
56
|
+
slug.includes("..") ||
|
|
57
|
+
slug === "." ||
|
|
58
|
+
slug.includes("\0")) {
|
|
59
|
+
throw new Error(`invalid company slug for local DB path: ${JSON.stringify(companySlug)}`);
|
|
60
|
+
}
|
|
61
|
+
return slug;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Canonical path for a company's local vault SQLite file:
|
|
65
|
+
* `~/.hq/db/{companySlug}/vault.db`.
|
|
66
|
+
*/
|
|
67
|
+
export function resolveLocalDbPath(companySlug, env) {
|
|
68
|
+
const slug = normalizeCompanySlugForLocalDb(companySlug);
|
|
69
|
+
return path.join(resolveLocalDbRoot(env), slug, LOCAL_VAULT_DB_FILENAME);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Directory that contains the company's vault.db (and WAL side files).
|
|
73
|
+
*/
|
|
74
|
+
export function resolveLocalDbDir(companySlug, env) {
|
|
75
|
+
return path.dirname(resolveLocalDbPath(companySlug, env));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Ensure the company local DB directory exists and is writable.
|
|
79
|
+
* Creates parent directories recursively. Does not create the .db file
|
|
80
|
+
* and does not write secrets into the tree.
|
|
81
|
+
*
|
|
82
|
+
* @returns absolute path of the directory
|
|
83
|
+
*/
|
|
84
|
+
export function ensureLocalDbDir(companySlug, env) {
|
|
85
|
+
const dir = resolveLocalDbDir(companySlug, env);
|
|
86
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
87
|
+
// Verify writable without leaving secrets or DB content behind.
|
|
88
|
+
fs.accessSync(dir, fs.constants.W_OK);
|
|
89
|
+
return dir;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Human-readable documentation of ignore rules for operators and agents.
|
|
93
|
+
*/
|
|
94
|
+
export function describeLocalDbIgnoreRules() {
|
|
95
|
+
return [
|
|
96
|
+
"Local vault databases live at ~/.hq/db/{company}/vault.db (outside the vault tree).",
|
|
97
|
+
"Never place *.db under companies/ — binary DB state is not vault-synced.",
|
|
98
|
+
"Ignore patterns:",
|
|
99
|
+
...LOCAL_DB_IGNORE_PATTERNS.map((p) => ` - ${p}`),
|
|
100
|
+
].join("\n");
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=paths.js.map
|
|
103
|
+
//# debugId=92e78769-940e-5fc9-a47e-7fbcc4415a3b
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable remote vault DB engine interface (vault-databases US-007).
|
|
3
|
+
*
|
|
4
|
+
* Default shipped adapter id: aurora-dsql.
|
|
5
|
+
* This module is interface + registry only — no production AWS provision here.
|
|
6
|
+
*/
|
|
7
|
+
/** Connection material written only to secrets stores — never CLI stdout. */
|
|
8
|
+
export interface RemoteConnectionSecretPayload {
|
|
9
|
+
/** Opaque secret body (e.g. JSON with host/user/password or IAM token recipe). */
|
|
10
|
+
payload: Record<string, unknown>;
|
|
11
|
+
/** Suggested vault/Secrets Manager key suffix (namespaced by company elsewhere). */
|
|
12
|
+
secretNameHint: string;
|
|
13
|
+
}
|
|
14
|
+
export interface RemoteProvisionRequest {
|
|
15
|
+
companyUid: string;
|
|
16
|
+
companySlug: string;
|
|
17
|
+
region?: string;
|
|
18
|
+
/** Engine-specific options (cluster params, etc.). */
|
|
19
|
+
options?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface RemoteProvisionResult {
|
|
22
|
+
engineId: string;
|
|
23
|
+
resourceArn: string;
|
|
24
|
+
region: string;
|
|
25
|
+
status: "ready" | "provisioning" | "failed" | "existing";
|
|
26
|
+
/** Secret payload to store — callers must not print. */
|
|
27
|
+
connectionSecret: RemoteConnectionSecretPayload;
|
|
28
|
+
}
|
|
29
|
+
export interface RemoteHealth {
|
|
30
|
+
engineId: string;
|
|
31
|
+
resourceArn: string;
|
|
32
|
+
healthy: boolean;
|
|
33
|
+
status: string;
|
|
34
|
+
checkedAt: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Remote Postgres-class engine adapter.
|
|
38
|
+
* Implementations live in control plane (hq-pro) for real AWS; CLI may mock.
|
|
39
|
+
*/
|
|
40
|
+
export interface RemoteDbEngine {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
provision(req: RemoteProvisionRequest): Promise<RemoteProvisionResult>;
|
|
43
|
+
deprovision(companyUid: string, resourceArn: string): Promise<void>;
|
|
44
|
+
connectionSecretPayload(companyUid: string, resourceArn: string): Promise<RemoteConnectionSecretPayload>;
|
|
45
|
+
healthCheck(resourceArn: string): Promise<RemoteHealth>;
|
|
46
|
+
}
|
|
47
|
+
/** Default engine selection (PRD decision). */
|
|
48
|
+
export declare const DEFAULT_REMOTE_ENGINE_ID = "aurora-dsql";
|
|
49
|
+
export declare function registerRemoteEngine(engine: RemoteDbEngine): void;
|
|
50
|
+
export declare function getRemoteEngine(id?: string): RemoteDbEngine;
|
|
51
|
+
export declare function listRemoteEngineIds(): string[];
|
|
52
|
+
/** Clear registry (tests only). */
|
|
53
|
+
export declare function _resetRemoteEngineRegistryForTests(): void;
|
|
54
|
+
/**
|
|
55
|
+
* In-memory mock engine for unit tests — no AWS.
|
|
56
|
+
*/
|
|
57
|
+
export declare function createMockRemoteEngine(id?: string): RemoteDbEngine;
|
|
58
|
+
//# sourceMappingURL=remote-engine.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pluggable remote vault DB engine interface (vault-databases US-007).
|
|
3
|
+
*
|
|
4
|
+
* Default shipped adapter id: aurora-dsql.
|
|
5
|
+
* This module is interface + registry only — no production AWS provision here.
|
|
6
|
+
*/
|
|
7
|
+
/** Default engine selection (PRD decision). */
|
|
8
|
+
|
|
9
|
+
!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]="738ccb65-e1d0-5466-b98e-a96058bda113")}catch(e){}}();
|
|
10
|
+
export const DEFAULT_REMOTE_ENGINE_ID = "aurora-dsql";
|
|
11
|
+
const registry = new Map();
|
|
12
|
+
export function registerRemoteEngine(engine) {
|
|
13
|
+
registry.set(engine.id, engine);
|
|
14
|
+
}
|
|
15
|
+
export function getRemoteEngine(id = DEFAULT_REMOTE_ENGINE_ID) {
|
|
16
|
+
const engine = registry.get(id);
|
|
17
|
+
if (!engine) {
|
|
18
|
+
throw new Error(`remote DB engine not registered: ${id} (available: ${[...registry.keys()].join(", ") || "none"})`);
|
|
19
|
+
}
|
|
20
|
+
return engine;
|
|
21
|
+
}
|
|
22
|
+
export function listRemoteEngineIds() {
|
|
23
|
+
return [...registry.keys()];
|
|
24
|
+
}
|
|
25
|
+
/** Clear registry (tests only). */
|
|
26
|
+
export function _resetRemoteEngineRegistryForTests() {
|
|
27
|
+
registry.clear();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* In-memory mock engine for unit tests — no AWS.
|
|
31
|
+
*/
|
|
32
|
+
export function createMockRemoteEngine(id = "mock") {
|
|
33
|
+
const resources = new Map();
|
|
34
|
+
return {
|
|
35
|
+
id,
|
|
36
|
+
async provision(req) {
|
|
37
|
+
const existing = [...resources.entries()].find(([, v]) => v.companyUid === req.companyUid);
|
|
38
|
+
if (existing) {
|
|
39
|
+
const [arn, meta] = existing;
|
|
40
|
+
return {
|
|
41
|
+
engineId: id,
|
|
42
|
+
resourceArn: arn,
|
|
43
|
+
region: meta.region,
|
|
44
|
+
status: "existing",
|
|
45
|
+
connectionSecret: {
|
|
46
|
+
payload: { mock: true, companyUid: req.companyUid },
|
|
47
|
+
secretNameHint: `db/remote/${req.companySlug}`,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const arn = `arn:mock:db:${req.companyUid}`;
|
|
52
|
+
const region = req.region ?? "us-east-1";
|
|
53
|
+
resources.set(arn, { companyUid: req.companyUid, region });
|
|
54
|
+
return {
|
|
55
|
+
engineId: id,
|
|
56
|
+
resourceArn: arn,
|
|
57
|
+
region,
|
|
58
|
+
status: "ready",
|
|
59
|
+
connectionSecret: {
|
|
60
|
+
payload: { mock: true, companyUid: req.companyUid },
|
|
61
|
+
secretNameHint: `db/remote/${req.companySlug}`,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
async deprovision(companyUid, resourceArn) {
|
|
66
|
+
const meta = resources.get(resourceArn);
|
|
67
|
+
if (meta && meta.companyUid === companyUid) {
|
|
68
|
+
resources.delete(resourceArn);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
async connectionSecretPayload(companyUid, resourceArn) {
|
|
72
|
+
return {
|
|
73
|
+
payload: { mock: true, companyUid, resourceArn },
|
|
74
|
+
secretNameHint: `db/remote/${companyUid}`,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
async healthCheck(resourceArn) {
|
|
78
|
+
const ok = resources.has(resourceArn);
|
|
79
|
+
return {
|
|
80
|
+
engineId: id,
|
|
81
|
+
resourceArn,
|
|
82
|
+
healthy: ok,
|
|
83
|
+
status: ok ? "ready" : "missing",
|
|
84
|
+
checkedAt: new Date().toISOString(),
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=remote-engine.js.map
|
|
90
|
+
//# debugId=738ccb65-e1d0-5466-b98e-a96058bda113
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote SQL via secrets-exec style injection (US-010).
|
|
3
|
+
*
|
|
4
|
+
* Connection string never appears in argv, logs, or stdout.
|
|
5
|
+
* Local remains default when --remote is absent (handled by command layer).
|
|
6
|
+
*/
|
|
7
|
+
export interface RemoteSqlOptions {
|
|
8
|
+
company: string;
|
|
9
|
+
sql: string;
|
|
10
|
+
/** Injected secret material — never log. */
|
|
11
|
+
getConnectionConfig: () => Promise<Record<string, unknown>>;
|
|
12
|
+
/** Execute against remote; tests inject mock. */
|
|
13
|
+
execute?: (config: Record<string, unknown>, sql: string) => Promise<Record<string, unknown>[]>;
|
|
14
|
+
}
|
|
15
|
+
export interface RemoteSqlResult {
|
|
16
|
+
rows: Record<string, unknown>[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Run SQL on remote tier using vault-bound credentials.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runRemoteSql(opts: RemoteSqlOptions): Promise<RemoteSqlResult>;
|
|
22
|
+
//# sourceMappingURL=remote-sql.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote SQL via secrets-exec style injection (US-010).
|
|
3
|
+
*
|
|
4
|
+
* Connection string never appears in argv, logs, or stdout.
|
|
5
|
+
* Local remains default when --remote is absent (handled by command layer).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
!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]="07948af3-ec73-5a1a-bf8a-d0197090af40")}catch(e){}}();
|
|
9
|
+
function assertNoLeak(label, value) {
|
|
10
|
+
const s = typeof value === "string" ? value : JSON.stringify(value);
|
|
11
|
+
if (/postgres:\/\//i.test(s) || /postgresql:\/\//i.test(s)) {
|
|
12
|
+
throw new Error(`${label}: connection string leak blocked`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Run SQL on remote tier using vault-bound credentials.
|
|
17
|
+
*/
|
|
18
|
+
export async function runRemoteSql(opts) {
|
|
19
|
+
if (!opts.sql?.trim()) {
|
|
20
|
+
throw new Error("SQL statement is required");
|
|
21
|
+
}
|
|
22
|
+
let config;
|
|
23
|
+
try {
|
|
24
|
+
config = await opts.getConnectionConfig();
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
const msg = e instanceof Error ? e.message : "no remote binding";
|
|
28
|
+
throw new Error(`remote SQL unavailable: ${msg}. Run \`hq db provision --company ${opts.company}\` first.`);
|
|
29
|
+
}
|
|
30
|
+
assertNoLeak("connection config", config);
|
|
31
|
+
if (!opts.execute) {
|
|
32
|
+
throw new Error("remote SQL executor not configured in this build (adapter pending live DSQL wire-up)");
|
|
33
|
+
}
|
|
34
|
+
const rows = await opts.execute(config, opts.sql);
|
|
35
|
+
assertNoLeak("remote sql rows", rows);
|
|
36
|
+
return { rows };
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=remote-sql.js.map
|
|
39
|
+
//# debugId=07948af3-ec73-5a1a-bf8a-d0197090af40
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local SQL execution helpers (vault-databases US-004).
|
|
3
|
+
*
|
|
4
|
+
* Company scope is path-bound via resolveLocalDbPath — callers must pass the
|
|
5
|
+
* resolved company slug from HQ session/flags. Path overrides that open
|
|
6
|
+
* another company's DB are denied unless an explicit dangerous flag is set.
|
|
7
|
+
*/
|
|
8
|
+
import { type LocalDbPathEnv } from "./paths.js";
|
|
9
|
+
export interface SqlRunOptions extends LocalDbPathEnv {
|
|
10
|
+
company: string;
|
|
11
|
+
sql: string;
|
|
12
|
+
/** Allow INSERT/UPDATE/DELETE/DDL. Default false (read-only). */
|
|
13
|
+
write?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Dangerous: open an absolute DB path instead of the company canonical path.
|
|
16
|
+
* Denied unless allowCrossCompanyPath is true.
|
|
17
|
+
*/
|
|
18
|
+
dbPathOverride?: string;
|
|
19
|
+
/** Explicit dangerous flag to open a non-canonical local DB path. Default false. */
|
|
20
|
+
allowCrossCompanyPath?: boolean;
|
|
21
|
+
/** Output format */
|
|
22
|
+
format?: "jsonl" | "table";
|
|
23
|
+
}
|
|
24
|
+
export interface SqlRunResult {
|
|
25
|
+
columns: string[];
|
|
26
|
+
rows: Record<string, unknown>[];
|
|
27
|
+
changes: number;
|
|
28
|
+
readonly: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function stripSqlNoise(sql: string): string;
|
|
31
|
+
export declare function isWriteSql(sql: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Statements that must never run via `hq db sql`, even with --write.
|
|
34
|
+
* ATTACH/DETACH would let a company-scoped session open another company's
|
|
35
|
+
* vault.db by absolute path (category-1 isolation).
|
|
36
|
+
*/
|
|
37
|
+
export declare function assertSqlAllowed(sql: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Resolve which file path to open, enforcing company isolation by default.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveSqlDbPath(opts: SqlRunOptions): string;
|
|
42
|
+
/**
|
|
43
|
+
* Execute SQL against the company local vault DB.
|
|
44
|
+
*/
|
|
45
|
+
export declare function runLocalSql(opts: SqlRunOptions): SqlRunResult;
|
|
46
|
+
export declare function formatSqlResult(result: SqlRunResult, format?: "jsonl" | "table"): string;
|
|
47
|
+
/** Test helper: company dir for isolation assertions. */
|
|
48
|
+
export declare function companyLocalDbDir(company: string, env?: LocalDbPathEnv): string;
|
|
49
|
+
//# sourceMappingURL=sql.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local SQL execution helpers (vault-databases US-004).
|
|
3
|
+
*
|
|
4
|
+
* Company scope is path-bound via resolveLocalDbPath — callers must pass the
|
|
5
|
+
* resolved company slug from HQ session/flags. Path overrides that open
|
|
6
|
+
* another company's DB are denied unless an explicit dangerous flag is set.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
!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]="f9dc08da-ad30-5af4-94fb-b167d4299692")}catch(e){}}();
|
|
10
|
+
import Database from "better-sqlite3";
|
|
11
|
+
import { openLocalDb } from "./local.js";
|
|
12
|
+
import { normalizeCompanySlugForLocalDb, resolveLocalDbDir, resolveLocalDbPath, } from "./paths.js";
|
|
13
|
+
const WRITE_PATTERN = /^\s*(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|ALTER|TRUNCATE|REINDEX|VACUUM|BEGIN|COMMIT|ROLLBACK)\b/i;
|
|
14
|
+
/** Always forbidden — opens other files/DBs and breaks company path isolation. */
|
|
15
|
+
const FORBIDDEN_SQL_PATTERN = /\b(ATTACH|DETACH|LOAD_EXTENSION)\b/i;
|
|
16
|
+
export function stripSqlNoise(sql) {
|
|
17
|
+
return sql
|
|
18
|
+
.replace(/^\s*--[^\n]*\n/gm, "")
|
|
19
|
+
.replace(/^\s*\/\*[\s\S]*?\*\//gm, "")
|
|
20
|
+
.trim();
|
|
21
|
+
}
|
|
22
|
+
export function isWriteSql(sql) {
|
|
23
|
+
return WRITE_PATTERN.test(stripSqlNoise(sql));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Statements that must never run via `hq db sql`, even with --write.
|
|
27
|
+
* ATTACH/DETACH would let a company-scoped session open another company's
|
|
28
|
+
* vault.db by absolute path (category-1 isolation).
|
|
29
|
+
*/
|
|
30
|
+
export function assertSqlAllowed(sql) {
|
|
31
|
+
const stripped = stripSqlNoise(sql);
|
|
32
|
+
if (FORBIDDEN_SQL_PATTERN.test(stripped)) {
|
|
33
|
+
throw new Error("ATTACH/DETACH/LOAD_EXTENSION are not allowed via hq db sql (tenant isolation); use the company-canonical local path only");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolve which file path to open, enforcing company isolation by default.
|
|
38
|
+
*/
|
|
39
|
+
export function resolveSqlDbPath(opts) {
|
|
40
|
+
const company = normalizeCompanySlugForLocalDb(opts.company);
|
|
41
|
+
const canonical = resolveLocalDbPath(company, opts);
|
|
42
|
+
if (!opts.dbPathOverride) {
|
|
43
|
+
return canonical;
|
|
44
|
+
}
|
|
45
|
+
if (opts.dbPathOverride === canonical) {
|
|
46
|
+
return canonical;
|
|
47
|
+
}
|
|
48
|
+
if (!opts.allowCrossCompanyPath) {
|
|
49
|
+
throw new Error("cross-company or path override denied: refusing to open a non-canonical local DB path without --allow-cross-company-path (dangerous)");
|
|
50
|
+
}
|
|
51
|
+
return opts.dbPathOverride;
|
|
52
|
+
}
|
|
53
|
+
function openByPath(dbPath) {
|
|
54
|
+
const db = new Database(dbPath);
|
|
55
|
+
db.pragma("journal_mode = WAL");
|
|
56
|
+
db.pragma("foreign_keys = ON");
|
|
57
|
+
return db;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Execute SQL against the company local vault DB.
|
|
61
|
+
*/
|
|
62
|
+
export function runLocalSql(opts) {
|
|
63
|
+
const sql = opts.sql?.trim();
|
|
64
|
+
if (!sql) {
|
|
65
|
+
throw new Error("SQL statement is required");
|
|
66
|
+
}
|
|
67
|
+
assertSqlAllowed(sql);
|
|
68
|
+
const writeRequested = !!opts.write;
|
|
69
|
+
if (isWriteSql(sql) && !writeRequested) {
|
|
70
|
+
throw new Error("write/DDL statement blocked in read-only mode; pass --write to allow (prefer hq db migrate for schema changes)");
|
|
71
|
+
}
|
|
72
|
+
const dbPath = resolveSqlDbPath(opts);
|
|
73
|
+
const usingCanonical = !opts.dbPathOverride || opts.dbPathOverride === resolveLocalDbPath(opts.company, opts);
|
|
74
|
+
const db = usingCanonical
|
|
75
|
+
? openLocalDb(opts.company, opts)
|
|
76
|
+
: openByPath(dbPath);
|
|
77
|
+
try {
|
|
78
|
+
if (!writeRequested) {
|
|
79
|
+
db.pragma("query_only = ON");
|
|
80
|
+
}
|
|
81
|
+
const stmt = db.prepare(sql);
|
|
82
|
+
if (stmt.reader) {
|
|
83
|
+
const rows = stmt.all();
|
|
84
|
+
const columns = rows.length > 0
|
|
85
|
+
? Object.keys(rows[0])
|
|
86
|
+
: stmt.columns().map((c) => c.name);
|
|
87
|
+
return {
|
|
88
|
+
columns,
|
|
89
|
+
rows,
|
|
90
|
+
changes: 0,
|
|
91
|
+
readonly: !writeRequested,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const info = stmt.run();
|
|
95
|
+
return {
|
|
96
|
+
columns: ["changes", "lastInsertRowid"],
|
|
97
|
+
rows: [
|
|
98
|
+
{
|
|
99
|
+
changes: info.changes,
|
|
100
|
+
lastInsertRowid: Number(info.lastInsertRowid),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
changes: info.changes,
|
|
104
|
+
readonly: !writeRequested,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
db.close();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function formatSqlResult(result, format = "jsonl") {
|
|
112
|
+
if (format === "jsonl") {
|
|
113
|
+
if (result.rows.length === 0) {
|
|
114
|
+
return JSON.stringify({ columns: result.columns, rows: 0 });
|
|
115
|
+
}
|
|
116
|
+
return result.rows.map((r) => JSON.stringify(r)).join("\n");
|
|
117
|
+
}
|
|
118
|
+
const cols = result.columns;
|
|
119
|
+
if (cols.length === 0)
|
|
120
|
+
return "(no columns)";
|
|
121
|
+
const header = cols.join("\t");
|
|
122
|
+
const body = result.rows
|
|
123
|
+
.map((r) => cols.map((c) => String(r[c] ?? "")).join("\t"))
|
|
124
|
+
.join("\n");
|
|
125
|
+
return body ? `${header}\n${body}` : header;
|
|
126
|
+
}
|
|
127
|
+
/** Test helper: company dir for isolation assertions. */
|
|
128
|
+
export function companyLocalDbDir(company, env) {
|
|
129
|
+
return resolveLocalDbDir(company, env);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=sql.js.map
|
|
132
|
+
//# debugId=f9dc08da-ad30-5af4-94fb-b167d4299692
|
package/dist/main.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// MUST be first: guard the Node version before any dependency that needs a
|
|
6
6
|
// Node 20+ API (e.g. util.styleText) or a newer native ABI is evaluated.
|
|
7
7
|
|
|
8
|
-
!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]="
|
|
8
|
+
!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]="d089113e-52b9-5313-a256-63f054d8e72a")}catch(e){}}();
|
|
9
9
|
import "./node-preflight.js";
|
|
10
10
|
import { Command } from "commander";
|
|
11
11
|
import { initSentry, Sentry } from "./sentry.js";
|
|
@@ -35,9 +35,11 @@ import { registerApiKeysCommand } from "./commands/api-keys.js";
|
|
|
35
35
|
import { registerSecretsCommand } from "./commands/secrets.js";
|
|
36
36
|
import { registerRunCommand } from "./commands/run.js";
|
|
37
37
|
import { registerGroupsCommand } from "./commands/groups.js";
|
|
38
|
+
import { registerWorkersCommand } from "./commands/workers.js";
|
|
38
39
|
import { registerGroupGrantsCommand } from "./commands/group-grants.js";
|
|
39
40
|
import { registerFilesCommand } from "./commands/files.js";
|
|
40
41
|
import { registerFilesBrowseCommands } from "./commands/files-browse.js";
|
|
42
|
+
import { registerSkillCommand } from "./commands/skill.js";
|
|
41
43
|
import { registerMembersCommand } from "./commands/members.js";
|
|
42
44
|
import { registerPeopleCommand } from "./commands/people.js";
|
|
43
45
|
import { registerDmCommand } from "./commands/dm.js";
|
|
@@ -46,11 +48,15 @@ import { registerFeedbackCommand } from "./commands/feedback.js";
|
|
|
46
48
|
import { registerMeetingsCommand } from "./commands/meetings.js";
|
|
47
49
|
import { registerSourcesCommand } from "./commands/sources.js";
|
|
48
50
|
import { registerSignalsCommand } from "./commands/signals.js";
|
|
51
|
+
import { registerIntegrationsCommand } from "./commands/integrations.js";
|
|
49
52
|
import { registerReindexCommand } from "./commands/reindex.js";
|
|
50
53
|
import { registerRescueCommand } from "./commands/rescue.js";
|
|
51
54
|
import { registerMcpCommand } from "./commands/mcp-status.js";
|
|
52
55
|
import { registerCrmCommand } from "./commands/crm.js";
|
|
53
56
|
import { registerCompanyCommand } from "./commands/company.js";
|
|
57
|
+
import { registerAgentsCommand } from "./commands/agents.js";
|
|
58
|
+
import { registerOutpostsCommand } from "./commands/outposts.js";
|
|
59
|
+
import { registerDbCommand } from "./commands/db.js";
|
|
54
60
|
import { sanitizeArgv } from "./utils/feedback-diagnostics.js";
|
|
55
61
|
import { environmentalFsErrorMessage } from "./utils/environmental-error.js";
|
|
56
62
|
import { isEpipe } from "./utils/epipe.js";
|
|
@@ -133,12 +139,16 @@ registerWhoamiCommand(program);
|
|
|
133
139
|
registerAuthCommands(program);
|
|
134
140
|
// Secrets management (subcommand group — hq secrets set|get|list|delete|exec|generate-link|cache)
|
|
135
141
|
registerSecretsCommand(program);
|
|
142
|
+
// Vault databases (subcommand group — hq db status|sql|migrate|provision)
|
|
143
|
+
registerDbCommand(program);
|
|
136
144
|
// API key management (subcommand group — hq api-keys create|list|revoke)
|
|
137
145
|
registerApiKeysCommand(program);
|
|
138
146
|
// Schema-driven dev runner — hq run [options] -- <cmd>
|
|
139
147
|
registerRunCommand(program);
|
|
140
148
|
// Groups management (subcommand group — hq groups create|delete|add|remove|list|members)
|
|
141
149
|
registerGroupsCommand(program);
|
|
150
|
+
// Worker discovery + sharing (subcommand group — hq workers list|share)
|
|
151
|
+
registerWorkersCommand(program);
|
|
142
152
|
// Cross-company group grants (subcommand group —
|
|
143
153
|
// hq group-grants grant|revoke|outbound|inbound)
|
|
144
154
|
registerGroupGrantsCommand(program);
|
|
@@ -147,6 +157,10 @@ registerGroupGrantsCommand(program);
|
|
|
147
157
|
// browse-vs-sync subcommands (`hq files browse`/`cat`) onto the same group.
|
|
148
158
|
const filesCmd = registerFilesCommand(program);
|
|
149
159
|
registerFilesBrowseCommands(filesCmd);
|
|
160
|
+
// Skill collaboration loop (subcommand group — hq skill suggest|list-suggestions|review).
|
|
161
|
+
// A thin terminal front-end over the SAME wired hq-pro skill suggestion + merge
|
|
162
|
+
// routes the MCP (US-007) and console merge (US-009) surfaces use — no forked logic.
|
|
163
|
+
registerSkillCommand(program);
|
|
150
164
|
// Membership management (subcommand group — hq members invite|list|revoke)
|
|
151
165
|
registerMembersCommand(program);
|
|
152
166
|
// People directory (subcommand group — hq people list|search|resolve), reading
|
|
@@ -164,6 +178,9 @@ registerMeetingsCommand(program);
|
|
|
164
178
|
registerSourcesCommand(program);
|
|
165
179
|
// Signals read surface (subcommand group — hq signals list|get|types|entities)
|
|
166
180
|
registerSignalsCommand(program);
|
|
181
|
+
// Company-connected apps via the governed integration gateway
|
|
182
|
+
// (subcommand group — hq integrations list|tools|call|approve|reject)
|
|
183
|
+
registerIntegrationsCommand(program);
|
|
167
184
|
// Skill/personal-overlay mirroring + workers-registry regen. Invoked by the
|
|
168
185
|
// hq-core reindex hook shim (Stop / PostToolUse) and by sync()/rescue() after
|
|
169
186
|
// they change on-disk sources. Keeps a `master-sync` alias for one release.
|
|
@@ -184,6 +201,14 @@ registerCrmCommand(program);
|
|
|
184
201
|
// Company settings (subcommand group — `hq company settings set`). Owner-only
|
|
185
202
|
// toggles for crmEnabled / ontologyEnabled via PUT /company-settings.
|
|
186
203
|
registerCompanyCommand(program);
|
|
204
|
+
// Cloud agent management (subcommand group — `hq agents …`). Rename, reconfigure,
|
|
205
|
+
// start/stop, and tear down a company's fleet agents via the hq-pro /v1/agents
|
|
206
|
+
// control plane — the same routes the web console's agents panel calls.
|
|
207
|
+
registerAgentsCommand(program);
|
|
208
|
+
// Personal Outpost management (subcommand group — `hq outposts …`). List, inspect,
|
|
209
|
+
// enable Codex on, refresh login for, and destroy your EC2 boxes via the hq-pro
|
|
210
|
+
// /outpost/* control plane.
|
|
211
|
+
registerOutpostsCommand(program);
|
|
187
212
|
export async function runCli() {
|
|
188
213
|
try {
|
|
189
214
|
Sentry.addBreadcrumb({
|
|
@@ -244,4 +269,4 @@ export async function runCli() {
|
|
|
244
269
|
}
|
|
245
270
|
}
|
|
246
271
|
//# sourceMappingURL=main.js.map
|
|
247
|
-
//# debugId=
|
|
272
|
+
//# debugId=d089113e-52b9-5313-a256-63f054d8e72a
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* HQ_VAULT_API_URL — vault-service API Gateway URL
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
!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]="
|
|
22
|
+
!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]="f5342b2c-413d-5142-a44a-92788f273678")}catch(e){}}();
|
|
23
23
|
import * as fs from "fs";
|
|
24
24
|
import * as os from "os";
|
|
25
25
|
import * as path from "path";
|
|
@@ -43,7 +43,7 @@ export const DEFAULT_COGNITO = {
|
|
|
43
43
|
? process.env.HQ_COGNITO_IDENTITY_PROVIDER || undefined
|
|
44
44
|
: "Google",
|
|
45
45
|
};
|
|
46
|
-
export const DEFAULT_VAULT_API_URL = process.env.HQ_VAULT_API_URL ?? "https://hqapi.
|
|
46
|
+
export const DEFAULT_VAULT_API_URL = process.env.HQ_VAULT_API_URL ?? "https://hqapi.hq.computer";
|
|
47
47
|
/**
|
|
48
48
|
* Resolve the HQ tree root for cloud-aware subcommands (`hq sync`, `hq onboard`,
|
|
49
49
|
* `hq cloud …`, etc.).
|
|
@@ -375,4 +375,4 @@ export async function refreshCachedSession() {
|
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
//# sourceMappingURL=cognito-session.js.map
|
|
378
|
-
//# debugId=
|
|
378
|
+
//# debugId=f5342b2c-413d-5142-a44a-92788f273678
|