spur-board 0.37.0 → 0.38.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/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { F as ERRORS, J as SLACK_BOT_SCOPES, K as configSchema, l as roleCanUseOperation, q as requiredSecretKeys, r as SYSTEMD_SERVICE_SETTINGS, u as OPERATIONS } from "./src-CzmL-_Vf.mjs";
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./config-
|
|
2
|
+
import { a as CliError, c as escapeTerminalControls, i as requestTokenEnrollment, n as fetchTokenStatus, o as errorExitCode, r as requestOperation, s as renderCliError } from "./client-DAWhcbvn.mjs";
|
|
3
|
+
import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, f as tokenInFolder, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./config-D9spr6M_.mjs";
|
|
4
4
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
5
5
|
import { accessSync, chmodSync, closeSync, constants, cpSync, existsSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
6
6
|
import { homedir, hostname, userInfo } from "node:os";
|
|
@@ -2048,12 +2048,15 @@ function registerOptions(command, op) {
|
|
|
2048
2048
|
else if (bare instanceof z.ZodString || bare instanceof z.ZodEnum || bare instanceof z.ZodLiteral) command.option(`${flag} <value>`, description);
|
|
2049
2049
|
else throw new Error(`Unsupported CLI field ${field} in ${op.id}.`);
|
|
2050
2050
|
}
|
|
2051
|
-
for (const mode of op.cli.modes ?? []) if (mode.value === null)
|
|
2052
|
-
|
|
2051
|
+
for (const mode of op.cli.modes ?? []) if (mode.value === null) {
|
|
2052
|
+
const branch = branches(op.input).find((item) => item.shape.mode?.safeParse(mode.mode).success);
|
|
2053
|
+
command.option(mode.flag, (branch?.shape.mode)?.description ?? mode.mode);
|
|
2054
|
+
} else {
|
|
2053
2055
|
const schema = fieldSchema(op, mode.value);
|
|
2054
2056
|
if (!schema) throw new Error(`Catalog mode value ${mode.value} is missing from ${op.id}.`);
|
|
2055
2057
|
const value = schema instanceof z.ZodOptional ? `[${mode.value}]` : `<${mode.value}>`;
|
|
2056
|
-
|
|
2058
|
+
const description = schema.description ?? bareSchema(schema).description ?? mode.value;
|
|
2059
|
+
command.option(`${mode.flag} ${value}`, description);
|
|
2057
2060
|
}
|
|
2058
2061
|
if (op.kind === "mutation") command.option("--key <key>", "Idempotency key for this action.");
|
|
2059
2062
|
command.option("--json", "Print JSON output or a JSON error.");
|
|
@@ -2268,8 +2271,7 @@ function createProgram(options = {}) {
|
|
|
2268
2271
|
const tokenFolder = join(folder, ".spur-board");
|
|
2269
2272
|
const file = join(tokenFolder, "token");
|
|
2270
2273
|
const secret = randomBytes(32).toString("base64url");
|
|
2271
|
-
|
|
2272
|
-
let descriptor;
|
|
2274
|
+
const exclusiveFailure = () => new CliError("config", void 0, void 0, "The token file could not be created exclusively.");
|
|
2273
2275
|
try {
|
|
2274
2276
|
mkdirSync(tokenFolder, {
|
|
2275
2277
|
recursive: true,
|
|
@@ -2277,41 +2279,87 @@ function createProgram(options = {}) {
|
|
|
2277
2279
|
});
|
|
2278
2280
|
const directory = lstatSync(tokenFolder);
|
|
2279
2281
|
if (!directory.isDirectory() || directory.uid !== process.getuid?.() || (directory.mode & 63) !== 0 || realpathSync(tokenFolder) !== tokenFolder) throw new Error("Token directory must be owned by the caller and private.");
|
|
2280
|
-
descriptor = openSync(file, "wx", 384);
|
|
2281
|
-
created = true;
|
|
2282
|
-
writeFileSync(descriptor, `${secret}\n`);
|
|
2283
|
-
closeSync(descriptor);
|
|
2284
|
-
descriptor = void 0;
|
|
2285
|
-
chmodSync(file, 384);
|
|
2286
2282
|
} catch {
|
|
2287
|
-
|
|
2288
|
-
if (created) try {
|
|
2289
|
-
unlinkSync(file);
|
|
2290
|
-
} catch {
|
|
2291
|
-
throw new CliError("config", void 0, void 0, "The new token file could not be secured or removed.");
|
|
2292
|
-
}
|
|
2293
|
-
throw new CliError("config", void 0, void 0, "The token file could not be created exclusively.");
|
|
2283
|
+
throw exclusiveFailure();
|
|
2294
2284
|
}
|
|
2285
|
+
const lock = join(tokenFolder, "token.lock");
|
|
2295
2286
|
try {
|
|
2296
|
-
|
|
2297
|
-
name,
|
|
2298
|
-
folder,
|
|
2299
|
-
host: hostname(),
|
|
2300
|
-
hash: createHash("sha256").update(secret).digest("hex")
|
|
2301
|
-
}, config);
|
|
2302
|
-
io.stdout(`${json || !io.isTTY ? JSON.stringify(result) : formatHuman(result)}\n`);
|
|
2287
|
+
closeSync(openSync(lock, "wx", 384));
|
|
2303
2288
|
} catch (error) {
|
|
2304
|
-
if (error
|
|
2289
|
+
if (error !== null && typeof error === "object" && "code" in error && error.code === "EEXIST") throw new CliError("config", void 0, void 0, `Another \`board token create\` is running for this folder: ${lock} exists. Wait for it to finish, or delete ${lock} if no such run is active, then run again.`);
|
|
2290
|
+
throw exclusiveFailure();
|
|
2291
|
+
}
|
|
2292
|
+
try {
|
|
2293
|
+
const existing = tokenInFolder(folder, () => {});
|
|
2294
|
+
if (existing !== void 0) await replaceStaleToken(file, existing, config);
|
|
2295
|
+
let created = false;
|
|
2296
|
+
let descriptor;
|
|
2305
2297
|
try {
|
|
2306
|
-
|
|
2298
|
+
descriptor = openSync(file, "wx", 384);
|
|
2299
|
+
created = true;
|
|
2300
|
+
writeFileSync(descriptor, `${secret}\n`);
|
|
2301
|
+
closeSync(descriptor);
|
|
2302
|
+
descriptor = void 0;
|
|
2303
|
+
chmodSync(file, 384);
|
|
2307
2304
|
} catch {
|
|
2308
|
-
|
|
2305
|
+
if (descriptor !== void 0) closeSync(descriptor);
|
|
2306
|
+
if (created) try {
|
|
2307
|
+
unlinkSync(file);
|
|
2308
|
+
} catch {
|
|
2309
|
+
throw new CliError("config", void 0, void 0, "The new token file could not be secured or removed.");
|
|
2310
|
+
}
|
|
2311
|
+
throw exclusiveFailure();
|
|
2309
2312
|
}
|
|
2310
|
-
|
|
2313
|
+
try {
|
|
2314
|
+
const result = await requestTokenEnrollment({
|
|
2315
|
+
name,
|
|
2316
|
+
folder,
|
|
2317
|
+
host: hostname(),
|
|
2318
|
+
hash: createHash("sha256").update(secret).digest("hex")
|
|
2319
|
+
}, config);
|
|
2320
|
+
io.stdout(`${json || !io.isTTY ? JSON.stringify(result) : formatHuman(result)}\n`);
|
|
2321
|
+
} catch (error) {
|
|
2322
|
+
if (error instanceof CliError && error.code === "outcome_unknown") throw new CliError("outcome_unknown", void 0, error.requestId, "The request may have reached the daemon. Keep the new token file and check the approval request before retrying.");
|
|
2323
|
+
try {
|
|
2324
|
+
unlinkSync(file);
|
|
2325
|
+
} catch {
|
|
2326
|
+
throw new CliError("config", void 0, void 0, "Registration failed and the new token file could not be removed. Remove it before retrying.");
|
|
2327
|
+
}
|
|
2328
|
+
throw error;
|
|
2329
|
+
}
|
|
2330
|
+
} finally {
|
|
2331
|
+
try {
|
|
2332
|
+
unlinkSync(lock);
|
|
2333
|
+
} catch {}
|
|
2311
2334
|
}
|
|
2312
2335
|
});
|
|
2313
2336
|
return program;
|
|
2314
2337
|
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Deletes a token file the daemon reports as expired or denied; refuses every other state. Only
|
|
2340
|
+
* the hash of the old token is sent.
|
|
2341
|
+
*/
|
|
2342
|
+
async function replaceStaleToken(file, token, config) {
|
|
2343
|
+
const refuse = (hint) => new CliError("config", void 0, void 0, hint);
|
|
2344
|
+
const { status } = await fetchTokenStatus(createHash("sha256").update(token).digest("hex"), config).catch((error) => {
|
|
2345
|
+
if (error instanceof CliError && error.code === "not_found") throw refuse(`The daemon cannot report the state of ${file}: it is older than this CLI. Ask the operator to run \`board service restart\`, then run again.`);
|
|
2346
|
+
throw error;
|
|
2347
|
+
});
|
|
2348
|
+
switch (status) {
|
|
2349
|
+
case "expired":
|
|
2350
|
+
case "denied":
|
|
2351
|
+
try {
|
|
2352
|
+
unlinkSync(file);
|
|
2353
|
+
} catch {
|
|
2354
|
+
throw refuse(`Delete ${file} by hand, then run again.`);
|
|
2355
|
+
}
|
|
2356
|
+
return;
|
|
2357
|
+
case "approved": throw refuse(`${file} holds an approved token. Use it from this folder, or ask the operator to revoke it with \`board token revoke\`, then delete the file and run again; or choose another --into folder.`);
|
|
2358
|
+
case "pending": throw refuse(`${file} holds a token request still awaiting approval. Ask the operator to approve or deny it, or wait until it expires, then run again; or choose another --into folder.`);
|
|
2359
|
+
case "revoked": throw refuse(`${file} holds a revoked token. Delete the file, then run again with another --name.`);
|
|
2360
|
+
case "unknown": throw refuse(`This daemon does not know the token in ${file}; it may belong to another board. Check BOARD_DAEMON_URL (or http.port in config.yaml) first; if it names this board, delete the file and run again.`);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2315
2363
|
async function runCli(argv, options = {}) {
|
|
2316
2364
|
const io = options.io ?? processIo;
|
|
2317
2365
|
try {
|
|
@@ -211,5 +211,24 @@ function requestTokenEnrollment(input, config) {
|
|
|
211
211
|
decode: (response, raw) => decodeResponse(enrollmentOutput, response, raw)
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
|
+
const tokenStatusOutput = z.strictObject({ status: z.enum([
|
|
215
|
+
"pending",
|
|
216
|
+
"approved",
|
|
217
|
+
"denied",
|
|
218
|
+
"expired",
|
|
219
|
+
"revoked",
|
|
220
|
+
"unknown"
|
|
221
|
+
]) });
|
|
222
|
+
/** The daemon's state for a token hash; sends no authorization header. */
|
|
223
|
+
function fetchTokenStatus(hash, config) {
|
|
224
|
+
return send({
|
|
225
|
+
method: "POST",
|
|
226
|
+
path: "/v1/tokens/status",
|
|
227
|
+
body: { hash },
|
|
228
|
+
config,
|
|
229
|
+
anonymous: true,
|
|
230
|
+
decode: (response, raw) => decodeResponse(tokenStatusOutput, response, raw)
|
|
231
|
+
});
|
|
232
|
+
}
|
|
214
233
|
//#endregion
|
|
215
|
-
export {
|
|
234
|
+
export { CliError as a, escapeTerminalControls as c, requestTokenEnrollment as i, fetchTokenStatus as n, errorExitCode as o, requestOperation as r, renderCliError as s, fetchCatalogVersion as t };
|
package/dist/client.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
export { fetchCatalogVersion, requestOperation, requestTokenEnrollment };
|
|
1
|
+
import { i as requestTokenEnrollment, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./client-DAWhcbvn.mjs";
|
|
2
|
+
export { fetchCatalogVersion, fetchTokenStatus, requestOperation, requestTokenEnrollment };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { K as configSchema, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-CzmL-_Vf.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { a as CliError, t as fetchCatalogVersion } from "./client-DAWhcbvn.mjs";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { homedir } from "node:os";
|
|
@@ -60,6 +60,7 @@ function resolveDaemonAddress(env = process.env, home = homedir(), configuredPor
|
|
|
60
60
|
if (!["http:", "https:"].includes(address.protocol) || address.username || address.password) throw new CliError("config", { environmentVariable: "BOARD_DAEMON_URL" });
|
|
61
61
|
return address;
|
|
62
62
|
}
|
|
63
|
+
/** The token under `<folder>/.spur-board`; undefined when absent, unsafe or empty. */
|
|
63
64
|
function tokenInFolder(folder, warn) {
|
|
64
65
|
const directory = join(folder, ".spur-board");
|
|
65
66
|
const file = join(directory, "token");
|
|
@@ -261,4 +262,4 @@ function fileVerdictCache(path, cliVersion) {
|
|
|
261
262
|
} };
|
|
262
263
|
}
|
|
263
264
|
//#endregion
|
|
264
|
-
export { memoryVerdictCache as a, loadClientConfig as c, resolveDaemonAddress as d, fileVerdictCache as i, loadEnrollmentConfig as l, cliPackageVersion as n, configFile as o, compareCatalogs as r, dataDirectory as s, checkCatalog as t, readConfiguredPort as u };
|
|
265
|
+
export { memoryVerdictCache as a, loadClientConfig as c, resolveDaemonAddress as d, tokenInFolder as f, fileVerdictCache as i, loadEnrollmentConfig as l, cliPackageVersion as n, configFile as o, compareCatalogs as r, dataDirectory as s, checkCatalog as t, readConfiguredPort as u };
|
package/dist/daemon.mjs
CHANGED
|
@@ -8041,17 +8041,36 @@ function fingerprint$1(id, input, actor) {
|
|
|
8041
8041
|
actor
|
|
8042
8042
|
])).digest("hex");
|
|
8043
8043
|
}
|
|
8044
|
+
function storedCommand(db, actor, key) {
|
|
8045
|
+
return db.selectFrom("command").select([
|
|
8046
|
+
"operation",
|
|
8047
|
+
"fingerprint",
|
|
8048
|
+
"result"
|
|
8049
|
+
]).where("actor", "=", actor).where("key", "=", key).executeTakeFirst();
|
|
8050
|
+
}
|
|
8051
|
+
/**
|
|
8052
|
+
* In-flight same-key calls per store. Keyed by the store, not the `createApply` closure:
|
|
8053
|
+
* `dispatchOperation` builds a new `createApply` for every request.
|
|
8054
|
+
*/
|
|
8055
|
+
const IN_FLIGHT = /* @__PURE__ */ new WeakMap();
|
|
8056
|
+
/** Runs `fn` after any in-flight call on `slot` settles, so one key never runs twice at once. */
|
|
8057
|
+
async function serialized(inFlight, slot, fn) {
|
|
8058
|
+
for (let busy = inFlight.get(slot); busy !== void 0; busy = inFlight.get(slot)) await busy.catch(() => void 0);
|
|
8059
|
+
const call = fn();
|
|
8060
|
+
inFlight.set(slot, call);
|
|
8061
|
+
try {
|
|
8062
|
+
return await call;
|
|
8063
|
+
} finally {
|
|
8064
|
+
if (inFlight.get(slot) === call) inFlight.delete(slot);
|
|
8065
|
+
}
|
|
8066
|
+
}
|
|
8044
8067
|
/**
|
|
8045
8068
|
* Replays one operation within the caller's transaction. Returning undefined from run leaves
|
|
8046
8069
|
* no command row; catalog authorization uses that path so a denial remains journal-only.
|
|
8047
8070
|
*/
|
|
8048
8071
|
async function replayOperation(trx, input) {
|
|
8049
8072
|
const hash = fingerprint$1(input.operation, input.fingerprintInput, input.actor);
|
|
8050
|
-
const row = await trx.
|
|
8051
|
-
"operation",
|
|
8052
|
-
"fingerprint",
|
|
8053
|
-
"result"
|
|
8054
|
-
]).where("actor", "=", input.actor).where("key", "=", input.key).executeTakeFirst();
|
|
8073
|
+
const row = await storedCommand(trx, input.actor, input.key);
|
|
8055
8074
|
if (row !== void 0) {
|
|
8056
8075
|
if (row.operation !== input.operation || row.fingerprint !== hash) throw new CommandError("idempotency_key_mismatch", "Use the original input or a new key.");
|
|
8057
8076
|
return parseJson(input.output, row.result);
|
|
@@ -8082,12 +8101,25 @@ function emptyAllowed(entry) {
|
|
|
8082
8101
|
/** Parse, replay, authorize, then apply one catalog mutation in one transaction. */
|
|
8083
8102
|
function createApply(deps) {
|
|
8084
8103
|
const { store, clock, config } = deps;
|
|
8085
|
-
|
|
8104
|
+
const inFlight = IN_FLIGHT.get(store) ?? /* @__PURE__ */ new Map();
|
|
8105
|
+
IN_FLIGHT.set(store, inFlight);
|
|
8106
|
+
const apply = async (op, input, actor, key) => {
|
|
8086
8107
|
const entry = catalogMutation(op.id);
|
|
8087
8108
|
const parsed = entry.input.safeParse(input);
|
|
8088
8109
|
if (!parsed.success) throw new CommandError(errorCodeOf(parsed.error), "Fix the operation input.");
|
|
8089
8110
|
if (key === "" || actor !== "operator" && key === void 0) throw new CommandError("usage", "Choose an idempotency key before sending an agent mutation.");
|
|
8090
8111
|
const commandKey = key ?? randomUUID();
|
|
8112
|
+
const parsedInput = parsed.data;
|
|
8113
|
+
const mode = "mode" in parsed.data ? parsed.data.mode : void 0;
|
|
8114
|
+
let prepared;
|
|
8115
|
+
if (op.prepare !== void 0 && await storedCommand(store.db, actor, commandKey) === void 0) {
|
|
8116
|
+
const targets = await op.resolveTargets(store.db, parsedInput, actor);
|
|
8117
|
+
if (targets.length > 0 && targets.every((target) => authorize(entry.grants, actor, {
|
|
8118
|
+
config,
|
|
8119
|
+
target,
|
|
8120
|
+
...mode === void 0 ? {} : { mode }
|
|
8121
|
+
}).status === "allowed")) prepared = await op.prepare(store.db, parsedInput, actor);
|
|
8122
|
+
}
|
|
8091
8123
|
let deniedHint;
|
|
8092
8124
|
const at = new Date(clock.now()).toISOString();
|
|
8093
8125
|
const result = await scanTransaction(store, config, (trx) => replayOperation(trx, {
|
|
@@ -8098,13 +8130,11 @@ function createApply(deps) {
|
|
|
8098
8130
|
output: entry.output,
|
|
8099
8131
|
at,
|
|
8100
8132
|
run: async () => {
|
|
8101
|
-
const parsedInput = parsed.data;
|
|
8102
8133
|
const resolved = await op.resolveTargets(trx, parsedInput, actor);
|
|
8103
8134
|
const taskless = resolved.length === 0 && emptyAllowed(entry);
|
|
8104
8135
|
const ackIds = entry.id === "inbox.ack" && "entries" in parsed.data ? parsed.data.entries.map((item) => item.id) : void 0;
|
|
8105
8136
|
const ackMismatch = ackIds !== void 0 && (resolved.length !== ackIds.length || resolved.some((target, index) => target.id !== ackIds[index]));
|
|
8106
8137
|
const targets = resolved.length === 0 ? [{ kind: "missing" }] : ackMismatch ? [...resolved, { kind: "missing" }] : resolved;
|
|
8107
|
-
const mode = "mode" in parsed.data ? parsed.data.mode : void 0;
|
|
8108
8138
|
for (const target of targets) {
|
|
8109
8139
|
const decision = authorize(entry.grants, actor, {
|
|
8110
8140
|
config,
|
|
@@ -8125,15 +8155,20 @@ function createApply(deps) {
|
|
|
8125
8155
|
}
|
|
8126
8156
|
}
|
|
8127
8157
|
if (!taskless && targets.some((target) => target.kind === "missing")) throw new CommandError("not_found", "Check the target ID.");
|
|
8128
|
-
return op.run(trx, parsedInput, {
|
|
8158
|
+
return op.run(trx, parsedInput, op.prepare === void 0 ? {
|
|
8129
8159
|
actor,
|
|
8130
8160
|
at
|
|
8161
|
+
} : {
|
|
8162
|
+
actor,
|
|
8163
|
+
at,
|
|
8164
|
+
prepared
|
|
8131
8165
|
});
|
|
8132
8166
|
}
|
|
8133
8167
|
}));
|
|
8134
8168
|
if (result === void 0) throw new CommandError("forbidden", deniedHint ?? "Caller is not allowed.");
|
|
8135
8169
|
return result;
|
|
8136
8170
|
};
|
|
8171
|
+
return (op, input, actor, key) => op.prepare === void 0 || key === void 0 ? apply(op, input, actor, key) : serialized(inFlight, `${actor}\0${key}`, () => apply(op, input, actor, key));
|
|
8137
8172
|
}
|
|
8138
8173
|
/** Deletes command keys older than `retentionDays`; a key exactly at the cutoff stays. */
|
|
8139
8174
|
async function purgeExpiredCommands(store, clock, retentionDays) {
|
|
@@ -9065,6 +9100,11 @@ async function verifyOperatorToken(store, token) {
|
|
|
9065
9100
|
const row = await store.db.selectFrom("operator_token").select(["name", "status"]).where("hash", "=", hash).executeTakeFirst();
|
|
9066
9101
|
return row?.status === "approved" ? { name: row.name } : null;
|
|
9067
9102
|
}
|
|
9103
|
+
/** Read-only: an expired pending row is reported as expired but left for the sweep. */
|
|
9104
|
+
async function tokenStatusByHash(store, hash, at) {
|
|
9105
|
+
const row = await store.db.selectFrom("operator_token").selectAll().where("hash", "=", hash).executeTakeFirst();
|
|
9106
|
+
return row === void 0 ? "unknown" : effectiveStatus(row, at);
|
|
9107
|
+
}
|
|
9068
9108
|
function tokenListQuery(clock) {
|
|
9069
9109
|
return {
|
|
9070
9110
|
id: "token.list",
|
|
@@ -9164,12 +9204,14 @@ const doctorReportSchema = z.strictObject({
|
|
|
9164
9204
|
fix: z.string().max(300).nullable()
|
|
9165
9205
|
})).max(30)
|
|
9166
9206
|
});
|
|
9207
|
+
const tokenHash = z.string().regex(/^[0-9a-f]{64}$/);
|
|
9167
9208
|
const tokenRequestSchema = z.strictObject({
|
|
9168
9209
|
name: z.string().min(1),
|
|
9169
9210
|
folder: z.string().min(1),
|
|
9170
9211
|
host: z.string().min(1),
|
|
9171
|
-
hash:
|
|
9212
|
+
hash: tokenHash
|
|
9172
9213
|
});
|
|
9214
|
+
const tokenStatusSchema = z.strictObject({ hash: tokenHash });
|
|
9173
9215
|
function header(value) {
|
|
9174
9216
|
return Array.isArray(value) ? void 0 : value;
|
|
9175
9217
|
}
|
|
@@ -9228,6 +9270,10 @@ async function createApiServer(options) {
|
|
|
9228
9270
|
if (error.statusCode === 400 || error.statusCode === 413) code = "usage";
|
|
9229
9271
|
if (error.statusCode === 413) hint = "Send a smaller JSON body.";
|
|
9230
9272
|
}
|
|
9273
|
+
if (code === "unexpected") options.logError?.({
|
|
9274
|
+
requestId: request.id,
|
|
9275
|
+
err: error
|
|
9276
|
+
});
|
|
9231
9277
|
const problem = renderHttpProblem({
|
|
9232
9278
|
code,
|
|
9233
9279
|
requestId: request.id
|
|
@@ -9277,6 +9323,18 @@ async function createApiServer(options) {
|
|
|
9277
9323
|
value: result
|
|
9278
9324
|
}));
|
|
9279
9325
|
});
|
|
9326
|
+
/** The hash travels in the body because request logs record the URL. */
|
|
9327
|
+
app.post("/v1/tokens/status", async (request, reply) => {
|
|
9328
|
+
if (!options.ready()) throw new CommandError("starting", "Wait until the daemon is ready.");
|
|
9329
|
+
const parsed = tokenStatusSchema.safeParse(request.body);
|
|
9330
|
+
if (!parsed.success) throw new CommandError("usage", "Provide a SHA-256 token hash.");
|
|
9331
|
+
const status = await tokenStatusByHash(options.store, parsed.data.hash, new Date(options.clock.now()));
|
|
9332
|
+
return reply.send(successEnvelopeSchema.parse({
|
|
9333
|
+
ok: true,
|
|
9334
|
+
requestId: request.id,
|
|
9335
|
+
value: { status }
|
|
9336
|
+
}));
|
|
9337
|
+
});
|
|
9280
9338
|
app.post("/v1/ops/:id", { onRequest: async (request) => {
|
|
9281
9339
|
if (!options.ready()) throw new CommandError("starting", "Wait until the daemon is ready.");
|
|
9282
9340
|
const sessionHeader = request.headers["x-board-session"];
|
|
@@ -9969,7 +10027,7 @@ function rule(fn) {
|
|
|
9969
10027
|
async function taskByKey$1(trx, key) {
|
|
9970
10028
|
return trx.selectFrom("task").selectAll().where("key", "=", key).executeTakeFirst();
|
|
9971
10029
|
}
|
|
9972
|
-
async function taskById(trx, id) {
|
|
10030
|
+
async function taskById$1(trx, id) {
|
|
9973
10031
|
return trx.selectFrom("task").selectAll().where("id", "=", id).executeTakeFirstOrThrow();
|
|
9974
10032
|
}
|
|
9975
10033
|
async function blockById(trx, id) {
|
|
@@ -10014,7 +10072,7 @@ async function taskTarget(trx, key) {
|
|
|
10014
10072
|
}
|
|
10015
10073
|
async function blockTarget(trx, id) {
|
|
10016
10074
|
const block = await blockById(trx, id);
|
|
10017
|
-
return [await authorizationTarget(trx, block === void 0 ? void 0 : await taskById(trx, block.task_id), block)];
|
|
10075
|
+
return [await authorizationTarget(trx, block === void 0 ? void 0 : await taskById$1(trx, block.task_id), block)];
|
|
10018
10076
|
}
|
|
10019
10077
|
async function turnTarget(trx, id) {
|
|
10020
10078
|
const turn = await trx.selectFrom("turn").select("task_id").where("id", "=", idNumber(id)).executeTakeFirst();
|
|
@@ -10023,18 +10081,18 @@ async function turnTarget(trx, id) {
|
|
|
10023
10081
|
id
|
|
10024
10082
|
};
|
|
10025
10083
|
return {
|
|
10026
|
-
...await authorizationTarget(trx, await taskById(trx, turn.task_id)),
|
|
10084
|
+
...await authorizationTarget(trx, await taskById$1(trx, turn.task_id)),
|
|
10027
10085
|
id
|
|
10028
10086
|
};
|
|
10029
10087
|
}
|
|
10030
10088
|
async function commentTarget(trx, id) {
|
|
10031
10089
|
const comment = await commentById(trx, id);
|
|
10032
10090
|
return {
|
|
10033
|
-
...await authorizationTarget(trx, comment === void 0 ? void 0 : await taskById(trx, comment.task_id)),
|
|
10091
|
+
...await authorizationTarget(trx, comment === void 0 ? void 0 : await taskById$1(trx, comment.task_id)),
|
|
10034
10092
|
id
|
|
10035
10093
|
};
|
|
10036
10094
|
}
|
|
10037
|
-
function current(block) {
|
|
10095
|
+
function current$1(block) {
|
|
10038
10096
|
return {
|
|
10039
10097
|
type: block.type,
|
|
10040
10098
|
state: block.state,
|
|
@@ -10196,7 +10254,7 @@ async function closeOpenBlock(trx, task, block, ctx, outcome, outcomeReason) {
|
|
|
10196
10254
|
/** Applies an operator message to the block selected by its conversation, without echoing it. */
|
|
10197
10255
|
async function recordInboundBlockMessage(trx, input) {
|
|
10198
10256
|
const block = await trx.selectFrom("block").selectAll().where("id", "=", input.blockId).executeTakeFirstOrThrow();
|
|
10199
|
-
const task = await taskById(trx, block.task_id);
|
|
10257
|
+
const task = await taskById$1(trx, block.task_id);
|
|
10200
10258
|
const ctx = {
|
|
10201
10259
|
actor: "operator",
|
|
10202
10260
|
at: input.at
|
|
@@ -10205,7 +10263,7 @@ async function recordInboundBlockMessage(trx, input) {
|
|
|
10205
10263
|
if (answered) {
|
|
10206
10264
|
active(task);
|
|
10207
10265
|
rule(() => {
|
|
10208
|
-
answerBlock(current(block));
|
|
10266
|
+
answerBlock(current$1(block));
|
|
10209
10267
|
});
|
|
10210
10268
|
}
|
|
10211
10269
|
return {
|
|
@@ -10221,7 +10279,7 @@ async function recordInboundBlockMessage(trx, input) {
|
|
|
10221
10279
|
}
|
|
10222
10280
|
/** Uses the same revision and acknowledgment rule as the catalog comment.edit mutation. */
|
|
10223
10281
|
async function editInboundComment(trx, input) {
|
|
10224
|
-
const task = await taskById(trx, input.comment.task_id);
|
|
10282
|
+
const task = await taskById$1(trx, input.comment.task_id);
|
|
10225
10283
|
active(task);
|
|
10226
10284
|
if (input.comment.author !== input.actor) throw new CommandError("forbidden", "Only the comment author can edit it.");
|
|
10227
10285
|
const next = editComment(input.comment.revision, input.comment.acked_revision);
|
|
@@ -10303,7 +10361,7 @@ function createBlockMutations(config) {
|
|
|
10303
10361
|
async resolveTargets(trx, input, actor) {
|
|
10304
10362
|
const block = await blockById(trx, input.block);
|
|
10305
10363
|
if (block === void 0) return blockTarget(trx, input.block);
|
|
10306
|
-
const task = await taskById(trx, block.task_id);
|
|
10364
|
+
const task = await taskById$1(trx, block.task_id);
|
|
10307
10365
|
const target = await authorizationTarget(trx, task, block);
|
|
10308
10366
|
if (target.kind !== "found" || target.value.block === null) return [target];
|
|
10309
10367
|
if (holdsBlock(config, actor, target)) return [target];
|
|
@@ -10325,10 +10383,10 @@ function createBlockMutations(config) {
|
|
|
10325
10383
|
},
|
|
10326
10384
|
async run(trx, input, ctx) {
|
|
10327
10385
|
const block = found(await blockById(trx, input.block));
|
|
10328
|
-
const task = await taskById(trx, block.task_id);
|
|
10386
|
+
const task = await taskById$1(trx, block.task_id);
|
|
10329
10387
|
active(task);
|
|
10330
10388
|
const hasCurator = curatorProject(config, task.project) !== null;
|
|
10331
|
-
const next = rule(() => escalateBlock(current(block), hasCurator));
|
|
10389
|
+
const next = rule(() => escalateBlock(current$1(block), hasCurator));
|
|
10332
10390
|
const unchanged = async () => {
|
|
10333
10391
|
if (input.note !== void 0) await addComment(trx, task, block, input.note, ctx, block.addressee_role, config, { ringsAuthor: false });
|
|
10334
10392
|
return { block: blockView(block, task) };
|
|
@@ -10352,10 +10410,10 @@ function createBlockMutations(config) {
|
|
|
10352
10410
|
resolveTargets: (trx, input) => blockTarget(trx, input.block),
|
|
10353
10411
|
async run(trx, input, ctx) {
|
|
10354
10412
|
const block = found(await blockById(trx, input.block));
|
|
10355
|
-
const task = await taskById(trx, block.task_id);
|
|
10413
|
+
const task = await taskById$1(trx, block.task_id);
|
|
10356
10414
|
active(task);
|
|
10357
10415
|
rule(() => {
|
|
10358
|
-
answerBlock(current(block));
|
|
10416
|
+
answerBlock(current$1(block));
|
|
10359
10417
|
});
|
|
10360
10418
|
const comment = await addComment(trx, task, block, input.text, ctx, authorRole(config, task, block.author), config);
|
|
10361
10419
|
const updated = await closeOpenBlock(trx, task, block, ctx, "done", null);
|
|
@@ -10371,16 +10429,16 @@ function createBlockMutations(config) {
|
|
|
10371
10429
|
resolveTargets: (trx, input) => blockTarget(trx, input.block),
|
|
10372
10430
|
async run(trx, input, ctx) {
|
|
10373
10431
|
const block = found(await blockById(trx, input.block));
|
|
10374
|
-
const task = await taskById(trx, block.task_id);
|
|
10432
|
+
const task = await taskById$1(trx, block.task_id);
|
|
10375
10433
|
active(task);
|
|
10376
10434
|
const target = await authorizationTarget(trx, task, block);
|
|
10377
|
-
const decision = rule(() => input.mode === "done" ? closeBlock(current(block), {
|
|
10435
|
+
const decision = rule(() => input.mode === "done" ? closeBlock(current$1(block), {
|
|
10378
10436
|
mode: "done",
|
|
10379
10437
|
...input.ref === void 0 ? {} : { ref: input.ref }
|
|
10380
|
-
}) : input.mode === "reason" ? closeBlock(current(block), {
|
|
10438
|
+
}) : input.mode === "reason" ? closeBlock(current$1(block), {
|
|
10381
10439
|
mode: "reason",
|
|
10382
10440
|
reason: input.reason
|
|
10383
|
-
}) : closeBlock(current(block), {
|
|
10441
|
+
}) : closeBlock(current$1(block), {
|
|
10384
10442
|
mode: "withdraw",
|
|
10385
10443
|
isAuthor: wroteBlock(config, ctx.actor, target),
|
|
10386
10444
|
reason: input.answer
|
|
@@ -10423,7 +10481,7 @@ function createBlockMutations(config) {
|
|
|
10423
10481
|
at: ctx.at,
|
|
10424
10482
|
actor: ctx.actor,
|
|
10425
10483
|
config
|
|
10426
|
-
}), await taskById(trx, comment.task_id)) };
|
|
10484
|
+
}), await taskById$1(trx, comment.task_id)) };
|
|
10427
10485
|
}
|
|
10428
10486
|
},
|
|
10429
10487
|
ack: {
|
|
@@ -10463,7 +10521,7 @@ function createBlockMutations(config) {
|
|
|
10463
10521
|
continue;
|
|
10464
10522
|
}
|
|
10465
10523
|
const comment = found(await commentById(trx, entry.id));
|
|
10466
|
-
const task = await taskById(trx, comment.task_id);
|
|
10524
|
+
const task = await taskById$1(trx, comment.task_id);
|
|
10467
10525
|
const revision = rule(() => acknowledgeComment(comment.revision, entry.revision));
|
|
10468
10526
|
await acknowledgeNotification(trx, {
|
|
10469
10527
|
commentId: comment.id,
|
|
@@ -12010,17 +12068,187 @@ function createTaskQueries(config) {
|
|
|
12010
12068
|
};
|
|
12011
12069
|
}
|
|
12012
12070
|
//#endregion
|
|
12013
|
-
//#region ../core/src/app/
|
|
12014
|
-
|
|
12015
|
-
|
|
12016
|
-
|
|
12017
|
-
|
|
12071
|
+
//#region ../core/src/app/turn-commands.ts
|
|
12072
|
+
/** How long `task.submit` waits for its on-demand PR poll; the CLI gives up at 30 s. */
|
|
12073
|
+
const SUBMIT_POLL_TIMEOUT_MS = 1e4;
|
|
12074
|
+
/** Columns a task returns to Dev from: right of Dev, before the terminal Done. */
|
|
12075
|
+
const RETURNABLE = [
|
|
12076
|
+
"review",
|
|
12077
|
+
"product-review",
|
|
12078
|
+
"external-review",
|
|
12079
|
+
"qa",
|
|
12080
|
+
"ready-to-merge"
|
|
12081
|
+
];
|
|
12082
|
+
const turnNumber = (id) => Number(id.slice(1));
|
|
12083
|
+
const turnLabel = (id) => `T${String(id)}`;
|
|
12084
|
+
async function turnById(db, id) {
|
|
12085
|
+
return db.selectFrom("turn").selectAll().where("id", "=", turnNumber(id)).executeTakeFirst();
|
|
12086
|
+
}
|
|
12087
|
+
async function taskById(db, id) {
|
|
12088
|
+
return db.selectFrom("task").selectAll().where("id", "=", id).executeTakeFirstOrThrow();
|
|
12089
|
+
}
|
|
12090
|
+
/** Authorizes against the turn's own column, so a late call on an old turn is `turn_closed`. */
|
|
12091
|
+
async function turnVisitTarget(db, id) {
|
|
12092
|
+
const turn = await turnById(db, id);
|
|
12093
|
+
if (turn === void 0) return [{
|
|
12094
|
+
kind: "missing",
|
|
12095
|
+
id
|
|
12096
|
+
}];
|
|
12097
|
+
return [{
|
|
12098
|
+
...await authorizationTarget(db, {
|
|
12099
|
+
...await taskById(db, turn.task_id),
|
|
12100
|
+
column: turn.column
|
|
12101
|
+
}),
|
|
12102
|
+
id
|
|
12103
|
+
}];
|
|
12104
|
+
}
|
|
12105
|
+
/** The task's PR: the open active unbanned link, else the newest active unbanned one. */
|
|
12106
|
+
async function taskPr(db, taskId) {
|
|
12107
|
+
const link = await db.selectFrom("link").select(["repo", "number"]).where("task_id", "=", taskId).where("entity", "=", "pr").where("pr_state", "=", "active").where("banned", "=", 0).where("repo", "is not", null).where("number", "is not", null).orderBy("pr_open", "desc").orderBy("id", "desc").executeTakeFirst();
|
|
12108
|
+
return link?.repo == null || link.number === null ? null : {
|
|
12109
|
+
repo: link.repo,
|
|
12110
|
+
number: link.number
|
|
12111
|
+
};
|
|
12112
|
+
}
|
|
12113
|
+
/** True when the turn is the current visit's, still unclosed. */
|
|
12114
|
+
function current(turn, task) {
|
|
12115
|
+
return turn.closed_at === null && turn.column === task.column && turn.epoch === task.column_epoch;
|
|
12116
|
+
}
|
|
12117
|
+
/** The refusals both operations share, in order: archived, closed, not the taker. */
|
|
12118
|
+
async function takenTurn(trx, id, ctx) {
|
|
12119
|
+
const turn = await turnById(trx, id);
|
|
12120
|
+
if (turn === void 0) throw new CommandError("not_found", "Check the turn ID.");
|
|
12121
|
+
const task = await taskById(trx, turn.task_id);
|
|
12122
|
+
if (task.membership === "archived") throw new CommandError("task_archived", "Add the task again before changing it.");
|
|
12123
|
+
if (!current(turn, task)) throw new CommandError("turn_closed", `Turn ${id} is closed; read your open turns with \`board inbox\`.`);
|
|
12124
|
+
if (turn.acked_by === null || turn.acked_by !== ctx.actor) throw new CommandError("not_turn_taker", turn.acked_by === null ? `Take turn ${id} with \`board inbox ack ${id}\` first.` : `Turn ${id} was taken by another session; only that session can submit or return it.`);
|
|
12018
12125
|
return {
|
|
12019
|
-
|
|
12020
|
-
|
|
12021
|
-
|
|
12126
|
+
turn,
|
|
12127
|
+
task
|
|
12128
|
+
};
|
|
12129
|
+
}
|
|
12130
|
+
function pollErrorHint(error, pr) {
|
|
12131
|
+
switch (error.kind) {
|
|
12132
|
+
case "timeout": return `GitHub did not answer for ${pr} within ${String(SUBMIT_POLL_TIMEOUT_MS / 1e3)} s; wait, then submit again.`;
|
|
12133
|
+
case "blind": return `The board cannot read ${pr} (${error.reason}); ask the operator to fix the GitHub access, then submit again.`;
|
|
12134
|
+
case "failed": return error.retryAt === void 0 ? `The GitHub poll of ${pr} failed (${error.adapterKind}); wait, then submit again.` : `GitHub is throttled until ${error.retryAt}; submit again after that.`;
|
|
12135
|
+
case "stopped": return "The GitHub poller is not running; submit again once the daemon is up.";
|
|
12136
|
+
case "unknown_source": return `The repo of ${pr} is not in the project's repos; ask the operator to add it to the config.`;
|
|
12137
|
+
case "unsupported": return "This daemon cannot poll a pull request on demand; ask the operator to update the daemon.";
|
|
12138
|
+
}
|
|
12139
|
+
}
|
|
12140
|
+
/** Throws `github_unavailable` unless `prepared` is a successful poll of this PR. */
|
|
12141
|
+
function confirmPolled(prepared, pr) {
|
|
12142
|
+
const label = `${pr.repo}#${String(pr.number)}`;
|
|
12143
|
+
const unavailable = (hint) => new CommandError("github_unavailable", hint);
|
|
12144
|
+
if (prepared?.kind !== "polled" || prepared.repo !== pr.repo.toLowerCase() || prepared.number !== pr.number) throw unavailable(`The board did not poll ${label} for this call; submit again.`);
|
|
12145
|
+
const { result } = prepared;
|
|
12146
|
+
if (result === null) throw unavailable("This daemon runs no GitHub poller; ask the operator to check the daemon.");
|
|
12147
|
+
if (!result.ok) throw unavailable(pollErrorHint(result.error, label));
|
|
12148
|
+
if (result.value.status !== "ok") throw unavailable(`GitHub answered ${result.value.status} for ${label}; ask the operator to check the board's GitHub access.`);
|
|
12149
|
+
}
|
|
12150
|
+
/** Moves the task back to Dev as a new visit and closes its turn. */
|
|
12151
|
+
async function moveTaskLeft(trx, task, turn, block, ctx) {
|
|
12152
|
+
const moved = await trx.updateTable("task").set({
|
|
12153
|
+
column: "dev",
|
|
12154
|
+
column_epoch: task.column_epoch + 1,
|
|
12155
|
+
left_moves: task.left_moves + 1,
|
|
12156
|
+
last_change_at: ctx.at
|
|
12157
|
+
}).where("id", "=", task.id).returningAll().executeTakeFirstOrThrow();
|
|
12158
|
+
await closeTurns(trx, {
|
|
12159
|
+
taskId: task.id,
|
|
12160
|
+
reason: "moved",
|
|
12161
|
+
at: new Date(ctx.at)
|
|
12162
|
+
});
|
|
12163
|
+
await emit(trx, "task_moved", task.project, task.id, ctx.at, {
|
|
12164
|
+
from: task.column,
|
|
12165
|
+
to: "dev",
|
|
12166
|
+
turn: turnLabel(turn.id),
|
|
12167
|
+
block: `B${String(block.id)}`
|
|
12168
|
+
}, ctx.actor);
|
|
12169
|
+
return moved;
|
|
12170
|
+
}
|
|
12171
|
+
/** The executor's submit and return of a turn it took. */
|
|
12172
|
+
function createTurnMutations(deps) {
|
|
12173
|
+
const { config, prPoller } = deps;
|
|
12174
|
+
return {
|
|
12175
|
+
submit: {
|
|
12176
|
+
id: "task.submit",
|
|
12177
|
+
resolveTargets: (trx, input) => turnVisitTarget(trx, input.turn),
|
|
12178
|
+
async prepare(db, input, actor) {
|
|
12179
|
+
const turn = await turnById(db, input.turn);
|
|
12180
|
+
if (turn?.acked_by !== actor) return { kind: "skipped" };
|
|
12181
|
+
const task = await taskById(db, turn.task_id);
|
|
12182
|
+
if (task.membership === "archived" || !current(turn, task)) return { kind: "skipped" };
|
|
12183
|
+
const pr = await taskPr(db, task.id);
|
|
12184
|
+
if (pr === null) return { kind: "skipped" };
|
|
12185
|
+
const repo = pr.repo.toLowerCase();
|
|
12186
|
+
const poll = prPoller?.();
|
|
12187
|
+
const result = poll === void 0 ? null : await poll(`github:${task.project}:${repo}`, {
|
|
12188
|
+
kind: "pr",
|
|
12189
|
+
repo: pr.repo,
|
|
12190
|
+
number: pr.number
|
|
12191
|
+
}, { timeoutMs: SUBMIT_POLL_TIMEOUT_MS });
|
|
12192
|
+
return {
|
|
12193
|
+
kind: "polled",
|
|
12194
|
+
repo,
|
|
12195
|
+
number: pr.number,
|
|
12196
|
+
result
|
|
12197
|
+
};
|
|
12198
|
+
},
|
|
12199
|
+
async run(trx, input, ctx) {
|
|
12200
|
+
const { turn, task } = await takenTurn(trx, input.turn, ctx);
|
|
12201
|
+
const pr = await taskPr(trx, task.id);
|
|
12202
|
+
if (pr === null) throw new CommandError("head_mismatch", "The task has no active pull request; ask the operator to link it with `board link`, then submit its head.");
|
|
12203
|
+
confirmPolled(ctx.prepared, pr);
|
|
12204
|
+
const snapshot = await trx.selectFrom("pr_snapshot").select("head_sha").where(sql`lower(repo) = ${pr.repo.toLowerCase()}`).where("number", "=", pr.number).executeTakeFirst();
|
|
12205
|
+
if (snapshot?.head_sha.toLowerCase() !== input.sha) throw new CommandError("head_mismatch", `The head of ${pr.repo}#${String(pr.number)} is ${snapshot?.head_sha ?? "unknown"}; push the commit, then submit the head.`);
|
|
12206
|
+
await trx.insertInto("submission").values({
|
|
12207
|
+
task_id: task.id,
|
|
12208
|
+
column: turn.column,
|
|
12209
|
+
epoch: turn.epoch,
|
|
12210
|
+
commit_sha: input.sha,
|
|
12211
|
+
author: ctx.actor,
|
|
12212
|
+
submitted_at: ctx.at,
|
|
12213
|
+
note: null
|
|
12214
|
+
}).execute();
|
|
12215
|
+
await closeTurns(trx, {
|
|
12216
|
+
taskId: task.id,
|
|
12217
|
+
reason: "submitted",
|
|
12218
|
+
at: new Date(ctx.at)
|
|
12219
|
+
});
|
|
12220
|
+
await emit(trx, "task_submitted", task.project, task.id, ctx.at, {
|
|
12221
|
+
turn: input.turn,
|
|
12222
|
+
column: turn.column,
|
|
12223
|
+
sha: input.sha
|
|
12224
|
+
}, ctx.actor);
|
|
12225
|
+
return {
|
|
12226
|
+
task: taskView(task),
|
|
12227
|
+
turn: input.turn,
|
|
12228
|
+
sha: input.sha
|
|
12229
|
+
};
|
|
12230
|
+
}
|
|
12231
|
+
},
|
|
12232
|
+
return: {
|
|
12233
|
+
id: "task.return",
|
|
12234
|
+
resolveTargets: (trx, input) => turnVisitTarget(trx, input.turn),
|
|
12235
|
+
async run(trx, input, ctx) {
|
|
12236
|
+
const { turn, task } = await takenTurn(trx, input.turn, ctx);
|
|
12237
|
+
if (!RETURNABLE.includes(task.column)) throw new CommandError("return_not_allowed", `The task is in ${task.column}; only a task right of Dev returns to Dev.`);
|
|
12238
|
+
const block = await openBlock(trx, task, "code", input.reason, ctx, config);
|
|
12239
|
+
await queueBlockOpen(trx, task, block, ctx, config);
|
|
12240
|
+
const moved = await moveTaskLeft(trx, task, turn, block, ctx);
|
|
12241
|
+
return {
|
|
12242
|
+
task: taskView(moved),
|
|
12243
|
+
block: blockView(block, moved)
|
|
12244
|
+
};
|
|
12245
|
+
}
|
|
12246
|
+
}
|
|
12022
12247
|
};
|
|
12023
12248
|
}
|
|
12249
|
+
//#endregion
|
|
12250
|
+
//#region ../core/src/app/registry.ts
|
|
12251
|
+
const catalog = await buildCatalogSnapshot(OPERATIONS);
|
|
12024
12252
|
/** Concrete handlers shared by the daemon's HTTP and inbound transports. */
|
|
12025
12253
|
function createOperationRegistry(deps) {
|
|
12026
12254
|
const { config, clock, completeSince, gateways } = deps;
|
|
@@ -12029,6 +12257,10 @@ function createOperationRegistry(deps) {
|
|
|
12029
12257
|
const links = createLinkMutations(config);
|
|
12030
12258
|
const blocks = createBlockMutations(config);
|
|
12031
12259
|
const taskQueries = createTaskQueries(config);
|
|
12260
|
+
const turns = createTurnMutations({
|
|
12261
|
+
config,
|
|
12262
|
+
prPoller: deps.prPoller
|
|
12263
|
+
});
|
|
12032
12264
|
return {
|
|
12033
12265
|
"schema.get": {
|
|
12034
12266
|
id: "schema.get",
|
|
@@ -12103,8 +12335,8 @@ function createOperationRegistry(deps) {
|
|
|
12103
12335
|
"inbox.ack": blocks.ack,
|
|
12104
12336
|
"item.retry": items.retry,
|
|
12105
12337
|
"item.close": items.close,
|
|
12106
|
-
"task.submit":
|
|
12107
|
-
"task.return":
|
|
12338
|
+
"task.submit": turns.submit,
|
|
12339
|
+
"task.return": turns.return
|
|
12108
12340
|
};
|
|
12109
12341
|
}
|
|
12110
12342
|
//#endregion
|
|
@@ -17537,9 +17769,9 @@ function createSocket(api, config, botIdentity) {
|
|
|
17537
17769
|
let stopping = false;
|
|
17538
17770
|
let connected = false;
|
|
17539
17771
|
const pending = /* @__PURE__ */ new Set();
|
|
17540
|
-
function track(work) {
|
|
17772
|
+
function track(work, kind) {
|
|
17541
17773
|
pending.add(work);
|
|
17542
|
-
work.finally(() => pending.delete(work)).catch(() => {});
|
|
17774
|
+
work.catch((err) => config.onError?.(err, kind)).finally(() => pending.delete(work)).catch(() => {});
|
|
17543
17775
|
}
|
|
17544
17776
|
function emit(event) {
|
|
17545
17777
|
if (sink === void 0) return Promise.resolve();
|
|
@@ -17607,7 +17839,7 @@ function createSocket(api, config, botIdentity) {
|
|
|
17607
17839
|
kind: "connection",
|
|
17608
17840
|
state: "up",
|
|
17609
17841
|
dedupeKey: `slack:connection:${randomUUID()}`
|
|
17610
|
-
}));
|
|
17842
|
+
}), "connection");
|
|
17611
17843
|
});
|
|
17612
17844
|
client.on("close", () => {
|
|
17613
17845
|
if (!connected || stopping) return;
|
|
@@ -17616,10 +17848,10 @@ function createSocket(api, config, botIdentity) {
|
|
|
17616
17848
|
kind: "connection",
|
|
17617
17849
|
state: "down",
|
|
17618
17850
|
dedupeKey: `slack:connection:${randomUUID()}`
|
|
17619
|
-
}));
|
|
17851
|
+
}), "connection");
|
|
17620
17852
|
});
|
|
17621
17853
|
client.on("slack_event", (envelope) => {
|
|
17622
|
-
track(handle(envelope));
|
|
17854
|
+
track(handle(envelope), "envelope");
|
|
17623
17855
|
});
|
|
17624
17856
|
try {
|
|
17625
17857
|
await client.start();
|
|
@@ -17751,6 +17983,8 @@ function createJob(options) {
|
|
|
17751
17983
|
/**
|
|
17752
17984
|
* Compose the board's timer and adapter runner without adding lifecycle state to main. `tick`
|
|
17753
17985
|
* runs the board-core job once more behind its active run and resolves when that run settles.
|
|
17986
|
+
* `pollPr` forwards to the running runner: `stopped` before its start and after its stop,
|
|
17987
|
+
* `unsupported` for a runner without on-demand polls.
|
|
17754
17988
|
*/
|
|
17755
17989
|
function createBoardModules(ctxFor, options = {}) {
|
|
17756
17990
|
const coreCtx = ctxFor("board-core");
|
|
@@ -17777,46 +18011,61 @@ function createBoardModules(ctxFor, options = {}) {
|
|
|
17777
18011
|
}
|
|
17778
18012
|
});
|
|
17779
18013
|
let runner;
|
|
17780
|
-
|
|
17781
|
-
|
|
17782
|
-
|
|
17783
|
-
|
|
17784
|
-
|
|
17785
|
-
|
|
17786
|
-
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
|
|
17790
|
-
|
|
17791
|
-
|
|
17792
|
-
|
|
17793
|
-
|
|
17794
|
-
warn
|
|
17795
|
-
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
|
|
17800
|
-
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
17804
|
-
|
|
17805
|
-
|
|
17806
|
-
|
|
17807
|
-
|
|
17808
|
-
|
|
17809
|
-
|
|
17810
|
-
|
|
17811
|
-
|
|
17812
|
-
|
|
17813
|
-
|
|
17814
|
-
|
|
17815
|
-
|
|
17816
|
-
|
|
18014
|
+
const entries = [{
|
|
18015
|
+
name: "board-core",
|
|
18016
|
+
stopStage: "final",
|
|
18017
|
+
module: boardCore
|
|
18018
|
+
}, {
|
|
18019
|
+
name: "board-adapters",
|
|
18020
|
+
stopStage: "pollers",
|
|
18021
|
+
module: {
|
|
18022
|
+
async start(startSignal) {
|
|
18023
|
+
const adapterOptions = {
|
|
18024
|
+
secrets: adapterCtx.secrets,
|
|
18025
|
+
now: () => adapterCtx.clock.now(),
|
|
18026
|
+
fetch: (url, init) => adapterCtx.logCall("adapter.fetch", () => fetch(url, init)),
|
|
18027
|
+
warn: (message) => {
|
|
18028
|
+
adapterCtx.log.warn({ message }, "adapter warning");
|
|
18029
|
+
},
|
|
18030
|
+
onPollFailure: ({ source, step, kind, error, issues }) => {
|
|
18031
|
+
adapterCtx.log.warn({
|
|
18032
|
+
source,
|
|
18033
|
+
step,
|
|
18034
|
+
kind,
|
|
18035
|
+
err: error,
|
|
18036
|
+
...issues === void 0 ? {} : { issues }
|
|
18037
|
+
}, "adapter poll failed");
|
|
18038
|
+
},
|
|
18039
|
+
onSpurNotice: async (notice) => {
|
|
18040
|
+
if (notice.kind === "restart") adapterCtx.log.info("spur restarted");
|
|
18041
|
+
else await core.notice(notice.kind, notice.value);
|
|
18042
|
+
}
|
|
18043
|
+
};
|
|
18044
|
+
runner = (options.startAdapters ?? startAdapters)(adapterCtx.config, core, adapterOptions);
|
|
18045
|
+
if (startSignal.aborted) await runner.stop();
|
|
18046
|
+
},
|
|
18047
|
+
async stop() {
|
|
18048
|
+
const current = runner;
|
|
18049
|
+
runner = void 0;
|
|
18050
|
+
await current?.stop();
|
|
17817
18051
|
}
|
|
17818
|
-
}
|
|
17819
|
-
|
|
18052
|
+
}
|
|
18053
|
+
}];
|
|
18054
|
+
const pollPr = (source, ref, pollOptions) => {
|
|
18055
|
+
if (runner === void 0) return Promise.resolve(err({
|
|
18056
|
+
kind: "stopped",
|
|
18057
|
+
message: "The adapter runner is not running."
|
|
18058
|
+
}));
|
|
18059
|
+
if (runner.pollPr === void 0) return Promise.resolve(err({
|
|
18060
|
+
kind: "unsupported",
|
|
18061
|
+
message: "The adapter runner polls no PR on demand."
|
|
18062
|
+
}));
|
|
18063
|
+
return runner.pollPr(source, ref, pollOptions);
|
|
18064
|
+
};
|
|
18065
|
+
return {
|
|
18066
|
+
entries,
|
|
18067
|
+
tick: () => boardCore.trigger(),
|
|
18068
|
+
pollPr
|
|
17820
18069
|
};
|
|
17821
18070
|
}
|
|
17822
18071
|
//#endregion
|
|
@@ -18273,6 +18522,12 @@ function createHttpModule(ctx, options = {}) {
|
|
|
18273
18522
|
status,
|
|
18274
18523
|
...tokenName === void 0 ? {} : { tokenName }
|
|
18275
18524
|
}, "http request");
|
|
18525
|
+
},
|
|
18526
|
+
logError: ({ requestId, err }) => {
|
|
18527
|
+
ctx.log.error({
|
|
18528
|
+
err,
|
|
18529
|
+
requestId
|
|
18530
|
+
}, "http request failed");
|
|
18276
18531
|
}
|
|
18277
18532
|
});
|
|
18278
18533
|
try {
|
|
@@ -18550,14 +18805,18 @@ function createDaemonModules(ctxFor, ports = {}) {
|
|
|
18550
18805
|
const settings = slackSettings(ctx.config, ctx.secrets);
|
|
18551
18806
|
const gateway = ports.gateway ?? (settings === null ? void 0 : createSlackGateway({
|
|
18552
18807
|
...settings,
|
|
18553
|
-
now: () => ctx.clock.now()
|
|
18808
|
+
now: () => ctx.clock.now(),
|
|
18809
|
+
onError: (err, work) => {
|
|
18810
|
+
ctx.log.error({ err }, work === "connection" ? "slack connection event failed" : "slack envelope failed");
|
|
18811
|
+
}
|
|
18554
18812
|
}));
|
|
18555
18813
|
const registry = createOperationRegistry({
|
|
18556
18814
|
config: board.config,
|
|
18557
18815
|
clock: board.clock,
|
|
18558
18816
|
completeSince: core.completeSince,
|
|
18559
18817
|
gateways: gateway === void 0 ? [] : [gateway.kind],
|
|
18560
|
-
reapplyInbound: () => inbound?.reapply
|
|
18818
|
+
reapplyInbound: () => inbound?.reapply,
|
|
18819
|
+
prPoller: () => boardModules.pollPr
|
|
18561
18820
|
});
|
|
18562
18821
|
const notifier = createSystemdNotifier({
|
|
18563
18822
|
log: ctxFor("systemd").log,
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { F as ERRORS, m as renderMcpError, u as OPERATIONS } from "./src-CzmL-_Vf.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-
|
|
2
|
+
import { a as CliError, r as requestOperation } from "./client-DAWhcbvn.mjs";
|
|
3
|
+
import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-D9spr6M_.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { z } from "zod";
|