@phnx-labs/agents-cli 1.20.29 → 1.20.31

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 (58) hide show
  1. package/dist/commands/computer-actions.js +6 -2
  2. package/dist/commands/computer.d.ts +12 -0
  3. package/dist/commands/computer.js +88 -13
  4. package/dist/commands/inspect.js +1 -1
  5. package/dist/commands/models.js +8 -2
  6. package/dist/commands/sessions-picker.js +35 -10
  7. package/dist/commands/sessions.js +164 -44
  8. package/dist/commands/setup.js +8 -0
  9. package/dist/commands/ssh.js +123 -15
  10. package/dist/commands/sync.js +70 -14
  11. package/dist/lib/agents.d.ts +0 -4
  12. package/dist/lib/agents.js +122 -22
  13. package/dist/lib/browser/drivers/ssh.js +4 -35
  14. package/dist/lib/computer-rpc.d.ts +6 -1
  15. package/dist/lib/computer-rpc.js +86 -3
  16. package/dist/lib/devices/registry.d.ts +11 -0
  17. package/dist/lib/devices/registry.js +53 -1
  18. package/dist/lib/devices/sync.d.ts +42 -0
  19. package/dist/lib/devices/sync.js +85 -0
  20. package/dist/lib/exec.js +14 -0
  21. package/dist/lib/models.js +138 -5
  22. package/dist/lib/runner.js +7 -7
  23. package/dist/lib/session/active.d.ts +15 -0
  24. package/dist/lib/session/active.js +108 -19
  25. package/dist/lib/session/cloud.js +2 -0
  26. package/dist/lib/session/db.d.ts +11 -0
  27. package/dist/lib/session/db.js +62 -5
  28. package/dist/lib/session/digest.d.ts +50 -0
  29. package/dist/lib/session/digest.js +170 -0
  30. package/dist/lib/session/discover.d.ts +5 -0
  31. package/dist/lib/session/discover.js +81 -0
  32. package/dist/lib/session/parse.d.ts +15 -0
  33. package/dist/lib/session/parse.js +22 -2
  34. package/dist/lib/session/remote.d.ts +1 -1
  35. package/dist/lib/session/remote.js +8 -3
  36. package/dist/lib/session/render.d.ts +2 -0
  37. package/dist/lib/session/render.js +83 -10
  38. package/dist/lib/session/state.d.ts +82 -0
  39. package/dist/lib/session/state.js +221 -0
  40. package/dist/lib/session/tail.d.ts +18 -0
  41. package/dist/lib/session/tail.js +57 -0
  42. package/dist/lib/session/types.d.ts +9 -0
  43. package/dist/lib/session/width.d.ts +29 -0
  44. package/dist/lib/session/width.js +91 -0
  45. package/dist/lib/shims.d.ts +17 -1
  46. package/dist/lib/shims.js +130 -6
  47. package/dist/lib/ssh-tunnel.d.ts +127 -0
  48. package/dist/lib/ssh-tunnel.js +346 -0
  49. package/dist/lib/state.d.ts +4 -0
  50. package/dist/lib/state.js +19 -1
  51. package/dist/lib/sync-umbrella.d.ts +5 -0
  52. package/dist/lib/sync-umbrella.js +10 -0
  53. package/dist/lib/teams/agents.d.ts +11 -1
  54. package/dist/lib/teams/agents.js +16 -2
  55. package/dist/lib/types.d.ts +1 -0
  56. package/dist/lib/versions.d.ts +19 -0
  57. package/dist/lib/versions.js +84 -24
  58. package/package.json +1 -1
@@ -16,13 +16,12 @@
16
16
  */
17
17
  import * as fs from 'fs';
18
18
  import * as path from 'path';
19
- import * as os from 'os';
20
19
  import * as yaml from 'yaml';
21
20
  import { exec, execFile } from 'child_process';
22
21
  import { promisify } from 'util';
