beadboard/.agents/skills/beadboard-driver/scripts/session-preflight.mjs

141 lines
3.5 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
import { spawnSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { findCommandInPath, resolveBbPath } from './lib/driver-lib.mjs';
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
const __dirname = dirname(fileURLToPath(import.meta.url));
/**
* Configures bd mail delegate to use bb-mail-shim.mjs.
* Runs `bd config set mail.delegate "node <shim-path>"` in the current directory.
*
* @param {string} bdPath - Resolved path to the bd binary.
* @param {string} shimPath - Absolute path to bb-mail-shim.mjs.
* @returns {object} Mail delegate config result.
*/
function configureMailDelegate(bdPath, shimPath) {
if (!existsSync(shimPath)) {
return {
configured: false,
reason: `shim not found at ${shimPath} — skill installation may be incomplete`,
};
}
const delegateCmd = `node ${shimPath}`;
const result = spawnSync(bdPath, ['config', 'set', 'mail.delegate', delegateCmd], {
stdio: 'pipe',
shell: false,
});
if (result.status !== 0) {
const stderr = result.stderr?.toString().trim() || '';
return {
configured: false,
reason: `bd config set failed: ${stderr || 'non-zero exit'}`,
delegate: delegateCmd,
};
}
return {
configured: true,
delegate: delegateCmd,
shim_path: shimPath,
note: 'Set BB_AGENT env var to your agent name before calling bd mail (e.g., export BB_AGENT=silver-scribe)',
};
}
async function main() {
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
const shimPath = join(__dirname, 'bb-mail-shim.mjs');
try {
const bdPath = await findCommandInPath('bd');
if (!bdPath) {
process.stdout.write(
`${JSON.stringify(
{
ok: false,
error_code: 'BD_NOT_FOUND',
reason: 'Could not find bd in PATH.',
remediation: 'Install beads CLI or add bd executable to PATH.',
tools: {
bd: { available: false, path: null },
},
bb: null,
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
mail: null,
},
null,
2,
)}\n`,
);
return;
}
const bb = await resolveBbPath();
if (!bb.ok) {
process.stdout.write(
`${JSON.stringify(
{
ok: false,
error_code: 'BB_NOT_FOUND',
reason: bb.reason,
remediation: bb.remediation,
tools: {
bd: { available: true, path: bdPath },
},
bb,
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
mail: {
configured: false,
reason: 'bb not available — mail delegate requires bb agent commands (see izs.2)',
},
},
null,
2,
)}\n`,
);
return;
}
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
const mail = configureMailDelegate(bdPath, shimPath);
process.stdout.write(
`${JSON.stringify(
{
ok: true,
timestamp: new Date().toISOString(),
tools: {
bd: { available: true, path: bdPath },
},
bb,
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
mail,
},
null,
2,
)}\n`,
);
} catch (error) {
process.stdout.write(
`${JSON.stringify(
{
ok: false,
error_code: 'PREFLIGHT_INTERNAL_ERROR',
reason: error instanceof Error ? error.message : String(error),
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
remediation: 'Inspect session-preflight.mjs and retry.',
tools: {
bd: { available: false, path: null },
},
bb: null,
feat(driver-skill): add bb-mail-shim + session-preflight mail delegate config (izs.5) ## What changed ### scripts/bb-mail-shim.mjs (new) Translates bd mail delegate calls into bb agent coordination commands. bd mail delegates by prepending the configured command to all args, so this shim bridges the interface mismatch between bd mail (gt-mail style) and bb agent (--agent/--from flags required). Command mappings: bd mail inbox [...] → bb agent inbox --agent $BB_AGENT [...] bd mail send --to foo [...] → bb agent send --from $BB_AGENT --to foo [...] bd mail read <msg-id> → bb agent read --agent $BB_AGENT --message <msg-id> bd mail ack <msg-id> → bb agent ack --agent $BB_AGENT --message <msg-id> bd mail <other> [...] → bb agent <other> [...] (passthrough) Agent identity injected automatically from BB_AGENT env var (primary) or BD_ACTOR env var (fallback). Caller can override --from by supplying it explicitly in bd mail send args. Falls back with clear error messages if bb is not in PATH or BB_AGENT/BD_ACTOR is unset. ### scripts/session-preflight.mjs (updated) Added mail delegate auto-configuration step after successful bb resolution: - Calls: bd config set mail.delegate "node <abs-path-to-bb-mail-shim.mjs>" - Uses absolute path to shim resolved relative to session-preflight.mjs - Reports mail.configured + mail.delegate + usage note in output JSON - Graceful failure if shim missing, bd config set fails, or bb not found - Added mail: null to all error branches for consistent output shape ## Verification Tested end-to-end on this machine: export BB_AGENT=silver-scribe node session-preflight.mjs # → ok:true, mail.configured:true bd mail send --to silver-scribe --bead beadboard-izs.5 \ --category INFO --subject "test" --body "pipeline verified" bd mail inbox # → Inbox (1): [msg_...] INFO: test All commands exit 0. Delegate persisted via bd config get mail.delegate. ## Bead: beadboard-izs.5 (closed) ## Also closed: beadboard-izs.2 — bb agent already in global CLI (feat(cli) commit) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 18:30:15 -08:00
mail: null,
},
null,
2,
)}\n`,
);
}
}
void main();