@phnx-labs/agents-cli 1.22.122 → 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 (194) hide show
  1. package/CHANGELOG.md +261 -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 +99 -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 +1 -1
  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
@@ -8,10 +8,16 @@ export function getBrowserRuntimeDir() {
8
8
  export function getProfileRuntimeDir(name) {
9
9
  return path.join(getBrowserRuntimeDir(), name);
10
10
  }
11
- function profileOfCacheKey(key) {
11
+ export function profileOfCacheKey(key) {
12
12
  const at = key.lastIndexOf('@');
13
13
  return at === -1 ? key : key.slice(0, at);
14
14
  }
15
+ export function profileScopeSql(column, profile) {
16
+ return {
17
+ sql: `(${column} = ? OR (substr(${column}, 1, length(?) + 1) = ? || '@' AND instr(substr(${column}, length(?) + 2), '@') = 0))`,
18
+ params: [profile, profile, profile, profile],
19
+ };
20
+ }
15
21
  export function listProfileCacheDirs(profileName) {
16
22
  const root = getBrowserRuntimeDir();
17
23
  if (!fs.existsSync(root))
@@ -20,7 +20,29 @@ export interface TaskIdentity {
20
20
  owner?: string;
21
21
  launchId?: string;
22
22
  sessionId?: string;
23
+ startedAt?: number;
24
+ lastActivity?: number;
25
+ machine?: string;
26
+ captureDir?: string;
27
+ capturesRemote?: string;
28
+ counts?: Partial<Record<ArtifactKind, number>>;
23
29
  }
30
+ export interface BrowserTaskSummary extends Omit<TaskIdentity, 'owner'> {
31
+ profile: string;
32
+ task: string;
33
+ actor?: string;
34
+ startedAt: number;
35
+ lastActivity: number;
36
+ }
37
+ export declare const BROWSER_HISTORY_LIMIT = 2000;
38
+ export declare function nativeBrowserHistoryPath(): string;
39
+ export interface BrowserHistoryQuery {
40
+ key?: string;
41
+ profile?: string;
42
+ limit?: number;
43
+ }
44
+ export declare function readNativeBrowserHistory(query?: BrowserHistoryQuery, file?: string): BrowserTaskSummary[];
45
+ export declare function readBrowserTaskHistory(query?: BrowserHistoryQuery): BrowserTaskSummary[];
24
46
  export declare function loadTaskIdentities(profile: string): Map<string, TaskIdentity>;
25
47
  export declare function loadDurableTaskIdentities(profile: string): Map<string, TaskIdentity>;
26
48
  export interface LaunchSessionIndex {
@@ -41,8 +63,13 @@ export interface BrowserSessionRow {
41
63
  artifacts: BrowserArtifact[];
42
64
  counts: Record<ArtifactKind, number>;
43
65
  latestMtimeMs: number;
66
+ startedAt?: number;
67
+ machine?: string;
68
+ captureDir?: string;
69
+ capturesRemote?: string;
44
70
  }
45
- export declare function groupIntoRows(groups: ProfileArtifacts[], taskIdentities: Map<string, Map<string, TaskIdentity>>, resolveLaunch?: (launchId: string) => SessionMeta | null, resolveSession?: (sessionId: string) => SessionMeta | null): BrowserSessionRow[];
71
+ export declare function groupIntoRows(groups: ProfileArtifacts[], taskIdentities: Map<string, Map<string, TaskIdentity>>, resolveLaunch?: (launchId: string) => SessionMeta | null, resolveSession?: (sessionId: string) => SessionMeta | null, listed?: Map<string, Set<string>>): BrowserSessionRow[];
72
+ export declare function readBrowserSessionRows(profile?: string): BrowserSessionRow[];
46
73
  export declare function buildBrowserSessionRows(profile?: string): BrowserSessionRow[];
47
74
  export declare function matchesBrowserSessionRow(row: BrowserSessionRow, query: string): boolean;
48
75
  export declare function runBrowserSessions(opts: {
@@ -3,9 +3,11 @@ import * as fs from 'fs';
3
3
  import { formatBytes } from '../format.js';
4
4
  export { formatBytes };
5
5
  import * as path from 'path';
6
- import { getBrowserRuntimeDir, getProfileRuntimeDir, listProfileCacheDirs } from './paths.js';
6
+ import { getBrowserRuntimeDir, getProfileRuntimeDir, listProfileCacheDirs, profileScopeSql } from './paths.js';
7
7
  import { formatRelativeTime } from '../session/relative-time.js';
8
8
  import { getSessionById, listBrowserSessionRecords, pruneToolSessions } from '../session/db.js';
9
+ import Database from '../sqlite.js';
10
+ import { getHistoryDir } from '../state.js';
9
11
  import { listPidSessionEntries } from '../session/pid-registry.js';
10
12
  import { loadHookSessionIndex } from '../session/hook-sessions.js';
11
13
  import { readRecentActivity } from '../feed/activity.js';
@@ -43,6 +45,19 @@ function walkFiles(dir) {
43
45
  }
44
46
  return out;
45
47
  }
48
+ function listTaskArtifacts(dir, task) {
49
+ const artifacts = [];
50
+ for (const file of walkFiles(dir)) {
51
+ const kind = EXT_KIND[path.extname(file).toLowerCase()];
52
+ if (!kind)
53
+ continue;
54
+ const st = statSafe(file);
55
+ if (!st)
56
+ continue;
57
+ artifacts.push({ kind, task, name: path.basename(file), path: file, bytes: st.size, mtimeMs: st.mtimeMs });
58
+ }
59
+ return artifacts;
60
+ }
46
61
  function listProfileArtifacts(profile) {
47
62
  const root = getProfileRuntimeDir(profile);
48
63
  const artifacts = [];
@@ -53,17 +68,8 @@ function listProfileArtifacts(profile) {
53
68
  }
54
69
  catch { }
55
70
  for (const t of taskDirs) {
56
- if (!t.isDirectory())
57
- continue;
58
- for (const file of walkFiles(path.join(sessionsRoot, t.name))) {
59
- const kind = EXT_KIND[path.extname(file).toLowerCase()];
60
- if (!kind)
61
- continue;
62
- const st = statSafe(file);
63
- if (!st)
64
- continue;
65
- artifacts.push({ kind, task: t.name, name: path.basename(file), path: file, bytes: st.size, mtimeMs: st.mtimeMs });
66
- }
71
+ if (t.isDirectory())
72
+ artifacts.push(...listTaskArtifacts(path.join(sessionsRoot, t.name), t.name));
67
73
  }
68
74
  for (const file of walkFiles(path.join(root, 'downloads'))) {
69
75
  const st = statSafe(file);
@@ -130,6 +136,74 @@ export function resolveArtifact(groups, selector) {
130
136
  const hit = all.find((a) => a.name === selector) ?? all.find((a) => a.name.includes(selector));
131
137
  return hit ? hit.path : null;
132
138
  }
139
+ export const BROWSER_HISTORY_LIMIT = 2000;
140
+ export function nativeBrowserHistoryPath() {
141
+ return path.join(getHistoryDir(), 'browser', 'history.db');
142
+ }
143
+ const SUMMARY_TEXT_FIELDS = ['actor', 'sessionId', 'launchId', 'machine', 'captureDir', 'capturesRemote'];
144
+ const COUNT_KINDS = ['screenshot', 'pdf', 'recording', 'download'];
145
+ function parseSummary(file, raw) {
146
+ let value;
147
+ try {
148
+ value = JSON.parse(raw);
149
+ }
150
+ catch (error) {
151
+ throw new Error(`unreadable browser history record in ${file}: ${error.message}`);
152
+ }
153
+ const r = value;
154
+ if (!r || typeof r !== 'object' || typeof r.profile !== 'string' || typeof r.task !== 'string'
155
+ || !Number.isFinite(r.startedAt) || !Number.isFinite(r.lastActivity)) {
156
+ throw new Error(`unexpected browser history record in ${file}: needs profile, task and finite timestamps`);
157
+ }
158
+ const summary = {
159
+ profile: r.profile, task: r.task, startedAt: r.startedAt, lastActivity: r.lastActivity,
160
+ };
161
+ for (const key of SUMMARY_TEXT_FIELDS) {
162
+ if (typeof r[key] === 'string')
163
+ summary[key] = r[key];
164
+ }
165
+ if (r.counts && typeof r.counts === 'object') {
166
+ const counts = {};
167
+ for (const kind of COUNT_KINDS) {
168
+ const n = r.counts[kind];
169
+ if (Number.isFinite(n))
170
+ counts[kind] = n;
171
+ }
172
+ summary.counts = counts;
173
+ }
174
+ return summary;
175
+ }
176
+ export function readNativeBrowserHistory(query = {}, file = nativeBrowserHistoryPath()) {
177
+ if (!fs.existsSync(file))
178
+ return [];
179
+ const where = query.key ? { sql: 'profile = ?', params: [query.key] }
180
+ : query.profile ? profileScopeSql('profile', query.profile) : undefined;
181
+ const db = new Database(file, { readOnly: true });
182
+ try {
183
+ const rows = db.prepare(`SELECT record FROM tasks${where ? ` WHERE ${where.sql}` : ''} ORDER BY last_activity DESC${query.limit === undefined ? '' : ' LIMIT ?'}`).all(...(where?.params ?? []), ...(query.limit === undefined ? [] : [query.limit]));
184
+ return rows.map((row) => parseSummary(file, row.record));
185
+ }
186
+ finally {
187
+ db.close();
188
+ }
189
+ }
190
+ export function readBrowserTaskHistory(query = {}) {
191
+ const merged = new Map();
192
+ const id = (s) => `${s.profile}\0${s.task}`;
193
+ const legacyRows = query.key
194
+ ? listBrowserSessionRecords(query.key, { limit: query.limit })
195
+ : listBrowserSessionRecords(query.profile, { deviceKeys: true, limit: query.limit });
196
+ for (const legacy of legacyRows) {
197
+ if (legacy.startedAt === undefined)
198
+ continue;
199
+ merged.set(id(legacy), { ...legacy, startedAt: legacy.startedAt, lastActivity: legacy.lastActivity ?? legacy.startedAt });
200
+ }
201
+ for (const native of readNativeBrowserHistory(query)) {
202
+ const legacy = merged.get(id(native));
203
+ merged.set(id(native), legacy ? { ...legacy, ...native } : native);
204
+ }
205
+ return [...merged.values()];
206
+ }
133
207
  export function loadTaskIdentities(profile) {
134
208
  const out = new Map();
135
209
  let raw;
@@ -162,16 +236,14 @@ export function loadTaskIdentities(profile) {
162
236
  }
163
237
  export function loadDurableTaskIdentities(profile) {
164
238
  const merged = new Map();
165
- for (const record of listBrowserSessionRecords(profile)) {
166
- merged.set(record.task, {
167
- owner: record.actor,
168
- launchId: record.launchId,
169
- sessionId: record.sessionId,
170
- });
239
+ for (const record of readBrowserTaskHistory({ key: profile })) {
240
+ const { actor, profile: _profile, task: _task, ...rest } = record;
241
+ merged.set(record.task, { ...rest, owner: actor });
171
242
  }
172
243
  for (const [task, live] of loadTaskIdentities(profile)) {
173
244
  const durable = merged.get(task);
174
245
  merged.set(task, {
246
+ ...durable,
175
247
  owner: live.owner ?? durable?.owner,
176
248
  launchId: live.launchId ?? durable?.launchId,
177
249
  sessionId: live.sessionId ?? durable?.sessionId,
@@ -199,7 +271,13 @@ export function resolveLaunchSession(index, launchId) {
199
271
  const sessionId = index.byLaunchId.get(launchId);
200
272
  return sessionId ? getSessionById(sessionId) : null;
201
273
  }
202
- export function groupIntoRows(groups, taskIdentities, resolveLaunch, resolveSession) {
274
+ function mergeCounts(found, recorded) {
275
+ const out = { ...found };
276
+ for (const kind of COUNT_KINDS)
277
+ out[kind] = Math.max(found[kind], recorded?.[kind] ?? 0);
278
+ return out;
279
+ }
280
+ export function groupIntoRows(groups, taskIdentities, resolveLaunch, resolveSession, listed) {
203
281
  const rows = [];
204
282
  for (const g of groups) {
205
283
  const identities = taskIdentities.get(g.profile) ?? new Map();
@@ -214,6 +292,10 @@ export function groupIntoRows(groups, taskIdentities, resolveLaunch, resolveSess
214
292
  list.push(a);
215
293
  byTask.set(a.task, list);
216
294
  }
295
+ for (const task of listed?.get(g.profile) ?? []) {
296
+ if (!byTask.has(task))
297
+ byTask.set(task, []);
298
+ }
217
299
  for (const [task, artifacts] of byTask) {
218
300
  artifacts.sort((a, b) => b.mtimeMs - a.mtimeMs);
219
301
  const identity = identities.get(task);
@@ -234,8 +316,12 @@ export function groupIntoRows(groups, taskIdentities, resolveLaunch, resolveSess
234
316
  linkStatus: linkedSession ? 'linked' : hasIdentityKey ? 'unresolved' : 'unlinked',
235
317
  linkedSession: linkedSession ?? undefined,
236
318
  artifacts,
237
- counts: countByKind(artifacts),
238
- latestMtimeMs: artifacts[0]?.mtimeMs ?? 0,
319
+ counts: mergeCounts(countByKind(artifacts), identity?.counts),
320
+ latestMtimeMs: Math.max(artifacts[0]?.mtimeMs ?? 0, identity?.lastActivity ?? 0),
321
+ ...(identity?.startedAt !== undefined ? { startedAt: identity.startedAt } : {}),
322
+ ...(identity?.machine ? { machine: identity.machine } : {}),
323
+ ...(identity?.captureDir ? { captureDir: identity.captureDir } : {}),
324
+ ...(identity?.capturesRemote ? { capturesRemote: identity.capturesRemote } : {}),
239
325
  });
240
326
  }
241
327
  if (downloads.length > 0) {
@@ -253,15 +339,41 @@ export function groupIntoRows(groups, taskIdentities, resolveLaunch, resolveSess
253
339
  rows.sort((a, b) => b.latestMtimeMs - a.latestMtimeMs);
254
340
  return rows;
255
341
  }
342
+ export function readBrowserSessionRows(profile) {
343
+ const groups = listBrowserSessions(profile);
344
+ const byProfile = new Map(groups.map((g) => [g.profile, g]));
345
+ const listed = new Map();
346
+ for (const record of readBrowserTaskHistory({ profile, limit: BROWSER_HISTORY_LIMIT })) {
347
+ if (!byProfile.has(record.profile)) {
348
+ const group = { profile: record.profile, artifacts: listProfileArtifacts(record.profile) };
349
+ byProfile.set(record.profile, group);
350
+ groups.push(group);
351
+ }
352
+ const tasks = listed.get(record.profile) ?? new Set();
353
+ tasks.add(record.task);
354
+ listed.set(record.profile, tasks);
355
+ }
356
+ const taskIdentities = new Map(groups.map((g) => [g.profile, loadDurableTaskIdentities(g.profile)]));
357
+ for (const group of groups) {
358
+ const identities = taskIdentities.get(group.profile);
359
+ const known = new Set(group.artifacts.map((a) => a.path));
360
+ const tasks = new Set([...(listed.get(group.profile) ?? []), ...group.artifacts.flatMap((a) => a.task ? [a.task] : [])]);
361
+ for (const task of tasks) {
362
+ const identity = identities.get(task);
363
+ if (!identity?.captureDir || identity.capturesRemote)
364
+ continue;
365
+ group.artifacts.push(...listTaskArtifacts(identity.captureDir, task).filter((a) => !known.has(a.path)));
366
+ }
367
+ }
368
+ const index = buildLaunchSessionIndex();
369
+ return groupIntoRows(groups, taskIdentities, (launchId) => resolveLaunchSession(index, launchId), (sessionId) => getSessionById(sessionId), listed);
370
+ }
256
371
  export function buildBrowserSessionRows(profile) {
257
372
  try {
258
373
  pruneToolSessions();
259
374
  }
260
375
  catch { }
261
- const groups = listBrowserSessions(profile);
262
- const taskIdentities = new Map(groups.map((g) => [g.profile, loadDurableTaskIdentities(g.profile)]));
263
- const index = buildLaunchSessionIndex();
264
- return groupIntoRows(groups, taskIdentities, (launchId) => resolveLaunchSession(index, launchId), (sessionId) => getSessionById(sessionId));
376
+ return readBrowserSessionRows(profile);
265
377
  }
266
378
  export function matchesBrowserSessionRow(row, query) {
267
379
  const q = query.trim().toLowerCase();
@@ -1,7 +1,8 @@
1
- import type { ChannelProvider } from '../registry.js';
1
+ import type { ChannelProvider, SendOptions, SendResult } from '../registry.js';
2
2
  export type RushChannel = 'telegram' | 'imessage' | 'slack' | 'discord';
3
3
  export declare const RUSH_CHANNELS: RushChannel[];
4
4
  export declare function buildImessageOsascriptArgs(text: string, phone: string): string[];
5
+ export declare function sendImessage(text: string, opts: SendOptions): Promise<SendResult>;
5
6
  export declare function resolveSlackToken(): string | undefined;
6
7
  export declare function buildSlackPayload(channel: string, text: string, thread?: string): Record<string, string>;
7
8
  export declare const rushProviders: ChannelProvider[];
@@ -17,12 +17,12 @@ export function buildImessageOsascriptArgs(text, phone) {
17
17
  ].join('\n');
18
18
  return ['-e', script];
19
19
  }
20
- async function sendImessage(text, opts) {
20
+ export async function sendImessage(text, opts) {
21
21
  const channel = 'imessage';
22
22
  if (opts.dryRun)
23
23
  return { ok: true, channel, id: opts.target };
24
24
  if (platform() !== 'darwin') {
25
- return { ok: false, channel, id: opts.target, error: 'iMessage requires macOS (peer-forward handles Linux delivery)' };
25
+ return { ok: false, channel, id: opts.target, error: 'iMessage requires macOS' };
26
26
  }
27
27
  if ((opts.attachments?.length ?? 0) > 0) {
28
28
  return { ok: false, channel, id: opts.target, error: 'iMessage attachments not supported via osascript' };
@@ -1,2 +1,3 @@
1
1
  import type { ChannelProvider } from '../registry.js';
2
+ export declare const SESSION_CHANNEL = "session";
2
3
  export declare const sessionProvider: ChannelProvider;
@@ -1,26 +1,37 @@
1
1
  import { injectIntoTerminal } from '../../terminal/index.js';
2
2
  import { resolveLiveInjectTarget } from '../../session/inject-target.js';
3
- const NAME = 'session';
3
+ export const SESSION_CHANNEL = 'session';
4
4
  export const sessionProvider = {
5
- name: NAME,
5
+ name: SESSION_CHANNEL,
6
6
  async send(text, opts) {
7
7
  const id = opts.target;
8
- const fail = (error) => ({ ok: false, channel: NAME, id, error });
9
- if (!text.trim())
10
- return fail('refusing to type an empty message into a session');
8
+ const fail = (error) => ({ ok: false, channel: SESSION_CHANNEL, id, error });
11
9
  if (opts.attachments?.length)
12
10
  return fail('the session channel types text only; --attach is not supported');
13
11
  if (opts.thread)
14
12
  return fail('the session channel has no threads; drop --thread');
15
13
  if (opts.from)
16
14
  return fail('the session channel types the text verbatim; drop --from');
17
- const resolved = await resolveLiveInjectTarget(id);
18
- if (!resolved.target) {
19
- return fail(resolved.hint ? `${resolved.reason}\n${resolved.hint}` : resolved.reason ?? 'session not addressable');
15
+ const terminal = opts.terminal ?? {};
16
+ let target;
17
+ if (terminal.pane) {
18
+ target = { backend: 'tmux', pane: terminal.pane, socket: terminal.socket };
20
19
  }
21
- if (opts.dryRun)
22
- return { ok: true, channel: NAME, id };
23
- const res = await injectIntoTerminal(resolved.target, text, { enter: true });
24
- return res.ok ? { ok: true, channel: NAME, id } : fail(res.error ?? 'injection failed');
20
+ else {
21
+ const resolved = await resolveLiveInjectTarget(id);
22
+ if (!resolved.target) {
23
+ return fail(resolved.hint ? `${resolved.reason}\n${resolved.hint}` : resolved.reason ?? 'session not addressable');
24
+ }
25
+ target = resolved.target;
26
+ }
27
+ const res = await injectIntoTerminal(target, text, {
28
+ enter: terminal.enter !== false,
29
+ combined: terminal.combined,
30
+ dryRun: opts.dryRun,
31
+ });
32
+ const delivery = { backend: res.backend, writes: res.writes, confirmed: res.confirmed };
33
+ return res.ok
34
+ ? { ok: true, channel: SESSION_CHANNEL, id, ...delivery }
35
+ : { ...fail(res.error ?? 'injection failed'), ...delivery };
25
36
  },
26
37
  };
@@ -1,10 +1,15 @@
1
+ import type { InjectOptions, InjectResult } from '../terminal/index.js';
2
+ export type TerminalSendOptions = Pick<InjectOptions, 'enter' | 'combined'> & {
3
+ pane?: string;
4
+ socket?: string;
5
+ };
1
6
  export interface SendOptions {
2
7
  target: string;
3
8
  thread?: string;
4
9
  attachments?: string[];
5
10
  from?: string;
6
- ownerScoped?: boolean;
7
11
  dryRun?: boolean;
12
+ terminal?: TerminalSendOptions;
8
13
  }
9
14
  export interface SendResult {
10
15
  ok: boolean;
@@ -14,7 +19,9 @@ export interface SendResult {
14
19
  attachments?: string[];
15
20
  msgId?: string;
16
21
  body?: string;
17
- deliveries?: SendResult[];
22
+ backend?: InjectResult['backend'];
23
+ writes?: number;
24
+ confirmed?: boolean;
18
25
  }
19
26
  export interface ChannelProvider {
20
27
  name: string;
@@ -1,6 +1,5 @@
1
1
  import type { Meta } from '../types.js';
2
- import type { SendResult } from './registry.js';
3
- import type { SinkMessageFormat } from '../sink-format.js';
2
+ import type { SendResult, TerminalSendOptions } from './registry.js';
4
3
  interface SendEnvelope {
5
4
  text: string;
6
5
  channel: string;
@@ -8,8 +7,8 @@ interface SendEnvelope {
8
7
  thread?: string;
9
8
  attachments?: string[];
10
9
  from?: string;
11
- ownerScoped?: boolean;
12
10
  dryRun?: boolean;
11
+ terminal?: TerminalSendOptions;
13
12
  }
14
13
  export interface ResolveSendInput {
15
14
  text?: string;
@@ -21,7 +20,7 @@ export interface ResolveSendInput {
21
20
  urls?: string[];
22
21
  from?: string;
23
22
  dryRun?: boolean;
24
- ownerMode?: boolean;
23
+ terminal?: TerminalSendOptions;
25
24
  }
26
25
  type ResolveSendResult = {
27
26
  ok: true;
@@ -31,14 +30,10 @@ type ResolveSendResult = {
31
30
  error: string;
32
31
  };
33
32
  export declare function isOwnerAlias(to: string | undefined): boolean;
34
- export declare function composeSendText(text: string, urls?: string[]): string;
35
- export declare function readOwnerDest(meta: Meta): {
36
- channel: string;
37
- to: string;
38
- } | null;
33
+ export declare function composeSendText(text: string, urls?: string[], verbatim?: boolean): string;
39
34
  export declare function resolveSendEnvelope(input: ResolveSendInput, meta: Meta): ResolveSendResult;
40
35
  export declare function deliverEnvelope(envelope: SendEnvelope, meta: Meta): Promise<SendResult>;
41
- export declare function sendMessage(input: ResolveSendInput, meta: Meta, ownerCompose?: (format: SinkMessageFormat) => string): Promise<{
36
+ export declare function sendMessage(input: ResolveSendInput, meta: Meta): Promise<{
42
37
  result: SendResult;
43
38
  envelope: SendEnvelope;
44
39
  } | {
@@ -1,13 +1,13 @@
1
- import { getOwnerNotifyFromHumans } from '../humans.js';
2
1
  import { registerBuiltinProviders } from './providers/index.js';
3
- import { resolveTransport } from './resolve.js';
2
+ import { lookupTransport, resolveTransport } from './resolve.js';
3
+ import { SESSION_CHANNEL } from './providers/session.js';
4
4
  import { sendToOwner } from '../notify.js';
5
5
  const OWNER_ALIAS = 'owner';
6
6
  export function isOwnerAlias(to) {
7
7
  return (to ?? '').trim().toLowerCase() === OWNER_ALIAS;
8
8
  }
9
- export function composeSendText(text, urls) {
10
- const body = text.trim();
9
+ export function composeSendText(text, urls, verbatim = false) {
10
+ const body = verbatim ? text : text.trim();
11
11
  const extra = (urls ?? [])
12
12
  .map((u) => u.trim())
13
13
  .filter(Boolean)
@@ -16,49 +16,71 @@ export function composeSendText(text, urls) {
16
16
  return body;
17
17
  return body ? `${body}\n${extra.join('\n')}` : extra.join('\n');
18
18
  }
19
- export function readOwnerDest(meta) {
20
- const canonical = getOwnerNotifyFromHumans();
21
- if (canonical)
22
- return canonical;
23
- const channel = meta.notify?.owner?.channel?.trim();
24
- const to = meta.notify?.owner?.to?.trim();
25
- return channel && to ? { channel, to } : null;
26
- }
27
- export function resolveSendEnvelope(input, meta) {
28
- const positional = (input.positionalText ?? '').trim();
29
- const flagged = (input.text ?? '').trim();
30
- if (positional && flagged && positional !== flagged) {
19
+ function resolveText(input, verbatim) {
20
+ const norm = (t) => (t === undefined || verbatim ? t : t.trim());
21
+ const positional = norm(input.positionalText);
22
+ const flagged = norm(input.text);
23
+ const conflict = verbatim
24
+ ? positional !== undefined && flagged !== undefined && positional !== flagged
25
+ : Boolean(positional && flagged && positional !== flagged);
26
+ if (conflict) {
31
27
  return {
32
28
  ok: false,
33
29
  error: 'Pass the message once: use --text, or a positional argument, not both with different values.',
34
30
  };
35
31
  }
36
- const rawText = flagged || positional;
37
32
  const urls = (input.urls ?? []).map((u) => u.trim()).filter(Boolean);
38
- const text = composeSendText(rawText, urls);
39
- if (!text) {
33
+ const supplied = verbatim ? (flagged ?? positional) : (flagged || positional);
34
+ const text = composeSendText(supplied ?? '', urls, verbatim);
35
+ if (!text && (supplied === undefined || !verbatim)) {
40
36
  return {
41
37
  ok: false,
42
38
  error: 'Message is empty. Pass --text "…", a positional message, and/or --url.',
43
39
  };
44
40
  }
45
- let channel = (input.channel ?? '').trim();
41
+ return { ok: true, text };
42
+ }
43
+ function terminalOptionsError(terminal, to) {
44
+ if (!terminal)
45
+ return null;
46
+ if (terminal.socket && !terminal.pane) {
47
+ return '--socket addresses an explicit --pane; a session found by --to already carries its own socket.';
48
+ }
49
+ if (terminal.combined && terminal.enter === false) {
50
+ return '--combined fuses the text with Enter; it cannot be used with --no-enter.';
51
+ }
52
+ if (terminal.pane && to && to !== terminal.pane) {
53
+ return `--pane ${terminal.pane} and --to ${to} name different targets; pass one of them.`;
54
+ }
55
+ return null;
56
+ }
57
+ export function resolveSendEnvelope(input, meta) {
58
+ const channel = (input.channel ?? '').trim();
46
59
  let to = (input.to ?? '').trim();
47
- const usedOwnerAlias = isOwnerAlias(to);
48
- if (input.ownerMode || usedOwnerAlias) {
49
- const owner = getOwnerNotifyFromHumans() ?? meta.notify?.owner;
50
- const ownerChannel = owner?.channel ?? '';
51
- const ownerTo = owner?.to ?? '';
52
- if (!channel)
53
- channel = ownerChannel;
54
- if (!to || usedOwnerAlias)
55
- to = ownerTo;
60
+ if (isOwnerAlias(to)) {
61
+ return { ok: false, error: '--to owner sends to your account, whose notification preferences pick the channels, so it cannot be combined with --channel (a feed sink uses `channel: owner` instead). Drop --channel, or name an explicit recipient.' };
56
62
  }
63
+ const isSession = Boolean(channel)
64
+ && lookupTransport(channel, meta).providerName === SESSION_CHANNEL;
65
+ if (input.terminal && !isSession) {
66
+ return {
67
+ ok: false,
68
+ error: '--pane, --socket, --no-enter and --combined only apply to --channel session.',
69
+ };
70
+ }
71
+ const terminalError = isSession ? terminalOptionsError(input.terminal, to) : null;
72
+ if (terminalError)
73
+ return { ok: false, error: terminalError };
74
+ if (isSession && input.terminal?.pane)
75
+ to = input.terminal.pane;
76
+ const resolvedText = resolveText(input, isSession);
77
+ if (!resolvedText.ok)
78
+ return resolvedText;
79
+ const { text } = resolvedText;
57
80
  if (!channel || !to) {
58
- const hint = input.ownerMode || usedOwnerAlias
59
- ? 'Set owner.channels and owner.policy.normal in humans.yaml, or pass --channel and --to explicitly.'
60
- : 'Need --channel and --to (or --to owner with notify.owner configured). ' +
61
- 'Example: agents send --channel desktop --to local --text "hi"';
81
+ const hint = isSession
82
+ ? 'Need --to <session> (find ids with: agents ps) or --pane <tmux pane id>.'
83
+ : 'Need --channel and --to, or --to owner. Example: agents send --channel desktop --to local --text "hi"';
62
84
  return { ok: false, error: hint };
63
85
  }
64
86
  const attachments = [
@@ -75,8 +97,8 @@ export function resolveSendEnvelope(input, meta) {
75
97
  thread: input.thread?.trim() || undefined,
76
98
  attachments: attachments.length ? attachments : undefined,
77
99
  from: input.from?.trim() || undefined,
78
- ownerScoped: usedOwnerAlias || (input.ownerMode === true && !input.to?.trim()),
79
100
  dryRun: input.dryRun,
101
+ terminal: isSession ? input.terminal : undefined,
80
102
  },
81
103
  };
82
104
  }
@@ -88,26 +110,42 @@ export async function deliverEnvelope(envelope, meta) {
88
110
  thread: envelope.thread,
89
111
  attachments: envelope.attachments,
90
112
  from: envelope.from,
91
- ownerScoped: envelope.ownerScoped,
92
113
  dryRun: envelope.dryRun,
114
+ terminal: envelope.terminal,
93
115
  });
94
116
  }
95
- export async function sendMessage(input, meta, ownerCompose) {
117
+ function ownerSendError(input) {
118
+ if (input.channel?.trim())
119
+ return '--to owner sends to your account, whose notification preferences pick the channels, so it cannot be combined with --channel (a feed sink uses `channel: owner` instead). Drop --channel, or name an explicit recipient.';
120
+ if (input.terminal)
121
+ return '--pane, --socket, --no-enter and --combined only apply to --channel session.';
122
+ if (input.thread?.trim())
123
+ return '--thread does not apply to --to owner; the account decides where the message lands.';
124
+ if (input.attachments?.length)
125
+ return '--attach does not apply to --to owner; owner notifications carry text and a link. Pass --url instead.';
126
+ return null;
127
+ }
128
+ export async function sendMessage(input, meta) {
129
+ if (isOwnerAlias(input.to)) {
130
+ const refused = ownerSendError(input);
131
+ if (refused)
132
+ return { error: refused };
133
+ const resolvedText = resolveText(input, false);
134
+ if (!resolvedText.ok)
135
+ return resolvedText;
136
+ const { ownerMessageNotification } = await import('../owner-message.js');
137
+ const notification = ownerMessageNotification(resolvedText.text, {
138
+ ...(input.from?.trim() ? { agent: input.from.trim() } : {}),
139
+ ...(input.urls?.[0]?.trim() ? { url: input.urls[0].trim() } : {}),
140
+ });
141
+ const result = await sendToOwner(notification, { dryRun: input.dryRun });
142
+ return {
143
+ result,
144
+ envelope: { text: notification.body, channel: 'owner', to: 'owner', dryRun: input.dryRun },
145
+ };
146
+ }
96
147
  const resolved = resolveSendEnvelope(input, meta);
97
148
  if (!resolved.ok)
98
149
  return { error: resolved.error };
99
- const ownerPolicyRequest = resolved.envelope.ownerScoped === true
100
- && !input.channel?.trim()
101
- && (!input.to?.trim() || isOwnerAlias(input.to));
102
- const result = ownerPolicyRequest
103
- ? await sendToOwner(resolved.envelope.text, {
104
- meta,
105
- dryRun: resolved.envelope.dryRun,
106
- thread: resolved.envelope.thread,
107
- attachments: resolved.envelope.attachments,
108
- from: resolved.envelope.from,
109
- ...(ownerCompose ? { composeForFormat: ownerCompose } : {}),
110
- })
111
- : await deliverEnvelope(resolved.envelope, meta);
112
- return { result, envelope: resolved.envelope };
150
+ return { result: await deliverEnvelope(resolved.envelope, meta), envelope: resolved.envelope };
113
151
  }
@@ -1,6 +1,12 @@
1
1
  import type { CloudProvider, CloudTask, CloudTaskStatus, CloudEvent, DispatchOptions, ProviderCapabilities, ImageAttachment, SkillRef } from './types.js';
2
2
  export declare function isRushSessionValid(yamlPath?: string): boolean;
3
3
  export declare function readToken(yamlPath?: string): string;
4
+ export interface RushOrg {
5
+ slug?: string;
6
+ kind?: string;
7
+ }
8
+ export declare function rushOrgHandle(token: string, yamlPath?: string): Promise<string>;
9
+ export declare function personalOrgHandle(orgs: RushOrg[]): string | undefined;
4
10
  interface AccountManifestEntry {
5
11
  version: string;
6
12
  email: string;