23
22
  import chalk from 'chalk';
24
23
  import { checkbox, select } from '@inquirer/prompts';
25
- import { getVersionsDir, ensureAgentsDir, readMeta, writeMeta, getCommandsDir, getSkillsDir, getHooksDir, getResolvedRulesDir, getUserRulesDir, getVersionResources, ensureVersionResourcePatterns, getProjectAgentsDir, getPromptcutsPath, getUserPromptcutsPath, getEnabledExtraRepos, getAgentsDir, getUserAgentsDir, getTrashVersionsDir, getActiveRulesPreset } from './state.js';
24
+ import { getVersionsDir, ensureAgentsDir, readMeta, writeMeta, getCommandsDir, getSkillsDir, getHooksDir, getResolvedRulesDir, getUserRulesDir, getVersionResources, ensureVersionResourcePatterns, getProjectAgentsDir, getPromptcutsPath, getUserPromptcutsPath, getEnabledExtraRepos, getAgentsDir, getUserAgentsDir, getTrashVersionsDir, getActiveRulesPreset, getHomeDir } from './state.js';
26
25
  import { defaultPatterns, expandPatterns } from './resource-patterns.js';
27
26
  import { listResources } from './resources.js';
28
27
  import { AGENTS, agentConfigDirName, getAccountEmail, resolveAgentName, formatAgentError, findInPath } from './agents.js';
