@brunobracaioli/aibrain 0.4.0-beta.3 → 0.4.0-beta.30

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.
Files changed (70) hide show
  1. package/README.md +199 -13
  2. package/dist/assets/claude/hooks/context-compaction.ts +17 -5
  3. package/dist/assets/claude/hooks/native-host-contract-runtime.ts +1 -1
  4. package/dist/assets/claude/hooks/native-host-contract.test.ts +8 -4
  5. package/dist/assets/claude/hooks/provider-window.d.ts +83 -0
  6. package/dist/assets/codex-context-compaction.mjs +939 -13
  7. package/dist/assets/jev-paid-pilot-terminal.mjs +34 -5
  8. package/dist/claude-compatibility.mjs +26 -25
  9. package/dist/claude-observation.mjs +2 -1
  10. package/dist/cli.mjs +1084 -44
  11. package/dist/codex-compatibility.mjs +67 -5
  12. package/dist/codex-hooks.mjs +411 -0
  13. package/dist/codex-permissions.mjs +242 -51
  14. package/dist/codex-protocol-fingerprint.json +12 -13
  15. package/dist/device-login.mjs +511 -0
  16. package/dist/engineering-init.mjs +615 -0
  17. package/dist/engineering-pack.mjs +191 -14
  18. package/dist/engineering-scan-pins.json +42 -0
  19. package/dist/engineering-scan-report.mjs +1274 -0
  20. package/dist/engineering-scan-tools.mjs +1418 -0
  21. package/dist/engineering-scan.mjs +1265 -0
  22. package/dist/engineering.mjs +43 -5
  23. package/dist/extensions-catalog.mjs +390 -0
  24. package/dist/extensions-cli.mjs +524 -0
  25. package/dist/extensions-preferences.mjs +151 -0
  26. package/dist/guardrails/continuity.mjs +239 -0
  27. package/dist/guardrails/format.mjs +111 -0
  28. package/dist/guardrails/guards.mjs +1560 -0
  29. package/dist/guardrails/patch.mjs +33 -0
  30. package/dist/guardrails/run.mjs +286 -0
  31. package/dist/guardrails/shell-words.mjs +206 -0
  32. package/dist/guardrails-plugin.mjs +216 -0
  33. package/dist/launch-banner-art.json +40 -0
  34. package/dist/launch-banner.mjs +533 -0
  35. package/dist/launch-feedback.mjs +286 -0
  36. package/dist/launch.mjs +744 -64
  37. package/dist/managed-host.mjs +1276 -0
  38. package/dist/manager/adapter.mjs +304 -0
  39. package/dist/manager/bus.mjs +2222 -0
  40. package/dist/manager/claude-bus-worker.mjs +1355 -0
  41. package/dist/manager/delegation.mjs +354 -0
  42. package/dist/manager/hooks.mjs +918 -0
  43. package/dist/manager/launch-role.mjs +733 -0
  44. package/dist/manager/mcp-stdio.mjs +463 -0
  45. package/dist/manager/messages.mjs +861 -0
  46. package/dist/manager/native-worker.mjs +338 -0
  47. package/dist/manager/reserve.mjs +2170 -0
  48. package/dist/manager/room.mjs +106 -0
  49. package/dist/manager/send-grant.mjs +147 -0
  50. package/dist/manager/server.mjs +2010 -0
  51. package/dist/manager/status.mjs +119 -0
  52. package/dist/manager/wake-state.mjs +93 -0
  53. package/dist/manager/watch.mjs +87 -0
  54. package/dist/manager/worker.mjs +2977 -0
  55. package/dist/manager/workers-cli.mjs +1880 -0
  56. package/dist/mcp-servers.mjs +192 -0
  57. package/dist/mcp.mjs +10 -2
  58. package/dist/monitor.mjs +179 -2
  59. package/dist/package.json +1 -1
  60. package/dist/platform.mjs +78 -29
  61. package/dist/release-manifest-public-keys.json +10 -0
  62. package/dist/release-manifest.json +334 -0
  63. package/dist/release-manifest.mjs +817 -0
  64. package/dist/release-settings.mjs +335 -0
  65. package/dist/self-update.mjs +1047 -0
  66. package/dist/setup-login-state.mjs +19 -0
  67. package/dist/state.mjs +25 -1
  68. package/dist/token-guide.mjs +201 -0
  69. package/dist/update-actions.mjs +442 -0
  70. package/package.json +2 -2
@@ -20,6 +20,8 @@ const MAX_AUXILIARY_IN_FLIGHT = 32;
20
20
  const MAX_AUXILIARY_NOTIFICATIONS = 256;
21
21
  const DEFAULT_AUXILIARY_IDLE_TIMEOUT_MS = 120_000;
22
22
  const NORMAL_DISCOVERY_CLOSE_CODES = new Set([1000, 1001, 1005]);
