@phnx-labs/agents-cli 1.22.121 → 1.22.123

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 (247) hide show
  1. package/CHANGELOG.md +316 -0
  2. package/README.md +53 -53
  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 -12
  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 +13 -8
  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/mailboxes.js +1 -1
  27. package/dist/commands/models.js +1 -1
  28. package/dist/commands/projects.js +3 -3
  29. package/dist/commands/prune.js +6 -28
  30. package/dist/commands/ps-roster.d.ts +0 -1
  31. package/dist/commands/ps-roster.js +2 -21
  32. package/dist/commands/ps.js +13 -1
  33. package/dist/commands/recordings.d.ts +2 -0
  34. package/dist/commands/recordings.js +117 -0
  35. package/dist/commands/routines.js +1 -1
  36. package/dist/commands/secrets-passthrough.js +3 -3
  37. package/dist/commands/send.js +33 -20
  38. package/dist/commands/sessions-backfill.d.ts +1 -0
  39. package/dist/commands/sessions-backfill.js +48 -13
  40. package/dist/commands/sessions-migrate.d.ts +1 -1
  41. package/dist/commands/sessions-migrate.js +11 -10
  42. package/dist/commands/sessions-optimize.d.ts +1 -0
  43. package/dist/commands/sessions-optimize.js +7 -4
  44. package/dist/commands/sessions-resume.js +8 -1
  45. package/dist/commands/sessions-stats.d.ts +2 -0
  46. package/dist/commands/sessions-stats.js +24 -7
  47. package/dist/commands/sessions.d.ts +5 -11
  48. package/dist/commands/sessions.js +8 -236
  49. package/dist/commands/setup-computer.js +1 -2
  50. package/dist/commands/setup-mine.js +0 -1
  51. package/dist/commands/setup.js +1 -1
  52. package/dist/commands/sync.js +101 -1
  53. package/dist/commands/teams.js +2 -2
  54. package/dist/commands/testdata/feed-hub.js +11 -0
  55. package/dist/commands/trash.d.ts +0 -1
  56. package/dist/commands/trash.js +74 -10
  57. package/dist/lib/accounting/usage-sync.js +7 -0
  58. package/dist/lib/agent-modes.d.ts +1 -1
  59. package/dist/lib/agent-modes.js +11 -5
  60. package/dist/lib/auth-mint.d.ts +4 -0
  61. package/dist/lib/auth-mint.js +6 -4
  62. package/dist/lib/browser/native-history.test-fixture.d.ts +12 -0
  63. package/dist/lib/browser/native-history.test-fixture.js +43 -0
  64. package/dist/lib/browser/paths.d.ts +5 -0
  65. package/dist/lib/browser/paths.js +7 -1
  66. package/dist/lib/browser/sessions-list.d.ts +28 -1
  67. package/dist/lib/browser/sessions-list.js +137 -25
  68. package/dist/lib/channels/providers/rush.d.ts +2 -1
  69. package/dist/lib/channels/providers/rush.js +2 -2
  70. package/dist/lib/channels/providers/session.d.ts +1 -0
  71. package/dist/lib/channels/providers/session.js +23 -12
  72. package/dist/lib/channels/registry.d.ts +9 -2
  73. package/dist/lib/channels/send.d.ts +5 -10
  74. package/dist/lib/channels/send.js +88 -50
  75. package/dist/lib/cloud/rush.d.ts +6 -0
  76. package/dist/lib/cloud/rush.js +18 -3
  77. package/dist/lib/computer-client.d.ts +19 -0
  78. package/dist/lib/computer-client.js +104 -0
  79. package/dist/lib/config-keys.d.ts +5 -1
  80. package/dist/lib/config-keys.js +14 -11
  81. package/dist/lib/daemon/auth-sync-service.js +13 -0
  82. package/dist/lib/daemon/daemon.js +20 -23
  83. package/dist/lib/daemon/owner-device-delivery-service.d.ts +10 -0
  84. package/dist/lib/daemon/owner-device-delivery-service.js +28 -0
  85. package/dist/lib/daemon-services.d.ts +2 -1
  86. package/dist/lib/daemon-services.js +17 -10
  87. package/dist/lib/daemon-webhooks.d.ts +1 -1
  88. package/dist/lib/daemon-webhooks.js +1 -1
  89. package/dist/lib/device-config.d.ts +4 -1
  90. package/dist/lib/device-config.js +58 -8
  91. package/dist/lib/devices/doctor-findings.d.ts +2 -3
  92. package/dist/lib/devices/doctor-findings.js +10 -19
  93. package/dist/lib/event-provenance.d.ts +1 -0
  94. package/dist/lib/event-provenance.js +2 -0
  95. package/dist/lib/exec.d.ts +1 -0
  96. package/dist/lib/exec.js +20 -15
  97. package/dist/lib/feed/pr-status.d.ts +5 -1
  98. package/dist/lib/feed/pr-status.js +44 -3
  99. package/dist/lib/feed/tool-activity.js +9 -6
  100. package/dist/lib/feed/tools.d.ts +4 -1
  101. package/dist/lib/feed/tools.js +8 -11
  102. package/dist/lib/feed-broadcast.d.ts +5 -3
  103. package/dist/lib/feed-broadcast.js +47 -36
  104. package/dist/lib/fleet-shared-state.d.ts +5 -0
  105. package/dist/lib/fleet-shared-state.js +8 -0
  106. package/dist/lib/github/project-prs.d.ts +4 -1
  107. package/dist/lib/github/project-prs.js +20 -7
  108. package/dist/lib/help.d.ts +1 -0
  109. package/dist/lib/help.js +8 -0
  110. package/dist/lib/helper-versions.js +1 -1
  111. package/dist/lib/hosts/passthrough.js +5 -9
  112. package/dist/lib/hosts/remote-cmd.d.ts +2 -7
  113. package/dist/lib/hosts/remote-cmd.js +14 -22
  114. package/dist/lib/hosts/routing-flag.d.ts +22 -0
  115. package/dist/lib/hosts/routing-flag.js +127 -14
  116. package/dist/lib/identity/index.d.ts +22 -0
  117. package/dist/lib/identity/index.js +3 -0
  118. package/dist/lib/installations/migrate.d.ts +7 -0
  119. package/dist/lib/installations/migrate.js +99 -88
  120. package/dist/lib/installations/versions.js +2 -2
  121. package/dist/lib/launch-identity.d.ts +6 -1
  122. package/dist/lib/launch-identity.js +12 -2
  123. package/dist/lib/menubar/install-menubar.d.ts +1 -0
  124. package/dist/lib/menubar/install-menubar.js +8 -5
  125. package/dist/lib/menubar/snapshot.js +2 -3
  126. package/dist/lib/notify.d.ts +7 -14
  127. package/dist/lib/notify.js +29 -75
  128. package/dist/lib/owner-message.d.ts +4 -6
  129. package/dist/lib/owner-message.js +12 -11
  130. package/dist/lib/owner-notify-tokens.d.ts +49 -0
  131. package/dist/lib/owner-notify-tokens.js +214 -0
  132. package/dist/lib/owner-notify.d.ts +75 -0
  133. package/dist/lib/owner-notify.js +144 -0
  134. package/dist/lib/plugins/plugins.d.ts +7 -1
  135. package/dist/lib/plugins/plugins.js +26 -5
  136. package/dist/lib/pr-land-detach.js +2 -2
  137. package/dist/lib/recordings/config.d.ts +11 -0
  138. package/dist/lib/recordings/config.js +54 -0
  139. package/dist/lib/recordings/identity.d.ts +12 -0
  140. package/dist/lib/recordings/identity.js +57 -0
  141. package/dist/lib/recordings/ledger.d.ts +16 -0
  142. package/dist/lib/recordings/ledger.js +141 -0
  143. package/dist/lib/recordings/model.d.ts +29 -0
  144. package/dist/lib/recordings/model.js +28 -0
  145. package/dist/lib/recordings/pipeline.d.ts +44 -0
  146. package/dist/lib/recordings/pipeline.js +272 -0
  147. package/dist/lib/recordings/process.d.ts +17 -0
  148. package/dist/lib/recordings/process.js +94 -0
  149. package/dist/lib/recordings/service.d.ts +15 -0
  150. package/dist/lib/recordings/service.js +45 -0
  151. package/dist/lib/recordings/settle.d.ts +21 -0
  152. package/dist/lib/recordings/settle.js +92 -0
  153. package/dist/lib/recordings/transcode.d.ts +13 -0
  154. package/dist/lib/recordings/transcode.js +44 -0
  155. package/dist/lib/refresh.js +4 -1
  156. package/dist/lib/reminders.d.ts +0 -1
  157. package/dist/lib/reminders.js +1 -1
  158. package/dist/lib/reserved-stores.d.ts +3 -0
  159. package/dist/lib/reserved-stores.js +13 -0
  160. package/dist/lib/routine-notify-owner.d.ts +3 -23
  161. package/dist/lib/routine-notify-owner.js +26 -107
  162. package/dist/lib/rush-api.d.ts +1 -0
  163. package/dist/lib/rush-api.js +1 -0
  164. package/dist/lib/scheduling/routines.d.ts +1 -1
  165. package/dist/lib/scheduling/routines.js +1 -1
  166. package/dist/lib/session/active.d.ts +18 -2
  167. package/dist/lib/session/active.js +47 -37
  168. package/dist/lib/session/cloud.js +18 -45
  169. package/dist/lib/session/db.d.ts +3 -1
  170. package/dist/lib/session/db.js +64 -32
  171. package/dist/lib/session/glance-files.d.ts +4 -3
  172. package/dist/lib/session/glance-files.js +31 -0
  173. package/dist/lib/session/inject-target.js +12 -2
  174. package/dist/lib/session/pid-registry.d.ts +2 -0
  175. package/dist/lib/session/pid-registry.js +6 -2
  176. package/dist/lib/session/presentation.d.ts +21 -0
  177. package/dist/lib/session/presentation.js +198 -0
  178. package/dist/lib/session/projection.js +9 -2
  179. package/dist/lib/sqlite.d.ts +3 -1
  180. package/dist/lib/sqlite.js +7 -3
  181. package/dist/lib/staleness/index.js +12 -0
  182. package/dist/lib/staleness/types.d.ts +5 -0
  183. package/dist/lib/standalone-tools.js +1 -1
  184. package/dist/lib/startup/command-registry.js +10 -5
  185. package/dist/lib/state.d.ts +2 -5
  186. package/dist/lib/state.js +3 -11
  187. package/dist/lib/sync-delete.d.ts +21 -0
  188. package/dist/lib/sync-delete.js +113 -0
  189. package/dist/lib/terminal/inject.js +1 -1
  190. package/dist/lib/testdata/owner-notify-api.d.ts +36 -0
  191. package/dist/lib/testdata/owner-notify-api.js +102 -0
  192. package/dist/lib/trash.d.ts +14 -0
  193. package/dist/lib/trash.js +75 -0
  194. package/dist/lib/types.d.ts +0 -34
  195. package/package.json +1 -3
  196. package/dist/commands/feedback.d.ts +0 -2
  197. package/dist/commands/feedback.js +0 -68
  198. package/dist/commands/humans.d.ts +0 -2
  199. package/dist/commands/humans.js +0 -83
  200. package/dist/commands/modes.d.ts +0 -2
  201. package/dist/commands/modes.js +0 -134
  202. package/dist/commands/monitors.d.ts +0 -2
  203. package/dist/commands/monitors.js +0 -1070
  204. package/dist/commands/reminders.d.ts +0 -2
  205. package/dist/commands/reminders.js +0 -49
  206. package/dist/lib/channels/owner-forward.d.ts +0 -25
  207. package/dist/lib/channels/owner-forward.js +0 -78
  208. package/dist/lib/channels/owner-sink.d.ts +0 -10
  209. package/dist/lib/channels/owner-sink.js +0 -26
  210. package/dist/lib/daemon/monitor-engine-service.d.ts +0 -13
  211. package/dist/lib/daemon/monitor-engine-service.js +0 -25
  212. package/dist/lib/humans.d.ts +0 -12
  213. package/dist/lib/humans.js +0 -64
  214. package/dist/lib/monitors/config.d.ts +0 -77
  215. package/dist/lib/monitors/config.js +0 -405
  216. package/dist/lib/monitors/dispatch.d.ts +0 -10
  217. package/dist/lib/monitors/dispatch.js +0 -72
  218. package/dist/lib/monitors/engine.d.ts +0 -45
  219. package/dist/lib/monitors/engine.js +0 -243
  220. package/dist/lib/monitors/fingerprint.d.ts +0 -3
  221. package/dist/lib/monitors/fingerprint.js +0 -43
  222. package/dist/lib/monitors/pid-watch.d.ts +0 -4
  223. package/dist/lib/monitors/pid-watch.js +0 -14
  224. package/dist/lib/monitors/remote.d.ts +0 -31
  225. package/dist/lib/monitors/remote.js +0 -63
  226. package/dist/lib/monitors/sources/command.d.ts +0 -4
  227. package/dist/lib/monitors/sources/command.js +0 -20
  228. package/dist/lib/monitors/sources/device.d.ts +0 -3
  229. package/dist/lib/monitors/sources/device.js +0 -31
  230. package/dist/lib/monitors/sources/failure.d.ts +0 -5
  231. package/dist/lib/monitors/sources/failure.js +0 -25
  232. package/dist/lib/monitors/sources/file.d.ts +0 -4
  233. package/dist/lib/monitors/sources/file.js +0 -46
  234. package/dist/lib/monitors/sources/http.d.ts +0 -3
  235. package/dist/lib/monitors/sources/http.js +0 -25
  236. package/dist/lib/monitors/sources/index.d.ts +0 -5
  237. package/dist/lib/monitors/sources/index.js +0 -22
  238. package/dist/lib/monitors/sources/poll.d.ts +0 -1
  239. package/dist/lib/monitors/sources/poll.js +0 -1
  240. package/dist/lib/monitors/sources/types.d.ts +0 -9
  241. package/dist/lib/monitors/sources/webhook.d.ts +0 -3
  242. package/dist/lib/monitors/sources/webhook.js +0 -3
  243. package/dist/lib/monitors/sources/ws.d.ts +0 -4
  244. package/dist/lib/monitors/sources/ws.js +0 -35
  245. package/dist/lib/monitors/state.d.ts +0 -51
  246. package/dist/lib/monitors/state.js +0 -221
  247. /package/dist/{lib/monitors/sources/types.js → commands/testdata/feed-hub.d.ts} +0 -0
