@bakers-build/conductor 0.8.1-next.4 → 0.8.1-next.6
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.js +4 -1
- package/dist/src/contract.d.ts +1 -1
- package/dist/src/core/conductor.js +41 -13
- package/dist/src/core/start-hooks.d.ts +3 -0
- package/dist/src/core/start-hooks.js +58 -0
- package/dist/src/plugins/executor.d.ts +11 -0
- package/dist/src/plugins/remote.d.ts +3 -2
- package/dist/src/types.d.ts +1 -0
- package/package.json +4 -4
- package/dist/src/core/required-skills.d.ts +0 -7
- package/dist/src/core/required-skills.js +0 -157
package/dist/src/config.js
CHANGED
|
@@ -144,7 +144,7 @@ function validateHookListeners(value) {
|
|
|
144
144
|
for (const [index, listener] of value.entries()) {
|
|
145
145
|
if (!isRecord(listener))
|
|
146
146
|
throw new Error(`hooks[${index}] must be a listener object`);
|
|
147
|
-
for (const slot of HOOK_SLOTS) {
|
|
147
|
+
for (const slot of [...HOOK_SLOTS, 'before_conductor_start']) {
|
|
148
148
|
if (listener[slot] !== undefined && typeof listener[slot] !== 'function')
|
|
149
149
|
throw new Error(`hooks[${index}].${slot} must be a function`);
|
|
150
150
|
}
|
|
@@ -520,6 +520,9 @@ export async function loadConductorConfig(configFile) {
|
|
|
520
520
|
...(config.hooks?.provision_up !== undefined ? { provisioning } : {}),
|
|
521
521
|
bakers,
|
|
522
522
|
...identityOf(machineCtx, project, variant),
|
|
523
|
+
...(machineCtx.connection_url !== undefined
|
|
524
|
+
? { connection_url: machineCtx.connection_url }
|
|
525
|
+
: {}),
|
|
523
526
|
variant,
|
|
524
527
|
project,
|
|
525
528
|
states,
|
package/dist/src/contract.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { AmbiguousProjectNameError, type ResolvedBbProjectContext, resolveBbProj
|
|
|
2
2
|
export { type AgentFootprint, type AgentRunIdentity, type BbAgent, CONDUCTOR_TOKEN_ENV, CONDUCTOR_TOOLS_SERVER, CONDUCTOR_URL_ENV, DEFAULT_ENV_DENY, emptyAgentFootprint, matchesEnvDeny, type PluginLaunch, type RunEnvPolicy, } from './plugins/agent.js';
|
|
3
3
|
export { detectKnownOverrides, type KnownOptionSpec, type KnownOverrides, type KnownScalarKind, type ResolvedSecurity, resolveAgentCliOptions, resolveSecurityOptions, type SandboxOptions, SECURITY_MODES, type SecurityMode, type SecurityOptions, type SecurityReport, SHARED_SECURITY_KEY, type SharedListKey, type SharedSecurity, validateAgentArgs, validateOptionalBoolean, validateOptionalString, validateSharedSecurity, } from './plugins/agent-args.js';
|
|
4
4
|
export { ensureHome, homeKey, homePath, type MarketplaceDeclaration, validateMarketplaces, } from './plugins/agent-home.js';
|
|
5
|
-
export type { BbExecutor, ExecutorCapabilities, HookContext, HookListener, HookListenerContext, HookListenerFn, HookName, HookResult, OpenWorkspaceContext, SpawnedSession, SpawnRunInput, WorktreeTeardown, } from './plugins/executor.js';
|
|
5
|
+
export type { BbExecutor, ConductorStartContext, ExecutorCapabilities, HookContext, HookListener, HookListenerContext, HookListenerFn, HookName, HookResult, MachineRegistrationData, OpenWorkspaceContext, SpawnedSession, SpawnRunInput, WorktreeTeardown, } from './plugins/executor.js';
|
|
6
6
|
export type { DiscoveredInbox, InboxBinding, InboxMessageHandler, InboxMessageRequest, InboxMessages, LoadedInbox, } from './plugins/message.js';
|
|
7
7
|
export { loadInbox, validateRequestPayload, } from './plugins/message.js';
|
|
8
8
|
export type { AgentCandidate, AgentPlugin, ExecutorDeps, ExecutorPlugin, RemotePlugin, ResolvedAgent, WorkspacePlugin, } from './plugins/plugins.js';
|
|
@@ -11,7 +11,7 @@ import { attemptFamily } from './attempt.js';
|
|
|
11
11
|
import { shellHookRunner } from './hook-runner.js';
|
|
12
12
|
import { InboxRuntime, runInbox } from './inbox-runtime.js';
|
|
13
13
|
import { measureMrChanges, mrChangesRows } from './mr-changes.js';
|
|
14
|
-
import {
|
|
14
|
+
import { runStartHooks } from './start-hooks.js';
|
|
15
15
|
import { startToolServer } from './tool-server.js';
|
|
16
16
|
import { signalUi } from './ui-signal.js';
|
|
17
17
|
function sleep(ms, signal) {
|
|
@@ -338,7 +338,44 @@ export class Conductor {
|
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
async start() {
|
|
341
|
-
|
|
341
|
+
const registration = this.registration();
|
|
342
|
+
const machine = this.ownsServeProcess
|
|
343
|
+
? await runStartHooks(this.config.hookListeners ?? [], {
|
|
344
|
+
...(registration.host_key !== undefined
|
|
345
|
+
? { host_key: registration.host_key }
|
|
346
|
+
: {}),
|
|
347
|
+
...(registration.machine_label !== undefined
|
|
348
|
+
? { machine_label: registration.machine_label }
|
|
349
|
+
: {}),
|
|
350
|
+
...(this.config.connection_url !== undefined
|
|
351
|
+
? { connection_url: this.config.connection_url }
|
|
352
|
+
: {}),
|
|
353
|
+
}, {
|
|
354
|
+
id: registration.id,
|
|
355
|
+
project: registration.project,
|
|
356
|
+
variant: registration.conductor_name ?? this.config.variant,
|
|
357
|
+
}, (reason) => this.logger.warn({ conductorId: this.id }, reason))
|
|
358
|
+
: {};
|
|
359
|
+
try {
|
|
360
|
+
this.uuid = await this.remote.registerConductor({
|
|
361
|
+
...registration,
|
|
362
|
+
...machine,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
if (typeof machine.connection_url !== 'string')
|
|
367
|
+
throw err;
|
|
368
|
+
// A server that refuses the address must not stop the start; without
|
|
369
|
+
// the field the stored address stays unchanged.
|
|
370
|
+
// Value-free: the error may quote the address.
|
|
371
|
+
this.logger.warn({ conductorId: this.id }, 'registration failed with the connection URL; retrying without it');
|
|
372
|
+
const rest = { ...machine };
|
|
373
|
+
delete rest.connection_url;
|
|
374
|
+
this.uuid = await this.remote.registerConductor({
|
|
375
|
+
...registration,
|
|
376
|
+
...rest,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
342
379
|
this.logger.info({ conductorId: this.id, uuid: this.uuid, project: this.config.project }, 'conductor started');
|
|
343
380
|
try {
|
|
344
381
|
await this.inboxAddons.register(this.id);
|
|
@@ -1152,7 +1189,7 @@ export class Conductor {
|
|
|
1152
1189
|
* Install the project's `marketplaces` into the run's agent home and log
|
|
1153
1190
|
* one `plugins` entry. A failed install throws, failing the run start.
|
|
1154
1191
|
*/
|
|
1155
|
-
async installPlugins(chosen, t, run
|
|
1192
|
+
async installPlugins(chosen, t, run) {
|
|
1156
1193
|
const marketplaces = this.config.marketplaces ?? [];
|
|
1157
1194
|
const harness = chosen.agent.id;
|
|
1158
1195
|
const entry = {
|
|
@@ -1170,8 +1207,6 @@ export class Conductor {
|
|
|
1170
1207
|
: undefined;
|
|
1171
1208
|
if (off || !chosen.agent.installPlugins) {
|
|
1172
1209
|
entry.state = `off (${off})`;
|
|
1173
|
-
// Without the agent home, which skills the run gets is the user's own setup.
|
|
1174
|
-
entry.required_skills = 'skipped (plugins off)';
|
|
1175
1210
|
log();
|
|
1176
1211
|
return { env: {}, args: [] };
|
|
1177
1212
|
}
|
|
@@ -1194,13 +1229,6 @@ export class Conductor {
|
|
|
1194
1229
|
log();
|
|
1195
1230
|
throw new Error(`plugins: ${harness} install failed: ${entry.failure}`);
|
|
1196
1231
|
}
|
|
1197
|
-
const skills = checkRequiredSkills(worktree, home, t);
|
|
1198
|
-
entry.required_skills = skills;
|
|
1199
|
-
if (skills.missing.length > 0) {
|
|
1200
|
-
entry.failure = `missing required skills: ${skills.missing.join(', ')}`;
|
|
1201
|
-
log();
|
|
1202
|
-
throw new Error(`plugins: ${harness}: ${entry.failure}`);
|
|
1203
|
-
}
|
|
1204
1232
|
log();
|
|
1205
1233
|
return { env: launch.env, args: launch.args };
|
|
1206
1234
|
}
|
|
@@ -1385,7 +1413,7 @@ export class Conductor {
|
|
|
1385
1413
|
const tools = chosen.agent.withoutConductorTools
|
|
1386
1414
|
? undefined
|
|
1387
1415
|
: this.issueRunTools(run.runUuid, { worktreePath: ws.path, ticket: t });
|
|
1388
|
-
const plugins = await this.installPlugins(chosen, t, run
|
|
1416
|
+
const plugins = await this.installPlugins(chosen, t, run);
|
|
1389
1417
|
Object.assign(env, plugins.env);
|
|
1390
1418
|
const command = chosen.agent.launchCommand(prompt, identity, ws.path, tools ? { url: tools.url } : undefined, env, plugins.args);
|
|
1391
1419
|
// Read after launchCommand: a warning may depend on what this launch got.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ConductorStartContext, HookListener, MachineRegistrationData } from '../plugins/executor.js';
|
|
2
|
+
/** Dispatch atomically: failures retain the validated baseline, never partial data. */
|
|
3
|
+
export declare function runStartHooks(listeners: readonly HookListener[], machine: MachineRegistrationData, conductor: Readonly<ConductorStartContext>, warn: (reason: string) => void): Promise<MachineRegistrationData>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isValidMachineConnectionUrl } from '@bakers-build/core';
|
|
2
|
+
/** Dispatch atomically: failures retain the validated baseline, never partial data. */
|
|
3
|
+
export async function runStartHooks(listeners, machine, conductor, warn) {
|
|
4
|
+
const baseline = { ...machine };
|
|
5
|
+
if (baseline.connection_url !== undefined &&
|
|
6
|
+
baseline.connection_url !== null &&
|
|
7
|
+
!isValidMachineConnectionUrl(baseline.connection_url)) {
|
|
8
|
+
delete baseline.connection_url;
|
|
9
|
+
warn('invalid manual connection URL; start hooks skipped');
|
|
10
|
+
return baseline;
|
|
11
|
+
}
|
|
12
|
+
const shared = { ...baseline };
|
|
13
|
+
const context = Object.freeze({ ...conductor });
|
|
14
|
+
let closed = false;
|
|
15
|
+
let timer;
|
|
16
|
+
const validate = () => {
|
|
17
|
+
if (Reflect.ownKeys(shared).some((key) => !['host_key', 'machine_label', 'connection_url'].includes(String(key))) ||
|
|
18
|
+
shared.host_key !== baseline.host_key ||
|
|
19
|
+
(shared.machine_label !== undefined &&
|
|
20
|
+
(typeof shared.machine_label !== 'string' ||
|
|
21
|
+
!shared.machine_label.trim() ||
|
|
22
|
+
shared.machine_label.length > 255)) ||
|
|
23
|
+
(shared.connection_url !== undefined &&
|
|
24
|
+
shared.connection_url !== null &&
|
|
25
|
+
!isValidMachineConnectionUrl(shared.connection_url)) ||
|
|
26
|
+
(baseline.connection_url !== undefined &&
|
|
27
|
+
shared.connection_url !== baseline.connection_url))
|
|
28
|
+
throw new Error('invalid start hook data');
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
return await Promise.race([
|
|
32
|
+
(async () => {
|
|
33
|
+
for (const listener of listeners) {
|
|
34
|
+
await listener.before_conductor_start?.(shared, context);
|
|
35
|
+
if (closed)
|
|
36
|
+
return baseline;
|
|
37
|
+
validate();
|
|
38
|
+
}
|
|
39
|
+
validate();
|
|
40
|
+
return { ...shared };
|
|
41
|
+
})(),
|
|
42
|
+
new Promise((_, reject) => {
|
|
43
|
+
timer = setTimeout(() => {
|
|
44
|
+
closed = true;
|
|
45
|
+
reject(new Error('deadline'));
|
|
46
|
+
}, 5000);
|
|
47
|
+
}),
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
warn('start hooks discarded after failure, invalid data or timeout');
|
|
52
|
+
return baseline;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
closed = true;
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -57,6 +57,16 @@ export interface HookListenerContext {
|
|
|
57
57
|
}
|
|
58
58
|
/** A listener's callback for one slot. Awaited; a failure is logged, never fatal. */
|
|
59
59
|
export type HookListenerFn = (ctx: HookListenerContext) => void | Promise<void>;
|
|
60
|
+
export interface MachineRegistrationData {
|
|
61
|
+
host_key?: string;
|
|
62
|
+
machine_label?: string;
|
|
63
|
+
connection_url?: string | null;
|
|
64
|
+
}
|
|
65
|
+
export interface ConductorStartContext {
|
|
66
|
+
id: string;
|
|
67
|
+
project: string;
|
|
68
|
+
variant: string;
|
|
69
|
+
}
|
|
60
70
|
/**
|
|
61
71
|
* One addon contribution to the conductor `hooks` accumulator (BB-599): an
|
|
62
72
|
* object with an optional function per lifecycle slot. Listeners run in
|
|
@@ -65,6 +75,7 @@ export type HookListenerFn = (ctx: HookListenerContext) => void | Promise<void>;
|
|
|
65
75
|
export type HookListener = {
|
|
66
76
|
[K in HookName]?: HookListenerFn;
|
|
67
77
|
} & {
|
|
78
|
+
before_conductor_start?: (machine: MachineRegistrationData, conductor: Readonly<ConductorStartContext>) => void | Promise<void>;
|
|
68
79
|
/** Names the listener in conductor logs. */
|
|
69
80
|
id?: string;
|
|
70
81
|
};
|
|
@@ -15,6 +15,7 @@ export interface ConductorRegistration {
|
|
|
15
15
|
host_key?: string;
|
|
16
16
|
/** This machine's display label; names a newly created bb_machine. */
|
|
17
17
|
machine_label?: string;
|
|
18
|
+
connection_url?: string | null;
|
|
18
19
|
project: string;
|
|
19
20
|
/** Empty = serve all claimable states in the project (BB-207). */
|
|
20
21
|
states: string[];
|
|
@@ -90,9 +91,9 @@ export interface Ticket {
|
|
|
90
91
|
*/
|
|
91
92
|
workspaceId?: string;
|
|
92
93
|
workspaceName?: string;
|
|
93
|
-
/** The ticket type term name (`feature`, `bug`, …), sideloaded for
|
|
94
|
+
/** The ticket type term name (`feature`, `bug`, …), sideloaded for agent selection. */
|
|
94
95
|
type?: string;
|
|
95
|
-
/** The recipe term name (`matt`, …)
|
|
96
|
+
/** The recipe term name (`matt`, …), sideloaded for agent selection. */
|
|
96
97
|
recipe?: string;
|
|
97
98
|
/** Ticket label term names (`label` bundle), sideloaded for agent selection. Empty when none. */
|
|
98
99
|
labels: string[];
|
package/dist/src/types.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface ConductorSettings {
|
|
|
22
22
|
variant: string;
|
|
23
23
|
/** This machine's display label (`machine.config.js` label). */
|
|
24
24
|
machine_label?: string;
|
|
25
|
+
connection_url?: string | null;
|
|
25
26
|
/** Project name (bb_project.name); resolved at registration. */
|
|
26
27
|
project: string;
|
|
27
28
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/conductor",
|
|
3
|
-
"version": "0.8.1-next.
|
|
3
|
+
"version": "0.8.1-next.6",
|
|
4
4
|
"description": "bakers.build conductor engine + CLI: registers, claims tickets via JSON:API, dispatches agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@dropsh/plugin-jsonapi-schema": "^0.8.2",
|
|
34
34
|
"@dropsh/plugin-oauth2": "^0.8.2",
|
|
35
|
-
"@bakers-build/core": "^0.8.1-next.
|
|
36
|
-
"@bakers-build/message": "^0.8.1-next.
|
|
35
|
+
"@bakers-build/core": "^0.8.1-next.6",
|
|
36
|
+
"@bakers-build/message": "^0.8.1-next.6",
|
|
37
37
|
"@modelcontextprotocol/sdk": "1.32.1",
|
|
38
38
|
"commander": "^12.1.0",
|
|
39
39
|
"dropsh": "^0.8.2"
|
|
40
40
|
},
|
|
41
41
|
"bakersBuild": {
|
|
42
|
-
"commit": "
|
|
42
|
+
"commit": "9c1260bb32d1d8857cb001e754acb2fea477b514",
|
|
43
43
|
"channel": "next"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The skills a run must be able to load: every skill named in the worktree's
|
|
3
|
-
* `WORKFLOW.md` › `## bb-phase-work`, the ticket's recipe skill
|
|
4
|
-
* `bb-recipe-<recipe>`, and the recipe's `metadata.requires` for the ticket's
|
|
5
|
-
* type. Available are the worktree's own skills and the plugins installed in
|
|
6
|
-
* the run's agent home; the user's own agent home never counts.
|
|
7
|
-
*/
|
|
8
|
-
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
9
|
-
import { basename, dirname, join } from 'node:path';
|
|
10
|
-
const read = (path) => {
|
|
11
|
-
try {
|
|
12
|
-
return readFileSync(path, 'utf8');
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return '';
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const frontmatter = (text) => /^---\n([\s\S]*?)\n---/.exec(text)?.[1] ?? '';
|
|
19
|
-
/** Skill directories (holding a SKILL.md) directly under `dir`, by their frontmatter name. */
|
|
20
|
-
function skillsIn(dir) {
|
|
21
|
-
let entries;
|
|
22
|
-
try {
|
|
23
|
-
entries = readdirSync(dir);
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
return entries.flatMap((entry) => skillAt(join(dir, entry), entry));
|
|
29
|
-
}
|
|
30
|
-
/** A skill directory's SKILL.md by its frontmatter name, if it holds one. */
|
|
31
|
-
function skillAt(dir, fallback) {
|
|
32
|
-
const path = join(dir, 'SKILL.md');
|
|
33
|
-
if (!existsSync(path))
|
|
34
|
-
return [];
|
|
35
|
-
const name = /^name:\s*(\S+)\s*$/m.exec(frontmatter(read(path)))?.[1];
|
|
36
|
-
return [[name ?? fallback, path]];
|
|
37
|
-
}
|
|
38
|
-
/** Every SKILL.md at or below `dir`, by its frontmatter name. */
|
|
39
|
-
function skillsBelow(dir) {
|
|
40
|
-
let files;
|
|
41
|
-
try {
|
|
42
|
-
files = readdirSync(dir, { recursive: true, encoding: 'utf8' });
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
return files
|
|
48
|
-
.filter((file) => basename(file) === 'SKILL.md')
|
|
49
|
-
.filter((file) => !file.includes('node_modules/'))
|
|
50
|
-
.flatMap((file) => {
|
|
51
|
-
const skillDir = join(dir, dirname(file));
|
|
52
|
-
return skillAt(skillDir, basename(skillDir));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* `<plugin>:<skill>` for each skill of the plugin rooted at `root`. The
|
|
57
|
-
* manifest names the plugin and its `skills` paths (one or a list); without
|
|
58
|
-
* one, the plugin is `fallback` with `skills/`. Like the harnesses, every
|
|
59
|
-
* SKILL.md below a skills path counts.
|
|
60
|
-
*/
|
|
61
|
-
function pluginSkills(root, fallback) {
|
|
62
|
-
let manifest = {};
|
|
63
|
-
for (const kind of ['.claude-plugin', '.codex-plugin']) {
|
|
64
|
-
try {
|
|
65
|
-
manifest = JSON.parse(read(join(root, kind, 'plugin.json')));
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
catch { }
|
|
69
|
-
}
|
|
70
|
-
const plugin = typeof manifest.name === 'string' ? manifest.name : fallback;
|
|
71
|
-
const paths = (Array.isArray(manifest.skills)
|
|
72
|
-
? manifest.skills
|
|
73
|
-
: [manifest.skills ?? 'skills']).filter((path) => typeof path === 'string');
|
|
74
|
-
return paths
|
|
75
|
-
.flatMap((path) => skillsBelow(join(root, path)))
|
|
76
|
-
.map(([name, path]) => [`${plugin}:${name}`, path]);
|
|
77
|
-
}
|
|
78
|
-
const dirs = (dir) => {
|
|
79
|
-
try {
|
|
80
|
-
return readdirSync(dir, { withFileTypes: true })
|
|
81
|
-
.filter((entry) => entry.isDirectory())
|
|
82
|
-
.map((entry) => entry.name);
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
function availableSkills(worktree, home) {
|
|
89
|
-
const found = new Map();
|
|
90
|
-
const add = (pairs) => {
|
|
91
|
-
for (const [name, path] of pairs)
|
|
92
|
-
if (!found.has(name))
|
|
93
|
-
found.set(name, path);
|
|
94
|
-
};
|
|
95
|
-
for (const root of ['.claude/skills', '.agents/skills']) {
|
|
96
|
-
const dir = join(worktree, root);
|
|
97
|
-
add(skillsIn(dir));
|
|
98
|
-
// A skills-directory plugin, such as the `bakers` skills of this repository.
|
|
99
|
-
for (const entry of dirs(dir))
|
|
100
|
-
if (existsSync(join(dir, entry, '.claude-plugin', 'plugin.json')) ||
|
|
101
|
-
existsSync(join(dir, entry, '.codex-plugin', 'plugin.json')))
|
|
102
|
-
add(pluginSkills(join(dir, entry), entry));
|
|
103
|
-
}
|
|
104
|
-
// Both harnesses install to plugins/cache/<marketplace>/<plugin>/<version>.
|
|
105
|
-
const cache = join(home, 'plugins', 'cache');
|
|
106
|
-
for (const marketplace of dirs(cache))
|
|
107
|
-
for (const plugin of dirs(join(cache, marketplace)))
|
|
108
|
-
for (const version of dirs(join(cache, marketplace, plugin)))
|
|
109
|
-
add(pluginSkills(join(cache, marketplace, plugin, version), plugin));
|
|
110
|
-
return found;
|
|
111
|
-
}
|
|
112
|
-
/** The backticked names in the last column of the `## bb-phase-work` table. */
|
|
113
|
-
function workflowSkills(worktree) {
|
|
114
|
-
const section = /^## bb-phase-work\s*$([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(read(join(worktree, 'WORKFLOW.md')))?.[1] ?? '';
|
|
115
|
-
return section
|
|
116
|
-
.split('\n')
|
|
117
|
-
.filter((line) => line.trim().startsWith('|'))
|
|
118
|
-
.flatMap((line) => {
|
|
119
|
-
const cells = line
|
|
120
|
-
.trim()
|
|
121
|
-
.replace(/^\||\|$/g, '')
|
|
122
|
-
.split('|');
|
|
123
|
-
return [...(cells.at(-1) ?? '').matchAll(/`([^`]+)`/g)].map((m) => m[1]);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* A recipe's `metadata.requires` (space-separated skill names), replaced by
|
|
128
|
-
* `requires-<type>` when the recipe declares one for the ticket's type.
|
|
129
|
-
*/
|
|
130
|
-
function recipeRequires(skillFile, type) {
|
|
131
|
-
const lists = new Map();
|
|
132
|
-
for (const m of frontmatter(read(skillFile)).matchAll(/^\s+requires(?:-([\w-]+))?:\s*"?([^"\n]*)"?\s*$/gm))
|
|
133
|
-
lists.set(m[1] ?? 'default', m[2]);
|
|
134
|
-
const list = (type && lists.get(type)) ?? lists.get('default') ?? '';
|
|
135
|
-
return list.split(/\s+/).filter(Boolean);
|
|
136
|
-
}
|
|
137
|
-
function lookup(found, name) {
|
|
138
|
-
if (name.includes(':'))
|
|
139
|
-
return found.get(name);
|
|
140
|
-
return (found.get(name) ?? [...found].find(([key]) => key.endsWith(`:${name}`))?.[1]);
|
|
141
|
-
}
|
|
142
|
-
export function checkRequiredSkills(worktree, home, ticket) {
|
|
143
|
-
const found = availableSkills(worktree, home);
|
|
144
|
-
const required = workflowSkills(worktree);
|
|
145
|
-
if (ticket.recipe) {
|
|
146
|
-
const recipe = `bb-recipe-${ticket.recipe}`;
|
|
147
|
-
required.push(recipe);
|
|
148
|
-
const path = lookup(found, recipe);
|
|
149
|
-
if (path)
|
|
150
|
-
required.push(...recipeRequires(path, ticket.type));
|
|
151
|
-
}
|
|
152
|
-
const unique = [...new Set(required)];
|
|
153
|
-
return {
|
|
154
|
-
required: unique,
|
|
155
|
-
missing: unique.filter((name) => !lookup(found, name)),
|
|
156
|
-
};
|
|
157
|
-
}
|