@bakers-build/addon-orca 0.6.1-next.6 → 0.6.1-next.7
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/config.d.ts +3 -9
- package/dist/src/index.d.ts +16 -10
- package/dist/src/index.js +46 -103
- package/dist/src/preset.js +1 -1
- package/dist/src/workspace.d.ts +9 -17
- package/dist/src/workspace.js +71 -57
- package/package.json +6 -6
package/dist/src/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RootGitExec } from '@bakers-build/core';
|
|
2
|
+
import type { OrcaOpenLayout } from './workspace.js';
|
|
2
3
|
export interface OrcaStateConfig {
|
|
3
4
|
/**
|
|
4
5
|
* Terminal title template; must contain `{identifier}`. Other vars:
|
|
@@ -11,15 +12,8 @@ export interface OrcaStateConfig {
|
|
|
11
12
|
export interface OrcaExecutorOptions {
|
|
12
13
|
/** Fallback agent command when the conductor supplies none. */
|
|
13
14
|
command?: string;
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
after_create?: string;
|
|
17
|
-
before_run?: string;
|
|
18
|
-
after_run?: string;
|
|
19
|
-
after_done?: string;
|
|
20
|
-
on_freeze?: string;
|
|
21
|
-
on_resume?: string;
|
|
22
|
-
};
|
|
15
|
+
/** Overview terminal of a fresh worktree. Unset → `DEFAULT_OPEN_LAYOUT`. */
|
|
16
|
+
open?: OrcaOpenLayout;
|
|
23
17
|
/** Main clone; otherwise derived from the git common dir by the factory. */
|
|
24
18
|
root?: string;
|
|
25
19
|
/** Overrideable git exec for root derivation (tests). */
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type { BbExecutor, ExecutorCapabilities, ExecutorPlugin,
|
|
1
|
+
import type { BbExecutor, ExecutorCapabilities, ExecutorPlugin, OpenWorkspaceContext, SpawnedSession, SpawnRunInput } from '@bakers-build/conductor/contract';
|
|
2
2
|
import type { ConductorLogger } from '@bakers-build/core';
|
|
3
3
|
import { type OrcaExecutorOptions } from './config.js';
|
|
4
4
|
import { type OrcaExec } from './orca-cli.js';
|
|
5
|
-
import { type
|
|
5
|
+
import { type Sleep } from './workspace.js';
|
|
6
6
|
export type { OrcaExecutorOptions } from './config.js';
|
|
7
7
|
export { OrcaError, type OrcaExec } from './orca-cli.js';
|
|
8
8
|
export { type OrcaOpenLayout, OrcaWorkspace, type OrcaWorkspaceOptions, orcaWorkspace, } from './workspace.js';
|
|
9
|
-
/** Runs a lifecycle-hook shell command in a cwd; rejects on non-zero exit. */
|
|
10
|
-
export type ShellRunner = (command: string, cwd: string, env?: Record<string, string>) => Promise<void>;
|
|
11
9
|
/**
|
|
12
10
|
* Executor hosting each run's agent in an Orca terminal of the ticket's
|
|
13
11
|
* worktree. Terminal handles do not survive an Orca restart, so none is kept
|
|
@@ -18,14 +16,10 @@ export declare class OrcaExecutor implements BbExecutor {
|
|
|
18
16
|
private readonly options;
|
|
19
17
|
private readonly execOrca;
|
|
20
18
|
private readonly logger;
|
|
21
|
-
private readonly runShell;
|
|
22
|
-
private readonly execGit;
|
|
23
19
|
private readonly sleep;
|
|
24
20
|
readonly id = "orca";
|
|
25
|
-
constructor(options: OrcaExecutorOptions, execOrca?: OrcaExec, logger?: ConductorLogger,
|
|
21
|
+
constructor(options: OrcaExecutorOptions, execOrca?: OrcaExec, logger?: ConductorLogger, sleep?: Sleep);
|
|
26
22
|
capabilities(): ExecutorCapabilities;
|
|
27
|
-
/** The single best-effort catch point for lifecycle hooks; never throws. */
|
|
28
|
-
runHook(name: HookName, cwd: string, ctx: HookContext, env?: Record<string, string>): Promise<HookResult>;
|
|
29
23
|
startRun(input: SpawnRunInput): Promise<SpawnedSession>;
|
|
30
24
|
private readTail;
|
|
31
25
|
/** Best-effort: a live or unverifiable stop must not abort the caller. */
|
|
@@ -37,7 +31,19 @@ export declare class OrcaExecutor implements BbExecutor {
|
|
|
37
31
|
stopRun(_branch: string): Promise<void>;
|
|
38
32
|
/** Close every terminal of this run on this branch; best-effort throughout. */
|
|
39
33
|
cleanupRun(branch: string, runId: number): Promise<void>;
|
|
40
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Open the ticket overview terminal of a freshly created worktree (the
|
|
36
|
+
* conductor calls this only on create). The worktree may come from any
|
|
37
|
+
* workspace: Orca adopts it first. Best-effort: a failure is logged, never
|
|
38
|
+
* thrown, so it cannot wedge dispatch.
|
|
39
|
+
*/
|
|
40
|
+
openWorkspace(path: string, ctx: OpenWorkspaceContext): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Make Orca resolve `path` as a worktree: register the repo (so a worktree
|
|
43
|
+
* made by any workspace, not only Orca's, becomes visible), then wait for
|
|
44
|
+
* Orca's rescan to adopt it.
|
|
45
|
+
*/
|
|
46
|
+
private adopt;
|
|
41
47
|
private commandFor;
|
|
42
48
|
}
|
|
43
49
|
export declare function orcaExecutor(options?: OrcaExecutorOptions): ExecutorPlugin;
|
package/dist/src/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { renderTemplate,
|
|
3
|
-
import { deriveCheckoutRoot,
|
|
1
|
+
import { rmSync } from 'node:fs';
|
|
2
|
+
import { renderTemplate, truncateOpenTabTitle, watchLaunch, writeLaunchScript, } from '@bakers-build/addon-herdr/shared';
|
|
3
|
+
import { deriveCheckoutRoot, shellQuote, slugify } from '@bakers-build/core';
|
|
4
4
|
import { resolveTabLabel } from './config.js';
|
|
5
5
|
import { assertOrcaReachable, createOrcaExec, isRecord, } from './orca-cli.js';
|
|
6
|
-
import { DEFAULT_ADOPT_TIMEOUT_MS, defaultSleep, noopLogger,
|
|
6
|
+
import { DEFAULT_ADOPT_TIMEOUT_MS, DEFAULT_OPEN_LAYOUT, defaultSleep, noopLogger, registerRepo, waitForAdoption, } from './workspace.js';
|
|
7
7
|
export { OrcaError } from './orca-cli.js';
|
|
8
8
|
export { OrcaWorkspace, orcaWorkspace, } from './workspace.js';
|
|
9
|
-
const defaultShellRunner = async (command, cwd, env) => {
|
|
10
|
-
await exec('sh', ['-c', command], { cwd, ...(env ? { env } : {}) });
|
|
11
|
-
};
|
|
12
9
|
/** Exact trailing `#<runId>` token, so `#7` never matches `#77`. */
|
|
13
10
|
function titleMatchesRun(title, runId) {
|
|
14
11
|
if (typeof title !== 'string')
|
|
@@ -40,9 +37,6 @@ function visualTabTitles(layouts) {
|
|
|
40
37
|
}
|
|
41
38
|
return titles;
|
|
42
39
|
}
|
|
43
|
-
function normPath(path) {
|
|
44
|
-
return path.replace(/\/+$/, '');
|
|
45
|
-
}
|
|
46
40
|
/**
|
|
47
41
|
* Executor hosting each run's agent in an Orca terminal of the ticket's
|
|
48
42
|
* worktree. Terminal handles do not survive an Orca restart, so none is kept
|
|
@@ -53,40 +47,20 @@ export class OrcaExecutor {
|
|
|
53
47
|
options;
|
|
54
48
|
execOrca;
|
|
55
49
|
logger;
|
|
56
|
-
runShell;
|
|
57
|
-
execGit;
|
|
58
50
|
sleep;
|
|
59
51
|
id = 'orca';
|
|
60
|
-
constructor(options, execOrca = createOrcaExec(), logger = noopLogger,
|
|
52
|
+
constructor(options, execOrca = createOrcaExec(), logger = noopLogger, sleep = defaultSleep) {
|
|
61
53
|
this.options = options;
|
|
62
54
|
this.execOrca = execOrca;
|
|
63
55
|
this.logger = logger;
|
|
64
|
-
this.runShell = runShell;
|
|
65
|
-
this.execGit = execGit;
|
|
66
56
|
this.sleep = sleep;
|
|
67
57
|
}
|
|
68
58
|
capabilities() {
|
|
69
59
|
return { persistent: true };
|
|
70
60
|
}
|
|
71
|
-
/** The single best-effort catch point for lifecycle hooks; never throws. */
|
|
72
|
-
async runHook(name, cwd, ctx, env) {
|
|
73
|
-
const command = this.options.hooks?.[name];
|
|
74
|
-
if (!command) {
|
|
75
|
-
return { hook: name, ran: false, ok: true };
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
await this.runShell(command, cwd, env);
|
|
79
|
-
return { hook: name, ran: true, ok: true };
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
this.logger.error({ hook: name, worktree: cwd, ticket: ctx.ticket, err: String(err) }, 'lifecycle hook failed');
|
|
83
|
-
return { hook: name, ran: true, ok: false, error: String(err) };
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
61
|
async startRun(input) {
|
|
87
62
|
const tabLabel = resolveTabLabel(this.options, input.ticket.state);
|
|
88
|
-
await
|
|
89
|
-
await waitForAdoption(this.execOrca, input.workspacePath, this.options.adoptTimeoutMs ?? DEFAULT_ADOPT_TIMEOUT_MS, this.sleep);
|
|
63
|
+
await this.adopt(input.workspacePath);
|
|
90
64
|
const title = `${renderTemplate(tabLabel, {
|
|
91
65
|
identifier: input.ticket.identifier,
|
|
92
66
|
state: input.ticket.state,
|
|
@@ -214,85 +188,55 @@ export class OrcaExecutor {
|
|
|
214
188
|
this.logger.warn({ branch, runId }, 'no orca terminal found for this run; its agent may still be running');
|
|
215
189
|
}
|
|
216
190
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
entries = porcelainEntries(await this.execGit(['-C', gitDir, 'worktree', 'list', '--porcelain'])).slice(1);
|
|
229
|
-
}
|
|
230
|
-
catch {
|
|
231
|
-
// Degrade to the on-disk answer below.
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
const path = worktreePath
|
|
235
|
-
? normPath(worktreePath)
|
|
236
|
-
: entries.find((e) => e.branch === branch)?.path;
|
|
237
|
-
if (!path) {
|
|
238
|
-
return 'unverified';
|
|
191
|
+
/**
|
|
192
|
+
* Open the ticket overview terminal of a freshly created worktree (the
|
|
193
|
+
* conductor calls this only on create). The worktree may come from any
|
|
194
|
+
* workspace: Orca adopts it first. Best-effort: a failure is logged, never
|
|
195
|
+
* thrown, so it cannot wedge dispatch.
|
|
196
|
+
*/
|
|
197
|
+
async openWorkspace(path, ctx) {
|
|
198
|
+
// `??`, not `||`: an explicit `open: {}` must survive as the opt-out.
|
|
199
|
+
const open = this.options.open ?? DEFAULT_OPEN_LAYOUT;
|
|
200
|
+
if (open.command === undefined) {
|
|
201
|
+
return;
|
|
239
202
|
}
|
|
240
|
-
const
|
|
241
|
-
|
|
203
|
+
const vars = {
|
|
204
|
+
identifier: ctx.identifier,
|
|
205
|
+
branch: ctx.branch,
|
|
206
|
+
title: ctx.title,
|
|
207
|
+
worktreePath: path,
|
|
208
|
+
};
|
|
242
209
|
try {
|
|
243
|
-
await
|
|
244
|
-
await this.execOrca(['worktree', 'show', '--worktree', `path:${path}`]);
|
|
245
|
-
orcaKnows = true;
|
|
246
|
-
}
|
|
247
|
-
catch {
|
|
248
|
-
// Orca is down or never adopted it: tear down with git alone.
|
|
249
|
-
}
|
|
250
|
-
// Drupal hardens web/sites/default (0555): restore owner-write first.
|
|
251
|
-
restoreWritable(path);
|
|
252
|
-
if (orcaKnows) {
|
|
210
|
+
await this.adopt(path);
|
|
253
211
|
await this.execOrca([
|
|
254
|
-
'
|
|
255
|
-
'
|
|
212
|
+
'terminal',
|
|
213
|
+
'create',
|
|
256
214
|
'--worktree',
|
|
257
215
|
`path:${path}`,
|
|
258
|
-
'--
|
|
216
|
+
'--title',
|
|
217
|
+
renderTemplate(open.title ?? '{identifier} · {title}', {
|
|
218
|
+
...vars,
|
|
219
|
+
title: truncateOpenTabTitle(ctx.title),
|
|
220
|
+
}),
|
|
221
|
+
'--command',
|
|
222
|
+
renderTemplate(open.command, vars),
|
|
259
223
|
]);
|
|
260
224
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return 'already_absent';
|
|
264
|
-
}
|
|
265
|
-
if (registered) {
|
|
266
|
-
try {
|
|
267
|
-
await this.execGit([
|
|
268
|
-
'-C',
|
|
269
|
-
gitDir,
|
|
270
|
-
'worktree',
|
|
271
|
-
'remove',
|
|
272
|
-
'--force',
|
|
273
|
-
path,
|
|
274
|
-
]);
|
|
275
|
-
}
|
|
276
|
-
catch (err) {
|
|
277
|
-
this.logger.warn({ path, err: String(err) }, 'git worktree remove failed on a registered worktree');
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
try {
|
|
281
|
-
rmSync(path, { recursive: true, force: true });
|
|
282
|
-
}
|
|
283
|
-
catch (err) {
|
|
284
|
-
this.logger.warn({ path, err: String(err) }, 'worktree directory reclaim failed');
|
|
285
|
-
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
this.logger.warn({ branch: ctx.branch, worktree: path, err: String(err) }, 'orca overview terminal failed (best-effort, ignored)');
|
|
286
227
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Make Orca resolve `path` as a worktree: register the repo (so a worktree
|
|
231
|
+
* made by any workspace, not only Orca's, becomes visible), then wait for
|
|
232
|
+
* Orca's rescan to adopt it.
|
|
233
|
+
*/
|
|
234
|
+
async adopt(path) {
|
|
235
|
+
await assertOrcaReachable(this.execOrca);
|
|
236
|
+
if (this.options.root) {
|
|
237
|
+
await registerRepo(this.execOrca, this.options.root);
|
|
294
238
|
}
|
|
295
|
-
|
|
239
|
+
await waitForAdoption(this.execOrca, path, this.options.adoptTimeoutMs ?? DEFAULT_ADOPT_TIMEOUT_MS, this.sleep);
|
|
296
240
|
}
|
|
297
241
|
commandFor(input) {
|
|
298
242
|
const env = Object.entries(input.env ?? {}).map(([key, value]) => {
|
|
@@ -319,7 +263,6 @@ export function orcaExecutor(options = {}) {
|
|
|
319
263
|
...options,
|
|
320
264
|
command: options.command ?? 'claude',
|
|
321
265
|
root,
|
|
322
|
-
...(config.hooks ? { hooks: config.hooks } : {}),
|
|
323
266
|
}, createOrcaExec(), deps.logger);
|
|
324
267
|
},
|
|
325
268
|
};
|
package/dist/src/preset.js
CHANGED
package/dist/src/workspace.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BbWorkspace, EnsuredWorkspace, WorkspacePlugin } from '@bakers-build/conductor/contract';
|
|
1
|
+
import type { BbWorkspace, EnsuredWorkspace, WorkspacePlugin, WorktreeTeardown } from '@bakers-build/conductor/contract';
|
|
2
2
|
import type { ConductorLogger, RootGitExec } from '@bakers-build/core';
|
|
3
3
|
import { type OrcaExec } from './orca-cli.js';
|
|
4
4
|
export type GitExec = (args: string[]) => Promise<string>;
|
|
@@ -22,6 +22,8 @@ export declare const noopLogger: ConductorLogger;
|
|
|
22
22
|
* 30 s, so a fresh worktree is `selector_not_found` for a while.
|
|
23
23
|
*/
|
|
24
24
|
export declare function waitForAdoption(orca: OrcaExec, path: string, timeoutMs: number, sleep: Sleep): Promise<void>;
|
|
25
|
+
/** Register `root` with Orca once and make its git worktrees visible. */
|
|
26
|
+
export declare function registerRepo(orca: OrcaExec, root: string): Promise<void>;
|
|
25
27
|
/** `git worktree list --porcelain` records; the main checkout comes first. */
|
|
26
28
|
export declare function porcelainEntries(output: string): {
|
|
27
29
|
path: string;
|
|
@@ -34,8 +36,6 @@ export interface OrcaWorkspaceOptions {
|
|
|
34
36
|
worktreeDir?: string;
|
|
35
37
|
/** Base ref for new branches. Default: the upstream of the root's HEAD. */
|
|
36
38
|
baseBranch?: string;
|
|
37
|
-
/** Overview terminal of a fresh worktree. Unset → {@link DEFAULT_OPEN_LAYOUT}. */
|
|
38
|
-
open?: OrcaOpenLayout;
|
|
39
39
|
adoptTimeoutMs?: number;
|
|
40
40
|
execOrca?: OrcaExec;
|
|
41
41
|
execGit?: GitExec;
|
|
@@ -58,36 +58,28 @@ export declare class OrcaWorkspace implements BbWorkspace {
|
|
|
58
58
|
private readonly root;
|
|
59
59
|
private readonly execOrca;
|
|
60
60
|
private readonly execGit;
|
|
61
|
-
private readonly open;
|
|
62
61
|
private readonly logger;
|
|
63
62
|
private readonly sleep;
|
|
64
|
-
/** Fresh worktrees awaiting {@link applyOpenLayout}; one-shot. */
|
|
65
|
-
private readonly pendingOpen;
|
|
66
63
|
constructor(options: OrcaWorkspaceOptions);
|
|
67
64
|
ensure(_identifier: string, branch?: string, baseRefOverride?: string): Promise<EnsuredWorkspace>;
|
|
68
|
-
/** Register the root with Orca once and make its git worktrees visible. */
|
|
69
|
-
private registerRepo;
|
|
70
65
|
private isRegisteredWorktree;
|
|
71
66
|
private refExists;
|
|
72
67
|
/** Check out the ticket branch as it is — never reset (`-B`) or renamed. */
|
|
73
68
|
private addWorktree;
|
|
74
69
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
70
|
+
* Tear down the ticket worktree: through Orca when it knows the worktree
|
|
71
|
+
* (`orca worktree rm`), otherwise with git alone ({@link removeGitWorktree}),
|
|
72
|
+
* which also refuses the main checkout.
|
|
78
73
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
title: string;
|
|
83
|
-
}): Promise<void>;
|
|
74
|
+
remove(branch: string, worktreePath?: string): Promise<WorktreeTeardown>;
|
|
75
|
+
private orcaKnows;
|
|
76
|
+
private pathOfBranch;
|
|
84
77
|
}
|
|
85
78
|
export declare function orcaWorkspace(opts?: {
|
|
86
79
|
/** Explicit repo-root override; otherwise derived from the git common dir. */
|
|
87
80
|
root?: string;
|
|
88
81
|
worktreeDir?: string;
|
|
89
82
|
baseBranch?: string;
|
|
90
|
-
open?: OrcaOpenLayout;
|
|
91
83
|
adoptTimeoutMs?: number;
|
|
92
84
|
autoSetupMerge?: boolean;
|
|
93
85
|
/** Overrideable git exec for root derivation (tests). */
|
package/dist/src/workspace.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import { loadInstructions, runBranchGit, } from '@bakers-build/addon-workspace-git';
|
|
3
|
+
import { resolveBaseRef, restoreWritable, validateBranch, } from '@bakers-build/addon-herdr/shared';
|
|
4
|
+
import { loadInstructions, removeGitWorktree, runBranchGit, } from '@bakers-build/addon-workspace-git';
|
|
5
5
|
import { deriveCheckoutRoot, exec } from '@bakers-build/core';
|
|
6
6
|
import { assertOrcaReachable, createOrcaExec, isRecord, OrcaError, } from './orca-cli.js';
|
|
7
|
+
function normPath(path) {
|
|
8
|
+
return path.replace(/\/+$/, '');
|
|
9
|
+
}
|
|
7
10
|
export const DEFAULT_OPEN_LAYOUT = {
|
|
8
11
|
command: 'bakers ui --ticket {identifier}',
|
|
9
12
|
title: '{identifier} · {title}',
|
|
@@ -40,6 +43,24 @@ export async function waitForAdoption(orca, path, timeoutMs, sleep) {
|
|
|
40
43
|
}
|
|
41
44
|
throw new Error(`Orca did not pick up worktree ${path} within ${Math.round(timeoutMs / 1000)}s`);
|
|
42
45
|
}
|
|
46
|
+
/** Register `root` with Orca once and make its git worktrees visible. */
|
|
47
|
+
export async function registerRepo(orca, root) {
|
|
48
|
+
const listed = await orca(['repo', 'list']);
|
|
49
|
+
const repos = isRecord(listed) && Array.isArray(listed.repos) ? listed.repos : [];
|
|
50
|
+
const known = repos.some((r) => isRecord(r) && typeof r.path === 'string' && resolve(r.path) === root);
|
|
51
|
+
if (!known) {
|
|
52
|
+
await orca(['repo', 'add', '--path', root]);
|
|
53
|
+
}
|
|
54
|
+
// Idempotent; without it Orca's sidebar hides worktrees it did not create.
|
|
55
|
+
await orca([
|
|
56
|
+
'repo',
|
|
57
|
+
'set',
|
|
58
|
+
'--repo',
|
|
59
|
+
`path:${root}`,
|
|
60
|
+
'--external-worktree-visibility',
|
|
61
|
+
'show',
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
43
64
|
/** `git worktree list --porcelain` records; the main checkout comes first. */
|
|
44
65
|
export function porcelainEntries(output) {
|
|
45
66
|
return output
|
|
@@ -70,18 +91,13 @@ export class OrcaWorkspace {
|
|
|
70
91
|
root;
|
|
71
92
|
execOrca;
|
|
72
93
|
execGit;
|
|
73
|
-
open;
|
|
74
94
|
logger;
|
|
75
95
|
sleep;
|
|
76
|
-
/** Fresh worktrees awaiting {@link applyOpenLayout}; one-shot. */
|
|
77
|
-
pendingOpen = new Set();
|
|
78
96
|
constructor(options) {
|
|
79
97
|
this.options = options;
|
|
80
98
|
this.root = resolve(options.root);
|
|
81
99
|
this.execOrca = options.execOrca ?? createOrcaExec();
|
|
82
100
|
this.execGit = options.execGit ?? ((args) => exec('git', args));
|
|
83
|
-
// `??`, not `||`: an explicit `open: {}` must survive as the opt-out.
|
|
84
|
-
this.open = options.open ?? DEFAULT_OPEN_LAYOUT;
|
|
85
101
|
this.logger = options.logger ?? noopLogger;
|
|
86
102
|
this.sleep = options.sleep ?? defaultSleep;
|
|
87
103
|
}
|
|
@@ -94,38 +110,15 @@ export class OrcaWorkspace {
|
|
|
94
110
|
? {}
|
|
95
111
|
: { env: await runBranchGit(this.root, this.logger) };
|
|
96
112
|
await assertOrcaReachable(this.execOrca);
|
|
97
|
-
await this.
|
|
113
|
+
await registerRepo(this.execOrca, this.root);
|
|
98
114
|
const path = resolve(this.root, this.options.worktreeDir ?? '.bakers-worktrees', branch);
|
|
99
115
|
const created = !(await this.isRegisteredWorktree(path));
|
|
100
116
|
if (created) {
|
|
101
117
|
await this.addWorktree(branch, path, baseRefOverride);
|
|
102
118
|
}
|
|
103
119
|
await waitForAdoption(this.execOrca, path, this.options.adoptTimeoutMs ?? DEFAULT_ADOPT_TIMEOUT_MS, this.sleep);
|
|
104
|
-
if (created) {
|
|
105
|
-
this.pendingOpen.add(path);
|
|
106
|
-
}
|
|
107
120
|
return { path, instructions: loadInstructions(path), created, ...extra };
|
|
108
121
|
}
|
|
109
|
-
/** Register the root with Orca once and make its git worktrees visible. */
|
|
110
|
-
async registerRepo() {
|
|
111
|
-
const listed = await this.execOrca(['repo', 'list']);
|
|
112
|
-
const repos = isRecord(listed) && Array.isArray(listed.repos) ? listed.repos : [];
|
|
113
|
-
const known = repos.some((r) => isRecord(r) &&
|
|
114
|
-
typeof r.path === 'string' &&
|
|
115
|
-
resolve(r.path) === this.root);
|
|
116
|
-
if (!known) {
|
|
117
|
-
await this.execOrca(['repo', 'add', '--path', this.root]);
|
|
118
|
-
}
|
|
119
|
-
// Idempotent; without it Orca's sidebar hides worktrees it did not create.
|
|
120
|
-
await this.execOrca([
|
|
121
|
-
'repo',
|
|
122
|
-
'set',
|
|
123
|
-
'--repo',
|
|
124
|
-
`path:${this.root}`,
|
|
125
|
-
'--external-worktree-visibility',
|
|
126
|
-
'show',
|
|
127
|
-
]);
|
|
128
|
-
}
|
|
129
122
|
async isRegisteredWorktree(path) {
|
|
130
123
|
const output = await this.execGit([
|
|
131
124
|
'-C',
|
|
@@ -185,37 +178,59 @@ export class OrcaWorkspace {
|
|
|
185
178
|
await this.execGit([...add, '-b', branch, path, ...(base ? [base] : [])]);
|
|
186
179
|
}
|
|
187
180
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
181
|
+
* Tear down the ticket worktree: through Orca when it knows the worktree
|
|
182
|
+
* (`orca worktree rm`), otherwise with git alone ({@link removeGitWorktree}),
|
|
183
|
+
* which also refuses the main checkout.
|
|
191
184
|
*/
|
|
192
|
-
async
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
title: ctx.title,
|
|
200
|
-
worktreePath: path,
|
|
201
|
-
};
|
|
202
|
-
try {
|
|
185
|
+
async remove(branch, worktreePath) {
|
|
186
|
+
const path = worktreePath
|
|
187
|
+
? normPath(worktreePath)
|
|
188
|
+
: await this.pathOfBranch(branch);
|
|
189
|
+
if (path && path !== this.root && (await this.orcaKnows(path))) {
|
|
190
|
+
// Drupal hardens web/sites/default (0555): restore owner-write first.
|
|
191
|
+
restoreWritable(path);
|
|
203
192
|
await this.execOrca([
|
|
204
|
-
'
|
|
205
|
-
'
|
|
193
|
+
'worktree',
|
|
194
|
+
'rm',
|
|
206
195
|
'--worktree',
|
|
207
196
|
`path:${path}`,
|
|
208
|
-
'--
|
|
209
|
-
renderTemplate(this.open.title ?? '{identifier} · {title}', {
|
|
210
|
-
...vars,
|
|
211
|
-
title: truncateOpenTabTitle(ctx.title),
|
|
212
|
-
}),
|
|
213
|
-
'--command',
|
|
214
|
-
renderTemplate(this.open.command, vars),
|
|
197
|
+
'--force',
|
|
215
198
|
]);
|
|
199
|
+
try {
|
|
200
|
+
await this.execGit(['-C', this.root, 'worktree', 'prune']);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
// best-effort sweep
|
|
204
|
+
}
|
|
205
|
+
return existsSync(path) ? 'unverified' : 'removed';
|
|
216
206
|
}
|
|
217
|
-
|
|
218
|
-
|
|
207
|
+
return removeGitWorktree(this.root, branch, worktreePath, (args, cwd) => this.execGit(['-C', cwd, ...args]), this.logger);
|
|
208
|
+
}
|
|
209
|
+
async orcaKnows(path) {
|
|
210
|
+
try {
|
|
211
|
+
await assertOrcaReachable(this.execOrca);
|
|
212
|
+
await this.execOrca(['worktree', 'show', '--worktree', `path:${path}`]);
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
// Orca is down or never adopted it: tear down with git alone.
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async pathOfBranch(branch) {
|
|
221
|
+
try {
|
|
222
|
+
return porcelainEntries(await this.execGit([
|
|
223
|
+
'-C',
|
|
224
|
+
this.root,
|
|
225
|
+
'worktree',
|
|
226
|
+
'list',
|
|
227
|
+
'--porcelain',
|
|
228
|
+
]))
|
|
229
|
+
.slice(1)
|
|
230
|
+
.find((e) => e.branch === branch)?.path;
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return undefined;
|
|
219
234
|
}
|
|
220
235
|
}
|
|
221
236
|
}
|
|
@@ -233,7 +248,6 @@ export function orcaWorkspace(opts = {}) {
|
|
|
233
248
|
root,
|
|
234
249
|
...(opts.worktreeDir ? { worktreeDir: opts.worktreeDir } : {}),
|
|
235
250
|
...(opts.baseBranch ? { baseBranch: opts.baseBranch } : {}),
|
|
236
|
-
...(opts.open ? { open: opts.open } : {}),
|
|
237
251
|
...(opts.adoptTimeoutMs !== undefined
|
|
238
252
|
? { adoptTimeoutMs: opts.adoptTimeoutMs }
|
|
239
253
|
: {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/addon-orca",
|
|
3
|
-
"version": "0.6.1-next.
|
|
3
|
+
"version": "0.6.1-next.7",
|
|
4
4
|
"description": "bakers.build Orca integration: executor + per-ticket worktree workspace hosted in Orca.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"directory": "bakers-cli/addons/orca"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@bakers-build/addon-herdr": "^0.6.1-next.
|
|
24
|
-
"@bakers-build/addon-workspace-git": "^0.6.1-next.
|
|
23
|
+
"@bakers-build/addon-herdr": "^0.6.1-next.7",
|
|
24
|
+
"@bakers-build/addon-workspace-git": "^0.6.1-next.7"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@bakers-build/conductor": "^0.6.1-next.
|
|
28
|
-
"@bakers-build/core": "^0.6.1-next.
|
|
27
|
+
"@bakers-build/conductor": "^0.6.1-next.7",
|
|
28
|
+
"@bakers-build/core": "^0.6.1-next.7"
|
|
29
29
|
},
|
|
30
30
|
"bakersBuild": {
|
|
31
|
-
"commit": "
|
|
31
|
+
"commit": "b89398b187bf51f4f9ca5bfc1150469f73a879e6",
|
|
32
32
|
"channel": "next"
|
|
33
33
|
}
|
|
34
34
|
}
|