SDK contract probe: a policy mod that guards tool calls

<h1>nixie</h1>
A personal assistant platform that its owner runs and controls: every rule readable and editable, every decision recorded, and personal data kept on the owner's own hosts.
<a href="./docs/README.md">Documentation</a> • <a href="./docs/README.md#decisions">Decisions</a> • <a href="./AGENTS.md">Agent Guidelines</a>
nixie is in Phase 2, Research, and has no product code. The work runs in 4 phases: brainstorm, research, design, and decide. Decisions are recorded as research settles each question.
bun install
bun run check # every check CI runs
hooks/register.js 54 lines1export function register(on) {
2 on('session.start', handleSessionStart);
3 on('command.run', { command: 'nixie-alive' }, handleAliveCommand);
4 on('tool.call', handleToolCall);
5 on('tool.check', handleToolCheck);
6}
7
8// Each marker in a Bash command picks one policy outcome, so one prompt exercises all of them.
9// /nixie-alive answers only while the module is loaded, so a host can probe for it.
10async function handleSessionStart($, event, next) {
11 await $.command.register({
12 description: 'Report that the nixie policy mod is loaded',
13 immediate: true,
14 name: 'nixie-alive',
15 });
16 return next(event);
17}
18
19function handleAliveCommand() {
20 return { text: 'nixie-policy alive' };
21}
22
23function handleToolCall($, event, next) {
24 if (event.tool !== 'Bash') {
25 return next(event);
26 }
27 return checkBash($, event, next);
28}
29
30function checkBash($, event, next) {
31 if (event.command.includes('MARK_DENY')) {
32 return { deny: 'nixie-policy denied this command.' };
33 }
34 if (event.command.includes('MARK_REWRITE')) {
35 return next({ ...event, command: 'echo rewritten-by-nixie' });
36 }
37 if (event.command.includes('MARK_ANSWER_TEXT')) {
38 return { result: 'answered-by-nixie as text' };
39 }
40 if (event.command.includes('MARK_ANSWER')) {
41 // The result takes the tool's own output shape, here Bash's.
42 return { result: { interrupted: false, stderr: '', stdout: 'answered-by-nixie' } };
43 }
44 return next(event);
45}
46
47async function handleToolCheck($, event, next) {
48 const decided = await next(event);
49 if (event.tool === 'Bash' && event.input.command.includes('MARK_CHECK')) {
50 return { decision: 'deny', reason: 'nixie-policy tool.check denied this command.' };
51 }
52 return decided;
53}
54