@phnx-labs/agents-cli 1.22.122 → 1.22.124

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 (194) hide show
  1. package/CHANGELOG.md +288 -0
  2. package/README.md +49 -10
  3. package/dist/bootstrap.js +22 -17
  4. package/dist/cli/command-registry.d.ts +0 -1
  5. package/dist/cli/command-registry.js +2 -10
  6. package/dist/commands/auth.js +13 -4
  7. package/dist/commands/browser.js +3 -4
  8. package/dist/commands/cloud-transcripts.d.ts +7 -0
  9. package/dist/commands/cloud-transcripts.js +100 -0
  10. package/dist/commands/cloud.js +5 -0
  11. package/dist/commands/computer.d.ts +0 -12
  12. package/dist/commands/computer.js +14 -124
  13. package/dist/commands/config.js +5 -4
  14. package/dist/commands/daemon-index.d.ts +2 -0
  15. package/dist/commands/daemon-index.js +44 -0
  16. package/dist/commands/daemon.js +6 -0
  17. package/dist/commands/doctor.js +3 -4
  18. package/dist/commands/exec.d.ts +5 -0
  19. package/dist/commands/exec.js +35 -7
  20. package/dist/commands/feed-watch.js +12 -0
  21. package/dist/commands/feed.d.ts +1 -1
  22. package/dist/commands/feed.js +7 -4
  23. package/dist/commands/insights.js +3 -1
  24. package/dist/commands/inspect.js +1 -1
  25. package/dist/commands/logs.js +2 -1
  26. package/dist/commands/models.js +1 -1
  27. package/dist/commands/prune.js +6 -28
  28. package/dist/commands/ps-roster.d.ts +0 -1
  29. package/dist/commands/ps-roster.js +2 -21
  30. package/dist/commands/ps.js +13 -1
  31. package/dist/commands/recordings.d.ts +2 -0
  32. package/dist/commands/recordings.js +117 -0
  33. package/dist/commands/routines.js +1 -1
  34. package/dist/commands/secrets-passthrough.js +3 -3
  35. package/dist/commands/send.js +33 -20
  36. package/dist/commands/sessions-backfill.d.ts +1 -0
  37. package/dist/commands/sessions-backfill.js +48 -13
  38. package/dist/commands/sessions-migrate.d.ts +1 -1
  39. package/dist/commands/sessions-migrate.js +11 -10
  40. package/dist/commands/sessions-optimize.d.ts +1 -0
  41. package/dist/commands/sessions-optimize.js +7 -4
  42. package/dist/commands/sessions-resume.js +8 -1
  43. package/dist/commands/sessions-stats.d.ts +2 -0
  44. package/dist/commands/sessions-stats.js +24 -7
  45. package/dist/commands/sessions.d.ts +5 -11
  46. package/dist/commands/sessions.js +8 -236
  47. package/dist/commands/setup-computer.js +1 -2
  48. package/dist/commands/setup.js +1 -1
  49. package/dist/commands/teams.js +2 -2
  50. package/dist/commands/testdata/feed-hub.d.ts +1 -0
  51. package/dist/commands/testdata/feed-hub.js +11 -0
  52. package/dist/commands/trash.d.ts +0 -1
  53. package/dist/commands/trash.js +74 -10
  54. package/dist/lib/accounting/usage-sync.js +7 -0
  55. package/dist/lib/agent-modes.d.ts +1 -1
  56. package/dist/lib/agent-modes.js +11 -5
  57. package/dist/lib/auth-mint.d.ts +4 -0
  58. package/dist/lib/auth-mint.js +6 -4
  59. package/dist/lib/browser/native-history.test-fixture.d.ts +12 -0
  60. package/dist/lib/browser/native-history.test-fixture.js +43 -0
  61. package/dist/lib/browser/paths.d.ts +5 -0
  62. package/dist/lib/browser/paths.js +7 -1
  63. package/dist/lib/browser/sessions-list.d.ts +28 -1
  64. package/dist/lib/browser/sessions-list.js +137 -25
  65. package/dist/lib/channels/providers/rush.d.ts +2 -1
  66. package/dist/lib/channels/providers/rush.js +2 -2
  67. package/dist/lib/channels/providers/session.d.ts +1 -0
  68. package/dist/lib/channels/providers/session.js +23 -12
  69. package/dist/lib/channels/registry.d.ts +9 -2
  70. package/dist/lib/channels/send.d.ts +5 -10
  71. package/dist/lib/channels/send.js +88 -50
  72. package/dist/lib/cloud/rush.d.ts +6 -0
  73. package/dist/lib/cloud/rush.js +18 -3
  74. package/dist/lib/computer-client.d.ts +19 -0
  75. package/dist/lib/computer-client.js +104 -0
  76. package/dist/lib/config-keys.d.ts +5 -1
  77. package/dist/lib/config-keys.js +14 -11
  78. package/dist/lib/daemon/auth-sync-service.js +13 -0
  79. package/dist/lib/daemon/daemon.js +20 -8
  80. package/dist/lib/daemon/owner-device-delivery-service.d.ts +10 -0
  81. package/dist/lib/daemon/owner-device-delivery-service.js +28 -0
  82. package/dist/lib/daemon-services.d.ts +2 -1
  83. package/dist/lib/daemon-services.js +17 -5
  84. package/dist/lib/device-config.d.ts +4 -1
  85. package/dist/lib/device-config.js +57 -7
  86. package/dist/lib/devices/doctor-findings.d.ts +2 -3
  87. package/dist/lib/devices/doctor-findings.js +10 -19
  88. package/dist/lib/event-provenance.d.ts +1 -0
  89. package/dist/lib/event-provenance.js +2 -0
  90. package/dist/lib/exec.d.ts +1 -0
  91. package/dist/lib/exec.js +20 -15
  92. package/dist/lib/feed/pr-status.d.ts +5 -1
  93. package/dist/lib/feed/pr-status.js +44 -3
  94. package/dist/lib/feed/tool-activity.js +9 -6
  95. package/dist/lib/feed/tools.d.ts +4 -1
  96. package/dist/lib/feed/tools.js +8 -11
  97. package/dist/lib/feed-broadcast.d.ts +5 -3
  98. package/dist/lib/feed-broadcast.js +47 -36
  99. package/dist/lib/fleet-shared-state.d.ts +5 -0
  100. package/dist/lib/fleet-shared-state.js +8 -0
  101. package/dist/lib/github/project-prs.d.ts +4 -1
  102. package/dist/lib/github/project-prs.js +18 -5
  103. package/dist/lib/help.d.ts +1 -0
  104. package/dist/lib/help.js +8 -0
  105. package/dist/lib/helper-versions.js +1 -1
  106. package/dist/lib/hosts/passthrough.js +5 -8
  107. package/dist/lib/hosts/remote-cmd.d.ts +2 -7
  108. package/dist/lib/hosts/remote-cmd.js +14 -22
  109. package/dist/lib/hosts/routing-flag.d.ts +22 -0
  110. package/dist/lib/hosts/routing-flag.js +127 -14
  111. package/dist/lib/identity/index.d.ts +22 -0
  112. package/dist/lib/identity/index.js +3 -0
  113. package/dist/lib/installations/migrate.d.ts +7 -0
  114. package/dist/lib/installations/migrate.js +101 -88
  115. package/dist/lib/installations/versions.js +2 -2
  116. package/dist/lib/launch-identity.d.ts +6 -1
  117. package/dist/lib/launch-identity.js +12 -2
  118. package/dist/lib/menubar/install-menubar.d.ts +1 -0
  119. package/dist/lib/menubar/install-menubar.js +8 -5
  120. package/dist/lib/menubar/snapshot.js +2 -3
  121. package/dist/lib/notify.d.ts +7 -14
  122. package/dist/lib/notify.js +29 -75
  123. package/dist/lib/owner-message.d.ts +4 -6
  124. package/dist/lib/owner-message.js +12 -11
  125. package/dist/lib/owner-notify-tokens.d.ts +49 -0
  126. package/dist/lib/owner-notify-tokens.js +214 -0
  127. package/dist/lib/owner-notify.d.ts +75 -0
  128. package/dist/lib/owner-notify.js +144 -0
  129. package/dist/lib/recordings/config.d.ts +11 -0
  130. package/dist/lib/recordings/config.js +54 -0
  131. package/dist/lib/recordings/identity.d.ts +12 -0
  132. package/dist/lib/recordings/identity.js +57 -0
  133. package/dist/lib/recordings/ledger.d.ts +16 -0
  134. package/dist/lib/recordings/ledger.js +141 -0
  135. package/dist/lib/recordings/model.d.ts +29 -0
  136. package/dist/lib/recordings/model.js +28 -0
  137. package/dist/lib/recordings/pipeline.d.ts +44 -0
  138. package/dist/lib/recordings/pipeline.js +272 -0
  139. package/dist/lib/recordings/process.d.ts +17 -0
  140. package/dist/lib/recordings/process.js +94 -0
  141. package/dist/lib/recordings/service.d.ts +15 -0
  142. package/dist/lib/recordings/service.js +45 -0
  143. package/dist/lib/recordings/settle.d.ts +21 -0
  144. package/dist/lib/recordings/settle.js +92 -0
  145. package/dist/lib/recordings/transcode.d.ts +13 -0
  146. package/dist/lib/recordings/transcode.js +44 -0
  147. package/dist/lib/reminders.d.ts +0 -1
  148. package/dist/lib/reminders.js +1 -1
  149. package/dist/lib/reserved-stores.d.ts +3 -0
  150. package/dist/lib/reserved-stores.js +13 -0
  151. package/dist/lib/routine-notify-owner.d.ts +3 -23
  152. package/dist/lib/routine-notify-owner.js +26 -107
  153. package/dist/lib/rush-api.d.ts +1 -0
  154. package/dist/lib/rush-api.js +1 -0
  155. package/dist/lib/session/active.d.ts +18 -2
  156. package/dist/lib/session/active.js +47 -37
  157. package/dist/lib/session/cloud.js +18 -45
  158. package/dist/lib/session/db.d.ts +2 -0
  159. package/dist/lib/session/db.js +13 -4
  160. package/dist/lib/session/glance-files.d.ts +4 -3
  161. package/dist/lib/session/glance-files.js +31 -0
  162. package/dist/lib/session/inject-target.js +12 -2
  163. package/dist/lib/session/pid-registry.d.ts +2 -0
  164. package/dist/lib/session/pid-registry.js +6 -2
  165. package/dist/lib/session/presentation.d.ts +21 -0
  166. package/dist/lib/session/presentation.js +198 -0
  167. package/dist/lib/session/projection.js +9 -2
  168. package/dist/lib/sqlite.d.ts +3 -1
  169. package/dist/lib/sqlite.js +7 -3
  170. package/dist/lib/standalone-tools.js +1 -1
  171. package/dist/lib/startup/command-registry.js +9 -4
  172. package/dist/lib/state.d.ts +2 -2
  173. package/dist/lib/state.js +3 -5
  174. package/dist/lib/terminal/inject.js +1 -1
  175. package/dist/lib/testdata/owner-notify-api.d.ts +36 -0
  176. package/dist/lib/testdata/owner-notify-api.js +102 -0
  177. package/dist/lib/trash.d.ts +14 -0
  178. package/dist/lib/trash.js +75 -0
  179. package/dist/lib/types.d.ts +0 -34
  180. package/package.json +2 -2
  181. package/dist/commands/feedback.d.ts +0 -2
  182. package/dist/commands/feedback.js +0 -68
  183. package/dist/commands/humans.d.ts +0 -2
  184. package/dist/commands/humans.js +0 -83
  185. package/dist/commands/modes.d.ts +0 -2
  186. package/dist/commands/modes.js +0 -134
  187. package/dist/commands/reminders.d.ts +0 -2
  188. package/dist/commands/reminders.js +0 -49
  189. package/dist/lib/channels/owner-forward.d.ts +0 -25
  190. package/dist/lib/channels/owner-forward.js +0 -78
  191. package/dist/lib/channels/owner-sink.d.ts +0 -10
  192. package/dist/lib/channels/owner-sink.js +0 -26
  193. package/dist/lib/humans.d.ts +0 -12
  194. package/dist/lib/humans.js +0 -64
