@indigoai-us/hq-cli 5.345.231 → 5.345.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +3 -2
- package/assets/lanes-reconcile/hq-lanes-reconcile.service +1 -1
- package/assets/scaffold/core/scripts/pipeline-conductor.sh +14 -14
- package/assets/scaffold/core/scripts/pipeline-driver.sh +7 -7
- package/assets/scaffold/core/scripts/session-project.sh +19 -4
- package/dist/command-catalog.generated.d.ts +213 -177
- package/dist/command-catalog.generated.js +263 -212
- package/dist/command-registration-plan.d.ts +6 -24
- package/dist/command-registration-plan.js +4 -8
- package/dist/commands/auth.js +3 -2
- package/dist/commands/core-pipeline-conductor-command.js +1 -1
- package/dist/commands/core-pipeline-conductor-native.js +5 -5
- package/dist/commands/core-pipeline-driver-native.js +5 -5
- package/dist/commands/daemon.js +7 -36
- package/dist/commands/deploy-access.js +6 -13
- package/dist/commands/deploy-comments.js +5 -13
- package/dist/commands/deploy-domains.js +6 -13
- package/dist/commands/deploy-list.js +25 -11
- package/dist/commands/deploy-mutations.d.ts +3 -0
- package/dist/commands/deploy-mutations.js +147 -0
- package/dist/commands/link.js +29 -0
- package/dist/commands/mesh.js +3 -1
- package/dist/commands/report.js +8 -9
- package/dist/data/command-states.json +10 -7
- package/dist/lib/bot/fleet-bots-update-pass.d.ts +8 -0
- package/dist/lib/bot/fleet-bots-update-pass.js +40 -0
- package/dist/lib/bot/fleet-bots-update-task.d.ts +12 -0
- package/dist/lib/bot/fleet-bots-update-task.js +52 -0
- package/dist/lib/bot/fleet-bots-update-worker-v1.d.ts +2 -0
- package/dist/lib/bot/fleet-bots-update-worker-v1.js +5 -0
- package/dist/lib/daemon/catalog.d.ts +8 -5
- package/dist/lib/daemon/catalog.js +15 -8
- package/dist/lib/daemon/lock.js +33 -37
- package/dist/lib/daemon/ops/skill-command.d.ts +99 -0
- package/dist/lib/daemon/ops/skill-command.js +260 -0
- package/dist/lib/daemon/protocol.d.ts +1 -1
- package/dist/lib/daemon/protocol.js +1 -0
- package/dist/lib/daemon/run.js +10 -18
- package/dist/lib/daemon/server.js +7 -0
- package/dist/lib/daemon/supervisor.d.ts +5 -0
- package/dist/lib/daemon/supervisor.js +17 -2
- package/dist/lib/db/app-ref.js +10 -15
- package/dist/lib/deploy-apps.d.ts +29 -0
- package/dist/lib/deploy-apps.js +37 -0
- package/dist/lib/doctor/checks/search-index.d.ts +16 -0
- package/dist/lib/doctor/checks/search-index.js +61 -0
- package/dist/lib/doctor/checks/stranded-lanes.js +1 -1
- package/dist/lib/doctor/registry.js +4 -0
- package/dist/lib/lanes/accounts.js +3 -3
- package/dist/lib/lanes/admission-host.js +1 -1
- package/dist/lib/lanes/admission.js +4 -4
- package/dist/lib/lanes/autopilot.js +2 -2
- package/dist/lib/lanes/blocker-freshness.js +1 -1
- package/dist/lib/lanes/compaction.js +5 -5
- package/dist/lib/lanes/delivery.js +1 -1
- package/dist/lib/lanes/depth-cap.js +1 -1
- package/dist/lib/lanes/disk-guard.js +1 -1
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/hooks-install.js +1 -1
- package/dist/lib/lanes/imported-question.js +1 -1
- package/dist/lib/lanes/keep-alive.d.ts +2 -2
- package/dist/lib/lanes/keep-alive.js +3 -3
- package/dist/lib/lanes/kr-freshness.js +1 -1
- package/dist/lib/lanes/links.js +4 -4
- package/dist/lib/lanes/loop.js +2 -2
- package/dist/lib/lanes/machine-identity.js +3 -3
- package/dist/lib/lanes/models.js +6 -6
- package/dist/lib/lanes/quota.js +1 -1
- package/dist/lib/lanes/reconcile-install.js +3 -3
- package/dist/lib/lanes/reconcile.js +16 -16
- package/dist/lib/lanes/remote-control-lane.js +6 -6
- package/dist/lib/lanes/reviews.js +2 -2
- package/dist/lib/lanes/spawn.js +24 -24
- package/dist/lib/lanes/status-fields.js +4 -4
- package/dist/lib/lanes/wait.js +4 -4
- package/dist/lib/lanes/watch.js +2 -2
- package/dist/lib/lanes/watcher-main.js +1 -1
- package/dist/lib/lanes/watcher.js +38 -38
- package/dist/lib/lanes/worker-process.js +5 -5
- package/dist/lib/mesh/live/daemon/pid-lock.d.ts +2 -4
- package/dist/lib/mesh/live/daemon/pid-lock.js +38 -55
- package/dist/utils/exclusive-lock.d.ts +60 -0
- package/dist/utils/exclusive-lock.js +65 -0
- package/package.json +8 -7
- package/dist/commands/staff/listings.d.ts +0 -41
- package/dist/commands/staff/listings.js +0 -160
- package/dist/commands/staff/reset-test-account.d.ts +0 -121
- package/dist/commands/staff/reset-test-account.js +0 -285
- package/dist/commands/staff/test-account.d.ts +0 -51
- package/dist/commands/staff/test-account.js +0 -196
|
@@ -35,7 +35,7 @@ async function boundedUsage(sampler, endedAt, waitMs) {
|
|
|
35
35
|
sampler.stop(endedAt),
|
|
36
36
|
new Promise((resolve) => {
|
|
37
37
|
timer = setTimeout(() => {
|
|
38
|
-
process.stderr.write("hq
|
|
38
|
+
process.stderr.write("hq runners: worker resource use was not ready in time; the exit record has none\n");
|
|
39
39
|
resolve(null);
|
|
40
40
|
}, waitMs);
|
|
41
41
|
// Not unref'd: this timer is what keeps the wrapper alive until the
|
|
@@ -44,7 +44,7 @@ async function boundedUsage(sampler, endedAt, waitMs) {
|
|
|
44
44
|
]);
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
47
|
-
process.stderr.write(`hq
|
|
47
|
+
process.stderr.write(`hq runners: could not measure worker resource use: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
50
|
finally {
|
|
@@ -79,7 +79,7 @@ export function runLaneWorkerProcess(command, args, env = process.env, cwd = pro
|
|
|
79
79
|
recordExit(exitPath, code, signal, endedAt, usage);
|
|
80
80
|
}
|
|
81
81
|
catch (error) {
|
|
82
|
-
process.stderr.write(`hq
|
|
82
|
+
process.stderr.write(`hq runners: could not persist worker exit status: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
return exitCodeFor(code, signal);
|
|
@@ -110,7 +110,7 @@ export function runLaneWorkerProcess(command, args, env = process.env, cwd = pro
|
|
|
110
110
|
});
|
|
111
111
|
};
|
|
112
112
|
child.once("error", (error) => {
|
|
113
|
-
process.stderr.write(`hq
|
|
113
|
+
process.stderr.write(`hq runners: worker process could not start: ${error.message}\n`);
|
|
114
114
|
end(127, null);
|
|
115
115
|
});
|
|
116
116
|
child.once("exit", (code, signal) => end(code, signal));
|
|
@@ -119,7 +119,7 @@ export function runLaneWorkerProcess(command, args, env = process.env, cwd = pro
|
|
|
119
119
|
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
120
120
|
const [command, ...args] = process.argv.slice(2);
|
|
121
121
|
if (!command) {
|
|
122
|
-
process.stderr.write("hq
|
|
122
|
+
process.stderr.write("hq runners: worker process command is missing\n");
|
|
123
123
|
process.exitCode = 2;
|
|
124
124
|
}
|
|
125
125
|
else {
|
|
@@ -9,10 +9,8 @@
|
|
|
9
9
|
* directory with a temp file inside (rmdir can never clear that class).
|
|
10
10
|
*/
|
|
11
11
|
import * as fs from "node:fs";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ts: number;
|
|
15
|
-
}
|
|
12
|
+
import { type PidLockRecord } from "../../../../utils/exclusive-lock.js";
|
|
13
|
+
export type { PidLockRecord };
|
|
16
14
|
export type PidLockResult = {
|
|
17
15
|
ok: true;
|
|
18
16
|
path: string;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* directory with a temp file inside (rmdir can never clear that class).
|
|
10
10
|
*/
|
|
11
11
|
import * as fs from "node:fs";
|
|
12
|
+
import { createLockFile, lockIsStale, parsePidLockRecord, readLockFile, releaseLockFile, } from "../../../../utils/exclusive-lock.js";
|
|
12
13
|
import { daemonDir, daemonPidPath } from "./paths.js";
|
|
13
14
|
function defaultAlive(pid) {
|
|
14
15
|
try {
|
|
@@ -20,29 +21,10 @@ function defaultAlive(pid) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
export function parsePidLock(content) {
|
|
23
|
-
|
|
24
|
-
for (const line of content.split("\n")) {
|
|
25
|
-
const i = line.indexOf("=");
|
|
26
|
-
if (i === -1)
|
|
27
|
-
continue;
|
|
28
|
-
fields[line.slice(0, i)] = line.slice(i + 1);
|
|
29
|
-
}
|
|
30
|
-
if (!/^\d+$/.test(fields.pid ?? "") || !/^\d+$/.test(fields.ts ?? "")) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
return { pid: Number(fields.pid), ts: Number(fields.ts) };
|
|
24
|
+
return parsePidLockRecord(content);
|
|
34
25
|
}
|
|
35
26
|
export function readPidLock(lockPath, deps = {}) {
|
|
36
|
-
|
|
37
|
-
const readFileSync = deps.readFileSync ?? fs.readFileSync;
|
|
38
|
-
if (!existsSync(lockPath))
|
|
39
|
-
return null;
|
|
40
|
-
try {
|
|
41
|
-
return parsePidLock(readFileSync(lockPath, "utf8"));
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
27
|
+
return readLockFile(lockPath, parsePidLockRecord, deps);
|
|
46
28
|
}
|
|
47
29
|
export function pidLockStatus(lockPath, deps) {
|
|
48
30
|
const record = readPidLock(lockPath, deps);
|
|
@@ -50,7 +32,11 @@ export function pidLockStatus(lockPath, deps) {
|
|
|
50
32
|
return "free";
|
|
51
33
|
return deps.isProcessAlive(record.pid) ? "held" : "stale";
|
|
52
34
|
}
|
|
53
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Bounded stale-takeover retries (exclusive create after unlink).
|
|
37
|
+
* Stale policy: pid only. A lock whose owner is unreadable or not alive is
|
|
38
|
+
* reclaimed at once; a live owner keeps it at any age.
|
|
39
|
+
*/
|
|
54
40
|
const STALE_TAKEOVER_ATTEMPTS = 3;
|
|
55
41
|
/**
|
|
56
42
|
* Acquire the single-file pid lock via exclusive create (`wx`).
|
|
@@ -67,9 +53,9 @@ export function acquirePidLock(dir, deps) {
|
|
|
67
53
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
68
54
|
const lockPath = daemonPidPath(dir);
|
|
69
55
|
const body = `pid=${deps.pid}\nts=${deps.now()}\n`;
|
|
56
|
+
const stale = { kind: "pid", alive: (pid) => deps.isProcessAlive(pid) };
|
|
70
57
|
for (let attempt = 0; attempt < STALE_TAKEOVER_ATTEMPTS; attempt += 1) {
|
|
71
|
-
|
|
72
|
-
writeFileSync(lockPath, body, { flag: "wx", mode: 0o600 });
|
|
58
|
+
if (createLockFile(lockPath, body, writeFileSync)) {
|
|
73
59
|
try {
|
|
74
60
|
chmodSync(lockPath, 0o600);
|
|
75
61
|
}
|
|
@@ -78,47 +64,44 @@ export function acquirePidLock(dir, deps) {
|
|
|
78
64
|
}
|
|
79
65
|
return { ok: true, path: lockPath };
|
|
80
66
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (ucode !== "ENOENT") {
|
|
96
|
-
const raced = readPidLock(lockPath, { readFileSync, existsSync });
|
|
97
|
-
if (raced && deps.isProcessAlive(raced.pid)) {
|
|
98
|
-
return { ok: false, reason: "held", owner: raced, path: lockPath };
|
|
99
|
-
}
|
|
100
|
-
throw unlinkErr;
|
|
67
|
+
const owner = readPidLock(lockPath, { readFileSync, existsSync });
|
|
68
|
+
if (owner && !lockIsStale(stale, { owner })) {
|
|
69
|
+
return { ok: false, reason: "held", owner, path: lockPath };
|
|
70
|
+
}
|
|
71
|
+
// Stale or unreadable: unlink and retry exclusive create.
|
|
72
|
+
try {
|
|
73
|
+
unlinkSync(lockPath);
|
|
74
|
+
}
|
|
75
|
+
catch (unlinkErr) {
|
|
76
|
+
const ucode = unlinkErr?.code;
|
|
77
|
+
if (ucode !== "ENOENT") {
|
|
78
|
+
const raced = readPidLock(lockPath, { readFileSync, existsSync });
|
|
79
|
+
if (raced && !lockIsStale(stale, { owner: raced })) {
|
|
80
|
+
return { ok: false, reason: "held", owner: raced, path: lockPath };
|
|
101
81
|
}
|
|
82
|
+
throw unlinkErr;
|
|
102
83
|
}
|
|
103
84
|
}
|
|
104
85
|
}
|
|
105
86
|
const finalOwner = readPidLock(lockPath, { readFileSync, existsSync });
|
|
106
|
-
if (finalOwner &&
|
|
87
|
+
if (finalOwner && !lockIsStale(stale, { owner: finalOwner })) {
|
|
107
88
|
return { ok: false, reason: "held", owner: finalOwner, path: lockPath };
|
|
108
89
|
}
|
|
109
90
|
throw new Error(`pid lock acquire failed after ${STALE_TAKEOVER_ATTEMPTS} attempts`);
|
|
110
91
|
}
|
|
111
92
|
export function releasePidLock(dir, deps) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
93
|
+
releaseLockFile(daemonPidPath(dir), {
|
|
94
|
+
read: (lockPath) => readPidLock(lockPath, deps),
|
|
95
|
+
owns: (record) => record.pid === deps.pid,
|
|
96
|
+
remove: (lockPath) => {
|
|
97
|
+
try {
|
|
98
|
+
(deps.unlinkSync ?? fs.unlinkSync)(lockPath);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
/* ignore */
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
});
|
|
122
105
|
}
|
|
123
106
|
export function defaultPidLockDeps(overrides = {}) {
|
|
124
107
|
return {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* Both paths fail with EEXIST when the lock is held, so contention, stale-
|
|
20
20
|
* owner reclamation and release are unchanged for every caller.
|
|
21
21
|
*/
|
|
22
|
+
import * as fs from "fs";
|
|
22
23
|
/** Test seam: forget what we learned about which filesystems do links. */
|
|
23
24
|
export declare function resetLinkSupportCache(): void;
|
|
24
25
|
/**
|
|
@@ -29,4 +30,63 @@ export declare function resetLinkSupportCache(): void;
|
|
|
29
30
|
* are written directly. Either way the lock ends up holding the same bytes.
|
|
30
31
|
*/
|
|
31
32
|
export declare function acquireLockFileExclusively(candidate: string, lockFile: string, dirKey: string): void;
|
|
33
|
+
/** A `pid=<n>\nts=<unix seconds>` lock file (the daemon and mesh daemon pid locks). */
|
|
34
|
+
export interface PidLockRecord {
|
|
35
|
+
pid: number;
|
|
36
|
+
ts: number;
|
|
37
|
+
}
|
|
38
|
+
/** Parse a `pid=<n>\nts=<n>` body; null unless both fields are plain digits. */
|
|
39
|
+
export declare function parsePidLockRecord(content: string): PidLockRecord | null;
|
|
40
|
+
export interface LockFileReadDeps {
|
|
41
|
+
existsSync?: typeof fs.existsSync;
|
|
42
|
+
readFileSync?: typeof fs.readFileSync;
|
|
43
|
+
}
|
|
44
|
+
/** Read and parse a lock file. A missing file, a read error or a parse error is null. */
|
|
45
|
+
export declare function readLockFile<T>(lockPath: string, parse: (content: string) => T | null, deps?: LockFileReadDeps): T | null;
|
|
46
|
+
/**
|
|
47
|
+
* Create `lockPath` with `body` exclusively (`wx`, mode 0600). True when this
|
|
48
|
+
* call created it, false when it already exists (EEXIST); any other error is
|
|
49
|
+
* thrown.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createLockFile(lockPath: string, body: string, writeFileSync?: typeof fs.writeFileSync): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* When a held lock may be reclaimed. Each caller passes the rule it has
|
|
54
|
+
* always used; the module does not choose one.
|
|
55
|
+
*
|
|
56
|
+
* - `pid`: stale unless the recorded owner is readable, is not `self` (when
|
|
57
|
+
* given) and `alive(owner.pid)` is true. No age limit: a live owner keeps
|
|
58
|
+
* the lock however old it is. `alive` is not called for `self`.
|
|
59
|
+
* - `age`: stale unless the lock's age is at most `maxAgeMs` (an age that
|
|
60
|
+
* is not a number is stale).
|
|
61
|
+
* - `none`: never stale.
|
|
62
|
+
*/
|
|
63
|
+
export type StalePolicy = {
|
|
64
|
+
kind: "pid";
|
|
65
|
+
alive: (pid: number) => boolean;
|
|
66
|
+
self?: number;
|
|
67
|
+
} | {
|
|
68
|
+
kind: "age";
|
|
69
|
+
maxAgeMs: number;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "none";
|
|
72
|
+
};
|
|
73
|
+
/** What the caller observed about the held lock: its owner (pid policy) or its age (age policy). */
|
|
74
|
+
export type LockObservation = {
|
|
75
|
+
owner: {
|
|
76
|
+
pid: number;
|
|
77
|
+
} | null;
|
|
78
|
+
} | {
|
|
79
|
+
ageMs: number;
|
|
80
|
+
};
|
|
81
|
+
export declare function lockIsStale(policy: StalePolicy, observed: LockObservation): boolean;
|
|
82
|
+
export interface LockFileRelease<T> {
|
|
83
|
+
/** Read the current owner; null when there is none or it is unreadable. */
|
|
84
|
+
read: (lockPath: string) => T | null;
|
|
85
|
+
/** The owner is this holder. */
|
|
86
|
+
owns: (owner: T) => boolean;
|
|
87
|
+
/** Remove the lock file (the caller's own error handling). */
|
|
88
|
+
remove: (lockPath: string) => void;
|
|
89
|
+
}
|
|
90
|
+
/** Remove the lock only when this holder owns it. True when `remove` ran. */
|
|
91
|
+
export declare function releaseLockFile<T>(lockPath: string, release: LockFileRelease<T>): boolean;
|
|
32
92
|
//# sourceMappingURL=exclusive-lock.d.ts.map
|
|
@@ -72,4 +72,69 @@ export function acquireLockFileExclusively(candidate, lockFile, dirKey) {
|
|
|
72
72
|
mode: 0o600,
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
/** Parse a `pid=<n>\nts=<n>` body; null unless both fields are plain digits. */
|
|
76
|
+
export function parsePidLockRecord(content) {
|
|
77
|
+
const fields = {};
|
|
78
|
+
for (const line of content.split("\n")) {
|
|
79
|
+
const i = line.indexOf("=");
|
|
80
|
+
if (i === -1)
|
|
81
|
+
continue;
|
|
82
|
+
fields[line.slice(0, i)] = line.slice(i + 1);
|
|
83
|
+
}
|
|
84
|
+
if (!/^\d+$/.test(fields.pid ?? "") || !/^\d+$/.test(fields.ts ?? "")) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return { pid: Number(fields.pid), ts: Number(fields.ts) };
|
|
88
|
+
}
|
|
89
|
+
/** Read and parse a lock file. A missing file, a read error or a parse error is null. */
|
|
90
|
+
export function readLockFile(lockPath, parse, deps = {}) {
|
|
91
|
+
const existsSync = deps.existsSync ?? fs.existsSync;
|
|
92
|
+
const readFileSync = deps.readFileSync ?? fs.readFileSync;
|
|
93
|
+
if (!existsSync(lockPath))
|
|
94
|
+
return null;
|
|
95
|
+
try {
|
|
96
|
+
return parse(readFileSync(lockPath, "utf8"));
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create `lockPath` with `body` exclusively (`wx`, mode 0600). True when this
|
|
104
|
+
* call created it, false when it already exists (EEXIST); any other error is
|
|
105
|
+
* thrown.
|
|
106
|
+
*/
|
|
107
|
+
export function createLockFile(lockPath, body, writeFileSync = fs.writeFileSync) {
|
|
108
|
+
try {
|
|
109
|
+
writeFileSync(lockPath, body, { flag: "wx", mode: 0o600 });
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error?.code === "EEXIST")
|
|
114
|
+
return false;
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function lockIsStale(policy, observed) {
|
|
119
|
+
switch (policy.kind) {
|
|
120
|
+
case "none":
|
|
121
|
+
return false;
|
|
122
|
+
case "pid": {
|
|
123
|
+
const owner = "owner" in observed ? observed.owner : null;
|
|
124
|
+
return !(owner && owner.pid !== policy.self && policy.alive(owner.pid));
|
|
125
|
+
}
|
|
126
|
+
case "age": {
|
|
127
|
+
const ageMs = "ageMs" in observed ? observed.ageMs : Number.NaN;
|
|
128
|
+
return !(ageMs <= policy.maxAgeMs);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Remove the lock only when this holder owns it. True when `remove` ran. */
|
|
133
|
+
export function releaseLockFile(lockPath, release) {
|
|
134
|
+
const owner = release.read(lockPath);
|
|
135
|
+
if (owner === null || !release.owns(owner))
|
|
136
|
+
return false;
|
|
137
|
+
release.remove(lockPath);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
75
140
|
//# sourceMappingURL=exclusive-lock.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.345.
|
|
3
|
+
"version": "5.345.232",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"!dist/**/__testing__",
|
|
15
15
|
"!dist/**/*.test-d.*",
|
|
16
16
|
"!dist/lib/test-utils",
|
|
17
|
+
"!dist/staff",
|
|
17
18
|
"!dist/lib/decisions/fixtures",
|
|
18
19
|
"!dist/lib/fingerprint/fixtures.*",
|
|
19
20
|
"assets/scaffold",
|
|
@@ -125,11 +126,11 @@
|
|
|
125
126
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
126
127
|
},
|
|
127
128
|
"optionalDependencies": {
|
|
128
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
129
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
130
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
131
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
133
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
129
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.232",
|
|
130
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.232",
|
|
131
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.232",
|
|
132
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.232",
|
|
133
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.232",
|
|
134
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.232"
|
|
134
135
|
}
|
|
135
136
|
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Command } from "commander";
|
|
2
|
-
/**
|
|
3
|
-
* `hq staff listings {queue|approve|reject}` — marketplace moderation from the
|
|
4
|
-
* CLI. Thin wrappers over the vault-service moderation routes:
|
|
5
|
-
*
|
|
6
|
-
* GET /v1/moderation/queue (queue)
|
|
7
|
-
* POST /v1/moderation/listings/{id} (approve | reject, body { action, note? })
|
|
8
|
-
*
|
|
9
|
-
* Every `hq publish` lands as `pending_review` and stays off the public
|
|
10
|
-
* marketplace until a staff member decides it. Before this command the only
|
|
11
|
-
* way to decide was the GTM admin web page. The server owns authorization
|
|
12
|
-
* (`isStaffEmail` on the id_token's email claim) and the state machine
|
|
13
|
-
* (pending_review -> approved | rejected, optimistic lock, superseding older
|
|
14
|
-
* approved versions). The moderation gate reads the `email` claim, which only
|
|
15
|
-
* the id_token carries, so this file uses `ensureCognitoIdToken`.
|
|
16
|
-
*/
|
|
17
|
-
export interface QueueItem {
|
|
18
|
-
listingId: string;
|
|
19
|
-
type?: string;
|
|
20
|
-
status?: string;
|
|
21
|
-
creatorHandle?: string;
|
|
22
|
-
name?: string;
|
|
23
|
-
slug?: string;
|
|
24
|
-
version?: string;
|
|
25
|
-
summary?: string;
|
|
26
|
-
createdAt?: string;
|
|
27
|
-
injectionScan?: {
|
|
28
|
-
flagged?: boolean;
|
|
29
|
-
flags?: unknown[];
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export declare function renderQueue(items: QueueItem[]): string;
|
|
33
|
-
export declare function runListingsQueue(): Promise<void>;
|
|
34
|
-
export interface RunDecisionParams {
|
|
35
|
-
listingId: string;
|
|
36
|
-
note?: string;
|
|
37
|
-
}
|
|
38
|
-
export declare function runApproveListing(params: RunDecisionParams): Promise<void>;
|
|
39
|
-
export declare function runRejectListing(params: RunDecisionParams): Promise<void>;
|
|
40
|
-
export declare function registerListingsCommand(staff: Command): Command;
|
|
41
|
-
//# sourceMappingURL=listings.d.ts.map
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { ensureCognitoIdToken } from "../../utils/cognito-session.js";
|
|
3
|
-
import { vaultApiFetch } from "../../utils/vault-api.js";
|
|
4
|
-
import { callerEmailFromToken, isStaffEmail } from "./reset-test-account.js";
|
|
5
|
-
// ── Rendering ───────────────────────────────────────────────────────────────
|
|
6
|
-
function renderQueueLine(item) {
|
|
7
|
-
const pack = `${item.slug ?? item.name ?? "?"}@${item.version ?? "?"}`;
|
|
8
|
-
const creator = item.creatorHandle ? `@${item.creatorHandle}` : chalk.dim("(no handle)");
|
|
9
|
-
const flag = item.injectionScan?.flagged
|
|
10
|
-
? chalk.yellow(` flagged (${item.injectionScan.flags?.length ?? 0})`)
|
|
11
|
-
: "";
|
|
12
|
-
const when = item.createdAt ? chalk.dim(` ${item.createdAt}`) : "";
|
|
13
|
-
return ` ${item.listingId} ${pack.padEnd(28)} ${(item.type ?? "").padEnd(6)} ${creator}${when}${flag}`;
|
|
14
|
-
}
|
|
15
|
-
export function renderQueue(items) {
|
|
16
|
-
if (items.length === 0) {
|
|
17
|
-
return chalk.dim("\n(no listings waiting for review)");
|
|
18
|
-
}
|
|
19
|
-
const lines = [chalk.bold(`\nListings waiting for review (${items.length}, oldest first)`)];
|
|
20
|
-
for (const item of items)
|
|
21
|
-
lines.push(renderQueueLine(item));
|
|
22
|
-
lines.push(chalk.dim("\nApprove with `hq staff listings approve <id>`, reject with `hq staff listings reject <id> --note <reason>`."));
|
|
23
|
-
return lines.join("\n");
|
|
24
|
-
}
|
|
25
|
-
// ── Shared helpers ──────────────────────────────────────────────────────────
|
|
26
|
-
async function readBody(res) {
|
|
27
|
-
try {
|
|
28
|
-
return (await res.json());
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function renderApiError(status, body) {
|
|
35
|
-
const code = typeof body.code === "string" ? body.code : undefined;
|
|
36
|
-
const message = typeof body.error === "string" ? body.error : `request failed (${status})`;
|
|
37
|
-
return code ? `${code}: ${message}` : message;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Local staff preflight so a non-staff caller stops before the round trip.
|
|
41
|
-
* The server remains the authorization boundary.
|
|
42
|
-
*/
|
|
43
|
-
async function requireStaffIdToken() {
|
|
44
|
-
const token = await ensureCognitoIdToken();
|
|
45
|
-
const callerEmail = callerEmailFromToken(token);
|
|
46
|
-
if (!callerEmail || !isStaffEmail(callerEmail)) {
|
|
47
|
-
throw new Error("hq staff listings requires a staff HQ session (@getindigo.ai, @hqforwork.com or @vyg.ai). " +
|
|
48
|
-
"Sign in with a staff account and retry.");
|
|
49
|
-
}
|
|
50
|
-
return token;
|
|
51
|
-
}
|
|
52
|
-
const LISTING_ID_RE = /^lst_[0-9A-Za-z]+$/;
|
|
53
|
-
function requireListingId(listingId) {
|
|
54
|
-
const id = listingId.trim();
|
|
55
|
-
if (!LISTING_ID_RE.test(id)) {
|
|
56
|
-
throw new Error(`"${listingId}" is not a listing id (expected lst_…). Run \`hq staff listings queue\` to see ids.`);
|
|
57
|
-
}
|
|
58
|
-
return id;
|
|
59
|
-
}
|
|
60
|
-
// ── Runners ─────────────────────────────────────────────────────────────────
|
|
61
|
-
export async function runListingsQueue() {
|
|
62
|
-
const token = await requireStaffIdToken();
|
|
63
|
-
const res = await vaultApiFetch({ token, path: "/v1/moderation/queue", method: "GET" });
|
|
64
|
-
const parsed = await readBody(res);
|
|
65
|
-
if (!res.ok)
|
|
66
|
-
throw new Error(renderApiError(res.status, parsed));
|
|
67
|
-
const queue = parsed.queue;
|
|
68
|
-
if (!Array.isArray(queue))
|
|
69
|
-
throw new Error("server did not return a moderation queue");
|
|
70
|
-
console.log(renderQueue(queue));
|
|
71
|
-
}
|
|
72
|
-
async function decide(action, params) {
|
|
73
|
-
const id = requireListingId(params.listingId);
|
|
74
|
-
const token = await requireStaffIdToken();
|
|
75
|
-
const body = { action };
|
|
76
|
-
if (params.note !== undefined && params.note.trim().length > 0)
|
|
77
|
-
body.note = params.note.trim();
|
|
78
|
-
const res = await vaultApiFetch({
|
|
79
|
-
token,
|
|
80
|
-
path: `/v1/moderation/listings/${encodeURIComponent(id)}`,
|
|
81
|
-
method: "POST",
|
|
82
|
-
body,
|
|
83
|
-
});
|
|
84
|
-
const parsed = await readBody(res);
|
|
85
|
-
if (!res.ok) {
|
|
86
|
-
const msg = renderApiError(res.status, parsed);
|
|
87
|
-
if (res.status === 409) {
|
|
88
|
-
throw new Error(`${msg} (the listing is no longer pending, or someone decided it at the same time)`);
|
|
89
|
-
}
|
|
90
|
-
throw new Error(msg);
|
|
91
|
-
}
|
|
92
|
-
return parsed;
|
|
93
|
-
}
|
|
94
|
-
function labelOf(listing, fallbackId) {
|
|
95
|
-
if (!listing)
|
|
96
|
-
return fallbackId;
|
|
97
|
-
return `${listing.slug ?? listing.name ?? fallbackId}@${listing.version ?? "?"} (${listing.listingId ?? fallbackId})`;
|
|
98
|
-
}
|
|
99
|
-
export async function runApproveListing(params) {
|
|
100
|
-
const result = await decide("approve", params);
|
|
101
|
-
console.log(chalk.green(`\n✓ approved ${labelOf(result.listing, params.listingId)}`));
|
|
102
|
-
const superseded = result.superseded ?? [];
|
|
103
|
-
if (superseded.length > 0) {
|
|
104
|
-
console.log(chalk.dim(` superseded older versions: ${superseded.join(", ")}`));
|
|
105
|
-
}
|
|
106
|
-
console.log(chalk.dim(" It is now live in the marketplace (the public pack page refreshes within ~10 minutes)."));
|
|
107
|
-
}
|
|
108
|
-
export async function runRejectListing(params) {
|
|
109
|
-
const result = await decide("reject", params);
|
|
110
|
-
console.log(chalk.yellow(`\n✗ rejected ${labelOf(result.listing, params.listingId)}`));
|
|
111
|
-
}
|
|
112
|
-
// ── Commander wiring ────────────────────────────────────────────────────────
|
|
113
|
-
function fail(err) {
|
|
114
|
-
console.error(chalk.red(err instanceof Error ? err.message : String(err)));
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
export function registerListingsCommand(staff) {
|
|
118
|
-
const group = staff
|
|
119
|
-
.command("listings")
|
|
120
|
-
.description("Review marketplace listings waiting for approval (staff only). Wraps /v1/moderation.");
|
|
121
|
-
group
|
|
122
|
-
.command("queue")
|
|
123
|
-
.description("List published packs waiting for review, oldest first.")
|
|
124
|
-
.action(async () => {
|
|
125
|
-
try {
|
|
126
|
-
await runListingsQueue();
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
fail(err);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
group
|
|
133
|
-
.command("approve")
|
|
134
|
-
.description("Approve a pending listing so it goes live (older approved versions are superseded).")
|
|
135
|
-
.argument("<listingId>", "Listing id from `hq staff listings queue` (lst_…)")
|
|
136
|
-
.option("--note <text>", "Reviewer note recorded on the listing")
|
|
137
|
-
.action(async (listingId, opts) => {
|
|
138
|
-
try {
|
|
139
|
-
await runApproveListing({ listingId, note: opts.note });
|
|
140
|
-
}
|
|
141
|
-
catch (err) {
|
|
142
|
-
fail(err);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
group
|
|
146
|
-
.command("reject")
|
|
147
|
-
.description("Reject a pending listing.")
|
|
148
|
-
.argument("<listingId>", "Listing id from `hq staff listings queue` (lst_…)")
|
|
149
|
-
.requiredOption("--note <reason>", "Why it was rejected (recorded on the listing)")
|
|
150
|
-
.action(async (listingId, opts) => {
|
|
151
|
-
try {
|
|
152
|
-
await runRejectListing({ listingId, note: opts.note });
|
|
153
|
-
}
|
|
154
|
-
catch (err) {
|
|
155
|
-
fail(err);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
return group;
|
|
159
|
-
}
|
|
160
|
-
//# sourceMappingURL=listings.js.map
|