cursedops 0.10.22 → 0.10.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedops",
3
- "version": "0.10.22",
3
+ "version": "0.10.24",
4
4
  "description": "The build-and-ops answers this generation's apps wrote independently and identically: finding a generation's roots — and printing a command that runs when pasted — without knowing a path, the generation's whole-tree laws run over one repo from a checkout or a worktree, macOS launchd agent install/replace/remove and the live port a job serves, the scaffolding and verdicts of a deployed smoke (origin probe, the smoke's own environment, a network that lies about DNS, a settled version), the static-serving helpers eight apps copied — the path-traversal guard among them — the API floor that keeps an unmatched /api/... from ever being answered with the app shell, the commit and dirty flag a checkout-served process reports, the Cloudflare Worker deploy toolkit four apps copied (the deploy sequence, exact-set secrets over a pipe, origin-first rollback, the curl edge fetch, the row-for-row D1 import proof, the billed-CPU tail check around a deploy's walk and smoke, and each app's worker:secrets and worker:smoke main as one function of its data), the relay a Worker fronts a Mac-bound app with (the Durable Object, the frames, the Mac's dialer and key rotation — lifted from station for roms — and the signed-in stage walk's skeleton and the relay app's whole worker:deploy), the Worker import-graph and await-port checks every Worker app's suite runs over its own source, and the public-surface ratchet three published libraries each carried a forked copy of. Mechanism only — no app knows its name from here. Bun, zero runtime dependencies (typescript is an optional peer, for public-surface only), ships source.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -923,6 +923,46 @@ export function judgeTailCapture(text: string, opts: JudgeOpts): TailVerdict {
923
923
  return { ok: failures.length === 0, failures, report, recorded, traces: traces.length };
924
924
  }
925
925
 
926
+ /** What `wrangler tail --format json` says a request did besides spend CPU. */
927
+ interface TailTraceLike {
928
+ scriptName?: string;
929
+ outcome?: string;
930
+ event?: { request?: { url?: string; method?: string } };
931
+ logs?: Array<{ level?: string; message?: unknown }>;
932
+ exceptions?: Array<{ name?: string; message?: string }>;
933
+ }
934
+
935
+ /**
936
+ * Every `console.*` line, exception and non-`ok` outcome this Worker produced in a capture, one line
937
+ * each, prefixed with the request that produced it. Pure.
938
+ *
939
+ * 🔴 Why it exists (task 2224): vault's stage walk went red with `callback → 302, NO cookie` while
940
+ * this tail was attached, and the consumer's own `console.warn` naming the cause was IN the capture —
941
+ * then thrown away, because only CPU was read out of it. Neither suspected cause reproduced after the
942
+ * fact. A failed command now prints what the Worker said while it failed.
943
+ */
944
+ export function workerTailEvents(traces: readonly unknown[], scriptName: string): string[] {
945
+ const out: string[] = [];
946
+ for (const raw of traces as TailTraceLike[]) {
947
+ if (!raw || raw.scriptName !== scriptName) continue;
948
+ const req = raw.event?.request;
949
+ let where = "(no request)";
950
+ if (req?.url) {
951
+ const url = new URL(req.url);
952
+ // A path, never a query: a grant or a token rides there, and this goes to a log file.
953
+ where = `${req.method ?? "GET"} ${url.pathname}`;
954
+ }
955
+ for (const log of raw.logs ?? []) {
956
+ const parts = Array.isArray(log.message) ? log.message : [log.message];
957
+ const text = parts.map((p) => (typeof p === "string" ? p : JSON.stringify(p))).join(" ");
958
+ out.push(`${where} — ${log.level ?? "log"}: ${text}`);
959
+ }
960
+ for (const ex of raw.exceptions ?? []) out.push(`${where} — exception ${ex.name ?? "Error"}: ${ex.message ?? ""}`);
961
+ if (raw.outcome && raw.outcome !== "ok") out.push(`${where} — outcome ${raw.outcome}`);
962
+ }
963
+ return out;
964
+ }
965
+
926
966
  /** The verdict in words, for the deploy log. */