@@ -30,6 +29,7 @@ import { discoverPermissionGroups, getActivePermissionPresetName, readPermission
30
29
  import { parseMcpServerConfig } from './mcp.js';
31
30
  import { createVersionedAlias, removeVersionedAlias, getConfigSymlinkVersion, ensureClaudeInsideSymlink } from './shims.js';
32
31
  import { importInstallScriptBinary } from './import.js';
32
+ import { IS_WINDOWS } from './platform/index.js';
33
33
  import { supports, explainSkip } from './capabilities.js';
34
34
  import { discoverPlugins } from './plugins.js';
35
35
  import { loadManifest, saveManifest, buildManifest as buildSyncManifest, isStale } from './staleness/index.js';
@@ -819,12 +819,17 @@ export function getBinaryPath(agent, version) {
819
819
  return path.join(grokDownloads, `grok-${version}`);
820
820
  }
821
821
  if (agent === 'droid') {
822
- // Factory's installer drops a standalone native binary at ~/.local/bin/droid
823
- // (no npm package, nothing in node_modules/.bin). The binary is global, not
824
- // per-version — config isolation rides the ~/.factory symlink switch, not a
825
- // separate binary per version. Mirror the shim's `droid` branch so
826
- // isVersionInstalled/`agents view` agree with what actually executes.
827
- return path.join(os.homedir(), '.local', 'bin', 'droid');
822
+ // Factory's installer drops a standalone native binary (no npm package,
823
+ // nothing in node_modules/.bin). The binary is global, not per-version —
824
+ // config isolation rides the ~/.factory symlink switch, not a separate
825
+ // binary per version. Install location is platform-specific:
826
+ // macOS/Linux: ~/.local/bin/droid (curl app.factory.ai/cli | sh)
827
+ // Windows: %USERPROFILE%\bin\droid.exe (irm app.factory.ai/cli/windows | iex)
828
+ // Mirror the shim's `droid` branch so isVersionInstalled/`agents view`
829
+ // agree with what actually executes.
830
+ return IS_WINDOWS
831
+ ? path.join(getHomeDir(), 'bin', 'droid.exe')
832
+ : path.join(getHomeDir(), '.local', 'bin', 'droid');
828
833
  }
829
834
  const versionDir = getVersionDir(agent, version);
830
835
  return path.join(versionDir, 'node_modules', '.bin', agentConfig.cliCommand);
@@ -1302,7 +1307,7 @@ export function removeVersion(agent, version) {
1302
1307
  // Clean up dangling config symlink if it pointed to the removed version
1303
1308
  const symlinkVersion = getConfigSymlinkVersion(agent);
1304
1309
  if (symlinkVersion === version) {
1305
- const configPath = path.join(os.homedir(), agentConfigDirName(agent));
1310
+ const configPath = path.join(getHomeDir(), agentConfigDirName(agent));
1306
1311
  try {
1307
1312
  fs.unlinkSync(configPath);
1308
1313
  }
@@ -1636,6 +1641,68 @@ export function getResourceDiff(agent, version) {
1636
1641
  diff.hooks.dangling.length + diff.memory.dangling.length;
1637
1642
  return diff;
1638
1643
  }
1644
+ /**
1645
+ * Enumerate the DotAgent repo names that resources can be scoped to:
1646
+ * the fixed `project` / `user` / `system` layers plus every enabled extra
1647
+ * repo alias. Used to validate `agents sync <agent> --repo <name>`.
1648
+ */
1649
+ export function listRepoNames() {
1650
+ return ['project', 'user', 'system', ...getEnabledExtraRepos().map(e => e.alias)];
1651
+ }
1652
+ /**
1653
+ * Build the name→source-layer map for one resource kind, the input
1654
+ * `expandPatterns` matches `source:*` patterns against. This is the single
1655
+ * source of truth for how each kind attributes its source layer:
1656
+ * - commands/skills/hooks/subagents → real layer from `listResources`
1657
+ * - permissions → always the system repo
1658
+ * - mcp → project vs user scope preserved
1659
+ * - plugins/workflows → user repo
1660
+ * Both the persisted-pattern sync path and `buildRepoScopedSelection` use it
1661
+ * so the attribution can't drift between the two.
1662
+ */
1663
+ function resourceSourceMap(kind, cwd, available) {
1664
+ switch (kind) {
1665
+ case 'commands':
1666
+ case 'skills':
1667
+ case 'hooks':
1668
+ case 'subagents':
1669
+ return new Map(listResources(kind, cwd).map(r => [r.name, r.source]));
1670
+ case 'permissions':
1671
+ return new Map(available.permissions.map(n => [n, 'system']));
1672
+ case 'mcp':
1673
+ return new Map(getScopedMcpResources(cwd).map(r => [r.name, r.scope]));
1674
+ case 'plugins':
1675
+ return new Map(available.plugins.map(n => [n, 'user']));
1676
+ case 'workflows':
1677
+ return new Map(available.workflows.map(n => [n, 'user']));
1678
+ }
1679
+ }
1680
+ /**
1681
+ * Build a ResourceSelection scoped to a single DotAgent repo (`system`,
1682
+ * `user`, `project`, or an extra-repo alias). Every resource kind is filtered
1683
+ * to the entries whose source layer matches `repo`, reusing the same
1684
+ * name→source maps and `source:*` pattern expansion the persisted-pattern
1685
+ * sync path uses. Passing the result as an explicit `selection` means the sync
1686
+ * touches only that repo's resources — no orphan-sweep of the other layers.
1687
+ *
1688
+ * `memory` is set to `[]` (not omitted): that empty-array sentinel is what
1689
+ * `syncResourcesToVersion`'s `skipMemory` gate keys on to leave the memory
1690
+ * file untouched — it's a merge of all layers, not a per-repo artifact.
1691
+ */
1692
+ export function buildRepoScopedSelection(repo, cwd = process.cwd()) {
1693
+ const patterns = [`${repo}:*`];
1694
+ const available = getAvailableResources(cwd);
1695
+ const selection = {};
1696
+ const kinds = ['commands', 'skills', 'hooks', 'subagents', 'permissions', 'mcp', 'plugins', 'workflows'];
1697
+ for (const kind of kinds) {
1698
+ const names = expandPatterns(patterns, resourceSourceMap(kind, cwd, available));
1699
+ if (names.length > 0)
1700
+ selection[kind] = names;
1701
+ }
1702
+ // Empty-array sentinel → skip the memory writer (see skipMemory below).
1703
+ selection.memory = [];
1704
+ return selection;
1705
+ }
1639
1706
  /**
1640
1707
  * Sync central resources (~/.agents/) into a specific version's config directory.
1641
1708
  * Copies selected resources from central storage into {versionHome}/.{agent}/.
@@ -1701,28 +1768,21 @@ export function syncResourcesToVersion(agent, version, selection, options = {})
1701
1768
  const patterns = vr[type];
1702
1769
  if (!Array.isArray(patterns) || patterns.length === 0)
1703
1770
  continue;
1704
- const sourceMap = new Map(listResources(kind, cwd).map(r => [r.name, r.source]));
1705
- patternSelection[type] = expandPatterns(patterns, sourceMap);
1771
+ patternSelection[type] = expandPatterns(patterns, resourceSourceMap(kind, cwd, available));
1706
1772
  }
1707
- // permissions: all groups are 'system' source.
1773
+ // permissions / mcp / plugins / workflows: source attribution lives in
1774
+ // resourceSourceMap so it can't drift from buildRepoScopedSelection.
1708
1775
  if (Array.isArray(vr.permissions) && vr.permissions.length > 0) {
1709
- const permMap = new Map(available.permissions.map(n => [n, 'system']));
1710
- patternSelection.permissions = expandPatterns(vr.permissions, permMap);
1776
+ patternSelection.permissions = expandPatterns(vr.permissions, resourceSourceMap('permissions', cwd, available));
1711
1777
  }
1712
- // mcp: pattern matching must preserve project vs user scope.
1713
1778
  if (Array.isArray(vr.mcp) && vr.mcp.length > 0) {
1714
- const mcpMap = new Map(getScopedMcpResources(cwd).map(resource => [resource.name, resource.scope]));
1715
- patternSelection.mcp = expandPatterns(vr.mcp, mcpMap);
1779
+ patternSelection.mcp = expandPatterns(vr.mcp, resourceSourceMap('mcp', cwd, available));
1716
1780
  }
1717
- // plugins: treat all as 'user' source for now.
1718
1781
  if (Array.isArray(vr.plugins) && vr.plugins.length > 0) {
1719
- const pluginMap = new Map(available.plugins.map(n => [n, 'user']));
1720
- patternSelection.plugins = expandPatterns(vr.plugins, pluginMap);
1782
+ patternSelection.plugins = expandPatterns(vr.plugins, resourceSourceMap('plugins', cwd, available));
1721
1783
  }
1722
- // workflows: treat all as 'user' source.
1723
1784
  if (Array.isArray(vr.workflows) && vr.workflows.length > 0) {
1724
- const workflowMap = new Map(available.workflows.map(n => [n, 'user']));
1725
- patternSelection.workflows = expandPatterns(vr.workflows, workflowMap);
1785
+ patternSelection.workflows = expandPatterns(vr.workflows, resourceSourceMap('workflows', cwd, available));
1726
1786
  }
1727
1787
  // memory is not pattern-controlled (rulesPreset handles it) — always sync.
1728
1788
  patternSelection.memory = 'all';
@@ -2071,7 +2131,7 @@ export function getEffectiveHome(agentId) {
2071
2131
  if (resolved && isVersionInstalled(agentId, resolved)) {
2072
2132
  return getVersionHomePath(agentId, resolved);
2073
2133
  }
2074
- return os.homedir();
2134
+ return getHomeDir();
2075
2135
  }
2076
2136
  /**
2077
2137
  * Thrown when the user references an agent@version that is not installed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phnx-labs/agents-cli",
3
- "version": "1.20.29",
3
+ "version": "1.20.31",
4
4
  "description": "One CLI for all your AI coding agents - versions, config, cloud dispatch, sessions, and teams (now with first-class Grok Build CLI support)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",