@phnx-labs/agents-cli 1.23.17 → 1.23.19
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.
- package/CHANGELOG.md +239 -0
- package/README.md +140 -165
- package/dist/bootstrap.js +11 -17
- package/dist/cli/command-registry.d.ts +1 -2
- package/dist/cli/command-registry.js +1 -10
- package/dist/commands/accounts.js +7 -7
- package/dist/commands/cloud-transcripts.d.ts +0 -1
- package/dist/commands/cloud-transcripts.js +2 -2
- package/dist/commands/cloud.js +2 -2
- package/dist/commands/config.js +1 -5
- package/dist/commands/cost.js +1 -1
- package/dist/commands/daemon-index.js +0 -1
- package/dist/commands/detach.d.ts +1 -1
- package/dist/commands/detach.js +10 -6
- package/dist/commands/doctor.js +11 -7
- package/dist/commands/exec.d.ts +0 -17
- package/dist/commands/exec.js +26 -72
- package/dist/commands/feed.d.ts +1 -1
- package/dist/commands/feed.js +3 -3
- package/dist/commands/focus.d.ts +11 -6
- package/dist/commands/focus.js +91 -31
- package/dist/commands/fork.d.ts +0 -1
- package/dist/commands/fork.js +7 -16
- package/dist/commands/harness-wizard.js +1 -1
- package/dist/commands/harness.js +1 -1
- package/dist/commands/insights.d.ts +0 -1
- package/dist/commands/insights.js +3 -7
- package/dist/commands/open.js +1 -1
- package/dist/commands/output.js +1 -1
- package/dist/commands/profiles.d.ts +1 -1
- package/dist/commands/profiles.js +2 -2
- package/dist/commands/projects-todo.js +10 -5
- package/dist/commands/projects.js +1 -1
- package/dist/commands/prune.js +1 -1
- package/dist/commands/ps.d.ts +8 -3
- package/dist/commands/ps.js +238 -110
- package/dist/commands/routines.js +1 -1
- package/dist/commands/send.js +1 -1
- package/dist/commands/sessions-backfill.d.ts +0 -1
- package/dist/commands/sessions-backfill.js +3 -6
- package/dist/commands/sessions-browser.d.ts +0 -10
- package/dist/commands/sessions-browser.js +19 -25
- package/dist/commands/sessions-migrate.d.ts +2 -2
- package/dist/commands/sessions-migrate.js +13 -13
- package/dist/commands/sessions-optimize.d.ts +0 -1
- package/dist/commands/sessions-optimize.js +0 -3
- package/dist/commands/sessions-picker.d.ts +0 -7
- package/dist/commands/sessions-picker.js +16 -310
- package/dist/commands/sessions-resume.d.ts +16 -15
- package/dist/commands/sessions-resume.js +101 -269
- package/dist/commands/sessions-stats.d.ts +0 -1
- package/dist/commands/sessions-stats.js +5 -8
- package/dist/commands/sessions-stop.d.ts +1 -1
- package/dist/commands/sessions-stop.js +8 -8
- package/dist/commands/sessions-trace.d.ts +1 -1
- package/dist/commands/sessions-trace.js +40 -17
- package/dist/commands/sessions-watch.js +2 -2
- package/dist/commands/sessions.test-fixture.d.ts +1 -0
- package/dist/commands/sessions.test-fixture.js +14 -0
- package/dist/commands/setup-browser.js +4 -4
- package/dist/commands/setup-computer.js +4 -4
- package/dist/commands/setup-fleet.js +1 -1
- package/dist/commands/setup-preferences.js +1 -1
- package/dist/commands/{sessions-backup-setup.d.ts → setup-session-backup.d.ts} +2 -2
- package/dist/commands/{sessions-backup-setup.js → setup-session-backup.js} +8 -8
- package/dist/commands/setup.js +3 -1
- package/dist/commands/ssh.js +4 -5
- package/dist/commands/sync.js +1 -1
- package/dist/commands/teams.js +2 -2
- package/dist/commands/utils.d.ts +0 -1
- package/dist/commands/utils.js +0 -10
- package/dist/index.js +0 -71
- package/dist/lib/account-registry.d.ts +3 -0
- package/dist/lib/account-registry.js +40 -0
- package/dist/lib/accounting/usage-sync.d.ts +1 -0
- package/dist/lib/accounting/usage-sync.js +20 -3
- package/dist/lib/accounting/usage.d.ts +4 -1
- package/dist/lib/accounting/usage.js +38 -6
- package/dist/lib/agent-spec/agents.js +12 -11
- package/dist/lib/analytics/mix-commands.js +1 -1
- package/dist/lib/auth-mint.js +2 -2
- package/dist/lib/browser-client.d.ts +0 -1
- package/dist/lib/browser-client.js +0 -3
- package/dist/lib/cloud/antigravity.js +1 -1
- package/dist/lib/cloud/cursor.js +3 -3
- package/dist/lib/cloud/store.d.ts +5 -1
- package/dist/lib/cloud/store.js +10 -3
- package/dist/lib/cloudflare/creds.js +2 -2
- package/dist/lib/computer/context.d.ts +4 -21
- package/dist/lib/computer/context.js +3 -24
- package/dist/lib/computer/policy.d.ts +0 -10
- package/dist/lib/computer/policy.js +0 -28
- package/dist/lib/computer-client.d.ts +0 -44
- package/dist/lib/computer-client.js +17 -121
- package/dist/lib/config-keys.d.ts +2 -2
- package/dist/lib/config-keys.js +1 -3
- package/dist/lib/crabbox/cli.js +1 -1
- package/dist/lib/daemon/account-state-daemon-service.js +9 -2
- package/dist/lib/daemon/self-update-service.js +1 -1
- package/dist/lib/device-config.d.ts +2 -1
- package/dist/lib/device-config.js +26 -39
- package/dist/lib/devices/connect.d.ts +1 -1
- package/dist/lib/devices/connect.js +3 -6
- package/dist/lib/devices/doctor-findings.d.ts +2 -1
- package/dist/lib/devices/doctor-findings.js +4 -4
- package/dist/lib/devices/health.d.ts +6 -0
- package/dist/lib/devices/health.js +11 -4
- package/dist/lib/exec.js +1 -1
- package/dist/lib/feed/activity.js +1 -1
- package/dist/lib/feed/watch.js +2 -1
- package/dist/lib/fleet/apply.d.ts +1 -1
- package/dist/lib/fleet/apply.js +6 -3
- package/dist/lib/fleet-shared-state.d.ts +2 -0
- package/dist/lib/fleet-shared-state.js +3 -1
- package/dist/lib/github/project-prs.js +14 -1
- package/dist/lib/help.d.ts +0 -1
- package/dist/lib/help.js +2 -10
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/hosts/option.js +1 -1
- package/dist/lib/hosts/passthrough.d.ts +0 -1
- package/dist/lib/hosts/passthrough.js +2 -26
- package/dist/lib/hosts/reconnect.js +5 -5
- package/dist/lib/hosts/remote-cmd.d.ts +3 -5
- package/dist/lib/hosts/remote-cmd.js +15 -20
- package/dist/lib/hosts/remote-session-id.js +1 -1
- package/dist/lib/installations/active-check.js +1 -1
- package/dist/lib/installations/migrate.js +4 -15
- package/dist/lib/installations/versions.js +5 -4
- package/dist/lib/launch-log.js +3 -6
- package/dist/lib/owner-notify.d.ts +1 -6
- package/dist/lib/owner-notify.js +0 -2
- package/dist/lib/paths.d.ts +0 -1
- package/dist/lib/paths.js +0 -8
- package/dist/lib/permissions.js +1 -1
- package/dist/lib/project-root.d.ts +1 -0
- package/dist/lib/project-root.js +11 -3
- package/dist/lib/projects.js +2 -2
- package/dist/lib/quick-todo.d.ts +5 -1
- package/dist/lib/quick-todo.js +14 -1
- package/dist/lib/redact.d.ts +0 -1
- package/dist/lib/redact.js +0 -4
- package/dist/lib/remote-agents-json.d.ts +3 -1
- package/dist/lib/remote-agents-json.js +12 -8
- package/dist/lib/reserved-stores.js +1 -1
- package/dist/lib/scheduling/routines.d.ts +0 -1
- package/dist/lib/scheduling/routines.js +1 -1
- package/dist/lib/self-update.d.ts +1 -1
- package/dist/lib/self-update.js +59 -2
- package/dist/lib/session/active.d.ts +1 -1
- package/dist/lib/session/db.js +4 -4
- package/dist/lib/session/detached.d.ts +0 -1
- package/dist/lib/session/detached.js +0 -23
- package/dist/lib/session/discover.d.ts +2 -2
- package/dist/lib/session/glance-files.d.ts +21 -0
- package/dist/lib/session/glance-files.js +123 -0
- package/dist/lib/session/presentation.d.ts +3 -7
- package/dist/lib/session/presentation.js +4 -4
- package/dist/lib/session/preview-digest.d.ts +13 -0
- package/dist/lib/session/preview-digest.js +328 -0
- package/dist/lib/session/projection.js +1 -1
- package/dist/lib/session/remote/remote-list.d.ts +5 -2
- package/dist/lib/session/remote/remote-list.js +15 -8
- package/dist/lib/session/remote/watch.d.ts +2 -0
- package/dist/lib/session/remote/watch.js +90 -10
- package/dist/lib/session/remote-active.js +1 -1
- package/dist/lib/session/resume-command.d.ts +0 -1
- package/dist/lib/session/resume-command.js +1 -4
- package/dist/lib/session/resume-owner.d.ts +0 -2
- package/dist/lib/session/resume-owner.js +0 -6
- package/dist/lib/session/selection.d.ts +4 -5
- package/dist/lib/session/selection.js +2 -2
- package/dist/lib/session/sync/config.d.ts +0 -25
- package/dist/lib/session/sync/config.js +0 -62
- package/dist/lib/session/sync/managed-config.d.ts +0 -1
- package/dist/lib/session/sync/managed-config.js +0 -3
- package/dist/lib/session/sync/worker-template.js +1 -1
- package/dist/lib/sessions-client.d.ts +0 -16
- package/dist/lib/sessions-client.js +1 -187
- package/dist/lib/smart-launch.js +6 -1
- package/dist/lib/startup/command-registry.d.ts +2 -0
- package/dist/lib/startup/command-registry.js +36 -3
- package/dist/lib/startup/root-command.d.ts +0 -1
- package/dist/lib/startup/root-command.js +0 -21
- package/dist/lib/sync-umbrella.js +1 -1
- package/dist/lib/teams/placement-probe.d.ts +2 -0
- package/dist/lib/teams/placement-probe.js +8 -3
- package/dist/lib/terminal/engine.d.ts +2 -0
- package/dist/lib/terminal/engine.js +5 -3
- package/dist/lib/terminal/index.d.ts +1 -1
- package/dist/lib/terminal/index.js +1 -1
- package/dist/lib/terminal/resolve.js +1 -1
- package/dist/lib/terminal/run-surface.d.ts +1 -0
- package/dist/lib/terminal/run-surface.js +9 -0
- package/dist/lib/watchdog/rotate.js +1 -1
- package/dist/lib/watchdog/watchdog.d.ts +1 -1
- package/dist/lib/watchdog/watchdog.js +2 -2
- package/package.json +1 -1
- package/dist/commands/browser.d.ts +0 -7
- package/dist/commands/browser.js +0 -139
- package/dist/commands/computer.d.ts +0 -48
- package/dist/commands/computer.js +0 -244
- package/dist/commands/resume.d.ts +0 -23
- package/dist/commands/resume.js +0 -158
- package/dist/commands/secrets-passthrough.d.ts +0 -3
- package/dist/commands/secrets-passthrough.js +0 -52
- package/dist/commands/sessions-bookmark.d.ts +0 -2
- package/dist/commands/sessions-bookmark.js +0 -92
- package/dist/commands/sessions-export.d.ts +0 -31
- package/dist/commands/sessions-export.js +0 -409
- package/dist/commands/sessions-import.d.ts +0 -6
- package/dist/commands/sessions-import.js +0 -343
- package/dist/commands/sessions-inject.d.ts +0 -14
- package/dist/commands/sessions-inject.js +0 -143
- package/dist/commands/sessions-picker-factory.d.ts +0 -24
- package/dist/commands/sessions-picker-factory.js +0 -59
- package/dist/commands/sessions-render.d.ts +0 -11
- package/dist/commands/sessions-render.js +0 -119
- package/dist/commands/sessions-share.d.ts +0 -15
- package/dist/commands/sessions-share.js +0 -171
- package/dist/commands/sessions.d.ts +0 -122
- package/dist/commands/sessions.js +0 -1760
- package/dist/lib/address.d.ts +0 -39
- package/dist/lib/address.js +0 -128
- package/dist/lib/computer/record.d.ts +0 -6
- package/dist/lib/computer/record.js +0 -25
- package/dist/lib/onepassword.d.ts +0 -57
- package/dist/lib/onepassword.js +0 -140
- package/dist/lib/openclaw-keychain.d.ts +0 -43
- package/dist/lib/openclaw-keychain.js +0 -227
- package/dist/lib/session/bundle.d.ts +0 -76
- package/dist/lib/session/bundle.js +0 -146
- package/dist/lib/session/remote/remote-bundle.d.ts +0 -7
- package/dist/lib/session/remote/remote-bundle.js +0 -40
- package/dist/lib/session/remote/remote.d.ts +0 -35
- package/dist/lib/session/remote/remote.js +0 -198
- package/dist/lib/session/remote-bundle.d.ts +0 -1
- package/dist/lib/session/remote-bundle.js +0 -1
- package/dist/lib/session/remote.d.ts +0 -1
- package/dist/lib/session/remote.js +0 -1
- package/dist/lib/session/sync/agents.d.ts +0 -24
- package/dist/lib/session/sync/agents.js +0 -0
- package/dist/lib/session/sync/backend.d.ts +0 -22
- package/dist/lib/session/sync/backend.js +0 -44
- package/dist/lib/session/sync/managed-key.d.ts +0 -5
- package/dist/lib/session/sync/managed-key.js +0 -87
- package/dist/lib/session/sync/net-client.d.ts +0 -29
- package/dist/lib/session/sync/net-client.js +0 -87
- package/dist/lib/session/sync/r2.d.ts +0 -20
- package/dist/lib/session/sync/r2.js +0 -103
- package/dist/lib/session/sync/transcript-crypto.d.ts +0 -41
- package/dist/lib/session/sync/transcript-crypto.js +0 -115
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { type SyncAgentSpec } from './sync/agents.js';
|
|
2
|
-
export declare const BUNDLE_KIND = "agents-session-bundle";
|
|
3
|
-
export interface BundleHeader {
|
|
4
|
-
kind: typeof BUNDLE_KIND;
|
|
5
|
-
version: number;
|
|
6
|
-
exportedAt: string;
|
|
7
|
-
origin: string;
|
|
8
|
-
encrypted: boolean;
|
|
9
|
-
redacted: boolean;
|
|
10
|
-
count: number;
|
|
11
|
-
sessions: number;
|
|
12
|
-
}
|
|
13
|
-
export interface BundleRecord {
|
|
14
|
-
agent: string;
|
|
15
|
-
machine: string;
|
|
16
|
-
sessionId: string;
|
|
17
|
-
relKey: string;
|
|
18
|
-
size: number;
|
|
19
|
-
hash: string;
|
|
20
|
-
label?: string;
|
|
21
|
-
encrypted: boolean;
|
|
22
|
-
body: string;
|
|
23
|
-
}
|
|
24
|
-
export interface ParsedBundle {
|
|
25
|
-
header: BundleHeader;
|
|
26
|
-
records: BundleRecord[];
|
|
27
|
-
}
|
|
28
|
-
export interface FileToExport {
|
|
29
|
-
agent: string;
|
|
30
|
-
machine: string;
|
|
31
|
-
sessionId: string;
|
|
32
|
-
relKey: string;
|
|
33
|
-
absPath: string;
|
|
34
|
-
label?: string;
|
|
35
|
-
}
|
|
36
|
-
interface BuildRecordOpts {
|
|
37
|
-
redact: boolean;
|
|
38
|
-
encryptKey: Buffer | null;
|
|
39
|
-
knownSecrets?: readonly string[];
|
|
40
|
-
}
|
|
41
|
-
export declare function specForAgent(agentId: string): SyncAgentSpec | undefined;
|
|
42
|
-
export declare function buildRecord(file: FileToExport, opts: BuildRecordOpts): BundleRecord;
|
|
43
|
-
export declare function makeHeader(args: {
|
|
44
|
-
origin: string;
|
|
45
|
-
exportedAt: string;
|
|
46
|
-
encrypted: boolean;
|
|
47
|
-
redacted: boolean;
|
|
48
|
-
records: BundleRecord[];
|
|
49
|
-
}): BundleHeader;
|
|
50
|
-
export declare function mergeRecords(sets: BundleRecord[][]): BundleRecord[];
|
|
51
|
-
export declare function serializeBundle(header: BundleHeader, records: BundleRecord[]): string;
|
|
52
|
-
export declare function writeBundleFile(outPath: string, wire: string): void;
|
|
53
|
-
export declare function parseBundle(text: string): ParsedBundle;
|
|
54
|
-
export type ImportStatus = 'new' | 'dup' | 'conflict' | 'unknown';
|
|
55
|
-
export interface ImportPlanItem {
|
|
56
|
-
record: BundleRecord;
|
|
57
|
-
targetPath: string;
|
|
58
|
-
status: ImportStatus;
|
|
59
|
-
}
|
|
60
|
-
interface PlanImportOpts {
|
|
61
|
-
decryptKey: Buffer | null;
|
|
62
|
-
}
|
|
63
|
-
export declare function planImport(bundle: ParsedBundle, opts: PlanImportOpts): ImportPlanItem[];
|
|
64
|
-
export interface WriteResult {
|
|
65
|
-
placed: number;
|
|
66
|
-
skipped: number;
|
|
67
|
-
overwritten: number;
|
|
68
|
-
conflicts: number;
|
|
69
|
-
unknown: number;
|
|
70
|
-
}
|
|
71
|
-
interface WriteImportOpts {
|
|
72
|
-
overwrite: boolean;
|
|
73
|
-
decryptKey: Buffer | null;
|
|
74
|
-
}
|
|
75
|
-
export declare function writeImport(plan: ImportPlanItem[], opts: WriteImportOpts): WriteResult;
|
|
76
|
-
export {};
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import * as crypto from 'crypto';
|
|
4
|
-
import { SYNC_AGENTS, mirrorPath } from './sync/agents.js';
|
|
5
|
-
import { redactSecrets } from '../redact.js';
|
|
6
|
-
import { encryptTranscript, decryptTranscriptBody } from './sync/transcript-crypto.js';
|
|
7
|
-
export const BUNDLE_KIND = 'agents-session-bundle';
|
|
8
|
-
const BUNDLE_VERSION = 1;
|
|
9
|
-
function hashContent(content) {
|
|
10
|
-
return crypto.createHash('sha256').update(content).digest('hex');
|
|
11
|
-
}
|
|
12
|
-
export function specForAgent(agentId) {
|
|
13
|
-
return SYNC_AGENTS.find(s => s.id === agentId);
|
|
14
|
-
}
|
|
15
|
-
export function buildRecord(file, opts) {
|
|
16
|
-
let body = fs.readFileSync(file.absPath, 'utf-8');
|
|
17
|
-
if (opts.redact)
|
|
18
|
-
body = redactSecrets(body, opts.knownSecrets);
|
|
19
|
-
const hash = hashContent(body);
|
|
20
|
-
const size = Buffer.byteLength(body, 'utf-8');
|
|
21
|
-
let stored = body;
|
|
22
|
-
let encrypted = false;
|
|
23
|
-
if (opts.encryptKey) {
|
|
24
|
-
stored = encryptTranscript(body, opts.encryptKey);
|
|
25
|
-
encrypted = true;
|
|
26
|
-
}
|
|
27
|
-
const rec = {
|
|
28
|
-
agent: file.agent,
|
|
29
|
-
machine: file.machine,
|
|
30
|
-
sessionId: file.sessionId,
|
|
31
|
-
relKey: file.relKey,
|
|
32
|
-
size,
|
|
33
|
-
hash,
|
|
34
|
-
encrypted,
|
|
35
|
-
body: stored,
|
|
36
|
-
};
|
|
37
|
-
if (file.label)
|
|
38
|
-
rec.label = file.label;
|
|
39
|
-
return rec;
|
|
40
|
-
}
|
|
41
|
-
export function makeHeader(args) {
|
|
42
|
-
const sessions = new Set(args.records.map(r => `${r.agent}:${r.machine}:${r.sessionId}`)).size;
|
|
43
|
-
return {
|
|
44
|
-
kind: BUNDLE_KIND,
|
|
45
|
-
version: BUNDLE_VERSION,
|
|
46
|
-
exportedAt: args.exportedAt,
|
|
47
|
-
origin: args.origin,
|
|
48
|
-
encrypted: args.encrypted,
|
|
49
|
-
redacted: args.redacted,
|
|
50
|
-
count: args.records.length,
|
|
51
|
-
sessions,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export function mergeRecords(sets) {
|
|
55
|
-
const seen = new Set();
|
|
56
|
-
const out = [];
|
|
57
|
-
for (const set of sets) {
|
|
58
|
-
for (const r of set) {
|
|
59
|
-
const key = `${r.agent}:${r.machine}:${r.sessionId}:${r.relKey}`;
|
|
60
|
-
if (seen.has(key))
|
|
61
|
-
continue;
|
|
62
|
-
seen.add(key);
|
|
63
|
-
out.push(r);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
|
-
export function serializeBundle(header, records) {
|
|
69
|
-
const lines = [JSON.stringify(header)];
|
|
70
|
-
for (const r of records)
|
|
71
|
-
lines.push(JSON.stringify(r));
|
|
72
|
-
return lines.join('\n') + '\n';
|
|
73
|
-
}
|
|
74
|
-
export function writeBundleFile(outPath, wire) {
|
|
75
|
-
fs.writeFileSync(outPath, wire, { encoding: 'utf-8', mode: 0o600 });
|
|
76
|
-
fs.chmodSync(outPath, 0o600);
|
|
77
|
-
}
|
|
78
|
-
export function parseBundle(text) {
|
|
79
|
-
const lines = text.split('\n').filter(l => l.trim().length > 0);
|
|
80
|
-
if (lines.length === 0)
|
|
81
|
-
throw new Error('Empty session bundle.');
|
|
82
|
-
let header;
|
|
83
|
-
try {
|
|
84
|
-
header = JSON.parse(lines[0]);
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
throw new Error('Malformed session bundle: first line is not JSON.');
|
|
88
|
-
}
|
|
89
|
-
if (!header || header.kind !== BUNDLE_KIND) {
|
|
90
|
-
throw new Error(`Not an agents session bundle (kind=${header?.kind ?? 'missing'}).`);
|
|
91
|
-
}
|
|
92
|
-
if (header.version !== BUNDLE_VERSION) {
|
|
93
|
-
throw new Error(`Unsupported bundle version ${header.version} — this CLI reads v${BUNDLE_VERSION}.`);
|
|
94
|
-
}
|
|
95
|
-
const records = [];
|
|
96
|
-
for (let i = 1; i < lines.length; i++) {
|
|
97
|
-
try {
|
|
98
|
-
records.push(JSON.parse(lines[i]));
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
throw new Error(`Malformed session bundle: record on line ${i + 1} is not JSON.`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return { header, records };
|
|
105
|
-
}
|
|
106
|
-
export function planImport(bundle, opts) {
|
|
107
|
-
return bundle.records.map((record) => {
|
|
108
|
-
const spec = specForAgent(record.agent);
|
|
109
|
-
if (!spec)
|
|
110
|
-
return { record, targetPath: '', status: 'unknown' };
|
|
111
|
-
const body = decryptTranscriptBody(record.body, opts.decryptKey);
|
|
112
|
-
const bodyHash = hashContent(body);
|
|
113
|
-
const targetPath = mirrorPath(spec, record.machine, record.relKey);
|
|
114
|
-
let status = 'new';
|
|
115
|
-
if (fs.existsSync(targetPath)) {
|
|
116
|
-
const existing = fs.readFileSync(targetPath, 'utf-8');
|
|
117
|
-
status = hashContent(existing) === bodyHash ? 'dup' : 'conflict';
|
|
118
|
-
}
|
|
119
|
-
return { record, targetPath, status };
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
export function writeImport(plan, opts) {
|
|
123
|
-
const res = { placed: 0, skipped: 0, overwritten: 0, conflicts: 0, unknown: 0 };
|
|
124
|
-
for (const item of plan) {
|
|
125
|
-
if (item.status === 'unknown') {
|
|
126
|
-
res.unknown++;
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
if (item.status === 'dup') {
|
|
130
|
-
res.skipped++;
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (item.status === 'conflict' && !opts.overwrite) {
|
|
134
|
-
res.conflicts++;
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
const body = decryptTranscriptBody(item.record.body, opts.decryptKey);
|
|
138
|
-
fs.mkdirSync(path.dirname(item.targetPath), { recursive: true });
|
|
139
|
-
fs.writeFileSync(item.targetPath, body, 'utf-8');
|
|
140
|
-
if (item.status === 'conflict')
|
|
141
|
-
res.overwritten++;
|
|
142
|
-
else
|
|
143
|
-
res.placed++;
|
|
144
|
-
}
|
|
145
|
-
return res;
|
|
146
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import { sshExec } from '../../ssh-exec.js';
|
|
3
|
-
import { shellQuote } from '../../ssh-exec.js';
|
|
4
|
-
import { resolveExplicitTargets } from '../../devices/resolve-target.js';
|
|
5
|
-
import { remoteShellFor, buildWindowsAgentsCommand } from '../../hosts/remote-cmd.js';
|
|
6
|
-
import { parseBundle } from '../bundle.js';
|
|
7
|
-
const REMOTE_EXPORT_TIMEOUT_MS = 300_000;
|
|
8
|
-
function remoteAgentsCommand(args, os) {
|
|
9
|
-
if (remoteShellFor(os) === 'powershell') {
|
|
10
|
-
return buildWindowsAgentsCommand({ args });
|
|
11
|
-
}
|
|
12
|
-
const inner = ['agents', ...args].map((t, i) => (i === 0 ? t : shellQuote(t))).join(' ');
|
|
13
|
-
return `bash -lc ${shellQuote(inner)}`;
|
|
14
|
-
}
|
|
15
|
-
export async function pullBundlesFromHosts(hosts, exportArgs) {
|
|
16
|
-
const targets = await resolveExplicitTargets(hosts);
|
|
17
|
-
const bundles = [];
|
|
18
|
-
const errors = [];
|
|
19
|
-
for (const t of targets) {
|
|
20
|
-
const cmd = remoteAgentsCommand(['sessions', 'export', ...exportArgs, '--stdout'], t.os);
|
|
21
|
-
process.stderr.write(chalk.dim(`Pulling sessions from ${t.name}…\n`));
|
|
22
|
-
const res = sshExec(t.target, cmd, { timeoutMs: REMOTE_EXPORT_TIMEOUT_MS, extraSshArgs: t.extraSshArgs });
|
|
23
|
-
if (res.timedOut) {
|
|
24
|
-
errors.push(`${t.name}: timed out after ${Math.round(REMOTE_EXPORT_TIMEOUT_MS / 1000)}s`);
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
if (res.code !== 0) {
|
|
28
|
-
const tail = res.stderr.trim().split('\n').filter(Boolean).pop();
|
|
29
|
-
errors.push(`${t.name}: remote export failed (${res.code ?? 'ssh error'})${tail ? ': ' + tail : ''}`);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
bundles.push(parseBundle(res.stdout));
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
errors.push(`${t.name}: ${err.message}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return { bundles, errors };
|
|
40
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export declare function shellQuote(s: string): string;
|
|
2
|
-
export declare function buildForwardedArgs(argv: string[], hosts?: Set<string>): string[];
|
|
3
|
-
export declare function ensureWholeIndex(forwardedArgs: string[]): string[];
|
|
4
|
-
export declare function buildRemoteCommand(forwardedArgs: string[], columns?: number, os?: string): string;
|
|
5
|
-
type SshOutcome = 'ok' | 'unreachable' | 'query-failed' | 'spawn-error';
|
|
6
|
-
export declare function classifySshFailure(res: {
|
|
7
|
-
error?: Error | null;
|
|
8
|
-
status: number | null;
|
|
9
|
-
}): SshOutcome;
|
|
10
|
-
export declare const REMOTE_CACHE_MAX_AGE_MS = 15000;
|
|
11
|
-
export declare function remoteCachePath(host: string, forwardedArgs: string[]): string;
|
|
12
|
-
export declare function isRemoteCacheFresh(mtimeMs: number, nowMs: number, maxAgeMs?: number): boolean;
|
|
13
|
-
interface RemoteCacheHit {
|
|
14
|
-
output: string;
|
|
15
|
-
mtimeMs: number;
|
|
16
|
-
}
|
|
17
|
-
export declare function readRemoteCache(host: string, forwardedArgs: string[], opts?: {
|
|
18
|
-
maxAgeMs?: number;
|
|
19
|
-
nowMs?: number;
|
|
20
|
-
}): RemoteCacheHit | null;
|
|
21
|
-
export declare function formatStaleBanner(host: string, mtimeMs: number): string;
|
|
22
|
-
export declare function formatUnreachable(host: string): string;
|
|
23
|
-
export declare function writeRemoteCache(host: string, forwardedArgs: string[], output: string): void;
|
|
24
|
-
export declare function serveWarmRemoteCache(host: string, forwardedArgs: string[], opts?: {
|
|
25
|
-
maxAgeMs?: number;
|
|
26
|
-
nowMs?: number;
|
|
27
|
-
}): boolean;
|
|
28
|
-
export declare function replayRemoteCache(host: string, forwardedArgs: string[]): boolean;
|
|
29
|
-
interface RunRemoteSessionsOptions {
|
|
30
|
-
forceRefresh?: boolean;
|
|
31
|
-
maxAgeMs?: number;
|
|
32
|
-
nowMs?: number;
|
|
33
|
-
}
|
|
34
|
-
export declare function runRemoteSessions(hosts: string[], argv?: string[], opts?: RunRemoteSessionsOptions): void;
|
|
35
|
-
export {};
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `agents sessions --device <target>` — run the session query on a remote machine
|
|
3
|
-
* over SSH and stream its output back. Session transcripts and the index DB live
|
|
4
|
-
* on the machine that produced them (see `discover.ts`, all `os.homedir()`-rooted),
|
|
5
|
-
* so instead of syncing the bytes here we invoke the *remote's own* `agents
|
|
6
|
-
* sessions` against its already-built index and forward stdout verbatim.
|
|
7
|
-
*
|
|
8
|
-
* This is the live counterpart to `agents sessions sync` (R2/CRDT, eventual): no
|
|
9
|
-
* upfront copy, always current, but the peer must be reachable. SSH access is the
|
|
10
|
-
* only auth — if you can `ssh <host>`, you own the box (no identity layer by design).
|
|
11
|
-
*
|
|
12
|
-
* Cache-first (RUSH-2062) + offline degradation: every *successful* fetch is
|
|
13
|
-
* cached to `~/.agents/.cache/remote-sessions/`, keyed by host + the exact query.
|
|
14
|
-
* A later call with a *fresh* cache serves it without SSH (same daemon-warmed
|
|
15
|
-
* shared-cache shape as `stats-cache.ts`) so a reachable host is not re-probed
|
|
16
|
-
* on every menubar/CLI/watchdog tick. When the host is unreachable, any cache
|
|
17
|
-
* (even stale) is replayed with a clearly labelled "showing cached results"
|
|
18
|
-
* banner. The cache is a byproduct of fetches you already made — freely
|
|
19
|
-
* deletable — so the fetch-don't-replicate model holds.
|
|
20
|
-
*
|
|
21
|
-
* Mirrors the transport already used by `agents secrets export --device`
|
|
22
|
-
* (`src/commands/secrets.ts`): `ssh -o BatchMode=yes <host> bash -lc '<cmd>'`,
|
|
23
|
-
* with `bash -lc` so the remote login PATH resolves `agents`.
|
|
24
|
-
*/
|
|
25
|
-
import { spawnSync } from 'child_process';
|
|
26
|
-
import { mkdirSync, writeFileSync, readFileSync, existsSync, statSync } from 'fs';
|
|
27
|
-
import { join } from 'path';
|
|
28
|
-
import { createHash } from 'crypto';
|
|
29
|
-
import chalk from 'chalk';
|
|
30
|
-
import { getCacheDir } from '../../state.js';
|
|
31
|
-
import { SSH_OPTS, controlOpts, assertValidSshTarget } from '../../ssh-exec.js';
|
|
32
|
-
import { remoteShellFor, buildWindowsAgentsCommand } from '../../hosts/remote-cmd.js';
|
|
33
|
-
import { resolveRemoteOsSync } from '../../hosts/remote-os.js';
|
|
34
|
-
import { NO_FANOUT_ENV } from '../remote-active.js';
|
|
35
|
-
import { formatRelativeTime } from '../../text/relative-time.js';
|
|
36
|
-
import { terminalWidth } from '../../text/width.js';
|
|
37
|
-
export function shellQuote(s) {
|
|
38
|
-
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
39
|
-
}
|
|
40
|
-
export function buildForwardedArgs(argv, hosts = new Set()) {
|
|
41
|
-
const args = argv.slice(2);
|
|
42
|
-
const out = [];
|
|
43
|
-
for (let i = 0; i < args.length; i++) {
|
|
44
|
-
const a = args[i];
|
|
45
|
-
if (a === '--device' || a === '--devices') {
|
|
46
|
-
if (hosts.size > 0) {
|
|
47
|
-
while (i + 1 < args.length && hosts.has(args[i + 1]))
|
|
48
|
-
i++;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
i++;
|
|
52
|
-
}
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
if (a.startsWith('--device=') || a.startsWith('--devices='))
|
|
56
|
-
continue;
|
|
57
|
-
out.push(a);
|
|
58
|
-
}
|
|
59
|
-
return out;
|
|
60
|
-
}
|
|
61
|
-
export function ensureWholeIndex(forwardedArgs) {
|
|
62
|
-
return forwardedArgs.includes('--all') ? forwardedArgs : [...forwardedArgs, '--all'];
|
|
63
|
-
}
|
|
64
|
-
export function buildRemoteCommand(forwardedArgs, columns, os) {
|
|
65
|
-
if (remoteShellFor(os) === 'powershell') {
|
|
66
|
-
const env = { [NO_FANOUT_ENV]: '1' };
|
|
67
|
-
if (columns && columns > 0)
|
|
68
|
-
env.COLUMNS = String(columns);
|
|
69
|
-
return buildWindowsAgentsCommand({ args: forwardedArgs, env });
|
|
70
|
-
}
|
|
71
|
-
const inner = ['agents', ...forwardedArgs].map(shellQuote).join(' ');
|
|
72
|
-
const envPrefix = `${NO_FANOUT_ENV}=1` + (columns && columns > 0 ? ` COLUMNS=${columns}` : '');
|
|
73
|
-
return `bash -lc ${shellQuote(`${envPrefix} ${inner}`)}`;
|
|
74
|
-
}
|
|
75
|
-
export function classifySshFailure(res) {
|
|
76
|
-
if (res.error)
|
|
77
|
-
return 'spawn-error';
|
|
78
|
-
if (res.status === 0)
|
|
79
|
-
return 'ok';
|
|
80
|
-
if (res.status === 255)
|
|
81
|
-
return 'unreachable';
|
|
82
|
-
return 'query-failed';
|
|
83
|
-
}
|
|
84
|
-
const REMOTE_CACHE_DIR = join(getCacheDir(), 'remote-sessions');
|
|
85
|
-
export const REMOTE_CACHE_MAX_AGE_MS = 15_000;
|
|
86
|
-
export function remoteCachePath(host, forwardedArgs) {
|
|
87
|
-
const hash = createHash('sha256').update(forwardedArgs.join('\u0000')).digest('hex').slice(0, 16);
|
|
88
|
-
const safeHost = host.replace(/[^a-zA-Z0-9._@-]/g, '_');
|
|
89
|
-
return join(REMOTE_CACHE_DIR, `${safeHost}__${hash}.txt`);
|
|
90
|
-
}
|
|
91
|
-
export function isRemoteCacheFresh(mtimeMs, nowMs, maxAgeMs = REMOTE_CACHE_MAX_AGE_MS) {
|
|
92
|
-
if (!Number.isFinite(mtimeMs) || !Number.isFinite(maxAgeMs) || maxAgeMs < 0)
|
|
93
|
-
return false;
|
|
94
|
-
return nowMs - mtimeMs <= maxAgeMs;
|
|
95
|
-
}
|
|
96
|
-
export function readRemoteCache(host, forwardedArgs, opts = {}) {
|
|
97
|
-
try {
|
|
98
|
-
const p = remoteCachePath(host, forwardedArgs);
|
|
99
|
-
if (!existsSync(p))
|
|
100
|
-
return null;
|
|
101
|
-
const mtimeMs = statSync(p).mtimeMs;
|
|
102
|
-
if (opts.maxAgeMs !== undefined) {
|
|
103
|
-
const now = opts.nowMs ?? Date.now();
|
|
104
|
-
if (!isRemoteCacheFresh(mtimeMs, now, opts.maxAgeMs))
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
return { output: readFileSync(p, 'utf8'), mtimeMs };
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
export function formatStaleBanner(host, mtimeMs) {
|
|
114
|
-
const ago = formatRelativeTime(new Date(mtimeMs).toISOString());
|
|
115
|
-
return chalk.yellow(`${host}: offline — showing cached results from ${ago}`);
|
|
116
|
-
}
|
|
117
|
-
export function formatUnreachable(host) {
|
|
118
|
-
return chalk.red(`${host}: unreachable over SSH (asleep, offline, or host key changed?) — ConnectTimeout 10s`);
|
|
119
|
-
}
|
|
120
|
-
export function writeRemoteCache(host, forwardedArgs, output) {
|
|
121
|
-
try {
|
|
122
|
-
mkdirSync(REMOTE_CACHE_DIR, { recursive: true });
|
|
123
|
-
writeFileSync(remoteCachePath(host, forwardedArgs), output);
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
export function serveWarmRemoteCache(host, forwardedArgs, opts = {}) {
|
|
129
|
-
const hit = readRemoteCache(host, forwardedArgs, {
|
|
130
|
-
maxAgeMs: opts.maxAgeMs ?? REMOTE_CACHE_MAX_AGE_MS,
|
|
131
|
-
nowMs: opts.nowMs,
|
|
132
|
-
});
|
|
133
|
-
if (!hit)
|
|
134
|
-
return false;
|
|
135
|
-
process.stdout.write(hit.output);
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
export function replayRemoteCache(host, forwardedArgs) {
|
|
139
|
-
const hit = readRemoteCache(host, forwardedArgs);
|
|
140
|
-
if (!hit)
|
|
141
|
-
return false;
|
|
142
|
-
process.stderr.write(formatStaleBanner(host, hit.mtimeMs) + '\n');
|
|
143
|
-
process.stdout.write(hit.output);
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
export function runRemoteSessions(hosts, argv = process.argv, opts = {}) {
|
|
147
|
-
for (const host of hosts)
|
|
148
|
-
assertValidSshTarget(host);
|
|
149
|
-
const forwarded = ensureWholeIndex(buildForwardedArgs(argv, new Set(hosts)));
|
|
150
|
-
const cols = terminalWidth();
|
|
151
|
-
const multi = hosts.length > 1;
|
|
152
|
-
let failures = 0;
|
|
153
|
-
const forceRefresh = opts.forceRefresh === true
|
|
154
|
-
|| process.env.AGENTS_SESSIONS_FORCE_REFRESH === '1';
|
|
155
|
-
for (const host of hosts) {
|
|
156
|
-
if (multi)
|
|
157
|
-
process.stdout.write(chalk.cyan(`\n── ${host} ──\n`));
|
|
158
|
-
if (!forceRefresh && serveWarmRemoteCache(host, forwarded, {
|
|
159
|
-
maxAgeMs: opts.maxAgeMs,
|
|
160
|
-
nowMs: opts.nowMs,
|
|
161
|
-
})) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const remoteCmd = buildRemoteCommand(forwarded, cols, resolveRemoteOsSync(host));
|
|
165
|
-
const res = spawnSync('ssh', [...SSH_OPTS, ...controlOpts(), host, remoteCmd], {
|
|
166
|
-
encoding: 'utf8',
|
|
167
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
168
|
-
});
|
|
169
|
-
switch (classifySshFailure(res)) {
|
|
170
|
-
case 'ok':
|
|
171
|
-
process.stdout.write(res.stdout ?? '');
|
|
172
|
-
if (res.stderr)
|
|
173
|
-
process.stderr.write(res.stderr);
|
|
174
|
-
writeRemoteCache(host, forwarded, res.stdout ?? '');
|
|
175
|
-
break;
|
|
176
|
-
case 'unreachable':
|
|
177
|
-
if (!replayRemoteCache(host, forwarded)) {
|
|
178
|
-
failures++;
|
|
179
|
-
console.error(formatUnreachable(host));
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
case 'spawn-error':
|
|
183
|
-
failures++;
|
|
184
|
-
console.error(chalk.red(`${host}: ${res.error?.message ?? 'failed to launch ssh'}`));
|
|
185
|
-
break;
|
|
186
|
-
case 'query-failed':
|
|
187
|
-
failures++;
|
|
188
|
-
if (res.stdout)
|
|
189
|
-
process.stdout.write(res.stdout);
|
|
190
|
-
if (res.stderr)
|
|
191
|
-
process.stderr.write(res.stderr);
|
|
192
|
-
console.error(chalk.red(`${host}: remote query failed (exit ${res.status ?? 'signal'}).`));
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (failures > 0)
|
|
197
|
-
process.exitCode = 1;
|
|
198
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './remote/remote-bundle.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './remote/remote-bundle.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './remote/remote.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './remote/remote.js';
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface SessionFile {
|
|
2
|
-
absPath: string;
|
|
3
|
-
relKey: string;
|
|
4
|
-
}
|
|
5
|
-
export interface LocalTranscript {
|
|
6
|
-
sessionId: string;
|
|
7
|
-
files: SessionFile[];
|
|
8
|
-
}
|
|
9
|
-
export interface SyncAgentSpec {
|
|
10
|
-
id: string;
|
|
11
|
-
subdir: string;
|
|
12
|
-
ext?: string;
|
|
13
|
-
dirShaped?: boolean;
|
|
14
|
-
exts?: string[];
|
|
15
|
-
fileFilter?(relKey: string): boolean;
|
|
16
|
-
mergeableExts?: string[];
|
|
17
|
-
sessionIdFromRelKey(relKey: string): string;
|
|
18
|
-
}
|
|
19
|
-
export declare function isMergeableFile(spec: SyncAgentSpec, relKey: string): boolean;
|
|
20
|
-
export declare const SYNC_AGENTS: SyncAgentSpec[];
|
|
21
|
-
export declare function listLocalTranscripts(spec: SyncAgentSpec): LocalTranscript[];
|
|
22
|
-
export declare function mirrorPath(spec: SyncAgentSpec, machine: string, relKey: string): string;
|
|
23
|
-
export declare function objectKey(machine: string, agentId: string, sessionId: string, relKey?: string): string;
|
|
24
|
-
export declare const SESSIONS_PREFIX = "sessions/";
|
|
Binary file
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type PhoenixSession } from '../../identity/client.js';
|
|
2
|
-
import { type R2Config } from './config.js';
|
|
3
|
-
export declare const SESSIONS_BACKEND_ENV = "AGENTS_SESSIONS_BACKEND";
|
|
4
|
-
interface ManagedSessionsBackend {
|
|
5
|
-
kind: 'managed';
|
|
6
|
-
baseUrl: string;
|
|
7
|
-
token: string;
|
|
8
|
-
userId: string;
|
|
9
|
-
}
|
|
10
|
-
interface ByoSessionsBackend {
|
|
11
|
-
kind: 'byo';
|
|
12
|
-
r2: R2Config;
|
|
13
|
-
}
|
|
14
|
-
type SessionsBackend = ManagedSessionsBackend | ByoSessionsBackend;
|
|
15
|
-
interface ResolveSessionsBackendOpts {
|
|
16
|
-
byo?: boolean;
|
|
17
|
-
writeToken?: string;
|
|
18
|
-
session?: PhoenixSession | null;
|
|
19
|
-
}
|
|
20
|
-
export declare function shouldUseManagedSessions(opts?: ResolveSessionsBackendOpts): boolean;
|
|
21
|
-
export declare function resolveSessionsBackend(opts?: ResolveSessionsBackendOpts): SessionsBackend;
|
|
22
|
-
export {};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { readSession } from '../../identity/client.js';
|
|
2
|
-
import { selectStorageBackendKind } from '../../storage/selection.js';
|
|
3
|
-
import { loadR2Config } from './config.js';
|
|
4
|
-
import { managedSessionsBaseUrl } from './managed-config.js';
|
|
5
|
-
export const SESSIONS_BACKEND_ENV = 'AGENTS_SESSIONS_BACKEND';
|
|
6
|
-
function sessionsByoOverride(opts) {
|
|
7
|
-
if (opts.byo === true)
|
|
8
|
-
return true;
|
|
9
|
-
if (opts.writeToken)
|
|
10
|
-
return true;
|
|
11
|
-
return (process.env[SESSIONS_BACKEND_ENV] ?? '').trim().toLowerCase() === 'byo';
|
|
12
|
-
}
|
|
13
|
-
export function shouldUseManagedSessions(opts = {}) {
|
|
14
|
-
return (selectStorageBackendKind({ byoOverride: sessionsByoOverride(opts), session: opts.session }) ===
|
|
15
|
-
'managed');
|
|
16
|
-
}
|
|
17
|
-
export function resolveSessionsBackend(opts = {}) {
|
|
18
|
-
const session = opts.session === undefined ? readSession() : opts.session;
|
|
19
|
-
const explicitByo = sessionsByoOverride(opts);
|
|
20
|
-
if (selectStorageBackendKind({ byoOverride: explicitByo, session }) === 'managed') {
|
|
21
|
-
if (!session) {
|
|
22
|
-
throw new Error("Not signed in. Run 'agents auth login' to back up sessions to your Phoenix account.");
|
|
23
|
-
}
|
|
24
|
-
if (!session.access_token) {
|
|
25
|
-
throw new Error("Session has no access token. Run 'agents auth login' again.");
|
|
26
|
-
}
|
|
27
|
-
const userId = (session.userId ?? '').trim();
|
|
28
|
-
if (!userId) {
|
|
29
|
-
throw new Error("Signed in but the session has no user id. Run 'agents auth login' again.");
|
|
30
|
-
}
|
|
31
|
-
return { kind: 'managed', baseUrl: managedSessionsBaseUrl(), token: session.access_token, userId };
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
return { kind: 'byo', r2: loadR2Config() };
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
if (!explicitByo) {
|
|
38
|
-
throw new Error("Not signed in, and no r2.backups bucket is configured. Run 'agents auth login' to " +
|
|
39
|
-
'back up to the managed Phoenix store (zero setup), or add the r2.backups bundle to ' +
|
|
40
|
-
'use your own bucket: agents secrets add r2.backups R2_ACCOUNT_ID R2_BUCKET_NAME R2_ACCESS_KEY_ID R2_SECRET_ACCESS_KEY');
|
|
41
|
-
}
|
|
42
|
-
throw err;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ManagedSessionsBackupClient } from './net-client.js';
|
|
2
|
-
export declare const ESCROW_REL_KEY = "__key/backup-dek";
|
|
3
|
-
export declare function backupKeyCachePath(): string;
|
|
4
|
-
export declare function readCachedBackupKey(userId: string): Buffer | null;
|
|
5
|
-
export declare function resolveManagedBackupKey(client: ManagedSessionsBackupClient, userId: string): Promise<Buffer>;
|