927
967
  export function formatTailVerdict(verdict: TailVerdict, bench: Pick<TailBench, "formatCpuBudgetReport">, scriptName: string): string {
928
968
  const r = verdict.recorded;
@@ -1134,7 +1174,15 @@ export async function runWorkerCpuTail(spec: WorkerCpuTailSpec, deps: WorkerCpuD
1134
1174
  deps.log(`\n${formatTailVerdict(verdict, spec.bench, spec.workerName)}`);
1135
1175
  if (!drained) deps.error(`🔴 ${tag} the end marker never came back — the capture may be missing the command's last requests.`);
1136
1176
 
1137
- if (ran !== 0) return { code: ran, step: "command", verdict };
1177
+ if (ran !== 0) {
1178
+ const said = workerTailEvents(spec.bench.parseTailLines(tail.captured()), spec.workerName);
1179
+ deps.error(
1180
+ said.length > 0
1181
+ ? `\n${tag} what ${spec.workerName} logged while \`${spec.command.join(" ")}\` failed:\n${said.map((s) => ` ${s}`).join("\n")}`
1182
+ : `\n${tag} ${spec.workerName} logged nothing while \`${spec.command.join(" ")}\` failed — no console line, exception or failed outcome.`,
1183
+ );
1184
+ return { code: ran, step: "command", verdict };
1185
+ }
1138
1186
  if (!drained) return { code: 1, step: "drain", verdict };
1139
1187
  return verdict.ok ? { code: 0, step: "done", verdict } : { code: 1, step: "budget", verdict };
1140
1188
  }
@@ -89,19 +89,40 @@ export interface SecretSync {
89
89
  after: string[];
90
90
  }
91
91
 
92
+ /** Tries per put. A put is idempotent, so a retry can only turn a network blip into a success. */
93
+ export const SECRET_PUT_ATTEMPTS = 3;
94
+
92
95
  /**
93
96
  * Apply `plan`: put every value, delete every extra, then READ THE ACCOUNT BACK and fail unless it
94
97
  * holds exactly the set. Refuses without touching anything when the plan has `absent` keys.
98
+ *
99
+ * 🔴 **A failed put is tried again, up to {@link SECRET_PUT_ATTEMPTS} times.** On 2026-09-28 one
100
+ * `wrangler secret put` of three hit `fetch failed` and the whole deploy stopped with
101
+ * collections-stage holding a Worker and no secrets — serving nothing — for a blip the next
102
+ * attempt would have cleared. The read-back is still the verdict.
95
103
  */
96
- export async function syncSecrets(plan: SecretPlan, ops: SecretOps): Promise<SecretSync> {
104
+ export async function syncSecrets(
105
+ plan: SecretPlan,
106
+ ops: SecretOps,
107
+ options: { attempts?: number; pause?: (ms: number) => Promise<void> } = {},
108
+ ): Promise<SecretSync> {
109
+ const attempts = Math.max(1, options.attempts ?? SECRET_PUT_ATTEMPTS);
110
+ const pause = options.pause ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));
97
111
  const lines: string[] = [];
98
112
  if (plan.absent.length > 0) {
99
113
  return { ok: false, lines: [`the secrets file has no ${plan.absent.join(" and no ")} — nothing was changed`], after: await ops.held() };
100
114
  }
101
115
  let bad = 0;
102
116
  for (const { name, from, value } of plan.put) {
103
- const ok = await ops.put(name, value);
104
- lines.push(`put ${name}${from === name ? "" : ` (from ${from})`} (${value.length} bytes) — ${ok ? "ok" : "FAILED"}`);
117
+ let ok = false;
118
+ let tries = 0;
119
+ while (!ok && tries < attempts) {
120
+ if (tries > 0) await pause(2_000 * tries);
121
+ ok = await ops.put(name, value);
122
+ tries++;
123
+ }
124
+ const retried = tries > 1 ? ` after ${tries} attempts` : "";
125
+ lines.push(`put ${name}${from === name ? "" : ` (from ${from})`} (${value.length} bytes) — ${ok ? "ok" : "FAILED"}${retried}`);
105
126
  if (!ok) bad++;
106
127
  }
107
128
  for (const name of plan.remove) {