23
+ // Smallest sun_path among supported hosts: macOS 104 bytes, minus the terminator.
24
+ const UNIX_SOCKET_PATH_MAX_BYTES = 103;
23
25
 
24
26
  function repoRoot() {
25
27
  return fileURLToPath(new URL('..', import.meta.url)).replace(/\/$/u, '');
@@ -77,6 +79,18 @@ async function main() {
77
79
  const childEnv = { ...process.env };
78
80
  delete childEnv.JEV_API_KEY;
79
81
  delete childEnv.TYPESAFE_API_KEY;
82
+ // The worker role's variables (ADR-0058) are for the adapter the monitor runs;
83
+ // the terminal, and every command its model runs, never carries them.
84
+ const terminalEnv = { ...childEnv };
85
+ for (const name of [
86
+ 'AISAC_WORKER_ROLE',
87
+ 'AISAC_WORKER_MODULE',
88
+ 'AISAC_MANAGER_ROLE',
89
+ 'AISAC_MANAGER_ADAPTER_MODULE',
90
+ 'AISAC_CODEX_MANAGER_CONFIG',
91
+ 'AISAC_CODEX_NATIVE_CONFIG_ARGS',
92
+ ])
93
+ delete terminalEnv[name];
80
94
  const bridgeRoot = await mkdtemp(join(tmpdir(), 'ai-brain-codex-terminal-'));
81
95
  await chmod(bridgeRoot, 0o700);
82
96
  const socketPath = join(bridgeRoot, 'codex.sock');
@@ -192,7 +206,7 @@ async function main() {
192
206
  }
193
207
  };
194
208
 
195
- const spawnMonitor = () => {
209
+ const spawnMonitor = ({ managerAuthority = true } = {}) => {
196
210
  const generation = {
197
211
  child: null,
198
212
  connection: null,
@@ -207,9 +221,20 @@ async function main() {
207
221
  queuedBytes: 0,
208
222
  retirementTimer: null,
209
223
  };
224
+ const monitorEnv = { ...childEnv };
225
+ if (!managerAuthority) {
226
+ // Resume-picker monitors are read-only auxiliary generations. They must
227
+ // never start a manager MCP server or wake adapter for the active room.
228
+ for (const name of [
229
+ 'AISAC_MANAGER_ROLE',
230
+ 'AISAC_MANAGER_ADAPTER_MODULE',
231
+ 'AISAC_CODEX_MANAGER_CONFIG',
232
+ ])
233
+ delete monitorEnv[name];
234
+ }
210
235
  const child = spawn(monitorCommand, [], {
211
236
  cwd: monitorCwd,
212
- env: childEnv,
237
+ env: monitorEnv,
213
238
  stdio: ['pipe', 'pipe', 'pipe'],
214
239
  detached: process.platform !== 'win32',
215
240
  });
@@ -772,11 +797,11 @@ async function main() {
772
797
  }
773
798
  if (connection.isCandidate && connection.generation === null) {
774
799
  handoffAttemptCount += 1;
775
- connection.generation = spawnMonitor();
800
+ connection.generation = spawnMonitor({ managerAuthority: true });
776
801
  connection.generation.connection = connection;
777
802
  }
778
803
  if (connection.isAuxiliary && connection.generation === null) {
779
- connection.generation = spawnMonitor();
804
+ connection.generation = spawnMonitor({ managerAuthority: false });
780
805
  connection.generation.connection = connection;
781
806
  }
782
807
  }
@@ -1022,6 +1047,10 @@ async function main() {
1022
1047
  });
1023
1048
  });
