@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,207 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* The session plugin `aisac-guardrails` (spec aisac-engineering-extensions
|
|
4
|
+
* FR5): written into the launch's private folder with only the enabled
|
|
5
|
+
* hooks, and deleted with that folder on exit. Every command is the absolute
|
|
6
|
+
* Node executable plus the dispatcher inside the installed package; nothing
|
|
7
|
+
* comes from the server (ADR-0048).
|
|
8
|
+
*/
|
|
9
|
+
import { access, mkdir, realpath, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { isAbsolute, join } from 'node:path';
|
|
11
|
+
import { hookById } from './extensions-catalog.mjs';
|
|
12
|
+
import { enabledHookIds, preferencesPath, readPreferences } from './extensions-preferences.mjs';
|
|
13
|
+
import { readStoredLocale, resolvePackLocale } from './engineering-pack.mjs';
|
|
14
|
+
import {
|
|
15
|
+
codexHookConfigArgs,
|
|
16
|
+
codexHooksLine,
|
|
17
|
+
codexHooksValue,
|
|
18
|
+
summarizeCodexHooks,
|
|
19
|
+
} from './codex-hooks.mjs';
|
|
20
|
+
import { readCodexHookList } from './codex-permissions.mjs';
|
|
21
|
+
|
|
22
|
+
export const GUARDRAILS_PLUGIN_NAME = 'aisac-guardrails';
|
|
23
|
+
const PLUGIN_VERSION = '1.0.0';
|
|
24
|
+
const PLUGIN_DIRECTORY = 'guardrails';
|
|
25
|
+
const STATE_DIRECTORY = 'guardrails-state';
|
|
26
|
+
const DISPATCHER = join('guardrails', 'run.mjs');
|
|
27
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/u;
|
|
28
|
+
/** @type {Readonly<Record<string, number>>} */
|
|
29
|
+
const TIMEOUT_SECONDS = Object.freeze({
|
|
30
|
+
PreToolUse: 5,
|
|
31
|
+
PostToolUse: 5,
|
|
32
|
+
UserPromptSubmit: 5,
|
|
33
|
+
Stop: 5,
|
|
34
|
+
SessionStart: 10,
|
|
35
|
+
PreCompact: 10,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/** POSIX single-quote quoting for the host's shell. @param {string} value */
|
|
39
|
+
export function shellQuote(value) {
|
|
40
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @param {string} path */
|
|
44
|
+
function safeAbsolute(path) {
|
|
45
|
+
return isAbsolute(path) && !CONTROL_CHARACTERS.test(path);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The plugin's hooks.json for the enabled ids: one entry per event, whose
|
|
50
|
+
* matcher is the union of the enabled hooks' matchers for that event.
|
|
51
|
+
* @param {string[]} enabled
|
|
52
|
+
* @param {{ node: string, dispatcher: string, stateDir: string, prefsPath: string, locale: 'pt-BR' | 'en' }} paths
|
|
53
|
+
*/
|
|
54
|
+
export function guardrailsHooks(enabled, paths) {
|
|
55
|
+
/** @type {Map<string, { ids: string[], matchers: Set<string>, unmatched: boolean }>} */
|
|
56
|
+
const events = new Map();
|
|
57
|
+
for (const id of enabled) {
|
|
58
|
+
for (const binding of hookById(id)?.bindings ?? []) {
|
|
59
|
+
const current = events.get(binding.event) ?? {
|
|
60
|
+
ids: [],
|
|
61
|
+
matchers: new Set(),
|
|
62
|
+
unmatched: false,
|
|
63
|
+
};
|
|
64
|
+
if (!current.ids.includes(id)) current.ids.push(id);
|
|
65
|
+
if (binding.matcher === undefined) current.unmatched = true;
|
|
66
|
+
else for (const name of binding.matcher.split('|')) current.matchers.add(name);
|
|
67
|
+
events.set(binding.event, current);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** @type {Record<string, unknown[]>} */
|
|
71
|
+
const hooks = {};
|
|
72
|
+
for (const [event, group] of events) {
|
|
73
|
+
const command = [
|
|
74
|
+
shellQuote(paths.node),
|
|
75
|
+
shellQuote(paths.dispatcher),
|
|
76
|
+
'--event',
|
|
77
|
+
event,
|
|
78
|
+
'--hooks',
|
|
79
|
+
group.ids.join(','),
|
|
80
|
+
'--state',
|
|
81
|
+
shellQuote(paths.stateDir),
|
|
82
|
+
'--prefs',
|
|
83
|
+
shellQuote(paths.prefsPath),
|
|
84
|
+
'--locale',
|
|
85
|
+
paths.locale,
|
|
86
|
+
].join(' ');
|
|
87
|
+
hooks[event] = [
|
|
88
|
+
{
|
|
89
|
+
...(group.unmatched || group.matchers.size === 0
|
|
90
|
+
? {}
|
|
91
|
+
: { matcher: [...group.matchers].join('|') }),
|
|
92
|
+
hooks: [{ type: 'command', command, timeout: TIMEOUT_SECONDS[event] ?? 5 }],
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
description: 'AISAC Engineering guardrails for this session (aisac hooks to change them).',
|
|
98
|
+
hooks,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Write the plugin for a licensed launch. Null when no hook is enabled or the
|
|
104
|
+
* package lacks the dispatcher; the launch then goes on without it.
|
|
105
|
+
* @param {{ directory: string, root: string, packageRoot: string }} input
|
|
106
|
+
* @returns {Promise<{ pluginRoot: string, count: number, line: string } | null>}
|
|
107
|
+
*/
|
|
108
|
+
export async function prepareGuardrails(input) {
|
|
109
|
+
const enabled = enabledHookIds(await readPreferences(input.root));
|
|
110
|
+
if (enabled.length === 0) return null;
|
|
111
|
+
const dispatcher = join(input.packageRoot, DISPATCHER);
|
|
112
|
+
const prefsPath = preferencesPath(input.root);
|
|
113
|
+
const pluginRoot = join(input.directory, PLUGIN_DIRECTORY);
|
|
114
|
+
const stateDir = join(input.directory, STATE_DIRECTORY);
|
|
115
|
+
if (![process.execPath, dispatcher, prefsPath, pluginRoot, stateDir].every(safeAbsolute))
|
|
116
|
+
return null;
|
|
117
|
+
if (
|
|
118
|
+
!(await access(dispatcher).then(
|
|
119
|
+
() => true,
|
|
120
|
+
() => false,
|
|
121
|
+
))
|
|
122
|
+
)
|
|
123
|
+
return null;
|
|
124
|
+
const locale = resolvePackLocale(await readStoredLocale(input.root));
|
|
125
|
+
await mkdir(join(pluginRoot, '.claude-plugin'), { recursive: true, mode: 0o700 });
|
|
126
|
+
await mkdir(join(pluginRoot, 'hooks'), { mode: 0o700 });
|
|
127
|
+
await mkdir(stateDir, { mode: 0o700 });
|
|
128
|
+
const manifest = {
|
|
129
|
+
name: GUARDRAILS_PLUGIN_NAME,
|
|
130
|
+
version: PLUGIN_VERSION,
|
|
131
|
+
description: 'AISAC Engineering guardrail hooks, loaded for this session only.',
|
|
132
|
+
author: { name: 'AISAC' },
|
|
133
|
+
hooks: './hooks/hooks.json',
|
|
134
|
+
};
|
|
135
|
+
const hooks = guardrailsHooks(enabled, {
|
|
136
|
+
node: process.execPath,
|
|
137
|
+
dispatcher,
|
|
138
|
+
stateDir,
|
|
139
|
+
prefsPath,
|
|
140
|
+
locale,
|
|
141
|
+
});
|
|
142
|
+
await writeFile(
|
|
143
|
+
join(pluginRoot, '.claude-plugin', 'plugin.json'),
|
|
144
|
+
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
145
|
+
{ mode: 0o600, flag: 'wx' },
|
|
146
|
+
);
|
|
147
|
+
await writeFile(join(pluginRoot, 'hooks', 'hooks.json'), `${JSON.stringify(hooks, null, 2)}\n`, {
|
|
148
|
+
mode: 0o600,
|
|
149
|
+
flag: 'wx',
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
pluginRoot,
|
|
153
|
+
count: enabled.length,
|
|
154
|
+
line: `AISAC Engineering: ${enabled.length} guardrail${enabled.length === 1 ? '' : 's'} on (aisac hooks to change them).`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* What Codex reports for the AISAC hooks the user has on, read with Codex's own
|
|
160
|
+
* `hooks/list` for the exact flags the monitor passes (spec FR6, E6b). Null when
|
|
161
|
+
* no Codex hook is enabled or the package lacks the dispatcher; `summary` is null
|
|
162
|
+
* when the listing failed.
|
|
163
|
+
* @param {{ root: string, packageRoot: string, executable: string, cwd: string, profile: string | undefined, environment: NodeJS.ProcessEnv }} input
|
|
164
|
+
* @param {{ listHooks?: typeof readCodexHookList }} [dependencies]
|
|
165
|
+
* @returns {Promise<{ enabled: string[], summary: import('./codex-hooks.mjs').CodexHooksSummary | null } | null>}
|
|
166
|
+
*/
|
|
167
|
+
export async function readCodexGuardrails(input, dependencies = {}) {
|
|
168
|
+
const listHooks = dependencies.listHooks ?? readCodexHookList;
|
|
169
|
+
const enabled = enabledHookIds(await readPreferences(input.root)).filter(
|
|
170
|
+
(id) => hookById(id)?.clients.includes('codex') === true,
|
|
171
|
+
);
|
|
172
|
+
if (enabled.length === 0) return null;
|
|
173
|
+
// The monitor resolves the same file from its own folder; both use the real path.
|
|
174
|
+
const dispatcher = await realpath(join(input.packageRoot, DISPATCHER)).catch(() => null);
|
|
175
|
+
if (dispatcher === null || !safeAbsolute(dispatcher) || !safeAbsolute(process.execPath))
|
|
176
|
+
return null;
|
|
177
|
+
const paths = { node: process.execPath, dispatcher };
|
|
178
|
+
const summary = await listHooks({
|
|
179
|
+
executable: input.executable,
|
|
180
|
+
cwd: input.cwd,
|
|
181
|
+
profile: input.profile,
|
|
182
|
+
environment: input.environment,
|
|
183
|
+
configArgs: codexHookConfigArgs(paths),
|
|
184
|
+
}).then(
|
|
185
|
+
(listed) => summarizeCodexHooks(listed, paths, enabled),
|
|
186
|
+
() => null,
|
|
187
|
+
);
|
|
188
|
+
return { enabled, summary };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The guardrails for a licensed Codex launch: the value the launcher hands the
|
|
193
|
+
* monitor, and the launch line. The line comes from `hooks/list`, so a guardrail
|
|
194
|
+
* that waits for the user's review in `/hooks` is never called on.
|
|
195
|
+
* @param {{ root: string, packageRoot: string, executable: string, cwd: string, profile: string | undefined, environment: NodeJS.ProcessEnv }} input
|
|
196
|
+
* @param {{ listHooks?: typeof readCodexHookList }} [dependencies]
|
|
197
|
+
* @returns {Promise<{ value: string, line: string } | null>}
|
|
198
|
+
*/
|
|
199
|
+
export async function prepareCodexGuardrails(input, dependencies = {}) {
|
|
200
|
+
const read = await readCodexGuardrails(input, dependencies);
|
|
201
|
+
if (read === null) return null;
|
|
202
|
+
const locale = resolvePackLocale(await readStoredLocale(input.root));
|
|
203
|
+
return {
|
|
204
|
+
value: codexHooksValue(read.enabled, locale),
|
|
205
|
+
line: codexHooksLine(read.enabled.length, read.summary),
|
|
206
|
+
};
|
|
207
|
+
}
|