@@ -1,19 +1,132 @@
1
- export function flagValue(args, long, short) {
2
- for (let i = 0; i < args.length; i++) {
3
- const a = args[i];
4
- if (a === `--${long}` || (short && a === `-${short}`))
5
- return args[i + 1];
6
- if (a.startsWith(`--${long}=`))
7
- return a.slice(long.length + 3);
8
- if (short && a.startsWith(`-${short}=`))
9
- return a.slice(short.length + 2);
10
- if (short && new RegExp(`^-${short}(.+)`).test(a))
11
- return a.slice(2);
1
+ export const HOST_ROUTING_SPECS = [
2
+ { long: 'device', short: 'D', takesValue: true },
3
+ { long: 'host', short: 'H', takesValue: true },
4
+ { long: 'remote-cwd', takesValue: true },
5
+ ];
6
+ export const ROUTING_OPTION_SPECS = [
7
+ ...HOST_ROUTING_SPECS,
8
+ { long: 'no-tty', takesValue: false },
9
+ { long: 'hosts', takesValue: true },
10
+ { long: 'devices', takesValue: true },
11
+ ];
12
+ let commandTree;
13
+ export function setArgvCommandTree(root) {
14
+ commandTree = root;
15
+ }
16
+ function matchRouting(arg, specs) {
17
+ for (const spec of specs) {
18
+ if (arg === `--${spec.long}`)
19
+ return { spec };
20
+ if (arg.startsWith(`--${spec.long}=`))
21
+ return { spec, joined: arg.slice(spec.long.length + 3) };
22
+ if (!spec.short)
23
+ continue;
24
+ if (arg === `-${spec.short}`)
25
+ return { spec };
26
+ if (arg.startsWith(`-${spec.short}=`))
27
+ return { spec, joined: arg.slice(spec.short.length + 2) };
28
+ if (arg.startsWith(`-${spec.short}`))
29
+ return { spec, joined: arg.slice(spec.short.length + 1) };
30
+ }
31
+ return undefined;
32
+ }
33
+ function findOption(chain, flag) {
34
+ for (let c = chain.length - 1; c >= 0; c--) {
35
+ const opt = chain[c].options.find((o) => o.long === flag || o.short === flag);
36
+ if (opt)
37
+ return opt;
12
38
  }
13
39
  return undefined;
14
40
  }
41
+ function lastValueIndex(args, i, opt) {
42
+ const next = (j) => j < args.length && !args[j].startsWith('-');
43
+ let j = i;
44
+ if (opt.required ? i + 1 < args.length : opt.optional && next(i + 1))
45
+ j = i + 1;
46
+ else
47
+ return i;
48
+ if (opt.variadic)
49
+ while (next(j + 1))
50
+ j++;
51
+ return j;
52
+ }
53
+ function lastLongOptionIndex(args, i, chain) {
54
+ const arg = args[i];
55
+ if (arg.includes('='))
56
+ return i;
57
+ const opt = findOption(chain, arg);
58
+ return opt ? lastValueIndex(args, i, opt) : i;
59
+ }
60
+ function scanShortCluster(args, i, chain, specs) {
61
+ const arg = args[i];
62
+ for (let k = 1; k < arg.length; k++) {
63
+ const spec = specs.find((s) => s.short === arg[k]);
64
+ if (spec) {
65
+ const kept = arg.slice(0, k);
66
+ if (!spec.takesValue)
67
+ return { last: i, occurrence: { spec, start: i, end: i, kept: kept + arg.slice(k + 1) } };
68
+ const joined = arg.slice(k + 1).replace(/^=/, '');
69
+ if (joined)
70
+ return { last: i, occurrence: { spec, start: i, end: i, value: joined, kept } };
71
+ const end = i + 1 < args.length ? i + 1 : i;
72
+ return { last: end, occurrence: { spec, start: i, end, value: end > i ? args[end] : undefined, kept } };
73
+ }
74
+ const opt = findOption(chain, `-${arg[k]}`);
75
+ if (!opt)
76
+ return { last: i };
77
+ if (opt.required || opt.optional)
78
+ return { last: k === arg.length - 1 ? lastValueIndex(args, i, opt) : i };
79
+ }
80
+ return { last: i };
81
+ }
82
+ export function scanArgv(args, extra = []) {
83
+ const specs = [...ROUTING_OPTION_SPECS, ...extra.filter((e) => !ROUTING_OPTION_SPECS.some((s) => s.long === e.long))];
84
+ const chain = commandTree ? [commandTree] : [];
85
+ const routing = [];
86
+ let commandIndex;
87
+ let operands = 0;
88
+ let optionsEnded = false;
89
+ for (let i = 0; i < args.length; i++) {
90
+ const arg = args[i];
91
+ if (arg === '--' && !optionsEnded) {
92
+ optionsEnded = true;
93
+ continue;
94
+ }
95
+ if (optionsEnded || arg.length < 2 || !arg.startsWith('-')) {
96
+ commandIndex ??= i;
97
+ const current = chain[chain.length - 1];
98
+ const sub = operands === 0 && current?.commands.find((c) => c.name() === arg || c.aliases().includes(arg));
99
+ if (sub)
100
+ chain.push(sub);
101
+ else if (commandIndex !== i)
102
+ operands++;
103
+ continue;
104
+ }
105
+ const hit = matchRouting(arg, specs);
106
+ if (hit) {
107
+ const takesNext = hit.spec.takesValue && hit.joined === undefined && i + 1 < args.length;
108
+ routing.push({ spec: hit.spec, start: i, end: takesNext ? i + 1 : i, value: hit.joined ?? (takesNext ? args[i + 1] : undefined) });
109
+ if (takesNext)
110
+ i++;
111
+ continue;
112
+ }
113
+ if (arg.startsWith('--')) {
114
+ i = lastLongOptionIndex(args, i, chain);
115
+ continue;
116
+ }
117
+ const cluster = scanShortCluster(args, i, chain, specs);
118
+ if (cluster.occurrence)
119
+ routing.push(cluster.occurrence);
120
+ i = cluster.last;
121
+ }
122
+ return { commandIndex, routing };
123
+ }
124
+ export function commandTokenIndex(args) {
125
+ return scanArgv(args).commandIndex;
126
+ }
127
+ export function flagValue(args, long, short) {
128
+ return scanArgv(args, [{ long, short, takesValue: true }]).routing.find((r) => r.spec.long === long)?.value;
129
+ }
15
130
  export function hasHostRoutingFlag(args) {
16
- return (flagValue(args, 'device', 'D') !== undefined ||
17
- flagValue(args, 'hosts') !== undefined ||
18
- flagValue(args, 'devices') !== undefined);
131
+ return scanArgv(args).routing.some((r) => ['device', 'hosts', 'devices'].includes(r.spec.long) && r.value !== undefined);
19
132
  }
@@ -14,6 +14,9 @@ export interface WhoAmI {
14
14
  valid: true;
15
15
  avatar_url?: string;
16
16
  name?: string;
17
+ tokenKind?: 'session' | 'device';
18
+ scopes?: string[];
19
+ device?: string | null;
17
20
  }
18
21
  export type DevicePoll = {
19
22
  status: 'authorized';
@@ -37,6 +40,25 @@ export type DevicePoll = {
37
40
  export declare function startDeviceAuthorization(): Promise<DeviceAuthorization>;
38
41
  export declare function pollDeviceToken(deviceCode: string): Promise<DevicePoll>;
39
42
  export declare function fetchWhoAmI(token?: string): Promise<WhoAmI>;
43
+ export type DeviceTokenScope = 'notify';
44
+ export interface MintedDeviceToken {
45
+ id: string;
46
+ token: string;
47
+ kind: 'device';
48
+ device: string;
49
+ scopes: DeviceTokenScope[];
50
+ createdAt: string;
51
+ }
52
+ export interface ApiTokenSummary {
53
+ id: string;
54
+ kind: 'session' | 'device';
55
+ device: string | null;
56
+ scopes: string[];
57
+ createdAt: string;
58
+ }
59
+ export declare const mintDeviceToken: (device: string, scopes: DeviceTokenScope[]) => Promise<MintedDeviceToken>;
60
+ export declare const listApiTokens: () => Promise<ApiTokenSummary[]>;
61
+ export declare const revokeApiToken: (id: string) => Promise<void>;
40
62
  export declare function refreshSessionProfile(known?: WhoAmI): Promise<void>;
41
63
  export interface SpaceSummary {
42
64
  id: string;
@@ -33,6 +33,9 @@ export async function pollDeviceToken(deviceCode) {
33
33
  export function fetchWhoAmI(token) {
34
34
  return phoenixRequest('GET', '/api/v1/auth/me', { token });
35
35
  }
36
+ export const mintDeviceToken = (device, scopes) => phoenixRequest('POST', '/api/v1/auth/tokens', { body: { device, scopes } });
37
+ export const listApiTokens = () => phoenixRequest('GET', '/api/v1/auth/tokens');
38
+ export const revokeApiToken = (id) => phoenixRequest('DELETE', `/api/v1/auth/tokens/${encodeURIComponent(id)}`);
36
39
  export async function refreshSessionProfile(known) {
37
40
  const session = readSession();
38
41
  if (!session)
@@ -1,4 +1,5 @@
1
1
  export { foldLegacySystemRepo } from '../migrate-fold.js';
2
+ import { type OwnerPreferencesPatch } from '../owner-notify.js';
2
3
  export declare function migrateAgentsYaml(systemDir?: string, userDir?: string): void;
3
4
  export declare function detrackUserChangelog(userDir?: string): void;
4
5
  export declare function foldBrowserSessionsIntoProfiles(browserDir?: string): void;
@@ -9,6 +10,12 @@ export declare function migrateRoutineDeviceToDevices(routinesDir?: string): voi
9
10
  export declare function migrateRoutineRemoteCwdToCwd(routinesDir?: string): void;
10
11
  export declare function migrateWatchdogSentinelToConfig(sentinelPath?: string, enable?: (value: boolean) => void): void;
11
12
  export declare function migrateCliDirToClis(agentsDirs: string[]): void;
13
+ export declare const LEGACY_HUMANS_FILE = "humans.yaml";
14
+ export declare function humansToPreferencesPatch(doc: unknown): {
15
+ patch: OwnerPreferencesPatch;
16
+ dropped: string[];
17
+ };
18
+ export declare function migrateHumansToAccount(userDir?: string, failureStamp?: string): Promise<'absent' | 'pending' | 'migrated'>;
12
19
  export declare function seedActiveCursorLoginPerVersion(): void;
13
20
  export declare function migrateKimiSubagentsToMarkdown(versionsDir?: string): void;
14
21
  export declare function removeHomeCompiledProjectRules(homeDir?: string): void;
@@ -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,108 @@ 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(transport);
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?.quiet_hours === 'string' ? owner.quiet_hours.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?.quiet_hours === 'string' && owner.quiet_hours.trim()) {
1671
+ dropped.push(`quiet_hours '${owner.quiet_hours}' (expected HH:MM-HH:MM)`);
1672
+ }
1673
+ if (Object.keys(settings).length > 0)
1674
+ patch.settings = settings;
1675
+ if (imessageAddress)
1676
+ patch.destinations = { imessage: { address: imessageAddress } };
1677
+ return { patch, dropped };
1678
+ }
1679
+ const HUMANS_RETRY_MS = 60 * 60_000;
1680
+ export async function migrateHumansToAccount(userDir = USER_DIR, failureStamp = path.join(CACHE_DIR, 'humans-migration-failed')) {
1681
+ const humansFile = path.join(userDir, LEGACY_HUMANS_FILE);
1682
+ if (!fs.existsSync(humansFile))
1683
+ return 'absent';
1684
+ if (resolveOwnerCredential()?.kind !== 'session')
1685
+ return 'pending';
1686
+ try {
1687
+ if (Date.now() - fs.statSync(failureStamp).mtimeMs < HUMANS_RETRY_MS)
1688
+ return 'pending';
1686
1689
  }
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 { }
1690
+ catch { }
1691
+ const { patch, dropped } = humansToPreferencesPatch(yaml.parse(fs.readFileSync(humansFile, 'utf-8')));
1692
+ try {
1693
+ if (Object.keys(patch).length > 0)
1694
+ await putOwnerPreferences(patch);
1700
1695
  }
1696
+ catch (err) {
1697
+ fs.mkdirSync(path.dirname(failureStamp), { recursive: true });
1698
+ fs.writeFileSync(failureStamp, `${err.message}\n`);
1699
+ console.error(`humans.yaml migration: ${err.message} The file is kept and the upload retries in an hour.`);
1700
+ return 'pending';
1701
+ }
1702
+ fs.rmSync(failureStamp, { force: true });
1703
+ const trashed = moveFileToTrash(humansFile);
1704
+ const committed = commitCentralConfig(userDir, LEGACY_HUMANS_FILE, 'chore(config): humans.yaml moved to account notification preferences');
1705
+ console.error(`Moved owner notification settings from ${humansFile} to your account (console Settings). Old file: ${trashed}`);
1706
+ if (!committed && fs.existsSync(path.join(userDir, '.git'))) {
1707
+ console.error(`Could not commit the removal of ${LEGACY_HUMANS_FILE}; commit and push it with: agents repo push`);
1708
+ }
1709
+ if (dropped.length > 0)
1710
+ console.error(`No account equivalent, not migrated: ${dropped.join(', ')}`);
1711
+ return 'migrated';
1701
1712
  }
1702
1713
  export function seedActiveCursorLoginPerVersion() {
1703
1714
  const realHome = process.env.AGENTS_REAL_HOME || os.homedir();
@@ -1848,7 +1859,7 @@ export async function runMigration() {
1848
1859
  cliMigrateDirs.push(projectDotAgents);
1849
1860
  migrateCliDirToClis(cliMigrateDirs);
1850
1861
  migrateAgentsYaml();
1851
- migrateHumans();
1862
+ await migrateHumansToAccount();
1852
1863
  deleteSystemPromptsJson();
1853
1864
  migrateSystemConfigJson();
1854
1865
  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>;