@phnx-labs/agents-cli 1.20.0 → 1.20.4

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.
Files changed (111) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +4 -4
  3. package/dist/commands/cli.js +3 -3
  4. package/dist/commands/cloud.js +1 -1
  5. package/dist/commands/commands.js +24 -7
  6. package/dist/commands/exec.js +36 -16
  7. package/dist/commands/feedback.d.ts +7 -0
  8. package/dist/commands/feedback.js +89 -0
  9. package/dist/commands/helper.d.ts +12 -0
  10. package/dist/commands/helper.js +87 -0
  11. package/dist/commands/hooks.js +86 -7
  12. package/dist/commands/import.js +90 -37
  13. package/dist/commands/mcp.js +166 -10
  14. package/dist/commands/packages.js +196 -27
  15. package/dist/commands/permissions.js +21 -6
  16. package/dist/commands/profiles.d.ts +8 -0
  17. package/dist/commands/profiles.js +117 -4
  18. package/dist/commands/pull.js +4 -4
  19. package/dist/commands/routines.js +6 -6
  20. package/dist/commands/rules.js +8 -4
  21. package/dist/commands/secrets-migrate.d.ts +24 -0
  22. package/dist/commands/secrets-migrate.js +198 -0
  23. package/dist/commands/secrets-sync.d.ts +11 -0
  24. package/dist/commands/secrets-sync.js +155 -0
  25. package/dist/commands/secrets.js +74 -39
  26. package/dist/commands/skills.js +22 -5
  27. package/dist/commands/subagents.js +69 -49
  28. package/dist/commands/teams.js +48 -10
  29. package/dist/commands/utils.d.ts +33 -0
  30. package/dist/commands/utils.js +139 -0
  31. package/dist/commands/versions.js +4 -4
  32. package/dist/commands/view.d.ts +6 -0
  33. package/dist/commands/view.js +169 -8
  34. package/dist/commands/workflows.js +29 -6
  35. package/dist/index.js +4 -0
  36. package/dist/lib/acp/client.js +6 -1
  37. package/dist/lib/agents.d.ts +4 -0
  38. package/dist/lib/agents.js +41 -17
  39. package/dist/lib/auto-pull-worker.js +18 -1
  40. package/dist/lib/browser/chrome.js +4 -0
  41. package/dist/lib/browser/drivers/ssh.js +1 -1
  42. package/dist/lib/browser/profiles.d.ts +3 -3
  43. package/dist/lib/browser/profiles.js +3 -3
  44. package/dist/lib/browser/service.js +19 -0
  45. package/dist/lib/browser/types.d.ts +4 -4
  46. package/dist/lib/cli-resources.d.ts +36 -8
  47. package/dist/lib/cli-resources.js +268 -46
  48. package/dist/lib/cloud/factory.d.ts +1 -1
  49. package/dist/lib/cloud/factory.js +1 -1
  50. package/dist/lib/events.d.ts +16 -2
  51. package/dist/lib/events.js +33 -2
  52. package/dist/lib/exec.d.ts +39 -11
  53. package/dist/lib/exec.js +90 -31
  54. package/dist/lib/help.js +11 -5
  55. package/dist/lib/hooks/cache.d.ts +38 -0
  56. package/dist/lib/hooks/cache.js +242 -0
  57. package/dist/lib/hooks/profile.d.ts +33 -0
  58. package/dist/lib/hooks/profile.js +129 -0
  59. package/dist/lib/hooks.d.ts +0 -10
  60. package/dist/lib/hooks.js +68 -15
  61. package/dist/lib/import.d.ts +21 -0
  62. package/dist/lib/import.js +55 -2
  63. package/dist/lib/mcp.d.ts +15 -0
  64. package/dist/lib/mcp.js +40 -0
  65. package/dist/lib/permissions.d.ts +13 -0
  66. package/dist/lib/permissions.js +51 -1
  67. package/dist/lib/plugin-marketplace.d.ts +10 -0
  68. package/dist/lib/plugin-marketplace.js +47 -1
  69. package/dist/lib/plugins.js +15 -1
  70. package/dist/lib/profiles-presets.d.ts +26 -0
  71. package/dist/lib/profiles-presets.js +187 -8
  72. package/dist/lib/profiles.d.ts +34 -0
  73. package/dist/lib/profiles.js +112 -1
  74. package/dist/lib/pty-server.js +27 -3
  75. package/dist/lib/routines-format.d.ts +17 -5
  76. package/dist/lib/routines-format.js +37 -16
  77. package/dist/lib/routines.d.ts +1 -1
  78. package/dist/lib/routines.js +2 -2
  79. package/dist/lib/runner.js +64 -10
  80. package/dist/lib/secrets/Agents CLI.app/Contents/CodeResources +0 -0
  81. package/dist/lib/secrets/Agents CLI.app/Contents/MacOS/Agents CLI +0 -0
  82. package/dist/lib/secrets/Agents CLI.app/Contents/_CodeSignature/CodeResources +1 -9
  83. package/dist/lib/secrets/bundles.d.ts +18 -22
  84. package/dist/lib/secrets/bundles.js +75 -99
  85. package/dist/lib/secrets/index.d.ts +51 -27
  86. package/dist/lib/secrets/index.js +147 -156
  87. package/dist/lib/secrets/install-helper.d.ts +45 -0
  88. package/dist/lib/secrets/install-helper.js +165 -0
  89. package/dist/lib/secrets/linux.js +4 -4
  90. package/dist/lib/secrets/sync.d.ts +56 -0
  91. package/dist/lib/secrets/sync.js +180 -0
  92. package/dist/lib/session/render.js +4 -4
  93. package/dist/lib/session/types.d.ts +1 -1
  94. package/dist/lib/shims.d.ts +4 -1
  95. package/dist/lib/shims.js +5 -35
  96. package/dist/lib/state.d.ts +14 -1
  97. package/dist/lib/state.js +49 -5
  98. package/dist/lib/teams/agents.d.ts +5 -4
  99. package/dist/lib/teams/agents.js +47 -21
  100. package/dist/lib/teams/api.d.ts +2 -1
  101. package/dist/lib/teams/api.js +4 -3
  102. package/dist/lib/types.d.ts +57 -1
  103. package/dist/lib/types.js +2 -0
  104. package/dist/lib/usage.d.ts +27 -2
  105. package/dist/lib/usage.js +100 -17
  106. package/dist/lib/versions.d.ts +35 -1
  107. package/dist/lib/versions.js +288 -64
  108. package/package.json +13 -12
  109. package/scripts/install-helper.js +97 -0
  110. package/scripts/postinstall.js +16 -0
  111. package/dist/lib/secrets/Agents CLI.app/Contents/embedded.provisionprofile +0 -0
