@aisac/cli 0.4.0-beta.18 → 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.
@@ -14,6 +14,7 @@ import {
14
14
  import { dirname, join, resolve } from 'node:path';
15
15
  import { tmpdir } from 'node:os';
16
16
  import { spawn } from 'node:child_process';
17
+ import releaseManifest from './release-manifest.json' with { type: 'json' };
17
18
 
18
19
  const MAX_OUTPUT_BYTES = 96 * 1024;
19
20
  const PROBE_TIMEOUT_MS = 30_000;
@@ -21,19 +22,9 @@ const MAX_PLUGIN_ASSET_BYTES = 4 * 1024 * 1024;
21
22
  const MAX_PLUGIN_TOTAL_BYTES = 16 * 1024 * 1024;
22
23
  const HOST_MAJOR = 2;
23
24
  const HOST_MINOR = 1;
24
- const QUALIFIED_VERSIONS = new Set([
25
- '2.1.294',
26
- '2.1.295',
27
- '2.1.296',
28
- '2.1.299',
29
- '2.1.300',
30
- '2.1.301',
31
- '2.1.302',
32
- '2.1.303',
33
- '2.1.311',
34
- '2.1.322',
35
- '2.1.323',
36
- ]);
25
+ // One source for the qualified releases: the manifest bundled with this client
26
+ // (ADR-0056 R2; spec aisac-release-manifest FR4).
27
+ const QUALIFIED_VERSIONS = new Set(releaseManifest.hosts.claude.qualified);
37
28
  const REQUIRED_FLAGS = ['--settings', '--mcp-config', '--allowedTools', '--plugin-dir'];
38
29
  const REQUIRED_INVENTORY = [
39
30
  'prompt.submit',
@@ -16,7 +16,7 @@ export const MAX_LOG_FILES = 3;
16
16
  const LOCK_WAIT_MS = 250;
17
17
  const LOCK_STALE_MS = 30_000;
18
18
  const ADMISSION_MS = 60 * 60 * 1000;
19
- export const ADAPTER_VERSION = '0.4.0-beta.18';
19
+ export const ADAPTER_VERSION = '0.4.0-beta.21';
20
20
  const MAX_DIAGNOSTIC_COUNT = 10_000_000;
21
21
  const MAX_DIAGNOSTIC_BYTES = 128 * 1024 * 1024;
22
22
  const CHECKPOINT_BACKENDS = new Set(['native_store', 'private_file']);
package/dist/cli.mjs CHANGED
@@ -38,6 +38,29 @@ import {
38
38
  writeStoredLocale,
39
39
  } from './engineering-pack.mjs';
40
40
  import { initCommand } from './engineering-init.mjs';
41
+ import { manifestDoctorSection, resolveReleaseManifest } from './release-manifest.mjs';
42
+ import {
43
+ isChannel,
44
+ isHostMode,
45
+ isUpdateMode,
46
+ readReleaseSettings,
47
+ writeReleaseSettings,
48
+ } from './release-settings.mjs';
49
+ import {
50
+ askReleaseConsent,
51
+ recordReleaseConsent,
52
+ releaseDisclosure,
53
+ releaseUpdateLock,
54
+ selfUpdateAtLaunch,
55
+ updateCommand,
56
+ updateDoctorSection,
57
+ } from './self-update.mjs';
58
+ import {
59
+ describeManagedHost,
60
+ hostFallbackLine,
61
+ resolveHostExecutable,
62
+ takeHostFlag,
63
+ } from './managed-host.mjs';
41
64
  import { scanCommand, scanToolAvailability } from './engineering-scan.mjs';
42
65
  import { extensionsSummary, hooksCommand, mcpCommand } from './extensions-cli.mjs';
43
66
  import { sessionServers } from './mcp-servers.mjs';
@@ -45,7 +68,7 @@ import { anyFormatter } from './guardrails/format.mjs';
45
68
  import { readCodexGuardrails } from './guardrails-plugin.mjs';
46
69
  import { codexHooksStatus, supportsCodexHooks } from './codex-hooks.mjs';
47
70
 
48
- const VERSION = '0.4.0-beta.18';
71
+ const VERSION = '0.4.0-beta.21';
49
72
  // The command is `aisac`; `aibrain` is an alias installed from the same entry.
50
73
  const COMMAND = 'aisac';
51
74
  /** `aisac scan` could not scan as asked (scan spec D6); 1 means findings, 2 a usage error. */
@@ -56,7 +79,7 @@ const LEGACY_DISCLOSURE_VERSION = 'aibrain-paid-context-v1-2026-10-09';
56
79
 
57
80
  function usage() {
58
81
  console.log(
59
- `${COMMAND} ${VERSION}\n\nUsage:\n ${COMMAND} setup [--client claude|codex|both] [--context-profile upstream|conservative]\n [--compact-at 1..95] [--keep-threshold 0..1] [--preserve-recent 1..100]\n [--min-reduction 0..1] [--truncate-head-chars 0..4096]\n [--max-state-tokens 1000..25000] [--max-request-tokens 1000..30000]\n [--tool-policy compatible|read_only] [--goal TEXT]\n ${COMMAND} doctor [--json]\n ${COMMAND} status [--json]\n ${COMMAND} disable\n ${COMMAND} setup --undo\n ${COMMAND} claude [-- native-args...]\n ${COMMAND} codex [-- native-args...]\n ${COMMAND} init [dir] [--lang pt-BR|en] [--stack node|python|none] [--dry-run] [--json]\n ${COMMAND} scan [dir] [--fail-on critical|high|medium|low|none] [--only <kinds>]\n [--skip <kinds>] [--history] [--no-docker] [--lang pt-BR|en] [--json]\n [--check-tools] [--timeout <seconds>]\n\nPolicy notes:\n Automatic monitoring asks for compaction at compact-at percent; state/request\n limits are estimated upper bounds and do not override server quotas.\n min-reduction, truncate-head-chars and tool-policy apply only to Claude;\n Codex keeps native compaction and same-session recovery.`,
82
+ `${COMMAND} ${VERSION}\n\nUsage:\n ${COMMAND} setup [--client claude|codex|both] [--context-profile upstream|conservative]\n [--compact-at 1..95] [--keep-threshold 0..1] [--preserve-recent 1..100]\n [--min-reduction 0..1] [--truncate-head-chars 0..4096]\n [--max-state-tokens 1000..25000] [--max-request-tokens 1000..30000]\n [--tool-policy compatible|read_only] [--goal TEXT]\n [--update-mode auto|notify|off] [--channel beta|latest] [--host-claude managed|system]\n ${COMMAND} doctor [--json]\n ${COMMAND} status [--json]\n ${COMMAND} update [--check] [--rollback] [--yes] [--json]\n ${COMMAND} disable\n ${COMMAND} setup --undo\n ${COMMAND} claude [--host managed|system] [-- native-args...]\n ${COMMAND} codex [-- native-args...]\n ${COMMAND} init [dir] [--lang pt-BR|en] [--stack node|python|none] [--dry-run] [--json]\n ${COMMAND} scan [dir] [--fail-on critical|high|medium|low|none] [--only <kinds>]\n [--skip <kinds>] [--history] [--no-docker] [--lang pt-BR|en] [--json]\n [--check-tools] [--timeout <seconds>]\n\nPolicy notes:\n Automatic monitoring asks for compaction at compact-at percent; state/request\n limits are estimated upper bounds and do not override server quotas.\n min-reduction, truncate-head-chars and tool-policy apply only to Claude;\n Codex keeps native compaction and same-session recovery.`,
60
83
  );
61
84
  console.log(
62
85
  'Clients: setup without --client configures the clients installed on PATH (Claude Code, Codex, or both).',
@@ -82,6 +105,12 @@ function usage() {
82
105
  console.log(
83
106
  '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.',
84
107
  );
108
+ console.log(
109
+ 'Updates: at launch `aisac` reads the signed release manifest and, in `auto` mode, installs the newer listed version into its own npm prefix and restarts; `notify` (the default) prints the command; `off` stays quiet. `aisac update` does it on demand (`--check` only looks, `--rollback` returns to the previous version, `--yes` for scripts); setup --update-mode and --channel record the choice; AISAC_NO_SELF_UPDATE=1 turns it off for one launch.',
110
+ );
111
+ console.log(
112
+ 'Managed host: `aisac setup --host-claude managed` (or `aisac claude --host managed` for one session) runs the Claude Code version the signed manifest pins, installed from the npm registry under the aisac state directory with scripts off; the installer never touches your own `claude`, your `~/.claude` (the managed copy shares your login and settings) or your shell profile. `system` (the default) keeps your binary; AISAC_HOST_MODE=system turns the managed host off for one launch; doctor reports it under `hosts`. After a failed install the launches of the next hour keep your binary without trying again; `aisac claude --host managed` tries at once.',
113
+ );
85
114
  }
86
115
 
87
116
  // Telemetry is opt-in; setup omits the flag to preserve the stored choice.
@@ -459,6 +488,63 @@ function setupClients(requested) {
459
488
  return detected;
460
489
  }
461
490
 
491
+ /**
492
+ * The release disclosure and its answer (spec aisac-release-manifest FR7, D8),
493
+ * recorded in `<state>/release.json`, never in `config.json`: `--update-mode`
494
+ * answers without a question, a terminal gets the one yes/no question, and
495
+ * without either nothing is recorded: the next interactive launch asks and the
496
+ * client keeps notifying meanwhile (FR7). A `--channel` alone is still recorded.
497
+ * @param {string} root @param {'pt-BR' | 'en'} locale
498
+ * @param {{ mode: import('./release-settings.mjs').UpdateMode | undefined,
499
+ * channel: import('./release-settings.mjs').Channel | undefined,
500
+ * hostClaude: import('./release-settings.mjs').HostMode | undefined }} requested
501
+ */
502
+ async function recordSetupConsent(root, locale, requested) {
503
+ const settings = await readReleaseSettings(root);
504
+ let mode = requested.mode;
505
+ if (mode === undefined && stdin.isTTY && stdout.isTTY) {
506
+ mode = (await askReleaseConsent(locale)) ?? undefined;
507
+ } else {
508
+ console.log(`\n${releaseDisclosure(locale)}`);
509
+ }
510
+ const channel = requested.channel ?? settings.update.channel;
511
+ const hosts =
512
+ requested.hostClaude === undefined
513
+ ? settings.hosts
514
+ : { ...settings.hosts, claude: requested.hostClaude };
515
+ if (mode !== undefined) {
516
+ await recordReleaseConsent(root, settings, mode, {
517
+ ...(requested.channel === undefined ? {} : { channel: requested.channel }),
518
+ hosts,
519
+ });
520
+ console.log(`Self-update ${mode} on channel ${channel}; recorded in ${root}/release.json.`);
521
+ } else {
522
+ if (requested.channel !== undefined || requested.hostClaude !== undefined)
523
+ await writeReleaseSettings(
524
+ { consent: settings.consent, update: { ...settings.update, channel }, hosts },
525
+ root,
526
+ );
527
+ console.log(
528
+ settings.consent === null
529
+ ? `Release disclosure not answered; aisac keeps notifying about updates on channel ${channel} until an interactive launch asks (pass --update-mode auto|notify|off to answer now).`
530
+ : `Self-update ${settings.update.mode} on channel ${channel}; recorded earlier in ${root}/release.json.`,
531
+ );
532
+ }
533
+ if (requested.hostClaude !== undefined)
534
+ console.log(`Claude Code host ${requested.hostClaude}; recorded in ${root}/release.json.`);
535
+ }
536
+
537
+ /** @param {string[]} args */
538
+ function requestedReleaseSettings(args) {
539
+ const mode = option(args, '--update-mode');
540
+ if (mode !== undefined && !isUpdateMode(mode)) throw new Error('invalid_update_mode');
541
+ const channel = option(args, '--channel');
542
+ if (channel !== undefined && !isChannel(channel)) throw new Error('invalid_channel');
543
+ const hostClaude = option(args, '--host-claude');
544
+ if (hostClaude !== undefined && !isHostMode(hostClaude)) throw new Error('invalid_host_mode');
545
+ return { mode, channel, hostClaude };
546
+ }
547
+
462
548
  /** @param {string[]} args */
463
549
  async function setup(args) {
464
550
  if (args.includes('--yes')) throw new Error('explicit_disclosure_flag_required');
@@ -478,6 +564,9 @@ async function setup(args) {
478
564
  '--claude-shadow',
479
565
  '--claude-diagnostics',
480
566
  '--lang',
567
+ '--update-mode',
568
+ '--channel',
569
+ '--host-claude',
481
570
  ]),
482
571
  new Set([
483
572
  '--client',
@@ -490,16 +579,61 @@ async function setup(args) {
490
579
  '--claude-shadow',
491
580
  '--claude-diagnostics',
492
581
  '--lang',
582
+ '--update-mode',
583
+ '--channel',
584
+ '--host-claude',
493
585
  ]),
494
586
  );
495
587
  if (args.includes('--undo') && args.length !== 1)
496
588
  throw new Error('setup_undo_cannot_have_options');
497
589
  const lang = option(args, '--lang');
498
590
  if (lang !== undefined && !isPackLocale(lang)) throw new Error('invalid_lang');
591
+ const release = requestedReleaseSettings(args);
499
592
  const previous = await readConfig();
500
593
  // `--lang` alone only switches the language of an existing setup. Before the first
501
594
  // setup it runs the full setup (token included) and stores the language at the end.
502
595
  if (lang !== undefined && args.length === 2 && previous !== null) return setPackLocale(lang);
596
+ // `--update-mode`, `--channel` and `--host-claude` alone change the release settings
597
+ // of an existing setup, offline (FR7, FR5); an explicit update flag is the answer to
598
+ // the disclosure, the host flag alone leaves the consent as it is. The managed copy
599
+ // is installed by the next launch, not here.
600
+ const releaseFlags = ['--update-mode', '--channel', '--host-claude'];
601
+ const releaseOnly =
602
+ (release.mode !== undefined ||
603
+ release.channel !== undefined ||
604
+ release.hostClaude !== undefined) &&
605
+ args.every((argument, index) =>
606
+ [...releaseFlags, '--accept-disclosure'].includes(argument)
607
+ ? true
608
+ : index > 0 && releaseFlags.includes(args[index - 1] ?? ''),
609
+ );
610
+ if (releaseOnly && previous !== null) {
611
+ const root = await ensureStateRoot();
612
+ const settings = await readReleaseSettings(root);
613
+ const hosts =
614
+ release.hostClaude === undefined
615
+ ? settings.hosts
616
+ : { ...settings.hosts, claude: release.hostClaude };
617
+ if (release.mode !== undefined || release.channel !== undefined) {
618
+ await recordReleaseConsent(root, settings, release.mode ?? settings.update.mode, {
619
+ ...(release.channel === undefined ? {} : { channel: release.channel }),
620
+ hosts,
621
+ });
622
+ console.log(
623
+ `Self-update ${release.mode ?? settings.update.mode} on channel ${release.channel ?? settings.update.channel}; recorded in ${root}/release.json. No network call was made.`,
624
+ );
625
+ } else {
626
+ await writeReleaseSettings(
627
+ { consent: settings.consent, update: settings.update, hosts },
628
+ root,
629
+ );
630
+ }
631
+ if (release.hostClaude !== undefined)
632
+ console.log(
633
+ `Claude Code host ${release.hostClaude}; recorded in ${root}/release.json. No network call was made.`,
634
+ );
635
+ return;
636
+ }
503
637
  if (await updateLocalOptOut(previous, args)) return;
504
638
  const localOptOut =
505
639
  option(args, '--telemetry') === 'off' &&
@@ -514,6 +648,8 @@ async function setup(args) {
514
648
  option(args, '--claude-diagnostics') !== undefined)
515
649
  )
516
650
  throw new Error('claude_observation_requires_claude_client');
651
+ if (clients === 'codex' && release.hostClaude !== undefined)
652
+ throw new Error('host_claude_requires_claude_client');
517
653
  const endpoint = option(args, '--endpoint') ?? ENDPOINT;
518
654
  validateEndpoint(endpoint);
519
655
  const selection = selectedPolicy(args, previous, clients);
@@ -550,16 +686,49 @@ async function setup(args) {
550
686
  }
551
687
  token = token.trim();
552
688
  if (!token) throw setupTokenError('empty_token', locale, endpoint);
553
- const claude = resolveNative('claude');
554
689
  const codex = resolveNative('codex');
555
690
  const node = resolveNative('node');
691
+ let claude = resolveNative('claude');
692
+ /** @type {import('./claude-compatibility.mjs').ClaudeCompatibility | null} */
693
+ let claudeCompatibility = null;
694
+ // A managed Claude host asked for at setup (ADR-0056 R4, FR5): the pinned copy is
695
+ // installed and probed in place of the user's binary, which may then be absent;
696
+ // when it cannot be, setup goes on with the user's binary and says why.
697
+ if ((clients === 'claude' || clients === 'both') && release.hostClaude === 'managed') {
698
+ const releaseSettings = await readReleaseSettings(root);
699
+ const manifest = await resolveReleaseManifest({
700
+ root,
701
+ packageRoot: PACKAGE_ROOT,
702
+ endpoint,
703
+ token,
704
+ host: 'claude',
705
+ }).catch(() => null);
706
+ const managed = await resolveHostExecutable({
707
+ host: 'claude',
708
+ root,
709
+ packageRoot: PACKAGE_ROOT,
710
+ manifest,
711
+ settings: { ...releaseSettings, hosts: { ...releaseSettings.hosts, claude: 'managed' } },
712
+ env: process.env,
713
+ flag: 'managed',
714
+ clientVersion: VERSION,
715
+ locale,
716
+ progress: (line) => console.error(line),
717
+ });
718
+ if (managed.mode === 'managed') {
719
+ claude = managed.executable;
720
+ claudeCompatibility = managed.compatibility;
721
+ } else console.error(hostFallbackLine('claude', managed, locale));
722
+ }
556
723
  if ((clients === 'claude' || clients === 'both') && !claude) throw new Error('claude_not_found');
557
724
  if ((clients === 'codex' || clients === 'both') && (!codex || !node))
558
725
  throw new Error('codex_or_node_not_found');
559
- const claudeCompatibility =
560
- (clients === 'claude' || clients === 'both') && claude !== null
561
- ? await resolveClaudeCompatibility(claude, PACKAGE_ROOT)
562
- : null;
726
+ if (
727
+ claudeCompatibility === null &&
728
+ (clients === 'claude' || clients === 'both') &&
729
+ claude !== null
730
+ )
731
+ claudeCompatibility = await resolveClaudeCompatibility(claude, PACKAGE_ROOT);
563
732
  if (claudeCompatibility?.status === 'rejected')
564
733
  throw new Error(claudeCompatibilityError(claudeCompatibility));
565
734
  const claudeVersion = claudeCompatibility?.version ?? (claude ? nativeVersion(claude) : null);
@@ -607,6 +776,7 @@ async function setup(args) {
607
776
  console.log(
608
777
  `Configured ${clients} in ${root}. Provider-free access verified; no provider batch was used.`,
609
778
  );
779
+ await recordSetupConsent(root, locale, release);
610
780
  if (lang !== undefined) await setPackLocale(lang);
611
781
  // Display only: the server decides again on every pack request (ADR-0047).
612
782
  const line = licenseLine(await checkEngineeringLicense(endpoint, token));
@@ -725,8 +895,35 @@ async function doctor(json) {
725
895
  codex: resolveNative('codex'),
726
896
  node: resolveNative('node'),
727
897
  };
898
+ // Release manifest (ADR-0056 R2): fetched at most every six hours when a setup
899
+ // exists, bundled copy otherwise; never the exit code.
900
+ const releaseManifest = await resolveReleaseManifest({
901
+ root: stateRoot(),
902
+ packageRoot: PACKAGE_ROOT,
903
+ endpoint: config?.endpoint ?? null,
904
+ token: config?.token ?? null,
905
+ }).catch(() => null);
906
+ const releaseSettings = await readReleaseSettings(stateRoot());
907
+ // Managed hosts (ADR-0056 R4, FR8): the host a launch would run and the state of
908
+ // the pinned copy; doctor installs nothing. A ready managed copy is the binary the
909
+ // compatibility fields describe, since it is the one `aisac claude` runs.
910
+ /** @param {'claude' | 'codex'} host */
911
+ const describeHost = (host) =>
912
+ describeManagedHost({
913
+ host,
914
+ root: stateRoot(),
915
+ packageRoot: PACKAGE_ROOT,
916
+ manifest: releaseManifest,
917
+ settings: releaseSettings,
918
+ env: process.env,
919
+ clientVersion: VERSION,
920
+ }).catch(() => null);
921
+ const managedHosts = { claude: await describeHost('claude'), codex: await describeHost('codex') };
922
+ const claudeExecutable = managedHosts.claude?.executable ?? native.claude;
728
923
  const claudeCompatibility =
729
- native.claude !== null ? await resolveClaudeCompatibility(native.claude, PACKAGE_ROOT) : null;
924
+ claudeExecutable !== null
925
+ ? await resolveClaudeCompatibility(claudeExecutable, PACKAGE_ROOT)
926
+ : null;
730
927
  const codexCompatibility =
731
928
  native.codex !== null ? await resolveCodexCompatibility(native.codex) : null;
732
929
  const rawNativeVersions = {
@@ -746,7 +943,7 @@ async function doctor(json) {
746
943
  const captureLockPlatform = needsCodex ? captureLockPlatformCheck() : null;
747
944
  const nativeReady =
748
945
  (!needsClaude ||
749
- (native.claude !== null &&
946
+ (claudeExecutable !== null &&
750
947
  (claudeCompatibility?.status === 'qualified' ||
751
948
  claudeCompatibility?.status === 'host_checked'))) &&
752
949
  (!needsCodex ||
@@ -794,6 +991,22 @@ async function doctor(json) {
794
991
  },
795
992
  engineering,
796
993
  engineeringPack: await engineeringPackState(),
994
+ manifest: releaseManifest === null ? null : manifestDoctorSection(releaseManifest),
995
+ // Self-update (ADR-0056 R3, FR8): the decision this launch would take, no action.
996
+ update: await updateDoctorSection({
997
+ root: stateRoot(),
998
+ packageRoot: PACKAGE_ROOT,
999
+ version: VERSION,
1000
+ env: process.env,
1001
+ manifest: releaseManifest,
1002
+ }).catch(() => null),
1003
+ // Managed hosts (ADR-0056 R4, FR8): the decision and the pinned copy, no path.
1004
+ hosts: {
1005
+ managed: {
1006
+ claude: hostDoctorSection(managedHosts.claude),
1007
+ codex: hostDoctorSection(managedHosts.codex),
1008
+ },
1009
+ },
797
1010
  extensions: await doctorExtensions({
798
1011
  executable: native.codex,
799
1012
  version: codexCompatibility?.version,
@@ -806,10 +1019,65 @@ async function doctor(json) {
806
1019
  : 'not_configured',
807
1020
  };
808
1021
  if (json) console.log(JSON.stringify(result));
809
- else console.log(result);
1022
+ else {
1023
+ console.log(result);
1024
+ for (const line of releaseDoctorLines(result)) console.log(line);
1025
+ }
810
1026
  if (!platform.ok || !config || !probe?.ok || !nativeReady) process.exitCode = 1;
811
1027
  }
812
1028
 
1029
+ /**
1030
+ * The `hosts.managed.<host>` section (FR8): everything `describeManagedHost`
1031
+ * found but the binary's path.
1032
+ * @param {Awaited<ReturnType<typeof describeManagedHost>> | null} described
1033
+ */
1034
+ function hostDoctorSection(described) {
1035
+ if (described === null) return null;
1036
+ return {
1037
+ mode: described.mode,
1038
+ reason: described.reason,
1039
+ pinned: described.pinned,
1040
+ platform: described.platform,
1041
+ installed: described.installed,
1042
+ on_disk: described.on_disk,
1043
+ pin_check: described.pin_check,
1044
+ resolver: described.resolver,
1045
+ resolver_reason: described.resolver_reason,
1046
+ install_failure: described.install_failure,
1047
+ };
1048
+ }
1049
+
1050
+ /**
1051
+ * One line per release section after the text doctor output (FR8, R4).
1052
+ * @param {{ manifest: ReturnType<typeof manifestDoctorSection> | null,
1053
+ * update: Awaited<ReturnType<typeof updateDoctorSection>> | null,
1054
+ * hosts: { managed: Record<'claude' | 'codex', ReturnType<typeof hostDoctorSection>> } }} result
1055
+ */
1056
+ function releaseDoctorLines(result) {
1057
+ const manifest =
1058
+ result.manifest === null
1059
+ ? 'unavailable'
1060
+ : `sequence ${result.manifest.sequence} (${result.manifest.source}), ${result.manifest.state}`;
1061
+ const update =
1062
+ result.update === null
1063
+ ? 'unavailable'
1064
+ : `${result.update.mode} on ${result.update.channel}; ${
1065
+ result.update.action === 'none' ? 'up to date' : result.update.action
1066
+ }${result.update.reason === null ? '' : ` (${result.update.reason})`}`;
1067
+ /** @param {'claude' | 'codex'} name @param {ReturnType<typeof hostDoctorSection>} section */
1068
+ const host = (name, section) =>
1069
+ section === null
1070
+ ? `${name} unknown`
1071
+ : `${name} ${section.mode}${section.pinned === null ? '' : `, pinned ${section.pinned}`}${
1072
+ section.mode === 'managed' ? (section.installed ? ', installed' : ', not installed') : ''
1073
+ }${section.reason === null ? '' : ` (${section.reason})`}`;
1074
+ return [
1075
+ `manifest: ${manifest}`,
1076
+ `update: ${update}`,
1077
+ `hosts: ${host('claude', result.hosts.managed.claude)}; ${host('codex', result.hosts.managed.codex)}`,
1078
+ ];
1079
+ }
1080
+
813
1081
  /**
814
1082
  * `aisac scan`. An error the engine did not classify still means it could not scan as
815
1083
  * asked: exit 3, never 1, which a CI step reads as findings (scan review F3). Usage
@@ -836,6 +1104,12 @@ async function scan(args) {
836
1104
  /** @param {boolean} json */
837
1105
  async function status(json) {
838
1106
  const config = await readConfig();
1107
+ // Offline: the cached or bundled manifest, never a fetch (FR8).
1108
+ const releaseManifest = await resolveReleaseManifest({
1109
+ root: stateRoot(),
1110
+ packageRoot: PACKAGE_ROOT,
1111
+ }).catch(() => null);
1112
+ const releaseSettings = await readReleaseSettings(stateRoot());
839
1113
  const policy =
840
1114
  config?.schemaVersion === 2 && config.context !== undefined
841
1115
  ? config.context
@@ -858,6 +1132,21 @@ async function status(json) {
858
1132
  config?.claudeObservation?.disclosedAt !== undefined,
859
1133
  },
860
1134
  engineeringPack: await engineeringPackState(),
1135
+ manifest:
1136
+ releaseManifest === null
1137
+ ? null
1138
+ : {
1139
+ sequence: releaseManifest.sequence,
1140
+ source: releaseManifest.source,
1141
+ state: releaseManifest.state,
1142
+ },
1143
+ update: {
1144
+ mode: releaseSettings.update.mode,
1145
+ channel: releaseSettings.update.channel,
1146
+ consent: releaseSettings.consent !== null,
1147
+ },
1148
+ // Host modes as stored (FR8); whether the managed copy is installed is doctor's.
1149
+ hosts: { claude: releaseSettings.hosts.claude, codex: releaseSettings.hosts.codex },
861
1150
  extensions: await extensionsSummary(stateRoot()),
862
1151
  monitoredSession: null,
863
1152
  monitoringStatus: 'not_observed',
@@ -921,6 +1210,20 @@ async function main(argv) {
921
1210
  process.exitCode = await scan(rest);
922
1211
  return;
923
1212
  }
1213
+ if (command === 'update') {
1214
+ process.exitCode = await updateCommand(rest, {
1215
+ root: stateRoot(),
1216
+ packageRoot: PACKAGE_ROOT,
1217
+ version: VERSION,
1218
+ env: process.env,
1219
+ readConfig: async () => {
1220
+ const config = await readConfig();
1221
+ return config === null ? null : { endpoint: config.endpoint, token: config.token };
1222
+ },
1223
+ interactive: stdin.isTTY === true && stdout.isTTY === true,
1224
+ });
1225
+ return;
1226
+ }
924
1227
  if (command === 'disable') {
925
1228
  if (rest.length > 0) throw new Error('disable_does_not_accept_options');
926
1229
  return removeOwnedSetup();
@@ -936,20 +1239,52 @@ async function main(argv) {
936
1239
  // metadata only, so patch updates do not block a fresh compatibility check.
937
1240
  if (command === 'codex' && typeof config.codexVersion !== 'string')
938
1241
  throw new Error('codex_version_unverified');
1242
+ // `--host managed|system` belongs to the launcher, not the host (ADR-0056 R4,
1243
+ // FR5); a managed Codex arrives with R5.
1244
+ const launch = takeHostFlag(rest);
1245
+ if (command === 'codex' && launch.hostMode === 'managed')
1246
+ throw new Error('host_mode_unsupported');
1247
+ const nativeArgs = launch.args[0] === '--' ? launch.args.slice(1) : launch.args;
939
1248
  const root = stateRoot();
940
- const result = await (command === 'claude'
941
- ? launchClaude(
942
- { ...config, packageRoot: PACKAGE_ROOT },
943
- root,
944
- rest[0] === '--' ? rest.slice(1) : rest,
945
- )
946
- : launchCodex(
947
- { ...config, packageRoot: PACKAGE_ROOT },
948
- root,
949
- rest[0] === '--' ? rest.slice(1) : rest,
950
- ));
951
- process.exitCode = result;
952
- return;
1249
+ try {
1250
+ // Self-update (ADR-0056 R3, FR6) before any host work: the one-time consent
1251
+ // question on a terminal, then install + re-exec in `auto` mode, one line in
1252
+ // `notify`, and a refusal to launch a host below the manifest's minimum.
1253
+ const update = await selfUpdateAtLaunch({
1254
+ root,
1255
+ packageRoot: PACKAGE_ROOT,
1256
+ version: VERSION,
1257
+ config: { endpoint: config.endpoint, token: config.token },
1258
+ host: command,
1259
+ argv,
1260
+ env: process.env,
1261
+ interactive: stdin.isTTY === true && stdout.isTTY === true,
1262
+ });
1263
+ if (update.kind === 'reexec') {
1264
+ process.exitCode = update.exitCode;
1265
+ return;
1266
+ }
1267
+ if (update.kind === 'blocked')
1268
+ throw Object.assign(new Error(update.reason), { guide: update.line });
1269
+ if (update.kind === 'continue')
1270
+ for (const line of update.lines) process.stderr.write(`${line}\n`);
1271
+ const result = await (command === 'claude'
1272
+ ? launchClaude(
1273
+ { ...config, packageRoot: PACKAGE_ROOT },
1274
+ root,
1275
+ nativeArgs,
1276
+ {},
1277
+ {
1278
+ hostMode: launch.hostMode,
1279
+ },
1280
+ )
1281
+ : launchCodex({ ...config, packageRoot: PACKAGE_ROOT }, root, nativeArgs));
1282
+ process.exitCode = result;
1283
+ return;
1284
+ } finally {
1285
+ // The update lock, when this launch still holds it (no host started).
1286
+ await releaseUpdateLock(root).catch(() => undefined);
1287
+ }
953
1288
  }
954
1289
  throw new Error('unknown_command');
955
1290
  }
@@ -7,6 +7,7 @@ import { spawn } from 'node:child_process';
7
7
  import { join } from 'node:path';
8
8
  import { tmpdir } from 'node:os';
9
9
  import fingerprint from './codex-protocol-fingerprint.json' with { type: 'json' };
10
+ import releaseManifest from './release-manifest.json' with { type: 'json' };
10
11
 
11
12
  const MAX_OUTPUT_BYTES = 64 * 1024;
12
13
  const MAX_SCHEMA_BYTES = 8 * 1024 * 1024;
@@ -26,15 +27,9 @@ const PAGINATION_CONTRACT_VALID =
26
27
  fingerprint.roots[PAGINATION_CONTRACT.response_schema]?.sha256 &&
27
28
  typeof PAGINATION_CONTRACT.graph_sha256 === 'string' &&
28
29
  PAGINATION_CONTRACT.graph_sha256.length === 64);
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
- '0.167.1',
37
- ]);
30
+ // One source for the qualified releases: the manifest bundled with this client
31
+ // (ADR-0056 R2; spec aisac-release-manifest FR4).
32
+ const QUALIFIED_VERSIONS = new Set(releaseManifest.hosts.codex.qualified);
38
33
  const ANNOTATIONS = new Set([
39
34
  '$comment',
40
35
  'title',
@@ -28,6 +28,7 @@ import {
28
28
  splitFrontMatter,
29
29
  } from './engineering-pack.mjs';
30
30
  import { isRecord } from './engineering.mjs';
31
+ import { updateCommandFor } from './release-settings.mjs';
31
32
 
32
33
  export const INIT_STACKS = /** @type {const} */ (['node', 'python', 'none']);
33
34
  const TEMPLATE_STACKS = new Set([...INIT_STACKS, 'all']);
@@ -51,7 +52,6 @@ const NODE_MANIFEST = 'package.json';
51
52
  const PYTHON_MANIFESTS = ['pyproject.toml', 'requirements.txt'];
52
53
  const CLAUDE_MEMORY_FILE = 'CLAUDE.md';
53
54
  const USAGE_EXIT_CODE = 2;
54
- const UPDATE_COMMAND = 'npm install -g @aisac/cli@beta';
55
55
 
56
56
  /** @typedef {(typeof INIT_STACKS)[number]} InitStack */
57
57
  /** @typedef {InitStack | 'all'} TemplateStack */
@@ -552,6 +552,8 @@ export async function initCommand(args, deps) {
552
552
  const account = accountOf(await deps.readConfig());
553
553
  const locale =
554
554
  options.lang ?? resolvePackLocale(await readStoredLocale(deps.stateRoot()), deps.env);
555
+ // The channel's command, the same one the launch notices print (release-manifest FR6).
556
+ const updateCommand = await updateCommandFor(deps.stateRoot(), deps.packageRoot);
555
557
  const outcome = await obtainPack({
556
558
  endpoint: account.endpoint,
557
559
  token: account.token,
@@ -560,7 +562,7 @@ export async function initCommand(args, deps) {
560
562
  ...(deps.fetchImpl === undefined ? {} : { fetchImpl: deps.fetchImpl }),
561
563
  });
562
564
  if (outcome.outcome !== 'loaded') {
563
- const notice = packNotice(outcome, locale);
565
+ const notice = packNotice(outcome, locale, updateCommand);
564
566
  if (notice !== null) warn(notice);
565
567
  switch (outcome.outcome) {
566
568
  case 'inactive':
@@ -577,8 +579,8 @@ export async function initCommand(args, deps) {
577
579
  if (templates.length === 0) {
578
580
  warn(
579
581
  locale === 'pt-BR'
580
- ? `AISAC Engineering: o pacote ainda não traz os modelos do init; atualize o aisac (${UPDATE_COMMAND}) ou tente mais tarde.`
581
- : `AISAC Engineering: the pack carries no init templates yet; update aisac (${UPDATE_COMMAND}) or try again later.`,
582
+ ? `AISAC Engineering: o pacote ainda não traz os modelos do init; atualize o aisac (${updateCommand}) ou tente mais tarde.`
583
+ : `AISAC Engineering: the pack carries no init templates yet; update aisac (${updateCommand}) or try again later.`,
582
584
  );
583
585
  throw new Error('init_templates_missing');
584
586
  }