@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,210 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* Release settings and consent (spec aisac-release-manifest FR7, D8; ADR-0056 R3):
|
|
4
|
+
* `<state>/release.json`, mode 0600, closed key set, written atomically. The
|
|
5
|
+
* file holds the one consent recorded by `aisac setup` (or by the first
|
|
6
|
+
* interactive launch of an existing setup), the self-update mode and channel,
|
|
7
|
+
* and the host modes R4/R5 read. An invalid file means defaults and never fails
|
|
8
|
+
* a launch; `config.json` is never touched, so older clients and the in-session
|
|
9
|
+
* hook helpers keep accepting it.
|
|
10
|
+
*/
|
|
11
|
+
import { constants } from 'node:fs';
|
|
12
|
+
import { lstat, open, readFile, stat } from 'node:fs/promises';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { atomicJson, ensureStateRoot } from './state.mjs';
|
|
15
|
+
import { CHANNELS, CLIENT_PACKAGES } from './release-manifest.mjs';
|
|
16
|
+
|
|
17
|
+
export const RELEASE_SETTINGS_FILE = 'release.json';
|
|
18
|
+
/** The disclosure the consent answers; a new paragraph means a new version. */
|
|
19
|
+
export const CONSENT_VERSION = 'release-manifest-v1';
|
|
20
|
+
export const UPDATE_MODES = Object.freeze(['auto', 'notify', 'off']);
|
|
21
|
+
export const HOST_MODES = Object.freeze(['system', 'managed']);
|
|
22
|
+
/** R3 default; `auto` becomes the default one beta later (spec §7 Q3, D12). */
|
|
23
|
+
export const DEFAULT_UPDATE_MODE = 'notify';
|
|
24
|
+
/** Until the owner moves the `latest` dist-tag (FR6). */
|
|
25
|
+
export const DEFAULT_CHANNEL = 'beta';
|
|
26
|
+
export const DEFAULT_HOST_MODE = 'system';
|
|
27
|
+
/** One-launch overrides (FR7, D9). */
|
|
28
|
+
export const NO_SELF_UPDATE_ENV = 'AISAC_NO_SELF_UPDATE';
|
|
29
|
+
export const HOST_MODE_ENV = 'AISAC_HOST_MODE';
|
|
30
|
+
const SCHEMA_VERSION = 1;
|
|
31
|
+
const MAX_SETTINGS_BYTES = 4 * 1024;
|
|
32
|
+
const MAX_PACKAGE_JSON_BYTES = 64 * 1024;
|
|
33
|
+
const TOP_LEVEL_KEYS = ['consent', 'hosts', 'schemaVersion', 'update'];
|
|
34
|
+
const CONSENT_KEYS = ['at', 'version'];
|
|
35
|
+
const UPDATE_KEYS = ['channel', 'mode'];
|
|
36
|
+
const HOST_KEYS = ['claude', 'codex'];
|
|
37
|
+
const ISO_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/u;
|
|
38
|
+
const CONSENT_VERSION_FORMAT = /^[a-z0-9-]{1,64}$/u;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {'auto' | 'notify' | 'off'} UpdateMode
|
|
42
|
+
* @typedef {'beta' | 'latest'} Channel
|
|
43
|
+
* @typedef {'system' | 'managed'} HostMode
|
|
44
|
+
* @typedef {{ version: string, at: string }} Consent
|
|
45
|
+
* @typedef {{ consent: Consent | null, update: { mode: UpdateMode, channel: Channel },
|
|
46
|
+
* hosts: { claude: HostMode, codex: HostMode } }} StoredSettings
|
|
47
|
+
* @typedef {StoredSettings & { status: 'missing' | 'valid' | 'invalid' }} ReleaseSettings
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
51
|
+
function isRecord(value) {
|
|
52
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @param {Record<string, unknown>} value @param {string[]} keys */
|
|
56
|
+
function hasExactKeys(value, keys) {
|
|
57
|
+
const present = Object.keys(value).sort();
|
|
58
|
+
return present.length === keys.length && present.every((key, index) => key === keys[index]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {unknown} value @returns {value is UpdateMode} */
|
|
62
|
+
export function isUpdateMode(value) {
|
|
63
|
+
return typeof value === 'string' && UPDATE_MODES.includes(value);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @param {unknown} value @returns {value is Channel} */
|
|
67
|
+
export function isChannel(value) {
|
|
68
|
+
return typeof value === 'string' && CHANNELS.includes(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @param {unknown} value @returns {value is HostMode} */
|
|
72
|
+
export function isHostMode(value) {
|
|
73
|
+
return typeof value === 'string' && HOST_MODES.includes(value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @returns {StoredSettings} */
|
|
77
|
+
export function defaultReleaseSettings() {
|
|
78
|
+
return {
|
|
79
|
+
consent: null,
|
|
80
|
+
update: { mode: DEFAULT_UPDATE_MODE, channel: DEFAULT_CHANNEL },
|
|
81
|
+
hosts: { claude: DEFAULT_HOST_MODE, codex: DEFAULT_HOST_MODE },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Validate a parsed settings document: closed keys at every level, closed
|
|
87
|
+
* enumerations, ISO instants. @param {unknown} value
|
|
88
|
+
* @returns {StoredSettings | null}
|
|
89
|
+
*/
|
|
90
|
+
export function parseReleaseSettings(value) {
|
|
91
|
+
if (!isRecord(value) || !hasExactKeys(value, TOP_LEVEL_KEYS)) return null;
|
|
92
|
+
if (value.schemaVersion !== SCHEMA_VERSION) return null;
|
|
93
|
+
/** @type {Consent | null} */
|
|
94
|
+
let consent = null;
|
|
95
|
+
if (value.consent !== null) {
|
|
96
|
+
if (!isRecord(value.consent) || !hasExactKeys(value.consent, CONSENT_KEYS)) return null;
|
|
97
|
+
const { version, at } = value.consent;
|
|
98
|
+
if (typeof version !== 'string' || !CONSENT_VERSION_FORMAT.test(version)) return null;
|
|
99
|
+
if (typeof at !== 'string' || !ISO_INSTANT.test(at)) return null;
|
|
100
|
+
consent = { version, at };
|
|
101
|
+
}
|
|
102
|
+
if (!isRecord(value.update) || !hasExactKeys(value.update, UPDATE_KEYS)) return null;
|
|
103
|
+
const { mode, channel } = value.update;
|
|
104
|
+
if (!isUpdateMode(mode) || !isChannel(channel)) return null;
|
|
105
|
+
if (!isRecord(value.hosts) || !hasExactKeys(value.hosts, HOST_KEYS)) return null;
|
|
106
|
+
const { claude, codex } = value.hosts;
|
|
107
|
+
if (!isHostMode(claude) || !isHostMode(codex)) return null;
|
|
108
|
+
return { consent, update: { mode, channel }, hosts: { claude, codex } };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** @param {string} root */
|
|
112
|
+
export function releaseSettingsPath(root) {
|
|
113
|
+
return join(root, RELEASE_SETTINGS_FILE);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The settings in force: a regular owned file of bounded size, opened without
|
|
118
|
+
* following symlinks; anything else means defaults with the matching status.
|
|
119
|
+
* @param {string} root @returns {Promise<ReleaseSettings>}
|
|
120
|
+
*/
|
|
121
|
+
export async function readReleaseSettings(root) {
|
|
122
|
+
const path = releaseSettingsPath(root);
|
|
123
|
+
/** @type {import('node:fs/promises').FileHandle | undefined} */
|
|
124
|
+
let handle;
|
|
125
|
+
try {
|
|
126
|
+
const link = await lstat(path);
|
|
127
|
+
if (!link.isFile() || link.size > MAX_SETTINGS_BYTES)
|
|
128
|
+
return { status: 'invalid', ...defaultReleaseSettings() };
|
|
129
|
+
if (typeof process.getuid === 'function' && link.uid !== process.getuid())
|
|
130
|
+
return { status: 'invalid', ...defaultReleaseSettings() };
|
|
131
|
+
handle = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
132
|
+
const parsed = parseReleaseSettings(JSON.parse(await handle.readFile('utf8')));
|
|
133
|
+
return parsed === null
|
|
134
|
+
? { status: 'invalid', ...defaultReleaseSettings() }
|
|
135
|
+
: { status: 'valid', ...parsed };
|
|
136
|
+
} catch (error) {
|
|
137
|
+
const missing = error instanceof Error && 'code' in error && error.code === 'ENOENT';
|
|
138
|
+
return { status: missing ? 'missing' : 'invalid', ...defaultReleaseSettings() };
|
|
139
|
+
} finally {
|
|
140
|
+
await handle?.close().catch(() => undefined);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Store settings (`0600`, atomic). Callers pass a complete document; the
|
|
146
|
+
* closed key set is what older clients and the hook helpers rely on.
|
|
147
|
+
* @param {StoredSettings} settings @param {string} [root]
|
|
148
|
+
*/
|
|
149
|
+
export async function writeReleaseSettings(settings, root) {
|
|
150
|
+
const stateRootPath = root ?? (await ensureStateRoot());
|
|
151
|
+
await atomicJson(releaseSettingsPath(stateRootPath), {
|
|
152
|
+
schemaVersion: SCHEMA_VERSION,
|
|
153
|
+
consent: settings.consent,
|
|
154
|
+
update: { mode: settings.update.mode, channel: settings.update.channel },
|
|
155
|
+
hosts: { claude: settings.hosts.claude, codex: settings.hosts.codex },
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The self-update mode for this process (FR7): the environment turns it off
|
|
161
|
+
* for one launch, and a setup that has not answered the release disclosure
|
|
162
|
+
* behaves as `notify` (D8), whatever the file says.
|
|
163
|
+
* @param {ReleaseSettings} settings @param {NodeJS.ProcessEnv} env
|
|
164
|
+
* @returns {{ mode: UpdateMode, reason: 'update_disabled_by_env' | 'consent_pending' | null }}
|
|
165
|
+
*/
|
|
166
|
+
export function effectiveUpdateMode(settings, env) {
|
|
167
|
+
if (env[NO_SELF_UPDATE_ENV] === '1') return { mode: 'off', reason: 'update_disabled_by_env' };
|
|
168
|
+
if (settings.consent === null) return { mode: 'notify', reason: 'consent_pending' };
|
|
169
|
+
return { mode: settings.update.mode, reason: null };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The package name the user installed (`@aisac/cli` or the legacy name), read
|
|
174
|
+
* from the package manifest next to the code; the first name when unreadable.
|
|
175
|
+
* The update keeps that name (FR6).
|
|
176
|
+
* @param {string} packageRoot @returns {Promise<string>}
|
|
177
|
+
*/
|
|
178
|
+
export async function installedPackageName(packageRoot) {
|
|
179
|
+
try {
|
|
180
|
+
const path = join(packageRoot, 'package.json');
|
|
181
|
+
const entry = await stat(path);
|
|
182
|
+
if (!entry.isFile() || entry.size > MAX_PACKAGE_JSON_BYTES) return CLIENT_PACKAGES[0];
|
|
183
|
+
/** @type {unknown} */
|
|
184
|
+
const parsed = JSON.parse(await readFile(path, 'utf8'));
|
|
185
|
+
return isRecord(parsed) &&
|
|
186
|
+
typeof parsed.name === 'string' &&
|
|
187
|
+
CLIENT_PACKAGES.includes(parsed.name)
|
|
188
|
+
? parsed.name
|
|
189
|
+
: CLIENT_PACKAGES[0];
|
|
190
|
+
} catch {
|
|
191
|
+
return CLIENT_PACKAGES[0];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The command every outdated-client notice prints (FR6). @param {string} packageName @param {Channel} channel */
|
|
196
|
+
export function updateCommandLine(packageName, channel) {
|
|
197
|
+
return `npm install -g ${packageName}@${channel}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The update command for this installation and the user's channel; never throws.
|
|
202
|
+
* @param {string} root @param {string} packageRoot
|
|
203
|
+
*/
|
|
204
|
+
export async function updateCommandFor(root, packageRoot) {
|
|
205
|
+
const [settings, packageName] = await Promise.all([
|
|
206
|
+
readReleaseSettings(root).catch(() => ({ ...defaultReleaseSettings(), status: 'invalid' })),
|
|
207
|
+
installedPackageName(packageRoot),
|
|
208
|
+
]);
|
|
209
|
+
return updateCommandLine(packageName, settings.update.channel);
|
|
210
|
+
}
|