@indigoai-us/hq-cli 5.345.262 → 5.345.263
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 +14 -0
- package/contracts/host-canary-release.json +7 -7
- package/dist/commands/core-handoff.js +273 -115
- package/dist/utils/delegate-lock.js +19 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.345.263] — 2026-11-26
|
|
6
|
+
- Fix false refusals in the credential guard's Windows shell-path check on Unix for `date +%H:%M:%S` / `+%Y-%m-%dT%H:%M:%S.000Z` format strings and `\t` escapes inside `awk` programs.
|
|
7
|
+
- fix(delegate): wait for a transiently contended coordination mutex during delegate lock release instead of leaving the lock file behind
|
|
8
|
+
- Use `exec sleep` in `dispatch.rs` timed-out hook test fixtures so parent `bash` cannot race to emit `"Terminated sleep ..."` job-reap notices on Windows stderr.
|
|
9
|
+
- test: prevent detached handoff publish writers from racing differential workspace cleanup in `e2e/handoff-differential.test.ts`
|
|
10
|
+
- Fixed: native `hq core handoff post` now matches `handoff-post.sh` for bound-session `meta.yaml` parsing, single-company ownership on thread metadata and touched file paths, normalizing `company` and `company_slugs` on both the root thread and cleaned mirror copy (instead of hard-linking), and accepting digit-first company slugs.
|
|
11
|
+
- hq-hook: scan each PreToolUse script once in `missing_registered_guards`, skip the duplicate pre-dispatch check inside supervised evaluation children, and run `us012_root_git_codex_grok` parity cases with the deterministic budget clock so loaded Linux CI shards no longer hit the 5000 ms wall-clock cutoff.
|
|
12
|
+
- Changed: the host canary record shipped with the CLI is refreshed for this release build.
|
|
13
|
+
- Add end-to-end tests in `hq-hook` covering a personal PreToolUse hook that times out and refuses, and a personal PreToolUse hook that exits 2 alongside an allowing sibling hook.
|
|
14
|
+
- Hard-link and warm the test sentinel executable in `run_starts_no_interpreter` so cold-start binary scans on Windows do not consume `SessionStart` hook budgets.
|
|
15
|
+
- Test and CI: update the Windows Claude Stop end-to-end checks (`registration::claude_stop_registered_binary_blocks_then_allows_end_of_turn_e2e` and `scripts/ci/windows-stop-e2e-check.mjs`) to write and invoke the exact project and `--global` `core.next` registrations (including `--global` from a foreign folder), and run the check on Beaker on `hook-registration.yml` dispatch.
|
|
16
|
+
- Refuse `master-hook.sh` hand-off in `hq-hook` with a clear error naming the missing tool when `awk` or another required shell utility is absent from `PATH`.
|
|
17
|
+
- Check the original directory components of Windows state-folder listings.
|
|
18
|
+
|
|
5
19
|
## [5.345.262] — 2026-11-26
|
|
6
20
|
- The Windows PR test scope now also runs the end-to-end tests a source module reaches through the hook binary: `command_rules` for `src/rules/`, and `host_run` and `replay` for `src/company_repo.rs`.
|
|
7
21
|
- The native hook engine now runs personal, pack and company folder hooks (`personal/hooks/<Event>`, `core/packages/<pack>/hooks/<Event>`, `companies/<co>/hooks/<Event>`) on Claude Code's PreToolUse, PostToolUse, SessionStart, UserPromptSubmit and SessionEnd, so `hq reindex` no longer keeps those events on `master-hook.sh` just because an HQ has such hooks. Each hook still runs as the script it is, with the same input, environment, order, tool matchers and time limit master-hook gave it. A hook answer the native engine cannot carry, or a guard hook whose result is unknown, refuses the call instead of letting it through.
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": "hq.host-canary-release.v1",
|
|
3
|
-
"cliVersion": "5.345.
|
|
3
|
+
"cliVersion": "5.345.263",
|
|
4
4
|
"hosts": {
|
|
5
5
|
"claude": [
|
|
6
6
|
{
|
|
7
7
|
"passed": true,
|
|
8
|
-
"at": "2026-11-
|
|
9
|
-
"engineVersion": "0.3.1+hq.5.345.
|
|
8
|
+
"at": "2026-11-26T20:09:17.136Z",
|
|
9
|
+
"engineVersion": "0.3.1+hq.5.345.263.src.636f8062850c948938e820cb17836ceea7d7d5b4663d2764d9fb94d92b0a09a3",
|
|
10
10
|
"gateSha256": "a2879dfe692233f5953bac86672947bbd82f3c5247292f3efcb80f16c3d2c6b1"
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
13
|
"passed": true,
|
|
14
|
-
"at": "2026-11-
|
|
15
|
-
"engineVersion": "0.3.1+hq.5.345.
|
|
14
|
+
"at": "2026-11-26T20:09:51.700Z",
|
|
15
|
+
"engineVersion": "0.3.1+hq.5.345.263.src.636f8062850c948938e820cb17836ceea7d7d5b4663d2764d9fb94d92b0a09a3",
|
|
16
16
|
"gateSha256": "ca58a94859eae0a345c11c8d9c59303eb76350dc1cf223391037d21979c28718"
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"passed": true,
|
|
20
|
-
"at": "2026-11-
|
|
21
|
-
"engineVersion": "0.3.1+hq.5.345.
|
|
20
|
+
"at": "2026-11-26T20:10:20.846Z",
|
|
21
|
+
"engineVersion": "0.3.1+hq.5.345.263.src.636f8062850c948938e820cb17836ceea7d7d5b4663d2764d9fb94d92b0a09a3",
|
|
22
22
|
"gateSha256": "ecdbab7c2e0a1d94eb9c98f15e760390f215bc7115a217ded24b4275322722d2"
|
|
23
23
|
}
|
|
24
24
|
]
|
|
@@ -39,34 +39,16 @@ const DESCRIPTIONS = {
|
|
|
39
39
|
post: "Run best-effort post-handoff maintenance",
|
|
40
40
|
openSteps: "List and update open handoff steps",
|
|
41
41
|
};
|
|
42
|
-
/** handoff-finalize.sh
|
|
42
|
+
/** handoff-finalize.sh, handoff-post.sh, and mirror-thread-to-company.sh accept digit-leading company slugs. */
|
|
43
43
|
const FINALIZE_COMPANY_SLUG_RE = /^[a-z0-9][a-z0-9_-]*$/;
|
|
44
|
-
|
|
45
|
-
const POST_COMPANY_SLUG_RE = /^[a-z][a-z0-9_-]*$/;
|
|
46
|
-
export function boundSessionCompany(root) {
|
|
47
|
-
const sessionId = resolveSessionId(root);
|
|
48
|
-
if (!sessionId)
|
|
49
|
-
return "";
|
|
50
|
-
const metadata = path.join(root, "workspace/sessions", sessionId, "meta.yaml");
|
|
51
|
-
let contents;
|
|
52
|
-
try {
|
|
53
|
-
contents = fs.readFileSync(metadata, "utf8");
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return "";
|
|
57
|
-
}
|
|
58
|
-
const line = contents.split(/\r?\n/).find((entry) => /^\s*company_slug:/.test(entry));
|
|
59
|
-
if (!line)
|
|
60
|
-
return "";
|
|
61
|
-
const company = (line.replace(/^\s*company_slug:\s*/, "").replace(/^"|"$/g, ""));
|
|
62
|
-
return POST_COMPANY_SLUG_RE.test(company) ? company : "";
|
|
63
|
-
}
|
|
44
|
+
const POST_COMPANY_SLUG_RE = FINALIZE_COMPANY_SLUG_RE;
|
|
64
45
|
/**
|
|
65
|
-
* meta.yaml `company_slug` as handoff-finalize.sh and the
|
|
66
|
-
* awk's `$1 == "company_slug:"` (the key is the whole
|
|
67
|
-
* `company_slug:acme` with no space is not a binding), the
|
|
68
|
-
*
|
|
69
|
-
*
|
|
46
|
+
* meta.yaml `company_slug` as handoff-finalize.sh, handoff-post.sh, and the
|
|
47
|
+
* mirror hook read it: awk's `$1 == "company_slug:"` (the key is the whole
|
|
48
|
+
* first field, so `company_slug:acme` with no space is not a binding), the
|
|
49
|
+
* first such line, preserving any trailing `\r` (CRLF), with the key, the
|
|
50
|
+
* whitespace after it and one quote at each end removed.
|
|
51
|
+
* No slug check here; the helpers apply their pattern, the hook does not.
|
|
70
52
|
*/
|
|
71
53
|
function metaCompanySlugRaw(root) {
|
|
72
54
|
const sessionId = resolveSessionId(root);
|
|
@@ -86,11 +68,14 @@ function metaCompanySlugRaw(root) {
|
|
|
86
68
|
}
|
|
87
69
|
return "";
|
|
88
70
|
}
|
|
89
|
-
/** bound_session_company in handoff-finalize.sh. */
|
|
71
|
+
/** bound_session_company in handoff-finalize.sh and handoff-post.sh. */
|
|
90
72
|
function finalizeBoundSessionCompany(root) {
|
|
91
73
|
const company = metaCompanySlugRaw(root);
|
|
92
74
|
return FINALIZE_COMPANY_SLUG_RE.test(company) ? company : "";
|
|
93
75
|
}
|
|
76
|
+
export function boundSessionCompany(root) {
|
|
77
|
+
return finalizeBoundSessionCompany(root);
|
|
78
|
+
}
|
|
94
79
|
const SESSION_SCOPE_LIB = "core/scripts/lib/session-scope-capability.sh";
|
|
95
80
|
/**
|
|
96
81
|
* bash for running the HQ root's own scripts (the mirror hook, the
|
|
@@ -630,53 +615,72 @@ function readDeficiencies(root, fileArg, given, stderrParts) {
|
|
|
630
615
|
}));
|
|
631
616
|
return { deficiencies: filtered };
|
|
632
617
|
}
|
|
633
|
-
function mirrorThread(root, threadPath) {
|
|
618
|
+
function mirrorThread(root, threadPath, expectedCompany, logicalRoot) {
|
|
634
619
|
try {
|
|
635
|
-
|
|
636
|
-
|
|
620
|
+
if (!expectedCompany || !POST_COMPANY_SLUG_RE.test(expectedCompany))
|
|
621
|
+
return;
|
|
622
|
+
const ownership = inspectThreadPostOwnership(root, threadPath, logicalRoot);
|
|
623
|
+
if (ownership.refused || ownership.validCompanies.length !== 1)
|
|
637
624
|
return;
|
|
638
|
-
const
|
|
639
|
-
if (
|
|
625
|
+
const company = ownership.validCompanies[0];
|
|
626
|
+
if (company !== expectedCompany)
|
|
627
|
+
return;
|
|
628
|
+
const thread = JSON.parse(stripByteOrderMark(fs.readFileSync(threadPath, "utf8")));
|
|
629
|
+
if (!isRecord(thread) || !isRecord(thread.metadata))
|
|
640
630
|
return;
|
|
641
|
-
const companies = Array.isArray(rawCompanies) ? rawCompanies : [rawCompanies];
|
|
642
631
|
if (typeof thread.thread_id !== "string" || !thread.thread_id)
|
|
643
632
|
return;
|
|
644
633
|
const updatedAt = thread.updated_at ?? thread.created_at ?? "";
|
|
645
634
|
const kind = thread.type ?? "unknown";
|
|
646
635
|
const rawTitle = thread.metadata.title ?? thread.conversation_summary ?? "";
|
|
647
636
|
const title = Buffer.from(typeof rawTitle === "string" ? rawTitle : compactJson(rawTitle)).subarray(0, 200).toString("utf8");
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
637
|
+
const companyRoot = path.join(root, "companies", company);
|
|
638
|
+
if (!isDirectory(companyRoot))
|
|
639
|
+
return;
|
|
640
|
+
const workspace = path.join(companyRoot, "workspace");
|
|
641
|
+
const sessions = path.join(workspace, "sessions");
|
|
642
|
+
const indexFile = path.join(workspace, "index.jsonl");
|
|
643
|
+
const ignoreFile = path.join(workspace, ".gitignore");
|
|
644
|
+
fs.mkdirSync(sessions, { recursive: true });
|
|
645
|
+
if (!fs.existsSync(ignoreFile)) {
|
|
646
|
+
fs.writeFileSync(ignoreFile, "# HQ workspace mirror — sessions are gitignored, index.jsonl is committed\nsessions/\n");
|
|
647
|
+
}
|
|
648
|
+
const mirroredThread = {
|
|
649
|
+
...thread,
|
|
650
|
+
metadata: {
|
|
651
|
+
...thread.metadata,
|
|
652
|
+
company_slugs: [company],
|
|
653
|
+
},
|
|
654
|
+
};
|
|
655
|
+
const target = path.join(sessions, `${thread.thread_id}.json`);
|
|
656
|
+
const temporaryMirror = path.join(sessions, `.mirror-${process.pid}-${Math.random().toString(36).slice(2)}`);
|
|
657
|
+
let temporaryFd;
|
|
658
|
+
try {
|
|
659
|
+
temporaryFd = fs.openSync(temporaryMirror, "wx", 0o600);
|
|
660
|
+
fs.writeFileSync(temporaryFd, `${JSON.stringify(mirroredThread, null, 2)}\n`);
|
|
661
|
+
fs.closeSync(temporaryFd);
|
|
662
|
+
temporaryFd = undefined;
|
|
663
|
+
fs.chmodSync(temporaryMirror, 0o600);
|
|
664
|
+
fs.renameSync(temporaryMirror, target);
|
|
665
|
+
}
|
|
666
|
+
catch {
|
|
667
|
+
if (temporaryFd !== undefined) {
|
|
669
668
|
try {
|
|
670
|
-
fs.
|
|
669
|
+
fs.closeSync(temporaryFd);
|
|
671
670
|
}
|
|
672
|
-
catch { /*
|
|
671
|
+
catch { /* temporary cleanup remains best effort */ }
|
|
673
672
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
673
|
+
try {
|
|
674
|
+
fs.rmSync(temporaryMirror, { force: true });
|
|
675
|
+
}
|
|
676
|
+
catch { /* temporary cleanup remains best effort */ }
|
|
677
|
+
return;
|
|
679
678
|
}
|
|
679
|
+
const row = compactJson({ thread_id: thread.thread_id, ts: updatedAt, kind, company, title }).trimEnd();
|
|
680
|
+
const dedupKey = `"thread_id":"${thread.thread_id}","ts":"${updatedAt}","kind":"${kind}"`;
|
|
681
|
+
if (fs.existsSync(indexFile) && fs.readFileSync(indexFile, "utf8").includes(dedupKey))
|
|
682
|
+
return;
|
|
683
|
+
fs.appendFileSync(indexFile, `${row}\n`);
|
|
680
684
|
}
|
|
681
685
|
catch {
|
|
682
686
|
// The legacy finalizer ignores every mirror-hook error.
|
|
@@ -1992,20 +1996,126 @@ function runIndexBackground(root, logPath) {
|
|
|
1992
1996
|
: "";
|
|
1993
1997
|
return { output, stderr };
|
|
1994
1998
|
}
|
|
1995
|
-
|
|
1999
|
+
/**
|
|
2000
|
+
* Validate single-owner company metadata and `files_touched` company paths for
|
|
2001
|
+
* `handoff post`. Mirrors the ownership rules from hq-core's `handoff-post.sh`
|
|
2002
|
+
* and `mirror-thread-to-company.sh`:
|
|
2003
|
+
* - `metadata.company` may be empty (`null`, `[]`, `""`), a single valid
|
|
2004
|
+
* company slug string, or a 1-element array containing one valid slug.
|
|
2005
|
+
* - Arrays with >1 entry (even duplicates or mixed valid/invalid entries) are
|
|
2006
|
+
* ambiguous and refused so no tenant mirrors are created or pushed.
|
|
2007
|
+
* - `files_touched` spanning >1 company, or naming a company that disagrees
|
|
2008
|
+
* with `metadata.company`, is refused as well.
|
|
2009
|
+
*/
|
|
2010
|
+
function inspectThreadPostOwnership(root, file, logicalRoot) {
|
|
2011
|
+
let thread;
|
|
1996
2012
|
try {
|
|
1997
|
-
|
|
1998
|
-
if (!isRecord(thread) || !isRecord(thread.metadata))
|
|
1999
|
-
return [];
|
|
2000
|
-
const value = thread.metadata.company;
|
|
2001
|
-
if (!jqTruthy(value))
|
|
2002
|
-
return [];
|
|
2003
|
-
const values = Array.isArray(value) ? value : [value];
|
|
2004
|
-
return [...new Set(values.filter((item) => typeof item === "string" && /^[a-z][a-z0-9_-]*$/.test(item)))].sort();
|
|
2013
|
+
thread = JSON.parse(stripByteOrderMark(fs.readFileSync(file, "utf8")));
|
|
2005
2014
|
}
|
|
2006
2015
|
catch {
|
|
2007
|
-
return
|
|
2016
|
+
return {
|
|
2017
|
+
validCompanies: [],
|
|
2018
|
+
pathCompanies: [],
|
|
2019
|
+
fileCount: 0,
|
|
2020
|
+
companyishCount: 0,
|
|
2021
|
+
hasInvalidJson: true,
|
|
2022
|
+
hasAmbiguousMetadata: false,
|
|
2023
|
+
hasInvalidMetadata: false,
|
|
2024
|
+
refused: true,
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
if (!isRecord(thread)) {
|
|
2028
|
+
return {
|
|
2029
|
+
validCompanies: [],
|
|
2030
|
+
pathCompanies: [],
|
|
2031
|
+
fileCount: 0,
|
|
2032
|
+
companyishCount: 0,
|
|
2033
|
+
hasInvalidJson: false,
|
|
2034
|
+
hasAmbiguousMetadata: false,
|
|
2035
|
+
hasInvalidMetadata: true,
|
|
2036
|
+
refused: true,
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
const rawCompany = isRecord(thread.metadata) ? thread.metadata.company : undefined;
|
|
2040
|
+
let validCompanies = [];
|
|
2041
|
+
let hasAmbiguousMetadata = false;
|
|
2042
|
+
let hasInvalidMetadata = false;
|
|
2043
|
+
if (rawCompany === undefined
|
|
2044
|
+
|| rawCompany === null
|
|
2045
|
+
|| rawCompany === ""
|
|
2046
|
+
|| (Array.isArray(rawCompany) && rawCompany.length === 0)) {
|
|
2047
|
+
// Empty metadata.company is valid (may still bind to session company).
|
|
2048
|
+
}
|
|
2049
|
+
else if (typeof rawCompany === "string") {
|
|
2050
|
+
if (POST_COMPANY_SLUG_RE.test(rawCompany))
|
|
2051
|
+
validCompanies = [rawCompany];
|
|
2052
|
+
else
|
|
2053
|
+
hasInvalidMetadata = true;
|
|
2054
|
+
}
|
|
2055
|
+
else if (Array.isArray(rawCompany)) {
|
|
2056
|
+
validCompanies = [
|
|
2057
|
+
...new Set(rawCompany.filter((item) => typeof item === "string" && POST_COMPANY_SLUG_RE.test(item))),
|
|
2058
|
+
].sort();
|
|
2059
|
+
if (rawCompany.length > 1) {
|
|
2060
|
+
hasAmbiguousMetadata = true;
|
|
2061
|
+
if (rawCompany.some((item) => typeof item !== "string" || !POST_COMPANY_SLUG_RE.test(item))) {
|
|
2062
|
+
hasInvalidMetadata = true;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
else if (validCompanies.length === 0) {
|
|
2066
|
+
hasInvalidMetadata = true;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
else {
|
|
2070
|
+
hasInvalidMetadata = true;
|
|
2071
|
+
}
|
|
2072
|
+
const rootsToStrip = [
|
|
2073
|
+
root.replaceAll("\\", "/").replace(/\/+$/, ""),
|
|
2074
|
+
...(logicalRoot ? [logicalRoot.replaceAll("\\", "/").replace(/\/+$/, "")] : []),
|
|
2075
|
+
];
|
|
2076
|
+
const rawFiles = Array.isArray(thread.files_touched) ? thread.files_touched : [];
|
|
2077
|
+
const pathCompanySet = new Set();
|
|
2078
|
+
let fileCount = 0;
|
|
2079
|
+
let companyishCount = 0;
|
|
2080
|
+
for (const entry of rawFiles) {
|
|
2081
|
+
const rawPath = typeof entry === "string"
|
|
2082
|
+
? entry
|
|
2083
|
+
: isRecord(entry) && typeof entry.path === "string"
|
|
2084
|
+
? entry.path
|
|
2085
|
+
: "";
|
|
2086
|
+
if (!rawPath)
|
|
2087
|
+
continue;
|
|
2088
|
+
fileCount += 1;
|
|
2089
|
+
let normalized = rawPath.replaceAll("\\", "/");
|
|
2090
|
+
for (const prefix of rootsToStrip) {
|
|
2091
|
+
if (prefix && normalized.startsWith(`${prefix}/`)) {
|
|
2092
|
+
normalized = normalized.slice(prefix.length + 1);
|
|
2093
|
+
break;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
normalized = normalized.replace(/^\.\//, "");
|
|
2097
|
+
if (normalized.startsWith("companies/") || normalized.startsWith("repos/")) {
|
|
2098
|
+
companyishCount += 1;
|
|
2099
|
+
}
|
|
2100
|
+
const match = /^companies\/([a-z0-9][a-z0-9_-]*)\//.exec(normalized);
|
|
2101
|
+
if (match?.[1])
|
|
2102
|
+
pathCompanySet.add(match[1]);
|
|
2008
2103
|
}
|
|
2104
|
+
const pathCompanies = [...pathCompanySet].sort();
|
|
2105
|
+
const refused = hasAmbiguousMetadata
|
|
2106
|
+
|| hasInvalidMetadata
|
|
2107
|
+
|| pathCompanies.length > 1
|
|
2108
|
+
|| (validCompanies.length === 1 && pathCompanies.length === 1 && pathCompanies[0] !== validCompanies[0]);
|
|
2109
|
+
return {
|
|
2110
|
+
validCompanies,
|
|
2111
|
+
pathCompanies,
|
|
2112
|
+
fileCount,
|
|
2113
|
+
companyishCount,
|
|
2114
|
+
hasInvalidJson: false,
|
|
2115
|
+
hasAmbiguousMetadata,
|
|
2116
|
+
hasInvalidMetadata,
|
|
2117
|
+
refused,
|
|
2118
|
+
};
|
|
2009
2119
|
}
|
|
2010
2120
|
function documentReleaseCounts(file) {
|
|
2011
2121
|
try {
|
|
@@ -2319,54 +2429,98 @@ export function runHandoffPostWorker(args, context) {
|
|
|
2319
2429
|
else
|
|
2320
2430
|
log("document-release: skipped (no thread path)");
|
|
2321
2431
|
if (threadFile && fs.existsSync(threadFile) && commandAvailable("hq")) {
|
|
2322
|
-
|
|
2432
|
+
const ownership = inspectThreadPostOwnership(root, threadFile, context.logicalRoot);
|
|
2433
|
+
let syncCompanies = [...ownership.validCompanies];
|
|
2434
|
+
let ownershipRefused = ownership.refused;
|
|
2323
2435
|
const sessionCompany = boundSessionCompany(root);
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2436
|
+
const sessionId = resolveSessionId(root);
|
|
2437
|
+
const sessionScope = sessionId ? readSessionLockedCompanies(root, sessionId) : undefined;
|
|
2438
|
+
if (ownership.hasInvalidJson || ownership.hasAmbiguousMetadata || ownership.hasInvalidMetadata) {
|
|
2439
|
+
// Unlike bash handoff-post.sh (which exits 2 immediately), the worker
|
|
2440
|
+
// records the refusal, skips mirroring/pushing, and continues to return 0:
|
|
2441
|
+
// hq-core-staging's handoff-thread-isolation.test.sh expects the
|
|
2442
|
+
// missing-mirror skip log line on 11-company metadata, existing POSIX
|
|
2443
|
+
// worker tests assert code 0 on invalid slugs, and the detached launcher
|
|
2444
|
+
// returns 0 in both implementations.
|
|
2445
|
+
ownershipRefused = true;
|
|
2446
|
+
log("workspace-sync: refused invalid or ambiguous ownership");
|
|
2447
|
+
if (!ownership.hasAmbiguousMetadata)
|
|
2448
|
+
syncCompanies = [];
|
|
2449
|
+
}
|
|
2450
|
+
else if (ownership.pathCompanies.length > 1) {
|
|
2451
|
+
ownershipRefused = true;
|
|
2452
|
+
syncCompanies = [];
|
|
2453
|
+
log("workspace-sync: skipped (handoff spans multiple companies)");
|
|
2454
|
+
}
|
|
2455
|
+
else if (!sessionCompany || !isDirectory(path.join(root, "companies", sessionCompany))) {
|
|
2456
|
+
ownershipRefused = true;
|
|
2457
|
+
syncCompanies = [];
|
|
2458
|
+
log("workspace-sync: skipped (no bound company for this session)");
|
|
2459
|
+
}
|
|
2460
|
+
else if (syncCompanies.length === 0 && ownership.fileCount > 0 && ownership.companyishCount === 0) {
|
|
2461
|
+
ownershipRefused = true;
|
|
2462
|
+
syncCompanies = [];
|
|
2463
|
+
log("workspace-sync: skipped (handoff touched no company or repo paths; personal or HQ-only work)");
|
|
2464
|
+
}
|
|
2465
|
+
else if ((syncCompanies.length === 1 && syncCompanies[0] !== sessionCompany)
|
|
2466
|
+
|| (ownership.pathCompanies.length === 1 && ownership.pathCompanies[0] !== sessionCompany)) {
|
|
2467
|
+
ownershipRefused = true;
|
|
2468
|
+
syncCompanies = [];
|
|
2469
|
+
log("workspace-sync: skipped (handoff paths do not match the bound company)");
|
|
2470
|
+
}
|
|
2471
|
+
else if (sessionScope?.capFile && sessionScope.companies.length === 0) {
|
|
2472
|
+
ownershipRefused = true;
|
|
2473
|
+
syncCompanies = [];
|
|
2474
|
+
log("workspace-sync: mirror hook failed for handoff thread");
|
|
2475
|
+
}
|
|
2476
|
+
else if (sessionScope?.capFile && !sessionScope.companies.includes(sessionCompany)) {
|
|
2477
|
+
ownershipRefused = true;
|
|
2478
|
+
syncCompanies = [];
|
|
2479
|
+
log("workspace-sync: skipped (handoff paths do not match the bound company)");
|
|
2480
|
+
}
|
|
2481
|
+
else {
|
|
2482
|
+
syncCompanies = [sessionCompany];
|
|
2483
|
+
try {
|
|
2484
|
+
const thread = JSON.parse(stripByteOrderMark(fs.readFileSync(threadFile, "utf8")));
|
|
2485
|
+
if (!isRecord(thread))
|
|
2486
|
+
throw new Error("thread is not an object");
|
|
2487
|
+
let metadata;
|
|
2488
|
+
if (thread.metadata === null || thread.metadata === undefined)
|
|
2489
|
+
metadata = {};
|
|
2490
|
+
else if (isRecord(thread.metadata))
|
|
2491
|
+
metadata = thread.metadata;
|
|
2492
|
+
else
|
|
2493
|
+
throw new Error("thread metadata is not an object");
|
|
2494
|
+
metadata.company = syncCompanies;
|
|
2495
|
+
metadata.company_slugs = syncCompanies;
|
|
2496
|
+
thread.metadata = metadata;
|
|
2497
|
+
const temporaryThread = path.join(path.dirname(threadFile), `.handoff-post-${process.pid}-${Math.random().toString(36).slice(2)}`);
|
|
2498
|
+
let temporaryFd;
|
|
2329
2499
|
try {
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
throw new Error("thread metadata is not an object");
|
|
2340
|
-
metadata.company = syncCompanies;
|
|
2341
|
-
thread.metadata = metadata;
|
|
2342
|
-
const temporaryThread = path.join(path.dirname(threadFile), `.handoff-post-${process.pid}-${Math.random().toString(36).slice(2)}`);
|
|
2343
|
-
let temporaryFd;
|
|
2344
|
-
try {
|
|
2345
|
-
temporaryFd = fs.openSync(temporaryThread, "wx", 0o600);
|
|
2346
|
-
fs.writeFileSync(temporaryFd, `${compactJson(thread).trimEnd()}\n`);
|
|
2347
|
-
fs.closeSync(temporaryFd);
|
|
2348
|
-
temporaryFd = undefined;
|
|
2349
|
-
fs.chmodSync(temporaryThread, 0o600);
|
|
2350
|
-
fs.renameSync(temporaryThread, threadFile);
|
|
2351
|
-
}
|
|
2352
|
-
catch (error) {
|
|
2353
|
-
if (temporaryFd !== undefined) {
|
|
2354
|
-
try {
|
|
2355
|
-
fs.closeSync(temporaryFd);
|
|
2356
|
-
}
|
|
2357
|
-
catch { /* temporary output cleanup remains best effort */ }
|
|
2358
|
-
}
|
|
2500
|
+
temporaryFd = fs.openSync(temporaryThread, "wx", 0o600);
|
|
2501
|
+
fs.writeFileSync(temporaryFd, `${compactJson(thread).trimEnd()}\n`);
|
|
2502
|
+
fs.closeSync(temporaryFd);
|
|
2503
|
+
temporaryFd = undefined;
|
|
2504
|
+
fs.chmodSync(temporaryThread, 0o600);
|
|
2505
|
+
fs.renameSync(temporaryThread, threadFile);
|
|
2506
|
+
}
|
|
2507
|
+
catch (error) {
|
|
2508
|
+
if (temporaryFd !== undefined) {
|
|
2359
2509
|
try {
|
|
2360
|
-
fs.
|
|
2510
|
+
fs.closeSync(temporaryFd);
|
|
2361
2511
|
}
|
|
2362
|
-
catch { /*
|
|
2363
|
-
throw error;
|
|
2512
|
+
catch { /* temporary output cleanup remains best effort */ }
|
|
2364
2513
|
}
|
|
2514
|
+
try {
|
|
2515
|
+
fs.rmSync(temporaryThread, { force: true });
|
|
2516
|
+
}
|
|
2517
|
+
catch { /* jq/mv cleanup is fail-soft */ }
|
|
2518
|
+
throw error;
|
|
2365
2519
|
}
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2520
|
+
}
|
|
2521
|
+
catch {
|
|
2522
|
+
log("workspace-sync: skipped (could not add bound company to handoff thread)");
|
|
2523
|
+
syncCompanies = [];
|
|
2370
2524
|
}
|
|
2371
2525
|
}
|
|
2372
2526
|
let threadId = "";
|
|
@@ -2379,10 +2533,10 @@ export function runHandoffPostWorker(args, context) {
|
|
|
2379
2533
|
&& /^T-[A-Za-z0-9._-]+$/.test(threadId);
|
|
2380
2534
|
}
|
|
2381
2535
|
catch { /* shell helper treats an invalid thread as non-mirrorable */ }
|
|
2382
|
-
if (threadMirrorable && syncCompanies.length
|
|
2536
|
+
if (!ownershipRefused && threadMirrorable && syncCompanies.length === 1 && sessionCompany && syncCompanies[0] === sessionCompany) {
|
|
2383
2537
|
const mirrorHook = path.join(root, ".claude/hooks/mirror-thread-to-company.sh");
|
|
2384
2538
|
if (fs.existsSync(mirrorHook))
|
|
2385
|
-
mirrorThread(root, threadFile);
|
|
2539
|
+
mirrorThread(root, threadFile, sessionCompany, context.logicalRoot);
|
|
2386
2540
|
else
|
|
2387
2541
|
log("workspace-sync: mirror hook unavailable for handoff thread");
|
|
2388
2542
|
}
|
|
@@ -2399,6 +2553,10 @@ export function runHandoffPostWorker(args, context) {
|
|
|
2399
2553
|
log(`workspace-sync: skipped (thread mirror missing for ${company})`);
|
|
2400
2554
|
continue;
|
|
2401
2555
|
}
|
|
2556
|
+
if (ownershipRefused) {
|
|
2557
|
+
log(`workspace-sync: skipped (ambiguous ownership for ${company})`);
|
|
2558
|
+
continue;
|
|
2559
|
+
}
|
|
2402
2560
|
const syncArgs = ["sync", "push", "--company", company, `companies/${company}/workspace`];
|
|
2403
2561
|
const spawnPlan = planHqSpawn(syncArgs, process.env, root);
|
|
2404
2562
|
const pushed = spawnSync(spawnPlan.cmd, spawnPlan.args, {
|
|
@@ -18,6 +18,24 @@ export function formatDelegateLockError(failure) {
|
|
|
18
18
|
? `could not acquire delegate lock: ${failure.detail}`
|
|
19
19
|
: 'could not acquire delegate lock';
|
|
20
20
|
}
|
|
21
|
+
const RELEASE_COORD_WAIT_MS = 5_000;
|
|
22
|
+
const RELEASE_COORD_POLL_MS = 10;
|
|
23
|
+
function sleepSync(ms) {
|
|
24
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
25
|
+
}
|
|
26
|
+
function acquireReleaseCoordination(coordinate, lock) {
|
|
27
|
+
const deadline = Date.now() + RELEASE_COORD_WAIT_MS;
|
|
28
|
+
while (true) {
|
|
29
|
+
const mutex = coordinate();
|
|
30
|
+
if (mutex)
|
|
31
|
+
return mutex;
|
|
32
|
+
if (!fs.existsSync(lock))
|
|
33
|
+
return null;
|
|
34
|
+
if (Date.now() >= deadline)
|
|
35
|
+
return null;
|
|
36
|
+
sleepSync(RELEASE_COORD_POLL_MS);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
21
39
|
/** A complete owner file is linked into place atomically. Legacy mkdir writers
|
|
22
40
|
* see EEXIST; unknown legacy directories stay held. Returns a structured result
|
|
23
41
|
* so callers can tell a held lock apart from a probe timeout or I/O error. */
|
|
@@ -174,7 +192,7 @@ export function acquireDelegateLockDetailed(lock, options = {}) {
|
|
|
174
192
|
ok: true,
|
|
175
193
|
lock: {
|
|
176
194
|
release() {
|
|
177
|
-
const releaseMutex = coordinate
|
|
195
|
+
const releaseMutex = acquireReleaseCoordination(coordinate, lock);
|
|
178
196
|
if (!releaseMutex)
|
|
179
197
|
return;
|
|
180
198
|
try {
|
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.263",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -128,11 +128,11 @@
|
|
|
128
128
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
129
129
|
},
|
|
130
130
|
"optionalDependencies": {
|
|
131
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
133
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
134
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
135
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
136
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
131
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.263",
|
|
132
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.263",
|
|
133
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.263",
|
|
134
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.263",
|
|
135
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.263",
|
|
136
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.263"
|
|
137
137
|
}
|
|
138
138
|
}
|