@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
@@ -100,7 +100,10 @@ export declare function fetchReviewAndHead(repo: string, number: number, gh?: Gh
100
100
  reviewDecision: string | null;
101
101
  headRefOid: string | null;
102
102
  }>;
103
- export declare function enrichPr(repo: string, pr: ProjectPr, gh?: GhExec): Promise<ProjectPr>;
103
+ export declare function enrichPr(repo: string, pr: ProjectPr, gh?: GhExec): Promise<{
104
+ pr: ProjectPr;
105
+ reviewError: string | null;
106
+ }>;
104
107
  export declare const MERGED_WINDOW_DAYS = 7;
105
108
  export declare const MERGED_LIMIT = 20;
106
109
  export declare const MERGED_PAGE_CAP = 3;
@@ -79,10 +79,21 @@ export async function fetchReviewAndHead(repo, number, gh = ghExec) {
79
79
  };
80
80
  }
81
81
  export async function enrichPr(repo, pr, gh = ghExec) {
82
- const { reviewDecision, headRefOid } = await fetchReviewAndHead(repo, pr.number, gh);
83
- const head = headRefOid || pr.headSha;
82
+ let review;
83
+ let reviewError = null;
84
+ try {
85
+ review = await fetchReviewAndHead(repo, pr.number, gh);
86
+ }
87
+ catch (err) {
88
+ const message = ghFailure(err);
89
+ if (!isRateLimited(message))
90
+ throw err;
91
+ review = { reviewDecision: null, headRefOid: null };
92
+ reviewError = `review status unavailable: ${message}`;
93
+ }
94
+ const head = review.headRefOid || pr.headSha;
84
95
  const checks = await rollupForSha(repo, head, gh);
85
- return { ...pr, headSha: head, checks, reviewDecision, ...ciFromRollupItems(checks) };
96
+ return { pr: { ...pr, headSha: head, checks, reviewDecision: review.reviewDecision, ...ciFromRollupItems(checks) }, reviewError };
86
97
  }
87
98
  export const MERGED_WINDOW_DAYS = 7;
88
99
  export const MERGED_LIMIT = 20;
@@ -397,11 +408,13 @@ export async function buildProjectPrs(def, opts = {}, gh = ghExec, peers = [], c
397
408
  const mergeRead = readRepoMergeAbility(slug, gh).then((merge) => ({ merge, error: null }), (err) => ({ merge: null, error: err }));
398
409
  if (opts.number !== undefined) {
399
410
  const pr = await fetchOnePr(slug, opts.number, gh);
400
- const enriched = await enrichPr(slug, pr, gh);
411
+ const { pr: enriched, reviewError } = await enrichPr(slug, pr, gh);
401
412
  const { merge, error: mergeError } = await mergeRead;
402
413
  return {
403
414
  slug, sharedWith, pullRequests: [enriched], merge,
404
- recentlyMerged: [], defaultBranch: null, ciError: mergeError === null ? null : ghFailure(mergeError), truncated: false, release: null, releaseError: null, error: null,
415
+ recentlyMerged: [], defaultBranch: null,
416
+ ciError: [reviewError, mergeError === null ? null : ghFailure(mergeError)].filter(Boolean).join('; ') || null,
417
+ truncated: false, release: null, releaseError: null, error: null,
405
418
  };
406
419
  }
407
420
  const errors = new CiErrors();
@@ -12,5 +12,6 @@ interface HelpSections {
12
12
  }
13
13
  export declare function setHelpSections(cmd: Command, sections: HelpSections): void;
14
14
  export declare function getHelpSections(cmd: Command): Readonly<HelpSections>;
15
+ export declare function forwardsHelp(cmd: Command): Command;
15
16
  export declare function applyGlobalHelpConventions(root: Command): void;
16
17
  export {};
package/dist/lib/help.js CHANGED
@@ -151,7 +151,15 @@ function formatHelpCommandsFirst(cmd, helper) {
151
151
  }
152
152
  return output.join('\n');
153
153
  }
