@aisac/cli 0.0.0-stage → 0.4.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +202 -2
  2. package/dist/assets/claude/.claude-plugin/plugin.json +147 -0
  3. package/dist/assets/claude/hooks/context-compaction.ts +6934 -0
  4. package/dist/assets/claude/hooks/hooks.json +3 -0
  5. package/dist/assets/claude/hooks/native-host-contract-runtime.ts +18 -0
  6. package/dist/assets/claude/hooks/native-host-contract.test.ts +51 -0
  7. package/dist/assets/claude/hooks/provider-window.js +263 -0
  8. package/dist/assets/claude/hooks/state-fitting.d.mts +47 -0
  9. package/dist/assets/claude/hooks/state-fitting.mjs +324 -0
  10. package/dist/assets/codex-context-compaction.mjs +4786 -0
  11. package/dist/assets/context-selection-fitting.mjs +194 -0
  12. package/dist/assets/context-state-fitting.mjs +324 -0
  13. package/dist/assets/context-telemetry-reporter.mjs +305 -0
  14. package/dist/assets/jev-paid-pilot-terminal.mjs +1066 -0
  15. package/dist/claude-checkpoint.mjs +1338 -0
  16. package/dist/claude-compatibility.mjs +506 -0
  17. package/dist/claude-observation.mjs +1338 -0
  18. package/dist/cli.mjs +805 -0
  19. package/dist/codex-compatibility.mjs +531 -0
  20. package/dist/codex-diagnostics.mjs +447 -0
  21. package/dist/codex-engineering.mjs +165 -0
  22. package/dist/codex-permissions.mjs +590 -0
  23. package/dist/codex-protocol-fingerprint.json +131 -0
  24. package/dist/context-telemetry.mjs +257 -0
  25. package/dist/engineering-pack-public-key.json +10 -0
  26. package/dist/engineering-pack.mjs +845 -0
  27. package/dist/engineering.mjs +194 -0
  28. package/dist/extensions-catalog.mjs +310 -0
  29. package/dist/extensions-cli.mjs +486 -0
  30. package/dist/extensions-preferences.mjs +151 -0
  31. package/dist/guardrails/continuity.mjs +239 -0
  32. package/dist/guardrails/format.mjs +111 -0
  33. package/dist/guardrails/guards.mjs +397 -0
  34. package/dist/guardrails/run.mjs +211 -0
  35. package/dist/guardrails/shell-words.mjs +206 -0
  36. package/dist/guardrails-plugin.mjs +149 -0
  37. package/dist/launch.mjs +786 -0
  38. package/dist/mcp-servers.mjs +192 -0
  39. package/dist/mcp.mjs +962 -0
  40. package/dist/monitor.mjs +166 -0
  41. package/dist/package.json +5 -0
  42. package/dist/platform.mjs +156 -0
  43. package/dist/policy.mjs +218 -0
  44. package/dist/state.mjs +408 -0
  45. package/dist/telemetry-report.mjs +133 -0
  46. package/package.json +24 -4
@@ -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
+ }