@phnx-labs/agents-cli 1.23.10 → 1.23.12

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.
@@ -1,11 +1,15 @@
1
1
  import { RecordingLedger } from './ledger.js';
2
- import { type RecordingCandidate, type RecordingLedgerRow } from './model.js';
2
+ import { type RecordingCandidate, type RecordingLedgerRow, type TranscodeJob } from './model.js';
3
3
  import { type TranscodedRecording } from './transcode.js';
4
+ type Transcode = (sourcePath: string, signal?: AbortSignal, onStart?: (job: TranscodeJob) => void) => Promise<TranscodedRecording>;
4
5
  export interface RecordingPipelineOptions {
5
6
  ledger?: RecordingLedger;
6
7
  artifactsBin?: string;
7
8
  env?: NodeJS.ProcessEnv;
8
- transcode?: (sourcePath: string, signal?: AbortSignal) => Promise<TranscodedRecording>;
9
+ transcode?: Transcode;
10
+ reapTranscode?: (job: TranscodeJob) => Promise<{
11
+ killed: boolean;
12
+ }>;
9
13
  verifyIdentity?: (signal?: AbortSignal) => Promise<{
10
14
  email: string;
11
15
  }>;
@@ -22,6 +26,7 @@ export declare class RecordingPipeline {
22
26
  private readonly configuredArtifactsBin?;
23
27
  private readonly env;
24
28
  private readonly transcode;
29
+ private readonly reapTranscode;
25
30
  private readonly verifyIdentity;
26
31
  private readonly raiseAttention;
27
32
  private readonly reportError;
@@ -31,7 +36,9 @@ export declare class RecordingPipeline {
31
36
  private artifactsBin;
32
37
  observeLatest(candidate: RecordingCandidate): void;
33
38
  queue(candidates: RecordingCandidate[]): Promise<void>;
34
- recoverInterrupted(): Promise<void>;
39
+ recoverInterrupted(): Promise<{
40
+ reaped: number;
41
+ }>;
35
42
  private attention;
36
43
  private share;
37
44
  private start;
@@ -42,3 +49,4 @@ export declare class RecordingPipeline {
42
49
  upload(candidate: RecordingCandidate, signal?: AbortSignal): Promise<RecordingLedgerRow>;
43
50
  stop(): Promise<void>;
44
51
  }
52
+ export {};
@@ -5,7 +5,7 @@ import { RecordingIdentityError, verifyOrganizationIdentity } from './identity.j
5
5
  import { RecordingLedger } from './ledger.js';
6
6
  import { isNewerRecording } from './model.js';
7
7
  import { processFailure, runProcess } from './process.js';
8
- import { RecordingDependencyError, transcodeRecording } from './transcode.js';
8
+ import { isProcessAlive, reapTranscode, RecordingDependencyError, transcodeRecording } from './transcode.js';
9
9
  function rowCandidate(row) {
10
10
  return {
11
11
  path: row.path,
@@ -69,6 +69,7 @@ export class RecordingPipeline {
69
69
  configuredArtifactsBin;
70
70
  env;
71
71
  transcode;
72
+ reapTranscode;
72
73
  verifyIdentity;
73
74
  raiseAttention;
74
75
  reportError;
@@ -78,7 +79,8 @@ export class RecordingPipeline {
78
79
  this.ledger = options.ledger ?? new RecordingLedger();
79
80
  this.configuredArtifactsBin = options.artifactsBin;
80
81
  this.env = options.env ?? process.env;
81
- this.transcode = options.transcode ?? ((source, signal) => transcodeRecording(source, signal));
82
+ this.transcode = options.transcode ?? ((source, signal, onStart) => transcodeRecording(source, signal, { onStart }));
83
+ this.reapTranscode = options.reapTranscode ?? reapTranscode;
82
84
  this.verifyIdentity = options.verifyIdentity
83
85
  ?? ((signal) => verifyOrganizationIdentity(signal, { artifactsBin: this.artifactsBin(), env: this.env }));
84
86
  this.raiseAttention = options.raiseAttention ?? defaultAttention;
@@ -110,7 +112,18 @@ export class RecordingPipeline {
110
112
  await this.ledger.queue(candidate);
111
113
  }
112
114
  async recoverInterrupted() {
113
- await this.ledger.recoverInterrupted();
115
+ let reaped = 0;
116
+ for (const job of await this.ledger.recoverInterrupted(isProcessAlive)) {
117
+ try {
118
+ if ((await this.reapTranscode(job)).killed)
119
+ reaped += 1;
120
+ await this.ledger.forgetTranscode(job);
121
+ }
122
+ catch (error) {
123
+ this.reportError(`could not reap transcode pid ${job.pid}: ${error instanceof Error ? error.message : String(error)}`);
124
+ }
125
+ }
126
+ return { reaped };
114
127
  }
115
128
  async attention(message) {
116
129
  if (!await this.ledger.shouldPostAttention(message))
@@ -150,10 +163,14 @@ export class RecordingPipeline {
150
163
  };
151
164
  const promise = (async () => {
152
165
  let transcoded;
166
+ let recorded;
153
167
  try {
154
168
  if (!await this.ledger.claim(candidate.stem, candidate.path))
155
169
  return null;
156
- transcoded = await this.transcode(candidate.path, controller.signal);
170
+ transcoded = await this.transcode(candidate.path, controller.signal, (job) => {
171
+ recorded = this.ledger.update(candidate.stem, candidate.path, { transcode: job });
172
+ });
173
+ await recorded;
157
174
  await this.ledger.update(candidate.stem, candidate.path, { status: 'uploading' });
158
175
  const url = await this.share(candidate, transcoded.filePath, controller.signal);
159
176
  const row = await this.ledger.update(candidate.stem, candidate.path, {
@@ -195,7 +212,10 @@ export class RecordingPipeline {
195
212
  throw error;
196
213
  }
197
214
  finally {
215
+ await recorded?.catch(() => undefined);
198
216
  await transcoded?.cleanup();
217
+ if (recorded)
218
+ await this.ledger.update(candidate.stem, candidate.path, { transcode: undefined });
199
219
  }
200
220
  })();
201
221
  active.promise = promise;
@@ -210,8 +230,10 @@ export class RecordingPipeline {
210
230
  return promise;
211
231
  }
212
232
  async drain(options = {}) {
233
+ if (this.active.size > 0)
234
+ return [];
213
235
  const pending = await this.ledger.pending();
214
- const candidates = pending.map(rowCandidate).filter((candidate) => !this.active.has(candidate.stem));
236
+ const candidates = pending.map(rowCandidate).slice(0, 1);
215
237
  if (candidates.length === 0)
216
238
  return [];
217
239
  try {
@@ -8,6 +8,7 @@ export interface RunProcessOptions {
8
8
  env?: NodeJS.ProcessEnv;
9
9
  signal?: AbortSignal;
10
10
  timeoutMs?: number;
11
+ onSpawn?: (pid: number) => void;
11
12
  }
12
13
  export declare class RecordingProcessError extends Error {
13
14
  readonly result?: ProcessResult | undefined;
@@ -22,6 +22,8 @@ export async function runProcess(command, args, options = {}) {
22
22
  detached: process.platform !== 'win32',
23
23
  stdio: ['ignore', 'pipe', 'pipe'],
24
24
  });
25
+ if (child.pid !== undefined)
26
+ options.onSpawn?.(child.pid);
25
27
  let stdout = '';
26
28
  let stderr = '';
27
29
  let settled = false;
@@ -17,7 +17,9 @@ export class RecordingsService extends BasePeriodicService {
17
17
  });
18
18
  this.settler = new RecordingSettler();
19
19
  this.startedAtMs = Date.now();
20
- await this.pipeline.recoverInterrupted();
20
+ const { reaped } = await this.pipeline.recoverInterrupted();
21
+ if (reaped > 0)
22
+ ctx.log('WARN', `recordings: stopped ${reaped} transcode(s) a previous daemon left running`, { event: 'recordings.reaped', reaped });
21
23
  }
22
24
  async onTick(ctx, signal) {
23
25
  if (!this.pipeline || !this.settler)
@@ -1,3 +1,4 @@
1
+ import type { TranscodeJob } from './model.js';
1
2
  export declare const FFMPEG_INSTALL_HINT: string;
2
3
  export declare class RecordingDependencyError extends Error {
3
4
  constructor(message: string);
@@ -10,4 +11,9 @@ export interface TranscodedRecording {
10
11
  export declare function transcodeRecording(sourcePath: string, signal?: AbortSignal, options?: {
11
12
  ffmpegBin?: string;
12
13
  platform?: NodeJS.Platform;
14
+ onStart?: (job: TranscodeJob) => void;
13
15
  }): Promise<TranscodedRecording>;
16
+ export declare function reapTranscode(job: TranscodeJob): Promise<{
17
+ killed: boolean;
18
+ }>;
19
+ export declare function isProcessAlive(pid: number): boolean;
@@ -2,7 +2,10 @@ import * as fs from 'node:fs/promises';
2
2
  import * as os from 'node:os';
3
3
  import * as path from 'node:path';
4
4
  import { findInPath } from '../agent-spec/agents.js';
5
+ import { execFileBounded } from '../exec-bounded.js';
5
6
  import { processFailure, runProcess } from './process.js';
7
+ const WORK_DIR_PREFIX = 'agents-recording-';
8
+ const OUTPUT_NAME = 'recording.mp4';
6
9
  export const FFMPEG_INSTALL_HINT = process.platform === 'darwin'
7
10
  ? 'Install it with `brew install ffmpeg`.'
8
11
  : 'Install it with your system package manager (for example `apt install ffmpeg`).';
@@ -21,8 +24,8 @@ export function resolveFfmpegBin() {
21
24
  }
22
25
  export async function transcodeRecording(sourcePath, signal, options = {}) {
23
26
  const ffmpeg = options.ffmpegBin ?? resolveFfmpegBin();
24
- const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'agents-recording-'));
25
- const output = path.join(directory, 'recording.mp4');
27
+ const directory = await fs.mkdtemp(path.join(os.tmpdir(), WORK_DIR_PREFIX));
28
+ const output = path.join(directory, OUTPUT_NAME);
26
29
  const codec = (options.platform ?? process.platform) === 'darwin' ? 'h264_videotoolbox' : 'libx264';
27
30
  const args = [
28
31
  '-hide_banner', '-loglevel', 'error', '-y', '-i', sourcePath,
@@ -32,7 +35,10 @@ export async function transcodeRecording(sourcePath, signal, options = {}) {
32
35
  '-c:a', 'aac', '-b:a', '128k', '-movflags', '+faststart', output,
33
36
  ];
34
37
  try {
35
- const result = await runProcess(ffmpeg, args, { signal });
38
+ const result = await runProcess(ffmpeg, args, {
39
+ signal,
40
+ onSpawn: (pid) => options.onStart?.({ pid, workDir: directory, ownerPid: process.pid }),
41
+ });
36
42
  if (result.exitCode !== 0)
37
43
  throw processFailure('ffmpeg', args, result);
38
44
  return { filePath: output, cleanup: () => fs.rm(directory, { recursive: true, force: true }) };
@@ -42,3 +48,35 @@ export async function transcodeRecording(sourcePath, signal, options = {}) {
42
48
  throw error;
43
49
  }
44
50
  }
51
+ export async function reapTranscode(job) {
52
+ if (!path.basename(job.workDir).startsWith(WORK_DIR_PREFIX)) {
53
+ throw new Error(`Refusing to reap a transcode outside an ${WORK_DIR_PREFIX}* work dir: ${job.workDir}`);
54
+ }
55
+ let killed = false;
56
+ if (process.platform !== 'win32') {
57
+ const ps = await execFileBounded('ps', ['-ww', '-o', 'args=', '-p', String(job.pid)], { timeoutMs: 5_000 });
58
+ if (ps.timedOut)
59
+ throw new Error(`ps timed out checking transcode pid ${job.pid}`);
60
+ if (ps.code === 0 && ps.stdout.includes(path.join(job.workDir, OUTPUT_NAME))) {
61
+ try {
62
+ process.kill(-job.pid, 'SIGKILL');
63
+ killed = true;
64
+ }
65
+ catch (error) {
66
+ if (error.code !== 'ESRCH')
67
+ throw error;
68
+ }
69
+ }
70
+ }
71
+ await fs.rm(job.workDir, { recursive: true, force: true });
72
+ return { killed };
73
+ }
74
+ export function isProcessAlive(pid) {
75
+ try {
76
+ process.kill(pid, 0);
77
+ return true;
78
+ }
79
+ catch (error) {
80
+ return error.code === 'EPERM';
81
+ }
82
+ }
@@ -3,7 +3,7 @@ import * as path from 'path';
3
3
  import * as TOML from 'smol-toml';
4
4
  import * as yaml from 'yaml';
5
5
  import { capableAgents } from '../../capabilities.js';
6
- import { discoverPermissionGroups, buildPermissionsFromGroups, CODEX_RULES_FILENAME, } from '../../permissions.js';
6
+ import { discoverPermissionGroups, buildPermissionsFromGroups, CODEX_ASK_RULES_FILENAME, CODEX_RULES_FILENAME, } from '../../permissions.js';
7
7
  import { lazyAgentMap } from '../writers/lazy-map.js';
8
8
  function buildClaudeDetector() {
9
9
  return {
@@ -17,19 +17,22 @@ function buildClaudeDetector() {
17
17
  const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
18
18
  const allowRules = settings.permissions?.allow || [];
19
19
  const denyRules = settings.permissions?.deny || [];
20
- if (allowRules.length === 0 && denyRules.length === 0)
20
+ const askRules = settings.permissions?.ask || [];
21
+ if (allowRules.length === 0 && denyRules.length === 0 && askRules.length === 0)
21
22
  return [];
22
23
  const groups = discoverPermissionGroups();
23
24
  const applied = [];
24
25
  for (const group of groups) {
25
26
  const built = buildPermissionsFromGroups([group.name]);
26
- if (built.allow.length === 0 && (!built.deny || built.deny.length === 0)) {
27
+ const askContent = built.ask ?? [];
28
+ if (built.allow.length === 0 && (!built.deny || built.deny.length === 0) && askContent.length === 0) {
27
29
  applied.push(group.name);
28
30
  continue;
29
31
  }
30
32
  const hasAllow = built.allow.some(r => allowRules.includes(r));
31
33
  const hasDeny = built.deny?.some(r => denyRules.includes(r)) || false;
32
- if (hasAllow || hasDeny)
34
+ const hasAsk = askContent.some(r => askRules.includes(r));
35
+ if (hasAllow || hasDeny || hasAsk)
33
36
  applied.push(group.name);
34
37
  }
35
38
  return applied;
@@ -47,9 +50,11 @@ function buildCodexDetector() {
47
50
  list({ versionHome }) {
48
51
  const codexConfigPath = path.join(versionHome, '.codex', 'config.toml');
49
52
  const codexRulesPath = path.join(versionHome, '.codex', 'rules', CODEX_RULES_FILENAME);
53
+ const codexAskPath = path.join(versionHome, '.codex', 'rules', CODEX_ASK_RULES_FILENAME);
50
54
  const hasConfig = fs.existsSync(codexConfigPath);
51
55
  const hasRules = fs.existsSync(codexRulesPath);
52
- if (!hasConfig && !hasRules)
56
+ const hasAskRules = fs.existsSync(codexAskPath);
57
+ if (!hasConfig && !hasRules && !hasAskRules)
53
58
  return [];
54
59
  try {
55
60
  let hasPermKeys = false;
@@ -57,7 +62,7 @@ function buildCodexDetector() {
57
62
  const config = TOML.parse(fs.readFileSync(codexConfigPath, 'utf-8'));
58
63
  hasPermKeys = !!(config.approval_policy || config.sandbox_mode || config.sandbox_workspace_write);
59
64
  }
60
- if (hasPermKeys || hasRules) {
65
+ if (hasPermKeys || hasRules || hasAskRules) {
61
66
  return discoverPermissionGroups().map(g => g.name);
62
67
  }
63
68
  }
@@ -100,7 +105,8 @@ function buildAntigravityDetector() {
100
105
  const perms = settings?.permissions;
101
106
  const hasAllow = Array.isArray(perms?.allow) && perms.allow.length > 0;
102
107
  const hasDeny = Array.isArray(perms?.deny) && perms.deny.length > 0;
103
- if (hasAllow || hasDeny) {
108
+ const hasAsk = Array.isArray(perms?.ask) && perms.ask.length > 0;
109
+ if (hasAllow || hasDeny || hasAsk) {
104
110
  return discoverPermissionGroups().map(g => g.name);
105
111
  }
106
112
  }
@@ -181,7 +187,9 @@ function buildDroidDetector() {
181
187
  const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
182
188
  const hasAllow = Array.isArray(settings.commandAllowlist) && settings.commandAllowlist.length > 0;
183
189
  const hasDeny = Array.isArray(settings.commandDenylist) && settings.commandDenylist.length > 0;
184
- if (hasAllow || hasDeny)
190
+ const askRules = settings.permissionRules?.rules;
191
+ const hasAsk = Array.isArray(askRules) && askRules.some((rule) => rule?.decision === 'ask');
192
+ if (hasAllow || hasDeny || hasAsk)
185
193
  return discoverPermissionGroups().map(g => g.name);
186
194
  }
187
195
  catch { }
@@ -11,9 +11,14 @@ function buildPermissionsWriter(agent) {
11
11
  const built = buildPermissionsFromGroups(selection);
12
12
  const hasAllow = built.allow.length > 0;
13
13
  const hasDeny = (built.deny?.length ?? 0) > 0;
14
- if (!hasAllow && !hasDeny)
14
+ const hasAsk = (built.ask?.length ?? 0) > 0;
15
+ if (!hasAllow && !hasDeny && !hasAsk)
15
16
  return { synced: [] };
16
17
  const r = applyPermsToVersion(agent, built, versionHome, true, cwd);
18
+ if (r.skipped?.length) {
19
+ for (const line of r.skipped)
20
+ console.warn(line);
21
+ }
17
22
  return { synced: r.success ? selection : [] };
18
23
  },
19
24
  };
@@ -98,6 +98,7 @@ export interface AgentConfig {
98
98
  mcpHttp: Capability;
99
99
  mcpHeaders: Capability;
100
100
  allowlist: Capability;
101
+ ask: Capability;
101
102
  skills: Capability;
102
103
  commands: Capability;
103
104
  plugins: Capability;
@@ -118,7 +119,7 @@ export type Capability = boolean | {
118
119
  export type RulesCapability = false | {
119
120
  file: string;
120
121
  };
121
- export type CapabilityName = 'hooks' | 'mcp' | 'mcpHttp' | 'mcpHeaders' | 'allowlist' | 'skills' | 'commands' | 'plugins' | 'subagents' | 'rules' | 'workflows' | 'memory' | 'interactiveRepl';
122
+ export type CapabilityName = 'hooks' | 'mcp' | 'mcpHttp' | 'mcpHeaders' | 'allowlist' | 'ask' | 'skills' | 'commands' | 'plugins' | 'subagents' | 'rules' | 'workflows' | 'memory' | 'interactiveRepl';
122
123
  export type Mode = 'plan' | 'edit' | 'auto' | 'skip';
123
124
  export declare const ALL_MODES: readonly Mode[];
124
125
  export type CapabilityFailReason = 'unsupported' | 'too_old' | 'too_new';
@@ -591,6 +592,7 @@ export interface PermissionSet {
591
592
  description?: string;
592
593
  allow: string[];
593
594
  deny?: string[];
595
+ ask?: string[];
594
596
  additionalDirectories?: string[];
595
597
  }
596
598
  export interface InstalledPermission {
@@ -602,6 +604,7 @@ export interface ClaudePermissions {
602
604
  permissions: {
603
605
  allow: string[];
604
606
  deny: string[];
607
+ ask?: string[];
605
608
  additionalDirectories?: string[];
606
609
  };
607
610
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.23.10",
3
+ "version": "1.23.12",
4
4
  "description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",