@factiii/runner 0.13.1 → 0.14.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.js
CHANGED
|
@@ -3712,8 +3712,8 @@ var require_common = __commonJS({
|
|
|
3712
3712
|
}
|
|
3713
3713
|
return debug12;
|
|
3714
3714
|
}
|
|
3715
|
-
function extend(namespace,
|
|
3716
|
-
const newDebug = createDebug(this.namespace + (typeof
|
|
3715
|
+
function extend(namespace, delimiter2) {
|
|
3716
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter2 === "undefined" ? ":" : delimiter2) + namespace);
|
|
3717
3717
|
newDebug.log = this.log;
|
|
3718
3718
|
return newDebug;
|
|
3719
3719
|
}
|
|
@@ -14612,7 +14612,8 @@ var tiktokPostOptionsSchema = external_exports.object({
|
|
|
14612
14612
|
});
|
|
14613
14613
|
var crossPostSubmitSchema = external_exports.object({
|
|
14614
14614
|
postId: external_exports.string(),
|
|
14615
|
-
platforms: external_exports.array(crossPostPlatformEnum).min(1).max(5)
|
|
14615
|
+
platforms: external_exports.array(crossPostPlatformEnum).min(1).max(5),
|
|
14616
|
+
scheduledFor: external_exports.coerce.date().optional()
|
|
14616
14617
|
});
|
|
14617
14618
|
var apiCostUpdateSchema = external_exports.object({
|
|
14618
14619
|
platform: crossPostPlatformEnum,
|
|
@@ -14953,6 +14954,7 @@ async function checkDeployStatus(opts) {
|
|
|
14953
14954
|
workspace,
|
|
14954
14955
|
"fetch",
|
|
14955
14956
|
"origin",
|
|
14957
|
+
"--prune",
|
|
14956
14958
|
"+refs/heads/deploy-skill*:refs/remotes/origin/deploy-skill*"
|
|
14957
14959
|
);
|
|
14958
14960
|
const refs = await hostGit(
|
|
@@ -15172,6 +15174,18 @@ async function loadSkillDraft(opts) {
|
|
|
15172
15174
|
}
|
|
15173
15175
|
await checkDeployStatus(opts);
|
|
15174
15176
|
const workspace = import_path6.default.join(opts.spaceDir, "workspace");
|
|
15177
|
+
const onRemote = await hostGit(
|
|
15178
|
+
workspace,
|
|
15179
|
+
"ls-remote",
|
|
15180
|
+
"--heads",
|
|
15181
|
+
"origin",
|
|
15182
|
+
branch
|
|
15183
|
+
).catch(() => "");
|
|
15184
|
+
if (!onRemote.trim()) {
|
|
15185
|
+
throw new Error(
|
|
15186
|
+
`Branch ${branch} is no longer on origin - it was merged or deleted. Draft the deploy skill again.`
|
|
15187
|
+
);
|
|
15188
|
+
}
|
|
15175
15189
|
await hostGit(
|
|
15176
15190
|
workspace,
|
|
15177
15191
|
"fetch",
|
|
@@ -16070,7 +16084,9 @@ EOF
|
|
|
16070
16084
|
# nohup, not setsid: setsid does not exist on macOS.
|
|
16071
16085
|
nohup frpc -c "$TOML" > "${p.runDir}/\${NAME}.log" 2>&1 < /dev/null &
|
|
16072
16086
|
echo $! > "${p.runDir}/\${NAME}.pid"
|
|
16073
|
-
|
|
16087
|
+
# https: the Mini terminates TLS for *.dev.factiii.com on the dockerized nginx
|
|
16088
|
+
# (wildcard cert, DNS-01). :80 still works and frps only speaks HTTP behind it.
|
|
16089
|
+
echo "https://\${DOMAIN}"
|
|
16074
16090
|
`;
|
|
16075
16091
|
}
|
|
16076
16092
|
function frpcUnexposeScript(p) {
|
|
@@ -16221,7 +16237,10 @@ async function listLiveTunnels(target) {
|
|
|
16221
16237
|
` port=$(sed -n 's/^localPort = *//p' "$name.toml" | head -1)`,
|
|
16222
16238
|
` sub=$(sed -n 's/^subdomain = *//p' "$name.toml" | tr -d '"' | head -1)`,
|
|
16223
16239
|
' [ -n "$port" ] && [ -n "$sub" ] || continue',
|
|
16224
|
-
|
|
16240
|
+
// https, matching what factiii-expose prints: the Mini terminates TLS for
|
|
16241
|
+
// *.dev.factiii.com on the dockerized nginx. Showing http:// here made the
|
|
16242
|
+
// Ports panel disagree with the URL the agent had just handed the user.
|
|
16243
|
+
` echo "$name${ROW_SEP}$port${ROW_SEP}https://$sub.$FACTIII_FRP_DOMAIN"`,
|
|
16225
16244
|
"done"
|
|
16226
16245
|
].join("\n");
|
|
16227
16246
|
const out = await target.run(["sh", "-c", script]).catch(() => "");
|
|
@@ -19579,12 +19598,82 @@ async function unsetSecret(configDir, spaceDir, password, key) {
|
|
|
19579
19598
|
const values = await readEnv(spaceDir, identity);
|
|
19580
19599
|
delete values[key];
|
|
19581
19600
|
await writeEnv(configDir, spaceDir, identity, values);
|
|
19601
|
+
await pruneSecretMeta(spaceDir);
|
|
19582
19602
|
return { success: true };
|
|
19583
19603
|
}
|
|
19584
19604
|
async function secretsForInjection(configDir, spaceDir, password) {
|
|
19585
19605
|
const identity = await identityFor(configDir, password);
|
|
19586
19606
|
return readEnv(spaceDir, identity);
|
|
19587
19607
|
}
|
|
19608
|
+
var META_FILE = "secrets.meta.json";
|
|
19609
|
+
function metaPath(spaceDir) {
|
|
19610
|
+
return import_path11.default.join(spaceDir, "secrets", META_FILE);
|
|
19611
|
+
}
|
|
19612
|
+
function normalizeMeta(raw) {
|
|
19613
|
+
const row = raw ?? {};
|
|
19614
|
+
const text = (v) => typeof v === "string" ? v.trim() : "";
|
|
19615
|
+
return {
|
|
19616
|
+
title: text(row.title),
|
|
19617
|
+
description: text(row.description),
|
|
19618
|
+
category: text(row.category),
|
|
19619
|
+
source: text(row.source)
|
|
19620
|
+
};
|
|
19621
|
+
}
|
|
19622
|
+
async function readSecretMeta(spaceDir) {
|
|
19623
|
+
const raw = await import_promises9.default.readFile(metaPath(spaceDir), "utf-8").catch(() => "");
|
|
19624
|
+
if (!raw) return {};
|
|
19625
|
+
let parsed;
|
|
19626
|
+
try {
|
|
19627
|
+
parsed = JSON.parse(raw);
|
|
19628
|
+
} catch {
|
|
19629
|
+
return {};
|
|
19630
|
+
}
|
|
19631
|
+
const keys = parsed.keys;
|
|
19632
|
+
if (!keys || typeof keys !== "object") return {};
|
|
19633
|
+
const out = {};
|
|
19634
|
+
for (const [key, row] of Object.entries(keys)) {
|
|
19635
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) continue;
|
|
19636
|
+
out[key] = normalizeMeta(row);
|
|
19637
|
+
}
|
|
19638
|
+
return out;
|
|
19639
|
+
}
|
|
19640
|
+
async function writeSecretMeta(spaceDir, keys) {
|
|
19641
|
+
const file = metaPath(spaceDir);
|
|
19642
|
+
await import_promises9.default.mkdir(import_path11.default.dirname(file), { recursive: true });
|
|
19643
|
+
const body = { v: 1, keys };
|
|
19644
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
19645
|
+
await import_promises9.default.writeFile(tmp, `${JSON.stringify(body, null, 2)}
|
|
19646
|
+
`, {
|
|
19647
|
+
mode: 384
|
|
19648
|
+
});
|
|
19649
|
+
await import_promises9.default.rename(tmp, file);
|
|
19650
|
+
}
|
|
19651
|
+
async function setSecretMeta(spaceDir, key, patch) {
|
|
19652
|
+
if (!/^[A-Z][A-Z0-9_]*$/i.test(key)) {
|
|
19653
|
+
throw new Error("Key must be an env-style name (letters, digits, _).");
|
|
19654
|
+
}
|
|
19655
|
+
const all = await readSecretMeta(spaceDir);
|
|
19656
|
+
const next = normalizeMeta({ ...all[key] ?? {}, ...patch });
|
|
19657
|
+
if (!next.title && !next.description && !next.source) {
|
|
19658
|
+
delete all[key];
|
|
19659
|
+
} else {
|
|
19660
|
+
all[key] = next;
|
|
19661
|
+
}
|
|
19662
|
+
await writeSecretMeta(spaceDir, all);
|
|
19663
|
+
return { success: true };
|
|
19664
|
+
}
|
|
19665
|
+
async function pruneSecretMeta(spaceDir) {
|
|
19666
|
+
const all = await readSecretMeta(spaceDir);
|
|
19667
|
+
const stored = new Set(await storedSecretKeys(spaceDir));
|
|
19668
|
+
let changed = false;
|
|
19669
|
+
for (const key of Object.keys(all)) {
|
|
19670
|
+
if (!stored.has(key)) {
|
|
19671
|
+
delete all[key];
|
|
19672
|
+
changed = true;
|
|
19673
|
+
}
|
|
19674
|
+
}
|
|
19675
|
+
if (changed) await writeSecretMeta(spaceDir, all);
|
|
19676
|
+
}
|
|
19588
19677
|
|
|
19589
19678
|
// ../../shared/all/helpers/board-agent-core/secrets-run.ts
|
|
19590
19679
|
var COMMAND_IDLE_TIMEOUT_MS = 45 * 6e4;
|
|
@@ -20100,6 +20189,16 @@ var ScratchpadStore = class {
|
|
|
20100
20189
|
var import_promises10 = require("fs/promises");
|
|
20101
20190
|
var import_path14 = __toESM(require("path"));
|
|
20102
20191
|
|
|
20192
|
+
// ../../shared/all/helpers/board-agent-core/secret-descriptions.ts
|
|
20193
|
+
var DEFAULT_SECRET_CATEGORY = "general";
|
|
20194
|
+
function describeSecret(meta, contract) {
|
|
20195
|
+
return {
|
|
20196
|
+
title: meta?.title || contract?.title || "",
|
|
20197
|
+
description: meta?.description || contract?.description || "",
|
|
20198
|
+
category: meta?.category || contract?.category || DEFAULT_SECRET_CATEGORY
|
|
20199
|
+
};
|
|
20200
|
+
}
|
|
20201
|
+
|
|
20103
20202
|
// ../../shared/all/helpers/board-agent-core/toolchain.ts
|
|
20104
20203
|
var TOOLS = [
|
|
20105
20204
|
{ bin: "git" },
|
|
@@ -20390,24 +20489,26 @@ var SpaceCore = class {
|
|
|
20390
20489
|
}
|
|
20391
20490
|
});
|
|
20392
20491
|
}
|
|
20393
|
-
/** Key NAMES and
|
|
20394
|
-
* public on the default branch,
|
|
20395
|
-
*
|
|
20492
|
+
/** Key NAMES, status and purpose, no password. The contract declares its
|
|
20493
|
+
* keys in public on the default branch, sops leaves names in cleartext, and
|
|
20494
|
+
* the meta sidecar holds only descriptions - so this reveals nothing the
|
|
20495
|
+
* repo and the files do not already say. */
|
|
20396
20496
|
async secretsKeyInfo() {
|
|
20397
20497
|
const stored = new Set(await storedSecretKeys(this.spaceDir()));
|
|
20498
|
+
const meta = await readSecretMeta(this.spaceDir());
|
|
20398
20499
|
const config = this.readConfig();
|
|
20399
|
-
const
|
|
20400
|
-
|
|
20401
|
-
|
|
20402
|
-
|
|
20403
|
-
|
|
20404
|
-
|
|
20405
|
-
|
|
20406
|
-
)
|
|
20407
|
-
return [.../* @__PURE__ */ new Set([...declared, ...stored])].sort().map((key) => ({
|
|
20500
|
+
const variables = await (config.repoUrl && config.githubToken ? checkDeployStatus({
|
|
20501
|
+
spaceDir: this.spaceDir(),
|
|
20502
|
+
repoUrl: config.repoUrl,
|
|
20503
|
+
mainBranch: config.mainBranch,
|
|
20504
|
+
githubToken: config.githubToken
|
|
20505
|
+
}).then((status) => status.variables).catch(() => []) : []);
|
|
20506
|
+
const declared = new Map(variables.map((v) => [v.key, v]));
|
|
20507
|
+
return [.../* @__PURE__ */ new Set([...declared.keys(), ...stored])].sort().map((key) => ({
|
|
20408
20508
|
key,
|
|
20409
20509
|
stored: stored.has(key),
|
|
20410
|
-
declared: declared.has(key)
|
|
20510
|
+
declared: declared.has(key),
|
|
20511
|
+
...describeSecret(meta[key], declared.get(key))
|
|
20411
20512
|
}));
|
|
20412
20513
|
}
|
|
20413
20514
|
/**
|
|
@@ -21526,7 +21627,8 @@ var BoardAgentEngine = class _BoardAgentEngine {
|
|
|
21526
21627
|
async deploySecretsList(payload) {
|
|
21527
21628
|
const { configDir, spaceDir } = this.secretsDirs();
|
|
21528
21629
|
return {
|
|
21529
|
-
keys: await listSecretKeys(configDir, spaceDir, payload.password)
|
|
21630
|
+
keys: await listSecretKeys(configDir, spaceDir, payload.password),
|
|
21631
|
+
meta: await readSecretMeta(spaceDir)
|
|
21530
21632
|
};
|
|
21531
21633
|
}
|
|
21532
21634
|
deploySecretsSet(payload) {
|
|
@@ -21539,6 +21641,10 @@ var BoardAgentEngine = class _BoardAgentEngine {
|
|
|
21539
21641
|
payload.value
|
|
21540
21642
|
);
|
|
21541
21643
|
}
|
|
21644
|
+
deploySecretsSetMeta(payload) {
|
|
21645
|
+
const { key, ...patch } = payload;
|
|
21646
|
+
return setSecretMeta(this.secretsDirs().spaceDir, key, patch);
|
|
21647
|
+
}
|
|
21542
21648
|
deploySecretsUnset(payload) {
|
|
21543
21649
|
const { configDir, spaceDir } = this.secretsDirs();
|
|
21544
21650
|
return unsetSecret(configDir, spaceDir, payload.password, payload.key);
|
|
@@ -22443,6 +22549,10 @@ ${c.content.trim() || "(no description)"}`
|
|
|
22443
22549
|
return await this.deploySecretsSet(
|
|
22444
22550
|
payload
|
|
22445
22551
|
);
|
|
22552
|
+
case "deploySecretsSetMeta":
|
|
22553
|
+
return await this.deploySecretsSetMeta(
|
|
22554
|
+
payload
|
|
22555
|
+
);
|
|
22446
22556
|
case "deploySecretsUnset":
|
|
22447
22557
|
return await this.deploySecretsUnset(
|
|
22448
22558
|
payload
|
|
@@ -22756,7 +22866,8 @@ var IndexService = class {
|
|
|
22756
22866
|
PORT: String(port),
|
|
22757
22867
|
CONTROL_TOKEN: this.opts.controlToken,
|
|
22758
22868
|
EMBED_URL: this.opts.embedUrl(),
|
|
22759
|
-
INDEX_DATA_DIR: this.opts.dataDir
|
|
22869
|
+
INDEX_DATA_DIR: this.opts.dataDir,
|
|
22870
|
+
...this.opts.reportToken?.() ? { REPORT_TOKEN: this.opts.reportToken() } : {}
|
|
22760
22871
|
},
|
|
22761
22872
|
stdio: log ? ["ignore", log, log] : "ignore",
|
|
22762
22873
|
// Own process group so stop() reaps it; nothing else reaps orphans here.
|
|
@@ -22814,7 +22925,7 @@ var IndexService = class {
|
|
|
22814
22925
|
// chosen interpreter has to lead PATH or the build targets the wrong ABI.
|
|
22815
22926
|
env: {
|
|
22816
22927
|
...process.env,
|
|
22817
|
-
PATH: `${(0, import_path17.dirname)(nodeBin)}
|
|
22928
|
+
PATH: `${(0, import_path17.dirname)(nodeBin)}${import_path17.delimiter}${process.env.PATH ?? ""}`
|
|
22818
22929
|
}
|
|
22819
22930
|
}
|
|
22820
22931
|
);
|
|
@@ -23907,6 +24018,14 @@ function installLatest() {
|
|
|
23907
24018
|
// src/supervisor.ts
|
|
23908
24019
|
var import_node_child_process2 = require("node:child_process");
|
|
23909
24020
|
|
|
24021
|
+
// ../../shared/all/domains/socket.ts
|
|
24022
|
+
function agentSettledPhase(previous, current) {
|
|
24023
|
+
if (previous !== "working" || current === "working") return null;
|
|
24024
|
+
if (current === "idle") return "terminal-idle";
|
|
24025
|
+
if (current === "blocked") return "terminal-blocked";
|
|
24026
|
+
return null;
|
|
24027
|
+
}
|
|
24028
|
+
|
|
23910
24029
|
// src/daemon.ts
|
|
23911
24030
|
var import_crypto11 = require("crypto");
|
|
23912
24031
|
var import_fs12 = __toESM(require("fs"));
|
|
@@ -27770,14 +27889,23 @@ async function startDaemon(config) {
|
|
|
27770
27889
|
"bare-review"
|
|
27771
27890
|
]);
|
|
27772
27891
|
const lastPhase = /* @__PURE__ */ new Map();
|
|
27892
|
+
const lastAgentState = /* @__PURE__ */ new Map();
|
|
27893
|
+
const settledEndPhase = (postId, s) => {
|
|
27894
|
+
const phase = s.phase ?? "";
|
|
27895
|
+
const previousPhase = lastPhase.get(postId);
|
|
27896
|
+
lastPhase.set(postId, phase);
|
|
27897
|
+
const previousState = lastAgentState.get(postId);
|
|
27898
|
+
lastAgentState.set(postId, s.agentState);
|
|
27899
|
+
if (previousPhase !== void 0 && previousPhase !== phase && END_PHASES.has(phase)) {
|
|
27900
|
+
return phase;
|
|
27901
|
+
}
|
|
27902
|
+
return agentSettledPhase(previousState, s.agentState);
|
|
27903
|
+
};
|
|
27773
27904
|
const reportSettledSession = (spaceSlug, payload) => {
|
|
27774
27905
|
const s = payload;
|
|
27775
27906
|
if (!s || typeof s.postId !== "string") return;
|
|
27776
|
-
const phase = s.
|
|
27777
|
-
|
|
27778
|
-
lastPhase.set(s.postId, phase);
|
|
27779
|
-
if (previous === void 0 || previous === phase) return;
|
|
27780
|
-
if (!END_PHASES.has(phase)) return;
|
|
27907
|
+
const phase = settledEndPhase(s.postId, s);
|
|
27908
|
+
if (!phase) return;
|
|
27781
27909
|
try {
|
|
27782
27910
|
socket.emit("runnerSessionFinished", {
|
|
27783
27911
|
spaceSlug,
|
|
@@ -27826,6 +27954,7 @@ async function startDaemon(config) {
|
|
|
27826
27954
|
const odIndex = new IndexService({
|
|
27827
27955
|
controlToken: (0, import_crypto11.createHash)("sha256").update(config.authToken).digest("hex"),
|
|
27828
27956
|
embedUrl: () => config.serverUrl,
|
|
27957
|
+
reportToken: () => config.authToken,
|
|
27829
27958
|
indexDir,
|
|
27830
27959
|
dataDir: import_path24.default.join(CONFIG_DIR, "index-data")
|
|
27831
27960
|
});
|
package/index/index.js
CHANGED
|
@@ -15849,7 +15849,7 @@ var require_BufferList = __commonJS({
|
|
|
15849
15849
|
this.tail = null;
|
|
15850
15850
|
this.length = 0;
|
|
15851
15851
|
}
|
|
15852
|
-
BufferList.prototype.push = function
|
|
15852
|
+
BufferList.prototype.push = function push3(v) {
|
|
15853
15853
|
var entry = { data: v, next: null };
|
|
15854
15854
|
if (this.length > 0) this.tail.next = entry;
|
|
15855
15855
|
else this.head = entry;
|
|
@@ -90706,12 +90706,12 @@ var readBodyBufferedBeforeDisconnect = (incoming, chunks) => {
|
|
|
90706
90706
|
incomingWithRecovery[bodyBufferedBeforeDisconnectKey] = result2;
|
|
90707
90707
|
return result2;
|
|
90708
90708
|
};
|
|
90709
|
-
var enqueueBufferedBody = (controller,
|
|
90710
|
-
if (
|
|
90711
|
-
controller.error(
|
|
90709
|
+
var enqueueBufferedBody = (controller, buffered2) => {
|
|
90710
|
+
if (buffered2 instanceof Error) {
|
|
90711
|
+
controller.error(buffered2);
|
|
90712
90712
|
return;
|
|
90713
90713
|
}
|
|
90714
|
-
if (
|
|
90714
|
+
if (buffered2.length > 0) controller.enqueue(buffered2);
|
|
90715
90715
|
controller.close();
|
|
90716
90716
|
};
|
|
90717
90717
|
var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
|
|
@@ -90737,9 +90737,9 @@ var newRequestFromIncoming = (method, url, headers, incoming, abortController) =
|
|
|
90737
90737
|
init.body = new ReadableStream({ async pull(controller) {
|
|
90738
90738
|
try {
|
|
90739
90739
|
if (!reader) {
|
|
90740
|
-
const
|
|
90741
|
-
if (
|
|
90742
|
-
enqueueBufferedBody(controller,
|
|
90740
|
+
const buffered2 = readBodyBufferedBeforeDisconnect(incoming);
|
|
90741
|
+
if (buffered2 !== void 0) {
|
|
90742
|
+
enqueueBufferedBody(controller, buffered2);
|
|
90743
90743
|
return;
|
|
90744
90744
|
}
|
|
90745
90745
|
}
|
|
@@ -90752,9 +90752,9 @@ var newRequestFromIncoming = (method, url, headers, incoming, abortController) =
|
|
|
90752
90752
|
}
|
|
90753
90753
|
} });
|
|
90754
90754
|
} else {
|
|
90755
|
-
const
|
|
90756
|
-
if (
|
|
90757
|
-
enqueueBufferedBody(controller,
|
|
90755
|
+
const buffered2 = readBodyBufferedBeforeDisconnect(incoming);
|
|
90756
|
+
if (buffered2 !== void 0) init.body = new ReadableStream({ start(controller) {
|
|
90757
|
+
enqueueBufferedBody(controller, buffered2);
|
|
90758
90758
|
} });
|
|
90759
90759
|
else init.body = import_node_stream.Readable.toWeb(incoming);
|
|
90760
90760
|
}
|
|
@@ -90861,11 +90861,11 @@ var readBodyDirect = (request) => {
|
|
|
90861
90861
|
if (request[bodyReadPromiseKey]) return request[bodyReadPromiseKey];
|
|
90862
90862
|
const incoming = request[incomingKey];
|
|
90863
90863
|
if (incoming.readableDidRead) return rejectBodyUnusable();
|
|
90864
|
-
const
|
|
90865
|
-
if (
|
|
90866
|
-
if (
|
|
90867
|
-
request[bodyBufferKey] =
|
|
90868
|
-
return Promise.resolve(
|
|
90864
|
+
const buffered2 = readBodyBufferedBeforeDisconnect(incoming);
|
|
90865
|
+
if (buffered2 !== void 0) {
|
|
90866
|
+
if (buffered2 instanceof Error) return Promise.reject(buffered2);
|
|
90867
|
+
request[bodyBufferKey] = buffered2;
|
|
90868
|
+
return Promise.resolve(buffered2);
|
|
90869
90869
|
}
|
|
90870
90870
|
const promise = new Promise((resolve, reject2) => {
|
|
90871
90871
|
const chunks = [];
|
|
@@ -93227,6 +93227,93 @@ function listFiles(db2, pathPrefix) {
|
|
|
93227
93227
|
).all(`${pathPrefix}%`);
|
|
93228
93228
|
}
|
|
93229
93229
|
|
|
93230
|
+
// ../../shared/all/helpers/errorRedaction.ts
|
|
93231
|
+
var REDACTED = "[redacted]";
|
|
93232
|
+
var SECRET_PARAMS = /\b(access_token|refresh_token|id_token|client_secret|client_id|code|token|tempauth|api[-_]?key|apikey|password|secret|authorization)=[^&\s"'<>)\]}]+/gi;
|
|
93233
|
+
var SECRET_FIELDS = /(["']?(?:access_?token|refresh_?token|id_?token|client_?secret|api_?key|password|secret|authorization)["']?\s*[:=]\s*)(["'][^"']*["']|[^\s,;}&]+)/gi;
|
|
93234
|
+
var BEARER = /\bBearer\s+[A-Za-z0-9\-._~+/]+=*/gi;
|
|
93235
|
+
var JWT = /\beyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}/g;
|
|
93236
|
+
var EMAIL = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
|
|
93237
|
+
var POSIX_HOME = /\/(Users|home)\/[^/\s"']+/g;
|
|
93238
|
+
var WINDOWS_HOME = /([A-Za-z]:\\Users\\)[^\\\s"']+/g;
|
|
93239
|
+
var DOCUMENT_FILE = /[^\n/\\"'<>:;,|?*]{1,120}\.(docx?|pptx?|xlsx?|pdf|txt|md|csv|rtf|odt|pages|key|numbers|epub|png|jpe?g|gif|webp|heic|tiff?|bmp|svg|mp[34]|m4a|mov|avi|mkv|wav|zip)\b/gi;
|
|
93240
|
+
function redactErrorText(input) {
|
|
93241
|
+
return input.replace(BEARER, `Bearer ${REDACTED}`).replace(JWT, REDACTED).replace(SECRET_PARAMS, (_m2, key) => `${key}=${REDACTED}`).replace(
|
|
93242
|
+
SECRET_FIELDS,
|
|
93243
|
+
(m, prefix, value) => value.includes(REDACTED) || /^(Bearer|Basic)$/i.test(value) ? m : `${prefix}${REDACTED}`
|
|
93244
|
+
).replace(EMAIL, "[email]").replace(POSIX_HOME, (_m2, root2) => `/${root2}/[user]`).replace(WINDOWS_HOME, (_m2, root2) => `${root2}[user]`).replace(
|
|
93245
|
+
DOCUMENT_FILE,
|
|
93246
|
+
(_m2, ext) => `[file].${ext.toLowerCase()}`
|
|
93247
|
+
);
|
|
93248
|
+
}
|
|
93249
|
+
var MAX_REPORT_STACK = 4e3;
|
|
93250
|
+
function redactForReport(input) {
|
|
93251
|
+
const redacted = redactErrorText(input);
|
|
93252
|
+
return redacted.length > MAX_REPORT_STACK ? `${redacted.slice(0, MAX_REPORT_STACK)}\u2026[truncated]` : redacted;
|
|
93253
|
+
}
|
|
93254
|
+
|
|
93255
|
+
// src/reporter.ts
|
|
93256
|
+
var REPORT_TOKEN = process.env.REPORT_TOKEN || "";
|
|
93257
|
+
var REPORT_URL = process.env.EMBED_URL || "";
|
|
93258
|
+
var REPORT_TIMEOUT_MS = 1e4;
|
|
93259
|
+
var MAX_BUFFERED = 100;
|
|
93260
|
+
var MAX_PER_PUSH = 50;
|
|
93261
|
+
var buffered = [];
|
|
93262
|
+
function bufferReport(report) {
|
|
93263
|
+
buffered.push(report);
|
|
93264
|
+
if (buffered.length > MAX_BUFFERED) buffered.splice(0, buffered.length - MAX_BUFFERED);
|
|
93265
|
+
}
|
|
93266
|
+
async function push2(reports) {
|
|
93267
|
+
if (!REPORT_TOKEN || !REPORT_URL || reports.length === 0) return false;
|
|
93268
|
+
try {
|
|
93269
|
+
const res = await fetch(
|
|
93270
|
+
`${REPORT_URL.replace(/\/$/, "")}/trpc/runners.reportError`,
|
|
93271
|
+
{
|
|
93272
|
+
method: "POST",
|
|
93273
|
+
headers: {
|
|
93274
|
+
"content-type": "application/json",
|
|
93275
|
+
// authGuard rejects a request with no user agent outright.
|
|
93276
|
+
"user-agent": "factiii-index",
|
|
93277
|
+
// Same header the board MCP presents; the runner's pairing token.
|
|
93278
|
+
"x-factiii-bot-token": REPORT_TOKEN
|
|
93279
|
+
},
|
|
93280
|
+
// The server's tRPC runs a superjson transformer, so input arrives
|
|
93281
|
+
// under `json`. Every field here is a plain string, so there is no meta
|
|
93282
|
+
// to send and no need to pull superjson into this bundle.
|
|
93283
|
+
body: JSON.stringify({ json: { reports } }),
|
|
93284
|
+
signal: AbortSignal.timeout(REPORT_TIMEOUT_MS)
|
|
93285
|
+
}
|
|
93286
|
+
);
|
|
93287
|
+
return res.ok;
|
|
93288
|
+
} catch {
|
|
93289
|
+
return false;
|
|
93290
|
+
}
|
|
93291
|
+
}
|
|
93292
|
+
async function reportSyncError(summary, detail, severity) {
|
|
93293
|
+
const text2 = detail instanceof Error ? detail.stack ?? detail.message : String(detail);
|
|
93294
|
+
const report = {
|
|
93295
|
+
summary: redactForReport(summary),
|
|
93296
|
+
detail: redactForReport(text2),
|
|
93297
|
+
severity,
|
|
93298
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
93299
|
+
};
|
|
93300
|
+
console.error(`[onedrive] ${report.summary}: ${report.detail}`);
|
|
93301
|
+
const batch = [...buffered.splice(0, MAX_PER_PUSH - 1), report];
|
|
93302
|
+
if (!await push2(batch)) batch.forEach(bufferReport);
|
|
93303
|
+
}
|
|
93304
|
+
async function flushSyncErrors() {
|
|
93305
|
+
let sent = 0;
|
|
93306
|
+
while (buffered.length > 0) {
|
|
93307
|
+
const batch = buffered.splice(0, MAX_PER_PUSH);
|
|
93308
|
+
if (!await push2(batch)) {
|
|
93309
|
+
batch.forEach(bufferReport);
|
|
93310
|
+
break;
|
|
93311
|
+
}
|
|
93312
|
+
sent += batch.length;
|
|
93313
|
+
}
|
|
93314
|
+
return sent;
|
|
93315
|
+
}
|
|
93316
|
+
|
|
93230
93317
|
// src/indexer.ts
|
|
93231
93318
|
function metaFromItem(item, filePath) {
|
|
93232
93319
|
const info = item.fileSystemInfo ?? {};
|
|
@@ -93275,6 +93362,7 @@ async function runIndex(serverUrl, spaceSlug, conn, hooks = {}, full = false) {
|
|
|
93275
93362
|
lastEmbedError = result2.lastEmbedError;
|
|
93276
93363
|
}
|
|
93277
93364
|
}
|
|
93365
|
+
void flushSyncErrors();
|
|
93278
93366
|
hooks.onProgress?.(
|
|
93279
93367
|
anyEmbedFailure && embedded === 0 ? {
|
|
93280
93368
|
status: "error",
|
|
@@ -93288,6 +93376,7 @@ async function runIndex(serverUrl, spaceSlug, conn, hooks = {}, full = false) {
|
|
|
93288
93376
|
done,
|
|
93289
93377
|
error: err instanceof Error ? err.message : String(err)
|
|
93290
93378
|
});
|
|
93379
|
+
await reportSyncError("OneDrive sync pass failed", err, "CRITICAL");
|
|
93291
93380
|
throw err;
|
|
93292
93381
|
} finally {
|
|
93293
93382
|
db2.close();
|
|
@@ -93326,9 +93415,9 @@ async function indexFolder(db2, serverUrl, token, folder, full, hooks) {
|
|
|
93326
93415
|
} catch (err) {
|
|
93327
93416
|
embedFailure = true;
|
|
93328
93417
|
lastEmbedError = err instanceof Error ? err.message : String(err);
|
|
93329
|
-
|
|
93330
|
-
`
|
|
93331
|
-
|
|
93418
|
+
void reportSyncError(
|
|
93419
|
+
`OneDrive embed failed (${fileExt(item.name) || "no ext"})`,
|
|
93420
|
+
err
|
|
93332
93421
|
);
|
|
93333
93422
|
}
|
|
93334
93423
|
} else if (cTagChanged) {
|
|
@@ -93348,9 +93437,10 @@ async function embedFile(db2, serverUrl, token, item) {
|
|
|
93348
93437
|
try {
|
|
93349
93438
|
text2 = await extractText2(item.name, bytes);
|
|
93350
93439
|
} catch (err) {
|
|
93351
|
-
|
|
93352
|
-
`
|
|
93353
|
-
err
|
|
93440
|
+
void reportSyncError(
|
|
93441
|
+
`OneDrive extract failed (${fileExt(item.name) || "no ext"})`,
|
|
93442
|
+
err,
|
|
93443
|
+
"LOW"
|
|
93354
93444
|
);
|
|
93355
93445
|
text2 = null;
|
|
93356
93446
|
}
|
|
@@ -93664,10 +93754,7 @@ var Store = class {
|
|
|
93664
93754
|
});
|
|
93665
93755
|
this.saveSub(spaceSlug, r.id, r.expirationDateTime);
|
|
93666
93756
|
} catch (err) {
|
|
93667
|
-
|
|
93668
|
-
`[onedrive] webhook ensure failed for ${spaceSlug}:`,
|
|
93669
|
-
err instanceof Error ? err.message : err
|
|
93670
|
-
);
|
|
93757
|
+
void reportSyncError(`OneDrive webhook ensure failed (${spaceSlug})`, err);
|
|
93671
93758
|
}
|
|
93672
93759
|
}
|
|
93673
93760
|
saveSub(spaceSlug, id2, expiry) {
|
package/package.json
CHANGED
|
@@ -84,18 +84,30 @@ function parseKeys(argv) {
|
|
|
84
84
|
return { keys, rest: argv.slice(i) };
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* `NAME status title` rows, aligned, each followed by its description
|
|
89
|
+
* indented underneath.
|
|
90
|
+
*
|
|
91
|
+
* The description is the reason to run this at all: a bare name says a
|
|
92
|
+
* credential exists, not which command wants it or what breaks without it.
|
|
93
|
+
* Older runners send no description, so every field here is optional and an
|
|
94
|
+
* undescribed store still prints exactly the rows it used to.
|
|
95
|
+
*/
|
|
88
96
|
function formatKeys(entries) {
|
|
89
97
|
const width = entries.reduce((max, e) => Math.max(max, e.key.length), 0);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
})
|
|
98
|
-
.
|
|
98
|
+
const lines = [];
|
|
99
|
+
for (const entry of entries) {
|
|
100
|
+
const status = [
|
|
101
|
+
entry.stored ? 'set' : 'not set',
|
|
102
|
+
entry.declared ? 'declared' : 'undeclared'
|
|
103
|
+
].join(', ');
|
|
104
|
+
const title = entry.title ? ` ${entry.title}` : '';
|
|
105
|
+
lines.push(`${entry.key.padEnd(width)} ${status}${title}`);
|
|
106
|
+
if (entry.description) {
|
|
107
|
+
lines.push(`${' '.repeat(width + 2)}${entry.description}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return lines.join('\n');
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
/** `<spaceDir>/state/secrets.sock`. The env var is what the runner sets on
|
|
@@ -75,17 +75,25 @@ factiii-secrets list
|
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
prints the key NAMES this workspace has, whether the store actually holds a
|
|
78
|
-
value for each,
|
|
78
|
+
value for each, whether the deploy contract declares it, and what each one is
|
|
79
|
+
FOR:
|
|
79
80
|
|
|
80
81
|
```
|
|
81
|
-
DATABASE_URL set, declared
|
|
82
|
-
|
|
82
|
+
DATABASE_URL set, declared Primary Postgres URL
|
|
83
|
+
The database migrations run against. Points at prod; staging
|
|
84
|
+
has its own.
|
|
85
|
+
EXPO_TOKEN not set, declared Expo access token
|
|
86
|
+
Authenticates the EAS CLI for mobile builds and submits.
|
|
83
87
|
OLD_TOKEN set, undeclared
|
|
84
88
|
```
|
|
85
89
|
|
|
86
|
-
Never their values; there is no command that prints a value, on purpose.
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
Never their values; there is no command that prints a value, on purpose.
|
|
91
|
+
|
|
92
|
+
Read this before guessing. It answers both "what is the key called" - a
|
|
93
|
+
guessed name gets you an empty variable, not the value - and "which key does
|
|
94
|
+
this step actually need", which the name alone often does not say. A key with
|
|
95
|
+
no description is simply one nobody has described yet; ask the owner rather
|
|
96
|
+
than inferring a purpose from the name.
|
|
89
97
|
|
|
90
98
|
## Things that will waste your time
|
|
91
99
|
|
|
@@ -22,6 +22,31 @@ background and lives until the session ends or you stop it.
|
|
|
22
22
|
second one, so it is safe to repeat.
|
|
23
23
|
- Start the server FIRST. A URL for a port nothing is listening on answers
|
|
24
24
|
with an error, which reads to the user like a broken tunnel.
|
|
25
|
+
- The URL is HTTPS. `http://` works too, on a different path through the Mini's
|
|
26
|
+
nginx, so prefer the https one you were given.
|
|
27
|
+
|
|
28
|
+
## Sharing an app, not just a port
|
|
29
|
+
|
|
30
|
+
A web app usually needs two tunnels, and its own config has to name them before
|
|
31
|
+
it is built or booted. A client that still points at `localhost:5001` loads over
|
|
32
|
+
HTTPS and then has every API call blocked as mixed content, which looks like a
|
|
33
|
+
broken deploy rather than a config miss.
|
|
34
|
+
|
|
35
|
+
So: expose both ports first, put those URLs in the app's config (for this repo,
|
|
36
|
+
`NEXT_PUBLIC_SITE_URL` / `NEXT_PUBLIC_API_URL` / `ALLOWED_ORIGINS` in `.env`),
|
|
37
|
+
and only then start the servers. Getting that order wrong costs a restart of
|
|
38
|
+
both.
|
|
39
|
+
|
|
40
|
+
Two more `.env` values matter once the app has logins, and both fail silently:
|
|
41
|
+
|
|
42
|
+
- `COOKIE_DOMAIN` — the two tunnels are different hostnames under one parent, so
|
|
43
|
+
a host-only cookie set on the web host is never sent to the api host. Every
|
|
44
|
+
authenticated call 401s while the UI looks signed in.
|
|
45
|
+
- `NEXT_PUBLIC_COOKIE_PREFIX` — must differ from production's. A preview under
|
|
46
|
+
`*.dev.factiii.com` also receives cookies scoped to `.factiii.com`, so anyone
|
|
47
|
+
logged into the real site sends a same-named cookie that shadows the
|
|
48
|
+
preview's, and signing in simply does not stick. `.env.example` already ships
|
|
49
|
+
a distinct value; keep it distinct.
|
|
25
50
|
|
|
26
51
|
## Stop sharing
|
|
27
52
|
|
|
@@ -36,6 +61,12 @@ whatever that port serves. Do not expose a service that fronts real
|
|
|
36
61
|
credentials, customer data, or a database. If you are unsure whether the user
|
|
37
62
|
wants something reachable from outside, ask first.
|
|
38
63
|
|
|
39
|
-
Always tell the user the URL you got back.
|
|
40
|
-
|
|
64
|
+
Always tell the user the URL you got back.
|
|
65
|
+
|
|
66
|
+
They can also see it themselves, in the card's **Tasks** panel — the button in
|
|
67
|
+
the session header, which lists what the card is running and which ports are
|
|
68
|
+
public. Point them there by that name. **Setup**, the button beside it, is a
|
|
69
|
+
different thing: a fixed log of how the workspace was prepared, which never
|
|
70
|
+
shows running servers. Saying "the task manager" or leaving it unnamed sends
|
|
71
|
+
people to Setup and looks like the tunnel failed.
|
|
41
72
|
|