@indigoai-us/hq-cli 5.345.234 → 5.345.235
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 +60 -0
- package/dist/command-catalog.generated.d.ts +236 -7
- package/dist/command-catalog.generated.js +291 -7
- package/dist/command-registration-plan.d.ts +24 -0
- package/dist/command-registration-plan.js +4 -0
- package/dist/commands/bot-companies.d.ts +4 -1
- package/dist/commands/bot-companies.js +5 -1
- package/dist/commands/bot.d.ts +10 -0
- package/dist/commands/bot.js +165 -36
- package/dist/commands/capacity.js +1 -1
- package/dist/commands/core-handoff.js +2 -2
- package/dist/commands/core-ontology-native.js +5 -4
- package/dist/commands/core-pipeline-workflow-runner-native.js +4 -9
- package/dist/commands/deploy-app-db.d.ts +3 -0
- package/dist/commands/deploy-app-db.js +79 -0
- package/dist/commands/deploy-app-upload.d.ts +3 -0
- package/dist/commands/deploy-app-upload.js +120 -0
- package/dist/commands/deploy-comments.js +46 -1
- package/dist/commands/deploy-mutations.js +71 -5
- package/dist/commands/deploy-ssr.d.ts +3 -0
- package/dist/commands/deploy-ssr.js +74 -0
- package/dist/commands/dm.d.ts +7 -1
- package/dist/commands/dm.js +39 -9
- package/dist/commands/doctor.js +2 -10
- package/dist/commands/fingerprint.js +4 -9
- package/dist/commands/lanes-accounts.js +5 -5
- package/dist/commands/lanes-hold.js +1 -1
- package/dist/commands/lanes-message.js +3 -3
- package/dist/commands/lanes-move.js +1 -1
- package/dist/commands/lanes-resume.js +6 -6
- package/dist/commands/lanes-watch.js +2 -2
- package/dist/commands/lanes.js +21 -21
- package/dist/commands/work-env.d.ts +90 -0
- package/dist/commands/work-env.js +304 -0
- package/dist/lazy-commands.js +2 -10
- package/dist/lib/bot/api.d.ts +27 -0
- package/dist/lib/bot/api.js +28 -2
- package/dist/lib/bot/cloud-create.d.ts +46 -0
- package/dist/lib/bot/cloud-create.js +128 -0
- package/dist/lib/bot/fleet-daemon.js +4 -1
- package/dist/lib/bot/fleet-local.d.ts +7 -0
- package/dist/lib/bot/fleet-local.js +39 -3
- package/dist/lib/bot/fleet-owner-companies.js +2 -2
- package/dist/lib/bot/promote.d.ts +81 -2
- package/dist/lib/bot/promote.js +425 -51
- package/dist/lib/bot/promotion-hold.d.ts +9 -0
- package/dist/lib/bot/promotion-hold.js +29 -0
- package/dist/lib/bot/promotion-receipt.d.ts +10 -0
- package/dist/lib/bot/promotion-receipt.js +41 -1
- package/dist/lib/bot/promotion-upload.d.ts +6 -1
- package/dist/lib/bot/promotion-upload.js +3 -1
- package/dist/lib/bot/readiness.d.ts +9 -0
- package/dist/lib/bot/readiness.js +16 -0
- package/dist/lib/capacity/route.js +4 -4
- package/dist/lib/capacity/sign-in.js +1 -1
- package/dist/lib/checkpoint-ontology/entity-file.js +15 -17
- package/dist/lib/daemon/catalog.d.ts +2 -0
- package/dist/lib/daemon/catalog.js +2 -0
- package/dist/lib/daemon/hook-requests.js +23 -3
- package/dist/lib/daemon/run.d.ts +14 -0
- package/dist/lib/daemon/run.js +24 -14
- package/dist/lib/deploy-api.d.ts +2 -0
- package/dist/lib/deploy-api.js +9 -0
- package/dist/lib/environment/work-requirements.js +1 -1
- package/dist/lib/hot-channels/signals-pass.d.ts +0 -76
- package/dist/lib/hot-channels/signals-pass.js +81 -4
- package/dist/lib/lanes/account-company.js +1 -1
- package/dist/lib/lanes/account-ownership.js +1 -1
- package/dist/lib/lanes/accounts.js +1 -1
- package/dist/lib/lanes/delivery.js +7 -7
- package/dist/lib/lanes/dropbox.js +1 -1
- package/dist/lib/lanes/grants.js +3 -3
- package/dist/lib/lanes/hq-root.js +1 -1
- package/dist/lib/lanes/keep-alive-audit.js +2 -2
- package/dist/lib/lanes/links.js +4 -4
- package/dist/lib/lanes/monitor.js +3 -3
- package/dist/lib/lanes/quota-notice.js +1 -1
- package/dist/lib/lanes/reconcile.js +22 -12
- package/dist/lib/lanes/signal-brief-template.js +1 -1
- package/dist/lib/lanes/worker-continuity.js +1 -1
- package/dist/lib/mesh/live/direct-drain.d.ts +1 -0
- package/dist/lib/mesh/live/direct-drain.js +12 -1
- package/dist/lib/mesh/live/emit.d.ts +1 -1
- package/dist/lib/mesh/live/emit.js +10 -5
- package/dist/lib/mesh/live/flush.js +19 -4
- package/dist/lib/mesh/live/reporting-privacy.d.ts +9 -3
- package/dist/lib/mesh/live/reporting-privacy.js +27 -7
- package/dist/lib/mesh/live/spool.d.ts +2 -0
- package/dist/lib/mesh/live/spool.js +41 -0
- package/dist/lib/signals/sanitize.js +5 -4
- package/dist/lib/signals/steps/garden.js +5 -4
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.js +11 -2
- package/dist/utils/hq-roots-core.d.ts +5 -0
- package/dist/utils/hq-roots-core.js +18 -9
- package/dist/utils/owner-session.d.ts +13 -0
- package/dist/utils/owner-session.js +28 -0
- package/package.json +7 -7
package/dist/lib/bot/promote.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { recordActivePromotion } from "./promotion-receipt.js";
|
|
1
|
+
import { recordActivePromotion, releaseLocalPromotion } from "./promotion-receipt.js";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { BotApiError } from "./api.js";
|
|
5
6
|
import { botCredsPath } from "./paths.js";
|
|
6
7
|
import { snapshotBotContinuity, validateBotContinuity } from "./continuity.js";
|
|
7
|
-
import { attestPromotionDrain, holdForPromotion, waitForPromotionDrain } from "./promotion-hold.js";
|
|
8
|
+
import { attestPromotionDrain, hasPromotionHold, holdForPromotion, localBotProcessAlive, promotionHoldSummary, readPromotionHoldOrigin, recordPromotionHoldOrigin, waitForPromotionDrain, } from "./promotion-hold.js";
|
|
8
9
|
import { uploadLocalBotPromotion } from "./promotion-upload.js";
|
|
10
|
+
import { appendBotLog, botLogLine } from "./log.js";
|
|
9
11
|
/** Private bounded reads; never expose parser errors containing credential bytes. */
|
|
10
12
|
function readPrivateJson(file, limit) {
|
|
11
13
|
if (fs.realpathSync(file) !== path.resolve(file))
|
|
@@ -37,71 +39,443 @@ function readPrivateJson(file, limit) {
|
|
|
37
39
|
fs.closeSync(fd);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
42
|
+
const OPERATION_ID = /^[A-Za-z0-9_-]{16,128}$/;
|
|
43
|
+
/** The local hold as saved, or why it cannot be used. Never throws for a bad file. */
|
|
44
|
+
function readLocalHold(dir, config) {
|
|
45
|
+
const holdFile = path.join(dir, "promotion-hold.json");
|
|
46
|
+
if (!hasPromotionHold(dir))
|
|
47
|
+
return { hold: null };
|
|
48
|
+
let hold;
|
|
49
|
+
try {
|
|
50
|
+
hold = readPrivateJson(holdFile, 2048);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return { hold: null, unreadable: error instanceof Error ? error.message : String(error) };
|
|
54
|
+
}
|
|
55
|
+
if (!hold || typeof hold !== "object")
|
|
56
|
+
return { hold: null, unreadable: "it is not a promotion hold" };
|
|
57
|
+
const saved = hold;
|
|
58
|
+
if (saved.agentUid !== config.agentUid || saved.ownerUid !== config.ownerUid)
|
|
59
|
+
return { hold: null, unreadable: "it names another bot" };
|
|
60
|
+
if (typeof saved.companyUid !== "string" || typeof saved.operationId !== "string" || !OPERATION_ID.test(saved.operationId))
|
|
61
|
+
return { hold: null, unreadable: "it is incomplete" };
|
|
62
|
+
return { hold: saved };
|
|
63
|
+
}
|
|
64
|
+
function holdCompany(dir, config) {
|
|
65
|
+
try {
|
|
66
|
+
return promotionHoldSummary(dir, config.agentUid, config.ownerUid)?.companyUid ?? null;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function unreadableHoldError(dir, config, reason) {
|
|
73
|
+
const company = holdCompany(dir, config);
|
|
74
|
+
return new Error(`The promotion hold for ${config.name} on this computer (${path.join(dir, "promotion-hold.json")}) cannot be used: ${reason}. ` +
|
|
75
|
+
`${company ? `It names company ${company}.` : "Its company could not be read."} The bot stays stopped here. ` +
|
|
76
|
+
`Ask HQ to cancel the move and free the bot with: hq bot promote ${config.name} --company ${company ?? "<uid>"} --cancel`);
|
|
77
|
+
}
|
|
78
|
+
function otherCompanyError(config, held, asked, cancel) {
|
|
79
|
+
return new Error(`${config.name} is held for a move to company ${held}, not ${asked}. ` +
|
|
80
|
+
(cancel ? "" : `Continue that move with: hq bot promote ${config.name} --company ${held}, or `) +
|
|
81
|
+
`${cancel ? "Cancel" : "cancel"} it with: hq bot promote ${config.name} --company ${held} --cancel`);
|
|
82
|
+
}
|
|
83
|
+
function damagedHoldError(dir, config, reason, companyUid) {
|
|
84
|
+
const file = path.join(dir, "promotion-hold.json");
|
|
85
|
+
return new Error(`The promotion hold for ${config.name} on this computer (${file}) is damaged: ${reason}. ` +
|
|
86
|
+
`HQ has no move to the cloud for ${config.name} in company ${companyUid}, but a damaged hold may belong to a move in another company, so it was not removed. ` +
|
|
87
|
+
`Nothing was released: ${config.name} stays held on this computer. If it is moving to another company, cancel there with: hq bot promote ${config.name} --company <uid> --cancel. ` +
|
|
88
|
+
`If you are sure it is not moving to the cloud anywhere, delete ${file} and the promotion-snapshot-*.json files beside it, then start it with: hq bot start ${config.name}`);
|
|
89
|
+
}
|
|
90
|
+
/** HQ's raw answer goes to the bot's own log only, never to the person. */
|
|
91
|
+
function logRaw(dir, error) {
|
|
92
|
+
if (error instanceof BotApiError)
|
|
93
|
+
appendBotLog(dir, botLogLine("warn", `promotion: ${error.message}`));
|
|
94
|
+
}
|
|
95
|
+
/** A short reason in plain words for an HQ refusal; other errors keep their own words. */
|
|
96
|
+
function reason(error, dir) {
|
|
97
|
+
logRaw(dir, error);
|
|
98
|
+
if (!(error instanceof BotApiError))
|
|
99
|
+
return sentence(error);
|
|
100
|
+
if (error.status === 404)
|
|
101
|
+
return "HQ could not find this bot's move";
|
|
102
|
+
if (error.status === 429)
|
|
103
|
+
return "HQ is busy right now";
|
|
104
|
+
if (error.status >= 500)
|
|
105
|
+
return "HQ had a problem on its side";
|
|
106
|
+
return "HQ refused the request";
|
|
107
|
+
}
|
|
108
|
+
/** An HQ API error as a short reason and the next step; any other error is kept. */
|
|
109
|
+
function plainError(error, dir, next) {
|
|
110
|
+
return error instanceof BotApiError ? new Error(`${reason(error, dir)}. ${next}`, { cause: error }) : error;
|
|
111
|
+
}
|
|
112
|
+
/** HQ's note on why a move is stuck, as the person should read it; HQ's own text goes to the bot log. */
|
|
113
|
+
export function promotionFailureText(dir, config, companyUid, failure, failureCode) {
|
|
114
|
+
appendBotLog(dir, botLogLine("warn", `promotion: ${failureCode ? `${failureCode}: ` : ""}${failure}`));
|
|
115
|
+
if (failureCode === "PROMOTION_BRAIN_NOT_SUPPORTED") {
|
|
116
|
+
return `HQ cannot run ${config.name}'s model in the cloud. Cancel the move with: hq bot promote ${config.name} --company ${companyUid} --cancel, switch it to Codex on this computer, then promote it again.`;
|
|
117
|
+
}
|
|
118
|
+
return `HQ could not finish setting up the cloud copy of ${config.name}; it stays paused. Run the same command to retry, or cancel the move with: hq bot promote ${config.name} --company ${companyUid} --cancel`;
|
|
119
|
+
}
|
|
120
|
+
/** Any error from reading a move's details, as a short reason; the raw text goes to the bot log. */
|
|
121
|
+
export function promotionDetailsError(dir, error) {
|
|
122
|
+
return reason(error, dir);
|
|
123
|
+
}
|
|
124
|
+
function statusError(error, config, companyUid, dir) {
|
|
125
|
+
if (!(error instanceof BotApiError))
|
|
126
|
+
return error;
|
|
127
|
+
logRaw(dir, error);
|
|
128
|
+
if (error.status === 409 && error.code === "PROMOTION_CLIENT_TOO_OLD")
|
|
129
|
+
return serverRefusal(error, config);
|
|
130
|
+
if (error.status === 403) {
|
|
131
|
+
return new Error(`HQ refused to show the move of ${config.name} to company ${companyUid}: sign in as the bot's owner (hq whoami) and check that you are a member of ${companyUid}. Nothing was changed.`, { cause: error });
|
|
132
|
+
}
|
|
133
|
+
if (error.status === 404) {
|
|
134
|
+
return new Error(`HQ has no bot ${config.agentUid} or does not support moving bots to the cloud yet. Check the bot with: hq bot status ${config.name}; if it was removed in the cloud, bring it back with: hq bot restore --all, otherwise update hq and try again. Nothing was changed.`, { cause: error });
|
|
135
|
+
}
|
|
136
|
+
return plainError(error, dir, "Nothing was changed; run the same command again.");
|
|
137
|
+
}
|
|
138
|
+
async function readPromotionStatusRaw(api, config, companyUid) {
|
|
139
|
+
const existing = await api.promotionStatus(config.agentUid, companyUid);
|
|
140
|
+
if (existing && (existing.agentUid !== config.agentUid || existing.ownerUid !== config.ownerUid || existing.companyUid !== companyUid))
|
|
141
|
+
throw new Error("Promotion belongs to another bot or destination");
|
|
142
|
+
return existing;
|
|
143
|
+
}
|
|
144
|
+
async function readPromotionStatus(api, config, companyUid, dir) {
|
|
145
|
+
try {
|
|
146
|
+
return await readPromotionStatusRaw(api, config, companyUid);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
throw statusError(error, config, companyUid, dir);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Whether HQ still has this bot's agent. Gone only when the bot's owner is
|
|
153
|
+
* signed in and HQ shows the agent archived. A 404 is never proof: HQ answers
|
|
154
|
+
* 404 to anyone who may not read the agent, and no other route the owner can
|
|
155
|
+
* read lists archived agents.
|
|
156
|
+
*/
|
|
157
|
+
export async function cloudAgentPresence(input) {
|
|
158
|
+
const { api, config, dir } = input;
|
|
159
|
+
let agent;
|
|
160
|
+
try {
|
|
161
|
+
agent = await api.getAgent(config.agentUid);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (error instanceof BotApiError)
|
|
165
|
+
logRaw(dir, error);
|
|
166
|
+
else
|
|
167
|
+
appendBotLog(dir, botLogLine("warn", `promotion: cloud agent check failed: ${sentence(error)}`));
|
|
168
|
+
if (error instanceof BotApiError && error.status === 404 && !await signedInAsOwner(input))
|
|
169
|
+
return "not-owner";
|
|
170
|
+
return "unknown";
|
|
171
|
+
}
|
|
172
|
+
if (!agent || typeof agent !== "object" || (agent.uid && agent.uid !== config.agentUid))
|
|
173
|
+
return "unknown";
|
|
174
|
+
if (agent.entityStatus !== "archived" && agent.agentStatus !== "archived")
|
|
175
|
+
return "present";
|
|
176
|
+
return await signedInAsOwner(input) ? "gone" : "not-owner";
|
|
177
|
+
}
|
|
178
|
+
async function signedInAsOwner(input) {
|
|
179
|
+
if (!input.signedInPerson)
|
|
180
|
+
return false;
|
|
181
|
+
try {
|
|
182
|
+
return await input.signedInPerson() === input.config.ownerUid;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
appendBotLog(input.dir, botLogLine("warn", `promotion: signed-in person lookup failed: ${sentence(error)}`));
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function cloudDeletedError(config) {
|
|
190
|
+
return Object.assign(new Error(`The cloud copy of ${config.name} was deleted in HQ, so there is no move left to cancel. ` +
|
|
191
|
+
`Nothing was released: ${config.name} stays held on this computer. Remove what is left of it here with: hq bot rm ${config.name}`), { expected: true });
|
|
192
|
+
}
|
|
193
|
+
/** `hq bot rm` of a bot held for, or moved by, a promotion. Allowed only when HQ
|
|
194
|
+
* shows the owner its cloud agent archived; otherwise the cloud copy is or may
|
|
195
|
+
* become the bot's active consumer, so this throws and nothing is removed.
|
|
196
|
+
* Returns the company the bot moved to: its seat there went with the agent.
|
|
197
|
+
*/
|
|
198
|
+
export async function assertPromotedBotRemovable(input) {
|
|
199
|
+
const { dir, config } = input;
|
|
200
|
+
const presence = await cloudAgentPresence(input);
|
|
201
|
+
const companyUid = holdCompany(dir, config);
|
|
202
|
+
if (presence === "gone")
|
|
203
|
+
return { companyUid };
|
|
204
|
+
const company = companyUid ?? "<uid>";
|
|
205
|
+
const next = `If it is live in the cloud, remove it there with: hq agents rm ${config.agentUid} --company <slug>. ` +
|
|
206
|
+
`If the move did not finish, cancel it with: hq bot promote ${config.name} --company ${company} --cancel`;
|
|
207
|
+
const text = presence === "present"
|
|
208
|
+
? `${config.name} has moved, or is moving, to the cloud, so it was not removed from this computer. ${next}`
|
|
209
|
+
: presence === "not-owner"
|
|
210
|
+
? `Only the owner of ${config.name} (${config.ownerUid}) can confirm that its cloud copy was deleted, and you are not signed in as them, so nothing was removed. Sign in as the bot's owner (hq whoami) and run the same command again.`
|
|
211
|
+
: `HQ did not confirm that the cloud copy of ${config.name} was deleted, so nothing was removed. Check your sign-in (hq whoami) and that you are still a member of company ${company}, then run the same command again. ${next}`;
|
|
212
|
+
throw Object.assign(new Error(text), { expected: true });
|
|
213
|
+
}
|
|
214
|
+
function personalBotError(config, cause) {
|
|
215
|
+
return Object.assign(new Error(`${config.name} is a personal bot. Only company bots can move to the cloud; nothing was changed.`, cause ? { cause } : undefined), { expected: true });
|
|
216
|
+
}
|
|
217
|
+
const sentence = (error) => (error instanceof Error ? error.message : String(error)).replace(/[.\s]+$/, "");
|
|
218
|
+
/** HQ's 409 refusals of a move, in HQ's own words. */
|
|
219
|
+
function serverRefusal(error, config) {
|
|
220
|
+
if (!(error instanceof BotApiError) || error.status !== 409)
|
|
221
|
+
return error;
|
|
222
|
+
if (error.code === "PERSONAL_BOT_NOT_PROMOTABLE")
|
|
223
|
+
return personalBotError(config, error);
|
|
224
|
+
if (error.code === "PROMOTION_CLIENT_TOO_OLD") {
|
|
225
|
+
return Object.assign(new Error(error.detail ?? "Update HQ to move this bot to the cloud, then try again. Nothing was changed.", { cause: error }), { expected: true });
|
|
226
|
+
}
|
|
227
|
+
if (error.code === "PROMOTION_BRAIN_NOT_SUPPORTED") {
|
|
228
|
+
return Object.assign(new Error(error.detail ?? `HQ cannot run ${config.name}'s model in the cloud. Switch it to Codex on this computer, then promote it again.`, { cause: error }), { expected: true });
|
|
229
|
+
}
|
|
230
|
+
return error;
|
|
231
|
+
}
|
|
232
|
+
function withCancelHint(error, config, companyUid, dir) {
|
|
233
|
+
return new Error(`${reason(error, dir)}. ${config.name} stays stopped on this computer while it is held for the move. ` +
|
|
234
|
+
`Run the same command to continue, or cancel the move with: hq bot promote ${config.name} --company ${companyUid} --cancel`, { cause: error });
|
|
235
|
+
}
|
|
236
|
+
/** The bot's brain as sent at prepare: a known runtime profile provider wins over bot.json. */
|
|
237
|
+
export function promotionBrain(config, runtime) {
|
|
238
|
+
const profile = runtime?.brain?.() ?? null;
|
|
239
|
+
const model = config.model?.trim() || profile?.model?.trim();
|
|
240
|
+
const effort = config.effort?.trim();
|
|
241
|
+
return { runtime: profile?.runtime ?? config.runtime, ...(model ? { model } : {}), ...(effort ? { effort } : {}) };
|
|
242
|
+
}
|
|
243
|
+
/** Cloud bots run on Codex only for now. A bot already held names the cancel. */
|
|
244
|
+
export function promotionBrainRefusal(config, brain, dir) {
|
|
245
|
+
if (brain.runtime === "codex")
|
|
246
|
+
return null;
|
|
247
|
+
const name = config.name;
|
|
248
|
+
const held = hasPromotionHold(dir) ? holdCompany(dir, config) ?? "<uid>" : null;
|
|
249
|
+
const cancel = held ? `${name} is held for a move to company ${held}: cancel that move with: hq bot promote ${name} --company ${held} --cancel, then switch it to Codex with: hq bot switch-account ${name} --runtime codex` : null;
|
|
250
|
+
const text = brain.runtime === "claude"
|
|
251
|
+
? cancel
|
|
252
|
+
? `${name} runs on Claude, which cloud bots cannot use yet. ${cancel}. Nothing was changed.`
|
|
253
|
+
: `${name} runs on Claude, which cloud bots cannot use yet. Switch it to Codex first with: hq bot switch-account ${name} --runtime codex, then promote it again. Nothing was changed.`
|
|
254
|
+
: cancel
|
|
255
|
+
? `Moving a Grok bot to the cloud is not supported yet. ${cancel}, or keep it on this computer. Nothing was changed.`
|
|
256
|
+
: `Moving a Grok bot to the cloud is not supported yet. Switch ${name} to Codex first with: hq bot switch-account ${name} --runtime codex, or keep it on this computer. Nothing was changed.`;
|
|
257
|
+
return Object.assign(new Error(text), { expected: true });
|
|
258
|
+
}
|
|
40
259
|
/** One recoverable local-to-cloud step, used by CLI and desktop. Never kills the
|
|
41
260
|
* local runtime, recopies provider login files, or changes another bot.
|
|
261
|
+
* When this call creates the hold and fails before the server records the
|
|
262
|
+
* operation, it releases the hold and starts the bot again if it was running.
|
|
42
263
|
*/
|
|
43
264
|
export async function promoteLocalBot(input) {
|
|
44
265
|
const { dir, config, companyUid, api, runtime } = input;
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
266
|
+
const brain = promotionBrain(config, runtime);
|
|
267
|
+
const refusal = promotionBrainRefusal(config, brain, dir);
|
|
268
|
+
if (refusal)
|
|
269
|
+
throw refusal;
|
|
270
|
+
if (config.kind === "personal")
|
|
271
|
+
throw personalBotError(config);
|
|
272
|
+
const read = readLocalHold(dir, config);
|
|
273
|
+
if (read.unreadable !== undefined)
|
|
274
|
+
throw unreadableHoldError(dir, config, read.unreadable);
|
|
275
|
+
let localHold = read.hold;
|
|
276
|
+
if (localHold && localHold.companyUid !== companyUid)
|
|
277
|
+
throw otherCompanyError(config, localHold.companyUid, companyUid, false);
|
|
278
|
+
let existing = await readPromotionStatus(api, config, companyUid, dir);
|
|
279
|
+
let priorOrigin = null;
|
|
280
|
+
if (existing?.phase === "cancelled") {
|
|
281
|
+
// A canceled operation is finished: no hold, id or frozen snapshot from before is used again.
|
|
282
|
+
priorOrigin = readPromotionHoldOrigin(dir);
|
|
283
|
+
releaseLocalPromotion(dir);
|
|
284
|
+
localHold = null;
|
|
285
|
+
existing = null;
|
|
286
|
+
}
|
|
48
287
|
const operationId = existing?.operationId ?? localHold?.operationId ?? randomUUID();
|
|
49
|
-
if (
|
|
288
|
+
if (!OPERATION_ID.test(operationId))
|
|
50
289
|
throw new Error("Invalid saved promotion operation");
|
|
51
290
|
const hold = { agentUid: config.agentUid, ownerUid: config.ownerUid, companyUid, operationId };
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (existing?.phase === "cancelled")
|
|
55
|
-
throw new Error("This promotion was cancelled");
|
|
291
|
+
const fresh = !existing && !localHold;
|
|
292
|
+
const wasRunning = fresh ? priorOrigin ?? (input.isRunning ?? (() => localBotProcessAlive(dir)))() : null;
|
|
56
293
|
holdForPromotion(dir, hold);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (existing)
|
|
66
|
-
throw new Error("The original frozen snapshot is missing. Restore it before retrying.");
|
|
67
|
-
const snapshot = snapshotBotContinuity(config, dir);
|
|
68
|
-
const temp = `${file}.${randomUUID()}.tmp`;
|
|
69
|
-
fs.writeFileSync(temp, JSON.stringify(snapshot), { mode: 0o600, flag: "wx" });
|
|
70
|
-
try {
|
|
71
|
-
fs.linkSync(temp, file);
|
|
294
|
+
let prepared = !fresh;
|
|
295
|
+
let prepareSent = false;
|
|
296
|
+
try {
|
|
297
|
+
if (fresh)
|
|
298
|
+
recordPromotionHoldOrigin(dir, operationId, wasRunning);
|
|
299
|
+
if (existing?.phase === "active") {
|
|
300
|
+
recordActivePromotion(dir, hold, existing);
|
|
301
|
+
return { promotion: existing, pending: false };
|
|
72
302
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
303
|
+
runtime?.stop();
|
|
304
|
+
await waitForPromotionDrain(dir, input.drainTimeoutMs ?? 60_000);
|
|
305
|
+
const file = path.join(dir, `promotion-snapshot-${operationId}.json`);
|
|
306
|
+
if (!fs.existsSync(file)) {
|
|
307
|
+
if (existing)
|
|
308
|
+
throw new Error("The original frozen snapshot is missing. Restore it before retrying.");
|
|
309
|
+
const snapshot = snapshotBotContinuity(config, dir);
|
|
310
|
+
const temp = `${file}.${randomUUID()}.tmp`;
|
|
311
|
+
fs.writeFileSync(temp, JSON.stringify(snapshot), { mode: 0o600, flag: "wx" });
|
|
312
|
+
try {
|
|
313
|
+
fs.linkSync(temp, file);
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
if (error.code !== "EEXIST")
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
fs.unlinkSync(temp);
|
|
321
|
+
}
|
|
76
322
|
}
|
|
77
|
-
|
|
78
|
-
|
|
323
|
+
const bundle = readPrivateJson(file, 48 * 1024 * 1024);
|
|
324
|
+
validateBotContinuity(bundle, { agentUid: config.agentUid, ownerUid: config.ownerUid });
|
|
325
|
+
if (existing && existing.snapshotSha256 !== bundle.digest)
|
|
326
|
+
throw new Error("Frozen snapshot does not match the cloud operation");
|
|
327
|
+
let state = existing;
|
|
328
|
+
if (!state || state.phase === "preparing") {
|
|
329
|
+
const machine = runtime ? runtime.machineCredential() : readPrivateJson(botCredsPath(dir), 8192);
|
|
330
|
+
if (!machine || typeof machine !== "object" || typeof machine.secret !== "string")
|
|
331
|
+
throw new Error("Invalid bot machine credential");
|
|
332
|
+
try {
|
|
333
|
+
state = await uploadLocalBotPromotion({ api, bundle, machine, companyUid, operationId, brain, onPreparing: () => { prepareSent = true; }, onPrepared: () => { prepared = true; } });
|
|
334
|
+
const proof = await attestPromotionDrain(dir, hold, bundle.digest, machine);
|
|
335
|
+
state = await api.confirmPromotionStopped(config.agentUid, { companyUid, operationId, proof });
|
|
336
|
+
}
|
|
337
|
+
finally {
|
|
338
|
+
machine.secret = "";
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (state.phase === "local-stopped" || state.phase === "imported" || state.phase === "cloud-ready") {
|
|
342
|
+
const result = await api.resumePromotion(config.agentUid, { companyUid, operationId });
|
|
343
|
+
if (result.promotion.phase === "active")
|
|
344
|
+
recordActivePromotion(dir, hold, result.promotion);
|
|
345
|
+
return result;
|
|
79
346
|
}
|
|
347
|
+
return { promotion: state, pending: state.phase !== "active" };
|
|
80
348
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
349
|
+
catch (error) {
|
|
350
|
+
if (prepared)
|
|
351
|
+
throw withCancelHint(error, config, companyUid, dir);
|
|
352
|
+
// A prepare whose answer was lost may still have been recorded: ask before releasing.
|
|
353
|
+
if (prepareSent && !(error instanceof BotApiError) && await serverMayKnow(api, config, companyUid, operationId))
|
|
354
|
+
throw withCancelHint(error, config, companyUid, dir);
|
|
355
|
+
const refused = serverRefusal(error, config);
|
|
356
|
+
releaseLocalPromotion(dir);
|
|
357
|
+
if (wasRunning && input.restart) {
|
|
358
|
+
try {
|
|
359
|
+
await input.restart();
|
|
360
|
+
}
|
|
361
|
+
catch (restartError) {
|
|
362
|
+
throw new Error(`${reason(refused, dir)}. The hold was removed, but ${config.name} did not start again: ${sentence(restartError)}. Start it with: hq bot start ${config.name}`, { cause: error });
|
|
363
|
+
}
|
|
94
364
|
}
|
|
95
|
-
|
|
96
|
-
|
|
365
|
+
throw plainError(refused, dir, "Nothing was changed; run the same command again.");
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
async function serverMayKnow(api, config, companyUid, operationId) {
|
|
369
|
+
try {
|
|
370
|
+
const state = await readPromotionStatusRaw(api, config, companyUid);
|
|
371
|
+
return !!state && state.operationId === operationId && state.phase !== "cancelled";
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
export const PROMOTION_CANCEL_POLL_MS = 5_000;
|
|
378
|
+
/** Below the bot lock's stale age, so no other command can take the lock mid-cancel. */
|
|
379
|
+
export const PROMOTION_CANCEL_TIMEOUT_MS = 8 * 60_000;
|
|
380
|
+
export const PROMOTION_CANCEL_IDENTITY_RETRIES = 3;
|
|
381
|
+
/** Cancel on the server first. The local hold, its receipt and its frozen
|
|
382
|
+
* snapshots are released only on proof that nothing needs the bot held: a
|
|
383
|
+
* confirmed cancel for this operation, PROMOTION_NOT_FOUND, or no server
|
|
384
|
+
* promotion at all. Anything else keeps the hold. A damaged hold may name
|
|
385
|
+
* another company, so only a confirmed cancel releases it. When HQ will not
|
|
386
|
+
* show the move (403, or 404 without a code), a readable hold for this company
|
|
387
|
+
* still asks HQ to cancel its operation: cancel is authorized on the bot alone.
|
|
388
|
+
*/
|
|
389
|
+
export async function cancelLocalBotPromotion(input) {
|
|
390
|
+
const { dir, config, companyUid, api } = input;
|
|
391
|
+
const read = readLocalHold(dir, config);
|
|
392
|
+
const damaged = read.unreadable;
|
|
393
|
+
const held = read.hold?.companyUid ?? (damaged !== undefined ? holdCompany(dir, config) : null);
|
|
394
|
+
if (held && held !== companyUid)
|
|
395
|
+
throw otherCompanyError(config, held, companyUid, true);
|
|
396
|
+
let existing;
|
|
397
|
+
let unseen = null;
|
|
398
|
+
try {
|
|
399
|
+
existing = await readPromotionStatusRaw(api, config, companyUid);
|
|
400
|
+
}
|
|
401
|
+
catch (error) {
|
|
402
|
+
const hidden = error instanceof BotApiError && (error.status === 403 || (error.status === 404 && !error.code));
|
|
403
|
+
if (!hidden || !read.hold)
|
|
404
|
+
throw statusError(error, config, companyUid, dir);
|
|
405
|
+
existing = null;
|
|
406
|
+
unseen = error;
|
|
407
|
+
}
|
|
408
|
+
const wasRunning = readPromotionHoldOrigin(dir, read.hold?.operationId);
|
|
409
|
+
const released = (outcome, promotion, identityRestored = null) => ({ outcome, promotion, pending: false, localHoldReleased: releaseLocalPromotion(dir), wasRunning, identityRestored });
|
|
410
|
+
if (!existing && !unseen) {
|
|
411
|
+
if (damaged !== undefined)
|
|
412
|
+
throw damagedHoldError(dir, config, damaged, companyUid);
|
|
413
|
+
return released("not-found", null);
|
|
414
|
+
}
|
|
415
|
+
const operationId = existing?.operationId ?? read.hold.operationId;
|
|
416
|
+
if (!OPERATION_ID.test(operationId))
|
|
417
|
+
throw new Error("Invalid saved promotion operation");
|
|
418
|
+
const pollMs = input.pollMs ?? PROMOTION_CANCEL_POLL_MS;
|
|
419
|
+
const timeoutMs = input.timeoutMs ?? PROMOTION_CANCEL_TIMEOUT_MS;
|
|
420
|
+
const sleep = input.sleep ?? ((ms) => new Promise(resolve => setTimeout(resolve, ms)));
|
|
421
|
+
const kept = `Nothing was released: ${config.name} stays held on this computer.`;
|
|
422
|
+
let result;
|
|
423
|
+
try {
|
|
424
|
+
result = await api.cancelPromotion(config.agentUid, { companyUid, operationId });
|
|
425
|
+
let waited = 0;
|
|
426
|
+
let identityRetries = 0;
|
|
427
|
+
for (;;) {
|
|
428
|
+
if (result.pending) {
|
|
429
|
+
if (waited >= timeoutMs)
|
|
430
|
+
break;
|
|
431
|
+
if (waited === 0)
|
|
432
|
+
input.onWaiting?.();
|
|
433
|
+
await sleep(pollMs);
|
|
434
|
+
waited += pollMs;
|
|
435
|
+
}
|
|
436
|
+
else if (result.identityRestored === false && identityRetries < PROMOTION_CANCEL_IDENTITY_RETRIES) {
|
|
437
|
+
identityRetries += 1;
|
|
438
|
+
await sleep(pollMs);
|
|
439
|
+
}
|
|
440
|
+
else
|
|
441
|
+
break;
|
|
442
|
+
result = await api.cancelPromotion(config.agentUid, { companyUid, operationId });
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
if (error instanceof BotApiError && error.status === 409 && error.code === "PROMOTION_ALREADY_ACTIVE") {
|
|
447
|
+
return { outcome: "active", promotion: existing, pending: false, localHoldReleased: false, wasRunning, identityRestored: null };
|
|
448
|
+
}
|
|
449
|
+
if (error instanceof BotApiError && error.status === 409 && error.code === "PROMOTION_INSTANCE_NOT_OWNED") {
|
|
450
|
+
throw new Error(`HQ says the cloud copy of ${config.name} does not belong to this move, so it cannot be canceled from here. ${kept}`, { cause: error });
|
|
451
|
+
}
|
|
452
|
+
if (unseen && !(error instanceof BotApiError && error.status === 404 && error.code === "PROMOTION_NOT_FOUND")) {
|
|
453
|
+
logRaw(dir, unseen);
|
|
454
|
+
const bothMissing = unseen.status === 404 && error instanceof BotApiError && error.status === 404 && !error.code;
|
|
455
|
+
if (bothMissing && await cloudAgentPresence(input) === "gone")
|
|
456
|
+
throw cloudDeletedError(config);
|
|
457
|
+
throw new Error(`${unseen.status === 403 ? "HQ refused to show" : "HQ could not find"} the move of ${config.name} to company ${companyUid}, and the cancel did not go through (${reason(error, dir)}). ${kept} ` +
|
|
458
|
+
`Sign in as the bot's owner (hq whoami) and run the same command again.`, { cause: error });
|
|
459
|
+
}
|
|
460
|
+
if (error instanceof BotApiError && error.status === 404 && error.code === "PROMOTION_NOT_FOUND") {
|
|
461
|
+
if (damaged !== undefined)
|
|
462
|
+
throw damagedHoldError(dir, config, damaged, companyUid);
|
|
463
|
+
return released("not-found", null);
|
|
464
|
+
}
|
|
465
|
+
if (error instanceof BotApiError && error.status === 404) {
|
|
466
|
+
logRaw(dir, error);
|
|
467
|
+
if (!error.code && await cloudAgentPresence(input) === "gone")
|
|
468
|
+
throw cloudDeletedError(config);
|
|
469
|
+
throw new Error(`HQ could not cancel the move: the server may not support cancel yet, or ${config.name} was removed in the cloud. ${kept} ` +
|
|
470
|
+
`Update hq and run the same command again; if the bot was removed in the cloud, check it with: hq bot status ${config.name}`, { cause: error });
|
|
97
471
|
}
|
|
472
|
+
throw plainError(error, dir, `${kept} Run the same command again.`);
|
|
98
473
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return result;
|
|
474
|
+
if (result.pending)
|
|
475
|
+
return { outcome: "pending", promotion: result.promotion, pending: true, localHoldReleased: false, wasRunning, identityRestored: null };
|
|
476
|
+
if (result.promotion?.phase !== "cancelled" || result.promotion.operationId !== operationId || result.promotion.agentUid !== config.agentUid || result.promotion.companyUid !== companyUid) {
|
|
477
|
+
throw new Error(`HQ answered the cancel without confirming it (phase ${result.promotion?.phase ?? "missing"}). ${kept} Run the same command again.`);
|
|
104
478
|
}
|
|
105
|
-
return
|
|
479
|
+
return released("canceled", result.promotion, result.identityRestored ?? null);
|
|
106
480
|
}
|
|
107
481
|
//# sourceMappingURL=promote.js.map
|
|
@@ -11,6 +11,15 @@ export interface LocalPromotionHold {
|
|
|
11
11
|
* possibly reused PID; it finishes its current reply/ACK and exits cleanly.
|
|
12
12
|
*/
|
|
13
13
|
export declare function holdForPromotion(dir: string, hold: LocalPromotionHold): void;
|
|
14
|
+
/** Whether the bot was running when its hold was first written. A file of its
|
|
15
|
+
* own: the drain attestation covers the hold file's bytes, so those never change.
|
|
16
|
+
*/
|
|
17
|
+
export declare const promotionHoldOriginPath: (dir: string) => string;
|
|
18
|
+
export declare function recordPromotionHoldOrigin(dir: string, operationId: string, wasRunning: boolean): void;
|
|
19
|
+
/** Null when nothing was recorded for this operation, as for a hold an earlier hq wrote. */
|
|
20
|
+
export declare function readPromotionHoldOrigin(dir: string, operationId?: string): boolean | null;
|
|
21
|
+
/** A live local process for this bot, read the way the drain wait reads it. */
|
|
22
|
+
export declare function localBotProcessAlive(dir: string): boolean;
|
|
14
23
|
/** A timeout leaves the hold intact and never aborts the model turn. */
|
|
15
24
|
export declare function waitForPromotionDrain(dir: string, timeoutMs?: number): Promise<void>;
|
|
16
25
|
/** Called after freezing/uploading the snapshot; rechecks the durable hold and
|
|
@@ -37,6 +37,35 @@ export function holdForPromotion(dir, hold) {
|
|
|
37
37
|
throw new Error("Another promotion owns this local bot");
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
/** Whether the bot was running when its hold was first written. A file of its
|
|
41
|
+
* own: the drain attestation covers the hold file's bytes, so those never change.
|
|
42
|
+
*/
|
|
43
|
+
export const promotionHoldOriginPath = (dir) => path.join(dir, "promotion-hold-origin.json");
|
|
44
|
+
export function recordPromotionHoldOrigin(dir, operationId, wasRunning) {
|
|
45
|
+
fs.rmSync(promotionHoldOriginPath(dir), { force: true });
|
|
46
|
+
fs.writeFileSync(promotionHoldOriginPath(dir), JSON.stringify({ operationId, wasRunning }), { flag: "wx", mode: 0o600 });
|
|
47
|
+
}
|
|
48
|
+
/** Null when nothing was recorded for this operation, as for a hold an earlier hq wrote. */
|
|
49
|
+
export function readPromotionHoldOrigin(dir, operationId) {
|
|
50
|
+
try {
|
|
51
|
+
const stat = fs.lstatSync(promotionHoldOriginPath(dir));
|
|
52
|
+
if (!stat.isFile() || stat.size > 512)
|
|
53
|
+
return null;
|
|
54
|
+
const origin = JSON.parse(fs.readFileSync(promotionHoldOriginPath(dir), "utf8"));
|
|
55
|
+
if (typeof origin?.wasRunning !== "boolean" || (operationId !== undefined && origin.operationId !== operationId))
|
|
56
|
+
return null;
|
|
57
|
+
return origin.wasRunning;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** A live local process for this bot, read the way the drain wait reads it. */
|
|
64
|
+
export function localBotProcessAlive(dir) {
|
|
65
|
+
const lock = readPidLock(daemonPidPath(dir));
|
|
66
|
+
const status = readBotStatus(dir);
|
|
67
|
+
return Boolean((lock && isPidAlive(lock.pid)) || (status && isPidAlive(status.pid)));
|
|
68
|
+
}
|
|
40
69
|
/** A timeout leaves the hold intact and never aborts the model turn. */
|
|
41
70
|
export async function waitForPromotionDrain(dir, timeoutMs = 60_000) {
|
|
42
71
|
if (!hasPromotionHold(dir))
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { BotPromotionState } from "./api.js";
|
|
2
2
|
import { type LocalPromotionHold } from "./promotion-hold.js";
|
|
3
|
+
/** `cloud`: the bot runs in the cloud. `moving`: held for a move that has not finished.
|
|
4
|
+
* An unreadable hold counts as `moving`, so nothing starts the bot locally.
|
|
5
|
+
*/
|
|
6
|
+
export type LocalPromotionState = "cloud" | "moving";
|
|
7
|
+
export declare function localPromotionState(dir: string, agentUid: string, ownerUid: string): LocalPromotionState | null;
|
|
8
|
+
/** Only on proof that no promotion needs this bot held. Every frozen snapshot
|
|
9
|
+
* goes too (they hold private context and mean nothing without a hold). The
|
|
10
|
+
* hold goes last, so a crash leaves the bot held.
|
|
11
|
+
*/
|
|
12
|
+
export declare function releaseLocalPromotion(dir: string): boolean;
|
|
3
13
|
/** Cache only the authenticated server's terminal response. The local hold is
|
|
4
14
|
* permanent until an explicit rollback; this receipt controls presentation only.
|
|
5
15
|
*/
|
|
@@ -1,8 +1,48 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { holdForPromotion } from "./promotion-hold.js";
|
|
4
|
+
import { hasPromotionHold, holdForPromotion, promotionHoldOriginPath } from "./promotion-hold.js";
|
|
5
5
|
const receiptPath = (dir) => path.join(dir, "promotion-active.json");
|
|
6
|
+
export function localPromotionState(dir, agentUid, ownerUid) {
|
|
7
|
+
if (hasActivePromotion(dir, agentUid, ownerUid))
|
|
8
|
+
return "cloud";
|
|
9
|
+
try {
|
|
10
|
+
return hasPromotionHold(dir) ? "moving" : null;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return "moving";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const SNAPSHOT_FILE = /^promotion-snapshot-[A-Za-z0-9_-]{16,128}\.json(\.[A-Za-z0-9-]+\.tmp)?$/;
|
|
17
|
+
/** Only on proof that no promotion needs this bot held. Every frozen snapshot
|
|
18
|
+
* goes too (they hold private context and mean nothing without a hold). The
|
|
19
|
+
* hold goes last, so a crash leaves the bot held.
|
|
20
|
+
*/
|
|
21
|
+
export function releaseLocalPromotion(dir) {
|
|
22
|
+
const holdFile = path.join(dir, "promotion-hold.json");
|
|
23
|
+
const held = hasHoldFile(holdFile) || fs.existsSync(receiptPath(dir));
|
|
24
|
+
fs.rmSync(receiptPath(dir), { force: true });
|
|
25
|
+
let names = [];
|
|
26
|
+
try {
|
|
27
|
+
names = fs.readdirSync(dir);
|
|
28
|
+
}
|
|
29
|
+
catch { /* nothing to remove */ }
|
|
30
|
+
for (const name of names)
|
|
31
|
+
if (SNAPSHOT_FILE.test(name))
|
|
32
|
+
fs.rmSync(path.join(dir, name), { force: true });
|
|
33
|
+
fs.rmSync(promotionHoldOriginPath(dir), { force: true });
|
|
34
|
+
fs.rmSync(holdFile, { force: true });
|
|
35
|
+
return held;
|
|
36
|
+
}
|
|
37
|
+
function hasHoldFile(holdFile) {
|
|
38
|
+
try {
|
|
39
|
+
fs.lstatSync(holdFile);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
6
46
|
/** Cache only the authenticated server's terminal response. The local hold is
|
|
7
47
|
* permanent until an explicit rollback; this receipt controls presentation only.
|
|
8
48
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BotMachineCreds } from "./creds.js";
|
|
2
|
-
import { BotApi, type BotPromotionState } from "./api.js";
|
|
2
|
+
import { BotApi, type BotPromotionBrain, type BotPromotionState } from "./api.js";
|
|
3
3
|
import { type BotContinuityBundle } from "./continuity.js";
|
|
4
4
|
/** Upload a frozen local snapshot plus ONLY its HQ machine credential. The
|
|
5
5
|
* caller owns draining and a durable local operation lock across this method.
|
|
@@ -11,6 +11,11 @@ export declare function uploadLocalBotPromotion(input: {
|
|
|
11
11
|
machine: BotMachineCreds;
|
|
12
12
|
companyUid: string;
|
|
13
13
|
operationId: string;
|
|
14
|
+
brain: BotPromotionBrain;
|
|
14
15
|
fetchImpl?: typeof fetch;
|
|
16
|
+
/** Called just before the prepare request is sent. */
|
|
17
|
+
onPreparing?: () => void;
|
|
18
|
+
/** Called once the server has recorded the operation. */
|
|
19
|
+
onPrepared?: () => void;
|
|
15
20
|
}): Promise<BotPromotionState>;
|
|
16
21
|
//# sourceMappingURL=promotion-upload.d.ts.map
|