@aisac/cli 0.4.0-beta.2 → 0.4.0-beta.22
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 +146 -10
- package/dist/assets/claude/hooks/context-compaction.ts +17 -5
- package/dist/assets/claude/hooks/native-host-contract-runtime.ts +1 -1
- package/dist/assets/claude/hooks/native-host-contract.test.ts +8 -4
- package/dist/assets/claude/hooks/provider-window.d.ts +83 -0
- package/dist/assets/codex-context-compaction.mjs +846 -14
- package/dist/assets/jev-paid-pilot-terminal.mjs +12 -1
- package/dist/claude-compatibility.mjs +26 -25
- package/dist/claude-observation.mjs +2 -1
- package/dist/cli.mjs +641 -35
- package/dist/codex-compatibility.mjs +48 -2
- package/dist/codex-engineering.mjs +165 -0
- package/dist/codex-hooks.mjs +411 -0
- package/dist/codex-permissions.mjs +67 -34
- package/dist/codex-protocol-fingerprint.json +11 -11
- package/dist/engineering-init.mjs +615 -0
- package/dist/engineering-pack.mjs +276 -23
- package/dist/engineering-scan-pins.json +42 -0
- package/dist/engineering-scan-report.mjs +1274 -0
- package/dist/engineering-scan-tools.mjs +1418 -0
- package/dist/engineering-scan.mjs +1265 -0
- package/dist/extensions-catalog.mjs +390 -0
- package/dist/extensions-cli.mjs +492 -0
- package/dist/extensions-preferences.mjs +151 -0
- package/dist/guardrails/continuity.mjs +239 -0
- package/dist/guardrails/format.mjs +111 -0
- package/dist/guardrails/guards.mjs +1557 -0
- package/dist/guardrails/patch.mjs +33 -0
- package/dist/guardrails/run.mjs +286 -0
- package/dist/guardrails/shell-words.mjs +206 -0
- package/dist/guardrails-plugin.mjs +207 -0
- package/dist/launch.mjs +403 -47
- package/dist/managed-host.mjs +977 -0
- package/dist/manager/bus.mjs +1921 -0
- package/dist/manager/delegation.mjs +354 -0
- package/dist/manager/hooks.mjs +918 -0
- package/dist/manager/launch-role.mjs +476 -0
- package/dist/manager/mcp-stdio.mjs +463 -0
- package/dist/manager/messages.mjs +791 -0
- package/dist/manager/reserve.mjs +2166 -0
- package/dist/manager/room.mjs +106 -0
- package/dist/manager/server.mjs +1792 -0
- package/dist/manager/status.mjs +118 -0
- package/dist/manager/watch.mjs +87 -0
- package/dist/manager/worker.mjs +2793 -0
- package/dist/manager/workers-cli.mjs +1403 -0
- package/dist/mcp-servers.mjs +192 -0
- package/dist/mcp.mjs +10 -2
- package/dist/monitor.mjs +76 -1
- package/dist/package.json +1 -1
- package/dist/platform.mjs +78 -29
- package/dist/release-manifest-public-keys.json +10 -0
- package/dist/release-manifest.json +328 -0
- package/dist/release-manifest.mjs +817 -0
- package/dist/release-settings.mjs +210 -0
- package/dist/self-update.mjs +1036 -0
- package/dist/state.mjs +25 -1
- package/dist/token-guide.mjs +132 -0
- package/dist/update-actions.mjs +442 -0
- package/package.json +1 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* Session configuration for the MCP catalog (spec aisac-engineering-extensions
|
|
4
|
+
* FR5.6, FR6, FR7): entries for Claude Code's `--mcp-config` file, and
|
|
5
|
+
* `-c mcp_servers.*` flags for the app-server that `aisac codex` owns. Only
|
|
6
|
+
* catalog ids reach this module from outside; every URL, command and argument
|
|
7
|
+
* comes from the catalog in this package. AISAC never reads or stores a
|
|
8
|
+
* third-party credential: logins live in the host's own store, and a token
|
|
9
|
+
* variable is only named, never read here.
|
|
10
|
+
*/
|
|
11
|
+
import { MCP_CATALOG, MCP_SERVER_PREFIX, mcpById } from './extensions-catalog.mjs';
|
|
12
|
+
import { tomlBasicString } from './codex-engineering.mjs';
|
|
13
|
+
|
|
14
|
+
/** @typedef {import('./extensions-catalog.mjs').McpEntry} McpEntry */
|
|
15
|
+
/** @typedef {'claude' | 'codex'} McpClient */
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} SessionServers
|
|
18
|
+
* @property {McpEntry[]} ready Servers that join the session.
|
|
19
|
+
* @property {{ id: string, variable: string }[]} missingEnv Skipped: the token variable is unset.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** The launcher hands the Codex monitor the ready ids in this variable. */
|
|
23
|
+
export const CODEX_MCP_ENV = 'AISAC_EXTENSIONS_CODEX_MCP';
|
|
24
|
+
const STDIO_STARTUP_TIMEOUT_SEC = 60;
|
|
25
|
+
const MAX_IDS = 16;
|
|
26
|
+
const MAX_IDS_BYTES = 1024;
|
|
27
|
+
|
|
28
|
+
/** @param {string} id */
|
|
29
|
+
export function serverName(id) {
|
|
30
|
+
return `${MCP_SERVER_PREFIX}${id}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Catalog entries for these ids that support the client. A token server whose
|
|
35
|
+
* variable is unset is skipped with a reason instead of failing in the host.
|
|
36
|
+
* @param {readonly string[]} ids
|
|
37
|
+
* @param {McpClient} client
|
|
38
|
+
* @param {NodeJS.ProcessEnv} environment
|
|
39
|
+
* @returns {SessionServers}
|
|
40
|
+
*/
|
|
41
|
+
export function sessionServers(ids, client, environment) {
|
|
42
|
+
/** @type {SessionServers} */
|
|
43
|
+
const result = { ready: [], missingEnv: [] };
|
|
44
|
+
for (const id of new Set(ids)) {
|
|
45
|
+
const entry = mcpById(id);
|
|
46
|
+
if (entry === undefined || !entry.clients.includes(client)) continue;
|
|
47
|
+
const variable = entry.transport.type === 'http' ? entry.transport.bearerEnv : undefined;
|
|
48
|
+
if (variable !== undefined && !environment[variable]?.trim()) {
|
|
49
|
+
result.missingEnv.push({ id, variable });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
result.ready.push(entry);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* `--mcp-config` entries. A token header uses Claude Code's `${VAR}` expansion,
|
|
59
|
+
* so the token never reaches the session file.
|
|
60
|
+
* @param {readonly McpEntry[]} entries
|
|
61
|
+
* @returns {Record<string, Record<string, unknown>>}
|
|
62
|
+
*/
|
|
63
|
+
export function claudeMcpEntries(entries) {
|
|
64
|
+
/** @type {Record<string, Record<string, unknown>>} */
|
|
65
|
+
const servers = {};
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
const { transport } = entry;
|
|
68
|
+
servers[serverName(entry.id)] =
|
|
69
|
+
transport.type === 'stdio'
|
|
70
|
+
? { type: 'stdio', command: transport.command, args: [...transport.args] }
|
|
71
|
+
: {
|
|
72
|
+
type: 'http',
|
|
73
|
+
url: transport.url,
|
|
74
|
+
...(transport.bearerEnv === undefined
|
|
75
|
+
? {}
|
|
76
|
+
: { headers: { Authorization: `Bearer \${${transport.bearerEnv}}` } }),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return servers;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Claude Code deny rules for the tools that spend money (FR7.2). They cover every
|
|
84
|
+
* catalog server, loaded or not, so the settings file can be written before the
|
|
85
|
+
* license is confirmed; a rule for a server that is not loaded matches nothing.
|
|
86
|
+
* Claude evaluates deny rules before allow rules, in every permission mode, and a
|
|
87
|
+
* deny rule removes the tool from the model's context (measured M1, Claude 2.1.318).
|
|
88
|
+
* @param {readonly McpEntry[]} [entries]
|
|
89
|
+
* @returns {string[]}
|
|
90
|
+
*/
|
|
91
|
+
export function claudeDenyRules(entries = MCP_CATALOG) {
|
|
92
|
+
return entries.flatMap((entry) => {
|
|
93
|
+
const prefix = `mcp__${serverName(entry.id)}__`;
|
|
94
|
+
return [
|
|
95
|
+
...(entry.blockedTools ?? []).map((tool) => `${prefix}${tool}`),
|
|
96
|
+
...(entry.blockedToolPrefixes ?? []).map((start) => `${prefix}${start}*`),
|
|
97
|
+
];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Session-only `-c` overrides for the owned Codex app-server. A server with
|
|
103
|
+
* blocked tools gets `disabled_tools` (FR7.2; measured M2, Codex 0.164.0).
|
|
104
|
+
* @param {readonly McpEntry[]} entries
|
|
105
|
+
* @returns {string[]}
|
|
106
|
+
*/
|
|
107
|
+
export function codexMcpConfigArgs(entries) {
|
|
108
|
+
return entries.flatMap((entry) => {
|
|
109
|
+
const key = `mcp_servers.${serverName(entry.id)}`;
|
|
110
|
+
const { transport } = entry;
|
|
111
|
+
const blocked = entry.blockedTools ?? [];
|
|
112
|
+
const disabled =
|
|
113
|
+
blocked.length === 0
|
|
114
|
+
? []
|
|
115
|
+
: ['-c', `${key}.disabled_tools=[${blocked.map(tomlBasicString).join(',')}]`];
|
|
116
|
+
if (transport.type === 'stdio')
|
|
117
|
+
return [
|
|
118
|
+
'-c',
|
|
119
|
+
`${key}.command=${tomlBasicString(transport.command)}`,
|
|
120
|
+
'-c',
|
|
121
|
+
`${key}.args=[${transport.args.map(tomlBasicString).join(',')}]`,
|
|
122
|
+
'-c',
|
|
123
|
+
`${key}.startup_timeout_sec=${STDIO_STARTUP_TIMEOUT_SEC}`,
|
|
124
|
+
...disabled,
|
|
125
|
+
];
|
|
126
|
+
return [
|
|
127
|
+
'-c',
|
|
128
|
+
`${key}.url=${tomlBasicString(transport.url)}`,
|
|
129
|
+
...(transport.bearerEnv === undefined
|
|
130
|
+
? []
|
|
131
|
+
: ['-c', `${key}.bearer_token_env_var=${tomlBasicString(transport.bearerEnv)}`]),
|
|
132
|
+
...disabled,
|
|
133
|
+
];
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The monitor's copy of the ready ids: a JSON array of catalog ids for Codex.
|
|
139
|
+
* Anything else throws, and the monitor then starts without catalog servers.
|
|
140
|
+
* @param {string | undefined} raw
|
|
141
|
+
* @returns {McpEntry[]}
|
|
142
|
+
*/
|
|
143
|
+
export function parseCodexMcp(raw) {
|
|
144
|
+
if (raw === undefined || raw === '') return [];
|
|
145
|
+
if (Buffer.byteLength(raw, 'utf8') > MAX_IDS_BYTES) throw new Error('codex_mcp_too_large');
|
|
146
|
+
const value = JSON.parse(raw);
|
|
147
|
+
if (!Array.isArray(value) || value.length > MAX_IDS) throw new Error('codex_mcp_invalid');
|
|
148
|
+
return value.map((id) => {
|
|
149
|
+
const entry = typeof id === 'string' ? mcpById(id) : undefined;
|
|
150
|
+
if (entry === undefined || !entry.clients.includes('codex'))
|
|
151
|
+
throw new Error('codex_mcp_invalid');
|
|
152
|
+
return entry;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Arguments for `codex` that log in to one catalog server with the same session
|
|
158
|
+
* flags `aisac codex` passes, so the next session finds the stored login.
|
|
159
|
+
* Spike Q5 (2026-11-03, Codex 0.164.0) measured this path end to end.
|
|
160
|
+
* @param {McpEntry} entry
|
|
161
|
+
*/
|
|
162
|
+
export function codexLoginArgs(entry) {
|
|
163
|
+
return [...codexMcpConfigArgs([entry]), 'mcp', 'login', serverName(entry.id)];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** @param {McpEntry} entry */
|
|
167
|
+
export function supportsHostLogin(entry) {
|
|
168
|
+
return entry.login === 'host-oauth' || entry.login === 'optional-oauth';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Launch lines: counts and names only, never a value.
|
|
173
|
+
* @param {SessionServers} servers
|
|
174
|
+
* @param {McpClient} client
|
|
175
|
+
* @returns {string[]}
|
|
176
|
+
*/
|
|
177
|
+
export function mcpLaunchLines(servers, client) {
|
|
178
|
+
/** @type {string[]} */
|
|
179
|
+
const lines = [];
|
|
180
|
+
const count = servers.ready.length;
|
|
181
|
+
if (count > 0) {
|
|
182
|
+
const login = client === 'claude' ? 'log in with /mcp' : 'log in with `aisac mcp login <id>`';
|
|
183
|
+
lines.push(
|
|
184
|
+
`AISAC Engineering: ${count} MCP server${count === 1 ? '' : 's'} on (${login}; aisac mcp to change them).`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
for (const skipped of servers.missingEnv)
|
|
188
|
+
lines.push(
|
|
189
|
+
`AISAC Engineering: ${serverName(skipped.id)} skipped: set ${skipped.variable} (aisac mcp info ${skipped.id}).`,
|
|
190
|
+
);
|
|
191
|
+
return lines;
|
|
192
|
+
}
|
package/dist/mcp.mjs
CHANGED
|
@@ -556,11 +556,14 @@ function structuredErrorCode(result) {
|
|
|
556
556
|
const text = result.content.find((item) => isObject(item) && typeof item.text === 'string')?.text;
|
|
557
557
|
const prefix =
|
|
558
558
|
typeof text === 'string'
|
|
559
|
-
? /^(FEATURE_DISABLED|TOOL_UNAVAILABLE|PAID_PLAN_REQUIRED)(?::|$)/u.exec(
|
|
559
|
+
? /^(FEATURE_DISABLED|TOOL_UNAVAILABLE|PAID_PLAN_REQUIRED|INVALID_INPUT)(?::|$)/u.exec(
|
|
560
|
+
text,
|
|
561
|
+
)?.[1]
|
|
560
562
|
: undefined;
|
|
561
563
|
if (prefix === 'FEATURE_DISABLED') return 'mcp_feature_disabled';
|
|
562
564
|
if (prefix === 'TOOL_UNAVAILABLE') return 'mcp_tool_unavailable';
|
|
563
565
|
if (prefix === 'PAID_PLAN_REQUIRED') return 'mcp_paid_plan_required';
|
|
566
|
+
if (prefix === 'INVALID_INPUT') return 'mcp_invalid_input';
|
|
564
567
|
return undefined;
|
|
565
568
|
}
|
|
566
569
|
|
|
@@ -923,7 +926,12 @@ export async function providerFreeProbeV2(endpoint, token, policy, clients) {
|
|
|
923
926
|
name === 'brain_context_select',
|
|
924
927
|
)
|
|
925
928
|
)
|
|
926
|
-
|
|
929
|
+
// A tool error carries the server's own code (paid plan, cohort, clock
|
|
930
|
+
// skew, disabled feature); only a reply that breaks the v2 contract is
|
|
931
|
+
// `mcp_v2_unsupported`. Same precedence as the v1 probe.
|
|
932
|
+
throw new Error(
|
|
933
|
+
responseError(response.response, structuredErrorCode(result) ?? 'mcp_v2_unsupported'),
|
|
934
|
+
);
|
|
927
935
|
};
|
|
928
936
|
await callTool(2, 'brain_context_select', {
|
|
929
937
|
schema_version: 2,
|
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';
|
|
@@ -12,6 +12,20 @@ import {
|
|
|
12
12
|
ownedAppServerConfigArgs,
|
|
13
13
|
parseCodexLaunchEnvelope,
|
|
14
14
|
} from './codex-permissions.mjs';
|
|
15
|
+
import {
|
|
16
|
+
CODEX_ENGINEERING_ENV,
|
|
17
|
+
CODEX_ENGINEERING_SKILLS_ROOT_ENV,
|
|
18
|
+
codexEngineeringConfigArgs,
|
|
19
|
+
parseCodexEngineering,
|
|
20
|
+
} from './codex-engineering.mjs';
|
|
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';
|
|
15
29
|
|
|
16
30
|
const root = dirname(fileURLToPath(import.meta.url));
|
|
17
31
|
const endpoint = process.env.AIBRAIN_MCP_URL?.trim();
|
|
@@ -32,6 +46,55 @@ if (parsed.search) throw new Error('aibrain_monitor_endpoint_query');
|
|
|
32
46
|
const canonical = join(root, 'assets', 'codex-context-compaction.mjs');
|
|
33
47
|
await access(canonical, constants.R_OK);
|
|
34
48
|
const launchEnvelope = parseCodexLaunchEnvelope(process.env[CODEX_LAUNCH_ENVELOPE]);
|
|
49
|
+
// AISAC Engineering (E4c): a malformed value starts the session without the pack.
|
|
50
|
+
let engineering = null;
|
|
51
|
+
try {
|
|
52
|
+
const stateDir = process.env.AIBRAIN_STATE_DIR;
|
|
53
|
+
engineering = parseCodexEngineering(
|
|
54
|
+
process.env[CODEX_ENGINEERING_ENV],
|
|
55
|
+
stateDir === undefined ? {} : { stateDir },
|
|
56
|
+
);
|
|
57
|
+
} catch {
|
|
58
|
+
engineering = null;
|
|
59
|
+
}
|
|
60
|
+
// MCP catalog servers (E6c) follow the pack: no license, no servers. A malformed
|
|
61
|
+
// value starts the session without them.
|
|
62
|
+
/** @type {import('./mcp-servers.mjs').McpEntry[]} */
|
|
63
|
+
let catalogServers = [];
|
|
64
|
+
try {
|
|
65
|
+
catalogServers = engineering === null ? [] : parseCodexMcp(process.env[CODEX_MCP_ENV]);
|
|
66
|
+
} catch {
|
|
67
|
+
catalogServers = [];
|
|
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
|
+
}
|
|
35
98
|
const policyText = process.env.CODEX_CONTEXT_POLICY_JSON;
|
|
36
99
|
let policy;
|
|
37
100
|
if (policyText === undefined) {
|
|
@@ -89,6 +152,15 @@ const env = {
|
|
|
89
152
|
};
|
|
90
153
|
delete env[CODEX_LAUNCH_ENVELOPE];
|
|
91
154
|
delete env[CODEX_APP_SERVER_PROFILE];
|
|
155
|
+
delete env[CODEX_ENGINEERING_ENV];
|
|
156
|
+
delete env[CODEX_ENGINEERING_SKILLS_ROOT_ENV];
|
|
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;
|
|
163
|
+
if (engineering !== null) env[CODEX_ENGINEERING_SKILLS_ROOT_ENV] = engineering.skillsRoot;
|
|
92
164
|
if (launchEnvelope?.profile !== undefined) env[CODEX_APP_SERVER_PROFILE] = launchEnvelope.profile;
|
|
93
165
|
if (policy !== null) env.CODEX_CONTEXT_POLICY_JSON = JSON.stringify(policy);
|
|
94
166
|
else delete env.CODEX_CONTEXT_POLICY_JSON;
|
|
@@ -109,6 +181,9 @@ const child = spawn(
|
|
|
109
181
|
'-c',
|
|
110
182
|
'mcp_servers.aibrain_context.bearer_token_env_var="CODEX_RECOVERY_MCP_TOKEN"',
|
|
111
183
|
...(launchEnvelope === null ? [] : ownedAppServerConfigArgs(launchEnvelope)),
|
|
184
|
+
...(engineering === null ? [] : codexEngineeringConfigArgs(engineering)),
|
|
185
|
+
...codexMcpConfigArgs(catalogServers),
|
|
186
|
+
...(guardrails === null ? [] : guardrails.args),
|
|
112
187
|
],
|
|
113
188
|
{ cwd: process.cwd(), env, stdio: 'inherit' },
|
|
114
189
|
);
|
package/dist/package.json
CHANGED
package/dist/platform.mjs
CHANGED
|
@@ -3,19 +3,25 @@
|
|
|
3
3
|
import { accessSync, constants, existsSync, statSync } from 'node:fs';
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
5
|
import { delimiter, isAbsolute, join } from 'node:path';
|
|
6
|
+
import releaseManifest from './release-manifest.json' with { type: 'json' };
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Host operating system gate shared by every command: Linux (including WSL)
|
|
10
|
+
* and macOS. Codex capture adds its lock-backend check below.
|
|
11
|
+
* @param {NodeJS.Platform} [platform]
|
|
12
|
+
*/
|
|
13
|
+
export function platformCheck(platform = process.platform) {
|
|
14
|
+
if (platform === 'win32')
|
|
9
15
|
return {
|
|
10
16
|
ok: false,
|
|
11
17
|
code: 'WINDOWS_NATIVE_UNSUPPORTED',
|
|
12
18
|
message: 'Run this beta inside WSL; native Windows launch is unsupported.',
|
|
13
19
|
};
|
|
14
|
-
if (
|
|
20
|
+
if (platform !== 'linux' && platform !== 'darwin')
|
|
15
21
|
return {
|
|
16
22
|
ok: false,
|
|
17
23
|
code: 'PLATFORM_UNSUPPORTED',
|
|
18
|
-
message: 'This beta supports Linux
|
|
24
|
+
message: 'This beta supports Linux, WSL and macOS.',
|
|
19
25
|
};
|
|
20
26
|
const major = Number.parseInt(process.versions.node.split('.')[0] ?? '', 10);
|
|
21
27
|
if (!Number.isInteger(major) || major < 22)
|
|
@@ -23,10 +29,45 @@ export function platformCheck() {
|
|
|
23
29
|
return { ok: true };
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
/**
|
|
33
|
+
* System tools the macOS capture lock runs by absolute path (ADR-0049): perl
|
|
34
|
+
* takes flock(2) on the guard descriptor; sysctl and ps identify the owner.
|
|
35
|
+
*/
|
|
36
|
+
export const DARWIN_CAPTURE_TOOLS = Object.freeze(['/usr/bin/perl', '/usr/sbin/sysctl', '/bin/ps']);
|
|
37
|
+
|
|
38
|
+
/** @param {string} path */
|
|
39
|
+
function isExecutableFile(path) {
|
|
40
|
+
try {
|
|
41
|
+
if (!statSync(path).isFile()) return false;
|
|
42
|
+
accessSync(path, constants.X_OK);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Codex capture needs a kernel-owned guard lock: util-linux flock on Linux/WSL,
|
|
51
|
+
* the system perl's flock(2) on macOS (spec codex-macos).
|
|
52
|
+
* @param {NodeJS.ProcessEnv} [environment]
|
|
53
|
+
* @param {NodeJS.Platform} [platform]
|
|
54
|
+
* @param {readonly string[]} [darwinTools]
|
|
55
|
+
*/
|
|
56
|
+
export function captureLockPlatformCheck(
|
|
57
|
+
environment = process.env,
|
|
58
|
+
platform = process.platform,
|
|
59
|
+
darwinTools = DARWIN_CAPTURE_TOOLS,
|
|
60
|
+
) {
|
|
61
|
+
const host = platformCheck(platform);
|
|
62
|
+
if (!host.ok) return host;
|
|
63
|
+
if (platform === 'darwin') {
|
|
64
|
+
if (darwinTools.every(isExecutableFile)) return { ok: true };
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
code: 'CODEX_CAPTURE_LOCK_BACKEND_UNAVAILABLE',
|
|
68
|
+
message: `Codex capture on macOS requires ${darwinTools.join(', ')}.`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
30
71
|
if (resolveNative('flock', environment) === null)
|
|
31
72
|
return {
|
|
32
73
|
ok: false,
|
|
@@ -36,7 +77,12 @@ export function captureLockPlatformCheck(environment = process.env) {
|
|
|
36
77
|
return { ok: true };
|
|
37
78
|
}
|
|
38
79
|
|
|
39
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* An executable by name, from the absolute directories of PATH only. An empty or relative
|
|
82
|
+
* entry (`.`, `node_modules/.bin`) would resolve against the working directory, often the
|
|
83
|
+
* user's project, and turn a file planted there into a trusted binary (scan review F7).
|
|
84
|
+
* @param {string} name @param {NodeJS.ProcessEnv} [environment]
|
|
85
|
+
*/
|
|
40
86
|
export function resolveNative(name, environment = process.env) {
|
|
41
87
|
if (!/^[A-Za-z0-9._+-]+$/u.test(name)) return null;
|
|
42
88
|
const pathValue = environment.PATH ?? '';
|
|
@@ -44,7 +90,7 @@ export function resolveNative(name, environment = process.env) {
|
|
|
44
90
|
? [name]
|
|
45
91
|
: pathValue
|
|
46
92
|
.split(delimiter)
|
|
47
|
-
.filter((directory) => directory
|
|
93
|
+
.filter((directory) => isAbsolute(directory))
|
|
48
94
|
.map((directory) => join(directory, name));
|
|
49
95
|
for (const candidate of candidates) {
|
|
50
96
|
try {
|
|
@@ -79,30 +125,33 @@ export function nativeVersion(executable, environment = process.env) {
|
|
|
79
125
|
);
|
|
80
126
|
}
|
|
81
127
|
|
|
128
|
+
// One source for the qualified releases: the manifest bundled with this client
|
|
129
|
+
// (ADR-0056 R2; spec aisac-release-manifest FR4).
|
|
130
|
+
const TESTED_NATIVE_VERSIONS = Object.freeze({
|
|
131
|
+
claude: Object.freeze([...releaseManifest.hosts.claude.qualified]),
|
|
132
|
+
codex: Object.freeze([...releaseManifest.hosts.codex.qualified]),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
/** @param {readonly string[]} versions */
|
|
136
|
+
function versionAlternatives(versions) {
|
|
137
|
+
return versions.map((version) => version.replace(/\./gu, '\\.')).join('|');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const TESTED_CLAUDE_OUTPUT = new RegExp(
|
|
141
|
+
`^(?:(?:claude(?:\\s+code)?)\\s+)?(?:${versionAlternatives(TESTED_NATIVE_VERSIONS.claude)})(?:\\s+\\(Claude\\s+Code\\))?$`,
|
|
142
|
+
'iu',
|
|
143
|
+
);
|
|
144
|
+
const TESTED_CODEX_OUTPUT = new RegExp(
|
|
145
|
+
`^(?:codex(?:-cli)?\\s+)?(?:${versionAlternatives(TESTED_NATIVE_VERSIONS.codex)})$`,
|
|
146
|
+
'iu',
|
|
147
|
+
);
|
|
148
|
+
|
|
82
149
|
/** @param {'claude'|'codex'} client @param {string} version */
|
|
83
150
|
export function isTestedNativeVersion(client, version) {
|
|
84
151
|
const value = version.trim();
|
|
85
|
-
|
|
86
|
-
return /^(?:(?:claude(?:\s+code)?)\s+)?2\.1\.(?:294|295|296|299|300|301|302|303)(?:\s+\(Claude\s+Code\))?$/iu.test(
|
|
87
|
-
value,
|
|
88
|
-
);
|
|
89
|
-
return /^(?:codex(?:-cli)?\s+)?0\.16(?:1\.0|2\.0|2\.1|3\.0|4\.0)$/iu.test(value);
|
|
152
|
+
return (client === 'claude' ? TESTED_CLAUDE_OUTPUT : TESTED_CODEX_OUTPUT).test(value);
|
|
90
153
|
}
|
|
91
154
|
|
|
92
|
-
const TESTED_NATIVE_VERSIONS = Object.freeze({
|
|
93
|
-
claude: Object.freeze([
|
|
94
|
-
'2.1.294',
|
|
95
|
-
'2.1.295',
|
|
96
|
-
'2.1.296',
|
|
97
|
-
'2.1.299',
|
|
98
|
-
'2.1.300',
|
|
99
|
-
'2.1.301',
|
|
100
|
-
'2.1.302',
|
|
101
|
-
'2.1.303',
|
|
102
|
-
]),
|
|
103
|
-
codex: Object.freeze(['0.161.0', '0.162.0', '0.162.1', '0.163.0', '0.164.0']),
|
|
104
|
-
});
|
|
105
|
-
|
|
106
155
|
/** @param {'claude'|'codex'} client @param {string} version */
|
|
107
156
|
export function nativeVersionDiagnostic(client, version) {
|
|
108
157
|
const detected = version.trim();
|