@indigoai-us/hq-cli 5.345.270 → 5.345.273
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 +64 -0
- package/contracts/host-canary-release.json +7 -7
- package/dist/command-catalog.generated.d.ts +2 -2
- package/dist/command-catalog.generated.js +2 -2
- package/dist/commands/core-checkpoint-stop-gate-native.js +2 -13
- package/dist/commands/core-session-journal-native.js +20 -4
- package/dist/commands/signals-run.d.ts +4 -1
- package/dist/commands/signals-run.js +6 -8
- package/dist/commands/sync-core.js +2 -1
- package/dist/lib/daemon/daemon-restart.d.ts +70 -0
- package/dist/lib/daemon/daemon-restart.js +114 -0
- package/dist/lib/daemon/hook-requests-work-mesh-shims.d.ts +41 -0
- package/dist/lib/daemon/hook-requests-work-mesh-shims.js +237 -0
- package/dist/lib/daemon/hook-requests.d.ts +4 -1
- package/dist/lib/daemon/hook-requests.js +23 -1
- package/dist/lib/daemon/hq-child-bootstrap.mjs +1 -0
- package/dist/lib/daemon/installed-cli-restart.js +14 -4
- package/dist/lib/daemon/merge-sections.d.ts +24 -1
- package/dist/lib/daemon/merge-sections.js +59 -11
- package/dist/lib/daemon/run.d.ts +1 -1
- package/dist/lib/daemon/run.js +67 -53
- package/dist/lib/daemon/supervisor.js +0 -2
- package/dist/lib/hook-engine/coverage.d.ts +21 -0
- package/dist/lib/hook-engine/coverage.js +98 -5
- package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +2 -1
- package/dist/lib/hot-channels/signals-pass.d.ts +10 -2
- package/dist/lib/hot-channels/signals-pass.js +13 -3
- package/dist/lib/signals/engine.d.ts +0 -2
- package/dist/lib/signals/engine.js +12 -7
- package/dist/lib/signals/reply.js +35 -82
- package/dist/lib/signals/run-lock.d.ts +8 -0
- package/dist/lib/signals/run-lock.js +42 -7
- package/dist/lib/signals/run-record.js +2 -1
- package/dist/lib/signals/settings.d.ts +9 -4
- package/dist/lib/signals/settings.js +7 -5
- package/dist/lib/signals/steps/extract.d.ts +37 -10
- package/dist/lib/signals/steps/extract.js +88 -111
- package/dist/lib/signals/steps/types.d.ts +3 -2
- package/dist/lib/sync-core/reconcile.d.ts +7 -1
- package/dist/lib/sync-core/reconcile.js +105 -18
- package/dist/lib/sync-core/release.d.ts +52 -2
- package/dist/lib/sync-core/release.js +172 -11
- package/dist/lib/sync-core/rollout-state.d.ts +11 -0
- package/dist/lib/sync-core/rollout-state.js +16 -0
- package/dist/utils/client-health-contract.d.ts +32 -0
- package/dist/utils/client-health-contract.js +35 -0
- package/dist/utils/client-health.d.ts +43 -0
- package/dist/utils/client-health.js +106 -3
- package/dist/utils/login-browser.d.ts +1 -0
- package/dist/utils/login-browser.js +31 -6
- package/dist/utils/spawn-detached-hidden.d.ts +66 -0
- package/dist/utils/spawn-detached-hidden.js +222 -0
- package/package.json +7 -7
package/dist/lib/daemon/run.js
CHANGED
|
@@ -69,7 +69,7 @@ import { needsWindowsTaskRelaunch, scheduleWindowsTaskRelaunch } from "./windows
|
|
|
69
69
|
import { detectMachineType } from "./machine-type.js";
|
|
70
70
|
import { appendPrivate, daemonPaths, ensurePrivateDir, openPrivateAppend } from "./paths.js";
|
|
71
71
|
import { SELF_CHECK_RESULT_FILE, readSelfCheckResult } from "./selfcheck.js";
|
|
72
|
-
import { createRegistryMergeFlagReader, startMergeSectionRefresh } from "./merge-sections.js";
|
|
72
|
+
import { createRegistryMergeFlagReader, MERGE_FLAG_REFRESH_AHEAD_MS, startMergeSectionRefresh } from "./merge-sections.js";
|
|
73
73
|
import { createDaemonStateWriter, daemonStateFilePath, defaultDaemonStateFilePath, readVaultAccessManifest, selfCheckMachineChecks, } from "./state-file.js";
|
|
74
74
|
import { hqdSocketPath } from "./protocol.js";
|
|
75
75
|
import { startHqdServer, syncHqdEnabledMarker } from "./server.js";
|
|
@@ -79,6 +79,7 @@ import { daemonStartEnv } from "./hook-env.js";
|
|
|
79
79
|
import { createProtocolTail, ensureProtocolFifo, openProtocolWriter } from "./protocol-tail.js";
|
|
80
80
|
import { takeControlRequests, writeControlRequest } from "./requests.js";
|
|
81
81
|
import { createInstalledCliRestartCheck, installedCliVersionOnDisk } from "./installed-cli-restart.js";
|
|
82
|
+
import { createDaemonRestart, exitWhenStopped, logServicesStopped, servicesAndJobsStopped, stopServicesAndExit, timeoutCap } from "./daemon-restart.js";
|
|
82
83
|
import { currentHqCloud, currentHqCloudAfterLeaseRelease, hqCloudRunners, hqCloudVersionOlder } from "./hq-cloud.js";
|
|
83
84
|
import { stageSyncRunnerBundle } from "./sync-runner-bundle.js";
|
|
84
85
|
import { stageHqChildBootstrap } from "./hq-child-bootstrap-stage.js";
|
|
@@ -780,6 +781,7 @@ export function unitProcessEnv(base, unit) {
|
|
|
780
781
|
};
|
|
781
782
|
for (const key of DAEMON_CHILD_ONE_SHOT_KEYS)
|
|
782
783
|
delete env[key];
|
|
784
|
+
delete env.HQ_DAEMON_UNIT_PARENT_PID;
|
|
783
785
|
// Scheduled hq commands stay eligible for Sentry. The resident mark goes only
|
|
784
786
|
// to a long-running hq command, which clears it before starting another hq
|
|
785
787
|
// command. A sync runner, sync-core engine, or outpost node runner must not
|
|
@@ -797,12 +799,14 @@ export function unitProcessEnv(base, unit) {
|
|
|
797
799
|
* leave even if it is killed before it can signal. Node and exec runners do
|
|
798
800
|
* not get either value.
|
|
799
801
|
*/
|
|
800
|
-
export function daemonChildOwnershipEnv(base, unit, handoffPath) {
|
|
802
|
+
export function daemonChildOwnershipEnv(base, unit, handoffPath, daemonPid = process.pid) {
|
|
801
803
|
const env = unitProcessEnv(base, unit);
|
|
802
804
|
if (unit.command?.type === "hq") {
|
|
803
805
|
if (handoffPath)
|
|
804
806
|
env.HQ_DAEMON_HANDOFF_PATH = handoffPath;
|
|
805
807
|
env.HQ_DAEMON_OWNER_CONTROL_FD = "3";
|
|
808
|
+
// The unit's own parent. The staged launcher replaces it with its pid.
|
|
809
|
+
env.HQ_DAEMON_UNIT_PARENT_PID = String(daemonPid);
|
|
806
810
|
}
|
|
807
811
|
return env;
|
|
808
812
|
}
|
|
@@ -1241,7 +1245,7 @@ export async function runDaemon(opts) {
|
|
|
1241
1245
|
// between the 30-second registry requests (merge-sections.ts).
|
|
1242
1246
|
const mergeSections = startMergeSectionRefresh({
|
|
1243
1247
|
hqRoot: () => readDaemonConfig(paths.configPath).hqRoot ?? (env.HQ_ROOT?.trim() || undefined),
|
|
1244
|
-
readFlag: createRegistryMergeFlagReader({ env }),
|
|
1248
|
+
readFlag: createRegistryMergeFlagReader({ env, refreshAheadMs: MERGE_FLAG_REFRESH_AHEAD_MS }),
|
|
1245
1249
|
onRefresh: () => stateWriter.refresh(),
|
|
1246
1250
|
log,
|
|
1247
1251
|
});
|
|
@@ -2110,7 +2114,11 @@ export async function runDaemon(opts) {
|
|
|
2110
2114
|
};
|
|
2111
2115
|
return await new Promise((resolve) => {
|
|
2112
2116
|
let stopping = false;
|
|
2113
|
-
|
|
2117
|
+
const exitAfter = (hardExitMs) => (code) => {
|
|
2118
|
+
extendSyncShutdownCap = undefined;
|
|
2119
|
+
resolve(code);
|
|
2120
|
+
setTimeout(() => process.exit(code), hardExitMs).unref();
|
|
2121
|
+
};
|
|
2114
2122
|
const shutdown = (why, exitCode = 0) => {
|
|
2115
2123
|
if (stopping)
|
|
2116
2124
|
return;
|
|
@@ -2123,25 +2131,30 @@ export async function runDaemon(opts) {
|
|
|
2123
2131
|
const stopJobsClosed = closeRuntimeWatchers();
|
|
2124
2132
|
// Keep shutdown bounded, but let a stopping sync runner reach its persist deadline.
|
|
2125
2133
|
const cap = createShutdownCap();
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
cap.extendForSyncRunnerPersist
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2134
|
+
let servicesStopped;
|
|
2135
|
+
try {
|
|
2136
|
+
extendSyncShutdownCap = cap.extendForSyncRunnerPersist;
|
|
2137
|
+
if (supervisor.hasStoppingSyncRunner())
|
|
2138
|
+
cap.extendForSyncRunnerPersist();
|
|
2139
|
+
servicesStopped = supervisor.stop();
|
|
2140
|
+
syncPerfForwarder.stop();
|
|
2141
|
+
}
|
|
2142
|
+
catch (err) {
|
|
2132
2143
|
cap.clear();
|
|
2133
2144
|
extendSyncShutdownCap = undefined;
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
+
throw err;
|
|
2146
|
+
}
|
|
2147
|
+
// Pipes, sockets and unrelated timers can outlive a clean shutdown.
|
|
2148
|
+
// Services and the lock are already stopped; unrelated handles should
|
|
2149
|
+
// not hold a restart or signal exit open for another service interval.
|
|
2150
|
+
void exitWhenStopped({
|
|
2151
|
+
stopped: servicesAndJobsStopped(servicesStopped, stopJobsClosed, log),
|
|
2152
|
+
cap,
|
|
2153
|
+
releaseLock: () => releaseDaemonLock(paths.lockPath),
|
|
2154
|
+
exit: exitAfter(1_000),
|
|
2155
|
+
log,
|
|
2156
|
+
onSettled: (result) => logServicesStopped(log, result),
|
|
2157
|
+
}, exitCode);
|
|
2145
2158
|
};
|
|
2146
2159
|
/** Exit for a restart but leave the services running for the next daemon to adopt. */
|
|
2147
2160
|
const handOver = () => {
|
|
@@ -2185,40 +2198,41 @@ export async function runDaemon(opts) {
|
|
|
2185
2198
|
child.unref();
|
|
2186
2199
|
// The aborted Stop job's receipt is written before the lease is released
|
|
2187
2200
|
// (bounded: the job's child is already signalled).
|
|
2188
|
-
|
|
2189
|
-
void
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
releaseDaemonLock(paths.lockPath)
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
});
|
|
2201
|
+
// Anything else still holding the event loop open must not delay the restart.
|
|
2202
|
+
void exitWhenStopped({
|
|
2203
|
+
stopped: stopJobsClosed,
|
|
2204
|
+
cap: timeoutCap(3_000),
|
|
2205
|
+
releaseLock: () => releaseDaemonLock(paths.lockPath),
|
|
2206
|
+
exit: exitAfter(5_000),
|
|
2207
|
+
log,
|
|
2208
|
+
}, RESTART_EXIT_CODE);
|
|
2197
2209
|
};
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
if (!stopping)
|
|
2214
|
-
relaunchWindowsTaskAfterExit();
|
|
2215
|
-
if (handoff && succession)
|
|
2216
|
-
handOver();
|
|
2217
|
-
else
|
|
2218
|
-
shutdown("restarting onto the updated CLI", RESTART_EXIT_CODE);
|
|
2219
|
-
return true;
|
|
2220
|
-
});
|
|
2210
|
+
const exitForRestartNow = () => {
|
|
2211
|
+
stopping = true;
|
|
2212
|
+
daemonStopping = true;
|
|
2213
|
+
void stopServicesAndExit({
|
|
2214
|
+
stopServices: () => supervisor.stop(),
|
|
2215
|
+
hasStoppingSyncRunner: () => supervisor.hasStoppingSyncRunner(),
|
|
2216
|
+
createCap: () => {
|
|
2217
|
+
const cap = createShutdownCap();
|
|
2218
|
+
extendSyncShutdownCap = cap.extendForSyncRunnerPersist;
|
|
2219
|
+
return cap;
|
|
2220
|
+
},
|
|
2221
|
+
releaseLock: () => releaseDaemonLock(paths.lockPath),
|
|
2222
|
+
exit: exitAfter(1_000),
|
|
2223
|
+
log,
|
|
2224
|
+
}, RESTART_EXIT_CODE);
|
|
2221
2225
|
};
|
|
2226
|
+
restartDaemon = createDaemonRestart({
|
|
2227
|
+
canRestart: () => restartsForParent(opts),
|
|
2228
|
+
isStopping: () => stopping,
|
|
2229
|
+
handoffWanted,
|
|
2230
|
+
beforeExit: relaunchWindowsTaskAfterExit,
|
|
2231
|
+
handOver: succession ? handOver : null,
|
|
2232
|
+
shutdown: () => shutdown("restarting onto the updated CLI", RESTART_EXIT_CODE),
|
|
2233
|
+
exitNow: exitForRestartNow,
|
|
2234
|
+
log,
|
|
2235
|
+
});
|
|
2222
2236
|
hqdShutdown = () => shutdown("hqd shutdown request");
|
|
2223
2237
|
tccEpermExit = (code) => shutdown("macOS refused file access under the HQ root; exiting so launchd starts a fresh daemon", code);
|
|
2224
2238
|
process.on("SIGTERM", () => shutdown("received SIGTERM"));
|
|
@@ -423,8 +423,6 @@ export function createSupervisor(deps) {
|
|
|
423
423
|
}
|
|
424
424
|
deferredCliRestart = true;
|
|
425
425
|
deps.log("info", "deferring CLI-update restart until sync is idle (maximum 10 minutes)");
|
|
426
|
-
if (pendingSyncCommandRestart?.slot === sync)
|
|
427
|
-
return;
|
|
428
426
|
deferredCliRestartTimer = setT(() => runDeferredCliRestart(true), CLI_UPDATE_SYNC_IDLE_MAX_MS);
|
|
429
427
|
};
|
|
430
428
|
const deferSyncCommandRestart = (slot, onFinish) => {
|
|
@@ -209,6 +209,27 @@ export declare const SESSION_START_PINS: ReadonlyArray<readonly [string, readonl
|
|
|
209
209
|
* any revision it does not rebuild. Null when every file matches.
|
|
210
210
|
*/
|
|
211
211
|
export declare function sessionStartHold(root: string): string | null;
|
|
212
|
+
/**
|
|
213
|
+
* Pinned revisions of the five legacy core Work Mesh shims and their `core/hooks/work-mesh-*.sh`
|
|
214
|
+
* bodies (`crates/hq-hook/src/work_mesh_shims.rs`):
|
|
215
|
+
* - `work-mesh-close.sh`: hq-core v16.0.52 (`8203c5f1`) and v16.0.53-beta.4 (`f8a3b57b`).
|
|
216
|
+
* - `work-mesh-register.sh` and `work-mesh-ground.sh`: upgraded-root and v15.0.120 revisions.
|
|
217
|
+
* Each shim is existence-gated: a fresh install without the shim on disk is never held.
|
|
218
|
+
*/
|
|
219
|
+
export interface WorkMeshShimPin {
|
|
220
|
+
readonly shim: PinnedFile;
|
|
221
|
+
readonly body: PinnedFile;
|
|
222
|
+
}
|
|
223
|
+
export declare const WORK_MESH_SESSION_START_PINS: readonly WorkMeshShimPin[];
|
|
224
|
+
export declare const WORK_MESH_USER_PROMPT_SUBMIT_PINS: readonly WorkMeshShimPin[];
|
|
225
|
+
export declare const WORK_MESH_SESSION_END_PINS: readonly WorkMeshShimPin[];
|
|
226
|
+
/**
|
|
227
|
+
* Why `event` (`SessionStart`, `UserPromptSubmit`, or `SessionEnd`) must stay on the shell
|
|
228
|
+
* registration for a present legacy Work Mesh shim in `root`: the shim file exists on disk, is
|
|
229
|
+
* claimed in `covered`, and either the shim or its `core/hooks/work-mesh-*.sh` body is not a
|
|
230
|
+
* pinned revision (`pinnedFilesHold`). Missing shims are not held.
|
|
231
|
+
*/
|
|
232
|
+
export declare function workMeshShimsHold(root: string, event: 'SessionStart' | 'UserPromptSubmit' | 'SessionEnd', covered: readonly string[]): string | null;
|
|
212
233
|
/**
|
|
213
234
|
* The script revisions the native SessionStart `migrate-policy-triggers` port rebuilds
|
|
214
235
|
* (`crates/hq-hook/src/session_start_ss1/migrate_triggers.rs`: `SCRIPT_SHA256`,
|
|
@@ -1815,6 +1815,11 @@ export function uncoveredHooks(root, host, event, covers, env = process.env) {
|
|
|
1815
1815
|
if (hold)
|
|
1816
1816
|
missing.push(`(native SessionStart compatibility: ${hold})`);
|
|
1817
1817
|
}
|
|
1818
|
+
if (event === 'SessionStart' || event === 'UserPromptSubmit' || event === 'SessionEnd') {
|
|
1819
|
+
const hold = workMeshShimsHold(root, event, covered);
|
|
1820
|
+
if (hold)
|
|
1821
|
+
missing.push(`(native ${event} compatibility: ${hold})`);
|
|
1822
|
+
}
|
|
1818
1823
|
if (host === 'fleet-local' && event === 'PreToolUse' && covered.includes('fleet-local-adapter:PreToolUse')) {
|
|
1819
1824
|
const hold = fleetLocalPreToolUseHold(root);
|
|
1820
1825
|
if (hold)
|
|
@@ -1921,7 +1926,7 @@ export const SESSION_START_PINS = [
|
|
|
1921
1926
|
['core/scripts/hqd-hook-flag-cache-lib.sh', ['061d264460408e9eaf43fdf0fdde662c906a9a7dacb4e7a591e684bca28c138a']],
|
|
1922
1927
|
['core/scripts/hq-session.sh', ['db701162f71b53fd2188974d2f46c58250593dde1252d65b36e6d02b9a765fe7', '02a37c5dbf4fb5af27cc64d0f271121e990758b757a479f60e9ce099f4d65ded', 'd4d4aef60ff8b095e3abcc817598f376d3c2de8d59758c3ed6dd40d4aa4b11fb']],
|
|
1923
1928
|
['core/scripts/lib/session-id.sh', ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d', 'd6a04155571ec53edd853878cebaba5a5bab93801a73e356499440c1cd009c71']],
|
|
1924
|
-
['core/scripts/lib/session-scope-capability.sh', ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38']],
|
|
1929
|
+
['core/scripts/lib/session-scope-capability.sh', ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38', 'cceddf40b3ec932cc4c83b31d72d9462f5a09be32246d57299591f4b75bdcd5a']],
|
|
1925
1930
|
['core/scripts/resolve-company.sh', ['00d6fa069f574a86087c77daa44887a2617446d4300d5daebecc9bfb5d81abe7']],
|
|
1926
1931
|
];
|
|
1927
1932
|
/**
|
|
@@ -1947,6 +1952,94 @@ export function sessionStartHold(root) {
|
|
|
1947
1952
|
}
|
|
1948
1953
|
return null;
|
|
1949
1954
|
}
|
|
1955
|
+
const WORK_MESH_REGISTER_BODY_PIN = {
|
|
1956
|
+
relative: 'core/hooks/work-mesh-register.sh',
|
|
1957
|
+
accepted: [
|
|
1958
|
+
'e02a0f24da2bc094c0ee78ee68b8f35659e30f62e38bf386f2f833f94d580e57',
|
|
1959
|
+
'5cbc16337f2e8dbd0f2c5322edc2be654d8c24887ccb435ad4e22a538483d685',
|
|
1960
|
+
],
|
|
1961
|
+
missing: 'allowed',
|
|
1962
|
+
};
|
|
1963
|
+
const WORK_MESH_CLOSE_BODY_PIN = {
|
|
1964
|
+
relative: 'core/hooks/work-mesh-close.sh',
|
|
1965
|
+
accepted: [
|
|
1966
|
+
'8203c5f18b296a392d843ba259e081de6b854932abb215e30cd068ed3c17c898',
|
|
1967
|
+
'f8a3b57b0df638968a1750d1c98dccdb9f37106a7027dfd8aebf4ae5243e4456',
|
|
1968
|
+
],
|
|
1969
|
+
missing: 'allowed',
|
|
1970
|
+
};
|
|
1971
|
+
const WORK_MESH_GROUND_BODY_PIN = {
|
|
1972
|
+
relative: 'core/hooks/work-mesh-ground.sh',
|
|
1973
|
+
accepted: [
|
|
1974
|
+
'22000e66f7f133f8ccda9556d53f61b6c861caf4169f78f142cd70d5e034eae0',
|
|
1975
|
+
'eb4ab208156399da64d925564b87191d3685d3ede4925e6b7f4e41467fdcd645',
|
|
1976
|
+
],
|
|
1977
|
+
missing: 'allowed',
|
|
1978
|
+
};
|
|
1979
|
+
export const WORK_MESH_SESSION_START_PINS = [
|
|
1980
|
+
{
|
|
1981
|
+
shim: {
|
|
1982
|
+
relative: 'core/hooks/SessionStart/35-work-mesh-register.sh',
|
|
1983
|
+
accepted: ['89f53b15099c7b01de6c5eeb35a7d40aa5075e8c4ac8cf9a6e511799cb3b57b9'],
|
|
1984
|
+
},
|
|
1985
|
+
body: WORK_MESH_REGISTER_BODY_PIN,
|
|
1986
|
+
},
|
|
1987
|
+
{
|
|
1988
|
+
shim: {
|
|
1989
|
+
relative: 'core/hooks/SessionStart/36-work-mesh-sweep.sh',
|
|
1990
|
+
accepted: ['870931f665f97cfa957806c2ba5466eb3ee2922a32c3c331a7c6fe447b60fc56'],
|
|
1991
|
+
},
|
|
1992
|
+
body: WORK_MESH_CLOSE_BODY_PIN,
|
|
1993
|
+
},
|
|
1994
|
+
];
|
|
1995
|
+
export const WORK_MESH_USER_PROMPT_SUBMIT_PINS = [
|
|
1996
|
+
{
|
|
1997
|
+
shim: {
|
|
1998
|
+
relative: 'core/hooks/UserPromptSubmit/35-work-mesh-register.sh',
|
|
1999
|
+
accepted: ['89f53b15099c7b01de6c5eeb35a7d40aa5075e8c4ac8cf9a6e511799cb3b57b9'],
|
|
2000
|
+
},
|
|
2001
|
+
body: WORK_MESH_REGISTER_BODY_PIN,
|
|
2002
|
+
},
|
|
2003
|
+
{
|
|
2004
|
+
shim: {
|
|
2005
|
+
relative: 'core/hooks/UserPromptSubmit/70-work-mesh-ground.sh',
|
|
2006
|
+
accepted: ['d07328e4e5d8d3572e91321d209bf4c712317b1c6616ddd9084d3e544baa2e88'],
|
|
2007
|
+
},
|
|
2008
|
+
body: WORK_MESH_GROUND_BODY_PIN,
|
|
2009
|
+
},
|
|
2010
|
+
];
|
|
2011
|
+
export const WORK_MESH_SESSION_END_PINS = [
|
|
2012
|
+
{
|
|
2013
|
+
shim: {
|
|
2014
|
+
relative: 'core/hooks/SessionEnd/35-work-mesh-close.sh',
|
|
2015
|
+
accepted: ['878d8e77bf67f3ad0cb9754ff625a001083213751ef2832c6071288e0b9f5bbe'],
|
|
2016
|
+
},
|
|
2017
|
+
body: WORK_MESH_CLOSE_BODY_PIN,
|
|
2018
|
+
},
|
|
2019
|
+
];
|
|
2020
|
+
/**
|
|
2021
|
+
* Why `event` (`SessionStart`, `UserPromptSubmit`, or `SessionEnd`) must stay on the shell
|
|
2022
|
+
* registration for a present legacy Work Mesh shim in `root`: the shim file exists on disk, is
|
|
2023
|
+
* claimed in `covered`, and either the shim or its `core/hooks/work-mesh-*.sh` body is not a
|
|
2024
|
+
* pinned revision (`pinnedFilesHold`). Missing shims are not held.
|
|
2025
|
+
*/
|
|
2026
|
+
export function workMeshShimsHold(root, event, covered) {
|
|
2027
|
+
const entries = event === 'SessionStart'
|
|
2028
|
+
? WORK_MESH_SESSION_START_PINS
|
|
2029
|
+
: event === 'UserPromptSubmit'
|
|
2030
|
+
? WORK_MESH_USER_PROMPT_SUBMIT_PINS
|
|
2031
|
+
: WORK_MESH_SESSION_END_PINS;
|
|
2032
|
+
for (const entry of entries) {
|
|
2033
|
+
if (!covered.includes(entry.shim.relative))
|
|
2034
|
+
continue;
|
|
2035
|
+
if (!regularFile(path.join(root, entry.shim.relative)))
|
|
2036
|
+
continue;
|
|
2037
|
+
const hold = pinnedFilesHold(root, event, [entry.shim, entry.body]);
|
|
2038
|
+
if (hold)
|
|
2039
|
+
return hold;
|
|
2040
|
+
}
|
|
2041
|
+
return null;
|
|
2042
|
+
}
|
|
1950
2043
|
/**
|
|
1951
2044
|
* The script revisions the native SessionStart `migrate-policy-triggers` port rebuilds
|
|
1952
2045
|
* (`crates/hq-hook/src/session_start_ss1/migrate_triggers.rs`: `SCRIPT_SHA256`,
|
|
@@ -2023,7 +2116,7 @@ export const FLEET_LOCAL_PRE_TOOL_USE_PINS = [
|
|
|
2023
2116
|
],
|
|
2024
2117
|
missing: 'allowed',
|
|
2025
2118
|
},
|
|
2026
|
-
{ relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38'], missing: 'allowed' },
|
|
2119
|
+
{ relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38', 'cceddf40b3ec932cc4c83b31d72d9462f5a09be32246d57299591f4b75bdcd5a'], missing: 'allowed' },
|
|
2027
2120
|
];
|
|
2028
2121
|
/**
|
|
2029
2122
|
* Why fleet-local PreToolUse must stay on the shell adapter in `root`: a present file of
|
|
@@ -2263,7 +2356,7 @@ export const PRE_TOOL_USE_DISPATCHER_PINS = [
|
|
|
2263
2356
|
{ relative: 'core/scripts/lib/epochrealtime.sh', accepted: ['4c9205520dba31533c95eea145f6068ba626885c342c2aa1f232a7237d046cdf'] },
|
|
2264
2357
|
{ relative: 'core/scripts/lib/perl-child-locale.sh', accepted: ['18e6b9d0e22874eea00ecc868b4dcfebbc3bb42434d8d0c81b20baec1194df2e'] },
|
|
2265
2358
|
{ relative: 'core/scripts/lib/session-id.sh', accepted: ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d', 'd6a04155571ec53edd853878cebaba5a5bab93801a73e356499440c1cd009c71'] },
|
|
2266
|
-
{ relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38'] },
|
|
2359
|
+
{ relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38', 'cceddf40b3ec932cc4c83b31d72d9462f5a09be32246d57299591f4b75bdcd5a'] },
|
|
2267
2360
|
{ relative: 'core/scripts/resolve-hq-root.sh', accepted: ['188e99c7c60bc9909290a666d6f3b93387ae6cf68f2eeb41fd24c2dea62a5240'] },
|
|
2268
2361
|
];
|
|
2269
2362
|
/**
|
|
@@ -2684,7 +2777,7 @@ export const PROMPT_COMPANY_BIND_PINS = [
|
|
|
2684
2777
|
},
|
|
2685
2778
|
{ relative: 'core/scripts/hq-session.sh', accepted: ['db701162f71b53fd2188974d2f46c58250593dde1252d65b36e6d02b9a765fe7', '02a37c5dbf4fb5af27cc64d0f271121e990758b757a479f60e9ce099f4d65ded', 'd4d4aef60ff8b095e3abcc817598f376d3c2de8d59758c3ed6dd40d4aa4b11fb'] },
|
|
2686
2779
|
{ relative: 'core/scripts/lib/session-id.sh', accepted: ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d', 'd6a04155571ec53edd853878cebaba5a5bab93801a73e356499440c1cd009c71'] },
|
|
2687
|
-
{ relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38'] },
|
|
2780
|
+
{ relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38', 'cceddf40b3ec932cc4c83b31d72d9462f5a09be32246d57299591f4b75bdcd5a'] },
|
|
2688
2781
|
];
|
|
2689
2782
|
/**
|
|
2690
2783
|
* Why UserPromptSubmit must stay on the shell registration in `root`: the native
|
|
@@ -2787,7 +2880,7 @@ export function postToolUseAdapterHold(root, host) {
|
|
|
2787
2880
|
return null;
|
|
2788
2881
|
}
|
|
2789
2882
|
/** The session-scope-capability.sh master-hook's Task-agent pin is modelled on (crates/hq-hook/src/scope/session.rs `SUBAGENT_PIN_LIB_SHA256`). */
|
|
2790
|
-
export const SUBAGENT_SCOPE_LIBRARY = { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38'] };
|
|
2883
|
+
export const SUBAGENT_SCOPE_LIBRARY = { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38', 'cceddf40b3ec932cc4c83b31d72d9462f5a09be32246d57299591f4b75bdcd5a'] };
|
|
2791
2884
|
/**
|
|
2792
2885
|
* Why SubagentStart or SubagentStop (`event`) must stay on the shell registration in `root`: the
|
|
2793
2886
|
* native master work (crates/hq-hook/src/lifecycle_master.rs `begin`) refuses every such event that
|
|
@@ -310,6 +310,7 @@
|
|
|
310
310
|
"3194d664e3840dcbf48a2d5681feb7cd299bd6f60d296337c70d8042d60886c2",
|
|
311
311
|
"388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead",
|
|
312
312
|
"498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38",
|
|
313
|
+
"cceddf40b3ec932cc4c83b31d72d9462f5a09be32246d57299591f4b75bdcd5a",
|
|
313
314
|
"5d4c619a55db0de6ff210a3aa0e99aa92fb5795a3290dcfcafc141e3ad3894b6",
|
|
314
315
|
"743d9438922f0bcc29f09b38f159b4fd686cc2ba15390602ef7b7f1d8db9ac26",
|
|
315
316
|
"9ea044084200e5f2d1f47477ffeaf591a87b406e9bf48c8fd6e24c551c799fc1",
|
|
@@ -197,7 +197,8 @@
|
|
|
197
197
|
],
|
|
198
198
|
"core/scripts/lib/session-scope-capability.sh": [
|
|
199
199
|
"388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead",
|
|
200
|
-
"498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38"
|
|
200
|
+
"498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38",
|
|
201
|
+
"cceddf40b3ec932cc4c83b31d72d9462f5a09be32246d57299591f4b75bdcd5a"
|
|
201
202
|
],
|
|
202
203
|
"core/scripts/lib/transcript-tail.sh": [
|
|
203
204
|
"73eadafdd8e7c375bd12383947ac73c43e7dfe79b29e6553da1cb5b2746bb217"
|
|
@@ -133,8 +133,9 @@ export declare const WORKLIST_TIMEOUT_MS = 60000;
|
|
|
133
133
|
* - Unusable replies: 40 documents x BAD_OUTPUT_ATTEMPTS (3) calls x 120 s =
|
|
134
134
|
* 4 hours (2 hours at the old cap of 20). That is longer than the 3 hours
|
|
135
135
|
* after which the engine's company run lock can be taken over (LOCK_STALE_MS
|
|
136
|
-
* in src/lib/signals/run-lock.ts
|
|
137
|
-
*
|
|
136
|
+
* in src/lib/signals/run-lock.ts). The engine refreshes that lock when a
|
|
137
|
+
* step starts or finishes, so the 3 hours count from the start of the
|
|
138
|
+
* adapters step; this pass does not refresh it per document.
|
|
138
139
|
* - Once a timed-out document is skipped instead of sent again (PR 3438, not
|
|
139
140
|
* merged when this was written): 40 x 120 s = 80 minutes (40 minutes at the
|
|
140
141
|
* old cap). That is longer than the 60 minutes after which the bot releases
|
|
@@ -156,6 +157,13 @@ export declare const BAD_OUTPUT_STOP_AFTER = 3;
|
|
|
156
157
|
export declare const TIMEOUT_STOP_AFTER = 3;
|
|
157
158
|
/** Payload bytes sent to claude per document (200 KB). A longer payload is cut with a marker. */
|
|
158
159
|
export declare const MAX_PAYLOAD_BYTES: number;
|
|
160
|
+
/** A reply that opens as a provider's limit sentence and has no clause after it. */
|
|
161
|
+
/**
|
|
162
|
+
* True when the whole text is a provider's usage-limit sentence: short, opening
|
|
163
|
+
* as the sentence, with no clause after it. Prose that mentions a limit, or a
|
|
164
|
+
* longer text that contains the sentence, is not one.
|
|
165
|
+
*/
|
|
166
|
+
export declare function isUsageLimitSentence(text: string): boolean;
|
|
159
167
|
export interface BoundedRun {
|
|
160
168
|
code: number | null;
|
|
161
169
|
stdout: string;
|
|
@@ -307,8 +307,9 @@ export const WORKLIST_TIMEOUT_MS = 60_000;
|
|
|
307
307
|
* - Unusable replies: 40 documents x BAD_OUTPUT_ATTEMPTS (3) calls x 120 s =
|
|
308
308
|
* 4 hours (2 hours at the old cap of 20). That is longer than the 3 hours
|
|
309
309
|
* after which the engine's company run lock can be taken over (LOCK_STALE_MS
|
|
310
|
-
* in src/lib/signals/run-lock.ts
|
|
311
|
-
*
|
|
310
|
+
* in src/lib/signals/run-lock.ts). The engine refreshes that lock when a
|
|
311
|
+
* step starts or finishes, so the 3 hours count from the start of the
|
|
312
|
+
* adapters step; this pass does not refresh it per document.
|
|
312
313
|
* - Once a timed-out document is skipped instead of sent again (PR 3438, not
|
|
313
314
|
* merged when this was written): 40 x 120 s = 80 minutes (40 minutes at the
|
|
314
315
|
* old cap). That is longer than the 60 minutes after which the bot releases
|
|
@@ -341,6 +342,15 @@ const MAX_REASON_CHARS = 300;
|
|
|
341
342
|
/** A reply longer than this is not a provider's limit sentence. */
|
|
342
343
|
const MAX_LIMIT_SENTENCE_CHARS = 500;
|
|
343
344
|
/** A reply that opens as a provider's limit sentence and has no clause after it. */
|
|
345
|
+
/**
|
|
346
|
+
* True when the whole text is a provider's usage-limit sentence: short, opening
|
|
347
|
+
* as the sentence, with no clause after it. Prose that mentions a limit, or a
|
|
348
|
+
* longer text that contains the sentence, is not one.
|
|
349
|
+
*/
|
|
350
|
+
export function isUsageLimitSentence(text) {
|
|
351
|
+
const t = text.trim();
|
|
352
|
+
return t.length <= MAX_LIMIT_SENTENCE_CHARS && LIMIT_SENTENCE_REPLY.test(t) && isRuntimeUsageLimit(t);
|
|
353
|
+
}
|
|
344
354
|
const LIMIT_SENTENCE_REPLY = /^(?:you(?:['’]?ve| have) (?:hit|reached) your |you['’]?re out of |(?:claude ai )?usage limit )[^,;\n]*(?:$|[|·.])/i;
|
|
345
355
|
/**
|
|
346
356
|
* Run a command with a hard timeout. The child leads its own process group;
|
|
@@ -786,7 +796,7 @@ export function parseSignalsReply(reply, runtime) {
|
|
|
786
796
|
// A limit sentence can arrive as a plain successful reply. The whole reply
|
|
787
797
|
// must be that sentence, so prose about a limit stays bad output, and the
|
|
788
798
|
// reply is not quoted because it is stdout.
|
|
789
|
-
if (
|
|
799
|
+
if (isUsageLimitSentence(text)) {
|
|
790
800
|
throw new SignalsPassError(`${runtime}-usage-limit`, `${runtime} is out of usage: its whole reply was a limit sentence`);
|
|
791
801
|
}
|
|
792
802
|
throw new SignalsPassError(`${runtime}-bad-output`, `${runtime} result is not JSON`);
|
|
@@ -67,7 +67,6 @@ export interface RunRecord {
|
|
|
67
67
|
skippedReason?: string;
|
|
68
68
|
currentStep: StepName | null;
|
|
69
69
|
steps: StepRecord[];
|
|
70
|
-
maxBudgetUsd: number;
|
|
71
70
|
maxTurns: number;
|
|
72
71
|
/** Set when a job run finishes complete or partial; carried forward by every later run that day. */
|
|
73
72
|
jobRanAt: string | null;
|
|
@@ -202,7 +201,6 @@ export interface RunSignalsOptions {
|
|
|
202
201
|
force?: boolean;
|
|
203
202
|
catchUp?: boolean;
|
|
204
203
|
maxTurns?: number;
|
|
205
|
-
maxBudgetUsd?: number;
|
|
206
204
|
now?: () => Date;
|
|
207
205
|
spawn?: SpawnSyncFn;
|
|
208
206
|
hotChannelSync?: HotChannelSyncFn;
|
|
@@ -23,7 +23,7 @@ import { loadSignalsSettings, loadIncrementalSettings } from "./settings.js";
|
|
|
23
23
|
import { createIncrementalStep } from "./incremental.js";
|
|
24
24
|
import { localDate } from "./local-date.js";
|
|
25
25
|
import { guardedWrite, WriteGuardError } from "./write-guard.js";
|
|
26
|
-
import { LOCK_STALE_MS, acquireCompanyLock, companyLockRel, defaultIsPidAlive, withSummaryLock, } from "./run-lock.js";
|
|
26
|
+
import { LOCK_STALE_MS, acquireCompanyLock, isLockExpired, companyLockRel, defaultIsPidAlive, withSummaryLock, } from "./run-lock.js";
|
|
27
27
|
import { gardenStep } from "./steps/garden.js";
|
|
28
28
|
import { adaptersStep } from "./steps/adapters.js";
|
|
29
29
|
import { extractStep, redoItemChannel } from "./steps/extract.js";
|
|
@@ -563,9 +563,8 @@ export async function runSignals(opts) {
|
|
|
563
563
|
}
|
|
564
564
|
const limits = opts.incremental ? loadIncrementalSettings(hqRoot) : settings;
|
|
565
565
|
const maxTurns = opts.maxTurns ?? limits.maxTurns;
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
throw new SignalsUsageError("invalid model cost limits");
|
|
566
|
+
if (!Number.isInteger(maxTurns) || maxTurns < 1)
|
|
567
|
+
throw new SignalsUsageError("invalid model turn limit");
|
|
569
568
|
const stepImpls = { ...DEFAULT_STEPS, ...(opts.steps ?? {}) };
|
|
570
569
|
if (opts.incremental)
|
|
571
570
|
stepImpls.extract = createIncrementalStep(opts.source, opts.incrementalOptions);
|
|
@@ -610,6 +609,7 @@ export async function runSignals(opts) {
|
|
|
610
609
|
const write = (r, data) => guardedWrite(hqRoot, r, data, { company });
|
|
611
610
|
// 1. Take the company lock (a dry run writes nothing, so it takes none).
|
|
612
611
|
let release = null;
|
|
612
|
+
let heartbeat = null;
|
|
613
613
|
let takeover = null;
|
|
614
614
|
if (!dryRun) {
|
|
615
615
|
const got = acquireCompanyLock({ hqRoot, date, company, trigger, now, ...(opts.isPidAlive ? { isPidAlive: opts.isPidAlive } : {}) });
|
|
@@ -618,6 +618,11 @@ export async function runSignals(opts) {
|
|
|
618
618
|
locked.push({ company, status: "running", startedAt: got.holder.startedAt, trigger: got.holder.trigger });
|
|
619
619
|
continue;
|
|
620
620
|
}
|
|
621
|
+
// The lock is refreshed on progress only: here when a step starts or
|
|
622
|
+
// finishes, and by the extract step when a source starts or finishes.
|
|
623
|
+
// No timer refreshes it, so a run that stops making progress loses the
|
|
624
|
+
// lock after LOCK_STALE_MS even while its process is alive.
|
|
625
|
+
heartbeat = got.heartbeat;
|
|
621
626
|
release = got.release;
|
|
622
627
|
takeover = got.takeover;
|
|
623
628
|
}
|
|
@@ -634,7 +639,6 @@ export async function runSignals(opts) {
|
|
|
634
639
|
skipReason: null,
|
|
635
640
|
currentStep: null,
|
|
636
641
|
steps: [],
|
|
637
|
-
maxBudgetUsd,
|
|
638
642
|
maxTurns,
|
|
639
643
|
jobRanAt: null,
|
|
640
644
|
nextRetryAt: null,
|
|
@@ -767,6 +771,7 @@ export async function runSignals(opts) {
|
|
|
767
771
|
for (const name of plan) {
|
|
768
772
|
record.currentStep = name;
|
|
769
773
|
persist();
|
|
774
|
+
heartbeat?.();
|
|
770
775
|
const t0 = now().getTime();
|
|
771
776
|
const ctx = {
|
|
772
777
|
hqRoot,
|
|
@@ -775,7 +780,7 @@ export async function runSignals(opts) {
|
|
|
775
780
|
trigger,
|
|
776
781
|
catchUp: record.catchUp,
|
|
777
782
|
maxTurns,
|
|
778
|
-
|
|
783
|
+
...(heartbeat ? { heartbeat } : {}),
|
|
779
784
|
unpricedSourceEstimateUsd: settings.unpricedSourceEstimateUsd,
|
|
780
785
|
now,
|
|
781
786
|
spawn,
|
|
@@ -923,7 +928,7 @@ function stoppedRunReason(hqRoot, record, date, nowMs, isPidAlive) {
|
|
|
923
928
|
return `${lead}: it holds no run lock.`;
|
|
924
929
|
if (!isPidAlive(holder.pid))
|
|
925
930
|
return `${lead}: its process (pid ${holder.pid}) is gone.`;
|
|
926
|
-
if (
|
|
931
|
+
if (isLockExpired({ startedAt: holder.startedAt, ...(typeof holder.heartbeatAt === "string" ? { heartbeatAt: holder.heartbeatAt } : {}) }, nowMs)) {
|
|
927
932
|
return `${lead}: it has held the run lock for more than ${LOCK_STALE_MS / 3_600_000} hours.`;
|
|
928
933
|
}
|
|
929
934
|
return null;
|