@aisac/cli 0.4.0-beta.1 → 0.4.0-beta.11
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 +50 -6
- package/dist/assets/claude/hooks/context-compaction.ts +5 -1
- package/dist/assets/codex-context-compaction.mjs +243 -5
- package/dist/assets/jev-paid-pilot-terminal.mjs +6 -0
- package/dist/claude-observation.mjs +1 -1
- package/dist/cli.mjs +91 -5
- package/dist/codex-compatibility.mjs +52 -2
- package/dist/codex-engineering.mjs +165 -0
- package/dist/codex-protocol-fingerprint.json +10 -10
- package/dist/engineering-pack-public-key.json +10 -0
- package/dist/engineering-pack.mjs +845 -0
- package/dist/engineering.mjs +15 -11
- package/dist/extensions-catalog.mjs +310 -0
- package/dist/extensions-cli.mjs +486 -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 +397 -0
- package/dist/guardrails/run.mjs +211 -0
- package/dist/guardrails/shell-words.mjs +206 -0
- package/dist/guardrails-plugin.mjs +149 -0
- package/dist/launch.mjs +143 -8
- package/dist/mcp-servers.mjs +192 -0
- package/dist/monitor.mjs +33 -0
- package/dist/package.json +1 -1
- package/dist/platform.mjs +50 -10
- package/dist/token-guide.mjs +105 -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/monitor.mjs
CHANGED
|
@@ -12,6 +12,13 @@ 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';
|
|
15
22
|
|
|
16
23
|
const root = dirname(fileURLToPath(import.meta.url));
|
|
17
24
|
const endpoint = process.env.AIBRAIN_MCP_URL?.trim();
|
|
@@ -32,6 +39,26 @@ if (parsed.search) throw new Error('aibrain_monitor_endpoint_query');
|
|
|
32
39
|
const canonical = join(root, 'assets', 'codex-context-compaction.mjs');
|
|
33
40
|
await access(canonical, constants.R_OK);
|
|
34
41
|
const launchEnvelope = parseCodexLaunchEnvelope(process.env[CODEX_LAUNCH_ENVELOPE]);
|
|
42
|
+
// AISAC Engineering (E4c): a malformed value starts the session without the pack.
|
|
43
|
+
let engineering = null;
|
|
44
|
+
try {
|
|
45
|
+
const stateDir = process.env.AIBRAIN_STATE_DIR;
|
|
46
|
+
engineering = parseCodexEngineering(
|
|
47
|
+
process.env[CODEX_ENGINEERING_ENV],
|
|
48
|
+
stateDir === undefined ? {} : { stateDir },
|
|
49
|
+
);
|
|
50
|
+
} catch {
|
|
51
|
+
engineering = null;
|
|
52
|
+
}
|
|
53
|
+
// MCP catalog servers (E6c) follow the pack: no license, no servers. A malformed
|
|
54
|
+
// value starts the session without them.
|
|
55
|
+
/** @type {import('./mcp-servers.mjs').McpEntry[]} */
|
|
56
|
+
let catalogServers = [];
|
|
57
|
+
try {
|
|
58
|
+
catalogServers = engineering === null ? [] : parseCodexMcp(process.env[CODEX_MCP_ENV]);
|
|
59
|
+
} catch {
|
|
60
|
+
catalogServers = [];
|
|
61
|
+
}
|
|
35
62
|
const policyText = process.env.CODEX_CONTEXT_POLICY_JSON;
|
|
36
63
|
let policy;
|
|
37
64
|
if (policyText === undefined) {
|
|
@@ -89,6 +116,10 @@ const env = {
|
|
|
89
116
|
};
|
|
90
117
|
delete env[CODEX_LAUNCH_ENVELOPE];
|
|
91
118
|
delete env[CODEX_APP_SERVER_PROFILE];
|
|
119
|
+
delete env[CODEX_ENGINEERING_ENV];
|
|
120
|
+
delete env[CODEX_ENGINEERING_SKILLS_ROOT_ENV];
|
|
121
|
+
delete env[CODEX_MCP_ENV];
|
|
122
|
+
if (engineering !== null) env[CODEX_ENGINEERING_SKILLS_ROOT_ENV] = engineering.skillsRoot;
|
|
92
123
|
if (launchEnvelope?.profile !== undefined) env[CODEX_APP_SERVER_PROFILE] = launchEnvelope.profile;
|
|
93
124
|
if (policy !== null) env.CODEX_CONTEXT_POLICY_JSON = JSON.stringify(policy);
|
|
94
125
|
else delete env.CODEX_CONTEXT_POLICY_JSON;
|
|
@@ -109,6 +140,8 @@ const child = spawn(
|
|
|
109
140
|
'-c',
|
|
110
141
|
'mcp_servers.aibrain_context.bearer_token_env_var="CODEX_RECOVERY_MCP_TOKEN"',
|
|
111
142
|
...(launchEnvelope === null ? [] : ownedAppServerConfigArgs(launchEnvelope)),
|
|
143
|
+
...(engineering === null ? [] : codexEngineeringConfigArgs(engineering)),
|
|
144
|
+
...codexMcpConfigArgs(catalogServers),
|
|
112
145
|
],
|
|
113
146
|
{ cwd: process.cwd(), env, stdio: 'inherit' },
|
|
114
147
|
);
|
package/dist/package.json
CHANGED
package/dist/platform.mjs
CHANGED
|
@@ -4,18 +4,23 @@ 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
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Host operating system gate shared by every command: Linux (including WSL)
|
|
9
|
+
* and macOS. Codex capture adds its lock-backend check below.
|
|
10
|
+
* @param {NodeJS.Platform} [platform]
|
|
11
|
+
*/
|
|
12
|
+
export function platformCheck(platform = process.platform) {
|
|
13
|
+
if (platform === 'win32')
|
|
9
14
|
return {
|
|
10
15
|
ok: false,
|
|
11
16
|
code: 'WINDOWS_NATIVE_UNSUPPORTED',
|
|
12
17
|
message: 'Run this beta inside WSL; native Windows launch is unsupported.',
|
|
13
18
|
};
|
|
14
|
-
if (
|
|
19
|
+
if (platform !== 'linux' && platform !== 'darwin')
|
|
15
20
|
return {
|
|
16
21
|
ok: false,
|
|
17
22
|
code: 'PLATFORM_UNSUPPORTED',
|
|
18
|
-
message: 'This beta supports Linux
|
|
23
|
+
message: 'This beta supports Linux, WSL and macOS.',
|
|
19
24
|
};
|
|
20
25
|
const major = Number.parseInt(process.versions.node.split('.')[0] ?? '', 10);
|
|
21
26
|
if (!Number.isInteger(major) || major < 22)
|
|
@@ -23,10 +28,45 @@ export function platformCheck() {
|
|
|
23
28
|
return { ok: true };
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* System tools the macOS capture lock runs by absolute path (ADR-0049): perl
|
|
33
|
+
* takes flock(2) on the guard descriptor; sysctl and ps identify the owner.
|
|
34
|
+
*/
|
|
35
|
+
export const DARWIN_CAPTURE_TOOLS = Object.freeze(['/usr/bin/perl', '/usr/sbin/sysctl', '/bin/ps']);
|
|
36
|
+
|
|
37
|
+
/** @param {string} path */
|
|
38
|
+
function isExecutableFile(path) {
|
|
39
|
+
try {
|
|
40
|
+
if (!statSync(path).isFile()) return false;
|
|
41
|
+
accessSync(path, constants.X_OK);
|
|
42
|
+
return true;
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Codex capture needs a kernel-owned guard lock: util-linux flock on Linux/WSL,
|
|
50
|
+
* the system perl's flock(2) on macOS (spec codex-macos).
|
|
51
|
+
* @param {NodeJS.ProcessEnv} [environment]
|
|
52
|
+
* @param {NodeJS.Platform} [platform]
|
|
53
|
+
* @param {readonly string[]} [darwinTools]
|
|
54
|
+
*/
|
|
55
|
+
export function captureLockPlatformCheck(
|
|
56
|
+
environment = process.env,
|
|
57
|
+
platform = process.platform,
|
|
58
|
+
darwinTools = DARWIN_CAPTURE_TOOLS,
|
|
59
|
+
) {
|
|
60
|
+
const host = platformCheck(platform);
|
|
61
|
+
if (!host.ok) return host;
|
|
62
|
+
if (platform === 'darwin') {
|
|
63
|
+
if (darwinTools.every(isExecutableFile)) return { ok: true };
|
|
64
|
+
return {
|
|
65
|
+
ok: false,
|
|
66
|
+
code: 'CODEX_CAPTURE_LOCK_BACKEND_UNAVAILABLE',
|
|
67
|
+
message: `Codex capture on macOS requires ${darwinTools.join(', ')}.`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
30
70
|
if (resolveNative('flock', environment) === null)
|
|
31
71
|
return {
|
|
32
72
|
ok: false,
|
|
@@ -86,7 +126,7 @@ export function isTestedNativeVersion(client, version) {
|
|
|
86
126
|
return /^(?:(?:claude(?:\s+code)?)\s+)?2\.1\.(?:294|295|296|299|300|301|302|303)(?:\s+\(Claude\s+Code\))?$/iu.test(
|
|
87
127
|
value,
|
|
88
128
|
);
|
|
89
|
-
return /^(?:codex(?:-cli)?\s+)?0\.16(?:1\.0|2\.0|2\.1|3\.0|4\.0)$/iu.test(value);
|
|
129
|
+
return /^(?:codex(?:-cli)?\s+)?0\.16(?:1\.0|2\.0|2\.1|3\.0|4\.0|6\.0)$/iu.test(value);
|
|
90
130
|
}
|
|
91
131
|
|
|
92
132
|
const TESTED_NATIVE_VERSIONS = Object.freeze({
|
|
@@ -100,7 +140,7 @@ const TESTED_NATIVE_VERSIONS = Object.freeze({
|
|
|
100
140
|
'2.1.302',
|
|
101
141
|
'2.1.303',
|
|
102
142
|
]),
|
|
103
|
-
codex: Object.freeze(['0.161.0', '0.162.0', '0.162.1', '0.163.0', '0.164.0']),
|
|
143
|
+
codex: Object.freeze(['0.161.0', '0.162.0', '0.162.1', '0.163.0', '0.164.0', '0.166.0']),
|
|
104
144
|
});
|
|
105
145
|
|
|
106
146
|
/** @param {'claude'|'codex'} client @param {string} version */
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Step-by-step guidance for obtaining an AI Brain PAT during `aisac setup`.
|
|
2
|
+
// Spec aibrain-subscriber-beta § Setup step 3: guide users to the existing
|
|
3
|
+
// dashboard token flow instead of failing with a bare error code. The text
|
|
4
|
+
// never contains the token or any account data; the URL is the endpoint origin.
|
|
5
|
+
|
|
6
|
+
const DEFAULT_DASHBOARD = 'https://mcp.ai-brain.aisac.cloud';
|
|
7
|
+
|
|
8
|
+
/** @typedef {'pt-BR' | 'en'} GuideLocale */
|
|
9
|
+
|
|
10
|
+
/** Setup failures that mean "you need a (different) token", mapped to a reason key. */
|
|
11
|
+
const TOKEN_FAILURES = Object.freeze({
|
|
12
|
+
empty_token: 'empty',
|
|
13
|
+
token_file_required_in_noninteractive_mode: 'noninteractive',
|
|
14
|
+
'provider_free_probe_failed:mcp_auth_denied': 'denied',
|
|
15
|
+
'provider_free_probe_failed:mcp_paid_plan_required': 'unlicensed',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const TEXT = Object.freeze({
|
|
19
|
+
'pt-BR': {
|
|
20
|
+
intro: 'O aisac precisa de um token pessoal (PAT) do seu AI Brain.',
|
|
21
|
+
missing: 'Não tem um? Gere em um minuto:',
|
|
22
|
+
login: (/** @type {string} */ url) =>
|
|
23
|
+
` 1. Abra ${url} e entre com o MESMO e-mail usado na compra\n (chega um código de 6 dígitos). A licença fica vinculada a esse e-mail.`,
|
|
24
|
+
label:
|
|
25
|
+
' 2. No painel, dê um rótulo (ex.: meu-mac) e escolha o agente\n (Anthropic para Claude Code, OpenAI para Codex). Isso só organiza a atribuição.',
|
|
26
|
+
generate: ' 3. Clique em "Gerar token" e copie na hora: ele aparece uma única vez.',
|
|
27
|
+
pasteHere: ' 4. Cole abaixo em "AI Brain PAT". A digitação fica oculta.',
|
|
28
|
+
rerun: ' 4. Rode `aisac setup` de novo e cole o token em "AI Brain PAT" (fica oculto).',
|
|
29
|
+
safety:
|
|
30
|
+
'Nunca coloque o token em argumento de comando, arquivo do repositório ou perfil do shell.',
|
|
31
|
+
support: 'Se o e-mail da compra não entrar ou não tiver a licença, fale com o suporte AISAC.',
|
|
32
|
+
reasons: {
|
|
33
|
+
empty: 'Nenhum token foi informado.',
|
|
34
|
+
noninteractive:
|
|
35
|
+
'Sem um terminal interativo, o token precisa vir de `--token-file` (um arquivo privado, modo 600).',
|
|
36
|
+
denied:
|
|
37
|
+
'O AI Brain recusou este token: ele está incompleto, foi revogado ou não existe. Gere um novo.',
|
|
38
|
+
unlicensed:
|
|
39
|
+
'Este token pertence a uma conta sem a licença. Gere o token entrando com o e-mail usado na compra.',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
en: {
|
|
43
|
+
intro: 'aisac needs a personal access token (PAT) from your AI Brain.',
|
|
44
|
+
missing: "Don't have one? Create it in a minute:",
|
|
45
|
+
login: (/** @type {string} */ url) =>
|
|
46
|
+
` 1. Open ${url} and sign in with the SAME email you used to buy\n (a 6-digit code arrives by email). The license is tied to that email.`,
|
|
47
|
+
label:
|
|
48
|
+
' 2. In the dashboard, enter a label (e.g. my-mac) and pick the agent\n (Anthropic for Claude Code, OpenAI for Codex). It only organizes attribution.',
|
|
49
|
+
generate: ' 3. Click "Gerar token" and copy it right away: it is shown only once.',
|
|
50
|
+
pasteHere: ' 4. Paste it below at "AI Brain PAT". Typing stays hidden.',
|
|
51
|
+
rerun: ' 4. Run `aisac setup` again and paste the token at "AI Brain PAT" (hidden).',
|
|
52
|
+
safety: 'Never put the token in command arguments, a repository file or a shell profile.',
|
|
53
|
+
support: 'If the purchase email cannot sign in or has no license, contact AISAC support.',
|
|
54
|
+
reasons: {
|
|
55
|
+
empty: 'No token was entered.',
|
|
56
|
+
noninteractive:
|
|
57
|
+
'Without an interactive terminal the token must come from `--token-file` (a private file, mode 600).',
|
|
58
|
+
denied:
|
|
59
|
+
'AI Brain rejected this token: it is incomplete, revoked or unknown. Create a new one.',
|
|
60
|
+
unlicensed:
|
|
61
|
+
'This token belongs to an account without the license. Create the token signed in with the purchase email.',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/** The dashboard origin derived from an https endpoint, else the production dashboard. @param {string} endpoint */
|
|
67
|
+
export function dashboardUrl(endpoint) {
|
|
68
|
+
try {
|
|
69
|
+
const url = new URL(endpoint);
|
|
70
|
+
return url.protocol === 'https:' ? url.origin : DEFAULT_DASHBOARD;
|
|
71
|
+
} catch {
|
|
72
|
+
return DEFAULT_DASHBOARD;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @param {GuideLocale} locale @param {string} endpoint @param {'prompt' | 'rerun'} step */
|
|
77
|
+
function steps(locale, endpoint, step) {
|
|
78
|
+
const text = TEXT[locale];
|
|
79
|
+
return [
|
|
80
|
+
text.intro,
|
|
81
|
+
text.missing,
|
|
82
|
+
text.login(dashboardUrl(endpoint)),
|
|
83
|
+
text.label,
|
|
84
|
+
text.generate,
|
|
85
|
+
step === 'prompt' ? text.pasteHere : text.rerun,
|
|
86
|
+
text.safety,
|
|
87
|
+
].join('\n');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Guidance printed right before the masked PAT prompt. @param {GuideLocale} locale @param {string} endpoint */
|
|
91
|
+
export function tokenPromptGuide(locale, endpoint) {
|
|
92
|
+
return steps(locale, endpoint, 'prompt');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Guidance for a setup failure caused by a missing, rejected or unlicensed token,
|
|
97
|
+
* or null when the failure has another cause.
|
|
98
|
+
* @param {string} code @param {GuideLocale} locale @param {string} endpoint
|
|
99
|
+
*/
|
|
100
|
+
export function tokenFailureGuide(code, locale, endpoint) {
|
|
101
|
+
const reason = /** @type {Record<string, keyof typeof TEXT.en.reasons>} */ (TOKEN_FAILURES)[code];
|
|
102
|
+
if (reason === undefined) return null;
|
|
103
|
+
const text = TEXT[locale];
|
|
104
|
+
return [text.reasons[reason], '', steps(locale, endpoint, 'rerun'), text.support].join('\n');
|
|
105
|
+
}
|
package/package.json
CHANGED