@bakers-build/ui 0.11.1-next.7 → 0.11.1-next.9

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/src/ui.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type BbCommandHost, type BbCommandPlugin, type BbConnectionConfig, type WorkspaceRecoveryOptions } from '@bakers-build/core';
1
+ import { type BbCommandHost, type BbCommandPlugin, type BbConnectionConfig, createBbConnectionContext, type WorkspaceRecoveryOptions } from '@bakers-build/core';
2
2
  import { type UiInitialRoute } from './route.js';
3
3
  import { type HomeConnection } from './ui-home.js';
4
4
  /** A dropsh program (only the `parseAsync` the launcher drives). */
@@ -28,11 +28,9 @@ export interface RunBbUiOptions {
28
28
  /** BB-472 — the loaded connection config's absolute path, so the
29
29
  * workspace-picker screen can find `workspace_id`'s owning file. */
30
30
  configPath?: string | undefined;
31
- /** BB-472 — re-executes this process; the picker calls it after writing a
32
- * new workspace selection. */
33
- restartProcess?: (() => void) | undefined;
34
- /** Persist a product-workspace name through the conductor-owned contract. */
35
- selectWorkspace?: ((name: string) => Promise<void>) | undefined;
31
+ /** BB-472 — re-executes this process scoped to the picked workspace; the
32
+ * picker calls it and nothing is written. */
33
+ restartProcess?: ((workspace: string) => void) | undefined;
36
34
  buildProgram: (opts: {
37
35
  plugins: unknown[];
38
36
  }) => DropshProgram;
@@ -54,6 +52,13 @@ export interface BuildWriteClientOptions {
54
52
  stateDir?: string;
55
53
  plugins: BbConnectionConfig['plugins'];
56
54
  }
55
+ /**
56
+ * Reads a run's stored log from the download route, signed in like the client
57
+ * ('' for 204, no log). JSON:API returns `log`/`error_log` empty, so a
58
+ * read-modify-write of either needs this; any other answer throws rather than
59
+ * read as empty and let the write replace the log.
60
+ */
61
+ export declare function runLogReader(context: Pick<Awaited<ReturnType<typeof createBbConnectionContext>>, 'http' | 'auth' | 'baseUrl'>): (runId: string, kind: "log" | "error_log") => Promise<string>;
57
62
  /** Test/composition seams for `bakers ui`. */
58
63
  export interface UiDeps {
59
64
  workspaceRecovery?: WorkspaceRecoveryOptions;
@@ -86,6 +91,8 @@ export interface UiDeps {
86
91
  printConfig?: boolean;
87
92
  /** Sink for `--print-config`; default: `process.stdout.write`. */
88
93
  stdout?: (s: string) => void;
94
+ /** Re-exec seam for the workspace switch; default: `reExecUnderBun`. */
95
+ reExec?: (argv: string[]) => void;
89
96
  /** Daily update lookup; injectable for startup ordering tests. */
90
97
  updateCheck?: () => Promise<string | null>;
91
98
  /** Positional `[target]` (`BB-221`, `#19`, `ticket:…`, `project:…`, `run:…`). */
package/dist/src/ui.js CHANGED
@@ -3,7 +3,7 @@ import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import { workspacePlugin } from '@bakers-build/addon-workspace';
6
- import { CommandRunner, createBbConnectionClient, createBbConnectionContext, createLogger, exec, fetchUpdateNotice, loadReadyBbConnection, resolveCliVersion, setDefaultCommandRunner, } from '@bakers-build/core';
6
+ import { CommandRunner, createBbConnectionContext, createLogger, exec, fetchUpdateNotice, loadReadyBbConnection, resolveCliVersion, setDefaultCommandRunner, } from '@bakers-build/core';
7
7
  import { buildProgram as buildDropshProgram } from 'dropsh';
8
8
  import { applyOpentuiLibc, reExecUnderBun, resolveBunBinary, shouldReExecUnderBun, } from './bun-runtime.js';
9
9
  import { parseTarget, resolveHere, UI_VIEW_MODES, } from './route.js';
@@ -28,10 +28,32 @@ import { resolveProjectRooting } from './ui-home.js';
28
28
  * with no resolvable provider still reads.
29
29
  */
30
30
  async function buildWriteClientDefault(o) {
31
- return createBbConnectionClient({
31
+ const context = await createBbConnectionContext({
32
32
  site: { base_url: o.baseUrl, jsonapi_prefix: o.jsonapiPrefix },
33
33
  plugins: o.plugins,
34
34
  }, o.stateDir ? { stateDir: o.stateDir } : {});
35
+ return { ...context.client, runLog: runLogReader(context) };
36
+ }
37
+ /**
38
+ * Reads a run's stored log from the download route, signed in like the client
39
+ * ('' for 204, no log). JSON:API returns `log`/`error_log` empty, so a
40
+ * read-modify-write of either needs this; any other answer throws rather than
41
+ * read as empty and let the write replace the log.
42
+ */
43
+ export function runLogReader(context) {
44
+ return async (runId, kind) => {
45
+ const base = context.baseUrl.replace(/\/+$/, '');
46
+ const response = await context.http.send(await context.auth.apply({
47
+ method: 'GET',
48
+ url: `${base}/_bakers-api/run/${runId}/log/${kind}`,
49
+ headers: { 'Accept-Encoding': 'gzip' },
50
+ }));
51
+ if (response.status === 204)
52
+ return '';
53
+ if (response.status !== 200)
54
+ throw new Error(`Run ${runId} ${kind}: HTTP ${response.status}`);
55
+ return response.body;
56
+ };
35
57
  }
36
58
  /**
37
59
  * The current branch of `cwd`. Git resolves this PER WORKTREE, so
@@ -421,18 +443,20 @@ export async function cmdUi(deps = {}) {
421
443
  // reExecUnderBun step this process took to reach OpenTUI at all
422
444
  // (`shouldReExecUnderBun`, above). Absent only when the bun binary could
423
445
  // not be resolved, which already failed startup before this point.
424
- restartProcess: () => {
425
- const bin = resolveBunBinary(host.resolveBases);
426
- if (bin)
427
- reExecUnderBun(bin, process.argv);
446
+ // A pick scopes the new process through `--workspace` and writes no
447
+ // config file, so it cannot pin a workspace the project is not in.
448
+ restartProcess: (workspace) => {
449
+ const argv = process.argv.filter((arg, i, all) => arg !== '--workspace' &&
450
+ all[i - 1] !== '--workspace' &&
451
+ !arg.startsWith('--workspace='));
452
+ const reExec = deps.reExec ??
453
+ ((next) => {
454
+ const bin = resolveBunBinary(host.resolveBases);
455
+ if (bin)
456
+ reExecUnderBun(bin, next);
457
+ });
458
+ reExec([...argv, '--workspace', workspace]);
428
459
  },
429
- ...(conductorPath && host.projectContext
430
- ? {
431
- selectWorkspace: async (name) => {
432
- await host.projectContext?.writeWorkspace(conductorPath, name);
433
- },
434
- }
435
- : {}),
436
460
  // The plugins are real constructed `DropSHPlugin[]` now (core built them),
437
461
  // matching dropsh's declared contract — F3's substance, a descriptor handed
438
462
  // to an API expecting instances, is gone. The two casts that remain are
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/ui",
3
- "version": "0.11.1-next.7",
3
+ "version": "0.11.1-next.9",
4
4
  "description": "bakers.build project-first cockpit: the `bakers ui` command plugin (renderer resolved dynamically).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,13 +26,13 @@
26
26
  "directory": "bakers-cli/ui"
27
27
  },
28
28
  "dependencies": {
29
- "@bakers-build/core": "^0.11.1-next.7",
30
- "@bakers-build/addon-workspace": "^0.11.1-next.7",
29
+ "@bakers-build/core": "^0.11.1-next.9",
30
+ "@bakers-build/addon-workspace": "^0.11.1-next.9",
31
31
  "commander": "^12.1.0",
32
32
  "dropsh": "^0.8.2"
33
33
  },
34
34
  "bakersBuild": {
35
- "commit": "9f305d0873788b79f7af9e8eb650eb4115fa72d6",
35
+ "commit": "4c0c7ffab0be833fb9cbb50b0784a949593f08e6",
36
36
  "channel": "next"
37
37
  }
38
38
  }