refactor: extract agent bounded context + fix SSE comments + cleanup unused

- Extract src/lib/agent/ bounded context with types, registry, messaging
- Add comments_count to BeadIssue for SSE comment detection
- Create batch endpoints for mail/reservations APIs
- Add memory validation to session-preflight
- Remove unused empty dirs (mockup, sessions, timeline)
- Move stashes to docs/references, gitignore them
This commit is contained in:
zenchantlive 2026-03-04 22:06:40 -08:00
parent 6f41c4af31
commit 18fbafdce4
34 changed files with 62714 additions and 1970 deletions

View file

@ -40,6 +40,38 @@ function configureMailDelegate(bdPath, shimPath) {
};
}
function validateMemorySystem(bdPath) {
try {
const result = spawnSync(bdPath, ['query', 'label=mem-canonical,status=closed', '--limit', '5'], {
stdio: 'pipe',
shell: false,
});
if (result.status !== 0) {
return {
validated: false,
reason: 'Failed to query memory system',
memories_found: 0,
};
}
const output = result.stdout?.toString() || '';
const memoryCount = (output.match(/beadboard-/g) || []).length;
return {
validated: true,
memories_found: memoryCount,
note: 'Remember to read memory beads at session start: bd show beadboard-116 beadboard-60a beadboard-zas',
};
} catch (error) {
return {
validated: false,
reason: error instanceof Error ? error.message : String(error),
memories_found: 0,
};
}
}
async function main() {
const shimPath = join(__dirname, 'bb-mail-shim.mjs');
@ -54,13 +86,14 @@ async function main() {
reason: 'Could not find bd in PATH.',
remediation:
process.platform === 'win32'
? 'Primary: npm i -g beadboard. Fallback: powershell -ExecutionPolicy Bypass -File .\\install\\install.ps1. Then ensure bd is available in PATH.'
? 'Primary: npm i -g beadboard. Fallback: powershell -ExecutionPolicy Bypass -File ./install/install.ps1. Then ensure bd is available in PATH.'
: 'Primary: npm i -g beadboard. Fallback: bash ./install/install.sh. Then ensure bd is available in PATH.',
tools: {
bd: { available: false, path: null },
},
bb: null,
mail: null,
memory: null,
},
null,
2,
@ -86,6 +119,7 @@ async function main() {
configured: false,
reason: 'bb not available — mail delegate requires bb agent commands',
},
memory: null,
},
null,
2,
@ -95,6 +129,7 @@ async function main() {
}
const mail = configureMailDelegate(bdPath, shimPath);
const memory = validateMemorySystem(bdPath);
process.stdout.write(
`${JSON.stringify(
@ -106,6 +141,7 @@ async function main() {
},
bb,
mail,
memory,
},
null,
2,
@ -124,6 +160,7 @@ async function main() {
},
bb: null,
mail: null,
memory: null,
},
null,
2,

View file

@ -0,0 +1,95 @@
#!/usr/bin/env node
/**
* setup-mail-delegate.mjs
*
* Configures bd's mail.delegate to point at the bb-mail-shim.mjs bundled
* alongside this script. Uses import.meta.url to resolve the absolute path
* so the caller never needs to know where the skill is installed.
*
* Usage: node {baseDir}/scripts/setup-mail-delegate.mjs
* Output: JSON { ok, configured, delegate } or { ok, error_code, reason }
*/
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { findCommandInPath } from './lib/driver-lib.mjs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const shimPath = join(__dirname, 'bb-mail-shim.mjs');
const delegateCommand = `node ${shimPath}`;
async function main() {
const dryRun = process.argv.includes('--dry-run');
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. Install with: npm install -g beads-cli',
delegate: null,
},
null,
2,
)}\n`,
);
return;
}
if (dryRun) {
process.stdout.write(
`${JSON.stringify(
{
ok: true,
dry_run: true,
configured: false,
delegate: delegateCommand,
},
null,
2,
)}\n`,
);
return;
}
const result = spawnSync(bdPath, ['config', 'set', 'mail.delegate', delegateCommand], {
stdio: 'pipe',
shell: false,
});
if (result.status !== 0) {
const stderr = result.stderr?.toString().trim() || '';
process.stdout.write(
`${JSON.stringify(
{
ok: false,
error_code: 'BD_CONFIG_FAILED',
reason: stderr || 'bd config set mail.delegate exited non-zero.',
delegate: delegateCommand,
},
null,
2,
)}\n`,
);
return;
}
process.stdout.write(
`${JSON.stringify(
{
ok: true,
configured: true,
delegate: delegateCommand,
},
null,
2,
)}\n`,
);
}
void main();