1024
1049
  try {
1050
+ // macOS sun_path holds 104 bytes including the terminator (Linux 108); refuse a
1051
+ // path that the kernel would truncate or reject instead of binding elsewhere.
1052
+ if (Buffer.byteLength(socketPath) > UNIX_SOCKET_PATH_MAX_BYTES)
1053
+ throw new Error('terminal_bridge_socket_path_too_long');
1025
1054
  await new Promise((resolve, reject) => {
1026
1055
  server.once('error', reject);
1027
1056
  server.listen(socketPath, async () => {
@@ -1042,7 +1071,7 @@ async function main() {
1042
1071
  }
1043
1072
  terminal = spawn(codexBinary, ['--remote', `unix://${socketPath}`, ...nativeArgs], {
1044
1073
  cwd: process.cwd(),
1045
- env: childEnv,
1074
+ env: terminalEnv,
1046
1075
  stdio: ['inherit', 'inherit', 'inherit'],
1047
1076
  });
1048
1077
  terminal.on('error', () => void cleanup().finally(() => process.exit(1)));
@@ -14,6 +14,7 @@ import {
14
14
  import { dirname, join, resolve } from 'node:path';
15
15
  import { tmpdir } from 'node:os';
16
16
  import { spawn } from 'node:child_process';
17
+ import releaseManifest from './release-manifest.json' with { type: 'json' };
17
18
 
18
19
  const MAX_OUTPUT_BYTES = 96 * 1024;
19
20
  const PROBE_TIMEOUT_MS = 30_000;
@@ -21,16 +22,9 @@ const MAX_PLUGIN_ASSET_BYTES = 4 * 1024 * 1024;
21
22
  const MAX_PLUGIN_TOTAL_BYTES = 16 * 1024 * 1024;
22
23
  const HOST_MAJOR = 2;
23
24
  const HOST_MINOR = 1;
24
- const QUALIFIED_VERSIONS = new Set([
25
- '2.1.294',
26
- '2.1.295',
27
- '2.1.296',
28
- '2.1.299',
29
- '2.1.300',
30
- '2.1.301',
31
- '2.1.302',
32
- '2.1.303',
33
- ]);
25
+ // One source for the qualified releases: the manifest bundled with this client
26
+ // (ADR-0056 R2; spec aisac-release-manifest FR4).
27
+ const QUALIFIED_VERSIONS = new Set(releaseManifest.hosts.claude.qualified);
34
28
  const REQUIRED_FLAGS = ['--settings', '--mcp-config', '--allowedTools', '--plugin-dir'];
35
29
  const REQUIRED_INVENTORY = [
36
30
  'prompt.submit',
@@ -57,6 +51,7 @@ const ALLOWED_PLUGIN_FILES = Object.freeze([
57
51
  'hooks/hooks.json',
58
52
  'hooks/context-compaction.ts',
59
53
  'hooks/provider-window.js',
54
+ 'hooks/provider-window.d.ts',
60
55
  'hooks/state-fitting.mjs',
61
56
  'hooks/state-fitting.d.mts',
62
57
  'hooks/native-host-contract.test.ts',
@@ -329,24 +324,30 @@ async function runHostProbe(executable, pluginRoot, limits = {}) {
329
324
  ];
330
325
  if (errors.length > 0) return { ok: false, reason: 'plugin_validation_failed' };
331
326
  const notes = contents.flatMap((item) => item.notes);
332
- const hookNote = notes.find((note) => typeof note === 'string' && note.includes(' hooks: '));
333
- const callNote = notes.find((note) => typeof note === 'string' && note.includes(' calls: '));
327
+ // Claude 2.1.323 wraps a long inventory into several notes that repeat the
328
+ // "<module> hooks: " or "<module> calls: " prefix, so read every matching note.
329
+ /** @param {string} marker */
330
+ const inventoryNotes = (marker) =>
331
+ notes.filter(
332
+ /** @returns {note is string} */
333
+ (note) => typeof note === 'string' && note.includes(marker),
334
+ );
334
335
  const hooks = new Set(
335
- typeof hookNote === 'string'
336
- ? hookNote
337
- .split(' hooks: ', 2)[1]
338
- .split(', ')
339
- .map((item) => item.trim())
340
- : [],
336
+ inventoryNotes(' hooks: ').flatMap((note) =>
337
+ note
338
+ .split(' hooks: ', 2)[1]
339
+ .split(', ')
340
+ .map((item) => item.trim()),
341
+ ),
341
342
  );
342
343
  const calls = new Set(
343
- typeof callNote === 'string'
344
- ? callNote
345
- .split(' calls: ', 2)[1]
346
- .replace(/\s+\(via[^)]*\)/gu, '')
347
- .split(', ')
348
- .map((item) => item.trim())
349
- : [],
344
+ inventoryNotes(' calls: ').flatMap((note) =>
345
+ note
346
+ .split(' calls: ', 2)[1]
347
+ .replace(/\s+\(via[^)]*\)/gu, '')
348
+ .split(', ')
349
+ .map((item) => item.trim()),
350
+ ),
350
351
  );
351
352
  const inventory = new Set([...hooks, ...calls]);
352
353
  if (inventory.size === 0 || REQUIRED_INVENTORY.some((item) => !inventory.has(item)))
@@ -16,7 +16,7 @@ export const MAX_LOG_FILES = 3;
16
16
  const LOCK_WAIT_MS = 250;
17
17
  const LOCK_STALE_MS = 30_000;
18
18
  const ADMISSION_MS = 60 * 60 * 1000;
19
- export const ADAPTER_VERSION = '0.4.0-beta.3';
19
+ export const ADAPTER_VERSION = '0.4.0-beta.30';
20
20
  const MAX_DIAGNOSTIC_COUNT = 10_000_000;
21
21
  const MAX_DIAGNOSTIC_BYTES = 128 * 1024 * 1024;
22
22
  const CHECKPOINT_BACKENDS = new Set(['native_store', 'private_file']);
@@ -206,6 +206,7 @@ const SAFE_ERROR_CODES = new Set([
206
206
  'mcp_tool_unavailable',
207
207
  'mcp_feature_disabled',
208
208
  'mcp_paid_plan_required',
209
+ 'mcp_invalid_input',
209
210
  'provider_error',
210
211
  'helper_failed',
211
212
  ]);