@@ -136,38 +136,59 @@ export function humanizeNextRun(date, now, tz) {
136
136
  // ---------------------------------------------------------------------------
137
137
  // formatRepoLink
138
138
  // ---------------------------------------------------------------------------
139
+ /**
140
+ * Maximum display length for a repo cell. Display strings longer than this
141
+ * are truncated with an ellipsis so column alignment is preserved.
142
+ * Consumers that render the column should use this constant as the column width.
143
+ */
144
+ export const REPO_DISPLAY_MAX = 24;
139
145
  /**
140
146
  * Parse a repo string into a display label and an optional hyperlink target.
141
147
  *
142
148
  * Rules:
143
- * - undefined / empty → display '-', href null
144
- * - 'owner/name' (one slash) → display 'owner/name', href 'https://github.com/owner/name/pulls'
145
- * - 'https://...' or 'http://…' → display hostname+path, href the URL verbatim
146
- * - anything else → display raw string, href null
149
+ * - null / undefined / empty / non-string → display '-', href null
150
+ * - 'owner/name' (one slash) → display 'owner/name', href 'https://github.com/owner/name/pulls'
151
+ * - 'https://...' or 'http://...' → display hostname+path, href the URL verbatim
152
+ * - anything else → display raw string, href null
153
+ *
154
+ * The display string is truncated to REPO_DISPLAY_MAX characters (with a
155
+ * trailing '…') when it would otherwise exceed the column width. The href
156
+ * is always the full untruncated URL so hyperlinks remain functional.
157
+ *
158
+ * NEVER throws — mirrors the contract of humanizeCron.
147
159
  */
148
160
  export function formatRepoLink(repo) {
149
- if (!repo || repo.trim() === '') {
161
+ if (repo == null || typeof repo !== 'string' || repo.trim() === '') {
150
162
  return { display: '-', href: null };
151
163
  }
152
164
  const trimmed = repo.trim();
165
+ let display;
166
+ let href;
153
167
  // Absolute URL
154
168
  if (trimmed.startsWith('https://') || trimmed.startsWith('http://')) {
155
169
  try {
156
170
  const url = new URL(trimmed);
157
- const display = url.hostname + url.pathname.replace(/\/$/, '');
158
- return { display, href: trimmed };
171
+ display = url.hostname + url.pathname.replace(/\/$/, '');
172
+ href = trimmed;
159
173
  }
160
174
  catch {
161
- return { display: trimmed, href: null };
175
+ display = trimmed;
176
+ href = null;
162
177
  }
163
178
  }
164
- // GitHub shorthand: owner/name (exactly one slash, no scheme, no extra slashes)
165
- if (/^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(trimmed)) {
166
- return {
167
- display: trimmed,
168
- href: `https://github.com/${trimmed}/pulls`,
169
- };
179
+ else if (/^[A-Za-z0-9._-]+\/[A-Za-z0-9._-]+$/.test(trimmed)) {
180
+ // GitHub shorthand: owner/name (exactly one slash, no scheme, no extra slashes)
181
+ display = trimmed;
182
+ href = `https://github.com/${trimmed}/pulls`;
183
+ }
184
+ else {
185
+ // Anything else: plain text, no link
186
+ display = trimmed;
187
+ href = null;
188
+ }
189
+ // Truncate display to column width; href stays untruncated.
190
+ if (display.length > REPO_DISPLAY_MAX) {
191
+ display = display.slice(0, REPO_DISPLAY_MAX - 1) + '…';
170
192
  }
171
- // Anything else: plain text, no link
172
- return { display: trimmed, href: null };
193
+ return { display, href };
173
194
  }
@@ -19,7 +19,7 @@ export interface JobConfig {
19
19
  schedule: string;
20
20
  agent: AgentId;
21
21
  workflow?: string;
22
- mode: 'plan' | 'edit' | 'full';
22
+ mode: 'plan' | 'edit' | 'auto' | 'skip' | 'full';
23
23
  effort: 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'auto';
24
24
  timeout: string;
25
25
  enabled: boolean;
@@ -135,8 +135,8 @@ export function validateJob(config) {
135
135
  errors.push('workflow must be a lowercase alphanumeric name (hyphens and underscores allowed, e.g. autodev)');
136
136
  }
137
137
  }
138
- if (config.mode && !['plan', 'edit', 'full'].includes(config.mode)) {
139
- errors.push('mode must be plan, edit, or full');
138
+ if (config.mode && !['plan', 'edit', 'auto', 'skip', 'full'].includes(config.mode)) {
139
+ errors.push("mode must be plan, edit, auto, or skip ('full' accepted as alias for skip)");
140
140
  }
141
141
  if (config.effort && !['low', 'medium', 'high', 'xhigh', 'max', 'auto'].includes(config.effort)) {
142
142
  errors.push('effort must be low, medium, high, xhigh, max, or auto');
@@ -14,7 +14,8 @@ import { resolveJobPrompt, parseTimeout, writeRunMeta, getRunDir, } from './rout
14
14
  import { getRunsDir } from './state.js';
15
15
  import { prepareJobHome, buildSpawnEnv } from './sandbox.js';
16
16
  import { resolveModel, buildReasoningFlags } from './models.js';
17
- import { createTimer, maybeRotate, truncate } from './events.js';
17
+ import { createTimer, maybeRotate, redactPrompt } from './events.js';
18
+ import { normalizeMode } from './exec.js';
18
19
  /** CLI command templates per agent, with {prompt} as a placeholder. */
19
20
  const AGENT_COMMANDS = {
20
21
  claude: ['claude', '-p', '--verbose', '{prompt}', '--output-format', 'stream-json', '--permission-mode', 'plan'],
@@ -36,13 +37,20 @@ export function buildJobCommand(config, resolvedPrompt) {
36
37
  throw new Error(`Unsupported agent for daemon jobs: ${config.agent}`);
37
38
  }
38
39
  let cmd = template.map((part) => part.replace('{prompt}', resolvedPrompt));
40
+ // Canonicalize mode (accepts legacy `full` as alias for `skip`).
41
+ const mode = normalizeMode(config.mode);
39
42
  if (config.agent === 'claude') {
40
- if (config.mode === 'edit') {
43
+ if (mode === 'edit') {
41
44
  const planIndex = cmd.indexOf('plan');
42
45
  if (planIndex !== -1)
43
46
  cmd[planIndex] = 'acceptEdits';
44
47
  }
45
- else if (config.mode === 'full') {
48
+ else if (mode === 'auto') {
49
+ const planIndex = cmd.indexOf('plan');
50
+ if (planIndex !== -1)
51
+ cmd[planIndex] = 'auto';
52
+ }
53
+ else if (mode === 'skip') {
46
54
  // Replace --permission-mode plan with --dangerously-skip-permissions
47
55
  const pmIndex = cmd.indexOf('--permission-mode');
48
56
  if (pmIndex !== -1)
@@ -63,10 +71,10 @@ export function buildJobCommand(config, resolvedPrompt) {
63
71
  appendModelAndReasoning(cmd, config);
64
72
  }
65
73
  if (config.agent === 'codex') {
66
- if (config.mode === 'edit') {
74
+ if (mode === 'edit') {
67
75
  cmd.push('--full-auto');
68
76
  }
69
- else if (config.mode === 'full') {
77
+ else if (mode === 'skip') {
70
78
  // Remove sandbox restriction, just --full-auto
71
79
  const sbIndex = cmd.indexOf('--sandbox');
72
80
  if (sbIndex !== -1)
@@ -76,7 +84,10 @@ export function buildJobCommand(config, resolvedPrompt) {
76
84
  appendModelAndReasoning(cmd, config);
77
85
  }
78
86
  if (config.agent === 'gemini') {
79
- if (config.mode === 'edit' || config.mode === 'full') {
87
+ if (mode === 'edit') {
88
+ cmd.push('--approval-mode', 'auto_edit');
89
+ }
90
+ else if (mode === 'skip') {
80
91
  cmd.push('--yolo');
81
92
  }
82
93
  appendModelAndReasoning(cmd, config);
@@ -122,7 +133,7 @@ export async function executeJob(config) {
122
133
  version: config.version,
123
134
  jobName: config.name,
124
135
  mode: config.mode,
125
- prompt: truncate(config.prompt, 200),
136
+ ...redactPrompt(config.prompt),
126
137
  schedule: config.schedule,
127
138
  });
128
139
  const resolvedPrompt = resolveJobPrompt(config);
@@ -321,6 +332,39 @@ export function extractReport(stdoutPath, agentType) {
321
332
  return null;
322
333
  }
323
334
  }
335
+ /** Derive the final status of a detached run by reading the agent's stream-json
336
+ * tail. Detached children fire-and-forget, so we never see their exit code
337
+ * directly — but Claude's stream-json terminates with a `type: result` line
338
+ * that carries `is_error`. If we find it, the run completed cleanly (modulo
339
+ * agent-reported error). If not, the process likely died mid-stream and the
340
+ * caller should treat the run as failed. */
341
+ function inferFinalStatusFromLog(stdoutPath, agent) {
342
+ if (!fs.existsSync(stdoutPath))
343
+ return null;
344
+ try {
345
+ const content = fs.readFileSync(stdoutPath, 'utf-8');
346
+ const lines = content.split('\n').filter((l) => l.trim());
347
+ // Walk backwards over the last few lines — the result marker is always
348
+ // at the tail. Cap the scan so a huge stdout doesn't iterate forever.
349
+ for (let i = lines.length - 1, scanned = 0; i >= 0 && scanned < 20; i--, scanned++) {
350
+ try {
351
+ const parsed = JSON.parse(lines[i]);
352
+ if (agent === 'claude' && parsed.type === 'result') {
353
+ return parsed.is_error
354
+ ? { status: 'failed', exitCode: 1 }
355
+ : { status: 'completed', exitCode: 0 };
356
+ }
357
+ }
358
+ catch {
359
+ // malformed JSONL line — keep scanning
360
+ }
361
+ }
362
+ return null;
363
+ }
364
+ catch {
365
+ return null;
366
+ }
367
+ }
324
368
  /** Scan all runs marked "running" and finalize any whose process has exited. */
325
369
  export function monitorRunningJobs() {
326
370
  const runsDir = getRunsDir();
@@ -346,11 +390,21 @@ export function monitorRunningJobs() {
346
390
  process.kill(meta.pid, 0);
347
391
  }
348
392
  catch { /* process no longer running */
349
- meta.status = 'failed';
393
+ const runDirPath = path.join(jobRunsPath, runDirEntry.name);
394
+ const stdoutPath = path.join(runDirPath, 'stdout.log');
395
+ // Prefer the agent's own success/error marker; fall back to "failed"
396
+ // only when the stream ended without one (process killed mid-run).
397
+ const inferred = inferFinalStatusFromLog(stdoutPath, meta.agent);
398
+ if (inferred) {
399
+ meta.status = inferred.status;
400
+ meta.exitCode = inferred.exitCode;
401
+ }
402
+ else {
403
+ meta.status = 'failed';
404
+ }
350
405
  meta.completedAt = new Date().toISOString();
351
406
  writeRunMeta(meta);
352
- const stdoutPath = path.join(jobRunsPath, runDirEntry.name, 'stdout.log');
353
- extractAndSaveReport(stdoutPath, meta.agent, path.join(jobRunsPath, runDirEntry.name));
407
+ extractAndSaveReport(stdoutPath, meta.agent, runDirPath);
354
408
  }
355
409
  }
356
410
  catch { /* corrupt or unreadable meta.json */ }
@@ -5,15 +5,7 @@
5
5
  <key>files</key>
6
6
  <dict/>
7
7
  <key>files2</key>
8
- <dict>
9
- <key>embedded.provisionprofile</key>
10
- <dict>
11
- <key>hash2</key>
12
- <data>
13
- 2vfA/eR3dTYgNc/fXhdADUPkp5tRIepPzE3FCLfDx4w=
14
- </data>
15
- </dict>
16
- </dict>
8
+ <dict/>
17
9
  <key>rules</key>
18
10
  <dict>
19
11
  <key>^Resources/</key>
@@ -1,15 +1,15 @@
1
1
  /**
2
- * Secret bundles -- named sets of keychain-backed environment variables.
2
+ * Secret bundles named sets of keychain-backed environment variables.
3
3
  *
4
4
  * Bundle metadata (name, description, vars map) is stored in the macOS
5
- * Keychain as a JSON blob under `agents-cli.bundles.<name>`. Bundles created
6
- * with `--icloud-sync` write the metadata to the iCloud-synced keychain so
7
- * the full bundle definition (not just secret values) propagates across
8
- * the user's Macs. Nothing about secrets ever lives in plaintext on disk.
5
+ * Keychain as a JSON blob under `agents-cli.bundles.<name>`. Secret values
6
+ * live one per keychain item under `agents-cli.secrets.<bundle>.<key>`.
7
+ * Every item is device-local and gated by Touch ID / device passcode — see
8
+ * src/lib/secrets/index.ts for the access-control story. Nothing about
9
+ * secrets ever lives in plaintext on disk.
9
10
  *
10
- * Secret values keep their old layout: one keychain item per key under
11
- * `agents-cli.secrets.<bundle>.<key>`, sync-state matching the bundle's
12
- * `icloud_sync` flag.
11
+ * Cross-machine sync is handled by src/lib/secrets/sync.ts via an explicit
12
+ * encrypted export/import flow; the bundle layer is sync-agnostic.
13
13
  */
14
14
  import { type BundleValue, type SecretRef } from './index.js';
15
15
  /** Allowed values for a secret's `type` metadata field. */
@@ -28,8 +28,6 @@ export interface SecretsBundle {
28
28
  name: string;
29
29
  description?: string;
30
30
  allow_exec?: boolean;
31
- /** When true, keychain-backed values and bundle metadata sync via iCloud Keychain. */
32
- icloud_sync?: boolean;
33
31
  /** ISO 8601 UTC timestamp. Set once on the first writeBundle() for a bundle. */
34
32
  created_at?: string;
35
33
  /** ISO 8601 UTC timestamp. Refreshed on every writeBundle(). */
@@ -49,6 +47,7 @@ export declare const RESERVED_ENV_NAMES: Set<string>;
49
47
  export declare function bundleToEnvPrefix(name: string): string;
50
48
  export declare function isReservedEnvName(key: string): boolean;
51
49
  export declare function isLoaderOrInterpreterEnv(name: string): boolean;
50
+ export declare function sanitizeProcessEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
52
51
  /** Validate a bundle name against the allowed pattern. Throws on invalid input. */
53
52
  export declare function validateBundleName(name: string): void;
54
53
  export declare function validateEnvKey(key: string): void;
@@ -62,11 +61,7 @@ export declare function validateSecretType(t: string): asserts t is SecretType;
62
61
  export declare function validateExpiresFutureDated(iso: string): void;
63
62
  export declare function bundleExists(name: string): boolean;
64
63
  export declare function readBundle(name: string): SecretsBundle;
65
- export interface WriteBundleOptions {
66
- /** Emit a secrets.set audit event. Internal bookkeeping writes turn this off. */
67
- emitEvent?: boolean;
68
- }
69
- export declare function writeBundle(bundle: SecretsBundle, opts?: WriteBundleOptions): void;
64
+ export declare function writeBundle(bundle: SecretsBundle): void;
70
65
  export declare function deleteBundle(name: string): boolean;
71
66
  export declare function listBundles(): SecretsBundle[];
72
67
  export interface BundleEntryInfo {
@@ -78,14 +73,15 @@ export declare function describeBundle(bundle: SecretsBundle): BundleEntryInfo[]
78
73
  /** Options for resolveBundleEnv. */
79
74
  export interface ResolveBundleOptions {
80
75
  /**
81
- * Human-readable label for who is requesting the secrets. Shown to the
82
- * user under the Touch ID prompt so they know what's about to read.
83
- * Example: "agent claude", "command curl", "browser profile".
84
- * When omitted the prompt only names the bundle.
76
+ * Human-readable label for who is requesting the secrets. Currently
77
+ * informational only the helper's Touch ID prompt is set by the OS and
78
+ * cannot be reliably customized once we drop the per-batch reason path,
79
+ * but we keep this in the API so call sites stay explicit about who's
80
+ * about to read the bundle.
85
81
  */
86
82
  caller?: string;
87
83
  }
88
- export declare function resolveBundleEnv(bundle: SecretsBundle, opts?: ResolveBundleOptions): Record<string, string>;
84
+ export declare function resolveBundleEnv(bundle: SecretsBundle, _opts?: ResolveBundleOptions): Record<string, string>;
89
85
  /**
90
86
  * Read a bundle's metadata AND resolve its env in a single Touch ID prompt.
91
87
  *
@@ -135,8 +131,8 @@ export interface RenameOptions {
135
131
  * 4) write new bundle metadata
136
132
  * 5) delete the old per-key keychain items + old metadata
137
133
  *
138
- * Steps 1-4 are reversible. If 5 partially fails (e.g. iCloud Keychain
139
- * hiccup), running `rename` again is a safe no-op for the source items.
134
+ * Steps 1-4 are reversible. If 5 partially fails, running `rename` again is
135
+ * a safe no-op for the source items.
140
136
  */
141
137
  export declare function renameBundle(oldName: string, newName: string, opts?: RenameOptions): void;
142
138
  export declare function keychainItemsForBundle(bundle: SecretsBundle): Array<{