@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
|
@@ -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,34 @@ 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]);
|
|
113
|
+
/**
|
|
114
|
+
* Pack prefixes only a Claude Code session gets (manager spec FR1, FR12): the
|
|
115
|
+
* manager's playbook is for the session that holds the `manager_*` tools, and
|
|
116
|
+
* that role exists only on Claude Code. A Codex session never lists it.
|
|
117
|
+
* @type {readonly string[]}
|
|
118
|
+
*/
|
|
119
|
+
export const CLAUDE_ONLY_PREFIXES = Object.freeze(['skills/manager/']);
|
|
88
120
|
const OUTPUT_STYLES_PREFIX = 'output-styles/';
|
|
121
|
+
const SKILLS_DIRECTORY = 'skills';
|
|
122
|
+
const AGENT_FILE = /^agents\/([a-z][a-z0-9-]{0,63})\.md$/u;
|
|
123
|
+
const WATERMARK_KEY = 'aisac_watermark';
|
|
124
|
+
const WATERMARK_VALUE = /^[0-9a-f]{16}$/u;
|
|
89
125
|
export const PUBLIC_KEY_FILE = 'engineering-pack-public-key.json';
|
|
90
126
|
const LOCALE_FILE = 'engineering-locale.json';
|
|
91
127
|
const LAST_LAUNCH_FILE = 'engineering-last-launch.json';
|
|
@@ -113,11 +149,12 @@ const SAFE_REASON = /^[a-z][a-z0-9_]{0,63}$/u;
|
|
|
113
149
|
* | { outcome: 'unavailable', reason: string }
|
|
114
150
|
* | { outcome: 'rejected', reason: string }} PackOutcome
|
|
115
151
|
*/
|
|
152
|
+
/** @typedef {'claude' | 'codex'} PackClient */
|
|
116
153
|
/**
|
|
117
154
|
* @typedef {{
|
|
118
155
|
* schemaVersion: 1,
|
|
119
156
|
* at: string,
|
|
120
|
-
* client:
|
|
157
|
+
* client: PackClient,
|
|
121
158
|
* state: PackOutcome['outcome'],
|
|
122
159
|
* reason: string | null,
|
|
123
160
|
* packVersion: string | null,
|
|
@@ -198,7 +235,7 @@ export async function readLastLaunch(root) {
|
|
|
198
235
|
value.schemaVersion !== 1 ||
|
|
199
236
|
typeof value.at !== 'string' ||
|
|
200
237
|
!ISO_INSTANT.test(value.at) ||
|
|
201
|
-
value.client !== 'claude' ||
|
|
238
|
+
(value.client !== 'claude' && value.client !== 'codex') ||
|
|
202
239
|
!['loaded', 'inactive', 'not_offered', 'unavailable', 'rejected'].includes(
|
|
203
240
|
/** @type {string} */ (value.state),
|
|
204
241
|
) ||
|
|
@@ -258,10 +295,11 @@ export function parsePinnedKeys(text) {
|
|
|
258
295
|
* The keys ship inside the installed package, which a global install may own
|
|
259
296
|
* as root, so only the size is bounded here (unlike private state files).
|
|
260
297
|
* @param {string} packageRoot
|
|
298
|
+
* @param {string} [fileName] another pinned-keys file of the same shape (the release manifest's)
|
|
261
299
|
* @returns {Promise<PinnedKey[]>}
|
|
262
300
|
*/
|
|
263
|
-
export async function loadPinnedKeys(packageRoot) {
|
|
264
|
-
const path = join(packageRoot,
|
|
301
|
+
export async function loadPinnedKeys(packageRoot, fileName = PUBLIC_KEY_FILE) {
|
|
302
|
+
const path = join(packageRoot, fileName);
|
|
265
303
|
const entry = await stat(path);
|
|
266
304
|
if (!entry.isFile() || entry.size > MAX_SMALL_STATE_BYTES) throw new Error('pinned_keys_invalid');
|
|
267
305
|
return parsePinnedKeys(await readFile(path, 'utf8'));
|
|
@@ -519,21 +557,53 @@ const PLUGIN_DESCRIPTION = {
|
|
|
519
557
|
};
|
|
520
558
|
|
|
521
559
|
/**
|
|
522
|
-
*
|
|
523
|
-
*
|
|
560
|
+
* Whether a pack path belongs to a client command rather than a session.
|
|
561
|
+
* @param {string} path
|
|
562
|
+
*/
|
|
563
|
+
export function isNonSessionPath(path) {
|
|
564
|
+
return NON_SESSION_PREFIXES.some((prefix) => path.startsWith(prefix));
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Whether a pack path is left out of a Codex session.
|
|
569
|
+
* @param {string} path
|
|
570
|
+
*/
|
|
571
|
+
export function isClaudeOnlyPath(path) {
|
|
572
|
+
return CLAUDE_ONLY_PREFIXES.some((prefix) => path.startsWith(prefix));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Write the pack files into `engineering/` of the launch's private directory:
|
|
577
|
+
* `0700` directories, `0600` files, exclusive creation, contained paths. Files
|
|
578
|
+
* under a non-session prefix stay out: the `init/` templates are for
|
|
579
|
+
* `aisac init` and the `scan/` rules for `aisac scan`, not for a session.
|
|
524
580
|
* @param {VerifiedPack} pack
|
|
525
581
|
* @param {string} launchDirectory
|
|
582
|
+
* @param {(path: string) => boolean} [leftOut] Paths this host does not get.
|
|
583
|
+
* @returns {Promise<string>} the pack root
|
|
526
584
|
*/
|
|
527
|
-
|
|
585
|
+
async function writePackFiles(pack, launchDirectory, leftOut = () => false) {
|
|
528
586
|
const base = resolve(launchDirectory, PACK_DIRECTORY);
|
|
529
587
|
await mkdir(base, { mode: 0o700 });
|
|
530
588
|
for (const file of pack.files) {
|
|
531
589
|
if (!isValidPackPath(file.path)) throw new Error('pack_path_invalid');
|
|
590
|
+
if (isNonSessionPath(file.path) || leftOut(file.path)) continue;
|
|
532
591
|
const target = resolve(base, ...file.path.split('/'));
|
|
533
592
|
if (!target.startsWith(`${base}${sep}`)) throw new Error('pack_path_escape');
|
|
534
593
|
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
535
594
|
await writeFile(target, file.content, { mode: 0o600, flag: 'wx' });
|
|
536
595
|
}
|
|
596
|
+
return base;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Write a verified pack as a Claude Code plugin inside the launch's private
|
|
601
|
+
* directory and return the plugin root. The manifest is the client's own.
|
|
602
|
+
* @param {VerifiedPack} pack
|
|
603
|
+
* @param {string} launchDirectory
|
|
604
|
+
*/
|
|
605
|
+
export async function materializePack(pack, launchDirectory) {
|
|
606
|
+
const base = await writePackFiles(pack, launchDirectory);
|
|
537
607
|
const manifest = {
|
|
538
608
|
name: PLUGIN_NAME,
|
|
539
609
|
version: `0.0.0-${pack.packVersion}`,
|
|
@@ -553,14 +623,105 @@ export async function materializePack(pack, launchDirectory) {
|
|
|
553
623
|
return base;
|
|
554
624
|
}
|
|
555
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Front-matter values (one `key: value` per line, lower-cased keys, matching
|
|
628
|
+
* outer quotes removed) and the body after it; null without front matter.
|
|
629
|
+
* @param {string} content
|
|
630
|
+
* @returns {{ values: Map<string, string>, body: string } | null}
|
|
631
|
+
*/
|
|
632
|
+
export function splitFrontMatter(content) {
|
|
633
|
+
if (!content.startsWith(FRONT_MATTER_FENCE)) return null;
|
|
634
|
+
const end = content.indexOf(FRONT_MATTER_CLOSE, FRONT_MATTER_FENCE.length - 1);
|
|
635
|
+
if (end === -1) return null;
|
|
636
|
+
/** @type {Map<string, string>} */
|
|
637
|
+
const values = new Map();
|
|
638
|
+
for (const line of content.slice(FRONT_MATTER_FENCE.length, end + 1).split('\n')) {
|
|
639
|
+
const key = FRONT_MATTER_KEY.exec(line)?.[1];
|
|
640
|
+
if (key === undefined) continue;
|
|
641
|
+
let value = line.slice(line.indexOf(':') + 1).trim();
|
|
642
|
+
if (value.length >= 2 && (value[0] === '"' || value[0] === "'") && value.at(-1) === value[0])
|
|
643
|
+
value = value.slice(1, -1);
|
|
644
|
+
values.set(key.toLowerCase(), value);
|
|
645
|
+
}
|
|
646
|
+
return { values, body: content.slice(end + FRONT_MATTER_CLOSE.length).replace(/^\n+/u, '') };
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* A Codex agent role file from a pack agent (`agents/<name>.md`): the front
|
|
651
|
+
* matter's name and description, the body as developer instructions, and the
|
|
652
|
+
* origin mark kept as a comment. Null when the agent cannot be a role.
|
|
653
|
+
* @param {PackFile} file
|
|
654
|
+
* @returns {{ name: string, description: string, toml: string } | null}
|
|
655
|
+
*/
|
|
656
|
+
export function codexRoleOf(file) {
|
|
657
|
+
const fileName = AGENT_FILE.exec(file.path)?.[1];
|
|
658
|
+
const parsed = splitFrontMatter(file.content);
|
|
659
|
+
if (fileName === undefined || parsed === null) return null;
|
|
660
|
+
const name = parsed.values.get('name');
|
|
661
|
+
const description = parsed.values.get('description');
|
|
662
|
+
if (name !== fileName || !AGENT_NAME.test(name)) return null;
|
|
663
|
+
if (
|
|
664
|
+
description === undefined ||
|
|
665
|
+
description.length === 0 ||
|
|
666
|
+
description.length > MAX_AGENT_DESCRIPTION_LENGTH ||
|
|
667
|
+
description === '>' ||
|
|
668
|
+
description === '|' ||
|
|
669
|
+
parsed.body.trim().length === 0
|
|
670
|
+
)
|
|
671
|
+
return null;
|
|
672
|
+
const watermark = parsed.values.get(WATERMARK_KEY);
|
|
673
|
+
const lines = [
|
|
674
|
+
'# AISAC Engineering. Licensed to your account; do not redistribute.',
|
|
675
|
+
...(watermark !== undefined && WATERMARK_VALUE.test(watermark)
|
|
676
|
+
? [`# ${WATERMARK_KEY}: ${watermark}`]
|
|
677
|
+
: []),
|
|
678
|
+
`name = ${tomlBasicString(name)}`,
|
|
679
|
+
`description = ${tomlBasicString(description)}`,
|
|
680
|
+
`developer_instructions = ${tomlBasicString(parsed.body)}`,
|
|
681
|
+
];
|
|
682
|
+
return { name, description, toml: `${lines.join('\n')}\n` };
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Write a verified pack for the Codex app-server this launch owns: the files
|
|
687
|
+
* as for Claude (without the Claude manifest), one role file per agent in
|
|
688
|
+
* `codex-agents/`, and the description the monitor turns into session
|
|
689
|
+
* arguments. Output styles have no Codex equivalent and stay unused, and the
|
|
690
|
+
* Claude-only files (the manager's playbook) are left out.
|
|
691
|
+
* @param {VerifiedPack} pack
|
|
692
|
+
* @param {string} launchDirectory
|
|
693
|
+
* @returns {Promise<import('./codex-engineering.mjs').CodexEngineering>}
|
|
694
|
+
*/
|
|
695
|
+
export async function materializeCodexPack(pack, launchDirectory) {
|
|
696
|
+
const base = await writePackFiles(pack, launchDirectory, isClaudeOnlyPath);
|
|
697
|
+
const skillsRoot = join(base, SKILLS_DIRECTORY);
|
|
698
|
+
await mkdir(skillsRoot, { recursive: true, mode: 0o700 });
|
|
699
|
+
const rolesDirectory = join(base, CODEX_AGENTS_DIRECTORY);
|
|
700
|
+
await mkdir(rolesDirectory, { mode: 0o700 });
|
|
701
|
+
/** @type {import('./codex-engineering.mjs').CodexAgentRole[]} */
|
|
702
|
+
const agents = [];
|
|
703
|
+
for (const file of pack.files) {
|
|
704
|
+
const role = codexRoleOf(file);
|
|
705
|
+
if (role === null) continue;
|
|
706
|
+
const configFile = join(rolesDirectory, `${role.name}.toml`);
|
|
707
|
+
await writeFile(configFile, role.toml, { mode: 0o600, flag: 'wx' });
|
|
708
|
+
agents.push({ name: role.name, description: role.description, configFile });
|
|
709
|
+
}
|
|
710
|
+
return validateCodexEngineering({ schemaVersion: 1, skillsRoot, agents });
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/** The update command when the caller has no channel to hand over (release-manifest FR6). */
|
|
714
|
+
export const DEFAULT_UPDATE_COMMAND = 'npm install -g @aisac/cli@beta';
|
|
715
|
+
|
|
556
716
|
/**
|
|
557
717
|
* One line for the launch, in the pack locale; null when the capability is
|
|
558
718
|
* not offered, so memory-only users see no change.
|
|
559
719
|
* @param {PackOutcome} outcome
|
|
560
720
|
* @param {PackLocale} locale
|
|
721
|
+
* @param {string} [updateCommand] The channel's command (release-manifest FR6).
|
|
561
722
|
* @returns {string | null}
|
|
562
723
|
*/
|
|
563
|
-
export function packNotice(outcome, locale) {
|
|
724
|
+
export function packNotice(outcome, locale, updateCommand = DEFAULT_UPDATE_COMMAND) {
|
|
564
725
|
const pt = locale === 'pt-BR';
|
|
565
726
|
const without = pt ? 'a sessão começa sem o método.' : 'the session starts without the method.';
|
|
566
727
|
switch (outcome.outcome) {
|
|
@@ -581,8 +742,8 @@ export function packNotice(outcome, locale) {
|
|
|
581
742
|
case 'rejected':
|
|
582
743
|
if (outcome.reason === 'client_outdated')
|
|
583
744
|
return pt
|
|
584
|
-
? `AISAC Engineering: atualize o aisac (
|
|
585
|
-
: `AISAC Engineering: update aisac (
|
|
745
|
+
? `AISAC Engineering: atualize o aisac (${updateCommand}); ${without}`
|
|
746
|
+
: `AISAC Engineering: update aisac (${updateCommand}); ${without}`;
|
|
586
747
|
return pt
|
|
587
748
|
? `AISAC Engineering: pacote recusado (${outcome.reason}); ${without}`
|
|
588
749
|
: `AISAC Engineering: pack rejected (${outcome.reason}); ${without}`;
|
|
@@ -594,13 +755,14 @@ export function packNotice(outcome, locale) {
|
|
|
594
755
|
/**
|
|
595
756
|
* @param {PackOutcome} outcome
|
|
596
757
|
* @param {PackLocale} locale
|
|
758
|
+
* @param {PackClient} client
|
|
597
759
|
* @returns {LastLaunch}
|
|
598
760
|
*/
|
|
599
|
-
function lastLaunchOf(outcome, locale) {
|
|
761
|
+
function lastLaunchOf(outcome, locale, client) {
|
|
600
762
|
return {
|
|
601
763
|
schemaVersion: 1,
|
|
602
764
|
at: new Date().toISOString(),
|
|
603
|
-
client
|
|
765
|
+
client,
|
|
604
766
|
state: outcome.outcome,
|
|
605
767
|
reason:
|
|
606
768
|
outcome.outcome === 'unavailable' || outcome.outcome === 'rejected' ? outcome.reason : null,
|
|
@@ -610,13 +772,17 @@ function lastLaunchOf(outcome, locale) {
|
|
|
610
772
|
}
|
|
611
773
|
|
|
612
774
|
/**
|
|
613
|
-
* Fetch, verify and write the pack for one Claude Code launch. Never
|
|
775
|
+
* Fetch, verify and write the pack for one Claude Code or Codex launch. Never
|
|
776
|
+
* throws. `hostSupported: false` (a Codex release older than the verified
|
|
777
|
+
* mechanism) still checks the license but loads nothing.
|
|
614
778
|
* @param {{ endpoint: string, token: string, root: string, directory: string,
|
|
615
|
-
* packageRoot: string,
|
|
616
|
-
* timeoutMs?: number }} input
|
|
617
|
-
* @returns {Promise<{ pluginRoot: string | null,
|
|
779
|
+
* packageRoot: string, client?: PackClient, hostSupported?: boolean, updateCommand?: string,
|
|
780
|
+
* env?: NodeJS.ProcessEnv, fetchImpl?: typeof fetch, timeoutMs?: number }} input
|
|
781
|
+
* @returns {Promise<{ pluginRoot: string | null,
|
|
782
|
+
* codex: import('./codex-engineering.mjs').CodexEngineering | null, line: string | null }>}
|
|
618
783
|
*/
|
|
619
784
|
export async function prepareEngineeringPack(input) {
|
|
785
|
+
const client = input.client ?? 'claude';
|
|
620
786
|
const locale = resolvePackLocale(await readStoredLocale(input.root), input.env);
|
|
621
787
|
/** @type {PackOutcome} */
|
|
622
788
|
let outcome;
|
|
@@ -632,28 +798,42 @@ export async function prepareEngineeringPack(input) {
|
|
|
632
798
|
} catch {
|
|
633
799
|
outcome = { outcome: 'unavailable', reason: 'client_error' };
|
|
634
800
|
}
|
|
801
|
+
if (outcome.outcome === 'loaded' && input.hostSupported === false)
|
|
802
|
+
outcome = { outcome: 'unavailable', reason: `${client}_outdated` };
|
|
635
803
|
let pluginRoot = null;
|
|
804
|
+
/** @type {import('./codex-engineering.mjs').CodexEngineering | null} */
|
|
805
|
+
let codex = null;
|
|
636
806
|
if (outcome.outcome === 'loaded') {
|
|
637
807
|
try {
|
|
638
|
-
|
|
808
|
+
if (client === 'codex') codex = await materializeCodexPack(outcome.pack, input.directory);
|
|
809
|
+
else pluginRoot = await materializePack(outcome.pack, input.directory);
|
|
639
810
|
} catch {
|
|
811
|
+
codex = null;
|
|
640
812
|
await rm(join(input.directory, PACK_DIRECTORY), { recursive: true, force: true }).catch(
|
|
641
813
|
() => undefined,
|
|
642
814
|
);
|
|
643
815
|
outcome = { outcome: 'rejected', reason: 'materialize_failed' };
|
|
644
816
|
}
|
|
645
817
|
}
|
|
646
|
-
await atomicJson(join(input.root, LAST_LAUNCH_FILE), lastLaunchOf(outcome, locale)).catch(
|
|
818
|
+
await atomicJson(join(input.root, LAST_LAUNCH_FILE), lastLaunchOf(outcome, locale, client)).catch(
|
|
647
819
|
() => undefined,
|
|
648
820
|
);
|
|
649
|
-
return { pluginRoot, line: packNotice(outcome, locale) };
|
|
821
|
+
return { pluginRoot, codex, line: packNotice(outcome, locale, input.updateCommand) };
|
|
650
822
|
}
|
|
651
823
|
|
|
824
|
+
/**
|
|
825
|
+
* The host a launch runs, as its marker records it (release-manifest FR5): the
|
|
826
|
+
* managed-host garbage collection never removes a version a live marker names.
|
|
827
|
+
* @typedef {{ name: 'claude' | 'codex', mode: 'system' | 'managed' | 'pending', version: string | null }} LaunchHost
|
|
828
|
+
* `pending`: the launch has not resolved its host yet (release-manifest FR5); collectors
|
|
829
|
+
* skip while one is live, so the version it is about to run is never removed.
|
|
830
|
+
*/
|
|
831
|
+
|
|
652
832
|
/**
|
|
653
833
|
* Record who owns a launch directory, so a later launch can sweep it once
|
|
654
|
-
* both processes are gone (spec FR4 step 7).
|
|
834
|
+
* both processes are gone (spec FR4 step 7), and which host it runs.
|
|
655
835
|
* @param {string} directory
|
|
656
|
-
* @param {{ launcherPid: number, childPid: number | null }} owners
|
|
836
|
+
* @param {{ launcherPid: number, childPid: number | null, host?: LaunchHost }} owners
|
|
657
837
|
*/
|
|
658
838
|
export async function writeLaunchMarker(directory, owners) {
|
|
659
839
|
const path = join(directory, LAUNCH_MARKER_FILE);
|
|
@@ -720,3 +900,76 @@ export async function sweepStaleLaunches(root, alive = processAlive) {
|
|
|
720
900
|
}
|
|
721
901
|
return removed;
|
|
722
902
|
}
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* Launches still running after the stale sweep: directories whose marker names
|
|
906
|
+
* a live launcher or child. The client never updates itself under one
|
|
907
|
+
* (release-manifest FR6). Never throws.
|
|
908
|
+
* @param {string} root
|
|
909
|
+
* @param {(pid: number) => boolean} [alive]
|
|
910
|
+
* @returns {Promise<number>}
|
|
911
|
+
*/
|
|
912
|
+
export async function liveLaunchCount(root, alive = processAlive) {
|
|
913
|
+
await sweepStaleLaunches(root, alive);
|
|
914
|
+
const runtime = join(root, 'runtime');
|
|
915
|
+
let entries;
|
|
916
|
+
try {
|
|
917
|
+
entries = await readdir(runtime, { withFileTypes: true });
|
|
918
|
+
} catch {
|
|
919
|
+
return 0;
|
|
920
|
+
}
|
|
921
|
+
let live = 0;
|
|
922
|
+
for (const entry of entries) {
|
|
923
|
+
if (!entry.isDirectory() || !LAUNCH_DIRECTORY.test(entry.name)) continue;
|
|
924
|
+
const marker = await readSmallStateJson(join(runtime, entry.name, LAUNCH_MARKER_FILE));
|
|
925
|
+
if (!isRecord(marker) || marker.schemaVersion !== 1 || !isPid(marker.launcherPid)) continue;
|
|
926
|
+
const childPid = isPid(marker.childPid) ? /** @type {number} */ (marker.childPid) : null;
|
|
927
|
+
if (alive(/** @type {number} */ (marker.launcherPid)) || (childPid !== null && alive(childPid)))
|
|
928
|
+
live += 1;
|
|
929
|
+
}
|
|
930
|
+
return live;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** @param {unknown} value @returns {LaunchHost | null} */
|
|
934
|
+
function launchHostOf(value) {
|
|
935
|
+
if (!isRecord(value)) return null;
|
|
936
|
+
const { name, mode, version } = value;
|
|
937
|
+
if (name !== 'claude' && name !== 'codex') return null;
|
|
938
|
+
if (mode !== 'system' && mode !== 'managed' && mode !== 'pending') return null;
|
|
939
|
+
if (version !== null && (typeof version !== 'string' || version.length > 64)) return null;
|
|
940
|
+
return { name, mode, version: /** @type {string | null} */ (version) };
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* The hosts of the launches still running (release-manifest FR5): a managed
|
|
945
|
+
* host version one of them names is never garbage-collected. Never throws.
|
|
946
|
+
* @param {string} root
|
|
947
|
+
* @param {(pid: number) => boolean} [alive]
|
|
948
|
+
* @returns {Promise<LaunchHost[]>}
|
|
949
|
+
*/
|
|
950
|
+
export async function liveLaunchHosts(root, alive = processAlive) {
|
|
951
|
+
await sweepStaleLaunches(root, alive);
|
|
952
|
+
const runtime = join(root, 'runtime');
|
|
953
|
+
let entries;
|
|
954
|
+
try {
|
|
955
|
+
entries = await readdir(runtime, { withFileTypes: true });
|
|
956
|
+
} catch {
|
|
957
|
+
return [];
|
|
958
|
+
}
|
|
959
|
+
/** @type {LaunchHost[]} */
|
|
960
|
+
const hosts = [];
|
|
961
|
+
for (const entry of entries) {
|
|
962
|
+
if (!entry.isDirectory() || !LAUNCH_DIRECTORY.test(entry.name)) continue;
|
|
963
|
+
const marker = await readSmallStateJson(join(runtime, entry.name, LAUNCH_MARKER_FILE));
|
|
964
|
+
if (!isRecord(marker) || marker.schemaVersion !== 1 || !isPid(marker.launcherPid)) continue;
|
|
965
|
+
const childPid = isPid(marker.childPid) ? /** @type {number} */ (marker.childPid) : null;
|
|
966
|
+
if (
|
|
967
|
+
!alive(/** @type {number} */ (marker.launcherPid)) &&
|
|
968
|
+
(childPid === null || !alive(childPid))
|
|
969
|
+
)
|
|
970
|
+
continue;
|
|
971
|
+
const host = launchHostOf(marker.host);
|
|
972
|
+
if (host !== null) hosts.push(host);
|
|
973
|
+
}
|
|
974
|
+
return hosts;
|
|
975
|
+
}
|
|
@@ -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
|
+
}
|