@phnx-labs/agents-cli 1.23.13 → 1.23.15

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 (164) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +30 -59
  3. package/dist/cli/command-registry.js +0 -24
  4. package/dist/commands/accounts.js +3 -3
  5. package/dist/commands/daemon.js +5 -147
  6. package/dist/commands/doctor.js +7 -0
  7. package/dist/commands/events-logs.d.ts +2 -0
  8. package/dist/commands/{logs.js → events-logs.js} +28 -127
  9. package/dist/commands/events.js +3 -1
  10. package/dist/commands/exec.d.ts +0 -1
  11. package/dist/commands/exec.js +3 -11
  12. package/dist/commands/feed.d.ts +1 -1
  13. package/dist/commands/feed.js +4 -7
  14. package/dist/commands/mcp.js +1 -1
  15. package/dist/commands/menubar.js +12 -226
  16. package/dist/commands/projects.js +1 -2
  17. package/dist/commands/{trash.d.ts → prune-trash.d.ts} +1 -1
  18. package/dist/commands/{trash.js → prune-trash.js} +8 -8
  19. package/dist/commands/prune.js +3 -1
  20. package/dist/commands/send.js +2 -5
  21. package/dist/commands/sessions.js +1 -1
  22. package/dist/commands/ssh.js +2 -2
  23. package/dist/commands/utils.d.ts +1 -5
  24. package/dist/commands/utils.js +1 -7
  25. package/dist/lib/agent-spec/agents.d.ts +0 -2
  26. package/dist/lib/agent-spec/agents.js +0 -12
  27. package/dist/lib/agent-spec/index.d.ts +0 -4
  28. package/dist/lib/agent-spec/index.js +0 -4
  29. package/dist/lib/commands.d.ts +1 -5
  30. package/dist/lib/commands.js +2 -69
  31. package/dist/lib/comms-render.d.ts +0 -7
  32. package/dist/lib/comms-render.js +0 -41
  33. package/dist/lib/config-keys.d.ts +1 -1
  34. package/dist/lib/config-keys.js +8 -0
  35. package/dist/lib/daemon/daemon.js +1 -6
  36. package/dist/lib/daemon-services.d.ts +1 -1
  37. package/dist/lib/daemon-services.js +0 -5
  38. package/dist/lib/device-config.d.ts +2 -0
  39. package/dist/lib/device-config.js +81 -8
  40. package/dist/lib/devices/doctor-findings.d.ts +6 -1
  41. package/dist/lib/devices/doctor-findings.js +34 -1
  42. package/dist/lib/git.d.ts +1 -0
  43. package/dist/lib/git.js +5 -0
  44. package/dist/lib/hooks/install.d.ts +0 -7
  45. package/dist/lib/hooks/install.js +0 -55
  46. package/dist/lib/hosts/passthrough.js +2 -4
  47. package/dist/lib/hosts/progress.js +2 -2
  48. package/dist/lib/hosts/remote-cmd.js +0 -1
  49. package/dist/lib/installations/migrate.d.ts +1 -0
  50. package/dist/lib/installations/migrate.js +18 -1
  51. package/dist/lib/installations/versions.js +2 -2
  52. package/dist/lib/loop.js +1 -1
  53. package/dist/lib/mailbox-target.d.ts +0 -31
  54. package/dist/lib/mailbox-target.js +0 -37
  55. package/dist/lib/mcp-lookup.d.ts +7 -0
  56. package/dist/lib/mcp-lookup.js +71 -0
  57. package/dist/lib/mcp.d.ts +0 -8
  58. package/dist/lib/mcp.js +0 -47
  59. package/dist/lib/menubar/install-menubar.d.ts +0 -15
  60. package/dist/lib/menubar/install-menubar.js +24 -118
  61. package/dist/lib/menubar/resolve-version.d.ts +9 -10
  62. package/dist/lib/menubar/resolve-version.js +70 -30
  63. package/dist/lib/paths.d.ts +0 -1
  64. package/dist/lib/paths.js +0 -18
  65. package/dist/lib/plugins/skills.d.ts +0 -10
  66. package/dist/lib/plugins/skills.js +2 -165
  67. package/dist/lib/project-pull.js +1 -2
  68. package/dist/lib/resources.d.ts +1 -1
  69. package/dist/lib/routines-project.js +1 -1
  70. package/dist/lib/session/local-tmux-attach.js +2 -2
  71. package/dist/lib/startup/command-registry.js +20 -7
  72. package/dist/lib/teams/agents.js +1 -1
  73. package/dist/lib/teams/placement-probe.d.ts +9 -0
  74. package/dist/lib/teams/placement-probe.js +20 -15
  75. package/dist/lib/triggers/webhook.d.ts +2 -59
  76. package/dist/lib/triggers/webhook.js +2 -422
  77. package/package.json +2 -1
  78. package/dist/commands/funnel.d.ts +0 -2
  79. package/dist/commands/funnel.js +0 -77
  80. package/dist/commands/logs.d.ts +0 -2
  81. package/dist/commands/mailboxes.d.ts +0 -2
  82. package/dist/commands/mailboxes.js +0 -400
  83. package/dist/commands/message.d.ts +0 -2
  84. package/dist/commands/message.js +0 -259
  85. package/dist/commands/packages-materialize.d.ts +0 -6
  86. package/dist/commands/packages-materialize.js +0 -90
  87. package/dist/commands/packages.d.ts +0 -5
  88. package/dist/commands/packages.js +0 -763
  89. package/dist/commands/route.d.ts +0 -2
  90. package/dist/commands/route.js +0 -259
  91. package/dist/commands/testdata/feed-hub.d.ts +0 -1
  92. package/dist/commands/testdata/feed-hub.js +0 -11
  93. package/dist/commands/tmux.d.ts +0 -7
  94. package/dist/commands/tmux.js +0 -529
  95. package/dist/commands/traces.d.ts +0 -2
  96. package/dist/commands/traces.js +0 -204
  97. package/dist/commands/webhook.d.ts +0 -5
  98. package/dist/commands/webhook.js +0 -105
  99. package/dist/lib/agent-spec/materialize.d.ts +0 -3
  100. package/dist/lib/agent-spec/materialize.js +0 -277
  101. package/dist/lib/agent-spec/package-resolve.d.ts +0 -4
  102. package/dist/lib/agent-spec/package-resolve.js +0 -231
  103. package/dist/lib/agent-spec/package-schema.d.ts +0 -3
  104. package/dist/lib/agent-spec/package-schema.js +0 -136
  105. package/dist/lib/agent-spec/package-types.d.ts +0 -94
  106. package/dist/lib/agent-spec/package-types.js +0 -10
  107. package/dist/lib/daemon/testdata/process-view-daemon.d.ts +0 -1
  108. package/dist/lib/daemon/testdata/process-view-daemon.js +0 -12
  109. package/dist/lib/daemon/testdata/process-view-start.d.ts +0 -1
  110. package/dist/lib/daemon/testdata/process-view-start.js +0 -41
  111. package/dist/lib/daemon/webhook-receiver-service.d.ts +0 -8
  112. package/dist/lib/daemon/webhook-receiver-service.js +0 -16
  113. package/dist/lib/daemon-webhooks.d.ts +0 -48
  114. package/dist/lib/daemon-webhooks.js +0 -177
  115. package/dist/lib/funnel.d.ts +0 -6
  116. package/dist/lib/funnel.js +0 -31
  117. package/dist/lib/net-close.d.ts +0 -2
  118. package/dist/lib/net-close.js +0 -20
  119. package/dist/lib/packages/output-home.d.ts +0 -9
  120. package/dist/lib/packages/output-home.js +0 -89
  121. package/dist/lib/registry.d.ts +0 -65
  122. package/dist/lib/registry.js +0 -432
  123. package/dist/lib/routers.d.ts +0 -25
  124. package/dist/lib/routers.js +0 -122
  125. package/dist/lib/run-trace-sync.d.ts +0 -7
  126. package/dist/lib/run-trace-sync.js +0 -35
  127. package/dist/lib/session/testdata/pid-registry-namespace.d.ts +0 -1
  128. package/dist/lib/session/testdata/pid-registry-namespace.js +0 -25
  129. package/dist/lib/session/testdata/process-view-namespace.d.ts +0 -1
  130. package/dist/lib/session/testdata/process-view-namespace.js +0 -56
  131. package/dist/lib/session/testdata/process-view-private.d.ts +0 -1
  132. package/dist/lib/session/testdata/process-view-private.js +0 -11
  133. package/dist/lib/testdata/daemon-health-writer.d.ts +0 -1
  134. package/dist/lib/testdata/daemon-health-writer.js +0 -8
  135. package/dist/lib/testdata/owner-notify-api.d.ts +0 -23
  136. package/dist/lib/testdata/owner-notify-api.js +0 -82
  137. package/dist/lib/testdata/refresh-coordinator-worker.d.ts +0 -1
  138. package/dist/lib/testdata/refresh-coordinator-worker.js +0 -23
  139. package/dist/lib/traces/backend.d.ts +0 -8
  140. package/dist/lib/traces/backend.js +0 -33
  141. package/dist/lib/traces/classify.d.ts +0 -40
  142. package/dist/lib/traces/classify.js +0 -70
  143. package/dist/lib/traces/config.d.ts +0 -2
  144. package/dist/lib/traces/config.js +0 -2
  145. package/dist/lib/traces/insights.d.ts +0 -30
  146. package/dist/lib/traces/insights.js +0 -198
  147. package/dist/lib/traces/phenotype.d.ts +0 -18
  148. package/dist/lib/traces/phenotype.js +0 -335
  149. package/dist/lib/traces/provision.d.ts +0 -16
  150. package/dist/lib/traces/provision.js +0 -25
  151. package/dist/lib/traces/schema2-build.d.ts +0 -28
  152. package/dist/lib/traces/schema2-build.js +0 -496
  153. package/dist/lib/traces/schema2-danger.d.ts +0 -7
  154. package/dist/lib/traces/schema2-danger.js +0 -123
  155. package/dist/lib/traces/schema2.d.ts +0 -139
  156. package/dist/lib/traces/schema2.js +0 -20
  157. package/dist/lib/traces/segments.d.ts +0 -73
  158. package/dist/lib/traces/segments.js +0 -236
  159. package/dist/lib/traces/sync.d.ts +0 -197
  160. package/dist/lib/traces/sync.js +0 -654
  161. package/dist/lib/traces/worker-template.d.ts +0 -1
  162. package/dist/lib/traces/worker-template.js +0 -292
  163. package/dist/lib/triggers/handlers.d.ts +0 -66
  164. package/dist/lib/triggers/handlers.js +0 -383
