@aisac/cli 0.4.0-beta.2 → 0.4.0-beta.21
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 +115 -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 +243 -5
- package/dist/assets/jev-paid-pilot-terminal.mjs +6 -0
- package/dist/claude-compatibility.mjs +26 -25
- package/dist/claude-observation.mjs +2 -1
- package/dist/cli.mjs +584 -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 +259 -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 +373 -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 +449 -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 +278 -34
- package/dist/managed-host.mjs +977 -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
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* AISAC Engineering pack for Claude Code (ADR-0047 wave E4b
|
|
4
|
+
* AISAC Engineering pack for Claude Code (ADR-0047 wave E4b) and Codex (E4c),
|
|
5
|
+
* spec FR4/FR8.
|
|
5
6
|
*
|
|
6
7
|
* One request per launch fetches the account's pack; it doubles as the live
|
|
7
8
|
* license check. The pack is trusted instruction for the user's agent, so it
|
|
8
9
|
* is accepted only when it is signed by a pinned key, matches the requested
|
|
9
10
|
* locale and passes the FR3 rules again here. It is written into the launch's
|
|
10
|
-
* private directory and handed to Claude Code as a second `--plugin-dir
|
|
11
|
+
* private directory and handed to Claude Code as a second `--plugin-dir`, or
|
|
12
|
+
* to the Codex app-server this launch owns (see codex-engineering.mjs).
|
|
11
13
|
* Any failure starts the session without the pack; nothing here can block a
|
|
12
14
|
* launch or treat a failure as licensed.
|
|
13
15
|
*/
|
|
@@ -35,6 +37,13 @@ import {
|
|
|
35
37
|
unavailableReasonFor,
|
|
36
38
|
} from './engineering.mjs';
|
|
37
39
|
import { atomicJson } from './state.mjs';
|
|
40
|
+
import {
|
|
41
|
+
AGENT_NAME,
|
|
42
|
+
CODEX_AGENTS_DIRECTORY,
|
|
43
|
+
MAX_AGENT_DESCRIPTION_LENGTH,
|
|
44
|
+
tomlBasicString,
|
|
45
|
+
validateCodexEngineering,
|
|
46
|
+
} from './codex-engineering.mjs';
|
|
38
47
|
|
|
39
48
|
const PACK_PATH = '/engineering/v1/pack';
|
|
40
49
|
export const PACK_TIMEOUT_MS = 10_000;
|
|
@@ -85,7 +94,27 @@ const FORBIDDEN_FRONT_MATTER_KEYS = new Set([
|
|
|
85
94
|
const PLUGIN_NAME = 'aisac-engineering';
|
|
86
95
|
const PLUGIN_LICENSE = 'LicenseRef-AISAC-Engineering';
|
|
87
96
|
const PACK_DIRECTORY = 'engineering';
|
|
97
|
+
/**
|
|
98
|
+
* `aisac init` templates (spec aisac-engineering-init D2, E5c): pack files that
|
|
99
|
+
* never reach a session. Only `engineering-init.mjs` reads them.
|
|
100
|
+
*/
|
|
101
|
+
export const INIT_PREFIX = 'init/';
|
|
102
|
+
/**
|
|
103
|
+
* `aisac scan` rules (spec aisac-engineering-scan D3, FR7): Semgrep rules as
|
|
104
|
+
* data that never reach a session. Only the scan command reads them.
|
|
105
|
+
*/
|
|
106
|
+
export const SCAN_PREFIX = 'scan/';
|
|
107
|
+
/**
|
|
108
|
+
* Pack prefixes the session materializers leave out (scan spec FR7): files
|
|
109
|
+
* under them are for a client command, never for a Claude or Codex session.
|
|
110
|
+
* @type {readonly string[]}
|
|
111
|
+
*/
|
|
112
|
+
export const NON_SESSION_PREFIXES = Object.freeze([INIT_PREFIX, SCAN_PREFIX]);
|
|
88
113
|
const OUTPUT_STYLES_PREFIX = 'output-styles/';
|
|
114
|
+
const SKILLS_DIRECTORY = 'skills';
|
|
115
|
+
const AGENT_FILE = /^agents\/([a-z][a-z0-9-]{0,63})\.md$/u;
|
|
116
|
+
const WATERMARK_KEY = 'aisac_watermark';
|
|
117
|
+
const WATERMARK_VALUE = /^[0-9a-f]{16}$/u;
|
|
89
118
|
export const PUBLIC_KEY_FILE = 'engineering-pack-public-key.json';
|
|
90
119
|
const LOCALE_FILE = 'engineering-locale.json';
|
|
91
120
|
const LAST_LAUNCH_FILE = 'engineering-last-launch.json';
|
|
@@ -113,11 +142,12 @@ const SAFE_REASON = /^[a-z][a-z0-9_]{0,63}$/u;
|
|
|
113
142
|
* | { outcome: 'unavailable', reason: string }
|
|
114
143
|
* | { outcome: 'rejected', reason: string }} PackOutcome
|
|
115
144
|
*/
|
|
145
|
+
/** @typedef {'claude' | 'codex'} PackClient */
|
|
116
146
|
/**
|
|
117
147
|
* @typedef {{
|
|
118
148
|
* schemaVersion: 1,
|
|
119
149
|
* at: string,
|
|
120
|
-
* client:
|
|
150
|
+
* client: PackClient,
|
|
121
151
|
* state: PackOutcome['outcome'],
|
|
122
152
|
* reason: string | null,
|
|
123
153
|
* packVersion: string | null,
|
|
@@ -198,7 +228,7 @@ export async function readLastLaunch(root) {
|
|
|
198
228
|
value.schemaVersion !== 1 ||
|
|
199
229
|
typeof value.at !== 'string' ||
|
|
200
230
|
!ISO_INSTANT.test(value.at) ||
|
|
201
|
-
value.client !== 'claude' ||
|
|
231
|
+
(value.client !== 'claude' && value.client !== 'codex') ||
|
|
202
232
|
!['loaded', 'inactive', 'not_offered', 'unavailable', 'rejected'].includes(
|
|
203
233
|
/** @type {string} */ (value.state),
|
|
204
234
|
) ||
|
|
@@ -258,10 +288,11 @@ export function parsePinnedKeys(text) {
|
|
|
258
288
|
* The keys ship inside the installed package, which a global install may own
|
|
259
289
|
* as root, so only the size is bounded here (unlike private state files).
|
|
260
290
|
* @param {string} packageRoot
|
|
291
|
+
* @param {string} [fileName] another pinned-keys file of the same shape (the release manifest's)
|
|
261
292
|
* @returns {Promise<PinnedKey[]>}
|
|
262
293
|
*/
|
|
263
|
-
export async function loadPinnedKeys(packageRoot) {
|
|
264
|
-
const path = join(packageRoot,
|
|
294
|
+
export async function loadPinnedKeys(packageRoot, fileName = PUBLIC_KEY_FILE) {
|
|
295
|
+
const path = join(packageRoot, fileName);
|
|
265
296
|
const entry = await stat(path);
|
|
266
297
|
if (!entry.isFile() || entry.size > MAX_SMALL_STATE_BYTES) throw new Error('pinned_keys_invalid');
|
|
267
298
|
return parsePinnedKeys(await readFile(path, 'utf8'));
|
|
@@ -519,21 +550,44 @@ const PLUGIN_DESCRIPTION = {
|
|
|
519
550
|
};
|
|
520
551
|
|
|
521
552
|
/**
|
|
522
|
-
*
|
|
523
|
-
*
|
|
553
|
+
* Whether a pack path belongs to a client command rather than a session.
|
|
554
|
+
* @param {string} path
|
|
555
|
+
*/
|
|
556
|
+
export function isNonSessionPath(path) {
|
|
557
|
+
return NON_SESSION_PREFIXES.some((prefix) => path.startsWith(prefix));
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Write the pack files into `engineering/` of the launch's private directory:
|
|
562
|
+
* `0700` directories, `0600` files, exclusive creation, contained paths. Files
|
|
563
|
+
* under a non-session prefix stay out: the `init/` templates are for
|
|
564
|
+
* `aisac init` and the `scan/` rules for `aisac scan`, not for a session.
|
|
524
565
|
* @param {VerifiedPack} pack
|
|
525
566
|
* @param {string} launchDirectory
|
|
567
|
+
* @returns {Promise<string>} the pack root
|
|
526
568
|
*/
|
|
527
|
-
|
|
569
|
+
async function writePackFiles(pack, launchDirectory) {
|
|
528
570
|
const base = resolve(launchDirectory, PACK_DIRECTORY);
|
|
529
571
|
await mkdir(base, { mode: 0o700 });
|
|
530
572
|
for (const file of pack.files) {
|
|
531
573
|
if (!isValidPackPath(file.path)) throw new Error('pack_path_invalid');
|
|
574
|
+
if (isNonSessionPath(file.path)) continue;
|
|
532
575
|
const target = resolve(base, ...file.path.split('/'));
|
|
533
576
|
if (!target.startsWith(`${base}${sep}`)) throw new Error('pack_path_escape');
|
|
534
577
|
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
535
578
|
await writeFile(target, file.content, { mode: 0o600, flag: 'wx' });
|
|
536
579
|
}
|
|
580
|
+
return base;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Write a verified pack as a Claude Code plugin inside the launch's private
|
|
585
|
+
* directory and return the plugin root. The manifest is the client's own.
|
|
586
|
+
* @param {VerifiedPack} pack
|
|
587
|
+
* @param {string} launchDirectory
|
|
588
|
+
*/
|
|
589
|
+
export async function materializePack(pack, launchDirectory) {
|
|
590
|
+
const base = await writePackFiles(pack, launchDirectory);
|
|
537
591
|
const manifest = {
|
|
538
592
|
name: PLUGIN_NAME,
|
|
539
593
|
version: `0.0.0-${pack.packVersion}`,
|
|
@@ -553,14 +607,104 @@ export async function materializePack(pack, launchDirectory) {
|
|
|
553
607
|
return base;
|
|
554
608
|
}
|
|
555
609
|
|
|
610
|
+
/**
|
|
611
|
+
* Front-matter values (one `key: value` per line, lower-cased keys, matching
|
|
612
|
+
* outer quotes removed) and the body after it; null without front matter.
|
|
613
|
+
* @param {string} content
|
|
614
|
+
* @returns {{ values: Map<string, string>, body: string } | null}
|
|
615
|
+
*/
|
|
616
|
+
export function splitFrontMatter(content) {
|
|
617
|
+
if (!content.startsWith(FRONT_MATTER_FENCE)) return null;
|
|
618
|
+
const end = content.indexOf(FRONT_MATTER_CLOSE, FRONT_MATTER_FENCE.length - 1);
|
|
619
|
+
if (end === -1) return null;
|
|
620
|
+
/** @type {Map<string, string>} */
|
|
621
|
+
const values = new Map();
|
|
622
|
+
for (const line of content.slice(FRONT_MATTER_FENCE.length, end + 1).split('\n')) {
|
|
623
|
+
const key = FRONT_MATTER_KEY.exec(line)?.[1];
|
|
624
|
+
if (key === undefined) continue;
|
|
625
|
+
let value = line.slice(line.indexOf(':') + 1).trim();
|
|
626
|
+
if (value.length >= 2 && (value[0] === '"' || value[0] === "'") && value.at(-1) === value[0])
|
|
627
|
+
value = value.slice(1, -1);
|
|
628
|
+
values.set(key.toLowerCase(), value);
|
|
629
|
+
}
|
|
630
|
+
return { values, body: content.slice(end + FRONT_MATTER_CLOSE.length).replace(/^\n+/u, '') };
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* A Codex agent role file from a pack agent (`agents/<name>.md`): the front
|
|
635
|
+
* matter's name and description, the body as developer instructions, and the
|
|
636
|
+
* origin mark kept as a comment. Null when the agent cannot be a role.
|
|
637
|
+
* @param {PackFile} file
|
|
638
|
+
* @returns {{ name: string, description: string, toml: string } | null}
|
|
639
|
+
*/
|
|
640
|
+
export function codexRoleOf(file) {
|
|
641
|
+
const fileName = AGENT_FILE.exec(file.path)?.[1];
|
|
642
|
+
const parsed = splitFrontMatter(file.content);
|
|
643
|
+
if (fileName === undefined || parsed === null) return null;
|
|
644
|
+
const name = parsed.values.get('name');
|
|
645
|
+
const description = parsed.values.get('description');
|
|
646
|
+
if (name !== fileName || !AGENT_NAME.test(name)) return null;
|
|
647
|
+
if (
|
|
648
|
+
description === undefined ||
|
|
649
|
+
description.length === 0 ||
|
|
650
|
+
description.length > MAX_AGENT_DESCRIPTION_LENGTH ||
|
|
651
|
+
description === '>' ||
|
|
652
|
+
description === '|' ||
|
|
653
|
+
parsed.body.trim().length === 0
|
|
654
|
+
)
|
|
655
|
+
return null;
|
|
656
|
+
const watermark = parsed.values.get(WATERMARK_KEY);
|
|
657
|
+
const lines = [
|
|
658
|
+
'# AISAC Engineering. Licensed to your account; do not redistribute.',
|
|
659
|
+
...(watermark !== undefined && WATERMARK_VALUE.test(watermark)
|
|
660
|
+
? [`# ${WATERMARK_KEY}: ${watermark}`]
|
|
661
|
+
: []),
|
|
662
|
+
`name = ${tomlBasicString(name)}`,
|
|
663
|
+
`description = ${tomlBasicString(description)}`,
|
|
664
|
+
`developer_instructions = ${tomlBasicString(parsed.body)}`,
|
|
665
|
+
];
|
|
666
|
+
return { name, description, toml: `${lines.join('\n')}\n` };
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Write a verified pack for the Codex app-server this launch owns: the files
|
|
671
|
+
* as for Claude (without the Claude manifest), one role file per agent in
|
|
672
|
+
* `codex-agents/`, and the description the monitor turns into session
|
|
673
|
+
* arguments. Output styles have no Codex equivalent and stay unused.
|
|
674
|
+
* @param {VerifiedPack} pack
|
|
675
|
+
* @param {string} launchDirectory
|
|
676
|
+
* @returns {Promise<import('./codex-engineering.mjs').CodexEngineering>}
|
|
677
|
+
*/
|
|
678
|
+
export async function materializeCodexPack(pack, launchDirectory) {
|
|
679
|
+
const base = await writePackFiles(pack, launchDirectory);
|
|
680
|
+
const skillsRoot = join(base, SKILLS_DIRECTORY);
|
|
681
|
+
await mkdir(skillsRoot, { recursive: true, mode: 0o700 });
|
|
682
|
+
const rolesDirectory = join(base, CODEX_AGENTS_DIRECTORY);
|
|
683
|
+
await mkdir(rolesDirectory, { mode: 0o700 });
|
|
684
|
+
/** @type {import('./codex-engineering.mjs').CodexAgentRole[]} */
|
|
685
|
+
const agents = [];
|
|
686
|
+
for (const file of pack.files) {
|
|
687
|
+
const role = codexRoleOf(file);
|
|
688
|
+
if (role === null) continue;
|
|
689
|
+
const configFile = join(rolesDirectory, `${role.name}.toml`);
|
|
690
|
+
await writeFile(configFile, role.toml, { mode: 0o600, flag: 'wx' });
|
|
691
|
+
agents.push({ name: role.name, description: role.description, configFile });
|
|
692
|
+
}
|
|
693
|
+
return validateCodexEngineering({ schemaVersion: 1, skillsRoot, agents });
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** The update command when the caller has no channel to hand over (release-manifest FR6). */
|
|
697
|
+
export const DEFAULT_UPDATE_COMMAND = 'npm install -g @aisac/cli@beta';
|
|
698
|
+
|
|
556
699
|
/**
|
|
557
700
|
* One line for the launch, in the pack locale; null when the capability is
|
|
558
701
|
* not offered, so memory-only users see no change.
|
|
559
702
|
* @param {PackOutcome} outcome
|
|
560
703
|
* @param {PackLocale} locale
|
|
704
|
+
* @param {string} [updateCommand] The channel's command (release-manifest FR6).
|
|
561
705
|
* @returns {string | null}
|
|
562
706
|
*/
|
|
563
|
-
export function packNotice(outcome, locale) {
|
|
707
|
+
export function packNotice(outcome, locale, updateCommand = DEFAULT_UPDATE_COMMAND) {
|
|
564
708
|
const pt = locale === 'pt-BR';
|
|
565
709
|
const without = pt ? 'a sessão começa sem o método.' : 'the session starts without the method.';
|
|
566
710
|
switch (outcome.outcome) {
|
|
@@ -581,8 +725,8 @@ export function packNotice(outcome, locale) {
|
|
|
581
725
|
case 'rejected':
|
|
582
726
|
if (outcome.reason === 'client_outdated')
|
|
583
727
|
return pt
|
|
584
|
-
? `AISAC Engineering: atualize o aisac (
|
|
585
|
-
: `AISAC Engineering: update aisac (
|
|
728
|
+
? `AISAC Engineering: atualize o aisac (${updateCommand}); ${without}`
|
|
729
|
+
: `AISAC Engineering: update aisac (${updateCommand}); ${without}`;
|
|
586
730
|
return pt
|
|
587
731
|
? `AISAC Engineering: pacote recusado (${outcome.reason}); ${without}`
|
|
588
732
|
: `AISAC Engineering: pack rejected (${outcome.reason}); ${without}`;
|
|
@@ -594,13 +738,14 @@ export function packNotice(outcome, locale) {
|
|
|
594
738
|
/**
|
|
595
739
|
* @param {PackOutcome} outcome
|
|
596
740
|
* @param {PackLocale} locale
|
|
741
|
+
* @param {PackClient} client
|
|
597
742
|
* @returns {LastLaunch}
|
|
598
743
|
*/
|
|
599
|
-
function lastLaunchOf(outcome, locale) {
|
|
744
|
+
function lastLaunchOf(outcome, locale, client) {
|
|
600
745
|
return {
|
|
601
746
|
schemaVersion: 1,
|
|
602
747
|
at: new Date().toISOString(),
|
|
603
|
-
client
|
|
748
|
+
client,
|
|
604
749
|
state: outcome.outcome,
|
|
605
750
|
reason:
|
|
606
751
|
outcome.outcome === 'unavailable' || outcome.outcome === 'rejected' ? outcome.reason : null,
|
|
@@ -610,13 +755,17 @@ function lastLaunchOf(outcome, locale) {
|
|
|
610
755
|
}
|
|
611
756
|
|
|
612
757
|
/**
|
|
613
|
-
* Fetch, verify and write the pack for one Claude Code launch. Never
|
|
758
|
+
* Fetch, verify and write the pack for one Claude Code or Codex launch. Never
|
|
759
|
+
* throws. `hostSupported: false` (a Codex release older than the verified
|
|
760
|
+
* mechanism) still checks the license but loads nothing.
|
|
614
761
|
* @param {{ endpoint: string, token: string, root: string, directory: string,
|
|
615
|
-
* packageRoot: string,
|
|
616
|
-
* timeoutMs?: number }} input
|
|
617
|
-
* @returns {Promise<{ pluginRoot: string | null,
|
|
762
|
+
* packageRoot: string, client?: PackClient, hostSupported?: boolean, updateCommand?: string,
|
|
763
|
+
* env?: NodeJS.ProcessEnv, fetchImpl?: typeof fetch, timeoutMs?: number }} input
|
|
764
|
+
* @returns {Promise<{ pluginRoot: string | null,
|
|
765
|
+
* codex: import('./codex-engineering.mjs').CodexEngineering | null, line: string | null }>}
|
|
618
766
|
*/
|
|
619
767
|
export async function prepareEngineeringPack(input) {
|
|
768
|
+
const client = input.client ?? 'claude';
|
|
620
769
|
const locale = resolvePackLocale(await readStoredLocale(input.root), input.env);
|
|
621
770
|
/** @type {PackOutcome} */
|
|
622
771
|
let outcome;
|
|
@@ -632,28 +781,42 @@ export async function prepareEngineeringPack(input) {
|
|
|
632
781
|
} catch {
|
|
633
782
|
outcome = { outcome: 'unavailable', reason: 'client_error' };
|
|
634
783
|
}
|
|
784
|
+
if (outcome.outcome === 'loaded' && input.hostSupported === false)
|
|
785
|
+
outcome = { outcome: 'unavailable', reason: `${client}_outdated` };
|
|
635
786
|
let pluginRoot = null;
|
|
787
|
+
/** @type {import('./codex-engineering.mjs').CodexEngineering | null} */
|
|
788
|
+
let codex = null;
|
|
636
789
|
if (outcome.outcome === 'loaded') {
|
|
637
790
|
try {
|
|
638
|
-
|
|
791
|
+
if (client === 'codex') codex = await materializeCodexPack(outcome.pack, input.directory);
|
|
792
|
+
else pluginRoot = await materializePack(outcome.pack, input.directory);
|
|
639
793
|
} catch {
|
|
794
|
+
codex = null;
|
|
640
795
|
await rm(join(input.directory, PACK_DIRECTORY), { recursive: true, force: true }).catch(
|
|
641
796
|
() => undefined,
|
|
642
797
|
);
|
|
643
798
|
outcome = { outcome: 'rejected', reason: 'materialize_failed' };
|
|
644
799
|
}
|
|
645
800
|
}
|
|
646
|
-
await atomicJson(join(input.root, LAST_LAUNCH_FILE), lastLaunchOf(outcome, locale)).catch(
|
|
801
|
+
await atomicJson(join(input.root, LAST_LAUNCH_FILE), lastLaunchOf(outcome, locale, client)).catch(
|
|
647
802
|
() => undefined,
|
|
648
803
|
);
|
|
649
|
-
return { pluginRoot, line: packNotice(outcome, locale) };
|
|
804
|
+
return { pluginRoot, codex, line: packNotice(outcome, locale, input.updateCommand) };
|
|
650
805
|
}
|
|
651
806
|
|
|
807
|
+
/**
|
|
808
|
+
* The host a launch runs, as its marker records it (release-manifest FR5): the
|
|
809
|
+
* managed-host garbage collection never removes a version a live marker names.
|
|
810
|
+
* @typedef {{ name: 'claude' | 'codex', mode: 'system' | 'managed' | 'pending', version: string | null }} LaunchHost
|
|
811
|
+
* `pending`: the launch has not resolved its host yet (release-manifest FR5); collectors
|
|
812
|
+
* skip while one is live, so the version it is about to run is never removed.
|
|
813
|
+
*/
|
|
814
|
+
|
|
652
815
|
/**
|
|
653
816
|
* Record who owns a launch directory, so a later launch can sweep it once
|
|
654
|
-
* both processes are gone (spec FR4 step 7).
|
|
817
|
+
* both processes are gone (spec FR4 step 7), and which host it runs.
|
|
655
818
|
* @param {string} directory
|
|
656
|
-
* @param {{ launcherPid: number, childPid: number | null }} owners
|
|
819
|
+
* @param {{ launcherPid: number, childPid: number | null, host?: LaunchHost }} owners
|
|
657
820
|
*/
|
|
658
821
|
export async function writeLaunchMarker(directory, owners) {
|
|
659
822
|
const path = join(directory, LAUNCH_MARKER_FILE);
|
|
@@ -720,3 +883,76 @@ export async function sweepStaleLaunches(root, alive = processAlive) {
|
|
|
720
883
|
}
|
|
721
884
|
return removed;
|
|
722
885
|
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Launches still running after the stale sweep: directories whose marker names
|
|
889
|
+
* a live launcher or child. The client never updates itself under one
|
|
890
|
+
* (release-manifest FR6). Never throws.
|
|
891
|
+
* @param {string} root
|
|
892
|
+
* @param {(pid: number) => boolean} [alive]
|
|
893
|
+
* @returns {Promise<number>}
|
|
894
|
+
*/
|
|
895
|
+
export async function liveLaunchCount(root, alive = processAlive) {
|
|
896
|
+
await sweepStaleLaunches(root, alive);
|
|
897
|
+
const runtime = join(root, 'runtime');
|
|
898
|
+
let entries;
|
|
899
|
+
try {
|
|
900
|
+
entries = await readdir(runtime, { withFileTypes: true });
|
|
901
|
+
} catch {
|
|
902
|
+
return 0;
|
|
903
|
+
}
|
|
904
|
+
let live = 0;
|
|
905
|
+
for (const entry of entries) {
|
|
906
|
+
if (!entry.isDirectory() || !LAUNCH_DIRECTORY.test(entry.name)) continue;
|
|
907
|
+
const marker = await readSmallStateJson(join(runtime, entry.name, LAUNCH_MARKER_FILE));
|
|
908
|
+
if (!isRecord(marker) || marker.schemaVersion !== 1 || !isPid(marker.launcherPid)) continue;
|
|
909
|
+
const childPid = isPid(marker.childPid) ? /** @type {number} */ (marker.childPid) : null;
|
|
910
|
+
if (alive(/** @type {number} */ (marker.launcherPid)) || (childPid !== null && alive(childPid)))
|
|
911
|
+
live += 1;
|
|
912
|
+
}
|
|
913
|
+
return live;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/** @param {unknown} value @returns {LaunchHost | null} */
|
|
917
|
+
function launchHostOf(value) {
|
|
918
|
+
if (!isRecord(value)) return null;
|
|
919
|
+
const { name, mode, version } = value;
|
|
920
|
+
if (name !== 'claude' && name !== 'codex') return null;
|
|
921
|
+
if (mode !== 'system' && mode !== 'managed' && mode !== 'pending') return null;
|
|
922
|
+
if (version !== null && (typeof version !== 'string' || version.length > 64)) return null;
|
|
923
|
+
return { name, mode, version: /** @type {string | null} */ (version) };
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* The hosts of the launches still running (release-manifest FR5): a managed
|
|
928
|
+
* host version one of them names is never garbage-collected. Never throws.
|
|
929
|
+
* @param {string} root
|
|
930
|
+
* @param {(pid: number) => boolean} [alive]
|
|
931
|
+
* @returns {Promise<LaunchHost[]>}
|
|
932
|
+
*/
|
|
933
|
+
export async function liveLaunchHosts(root, alive = processAlive) {
|
|
934
|
+
await sweepStaleLaunches(root, alive);
|
|
935
|
+
const runtime = join(root, 'runtime');
|
|
936
|
+
let entries;
|
|
937
|
+
try {
|
|
938
|
+
entries = await readdir(runtime, { withFileTypes: true });
|
|
939
|
+
} catch {
|
|
940
|
+
return [];
|
|
941
|
+
}
|
|
942
|
+
/** @type {LaunchHost[]} */
|
|
943
|
+
const hosts = [];
|
|
944
|
+
for (const entry of entries) {
|
|
945
|
+
if (!entry.isDirectory() || !LAUNCH_DIRECTORY.test(entry.name)) continue;
|
|
946
|
+
const marker = await readSmallStateJson(join(runtime, entry.name, LAUNCH_MARKER_FILE));
|
|
947
|
+
if (!isRecord(marker) || marker.schemaVersion !== 1 || !isPid(marker.launcherPid)) continue;
|
|
948
|
+
const childPid = isPid(marker.childPid) ? /** @type {number} */ (marker.childPid) : null;
|
|
949
|
+
if (
|
|
950
|
+
!alive(/** @type {number} */ (marker.launcherPid)) &&
|
|
951
|
+
(childPid === null || !alive(childPid))
|
|
952
|
+
)
|
|
953
|
+
continue;
|
|
954
|
+
const host = launchHostOf(marker.host);
|
|
955
|
+
if (host !== null) hosts.push(host);
|
|
956
|
+
}
|
|
957
|
+
return hosts;
|
|
958
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"capturedAt": "2026-11-12T11:56:20Z",
|
|
4
|
+
"tools": {
|
|
5
|
+
"gitleaks": {
|
|
6
|
+
"kinds": ["secrets"],
|
|
7
|
+
"image": "ghcr.io/gitleaks/gitleaks",
|
|
8
|
+
"tag": "v8.30.1",
|
|
9
|
+
"digest": "sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9ab65d25e6bc8abbb7f",
|
|
10
|
+
"binary": "gitleaks",
|
|
11
|
+
"versions": ["8.30.1"],
|
|
12
|
+
"user": "65532:65532"
|
|
13
|
+
},
|
|
14
|
+
"semgrep": {
|
|
15
|
+
"kinds": ["sast"],
|
|
16
|
+
"image": "semgrep/semgrep",
|
|
17
|
+
"tag": "1.185.0",
|
|
18
|
+
"digest": "sha256:67518c174185a2043fdbed16c70631b79209499b3671178e7194379b48295a0d",
|
|
19
|
+
"binary": "semgrep",
|
|
20
|
+
"versions": ["1.185.0"],
|
|
21
|
+
"user": "65532:65532"
|
|
22
|
+
},
|
|
23
|
+
"osv-scanner": {
|
|
24
|
+
"kinds": ["sca"],
|
|
25
|
+
"image": "ghcr.io/google/osv-scanner",
|
|
26
|
+
"tag": "v2.7.1",
|
|
27
|
+
"digest": "sha256:a70ffffc2bfd33482953e5d6b64c6fcdb30239717a07b0f0d3ab2859ce3e4cde",
|
|
28
|
+
"binary": "osv-scanner",
|
|
29
|
+
"versions": ["2.7.1"],
|
|
30
|
+
"user": "65532:65532"
|
|
31
|
+
},
|
|
32
|
+
"trivy": {
|
|
33
|
+
"kinds": ["iac", "container"],
|
|
34
|
+
"image": "ghcr.io/aquasecurity/trivy",
|
|
35
|
+
"tag": "0.76.2",
|
|
36
|
+
"digest": "sha256:8f6bb947dbc528902e11f2f5be52f7b519f6a39d5d148f41166f2040499768fb",
|
|
37
|
+
"binary": "trivy",
|
|
38
|
+
"versions": ["0.76.2"],
|
|
39
|
+
"user": "65532:65532"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|