154
+ const FORWARDS_HELP = new WeakSet();
155
+ export function forwardsHelp(cmd) {
156
+ cmd.helpOption(false);
157
+ FORWARDS_HELP.add(cmd);
158
+ return cmd;
159
+ }
154
160
  function applyHelpConventionsRecursive(cmd) {
161
+ if (FORWARDS_HELP.has(cmd))
162
+ return;
155
163
  cmd
156
164
  .helpOption('-h, --help', 'Show help')
157
165
  .addHelpCommand(false)
@@ -1,5 +1,5 @@
1
1
  export const HELPER_RELEASES = {
2
- menubar: { tagPrefix: 'menubar', floor: '1.7.0' },
2
+ menubar: { tagPrefix: 'menubar', floor: '1.15.8' },
3
3
  };
4
4
  export function helperTag(helper, version) {
5
5
  const release = HELPER_RELEASES[helper];
@@ -3,12 +3,12 @@ import { assertValidSshTarget, sshStream } from '../ssh-exec.js';
3
3
  import { resolveHost, resolveHostByCap } from './registry.js';
4
4
  import { sshTargetFor, hostIdentityArgs } from './types.js';
5
5
  import { dispatchAgentsCommand, withActorEnv } from './dispatch.js';
6
- import { stripRoutingFlags, buildRemoteAgentsInvocation, stripClixml, HOST_ROUTING_SPECS, } from './remote-cmd.js';
6
+ import { stripRoutingFlags, buildRemoteAgentsInvocation, stripClixml, } from './remote-cmd.js';
7
7
  import { resolveRemoteOsSync } from './remote-os.js';
8
8
  import { machineId } from '../machine-id.js';
9
9
  import { isDeviceAuto, resolveDeviceAffinity } from '../smart-launch.js';
10
10
  import { isDeviceInteractive, resolveInteractiveDevice, interactiveUnsetError, } from '../devices/interactive-host.js';
11
- import { flagValue, hasHostRoutingFlag } from './routing-flag.js';
11
+ import { flagValue, hasHostRoutingFlag, ROUTING_OPTION_SPECS } from './routing-flag.js';
12
12
  import { loadDevices } from '../devices/registry.js';
13
13
  import { isSelfHost } from '../devices/self-host.js';
14
14
  import { markFleetRemote } from '../devices/connect.js';
@@ -85,12 +85,7 @@ export const OWN_HOST_COMMANDS = new Set([
85
85
  'fleet',
86
86
  'apply',
87
87
  ]);
88
- const STRIP_SPECS = [
89
- ...HOST_ROUTING_SPECS,
90
- { long: 'no-tty', takesValue: false },
91
- { long: 'hosts', takesValue: true },
92
- { long: 'devices', takesValue: true },
93
- ];
88
+ const STRIP_SPECS = ROUTING_OPTION_SPECS;
94
89
  function firstSubcommand(allArgs, group) {
95
90
  const idx = allArgs.indexOf(group);
96
91
  return idx >= 0 ? allArgs.slice(idx + 1).find((a) => !a.startsWith('-')) : undefined;
@@ -348,6 +343,8 @@ export async function maybeRunOnHost(command, allArgs, opts) {
348
343
  return false;
349
344
  if (OWN_HOST_COMMANDS.has(command))
350
345
  return false;
346
+ if (command === 'daemon' && firstSubcommand(allArgs, 'daemon') === 'index')
347
+ return false;
351
348
  if (command === 'teams') {
352
349
  const teamsIdx = allArgs.indexOf('teams');
353
350
  const sub = teamsIdx >= 0 ? allArgs.slice(teamsIdx + 1).find((a) => !a.startsWith('-')) : undefined;
@@ -1,10 +1,6 @@
1
- export interface StripSpec {
2
- long: string;
3
- short?: string;
4
- takesValue: boolean;
5
- }
1
+ import { type StripSpec } from './routing-flag.js';
2
+ export { HOST_ROUTING_SPECS, type StripSpec } from './routing-flag.js';
6
3
  export declare function stripRoutingFlags(args: string[], specs: StripSpec[]): string[];
7
- export declare const HOST_ROUTING_SPECS: StripSpec[];
8
4
  type RunOptionForwarding = 'forward' | 'reject' | 'local-only';
9
5
  export declare const RUN_OPTION_FORWARDING: Record<string, RunOptionForwarding>;
10
6
  export declare const RUN_OPTION_REJECT_MESSAGES: Record<string, string>;
@@ -36,4 +32,3 @@ export declare function buildWindowsStdinImportCommand(bundle: string, opts?: {
36
32
  force?: boolean;
37
33
  policyNever?: boolean;
38
34
  }): string;
39
- export {};
@@ -3,32 +3,20 @@ import { pwshLiteral, pwshNativeExecStatements } from '../pwsh.js';
3
3
  import { quoteWin32ExecArg } from '../platform/exec.js';
4
4
  import { homeRemainder } from '../project-root.js';
5
5
  import * as zlib from 'node:zlib';
6
+ import { scanArgv } from './routing-flag.js';
7
+ export { HOST_ROUTING_SPECS } from './routing-flag.js';
6
8
  export function stripRoutingFlags(args, specs) {
7
- const out = [];
8
- for (let i = 0; i < args.length; i++) {
9
- const a = args[i];
10
- const spec = specs.find((s) => {
11
- if (a === `--${s.long}` || a.startsWith(`--${s.long}=`))
12
- return true;
13
- if (s.short && (a === `-${s.short}` || a.startsWith(`-${s.short}=`) || new RegExp(`^-${s.short}.+`).test(a)))
14
- return true;
15
- return false;
16
- });
17
- if (!spec) {
18
- out.push(a);
9
+ const out = [...args];
10
+ for (const r of scanArgv(args, specs).routing) {
11
+ if (!specs.some((s) => s.long === r.spec.long))
19
12
  continue;
20
- }
21
- const isExact = a === `--${spec.long}` || (spec.short && a === `-${spec.short}`);
22
- if (spec.takesValue && isExact && i + 1 < args.length)
23
- i++;
13
+ for (let i = r.start; i <= r.end; i++)
14
+ out[i] = undefined;
15
+ if (r.kept && r.kept !== '-')
16
+ out[r.start] = r.kept;
24
17
  }
25
- return out;
18
+ return out.filter((a) => a !== undefined);
26
19
  }
27
- export const HOST_ROUTING_SPECS = [
28
- { long: 'device', short: 'D', takesValue: true },
29
- { long: 'host', short: 'H', takesValue: true },
30
- { long: 'remote-cwd', takesValue: true },
31
- ];
32
20
  export const RUN_OPTION_FORWARDING = {
33
21
  mode: 'forward',
34
22
  effort: 'forward',
@@ -96,6 +84,10 @@ export const RUN_OPTION_FORWARDING = {
96
84
  listTasks: 'local-only',
97
85
  results: 'local-only',
98
86
  concurrency: 'local-only',
87
+ all: 'local-only',
88
+ teams: 'local-only',
89
+ since: 'local-only',
90
+ limit: 'local-only',
99
91
  };
100
92
  export const RUN_OPTION_REJECT_MESSAGES = {
101
93
  terminal: '--terminal opens a tab on THIS machine; it cannot be combined with --device. ' +
@@ -1,2 +1,24 @@
1
+ import type { Command } from 'commander';
2
+ export interface StripSpec {
3
+ long: string;
4
+ short?: string;
5
+ takesValue: boolean;
6
+ }
7
+ export declare const HOST_ROUTING_SPECS: StripSpec[];
8
+ export declare const ROUTING_OPTION_SPECS: StripSpec[];
9
+ export interface RoutingOccurrence {
10
+ spec: StripSpec;
11
+ start: number;
12
+ end: number;
13
+ value?: string;
14
+ kept?: string;
15
+ }
16
+ export interface ScannedArgv {
17
+ commandIndex?: number;
18
+ routing: RoutingOccurrence[];
19
+ }
20
+ export declare function setArgvCommandTree(root: Command | undefined): void;
21
+ export declare function scanArgv(args: string[], extra?: StripSpec[]): ScannedArgv;
22
+ export declare function commandTokenIndex(args: string[]): number | undefined;
1
23
  export declare function flagValue(args: string[], long: string, short?: string): string | undefined;
2
24
  export declare function hasHostRoutingFlag(args: string[]): boolean;
@@ -1,19 +1,132 @@
1
- export function flagValue(args, long, short) {
2
- for (let i = 0; i < args.length; i++) {
3
- const a = args[i];
4
- if (a === `--${long}` || (short && a === `-${short}`))
5
- return args[i + 1];
6
- if (a.startsWith(`--${long}=`))
7
- return a.slice(long.length + 3);
8
- if (short && a.startsWith(`-${short}=`))
9
- return a.slice(short.length + 2);
10
- if (short && new RegExp(`^-${short}(.+)`).test(a))
11
- return a.slice(2);
1
+ export const HOST_ROUTING_SPECS = [
2
+ { long: 'device', short: 'D', takesValue: true },
3
+ { long: 'host', short: 'H', takesValue: true },
4
+ { long: 'remote-cwd', takesValue: true },
5
+ ];
6
+ export const ROUTING_OPTION_SPECS = [
7
+ ...HOST_ROUTING_SPECS,
8
+ { long: 'no-tty', takesValue: false },
9
+ { long: 'hosts', takesValue: true },
10
+ { long: 'devices', takesValue: true },
11
+ ];
12
+ let commandTree;
13
+ export function setArgvCommandTree(root) {
14
+ commandTree = root;
15
+ }
16
+ function matchRouting(arg, specs) {
17
+ for (const spec of specs) {
18
+ if (arg === `--${spec.long}`)
19
+ return { spec };
20
+ if (arg.startsWith(`--${spec.long}=`))
21
+ return { spec, joined: arg.slice(spec.long.length + 3) };
22
+ if (!spec.short)
23
+ continue;
24
+ if (arg === `-${spec.short}`)
25
+ return { spec };
26
+ if (arg.startsWith(`-${spec.short}=`))
27
+ return { spec, joined: arg.slice(spec.short.length + 2) };
28
+ if (arg.startsWith(`-${spec.short}`))
29
+ return { spec, joined: arg.slice(spec.short.length + 1) };
30
+ }
31
+ return undefined;
32
+ }
33
+ function findOption(chain, flag) {
34
+ for (let c = chain.length - 1; c >= 0; c--) {
35
+ const opt = chain[c].options.find((o) => o.long === flag || o.short === flag);
36
+ if (opt)
37
+ return opt;
12
38
  }
13
39
  return undefined;
14
40
  }
41
+ function lastValueIndex(args, i, opt) {
42
+ const next = (j) => j < args.length && !args[j].startsWith('-');
43
+ let j = i;
44
+ if (opt.required ? i + 1 < args.length : opt.optional && next(i + 1))
45
+ j = i + 1;
46
+ else
47
+ return i;
48
+ if (opt.variadic)
49
+ while (next(j + 1))
50
+ j++;
51
+ return j;
52
+ }
53
+ function lastLongOptionIndex(args, i, chain) {
54
+ const arg = args[i];
55
+ if (arg.includes('='))
56
+ return i;
57
+ const opt = findOption(chain, arg);
58
+ return opt ? lastValueIndex(args, i, opt) : i;
59
+ }
60
+ function scanShortCluster(args, i, chain, specs) {
61
+ const arg = args[i];
62
+ for (let k = 1; k < arg.length; k++) {
63
+ const spec = specs.find((s) => s.short === arg[k]);
64
+ if (spec) {
65
+ const kept = arg.slice(0, k);
66
+ if (!spec.takesValue)
67
+ return { last: i, occurrence: { spec, start: i, end: i, kept: kept + arg.slice(k + 1) } };
68
+ const joined = arg.slice(k + 1).replace(/^=/, '');
69
+ if (joined)
70
+ return { last: i, occurrence: { spec, start: i, end: i, value: joined, kept } };
71
+ const end = i + 1 < args.length ? i + 1 : i;
72
+ return { last: end, occurrence: { spec, start: i, end, value: end > i ? args[end] : undefined, kept } };
73
+ }
74
+ const opt = findOption(chain, `-${arg[k]}`);
75
+ if (!opt)
76
+ return { last: i };
77
+ if (opt.required || opt.optional)
78
+ return { last: k === arg.length - 1 ? lastValueIndex(args, i, opt) : i };
79
+ }
80
+ return { last: i };
81
+ }
82
+ export function scanArgv(args, extra = []) {
83
+ const specs = [...ROUTING_OPTION_SPECS, ...extra.filter((e) => !ROUTING_OPTION_SPECS.some((s) => s.long === e.long))];
84
+ const chain = commandTree ? [commandTree] : [];
85
+ const routing = [];
86
+ let commandIndex;
87
+ let operands = 0;
88
+ let optionsEnded = false;
89
+ for (let i = 0; i < args.length; i++) {
90
+ const arg = args[i];
91
+ if (arg === '--' && !optionsEnded) {
92
+ optionsEnded = true;
93
+ continue;
94
+ }
95
+ if (optionsEnded || arg.length < 2 || !arg.startsWith('-')) {
96
+ commandIndex ??= i;
97
+ const current = chain[chain.length - 1];
98
+ const sub = operands === 0 && current?.commands.find((c) => c.name() === arg || c.aliases().includes(arg));
99
+ if (sub)
100
+ chain.push(sub);
101
+ else if (commandIndex !== i)
102
+ operands++;
103
+ continue;
104
+ }
105
+ const hit = matchRouting(arg, specs);
106
+ if (hit) {
107
+ const takesNext = hit.spec.takesValue && hit.joined === undefined && i + 1 < args.length;
108
+ routing.push({ spec: hit.spec, start: i, end: takesNext ? i + 1 : i, value: hit.joined ?? (takesNext ? args[i + 1] : undefined) });
109
+ if (takesNext)
110
+ i++;
111
+ continue;
112
+ }
113
+ if (arg.startsWith('--')) {
114
+ i = lastLongOptionIndex(args, i, chain);
115
+ continue;
116
+ }
117
+ const cluster = scanShortCluster(args, i, chain, specs);
118
+ if (cluster.occurrence)
119
+ routing.push(cluster.occurrence);
120
+ i = cluster.last;
121
+ }
122
+ return { commandIndex, routing };
123
+ }
124
+ export function commandTokenIndex(args) {
125
+ return scanArgv(args).commandIndex;
126
+ }
127
+ export function flagValue(args, long, short) {
128
+ return scanArgv(args, [{ long, short, takesValue: true }]).routing.find((r) => r.spec.long === long)?.value;
129
+ }
15
130
  export function hasHostRoutingFlag(args) {
16
- return (flagValue(args, 'device', 'D') !== undefined ||
17
- flagValue(args, 'hosts') !== undefined ||
18
- flagValue(args, 'devices') !== undefined);
131
+ return scanArgv(args).routing.some((r) => ['device', 'hosts', 'devices'].includes(r.spec.long) && r.value !== undefined);
19
132
  }
@@ -14,6 +14,9 @@ export interface WhoAmI {
14
14
  valid: true;
15
15
  avatar_url?: string;
16
16
  name?: string;
17
+ tokenKind?: 'session' | 'device';
18
+ scopes?: string[];
19
+ device?: string | null;
17
20
  }
18
21
  export type DevicePoll = {
19
22
  status: 'authorized';
@@ -37,6 +40,25 @@ export type DevicePoll = {
37
40
  export declare function startDeviceAuthorization(): Promise<DeviceAuthorization>;
38
41
  export declare function pollDeviceToken(deviceCode: string): Promise<DevicePoll>;
39
42
  export declare function fetchWhoAmI(token?: string): Promise<WhoAmI>;
43
+ export type DeviceTokenScope = 'notify';
44
+ export interface MintedDeviceToken {
45
+ id: string;
46
+ token: string;
47
+ kind: 'device';
48
+ device: string;
49
+ scopes: DeviceTokenScope[];
50
+ createdAt: string;
51
+ }
52
+ export interface ApiTokenSummary {
53
+ id: string;
54
+ kind: 'session' | 'device';
55
+ device: string | null;
56
+ scopes: string[];
57
+ createdAt: string;
58
+ }
59
+ export declare const mintDeviceToken: (device: string, scopes: DeviceTokenScope[]) => Promise<MintedDeviceToken>;
60
+ export declare const listApiTokens: () => Promise<ApiTokenSummary[]>;
61
+ export declare const revokeApiToken: (id: string) => Promise<void>;
40
62
  export declare function refreshSessionProfile(known?: WhoAmI): Promise<void>;
41
63
  export interface SpaceSummary {
42
64
  id: string;
@@ -33,6 +33,9 @@ export async function pollDeviceToken(deviceCode) {
33
33
  export function fetchWhoAmI(token) {
34
34
  return phoenixRequest('GET', '/api/v1/auth/me', { token });
35
35
  }
36
+ export const mintDeviceToken = (device, scopes) => phoenixRequest('POST', '/api/v1/auth/tokens', { body: { device, scopes } });
37
+ export const listApiTokens = () => phoenixRequest('GET', '/api/v1/auth/tokens');
38
+ export const revokeApiToken = (id) => phoenixRequest('DELETE', `/api/v1/auth/tokens/${encodeURIComponent(id)}`);
36
39
  export async function refreshSessionProfile(known) {
37
40
  const session = readSession();
38
41
  if (!session)
@@ -1,4 +1,5 @@
1
1
  export { foldLegacySystemRepo } from '../migrate-fold.js';
2
+ import { type OwnerPreferencesPatch } from '../owner-notify.js';
2
3
  export declare function migrateAgentsYaml(systemDir?: string, userDir?: string): void;
3
4
  export declare function detrackUserChangelog(userDir?: string): void;
4
5
  export declare function foldBrowserSessionsIntoProfiles(browserDir?: string): void;
@@ -9,6 +10,12 @@ export declare function migrateRoutineDeviceToDevices(routinesDir?: string): voi
9
10
  export declare function migrateRoutineRemoteCwdToCwd(routinesDir?: string): void;
10
11
  export declare function migrateWatchdogSentinelToConfig(sentinelPath?: string, enable?: (value: boolean) => void): void;
11
12
  export declare function migrateCliDirToClis(agentsDirs: string[]): void;
13
+ export declare const LEGACY_HUMANS_FILE = "humans.yaml";
14
+ export declare function humansToPreferencesPatch(doc: unknown): {
15
+ patch: OwnerPreferencesPatch;
16
+ dropped: string[];
17
+ };
18
+ export declare function migrateHumansToAccount(userDir?: string, failureStamp?: string): Promise<'absent' | 'pending' | 'migrated'>;
12
19
  export declare function seedActiveCursorLoginPerVersion(): void;
13
20
  export declare function migrateKimiSubagentsToMarkdown(versionsDir?: string): void;
14
21
  export declare function removeHomeCompiledProjectRules(homeDir?: string): void;