@indigoai-us/hq-cli 5.345.226 → 5.345.228
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 +142 -0
- package/dist/command-catalog.generated.d.ts +137 -0
- package/dist/command-catalog.generated.js +164 -0
- package/dist/commands/auth.d.ts +2 -2
- package/dist/commands/auth.js +3 -3
- package/dist/commands/core-delegate-w1b.js +92 -69
- package/dist/commands/core-delegate.d.ts +19 -1
- package/dist/commands/core-delegate.js +411 -6
- package/dist/commands/core-dm-bind-native.js +2 -1
- package/dist/commands/core-handoff.d.ts +5 -0
- package/dist/commands/core-handoff.js +1008 -14
- package/dist/commands/core-pin-native.d.ts +1 -0
- package/dist/commands/core-pin-native.js +3 -15
- package/dist/commands/core-register-project-native.d.ts +6 -0
- package/dist/commands/core-register-project-native.js +182 -52
- package/dist/commands/core-work-mesh-bind-trusted-native.js +4 -9
- package/dist/commands/daemon.js +2 -2
- package/dist/commands/index-cmd.d.ts +3 -1
- package/dist/commands/index-cmd.js +12 -0
- package/dist/commands/lanes-checks.js +1 -1
- package/dist/commands/lanes-session-start.d.ts +1 -2
- package/dist/commands/lanes-session-start.js +9 -145
- package/dist/commands/lanes-shared.d.ts +3 -0
- package/dist/commands/lanes.d.ts +3 -0
- package/dist/commands/lanes.js +94 -27
- package/dist/commands/link.d.ts +8 -3
- package/dist/commands/link.js +14 -17
- package/dist/commands/mcp-registration.d.ts +65 -7
- package/dist/commands/mcp-registration.js +289 -51
- package/dist/commands/mesh.d.ts +12 -0
- package/dist/commands/mesh.js +92 -10
- package/dist/commands/reindex.js +6 -0
- package/dist/commands/repo.d.ts +13 -0
- package/dist/commands/repo.js +39 -1
- package/dist/commands/sync-mode.d.ts +3 -1
- package/dist/commands/sync-mode.js +11 -1
- package/dist/lazy-commands.js +3 -4
- package/dist/lib/checkpoint-ontology/entity-file.js +4 -4
- package/dist/lib/checkpoint-ontology/merge-copies.js +7 -11
- package/dist/lib/checkpoint-ontology/plan.js +2 -1
- package/dist/lib/core-utils/archive-old-threads.js +5 -2
- package/dist/lib/core-utils/session-company.d.ts +13 -1
- package/dist/lib/core-utils/session-company.js +75 -4
- package/dist/lib/core-utils/worktree-resume.d.ts +6 -0
- package/dist/lib/core-utils/worktree-resume.js +8 -4
- package/dist/lib/daemon/background-qos.d.ts +7 -0
- package/dist/lib/daemon/background-qos.js +13 -0
- package/dist/lib/daemon/catalog.d.ts +9 -0
- package/dist/lib/daemon/catalog.js +8 -1
- package/dist/lib/daemon/hook-requests-acl-suggest.d.ts +18 -0
- package/dist/lib/daemon/hook-requests-acl-suggest.js +245 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +32 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.js +214 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.d.ts +44 -0
- package/dist/lib/daemon/hook-requests-mesh-tool-writes.js +292 -0
- package/dist/lib/daemon/hook-requests-mesh.d.ts +54 -0
- package/dist/lib/daemon/hook-requests-mesh.js +559 -0
- package/dist/lib/daemon/hook-requests.d.ts +349 -8
- package/dist/lib/daemon/hook-requests.js +1312 -46
- package/dist/lib/daemon/machine-checks.d.ts +12 -2
- package/dist/lib/daemon/machine-checks.js +27 -10
- package/dist/lib/daemon/merge-sections.d.ts +24 -2
- package/dist/lib/daemon/merge-sections.js +58 -16
- package/dist/lib/daemon/ops/policy.js +4 -2
- package/dist/lib/daemon/resolver.js +9 -2
- package/dist/lib/daemon/run.d.ts +11 -7
- package/dist/lib/daemon/run.js +168 -24
- package/dist/lib/daemon/search-index-worker-v1.d.ts +2 -0
- package/dist/lib/daemon/search-index-worker-v1.js +25 -0
- package/dist/lib/daemon/session-registry.d.ts +0 -1
- package/dist/lib/daemon/session-registry.js +0 -3
- package/dist/lib/daemon/supervisor.d.ts +3 -1
- package/dist/lib/daemon/supervisor.js +1 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +59 -4
- package/dist/lib/daemon/tcc-eperm.js +110 -8
- package/dist/lib/doctor/fix/process-identity.d.ts +20 -2
- package/dist/lib/doctor/fix/process-identity.js +48 -5
- package/dist/lib/hook-engine/canary-gate.js +1 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
- package/dist/lib/hot-channels/adapters/attio.js +2 -1
- package/dist/lib/hot-channels/adapters/meetings.js +2 -1
- package/dist/lib/lanes/company-outposts.d.ts +37 -0
- package/dist/lib/lanes/company-outposts.js +164 -0
- package/dist/lib/lanes/liveness.d.ts +6 -0
- package/dist/lib/lanes/liveness.js +49 -8
- package/dist/lib/lanes/orphan-report.d.ts +15 -0
- package/dist/lib/lanes/orphan-report.js +223 -0
- package/dist/lib/lanes/orphan-sweep.d.ts +26 -0
- package/dist/lib/lanes/orphan-sweep.js +152 -0
- package/dist/lib/lanes/reaper.d.ts +2 -0
- package/dist/lib/lanes/reaper.js +11 -8
- package/dist/lib/lanes/reconcile.d.ts +8 -7
- package/dist/lib/lanes/reconcile.js +39 -0
- package/dist/lib/mesh/live/backfill-held.d.ts +13 -0
- package/dist/lib/mesh/live/backfill-held.js +23 -0
- package/dist/lib/mesh/live/daemon/mode.d.ts +8 -4
- package/dist/lib/mesh/live/daemon/mode.js +8 -4
- package/dist/lib/mesh/live/daemon/run.d.ts +14 -3
- package/dist/lib/mesh/live/daemon/run.js +116 -7
- package/dist/lib/mesh/live/direct-drain.d.ts +123 -0
- package/dist/lib/mesh/live/direct-drain.js +315 -0
- package/dist/lib/mesh/live/emit-replay.d.ts +10 -0
- package/dist/lib/mesh/live/emit-replay.js +10 -0
- package/dist/lib/mesh/live/flush.d.ts +15 -0
- package/dist/lib/mesh/live/flush.js +27 -0
- package/dist/lib/mesh/live/liveness-carry.d.ts +45 -0
- package/dist/lib/mesh/live/liveness-carry.js +141 -0
- package/dist/lib/mesh/live/spool.d.ts +19 -0
- package/dist/lib/mesh/live/spool.js +80 -0
- package/dist/lib/safe-store.d.ts +2 -0
- package/dist/lib/safe-store.js +8 -6
- package/dist/lib/search-index/index.d.ts +9 -3
- package/dist/lib/search-index/index.js +35 -10
- package/dist/lib/search-index/worker-process.d.ts +9 -0
- package/dist/lib/search-index/worker-process.js +171 -0
- package/dist/lib/session-company-lock.d.ts +3 -1
- package/dist/lib/session-company-lock.js +3 -2
- package/dist/utils/delegate-command-supervisor.d.ts +3 -0
- package/dist/utils/delegate-command-supervisor.js +44 -0
- package/dist/utils/delegate-lock.d.ts +12 -0
- package/dist/utils/delegate-lock.js +88 -0
- package/dist/utils/frontmatter.d.ts +27 -0
- package/dist/utils/frontmatter.js +33 -0
- package/dist/utils/hook-trust.d.ts +1 -0
- package/dist/utils/hook-trust.js +18 -2
- package/dist/utils/host-registration.d.ts +13 -1
- package/dist/utils/host-registration.js +98 -5
- package/dist/utils/package-use-lease.d.ts +1 -1
- package/dist/utils/package-use-lease.js +15 -7
- package/docs/anywhere-runtime.md +17 -0
- package/package.json +8 -7
- package/scripts/check-function-manifest.mjs +17 -3
|
@@ -8,6 +8,7 @@ export type PinDependencies = {
|
|
|
8
8
|
now: () => Date;
|
|
9
9
|
tmpDir?: string;
|
|
10
10
|
};
|
|
11
|
+
/** The shared session-id resolver (US-030 c2): env keys first, then workspace/sessions/.current. */
|
|
11
12
|
export declare function resolvePinSessionId(root: string, env: NodeJS.ProcessEnv): string;
|
|
12
13
|
export declare function runPin(args: string[], deps: PinDependencies): UtilityOutput;
|
|
13
14
|
export declare function registerCorePinNative(core: Command): void;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
|
+
import { resolveSessionId } from "../lib/core-utils/session-id.js";
|
|
5
6
|
import { resolveLiveRoot } from "../utils/hq-roots.js";
|
|
6
7
|
import { bundledShellUnboundValue, registerNativeUtility, utilityError } from "./core-native-utilities.js";
|
|
7
8
|
export const PIN_ASSET = "core/scripts/hq-pin.sh";
|
|
@@ -20,23 +21,10 @@ export const PIN_HELP = `# hq-pin.sh — anchor the current session to one goal
|
|
|
20
21
|
#
|
|
21
22
|
# Storage: workspace/sessions/<sid>/pin.md plus \`pin: <goal>\` in the session's
|
|
22
23
|
`;
|
|
23
|
-
const SESSION_ENV_KEYS = ["HQ_SESSION_ID", "CLAUDE_CODE_SESSION_ID", "CLAUDE_SESSION_ID", "CODEX_SESSION_ID", "CODEX_THREAD_ID", "GROK_SESSION_ID", "HQ_FLEET_SESSION_ID"];
|
|
24
24
|
const stamp = (date) => date.toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
25
|
-
|
|
26
|
-
function validId(value) { return value !== "" && value !== "." && value !== ".." && /^[A-Za-z0-9._-]+$/.test(value); }
|
|
25
|
+
/** The shared session-id resolver (US-030 c2): env keys first, then workspace/sessions/.current. */
|
|
27
26
|
export function resolvePinSessionId(root, env) {
|
|
28
|
-
|
|
29
|
-
const value = normalizeId(env[key] ?? "");
|
|
30
|
-
if (validId(value))
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const value = normalizeId(fs.readFileSync(path.join(root, "workspace/sessions/.current"), "utf8"));
|
|
35
|
-
return validId(value) ? value : "";
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return "";
|
|
39
|
-
}
|
|
27
|
+
return resolveSessionId(root, env);
|
|
40
28
|
}
|
|
41
29
|
function pinPath(deps, sid) { return path.join(deps.root, "workspace/sessions", sid, "pin.md"); }
|
|
42
30
|
function fail(message) { return utilityError(`hq-pin: ${message}`, 2); }
|
|
@@ -17,7 +17,13 @@ export type RegisterProjectDeps = {
|
|
|
17
17
|
stdout: string;
|
|
18
18
|
stderr: string;
|
|
19
19
|
};
|
|
20
|
+
/** Runs `bash <script> get company_slug`; code is null when it did not exit normally. */
|
|
21
|
+
runSession?: (script: string, env: NodeJS.ProcessEnv, cwd: string) => {
|
|
22
|
+
code: number | null;
|
|
23
|
+
stdout: string;
|
|
24
|
+
};
|
|
20
25
|
};
|
|
26
|
+
export declare function createRegisterProjectSessionRunner(spawn?: typeof spawnSync): NonNullable<RegisterProjectDeps["runSession"]>;
|
|
21
27
|
export declare function createRegisterProjectHqRunner(spawn?: typeof spawnSync): RegisterProjectDeps["runHq"];
|
|
22
28
|
type NativeResult = {
|
|
23
29
|
code: number;
|
|
@@ -7,8 +7,20 @@ import { serializeJqJson } from "../lib/core-utils/jq-json-serializer.js";
|
|
|
7
7
|
import { resolveBundledAsset } from "../utils/hq-roots-core.js";
|
|
8
8
|
import { buildSpawnPlan } from "../utils/windows-spawn.js";
|
|
9
9
|
export const REGISTER_PROJECT_ASSET = "core/scripts/register-project.sh";
|
|
10
|
-
const USAGE = "usage: register-project.sh <company> <project> | --
|
|
10
|
+
const USAGE = "usage: register-project.sh <company> <project> | --board <company> <board-project-id> | --audit <company> | --backfill <company> --only-active [--yes] | --retry-pending <company>";
|
|
11
11
|
const MIN_HQ_CLI = "5.139.0";
|
|
12
|
+
// hq-session.sh answers from local files; a hung answer must not hang
|
|
13
|
+
// registration. A run that does not finish in time counts as no answer.
|
|
14
|
+
const SESSION_TIMEOUT_MS = 10_000;
|
|
15
|
+
export function createRegisterProjectSessionRunner(spawn = spawnSync) {
|
|
16
|
+
return (script, env, cwd) => {
|
|
17
|
+
const result = spawn("bash", [script, "get", "company_slug"], {
|
|
18
|
+
cwd, env, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: SESSION_TIMEOUT_MS,
|
|
19
|
+
});
|
|
20
|
+
return { code: result.error ? null : result.status, stdout: String(result.stdout ?? "") };
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const defaultRunSession = createRegisterProjectSessionRunner();
|
|
12
24
|
export function createRegisterProjectHqRunner(spawn = spawnSync) {
|
|
13
25
|
return (args, options) => {
|
|
14
26
|
const plan = buildSpawnPlan("hq", args);
|
|
@@ -45,50 +57,140 @@ function readJson(fileSystem, file) {
|
|
|
45
57
|
return JSON.parse(fileSystem.readFileSync(file, "utf8"));
|
|
46
58
|
}
|
|
47
59
|
function timestamp(deps) { return deps.now().toISOString().replace(/\.\d{3}Z$/, "Z"); }
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
class UidSourceUnreadable extends Error {
|
|
61
|
+
relative;
|
|
62
|
+
constructor(relative) {
|
|
63
|
+
super(relative);
|
|
64
|
+
this.relative = relative;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// awk's [[:space:]]: space, tab, newline, vertical tab, form feed, carriage return.
|
|
68
|
+
const AWK_TRAILING_SPACE = /[ \t\n\v\f\r]+$/u;
|
|
69
|
+
const AWK_COMPANIES_LINE = /^companies:[ \t\n\v\f\r]*$/u;
|
|
70
|
+
const AWK_UNINDENTED_LINE = /^[^ \t\n\v\f\r]/u;
|
|
71
|
+
function stripBlanks(value) { return value.replace(/[\s\u0085\u00a0]+/g, ""); }
|
|
72
|
+
function awkFields(line) { return line.split(/[\t ]+/u).filter((field) => field !== ""); }
|
|
73
|
+
function missingPath(err) {
|
|
74
|
+
const code = err?.code;
|
|
75
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
76
|
+
}
|
|
77
|
+
/** Contents of `file` when it is a regular file (`[ -f ]`), null when it is not. */
|
|
78
|
+
function readUidSource(file, relative, deps) {
|
|
79
|
+
let stat;
|
|
53
80
|
try {
|
|
54
|
-
|
|
55
|
-
if (fromFile)
|
|
56
|
-
return fromFile;
|
|
81
|
+
stat = deps.fs.statSync(file);
|
|
57
82
|
}
|
|
58
|
-
catch {
|
|
59
|
-
|
|
60
|
-
|
|
83
|
+
catch (err) {
|
|
84
|
+
if (missingPath(err))
|
|
85
|
+
return null;
|
|
86
|
+
throw new UidSourceUnreadable(relative);
|
|
87
|
+
}
|
|
88
|
+
if (!stat.isFile())
|
|
89
|
+
return null;
|
|
61
90
|
try {
|
|
62
|
-
|
|
91
|
+
return deps.fs.readFileSync(file, "utf8");
|
|
63
92
|
}
|
|
64
93
|
catch {
|
|
65
|
-
|
|
94
|
+
throw new UidSourceUnreadable(relative);
|
|
66
95
|
}
|
|
96
|
+
}
|
|
97
|
+
/** The reference's recorded_uid awk over companies/manifest.yaml (lines 82-90). */
|
|
98
|
+
function manifestCloudUid(contents, company) {
|
|
67
99
|
let inCompanies = false;
|
|
68
100
|
let inCompany = false;
|
|
69
|
-
for (const line of contents.split(
|
|
70
|
-
if (
|
|
101
|
+
for (const line of contents.split("\n")) {
|
|
102
|
+
if (AWK_COMPANIES_LINE.test(line)) {
|
|
71
103
|
inCompanies = true;
|
|
72
104
|
continue;
|
|
73
105
|
}
|
|
74
|
-
if (inCompanies &&
|
|
106
|
+
if (inCompanies && AWK_UNINDENTED_LINE.test(line))
|
|
75
107
|
inCompanies = false;
|
|
76
|
-
inCompany = false;
|
|
77
|
-
}
|
|
78
108
|
if (inCompanies && /^ {2}[^ #][^:]*:/u.test(line)) {
|
|
79
|
-
|
|
80
|
-
inCompany = slug === company;
|
|
109
|
+
inCompany = (awkFields(line)[0] ?? "").replace(AWK_TRAILING_SPACE, "").replace(/:$/u, "") === company;
|
|
81
110
|
continue;
|
|
82
111
|
}
|
|
83
|
-
if (inCompany && /^ {2}[
|
|
84
|
-
|
|
112
|
+
if (inCompany && /^ {2}[^ \t\n\v\f\r#]/u.test(line))
|
|
113
|
+
return "";
|
|
85
114
|
if (inCompany) {
|
|
86
|
-
const fields = line
|
|
87
|
-
if (fields[0] === "cloud_uid:"
|
|
88
|
-
return fields[1].replace(/["']/gu, "").replace(
|
|
115
|
+
const fields = awkFields(line);
|
|
116
|
+
if (fields[0] === "cloud_uid:")
|
|
117
|
+
return (fields[1] ?? "").replace(/["']/gu, "").replace(AWK_TRAILING_SPACE, "");
|
|
89
118
|
}
|
|
90
119
|
}
|
|
91
|
-
return
|
|
120
|
+
return "";
|
|
121
|
+
}
|
|
122
|
+
function recordedUid(company, deps) {
|
|
123
|
+
const own = readUidSource(path.join(deps.root, "companies", company, ".company-uid"), `companies/${company}/.company-uid`, deps);
|
|
124
|
+
// An existing .company-uid is the answer even when it is blank (ref lines 76-79).
|
|
125
|
+
if (own !== null)
|
|
126
|
+
return stripBlanks(own);
|
|
127
|
+
const manifest = readUidSource(path.join(deps.root, "companies", "manifest.yaml"), "companies/manifest.yaml", deps);
|
|
128
|
+
return manifest === null ? "" : manifestCloudUid(manifest, company);
|
|
129
|
+
}
|
|
130
|
+
function activeCompanySlug(deps) {
|
|
131
|
+
const slug = deps.env.HQ_COMPANY_SLUG ?? "";
|
|
132
|
+
if (slug)
|
|
133
|
+
return slug;
|
|
134
|
+
const script = path.join(deps.root, "core", "scripts", "hq-session.sh");
|
|
135
|
+
if (!isFile(script, deps))
|
|
136
|
+
return "";
|
|
137
|
+
const answer = (deps.runSession ?? defaultRunSession)(script, { ...deps.env, HQ_ROOT: deps.root, HQ_HQ_SESSION_NO_CLI: "1" }, deps.cwd);
|
|
138
|
+
// The reference keeps whatever a failed run printed (`|| true`); a failed or
|
|
139
|
+
// timed-out answer is no answer here.
|
|
140
|
+
return answer.code === 0 ? stripBlanks(answer.stdout) : "";
|
|
141
|
+
}
|
|
142
|
+
function uidRecordedElsewhere(company, uid, deps) {
|
|
143
|
+
const companies = path.join(deps.root, "companies");
|
|
144
|
+
let names;
|
|
145
|
+
try {
|
|
146
|
+
names = deps.fs.readdirSync(companies).map(String).sort();
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
if (!missingPath(err))
|
|
150
|
+
throw new UidSourceUnreadable("companies");
|
|
151
|
+
names = [];
|
|
152
|
+
}
|
|
153
|
+
for (const name of names) {
|
|
154
|
+
if (name.startsWith(".") || name === company)
|
|
155
|
+
continue;
|
|
156
|
+
const recorded = readUidSource(path.join(companies, name, ".company-uid"), `companies/${name}/.company-uid`, deps);
|
|
157
|
+
if (recorded !== null && stripBlanks(recorded) === uid)
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
const manifest = readUidSource(path.join(companies, "manifest.yaml"), "companies/manifest.yaml", deps);
|
|
161
|
+
if (manifest === null)
|
|
162
|
+
return false;
|
|
163
|
+
return manifest.replace(/\r/gu, "").split("\n").some((line) => {
|
|
164
|
+
const fields = awkFields(line);
|
|
165
|
+
return fields[0] === "cloud_uid:" && (fields[1] ?? "").replace(/["']/gu, "") === uid;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function activeCompanyEnvUid(company, deps) {
|
|
169
|
+
const envUid = deps.env.HQ_COMPANY_UID ?? "";
|
|
170
|
+
if (!/^cmp_[A-Za-z0-9]{3,128}$/u.test(envUid))
|
|
171
|
+
return "";
|
|
172
|
+
const active = activeCompanySlug(deps);
|
|
173
|
+
if (!active || active !== company)
|
|
174
|
+
return "";
|
|
175
|
+
return uidRecordedElsewhere(company, envUid, deps) ? "" : envUid;
|
|
176
|
+
}
|
|
177
|
+
function resolveUid(company, deps) {
|
|
178
|
+
try {
|
|
179
|
+
const recorded = recordedUid(company, deps);
|
|
180
|
+
if (!recorded) {
|
|
181
|
+
const envUid = activeCompanyEnvUid(company, deps);
|
|
182
|
+
return envUid ? { uid: envUid } : { refusal: `no company uid for ${company} (set companies/${company}/.company-uid or manifest cloud_uid, or run with HQ_COMPANY_UID while ${company} is the active company)` };
|
|
183
|
+
}
|
|
184
|
+
const envUid = deps.env.HQ_COMPANY_UID ?? "";
|
|
185
|
+
if (envUid && envUid !== recorded)
|
|
186
|
+
return { refusal: `HQ_COMPANY_UID does not match ${company}'s recorded uid; refusing to register into another company's Work Mesh` };
|
|
187
|
+
return { uid: recorded };
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
if (err instanceof UidSourceUnreadable)
|
|
191
|
+
return { refusal: `registration refused: cannot read ${err.relative} to decide ${company}'s company uid` };
|
|
192
|
+
throw err;
|
|
193
|
+
}
|
|
92
194
|
}
|
|
93
195
|
function boardPath(company, deps) { return path.join(deps.root, "companies", company, "board.json"); }
|
|
94
196
|
function runHelpProbe(deps) {
|
|
@@ -200,6 +302,9 @@ function ensureOne(company, project, deps) {
|
|
|
200
302
|
const ambiguous = ambiguousBoardMatch(company, project, deps, (row) => matchesProject(row, project, prdRel, meshProject));
|
|
201
303
|
if (ambiguous)
|
|
202
304
|
return ambiguous;
|
|
305
|
+
const resolved = resolveUid(company, deps);
|
|
306
|
+
if (resolved.refusal !== undefined)
|
|
307
|
+
return errorResult(resolved.refusal);
|
|
203
308
|
if (!runHelpProbe(deps)) {
|
|
204
309
|
try {
|
|
205
310
|
markPending(company, project, deps);
|
|
@@ -213,7 +318,7 @@ function ensureOne(company, project, deps) {
|
|
|
213
318
|
? `${deps.root.replace(/[\\/]+$/u, "")}/companies/${company}/projects/${project}/prd.json`
|
|
214
319
|
: prd;
|
|
215
320
|
const ensure = deps.runHq(["mesh", "project", "ensure", meshProject, "--company", company, "--stories-file", hqPrd, "--json"], {
|
|
216
|
-
cwd: deps.cwd, env: deps.env, capture: true,
|
|
321
|
+
cwd: deps.cwd, env: { ...deps.env, HQ_COMPANY_UID: resolved.uid }, capture: true,
|
|
217
322
|
});
|
|
218
323
|
if (ensure.code !== 0)
|
|
219
324
|
return errorResult(`registration incomplete: hq mesh project ensure failed for ${company}/${project}`);
|
|
@@ -270,8 +375,11 @@ function ensureOne(company, project, deps) {
|
|
|
270
375
|
return { code: 0, stdout: `registered ${company}/${project} thread=${thread} channel=${channel}\n`, stderr: "" };
|
|
271
376
|
}
|
|
272
377
|
function registerBrainstorm(company, project, deps) {
|
|
273
|
-
|
|
274
|
-
|
|
378
|
+
// Pin the child CLI to the named company's uid so an ambient or cached
|
|
379
|
+
// company context cannot send this Board entry to another company's mesh.
|
|
380
|
+
const resolved = resolveUid(company, deps);
|
|
381
|
+
if (resolved.refusal !== undefined)
|
|
382
|
+
return errorResult(resolved.refusal);
|
|
275
383
|
const board = boardPath(company, deps);
|
|
276
384
|
if (!deps.fs.existsSync(board))
|
|
277
385
|
return errorResult(`registration incomplete: missing ${board}`);
|
|
@@ -285,33 +393,39 @@ function registerBrainstorm(company, project, deps) {
|
|
|
285
393
|
if (!title)
|
|
286
394
|
return errorResult(`registration incomplete: missing local Board project ${company}/${project}`);
|
|
287
395
|
const set = deps.runHq(["mesh", "project", "set", project, "--company", company, "--name", title, "--description", description, "--create", "--json"], {
|
|
288
|
-
cwd: deps.cwd, env: deps.env, capture: true,
|
|
396
|
+
cwd: deps.cwd, env: { ...deps.env, HQ_COMPANY_UID: resolved.uid }, capture: true,
|
|
289
397
|
});
|
|
290
398
|
if (set.code !== 0)
|
|
291
399
|
return errorResult(`registration incomplete: hq mesh project set failed for ${company}/${project}`);
|
|
292
|
-
|
|
400
|
+
// The shell discards jq errors on this output (`2>/dev/null || thread=""`).
|
|
401
|
+
let result = null;
|
|
293
402
|
try {
|
|
294
403
|
result = asRecord(JSON.parse(set.stdout));
|
|
295
404
|
}
|
|
296
|
-
catch {
|
|
297
|
-
return errorResult("registration incomplete: project set output missing threadId");
|
|
298
|
-
}
|
|
405
|
+
catch { /* falls back to the Board entry below */ }
|
|
299
406
|
const registration = asRecord(result?.registration);
|
|
300
|
-
|
|
407
|
+
let thread = jqString(jqOr(registration?.threadId, jqOr(result?.threadId, "")));
|
|
408
|
+
let channel = jqString(jqOr(registration?.channelId, jqOr(result?.channelId, "")));
|
|
409
|
+
// `project set` on an already-registered project can return no thread or
|
|
410
|
+
// channel. Fall back to the ids the local Board entry already records.
|
|
411
|
+
if (!thread)
|
|
412
|
+
thread = jqString(jqOr(asRecord(row)?.threadId, ""));
|
|
413
|
+
if (!channel)
|
|
414
|
+
channel = jqString(jqOr(asRecord(row)?.channelId, ""));
|
|
301
415
|
if (!thread)
|
|
302
416
|
return errorResult("registration incomplete: project set output missing threadId");
|
|
303
|
-
const channel = jqString(jqOr(registration?.channelId, jqOr(result?.channelId, "")));
|
|
304
417
|
if (!channel)
|
|
305
418
|
return errorResult("registration incomplete: project set output missing channelId");
|
|
306
419
|
const now = timestamp(deps);
|
|
307
420
|
const rows = projectRows(document);
|
|
308
|
-
document.projects = rows.map((item) =>
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
421
|
+
document.projects = rows.map((item) => {
|
|
422
|
+
if (item.id !== project && item.mesh_project_id !== project)
|
|
423
|
+
return item;
|
|
424
|
+
const updated = { ...item, threadId: thread, channelId: channel, mesh_project_id: project, updated_at: now };
|
|
425
|
+
delete updated.pending_registration;
|
|
426
|
+
delete updated.mesh_registration_prompt_state;
|
|
427
|
+
return updated;
|
|
428
|
+
});
|
|
315
429
|
try {
|
|
316
430
|
atomicJqWrite(board, document, deps);
|
|
317
431
|
}
|
|
@@ -321,7 +435,20 @@ function registerBrainstorm(company, project, deps) {
|
|
|
321
435
|
const verified = projectRows(boardData(company, board, deps)).some((item) => (item.id === project || item.mesh_project_id === project) && item.threadId === thread && item.channelId === channel);
|
|
322
436
|
if (!verified)
|
|
323
437
|
return errorResult("registration incomplete: local Board registration did not verify");
|
|
324
|
-
|
|
438
|
+
const registered = `registered ${company}/${project} thread=${thread} channel=${channel}\n`;
|
|
439
|
+
// Once the project has a prd.json, --board also syncs its stories.
|
|
440
|
+
if (!isFile(path.join(deps.root, "companies", company, "projects", project, "prd.json"), deps))
|
|
441
|
+
return { code: 0, stdout: registered, stderr: "" };
|
|
442
|
+
const sync = ensureOne(company, project, deps);
|
|
443
|
+
return { ...sync, stdout: `${registered}${sync.stdout}` };
|
|
444
|
+
}
|
|
445
|
+
function isFile(file, deps) {
|
|
446
|
+
try {
|
|
447
|
+
return deps.fs.statSync(file).isFile();
|
|
448
|
+
}
|
|
449
|
+
catch {
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
325
452
|
}
|
|
326
453
|
function audit(company, deps) {
|
|
327
454
|
if (!company)
|
|
@@ -342,11 +469,12 @@ function audit(company, deps) {
|
|
|
342
469
|
try {
|
|
343
470
|
if (!deps.fs.statSync(prd).isFile())
|
|
344
471
|
return false;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
472
|
+
// The reference reports a refused uid and still looks the project up
|
|
473
|
+
// with an empty uid, so it is listed as unregistered (ref lines 111-117).
|
|
474
|
+
const resolved = resolveUid(company, deps);
|
|
475
|
+
if (resolved.refusal !== undefined)
|
|
476
|
+
stderr += `${resolved.refusal}\n`;
|
|
477
|
+
const uid = resolved.uid ?? "";
|
|
350
478
|
const cache = path.join(deps.env.HOME || os.homedir(), ".hq/work-mesh/cache/projects", uid);
|
|
351
479
|
const meshProject = meshProjectIdForPrd(company, project, deps);
|
|
352
480
|
return !deps.fs.existsSync(path.join(cache, `${meshProject}.json`))
|
|
@@ -457,9 +585,11 @@ function retryPending(company, deps) {
|
|
|
457
585
|
export function runRegisterProject(args, deps) {
|
|
458
586
|
try {
|
|
459
587
|
const [mode, arg1, ...rest] = args;
|
|
460
|
-
|
|
588
|
+
// --board registers a Board entry that has no prd.json yet (a brainstorm or
|
|
589
|
+
// PRD that just started). --brainstorm is the older spelling of the same mode.
|
|
590
|
+
if (mode === "--board" || mode === "--brainstorm") {
|
|
461
591
|
if (args.length !== 3)
|
|
462
|
-
return errorResult("usage: register-project.sh --
|
|
592
|
+
return errorResult("usage: register-project.sh --board <company> <board-project-id>");
|
|
463
593
|
return registerBrainstorm(arg1 ?? "", rest[0] ?? "", deps);
|
|
464
594
|
}
|
|
465
595
|
if (mode === "--audit")
|
|
@@ -3,7 +3,7 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import { resolveWindowsExecutable } from "../lib/bot/runtime/windows.js";
|
|
6
|
-
import { sessionIdFromEnv, validSessionId } from "../lib/core-utils/session-id.js";
|
|
6
|
+
import { resolveSessionId, sessionIdFromEnv, validSessionId } from "../lib/core-utils/session-id.js";
|
|
7
7
|
import { generateUlid } from "../lib/mesh/live/ulid.js";
|
|
8
8
|
import { resolveLiveRoot } from "../utils/hq-roots.js";
|
|
9
9
|
import { planResolvedCommandSpawn } from "../utils/windows-spawn.js";
|
|
@@ -118,16 +118,11 @@ export function resolveWorkMeshBindSession(root, env, fileSystem = fs) {
|
|
|
118
118
|
const fromEnv = sessionIdFromEnv(env);
|
|
119
119
|
if (fromEnv)
|
|
120
120
|
return { sid: fromEnv, trusted: true };
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return { sid: validSessionId(value) ? value : "", trusted: false };
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
return { sid: "", trusted: false };
|
|
127
|
-
}
|
|
121
|
+
// No env id: the shared resolver's .current fallback (an empty env skips its env step).
|
|
122
|
+
return { sid: resolveSessionId(root, {}, (file, encoding) => fileSystem.readFileSync(file, encoding)), trusted: false };
|
|
128
123
|
}
|
|
129
124
|
export function resolveWorkMeshBindSessionId(root, env, fileSystem = fs) {
|
|
130
|
-
return
|
|
125
|
+
return resolveSessionId(root, env, (file, encoding) => fileSystem.readFileSync(file, encoding));
|
|
131
126
|
}
|
|
132
127
|
function hasExecutable(deps, command) {
|
|
133
128
|
if (process.platform === "win32") {
|
package/dist/commands/daemon.js
CHANGED
|
@@ -31,7 +31,7 @@ import { daemonUnitInstalled } from "../lib/daemon/handoff.js";
|
|
|
31
31
|
import { adoptLegacyUnits, readAdoptedUnits, restoreLegacyUnits } from "../lib/daemon/migrate.js";
|
|
32
32
|
import { DAEMON_ALIVE_WAIT_MS, ROOT_REFUSAL, SYSTEM_UNIT_DIR, WINDOWS_START_WAIT_MS, waitForLiveDaemon, daemonRootRefusal, installDaemonUnit, installScopeFor, classifyWindowsTask, daemonServiceStatus, describeSupervision, legacyWindowsTask, startDaemonUnit, readWindowsSid, uninstallDaemonUnit, windowsInteractiveSession, windowsTaskName, } from "../lib/daemon/install.js";
|
|
33
33
|
import { PLIST_REFRESH_MARKER } from "../lib/daemon/plist-refresh.js";
|
|
34
|
-
import {
|
|
34
|
+
import { filesAccessNeeded, filesAccessNeededMessageFromMarker } from "../lib/daemon/tcc-eperm.js";
|
|
35
35
|
import { describeLegacyUnit, findLegacyUnits } from "../lib/daemon/legacy.js";
|
|
36
36
|
import { isDaemonProcess, liveDaemonLock, runningDaemonPid } from "../lib/daemon/lock.js";
|
|
37
37
|
import { bundledHqCloud, managedHqCloud, managedHqCloudRoot, readHqCloudCopy, readHqCloudUpdateState } from "../lib/daemon/hq-cloud.js";
|
|
@@ -524,7 +524,7 @@ function statusWarnings(service, paths) {
|
|
|
524
524
|
// Written by a daemon that macOS keeps refusing under the HQ root (tcc-eperm.ts).
|
|
525
525
|
// A stopped daemon's marker is stale: the next daemon clears it on start.
|
|
526
526
|
if (service.daemonPid !== null && filesAccessNeeded(paths.root))
|
|
527
|
-
warnings.push(
|
|
527
|
+
warnings.push(filesAccessNeededMessageFromMarker(paths.root));
|
|
528
528
|
return warnings;
|
|
529
529
|
}
|
|
530
530
|
async function runStatus(d, opts) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { type RunQmdOptions, type SearchCollection, type QmdProcessResult } from '../lib/search-index/index.js';
|
|
2
|
+
import { type RunQmdOptions, type SearchCollection, type QmdProcessResult, type QmdSpawn } from '../lib/search-index/index.js';
|
|
3
3
|
import { type BackgroundDependencies, type BackgroundResult, type BackgroundStatus } from '../lib/search-index/background.js';
|
|
4
4
|
import { type EmbedLockDependencies } from '../lib/search-index/embed-lock.js';
|
|
5
5
|
import { type LoadGateDependencies } from '../lib/search-index/load-gate.js';
|
|
@@ -35,6 +35,8 @@ export type SyncSearchIndexResult = {
|
|
|
35
35
|
};
|
|
36
36
|
/** Incrementally update qmd, embedding only when an operator explicitly asks. */
|
|
37
37
|
export declare function syncSearchIndex(hqRoot: string, embed: boolean, dependencies?: SearchIndexDependencies): SyncSearchIndexResult;
|
|
38
|
+
/** Update from a daemon worker, with the scheduled job's qmd process policy. */
|
|
39
|
+
export declare function syncScheduledSearchIndex(hqRoot: string, spawn: QmdSpawn, waitForWriter: (milliseconds: number) => void): SyncSearchIndexResult;
|
|
38
40
|
export declare function collectionStatusLines(expected: SearchCollection[], registered: ReadonlySet<string>): string[];
|
|
39
41
|
export declare function collectionSummary(expected: SearchCollection[], registered: ReadonlySet<string>): string;
|
|
40
42
|
export declare function registerIndexCommand(program: Command, dependencies?: SearchIndexDependencies): void;
|
|
@@ -129,6 +129,18 @@ export function syncSearchIndex(hqRoot, embed, dependencies = defaults) {
|
|
|
129
129
|
writeStderr('hq: cannot access the qmd embed lock; skipping this pass.\n');
|
|
130
130
|
return { status: 'updated', embedded: outcome === 'ran' && embedded };
|
|
131
131
|
}
|
|
132
|
+
/** Update from a daemon worker, with the scheduled job's qmd process policy. */
|
|
133
|
+
export function syncScheduledSearchIndex(hqRoot, spawn, waitForWriter) {
|
|
134
|
+
return syncSearchIndex(hqRoot, false, {
|
|
135
|
+
...defaults,
|
|
136
|
+
sleepSync: waitForWriter,
|
|
137
|
+
reconcileCollections: (root) => reconcileCollections(root, {
|
|
138
|
+
repairPathDrift: qmdCollectionPathRepairEnabled(),
|
|
139
|
+
spawn,
|
|
140
|
+
}),
|
|
141
|
+
runQmd: (args, options) => runQmd(args, { ...options, spawn }),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
132
144
|
function resolveRoot(hqRoot) {
|
|
133
145
|
return hqRoot ?? findHqRoot();
|
|
134
146
|
}
|
|
@@ -931,7 +931,7 @@ async function orphanReport(root, company, now, minAgeMinutes, userIdleHours, de
|
|
|
931
931
|
}
|
|
932
932
|
export function registerLaneChecksCommand(parent, deps, wrap) {
|
|
933
933
|
parent.command("reap")
|
|
934
|
-
//
|
|
934
|
+
// Preserve the historical internal alias for older callers.
|
|
935
935
|
.alias("_reap")
|
|
936
936
|
.description("Classify local lanes whose session senior has ended; report only by default")
|
|
937
937
|
.option("--min-age <minutes>", "Minimum lane age in minutes (default: 120)")
|
|
@@ -7,6 +7,7 @@ export interface SessionStartOptions {
|
|
|
7
7
|
stdout?: Pick<NodeJS.WriteStream, "write">;
|
|
8
8
|
stderr?: Pick<NodeJS.WriteStream, "write">;
|
|
9
9
|
resolveRoot?: (env: NodeJS.ProcessEnv, cwd?: string) => string;
|
|
10
|
+
/** Compatibility option; orphan sweeping is now owned by daemon reconcile. */
|
|
10
11
|
startSweep?: (root: string, env: NodeJS.ProcessEnv) => void;
|
|
11
12
|
/** Starts the off-hot-path registry read when an offline flag value is missing or old. */
|
|
12
13
|
refreshFlags?: (env: NodeJS.ProcessEnv) => void;
|
|
@@ -30,8 +31,6 @@ export declare const CONDUCT_RUNNERS_CORE_MISSING_LINE = "hq runners session-sta
|
|
|
30
31
|
* that: a stalled resolver costs the pin, and the inject block still prints.
|
|
31
32
|
*/
|
|
32
33
|
export declare const CONDUCT_RUNNER_RESOLVE_TIMEOUT_MS = 500;
|
|
33
|
-
/** Starts the CL-4 read-only orphan report once per host, without holding SessionStart open. */
|
|
34
|
-
export declare function startSessionStartOrphanSweep(root: string, env?: NodeJS.ProcessEnv, spawnDetached?: typeof spawn, rootScoped?: boolean): void;
|
|
35
34
|
/**
|
|
36
35
|
* Start a detached `hq lanes session-start --refresh-flags` so the registry
|
|
37
36
|
* read never runs inside the SessionStart hook. A short lease keeps a burst of
|