@aisac/cli 0.4.0-beta.1 → 0.4.0-beta.11
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 +50 -6
- package/dist/assets/claude/hooks/context-compaction.ts +5 -1
- package/dist/assets/codex-context-compaction.mjs +243 -5
- package/dist/assets/jev-paid-pilot-terminal.mjs +6 -0
- package/dist/claude-observation.mjs +1 -1
- package/dist/cli.mjs +91 -5
- package/dist/codex-compatibility.mjs +52 -2
- package/dist/codex-engineering.mjs +165 -0
- package/dist/codex-protocol-fingerprint.json +10 -10
- package/dist/engineering-pack-public-key.json +10 -0
- package/dist/engineering-pack.mjs +845 -0
- package/dist/engineering.mjs +15 -11
- package/dist/extensions-catalog.mjs +310 -0
- package/dist/extensions-cli.mjs +486 -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 +397 -0
- package/dist/guardrails/run.mjs +211 -0
- package/dist/guardrails/shell-words.mjs +206 -0
- package/dist/guardrails-plugin.mjs +149 -0
- package/dist/launch.mjs +143 -8
- package/dist/mcp-servers.mjs +192 -0
- package/dist/monitor.mjs +33 -0
- package/dist/package.json +1 -1
- package/dist/platform.mjs +50 -10
- package/dist/token-guide.mjs +105 -0
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -25,12 +25,23 @@ import { launchClaude, launchCodex } from './launch.mjs';
|
|
|
25
25
|
import { claudeCompatibilityError, resolveClaudeCompatibility } from './claude-compatibility.mjs';
|
|
26
26
|
import { codexCompatibilityError, resolveCodexCompatibility } from './codex-compatibility.mjs';
|
|
27
27
|
import { providerFreeProbe } from './mcp.mjs';
|
|
28
|
+
import { tokenFailureGuide, tokenPromptGuide } from './token-guide.mjs';
|
|
28
29
|
import { codexPolicyJson, makePolicy, publicPolicy, isProfile } from './policy.mjs';
|
|
29
30
|
import { readDiagnostics } from './claude-observation.mjs';
|
|
30
31
|
import { readCodexDiagnostics } from './codex-diagnostics.mjs';
|
|
31
32
|
import { checkEngineeringLicense, licenseLine, unavailableLicense } from './engineering.mjs';
|
|
33
|
+
import {
|
|
34
|
+
isPackLocale,
|
|
35
|
+
readLastLaunch,
|
|
36
|
+
readStoredLocale,
|
|
37
|
+
resolvePackLocale,
|
|
38
|
+
writeStoredLocale,
|
|
39
|
+
} from './engineering-pack.mjs';
|
|
40
|
+
import { extensionsSummary, hooksCommand, mcpCommand } from './extensions-cli.mjs';
|
|
41
|
+
import { sessionServers } from './mcp-servers.mjs';
|
|
42
|
+
import { anyFormatter } from './guardrails/format.mjs';
|
|
32
43
|
|
|
33
|
-
const VERSION = '0.4.0-beta.
|
|
44
|
+
const VERSION = '0.4.0-beta.11';
|
|
34
45
|
// The command is `aisac`; `aibrain` is an alias installed from the same entry.
|
|
35
46
|
const COMMAND = 'aisac';
|
|
36
47
|
const ENDPOINT = 'https://mcp.ai-brain.aisac.cloud/mcp';
|
|
@@ -48,7 +59,13 @@ function usage() {
|
|
|
48
59
|
'Claude shadow: setup --claude-shadow on|off and --claude-diagnostics on|off (preview stays applied=false).',
|
|
49
60
|
);
|
|
50
61
|
console.log(
|
|
51
|
-
'AISAC Engineering: setup and doctor report the license; status stays offline. `aibrain` is an alias of `aisac`.',
|
|
62
|
+
'AISAC Engineering: `aisac claude` and `aisac codex` (Codex 0.164+) load the licensed method; setup --lang pt-BR|en picks its language; setup and doctor report the license; status stays offline. `aibrain` is an alias of `aisac`.',
|
|
63
|
+
);
|
|
64
|
+
console.log(
|
|
65
|
+
'Guardrails: `aisac hooks` lists them (a checklist on a terminal); `aisac hooks enable|disable <id>...` and `aisac hooks reset` change the next `aisac claude` session.',
|
|
66
|
+
);
|
|
67
|
+
console.log(
|
|
68
|
+
'MCP catalog: `aisac mcp` lists the reviewed servers (GitHub, Supabase, Vercel, Playwright, Context7); `aisac mcp enable|disable <id>...`, `aisac mcp reset`, `aisac mcp info <id>` and `aisac mcp login <id>` (Codex) change or explain the next session.',
|
|
52
69
|
);
|
|
53
70
|
}
|
|
54
71
|
|
|
@@ -99,6 +116,18 @@ async function maskedPrompt() {
|
|
|
99
116
|
}
|
|
100
117
|
}
|
|
101
118
|
|
|
119
|
+
/**
|
|
120
|
+
* A setup error that carries the PAT step-by-step guide when the failure means
|
|
121
|
+
* the subscriber needs a (different) token.
|
|
122
|
+
* @param {string} code @param {'pt-BR' | 'en'} locale @param {string} endpoint
|
|
123
|
+
*/
|
|
124
|
+
function setupTokenError(code, locale, endpoint) {
|
|
125
|
+
const error = new Error(code);
|
|
126
|
+
const guide = tokenFailureGuide(code, locale, endpoint);
|
|
127
|
+
if (guide !== null) Object.defineProperty(error, 'guide', { value: guide });
|
|
128
|
+
return error;
|
|
129
|
+
}
|
|
130
|
+
|
|
102
131
|
/** @param {string[]} args @param {string} name */
|
|
103
132
|
function option(args, name) {
|
|
104
133
|
const index = args.indexOf(name);
|
|
@@ -310,6 +339,26 @@ async function updateLocalOptOut(previous, args) {
|
|
|
310
339
|
return true;
|
|
311
340
|
}
|
|
312
341
|
|
|
342
|
+
/** Store the AISAC Engineering pack language; local only, no network call. @param {'pt-BR' | 'en'} locale */
|
|
343
|
+
async function setPackLocale(locale) {
|
|
344
|
+
const root = await ensureStateRoot();
|
|
345
|
+
await writeStoredLocale(root, locale);
|
|
346
|
+
console.log(
|
|
347
|
+
`AISAC Engineering pack language set to ${locale} for future launches; no network call was made.`,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Offline view of the pack language and the last launch (status, doctor). */
|
|
352
|
+
async function engineeringPackState() {
|
|
353
|
+
const root = stateRoot();
|
|
354
|
+
const stored = await readStoredLocale(root);
|
|
355
|
+
return {
|
|
356
|
+
locale: resolvePackLocale(stored),
|
|
357
|
+
localeSource: stored === null ? 'system' : 'setup',
|
|
358
|
+
lastLaunch: await readLastLaunch(root),
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
313
362
|
/** @param {string} endpoint */
|
|
314
363
|
function validateEndpoint(endpoint) {
|
|
315
364
|
if (endpoint.length > 2048) throw new Error('endpoint_too_long');
|
|
@@ -385,6 +434,7 @@ async function setup(args) {
|
|
|
385
434
|
'--telemetry',
|
|
386
435
|
'--claude-shadow',
|
|
387
436
|
'--claude-diagnostics',
|
|
437
|
+
'--lang',
|
|
388
438
|
]),
|
|
389
439
|
new Set([
|
|
390
440
|
'--client',
|
|
@@ -396,10 +446,14 @@ async function setup(args) {
|
|
|
396
446
|
'--telemetry',
|
|
397
447
|
'--claude-shadow',
|
|
398
448
|
'--claude-diagnostics',
|
|
449
|
+
'--lang',
|
|
399
450
|
]),
|
|
400
451
|
);
|
|
401
452
|
if (args.includes('--undo') && args.length !== 1)
|
|
402
453
|
throw new Error('setup_undo_cannot_have_options');
|
|
454
|
+
const lang = option(args, '--lang');
|
|
455
|
+
if (lang !== undefined && !isPackLocale(lang)) throw new Error('invalid_lang');
|
|
456
|
+
if (lang !== undefined && args.length === 2) return setPackLocale(lang);
|
|
403
457
|
const previous = await readConfig();
|
|
404
458
|
if (await updateLocalOptOut(previous, args)) return;
|
|
405
459
|
const localOptOut =
|
|
@@ -440,10 +494,18 @@ async function setup(args) {
|
|
|
440
494
|
)
|
|
441
495
|
throw new Error('disclosure_not_accepted');
|
|
442
496
|
const root = await ensureStateRoot();
|
|
497
|
+
const locale = resolvePackLocale(lang ?? (await readStoredLocale(root)));
|
|
443
498
|
const tokenPath = option(args, '--token-file');
|
|
444
|
-
|
|
499
|
+
if (!tokenPath && stdin.isTTY && stdout.isTTY)
|
|
500
|
+
console.log(`\n${tokenPromptGuide(locale, endpoint)}\n`);
|
|
501
|
+
let token;
|
|
502
|
+
try {
|
|
503
|
+
token = tokenPath ? await readPrivateToken(tokenPath) : await maskedPrompt();
|
|
504
|
+
} catch (error) {
|
|
505
|
+
throw setupTokenError(errorMessage(error), locale, endpoint);
|
|
506
|
+
}
|
|
445
507
|
token = token.trim();
|
|
446
|
-
if (!token) throw
|
|
508
|
+
if (!token) throw setupTokenError('empty_token', locale, endpoint);
|
|
447
509
|
const claude = resolveNative('claude');
|
|
448
510
|
const codex = resolveNative('codex');
|
|
449
511
|
const node = resolveNative('node');
|
|
@@ -489,7 +551,7 @@ async function setup(args) {
|
|
|
489
551
|
? await providerFreeProbe(endpoint, token, policy, clients)
|
|
490
552
|
: await providerFreeProbe(endpoint, token);
|
|
491
553
|
} catch (error) {
|
|
492
|
-
throw
|
|
554
|
+
throw setupTokenError(`provider_free_probe_failed:${errorMessage(error)}`, locale, endpoint);
|
|
493
555
|
}
|
|
494
556
|
try {
|
|
495
557
|
const configWithToken = { ...config, token, tokenSha256: await tokenDigest(token), probe };
|
|
@@ -501,11 +563,27 @@ async function setup(args) {
|
|
|
501
563
|
console.log(
|
|
502
564
|
`Configured ${clients} in ${root}. Provider-free access verified; no provider batch was used.`,
|
|
503
565
|
);
|
|
566
|
+
if (lang !== undefined) await setPackLocale(lang);
|
|
504
567
|
// Display only: the server decides again on every pack request (ADR-0047).
|
|
505
568
|
const line = licenseLine(await checkEngineeringLicense(endpoint, token));
|
|
506
569
|
if (line !== null) console.log(line);
|
|
507
570
|
}
|
|
508
571
|
|
|
572
|
+
/** Extension state plus whether `format-on-edit` has a formatter in this folder (FR8). */
|
|
573
|
+
async function doctorExtensions() {
|
|
574
|
+
const summary = await extensionsSummary(stateRoot());
|
|
575
|
+
// A token server is skipped at launch when its variable is unset (names only).
|
|
576
|
+
const mcpMissingEnv = sessionServers(summary.mcp, 'claude', process.env).missingEnv.map(
|
|
577
|
+
(skipped) => skipped.id,
|
|
578
|
+
);
|
|
579
|
+
const formatOnEdit = !summary.hooks.includes('format-on-edit')
|
|
580
|
+
? 'off'
|
|
581
|
+
: (await anyFormatter(process.cwd()))
|
|
582
|
+
? 'ready'
|
|
583
|
+
: 'no_formatter_found';
|
|
584
|
+
return { ...summary, formatOnEdit, mcpMissingEnv };
|
|
585
|
+
}
|
|
586
|
+
|
|
509
587
|
/** @param {boolean} json */
|
|
510
588
|
async function doctor(json) {
|
|
511
589
|
const platform = platformCheck();
|
|
@@ -599,6 +677,8 @@ async function doctor(json) {
|
|
|
599
677
|
config?.claudeObservation?.disclosedAt !== undefined,
|
|
600
678
|
},
|
|
601
679
|
engineering,
|
|
680
|
+
engineeringPack: await engineeringPackState(),
|
|
681
|
+
extensions: await doctorExtensions(),
|
|
602
682
|
paidOrPilot: probe?.ok
|
|
603
683
|
? 'provider_free_probe_ok; paid entitlement or pilot invitation remains server-enforced'
|
|
604
684
|
: config
|
|
@@ -634,6 +714,8 @@ async function status(json) {
|
|
|
634
714
|
config?.claudeObservation?.disclosedAt !== null &&
|
|
635
715
|
config?.claudeObservation?.disclosedAt !== undefined,
|
|
636
716
|
},
|
|
717
|
+
engineeringPack: await engineeringPackState(),
|
|
718
|
+
extensions: await extensionsSummary(stateRoot()),
|
|
637
719
|
monitoredSession: null,
|
|
638
720
|
monitoringStatus: 'not_observed',
|
|
639
721
|
};
|
|
@@ -682,6 +764,8 @@ async function main(argv) {
|
|
|
682
764
|
else console.log(records);
|
|
683
765
|
return;
|
|
684
766
|
}
|
|
767
|
+
if (command === 'hooks') return hooksCommand(rest);
|
|
768
|
+
if (command === 'mcp') return mcpCommand(rest);
|
|
685
769
|
if (command === 'disable') {
|
|
686
770
|
if (rest.length > 0) throw new Error('disable_does_not_accept_options');
|
|
687
771
|
return removeOwnedSetup();
|
|
@@ -731,6 +815,8 @@ main(cliArgs).catch((error) => {
|
|
|
731
815
|
);
|
|
732
816
|
} else {
|
|
733
817
|
console.error(`${COMMAND}: ${errorMessage(error)}`);
|
|
818
|
+
const guide = /** @type {{ guide?: unknown }} */ (error ?? {}).guide;
|
|
819
|
+
if (typeof guide === 'string') console.error(`\n${guide}`);
|
|
734
820
|
}
|
|
735
821
|
process.exitCode = 1;
|
|
736
822
|
});
|
|
@@ -26,7 +26,14 @@ const PAGINATION_CONTRACT_VALID =
|
|
|
26
26
|
fingerprint.roots[PAGINATION_CONTRACT.response_schema]?.sha256 &&
|
|
27
27
|
typeof PAGINATION_CONTRACT.graph_sha256 === 'string' &&
|
|
28
28
|
PAGINATION_CONTRACT.graph_sha256.length === 64);
|
|
29
|
-
const QUALIFIED_VERSIONS = new Set([
|
|
29
|
+
const QUALIFIED_VERSIONS = new Set([
|
|
30
|
+
'0.161.0',
|
|
31
|
+
'0.162.0',
|
|
32
|
+
'0.162.1',
|
|
33
|
+
'0.163.0',
|
|
34
|
+
'0.164.0',
|
|
35
|
+
'0.166.0',
|
|
36
|
+
]);
|
|
30
37
|
const ANNOTATIONS = new Set([
|
|
31
38
|
'$comment',
|
|
32
39
|
'title',
|
|
@@ -475,7 +482,50 @@ export async function resolveCodexCompatibility(executable, baseEnvironment = pr
|
|
|
475
482
|
}
|
|
476
483
|
}
|
|
477
484
|
|
|
485
|
+
/** @param {string} left @param {string} right */
|
|
486
|
+
function compareStableVersions(left, right) {
|
|
487
|
+
const a = left.split('.').map(Number);
|
|
488
|
+
const b = right.split('.').map(Number);
|
|
489
|
+
for (let index = 0; index < 3; index += 1) {
|
|
490
|
+
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
491
|
+
if (difference !== 0) return difference;
|
|
492
|
+
}
|
|
493
|
+
return 0;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** The newest Codex release this client was qualified against. */
|
|
497
|
+
export const LATEST_QUALIFIED_CODEX = /** @type {string} */ (
|
|
498
|
+
[...QUALIFIED_VERSIONS].sort(compareStableVersions).at(-1)
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
// Rejections a user fixes by installing a qualified Codex (or a newer aisac):
|
|
502
|
+
// the installed release's contract or transport differs from the bundled one.
|
|
503
|
+
const CONTRACT_REJECTIONS = new Set([
|
|
504
|
+
'protocol_schema_mismatch',
|
|
505
|
+
'protocol_method_missing',
|
|
506
|
+
'schema_root_missing_or_invalid',
|
|
507
|
+
'schema_set_too_large',
|
|
508
|
+
'schema_generation_failed',
|
|
509
|
+
'transport_flags_missing',
|
|
510
|
+
'protocol_probe_failed',
|
|
511
|
+
]);
|
|
512
|
+
|
|
513
|
+
/** @param {{reason:string, version:string|null}} decision @returns {string|null} */
|
|
514
|
+
export function codexCompatibilityRemedy(decision) {
|
|
515
|
+
const detected = decision.version === null ? 'The installed Codex' : `Codex ${decision.version}`;
|
|
516
|
+
const reinstall = `npm install -g @openai/codex@${LATEST_QUALIFIED_CODEX}`;
|
|
517
|
+
if (CONTRACT_REJECTIONS.has(decision.reason))
|
|
518
|
+
return `${detected} is not qualified by this aisac (newest qualified: ${LATEST_QUALIFIED_CODEX}). Install the qualified Codex with \`${reinstall}\`, or check for an aisac release that qualifies it with \`npm install -g @aisac/cli@beta\`.`;
|
|
519
|
+
if (decision.reason === 'version_unqualified')
|
|
520
|
+
return `${detected} is older than this aisac supports. Update it with \`${reinstall}\`.`;
|
|
521
|
+
if (decision.reason === 'version_not_stable_0x')
|
|
522
|
+
return `${detected} is not a stable 0.x release. Install a qualified one with \`${reinstall}\`.`;
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
|
|
478
526
|
/** @param {{reason:string, version:string|null}} decision @returns {string} */
|
|
479
527
|
export function codexCompatibilityError(decision) {
|
|
480
|
-
|
|
528
|
+
const coded = `codex_protocol_incompatible:${decision.reason}:detected=${decision.version ?? 'unavailable'};run aisac doctor --json`;
|
|
529
|
+
const remedy = codexCompatibilityRemedy(decision);
|
|
530
|
+
return remedy === null ? coded : `${coded}\n${remedy}`;
|
|
481
531
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AISAC Engineering for Codex (ADR-0047 wave E4c, spec FR4).
|
|
5
|
+
*
|
|
6
|
+
* Codex has no session plugin directory, so the method reaches only the
|
|
7
|
+
* app-server this launch owns, and nothing is written to `~/.codex`,
|
|
8
|
+
* `~/.agents` or the project:
|
|
9
|
+
* - skills: the adapter sends `skills/extraRoots/set` with the pack's
|
|
10
|
+
* `skills/` directory right after the client's initialize (in-memory in that
|
|
11
|
+
* process);
|
|
12
|
+
* - agents: one role file per pack agent, declared with `-c agents.<name>.*`
|
|
13
|
+
* overrides on the owned app-server (the session-flags config layer).
|
|
14
|
+
* The launcher hands the monitor one JSON value; the monitor validates it
|
|
15
|
+
* again before turning it into arguments.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
19
|
+
|
|
20
|
+
export const CODEX_ENGINEERING_ENV = 'AISAC_ENGINEERING_CODEX';
|
|
21
|
+
export const CODEX_ENGINEERING_SKILLS_ROOT_ENV = 'AISAC_ENGINEERING_SKILLS_ROOT';
|
|
22
|
+
export const CODEX_AGENTS_DIRECTORY = 'codex-agents';
|
|
23
|
+
const SKILLS_DIRECTORY = 'skills';
|
|
24
|
+
const PACK_DIRECTORY = 'engineering';
|
|
25
|
+
const RUNTIME_DIRECTORY = 'runtime';
|
|
26
|
+
const CODEX_LAUNCH_DIRECTORY = /^codex-[A-Za-z0-9]{6}$/u;
|
|
27
|
+
const SCHEMA_VERSION = 1;
|
|
28
|
+
const MAX_SPEC_BYTES = 16 * 1024;
|
|
29
|
+
const MAX_AGENTS = 16;
|
|
30
|
+
const MAX_PATH_LENGTH = 4096;
|
|
31
|
+
export const MAX_AGENT_DESCRIPTION_LENGTH = 1024;
|
|
32
|
+
export const AGENT_NAME = /^[a-z][a-z0-9-]{0,63}$/u;
|
|
33
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/u;
|
|
34
|
+
/** First Codex release whose session mechanism was verified (spike Q4, 2026-11-03). */
|
|
35
|
+
const MIN_CODEX_VERSION = /** @type {const} */ ([0, 164, 0]);
|
|
36
|
+
|
|
37
|
+
/** @typedef {{ name: string, description: string, configFile: string }} CodexAgentRole */
|
|
38
|
+
/** @typedef {{ schemaVersion: 1, skillsRoot: string, agents: CodexAgentRole[] }} CodexEngineering */
|
|
39
|
+
|
|
40
|
+
/** @param {string} code @returns {never} */
|
|
41
|
+
function fail(code) {
|
|
42
|
+
throw new Error(`codex_engineering_${code}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @param {unknown} value @returns {value is Record<string, unknown>} */
|
|
46
|
+
function isRecord(value) {
|
|
47
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Whether this Codex version receives the pack. A null or malformed version
|
|
52
|
+
* never does.
|
|
53
|
+
* @param {string | null | undefined} version
|
|
54
|
+
*/
|
|
55
|
+
export function supportsCodexEngineering(version) {
|
|
56
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/u.exec(version ?? '');
|
|
57
|
+
if (match === null) return false;
|
|
58
|
+
const parts = match.slice(1).map(Number);
|
|
59
|
+
for (let index = 0; index < MIN_CODEX_VERSION.length; index += 1) {
|
|
60
|
+
const part = /** @type {number} */ (parts[index]);
|
|
61
|
+
const minimum = MIN_CODEX_VERSION[index] ?? 0;
|
|
62
|
+
if (part !== minimum) return part > minimum;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {unknown} value */
|
|
68
|
+
function isCleanAbsolutePath(value) {
|
|
69
|
+
return (
|
|
70
|
+
typeof value === 'string' &&
|
|
71
|
+
value.length > 0 &&
|
|
72
|
+
value.length <= MAX_PATH_LENGTH &&
|
|
73
|
+
!CONTROL_CHARACTERS.test(value) &&
|
|
74
|
+
value.startsWith('/') &&
|
|
75
|
+
resolve(value) === value
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {unknown} value
|
|
81
|
+
* @param {{ stateDir?: string }} [options] when given, the pack must sit in a
|
|
82
|
+
* Codex launch directory of that state directory
|
|
83
|
+
* @returns {CodexEngineering}
|
|
84
|
+
*/
|
|
85
|
+
export function validateCodexEngineering(value, options = {}) {
|
|
86
|
+
if (!isRecord(value)) fail('invalid');
|
|
87
|
+
const keys = Object.keys(value).sort().join(',');
|
|
88
|
+
if (keys !== 'agents,schemaVersion,skillsRoot') fail('invalid');
|
|
89
|
+
if (value.schemaVersion !== SCHEMA_VERSION) fail('schema');
|
|
90
|
+
const skillsRoot = value.skillsRoot;
|
|
91
|
+
if (!isCleanAbsolutePath(skillsRoot)) fail('path');
|
|
92
|
+
const skills = /** @type {string} */ (skillsRoot);
|
|
93
|
+
if (basename(skills) !== SKILLS_DIRECTORY) fail('path');
|
|
94
|
+
const base = dirname(skills);
|
|
95
|
+
if (basename(base) !== PACK_DIRECTORY) fail('path');
|
|
96
|
+
if (options.stateDir !== undefined) {
|
|
97
|
+
const launch = dirname(base);
|
|
98
|
+
if (
|
|
99
|
+
!CODEX_LAUNCH_DIRECTORY.test(basename(launch)) ||
|
|
100
|
+
dirname(launch) !== join(resolve(options.stateDir), RUNTIME_DIRECTORY)
|
|
101
|
+
)
|
|
102
|
+
fail('path');
|
|
103
|
+
}
|
|
104
|
+
if (!Array.isArray(value.agents) || value.agents.length > MAX_AGENTS) fail('agents');
|
|
105
|
+
const seen = new Set();
|
|
106
|
+
/** @type {CodexAgentRole[]} */
|
|
107
|
+
const agents = [];
|
|
108
|
+
for (const agent of value.agents) {
|
|
109
|
+
if (!isRecord(agent) || Object.keys(agent).sort().join(',') !== 'configFile,description,name')
|
|
110
|
+
fail('agents');
|
|
111
|
+
const { name, description, configFile } = agent;
|
|
112
|
+
if (typeof name !== 'string' || !AGENT_NAME.test(name) || seen.has(name)) fail('agents');
|
|
113
|
+
if (
|
|
114
|
+
typeof description !== 'string' ||
|
|
115
|
+
description.trim().length === 0 ||
|
|
116
|
+
description.length > MAX_AGENT_DESCRIPTION_LENGTH ||
|
|
117
|
+
CONTROL_CHARACTERS.test(description)
|
|
118
|
+
)
|
|
119
|
+
fail('agents');
|
|
120
|
+
if (configFile !== join(base, CODEX_AGENTS_DIRECTORY, `${name}.toml`)) fail('agents');
|
|
121
|
+
seen.add(name);
|
|
122
|
+
agents.push({ name, description, configFile });
|
|
123
|
+
}
|
|
124
|
+
return { schemaVersion: SCHEMA_VERSION, skillsRoot: skills, agents };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Parse the monitor's environment value; null when absent.
|
|
129
|
+
* @param {string | undefined} raw
|
|
130
|
+
* @param {{ stateDir?: string }} [options]
|
|
131
|
+
* @returns {CodexEngineering | null}
|
|
132
|
+
*/
|
|
133
|
+
export function parseCodexEngineering(raw, options = {}) {
|
|
134
|
+
if (raw === undefined || raw === '') return null;
|
|
135
|
+
if (Buffer.byteLength(raw, 'utf8') > MAX_SPEC_BYTES) fail('too_large');
|
|
136
|
+
let value;
|
|
137
|
+
try {
|
|
138
|
+
value = JSON.parse(raw);
|
|
139
|
+
} catch {
|
|
140
|
+
fail('invalid');
|
|
141
|
+
}
|
|
142
|
+
return validateCodexEngineering(value, options);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* A TOML basic string. JSON escapes are TOML escapes; DEL is escaped too.
|
|
147
|
+
* @param {string} value
|
|
148
|
+
*/
|
|
149
|
+
export function tomlBasicString(value) {
|
|
150
|
+
return JSON.stringify(value).replace(/\u007f/gu, '\\u007F');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Session-only `-c` overrides for the owned app-server, one role per agent.
|
|
155
|
+
* @param {CodexEngineering} engineering
|
|
156
|
+
* @returns {string[]}
|
|
157
|
+
*/
|
|
158
|
+
export function codexEngineeringConfigArgs(engineering) {
|
|
159
|
+
return engineering.agents.flatMap((agent) => [
|
|
160
|
+
'-c',
|
|
161
|
+
`agents.${agent.name}.description=${tomlBasicString(agent.description)}`,
|
|
162
|
+
'-c',
|
|
163
|
+
`agents.${agent.name}.config_file=${tomlBasicString(agent.configFile)}`,
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"native": "0.
|
|
3
|
+
"native": "0.166.0",
|
|
4
4
|
"consumed_pagination": {
|
|
5
5
|
"method": "thread/turns/list",
|
|
6
6
|
"request_schema": "v2/ThreadTurnsListParams.json",
|
|
7
7
|
"response_schema": "v2/ThreadTurnsListResponse.json",
|
|
8
8
|
"request_schema_sha256": "29717980579b77eb4c7cbd1118dd238fcb3e010f3ef5236d74bd4e4f6e02c005",
|
|
9
|
-
"response_schema_sha256": "
|
|
10
|
-
"graph_sha256": "
|
|
9
|
+
"response_schema_sha256": "53d96dae44edcecee02d8dcce5645800a52a62444f288ff48376e99e506561c6",
|
|
10
|
+
"graph_sha256": "a9008170cbf190054a75f4a539db7fe271e30cf85a157ad27e2dc2192785f311",
|
|
11
11
|
"ordering": "asc",
|
|
12
12
|
"items_view": "full"
|
|
13
13
|
},
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"v2/ThreadTurnsListResponse.json": {
|
|
20
20
|
"methods": null,
|
|
21
|
-
"sha256": "
|
|
21
|
+
"sha256": "53d96dae44edcecee02d8dcce5645800a52a62444f288ff48376e99e506561c6"
|
|
22
22
|
},
|
|
23
23
|
"ClientRequest.json": {
|
|
24
24
|
"methods": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"config/read",
|
|
40
40
|
"account/read"
|
|
41
41
|
],
|
|
42
|
-
"sha256": "
|
|
42
|
+
"sha256": "950bcefcb938bdf04b84305fdcf6767b05db782a0853ef1356fe05d607b0f5b3"
|
|
43
43
|
},
|
|
44
44
|
"ClientNotification.json": {
|
|
45
45
|
"methods": ["initialized"],
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"thread/compacted",
|
|
79
79
|
"warning"
|
|
80
80
|
],
|
|
81
|
-
"sha256": "
|
|
81
|
+
"sha256": "7f739a3a39a248692147f1a5b2212f440d36350bf2bcca0a5393abd32c188bdf"
|
|
82
82
|
},
|
|
83
83
|
"JSONRPCResponse.json": {
|
|
84
84
|
"methods": null,
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
},
|
|
107
107
|
"v2/ThreadForkResponse.json": {
|
|
108
108
|
"methods": null,
|
|
109
|
-
"sha256": "
|
|
109
|
+
"sha256": "36af2650a2f2fddd081dd6cb92a91632d0fc12e819fb47ceadcaf238990bec1e"
|
|
110
110
|
},
|
|
111
111
|
"v2/ThreadInjectItemsResponse.json": {
|
|
112
112
|
"methods": null,
|
|
@@ -114,15 +114,15 @@
|
|
|
114
114
|
},
|
|
115
115
|
"v2/ThreadReadResponse.json": {
|
|
116
116
|
"methods": null,
|
|
117
|
-
"sha256": "
|
|
117
|
+
"sha256": "136c873857d2ba0e1aa0836d96ec8d81bfc30a9209e058226e910e0179563e6b"
|
|
118
118
|
},
|
|
119
119
|
"v2/ThreadResumeResponse.json": {
|
|
120
120
|
"methods": null,
|
|
121
|
-
"sha256": "
|
|
121
|
+
"sha256": "ea37ce77b7a1b2fff78191dac117013ef817cfe1f0ab04f95d1bdc847ceacbb9"
|
|
122
122
|
},
|
|
123
123
|
"v2/ThreadStartResponse.json": {
|
|
124
124
|
"methods": null,
|
|
125
|
-
"sha256": "
|
|
125
|
+
"sha256": "36af2650a2f2fddd081dd6cb92a91632d0fc12e819fb47ceadcaf238990bec1e"
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
128
|
"requiredClientFlags": ["app-server", "--listen", "stdio://"],
|