@phnx-labs/agents-cli 1.23.21 → 1.23.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.
Files changed (176) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/README.md +17 -0
  3. package/dist/bootstrap.js +5 -4
  4. package/dist/cli/command-registry.js +2 -0
  5. package/dist/commands/config.js +16 -0
  6. package/dist/commands/daemon.js +3 -3
  7. package/dist/commands/doctor.js +10 -19
  8. package/dist/commands/events.js +1 -14
  9. package/dist/commands/feed-watch.js +5 -2
  10. package/dist/commands/go.js +2 -2
  11. package/dist/commands/lead.d.ts +3 -0
  12. package/dist/commands/lead.js +280 -0
  13. package/dist/commands/projects.js +3 -2
  14. package/dist/commands/ps-roster.d.ts +2 -12
  15. package/dist/commands/ps-roster.js +5 -87
  16. package/dist/commands/ps.js +3 -1
  17. package/dist/commands/repo.js +12 -12
  18. package/dist/commands/resource-view.js +5 -5
  19. package/dist/commands/sessions-browser.js +2 -2
  20. package/dist/commands/sessions-watch.js +5 -2
  21. package/dist/commands/setup-secrets.d.ts +3 -4
  22. package/dist/commands/setup-secrets.js +15 -46
  23. package/dist/commands/setup-session-backup.js +1 -1
  24. package/dist/commands/ssh.d.ts +0 -4
  25. package/dist/commands/ssh.js +14 -81
  26. package/dist/commands/teams-picker.js +1 -12
  27. package/dist/commands/teams.js +1 -13
  28. package/dist/commands/view.d.ts +1 -40
  29. package/dist/commands/view.js +9 -330
  30. package/dist/commands/watchdog.js +4 -4
  31. package/dist/index.js +4 -0
  32. package/dist/lib/accounting/usage.d.ts +0 -1
  33. package/dist/lib/accounting/usage.js +1 -112
  34. package/dist/lib/accounts/add.js +1 -1
  35. package/dist/lib/accounts/migrate.js +1 -1
  36. package/dist/lib/auto-pull-worker.js +2 -16
  37. package/dist/lib/auto-pull.d.ts +1 -0
  38. package/dist/lib/auto-pull.js +27 -0
  39. package/dist/lib/browser-client.js +2 -11
  40. package/dist/lib/cloud/codex.js +3 -0
  41. package/dist/lib/commands.d.ts +0 -6
  42. package/dist/lib/commands.js +3 -116
  43. package/dist/lib/comms-render.d.ts +1 -7
  44. package/dist/lib/comms-render.js +0 -19
  45. package/dist/lib/computer-client.js +2 -11
  46. package/dist/lib/config-keys.d.ts +7 -3
  47. package/dist/lib/config-keys.js +15 -2
  48. package/dist/lib/crabbox/runtimes.d.ts +0 -14
  49. package/dist/lib/crabbox/runtimes.js +0 -80
  50. package/dist/lib/daemon/attention-notify-service.d.ts +51 -28
  51. package/dist/lib/daemon/attention-notify-service.js +219 -53
  52. package/dist/lib/daemon/daemon.js +1 -2
  53. package/dist/lib/daemon/feed-stream-service.js +2 -4
  54. package/dist/lib/device-config.d.ts +0 -5
  55. package/dist/lib/device-config.js +20 -27
  56. package/dist/lib/devices/doctor-findings.d.ts +2 -1
  57. package/dist/lib/devices/doctor-findings.js +12 -1
  58. package/dist/lib/devices/fleet.d.ts +6 -0
  59. package/dist/lib/devices/fleet.js +15 -0
  60. package/dist/lib/devices/harness-inventory.d.ts +9 -0
  61. package/dist/lib/devices/harness-inventory.js +66 -0
  62. package/dist/lib/exec.js +1 -3
  63. package/dist/lib/feed/attention.d.ts +16 -1
  64. package/dist/lib/feed/attention.js +63 -1
  65. package/dist/lib/feed/feed.d.ts +1 -1
  66. package/dist/lib/feed/feed.js +12 -2
  67. package/dist/lib/feed/hub.d.ts +9 -0
  68. package/dist/lib/feed/hub.js +27 -1
  69. package/dist/lib/feed/notify-schedule.d.ts +16 -0
  70. package/dist/lib/feed/notify-schedule.js +62 -0
  71. package/dist/lib/feed/ticket-priority.d.ts +4 -0
  72. package/dist/lib/feed/ticket-priority.js +30 -0
  73. package/dist/lib/feed/watch.d.ts +1 -0
  74. package/dist/lib/feed/watch.js +27 -3
  75. package/dist/lib/feed-ranking.d.ts +1 -0
  76. package/dist/lib/feed-ranking.js +3 -1
  77. package/dist/lib/format.d.ts +0 -2
  78. package/dist/lib/format.js +0 -8
  79. package/dist/lib/helper-versions.js +1 -1
  80. package/dist/lib/hooks/cache.d.ts +1 -0
  81. package/dist/lib/hooks/cache.js +12 -1
  82. package/dist/lib/installations/duplicate-prune.d.ts +37 -0
  83. package/dist/lib/installations/duplicate-prune.js +85 -0
  84. package/dist/lib/installations/inventory-json.d.ts +20 -0
  85. package/dist/lib/installations/inventory-json.js +252 -0
  86. package/dist/lib/installations/shims.d.ts +0 -18
  87. package/dist/lib/installations/shims.js +1 -257
  88. package/dist/lib/lead/brief.d.ts +49 -0
  89. package/dist/lib/lead/brief.js +173 -0
  90. package/dist/lib/lead/client.d.ts +21 -0
  91. package/dist/lib/lead/client.js +167 -0
  92. package/dist/lib/lead/confirm.d.ts +22 -0
  93. package/dist/lib/lead/confirm.js +73 -0
  94. package/dist/lib/lead/events.d.ts +106 -0
  95. package/dist/lib/lead/events.js +188 -0
  96. package/dist/lib/lead/harness.d.ts +29 -0
  97. package/dist/lib/lead/harness.js +107 -0
  98. package/dist/lib/lead/host.d.ts +132 -0
  99. package/dist/lib/lead/host.js +675 -0
  100. package/dist/lib/lead/paths.d.ts +22 -0
  101. package/dist/lib/lead/paths.js +69 -0
  102. package/dist/lib/lead/refs.d.ts +17 -0
  103. package/dist/lib/lead/refs.js +75 -0
  104. package/dist/lib/lead/roster.d.ts +26 -0
  105. package/dist/lib/lead/roster.js +121 -0
  106. package/dist/lib/lead/shapes.d.ts +23 -0
  107. package/dist/lib/lead/shapes.js +95 -0
  108. package/dist/lib/lead/store.d.ts +46 -0
  109. package/dist/lib/lead/store.js +77 -0
  110. package/dist/lib/lead/tools.d.ts +18 -0
  111. package/dist/lib/lead/tools.js +106 -0
  112. package/dist/lib/lead/visibility.d.ts +16 -0
  113. package/dist/lib/lead/visibility.js +77 -0
  114. package/dist/lib/mailbox.d.ts +0 -18
  115. package/dist/lib/mailbox.js +0 -170
  116. package/dist/lib/menubar/notify-desktop.d.ts +5 -0
  117. package/dist/lib/menubar/notify-desktop.js +24 -0
  118. package/dist/lib/models.js +1 -19
  119. package/dist/lib/permissions.d.ts +0 -6
  120. package/dist/lib/permissions.js +0 -140
  121. package/dist/lib/platform/process.d.ts +1 -0
  122. package/dist/lib/platform/process.js +5 -0
  123. package/dist/lib/probe.js +13 -1
  124. package/dist/lib/project-status.js +4 -3
  125. package/dist/lib/projects.d.ts +9 -0
  126. package/dist/lib/projects.js +61 -3
  127. package/dist/lib/scheduling/routines.d.ts +1 -13
  128. package/dist/lib/scheduling/routines.js +1 -37
  129. package/dist/lib/secrets-cli.d.ts +3 -3
  130. package/dist/lib/secrets-cli.js +1 -1
  131. package/dist/lib/secrets-client.d.ts +4 -37
  132. package/dist/lib/secrets-client.js +19 -265
  133. package/dist/lib/session/active.d.ts +18 -8
  134. package/dist/lib/session/active.js +94 -18
  135. package/dist/lib/session/db.d.ts +0 -16
  136. package/dist/lib/session/db.js +1 -134
  137. package/dist/lib/session/detached.d.ts +0 -1
  138. package/dist/lib/session/detached.js +0 -18
  139. package/dist/lib/session/pending-work.d.ts +21 -0
  140. package/dist/lib/session/pending-work.js +284 -0
  141. package/dist/lib/session/remote/remote-list.d.ts +0 -3
  142. package/dist/lib/session/remote/remote-list.js +1 -23
  143. package/dist/lib/session/remote/watch.d.ts +5 -0
  144. package/dist/lib/session/remote/watch.js +19 -2
  145. package/dist/lib/session/session-cache.d.ts +1 -1
  146. package/dist/lib/session/session-cache.js +12 -5
  147. package/dist/lib/session/sync/provision.js +1 -2
  148. package/dist/lib/smart-launch.js +7 -2
  149. package/dist/lib/snapshot.js +3 -4
  150. package/dist/lib/ssh-exec.d.ts +0 -40
  151. package/dist/lib/ssh-exec.js +0 -108
  152. package/dist/lib/ssh-tunnel.d.ts +0 -6
  153. package/dist/lib/ssh-tunnel.js +0 -42
  154. package/dist/lib/standalone-tools.js +12 -1
  155. package/dist/lib/startup/command-registry.js +1 -1
  156. package/dist/lib/startup/spellcheck.d.ts +0 -1
  157. package/dist/lib/startup/spellcheck.js +1 -20
  158. package/dist/lib/state.d.ts +0 -6
  159. package/dist/lib/state.js +1 -14
  160. package/dist/lib/teams/delivery.d.ts +1 -0
  161. package/dist/lib/teams/delivery.js +13 -0
  162. package/dist/lib/types.d.ts +0 -37
  163. package/dist/lib/types.js +0 -9
  164. package/dist/lib/watchdog/log.d.ts +1 -1
  165. package/dist/lib/watchdog/log.js +6 -4
  166. package/package.json +2 -1
  167. package/dist/lib/artifact-actions.d.ts +0 -7
  168. package/dist/lib/artifact-actions.js +0 -39
  169. package/dist/lib/session/sync/managed-config.d.ts +0 -3
  170. package/dist/lib/session/sync/managed-config.js +0 -3
  171. package/dist/lib/session/sync/worker-template.d.ts +0 -1
  172. package/dist/lib/session/sync/worker-template.js +0 -807
  173. package/dist/lib/storage/selection.d.ts +0 -8
  174. package/dist/lib/storage/selection.js +0 -10
  175. package/dist/lib/watchdog/index.d.ts +0 -3
  176. package/dist/lib/watchdog/index.js +0 -3
