@indigoai-us/hq-cli 5.60.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/pack-install.d.ts +7 -1
- package/dist/commands/pack-install.js +86 -15
- package/dist/commands/packs.d.ts +2 -1
- package/dist/commands/packs.js +13 -8
- package/dist/commands/secrets.d.ts +13 -0
- package/dist/commands/secrets.js +149 -10
- 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/index.d.ts +5 -3
- package/dist/index.js +14 -240
- 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.d.ts +7 -0
- package/dist/main.js +272 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/sandbox-runner-client.d.ts +13 -0
- package/dist/utils/sandbox-runner-client.js +83 -6
- package/dist/utils/version-check.d.ts +6 -0
- package/dist/utils/version-check.js +78 -2
- 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/pack-install.ts +115 -18
- package/src/commands/pack-update-cache.test.ts +149 -0
- package/src/commands/packs.ts +28 -7
- package/src/commands/secrets.parse-destination.test.ts +38 -0
- package/src/commands/secrets.test.ts +342 -0
- package/src/commands/secrets.ts +227 -13
- 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/index.test.ts +32 -0
- package/src/index.ts +11 -274
- 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 +314 -0
- package/src/utils/cognito-session.ts +1 -1
- package/src/utils/sandbox-runner-client.test.ts +128 -0
- package/src/utils/sandbox-runner-client.ts +100 -4
- package/src/utils/version-check.test.ts +30 -0
- package/src/utils/version-check.ts +72 -0
- package/test/commands/db-tenant-isolation.test.ts +94 -0
- package/test/commands/db.test.ts +85 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local vault SQLite open/create (C1).
|
|
3
|
+
*
|
|
4
|
+
* File lives at ~/.hq/db/{company}/vault.db with WAL journal mode.
|
|
5
|
+
* Never returns or logs remote connection strings.
|
|
6
|
+
*/
|
|
7
|
+
import Database from "better-sqlite3";
|
|
8
|
+
import { type LocalDbPathEnv } from "./paths.js";
|
|
9
|
+
export type LocalDb = Database.Database;
|
|
10
|
+
export interface OpenLocalDbOptions extends LocalDbPathEnv {
|
|
11
|
+
/** When true, do not create the file if missing (throws). Default false. */
|
|
12
|
+
readonly?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface LocalDbStatus {
|
|
15
|
+
company: string;
|
|
16
|
+
tier: "local";
|
|
17
|
+
path: string;
|
|
18
|
+
exists: boolean;
|
|
19
|
+
healthy: boolean;
|
|
20
|
+
journalMode: string | null;
|
|
21
|
+
/** Migration ledger head when present; null if ledger not initialized. */
|
|
22
|
+
schemaVersion: string | null;
|
|
23
|
+
/** Fingerprint of path for logs that prefer not to echo full home paths. */
|
|
24
|
+
pathFingerprint: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Short non-reversible fingerprint of a path (for status display).
|
|
28
|
+
* Not a secret — just avoids dumping full home paths when preferred.
|
|
29
|
+
*/
|
|
30
|
+
export declare function fingerprintPath(filePath: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Open (and create if missing) the company local vault DB with WAL mode.
|
|
33
|
+
* Idempotent: reopening an existing file does not recreate or wipe it.
|
|
34
|
+
*/
|
|
35
|
+
export declare function openLocalDb(companySlug: string, opts?: OpenLocalDbOptions): LocalDb;
|
|
36
|
+
/**
|
|
37
|
+
* Read migration head from platform ledger if the table exists.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readMigrationHead(db: LocalDb): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Ensure local DB exists (create if needed), report status, close handle.
|
|
42
|
+
* Safe for CLI status: never includes connection strings.
|
|
43
|
+
*/
|
|
44
|
+
export declare function ensureAndStatusLocalDb(companySlug: string, opts?: LocalDbPathEnv): LocalDbStatus;
|
|
45
|
+
/**
|
|
46
|
+
* Format status for CLI stdout (no secrets).
|
|
47
|
+
*/
|
|
48
|
+
export declare function formatLocalDbStatus(status: LocalDbStatus): string;
|
|
49
|
+
//# sourceMappingURL=local.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local vault SQLite open/create (C1).
|
|
3
|
+
*
|
|
4
|
+
* File lives at ~/.hq/db/{company}/vault.db with WAL journal mode.
|
|
5
|
+
* Never returns or logs remote connection strings.
|
|
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]="3cf7d852-6ced-5521-a8de-8da889a5b97c")}catch(e){}}();
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import Database from "better-sqlite3";
|
|
11
|
+
import { ensureLocalDbDir, resolveLocalDbPath, } from "./paths.js";
|
|
12
|
+
const MIGRATIONS_TABLE = "hq_schema_migrations";
|
|
13
|
+
/**
|
|
14
|
+
* Short non-reversible fingerprint of a path (for status display).
|
|
15
|
+
* Not a secret — just avoids dumping full home paths when preferred.
|
|
16
|
+
*/
|
|
17
|
+
export function fingerprintPath(filePath) {
|
|
18
|
+
let h = 2166136261;
|
|
19
|
+
for (let i = 0; i < filePath.length; i++) {
|
|
20
|
+
h ^= filePath.charCodeAt(i);
|
|
21
|
+
h = Math.imul(h, 16777619);
|
|
22
|
+
}
|
|
23
|
+
return `fp_${(h >>> 0).toString(16).padStart(8, "0")}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Open (and create if missing) the company local vault DB with WAL mode.
|
|
27
|
+
* Idempotent: reopening an existing file does not recreate or wipe it.
|
|
28
|
+
*/
|
|
29
|
+
export function openLocalDb(companySlug, opts) {
|
|
30
|
+
const dbPath = resolveLocalDbPath(companySlug, opts);
|
|
31
|
+
const exists = fs.existsSync(dbPath);
|
|
32
|
+
if (!exists) {
|
|
33
|
+
if (opts?.readonly) {
|
|
34
|
+
throw new Error(`local vault DB not found for company ${JSON.stringify(companySlug)} at ${dbPath}`);
|
|
35
|
+
}
|
|
36
|
+
ensureLocalDbDir(companySlug, opts);
|
|
37
|
+
}
|
|
38
|
+
const db = new Database(dbPath);
|
|
39
|
+
// WAL for concurrent readers; safe for agent/CLI workloads.
|
|
40
|
+
db.pragma("journal_mode = WAL");
|
|
41
|
+
db.pragma("foreign_keys = ON");
|
|
42
|
+
return db;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Read migration head from platform ledger if the table exists.
|
|
46
|
+
*/
|
|
47
|
+
export function readMigrationHead(db) {
|
|
48
|
+
try {
|
|
49
|
+
const row = db
|
|
50
|
+
.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name=?`)
|
|
51
|
+
.get(MIGRATIONS_TABLE);
|
|
52
|
+
if (!row?.name)
|
|
53
|
+
return null;
|
|
54
|
+
const head = db
|
|
55
|
+
.prepare(`SELECT version FROM ${MIGRATIONS_TABLE} ORDER BY version DESC LIMIT 1`)
|
|
56
|
+
.get();
|
|
57
|
+
return head?.version ?? null;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Ensure local DB exists (create if needed), report status, close handle.
|
|
65
|
+
* Safe for CLI status: never includes connection strings.
|
|
66
|
+
*/
|
|
67
|
+
export function ensureAndStatusLocalDb(companySlug, opts) {
|
|
68
|
+
const dbPath = resolveLocalDbPath(companySlug, opts);
|
|
69
|
+
const db = openLocalDb(companySlug, opts);
|
|
70
|
+
try {
|
|
71
|
+
const journalMode = String(db.pragma("journal_mode", { simple: true }));
|
|
72
|
+
const schemaVersion = readMigrationHead(db);
|
|
73
|
+
// Touch a trivial query to prove the handle is healthy.
|
|
74
|
+
db.prepare("SELECT 1 AS ok").get();
|
|
75
|
+
return {
|
|
76
|
+
company: companySlug.trim().toLowerCase(),
|
|
77
|
+
tier: "local",
|
|
78
|
+
path: dbPath,
|
|
79
|
+
exists: true,
|
|
80
|
+
healthy: true,
|
|
81
|
+
journalMode,
|
|
82
|
+
schemaVersion,
|
|
83
|
+
pathFingerprint: fingerprintPath(dbPath),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
db.close();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Format status for CLI stdout (no secrets).
|
|
92
|
+
*/
|
|
93
|
+
export function formatLocalDbStatus(status) {
|
|
94
|
+
const lines = [
|
|
95
|
+
`company: ${status.company}`,
|
|
96
|
+
`tier: ${status.tier}`,
|
|
97
|
+
`healthy: ${status.healthy ? "yes" : "no"}`,
|
|
98
|
+
`path: ${status.path}`,
|
|
99
|
+
`pathFingerprint: ${status.pathFingerprint}`,
|
|
100
|
+
`journalMode: ${status.journalMode ?? "unknown"}`,
|
|
101
|
+
`schemaVersion: ${status.schemaVersion ?? "(none)"}`,
|
|
102
|
+
];
|
|
103
|
+
return lines.join("\n");
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=local.js.map
|
|
106
|
+
//# debugId=3cf7d852-6ced-5521-a8de-8da889a5b97c
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault text migrations for local SQLite (vault-databases US-005).
|
|
3
|
+
*
|
|
4
|
+
* Migrations live as reviewable text under:
|
|
5
|
+
* companies/{company}/db/migrations/*.sql
|
|
6
|
+
* Applied versions are recorded in hq_schema_migrations inside the local DB.
|
|
7
|
+
*/
|
|
8
|
+
import type { LocalDb } from "./local.js";
|
|
9
|
+
import type { LocalDbPathEnv } from "./paths.js";
|
|
10
|
+
export declare const MIGRATIONS_TABLE = "hq_schema_migrations";
|
|
11
|
+
export interface MigrateOptions extends LocalDbPathEnv {
|
|
12
|
+
company: string;
|
|
13
|
+
/**
|
|
14
|
+
* Absolute path to HQ root containing companies/{co}/db/migrations.
|
|
15
|
+
* Required for vault-relative migrations.
|
|
16
|
+
*/
|
|
17
|
+
hqRoot: string;
|
|
18
|
+
}
|
|
19
|
+
export interface MigrateResult {
|
|
20
|
+
company: string;
|
|
21
|
+
migrationsDir: string;
|
|
22
|
+
applied: string[];
|
|
23
|
+
skipped: string[];
|
|
24
|
+
head: string | null;
|
|
25
|
+
}
|
|
26
|
+
export declare function resolveMigrationsDir(hqRoot: string, companySlug: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Ensure migrations directory exists (creates empty dir on first migrate).
|
|
29
|
+
*/
|
|
30
|
+
export declare function ensureMigrationsDir(hqRoot: string, companySlug: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* List pending migration files in lexical/version order (filename sort).
|
|
33
|
+
*/
|
|
34
|
+
export declare function listMigrationFiles(migrationsDir: string): string[];
|
|
35
|
+
export declare function ensureMigrationsLedger(db: LocalDb): void;
|
|
36
|
+
export declare function listAppliedVersions(db: LocalDb): Set<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Apply pending migrations. On failure, does not mark the failed file applied.
|
|
39
|
+
*/
|
|
40
|
+
export declare function migrateLocalDb(opts: MigrateOptions): MigrateResult;
|
|
41
|
+
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault text migrations for local SQLite (vault-databases US-005).
|
|
3
|
+
*
|
|
4
|
+
* Migrations live as reviewable text under:
|
|
5
|
+
* companies/{company}/db/migrations/*.sql
|
|
6
|
+
* Applied versions are recorded in hq_schema_migrations inside the local DB.
|
|
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]="d8abc231-bc36-5aad-a942-acbb0b86ea96")}catch(e){}}();
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { openLocalDb, readMigrationHead } from "./local.js";
|
|
13
|
+
import { normalizeCompanySlugForLocalDb } from "./paths.js";
|
|
14
|
+
export const MIGRATIONS_TABLE = "hq_schema_migrations";
|
|
15
|
+
export function resolveMigrationsDir(hqRoot, companySlug) {
|
|
16
|
+
const slug = normalizeCompanySlugForLocalDb(companySlug);
|
|
17
|
+
return path.join(hqRoot, "companies", slug, "db", "migrations");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Ensure migrations directory exists (creates empty dir on first migrate).
|
|
21
|
+
*/
|
|
22
|
+
export function ensureMigrationsDir(hqRoot, companySlug) {
|
|
23
|
+
const dir = resolveMigrationsDir(hqRoot, companySlug);
|
|
24
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
25
|
+
return dir;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* List pending migration files in lexical/version order (filename sort).
|
|
29
|
+
*/
|
|
30
|
+
export function listMigrationFiles(migrationsDir) {
|
|
31
|
+
if (!fs.existsSync(migrationsDir))
|
|
32
|
+
return [];
|
|
33
|
+
return fs
|
|
34
|
+
.readdirSync(migrationsDir)
|
|
35
|
+
.filter((f) => f.endsWith(".sql"))
|
|
36
|
+
.sort((a, b) => a.localeCompare(b, "en"));
|
|
37
|
+
}
|
|
38
|
+
export function ensureMigrationsLedger(db) {
|
|
39
|
+
db.exec(`
|
|
40
|
+
CREATE TABLE IF NOT EXISTS ${MIGRATIONS_TABLE} (
|
|
41
|
+
version TEXT PRIMARY KEY NOT NULL,
|
|
42
|
+
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
43
|
+
);
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
export function listAppliedVersions(db) {
|
|
47
|
+
ensureMigrationsLedger(db);
|
|
48
|
+
const rows = db
|
|
49
|
+
.prepare(`SELECT version FROM ${MIGRATIONS_TABLE} ORDER BY version`)
|
|
50
|
+
.all();
|
|
51
|
+
return new Set(rows.map((r) => r.version));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Apply pending migrations. On failure, does not mark the failed file applied.
|
|
55
|
+
*/
|
|
56
|
+
export function migrateLocalDb(opts) {
|
|
57
|
+
const company = normalizeCompanySlugForLocalDb(opts.company);
|
|
58
|
+
if (!opts.hqRoot?.trim()) {
|
|
59
|
+
throw new Error("hqRoot is required for vault migrations");
|
|
60
|
+
}
|
|
61
|
+
const migrationsDir = ensureMigrationsDir(opts.hqRoot, company);
|
|
62
|
+
const files = listMigrationFiles(migrationsDir);
|
|
63
|
+
const db = openLocalDb(company, opts);
|
|
64
|
+
const applied = [];
|
|
65
|
+
const skipped = [];
|
|
66
|
+
try {
|
|
67
|
+
ensureMigrationsLedger(db);
|
|
68
|
+
const already = listAppliedVersions(db);
|
|
69
|
+
for (const file of files) {
|
|
70
|
+
const version = file.replace(/\.sql$/i, "");
|
|
71
|
+
if (already.has(version) || already.has(file)) {
|
|
72
|
+
skipped.push(file);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const fullPath = path.join(migrationsDir, file);
|
|
76
|
+
const sql = fs.readFileSync(fullPath, "utf8");
|
|
77
|
+
const run = db.transaction(() => {
|
|
78
|
+
db.exec(sql);
|
|
79
|
+
db.prepare(`INSERT INTO ${MIGRATIONS_TABLE} (version) VALUES (?)`).run(version);
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
run();
|
|
83
|
+
applied.push(file);
|
|
84
|
+
already.add(version);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
88
|
+
throw new Error(`migration failed: ${file} — ${msg} (not marked applied)`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
company,
|
|
93
|
+
migrationsDir,
|
|
94
|
+
applied,
|
|
95
|
+
skipped,
|
|
96
|
+
head: readMigrationHead(db),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
db.close();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=migrate.js.map
|
|
104
|
+
//# debugId=d8abc231-bc36-5aad-a942-acbb0b86ea96
|
|
@@ -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
|