@staff0rd/assist 0.1074.5 → 0.1075.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/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.1074.5",
9
+ version: "0.1075.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -1371,6 +1371,14 @@ var assistConfigShape = {
1371
1371
  ).default([]),
1372
1372
  defaultConnection: z6.string().optional()
1373
1373
  }).optional(),
1374
+ testflight: z6.strictObject({
1375
+ keyId: z6.string().optional(),
1376
+ issuerId: z6.string().optional(),
1377
+ keyRef: z6.string().optional(),
1378
+ bundleId: z6.string().optional(),
1379
+ externalGroup: z6.string().optional(),
1380
+ internalGroup: z6.string().optional()
1381
+ }).optional(),
1374
1382
  sql: z6.strictObject({
1375
1383
  connections: z6.array(
1376
1384
  z6.strictObject({
@@ -6920,6 +6928,40 @@ var sqlConfigHelp = [
6920
6928
  }
6921
6929
  ];
6922
6930
 
6931
+ // src/commands/testflight/testflightConfigHelp.ts
6932
+ var testflightConfigHelp = [
6933
+ {
6934
+ key: "testflight.keyId",
6935
+ setter: "assist config set testflight.keyId N5YK6FM442",
6936
+ note: "App Store Connect API key id"
6937
+ },
6938
+ {
6939
+ key: "testflight.issuerId",
6940
+ setter: "assist config set testflight.issuerId <uuid>",
6941
+ note: "App Store Connect API issuer id"
6942
+ },
6943
+ {
6944
+ key: "testflight.keyRef",
6945
+ setter: "assist config set testflight.keyRef op://<vault>/<item>/<field>",
6946
+ note: "1Password reference to the API key .p8 (read via op, never stored)"
6947
+ },
6948
+ {
6949
+ key: "testflight.bundleId",
6950
+ setter: "assist config set testflight.bundleId com.staff0rd.assist",
6951
+ note: "bundle id of the app whose testers are managed"
6952
+ },
6953
+ {
6954
+ key: "testflight.externalGroup",
6955
+ setter: "assist config set testflight.externalGroup <group name>",
6956
+ note: "external beta group that new testers are added to"
6957
+ },
6958
+ {
6959
+ key: "testflight.internalGroup",
6960
+ setter: "assist config set testflight.internalGroup <group name>",
6961
+ note: "internal beta group for App Store Connect team members"
6962
+ }
6963
+ ];
6964
+
6923
6965
  // src/commands/transcript/transcriptConfigHelp.ts
6924
6966
  var transcriptConfigHelp = [
6925
6967
  {
@@ -7000,6 +7042,7 @@ var configHelpEntries = [
7000
7042
  ...hotkeysConfigHelp,
7001
7043
  ...slackConfigHelp,
7002
7044
  ...sqlConfigHelp,
7045
+ ...testflightConfigHelp,
7003
7046
  ...transcriptConfigHelp,
7004
7047
  ...verifyConfigHelp
7005
7048
  ];
@@ -8786,9 +8829,9 @@ function forwardToPeer(req, res, node, url) {
8786
8829
  const traceId = newTraceId();
8787
8830
  const label = `link ${node} http: ${req.method} ${url.pathname} trace=${traceId}`;
8788
8831
  const log2 = (outcome) => console.log(`${label} -> ${outcome} (${Date.now() - started2}ms)`);
8789
- const send = url.protocol === "https:" ? httpsRequest : httpRequest;
8832
+ const send2 = url.protocol === "https:" ? httpsRequest : httpRequest;
8790
8833
  return new Promise((resolve34) => {
8791
- const upstream = send(
8834
+ const upstream = send2(
8792
8835
  url,
8793
8836
  {
8794
8837
  method: req.method,
@@ -9962,10 +10005,10 @@ function throwOnGraphqlErrors(stdout) {
9962
10005
  if (!parsed || typeof parsed !== "object") return;
9963
10006
  const errors = parsed.errors;
9964
10007
  if (!Array.isArray(errors) || errors.length === 0) return;
9965
- const messages = errors.map(
10008
+ const messages2 = errors.map(
9966
10009
  (entry) => entry && typeof entry === "object" && "message" in entry ? String(entry.message) : String(entry)
9967
10010
  ).join("; ");
9968
- throw new Error(messages || "GraphQL request returned errors");
10011
+ throw new Error(messages2 || "GraphQL request returned errors");
9969
10012
  }
9970
10013
 
9971
10014
  // src/shared/runGhGraphqlJson.ts
@@ -12534,10 +12577,10 @@ function literalAndJsonEncoded(secret) {
12534
12577
  const encoded = JSON.stringify(secret).slice(1, -1);
12535
12578
  return encoded === secret ? [secret] : [secret, encoded];
12536
12579
  }
12537
- function scrubConfigSecrets(messages, value, node) {
12580
+ function scrubConfigSecrets(messages2, value, node) {
12538
12581
  const needles = secretStrings(value, node).flatMap(literalAndJsonEncoded).sort((a, b) => b.length - a.length);
12539
- if (needles.length === 0) return messages;
12540
- return messages.map(
12582
+ if (needles.length === 0) return messages2;
12583
+ return messages2.map(
12541
12584
  (message3) => needles.reduce(
12542
12585
  (text20, needle) => text20.split(needle).join(SECRET_MASK),
12543
12586
  message3
@@ -31464,12 +31507,12 @@ function registerGithub(program) {
31464
31507
  // src/commands/inbox/list.ts
31465
31508
  import chalk188 from "chalk";
31466
31509
  async function list3() {
31467
- const messages = await listInboxMessages(await getDb());
31468
- if (messages.length === 0) {
31510
+ const messages2 = await listInboxMessages(await getDb());
31511
+ if (messages2.length === 0) {
31469
31512
  console.log(chalk188.dim("No flagged messages; run assist inbox scan"));
31470
31513
  return;
31471
31514
  }
31472
- for (const message3 of messages) {
31515
+ for (const message3 of messages2) {
31473
31516
  const when = (message3.receivedAt ?? message3.flaggedAt).toISOString();
31474
31517
  console.log(
31475
31518
  `${chalk188.dim(when)} ${chalk188.cyan(message3.source)} ${chalk188.bold(message3.sender)}`
@@ -31501,9 +31544,9 @@ function formatScanUsage(usage) {
31501
31544
  }
31502
31545
 
31503
31546
  // src/shared/db/upsertInboxMessages.ts
31504
- async function upsertInboxMessages(orm, messages) {
31505
- if (messages.length === 0) return 0;
31506
- const inserted = await orm.insert(inboxMessages).values(messages).onConflictDoNothing({
31547
+ async function upsertInboxMessages(orm, messages2) {
31548
+ if (messages2.length === 0) return 0;
31549
+ const inserted = await orm.insert(inboxMessages).values(messages2).onConflictDoNothing({
31507
31550
  target: [inboxMessages.source, inboxMessages.messageId]
31508
31551
  }).returning({ messageId: inboxMessages.messageId });
31509
31552
  return inserted.length;
@@ -31604,7 +31647,7 @@ function errorEvent(detail) {
31604
31647
  }
31605
31648
  async function scanUnopenedThreads(threadIds, scanThreads, onEvent = () => {
31606
31649
  }) {
31607
- const messages = [];
31650
+ const messages2 = [];
31608
31651
  let pending = threadIds;
31609
31652
  for (let attempt2 = 0; attempt2 < MAX_ATTEMPTS && pending.length; attempt2++) {
31610
31653
  const results = await mapAsync(
@@ -31618,7 +31661,7 @@ async function scanUnopenedThreads(threadIds, scanThreads, onEvent = () => {
31618
31661
  })
31619
31662
  );
31620
31663
  const opened = new Set(results.flatMap((r) => r?.threads.opened ?? []));
31621
- messages.push(...results.flatMap((r) => r?.messages ?? []));
31664
+ messages2.push(...results.flatMap((r) => r?.messages ?? []));
31622
31665
  pending = pending.filter((id) => !opened.has(id));
31623
31666
  }
31624
31667
  if (pending.length)
@@ -31627,7 +31670,7 @@ async function scanUnopenedThreads(threadIds, scanThreads, onEvent = () => {
31627
31670
  `${pending.length} unread thread(s) never opened: ${pending.join(" ")}`
31628
31671
  )
31629
31672
  );
31630
- return messages;
31673
+ return messages2;
31631
31674
  }
31632
31675
 
31633
31676
  // src/commands/inbox/scanInboxWithCoverage.ts
@@ -31738,13 +31781,13 @@ async function runInboxScan(orm, { trigger, wrap = (_since, run4) => run4(), ...
31738
31781
  return withInboxScanJob(orm, trigger, listener, async (tracked) => {
31739
31782
  const startedAt = /* @__PURE__ */ new Date();
31740
31783
  const since = await readInboxLastScan(orm) ?? new Date(startedAt.getTime() - FIRST_SCAN_LOOKBACK_MS);
31741
- const { messages, usage } = await wrap(
31784
+ const { messages: messages2, usage } = await wrap(
31742
31785
  since,
31743
31786
  () => scanInboxWithCoverage(since, tracked)
31744
31787
  );
31745
- const added = await upsertInboxMessages(orm, messages.map(toRow2));
31788
+ const added = await upsertInboxMessages(orm, messages2.map(toRow2));
31746
31789
  await writeInboxLastScan(orm, startedAt);
31747
- return { flagged: messages.length, added, usage };
31790
+ return { flagged: messages2.length, added, usage };
31748
31791
  });
31749
31792
  }
31750
31793
 
@@ -46525,6 +46568,236 @@ function registerSync(program) {
46525
46568
  configHelp(syncCommand, rootConfigHelp.sync);
46526
46569
  }
46527
46570
 
46571
+ // src/commands/testflight/testflightAdd.ts
46572
+ import chalk281 from "chalk";
46573
+
46574
+ // src/commands/testflight/addExternalTester.ts
46575
+ async function addExternalTester(client, groupId, email) {
46576
+ const inGroup = await client.get("/v1/betaTesters", {
46577
+ "filter[email]": email,
46578
+ "filter[betaGroups]": groupId,
46579
+ limit: "1"
46580
+ });
46581
+ if (inGroup.data.length > 0) return "already-in-group";
46582
+ const existing = await client.get("/v1/betaTesters", {
46583
+ "filter[email]": email,
46584
+ limit: "1"
46585
+ });
46586
+ const tester = existing.data[0];
46587
+ if (tester) {
46588
+ await client.post(`/v1/betaGroups/${groupId}/relationships/betaTesters`, {
46589
+ data: [{ type: "betaTesters", id: tester.id }]
46590
+ });
46591
+ return "added";
46592
+ }
46593
+ await client.post("/v1/betaTesters", {
46594
+ data: {
46595
+ type: "betaTesters",
46596
+ attributes: { email },
46597
+ relationships: {
46598
+ betaGroups: { data: [{ type: "betaGroups", id: groupId }] }
46599
+ }
46600
+ }
46601
+ });
46602
+ return "created";
46603
+ }
46604
+
46605
+ // src/commands/testflight/formatAscError.ts
46606
+ var statusHints = {
46607
+ 401: "Check testflight.keyId, testflight.issuerId and that testflight.keyRef points at the matching .p8.",
46608
+ 403: "The App Store Connect API key may lack the role this action needs (team invitations need Admin)."
46609
+ };
46610
+ function parseErrors(body) {
46611
+ try {
46612
+ const parsed = JSON.parse(body);
46613
+ return (parsed.errors ?? []).map(
46614
+ (error) => [error.title, error.detail].filter(Boolean).join(": ")
46615
+ );
46616
+ } catch {
46617
+ return body ? [body] : [];
46618
+ }
46619
+ }
46620
+ function formatAscError(method, path109, status2, body) {
46621
+ const lines2 = [
46622
+ `App Store Connect ${method} ${path109} failed (${status2})`,
46623
+ ...parseErrors(body).map((line) => ` ${line}`)
46624
+ ];
46625
+ const hint = statusHints[status2];
46626
+ if (hint) lines2.push(hint);
46627
+ return lines2.join("\n");
46628
+ }
46629
+
46630
+ // src/commands/testflight/TestflightError.ts
46631
+ var TestflightError = class extends Error {
46632
+ name = "TestflightError";
46633
+ };
46634
+
46635
+ // src/commands/testflight/ascRequest.ts
46636
+ var BASE_URL = "https://api.appstoreconnect.apple.com";
46637
+ async function send(fetchFn, token, method, path109, body) {
46638
+ try {
46639
+ return await fetchFn(`${BASE_URL}${path109}`, {
46640
+ method,
46641
+ headers: {
46642
+ Authorization: `Bearer ${token}`,
46643
+ Accept: "application/json",
46644
+ ...body === void 0 ? {} : { "Content-Type": "application/json" }
46645
+ },
46646
+ body: body === void 0 ? void 0 : JSON.stringify(body)
46647
+ });
46648
+ } catch (error) {
46649
+ const reason4 = error instanceof Error ? error.message : String(error);
46650
+ throw new TestflightError(`Failed to reach App Store Connect: ${reason4}`);
46651
+ }
46652
+ }
46653
+ async function ascRequest(fetchFn, token, method, path109, body) {
46654
+ const response = await send(fetchFn, token, method, path109, body);
46655
+ const text20 = await response.text();
46656
+ if (!response.ok) {
46657
+ throw new TestflightError(
46658
+ formatAscError(method, path109.split("?")[0], response.status, text20)
46659
+ );
46660
+ }
46661
+ return text20 ? JSON.parse(text20) : void 0;
46662
+ }
46663
+
46664
+ // src/commands/testflight/createAscClient.ts
46665
+ function createAscClient(token, fetchFn = fetch) {
46666
+ return {
46667
+ get: (path109, params) => {
46668
+ const query = params ? `?${new URLSearchParams(params)}` : "";
46669
+ return ascRequest(fetchFn, token, "GET", `${path109}${query}`);
46670
+ },
46671
+ post: (path109, body) => ascRequest(fetchFn, token, "POST", path109, body)
46672
+ };
46673
+ }
46674
+
46675
+ // src/commands/testflight/createAscToken.ts
46676
+ import { createPrivateKey, sign } from "crypto";
46677
+ var TOKEN_LIFETIME_SECONDS = 20 * 60;
46678
+ function base64url(value) {
46679
+ return Buffer.from(JSON.stringify(value)).toString("base64url");
46680
+ }
46681
+ function createAscToken(options2) {
46682
+ const iat = Math.floor((options2.now ?? Date.now()) / 1e3);
46683
+ const header = { alg: "ES256", kid: options2.keyId, typ: "JWT" };
46684
+ const payload = {
46685
+ iss: options2.issuerId,
46686
+ iat,
46687
+ exp: iat + TOKEN_LIFETIME_SECONDS,
46688
+ aud: "appstoreconnect-v1"
46689
+ };
46690
+ const signingInput = `${base64url(header)}.${base64url(payload)}`;
46691
+ const signature = sign("sha256", Buffer.from(signingInput), {
46692
+ key: createPrivateKey(options2.privateKey),
46693
+ dsaEncoding: "ieee-p1363"
46694
+ });
46695
+ return `${signingInput}.${signature.toString("base64url")}`;
46696
+ }
46697
+
46698
+ // src/commands/testflight/findAppId.ts
46699
+ async function findAppId(client, bundleId) {
46700
+ const { data } = await client.get("/v1/apps", {
46701
+ "filter[bundleId]": bundleId,
46702
+ "fields[apps]": "bundleId"
46703
+ });
46704
+ const app = data.find((item) => item.attributes?.bundleId === bundleId);
46705
+ if (!app) {
46706
+ throw new TestflightError(
46707
+ `No App Store Connect app has bundle id ${bundleId} (testflight.bundleId)`
46708
+ );
46709
+ }
46710
+ return app.id;
46711
+ }
46712
+
46713
+ // src/commands/testflight/findBetaGroupId.ts
46714
+ async function findBetaGroupId(client, appId, name, configKey) {
46715
+ const { data } = await client.get(`/v1/apps/${appId}/betaGroups`, {
46716
+ "fields[betaGroups]": "name",
46717
+ limit: "200"
46718
+ });
46719
+ const group = data.find((item) => item.attributes?.name === name);
46720
+ if (!group) {
46721
+ const available = data.map((item) => String(item.attributes?.name)).join(", ");
46722
+ throw new TestflightError(
46723
+ `No beta group named "${name}" (${configKey}). Available groups: ${available || "none"}`
46724
+ );
46725
+ }
46726
+ return group.id;
46727
+ }
46728
+
46729
+ // src/commands/testflight/addTester.ts
46730
+ async function addTester(config, email, deps2 = {}) {
46731
+ const privateKey = (deps2.readKey ?? resolveOpSecret)(config.keyRef);
46732
+ const token = createAscToken({
46733
+ keyId: config.keyId,
46734
+ issuerId: config.issuerId,
46735
+ privateKey
46736
+ });
46737
+ const client = createAscClient(token, deps2.fetchFn);
46738
+ const appId = await findAppId(client, config.bundleId);
46739
+ const groupId = await findBetaGroupId(
46740
+ client,
46741
+ appId,
46742
+ config.externalGroup,
46743
+ "testflight.externalGroup"
46744
+ );
46745
+ return addExternalTester(client, groupId, email);
46746
+ }
46747
+
46748
+ // src/commands/testflight/readTestflightConfig.ts
46749
+ var requiredKeys = [
46750
+ "keyId",
46751
+ "issuerId",
46752
+ "keyRef",
46753
+ "bundleId",
46754
+ "externalGroup"
46755
+ ];
46756
+ function readTestflightConfig(config) {
46757
+ const testflight = config.testflight ?? {};
46758
+ const missing = requiredKeys.filter((key) => !testflight[key]);
46759
+ if (missing.length > 0) {
46760
+ const lines2 = missing.map((key) => {
46761
+ const entry = testflightConfigHelp.find(
46762
+ (help) => help.key === `testflight.${key}`
46763
+ );
46764
+ return ` testflight.${key} is not set. Set it with: ${entry?.setter}`;
46765
+ });
46766
+ throw new TestflightError(
46767
+ ["TestFlight is not configured", ...lines2].join("\n")
46768
+ );
46769
+ }
46770
+ return testflight;
46771
+ }
46772
+
46773
+ // src/commands/testflight/testflightAdd.ts
46774
+ var messages = {
46775
+ created: (email, group) => `Invited ${email} to TestFlight group "${group}"`,
46776
+ added: (email, group) => `Added existing tester ${email} to TestFlight group "${group}"`,
46777
+ "already-in-group": (email, group) => `${email} is already in TestFlight group "${group}"`
46778
+ };
46779
+ async function testflightAdd(email) {
46780
+ try {
46781
+ const config = readTestflightConfig(loadConfig());
46782
+ const result = await addTester(config, email);
46783
+ const message3 = messages[result](email, config.externalGroup);
46784
+ console.log(
46785
+ result === "already-in-group" ? chalk281.yellow(message3) : chalk281.green(message3)
46786
+ );
46787
+ } catch (error) {
46788
+ if (!(error instanceof TestflightError)) throw error;
46789
+ console.error(chalk281.red(error.message));
46790
+ process.exit(1);
46791
+ }
46792
+ }
46793
+
46794
+ // src/commands/registerTestflight.ts
46795
+ function registerTestflight(program) {
46796
+ const cmd = program.command("testflight").description("Manage TestFlight testers via the App Store Connect API");
46797
+ const addCommand = cmd.command("add <email>").description("Add an external tester to the configured beta group").action((email) => testflightAdd(email));
46798
+ configHelp(addCommand, testflightConfigHelp);
46799
+ }
46800
+
46528
46801
  // src/commands/transcript/clean.ts
46529
46802
  import { existsSync as existsSync82 } from "fs";
46530
46803
 
@@ -46724,23 +46997,23 @@ function parseVtt(content) {
46724
46997
 
46725
46998
  // src/commands/transcript/convert/formatChatLog.ts
46726
46999
  function cuesToChatMessages(cues) {
46727
- const messages = [];
47000
+ const messages2 = [];
46728
47001
  for (const cue of cues) {
46729
47002
  const speaker = cue.speaker || "Unknown";
46730
- const lastMessage = messages[messages.length - 1];
47003
+ const lastMessage = messages2[messages2.length - 1];
46731
47004
  if (lastMessage && lastMessage.speaker === speaker) {
46732
47005
  lastMessage.text += ` ${cue.text}`;
46733
47006
  } else {
46734
- messages.push({ speaker, text: cue.text, startMs: cue.startMs });
47007
+ messages2.push({ speaker, text: cue.text, startMs: cue.startMs });
46735
47008
  }
46736
47009
  }
46737
- return messages.map((msg) => ({
47010
+ return messages2.map((msg) => ({
46738
47011
  ...msg,
46739
47012
  text: cleanText(msg.text)
46740
47013
  }));
46741
47014
  }
46742
- function formatChatLog(messages, options2 = {}) {
46743
- return messages.map((msg) => {
47015
+ function formatChatLog(messages2, options2 = {}) {
47016
+ return messages2.map((msg) => {
46744
47017
  const prefix2 = options2.timestamps ? `[${formatClock(msg.startMs)}] ` : "";
46745
47018
  return `${prefix2}${msg.speaker}: ${msg.text}`;
46746
47019
  }).join("\n\n");
@@ -48003,6 +48276,11 @@ function describeOutcome(outcome) {
48003
48276
  exitCode: 3,
48004
48277
  message: `simulated divergence from ${outcome.upstream} (${simulatedDivergenceNote})`
48005
48278
  };
48279
+ case "fetch-failed":
48280
+ return {
48281
+ exitCode: 5,
48282
+ message: `git fetch for ${outcome.upstream} failed: ${outcome.reason}`
48283
+ };
48006
48284
  case "unavailable":
48007
48285
  return { exitCode: 1, message: `cannot wait: ${outcome.reason}` };
48008
48286
  case "interrupted":
@@ -48548,7 +48826,7 @@ function fetchQuietly(cwd, intervalMs) {
48548
48826
  });
48549
48827
  return void 0;
48550
48828
  } catch (error) {
48551
- return error instanceof Error ? error.message : String(error);
48829
+ return gitFailureReason(error).replace(/\s*\n\s*/g, " \xB7 ");
48552
48830
  }
48553
48831
  }
48554
48832
 
@@ -48571,6 +48849,16 @@ function readMovement(cwd) {
48571
48849
  }
48572
48850
  }
48573
48851
 
48852
+ // src/commands/watch/checkUpstream.ts
48853
+ function checkUpstream(upstream, intervalMs, cwd) {
48854
+ if (consumeSimulatedDivergence(cwd))
48855
+ return { kind: "simulated-divergence", upstream };
48856
+ const fetchError = fetchQuietly(cwd, intervalMs);
48857
+ if (fetchError) return { kind: "fetch-failed", upstream, reason: fetchError };
48858
+ const found = readMovement(cwd);
48859
+ return found && { kind: "moved", upstream, ...found };
48860
+ }
48861
+
48574
48862
  // src/commands/watch/pollForMovement.ts
48575
48863
  var CONTROL_POLL_MS = 1e3;
48576
48864
  function pollForMovement(options2) {
@@ -48588,11 +48876,8 @@ function pollForMovement(options2) {
48588
48876
  };
48589
48877
  const onInterrupt = () => finish2({ kind: "interrupted" });
48590
48878
  const check2 = () => {
48591
- if (consumeSimulatedDivergence(cwd))
48592
- return finish2({ kind: "simulated-divergence", upstream });
48593
- fetchQuietly(cwd, intervalMs);
48594
- const found = readMovement(cwd);
48595
- if (found) finish2({ kind: "moved", upstream, ...found });
48879
+ const outcome = checkUpstream(upstream, intervalMs, cwd);
48880
+ if (outcome) finish2(outcome);
48596
48881
  };
48597
48882
  const ticker = setInterval(check2, intervalMs);
48598
48883
  const controller = control && setInterval(() => {
@@ -48635,9 +48920,15 @@ function waitForUpstream(options2) {
48635
48920
  if (consumeSimulatedDivergence(cwd))
48636
48921
  return Promise.resolve({ kind: "simulated-divergence", upstream });
48637
48922
  const control = watchControlPaths(cwd);
48638
- fetchQuietly(cwd, intervalMs);
48923
+ const fetchError = fetchQuietly(cwd, intervalMs);
48639
48924
  if (control && consumeMarker(control.stop))
48640
48925
  return Promise.resolve({ kind: "interrupted" });
48926
+ if (fetchError)
48927
+ return Promise.resolve({
48928
+ kind: "fetch-failed",
48929
+ upstream,
48930
+ reason: fetchError
48931
+ });
48641
48932
  const moved = readMovement(cwd);
48642
48933
  if (moved) return Promise.resolve({ kind: "moved", upstream, ...moved });
48643
48934
  return pollForMovement({
@@ -48678,7 +48969,7 @@ async function watchWait(options2) {
48678
48969
  function registerWatchWait(watchCommand) {
48679
48970
  internalCommand(
48680
48971
  watchCommand.command("wait").description(
48681
- "Block until the current branch's upstream gains commits, then exit 0 (2 on timeout, 3 when --pull hits genuine divergence, 4 when --build or the post-build sync fails, 1 when waiting is impossible, 130 on interrupt)"
48972
+ "Block until the current branch's upstream gains commits, then exit 0 (2 on timeout, 3 when --pull hits genuine divergence, 4 when --build or the post-build sync fails, 5 when git fetch fails, 1 when waiting is impossible, 130 on interrupt)"
48682
48973
  ).option(
48683
48974
  "--interval <duration>",
48684
48975
  "How often to fetch after the fetch at startup (e.g. 30s, 2m)",
@@ -49384,18 +49675,18 @@ function registerRun(program) {
49384
49675
  }
49385
49676
 
49386
49677
  // src/commands/sessions/nodes/formatLink.ts
49387
- import chalk281 from "chalk";
49678
+ import chalk282 from "chalk";
49388
49679
  var STATE_COLOURS = {
49389
- connected: chalk281.green,
49390
- connecting: chalk281.yellow,
49391
- disconnected: chalk281.red,
49392
- "version-blocked": chalk281.red
49680
+ connected: chalk282.green,
49681
+ connecting: chalk282.yellow,
49682
+ disconnected: chalk282.red,
49683
+ "version-blocked": chalk282.red
49393
49684
  };
49394
49685
  function formatLink(link3) {
49395
- const colour = STATE_COLOURS[link3.state] ?? chalk281.white;
49686
+ const colour = STATE_COLOURS[link3.state] ?? chalk282.white;
49396
49687
  const peer = link3.peerVersion ? ` peer ${link3.peerVersion}` : "";
49397
49688
  const error = link3.error ? `
49398
- ${chalk281.dim(`last error${link3.errorAt ? ` ${link3.errorAt}` : ""}: ${link3.error}`)}` : "";
49689
+ ${chalk282.dim(`last error${link3.errorAt ? ` ${link3.errorAt}` : ""}: ${link3.error}`)}` : "";
49399
49690
  return ` ${link3.name} ${colour(link3.state)} ${link3.url}${peer}${error}`;
49400
49691
  }
49401
49692
 
@@ -50301,10 +50592,10 @@ function sessionSnapshot(s) {
50301
50592
  }
50302
50593
 
50303
50594
  // src/commands/sessions/daemon/sendResizeSnapshot.ts
50304
- function sendResizeSnapshot(s, send) {
50595
+ function sendResizeSnapshot(s, send2) {
50305
50596
  const data = sessionSnapshot(s);
50306
50597
  daemonLog(`session ${s.id} resize snapshot ${data.length} chars`);
50307
- send(data);
50598
+ send2(data);
50308
50599
  }
50309
50600
 
50310
50601
  // src/commands/sessions/daemon/viewerSize.ts
@@ -51197,9 +51488,15 @@ async function settleLap(lap, { end, tail }, deps2) {
51197
51488
  if (deps2.paused()) deps2.note(`lap ${lap} ${how}; paused`);
51198
51489
  else if (decideLap(end, false).kind === "relaunch")
51199
51490
  deps2.note(`lap ${lap} ${how}; relaunching`);
51200
- else await backOff(`lap ${lap} ${how}`, deps2);
51491
+ else {
51492
+ const why = lastLine(tail);
51493
+ await backOff(`lap ${lap} ${how}${why ? `: ${why}` : ""}`, deps2);
51494
+ }
51201
51495
  return void 0;
51202
51496
  }
51497
+ function lastLine(text20) {
51498
+ return stripAnsi(text20).split(/\r?\n|\r/).map((line) => line.trim()).filter(Boolean).pop();
51499
+ }
51203
51500
 
51204
51501
  // src/commands/sessions/daemon/autoUpdate/runAutoUpdateLoop.ts
51205
51502
  var PAUSE_POLL_MS = 60 * 1e3;
@@ -57178,12 +57475,12 @@ function condense(value) {
57178
57475
 
57179
57476
  // src/commands/sessions/shared/codex/parseCodexTranscriptLines.ts
57180
57477
  function parseCodexTranscriptLines(lines2) {
57181
- const messages = [];
57478
+ const messages2 = [];
57182
57479
  for (const line of lines2) {
57183
57480
  const entry = line.trim() ? parseRolloutEntry(line) : null;
57184
- if (entry) messages.push(...rolloutMessages(entry));
57481
+ if (entry) messages2.push(...rolloutMessages(entry));
57185
57482
  }
57186
- return messages;
57483
+ return messages2;
57187
57484
  }
57188
57485
  function rolloutMessages(entry) {
57189
57486
  const payload = rolloutPayload(entry);
@@ -57216,8 +57513,8 @@ function text19(role, value) {
57216
57513
 
57217
57514
  // src/commands/sessions/daemon/historySearch/transcriptLineTexts.ts
57218
57515
  function transcriptLineTexts(line, harness) {
57219
- const messages = harness === "codex" ? parseCodexTranscriptLines([line]) : claudeMessages(line);
57220
- return messages.flatMap((m) => m.role === "tool" ? [] : [m.text]);
57516
+ const messages2 = harness === "codex" ? parseCodexTranscriptLines([line]) : claudeMessages(line);
57517
+ return messages2.flatMap((m) => m.role === "tool" ? [] : [m.text]);
57221
57518
  }
57222
57519
  function claudeMessages(line) {
57223
57520
  try {
@@ -57665,13 +57962,13 @@ async function readMessages(filePath, parse5) {
57665
57962
  }
57666
57963
  }
57667
57964
  function parseTranscriptLines(lines2) {
57668
- const messages = [];
57965
+ const messages2 = [];
57669
57966
  for (const line of lines2) {
57670
57967
  const entry = line.trim() ? safeParse2(line) : null;
57671
57968
  if (!entry || entry.isSidechain || entry.isMeta) continue;
57672
- messages.push(...entryMessages(entry));
57969
+ messages2.push(...entryMessages(entry));
57673
57970
  }
57674
- return messages;
57971
+ return messages2;
57675
57972
  }
57676
57973
  function safeParse2(line) {
57677
57974
  try {
@@ -57683,12 +57980,12 @@ function safeParse2(line) {
57683
57980
 
57684
57981
  // src/commands/sessions/shared/extractUserMessages.ts
57685
57982
  function extractUserMessages(entries, maxLength) {
57686
- const messages = [];
57983
+ const messages2 = [];
57687
57984
  for (const entry of entries) {
57688
57985
  const message3 = renderUserPrompt(entry, maxLength);
57689
- if (message3) messages.push(message3);
57986
+ if (message3) messages2.push(message3);
57690
57987
  }
57691
- return messages;
57988
+ return messages2;
57692
57989
  }
57693
57990
 
57694
57991
  // src/commands/sessions/daemon/handleFetchUserMessages.ts
@@ -57705,11 +58002,11 @@ async function handleFetchUserMessages(client, manager, data) {
57705
58002
  const session = findSession(manager, sessionId2);
57706
58003
  const filePath = session ? await resolveTranscriptPath(session) : null;
57707
58004
  const entries = filePath ? await readTranscriptTail(filePath, Number.POSITIVE_INFINITY) : [];
57708
- const messages = extractUserMessages(entries);
58005
+ const messages2 = extractUserMessages(entries);
57709
58006
  daemonLog(
57710
- `session ${sessionId2} user messages: ${messages.length} from ${filePath ?? "no transcript"}`
58007
+ `session ${sessionId2} user messages: ${messages2.length} from ${filePath ?? "no transcript"}`
57711
58008
  );
57712
- sendTo(client, { type: "user-messages", sessionId: sessionId2, messages });
58009
+ sendTo(client, { type: "user-messages", sessionId: sessionId2, messages: messages2 });
57713
58010
  }
57714
58011
 
57715
58012
  // src/commands/sessions/daemon/lifecycleHandlers.ts
@@ -57720,7 +58017,7 @@ async function handleHistory(client, manager) {
57720
58017
  function handleFetchTranscript(client, _manager, data) {
57721
58018
  const sessionId2 = data.sessionId;
57722
58019
  parseTranscript(sessionId2).then(
57723
- (messages) => sendTo(client, { type: "transcript", sessionId: sessionId2, messages })
58020
+ (messages2) => sendTo(client, { type: "transcript", sessionId: sessionId2, messages: messages2 })
57724
58021
  );
57725
58022
  }
57726
58023
  async function handleShutdown(client, manager) {
@@ -58486,7 +58783,7 @@ async function closeSession2() {
58486
58783
  }
58487
58784
 
58488
58785
  // src/commands/sessions/nodes/listNodes.ts
58489
- import chalk282 from "chalk";
58786
+ import chalk283 from "chalk";
58490
58787
  async function nodesReport() {
58491
58788
  const live = await queryNodes();
58492
58789
  if (live)
@@ -58503,10 +58800,10 @@ async function listNodes(options2) {
58503
58800
  console.log(JSON.stringify(report, null, 2));
58504
58801
  return;
58505
58802
  }
58506
- console.log(`${report.local} ${chalk282.dim("(this node)")}`);
58803
+ console.log(`${report.local} ${chalk283.dim("(this node)")}`);
58507
58804
  if (!report.daemonRunning)
58508
- console.log(chalk282.dim(" daemon not running; showing configured links"));
58509
- if (report.links.length === 0) console.log(chalk282.dim(" no links"));
58805
+ console.log(chalk283.dim(" daemon not running; showing configured links"));
58806
+ if (report.links.length === 0) console.log(chalk283.dim(" no links"));
58510
58807
  for (const link3 of report.links) console.log(formatLink(link3));
58511
58808
  }
58512
58809
 
@@ -58528,7 +58825,7 @@ async function findUnlinkedWindowsNode(health2, platform = detectPlatform()) {
58528
58825
  }
58529
58826
 
58530
58827
  // src/commands/sessions/nodes/printReport.ts
58531
- import chalk283 from "chalk";
58828
+ import chalk284 from "chalk";
58532
58829
  function printReport(report) {
58533
58830
  if (report.links.length === 0) {
58534
58831
  console.log(`${report.local} has no links`);
@@ -58542,11 +58839,11 @@ function printReport(report) {
58542
58839
  for (const diagnosis of report.links) printDiagnosis(diagnosis);
58543
58840
  }
58544
58841
  function printDiagnosis(diagnosis) {
58545
- console.log(`${chalk283.bold(diagnosis.name)} ${chalk283.dim(diagnosis.url)}`);
58842
+ console.log(`${chalk284.bold(diagnosis.name)} ${chalk284.dim(diagnosis.url)}`);
58546
58843
  for (const hop of diagnosis.hops) {
58547
- const mark = hop.ok ? chalk283.green("\u2713") : chalk283.red("\u2717");
58844
+ const mark = hop.ok ? chalk284.green("\u2713") : chalk284.red("\u2717");
58548
58845
  console.log(` ${mark} ${hop.hop.padEnd(9)} ${hop.detail ?? hop.error}`);
58549
- if (hop.remediation) console.log(` ${chalk283.yellow(hop.remediation)}`);
58846
+ if (hop.remediation) console.log(` ${chalk284.yellow(hop.remediation)}`);
58550
58847
  }
58551
58848
  }
58552
58849
 
@@ -58618,14 +58915,14 @@ function registerDiagnoseCommands(nodes, calledBy5) {
58618
58915
  }
58619
58916
 
58620
58917
  // src/commands/sessions/nodes/linkNode.ts
58621
- import chalk286 from "chalk";
58918
+ import chalk287 from "chalk";
58622
58919
 
58623
58920
  // src/commands/sessions/nodes/notifyDaemonLinks.ts
58624
- import chalk284 from "chalk";
58921
+ import chalk285 from "chalk";
58625
58922
  async function notifyDaemonLinks() {
58626
58923
  if (!await isDaemonRunning()) {
58627
58924
  console.log(
58628
- chalk284.yellow(
58925
+ chalk285.yellow(
58629
58926
  "The sessions daemon is not running; it loads the links when it starts."
58630
58927
  )
58631
58928
  );
@@ -58633,11 +58930,11 @@ async function notifyDaemonLinks() {
58633
58930
  }
58634
58931
  try {
58635
58932
  await sendToDaemonAwaitAck({ type: "reload-links" });
58636
- console.log(chalk284.dim("The sessions daemon reloaded its links."));
58933
+ console.log(chalk285.dim("The sessions daemon reloaded its links."));
58637
58934
  } catch (error) {
58638
58935
  const message3 = error instanceof Error ? error.message : String(error);
58639
58936
  console.log(
58640
- chalk284.yellow(
58937
+ chalk285.yellow(
58641
58938
  `Could not notify the sessions daemon (${message3}); run \`assist daemon restart\` to apply the change.`
58642
58939
  )
58643
58940
  );
@@ -58645,7 +58942,7 @@ async function notifyDaemonLinks() {
58645
58942
  }
58646
58943
 
58647
58944
  // src/commands/sessions/nodes/readLinks.ts
58648
- import chalk285 from "chalk";
58945
+ import chalk286 from "chalk";
58649
58946
 
58650
58947
  // src/commands/sessions/nodes/writeLinks.ts
58651
58948
  async function writeLinks(links2) {
@@ -58668,7 +58965,7 @@ async function readLinks() {
58668
58965
  await writeLinks(links2);
58669
58966
  const dropped = stored.filter((link3) => !link3.url).map((link3) => link3.name);
58670
58967
  console.log(
58671
- chalk285.yellow(`Removed ${dropped.join(", ")}: ${SSH_LINK_RETIRED}`)
58968
+ chalk286.yellow(`Removed ${dropped.join(", ")}: ${SSH_LINK_RETIRED}`)
58672
58969
  );
58673
58970
  return links2;
58674
58971
  }
@@ -58724,7 +59021,7 @@ async function linkNode(name, url, options2) {
58724
59021
  throw new Error(`${name} is this node; link to a different node`);
58725
59022
  const link3 = await buildLink(name, url, options2);
58726
59023
  await writeLinks([...others, link3]);
58727
- console.log(chalk286.green(`Linked ${name} (${link3.url})`));
59024
+ console.log(chalk287.green(`Linked ${name} (${link3.url})`));
58728
59025
  await notifyDaemonLinks();
58729
59026
  }
58730
59027
 
@@ -58907,16 +59204,16 @@ function registerPeerActionCommands(nodes, calledBy5) {
58907
59204
  }
58908
59205
 
58909
59206
  // src/commands/sessions/nodes/unlinkNode.ts
58910
- import chalk287 from "chalk";
59207
+ import chalk288 from "chalk";
58911
59208
  async function unlinkNode(name) {
58912
59209
  const links2 = await readLinks();
58913
59210
  const remaining = links2.filter((link3) => link3.name !== name);
58914
59211
  if (remaining.length === links2.length) {
58915
- console.log(chalk287.yellow(`No link named ${name}`));
59212
+ console.log(chalk288.yellow(`No link named ${name}`));
58916
59213
  return;
58917
59214
  }
58918
59215
  await writeLinks(remaining);
58919
- console.log(chalk287.green(`Unlinked ${name}`));
59216
+ console.log(chalk288.green(`Unlinked ${name}`));
58920
59217
  await notifyDaemonLinks();
58921
59218
  }
58922
59219
 
@@ -59145,6 +59442,7 @@ var programRegistrars = [
59145
59442
  registerAskDesign,
59146
59443
  registerSlack,
59147
59444
  registerSql,
59445
+ registerTestflight,
59148
59446
  registerTranscript,
59149
59447
  registerWatch,
59150
59448
  registerSessions,
@@ -59164,10 +59462,10 @@ function createProgram() {
59164
59462
  }
59165
59463
 
59166
59464
  // src/reportCliError.ts
59167
- import chalk288 from "chalk";
59465
+ import chalk289 from "chalk";
59168
59466
  function reportCliError(error) {
59169
59467
  if (error instanceof InvalidItemIdError || error instanceof AmbiguousRepoConfigError || error instanceof UnknownRepoConfigError || error instanceof MissingRunCwdError || error instanceof MiroExtractError || error instanceof MissingDatabaseUrlError) {
59170
- console.error(chalk288.red(error.message));
59468
+ console.error(chalk289.red(error.message));
59171
59469
  } else {
59172
59470
  console.error(error);
59173
59471
  }