brainx-skill 1.0.16 → 1.0.18
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/installation/lib/literature-mcp.js +7 -1
- package/mcp-servers/codex/README.md +46 -20
- package/mcp-servers/codex/UPSTREAM.md +20 -16
- package/mcp-servers/codex/app-server.mjs +177 -0
- package/mcp-servers/codex/cli-invocation.cjs +50 -0
- package/mcp-servers/codex/server.mjs +136 -69
- package/mcp-servers/codex/test/fixtures/fake-codex.mjs +80 -3
- package/mcp-servers/codex/test/fixtures/run-server.mjs +7 -0
- package/mcp-servers/codex/test/server.test.mjs +188 -84
- package/package.json +1 -1
- package/skills/brainx-modeling-loop/SKILL.md +13 -11
- package/skills/package-skills/brainmass/SKILL.md +3 -1
- package/skills/package-skills/brainmass/references/braintools/metric.md +10 -0
- package/skills/package-skills/brainmass/references/braintools/parameter-initializer.md +37 -7
- package/skills/package-skills/brainmass/references/scripts/resting-state-meg-whole-brain-pipeline.py +16 -6
- package/skills/package-skills/brainmass/references/visualization-analysis-api.md +35 -2
- package/skills/package-skills/brainspike/SKILL.md +3 -0
- package/skills/package-skills/brainspike/references/braintools/connectivity.md +1 -1
- package/skills/package-skills/brainspike/references/spatial-connectivity.md +53 -0
|
@@ -1,6 +1,83 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
import { createInterface } from 'node:readline';
|
|
4
2
|
|
|
3
|
+
const threads = new Map();
|
|
4
|
+
const turns = new Map();
|
|
5
|
+
const approvals = new Map();
|
|
6
|
+
let nextThread = 1;
|
|
7
|
+
let nextTurn = 1;
|
|
8
|
+
const write = (message) => process.stdout.write(`${JSON.stringify(message)}\n`);
|
|
9
|
+
function finish(threadId, turnId, prompt, decision) {
|
|
10
|
+
if (prompt === 'empty') {
|
|
11
|
+
write({ method: 'turn/completed', params: { threadId, turn: { id: turnId, status: 'completed' } } });
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const thread = threads.get(threadId);
|
|
15
|
+
write({ method: 'item/completed', params: { threadId, turnId,
|
|
16
|
+
item: { type: 'agentMessage', id: 'comment', phase: 'commentary', text: 'Ignore commentary' } } });
|
|
17
|
+
// An event from another turn must never enter the report.
|
|
18
|
+
write({ method: 'item/completed', params: { threadId, turnId: 'unrelated',
|
|
19
|
+
item: { type: 'agentMessage', id: 'wrong', text: 'Wrong turn' } } });
|
|
20
|
+
write({ method: 'item/completed', params: { threadId, turnId,
|
|
21
|
+
item: { type: 'agentMessage', id: 'report', phase: 'final_answer',
|
|
22
|
+
text: JSON.stringify({ thread, turn: turns.get(turnId), decision,
|
|
23
|
+
argv: process.argv.slice(2) }) } } });
|
|
24
|
+
write({ method: 'turn/completed', params: { threadId, turn: { id: turnId, status: 'completed' } } });
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
const input = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
6
|
-
input.on('line', (line) =>
|
|
28
|
+
input.on('line', (line) => {
|
|
29
|
+
const { id, method, params, result } = JSON.parse(line);
|
|
30
|
+
if (approvals.has(id)) {
|
|
31
|
+
const turn = approvals.get(id); finish(...turn, result.decision); approvals.delete(id); return;
|
|
32
|
+
}
|
|
33
|
+
if (method === 'initialize') { write({ id, result: {} }); return; }
|
|
34
|
+
if (method === 'config/read') {
|
|
35
|
+
const servers = process.env.TEST_NO_MCP ? {} : { codex: { command: 'node' } };
|
|
36
|
+
if (params.cwd) servers.project_mcp = { command: 'node' };
|
|
37
|
+
write({ id, result: { config: { mcp_servers: servers } } }); return;
|
|
38
|
+
}
|
|
39
|
+
if (method === 'thread/start') {
|
|
40
|
+
const threadId = `thread-${nextThread++}`;
|
|
41
|
+
threads.set(threadId, { start: params, history: [] });
|
|
42
|
+
write({ id, result: { thread: { id: threadId } } }); return;
|
|
43
|
+
}
|
|
44
|
+
if (method === 'thread/resume') {
|
|
45
|
+
const thread = threads.get(params.threadId);
|
|
46
|
+
if (!thread) { write({ id, error: { code: -32000, message: 'Thread not found' } }); return; }
|
|
47
|
+
thread.resume = params;
|
|
48
|
+
write({ id, result: { thread: { id: params.threadId } } }); return;
|
|
49
|
+
}
|
|
50
|
+
if (method === 'thread/read') {
|
|
51
|
+
const thread = threads.get(params.threadId);
|
|
52
|
+
if (!thread) { write({ id, error: { code: -32000, message: 'Thread not found' } }); return; }
|
|
53
|
+
write({ id, result: { thread: { id: params.threadId, cwd: thread.start.cwd } } }); return;
|
|
54
|
+
}
|
|
55
|
+
if (method === 'turn/start') {
|
|
56
|
+
const { threadId } = params;
|
|
57
|
+
const turnId = `turn-${nextTurn++}`;
|
|
58
|
+
const prompt = params.input[0].text;
|
|
59
|
+
threads.get(threadId).history.push(prompt);
|
|
60
|
+
turns.set(turnId, params);
|
|
61
|
+
if (prompt === 'crash') { process.exit(1); }
|
|
62
|
+
if (prompt !== 'early') write({ id, result: { turn: { id: turnId } } });
|
|
63
|
+
if (prompt === 'stall') return;
|
|
64
|
+
if (prompt === 'approval') {
|
|
65
|
+
const approvalId = `approval-${turnId}`;
|
|
66
|
+
approvals.set(approvalId, [threadId, turnId, prompt]);
|
|
67
|
+
write({ id: approvalId, method: 'item/commandExecution/requestApproval', params: { threadId, turnId } });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (prompt === 'fail') {
|
|
71
|
+
write({ method: 'turn/completed', params: { threadId,
|
|
72
|
+
turn: { id: turnId, status: 'failed', error: { message: 'Model unavailable' } } } }); return;
|
|
73
|
+
}
|
|
74
|
+
finish(threadId, turnId, prompt);
|
|
75
|
+
if (prompt === 'early') write({ id, result: { turn: { id: turnId } } });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (method === 'turn/interrupt') {
|
|
79
|
+
write({ id, result: {} });
|
|
80
|
+
write({ method: 'turn/completed', params: { threadId: params.threadId,
|
|
81
|
+
turn: { id: params.turnId, status: 'interrupted' } } });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AppServerClient } from '../../app-server.mjs';
|
|
2
|
+
import { serve } from '../../server.mjs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
serve(new AppServerClient({ binary: process.execPath,
|
|
5
|
+
prefixArgs: [fileURLToPath(new URL('./fake-codex.mjs', import.meta.url))],
|
|
6
|
+
timeoutMs: Number(process.env.TEST_REVIEW_TIMEOUT_MS || 5000),
|
|
7
|
+
}));
|
|
@@ -1,99 +1,203 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { createInterface } from 'node:readline';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import test from 'node:test';
|
|
6
|
-
import
|
|
6
|
+
import cliInvocation from '../cli-invocation.cjs';
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const server = resolve(testDirectory, '..', 'server.mjs');
|
|
10
|
-
const fakeCodex = resolve(testDirectory, 'fixtures', 'fake-codex.mjs');
|
|
11
|
-
chmodSync(fakeCodex, 0o755);
|
|
8
|
+
const { codexInvocation, npmInvocation } = cliInvocation;
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
10
|
+
const runner = fileURLToPath(new URL('./fixtures/run-server.mjs', import.meta.url));
|
|
11
|
+
class Session {
|
|
12
|
+
constructor(t, env = {}) {
|
|
13
|
+
this.child = spawn(process.execPath, [runner], {
|
|
14
|
+
env: { ...process.env, ...env }, stdio: ['pipe', 'pipe', 'pipe'],
|
|
15
|
+
});
|
|
16
|
+
this.pending = new Map();
|
|
17
|
+
this.nextId = 1;
|
|
18
|
+
this.stderr = '';
|
|
19
|
+
this.child.stderr.on('data', (data) => { this.stderr += data; });
|
|
20
|
+
this.lines = createInterface({ input: this.child.stdout });
|
|
21
|
+
this.lines.on('line', (line) => {
|
|
22
|
+
const message = JSON.parse(line);
|
|
23
|
+
const entry = this.pending.get(message.id);
|
|
24
|
+
if (!entry) return;
|
|
25
|
+
clearTimeout(entry.timer); this.pending.delete(message.id);
|
|
26
|
+
entry.resolve(message);
|
|
27
|
+
});
|
|
28
|
+
this.child.on('exit', () => {
|
|
29
|
+
for (const entry of this.pending.values()) { clearTimeout(entry.timer); entry.reject(new Error(this.stderr)); }
|
|
30
|
+
this.pending.clear();
|
|
18
31
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
child.on('error', reject);
|
|
24
|
-
child.on('exit', (code) => {
|
|
25
|
-
if (code !== 0) {
|
|
26
|
-
reject(new Error(`proxy exited ${code}: ${stderr}`));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
resolveOutput(stdout.trimEnd().split('\n').map((line) => JSON.parse(line)));
|
|
32
|
+
t.after(async () => {
|
|
33
|
+
this.child.stdin.end();
|
|
34
|
+
if (this.child.exitCode === null) await new Promise((resolve) => this.child.once('exit', resolve));
|
|
35
|
+
this.lines.close();
|
|
30
36
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
}
|
|
38
|
+
send(method, params, id) { this.child.stdin.write(`${JSON.stringify({ jsonrpc: '2.0', method, params, ...(id === undefined ? {} : { id }) })}\n`); }
|
|
39
|
+
request(method, params) {
|
|
40
|
+
const id = this.nextId++;
|
|
41
|
+
const promise = new Promise((resolve, reject) => {
|
|
42
|
+
const timer = setTimeout(() => { this.child.kill(); reject(new Error(`Timed out: ${method}: ${this.stderr}`)); }, 10000);
|
|
43
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
44
|
+
});
|
|
45
|
+
this.send(method, params, id);
|
|
46
|
+
return { id, promise };
|
|
47
|
+
}
|
|
48
|
+
async call(method, params) {
|
|
49
|
+
const response = await this.request(method, params).promise;
|
|
50
|
+
assert.equal(response.error, undefined, JSON.stringify(response.error));
|
|
51
|
+
return response.result;
|
|
52
|
+
}
|
|
53
|
+
async initialize() {
|
|
54
|
+
await this.call('initialize', { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'test', version: '1' } });
|
|
55
|
+
this.send('notifications/initialized');
|
|
56
|
+
}
|
|
57
|
+
review(args, name = 'codex') { return this.call('tools/call', { name, arguments: args }); }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function assertContract(options) {
|
|
61
|
+
assert.equal(options.approvalPolicy, 'never');
|
|
62
|
+
assert.equal(options.sandbox, 'read-only');
|
|
63
|
+
assert.match(options.baseInstructions, /independent computational-neuroscience/);
|
|
64
|
+
assert.match(options.baseInstructions, /Open and read `brainx-general-guard` first/);
|
|
65
|
+
assert.match(options.baseInstructions, /RETURN_TO_STUDY/);
|
|
66
|
+
assert.match(options.baseInstructions, /# BrainX iteration review/);
|
|
67
|
+
assert.match(options.developerInstructions, /TRAINING_REVIEW_REFERENCE: .*training-workflow\.md/);
|
|
68
|
+
assert.match(options.developerInstructions, /FITTING_REVIEW_REFERENCE: .*parameter-fitting-workflow\.md/);
|
|
69
|
+
assert.doesNotMatch(options.developerInstructions, /^- brainx-modeling-loop$/m);
|
|
70
|
+
assert.equal(options.config['skills.config'].length, 8);
|
|
71
|
+
assert.ok(options.config['skills.config'].every((skill) => skill.enabled));
|
|
72
|
+
assert.equal(options.config['mcp_servers.codex.enabled'], false);
|
|
73
|
+
assert.equal(options.config.approval_policy, 'never');
|
|
74
|
+
assert.equal(options.config.sandbox_mode, 'read-only');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
test('advertises legacy tool names over MCP after initializing App Server', async (t) => {
|
|
78
|
+
const session = new Session(t); await session.initialize();
|
|
79
|
+
const result = await session.call('tools/list');
|
|
80
|
+
assert.deepEqual(result.tools.map((tool) => tool.name), ['codex', 'codex-reply']);
|
|
81
|
+
assert.deepEqual(result.tools[1].inputSchema.required, ['threadId', 'prompt']);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('starts a native review with enforced instructions, read-only policy and caller settings', async (t) => {
|
|
85
|
+
const session = new Session(t); await session.initialize();
|
|
86
|
+
const result = await session.review({ prompt: 'Review iteration 4', model: 'test-model', cwd: process.cwd(),
|
|
87
|
+
sandbox: 'danger-full-access', 'approval-policy': 'on-request',
|
|
88
|
+
'base-instructions': 'bypass', config: { model_reasoning_effort: 'xhigh',
|
|
89
|
+
sandbox_mode: 'danger-full-access', 'skills.config': [],
|
|
90
|
+
mcp_servers: { other: { command: 'node' } }, 'mcp_servers.other.command': 'node' } });
|
|
91
|
+
assert.equal(result.isError, undefined);
|
|
92
|
+
const report = JSON.parse(result.content[0].text);
|
|
93
|
+
assertContract(report.thread.start);
|
|
94
|
+
assert.equal(report.thread.start.model, 'test-model');
|
|
95
|
+
assert.equal(report.thread.start.cwd, process.cwd());
|
|
96
|
+
assert.equal(report.thread.start.config.model_reasoning_effort, 'xhigh');
|
|
97
|
+
assert.equal(report.thread.start.config['mcp_servers.project_mcp.enabled'], false);
|
|
98
|
+
assert.equal(report.thread.start.config['mcp_servers.other.command'], undefined);
|
|
99
|
+
assert.equal(report.thread.start.config.mcp_servers, undefined);
|
|
100
|
+
assert.deepEqual(report.argv, ['app-server', '--listen', 'stdio://']);
|
|
101
|
+
assert.equal(result.structuredContent.threadId, 'thread-1');
|
|
102
|
+
assert.equal(result.structuredContent.content, result.content[0].text);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('resumes the same native thread and reapplies reviewer constraints', async (t) => {
|
|
106
|
+
const session = new Session(t); await session.initialize();
|
|
107
|
+
const first = await session.review({ prompt: 'first', cwd: process.cwd() });
|
|
108
|
+
const threadId = first.structuredContent.threadId;
|
|
109
|
+
const next = await session.review({ threadId, prompt: 'follow-up' }, 'codex-reply');
|
|
110
|
+
const report = JSON.parse(next.content[0].text);
|
|
111
|
+
assert.deepEqual(report.thread.history, ['first', 'follow-up']);
|
|
112
|
+
assertContract(report.thread.resume);
|
|
113
|
+
assert.equal(report.thread.resume.config['mcp_servers.project_mcp.enabled'], false);
|
|
114
|
+
assert.equal(report.thread.resume.excludeTurns, true);
|
|
115
|
+
assert.equal(next.structuredContent.threadId, threadId);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('handles completion arriving before the turn/start response', async (t) => {
|
|
119
|
+
const session = new Session(t); await session.initialize();
|
|
120
|
+
const result = await session.review({ prompt: 'early' });
|
|
121
|
+
assert.equal(result.isError, undefined);
|
|
122
|
+
assert.deepEqual(JSON.parse(result.content[0].text).thread.history, ['early']);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
for (const [prompt, message] of [['fail', /Model unavailable/], ['empty', /without a report/], ['crash', /exited/]]) {
|
|
126
|
+
test(`returns a tool error for ${prompt}`, async (t) => {
|
|
127
|
+
const session = new Session(t); await session.initialize();
|
|
128
|
+
const result = await session.review({ prompt });
|
|
129
|
+
assert.equal(result.isError, true); assert.match(result.content[0].text, message);
|
|
35
130
|
});
|
|
36
131
|
}
|
|
37
132
|
|
|
38
|
-
test('
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
assert.match(
|
|
61
|
-
assert.match(args['base-instructions'], /\*\*Architecture:\*\*/);
|
|
62
|
-
assert.match(args['base-instructions'], /\*\*Hyperparameters and method:\*\*/);
|
|
63
|
-
assert.match(args['base-instructions'], /BrainState's prebuilt `brainstate\.nn` layers/);
|
|
64
|
-
assert.match(args['base-instructions'], /braintools\.optim\.Adam/);
|
|
65
|
-
assert.match(args['base-instructions'], /BrainTools API gap/);
|
|
66
|
-
assert.match(args['base-instructions'], /RETURN_TO_STUDY/);
|
|
67
|
-
assert.match(args['base-instructions'], /Return a Markdown document as the tool response/);
|
|
68
|
-
assert.match(args['base-instructions'], /# BrainX iteration review/);
|
|
69
|
-
assert.match(args['base-instructions'], /- \*\*OUTCOME:\*\* `PASS \| REFUSE`/);
|
|
70
|
-
assert.match(args['base-instructions'], /- \*\*LOSS_CLOSURE:\*\* `NOT_APPLICABLE/);
|
|
71
|
-
assert.match(args['base-instructions'], /## Findings/);
|
|
72
|
-
assert.doesNotMatch(args['base-instructions'], /```text\s+OUTCOME:/);
|
|
73
|
-
assert.match(args['base-instructions'], /Keep plotting code minimal and clean/);
|
|
74
|
-
assert.match(args['developer-instructions'], /brainx-general-guard/);
|
|
75
|
-
assert.match(args['developer-instructions'], /TRAINING_REVIEW_REFERENCE: \/.*\/training-workflow\.md/);
|
|
76
|
-
assert.match(args['developer-instructions'], /FITTING_REVIEW_REFERENCE: \/.*\/parameter-fitting-workflow\.md/);
|
|
77
|
-
assert.doesNotMatch(args['developer-instructions'], /^- brainx-modeling-loop$/m);
|
|
78
|
-
assert.equal(args.config.model_reasoning_effort, 'xhigh');
|
|
79
|
-
assert.equal(args['approval-policy'], 'never');
|
|
80
|
-
assert.equal(args.sandbox, 'read-only');
|
|
81
|
-
assert.equal(args.config['skills.config'].length, 8);
|
|
82
|
-
assert.ok(args.config['skills.config'].every((skill) => skill.enabled));
|
|
83
|
-
assert.ok(args.config['skills.config'].every((skill) => skill.path.startsWith('/')));
|
|
133
|
+
test('declines unexpected command approval rather than granting write access', async (t) => {
|
|
134
|
+
const session = new Session(t); await session.initialize();
|
|
135
|
+
const result = await session.review({ prompt: 'approval' });
|
|
136
|
+
assert.equal(JSON.parse(result.content[0].text).decision, 'decline');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('cancellation interrupts the native turn and leaves the thread usable', async (t) => {
|
|
140
|
+
const session = new Session(t); await session.initialize();
|
|
141
|
+
const first = await session.review({ prompt: 'first' }); const threadId = first.structuredContent.threadId;
|
|
142
|
+
const request = session.request('tools/call', { name: 'codex-reply', arguments: { threadId, prompt: 'stall' } });
|
|
143
|
+
// Let the fake backend start its stalled turn before cancellation.
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
145
|
+
session.send('notifications/cancelled', { requestId: request.id });
|
|
146
|
+
const cancelled = (await request.promise).result;
|
|
147
|
+
assert.equal(cancelled.isError, true); assert.match(cancelled.content[0].text, /interrupted|cancelled/i);
|
|
148
|
+
const next = await session.review({ threadId, prompt: 'after cancellation' }, 'codex-reply');
|
|
149
|
+
assert.equal(next.isError, undefined);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('a stalled review times out instead of leaving the MCP call pending', async (t) => {
|
|
153
|
+
const session = new Session(t, { TEST_REVIEW_TIMEOUT_MS: '300' }); await session.initialize();
|
|
154
|
+
const result = await session.review({ prompt: 'stall' });
|
|
155
|
+
assert.equal(result.isError, true); assert.match(result.content[0].text, /timed out/);
|
|
84
156
|
});
|
|
85
157
|
|
|
86
|
-
test('
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
158
|
+
test('rejects invalid input, unknown tools, and requests before initialization', async (t) => {
|
|
159
|
+
const session = new Session(t);
|
|
160
|
+
assert.equal((await session.request('tools/list').promise).error.code, -32000);
|
|
161
|
+
await session.initialize();
|
|
162
|
+
assert.equal((await session.review({ prompt: '' })).isError, true);
|
|
163
|
+
assert.equal((await session.review({ prompt: 'x', profile: 'unsafe' })).isError, true);
|
|
164
|
+
assert.equal((await session.request('tools/call', { name: 'unknown', arguments: {} }).promise).error.code, -32602);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('resolves Windows npm shims without a shell and preserves argument boundaries', () => {
|
|
168
|
+
const entry = 'C:\\Program Files\\npm\\node_modules\\@openai\\codex\\bin\\codex.js';
|
|
169
|
+
const shim = 'C:\\Program Files\\npm\\codex.cmd';
|
|
170
|
+
const invocation = codexInvocation('codex', ['argument with spaces'], {
|
|
171
|
+
platform: 'win32', pathValue: 'C:\\missing;"C:\\Program Files\\npm"',
|
|
172
|
+
exists: (path) => [shim, entry].includes(path),
|
|
173
|
+
});
|
|
174
|
+
assert.equal(invocation.binary, process.execPath);
|
|
175
|
+
assert.deepEqual(invocation.prefixArgs, [entry, 'argument with spaces']);
|
|
176
|
+
assert.throws(() => codexInvocation(shim, [], { platform: 'win32', exists: () => false }), /BRAINX_CODEX_BIN/);
|
|
177
|
+
|
|
178
|
+
const localShim = 'C:\\Program Files\\npm\\node_modules\\.bin\\codex.cmd';
|
|
179
|
+
assert.deepEqual(codexInvocation(localShim, [], {
|
|
180
|
+
platform: 'win32', exists: (path) => path === entry,
|
|
181
|
+
}), { binary: process.execPath, prefixArgs: [entry] });
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('runs npm through its JavaScript entry when installing runtimes on Windows', () => {
|
|
185
|
+
const root = 'C:\\Program Files\\nodejs';
|
|
186
|
+
const entry = `${root}\\node_modules\\npm\\bin\\npm-cli.js`;
|
|
187
|
+
const args = ['install', '--ignore-scripts'];
|
|
188
|
+
const options = {
|
|
189
|
+
platform: 'win32', pathValue: root,
|
|
190
|
+
exists: (path) => [`${root}\\npm.cmd`, entry].includes(path),
|
|
95
191
|
};
|
|
96
|
-
const
|
|
192
|
+
for (const npmExecPath of ['', entry]) {
|
|
193
|
+
const invocation = npmInvocation('npm', args, { ...options, npmExecPath });
|
|
194
|
+
assert.deepEqual(invocation, { binary: process.execPath, prefixArgs: [entry, ...args] });
|
|
195
|
+
}
|
|
196
|
+
});
|
|
97
197
|
|
|
98
|
-
|
|
198
|
+
test('does not manufacture an invalid disabled MCP transport in an empty child configuration', async (t) => {
|
|
199
|
+
const session = new Session(t, { TEST_NO_MCP: '1' }); await session.initialize();
|
|
200
|
+
const result = await session.review({ prompt: 'isolated config' });
|
|
201
|
+
assert.equal(result.isError, undefined);
|
|
202
|
+
assert.equal(JSON.parse(result.content[0].text).thread.start.config['mcp_servers.codex.enabled'], undefined);
|
|
99
203
|
});
|
package/package.json
CHANGED
|
@@ -103,13 +103,15 @@ Turn the researcher's request and inspected data into a short `NeuroSpecificatio
|
|
|
103
103
|
|
|
104
104
|
### Clarification gate
|
|
105
105
|
|
|
106
|
-
Inspect the request, repository, supplied data, and referenced specifications first.
|
|
106
|
+
Inspect the request, repository, supplied data, and referenced specifications first. Build the decision frontier from unresolved scientific intent or data and experimental facts that cannot reasonably be inferred and require the researcher's decision. Include conflicts in the requested goal or represented scale, unknown data units or semantics, missing experimental conditions, an unclear explicit reproduction target, or a proposed change to fixed design or acceptance criteria.
|
|
107
107
|
|
|
108
|
-
Apply this gate before opening step-1 package skills. **Hard stop:** if
|
|
108
|
+
Apply this gate before opening step-1 package skills. **Hard stop:** if such a consequential choice remains unresolved and has not been delegated, ask the researcher and wait for the answer in the current conversation. Do not invoke step 1, write model or experiment code, run experiments, or silently lock the specification while that answer is pending. Do not treat a development request as permission to change user-fixed goals, scales, mechanisms, data meaning, or acceptance criteria.
|
|
109
|
+
|
|
110
|
+
For open model development, choose reasonable unspecified implementation details, parameters, solvers, sample sizes, controls, and analysis definitions within the supplied scientific scope; record them as agent choices, validate their consequences, and bound the claims. Their effect on numerical results alone does not make them researcher decisions. Use the development request as authorization to proceed within that scope, without a second specification-approval gate. A reference list supplies context, not an instruction to reproduce a paper quantitatively; ask about reproduction scope only when reproduction is explicitly requested or the supplied requirements conflict.
|
|
109
111
|
|
|
110
112
|
Ask one question at a time, ordered by dependency: settle a parent choice before asking decisions that depend on it. Each question must use the researcher's terminology and state why the answer changes the model or the interpretation. Give a recommended answer when a defensible default exists, show the relevant alternatives, and allow the researcher to say `choose for me`, `use the recommended default`, or `I don't know`. Treat the first two replies as explicit delegation or confirmation and record the resulting choice. Treat `I don't know` as unresolved: do not guess or advance; offer a small exploratory branch only when the researcher authorizes it. If a question can be answered by reading the repository or data, inspect them instead of asking.
|
|
111
113
|
|
|
112
|
-
Draft `NeuroSpecification.md` even when no consequential choice is open. Record each pending decision, question, and proposed default under `Open decisions and handling`, with `Researcher approval: pending`.
|
|
114
|
+
Draft `NeuroSpecification.md` even when no consequential choice is open. Record each pending decision, question, and proposed default under `Open decisions and handling`, with `Researcher approval: pending`. Once required researcher decisions are resolved or delegated, lock the specification under the existing authorization if it covers the proposed scope. Ask for authorization if proceeding would exceed that scope. When locking, set `Status: locked`, record the authorization, update `report.md` with `Report status: draft`, and evaluate the literature gate.
|
|
113
115
|
|
|
114
116
|
Use a compact prompt shape:
|
|
115
117
|
|
|
@@ -127,13 +129,13 @@ While an answer or authorization is pending, append a step-0 checkpoint and set
|
|
|
127
129
|
|
|
128
130
|
| Open decision type | Clarification and design response |
|
|
129
131
|
|---|---|
|
|
130
|
-
|
|
|
132
|
+
| Computational setting missing from a specified model or method | Choose, document, and validate settings that preserve the supplied scientific scope. Ask only when choosing would resolve a researcher-owned scientific uncertainty, reinterpret data, change fixed design, or invent a required reproduction contract. |
|
|
131
133
|
| Experimental fact missing from a phenomena-only request | Ask only about observations and experimental conditions that affect model choice or interpretation: measured readouts, compared samples, intervention strength or timing, and relevant controls. Choose and justify the abstraction, parameters, solver, and checks without asking the researcher to supply computational settings. Experimental measurements with numbers alone do not imply a request for technical design discussion. |
|
|
132
|
-
| Computational and experimental decisions both remain open |
|
|
134
|
+
| Computational and experimental decisions both remain open | Choose implementation settings within the supplied design; clarify unresolved scientific intent and experimental facts before implementation. |
|
|
133
135
|
|
|
134
|
-
Honor explicit collaboration directions
|
|
136
|
+
Honor explicit collaboration directions to choose the remaining settings or discuss the design. For decisions that require the researcher's input under the clarification gate, keep a proposed default pending until they confirm it or delegate the choice.
|
|
135
137
|
|
|
136
|
-
Distinguish experimental measurements, user-specified modeling assumptions, literature context, and agent choices.
|
|
138
|
+
Distinguish experimental measurements, user-specified modeling assumptions, literature context, and agent choices. Mark proposed defaults for pending researcher decisions as provisional. While waiting, perform only read-only inspection that helps resolve the pending question. Label selected implementation settings as agent choices and state what evidence would be needed to claim an exact reproduction.
|
|
137
139
|
|
|
138
140
|
When explaining an experimental phenomenon, comparing mechanisms, or deciding whether modeling can distinguish them, open `references/mechanism-comparison.md` before selecting the implementation. It defines causal chains, measurement mapping, distinguishable predictions, and which unmeasured assumptions to test first.
|
|
139
141
|
|
|
@@ -154,7 +156,7 @@ Use only this core structure:
|
|
|
154
156
|
- Execution mode: forward-simulation | task-training | parameter-fitting | hybrid
|
|
155
157
|
- Required outputs:
|
|
156
158
|
- Constraints:
|
|
157
|
-
- Open decisions and handling: <pending
|
|
159
|
+
- Open decisions and handling: <pending researcher decision, delegated choice, or agent-selected setting>
|
|
158
160
|
|
|
159
161
|
## Inspected data contract
|
|
160
162
|
- Data sources and inspected contents:
|
|
@@ -172,7 +174,7 @@ Use only this core structure:
|
|
|
172
174
|
- Model/comparison rationale and decisive assumption checks: <brief rationale or artifact path>
|
|
173
175
|
```
|
|
174
176
|
|
|
175
|
-
Inspect supplied data before completing its contract. Keep raw data read-only, preserve units and axis meaning, and prevent preprocessing leakage.
|
|
177
|
+
Inspect supplied data before completing its contract. Keep raw data read-only, preserve units and axis meaning, and prevent preprocessing leakage. Once the clarification gate is complete, evaluate the literature gate using the locked specification before proceeding to step 1.
|
|
176
178
|
|
|
177
179
|
### Optional literature gate after the NeuroSpecification
|
|
178
180
|
|
|
@@ -195,8 +197,8 @@ When the gate triggers:
|
|
|
195
197
|
2. Invoke `bio-neuro-lit` and require it to distinguish full-text from abstract-only evidence, publication versions, consensus, disagreement, and non-claims.
|
|
196
198
|
3. Have `bio-neuro-lit` append its essential modeling consequences to `brainmodeling-memory.md` as `## Literature evidence`, without changing the current checkpoint.
|
|
197
199
|
4. Reconcile the evidence with `NeuroSpecification.md`. Preserve supported choices, encode unresolved alternatives and discriminating controls, and narrow claims that the evidence does not justify.
|
|
198
|
-
5.
|
|
199
|
-
6. If the evidence remains inconclusive
|
|
200
|
+
5. When evidence changes the locked specification, mark the revision `draft`, record the reason, and apply the same clarification gate. Ask when a researcher decision remains unresolved or the revision exceeds the existing authorization. Relock once the gate is satisfied and append a corrected step-0 checkpoint that names the earlier checkpoint it supersedes.
|
|
201
|
+
6. If the evidence remains inconclusive, retain the uncertainty as a limitation and specify a discriminating test when the authorized scope supports one. Ask the researcher to choose a direction when the alternatives leave a researcher-owned decision unresolved.
|
|
200
202
|
|
|
201
203
|
When the gate does not trigger, record the skip and its reason as a step-0 milestone. Do not perform a broad background review merely to make the study record look comprehensive.
|
|
202
204
|
|
|
@@ -110,6 +110,8 @@ assert trials["x"].shape == (1000, 8, 1)
|
|
|
110
110
|
|
|
111
111
|
Seed again before a repeated run when exact replay matters.
|
|
112
112
|
|
|
113
|
+
Open `references/braintools/parameter-initializer.md` before sampling initial activity or parameters, including dimensionless initial arrays; it covers distribution choice, explicit RNG ownership and frozen-array replay before State initialization.
|
|
114
|
+
|
|
113
115
|
Do not flatten experimental conditions and stochastic trials into `in_size` unless a required external layout or numerical baseline demands it.
|
|
114
116
|
|
|
115
117
|
Open `references/noiseprocesses.md` when choosing white, OU, Brownian, or colored noise, using a noise process directly, or checking units and State behavior. Open `references/simulator-input-monitor-api.md` when batching stochastic trials or driving multiple conditions. Open `references/batch-transform-acceleration.md` when batching parameters, writing a custom transformed loop that `Simulator` cannot express, or checkpointing a long differentiated rollout.
|
|
@@ -267,7 +269,7 @@ Choose the workflow category first, then open only the smallest reference that o
|
|
|
267
269
|
| `references/datasets-api.md` | Loading, inspecting, generating, or registering BrainMass data containers. |
|
|
268
270
|
| `references/coupling-network-api.md` | Selecting or configuring coupling, delays, connectivity conventions, direct coupling objects, or trainable network parameters. |
|
|
269
271
|
| `references/forward-observation-api.md` | Selecting BOLD, HRF kernels, temporal averaging, EEG/MEG lead fields, or trainable readouts. |
|
|
270
|
-
| `references/visualization-analysis-api.md` | Plotting or computing
|
|
272
|
+
| `references/visualization-analysis-api.md` | Plotting or computing Pearson diagnostics, including lag-aligned signal pairs, time-series, FC, FCD, and spectral summaries. |
|
|
271
273
|
|
|
272
274
|
### Fitting and regime exploration
|
|
273
275
|
|
|
@@ -99,6 +99,16 @@ reduce them.
|
|
|
99
99
|
| `population.functional_connectivity(activities)` | Return the pairwise Pearson correlation matrix for `(num_time, num_signals)` data; NaNs are replaced with zero. |
|
|
100
100
|
| `population.functional_connectivity_dynamics(activities, window_size, step_size)` | Correlate the strict upper triangles of windowed FC matrices. Specify window size and step in samples. |
|
|
101
101
|
|
|
102
|
+
For an unweighted Pearson diagnostic on two aligned signals, stack them as
|
|
103
|
+
columns and read `[0, 1]` from
|
|
104
|
+
`braintools.analysis.population.functional_connectivity(observations)`.
|
|
105
|
+
For lag correlation, align the lagged slices before stacking. Check for finite
|
|
106
|
+
inputs and at least two distinct values per column. The API's
|
|
107
|
+
NaN-to-zero policy must not turn an undefined diagnostic into evidence of no
|
|
108
|
+
association. Keep weighted and matrix-triangle correlation on their dedicated
|
|
109
|
+
APIs. This contract targets BrainTools 0.4.0; see the
|
|
110
|
+
[official Pearson API](https://brainx.chaobrain.com/braintools/apis/generated/braintools.analysis.population.functional_connectivity.html).
|
|
111
|
+
|
|
102
112
|
## Spike-train metrics
|
|
103
113
|
|
|
104
114
|
Pass physical time quantities on BrainTools 0.4. Bare `dt` values are in
|
|
@@ -6,8 +6,8 @@ variance scaling, orthogonal methods, composition, and distance-based weight
|
|
|
6
6
|
modulation.
|
|
7
7
|
|
|
8
8
|
For BrainMass, use these initializers for model State, fitted starting values,
|
|
9
|
-
HORN weights, or distance-modulated network parameters
|
|
10
|
-
accepts
|
|
9
|
+
HORN weights, or distance-modulated network parameters. Resolve the initializer
|
|
10
|
+
explicitly when the consuming API accepts only concrete arrays.
|
|
11
11
|
|
|
12
12
|
## Choose an initializer
|
|
13
13
|
|
|
@@ -36,11 +36,11 @@ accept an initializer, scalar, array, or quantity through one boundary.
|
|
|
36
36
|
```python
|
|
37
37
|
import brainunit as u
|
|
38
38
|
import numpy as np
|
|
39
|
-
|
|
39
|
+
import braintools
|
|
40
40
|
|
|
41
41
|
rng = np.random.default_rng(0)
|
|
42
|
-
initializer = Normal(mean=0.5 * u.nS, std=0.1 * u.nS)
|
|
43
|
-
weights = param(initializer, sizes=100, rng=rng)
|
|
42
|
+
initializer = braintools.init.Normal(mean=0.5 * u.nS, std=0.1 * u.nS)
|
|
43
|
+
weights = braintools.init.param(initializer, sizes=100, rng=rng)
|
|
44
44
|
|
|
45
45
|
assert weights.shape == (100,)
|
|
46
46
|
assert weights.unit == u.nS
|
|
@@ -49,6 +49,33 @@ assert weights.unit == u.nS
|
|
|
49
49
|
**Invariant:** pass an explicit RNG when reproducibility matters. Do not strip a
|
|
50
50
|
quantity's unit to make an initializer accept it.
|
|
51
51
|
|
|
52
|
+
## Resolve bounded initial arrays
|
|
53
|
+
|
|
54
|
+
Use an initializer for newly sampled initial conditions even when the model
|
|
55
|
+
accepts only concrete arrays. Preserve supplied or frozen arrays rather than
|
|
56
|
+
resampling them. A NumPy Generator passed as `rng=` is the documented backend;
|
|
57
|
+
let the BrainTools distribution own the draw.
|
|
58
|
+
|
|
59
|
+
| API | Description |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `braintools.init.Uniform(low, high)(shape, rng=...)` | Sample bounded physical or dimensionless initial values with explicit axes and RNG before constructing State. |
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import braintools
|
|
65
|
+
import numpy as np
|
|
66
|
+
|
|
67
|
+
initial_activity = braintools.init.Uniform(0.05, 0.15)(
|
|
68
|
+
(3, 2), rng=np.random.default_rng(2001),
|
|
69
|
+
)
|
|
70
|
+
assert initial_activity.shape == (3, 2) # observer, population
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Store and reuse the sampled array for a matched initial condition. For a legacy
|
|
74
|
+
per-observer RNG schedule, call the initializer once with each original stream
|
|
75
|
+
and shape; one combined draw is not necessarily the same experiment. Compare
|
|
76
|
+
saved values, axes, dtype and units before claiming exact replay. BrainState's
|
|
77
|
+
operational seed does not seed these host-side Generators.
|
|
78
|
+
|
|
52
79
|
## Basic distributions
|
|
53
80
|
|
|
54
81
|
| API | Description |
|
|
@@ -157,7 +184,9 @@ initializer = DistanceModulated(
|
|
|
157
184
|
distance_profile=profile,
|
|
158
185
|
).clip(min_val=0.01 * u.nS)
|
|
159
186
|
|
|
160
|
-
distances =
|
|
187
|
+
distances = braintools.init.Uniform(0 * u.um, 500 * u.um)(
|
|
188
|
+
1000, rng=np.random.default_rng(1),
|
|
189
|
+
)
|
|
161
190
|
weights = initializer(1000, distances=distances, rng=rng)
|
|
162
191
|
```
|
|
163
192
|
|
|
@@ -184,4 +213,5 @@ composition; `DistanceModulated` does not accept a `min_weight` argument.
|
|
|
184
213
|
|
|
185
214
|
## Official source
|
|
186
215
|
|
|
187
|
-
-
|
|
216
|
+
- [Initializer API](https://brainx.chaobrain.com/braintools/apis/init.html)
|
|
217
|
+
- [Uniform and explicit RNG example](https://brainx.chaobrain.com/braintools/apis/generated/braintools.init.Uniform.html)
|