@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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/** Native implementations of
|
|
1
|
+
/** Native implementations of `hq core delegate`, including the one-process `run` flow. */
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { DELEGATE_COMMAND_SUPERVISOR } from "../utils/delegate-command-supervisor.js";
|
|
3
4
|
import { randomBytes } from "node:crypto";
|
|
4
5
|
import * as fs from "node:fs";
|
|
5
6
|
import * as os from "node:os";
|
|
@@ -10,6 +11,7 @@ import { resolveWindowsExecutable } from "../lib/bot/runtime/windows.js";
|
|
|
10
11
|
import { buildCmdExeSpawnPlan, isWindowsBatchFile } from "../utils/windows-spawn.js";
|
|
11
12
|
import { describeCoreCommand } from "./core-command-catalog.js";
|
|
12
13
|
import { resolveLiveRoot } from "../utils/hq-roots.js";
|
|
14
|
+
import { acquireDelegateLock } from "../utils/delegate-lock.js";
|
|
13
15
|
import { runBundledScript } from "../utils/run-bundled-script.js";
|
|
14
16
|
import { brainstormFrontmatterSet, brainstormSummary, brainstormTitle } from "./core-delegate-brainstorm.js";
|
|
15
17
|
export const CORE_NATIVE_DELEGATE_FLAG = "core-native-delegate";
|
|
@@ -95,28 +97,40 @@ export function delegateSubprocessSpawnPlan(command, args, env = process.env, pl
|
|
|
95
97
|
? buildCmdExeSpawnPlan(command, args, env, platform)
|
|
96
98
|
: { cmd: command, args: [...args], shell: false };
|
|
97
99
|
}
|
|
100
|
+
// Set while `hq core delegate run` executes a step. Its stdout carries only the
|
|
101
|
+
// final JSON line, so a child that would inherit stdout writes to stderr instead.
|
|
102
|
+
let childStdoutToStderr = false;
|
|
103
|
+
function inheritedChildStdout() {
|
|
104
|
+
return childStdoutToStderr ? 2 : "inherit";
|
|
105
|
+
}
|
|
98
106
|
export function subprocess(command, args, cwd, options = {}) {
|
|
99
107
|
const childEnv = { ...process.env, ...options.env };
|
|
100
108
|
const resolvedCommand = process.platform === "win32" ? commandPath(command, cwd, { env: childEnv }) : undefined;
|
|
101
109
|
const spawn = resolvedCommand ? delegateSubprocessSpawnPlan(resolvedCommand, args, childEnv) : { cmd: command, args, shell: false };
|
|
102
|
-
const
|
|
110
|
+
const supervised = options.timeout !== undefined;
|
|
111
|
+
const result = spawnSync(supervised ? process.execPath : spawn.cmd, supervised
|
|
112
|
+
? ["-e", DELEGATE_COMMAND_SUPERVISOR, String(options.timeout), spawn.cmd, JSON.stringify({ args: spawn.args, windowsVerbatimArguments: spawn.windowsVerbatimArguments })]
|
|
113
|
+
: spawn.args, {
|
|
103
114
|
cwd,
|
|
104
115
|
env: childEnv,
|
|
105
116
|
input: options.input,
|
|
106
117
|
maxBuffer: options.maxBuffer,
|
|
118
|
+
timeout: options.timeout === undefined ? undefined : options.timeout + 10_000,
|
|
119
|
+
...(supervised ? { killSignal: "SIGTERM" } : {}),
|
|
107
120
|
encoding: "buffer",
|
|
108
121
|
shell: spawn.shell,
|
|
109
|
-
...(spawn.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}),
|
|
110
|
-
stdio: [options.input === undefined ? options.stdinFd ?? "inherit" : "pipe", options.stdout === "inherit" ?
|
|
122
|
+
...(!supervised && spawn.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}),
|
|
123
|
+
stdio: [options.input === undefined ? options.stdinFd ?? "inherit" : "pipe", options.stdout === "inherit" ? inheritedChildStdout() : options.stdout === "ignore" ? "ignore" : "pipe", options.stderr === "pipe" ? "pipe" : options.stderr ?? "inherit"],
|
|
111
124
|
});
|
|
112
125
|
if (result.error) {
|
|
113
126
|
const stderr = Buffer.from(result.error.message);
|
|
114
|
-
return { code: 127, stderr: stderr.toString("utf8"), stderrBytes: stderr, stdout: "", stdoutBytes: Buffer.alloc(0) };
|
|
127
|
+
return { code: 127, stderr: stderr.toString("utf8"), stderrBytes: stderr, stdout: "", stdoutBytes: Buffer.alloc(0), ...(result.error.code === "ETIMEDOUT" ? { timedOut: true } : {}) };
|
|
115
128
|
}
|
|
116
129
|
const stdoutBytes = Buffer.isBuffer(result.stdout) ? result.stdout : Buffer.alloc(0);
|
|
117
130
|
const stderrBytes = Buffer.isBuffer(result.stderr) ? result.stderr : Buffer.alloc(0);
|
|
118
131
|
return {
|
|
119
132
|
code: result.status ?? (result.signal ? 128 : 1),
|
|
133
|
+
...(supervised && result.status === 124 ? { timedOut: true } : {}),
|
|
120
134
|
stdout: stdoutBytes.toString("utf8"),
|
|
121
135
|
stderr: stderrBytes.toString("utf8"),
|
|
122
136
|
stdoutBytes,
|
|
@@ -1028,7 +1042,7 @@ function runTransfer(args, context) {
|
|
|
1028
1042
|
writeOut(`${prefix} ownership of '${project}'${stageLabel} transferred to ${display} (${principal}) — local board, ${sourceLabel}, and journal updated; Work Mesh ownership unconfirmed\n`);
|
|
1029
1043
|
return 0;
|
|
1030
1044
|
}
|
|
1031
|
-
function
|
|
1045
|
+
function runNativeUnlocked(name, args, context) {
|
|
1032
1046
|
switch (name) {
|
|
1033
1047
|
case "resolve": return runResolve(args, context);
|
|
1034
1048
|
case "pickup": return runPickup(args, context);
|
|
@@ -1037,6 +1051,44 @@ function runNative(name, args, context) {
|
|
|
1037
1051
|
case "transfer": return runTransfer(args, context);
|
|
1038
1052
|
}
|
|
1039
1053
|
}
|
|
1054
|
+
export function runNative(name, args, context) {
|
|
1055
|
+
if (name === "resolve")
|
|
1056
|
+
return runNativeUnlocked(name, args, context);
|
|
1057
|
+
const parsed = name === "pickup" ? parsePickup(args) : parseStandard(name, args);
|
|
1058
|
+
const manifest = String(parsed.values.manifest ?? "");
|
|
1059
|
+
if (parsed.help || parsed.error || !manifest || (name === "pickup" && parsed.values.status)) {
|
|
1060
|
+
return runNativeUnlocked(name, args, context);
|
|
1061
|
+
}
|
|
1062
|
+
const file = path.resolve(context.cwd, manifest);
|
|
1063
|
+
// Leave the existing command's argument and missing-file diagnostics intact.
|
|
1064
|
+
try {
|
|
1065
|
+
if (!fs.statSync(file).isFile())
|
|
1066
|
+
return runNativeUnlocked(name, args, context);
|
|
1067
|
+
}
|
|
1068
|
+
catch (error) {
|
|
1069
|
+
const code = error.code;
|
|
1070
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
1071
|
+
return runNativeUnlocked(name, args, context);
|
|
1072
|
+
}
|
|
1073
|
+
if (name === "pickup" && (code === "EACCES" || code === "EPERM")) {
|
|
1074
|
+
writeErr("usage: --manifest <path> (--ack|--evidence|--check|--status)\n");
|
|
1075
|
+
return 2;
|
|
1076
|
+
}
|
|
1077
|
+
writeErr(`hq-delegate-${name}: cannot check the manifest before locking it\n`);
|
|
1078
|
+
return 1;
|
|
1079
|
+
}
|
|
1080
|
+
const lock = acquireDelegateLock(`${file}.send-lock`);
|
|
1081
|
+
if (!lock) {
|
|
1082
|
+
writeErr(`hq-delegate-${name}: verification or delivery is active; retry after it finishes\n`);
|
|
1083
|
+
return 1;
|
|
1084
|
+
}
|
|
1085
|
+
try {
|
|
1086
|
+
return runNativeUnlocked(name, args, context);
|
|
1087
|
+
}
|
|
1088
|
+
finally {
|
|
1089
|
+
lock.release();
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1040
1092
|
/** Fast-entry adapter; family gating and shell fallback happen before import. */
|
|
1041
1093
|
export function runDelegateFast(args, _stdin, cwd, hqRoot, commandName) {
|
|
1042
1094
|
const name = commandName;
|
|
@@ -1068,6 +1120,308 @@ export function runDelegateFast(args, _stdin, cwd, hqRoot, commandName) {
|
|
|
1068
1120
|
process.exitCode = code;
|
|
1069
1121
|
return code;
|
|
1070
1122
|
}
|
|
1123
|
+
const DELEGATE_RUN_CLOSED = new Set(["sent", "picked-up", "failed"]);
|
|
1124
|
+
const DELEGATE_RUN_AFTER_GRANT = new Set(["repo", "secrets", "transfer", "verify", "send"]);
|
|
1125
|
+
function captureStep(run) {
|
|
1126
|
+
let stdout = "";
|
|
1127
|
+
let stderr = "";
|
|
1128
|
+
const stdoutWrite = process.stdout.write;
|
|
1129
|
+
const stderrWrite = process.stderr.write;
|
|
1130
|
+
process.stdout.write = ((chunk) => {
|
|
1131
|
+
stdout += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
1132
|
+
return true;
|
|
1133
|
+
});
|
|
1134
|
+
process.stderr.write = ((chunk) => {
|
|
1135
|
+
stderr += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
1136
|
+
return true;
|
|
1137
|
+
});
|
|
1138
|
+
const previousChildStdout = childStdoutToStderr;
|
|
1139
|
+
childStdoutToStderr = true;
|
|
1140
|
+
try {
|
|
1141
|
+
return { code: run(), stdout, stderr };
|
|
1142
|
+
}
|
|
1143
|
+
finally {
|
|
1144
|
+
childStdoutToStderr = previousChildStdout;
|
|
1145
|
+
process.stdout.write = stdoutWrite;
|
|
1146
|
+
process.stderr.write = stderrWrite;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
function forwardStep(captured) {
|
|
1150
|
+
if (captured.stdout)
|
|
1151
|
+
process.stderr.write(captured.stdout);
|
|
1152
|
+
if (captured.stderr)
|
|
1153
|
+
process.stderr.write(captured.stderr);
|
|
1154
|
+
}
|
|
1155
|
+
function delegateRecipient(value) {
|
|
1156
|
+
if (!isRecord(value))
|
|
1157
|
+
return null;
|
|
1158
|
+
const to = isRecord(value.to) ? value.to : value;
|
|
1159
|
+
const principal = typeof to.principal === "string" ? to.principal : "";
|
|
1160
|
+
if (!principal)
|
|
1161
|
+
return null;
|
|
1162
|
+
const kind = typeof to.kind === "string" && to.kind ? to.kind : "person";
|
|
1163
|
+
const displayName = typeof to.displayName === "string" && to.displayName ? to.displayName : null;
|
|
1164
|
+
return { kind, principal, displayName };
|
|
1165
|
+
}
|
|
1166
|
+
function delegateOwnership(value) {
|
|
1167
|
+
if (!isRecord(value) || typeof value.workMeshOwnership !== "string")
|
|
1168
|
+
return null;
|
|
1169
|
+
return value.workMeshOwnership;
|
|
1170
|
+
}
|
|
1171
|
+
function loadDelegateManifest(file) {
|
|
1172
|
+
if (!file)
|
|
1173
|
+
return undefined;
|
|
1174
|
+
try {
|
|
1175
|
+
const document = readJsonFile(file);
|
|
1176
|
+
return isRecord(document) ? document : undefined;
|
|
1177
|
+
}
|
|
1178
|
+
catch {
|
|
1179
|
+
return undefined;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
function rootRelative(root, file) {
|
|
1183
|
+
return path.relative(root, file).split(path.sep).join("/");
|
|
1184
|
+
}
|
|
1185
|
+
function grantsAreLive(document, grantSucceeded) {
|
|
1186
|
+
if (grantSucceeded)
|
|
1187
|
+
return true;
|
|
1188
|
+
const status = document ? jqRawPath(document, "status") : "";
|
|
1189
|
+
return status !== "" && status !== "building";
|
|
1190
|
+
}
|
|
1191
|
+
function delegationManifests(root) {
|
|
1192
|
+
const dir = path.join(root, "workspace", "delegations");
|
|
1193
|
+
let entries;
|
|
1194
|
+
try {
|
|
1195
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
1196
|
+
}
|
|
1197
|
+
catch (error) {
|
|
1198
|
+
const code = error.code;
|
|
1199
|
+
if (code === "ENOENT" || code === "ENOTDIR")
|
|
1200
|
+
return [];
|
|
1201
|
+
throw error;
|
|
1202
|
+
}
|
|
1203
|
+
const hits = [];
|
|
1204
|
+
for (const entry of entries) {
|
|
1205
|
+
if (!entry.isDirectory())
|
|
1206
|
+
continue;
|
|
1207
|
+
const file = path.join(dir, entry.name, "manifest.json");
|
|
1208
|
+
let document;
|
|
1209
|
+
try {
|
|
1210
|
+
if (!fs.statSync(file).isFile())
|
|
1211
|
+
continue;
|
|
1212
|
+
document = readJsonFile(file);
|
|
1213
|
+
}
|
|
1214
|
+
catch (error) {
|
|
1215
|
+
const code = error.code;
|
|
1216
|
+
if (code === "ENOENT" || code === "ENOTDIR" || error instanceof SyntaxError)
|
|
1217
|
+
continue;
|
|
1218
|
+
throw error;
|
|
1219
|
+
}
|
|
1220
|
+
if (!isRecord(document))
|
|
1221
|
+
continue;
|
|
1222
|
+
const createdAt = jsonAt(document, "createdAt");
|
|
1223
|
+
hits.push({
|
|
1224
|
+
file,
|
|
1225
|
+
createdAt: typeof createdAt === "string" ? createdAt : "",
|
|
1226
|
+
dirName: entry.name,
|
|
1227
|
+
status: jqRawPath(document, "status"),
|
|
1228
|
+
document,
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
return hits;
|
|
1232
|
+
}
|
|
1233
|
+
function newestManifest(hits) {
|
|
1234
|
+
return [...hits].sort((left, right) => {
|
|
1235
|
+
const leftKey = left.createdAt || left.dirName;
|
|
1236
|
+
const rightKey = right.createdAt || right.dirName;
|
|
1237
|
+
if (leftKey < rightKey)
|
|
1238
|
+
return 1;
|
|
1239
|
+
if (leftKey > rightKey)
|
|
1240
|
+
return -1;
|
|
1241
|
+
if (left.dirName < right.dirName)
|
|
1242
|
+
return 1;
|
|
1243
|
+
if (left.dirName > right.dirName)
|
|
1244
|
+
return -1;
|
|
1245
|
+
return 0;
|
|
1246
|
+
})[0];
|
|
1247
|
+
}
|
|
1248
|
+
function sameDelegation(document, company, project, principal, mode) {
|
|
1249
|
+
const manifestMode = jqRawPath(document, "mode", "transfer") || "transfer";
|
|
1250
|
+
return jqRawPath(document, "company") === company
|
|
1251
|
+
&& jqRawPath(document, "project.name") === project
|
|
1252
|
+
&& jqRawPath(document, "to.principal") === principal
|
|
1253
|
+
&& manifestMode === mode;
|
|
1254
|
+
}
|
|
1255
|
+
/** Run the /delegate flow in one process. Returns the process exit code. */
|
|
1256
|
+
export async function runDelegateFlow(options, context) {
|
|
1257
|
+
const root = context.root ?? context.cwd;
|
|
1258
|
+
const mode = options.share ? "share" : "transfer";
|
|
1259
|
+
const steps = [];
|
|
1260
|
+
const { runNativeDelegateW1b } = await import("./core-delegate-w1b.js");
|
|
1261
|
+
const emit = (code, status, details) => {
|
|
1262
|
+
const document = loadDelegateManifest(details.manifestPath);
|
|
1263
|
+
if (details.warn && details.failedStep) {
|
|
1264
|
+
process.stderr.write(`hq core delegate run: grants are live but the delegation stopped at ${details.failedStep}; re-run the same command to resume, or revoke the grants\n`);
|
|
1265
|
+
}
|
|
1266
|
+
const payload = {
|
|
1267
|
+
status,
|
|
1268
|
+
delegationId: document ? jqRawPath(document, "delegationId") || null : null,
|
|
1269
|
+
manifest: details.manifestPath ? rootRelative(root, details.manifestPath) : null,
|
|
1270
|
+
recipient: (document ? delegateRecipient(document) : null) ?? details.recipient,
|
|
1271
|
+
mode,
|
|
1272
|
+
resumed: details.resumed,
|
|
1273
|
+
steps,
|
|
1274
|
+
failedStep: details.failedStep,
|
|
1275
|
+
workMeshOwnership: document ? delegateOwnership(document) : null,
|
|
1276
|
+
grantsLive: grantsAreLive(document, details.grantSucceeded),
|
|
1277
|
+
};
|
|
1278
|
+
if (details.reason !== undefined)
|
|
1279
|
+
payload.reason = details.reason;
|
|
1280
|
+
process.stdout.write(`${JSON.stringify(payload)}\n`);
|
|
1281
|
+
return code;
|
|
1282
|
+
};
|
|
1283
|
+
const runStep = (name, run) => {
|
|
1284
|
+
const captured = captureStep(run);
|
|
1285
|
+
forwardStep(captured);
|
|
1286
|
+
steps.push({ name, code: captured.code });
|
|
1287
|
+
return captured;
|
|
1288
|
+
};
|
|
1289
|
+
const failStep = (name, code, manifestPath, resumed, recipient, grantSucceeded) => {
|
|
1290
|
+
const live = grantsAreLive(loadDelegateManifest(manifestPath), grantSucceeded);
|
|
1291
|
+
return emit(code, "failed", {
|
|
1292
|
+
failedStep: name,
|
|
1293
|
+
manifestPath,
|
|
1294
|
+
resumed,
|
|
1295
|
+
recipient,
|
|
1296
|
+
grantSucceeded,
|
|
1297
|
+
warn: live && DELEGATE_RUN_AFTER_GRANT.has(name),
|
|
1298
|
+
});
|
|
1299
|
+
};
|
|
1300
|
+
const resolvedCapture = runStep("resolve", () => runNative("resolve", ["--company", options.company, "--to", options.to], context));
|
|
1301
|
+
if (resolvedCapture.code === 3) {
|
|
1302
|
+
process.stdout.write(resolvedCapture.stdout);
|
|
1303
|
+
return 3;
|
|
1304
|
+
}
|
|
1305
|
+
if (resolvedCapture.code !== 0) {
|
|
1306
|
+
return emit(resolvedCapture.code, "failed", {
|
|
1307
|
+
failedStep: "resolve",
|
|
1308
|
+
resumed: false,
|
|
1309
|
+
recipient: null,
|
|
1310
|
+
grantSucceeded: false,
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
let resolved;
|
|
1314
|
+
try {
|
|
1315
|
+
const recipient = delegateRecipient(JSON.parse(resolvedCapture.stdout));
|
|
1316
|
+
if (!recipient)
|
|
1317
|
+
throw new Error("resolve returned no principal");
|
|
1318
|
+
resolved = recipient;
|
|
1319
|
+
}
|
|
1320
|
+
catch {
|
|
1321
|
+
return emit(1, "failed", { failedStep: "resolve", resumed: false, recipient: null, grantSucceeded: false });
|
|
1322
|
+
}
|
|
1323
|
+
if (options.dryRun) {
|
|
1324
|
+
const dryArgs = ["--dry-run", "--company", options.company, "--project", options.project, "--to", resolved.principal];
|
|
1325
|
+
if (options.share)
|
|
1326
|
+
dryArgs.push("--mode", "share");
|
|
1327
|
+
const dry = runStep("verify", () => runNativeDelegateW1b("verify", dryArgs, context));
|
|
1328
|
+
return emit(dry.code, "dry-run", {
|
|
1329
|
+
failedStep: dry.code === 0 ? null : "verify",
|
|
1330
|
+
resumed: false,
|
|
1331
|
+
recipient: resolved,
|
|
1332
|
+
grantSucceeded: false,
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
let manifestPath;
|
|
1336
|
+
let resumed = false;
|
|
1337
|
+
if (options.manifest) {
|
|
1338
|
+
manifestPath = path.resolve(context.cwd, options.manifest);
|
|
1339
|
+
}
|
|
1340
|
+
else {
|
|
1341
|
+
const hits = delegationManifests(root).filter((hit) => sameDelegation(hit.document, options.company, options.project, resolved.principal, mode));
|
|
1342
|
+
const chosen = newestManifest(hits.filter((hit) => !DELEGATE_RUN_CLOSED.has(hit.status)))
|
|
1343
|
+
?? newestManifest(hits.filter((hit) => hit.status === "sent" || hit.status === "picked-up"));
|
|
1344
|
+
if (chosen) {
|
|
1345
|
+
manifestPath = chosen.file;
|
|
1346
|
+
resumed = true;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
if (!manifestPath) {
|
|
1350
|
+
const bundleArgs = [
|
|
1351
|
+
"build",
|
|
1352
|
+
"--company", options.company,
|
|
1353
|
+
"--project", options.project,
|
|
1354
|
+
"--to", resolved.principal,
|
|
1355
|
+
"--to-kind", resolved.kind,
|
|
1356
|
+
"--to-name", resolved.displayName ?? "",
|
|
1357
|
+
];
|
|
1358
|
+
if (options.share)
|
|
1359
|
+
bundleArgs.push("--mode", "share");
|
|
1360
|
+
const bundle = runStep("bundle", () => runNativeDelegateW1b("bundle", bundleArgs, context));
|
|
1361
|
+
if (bundle.code !== 0)
|
|
1362
|
+
return failStep("bundle", bundle.code, undefined, false, resolved, false);
|
|
1363
|
+
const delegationId = bundle.stdout.split("\n").map((line) => line.trim()).find((line) => line.length > 0) ?? "";
|
|
1364
|
+
if (!delegationId)
|
|
1365
|
+
return failStep("bundle", 1, undefined, false, resolved, false);
|
|
1366
|
+
manifestPath = path.join(root, "workspace", "delegations", delegationId, "manifest.json");
|
|
1367
|
+
}
|
|
1368
|
+
const current = loadDelegateManifest(manifestPath);
|
|
1369
|
+
const currentStatus = current ? jqRawPath(current, "status") : "";
|
|
1370
|
+
if (currentStatus === "sent" || currentStatus === "picked-up") {
|
|
1371
|
+
return emit(0, "already-sent", {
|
|
1372
|
+
failedStep: null,
|
|
1373
|
+
manifestPath,
|
|
1374
|
+
resumed,
|
|
1375
|
+
recipient: resolved,
|
|
1376
|
+
grantSucceeded: false,
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
if (currentStatus === "sending") {
|
|
1380
|
+
const relative = rootRelative(root, manifestPath);
|
|
1381
|
+
return emit(2, "failed", {
|
|
1382
|
+
failedStep: "send",
|
|
1383
|
+
manifestPath,
|
|
1384
|
+
resumed,
|
|
1385
|
+
recipient: resolved,
|
|
1386
|
+
grantSucceeded: false,
|
|
1387
|
+
reason: `a previous send may have delivered and must be reconciled with hq core delegate send --manifest ${relative} --reconcile <eventId>`,
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
const grant = runStep("grant", () => runNativeDelegateW1b("grant", ["--manifest", manifestPath, "--yes"], context));
|
|
1391
|
+
if (grant.code !== 0)
|
|
1392
|
+
return failStep("grant", grant.code, manifestPath, resumed, resolved, false);
|
|
1393
|
+
const repoArgs = ["--manifest", manifestPath, "--yes"];
|
|
1394
|
+
if (options.githubUser)
|
|
1395
|
+
repoArgs.push("--github-user", options.githubUser);
|
|
1396
|
+
const repo = runStep("repo", () => runNative("repo", repoArgs, context));
|
|
1397
|
+
if (repo.code !== 0)
|
|
1398
|
+
return failStep("repo", repo.code, manifestPath, resumed, resolved, true);
|
|
1399
|
+
const secretsArgs = ["--manifest", manifestPath, options.noSecrets ? "--no-secrets" : "--yes"];
|
|
1400
|
+
const secrets = runStep("secrets", () => runNative("secrets", secretsArgs, context));
|
|
1401
|
+
if (secrets.code !== 0)
|
|
1402
|
+
return failStep("secrets", secrets.code, manifestPath, resumed, resolved, true);
|
|
1403
|
+
const transfer = runStep("transfer", () => runNative("transfer", ["--manifest", manifestPath], context));
|
|
1404
|
+
if (transfer.code !== 0)
|
|
1405
|
+
return failStep("transfer", transfer.code, manifestPath, resumed, resolved, true);
|
|
1406
|
+
const verify = runStep("verify", () => runNativeDelegateW1b("verify", ["--manifest", manifestPath], context));
|
|
1407
|
+
if (verify.code !== 0)
|
|
1408
|
+
return failStep("verify", verify.code, manifestPath, resumed, resolved, true);
|
|
1409
|
+
const sendArgs = ["--manifest", manifestPath, "--send"];
|
|
1410
|
+
if (options.headline)
|
|
1411
|
+
sendArgs.push("--headline", options.headline);
|
|
1412
|
+
if (options.note)
|
|
1413
|
+
sendArgs.push("--note", options.note);
|
|
1414
|
+
const send = runStep("send", () => runNativeDelegateW1b("send", sendArgs, context));
|
|
1415
|
+
if (send.code !== 0)
|
|
1416
|
+
return failStep("send", send.code, manifestPath, resumed, resolved, true);
|
|
1417
|
+
return emit(0, "sent", {
|
|
1418
|
+
failedStep: null,
|
|
1419
|
+
manifestPath,
|
|
1420
|
+
resumed,
|
|
1421
|
+
recipient: resolved,
|
|
1422
|
+
grantSucceeded: true,
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1071
1425
|
/** Register the Wave 1a delegate commands and preserve the shell rollback path. */
|
|
1072
1426
|
export function registerCoreDelegateCommand(core, registerWave1b) {
|
|
1073
1427
|
const delegate = core.command("delegate").description("Delegation handover helpers");
|
|
@@ -1117,6 +1471,57 @@ export function registerCoreDelegateCommand(core, registerWave1b) {
|
|
|
1117
1471
|
});
|
|
1118
1472
|
describeCoreCommand(command, { execution: "native", asset: SCRIPT_ASSETS[name], root: rootMode });
|
|
1119
1473
|
}
|
|
1474
|
+
const runCommand = delegate.command("run")
|
|
1475
|
+
.description("Run a delegation from resolve through send in one process")
|
|
1476
|
+
.requiredOption("--company <slug>", "Company slug")
|
|
1477
|
+
.requiredOption("--project <name>", "Project name")
|
|
1478
|
+
.requiredOption("--to <recipient>", "Recipient name, email, person uid, or agent uid")
|
|
1479
|
+
.option("--share", "Grant access without transferring ownership")
|
|
1480
|
+
.option("--no-secrets", "Skip credential handover")
|
|
1481
|
+
.option("--dry-run", "Print the plan and change nothing")
|
|
1482
|
+
.option("--manifest <path>", "Use this delegation manifest instead of resuming or bundling")
|
|
1483
|
+
.option("--headline <text>", "Pickup DM headline")
|
|
1484
|
+
.option("--note <text>", "Note included in the pickup DM")
|
|
1485
|
+
.option("--github-user <login>", "GitHub login for the repository access check")
|
|
1486
|
+
.action(async (opts) => {
|
|
1487
|
+
const scope = core.opts();
|
|
1488
|
+
const liveRoot = resolveLiveRoot({ hqRoot: scope.hqRoot });
|
|
1489
|
+
const runContext = { cwd: liveRoot, root: liveRoot };
|
|
1490
|
+
const savedEnvironment = new Map();
|
|
1491
|
+
for (const key of ["HQ_ROOT", "CLAUDE_PROJECT_DIR", "PWD"]) {
|
|
1492
|
+
savedEnvironment.set(key, process.env[key]);
|
|
1493
|
+
}
|
|
1494
|
+
process.env.HQ_ROOT = liveRoot;
|
|
1495
|
+
process.env.CLAUDE_PROJECT_DIR = liveRoot;
|
|
1496
|
+
process.env.PWD = runContext.cwd;
|
|
1497
|
+
const code = await (async () => {
|
|
1498
|
+
try {
|
|
1499
|
+
return await runDelegateFlow({
|
|
1500
|
+
company: opts.company,
|
|
1501
|
+
project: opts.project,
|
|
1502
|
+
to: opts.to,
|
|
1503
|
+
share: opts.share === true,
|
|
1504
|
+
noSecrets: opts.secrets === false,
|
|
1505
|
+
dryRun: opts.dryRun === true,
|
|
1506
|
+
manifest: opts.manifest,
|
|
1507
|
+
headline: opts.headline,
|
|
1508
|
+
note: opts.note,
|
|
1509
|
+
githubUser: opts.githubUser,
|
|
1510
|
+
}, runContext);
|
|
1511
|
+
}
|
|
1512
|
+
finally {
|
|
1513
|
+
for (const [key, value] of savedEnvironment) {
|
|
1514
|
+
if (value === undefined)
|
|
1515
|
+
delete process.env[key];
|
|
1516
|
+
else
|
|
1517
|
+
process.env[key] = value;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
})();
|
|
1521
|
+
if (code !== 0)
|
|
1522
|
+
process.exit(code);
|
|
1523
|
+
});
|
|
1524
|
+
describeCoreCommand(runCommand, { execution: "native", root: "live" });
|
|
1120
1525
|
registerWave1b?.(delegate, core);
|
|
1121
1526
|
}
|
|
1122
1527
|
//# sourceMappingURL=core-delegate.js.map
|
|
@@ -6,6 +6,7 @@ import * as path from "node:path";
|
|
|
6
6
|
import { tokenIsMachinePrincipal } from "../lib/caller-principal.js";
|
|
7
7
|
import { spawnSync } from "node:child_process";
|
|
8
8
|
import { resolveWindowsExecutable } from "../lib/bot/runtime/windows.js";
|
|
9
|
+
import { validSessionId } from "../lib/core-utils/session-id.js";
|
|
9
10
|
import { resolveLiveRoot } from "../utils/hq-roots.js";
|
|
10
11
|
import { planHqSpawn } from "../utils/hq-spawn.js";
|
|
11
12
|
import { bundledShellUnboundValue, registerNativeUtility, utilityError } from "./core-native-utilities.js";
|
|
@@ -54,7 +55,7 @@ const fail = (message, code = 2) => utilityError(`hq-dm-bind: ${message}`, code)
|
|
|
54
55
|
const sessionDirectory = (d, sid) => path.join(d.root, "workspace/sessions", sid);
|
|
55
56
|
const filePath = (d, sid, name) => path.join(sessionDirectory(d, sid), name);
|
|
56
57
|
const sessionArgs = (d, args) => d.runHqSession(args, d.env);
|
|
57
|
-
const validSid =
|
|
58
|
+
const validSid = validSessionId;
|
|
58
59
|
export function resolveDmBindSessionId(d) {
|
|
59
60
|
for (const key of ["HQ_SESSION_ID", "CLAUDE_CODE_SESSION_ID", "CLAUDE_SESSION_ID", "CODEX_SESSION_ID", "CODEX_THREAD_ID", "GROK_SESSION_ID"]) {
|
|
60
61
|
const candidate = (d.env[key] ?? "").replace(/\s/g, "");
|
|
@@ -19,6 +19,11 @@ type HandoffContext = {
|
|
|
19
19
|
export declare function runHandoffFinalize(args: string[], context: HandoffContext): RunResult;
|
|
20
20
|
export declare function runHandoffPost(args: string[], context: HandoffContext): RunResult | Promise<RunResult>;
|
|
21
21
|
export declare function runHandoffPostWorker(args: string[], context: HandoffContext): RunResult;
|
|
22
|
+
export declare function runHandoffPointerCompany(args: string[], context: HandoffContext): RunResult;
|
|
23
|
+
export declare function runHandoffBuilderRoute(args: string[], context: HandoffContext): RunResult;
|
|
24
|
+
export declare function runHandoffAutofile(args: string[], context: HandoffContext): RunResult;
|
|
25
|
+
export declare function runHandoffArchiveDecision(args: string[], context: HandoffContext): RunResult;
|
|
26
|
+
export declare function runHandoffFlow(args: string[], context: HandoffContext): Promise<RunResult>;
|
|
22
27
|
/** Fast-entry adapter; the shared family flag is resolved before this module loads. */
|
|
23
28
|
export declare function runHandoffFast(args: readonly string[], _stdin: string, _cwd: string, hqRoot: string | undefined, commandName: string): Promise<number>;
|
|
24
29
|
/** Register native handoff commands behind the shared default-off flag. */
|