@aisac/cli 0.4.0-beta.21 → 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.
@@ -79,6 +79,11 @@ async function main() {
79
79
  const childEnv = { ...process.env };
80
80
  delete childEnv.JEV_API_KEY;
81
81
  delete childEnv.TYPESAFE_API_KEY;
82
+ // The worker role's variables (ADR-0058) are for the adapter the monitor runs;
83
+ // the terminal, and every command its model runs, never carries them.
84
+ const terminalEnv = { ...childEnv };
85
+ for (const name of ['AISAC_WORKER_ROLE', 'AISAC_WORKER_MODULE', 'AISAC_MANAGER_ROLE'])
86
+ delete terminalEnv[name];
82
87
  const bridgeRoot = await mkdtemp(join(tmpdir(), 'ai-brain-codex-terminal-'));
83
88
  await chmod(bridgeRoot, 0o700);
84
89
  const socketPath = join(bridgeRoot, 'codex.sock');
@@ -1048,7 +1053,7 @@ async function main() {
1048
1053
  }
1049
1054
  terminal = spawn(codexBinary, ['--remote', `unix://${socketPath}`, ...nativeArgs], {
1050
1055
  cwd: process.cwd(),
1051
- env: childEnv,
1056
+ env: terminalEnv,
1052
1057
  stdio: ['inherit', 'inherit', 'inherit'],
1053
1058
  });
1054
1059
  terminal.on('error', () => void cleanup().finally(() => process.exit(1)));
@@ -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.21';
19
+ export const ADAPTER_VERSION = '0.4.0-beta.22';
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
@@ -67,8 +67,10 @@ import { sessionServers } from './mcp-servers.mjs';
67
67
  import { anyFormatter } from './guardrails/format.mjs';
68
68
  import { readCodexGuardrails } from './guardrails-plugin.mjs';
69
69
  import { codexHooksStatus, supportsCodexHooks } from './codex-hooks.mjs';
70
+ import { managerDoctorLine, managerDoctorSection, takeRoleFlags } from './manager/launch-role.mjs';
71
+ import { WORKERS_USAGE, workersCommand } from './manager/workers-cli.mjs';
70
72
 
71
- const VERSION = '0.4.0-beta.21';
73
+ const VERSION = '0.4.0-beta.22';
72
74
  // The command is `aisac`; `aibrain` is an alias installed from the same entry.
73
75
  const COMMAND = 'aisac';
74
76
  /** `aisac scan` could not scan as asked (scan spec D6); 1 means findings, 2 a usage error. */
@@ -79,7 +81,7 @@ const LEGACY_DISCLOSURE_VERSION = 'aibrain-paid-context-v1-2026-10-09';
79
81
 
80
82
  function usage() {
81
83
  console.log(
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.`,
84
+ `${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] [--manager [--room <name>]] [-- native-args...]\n ${COMMAND} codex [--worker <name> [--room <name>]] [-- native-args...]\n${WORKERS_USAGE.map((line) => ` ${COMMAND} ${line}\n`).join('')} ${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.`,
83
85
  );
84
86
  console.log(
85
87
  'Clients: setup without --client configures the clients installed on PATH (Claude Code, Codex, or both).',
@@ -111,6 +113,39 @@ function usage() {
111
113
  console.log(
112
114
  '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
115
  );
116
+ console.log(
117
+ "Manager and workers (licensed accounts): `aisac claude --manager` coordinates the Codex sessions started with `aisac codex --worker <name>` in the same repository (or the same `--room <name>`): its manager_* tools send a message to a worker, which runs it as one turn under its own sandbox and approval policy, and read the reply; you can still type in any worker. `aisac workers` lists the room; `aisac workers delegate [<name>...] [--for 8h]`, typed by you on a terminal, lets the manager answer the workers' approval prompts for a limited time, except a fixed reserve that always stays with you; `aisac workers delegate --off` ends it and `aisac workers decisions` shows what was decided. Messages are local files under the aisac state directory, deleted when read; a message becomes part of the other session's conversation, so its text reaches that session's model provider like anything typed there.",
118
+ );
119
+ }
120
+
121
+ /**
122
+ * `aisac workers` (spec aisac-engineering-manager FR1, FR9, FR13): local state
123
+ * only, so it needs no setup and no license.
124
+ * @param {string[]} args
125
+ */
126
+ async function workers(args) {
127
+ const root = stateRoot();
128
+ const locale = resolvePackLocale(await readStoredLocale(root), process.env);
129
+ return workersCommand(args, {
130
+ stateRoot: root,
131
+ cwd: process.cwd(),
132
+ env: process.env,
133
+ locale,
134
+ out: (text) => stdout.write(`${text}\n`),
135
+ err: (text) => process.stderr.write(`${text}\n`),
136
+ terminal: {
137
+ // A delegation is typed by a person: standard input must be a terminal (FR13).
138
+ isTTY: stdin.isTTY === true,
139
+ question: async (prompt) => {
140
+ const reader = createInterface({ input: stdin, output: stdout });
141
+ try {
142
+ return await reader.question(prompt);
143
+ } finally {
144
+ reader.close();
145
+ }
146
+ },
147
+ },
148
+ });
114
149
  }
115
150
 
116
151
  // Telemetry is opt-in; setup omits the flag to preserve the stored choice.
@@ -1012,6 +1047,12 @@ async function doctor(json) {
1012
1047
  version: codexCompatibility?.version,
1013
1048
  }),
1014
1049
  scan: await doctorScan(json),
1050
+ // Manager and workers (ADR-0058, FR11): role support and the live rooms, no path.
1051
+ manager: await managerDoctorSection({
1052
+ root: stateRoot(),
1053
+ claude: native.claude !== null,
1054
+ codexVersion: native.codex === null ? null : (codexCompatibility?.version ?? null),
1055
+ }).catch(() => null),
1015
1056
  paidOrPilot: probe?.ok
1016
1057
  ? 'provider_free_probe_ok; paid entitlement or pilot invitation remains server-enforced'
1017
1058
  : config
@@ -1022,6 +1063,7 @@ async function doctor(json) {
1022
1063
  else {
1023
1064
  console.log(result);
1024
1065
  for (const line of releaseDoctorLines(result)) console.log(line);
1066
+ console.log(managerDoctorLine(result.manager));
1025
1067
  }
1026
1068
  if (!platform.ok || !config || !probe?.ok || !nativeReady) process.exitCode = 1;
1027
1069
  }
@@ -1210,6 +1252,10 @@ async function main(argv) {
1210
1252
  process.exitCode = await scan(rest);
1211
1253
  return;
1212
1254
  }
1255
+ if (command === 'workers') {
1256
+ process.exitCode = await workers(rest);
1257
+ return;
1258
+ }
1213
1259
  if (command === 'update') {
1214
1260
  process.exitCode = await updateCommand(rest, {
1215
1261
  root: stateRoot(),
@@ -1244,7 +1290,11 @@ async function main(argv) {
1244
1290
  const launch = takeHostFlag(rest);
1245
1291
  if (command === 'codex' && launch.hostMode === 'managed')
1246
1292
  throw new Error('host_mode_unsupported');
1247
- const nativeArgs = launch.args[0] === '--' ? launch.args.slice(1) : launch.args;
1293
+ // `--manager`, `--worker <name>` and `--room <name>` belong to the launcher as
1294
+ // well (spec aisac-engineering-manager D2): a manager is a Claude Code session,
1295
+ // a worker a Codex session.
1296
+ const role = takeRoleFlags(launch.args, command);
1297
+ const nativeArgs = role.args[0] === '--' ? role.args.slice(1) : role.args;
1248
1298
  const root = stateRoot();
1249
1299
  try {
1250
1300
  // Self-update (ADR-0056 R3, FR6) before any host work: the one-time consent
@@ -1276,9 +1326,16 @@ async function main(argv) {
1276
1326
  {},
1277
1327
  {
1278
1328
  hostMode: launch.hostMode,
1329
+ role: role.request,
1279
1330
  },
1280
1331
  )
1281
- : launchCodex({ ...config, packageRoot: PACKAGE_ROOT }, root, nativeArgs));
1332
+ : launchCodex(
1333
+ { ...config, packageRoot: PACKAGE_ROOT },
1334
+ root,
1335
+ nativeArgs,
1336
+ {},
1337
+ { role: role.request },
1338
+ ));
1282
1339
  process.exitCode = result;
1283
1340
  return;
1284
1341
  } finally {
@@ -110,6 +110,13 @@ export const SCAN_PREFIX = 'scan/';
110
110
  * @type {readonly string[]}
111
111
  */
112
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/']);
113
120
  const OUTPUT_STYLES_PREFIX = 'output-styles/';
114
121
  const SKILLS_DIRECTORY = 'skills';
115
122
  const AGENT_FILE = /^agents\/([a-z][a-z0-9-]{0,63})\.md$/u;
@@ -557,6 +564,14 @@ export function isNonSessionPath(path) {
557
564
  return NON_SESSION_PREFIXES.some((prefix) => path.startsWith(prefix));
558
565
  }
559
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
+
560
575
  /**
561
576
  * Write the pack files into `engineering/` of the launch's private directory:
562
577
  * `0700` directories, `0600` files, exclusive creation, contained paths. Files
@@ -564,14 +579,15 @@ export function isNonSessionPath(path) {
564
579
  * `aisac init` and the `scan/` rules for `aisac scan`, not for a session.
565
580
  * @param {VerifiedPack} pack
566
581
  * @param {string} launchDirectory
582
+ * @param {(path: string) => boolean} [leftOut] Paths this host does not get.
567
583
  * @returns {Promise<string>} the pack root
568
584
  */
569
- async function writePackFiles(pack, launchDirectory) {
585
+ async function writePackFiles(pack, launchDirectory, leftOut = () => false) {
570
586
  const base = resolve(launchDirectory, PACK_DIRECTORY);
571
587
  await mkdir(base, { mode: 0o700 });
572
588
  for (const file of pack.files) {
573
589
  if (!isValidPackPath(file.path)) throw new Error('pack_path_invalid');
574
- if (isNonSessionPath(file.path)) continue;
590
+ if (isNonSessionPath(file.path) || leftOut(file.path)) continue;
575
591
  const target = resolve(base, ...file.path.split('/'));
576
592
  if (!target.startsWith(`${base}${sep}`)) throw new Error('pack_path_escape');
577
593
  await mkdir(dirname(target), { recursive: true, mode: 0o700 });
@@ -670,13 +686,14 @@ export function codexRoleOf(file) {
670
686
  * Write a verified pack for the Codex app-server this launch owns: the files
671
687
  * as for Claude (without the Claude manifest), one role file per agent in
672
688
  * `codex-agents/`, and the description the monitor turns into session
673
- * arguments. Output styles have no Codex equivalent and stay unused.
689
+ * arguments. Output styles have no Codex equivalent and stay unused, and the
690
+ * Claude-only files (the manager's playbook) are left out.
674
691
  * @param {VerifiedPack} pack
675
692
  * @param {string} launchDirectory
676
693
  * @returns {Promise<import('./codex-engineering.mjs').CodexEngineering>}
677
694
  */
678
695
  export async function materializeCodexPack(pack, launchDirectory) {
679
- const base = await writePackFiles(pack, launchDirectory);
696
+ const base = await writePackFiles(pack, launchDirectory, isClaudeOnlyPath);
680
697
  const skillsRoot = join(base, SKILLS_DIRECTORY);
681
698
  await mkdir(skillsRoot, { recursive: true, mode: 0o700 });
682
699
  const rolesDirectory = join(base, CODEX_AGENTS_DIRECTORY);
@@ -67,6 +67,23 @@ export const HOOK_CATALOG = Object.freeze([
67
67
  'pt-BR': 'Recusa rm -rf em /, ~, . ou .. e DROP DATABASE, DROP TABLE ou TRUNCATE.',
68
68
  },
69
69
  },
70
+ {
71
+ // Spec aisac-engineering-manager FR10 (D13): the manager's bus directory, and
72
+ // `aisac workers delegate`, stay out of agent tools. Glob too: listing the bus
73
+ // names its sessions and messages.
74
+ id: 'bus-guard',
75
+ mode: 'block',
76
+ defaultOn: true,
77
+ clients: ['claude', 'codex'],
78
+ bindings: [
79
+ { event: 'PreToolUse', matcher: 'Read|Edit|MultiEdit|Write|NotebookEdit|Grep|Glob|Bash' },
80
+ ],
81
+ description: {
82
+ en: 'Keeps agent tools out of the manager bus directory and refuses aisac workers delegate; decides from names only.',
83
+ 'pt-BR':
84
+ 'Mantém as ferramentas do agente fora do diretório do bus do gerente e recusa aisac workers delegate; decide só pelo nome.',
85
+ },
86
+ },
70
87
  {
71
88
  id: 'format-on-edit',
72
89
  mode: 'advise',
@@ -140,7 +157,7 @@ export const HOOK_CATALOG = Object.freeze([
140
157
  * @type {Readonly<Record<HookEvent, readonly string[]>>}
141
158
  */
142
159
  export const CODEX_HOOK_POSITIONS = Object.freeze({
143
- PreToolUse: Object.freeze(['secrets-guard', 'git-guard', 'destructive-guard']),
160
+ PreToolUse: Object.freeze(['secrets-guard', 'git-guard', 'destructive-guard', 'bus-guard']),
144
161
  PostToolUse: Object.freeze(['format-on-edit', 'docs-reminder', 'continuity-reminder']),
145
162
  UserPromptSubmit: Object.freeze(['docs-reminder', 'continuity-reminder']),
146
163
  SessionStart: Object.freeze(['session-context', 'compact-continuity']),