@@ -16,9 +16,11 @@ import { enabledRoutineNames, replaceEnabledRoutines } from '../routine-activati
16
16
  import { evaluateActivationReadiness } from '../routine-readiness.js';
17
17
  import { migrateDeviceConfigStores } from '../devices/config-migration.js';
18
18
  import { detrackViaGitExclude } from '../project-resources.js';
19
- import { META_HEADER as DEVICE_META_HEADER } from '../state.js';
19
+ import { META_HEADER as DEVICE_META_HEADER, commitCentralConfig } from '../state.js';
20
20
  const LEGACY_DEFAULT_BROWSER_PROFILE_NAME = 'default';
21
21
  import { COMPILED_HEADER_PROJECT } from '../rules/compile.js';
22
+ import { putOwnerPreferences, resolveOwnerCredential } from '../owner-notify.js';
23
+ import { moveFileToTrash } from '../trash.js';
22
24
  const HOME = process.env.HOME ?? os.homedir();
23
25
  const USER_DIR = path.join(HOME, '.agents');
24
26
  const SYSTEM_DIR = path.join(USER_DIR, '.system');
@@ -1605,99 +1607,110 @@ export function migrateCliDirToClis(agentsDirs) {
1605
1607
  fs.renameSync(src, dest);
1606
1608
  }
