@phnx-labs/agents-cli 1.23.17 → 1.23.18

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 (204) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +140 -165
  3. package/dist/bootstrap.js +10 -16
  4. package/dist/cli/command-registry.d.ts +1 -2
  5. package/dist/cli/command-registry.js +1 -10
  6. package/dist/commands/accounts.js +7 -7
  7. package/dist/commands/cloud-transcripts.d.ts +0 -1
  8. package/dist/commands/cloud-transcripts.js +2 -2
  9. package/dist/commands/cloud.js +1 -1
  10. package/dist/commands/config.js +0 -4
  11. package/dist/commands/cost.js +1 -1
  12. package/dist/commands/daemon-index.js +0 -1
  13. package/dist/commands/detach.d.ts +1 -1
  14. package/dist/commands/detach.js +5 -5
  15. package/dist/commands/exec.js +10 -22
  16. package/dist/commands/feed.d.ts +1 -1
  17. package/dist/commands/feed.js +3 -3
  18. package/dist/commands/focus.d.ts +1 -4
  19. package/dist/commands/focus.js +12 -13
  20. package/dist/commands/fork.d.ts +0 -1
  21. package/dist/commands/fork.js +7 -16
  22. package/dist/commands/harness-wizard.js +1 -1
  23. package/dist/commands/harness.js +1 -1
  24. package/dist/commands/insights.d.ts +0 -1
  25. package/dist/commands/insights.js +3 -7
  26. package/dist/commands/open.js +1 -1
  27. package/dist/commands/output.js +1 -1
  28. package/dist/commands/profiles.d.ts +1 -1
  29. package/dist/commands/profiles.js +2 -2
  30. package/dist/commands/projects.js +1 -1
  31. package/dist/commands/prune.js +1 -1
  32. package/dist/commands/ps.d.ts +0 -1
  33. package/dist/commands/ps.js +63 -18
  34. package/dist/commands/routines.js +1 -1
  35. package/dist/commands/send.js +1 -1
  36. package/dist/commands/sessions-backfill.d.ts +0 -1
  37. package/dist/commands/sessions-backfill.js +3 -6
  38. package/dist/commands/sessions-browser.d.ts +0 -10
  39. package/dist/commands/sessions-browser.js +19 -25
  40. package/dist/commands/sessions-migrate.d.ts +2 -2
  41. package/dist/commands/sessions-migrate.js +13 -13
  42. package/dist/commands/sessions-optimize.d.ts +0 -1
  43. package/dist/commands/sessions-optimize.js +0 -3
  44. package/dist/commands/sessions-picker.js +11 -11
  45. package/dist/commands/sessions-resume.d.ts +16 -15
  46. package/dist/commands/sessions-resume.js +101 -269
  47. package/dist/commands/sessions-stats.d.ts +0 -1
  48. package/dist/commands/sessions-stats.js +5 -8
  49. package/dist/commands/sessions-stop.d.ts +1 -1
  50. package/dist/commands/sessions-stop.js +6 -6
  51. package/dist/commands/sessions-trace.d.ts +1 -1
  52. package/dist/commands/sessions-trace.js +40 -17
  53. package/dist/commands/sessions-watch.js +2 -2
  54. package/dist/commands/sessions.test-fixture.d.ts +1 -0
  55. package/dist/commands/sessions.test-fixture.js +14 -0
  56. package/dist/commands/setup-browser.js +4 -4
  57. package/dist/commands/setup-computer.js +4 -4
  58. package/dist/commands/setup-fleet.js +1 -1
  59. package/dist/commands/setup-preferences.js +1 -1
  60. package/dist/commands/{sessions-backup-setup.d.ts → setup-session-backup.d.ts} +2 -2
  61. package/dist/commands/{sessions-backup-setup.js → setup-session-backup.js} +8 -8
  62. package/dist/commands/setup.js +3 -1
  63. package/dist/commands/ssh.js +4 -5
  64. package/dist/commands/sync.js +1 -1
  65. package/dist/commands/teams.js +2 -2
  66. package/dist/commands/utils.d.ts +0 -1
  67. package/dist/commands/utils.js +0 -10
  68. package/dist/index.js +0 -71
  69. package/dist/lib/analytics/mix-commands.js +1 -1
  70. package/dist/lib/auth-mint.js +2 -2
  71. package/dist/lib/browser-client.d.ts +0 -1
  72. package/dist/lib/browser-client.js +0 -3
  73. package/dist/lib/cloud/antigravity.js +1 -1
  74. package/dist/lib/cloud/cursor.js +3 -3
  75. package/dist/lib/cloudflare/creds.js +2 -2
  76. package/dist/lib/computer/context.d.ts +4 -21
  77. package/dist/lib/computer/context.js +3 -24
  78. package/dist/lib/computer/policy.d.ts +0 -10
  79. package/dist/lib/computer/policy.js +0 -28
  80. package/dist/lib/computer-client.d.ts +0 -44
  81. package/dist/lib/computer-client.js +17 -121
  82. package/dist/lib/config-keys.d.ts +1 -1
  83. package/dist/lib/config-keys.js +0 -3
  84. package/dist/lib/crabbox/cli.js +1 -1
  85. package/dist/lib/device-config.js +5 -28
  86. package/dist/lib/devices/connect.d.ts +1 -1
  87. package/dist/lib/devices/connect.js +3 -6
  88. package/dist/lib/devices/doctor-findings.d.ts +2 -1
  89. package/dist/lib/devices/doctor-findings.js +4 -4
  90. package/dist/lib/exec.js +1 -1
  91. package/dist/lib/feed/activity.js +1 -1
  92. package/dist/lib/fleet/apply.js +1 -1
  93. package/dist/lib/help.d.ts +0 -1
  94. package/dist/lib/help.js +2 -10
  95. package/dist/lib/hosts/option.js +1 -1
  96. package/dist/lib/hosts/passthrough.d.ts +0 -1
  97. package/dist/lib/hosts/passthrough.js +2 -26
  98. package/dist/lib/hosts/reconnect.js +5 -5
  99. package/dist/lib/hosts/remote-cmd.d.ts +3 -5
  100. package/dist/lib/hosts/remote-cmd.js +15 -20
  101. package/dist/lib/hosts/remote-session-id.js +1 -1
  102. package/dist/lib/installations/active-check.js +1 -1
  103. package/dist/lib/installations/migrate.js +4 -15
  104. package/dist/lib/installations/versions.js +1 -1
  105. package/dist/lib/launch-log.js +3 -6
  106. package/dist/lib/owner-notify.d.ts +1 -6
  107. package/dist/lib/owner-notify.js +0 -2
  108. package/dist/lib/paths.d.ts +0 -1
  109. package/dist/lib/paths.js +0 -8
  110. package/dist/lib/permissions.js +1 -1
  111. package/dist/lib/redact.d.ts +0 -1
  112. package/dist/lib/redact.js +0 -4
  113. package/dist/lib/remote-agents-json.d.ts +3 -1
  114. package/dist/lib/remote-agents-json.js +8 -6
  115. package/dist/lib/reserved-stores.js +1 -1
  116. package/dist/lib/scheduling/routines.d.ts +0 -1
  117. package/dist/lib/scheduling/routines.js +1 -1
  118. package/dist/lib/session/active.d.ts +1 -1
  119. package/dist/lib/session/db.js +3 -3
  120. package/dist/lib/session/detached.d.ts +0 -1
  121. package/dist/lib/session/detached.js +0 -23
  122. package/dist/lib/session/discover.d.ts +2 -2
  123. package/dist/lib/session/presentation.d.ts +0 -7
  124. package/dist/lib/session/presentation.js +4 -4
  125. package/dist/lib/session/projection.js +1 -1
  126. package/dist/lib/session/remote/remote-list.d.ts +2 -0
  127. package/dist/lib/session/remote/remote-list.js +3 -2
  128. package/dist/lib/session/remote/watch.js +4 -5
  129. package/dist/lib/session/remote-active.js +1 -1
  130. package/dist/lib/session/resume-command.d.ts +0 -1
  131. package/dist/lib/session/resume-command.js +1 -4
  132. package/dist/lib/session/resume-owner.d.ts +0 -2
  133. package/dist/lib/session/resume-owner.js +0 -6
  134. package/dist/lib/session/selection.d.ts +4 -5
  135. package/dist/lib/session/selection.js +2 -2
  136. package/dist/lib/session/sync/config.d.ts +0 -25
  137. package/dist/lib/session/sync/config.js +0 -62
  138. package/dist/lib/session/sync/managed-config.d.ts +0 -1
  139. package/dist/lib/session/sync/managed-config.js +0 -3
  140. package/dist/lib/session/sync/worker-template.js +1 -1
  141. package/dist/lib/sessions-client.d.ts +0 -16
  142. package/dist/lib/sessions-client.js +1 -187
  143. package/dist/lib/startup/command-registry.d.ts +2 -0
  144. package/dist/lib/startup/command-registry.js +36 -3
  145. package/dist/lib/startup/root-command.d.ts +0 -1
  146. package/dist/lib/startup/root-command.js +0 -21
  147. package/dist/lib/sync-umbrella.js +1 -1
  148. package/dist/lib/terminal/resolve.js +1 -1
  149. package/dist/lib/watchdog/rotate.js +1 -1
  150. package/dist/lib/watchdog/watchdog.d.ts +1 -1
  151. package/dist/lib/watchdog/watchdog.js +2 -2
  152. package/package.json +1 -1
  153. package/dist/commands/browser.d.ts +0 -7
  154. package/dist/commands/browser.js +0 -139
  155. package/dist/commands/computer.d.ts +0 -48
  156. package/dist/commands/computer.js +0 -244
  157. package/dist/commands/resume.d.ts +0 -23
  158. package/dist/commands/resume.js +0 -158
  159. package/dist/commands/secrets-passthrough.d.ts +0 -3
  160. package/dist/commands/secrets-passthrough.js +0 -52
  161. package/dist/commands/sessions-bookmark.d.ts +0 -2
  162. package/dist/commands/sessions-bookmark.js +0 -92
  163. package/dist/commands/sessions-export.d.ts +0 -31
  164. package/dist/commands/sessions-export.js +0 -409
  165. package/dist/commands/sessions-import.d.ts +0 -6
  166. package/dist/commands/sessions-import.js +0 -343
  167. package/dist/commands/sessions-inject.d.ts +0 -14
  168. package/dist/commands/sessions-inject.js +0 -143
  169. package/dist/commands/sessions-picker-factory.d.ts +0 -24
  170. package/dist/commands/sessions-picker-factory.js +0 -59
  171. package/dist/commands/sessions-render.d.ts +0 -11
  172. package/dist/commands/sessions-render.js +0 -119
  173. package/dist/commands/sessions-share.d.ts +0 -15
  174. package/dist/commands/sessions-share.js +0 -171
  175. package/dist/commands/sessions.d.ts +0 -122
  176. package/dist/commands/sessions.js +0 -1760
  177. package/dist/lib/address.d.ts +0 -39
  178. package/dist/lib/address.js +0 -128
  179. package/dist/lib/computer/record.d.ts +0 -6
  180. package/dist/lib/computer/record.js +0 -25
  181. package/dist/lib/openclaw-keychain.d.ts +0 -43
  182. package/dist/lib/openclaw-keychain.js +0 -227
  183. package/dist/lib/session/bundle.d.ts +0 -76
  184. package/dist/lib/session/bundle.js +0 -146
  185. package/dist/lib/session/remote/remote-bundle.d.ts +0 -7
  186. package/dist/lib/session/remote/remote-bundle.js +0 -40
  187. package/dist/lib/session/remote/remote.d.ts +0 -35
  188. package/dist/lib/session/remote/remote.js +0 -198
  189. package/dist/lib/session/remote-bundle.d.ts +0 -1
  190. package/dist/lib/session/remote-bundle.js +0 -1
  191. package/dist/lib/session/remote.d.ts +0 -1
  192. package/dist/lib/session/remote.js +0 -1
  193. package/dist/lib/session/sync/agents.d.ts +0 -24
  194. package/dist/lib/session/sync/agents.js +0 -0
  195. package/dist/lib/session/sync/backend.d.ts +0 -22
  196. package/dist/lib/session/sync/backend.js +0 -44
  197. package/dist/lib/session/sync/managed-key.d.ts +0 -5
  198. package/dist/lib/session/sync/managed-key.js +0 -87
  199. package/dist/lib/session/sync/net-client.d.ts +0 -29
  200. package/dist/lib/session/sync/net-client.js +0 -87
  201. package/dist/lib/session/sync/r2.d.ts +0 -20
  202. package/dist/lib/session/sync/r2.js +0 -103
  203. package/dist/lib/session/sync/transcript-crypto.d.ts +0 -41
  204. package/dist/lib/session/sync/transcript-crypto.js +0 -115
