@indigoai-us/hq-cli 5.345.214 → 5.345.215-beta.0
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 +29 -0
- package/dist/command-catalog.generated.d.ts +134 -7
- package/dist/command-catalog.generated.js +168 -7
- package/dist/commands/agents.d.ts +51 -1
- package/dist/commands/agents.js +154 -2
- package/dist/commands/bot-jobs.d.ts +2 -15
- package/dist/commands/bot-jobs.js +2 -94
- package/dist/commands/bot-runtime.d.ts +46 -5
- package/dist/commands/bot-runtime.js +228 -18
- package/dist/commands/bot.d.ts +16 -9
- package/dist/commands/bot.js +169 -51
- package/dist/commands/cloud.d.ts +66 -13
- package/dist/commands/cloud.js +120 -39
- package/dist/commands/company-restore.d.ts +23 -0
- package/dist/commands/company-restore.js +128 -0
- package/dist/commands/company.js +2 -0
- package/dist/commands/integrations-connect.d.ts +10 -3
- package/dist/commands/integrations-connect.js +87 -13
- package/dist/commands/lanes.js +26 -9
- package/dist/commands/sources.js +6 -0
- package/dist/commands/storage-offload.d.ts +12 -0
- package/dist/commands/storage-offload.js +41 -3
- package/dist/commands/sync-mode.js +5 -0
- package/dist/commands/whoami.js +4 -0
- package/dist/lib/bot/config.d.ts +1 -0
- package/dist/lib/bot/config.js +10 -0
- package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
- package/dist/lib/bot/eventbridge-cron.js +104 -0
- package/dist/lib/bot/fleet-local.d.ts +33 -1
- package/dist/lib/bot/fleet-local.js +215 -31
- package/dist/lib/bot/fleet-python.d.ts +3 -0
- package/dist/lib/bot/fleet-python.js +34 -4
- package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
- package/dist/lib/bot/fleet-runtime-sources.js +30 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
- package/dist/lib/bot/legacy-provider-login.js +19 -2
- package/dist/lib/bot/prompt.js +1 -1
- package/dist/lib/bot/readiness.d.ts +8 -0
- package/dist/lib/bot/readiness.js +17 -3
- package/dist/lib/bot/runtime-auth.d.ts +30 -0
- package/dist/lib/bot/runtime-auth.js +94 -3
- package/dist/lib/bot/status.d.ts +2 -0
- package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
- package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
- package/dist/lib/capacity/collectors/grok.d.ts +5 -0
- package/dist/lib/capacity/collectors/grok.js +56 -5
- package/dist/lib/daemon/catalog.js +11 -1
- package/dist/lib/db/sqlite-binding.d.ts +1 -0
- package/dist/lib/db/sqlite-binding.js +1 -1
- package/dist/lib/delivery/artifacts.d.ts +99 -0
- package/dist/lib/delivery/artifacts.js +548 -0
- package/dist/lib/delivery/backup.d.ts +78 -0
- package/dist/lib/delivery/backup.js +343 -0
- package/dist/lib/delivery/cache.d.ts +29 -0
- package/dist/lib/delivery/cache.js +33 -0
- package/dist/lib/delivery/contracts.d.ts +142 -0
- package/dist/lib/delivery/contracts.js +289 -0
- package/dist/lib/delivery/credentials.d.ts +54 -0
- package/dist/lib/delivery/credentials.js +119 -0
- package/dist/lib/delivery/enrollment.d.ts +142 -0
- package/dist/lib/delivery/enrollment.js +382 -0
- package/dist/lib/delivery/identity.d.ts +25 -0
- package/dist/lib/delivery/identity.js +82 -0
- package/dist/lib/delivery/inbox.d.ts +116 -0
- package/dist/lib/delivery/inbox.js +260 -0
- package/dist/lib/delivery/migrations.d.ts +139 -0
- package/dist/lib/delivery/migrations.js +623 -0
- package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
- package/dist/lib/delivery/mqtt-adapter.js +242 -0
- package/dist/lib/delivery/mqtt.d.ts +61 -0
- package/dist/lib/delivery/mqtt.js +112 -0
- package/dist/lib/delivery/outbox.d.ts +95 -0
- package/dist/lib/delivery/outbox.js +187 -0
- package/dist/lib/delivery/provenance.d.ts +129 -0
- package/dist/lib/delivery/provenance.js +93 -0
- package/dist/lib/delivery/reconciler.d.ts +151 -0
- package/dist/lib/delivery/reconciler.js +492 -0
- package/dist/lib/delivery/restore.d.ts +35 -0
- package/dist/lib/delivery/restore.js +134 -0
- package/dist/lib/delivery/store.d.ts +161 -0
- package/dist/lib/delivery/store.js +940 -0
- package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
- package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
- package/dist/lib/delivery/workers/macos.d.ts +176 -0
- package/dist/lib/delivery/workers/macos.js +901 -0
- package/dist/lib/delivery/workers/windows-boundary.d.ts +453 -0
- package/dist/lib/delivery/workers/windows-boundary.js +693 -0
- package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
- package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
- package/dist/lib/delivery/workers/windows.d.ts +241 -0
- package/dist/lib/delivery/workers/windows.js +608 -0
- package/dist/lib/install/provider-wrappers.d.ts +2 -0
- package/dist/lib/install/provider-wrappers.js +68 -3
- package/dist/utils/cognito-callback-port.d.ts +14 -0
- package/dist/utils/cognito-callback-port.js +24 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/deleted-company-notice.d.ts +59 -0
- package/dist/utils/deleted-company-notice.js +156 -0
- package/dist/utils/login-browser.d.ts +1 -1
- package/dist/utils/login-browser.js +7 -5
- package/dist/utils/resident-package-preload.js +30 -15
- package/dist/utils/vault-api.js +7 -0
- package/package.json +7 -7
package/dist/commands/agents.js
CHANGED
|
@@ -31,6 +31,7 @@ import { runResidentCommandWithPackageLease, } from "../utils/resident-package-p
|
|
|
31
31
|
import { waitForAgentTerminalSession } from "../lib/agents/terminal-wait.js";
|
|
32
32
|
import chalk from "chalk";
|
|
33
33
|
import { randomUUID } from "node:crypto";
|
|
34
|
+
import { readFileSync } from "node:fs";
|
|
34
35
|
import * as readline from "node:readline";
|
|
35
36
|
import { resolveVaultCredential } from "../utils/resolve-vault-credential.js";
|
|
36
37
|
import { maxLength } from "../utils/table-width.js";
|
|
@@ -39,6 +40,7 @@ import { gateApiKeyCapabilities } from "../utils/api-key-command-gate.js";
|
|
|
39
40
|
import { queueCliLimitNoticeEngagement, queueCliLimitNoticeExposure, } from "../utils/cli-telemetry.js";
|
|
40
41
|
import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
|
|
41
42
|
import { consoleOrigin } from "./integrations-connect.js";
|
|
43
|
+
import { toEventBridgeCron } from "../lib/bot/eventbridge-cron.js";
|
|
42
44
|
import { launchSessionManagerPlugin, SessionManagerPluginLaunchError, TerminalSessionTimeoutError, } from "@indigoai-us/hq-cloud/outposts/node";
|
|
43
45
|
import { peekIdToken } from "../utils/id-token.js";
|
|
44
46
|
import { canOfferTeamUpgrade, formatUpgradeRefusal, isPlanGateError, offerUpgradeLink, } from "../utils/plan-gate-error.js";
|
|
@@ -909,6 +911,94 @@ export async function cancelAgentJob(token, agentUid, jobId) {
|
|
|
909
911
|
method: "POST",
|
|
910
912
|
});
|
|
911
913
|
}
|
|
914
|
+
export async function updateAgentJob(token, agentUid, jobId, body) {
|
|
915
|
+
return agentsRequest({
|
|
916
|
+
token,
|
|
917
|
+
path: `/v1/agents/${encodeURIComponent(agentUid)}/jobs/${encodeURIComponent(jobId)}/update`,
|
|
918
|
+
method: "POST",
|
|
919
|
+
body: { ...body },
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Build the edit body from `hq agents jobs update` flags. Pure: file reads
|
|
924
|
+
* (`--prompt-file`, `--script-file`) happen before this is called. Throws a
|
|
925
|
+
* plain Error with operator copy on a bad combination.
|
|
926
|
+
*
|
|
927
|
+
* `--cron` takes the stored six-field `cron(...)`/`rate(...)` form verbatim
|
|
928
|
+
* or a standard five-field expression, translated with the same rules local
|
|
929
|
+
* bot jobs use. A schedule change needs an explicit `--tz`: defaulting to
|
|
930
|
+
* the operator's machine zone would silently move a job that runs in another
|
|
931
|
+
* zone. `--tz` on its own is refused.
|
|
932
|
+
*/
|
|
933
|
+
export function buildJobUpdateBody(opts, translateCron) {
|
|
934
|
+
const body = {};
|
|
935
|
+
if (opts.name !== undefined)
|
|
936
|
+
body.name = opts.name;
|
|
937
|
+
if (opts.prompt !== undefined) {
|
|
938
|
+
if (!opts.prompt.trim())
|
|
939
|
+
throw new Error("--prompt cannot be empty.");
|
|
940
|
+
body.prompt = opts.prompt;
|
|
941
|
+
}
|
|
942
|
+
if (opts.cron !== undefined && opts.at !== undefined) {
|
|
943
|
+
throw new Error("Pass --cron or --at, not both.");
|
|
944
|
+
}
|
|
945
|
+
if (opts.tz !== undefined && opts.cron === undefined && opts.at === undefined) {
|
|
946
|
+
throw new Error("--tz changes the schedule, so pass --cron or --at with it.");
|
|
947
|
+
}
|
|
948
|
+
const timezone = opts.tz?.trim() ?? "";
|
|
949
|
+
if ((opts.cron !== undefined || opts.at !== undefined) && !timezone) {
|
|
950
|
+
throw new Error("Pass --tz <IANA timezone> with --cron or --at (for example --tz America/New_York), so the job's zone never changes by accident.");
|
|
951
|
+
}
|
|
952
|
+
if (opts.cron !== undefined) {
|
|
953
|
+
body.schedule = { kind: "recurring", cron: translateCron(opts.cron), timezone };
|
|
954
|
+
}
|
|
955
|
+
else if (opts.at !== undefined) {
|
|
956
|
+
const at = new Date(opts.at);
|
|
957
|
+
if (Number.isNaN(at.getTime())) {
|
|
958
|
+
throw new Error(`--at "${opts.at}" is not a date and time (use ISO-8601, e.g. 2026-12-01T09:00:00Z).`);
|
|
959
|
+
}
|
|
960
|
+
body.schedule = { kind: "once", at: at.toISOString(), timezone };
|
|
961
|
+
}
|
|
962
|
+
if (opts.context !== undefined && opts.clearContext) {
|
|
963
|
+
throw new Error("Pass --context or --clear-context, not both.");
|
|
964
|
+
}
|
|
965
|
+
if (opts.context !== undefined) {
|
|
966
|
+
let parsed;
|
|
967
|
+
try {
|
|
968
|
+
parsed = JSON.parse(opts.context);
|
|
969
|
+
}
|
|
970
|
+
catch {
|
|
971
|
+
throw new Error("--context must be a JSON object.");
|
|
972
|
+
}
|
|
973
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
974
|
+
throw new Error("--context must be a JSON object.");
|
|
975
|
+
}
|
|
976
|
+
body.context = parsed;
|
|
977
|
+
}
|
|
978
|
+
else if (opts.clearContext) {
|
|
979
|
+
body.context = null;
|
|
980
|
+
}
|
|
981
|
+
if (opts.script !== undefined && opts.clearScript) {
|
|
982
|
+
throw new Error("Pass --script-file or --clear-script, not both.");
|
|
983
|
+
}
|
|
984
|
+
if (opts.script !== undefined) {
|
|
985
|
+
if (!opts.script.trim())
|
|
986
|
+
throw new Error("The --script-file is empty.");
|
|
987
|
+
body.script = opts.script;
|
|
988
|
+
}
|
|
989
|
+
else if (opts.clearScript) {
|
|
990
|
+
body.script = null;
|
|
991
|
+
}
|
|
992
|
+
if (Object.keys(body).length === 0) {
|
|
993
|
+
throw new Error("Nothing to change. Pass --prompt, --prompt-file, --name, --cron, --at, --context or --script-file.");
|
|
994
|
+
}
|
|
995
|
+
return body;
|
|
996
|
+
}
|
|
997
|
+
export function formatUpdateResult(result) {
|
|
998
|
+
if (result.changed.length === 0)
|
|
999
|
+
return `${result.job.jobId} already matches; nothing changed.`;
|
|
1000
|
+
return `Updated ${result.job.jobId} (${result.changed.join(", ")}). Applies from the next run.`;
|
|
1001
|
+
}
|
|
912
1002
|
/**
|
|
913
1003
|
* Map a jobs-control HTTP error to a single operator-facing line. Pure so the
|
|
914
1004
|
* status/code → copy mapping is unit-tested without a process exit.
|
|
@@ -943,8 +1033,14 @@ export function formatJobsHttpError(err, jobId, action) {
|
|
|
943
1033
|
const id = jobId ?? extractQuotedJobId(err.message) ?? "unknown";
|
|
944
1034
|
return `Job '${id}' not found.`;
|
|
945
1035
|
}
|
|
1036
|
+
if (action === "update" && err.status === 404) {
|
|
1037
|
+
return "Agent not found or not accessible, or this HQ server cannot edit jobs yet.";
|
|
1038
|
+
}
|
|
946
1039
|
if (err.status === 404)
|
|
947
1040
|
return "Agent not found or not accessible.";
|
|
1041
|
+
if (err.code === "JOB_EDIT_BOX_CRON" || err.code === "JOB_EDIT_CONFLICT") {
|
|
1042
|
+
return err.message;
|
|
1043
|
+
}
|
|
948
1044
|
if (err.code === "JOBS_SCHEDULER_UNAVAILABLE" ||
|
|
949
1045
|
err.code === "SCHEDULE_DELETE_FAILED") {
|
|
950
1046
|
return `${err.code}: ${err.message}`;
|
|
@@ -2090,7 +2186,7 @@ export function registerAgentsCommand(program) {
|
|
|
2090
2186
|
// this file; keyed HQ_API_KEY rewrites /v1/agents → /v1/keys/agents.
|
|
2091
2187
|
const jobs = agents
|
|
2092
2188
|
.command("jobs")
|
|
2093
|
-
.description("List, pause, resume, or
|
|
2189
|
+
.description("List, edit, pause, resume, or delete an agent's scheduled jobs");
|
|
2094
2190
|
jobs
|
|
2095
2191
|
.command("list <agentUid>")
|
|
2096
2192
|
.description("List an agent's scheduled jobs")
|
|
@@ -2142,9 +2238,65 @@ export function registerAgentsCommand(program) {
|
|
|
2142
2238
|
failJobs(err, jobId, "resume");
|
|
2143
2239
|
}
|
|
2144
2240
|
});
|
|
2241
|
+
jobs
|
|
2242
|
+
.command("update <agentUid> <jobId>")
|
|
2243
|
+
.alias("edit")
|
|
2244
|
+
.description("Edit a job in place (instructions, schedule, name). Only the options you pass change; the job keeps its id and status, and the change applies from the next run.")
|
|
2245
|
+
.option("--company <slug>", "Company slug (to resolve an agent by name/slug)")
|
|
2246
|
+
.option("--prompt <text>", "New instructions")
|
|
2247
|
+
.option("--prompt-file <path>", "Read the new instructions from a file")
|
|
2248
|
+
.option("--name <label>", "Short label for the job")
|
|
2249
|
+
.option("--cron <expr>", 'New recurring schedule: "0 9 * * 1-5" or cron(...)/rate(...)')
|
|
2250
|
+
.option("--at <iso8601>", "New one-time run instant")
|
|
2251
|
+
.option("--tz <IANA>", "Timezone for --cron/--at (required with them)")
|
|
2252
|
+
.option("--context <json>", "Replace the JSON context handed to the agent at run time")
|
|
2253
|
+
.option("--clear-context", "Remove the job's context")
|
|
2254
|
+
.option("--script-file <path>", "Replace the precondition script with this file")
|
|
2255
|
+
.option("--clear-script", "Remove the job's precondition script")
|
|
2256
|
+
.option("--json", "Emit raw JSON")
|
|
2257
|
+
.action(async function (agentUid, jobId, opts) {
|
|
2258
|
+
let body;
|
|
2259
|
+
try {
|
|
2260
|
+
if (opts.prompt !== undefined && opts.promptFile !== undefined) {
|
|
2261
|
+
throw new Error("Pass --prompt or --prompt-file, not both.");
|
|
2262
|
+
}
|
|
2263
|
+
const prompt = opts.promptFile !== undefined ? readFileSync(opts.promptFile, "utf8") : opts.prompt;
|
|
2264
|
+
const script = opts.scriptFile !== undefined ? readFileSync(opts.scriptFile, "utf8") : undefined;
|
|
2265
|
+
body = buildJobUpdateBody({
|
|
2266
|
+
...(prompt !== undefined ? { prompt } : {}),
|
|
2267
|
+
...(opts.name !== undefined ? { name: opts.name } : {}),
|
|
2268
|
+
...(opts.cron !== undefined ? { cron: opts.cron } : {}),
|
|
2269
|
+
...(opts.at !== undefined ? { at: opts.at } : {}),
|
|
2270
|
+
...(opts.tz !== undefined ? { tz: opts.tz } : {}),
|
|
2271
|
+
...(opts.context !== undefined ? { context: opts.context } : {}),
|
|
2272
|
+
...(opts.clearContext ? { clearContext: true } : {}),
|
|
2273
|
+
...(script !== undefined ? { script } : {}),
|
|
2274
|
+
...(opts.clearScript ? { clearScript: true } : {}),
|
|
2275
|
+
}, toEventBridgeCron);
|
|
2276
|
+
}
|
|
2277
|
+
catch (err) {
|
|
2278
|
+
console.error(chalk.red(err instanceof Error ? err.message : String(err)));
|
|
2279
|
+
process.exit(1);
|
|
2280
|
+
}
|
|
2281
|
+
const { token, targetUid } = await resolveJobsTargetOrExit(agentUid, companyOf(this));
|
|
2282
|
+
try {
|
|
2283
|
+
const result = await updateAgentJob(token, targetUid, jobId, body);
|
|
2284
|
+
if (opts.json) {
|
|
2285
|
+
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
console.log(chalk.green(formatUpdateResult(result)));
|
|
2289
|
+
if (result.warning)
|
|
2290
|
+
console.error(chalk.yellow(result.warning));
|
|
2291
|
+
}
|
|
2292
|
+
catch (err) {
|
|
2293
|
+
failJobs(err, jobId, "update");
|
|
2294
|
+
}
|
|
2295
|
+
});
|
|
2145
2296
|
jobs
|
|
2146
2297
|
.command("cancel <agentUid> <jobId>")
|
|
2147
|
-
.
|
|
2298
|
+
.alias("delete")
|
|
2299
|
+
.description("Delete a job for good (active or paused) and its schedule")
|
|
2148
2300
|
.option("--company <slug>", "Company slug (to resolve an agent by name/slug)")
|
|
2149
2301
|
.action(async function (agentUid, jobId) {
|
|
2150
2302
|
const { token, targetUid } = await resolveJobsTargetOrExit(agentUid, companyOf(this));
|
|
@@ -20,29 +20,16 @@ import { type LocalJobsApi } from "../lib/bot/local-jobs.js";
|
|
|
20
20
|
import { type BotJobRecord, type CreateJobInput } from "../lib/bot/api.js";
|
|
21
21
|
import { type BotConfig, type BotKind } from "../lib/bot/config.js";
|
|
22
22
|
import { type FleetCronJob, type FleetCronOps } from "../lib/bot/fleet-cron.js";
|
|
23
|
+
import { BotJobsError, toEventBridgeCron } from "../lib/bot/eventbridge-cron.js";
|
|
24
|
+
export { BotJobsError, toEventBridgeCron };
|
|
23
25
|
/** Mirrors hq-pro-agents `MIN_RECURRING_INTERVAL_SECONDS`. */
|
|
24
26
|
export declare const MIN_RECURRING_INTERVAL_SECONDS: number;
|
|
25
27
|
/** Mirrors hq-pro-agents `DEFAULT_MAX_ACTIVE_JOBS_PER_AGENT`. */
|
|
26
28
|
export declare const MAX_ACTIVE_JOBS_PER_AGENT = 25;
|
|
27
29
|
/** Mirrors hq-pro-agents `MAX_PROMPT_BYTES`. */
|
|
28
30
|
export declare const MAX_PROMPT_BYTES: number;
|
|
29
|
-
export declare class BotJobsError extends Error {
|
|
30
|
-
readonly expected: true;
|
|
31
|
-
}
|
|
32
31
|
/** The machine's own IANA zone, so "9am" means 9am where the owner lives. */
|
|
33
32
|
export declare function machineTimezone(): string;
|
|
34
|
-
/**
|
|
35
|
-
* Standard 5-field cron → the six-field `cron(...)` string a job is stored as.
|
|
36
|
-
*
|
|
37
|
-
* The stored form (the six-field cron syntax hosted agent jobs also use, so
|
|
38
|
-
* local and hosted jobs share one format; the function keeps its historical
|
|
39
|
-
* name) has SIX fields (a trailing year), numbers its days of week
|
|
40
|
-
* 1–7 with SUNDAY = 1 (standard cron uses 0–6 with SUNDAY = 0), and refuses
|
|
41
|
-
* `*` in BOTH the day-of-month and day-of-week fields — exactly one must be
|
|
42
|
-
* `?`. An expression that is already `cron(...)` or `rate(...)` is passed
|
|
43
|
-
* through untouched.
|
|
44
|
-
*/
|
|
45
|
-
export declare function toEventBridgeCron(expr: string): string;
|
|
46
33
|
/**
|
|
47
34
|
* The smallest gap a recurring expression can produce, in seconds, or null
|
|
48
35
|
* when it is not a recognised rate()/cron() form. Mirrors hq-pro-agents
|
|
@@ -23,6 +23,8 @@ import { fleetCronOps, fleetOwnerOrigin, fleetScheduleFromLegacy } from "../lib/
|
|
|
23
23
|
import { isQuietJobContext, JOB_RUN_OPTIONS_CONTEXT_KEY } from "../lib/bot/job-run.js";
|
|
24
24
|
import { BOT_JOB_QUIET_OPTION_FLAG, botJobQuietOptionEnabled } from "../lib/bot/job-quiet-flag.js";
|
|
25
25
|
import { runScheduleParse } from "./core-jobs-schedule.js";
|
|
26
|
+
import { BotJobsError, toEventBridgeCron } from "../lib/bot/eventbridge-cron.js";
|
|
27
|
+
export { BotJobsError, toEventBridgeCron };
|
|
26
28
|
// ─── Schedule translation ────────────────────────────────────────────────────
|
|
27
29
|
/** Mirrors hq-pro-agents `MIN_RECURRING_INTERVAL_SECONDS`. */
|
|
28
30
|
export const MIN_RECURRING_INTERVAL_SECONDS = 5 * 60;
|
|
@@ -30,9 +32,6 @@ export const MIN_RECURRING_INTERVAL_SECONDS = 5 * 60;
|
|
|
30
32
|
export const MAX_ACTIVE_JOBS_PER_AGENT = 25;
|
|
31
33
|
/** Mirrors hq-pro-agents `MAX_PROMPT_BYTES`. */
|
|
32
34
|
export const MAX_PROMPT_BYTES = 16 * 1024;
|
|
33
|
-
export class BotJobsError extends Error {
|
|
34
|
-
expected = true;
|
|
35
|
-
}
|
|
36
35
|
function refuse(message) {
|
|
37
36
|
throw new BotJobsError(message);
|
|
38
37
|
}
|
|
@@ -45,97 +44,6 @@ export function machineTimezone() {
|
|
|
45
44
|
return "UTC";
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Standard 5-field cron → the six-field `cron(...)` string a job is stored as.
|
|
50
|
-
*
|
|
51
|
-
* The stored form (the six-field cron syntax hosted agent jobs also use, so
|
|
52
|
-
* local and hosted jobs share one format; the function keeps its historical
|
|
53
|
-
* name) has SIX fields (a trailing year), numbers its days of week
|
|
54
|
-
* 1–7 with SUNDAY = 1 (standard cron uses 0–6 with SUNDAY = 0), and refuses
|
|
55
|
-
* `*` in BOTH the day-of-month and day-of-week fields — exactly one must be
|
|
56
|
-
* `?`. An expression that is already `cron(...)` or `rate(...)` is passed
|
|
57
|
-
* through untouched.
|
|
58
|
-
*/
|
|
59
|
-
export function toEventBridgeCron(expr) {
|
|
60
|
-
const trimmed = expr.trim();
|
|
61
|
-
// An explicit cron(...) / rate(...) is the caller saying "this is already the
|
|
62
|
-
// stored syntax" — passed through untranslated, on purpose.
|
|
63
|
-
if (/^(cron|rate)\s*\(/i.test(trimmed))
|
|
64
|
-
return trimmed;
|
|
65
|
-
const fields = trimmed.split(/\s+/).filter(Boolean);
|
|
66
|
-
if (fields.length === 6) {
|
|
67
|
-
// Six BARE fields are ambiguous: the stored form's sixth field is a
|
|
68
|
-
// trailing year, Quartz's first is leading seconds. Guessing wrong
|
|
69
|
-
// silently moves every run. Make the caller say which they mean.
|
|
70
|
-
refuse(`"${trimmed}" has six fields, and I can't tell whether the last one is a year ` +
|
|
71
|
-
`(minute hour day-of-month month day-of-week year, the form bot jobs are stored in) or the ` +
|
|
72
|
-
`first one is seconds (a Quartz expression) — reading it the wrong way would schedule the job ` +
|
|
73
|
-
`at the wrong time. Pass five fields ("0 9 * * 1-5"), or wrap it yourself as cron(...) if it ` +
|
|
74
|
-
`already ends with a year field.`);
|
|
75
|
-
}
|
|
76
|
-
if (fields.length !== 5) {
|
|
77
|
-
refuse(`"${trimmed}" is not a cron expression. A cron expression has five fields: ` +
|
|
78
|
-
`minute hour day-of-month month day-of-week (for example "0 9 * * 1-5").`);
|
|
79
|
-
}
|
|
80
|
-
const [minute, hour, month] = [fields[0], fields[1], fields[3]];
|
|
81
|
-
let dayOfMonth = fields[2];
|
|
82
|
-
let dayOfWeek = fields[4];
|
|
83
|
-
if (dayOfWeek === "*" || dayOfWeek === "?") {
|
|
84
|
-
dayOfWeek = "?";
|
|
85
|
-
if (dayOfMonth === "?")
|
|
86
|
-
dayOfMonth = "*";
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
dayOfWeek = shiftDayOfWeek(dayOfWeek);
|
|
90
|
-
if (dayOfMonth === "*")
|
|
91
|
-
dayOfMonth = "?";
|
|
92
|
-
}
|
|
93
|
-
return `cron(${minute} ${hour} ${dayOfMonth} ${month} ${dayOfWeek} *)`;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Standard 0–6 (SUN=0, and 7 also SUN) → the stored form's 1–7 (SUN=1).
|
|
97
|
-
*
|
|
98
|
-
* Mapped per TERM, not per digit. Shifting digits individually turned a range
|
|
99
|
-
* that wraps past Sunday — "6-0" (Sat–Sun), "5-1" (Fri–Mon) — into "7-1" /
|
|
100
|
-
* "6-2": reversed or plain wrong, and silently so. Such a range is refused with
|
|
101
|
-
* the list form that does work.
|
|
102
|
-
*/
|
|
103
|
-
function shiftDayOfWeek(field) {
|
|
104
|
-
return field
|
|
105
|
-
.split(",")
|
|
106
|
-
.map((term) => shiftDayOfWeekTerm(term.trim()))
|
|
107
|
-
.join(",");
|
|
108
|
-
}
|
|
109
|
-
function shiftDay(n) {
|
|
110
|
-
return (n % 7) + 1;
|
|
111
|
-
}
|
|
112
|
-
function shiftDayOfWeekTerm(term) {
|
|
113
|
-
const step = term.match(/^(.+)\/(\d+)$/);
|
|
114
|
-
if (step)
|
|
115
|
-
return `${shiftDayOfWeekTerm(step[1])}/${step[2]}`;
|
|
116
|
-
const range = term.match(/^(\d+)-(\d+)$/);
|
|
117
|
-
if (range) {
|
|
118
|
-
const from = shiftDay(Number(range[1]));
|
|
119
|
-
const to = shiftDay(Number(range[2]));
|
|
120
|
-
if (from > to) {
|
|
121
|
-
const days = [];
|
|
122
|
-
for (let d = Number(range[1]);; d = (d + 1) % 7) {
|
|
123
|
-
days.push(d);
|
|
124
|
-
if (d === Number(range[2]) % 7)
|
|
125
|
-
break;
|
|
126
|
-
if (days.length > 7)
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
refuse(`"${term}" is a day-of-week range that wraps past Sunday, which the schedule cannot express. ` +
|
|
130
|
-
`List the days instead, for example "${days.join(",")}".`);
|
|
131
|
-
}
|
|
132
|
-
return `${from}-${to}`;
|
|
133
|
-
}
|
|
134
|
-
if (/^\d+$/.test(term))
|
|
135
|
-
return String(shiftDay(Number(term)));
|
|
136
|
-
// Day NAMES (MON, MON-FRI) mean the same thing in both syntaxes.
|
|
137
|
-
return term;
|
|
138
|
-
}
|
|
139
47
|
/**
|
|
140
48
|
* The smallest gap a recurring expression can produce, in seconds, or null
|
|
141
49
|
* when it is not a recognised rate()/cron() form. Mirrors hq-pro-agents
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { type ClaudeLoginCheck } from "../lib/bot/claude-login.js";
|
|
1
2
|
import { fleetRuntimeReady, type FleetInstallProgress, type FleetInstallProgressListener, type FleetLocalTargetRelease } from "../lib/bot/fleet-local.js";
|
|
2
3
|
import { installedFleetPython } from "../lib/bot/fleet-python.js";
|
|
3
4
|
import { type FleetSignInHereDeps, type FleetSignInProvider } from "../lib/bot/legacy-provider-login.js";
|
|
5
|
+
import type { LegacyProviderLogin } from "../lib/bot/legacy-convert.js";
|
|
4
6
|
export type FleetProgressMode = "text" | "json" | "silent";
|
|
5
7
|
interface ProgressOutput {
|
|
6
8
|
write(text: string): void;
|
|
7
9
|
isTTY: boolean;
|
|
8
10
|
}
|
|
9
|
-
/** The sentence for a phase, for people. */
|
|
10
11
|
export declare function describeFleetInstallPhase(event: FleetInstallProgress): string;
|
|
11
12
|
/**
|
|
12
13
|
* Progress for a terminal (stderr, one line that rewrites itself on a TTY and
|
|
@@ -41,14 +42,54 @@ export declare function runBotRuntimeInstall(opts: {
|
|
|
41
42
|
export declare function runBotRuntimeStatus(opts: {
|
|
42
43
|
json?: boolean;
|
|
43
44
|
}): Promise<void>;
|
|
45
|
+
export type BrainProvider = "claude" | FleetSignInProvider;
|
|
46
|
+
export type BrainLoginSource = "claude-code" | "codex-cli" | "grok-cli" | "fleet-bot";
|
|
47
|
+
export interface BrainSignInStatus {
|
|
48
|
+
provider: BrainProvider;
|
|
49
|
+
signedIn: boolean;
|
|
50
|
+
source: BrainLoginSource | null;
|
|
51
|
+
}
|
|
52
|
+
export interface BrainSignInDeps extends FleetSignInHereDeps {
|
|
53
|
+
target?: () => Promise<FleetLocalTargetRelease>;
|
|
54
|
+
claudeLogin?: () => ClaudeLoginCheck;
|
|
55
|
+
grokSiblings?: () => Promise<LegacyProviderLogin>;
|
|
56
|
+
}
|
|
57
|
+
export declare function parseBrainProvider(value: string): BrainProvider;
|
|
44
58
|
export declare function parseFleetSignInProvider(value: string): FleetSignInProvider;
|
|
59
|
+
export declare function brainSignInStatus(provider: BrainProvider, deps?: BrainSignInDeps): Promise<BrainSignInStatus>;
|
|
45
60
|
export declare function runBotAuthStatus(opts: {
|
|
46
61
|
provider: string;
|
|
47
62
|
json?: boolean;
|
|
48
|
-
}, deps?:
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
|
|
63
|
+
}, deps?: BrainSignInDeps): Promise<(BrainSignInStatus & {
|
|
64
|
+
ok: true;
|
|
65
|
+
}) | {
|
|
66
|
+
ok: false;
|
|
67
|
+
provider: string;
|
|
68
|
+
reason: "unknown-provider";
|
|
69
|
+
}>;
|
|
70
|
+
export interface BrainSignInRun {
|
|
71
|
+
stdout: NodeJS.ReadableStream | null;
|
|
72
|
+
stderr: NodeJS.ReadableStream | null;
|
|
73
|
+
exit: Promise<number | null>;
|
|
74
|
+
kill(signal?: NodeJS.Signals): void;
|
|
75
|
+
}
|
|
76
|
+
export interface BotSignInDeps extends BrainSignInDeps {
|
|
77
|
+
findCli?: (name: string) => string | null;
|
|
78
|
+
run?: (cli: string, args: string[]) => BrainSignInRun;
|
|
79
|
+
emit?: (line: string) => void;
|
|
80
|
+
write?: (text: string) => void;
|
|
81
|
+
onCancel?: (cancel: () => void) => () => void;
|
|
82
|
+
}
|
|
83
|
+
export declare const BRAIN_SIGN_IN_KILL_AFTER_MS = 1500;
|
|
84
|
+
export declare function findCliOnPath(name: string, env?: NodeJS.ProcessEnv): string | null;
|
|
85
|
+
export declare function deviceCodeTracker(emit: (event: Record<string, unknown>) => void): (line: string) => void;
|
|
86
|
+
export declare function runBotSignIn(opts: {
|
|
87
|
+
provider: string;
|
|
88
|
+
json?: boolean;
|
|
89
|
+
browser?: boolean;
|
|
90
|
+
}, deps?: BotSignInDeps): Promise<BrainSignInStatus & {
|
|
91
|
+
ok: boolean;
|
|
92
|
+
reason?: string;
|
|
52
93
|
}>;
|
|
53
94
|
export {};
|
|
54
95
|
//# sourceMappingURL=bot-runtime.d.ts.map
|