@@ -0,0 +1,107 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { getCliLaunch } from '../cli-entry.js';
5
+ import { atomicWriteFileSync, atomicWriteJsonSync } from '../fs-atomic.js';
6
+ import { configKeySpec, getConfigValue } from '../device-config.js';
7
+ export const LEAD_TOOL_NAMES = ['roster', 'dispatch', 'start', 'send', 'stop', 'linear', 'remember'];
8
+ export const LEAD_ALLOWED_TOOLS = LEAD_TOOL_NAMES.map((name) => `Bash(agents lead tool ${name}:*)`);
9
+ export const LEAD_DENIED_TOOLS = ['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'Read', 'Glob', 'Grep', 'WebFetch', 'WebSearch'];
10
+ export const LEAD_EFFORT = 'low';
11
+ export const LEAD_ENV_PASSTHROUGH = ['PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'LANG', 'LC_ALL', 'TMPDIR', 'XDG_RUNTIME_DIR', 'TERM'];
12
+ const LEAD_ENV_AUTH = /^(ANTHROPIC_[A-Z_]+|CLAUDE_CODE_OAUTH_TOKEN)$/;
13
+ export function leadModel() {
14
+ const value = getConfigValue('lead.model').value;
15
+ return typeof value === 'string' && value.length > 0 ? value : String(configKeySpec('lead.model').defaultValue);
16
+ }
17
+ export function cliVersion() {
18
+ const pkg = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..', 'package.json');
19
+ return JSON.parse(fs.readFileSync(pkg, 'utf-8')).version;
20
+ }
21
+ export function leadSettings() {
22
+ return {
23
+ permissions: {
24
+ allow: [...LEAD_ALLOWED_TOOLS],
25
+ deny: [...LEAD_DENIED_TOOLS],
26
+ defaultMode: 'dontAsk',
27
+ },
28
+ hooks: {},
29
+ disableAllHooks: true,
30
+ };
31
+ }
32
+ export function writeLeadSettings(paths) {
33
+ atomicWriteJsonSync(paths.settings, leadSettings());
34
+ return paths.settings;
35
+ }
36
+ export function writeAgentsShim(paths, launch = getCliLaunch([])) {
37
+ fs.mkdirSync(paths.bin, { recursive: true, mode: 0o700 });
38
+ const file = path.join(paths.bin, 'agents');
39
+ const quote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
40
+ atomicWriteFileSync(file, `#!/bin/sh\nexec ${[launch.command, ...launch.args].map(quote).join(' ')} "$@"\n`);
41
+ fs.chmodSync(file, 0o755);
42
+ return file;
43
+ }
44
+ export function leadChildEnv(project, paths, source = process.env) {
45
+ const env = {};
46
+ for (const key of LEAD_ENV_PASSTHROUGH)
47
+ if (source[key] !== undefined)
48
+ env[key] = source[key];
49
+ for (const [key, value] of Object.entries(source))
50
+ if (LEAD_ENV_AUTH.test(key) && value !== undefined)
51
+ env[key] = value;
52
+ env.PATH = [paths.bin, env.PATH].filter(Boolean).join(path.delimiter);
53
+ env.AGENTS_LEAD_PROJECT = project;
54
+ env.AGENTS_NO_AUTOPULL = '1';
55
+ return env;
56
+ }
57
+ export const WORKER_ENV_PASSTHROUGH = [
58
+ ...LEAD_ENV_PASSTHROUGH,
59
+ 'SSH_AUTH_SOCK', 'GH_TOKEN', 'GITHUB_TOKEN', 'LINEAR_API_KEY', 'DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY',
60
+ 'DBUS_SESSION_BUS_ADDRESS', 'COLORTERM', 'EDITOR', 'VISUAL',
61
+ ];
62
+ export function curatedClientEnv(source = process.env) {
63
+ const env = {};
64
+ for (const key of WORKER_ENV_PASSTHROUGH) {
65
+ const value = source[key];
66
+ if (value !== undefined)
67
+ env[key] = value;
68
+ }
69
+ for (const [key, value] of Object.entries(source))
70
+ if (LEAD_ENV_AUTH.test(key) && value !== undefined)
71
+ env[key] = value;
72
+ return env;
73
+ }
74
+ export function workerEnv(hostEnv, clientEnv, leadRootDir) {
75
+ const env = { ...curatedClientEnv(hostEnv), ...curatedClientEnv(clientEnv) };
76
+ if (env.PATH) {
77
+ env.PATH = env.PATH.split(path.delimiter).filter((dir) => dir && !path.resolve(dir).startsWith(path.resolve(leadRootDir))).join(path.delimiter);
78
+ }
79
+ return env;
80
+ }
81
+ export function leadRunArgs(project, model, start, paths) {
82
+ const session = start.mode === 'fresh'
83
+ ? ['--session-id', start.sessionId, '--name', `lead-${project}`]
84
+ : ['--resume', start.sessionId];
85
+ return [
86
+ 'run', 'claude', '--headless', '--quiet',
87
+ '--cwd', paths.dir,
88
+ '--model', model,
89
+ '--effort', LEAD_EFFORT,
90
+ ...session,
91
+ '--',
92
+ '--input-format', 'stream-json',
93
+ '--output-format', 'stream-json',
94
+ '--verbose',
95
+ '--include-partial-messages',
96
+ '--setting-sources', 'local',
97
+ '--settings', paths.settings,
98
+ '--strict-mcp-config',
99
+ '--tools', 'Bash',
100
+ '--permission-mode', 'dontAsk',
101
+ '--allowedTools', ...LEAD_ALLOWED_TOOLS,
102
+ '--disallowedTools', ...LEAD_DENIED_TOOLS,
103
+ ];
104
+ }
105
+ export function agentsCliLaunch(args) {
106
+ return getCliLaunch(args);
107
+ }
@@ -0,0 +1,132 @@
1
+ import { type ProjectDef } from '../projects.js';
2
+ import { type LeadEngine, type LeadEvent } from './events.js';
3
+ import { type BriefPr, type BriefTicket } from './brief.js';
4
+ import { type LeadPaths } from './paths.js';
5
+ import { type Launch } from './harness.js';
6
+ export declare const LEAD_IDLE_EXIT_MS: number;
7
+ export declare const ROSTER_WAIT_MS = 4000;
8
+ export declare const CONFIRM_SWEEP_MS: number;
9
+ export declare const MEMORY_PROMPT: string;
10
+ export type LeadHostState = 'warm' | 'cold' | 'stopped';
11
+ export interface LeadStatus {
12
+ project: string;
13
+ state: LeadHostState;
14
+ session: string | null;
15
+ engine: LeadEngine | null;
16
+ model: string;
17
+ host: string;
18
+ brief: string[];
19
+ memory: string[];
20
+ tools: string[];
21
+ pid: number | null;
22
+ version: string | null;
23
+ busy: boolean;
24
+ queued: number;
25
+ turns: number;
26
+ contextPct: number | null;
27
+ lastTurnAt: string | null;
28
+ }
29
+ export type LeadRequest = {
30
+ op: 'ask';
31
+ text: string;
32
+ voice?: number;
33
+ env?: Record<string, string>;
34
+ } | {
35
+ op: 'status';
36
+ } | {
37
+ op: 'stop';
38
+ } | {
39
+ op: 'roster';
40
+ project?: string;
41
+ } | {
42
+ op: 'resolve';
43
+ session: string;
44
+ } | {
45
+ op: 'hold-stop';
46
+ session: string;
47
+ } | {
48
+ op: 'spawn';
49
+ agent: string;
50
+ prompt: string;
51
+ };
52
+ export interface LeadHostRecord {
53
+ pid: number;
54
+ project: string;
55
+ version: string;
56
+ model: string;
57
+ startedAtMs: number;
58
+ }
59
+ export interface LeadHostOptions {
60
+ project: string;
61
+ def: ProjectDef;
62
+ paths: LeadPaths;
63
+ model: string;
64
+ version: string;
65
+ harness: (args: string[]) => Launch;
66
+ feed: Launch | null;
67
+ childEnv?: NodeJS.ProcessEnv;
68
+ workerLaunch?: (args: string[]) => Launch;
69
+ fetchTickets?: (def: ProjectDef) => Promise<BriefTicket[]>;
70
+ fetchPrs?: (def: ProjectDef) => Promise<BriefPr[]>;
71
+ teamKey?: string;
72
+ idleExitMs?: number;
73
+ log?: (line: string) => void;
74
+ }
75
+ export declare function isLeadRow(row: {
76
+ title: string;
77
+ cwd?: string;
78
+ }): boolean;
79
+ export declare function readHostRecord(paths: LeadPaths): LeadHostRecord | null;
80
+ export declare function acquireHostLock(paths: LeadPaths): void;
81
+ export declare function statusFromFiles(project: string, paths: LeadPaths, model: string): LeadStatus;
82
+ export declare class LeadHost {
83
+ private readonly opts;
84
+ private server;
85
+ private child;
86
+ private childSessionId;
87
+ private childStderr;
88
+ private active;
89
+ private queue;
90
+ private queued;
91
+ private busy;
92
+ private stopping;
93
+ private readonly roster;
94
+ private feedChild;
95
+ private feedBackoffMs;
96
+ private timers;
97
+ private idleTimer;
98
+ private readonly ticketCache;
99
+ private readonly knownPrs;
100
+ private readonly ticketPrefixes;
101
+ private rotatedFrom;
102
+ private clientEnv;
103
+ private resolveClosed;
104
+ readonly closed: Promise<void>;
105
+ constructor(opts: LeadHostOptions);
106
+ private log;
107
+ start(): Promise<void>;
108
+ private claimSocket;
109
+ private armIdle;
110
+ private startFeed;
111
+ private isSelf;
112
+ private liveRows;
113
+ private projectRoster;
114
+ private fleetSummary;
115
+ private findRow;
116
+ private onConnection;
117
+ private rosterReply;
118
+ private resolveReply;
119
+ private holdStop;
120
+ private spawnWorker;
121
+ status(): LeadStatus;
122
+ private schedule;
123
+ enqueue(text: string, voice: number | undefined, emit: (e: LeadEvent) => void): Promise<void>;
124
+ private spawnChild;
125
+ private refreshRefData;
126
+ private gatherBrief;
127
+ private exchange;
128
+ private runTurn;
129
+ private rotate;
130
+ private stopChild;
131
+ shutdown(): Promise<void>;
132
+ }