@phnx-labs/agents-cli 1.23.21 → 1.23.23

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 +115 -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 +53 -28
  51. package/dist/lib/daemon/attention-notify-service.js +232 -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,16 @@
1
+ export interface LeadCandidate {
2
+ lead?: boolean;
3
+ cwd?: string | null;
4
+ sessionId?: string | null;
5
+ }
6
+ export declare function isLeadCwd(cwd: string | null | undefined): boolean;
7
+ export declare function leadSessionIds(root?: string): Set<string>;
8
+ export declare function isLeadSession(row: LeadCandidate, hostSessionIds: ReadonlySet<string>): boolean;
9
+ export declare function markLeadSessions<T extends LeadCandidate>(rows: T[], hostSessionIds?: ReadonlySet<string>): T[];
10
+ export declare function withoutLeadSessions<T extends LeadCandidate>(rows: T[], hostSessionIds?: ReadonlySet<string>): T[];
11
+ export declare function hideLeadInSessionEnvelope<E extends {
12
+ type: string;
13
+ }>(event: E, hostSessionIds: ReadonlySet<string>): E;
14
+ export declare function hideLeadInFeedEnvelope<E extends {
15
+ type: string;
16
+ }>(event: E, hostSessionIds: ReadonlySet<string>): E;
@@ -0,0 +1,77 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { leadRoot } from './paths.js';
4
+ const LEAD_CWD_RE = /[\\/]\.agents[\\/]lead(?:[\\/]|$)/;
5
+ export function isLeadCwd(cwd) {
6
+ return typeof cwd === 'string' && LEAD_CWD_RE.test(cwd);
7
+ }
8
+ export function leadSessionIds(root = leadRoot()) {
9
+ const ids = new Set();
10
+ let names;
11
+ try {
12
+ names = fs.readdirSync(root);
13
+ }
14
+ catch (err) {
15
+ if (err.code === 'ENOENT')
16
+ return ids;
17
+ throw err;
18
+ }
19
+ for (const name of names) {
20
+ let raw;
21
+ try {
22
+ raw = fs.readFileSync(path.join(root, name, 'session.json'), 'utf-8');
23
+ }
24
+ catch (err) {
25
+ const code = err.code;
26
+ if (code === 'ENOENT' || code === 'ENOTDIR')
27
+ continue;
28
+ throw err;
29
+ }
30
+ const id = JSON.parse(raw).sessionId;
31
+ if (typeof id === 'string')
32
+ ids.add(id);
33
+ }
34
+ return ids;
35
+ }
36
+ export function isLeadSession(row, hostSessionIds) {
37
+ if (row.lead === true || isLeadCwd(row.cwd))
38
+ return true;
39
+ return typeof row.sessionId === 'string' && hostSessionIds.has(row.sessionId);
40
+ }
41
+ export function markLeadSessions(rows, hostSessionIds = leadSessionIds()) {
42
+ for (const row of rows)
43
+ if (isLeadSession(row, hostSessionIds))
44
+ row.lead = true;
45
+ return rows;
46
+ }
47
+ export function withoutLeadSessions(rows, hostSessionIds = leadSessionIds()) {
48
+ return rows.filter((row) => !isLeadSession(row, hostSessionIds));
49
+ }
50
+ export function hideLeadInSessionEnvelope(event, hostSessionIds) {
51
+ const e = event;
52
+ if (e.type === 'reset')
53
+ return { ...event, rows: e.rows.filter((r) => !isLeadSession(r, hostSessionIds)) };
54
+ if (e.type === 'upsert' && isLeadSession(e.row, hostSessionIds)) {
55
+ const { row: _row, ...rest } = e;
56
+ return { ...rest, type: 'remove' };
57
+ }
58
+ return event;
59
+ }
60
+ export function hideLeadInFeedEnvelope(event, hostSessionIds) {
61
+ const e = event;
62
+ if (e.type === 'reset') {
63
+ const agents = e.agents ?? [];
64
+ const attention = e.attention ?? [];
65
+ const hidden = new Set(agents.filter((a) => isLeadSession(a, hostSessionIds)).map((a) => a.sessionId).filter(Boolean));
66
+ return {
67
+ ...event,
68
+ agents: agents.filter((a) => !isLeadSession(a, hostSessionIds)),
69
+ attention: attention.filter((a) => !a.sessionId || !hidden.has(a.sessionId)),
70
+ };
71
+ }
72
+ if (e.type === 'agent.upsert' && isLeadSession(e.agent, hostSessionIds)) {
73
+ const { agent: _agent, ...rest } = e;
74
+ return { ...rest, type: 'agent.remove' };
75
+ }
76
+ return event;
77
+ }
@@ -27,26 +27,8 @@ export declare function enqueue(boxDir: string, msg: {
27
27
  export declare function readMessage(file: string): MailboxMessage | null;
28
28
  export declare function isExpired(msg: MailboxMessage, now?: Date): boolean;
29
29
  export declare function sweepExpired(boxDir: string, boxId?: string, now?: Date, feedRoot?: string): number;
30
- export declare function drain(boxDir: string, boxId?: string, now?: Date): MailboxMessage[];
31
- export declare function peek(boxDir: string, boxId?: string, now?: Date): MailboxMessage[];
32
- export declare function clear(boxDir: string): number;
33
30
  export type MailboxState = 'inbox' | 'processing' | 'consumed';
34
31
  export interface StoredMessage extends MailboxMessage {
35
32
  state: MailboxState;
36
33
  }
37
- export interface CommsMsg {
38
- from: string;
39
- to: string;
40
- toLabel: string;
41
- ts: string;
42
- text: string;
43
- state: MailboxState;
44
- box: string;
45
- }
46
- export declare function listBoxes(root?: string): string[];
47
34
  export declare function readBox(boxDir: string): StoredMessage[];
48
- export declare function watchMessages(root: string, opts: {
49
- signal?: AbortSignal;
50
- intervalMs?: number;
51
- backfill?: boolean;
52
- }): AsyncGenerator<CommsMsg>;
@@ -98,24 +98,6 @@ export function isExpired(msg, now = new Date()) {
98
98
  const ts = Date.parse(msg.expiresAt);
99
99
  return !Number.isNaN(ts) && ts <= now.getTime();
100
100
  }
101
- function archiveDropped(boxDir, name, reason) {
102
- const src = path.join(inboxDir(boxDir), name);
103
- const dest = path.join(consumedDir(boxDir), name);
104
- try {
105
- const msg = readMessage(src);
106
- if (msg) {
107
- msg.dropped = reason;
108
- fs.writeFileSync(`${dest}.tmp`, JSON.stringify(msg, null, 2), 'utf-8');
109
- fs.renameSync(`${dest}.tmp`, dest);
110
- fs.unlinkSync(src);
111
- }
112
- else {
113
- fs.renameSync(src, dest);
114
- }
115
- }
116
- catch {
117
- }
118
- }
119
101
  export function sweepExpired(boxDir, boxId = path.basename(boxDir), now = new Date(), feedRoot) {
120
102
  ensureDirs(boxDir);
121
103
  let n = 0;
@@ -156,90 +138,6 @@ function jsonFiles(dir) {
156
138
  }
157
139
  return names.filter((n) => n.endsWith('.json')).sort();
158
140
  }
159
- function consumeClaimed(boxDir, name, expectedTo) {
160
- const src = path.join(processingDir(boxDir), name);
161
- const dest = path.join(consumedDir(boxDir), name);
162
- const msg = readMessage(src);
163
- try {
164
- fs.renameSync(src, dest);
165
- }
166
- catch {
167
- return null;
168
- }
169
- if (!msg || msg.to !== expectedTo)
170
- return null;
171
- if (msg.blockId) {
172
- try {
173
- const feedRoot = process.env.AGENTS_FEED_DIR;
174
- recordMessageReceipt(msg.blockId, {
175
- msgId: msg.msgId, status: 'consumed', at: new Date().toISOString(), from: msg.from,
176
- ...(msg.generation !== undefined ? { generation: msg.generation } : {}),
177
- ...(msg.attempt !== undefined ? { attempt: msg.attempt } : {}),
178
- }, feedRoot);
179
- }
180
- catch {
181
- }
182
- }
183
- return msg;
184
- }
185
- export function drain(boxDir, boxId = path.basename(boxDir), now = new Date()) {
186
- ensureDirs(boxDir);
187
- sweepExpired(boxDir, boxId, now);
188
- const out = [];
189
- for (const name of jsonFiles(processingDir(boxDir))) {
190
- const msg = consumeClaimed(boxDir, name, boxId);
191
- if (msg)
192
- out.push(msg);
193
- }
194
- for (const name of jsonFiles(inboxDir(boxDir))) {
195
- const from = path.join(inboxDir(boxDir), name);
196
- const to = path.join(processingDir(boxDir), name);
197
- try {
198
- fs.renameSync(from, to);
199
- }
200
- catch {
201
- continue;
202
- }
203
- const msg = consumeClaimed(boxDir, name, boxId);
204
- if (msg)
205
- out.push(msg);
206
- }
207
- return out;
208
- }
209
- export function peek(boxDir, boxId = path.basename(boxDir), now = new Date()) {
210
- sweepExpired(boxDir, boxId, now);
211
- const out = [];
212
- for (const dir of [processingDir(boxDir), inboxDir(boxDir)]) {
213
- for (const name of jsonFiles(dir)) {
214
- const msg = readMessage(path.join(dir, name));
215
- if (msg && msg.to === boxId)
216
- out.push(msg);
217
- }
218
- }
219
- return out;
220
- }
221
- export function clear(boxDir) {
222
- let n = 0;
223
- for (const name of jsonFiles(inboxDir(boxDir))) {
224
- try {
225
- fs.unlinkSync(path.join(inboxDir(boxDir), name));
226
- n++;
227
- }
228
- catch {
229
- }
230
- }
231
- return n;
232
- }
233
- export function listBoxes(root = getMailboxRootDir()) {
234
- let names;
235
- try {
236
- names = fs.readdirSync(root);
237
- }
238
- catch {
239
- return [];
240
- }
241
- return names.filter((n) => isValidMailboxId(n) && fs.statSync(path.join(root, n)).isDirectory()).sort();
242
- }
243
141
  export function readBox(boxDir) {
244
142
  const out = [];
245
143
  const buckets = [
@@ -257,71 +155,3 @@ export function readBox(boxDir) {
257
155
  out.sort((a, b) => (a.msgId < b.msgId ? -1 : a.msgId > b.msgId ? 1 : 0));
258
156
  return out;
259
157
  }
260
- export async function* watchMessages(root, opts) {
261
- const seen = new Set();
262
- const requestedInterval = opts.intervalMs ?? 500;
263
- const intervalMs = Number.isFinite(requestedInterval) ? Math.max(1, requestedInterval) : 500;
264
- let firstPoll = true;
265
- while (!opts.signal?.aborted) {
266
- const fresh = [];
267
- for (const box of listBoxes(root)) {
268
- for (const stored of readBox(mailboxDir(box, root))) {
269
- const key = `${box}\0${stored.msgId}`;
270
- if (seen.has(key))
271
- continue;
272
- seen.add(key);
273
- if (firstPoll && !opts.backfill)
274
- continue;
275
- fresh.push({
276
- key,
277
- message: {
278
- from: stored.from || 'operator',
279
- to: stored.to,
280
- toLabel: box.slice(0, 8),
281
- ts: stored.ts,
282
- text: stored.text,
283
- state: stored.state,
284
- box,
285
- },
286
- });
287
- }
288
- }
289
- firstPoll = false;
290
- fresh.sort((a, b) => compareWatched(a.message.ts, b.message.ts) ||
291
- compareWatched(a.key, b.key));
292
- for (const { message } of fresh) {
293
- if (opts.signal?.aborted)
294
- return;
295
- yield message;
296
- }
297
- if (!await waitForMailboxPoll(intervalMs, opts.signal))
298
- return;
299
- }
300
- }
301
- function compareWatched(a, b) {
302
- return a < b ? -1 : a > b ? 1 : 0;
303
- }
304
- function waitForMailboxPoll(intervalMs, signal) {
305
- if (signal?.aborted)
306
- return Promise.resolve(false);
307
- return new Promise((resolve) => {
308
- let timer;
309
- let settled = false;
310
- const finish = (keepWatching) => {
311
- if (settled)
312
- return;
313
- settled = true;
314
- if (timer)
315
- clearTimeout(timer);
316
- signal?.removeEventListener('abort', onAbort);
317
- resolve(keepWatching);
318
- };
319
- const onAbort = () => finish(false);
320
- signal?.addEventListener('abort', onAbort, { once: true });
321
- if (signal?.aborted) {
322
- finish(false);
323
- return;
324
- }
325
- timer = setTimeout(() => finish(true), intervalMs);
326
- });
327
- }
@@ -12,8 +12,13 @@ export interface DesktopNotification {
12
12
  id: string;
13
13
  label: string;
14
14
  }[];
15
+ level?: 'urgent' | 'high' | 'normal' | 'low';
16
+ sound?: boolean;
17
+ reminder?: number;
15
18
  }
16
19
  export declare function buildMenubarNotifyArgs(n: DesktopNotification): string[];
20
+ export declare function buildMenubarWithdrawArgs(keys: readonly string[]): string[];
17
21
  export declare function buildOsascriptNotifyArgs(n: DesktopNotification): string[];
18
22
  export declare function spawnDetachedQuiet(command: string, args: string[], timeoutMs?: number): ChildProcess;
19
23
  export declare function notifyDesktop(n: DesktopNotification): void;
24
+ export declare function withdrawDesktop(keys: readonly string[]): void;
@@ -18,6 +18,19 @@ export function buildMenubarNotifyArgs(n) {
18
18
  args.push('--session', n.sessionId);
19
19
  for (const c of n.choices ?? [])
20
20
  args.push('--choice', `${c.id}=${c.label}`);
21
+ if (n.level)
22
+ args.push('--level', n.level);
23
+ if (n.sound)
24
+ args.push('--sound');
25
+ if (n.reminder !== undefined && n.reminder >= 1)
26
+ args.push('--reminder', String(n.reminder));
27
+ return args;
28
+ }
29
+ // Rides on --notify so an AGI Menu without withdraw exits 2 instead of starting a second menu-bar instance.
30
+ export function buildMenubarWithdrawArgs(keys) {
31
+ const args = ['--notify'];
32
+ for (const key of keys)
33
+ args.push('--withdraw', key);
21
34
  return args;
22
35
  }
23
36
  export function buildOsascriptNotifyArgs(n) {
@@ -61,3 +74,14 @@ export function notifyDesktop(n) {
61
74
  catch {
62
75
  }
63
76
  }
77
+ export function withdrawDesktop(keys) {
78
+ if (keys.length === 0 || os.platform() !== 'darwin')
79
+ return;
80
+ try {
81
+ const exec = resolveInstalledMenubarExecutable();
82
+ if (exec)
83
+ spawnDetachedQuiet(exec, buildMenubarWithdrawArgs(keys));
84
+ }
85
+ catch {
86
+ }
87
+ }
@@ -8,6 +8,7 @@ import { agentConfigDirName, resolveOpenCodeXdgPath } from './agents.js';
8
8
  import { stripJsonComments } from './permissions-registry.js';
9
9
  import { resolveRunDefaults } from './run-defaults.js';
10
10
  import { getModelPricing } from './pricing/index.js';
11
+ import { levenshtein } from './fuzzy.js';
11
12
  const CACHE_PATH = getModelsCachePath();
12
13
  const CACHE_SCHEMA_VERSION = 4;
13
14
  const EMPTY_CATALOG_RETRY_MS = 24 * 60 * 60 * 1000;
@@ -820,25 +821,6 @@ function similarity(a, b) {
820
821
  const distance = levenshtein(longer, shorter);
821
822
  return (longer.length - distance) / longer.length;
822
823
  }
823
- function levenshtein(a, b) {
824
- const m = a.length;
825
- const n = b.length;
826
- const dp = Array(m + 1)
827
- .fill(null)
828
- .map(() => Array(n + 1).fill(0));
829
- for (let i = 0; i <= m; i++)
830
- dp[i][0] = i;
831
- for (let j = 0; j <= n; j++)
832
- dp[0][j] = j;
833
- for (let i = 1; i <= m; i++) {
834
- for (let j = 1; j <= n; j++) {
835
- dp[i][j] = a[i - 1] === b[j - 1]
836
- ? dp[i - 1][j - 1]
837
- : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
838
- }
839
- }
840
- return dp[m][n];
841
- }
842
824
  export function buildReasoningFlags(agent, level) {
843
825
  const normalized = level.toLowerCase();
844
826
  if (normalized === 'auto') {
@@ -2,8 +2,6 @@ import type { AgentId, PermissionSet, InstalledPermission, ClaudePermissions, Cu
2
2
  import { CODEX_ASK_RULES_FILENAME, CODEX_RULES_FILENAME } from './permissions-registry.js';
3
3
  export { CODEX_ASK_RULES_FILENAME, CODEX_RULES_FILENAME };
4
4
  type ParsedRules = PermissionSet;
5
- export declare const COMPUTER_APP_GATED_VERBS: readonly ["screenshot", "describe", "get-text", "launch", "raise", "click", "right-click", "type", "type-text", "key", "drag", "scroll", "ax-action", "focus", "wait"];
6
- export declare function formatComputerPermissionGrantHint(bundleId?: string): string;
7
5
  export declare function containsBroadGrants(rules: ParsedRules): {
8
6
  broad: string[];
9
7
  reason: string;
@@ -118,10 +116,6 @@ export declare function convertToCodexFormat(set: PermissionSet, cwd?: string):
118
116
  export declare function readAgentPermissions(agentId: AgentId, scope?: 'user' | 'project', cwd?: string, options?: {
119
117
  home?: string;
120
118
  }): ClaudePermissions | OpenCodePermissions | CodexPermissions | PermissionSet | null;
121
- export declare function applyClaudePermissions(set: PermissionSet, scope?: 'user' | 'project', cwd?: string, merge?: boolean): {
122
- success: boolean;
123
- error?: string;
124
- };
125
119
  export declare function openCodeConfigPath(scope: 'user' | 'project', cwd?: string, home?: string): string;
126
120
  export type ApplyPermissionsResult = {
127
121
  success: boolean;
@@ -11,28 +11,6 @@ import { updateGeminiSettings } from './gemini-settings.js';
11
11
  import { ANTIGRAVITY_ACTION_BY_TOOL, CANONICAL_TO_OPENCLAW_TOOL, CODEX_ASK_RULES_FILENAME, CODEX_RULES_FILENAME, stripJsonComments, GROK_TOOL_BY_CANONICAL, PERMISSION_TARGETS, readCanonicalPermissions, } from './permissions-registry.js';
12
12
  export { CODEX_ASK_RULES_FILENAME, CODEX_RULES_FILENAME };
13
13
  const HOME = os.homedir();
14
- export const COMPUTER_APP_GATED_VERBS = [
15
- 'screenshot',
16
- 'describe',
17
- 'get-text',
18
- 'launch',
19
- 'raise',
20
- 'click',
21
- 'right-click',
22
- 'type',
23
- 'type-text',
24
- 'key',
25
- 'drag',
26
- 'scroll',
27
- 'ax-action',
28
- 'focus',
29
- 'wait',
30
- ];
31
- export function formatComputerPermissionGrantHint(bundleId) {
32
- const target = bundleId && bundleId.length > 0 ? bundleId : '<bundle-id>';
33
- return `add Computer(${target}) to a permissions group, then \`computer reload\`\n` +
34
- `app-targeted computer verbs are gated by Computer(<bundle-id>): ${COMPUTER_APP_GATED_VERBS.join(', ')}`;
35
- }
36
14
  export function containsBroadGrants(rules) {
37
15
  const broad = [];
38
16
  const reasons = new Set();
@@ -925,43 +903,6 @@ export function readAgentPermissions(agentId, scope = 'user', cwd, options) {
925
903
  return readCanonicalPermissions(agentId, scope, cwd, options?.home);
926
904
  }
927
905
  }
928
- export function applyClaudePermissions(set, scope = 'user', cwd, merge = true) {
929
- const configDir = scope === 'user'
930
- ? path.join(HOME, '.claude')
931
- : path.join(cwd || process.cwd(), '.claude');
932
- const configPath = path.join(configDir, 'settings.json');
933
- try {
934
- if (!fs.existsSync(configDir)) {
935
- fs.mkdirSync(configDir, { recursive: true });
936
- }
937
- let config = {};
938
- if (fs.existsSync(configPath)) {
939
- config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
940
- }
941
- const newPermissions = convertToClaudeFormat(set);
942
- if (merge && config.permissions) {
943
- const existing = config.permissions;
944
- const mergedAllow = new Set([...(existing.allow || []).map(canonicalToClaudeRule), ...newPermissions.permissions.allow]);
945
- const mergedDeny = new Set([...(existing.deny || []).map(canonicalToClaudeRule), ...newPermissions.permissions.deny]);
946
- const mergedAsk = new Set([...(existing.ask || []).map(canonicalToClaudeRule), ...(newPermissions.permissions.ask || []).map(canonicalToClaudeRule)]);
947
- const perms = {
948
- allow: [...mergedAllow],
949
- deny: [...mergedDeny],
950
- };
951
- if (mergedAsk.size > 0)
952
- perms.ask = [...mergedAsk];
953
- config.permissions = perms;
954
- }
955
- else {
956
- config.permissions = newPermissions.permissions;
957
- }
958
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
959
- return { success: true };
960
- }
961
- catch (err) {
962
- return { success: false, error: err.message };
963
- }
964
- }
965
906
  export function openCodeConfigPath(scope, cwd, home = HOME) {
966
907
  if (scope === 'project') {
967
908
  const root = cwd || process.cwd();
@@ -980,87 +921,6 @@ export function openCodeConfigPath(scope, cwd, home = HOME) {
980
921
  }
981
922
  return path.join(globalDir, 'opencode.jsonc');
982
923
  }
983
- function applyOpenCodePermissions(set, scope = 'user', cwd, merge = true) {
984
- const configPath = openCodeConfigPath(scope, cwd);
985
- const configDir = path.dirname(configPath);
986
- try {
987
- if (!fs.existsSync(configDir)) {
988
- fs.mkdirSync(configDir, { recursive: true });
989
- }
990
- let config = {};
991
- if (fs.existsSync(configPath)) {
992
- const content = stripJsonComments(fs.readFileSync(configPath, 'utf-8'));
993
- config = JSON.parse(content);
994
- }
995
- const newPermissions = convertToOpenCodeFormat(set);
996
- if (merge && config.permission) {
997
- const existing = config.permission;
998
- config.permission = {
999
- ...existing,
1000
- bash: {
1001
- ...(existing.bash || {}),
1002
- ...newPermissions.permission.bash,
1003
- },
1004
- };
1005
- }
1006
- else {
1007
- config.permission = newPermissions.permission;
1008
- }
1009
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
1010
- return { success: true };
1011
- }
1012
- catch (err) {
1013
- return { success: false, error: err.message };
1014
- }
1015
- }
1016
- function applyCodexPermissions(set, scope = 'user', cwd, merge = true) {
1017
- const configDir = scope === 'user'
1018
- ? path.join(HOME, '.codex')
1019
- : path.join(cwd || process.cwd(), '.codex');
1020
- const configPath = path.join(configDir, 'config.toml');
1021
- try {
1022
- if (!fs.existsSync(configDir)) {
1023
- fs.mkdirSync(configDir, { recursive: true });
1024
- }
1025
- let config = {};
1026
- if (fs.existsSync(configPath)) {
1027
- const content = fs.readFileSync(configPath, 'utf-8');
1028
- config = TOML.parse(content);
1029
- }
1030
- const newPermissions = convertToCodexFormat(set, cwd);
1031
- if (newPermissions.approval_policy) {
1032
- config.approval_policy = newPermissions.approval_policy;
1033
- }
1034
- if (newPermissions.sandbox_mode) {
1035
- config.sandbox_mode = newPermissions.sandbox_mode;
1036
- }
1037
- if (newPermissions.sandbox_workspace_write) {
1038
- const existing = config.sandbox_workspace_write;
1039
- config.sandbox_workspace_write = merge
1040
- ? mergeCodexSandboxWrite(existing, newPermissions.sandbox_workspace_write)
1041
- : newPermissions.sandbox_workspace_write;
1042
- }
1043
- fs.writeFileSync(configPath, TOML.stringify(config), 'utf-8');
1044
- syncCodexDenyRules(configDir, set.deny);
1045
- syncCodexAskRules(configDir, set.ask);
1046
- return { success: true };
1047
- }
1048
- catch (err) {
1049
- return { success: false, error: err.message };
1050
- }
1051
- }
1052
- function applyPermissionsToAgent(agentId, set, scope = 'user', cwd, merge = true) {
1053
- switch (agentId) {
1054
- case 'claude':
1055
- return applyClaudePermissions(set, scope, cwd, merge);
1056
- case 'opencode':
1057
- return applyOpenCodePermissions(set, scope, cwd, merge);
1058
- case 'codex':
1059
- return applyCodexPermissions(set, scope, cwd, merge);
1060
- default:
1061
- return { success: false, error: `Agent '${agentId}' does not support permissions` };
1062
- }
1063
- }
1064
924
  function askSkipMessage(agentId, set) {
1065
925
  if (!set.ask?.length)
1066
926
  return undefined;
@@ -8,6 +8,7 @@ export declare function backgroundSpawnOptions(opts?: {
8
8
  detached: boolean;
9
9
  windowsHide: boolean;
10
10
  };
11
+ export declare function childExitCode(status: number | null, signal: NodeJS.Signals | null): number;
11
12
  export declare function hasExited(pid: number): boolean;
12
13
  export declare function waitForExit(pid: number, timeoutMs: number): boolean;
13
14
  export declare function isAlive(pid: number): boolean;
@@ -28,6 +28,11 @@ export function backgroundSpawnOptions(opts = {}) {
28
28
  }
29
29
  return { cwd, detached: true, windowsHide: false };
30
30
  }
31
+ export function childExitCode(status, signal) {
32
+ if (status != null)
33
+ return status;
34
+ return signal ? 128 + (os.constants.signals[signal] ?? 0) : 1;
35
+ }
31
36
  const EXIT_POLL_MS = 50;
32
37
  export function hasExited(pid) {
33
38
  if (!isAlive(pid))
package/dist/lib/probe.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { spawn } from 'child_process';
2
2
  const GROUP_REAP = process.platform !== 'win32';
3
+ const STDOUT_DRAIN_MS = 250;
3
4
  const LIVE_GROUPS = new Set();
4
5
  let exitHookInstalled = false;
5
6
  function ensureExitHook() {
@@ -62,7 +63,18 @@ export function probeCapture(cmd, args, timeoutMs, options = {}) {
62
63
  });
63
64
  child.on('error', (e) => settle(e));
64
65
  child.on('exit', (code) => {
65
- setImmediate(() => settle(code !== null && (options.acceptedExitCodes ?? [0]).includes(code) ? null : new Error(`probe exited ${code}: ${cmd} ${args.join(' ')}`)));
66
+ const done = () => settle(code !== null && (options.acceptedExitCodes ?? [0]).includes(code) ? null : new Error(`probe exited ${code}: ${cmd} ${args.join(' ')}`));
67
+ const stdout = child.stdout;
68
+ if (!stdout || stdout.readableEnded) {
69
+ setImmediate(done);
70
+ return;
71
+ }
72
+ // Exit can be delivered before the child's last write is read; a grandchild holding the pipe must not stall the probe.
73
+ const drain = setTimeout(done, STDOUT_DRAIN_MS);
74
+ stdout.once('end', () => {
75
+ clearTimeout(drain);
76
+ done();
77
+ });
66
78
  });
67
79
  });
68
80
  }
@@ -1,7 +1,7 @@
1
1
  import { execFile } from 'child_process';
2
2
  import { promisify } from 'util';
3
3
  import chalk from 'chalk';
4
- import { projectNameForCwd } from './projects.js';
4
+ import { canonicalProjectName, projectNameForCwd } from './projects.js';
5
5
  import { readRecentActivity } from './feed/activity.js';
6
6
  const execFileAsync = promisify(execFile);
7
7
  const MERGED_PR_LIMIT = 100;
@@ -25,9 +25,10 @@ export function rollupSessionsByProject(defs, sessions) {
25
25
  const prSeen = new Map();
26
26
  const ticketSeen = new Map();
27
27
  for (const s of sessions) {
28
- const name = projectNameForCwd(s.cwd, defs);
29
- if (!name)
28
+ const found = projectNameForCwd(s.cwd, defs);
29
+ if (!found)
30
30
  continue;
31
+ const name = canonicalProjectName(found, defs);
31
32
  let r = map.get(name);
32
33
  if (!r) {
33
34
  r = blank(name);
@@ -22,6 +22,7 @@ export interface ProjectIntegration {
22
22
  }
23
23
  export interface ProjectDef {
24
24
  name: string;
25
+ aliases?: string[];
25
26
  description?: string;
26
27
  root?: string;
27
28
  defaultPath?: string;
@@ -64,6 +65,14 @@ export declare function repoPathClaims(def: ProjectDef): Array<{
64
65
  export declare function projectNameForCwd(cwd: string | undefined, defs: ProjectDef[]): string | undefined;
65
66
  export declare function listProjectDefsCached(): ProjectDef[];
66
67
  export declare function resetProjectDefsCache(): void;
68
+ interface AliasResolution {
69
+ table: Map<string, string>;
70
+ ignored: string[];
71
+ }
72
+ export declare function resolveProjectAliases(defs: ProjectDef[]): AliasResolution;
73
+ export declare function projectAliasTable(defs: ProjectDef[]): Map<string, string>;
74
+ export declare function canonicalProjectName(name: string, defs?: ProjectDef[]): string;
67
75
  export declare function confirmedProjectForCwd(cwd: string | undefined | null, defs?: ProjectDef[]): string | undefined;
68
76
  export declare function resolveProjectNameForCwd(cwd: string | undefined | null, defs: ProjectDef[]): string | undefined;
69
77
  export declare function resolveDefinedProjectPath(def: ProjectDef, worktree: string | undefined, forRemote: boolean): string | undefined;
78
+ export {};