@@ -1,343 +0,0 @@
1
- import * as fs from 'fs';
2
- import chalk from 'chalk';
3
- import { isSyncConfigured, loadR2Config } from '../lib/session/sync/config.js';
4
- import { isTranscriptEnvelope, resolveSyncEncKey } from '../lib/session/sync/transcript-crypto.js';
5
- import { R2Client } from '../lib/session/sync/r2.js';
6
- import { SESSIONS_PREFIX } from '../lib/session/sync/agents.js';
7
- import { resolveSessionsBackend } from '../lib/session/sync/backend.js';
8
- import { SessionsHttpClient } from '../lib/session/sync/net-client.js';
9
- import { resolveManagedBackupKey } from '../lib/session/sync/managed-key.js';
10
- import { parseBundle, planImport, writeImport, mergeRecords, makeHeader, } from '../lib/session/bundle.js';
11
- import { pullBundlesFromHosts } from '../lib/session/remote-bundle.js';
12
- import { setHelpSections } from '../lib/help.js';
13
- export function registerSessionsImportCommand(sessionsCmd) {
14
- const cmd = sessionsCmd
15
- .command('import [bundle]')
16
- .description('Restore an export bundle (file, - for stdin, or --from-host <h>) into the local session store, deduping against what you already have.')
17
- .option('--dry-run', 'Show what would be placed without writing anything')
18
- .option('--overwrite', 'Replace local files that differ from the bundle (default: keep local)')
19
- .option('--decrypt [key]', 'Decrypt an encrypted bundle (key optional if the r2.backups sync key is configured)')
20
- .option('--from-host <target...>', 'Pull sessions live from remote peer(s) over SSH instead of a file (repeatable)')
21
- .option('--from-r2', 'Restore session backups from the off-box store (managed Phoenix store when signed in; your own r2.backups bucket with --byo)')
22
- .option('--byo', 'With --from-r2: restore from your own r2.backups bucket instead of the managed Phoenix store');
23
- setHelpSections(cmd, {
24
- examples: `# Preview what a bundle would restore
25
- agents sessions import week.bundle --dry-run
26
-
27
- # Restore it
28
- agents sessions import week.bundle
29
-
30
- # Pull straight off another machine (one command, over SSH)
31
- agents sessions import --from-host yosemite-s1 --since 7d
32
-
33
- # Or the equivalent raw pipe
34
- agents ssh boxB 'agents sessions export --since 7d --stdout' | agents sessions import -
35
-
36
- # Restore everything backed up to R2 (e.g. on a fresh box)
37
- agents sessions import --from-r2`,
38
- notes: `Sessions land under the cross-machine mirror keyed by their origin machine, so
39
- they show up in 'agents sessions' tagged with that machine and never overwrite
40
- your own local sessions. Byte-exact duplicates are skipped. --from-host reuses
41
- the same SSH transport as the cross-machine listing (no R2, no daemon).
42
-
43
- --from-r2 downloads every session backup from the off-box store and restores it
44
- through the same placement. When signed in it restores from the MANAGED Phoenix
45
- store and decrypts with your per-account key (recovered automatically, even on a
46
- fresh box); --byo restores from your own r2.backups bucket with its shared
47
- R2_SYNC_ENC_KEY (or pass --decrypt <key>). It is the inverse of
48
- 'sessions export --to-r2'.`,
49
- });
50
- cmd.action(async (bundlePath, options, command) => {
51
- const g = command.optsWithGlobals();
52
- await runImport(bundlePath, { ...options, agent: g.agent }, g, command);
53
- });
54
- }
55
- async function runImport(bundlePath, options, g, command) {
56
- let bundle;
57
- let managedDecryptKey;
58
- if (options.byo && !options.fromR2) {
59
- process.stderr.write(chalk.red('--byo is only valid with --from-r2.\n'));
60
- process.exit(1);
61
- }
62
- if (options.fromR2) {
63
- let client;
64
- let managedClient;
65
- let managedUserId;
66
- try {
67
- const backend = resolveSessionsBackend({ byo: options.byo });
68
- if (backend.kind === 'managed') {
69
- managedClient = new SessionsHttpClient({ baseUrl: backend.baseUrl, userId: backend.userId, token: backend.token });
70
- client = managedClient;
71
- managedUserId = backend.userId;
72
- }
73
- else {
74
- const gateErr = r2ImportGateError(true, isSyncConfigured());
75
- if (gateErr)
76
- throw new Error(gateErr);
77
- client = new R2Client(backend.r2);
78
- }
79
- }
80
- catch (err) {
81
- process.stderr.write(chalk.red(`R2 restore: ${err.message}\n`));
82
- process.exit(1);
83
- }
84
- bundle = await pullFromR2(client);
85
- if (managedUserId) {
86
- managedDecryptKey = await resolveManagedBackupKey(managedClient, managedUserId);
87
- }
88
- }
89
- else if (options.fromHost && options.fromHost.length > 0) {
90
- bundle = await pullForImport(options.fromHost, bundlePath, g, command);
91
- }
92
- else {
93
- if (!bundlePath) {
94
- process.stderr.write(chalk.red('Provide a bundle path, - for stdin, or --from-host <host>.\n'));
95
- process.exit(1);
96
- }
97
- let text;
98
- try {
99
- text = bundlePath === '-' ? await readStdin() : fs.readFileSync(bundlePath, 'utf-8');
100
- }
101
- catch (err) {
102
- process.stderr.write(chalk.red(`Cannot read bundle: ${err.message}\n`));
103
- process.exit(1);
104
- }
105
- try {
106
- bundle = parseBundle(text);
107
- }
108
- catch (err) {
109
- process.stderr.write(chalk.red(`${err.message}\n`));
110
- process.exit(1);
111
- }
112
- }
113
- if (options.agent) {
114
- bundle = { header: bundle.header, records: bundle.records.filter(r => r.agent === options.agent) };
115
- if (bundle.records.length === 0) {
116
- process.stderr.write(chalk.yellow(`No records for agent '${options.agent}' in this bundle.\n`));
117
- process.exit(1);
118
- }
119
- }
120
- const decryptKey = bundle.header.encrypted
121
- ? (managedDecryptKey ?? resolveDecryptKey(options.decrypt))
122
- : null;
123
- let plan;
124
- try {
125
- plan = planImport(bundle, { decryptKey });
126
- }
127
- catch (err) {
128
- process.stderr.write(chalk.red(`${err.message}\n`));
129
- process.exit(1);
130
- }
131
- if (options.dryRun) {
132
- printDryRun(plan, bundle);
133
- return;
134
- }
135
- const res = writeImport(plan, { overwrite: options.overwrite === true, decryptKey });
136
- const parts = [];
137
- if (res.placed)
138
- parts.push(`${res.placed} placed`);
139
- if (res.overwritten)
140
- parts.push(`${res.overwritten} overwritten`);
141
- if (res.skipped)
142
- parts.push(`${res.skipped} duplicate${res.skipped === 1 ? '' : 's'} skipped`);
143
- if (res.conflicts)
144
- parts.push(chalk.yellow(`${res.conflicts} conflict${res.conflicts === 1 ? '' : 's'} kept local (use --overwrite)`));
145
- if (res.unknown)
146
- parts.push(chalk.yellow(`${res.unknown} unknown-agent skipped`));
147
- process.stderr.write(chalk.green(`Imported: ${parts.join(', ') || 'nothing to do'}.\n`));
148
- }
149
- async function readStdin() {
150
- const chunks = [];
151
- for await (const chunk of process.stdin)
152
- chunks.push(Buffer.from(chunk));
153
- return Buffer.concat(chunks).toString('utf-8');
154
- }
155
- async function pullForImport(hosts, selector, g, command) {
156
- const args = [];
157
- if (selector && selector !== '-')
158
- args.push(selector);
159
- if (g.since)
160
- args.push('--since', g.since);
161
- const agent = command.optsWithGlobals().agent;
162
- if (agent)
163
- args.push('-a', agent);
164
- if (g.all !== false)
165
- args.push('--all');
166
- if (command.parent?.getOptionValueSource?.('limit') === 'cli' && g.limit)
167
- args.push('-n', String(g.limit));
168
- const { bundles, errors } = await pullBundlesFromHosts(hosts, args);
169
- for (const e of errors)
170
- process.stderr.write(chalk.yellow(` ${e}\n`));
171
- const records = mergeRecords(bundles.map(b => b.records));
172
- if (records.length === 0) {
173
- process.stderr.write(chalk.red('No sessions pulled from the given host(s).\n'));
174
- process.exit(1);
175
- }
176
- const header = makeHeader({
177
- origin: hosts.join(','),
178
- exportedAt: new Date().toISOString(),
179
- encrypted: false,
180
- redacted: bundles.some(b => b.header.redacted),
181
- records,
182
- });
183
- return { header, records };
184
- }
185
- export function r2ImportGateError(fromR2, isConfigured) {
186
- if (fromR2 && !isConfigured) {
187
- return ('R2 restore is not configured: the r2.backups secrets bundle is missing or locked.\n' +
188
- 'Add it with: agents secrets add r2.backups R2_ACCOUNT_ID R2_BUCKET_NAME R2_ACCESS_KEY_ID R2_SECRET_ACCESS_KEY');
189
- }
190
- return null;
191
- }
192
- export async function pullFromR2(resolvedClient) {
193
- let client;
194
- let bucket;
195
- if (resolvedClient) {
196
- client = resolvedClient;
197
- bucket = resolvedClient.kind === 'managed' ? 'managed' : 'byo';
198
- }
199
- else {
200
- try {
201
- const cfg = loadR2Config();
202
- bucket = cfg.bucket;
203
- client = new R2Client(cfg);
204
- }
205
- catch (err) {
206
- process.stderr.write(chalk.red(`R2 restore: ${err.message}\n`));
207
- process.exit(1);
208
- }
209
- }
210
- let keys;
211
- try {
212
- keys = client.kind === 'managed'
213
- ? await client.list()
214
- : await client.list(SESSIONS_PREFIX);
215
- }
216
- catch (err) {
217
- process.stderr.write(chalk.red(`R2 restore: listing failed: ${err.message}\n`));
218
- process.exit(1);
219
- }
220
- const records = [];
221
- let encryptedAny = false;
222
- let redactedAll = true;
223
- let skipped = 0;
224
- for (const key of keys) {
225
- if (key.endsWith('/manifest.json'))
226
- continue;
227
- let body;
228
- try {
229
- body = await client.get(key);
230
- }
231
- catch (err) {
232
- process.stderr.write(chalk.red(`R2 restore: fetching ${key} failed: ${err.message}\n`));
233
- process.exit(1);
234
- }
235
- if (body === null)
236
- continue;
237
- let parsed;
238
- try {
239
- parsed = parseBundle(body);
240
- }
241
- catch {
242
- skipped++;
243
- continue;
244
- }
245
- if (client.kind === 'managed') {
246
- const plaintext = !parsed.header.encrypted
247
- || parsed.records.some(rec => !rec.encrypted || !isTranscriptEnvelope(rec.body));
248
- if (plaintext) {
249
- process.stderr.write(chalk.red(`R2 restore: managed backup ${key} is not encrypted — managed transcripts are always sealed; refusing to import plaintext.\n`));
250
- process.exit(1);
251
- }
252
- }
253
- records.push(...parsed.records);
254
- if (parsed.header.encrypted)
255
- encryptedAny = true;
256
- if (!parsed.header.redacted)
257
- redactedAll = false;
258
- }
259
- if (skipped > 0) {
260
- process.stderr.write(chalk.yellow(`Skipped ${skipped} object(s) under ${SESSIONS_PREFIX} that are not session bundles.\n`));
261
- }
262
- const deduped = mergeRecords([records]);
263
- if (deduped.length === 0) {
264
- process.stderr.write(chalk.red(bucket === 'managed'
265
- ? 'No session backups found in the managed store.\n'
266
- : `No session backups found in R2 bucket '${bucket}'.\n`));
267
- process.exit(1);
268
- }
269
- const header = makeHeader({
270
- origin: `r2:${bucket}`,
271
- exportedAt: new Date().toISOString(),
272
- encrypted: encryptedAny,
273
- redacted: redactedAll,
274
- records: deduped,
275
- });
276
- return { header, records: deduped };
277
- }
278
- function resolveDecryptKey(decrypt) {
279
- if (typeof decrypt === 'string' && decrypt.trim()) {
280
- const raw = decrypt.trim();
281
- const key = /^[0-9a-f]{64}$/i.test(raw) ? Buffer.from(raw, 'hex') : Buffer.from(raw, 'base64');
282
- if (key.length !== 32) {
283
- process.stderr.write(chalk.red(`--decrypt key must decode to 32 bytes (got ${key.length}).\n`));
284
- process.exit(1);
285
- }
286
- return key;
287
- }
288
- try {
289
- const key = resolveSyncEncKey(loadR2Config());
290
- if (key)
291
- return key;
292
- }
293
- catch {
294
- }
295
- process.stderr.write(chalk.red('This bundle is encrypted but no key is available. Pass --decrypt <key>, ' +
296
- 'or configure the r2.backups sync bundle so its shared key is used.\n'));
297
- process.exit(1);
298
- }
299
- function printDryRun(plan, bundle) {
300
- const bySession = new Map();
301
- for (const item of plan) {
302
- const key = `${item.record.agent}:${item.record.machine}:${item.record.sessionId}`;
303
- let row = bySession.get(key);
304
- if (!row)
305
- bySession.set(key, (row = { agent: item.record.agent, machine: item.record.machine, sessionId: item.record.sessionId, statuses: new Set(), files: 0 }));
306
- row.statuses.add(item.status);
307
- row.files++;
308
- }
309
- process.stdout.write(chalk.bold(`Bundle: ${bundle.header.sessions} session(s), ${bundle.header.count} file(s), origin ${bundle.header.origin}${bundle.header.encrypted ? ', encrypted' : ''}\n\n`));
310
- const header = `${pad('SESSION', 22)}${pad('AGENT', 10)}${pad('ORIGIN', 16)}${pad('FILES', 7)}STATUS`;
311
- process.stdout.write(chalk.dim(header) + '\n');
312
- for (const row of bySession.values()) {
313
- const status = aggregateStatus(row.statuses);
314
- process.stdout.write(pad(row.sessionId.slice(0, 20), 22) +
315
- pad(row.agent, 10) +
316
- pad(row.machine, 16) +
317
- pad(String(row.files), 7) +
318
- colorStatus(status) + '\n');
319
- }
320
- process.stdout.write(chalk.dim('\n(dry run — nothing was written)\n'));
321
- }
322
- function aggregateStatus(statuses) {
323
- if (statuses.has('conflict'))
324
- return 'conflict';
325
- if (statuses.has('unknown'))
326
- return 'unknown';
327
- if (statuses.has('new'))
328
- return statuses.has('dup') ? 'partial' : 'new';
329
- return 'dup';
330
- }
331
- function colorStatus(status) {
332
- switch (status) {
333
- case 'new': return chalk.green(status);
334
- case 'dup': return chalk.dim(status);
335
- case 'partial': return chalk.cyan(status);
336
- case 'conflict': return chalk.yellow(status);
337
- case 'unknown': return chalk.red(status);
338
- default: return status;
339
- }
340
- }
341
- function pad(s, w) {
342
- return s.length >= w ? s.slice(0, w - 1) + ' ' : s + ' '.repeat(w - s.length);
343
- }
@@ -1,14 +0,0 @@
1
- import type { Command } from 'commander';
2
- interface InjectOptions {
3
- pane?: string;
4
- socket?: string;
5
- device?: string | string[];
6
- enter?: boolean;
7
- combined?: boolean;
8
- json?: boolean;
9
- }
10
- export declare function normalizeInjectDevice(value: string | string[] | undefined): string | undefined;
11
- export declare function buildRemoteInjectArgv(sessionId: string, text: string, options: InjectOptions): string[];
12
- export declare function resolveInjectSshTarget(device: string): Promise<string>;
13
- export declare function registerSessionsInjectCommand(sessionsCmd: Command): void;
14
- export {};
@@ -1,143 +0,0 @@
1
- import chalk from 'chalk';
2
- import { injectIntoTerminal } from '../lib/terminal/index.js';
3
- import { resolveLiveInjectTarget } from '../lib/session/inject-target.js';
4
- import { sshExec, shellQuote } from '../lib/ssh-exec.js';
5
- import { resolveHost } from '../lib/hosts/registry.js';
6
- import { sshTargetFor } from '../lib/hosts/types.js';
7
- import { setHelpSections } from '../lib/help.js';
8
- import { normalizeSingleDeviceOption } from './utils.js';
9
- export function normalizeInjectDevice(value) {
10
- return normalizeSingleDeviceOption(value, 'sessions inject');
11
- }
12
- export function buildRemoteInjectArgv(sessionId, text, options) {
13
- const argv = ['agents', 'sessions', 'inject', sessionId, text];
14
- if (options.enter === false)
15
- argv.push('--no-enter');
16
- if (options.combined)
17
- argv.push('--combined');
18
- if (options.socket)
19
- argv.push('--socket', options.socket);
20
- if (options.pane)
21
- argv.push('--pane', options.pane);
22
- if (options.json)
23
- argv.push('--json');
24
- return argv;
25
- }
26
- export async function resolveInjectSshTarget(device) {
27
- const host = await resolveHost(device);
28
- return host ? sshTargetFor(host) : device;
29
- }
30
- async function injectOnDevice(sessionId, text, options, device) {
31
- let target;
32
- try {
33
- target = await resolveInjectSshTarget(device);
34
- }
35
- catch (err) {
36
- const message = err instanceof Error ? err.message : String(err);
37
- if (options.json)
38
- console.log(JSON.stringify({ ok: false, error: message }));
39
- else
40
- console.error(chalk.red(message));
41
- process.exit(1);
42
- }
43
- const remoteCmd = buildRemoteInjectArgv(sessionId, text, options).map(shellQuote).join(' ');
44
- const res = sshExec(target, remoteCmd, { multiplex: true });
45
- if (res.stdout)
46
- process.stdout.write(res.stdout);
47
- if (res.stderr)
48
- process.stderr.write(res.stderr);
49
- if (res.code !== 0)
50
- process.exit(res.code ?? 1);
51
- }
52
- async function runInject(sessionId, text, options) {
53
- let device;
54
- try {
55
- device = normalizeInjectDevice(options.device);
56
- }
57
- catch (err) {
58
- const message = err instanceof Error ? err.message : String(err);
59
- if (options.json)
60
- console.log(JSON.stringify({ ok: false, error: message }));
61
- else
62
- console.error(chalk.red(message));
63
- process.exit(1);
64
- }
65
- let target = null;
66
- if (options.pane) {
67
- target = { backend: 'tmux', pane: options.pane, socket: options.socket };
68
- }
69
- else if (device) {
70
- return injectOnDevice(sessionId, text, options, device);
71
- }
72
- else {
73
- const resolved = await resolveLiveInjectTarget(sessionId);
74
- if (!resolved.target) {
75
- const message = resolved.hint ? `${resolved.reason}\n${resolved.hint}` : resolved.reason;
76
- if (options.json)
77
- console.log(JSON.stringify({ ok: false, error: message }));
78
- else
79
- console.error(chalk.red(message));
80
- process.exit(1);
81
- }
82
- target = resolved.target;
83
- }
84
- const res = await injectIntoTerminal(target, text, {
85
- enter: options.enter !== false,
86
- combined: options.combined,
87
- socket: options.socket,
88
- host: device,
89
- });
90
- if (options.json) {
91
- console.log(JSON.stringify(res));
92
- }
93
- else if (res.ok) {
94
- console.log(chalk.green(`Injected into ${res.backend} (${res.writes} write${res.writes === 1 ? '' : 's'}).`));
95
- }
96
- else {
97
- console.error(chalk.red(res.error ?? 'injection failed'));
98
- }
99
- if (!res.ok)
100
- process.exit(1);
101
- }
102
- export function registerSessionsInjectCommand(sessionsCmd) {
103
- const injectCmd = sessionsCmd
104
- .command('inject <sessionId> <text>')
105
- .description('Deliver text (+ Enter) into the terminal a running session lives in — nudge a stalled agent.')
106
- .option('--pane <id>', 'Target a tmux pane id directly (e.g. %3), skipping session lookup')
107
- .option('--socket <path>', 'tmux socket path (defaults to the session/shared socket)')
108
- .option('--device <target>', 'Deliver on a remote device over SSH. With a bare session id, the session is resolved ON that device; with --pane, the pane is addressed there directly.')
109
- .option('--no-enter', 'Send only the text, without a trailing Enter')
110
- .option('--combined', 'Fuse text + Enter into ONE write (default: two writes, Ink-TUI safe)')
111
- .option('--json', 'Output the InjectResult as JSON');
112
- setHelpSections(injectCmd, {
113
- examples: `
114
- # Nudge a stalled agent by session id (resolves its tmux pane)
115
- agents sessions inject a1b2c3d4 "continue"
116
-
117
- # Target a tmux pane directly (what a watchdog already holds)
118
- agents sessions inject _ "continue" --pane %3 --socket /tmp/agents/tmux.sock
119
-
120
- # Nudge a live session on another box (resolved on the device)
121
- agents sessions inject 214edaae "continue" --device yosemite-s0
122
-
123
- # Address a known remote pane directly (skips lookup, sends over SSH)
124
- agents sessions inject _ "continue" --pane %122 --socket $SOCK --device yosemite-s0
125
- `,
126
- notes: `
127
- - Ink-TUI Enter semantics: by default the text and Enter are two separate
128
- writes, which is what Claude's Ink TUI needs. --combined fuses them.
129
- - A session is addressable by id when it resolves to a precise split —
130
- tmux, iTerm, or a VSCodium/Cursor/VS Code integrated terminal
131
- (resolveInjectTargetForSession). Use --pane for direct targeting.
132
- - The id may be the session id (short or full) OR the '<shortid>' suffix of
133
- a tmux target (ag-<agent>-<shortid>) — the only selector a live tmux
134
- session whose id column shows '-' exposes.
135
- - Built on the Terminal Engine (src/lib/terminal): with --pane, --device
136
- runs the tmux send-keys spec over SSH; with a bare id, --device re-runs
137
- the lookup on that box (its tmux panes live there, not here).
138
- `,
139
- });
140
- injectCmd.action(async (sessionId, text, _options, command) => {
141
- await runInject(sessionId, text, command.optsWithGlobals());
142
- });
143
- }
@@ -1,24 +0,0 @@
1
- interface SessionsPickerGateOpts {
2
- interactive?: boolean;
3
- json?: boolean;
4
- open?: string | boolean;
5
- }
6
- interface SessionsPickerCommandSpec<TRow, TOpts extends SessionsPickerGateOpts> {
7
- requireOpenUndefined?: boolean;
8
- runFlat: (opts: TOpts) => void | Promise<void>;
9
- buildRows: (opts: TOpts) => TRow[];
10
- emptyMessage: (opts: TOpts) => string;
11
- message: string;
12
- matches: (row: TRow, query: string) => boolean;
13
- labelFor: (row: TRow) => string;
14
- buildPreview: (row: TRow) => string;
15
- emptyFilterMessage: string;
16
- enterHint: string;
17
- onOpen: (row: TRow) => void | Promise<void>;
18
- }
19
- interface SessionsPickerCommand<TOpts extends SessionsPickerGateOpts> {
20
- shouldOpen: (opts: TOpts, isTTY: boolean) => boolean;
21
- run: (opts: TOpts) => Promise<void>;
22
- }
23
- export declare function createSessionsPickerCommand<TRow, TOpts extends SessionsPickerGateOpts>(spec: SessionsPickerCommandSpec<TRow, TOpts>): SessionsPickerCommand<TOpts>;
24
- export {};
@@ -1,59 +0,0 @@
1
- import { itemPicker } from '../lib/picker.js';
2
- import { isInteractiveTerminal, isPromptCancelled } from './utils.js';
3
- function shouldOpenInteractiveSessions(opts, isTTY, requireOpenUndefined = false) {
4
- return (opts.interactive !== false &&
5
- !opts.json &&
6
- (!requireOpenUndefined || opts.open === undefined) &&
7
- isTTY);
8
- }
9
- async function browseSessionsUntilQuit(spec) {
10
- for (;;) {
11
- let picked;
12
- try {
13
- picked = await itemPicker({
14
- message: spec.message,
15
- items: spec.rows,
16
- filter: (query) => (query.trim() ? spec.rows.filter((r) => spec.matches(r, query)) : spec.rows),
17
- labelFor: spec.labelFor,
18
- buildPreview: spec.buildPreview,
19
- emptyMessage: spec.emptyFilterMessage,
20
- enterHint: spec.enterHint,
21
- });
22
- }
23
- catch (err) {
24
- if (isPromptCancelled(err))
25
- return;
26
- throw err;
27
- }
28
- if (!picked)
29
- return;
30
- await spec.onOpen(picked.item);
31
- }
32
- }
33
- export function createSessionsPickerCommand(spec) {
34
- const shouldOpen = (opts, isTTY) => shouldOpenInteractiveSessions(opts, isTTY, spec.requireOpenUndefined === true);
35
- return {
36
- shouldOpen,
37
- run: async (opts) => {
38
- if (!shouldOpen(opts, isInteractiveTerminal())) {
39
- await spec.runFlat(opts);
40
- return;
41
- }
42
- const rows = spec.buildRows(opts);
43
- if (rows.length === 0) {
44
- console.log(spec.emptyMessage(opts));
45
- return;
46
- }
47
- await browseSessionsUntilQuit({
48
- message: spec.message,
49
- rows,
50
- matches: spec.matches,
51
- labelFor: spec.labelFor,
52
- buildPreview: spec.buildPreview,
53
- emptyFilterMessage: spec.emptyFilterMessage,
54
- enterHint: spec.enterHint,
55
- onOpen: spec.onOpen,
56
- });
57
- },
58
- };
59
- }
@@ -1,11 +0,0 @@
1
- import type { Command } from 'commander';
2
- import type { SessionMeta } from '@phnx-labs/sessions-cli/reader';
3
- export declare const MARKDOWN_RENDER_AGENTS: readonly ["claude", "codex", "antigravity", "opencode", "grok", "rush", "hermes", "kimi", "droid", "cursor"];
4
- export type ReasoningMode = 'omit' | 'fold' | 'include';
5
- export declare function renderSessionMarkdownDocument(session: SessionMeta, options?: {
6
- redact?: boolean;
7
- reasoning?: ReasoningMode;
8
- knownSecrets?: readonly string[];
9
- maxToolOutputChars?: number;
10
- }): string;
11
- export declare function registerSessionsRenderCommand(sessionsCmd: Command): void;