@brunobracaioli/aibrain 0.4.0-beta.12 → 0.4.0-beta.13
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/README.md +6 -0
- package/dist/claude-observation.mjs +1 -1
- package/dist/cli.mjs +53 -6
- package/dist/codex-hooks.mjs +411 -0
- package/dist/codex-permissions.mjs +67 -34
- package/dist/extensions-catalog.mjs +26 -8
- package/dist/extensions-cli.mjs +2 -2
- package/dist/guardrails/guards.mjs +64 -12
- package/dist/guardrails/patch.mjs +33 -0
- package/dist/guardrails/run.mjs +106 -31
- package/dist/guardrails-plugin.mjs +59 -1
- package/dist/launch.mjs +22 -1
- package/dist/monitor.mjs +43 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/monitor.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// @ts-check
|
|
3
3
|
|
|
4
|
-
import { access } from 'node:fs/promises';
|
|
4
|
+
import { access, realpath } from 'node:fs/promises';
|
|
5
5
|
import { constants } from 'node:fs';
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
7
|
import { dirname, join } from 'node:path';
|
|
@@ -19,6 +19,13 @@ import {
|
|
|
19
19
|
parseCodexEngineering,
|
|
20
20
|
} from './codex-engineering.mjs';
|
|
21
21
|
import { CODEX_MCP_ENV, codexMcpConfigArgs, parseCodexMcp } from './mcp-servers.mjs';
|
|
22
|
+
import {
|
|
23
|
+
CODEX_HOOKS_ENV,
|
|
24
|
+
GUARDRAILS_SESSION_ENV,
|
|
25
|
+
codexHookConfigArgs,
|
|
26
|
+
guardrailsSessionValue,
|
|
27
|
+
parseCodexHooks,
|
|
28
|
+
} from './codex-hooks.mjs';
|
|
22
29
|
|
|
23
30
|
const root = dirname(fileURLToPath(import.meta.url));
|
|
24
31
|
const endpoint = process.env.AIBRAIN_MCP_URL?.trim();
|
|
@@ -59,6 +66,35 @@ try {
|
|
|
59
66
|
} catch {
|
|
60
67
|
catalogServers = [];
|
|
61
68
|
}
|
|
69
|
+
// Guardrail hooks (E6b) follow the pack as well, and need the state root the pack
|
|
70
|
+
// was checked against: their session value points at this launch's folder. The
|
|
71
|
+
// flags are the whole catalog with byte-stable commands (codex-hooks.mjs). A
|
|
72
|
+
// malformed value, or a package without the dispatcher, starts the session without
|
|
73
|
+
// them.
|
|
74
|
+
/** @type {{ args: string[], session: string } | null} */
|
|
75
|
+
let guardrails = null;
|
|
76
|
+
try {
|
|
77
|
+
const stateRoot = process.env.AIBRAIN_STATE_DIR;
|
|
78
|
+
const hooks =
|
|
79
|
+
engineering === null || stateRoot === undefined
|
|
80
|
+
? null
|
|
81
|
+
: parseCodexHooks(process.env[CODEX_HOOKS_ENV]);
|
|
82
|
+
if (hooks !== null && engineering !== null && stateRoot !== undefined) {
|
|
83
|
+
// The real path, as the launcher's hooks/list probe uses (prepareCodexGuardrails).
|
|
84
|
+
const dispatcher = await realpath(join(root, 'guardrails', 'run.mjs'));
|
|
85
|
+
await access(dispatcher, constants.R_OK);
|
|
86
|
+
guardrails = {
|
|
87
|
+
args: codexHookConfigArgs({ node: process.execPath, dispatcher }),
|
|
88
|
+
session: guardrailsSessionValue(hooks, {
|
|
89
|
+
// The pack sits in <launch>/engineering/skills, inside <state>/runtime.
|
|
90
|
+
launchDirectory: dirname(dirname(engineering.skillsRoot)),
|
|
91
|
+
stateRoot,
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
} catch {
|
|
96
|
+
guardrails = null;
|
|
97
|
+
}
|
|
62
98
|
const policyText = process.env.CODEX_CONTEXT_POLICY_JSON;
|
|
63
99
|
let policy;
|
|
64
100
|
if (policyText === undefined) {
|
|
@@ -119,6 +155,11 @@ delete env[CODEX_APP_SERVER_PROFILE];
|
|
|
119
155
|
delete env[CODEX_ENGINEERING_ENV];
|
|
120
156
|
delete env[CODEX_ENGINEERING_SKILLS_ROOT_ENV];
|
|
121
157
|
delete env[CODEX_MCP_ENV];
|
|
158
|
+
delete env[CODEX_HOOKS_ENV];
|
|
159
|
+
// Only this monitor sets the value the hook processes read; one inherited from an
|
|
160
|
+
// outer session never reaches the app-server.
|
|
161
|
+
delete env[GUARDRAILS_SESSION_ENV];
|
|
162
|
+
if (guardrails !== null) env[GUARDRAILS_SESSION_ENV] = guardrails.session;
|
|
122
163
|
if (engineering !== null) env[CODEX_ENGINEERING_SKILLS_ROOT_ENV] = engineering.skillsRoot;
|
|
123
164
|
if (launchEnvelope?.profile !== undefined) env[CODEX_APP_SERVER_PROFILE] = launchEnvelope.profile;
|
|
124
165
|
if (policy !== null) env.CODEX_CONTEXT_POLICY_JSON = JSON.stringify(policy);
|
|
@@ -142,6 +183,7 @@ const child = spawn(
|
|
|
142
183
|
...(launchEnvelope === null ? [] : ownedAppServerConfigArgs(launchEnvelope)),
|
|
143
184
|
...(engineering === null ? [] : codexEngineeringConfigArgs(engineering)),
|
|
144
185
|
...codexMcpConfigArgs(catalogServers),
|
|
186
|
+
...(guardrails === null ? [] : guardrails.args),
|
|
145
187
|
],
|
|
146
188
|
{ cwd: process.cwd(), env, stdio: 'inherit' },
|
|
147
189
|
);
|
package/dist/package.json
CHANGED
package/package.json
CHANGED