@@ -3,8 +3,8 @@ import * as path from 'path';
3
3
  import * as os from 'os';
4
4
  import * as yaml from 'yaml';
5
5
  import { normalizeAliases } from '../resource-aliases.js';
6
- import { AGENTS, ensureSkillsDir, agentConfigDirName } from '../agents.js';
7
- import { capableAgents, isCapable } from '../capabilities.js';
6
+ import { AGENTS, agentConfigDirName } from '../agents.js';
7
+ import { capableAgents } from '../capabilities.js';
8
8
  import { getUserSkillsDir, getSkillsDir as getSystemSkillsDir, getProjectAgentsDir, getEnabledExtraRepos, getTrashSkillsDir } from '../state.js';
9
9
  import { getEffectiveHome, getVersionHomePath, listInstalledVersions } from '../installations/store.js';
10
10
  import { listCommandSkillsInVersion } from '../command-skills.js';
@@ -179,57 +179,6 @@ export function discoverSkillsFromRepo(repoPath) {
179
179
  }
180
180
  return skills;
181
181
  }
182
- export function installSkill(sourcePath, skillName, agents, method = 'symlink') {
183
- const metadata = parseSkillMetadata(sourcePath);
184
- const validation = validateSkillMetadata(metadata, skillName);
185
- if (!validation.valid) {
186
- return {
187
- success: false,
188
- error: `Invalid skill: ${validation.errors.join(', ')}`,
189
- warnings: validation.warnings,
190
- };
191
- }
192
- ensureCentralSkillsDir();
193
- const centralPath = path.join(getSkillsDir(), skillName);
194
- if (!fs.existsSync(centralPath)) {
195
- try {
196
- fs.cpSync(sourcePath, centralPath, { recursive: true });
197
- }
198
- catch (err) {
199
- return { success: false, error: `Failed to copy skill: ${err.message}` };
200
- }
201
- }
202
- for (const agentId of agents) {
203
- if (!isCapable(agentId, 'skills')) {
204
- continue;
205
- }
206
- ensureSkillsDir(agentId);
207
- const agentSkillPath = path.join(getAgentSkillsDir(agentId), skillName);
208
- if (fs.existsSync(agentSkillPath)) {
209
- try {
210
- fs.rmSync(agentSkillPath, { recursive: true, force: true });
211
- }
212
- catch {
213
- }
214
- }
215
- try {
216
- if (method === 'symlink') {
217
- fs.symlinkSync(centralPath, agentSkillPath, 'dir');
218
- }
219
- else {
220
- fs.cpSync(centralPath, agentSkillPath, { recursive: true });
221
- }
222
- }
223
- catch (err) {
224
- return {
225
- success: false,
226
- error: `Failed to ${method} skill to ${agentId}: ${err.message}`,
227
- };
228
- }
229
- }
230
- emit('skill.install', { skill: skillName, agents });
231
- return { success: true };
232
- }
233
182
  export function skillExists(agentId, skillName) {
234
183
  const agentSkillPath = path.join(getAgentSkillsDir(agentId), skillName);
235
184
  return fs.existsSync(agentSkillPath);
@@ -261,30 +210,6 @@ function directoriesMatch(dir1, dir2) {
261
210
  return false;
262
211
  }
263
212
  }
