@sideboard-ai/core 0.1.10 → 0.1.19

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.
@@ -3,7 +3,7 @@ import {
3
3
  ensureWorkspace,
4
4
  removeWorkspace,
5
5
  syncWorkspacesFromThreads
6
- } from "./chunk-TLJH3L2C.js";
6
+ } from "./chunk-LIUV5ONW.js";
7
7
  import {
8
8
  GLOBAL_WORKSPACE_ID,
9
9
  createGlobalChat,
@@ -13,19 +13,19 @@ import {
13
13
  isGlobalThread,
14
14
  isOrchestratorThread,
15
15
  orchestratorSessionPoisonedByBuiltins
16
- } from "./chunk-2M4OHXYX.js";
16
+ } from "./chunk-5263JXQY.js";
17
17
  import {
18
18
  coordinatorSystemPrompt,
19
19
  coordinatorTurnReminder,
20
20
  enrichWorkspacesWithGithub,
21
21
  ensureGlobalCoordinatorCwd
22
- } from "./chunk-2R5VV4BA.js";
22
+ } from "./chunk-SNHWAARD.js";
23
23
  import {
24
24
  PLAN_MODE_INSTRUCTION,
25
25
  allAdapters,
26
26
  getAdapter,
27
27
  parseBrightsyCliLine
28
- } from "./chunk-WMCPLDW3.js";
28
+ } from "./chunk-JQJZTL2Q.js";
29
29
  import {
30
30
  childEnvWithAppSettings,
31
31
  getLinearApiKey,
@@ -41,9 +41,11 @@ import {
41
41
  createOrUpdatePr,
42
42
  createThreadWorktree,
43
43
  fetchPrHead,
44
+ formatGhLandError,
44
45
  getPr,
45
46
  getPrChecks,
46
47
  getPrDetails,
48
+ getPrMeta,
47
49
  isDirty,
48
50
  isPlaceholderBranch,
49
51
  listBranches,
@@ -51,6 +53,7 @@ import {
51
53
  listWorktrees,
52
54
  mergePr,
53
55
  normalizeWorktreePath,
56
+ originGhRepoEnv,
54
57
  pushBranch,
55
58
  removeWorktree,
56
59
  resolveDefaultBranch,
@@ -61,7 +64,7 @@ import {
61
64
  takenSlugsFromThread,
62
65
  threadDisplayLabel,
63
66
  worktreeNameFromPath
64
- } from "./chunk-LL7DTZ5B.js";
67
+ } from "./chunk-LXHSRNJJ.js";
65
68
  import {
66
69
  appendMessage,
67
70
  createEmptyThread,
@@ -429,9 +432,9 @@ async function spawnAgentTurn(thread, input, onEvent) {
429
432
  `Cannot spawn ${thread.agent}: thread ${thread.id} has no worktreePath`
430
433
  );
431
434
  }
432
- const { isGlobalThread: isGlobalThread2 } = await import("./global-workspace-R44HGBU6.js");
435
+ const { isGlobalThread: isGlobalThread2 } = await import("./global-workspace-IV6LIDTO.js");
433
436
  if (isGlobalThread2(thread)) {
434
- const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("./coordinator-prompt-6R2TX4WQ.js");
437
+ const { ensureGlobalCoordinatorCwd: ensureGlobalCoordinatorCwd2 } = await import("./coordinator-prompt-QPTX6YCW.js");
435
438
  ensureGlobalCoordinatorCwd2();
436
439
  }
437
440
  const adapter = getAdapter(thread.agent);
@@ -441,9 +444,14 @@ async function spawnAgentTurn(thread, input, onEvent) {
441
444
  `Agent cwd must be the thread worktree (got ${cmd.cwd}, expected ${thread.worktreePath})`
442
445
  );
443
446
  }
447
+ const env = childEnvWithAppSettings(cmd.env);
448
+ if (!isOrchestratorThread(thread)) {
449
+ const originEnv = await originGhRepoEnv(thread.worktreePath).catch(() => ({}));
450
+ Object.assign(env, originEnv);
451
+ }
444
452
  const child = execa(cmd.file, cmd.args, {
445
453
  cwd: cmd.cwd,
446
- env: childEnvWithAppSettings(cmd.env),
454
+ env,
447
455
  reject: false,
448
456
  stdout: "pipe",
449
457
  stderr: "pipe",
@@ -546,7 +554,7 @@ function formatRenameBranchDirective(thread, opts) {
546
554
  }
547
555
  return lines.join("\n");
548
556
  }
549
- function formatWorktreeDirective(thread) {
557
+ function formatWorktreeDirective(thread, opts) {
550
558
  const worktree = normPath(thread.worktreePath);
551
559
  const repo = normPath(thread.repoPath);
552
560
  const dir = worktreeNameFromPath(thread.worktreePath);
@@ -567,7 +575,13 @@ function formatWorktreeDirective(thread) {
567
575
  );
568
576
  }
569
577
  lines.push("");
570
- lines.push("Pull requests (when the work is ready to share):");
578
+ lines.push("Git remotes + pull requests (when the work is ready to share):");
579
+ lines.push(
580
+ "- Always use this worktree's `origin` remote (`git remote get-url origin` from this cwd). Never push to or open PRs against `upstream` (template remotes)."
581
+ );
582
+ lines.push(
583
+ "- Push with `git push -u origin HEAD` (or the current branch name). Do not `git push upstream`."
584
+ );
571
585
  lines.push(
572
586
  "- Derive the PR title and body from what the changes actually do and why \u2014 inspect the diff/commits and the user request. Do not use the soccer-team worktree nickname or placeholder branch as the PR title."
573
587
  );
@@ -581,9 +595,13 @@ function formatWorktreeDirective(thread) {
581
595
  lines.push(
582
596
  `- A PR already exists (${thread.prUrl}). Update it (push + edit title/body if the purpose drifted) instead of opening a duplicate.`
583
597
  );
598
+ } else if (opts?.githubSlug) {
599
+ lines.push(
600
+ `- Prefer a draft PR first: \`gh pr create --draft -R ${opts.githubSlug}\` (or update via \`gh pr edit -R ${opts.githubSlug}\`) once the change set is coherent. Always pass \`-R ${opts.githubSlug}\` (this worktree's origin). Bare \`gh pr create\` may target upstream instead of origin on dual-remote checkouts. Mark ready for review only when asked. Title/body must reflect the change purpose, not the worktree name.`
601
+ );
584
602
  } else {
585
603
  lines.push(
586
- "- Prefer a draft PR first: `gh pr create --draft` (or update via `gh pr edit`) once the change set is coherent. Mark ready for review only when asked. Title/body must reflect the change purpose, not the worktree name."
604
+ "- Prefer a draft PR first: `gh pr create --draft -R <origin-owner/name>` (or update via `gh pr edit -R \u2026`) once the change set is coherent. Resolve `<origin-owner/name>` with `git remote get-url origin` in this worktree \u2014 never from `upstream`. Mark ready for review only when asked. Title/body must reflect the change purpose, not the worktree name."
587
605
  );
588
606
  }
589
607
  return lines.join("\n");
@@ -2157,15 +2175,24 @@ async function confirmLand(thread, opts) {
2157
2175
  const head = headOut.trim();
2158
2176
  const branch = head && head !== "HEAD" ? head : thread.branchName;
2159
2177
  await pushBranch(thread.worktreePath, branch);
2160
- const prUrl = await createOrUpdatePr(thread.worktreePath, {
2161
- title: meta.title,
2162
- body: meta.body,
2163
- base: preview.target,
2164
- head: branch,
2165
- draft: opts?.draft,
2166
- web: opts?.web
2167
- });
2168
- return { prUrl, pushed: true, committed };
2178
+ try {
2179
+ const prUrl = await createOrUpdatePr(thread.worktreePath, {
2180
+ title: meta.title,
2181
+ body: meta.body,
2182
+ base: preview.target,
2183
+ head: branch,
2184
+ draft: opts?.draft,
2185
+ web: opts?.web
2186
+ });
2187
+ return { prUrl, pushed: true, committed };
2188
+ } catch (err) {
2189
+ const raw = err instanceof Error ? err.message : String(err);
2190
+ if (raw.startsWith("GitHub API rate limit exceeded.")) throw err;
2191
+ if (/Command failed with exit code|API rate limit/i.test(raw)) {
2192
+ throw new Error(formatGhLandError(raw));
2193
+ }
2194
+ throw err;
2195
+ }
2169
2196
  }
2170
2197
 
2171
2198
  // src/threads/create.ts
@@ -2246,7 +2273,7 @@ async function createThread(input, onSetupLine) {
2246
2273
  return readThread(thread.id) ?? thread;
2247
2274
  }
2248
2275
  async function listLinearIssues(agent, repoPath) {
2249
- const { getAdapter: getAdapter2 } = await import("./agents-OAX7XPKX.js");
2276
+ const { getAdapter: getAdapter2 } = await import("./agents-2XMZO3CY.js");
2250
2277
  await requireAgent(agent, { requireLinear: true });
2251
2278
  const adapter = getAdapter2(agent);
2252
2279
  if (!adapter.listLinearIssues) {
@@ -2462,7 +2489,7 @@ async function adoptThread(input) {
2462
2489
  messages: input.messages ?? []
2463
2490
  });
2464
2491
  writeThread(thread);
2465
- const { ensureWorkspace: ensureWorkspace2 } = await import("./workspaces-TCJFYI35.js");
2492
+ const { ensureWorkspace: ensureWorkspace2 } = await import("./workspaces-JBWIRU55.js");
2466
2493
  await ensureWorkspace2(repoPath);
2467
2494
  return thread;
2468
2495
  }
@@ -3038,7 +3065,7 @@ var Orchestrator = class {
3038
3065
  return thread;
3039
3066
  }
3040
3067
  listWorkspaces() {
3041
- const fromThreads = listThreads({ includeArchived: true }).map((t) => t.repoPath);
3068
+ const fromThreads = listThreads({ includeArchived: false }).map((t) => t.repoPath);
3042
3069
  return syncWorkspacesFromThreads(fromThreads);
3043
3070
  }
3044
3071
  async addWorkspace(repoPath) {
@@ -3184,7 +3211,11 @@ var Orchestrator = class {
3184
3211
  }
3185
3212
  const isBrightsy = fresh.agent === "brightsy";
3186
3213
  const isOrchestration = isOrchestratorThread(fresh);
3187
- const worktreeDirective = isBrightsy || isOrchestration ? null : formatWorktreeDirective(fresh);
3214
+ const worktreeDirective = isBrightsy || isOrchestration ? null : formatWorktreeDirective(fresh, {
3215
+ githubSlug: await resolveGithubRepoSlug(fresh.worktreePath).catch(
3216
+ () => null
3217
+ )
3218
+ });
3188
3219
  const settings = loadWorkspaceSettings(fresh.worktreePath, fresh.repoPath);
3189
3220
  const { autoRenameBranchEnabled } = await import("./app-settings-BDMLWCWI.js");
3190
3221
  const renameBranchDirective = !isBrightsy && !isOrchestration && autoRenameBranchEnabled() ? formatRenameBranchDirective(fresh, {
@@ -3655,8 +3686,8 @@ var Orchestrator = class {
3655
3686
  if (result.prUrl) {
3656
3687
  const patch = { prUrl: result.prUrl };
3657
3688
  try {
3658
- const details = await getPrDetails(thread.worktreePath, result.prUrl);
3659
- if (details?.title) patch.prTitle = details.title;
3689
+ const meta = await getPrMeta(thread.worktreePath, result.prUrl);
3690
+ if (meta?.title) patch.prTitle = meta.title;
3660
3691
  } catch {
3661
3692
  }
3662
3693
  updateThread(thread.id, patch);
@@ -3689,6 +3720,24 @@ var Orchestrator = class {
3689
3720
  if (!selector) return null;
3690
3721
  return getPrChecks(cwd, selector);
3691
3722
  }
3723
+ async getPrMeta(threadRef) {
3724
+ const { thread, selector, cwd } = await this.withPrSelector(threadRef);
3725
+ if (!selector) return null;
3726
+ const meta = await getPrMeta(cwd, selector);
3727
+ if (meta) {
3728
+ const patch = {};
3729
+ if (meta.url && meta.url !== thread.prUrl) patch.prUrl = meta.url;
3730
+ if (meta.title && meta.title !== thread.prTitle) patch.prTitle = meta.title;
3731
+ if (Object.keys(patch).length > 0) {
3732
+ updateThread(thread.id, patch);
3733
+ const latest = this.requireThread(thread.id);
3734
+ if (!latest.userSetTitle && meta.title && latest.title !== meta.title) {
3735
+ updateThread(thread.id, { title: meta.title });
3736
+ }
3737
+ }
3738
+ }
3739
+ return meta;
3740
+ }
3692
3741
  async getPrDetails(threadRef) {
3693
3742
  const { thread, selector, cwd } = await this.withPrSelector(threadRef);
3694
3743
  if (!selector) return null;
@@ -3810,7 +3859,7 @@ var Orchestrator = class {
3810
3859
  return setStatus(thread.id, "idle");
3811
3860
  }
3812
3861
  if (!existsSync10(thread.worktreePath)) {
3813
- const { createThreadWorktree: createThreadWorktree2 } = await import("./worktree-NGFDN3J4.js");
3862
+ const { createThreadWorktree: createThreadWorktree2 } = await import("./worktree-TYI2SANE.js");
3814
3863
  const { execa: execa6 } = await import("execa");
3815
3864
  const slug = thread.worktreePath.split("/").pop();
3816
3865
  const dest = thread.worktreePath;
@@ -3887,7 +3936,7 @@ async function startOrchestration(opts) {
3887
3936
  sourceRef: "default",
3888
3937
  ...createOpts
3889
3938
  }).catch(async () => {
3890
- const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-NGFDN3J4.js");
3939
+ const { resolveDefaultBranch: resolveDefaultBranch2, resolveRepoRoot: resolveRepoRoot2 } = await import("./worktree-TYI2SANE.js");
3891
3940
  const repo = await resolveRepoRoot2(repoPath);
3892
3941
  const def = await resolveDefaultBranch2(repo);
3893
3942
  return createThread({
@@ -4341,7 +4390,7 @@ async function startMcpServer() {
4341
4390
  );
4342
4391
  server.tool(
4343
4392
  "create_draft_pr",
4344
- "Commit dirty changes if needed, push the thread branch, and create/update a DRAFT GitHub PR. Ready-for-review / non-draft land stays human-only (CLI/app confirm_land). Prefer this when the orchestrator should open a PR itself; alternatively send_to_thread asking the worktree agent to run `gh pr create --draft`.",
4393
+ "Commit dirty changes if needed, push the thread branch to origin, and create/update a DRAFT GitHub PR against that worktree's origin (never upstream). Ready-for-review / non-draft land stays human-only (CLI/app confirm_land). Prefer this when the orchestrator should open a PR itself; alternatively send_to_thread asking the worktree agent to run `gh pr create --draft -R <origin-owner/name>`.",
4345
4394
  { ref: z.string() },
4346
4395
  async ({ ref }) => {
4347
4396
  try {
@@ -6,8 +6,8 @@ import {
6
6
  enrichWorkspacesWithGithub,
7
7
  ensureGlobalCoordinatorCwd,
8
8
  formatWorkspaceInventory
9
- } from "./chunk-2R5VV4BA.js";
10
- import "./chunk-LL7DTZ5B.js";
9
+ } from "./chunk-SNHWAARD.js";
10
+ import "./chunk-LXHSRNJJ.js";
11
11
  import "./chunk-HYRHI3QU.js";
12
12
  import "./chunk-M37RITA6.js";
13
13
  import "./chunk-AJ6ROGD7.js";
@@ -11,9 +11,9 @@ import {
11
11
  orchestrationTitleNeedsSoccerNickname,
12
12
  orchestratorSessionPoisonedByBuiltins,
13
13
  takenTeamSlugsForOrchestration
14
- } from "./chunk-2M4OHXYX.js";
15
- import "./chunk-2R5VV4BA.js";
16
- import "./chunk-LL7DTZ5B.js";
14
+ } from "./chunk-5263JXQY.js";
15
+ import "./chunk-SNHWAARD.js";
16
+ import "./chunk-LXHSRNJJ.js";
17
17
  import "./chunk-HYRHI3QU.js";
18
18
  import {
19
19
  globalAgentCwd