1607
1609
  }
1608
- function migrateHumans() {
1609
- const humansFile = path.join(USER_DIR, 'humans.yaml');
1610
- if (fs.existsSync(humansFile))
1611
- return;
1612
- const agentsYamlPath = path.join(USER_DIR, 'agents.yaml');
1613
- const ownerMdPath = path.join(USER_DIR, 'owner.md');
1614
- let notifyOwner;
1615
- let ownerName;
1616
- let ownerTimezone;
1617
- let ownerQuietHours;
1618
- let ownerDefaultSeverity;
1619
- let ownerChannels;
1620
- let ownerPolicy;
1621
- if (fs.existsSync(agentsYamlPath)) {
1622
- try {
1623
- const raw = fs.readFileSync(agentsYamlPath, 'utf-8');
1624
- const doc = yaml.parse(raw);
1625
- const notify = doc?.['notify'];
1626
- const owner = notify?.['owner'];
1627
- const channel = typeof owner?.['channel'] === 'string' ? owner['channel'] : undefined;
1628
- const to = typeof owner?.['to'] === 'string' ? owner['to'] : undefined;
1629
- if (channel && to) {
1630
- notifyOwner = { channel, to };
1631
- }
1610
+ export const LEGACY_HUMANS_FILE = 'humans.yaml';
1611
+ const SEVERITY_EVENTS = {
1612
+ critical: ['needs_you'],
1613
+ normal: ['failed', 'message'],
1614
+ low: ['completed'],
1615
+ };
1616
+ function accountChannelFor(transport) {
1617
+ const t = transport.trim().toLowerCase();
1618
+ return t === 'imessage' || t === 'slack' || t === 'email' ? t : null;
1619
+ }
1620
+ export function humansToPreferencesPatch(doc) {
1621
+ const owner = (doc && typeof doc === 'object' ? doc.owner : undefined);
1622
+ const rawChannels = Array.isArray(owner?.channels) ? owner.channels : [];
1623
+ const legacy = owner?.notify;
1624
+ const channels = rawChannels.length > 0
1625
+ ? rawChannels
1626
+ : (typeof legacy?.channel === 'string' ? [{ id: legacy.channel, transport: legacy.channel, to: legacy.to }] : []);
1627
+ const byId = new Map();
1628
+ const dropped = [];
1629
+ let imessageAddress;
1630
+ for (const entry of channels) {
1631
+ if (typeof entry.id !== 'string')
1632
+ continue;
1633
+ const transport = typeof entry.transport === 'string' ? entry.transport : entry.id;
1634
+ const channel = accountChannelFor(entry.id);
1635
+ if (!channel) {
1636
+ dropped.push(`${entry.id} (${transport})`);
1637
+ continue;
1632
1638
  }
1633
- catch { }
1634
- }
1635
- if (fs.existsSync(ownerMdPath)) {
1636
- try {
1637
- const raw = fs.readFileSync(ownerMdPath, 'utf-8');
1638
- const fmMatch = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
1639
- if (fmMatch) {
1640
- const fm = yaml.parse(fmMatch[1]);
1641
- if (fm && typeof fm === 'object') {
1642
- if (typeof fm['name'] === 'string')
1643
- ownerName = fm['name'];
1644
- if (typeof fm['timezone'] === 'string')
1645
- ownerTimezone = fm['timezone'];
1646
- if (typeof fm['quiet_hours'] === 'string')
1647
- ownerQuietHours = fm['quiet_hours'];
1648
- if (typeof fm['default_severity'] === 'string')
1649
- ownerDefaultSeverity = fm['default_severity'];
1650
- if (Array.isArray(fm['channels']))
1651
- ownerChannels = fm['channels'];
1652
- if (fm['policy'] && typeof fm['policy'] === 'object')
1653
- ownerPolicy = fm['policy'];
1639
+ byId.set(entry.id, channel);
1640
+ if (channel === 'imessage' && typeof entry.to === 'string' && entry.to.trim())
1641
+ imessageAddress ??= entry.to.trim();
1642
+ }
1643
+ const policy = (owner?.policy ?? {});
1644
+ const [firstChannel] = byId.keys();
1645
+ const preferences = [];
1646
+ if (byId.size > 0) {
1647
+ for (const severity of ['critical', 'normal', 'low']) {
1648
+ const listed = Array.isArray(policy[severity])
1649
+ ? policy[severity].filter((id) => typeof id === 'string')
1650
+ : (severity === 'low' ? [] : [firstChannel]);
1651
+ const enabled = new Set(listed.map((id) => byId.get(id)).filter((c) => Boolean(c)));
1652
+ for (const event of SEVERITY_EVENTS[severity]) {
1653
+ for (const channel of ['email', 'slack', 'imessage']) {
1654
+ preferences.push({ event, channel, enabled: enabled.has(channel) });
1654
1655
  }
1655
1656
  }
1656
1657
  }
1657
- catch { }
1658
1658
  }
1659
- if (!notifyOwner && !ownerName && !ownerTimezone && !ownerQuietHours && !ownerDefaultSeverity && !ownerChannels && !ownerPolicy)
1660
- return;
1661
- const humansDoc = { version: 1 };
1662
- const ownerDoc = {};
1663
- if (ownerName)
1664
- ownerDoc['name'] = ownerName;
1665
- if (ownerTimezone)
1666
- ownerDoc['timezone'] = ownerTimezone;
1667
- if (ownerQuietHours)
1668
- ownerDoc['quiet_hours'] = ownerQuietHours;
1669
- if (ownerDefaultSeverity)
1670
- ownerDoc['default_severity'] = ownerDefaultSeverity;
1671
- if (notifyOwner)
1672
- ownerDoc['notify'] = notifyOwner;
1673
- if (ownerChannels)
1674
- ownerDoc['channels'] = ownerChannels;
1675
- if (ownerPolicy)
1676
- ownerDoc['policy'] = ownerPolicy;
1677
- humansDoc['owner'] = ownerDoc;
1678
- try {
1679
- const header = '# humans.yaml — owner identity and notification channels\n# Managed by agents-cli. See: agents humans --help\n';
1680
- fs.writeFileSync(humansFile, header + yaml.stringify(humansDoc, { lineWidth: 120 }), { encoding: 'utf-8', mode: 0o600 });
1681
- console.error('Migrated owner config to humans.yaml');
1682
- }
1683
- catch (err) {
1684
- console.error(`humans.yaml migration: could not write (${err.message})`);
1685
- return;
1659
+ const patch = {};
1660
+ if (preferences.length > 0)
1661
+ patch.preferences = preferences;
1662
+ const settings = {};
1663
+ if (typeof owner?.timezone === 'string' && owner.timezone.trim())
1664
+ settings.timezone = owner.timezone.trim();
1665
+ const quiet = typeof owner?.quietHours === 'string' ? owner.quietHours.match(/^\s*(\d{1,2}:\d{2})\s*-\s*(\d{1,2}:\d{2})\s*$/) : null;
1666
+ if (quiet) {
1667
+ settings.quietStart = quiet[1].padStart(5, '0');
1668
+ settings.quietEnd = quiet[2].padStart(5, '0');
1669
+ }
1670
+ else if (typeof owner?.quietHours === 'string' && owner.quietHours.trim()) {
1671
+ dropped.push(`quietHours '${owner.quietHours}' (expected HH:MM-HH:MM)`);
1672
+ }
1673
+ if (owner?.quiet_hours !== undefined)
1674
+ dropped.push(`quiet_hours (older key; set quietHours or use console Settings)`);
1675
+ if (Object.keys(settings).length > 0)
1676
+ patch.settings = settings;
1677
+ if (imessageAddress)
1678
+ patch.destinations = { imessage: { address: imessageAddress } };
1679
+ return { patch, dropped };
1680
+ }
1681
+ const HUMANS_RETRY_MS = 60 * 60_000;
1682
+ export async function migrateHumansToAccount(userDir = USER_DIR, failureStamp = path.join(CACHE_DIR, 'humans-migration-failed')) {
1683
+ const humansFile = path.join(userDir, LEGACY_HUMANS_FILE);
1684
+ if (!fs.existsSync(humansFile))
1685
+ return 'absent';
1686
+ if (resolveOwnerCredential()?.kind !== 'session')
1687
+ return 'pending';
1688
+ try {
1689
+ if (Date.now() - fs.statSync(failureStamp).mtimeMs < HUMANS_RETRY_MS)
1690
+ return 'pending';
1686
1691
  }
1687
- if (notifyOwner && fs.existsSync(agentsYamlPath)) {
1688
- try {
1689
- const raw = fs.readFileSync(agentsYamlPath, 'utf-8');
1690
- const doc = yaml.parseDocument(raw);
1691
- const notifyNode = doc.get('notify');
1692
- if (notifyNode instanceof yaml.YAMLMap) {
1693
- notifyNode.delete('owner');
1694
- if (notifyNode.items.length === 0)
1695
- doc.delete('notify');
1696
- }
1697
- fs.writeFileSync(agentsYamlPath, stringifyDoc(doc), 'utf-8');
1698
- }
1699
- catch { }
1692
+ catch { }
1693
+ const { patch, dropped } = humansToPreferencesPatch(yaml.parse(fs.readFileSync(humansFile, 'utf-8')));
1694
+ try {
1695
+ if (Object.keys(patch).length > 0)
1696
+ await putOwnerPreferences(patch);
1700
1697
  }
1698
+ catch (err) {
1699
+ fs.mkdirSync(path.dirname(failureStamp), { recursive: true });
1700
+ fs.writeFileSync(failureStamp, `${err.message}\n`);
1701
+ console.error(`humans.yaml migration: ${err.message} The file is kept and the upload retries in an hour.`);
1702
+ return 'pending';
1703
+ }
1704
+ fs.rmSync(failureStamp, { force: true });
1705
+ const trashed = moveFileToTrash(humansFile);
1706
+ const committed = commitCentralConfig(userDir, LEGACY_HUMANS_FILE, 'chore(config): humans.yaml moved to account notification preferences');
1707
+ console.error(`Moved owner notification settings from ${humansFile} to your account (console Settings). Old file: ${trashed}`);
1708
+ if (!committed && fs.existsSync(path.join(userDir, '.git'))) {
1709
+ console.error(`Could not commit the removal of ${LEGACY_HUMANS_FILE}; commit and push it with: agents repo push`);
1710
+ }
1711
+ if (dropped.length > 0)
1712
+ console.error(`No account equivalent, not migrated: ${dropped.join(', ')}`);
1713
+ return 'migrated';
1701
1714
  }
1702
1715
  export function seedActiveCursorLoginPerVersion() {
1703
1716
  const realHome = process.env.AGENTS_REAL_HOME || os.homedir();
@@ -1848,7 +1861,7 @@ export async function runMigration() {
1848
1861
  cliMigrateDirs.push(projectDotAgents);
1849
1862
  migrateCliDirToClis(cliMigrateDirs);
1850
1863
  migrateAgentsYaml();
1851
- migrateHumans();
1864
+ await migrateHumansToAccount();
1852
1865
  deleteSystemPromptsJson();
1853
1866
  migrateSystemConfigJson();
1854
1867
  detrackUserChangelog();
@@ -1302,10 +1302,10 @@ export function printTrashFooter(moved) {
1302
1302
  console.log(chalk.gray('Sessions remain accessible via `agents sessions`.'));
1303
1303
  if (moved.length === 1) {
1304
1304
  const { agent, version } = moved[0];
1305
- console.log(chalk.gray(`Restore with: agents restore ${agent}@${version}`));
1305
+ console.log(chalk.gray(`Restore with: agents trash restore ${agent}@${version}`));
1306
1306
  }
1307
1307
  else {
1308
- console.log(chalk.gray('Restore with: agents restore <agent>@<version> (run `agents trash list` to see)'));
1308
+ console.log(chalk.gray('Restore with: agents trash restore <agent>@<version> (run `agents trash list` to see)'));
1309
1309
  }
1310
1310
  }
1311
1311
  export function removeAllVersions(agent) {
@@ -1,2 +1,7 @@
1
1
  export declare function launchIdentityEnv(env?: NodeJS.ProcessEnv): Record<string, string>;
2
- export declare const LAUNCH_IDENTITY_KEYS: readonly ["AGENT_TERMINAL_ID", "AGENT_SESSION_ID", "AGENTS_SESSION_ID", "AGENTS_MAILBOX_DIR", "AGENT_LAUNCH_ID", "AGENTS_PARENT_SESSION_ID", "AGENTS_PARENT_LAUNCH_ID", "AGENTS_ORIGIN_TERMINAL_ID"];
2
+ export interface LaunchOrigin {
3
+ device: string;
4
+ terminalId: string;
5
+ }
6
+ export declare function launchOrigin(identity?: Record<string, string>): LaunchOrigin | undefined;
7
+ export declare const LAUNCH_IDENTITY_KEYS: readonly ["AGENT_TERMINAL_ID", "AGENT_SESSION_ID", "AGENTS_SESSION_ID", "AGENTS_MAILBOX_DIR", "AGENT_LAUNCH_ID", "AGENTS_PARENT_SESSION_ID", "AGENTS_PARENT_LAUNCH_ID", "AGENTS_ORIGIN_TERMINAL_ID", "AGENTS_ORIGIN_DEVICE"];
@@ -1,12 +1,16 @@
1
+ import { machineId } from './machine-id.js';
1
2
  export function launchIdentityEnv(env = process.env) {
2
3
  const result = {};
3
4
  const terminal = env.AGENT_TERMINAL_ID?.trim();
4
5
  const nested = env.AGENTS_RUNTIME === 'terminal' || env.AGENTS_RUNTIME === 'headless' || env.AGENTS_RUNTIME === 'teams';
5
6
  if (terminal && !nested)
6
7
  result.AGENT_TERMINAL_ID = terminal;
7
- const originTerminal = env.AGENTS_ORIGIN_TERMINAL_ID?.trim() || terminal;
8
- if (originTerminal)
8
+ const inheritedTerminal = env.AGENTS_ORIGIN_TERMINAL_ID?.trim();
9
+ const originTerminal = inheritedTerminal || terminal;
10
+ if (originTerminal) {
9
11
  result.AGENTS_ORIGIN_TERMINAL_ID = originTerminal;
12
+ result.AGENTS_ORIGIN_DEVICE = (inheritedTerminal && env.AGENTS_ORIGIN_DEVICE?.trim()) || machineId();
13
+ }
10
14
  const parentLaunch = nested ? env.AGENT_LAUNCH_ID : env.AGENTS_PARENT_LAUNCH_ID;
11
15
  const parentSession = nested
12
16
  ? env.AGENTS_SESSION_ID || env.AGENT_SESSION_ID
@@ -17,7 +21,13 @@ export function launchIdentityEnv(env = process.env) {
17
21
  result.AGENTS_PARENT_SESSION_ID = parentSession;
18
22
  return result;
19
23
  }
24
+ export function launchOrigin(identity = launchIdentityEnv()) {
25
+ const device = identity.AGENTS_ORIGIN_DEVICE;
26
+ const terminalId = identity.AGENTS_ORIGIN_TERMINAL_ID;
27
+ return device && terminalId && identity.AGENT_TERMINAL_ID ? { device, terminalId } : undefined;
28
+ }
20
29
  export const LAUNCH_IDENTITY_KEYS = [
21
30
  'AGENT_TERMINAL_ID', 'AGENT_SESSION_ID', 'AGENTS_SESSION_ID', 'AGENTS_MAILBOX_DIR',
22
31
  'AGENT_LAUNCH_ID', 'AGENTS_PARENT_SESSION_ID', 'AGENTS_PARENT_LAUNCH_ID', 'AGENTS_ORIGIN_TERMINAL_ID',
32
+ 'AGENTS_ORIGIN_DEVICE',
23
33
  ];
@@ -71,6 +71,7 @@ export declare function mayInstallMenubarHelper(opts: {
71
71
  cooldownMs: number;
72
72
  sourceIsDeveloperId: boolean;
73
73
  }): boolean;
74
+ export declare function menubarGateVersion(source: string | null, cached?: () => string): string;
74
75
  export declare function installMenubarLaunchAgentOnUpgrade(): void;
75
76
  export declare function shouldMigrateMenubarTcc(opts: {
76
77
  needsDevIdHeal: boolean;
@@ -493,9 +493,12 @@ function stampMenubarHeal() {
493
493
  }
494
494
  catch { }
495
495
  }
496
- function mayHealMenubar(needsDevIdHeal) {
496
+ export function menubarGateVersion(source, cached = availableHelperLabel) {
497
+ return source ? stampVersionLabel(stampFor(source)) ?? LOCAL_BUILD_LABEL : cached();
498
+ }
499
+ function mayHealMenubar(needsDevIdHeal, source = sourceAppPath()) {
497
500
  const plistEntry = readPlistEnvValue('AGENTS_ENTRY');
498
- const src = sourceAppPath();
501
+ const src = source;
499
502
  return mayInstallMenubarHelper({
500
503
  plistEntry,
501
504
  activeEntry: resolveCliEntry(),
@@ -503,7 +506,7 @@ function mayHealMenubar(needsDevIdHeal) {
503
506
  helperExecMissing: !fs.existsSync(installedExecutablePath()),
504
507
  needsDevIdHeal,
505
508
  installedVersion: stampVersionLabel(readInstalledMenubarStamp()),
506
- currentVersion: availableHelperLabel(),
509
+ currentVersion: menubarGateVersion(src),
507
510
  msSinceLastHeal: msSinceLastMenubarHeal(),
508
511
  cooldownMs: MENUBAR_TAKEOVER_COOLDOWN_MS,
509
512
  sourceIsDeveloperId: Boolean(src) && hasDeveloperIdSignature(src),
@@ -807,12 +810,12 @@ export async function updateMenubarHelperIfNewer(opts = {}) {
807
810
  if (menubarUpdateOutcome(release.helperVersion, available) === 'current') {
808
811
  return { outcome: 'current', installed, available, detail: `AGI Menu ${installed} is the newest published build` };
809
812
  }
810
- if (!mayHealMenubar(false))
811
- return skip(`another install owns the helper; it will update on its own cooldown`, available);
812
813
  if (opts.dryRun)
813
814
  return { outcome: 'updated', installed, available, detail: `would update AGI Menu ${installed} → ${available}` };
814
815
  try {
815
816
  const src = await downloadMenubarHelperApp(available);
817
+ if (!mayHealMenubar(false, src))
818
+ return skip(`another install owns the helper; it will update on its own cooldown`, available);
816
819
  const exec = ensureMenubarAppInstalled({ forceReinstall: true, sourceAppPath: src });
817
820
  if (!exec)
818
821
  return { outcome: 'failed', installed, available, detail: 'the verified bundle could not be installed' };
@@ -8,7 +8,7 @@ import { backfillActiveRowsFromIndex, isRunningLiveSession, serializeActiveSessi
8
8
  import { getConfigValue, listConfiguredDeviceRoles, loadAutoLaunchPreferences } from '../device-config.js';
9
9
  import { filterAutoPool } from '../devices/pool.js';
10
10
  import { isFreshDeviceStats, readStatsCache } from '../devices/stats-cache.js';
11
- import { MENUBAR_MENU_PROPERTIES } from '../config-keys.js';
11
+ import { MENUBAR_CONFIG_KEYS } from '../config-keys.js';
12
12
  import { migrateMenubarPreferencesFromUserDefaults } from './migrate-prefs.js';
13
13
  import { loadDevices } from '../devices/registry.js';
14
14
  import { machineId } from '../machine-id.js';
@@ -53,8 +53,7 @@ export function buildMenuListPreferences() {
53
53
  }
54
54
  function effectiveMenuPreferences() {
55
55
  const out = [];
56
- for (const prop of MENUBAR_MENU_PROPERTIES) {
57
- const name = `menubar.menu.${prop}`;
56
+ for (const name of MENUBAR_CONFIG_KEYS) {
58
57
  const entry = getConfigValue(name);
59
58
  const value = entry.value !== undefined ? entry.value : entry.spec.defaultValue;
60
59
  if (value === undefined)
@@ -1,17 +1,6 @@
1
1
  import type { OpenBlock } from './feed/feed.js';
2
- import type { Meta } from './types.js';
3
2
  import type { SendResult } from './channels/registry.js';
4
- import { type SinkMessageFormat } from './sink-format.js';
5
- export interface OwnerNotifyOptions {
6
- meta?: Meta;
7
- channel?: string;
8
- target?: string;
9
- dryRun?: boolean;
10
- thread?: string;
11
- attachments?: string[];
12
- from?: string;
13
- composeForFormat?: (format: SinkMessageFormat) => string;
14
- }
3
+ import { type OwnerNotification } from './owner-notify.js';
15
4
  export interface NotifyResult {
16
5
  ok: boolean;
17
6
  skipped?: boolean;
@@ -23,5 +12,9 @@ export declare function buildOpenClawNotifyArgs(text: string, opts: {
23
12
  channel?: string;
24
13
  account?: string;
25
14
  }): string[];
26
- export declare function sendToOwner(text: string, options?: OwnerNotifyOptions): Promise<SendResult>;
27
- export declare function notifyUrgentBlock(block: OpenBlock, options?: OwnerNotifyOptions): Promise<NotifyResult>;
15
+ export declare function sendToOwner(notification: OwnerNotification, options?: {
16
+ dryRun?: boolean;
17
+ }): Promise<SendResult>;
18
+ export declare function notifyUrgentBlock(block: OpenBlock, options?: {
19
+ dryRun?: boolean;
20
+ }): Promise<NotifyResult>;
@@ -1,9 +1,4 @@
1
- import { readMeta } from './state.js';
2
- import { getOwnerNotifyDestinationsFromHumans } from './humans.js';
3
- import { registerBuiltinProviders } from './channels/providers/index.js';
4
- import { lookupTransport } from './channels/resolve.js';
5
- import { forwardOwnerNotifyToPeer } from './channels/owner-forward.js';
6
- import { sinkMessageFormat } from './sink-format.js';
1
+ import { describeOwnerResult, postOwnerNotification, resolveOwnerCredential, OwnerNotSignedInError, } from './owner-notify.js';
7
2
  export function formatUrgentBlockMessage(block) {
8
3
  const q = block.questions[0];
9
4
  const header = q?.header ? `[${q.header}] ` : '';
@@ -29,78 +24,28 @@ export function buildOpenClawNotifyArgs(text, opts) {
29
24
  text,
30
25
  ];
31
26
  }
32
- export async function sendToOwner(text, options = {}) {
33
- const meta = options.meta ?? readMeta();
34
- const canonical = getOwnerNotifyDestinationsFromHumans();
35
- const legacy = meta.notify?.owner ? [meta.notify.owner] : [];
36
- const configured = canonical.length > 0 ? canonical : legacy;
37
- const destinations = options.target
38
- ? [{ channel: options.channel ?? configured[0]?.channel, to: options.target }]
39
- : options.channel
40
- ? [configured.find((dest) => dest.channel === options.channel) ?? {
41
- channel: options.channel,
42
- to: configured[0]?.to,
43
- }]
44
- : configured;
45
- const addressable = destinations.filter((dest) => Boolean(dest.channel && dest.to));
46
- if (addressable.length === 0) {
27
+ export async function sendToOwner(notification, options = {}) {
28
+ try {
29
+ if (options.dryRun) {
30
+ if (!resolveOwnerCredential())
31
+ throw new OwnerNotSignedInError();
32
+ return { ok: true, channel: 'owner', id: notification.dedupKey, body: notification.body };
33
+ }
34
+ const result = await postOwnerNotification(notification);
35
+ const partial = result.skipped.length > 0 && result.delivered.length + result.queued.length > 0;
36
+ const reachedNobody = result.suppressed === null && result.delivered.length + result.queued.length === 0;
47
37
  return {
48
- ok: false,
49
- channel: options.channel ?? 'unknown',
50
- id: options.target ?? '',
51
- error: 'No addressable owner channel configured in humans.yaml or legacy notify.owner',
38
+ ok: !reachedNobody,
39
+ channel: 'owner',
40
+ id: result.dispatchId ?? notification.dedupKey,
41
+ body: notification.body,
42
+ msgId: describeOwnerResult(result),
43
+ ...(partial || reachedNobody ? { error: describeOwnerResult(result) } : {}),
52
44
  };
53
45
  }
54
- registerBuiltinProviders();
55
- const deliveries = [];
56
- for (const { channel, to: target } of addressable) {
57
- const { provider, providerName, error } = lookupTransport(channel, meta);
58
- const body = options.composeForFormat
59
- ? options.composeForFormat(sinkMessageFormat(providerName))
60
- : text;
61
- let result;
62
- try {
63
- result = provider
64
- ? await provider.send(body, {
65
- target,
66
- ownerScoped: options.target === undefined,
67
- dryRun: options.dryRun,
68
- thread: options.thread,
69
- attachments: options.attachments,
70
- from: options.from,
71
- })
72
- : { ok: false, channel, id: target, error };
73
- }
74
- catch (err) {
75
- result = { ok: false, channel, id: target, error: err.message };
76
- }
77
- if (!result.ok && !options.dryRun && options.target === undefined) {
78
- if (options.attachments?.length) {
79
- result = {
80
- ...result,
81
- error: `${result.error ?? 'local delivery failed'}; owner attachments cannot be forwarded to another device`,
82
- };
83
- }
84
- else {
85
- result = await forwardOwnerNotifyToPeer(body, channel, target, meta, {
86
- envelope: { thread: options.thread, from: options.from },
87
- }) ?? result;
88
- }
89
- }
90
- deliveries.push({ ...result, body });
46
+ catch (err) {
47
+ return { ok: false, channel: 'owner', id: notification.dedupKey, error: err.message };
91
48
  }
92
- if (deliveries.length === 1)
93
- return deliveries[0];
94
- const failures = deliveries.filter((result) => !result.ok);
95
- return {
96
- ok: deliveries.some((result) => result.ok),
97
- channel: 'owner',
98
- id: deliveries.map((result) => `${result.channel}:${result.id}`).join(','),
99
- ...(failures.length > 0
100
- ? { error: failures.map((result) => `${result.channel}: ${result.error ?? 'failed'}`).join('; ') }
101
- : {}),
102
- deliveries,
103
- };
104
49
  }
105
50
  export async function notifyUrgentBlock(block, options = {}) {
106
51
  if (block.notifiedAt) {
@@ -109,6 +54,15 @@ export async function notifyUrgentBlock(block, options = {}) {
109
54
  if (options.dryRun) {
110
55
  return { ok: true, skipped: true };
111
56
  }
112
- const result = await sendToOwner(formatUrgentBlockMessage(block), options);
57
+ const q = block.questions[0];
58
+ const result = await sendToOwner({
59
+ event: 'needs_you',
60
+ title: q?.header?.trim() || 'Agent needs input',
61
+ body: formatUrgentBlockMessage(block),
62
+ sessionId: block.sessionId,
63
+ ...(block.ticket ? { ticket: block.ticket } : {}),
64
+ dedupKey: `block:${block.blockId}`,
65
+ source: { device: block.host },
66
+ });
113
67
  return result.ok ? { ok: true } : { ok: false, error: result.error };
114
68
  }
@@ -1,9 +1,7 @@
1
- import type { SinkMessageFormat } from './sink-format.js';
1
+ import type { OwnerNotification } from './owner-notify.js';
2
2
  interface OwnerMessageOptions {
3
- title?: string;
4
- sessionId?: string;
5
- format?: SinkMessageFormat;
3
+ agent?: string;
4
+ url?: string;
6
5
  }
7
- export declare function composeOwnerMessage(rawText: string, opts?: OwnerMessageOptions): string;
8
- export declare function ownerMessageComposer(rawText: string, opts?: OwnerMessageOptions): (format: SinkMessageFormat) => string;
6
+ export declare function ownerMessageNotification(rawText: string, opts?: OwnerMessageOptions): OwnerNotification;
9
7
  export {};
@@ -1,25 +1,26 @@
1
- import { composeBroadcastMessage } from './feed-broadcast.js';
1
+ import { randomUUID } from 'crypto';
2
+ import { ownerNotificationFromContext } from './feed-broadcast.js';
2
3
  import { resolvePostIdentity } from './feed-post.js';
3
4
  import { getSessionById, resolveFullSessionId } from './session/db.js';
4
5
  import { linearIssueUrl } from '@phnx-labs/sessions-cli/reader';
5
- function ownerMessageContext(rawText, opts = {}) {
6
- const identity = resolvePostIdentity({ sessionId: opts.sessionId });
6
+ function ownerMessageContext(rawText, opts) {
7
+ const identity = resolvePostIdentity({});
7
8
  const session = resolveFullSessionId(identity?.sessionId);
8
9
  const ticket = session ? getSessionById(session)?.ticketId : undefined;
10
+ const agent = opts.agent ?? identity?.agent;
9
11
  return {
10
- ...(opts.title?.trim() ? { title: opts.title.trim() } : {}),
11
12
  text: rawText,
12
13
  level: 'important',
13
14
  ...(ticket ? { ticket, ticketUrl: linearIssueUrl(ticket) } : {}),
14
- ...(identity?.agent ? { agent: identity.agent } : {}),
15
+ ...(agent ? { agent } : {}),
15
16
  ...(identity?.host ? { host: identity.host } : {}),
16
17
  ...(session ? { session } : {}),
18
+ ...(opts.url ? { links: [opts.url] } : {}),
17
19
  };
18
20
  }
19
- export function composeOwnerMessage(rawText, opts = {}) {
20
- return composeBroadcastMessage(ownerMessageContext(rawText, opts), opts.format ?? 'plain');
21
- }
22
- export function ownerMessageComposer(rawText, opts = {}) {
23
- const ctx = ownerMessageContext(rawText, opts);
24
- return (format) => composeBroadcastMessage(ctx, format);
21
+ export function ownerMessageNotification(rawText, opts = {}) {
22
+ const notification = ownerNotificationFromContext(ownerMessageContext(rawText, opts), 'message', `send:${randomUUID()}`);
23
+ if (!notification)
24
+ throw new Error('Message is empty.');
25
+ return notification;
25
26
  }
@@ -0,0 +1,49 @@
1
+ import type { PushBundleResult } from './secrets-types.js';
2
+ import { type DeviceProfile } from './devices/registry.js';
3
+ import { selfConfiguredDeviceRole } from './device-config.js';
4
+ export declare const OWNER_NOTIFY_PEER_FRESH_MS: number;
5
+ type Role = ReturnType<typeof selfConfiguredDeviceRole>;
6
+ export declare function publishOwnerNotifyState(opts?: {
7
+ device?: string;
8
+ userAgentsDir?: string;
9
+ }): Promise<{
10
+ signedIn: boolean;
11
+ deviceToken: boolean;
12
+ changed: boolean;
13
+ }>;
14
+ export declare function electOwnerNotifyMinter(signedInHeaded: readonly string[]): string | null;
15
+ interface OwnerNotifySyncResult {
16
+ minter: string | null;
17
+ minted: string[];
18
+ pushed: string[];
19
+ revoked: string[];
20
+ skipped: Array<{
21
+ device: string;
22
+ reason: string;
23
+ }>;
24
+ errors: Array<{
25
+ device: string;
26
+ message: string;
27
+ }>;
28
+ }
29
+ interface OwnerNotifySyncDeps {
30
+ localName?: string;
31
+ userAgentsDir?: string;
32
+ cacheDir?: string;
33
+ listDevices?: () => DeviceProfile[];
34
+ selfRole?: () => Role;
35
+ peerRole?: (name: string) => Role;
36
+ isPinned?: (name: string) => boolean;
37
+ push?: (bundle: string, host: string) => Promise<PushBundleResult>;
38
+ sshTarget?: (device: DeviceProfile) => string;
39
+ now?: () => number;
40
+ }
41
+ export declare function syncOwnerNotifyTokens(deps?: OwnerNotifySyncDeps): Promise<OwnerNotifySyncResult>;
42
+ export declare function revokeMintedOwnerNotifyTokens(cacheDir?: string): Promise<{
43
+ revoked: string[];
44
+ errors: Array<{
45
+ device: string;
46
+ message: string;
47
+ }>;
48
+ }>;
49
+ export {};