264
- export function skillContentMatches(agentId, skillName, sourcePath) {
265
- const installedPath = path.join(getAgentSkillsDir(agentId), skillName);
266
- if (!fs.existsSync(installedPath) || !fs.existsSync(sourcePath)) {
267
- return false;
268
- }
269
- try {
270
- const installedSkillMd = path.join(installedPath, 'SKILL.md');
271
- const sourceSkillMd = path.join(sourcePath, 'SKILL.md');
272
- if (!fs.existsSync(installedSkillMd) || !fs.existsSync(sourceSkillMd)) {
273
- return false;
274
- }
275
- const installedContent = fs.readFileSync(installedSkillMd, 'utf-8');
276
- const sourceContent = fs.readFileSync(sourceSkillMd, 'utf-8');
277
- if (normalizeContent(installedContent) !== normalizeContent(sourceContent)) {
278
- return false;
279
- }
280
- const installedRulesDir = path.join(installedPath, 'rules');
281
- const sourceRulesDir = path.join(sourcePath, 'rules');
282
- return directoriesMatch(installedRulesDir, sourceRulesDir);
283
- }
284
- catch {
285
- return false;
286
- }
287
- }
288
213
  export function listCentralSkills() {
289
214
  const seen = new Set();
290
215
  for (const dir of [getUserSkillsDir(), getSystemSkillsDir()]) {
@@ -404,94 +329,6 @@ export function diffVersionSkills(agent, version) {
404
329
  }
405
330
  return { agent, version, toAdd: toAdd.sort(), toUpdate: toUpdate.sort(), matched, orphans: orphans.sort() };
406
331
  }
407
- function walkRelativeFiles(base) {
408
- const out = new Set();
409
- if (!fs.existsSync(base))
410
- return out;
411
- const stack = [''];
412
- while (stack.length > 0) {
413
- const rel = stack.pop();
414
- const abs = path.join(base, rel);
415
- let entries;
416
- try {
417
- entries = fs.readdirSync(abs, { withFileTypes: true });
418
- }
419
- catch {
420
- continue;
421
- }
422
- for (const entry of entries) {
423
- const childRel = rel ? path.join(rel, entry.name) : entry.name;
424
- if (entry.isDirectory()) {
425
- stack.push(childRel);
426
- }
427
- else if (entry.isFile()) {
428
- out.add(childRel);
429
- }
430
- }
431
- }
432
- return out;
433
- }
434
- export function installSkillToVersion(agent, version, skillName, method = 'copy') {
435
- const sourcePath = resolveSkillSourcePath(skillName);
436
- if (!sourcePath) {
437
- return { success: false, error: `Skill '${skillName}' not found in central or any extra repo` };
438
- }
439
- const skillsDir = getVersionSkillsDir(agent, version);
440
- if (!fs.existsSync(skillsDir)) {
441
- fs.mkdirSync(skillsDir, { recursive: true });
442
- }
443
- const target = path.join(skillsDir, skillName);
444
- const preserved = [];
445
- if (method === 'copy' && fs.existsSync(target) && !fs.lstatSync(target).isSymbolicLink()) {
446
- const sourceFiles = walkRelativeFiles(sourcePath);
447
- const installedFiles = walkRelativeFiles(target);
448
- for (const rel of installedFiles) {
449
- if (sourceFiles.has(rel))
450
- continue;
451
- try {
452
- const abs = path.join(target, rel);
453
- preserved.push({
454
- rel,
455
- buf: fs.readFileSync(abs),
456
- mode: fs.statSync(abs).mode,
457
- });
458
- }
459
- catch {
460
- }
461
- }
462
- }
463
- if (fs.existsSync(target) || fs.lstatSync(target, { throwIfNoEntry: false })) {
464
- try {
465
- fs.rmSync(target, { recursive: true, force: true });
466
- }
467
- catch (err) {
468
- return { success: false, error: `Failed to remove existing: ${err.message}` };
469
- }
470
- }
471
- try {
472
- if (method === 'symlink') {
473
- fs.symlinkSync(sourcePath, target, 'dir');
474
- }
475
- else {
476
- fs.cpSync(sourcePath, target, { recursive: true });
477
- }
478
- }
479
- catch (err) {
480
- return { success: false, error: `Failed to ${method}: ${err.message}` };
481
- }
482
- for (const { rel, buf, mode } of preserved) {
483
- try {
484
- const dest = path.join(target, rel);
485
- fs.mkdirSync(path.dirname(dest), { recursive: true });
486
- fs.writeFileSync(dest, buf);
487
- fs.chmodSync(dest, mode);
488
- }
489
- catch {
490
- }
491
- }
492
- emit('skill.install', { skill: skillName, agent, version });
493
- return { success: true };
494
- }
495
332
  export function removeSkillFromVersion(agent, version, skillName) {
496
333
  const target = path.join(getVersionSkillsDir(agent, version), skillName);
497
334
  if (!fs.existsSync(target) && !fs.lstatSync(target, { throwIfNoEntry: false })) {
@@ -3,8 +3,7 @@ import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
  import chalk from 'chalk';
5
5
  import { expandLocalHome } from './project-root.js';
6
- import { getRepoCommit, getRemoteUrl, pullRepo } from './git.js';
7
- import { parseOwnerRepoFromRemote } from './registry.js';
6
+ import { getRepoCommit, getRemoteUrl, parseOwnerRepoFromRemote, pullRepo } from './git.js';
8
7
  import { machineId } from './machine-id.js';
9
8
  export function fingerprintTargets(targets) {
10
9
  const lines = targets
@@ -1,6 +1,6 @@
1
1
  import type { AgentId } from './types.js';
2
2
  import { type SkillParseError } from './plugins/skills.js';
3
- export type ResourceKind = 'commands' | 'skills' | 'hooks' | 'rules' | 'mcp' | 'clis' | 'permissions' | 'subagents' | 'workflows' | 'profiles' | 'routers' | 'secrets';
3
+ export type ResourceKind = 'commands' | 'skills' | 'hooks' | 'rules' | 'mcp' | 'clis' | 'permissions' | 'subagents' | 'workflows' | 'profiles' | 'secrets';
4
4
  export interface ResolvedResource {
5
5
  name: string;
6
6
  path: string;
@@ -5,7 +5,7 @@ import * as yaml from 'yaml';
5
5
  import { execFileSync } from 'child_process';
6
6
  import { getProjectAgentsDir, getProjectRoutinesDir, ensureAgentsDir, } from './state.js';
7
7
  import { readJob, writeJob, deleteJob, listJobs, validateJob, } from './scheduling/routines.js';
8
- import { parseOwnerRepoFromRemote } from './registry.js';
8
+ import { parseOwnerRepoFromRemote } from './git.js';
9
9
  import { listProjectDefs, projectDirsAbs } from './projects.js';
10
10
  import { isSafeSegmentName } from './paths.js';
11
11
  export function expandProjectPath(p) {
@@ -30,7 +30,7 @@ async function attachLiveTmuxAlias(selector) {
30
30
  return false;
31
31
  if (!process.stdout.isTTY) {
32
32
  console.error(chalk.red(`"${selector}" is a live tmux session, but attaching needs a TTY.`));
33
- console.error(chalk.gray(` Run it from a terminal, or: agents tmux attach ${selector}`));
33
+ console.error(chalk.gray(` Run it from a terminal, or: tmux -S ${socket} attach -t =${selector}`));
34
34
  process.exitCode = 1;
35
35
  return true;
36
36
  }
@@ -81,7 +81,7 @@ export async function attachLocalLiveSelector(selector, hosts) {
81
81
  return false;
82
82
  if (found.kind === 'collision') {
83
83
  console.error(chalk.red(`"${selector}" matches ${found.aliases.length} live local panes: ${found.aliases.join(', ')}`));
84
- console.error(chalk.gray(' Pass the full alias to disambiguate — see: agents tmux ls'));
84
+ console.error(chalk.gray(` Pass the full alias to disambiguate — see: tmux -S ${getDefaultSocketPath()} ls`));
85
85
  process.exitCode = 1;
86
86
  return true;
87
87
  }
@@ -1,16 +1,15 @@
1
1
  const LOADED_COMMAND_NAMES = [
2
2
  'accounts', 'auth', 'view', 'inspect', 'commands', 'hooks', 'skills', 'rules', 'memory',
3
3
  'permissions', 'mcp', 'clis', 'subagents', 'plugins', 'workflows', 'add', 'use',
4
- 'remove', 'rm', 'purge', 'update', 'prune', 'import', 'registry', 'search', 'install', 'packages',
4
+ 'remove', 'rm', 'purge', 'update', 'prune', 'import',
5
5
  'routines', 'projects', 'run', '_callback', 'open', 'fork', 'config',
6
- 'models', 'trash', 'doctor',
7
- 'route', 'routes', 'harness', 'harnesses', 'secrets', 'menubar', 'sync',
6
+ 'models', 'doctor',
7
+ 'harness', 'harnesses', 'secrets', 'menubar', 'sync',
8
8
  'refresh-rules', 'factory', 'insights', 'trace',
9
- 'tmux', 'watchdog', 'browser', 'computer', 'logs', 'events',
9
+ 'watchdog', 'browser', 'computer', 'events',
10
10
  'ssh', 'devices', 'fleet', 'repos', 'repo', 'setup', 'uninstall', 'upgrade', 'sessions',
11
- 'teams', 'cloud', 'message', 'ps', 'send', 'feed',
12
- 'mailboxes', 'mailbox', 'webhooks',
13
- 'daemon', 'traces', 'recordings',
11
+ 'teams', 'cloud', 'ps', 'send', 'feed',
12
+ 'daemon', 'recordings',
14
13
  ];
15
14
  const INLINE_COMMAND_NAMES = [
16
15
  'perms', 'exec', 'jobs', 'cron', 'check', 'resources', 'hq', '_internal',
@@ -56,6 +55,20 @@ export const RETIRED_TOP_LEVEL_COMMANDS = new Set([
56
55
  'modes',
57
56
  'feedback',
58
57
  'restore',
58
+ 'route',
59
+ 'routes',
60
+ 'registry',
61
+ 'packages',
62
+ 'search',
63
+ 'install',
64
+ 'tmux',
65
+ 'message',
66
+ 'mailboxes',
67
+ 'mailbox',
68
+ 'traces',
69
+ 'webhooks',
70
+ 'logs',
71
+ 'trash',
59
72
  ]);
60
73
  export function isKnownTopLevelCommand(name) {
61
74
  return KNOWN_TOP_LEVEL_COMMANDS.has(name);
@@ -1402,7 +1402,7 @@ export class AgentManager {
1402
1402
  }
1403
1403
  if (agent.cloudProvider) {
1404
1404
  throw new Error(`Teammate '${who}' is a ${agent.cloudProvider} cloud task — resume it with ` +
1405
- `\`agents message ${agent.cloudSessionId ?? agent.agentId} "<message>"\` instead.`);
1405
+ `\`agents cloud message ${agent.cloudSessionId ?? agent.agentId} "<message>"\` instead.`);
1406
1406
  }
1407
1407
  if (agent.agentType !== 'claude' && !agent.remoteSessionId) {
1408
1408
  throw new Error(`No resumable session id was captured for ${agent.agentType} teammate '${who}' — ` +
@@ -1,9 +1,18 @@
1
+ import { type DeviceStats } from '../devices/health.js';
1
2
  import { type AgentType } from './agents.js';
2
3
  import type { DevicePlacementSignal } from './scheduler.js';
3
4
  export declare const READY_PROBE_TIMEOUT_MS = 8000;
4
5
  export declare const SIGNAL_TTL_MS = 15000;
5
6
  export declare function clearPlacementSignalCache(): void;
7
+ interface ReadinessInfo {
8
+ answered: boolean;
9
+ installed: boolean | undefined;
10
+ signedIn: boolean | undefined;
11
+ pickerEligible: boolean | undefined;
12
+ }
13
+ export declare function mergePlacementSignal(stats: DeviceStats | undefined, readiness: ReadinessInfo | undefined): DevicePlacementSignal;
6
14
  export declare function probePoolSignals(pool: string[], agent?: AgentType, opts?: {
7
15
  force?: boolean;
8
16
  now?: number;
9
17
  }): Promise<Map<string, DevicePlacementSignal>>;
18
+ export {};
@@ -18,7 +18,7 @@ export function clearPlacementSignalCache() {
18
18
  cache.clear();
19
19
  }
20
20
  function probeRemoteReadiness(device, agent, usagePayload) {
21
- const unknown = { installed: undefined, signedIn: undefined, pickerEligible: undefined };
21
+ const unknown = { answered: false, installed: undefined, signedIn: undefined, pickerEligible: undefined };
22
22
  let args;
23
23
  let env;
24
24
  try {
@@ -60,17 +60,30 @@ function probeRemoteReadiness(device, agent, usagePayload) {
60
60
  if (!probe.reachable)
61
61
  return finish(unknown);
62
62
  if (!probe.version)
63
- return finish({ installed: false, signedIn: false, pickerEligible: false });
63
+ return finish({ answered: true, installed: false, signedIn: false, pickerEligible: false });
64
64
  const installed = viewHasAgent(probe.view, agent);
65
65
  const eligibility = installed
66
66
  ? viewAgentAccountEligibility(probe.view, agent)
67
67
  : { signedIn: false, pickerEligible: false };
68
- finish({ installed, ...eligibility });
68
+ finish({ answered: true, installed, ...eligibility });
69
69
  });
70
70
  child.stdin.on('error', () => { });
71
71
  child.stdin.end(usagePayload);
72
72
  });
73
73
  }
74
+ export function mergePlacementSignal(stats, readiness) {
75
+ const reachable = readiness?.answered === true ? true : stats?.reachable;
76
+ return {
77
+ reachable,
78
+ timedOut: reachable === true ? undefined : stats?.timedOut,
79
+ headroom: stats ? headroom(stats) : undefined,
80
+ loadPercent: stats?.loadPercent,
81
+ memPercent: stats?.memPercent,
82
+ installed: readiness?.installed,
83
+ signedIn: readiness?.signedIn,
84
+ pickerEligible: readiness?.pickerEligible,
85
+ };
86
+ }
74
87
  export async function probePoolSignals(pool, agent, opts = {}) {
75
88
  const now = opts.now ?? Date.now();
76
89
  const key = cacheKey(pool, agent);
@@ -98,13 +111,14 @@ export async function probePoolSignals(pool, agent, opts = {}) {
98
111
  if (isSelf) {
99
112
  const inst = checkCliAvailable(agent)[0];
100
113
  if (!inst)
101
- return [d.name, { installed: false, signedIn: false, pickerEligible: false }];
114
+ return [d.name, { answered: true, installed: false, signedIn: false, pickerEligible: false }];
102
115
  const candidates = await collectRunCandidates(agent).catch(() => null);
103
116
  if (!candidates) {
104
- return [d.name, { installed: true, signedIn: undefined, pickerEligible: undefined }];
117
+ return [d.name, { answered: true, installed: true, signedIn: undefined, pickerEligible: undefined }];
105
118
  }
106
119
  const readiness = candidates.map((candidate) => readinessFromCandidate(candidate));
107
120
  return [d.name, {
121
+ answered: true,
108
122
  installed: true,
109
123
  signedIn: readiness.some((candidate) => candidate.ready),
110
124
  pickerEligible: readiness.some((candidate) => candidate.ready || isSignInRecoverable(candidate)),
@@ -120,16 +134,7 @@ export async function probePoolSignals(pool, agent, opts = {}) {
120
134
  const inst = d ? installed.get(d.name) : undefined;
121
135
  if (!s && !inst)
122
136
  continue;
123
- signals.set(name, {
124
- reachable: s?.reachable,
125
- timedOut: s?.timedOut,
126
- headroom: s ? headroom(s) : undefined,
127
- loadPercent: s?.loadPercent,
128
- memPercent: s?.memPercent,
129
- installed: inst?.installed,
130
- signedIn: inst?.signedIn,
131
- pickerEligible: inst?.pickerEligible,
132
- });
137
+ signals.set(name, mergePlacementSignal(s, inst));
133
138
  }
134
139
  cache.set(key, { at: now, signals });
135
140
  return signals;
@@ -1,8 +1,5 @@
1
- import * as http from 'http';
2
- import type { IncomingHttpHeaders } from 'http';
3
- import type { JobConfig, RunMeta, WebhookContext } from '../scheduling/routines.js';
4
- import { type FiredHandler } from './handlers.js';
5
- export type WebhookSource = 'github' | 'linear' | 'slack';
1
+ import type { JobConfig, RunMeta } from '../scheduling/routines.js';
2
+ export type WebhookSource = 'github' | 'linear';
6
3
  export interface IncomingWebhook {
7
4
  source: WebhookSource;
8
5
  event: string;
@@ -20,64 +17,10 @@ export declare function matchJobsToWebhook(jobs: JobConfig[], webhook: IncomingW
20
17
  export interface FireWebhookOptions {
21
18
  jobs?: JobConfig[];
22
19
  dispatch?: (config: JobConfig) => Promise<RunMeta>;
23
- skipJobNames?: ReadonlySet<string>;
24
- onJobFired?: (job: JobConfig, fired: FiredJob) => void;
25
- context?: WebhookContext;
26
20
  }
27
21
  interface FiredJob {
28
22
  jobName: string;
29
23
  runId: string;
30
24
  }
31
25
  export declare function fireWebhookJobs(webhook: IncomingWebhook, options?: FireWebhookOptions): Promise<FiredJob[]>;
32
- export declare function verifyGithubSignature(headers: IncomingHttpHeaders, rawBody: Buffer, secret: string): boolean;
33
- export declare function verifyLinearSignature(headers: IncomingHttpHeaders, rawBody: Buffer, secret: string): boolean;
34
- export declare function verifySlackSignature(headers: IncomingHttpHeaders, rawBody: Buffer, secret: string, now?: number, toleranceSec?: number): boolean;
35
- export interface SlackPayload extends Record<string, unknown> {
36
- type: string;
37
- challenge?: string;
38
- event_id?: string;
39
- event_type?: string;
40
- text?: string;
41
- channel?: string;
42
- thread_ts?: string;
43
- user?: string;
44
- command?: string;
45
- response_url?: string;
46
- team?: string;
47
- }
48
- export declare function parseSlackBody(contentType: string | undefined, rawBody: Buffer): SlackPayload;
49
- export declare function slackEventName(payload: SlackPayload): string;
50
- export interface WebhookSecrets {
51
- github?: string;
52
- linear?: string;
53
- slack?: string;
54
- }
55
- interface DeliveryStore {
56
- seen(id: string): boolean;
57
- mark(id: string): void;
58
- completedJobs(id: string): ReadonlySet<string>;
59
- markJob(id: string, jobName: string): void;
60
- }
61
- export declare function createFileDeliveryStore(filePath: string, retentionMs?: number): DeliveryStore;
62
- interface RateLimiter {
63
- take(key: string): boolean;
64
- }
65
- export declare function waitForListening(server: http.Server): Promise<void>;
66
- interface WebhookServerOptions {
67
- port?: number;
68
- host?: string;
69
- secrets: WebhookSecrets;
70
- fire?: FireWebhookOptions;
71
- onMatch?: (webhook: IncomingWebhook, matchedJobNames: string[], matchedHandlerNames: string[]) => void;
72
- onDelivery?: (webhook: IncomingWebhook, fired: FiredJob[], handlers: FiredHandler[]) => void;
73
- onDeliveryError?: (webhook: IncomingWebhook, error: Error) => void;
74
- deliveryStore?: DeliveryStore;
75
- rateLimiter?: RateLimiter;
76
- rateLimitPerMinute?: number;
77
- maxBodyBytes?: number;
78
- ipRateLimiter?: RateLimiter;
79
- ipRateLimitPerMinute?: number;
80
- maxConnections?: number;
81
- }
82
- export declare function startWebhookServer(options: WebhookServerOptions): http.Server;
83
26
  export {};