@adhdev/daemon-core 0.9.82-rc.446 → 0.9.82-rc.447

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.
@@ -110,6 +110,11 @@ export interface AddNodeOptions {
110
110
  clonedFromNodeId?: string;
111
111
  worktreeBootstrap?: LocalMeshNodeEntry['worktreeBootstrap'];
112
112
  role?: RepoMeshDaemonRole;
113
+ /** Owning daemon's machine nickname. Defaults to this daemon's local
114
+ * config.machineNickname when omitted — a node is always added by (and on)
115
+ * the daemon that owns its workspace (self/base node or a local worktree
116
+ * clone), so the local config is the correct source. */
117
+ machineNickname?: string;
113
118
  }
114
119
  export declare function addNode(meshId: string, opts: AddNodeOptions): LocalMeshNodeEntry | undefined;
115
120
  export declare function removeNode(meshId: string, nodeId: string): boolean;
@@ -125,6 +130,10 @@ export declare function updateNode(meshId: string, nodeId: string, opts: {
125
130
  * operator intent) so capability-tag os=/arch= self-heals across loads. */
126
131
  reportedPlatform?: string;
127
132
  reportedArch?: string;
133
+ /** Owning daemon's self-reported machine nickname, carried on the
134
+ * git_status envelope. Persisted so the friendly label survives across
135
+ * coordinator restarts (mirrors reportedPlatform/reportedArch). */
136
+ reportedMachineNickname?: string;
128
137
  }): LocalMeshNodeEntry | undefined;
129
138
  /**
130
139
  * Validate + normalize a panel config before persisting. Mirrors the node-config
@@ -123,6 +123,7 @@ type GitCommandSuccess = {
123
123
  status: GitRepoStatus;
124
124
  reporterPlatform?: string;
125
125
  reporterArch?: string;
126
+ reporterMachineNickname?: string;
126
127
  } | {
127
128
  success: true;
128
129
  diffSummary: GitDiffSummary;
package/dist/index.js CHANGED
@@ -409,10 +409,10 @@ function readInjected(value) {
409
409
  }
410
410
  function getDaemonBuildInfo() {
411
411
  if (cached) return cached;
412
- const commit = readInjected(true ? "c70a1cf556d27bbee6f81e64ea13699887f50ecc" : void 0) ?? "unknown";
413
- const commitShort = readInjected(true ? "c70a1cf5" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
- const version = readInjected(true ? "0.9.82-rc.446" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
- const builtAt = readInjected(true ? "2026-07-01T15:09:11.778Z" : void 0);
412
+ const commit = readInjected(true ? "fb4b6fd9ffb70781692aceb7eea162dd92606fad" : void 0) ?? "unknown";
413
+ const commitShort = readInjected(true ? "fb4b6fd9" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
+ const version = readInjected(true ? "0.9.82-rc.447" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
+ const builtAt = readInjected(true ? "2026-07-01T16:13:26.252Z" : void 0);
416
416
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
417
417
  return cached;
418
418
  }
@@ -1502,6 +1502,255 @@ var init_git_diff = __esm({
1502
1502
  }
1503
1503
  });
1504
1504
 
1505
+ // src/config/config.ts
1506
+ var config_exports = {};
1507
+ __export(config_exports, {
1508
+ generateMachineId: () => generateMachineId,
1509
+ getConfigDir: () => getConfigDir,
1510
+ getDaemonDataDir: () => getDaemonDataDir,
1511
+ isSetupComplete: () => isSetupComplete,
1512
+ isStableMachineId: () => isStableMachineId,
1513
+ loadConfig: () => loadConfig,
1514
+ markSetupComplete: () => markSetupComplete,
1515
+ resetConfig: () => resetConfig,
1516
+ resolveProviderSourceMode: () => resolveProviderSourceMode,
1517
+ saveConfig: () => saveConfig,
1518
+ updateConfig: () => updateConfig
1519
+ });
1520
+ function resolveProviderSourceMode(providerSourceMode, legacyDisableUpstream) {
1521
+ if (providerSourceMode === "normal" || providerSourceMode === "no-upstream") {
1522
+ return providerSourceMode;
1523
+ }
1524
+ return legacyDisableUpstream === true ? "no-upstream" : "normal";
1525
+ }
1526
+ function isPlainObject(value) {
1527
+ return !!value && typeof value === "object" && !Array.isArray(value);
1528
+ }
1529
+ function asStringArray(value) {
1530
+ if (!Array.isArray(value)) return [];
1531
+ return value.filter((item) => typeof item === "string");
1532
+ }
1533
+ function asNullableString(value) {
1534
+ return typeof value === "string" ? value : null;
1535
+ }
1536
+ function asOptionalString(value) {
1537
+ return typeof value === "string" && value.trim() ? value : void 0;
1538
+ }
1539
+ function asBoolean(value, fallback) {
1540
+ return typeof value === "boolean" ? value : fallback;
1541
+ }
1542
+ function normalizeMachineProviders(value) {
1543
+ if (!isPlainObject(value)) return {};
1544
+ const result = {};
1545
+ for (const [providerType, raw] of Object.entries(value)) {
1546
+ if (!isPlainObject(raw)) continue;
1547
+ const entry = {};
1548
+ if (raw.enabled === true) entry.enabled = true;
1549
+ if (typeof raw.executable === "string" && raw.executable.trim()) {
1550
+ entry.executable = raw.executable.trim();
1551
+ }
1552
+ if (Array.isArray(raw.args)) {
1553
+ entry.args = raw.args.filter((arg) => typeof arg === "string");
1554
+ }
1555
+ if (isPlainObject(raw.lastDetection)) {
1556
+ entry.lastDetection = raw.lastDetection;
1557
+ }
1558
+ if (isPlainObject(raw.lastVerification)) {
1559
+ entry.lastVerification = raw.lastVerification;
1560
+ }
1561
+ result[providerType] = entry;
1562
+ }
1563
+ return result;
1564
+ }
1565
+ function normalizeConfig(raw) {
1566
+ const parsed = isPlainObject(raw) ? raw : {};
1567
+ return {
1568
+ serverUrl: typeof parsed.serverUrl === "string" && parsed.serverUrl.trim() ? parsed.serverUrl : DEFAULT_CONFIG.serverUrl,
1569
+ allowServerApiProxy: asBoolean(parsed.allowServerApiProxy, DEFAULT_CONFIG.allowServerApiProxy ?? false),
1570
+ selectedIde: asNullableString(parsed.selectedIde),
1571
+ configuredIdes: asStringArray(parsed.configuredIdes),
1572
+ installedExtensions: asStringArray(parsed.installedExtensions),
1573
+ userEmail: asNullableString(parsed.userEmail),
1574
+ userName: asNullableString(parsed.userName),
1575
+ setupCompleted: asBoolean(parsed.setupCompleted, DEFAULT_CONFIG.setupCompleted),
1576
+ setupDate: asNullableString(parsed.setupDate),
1577
+ enabledIdes: asStringArray(parsed.enabledIdes),
1578
+ workspaces: Array.isArray(parsed.workspaces) ? parsed.workspaces : [],
1579
+ defaultWorkspaceId: asNullableString(parsed.defaultWorkspaceId) ?? asNullableString(parsed.activeWorkspaceId),
1580
+ machineNickname: asNullableString(parsed.machineNickname),
1581
+ machineId: asOptionalString(parsed.machineId),
1582
+ machineSecret: parsed.machineSecret === null ? null : asOptionalString(parsed.machineSecret),
1583
+ registeredMachineId: asOptionalString(parsed.registeredMachineId),
1584
+ providerSettings: isPlainObject(parsed.providerSettings) ? parsed.providerSettings : {},
1585
+ machineProviders: normalizeMachineProviders(parsed.machineProviders),
1586
+ ideSettings: isPlainObject(parsed.ideSettings) ? parsed.ideSettings : {},
1587
+ providerSourceMode: resolveProviderSourceMode(parsed.providerSourceMode, parsed.disableUpstream),
1588
+ providerDir: asOptionalString(parsed.providerDir),
1589
+ updateChannel: parsed.updateChannel === "preview" ? "preview" : "stable",
1590
+ terminalSizingMode: parsed.terminalSizingMode === "fit" ? "fit" : "measured"
1591
+ };
1592
+ }
1593
+ function generateMachineId() {
1594
+ return `${MACHINE_ID_PREFIX}${(0, import_crypto.randomUUID)().replace(/-/g, "")}`;
1595
+ }
1596
+ function isStableMachineId(machineId) {
1597
+ return typeof machineId === "string" && machineId.startsWith(MACHINE_ID_PREFIX);
1598
+ }
1599
+ function ensureMachineId(config) {
1600
+ if (isStableMachineId(config.machineId)) {
1601
+ return { config, changed: false };
1602
+ }
1603
+ return {
1604
+ config: {
1605
+ ...config,
1606
+ machineId: generateMachineId()
1607
+ },
1608
+ changed: true
1609
+ };
1610
+ }
1611
+ function getConfigDir() {
1612
+ const override = process.env.ADHDEV_CONFIG_DIR;
1613
+ const dir = override && override.trim() ? override.trim() : (0, import_path2.join)((0, import_os.homedir)(), ".adhdev");
1614
+ if (!(0, import_fs2.existsSync)(dir)) {
1615
+ (0, import_fs2.mkdirSync)(dir, { recursive: true });
1616
+ }
1617
+ return dir;
1618
+ }
1619
+ function getDaemonDataDir() {
1620
+ const dir = (0, import_path2.join)(getConfigDir(), "daemon");
1621
+ if (!(0, import_fs2.existsSync)(dir)) {
1622
+ (0, import_fs2.mkdirSync)(dir, { recursive: true });
1623
+ }
1624
+ return dir;
1625
+ }
1626
+ function getConfigPath() {
1627
+ return (0, import_path2.join)(getConfigDir(), "config.json");
1628
+ }
1629
+ function migrateStateToStateFile(raw) {
1630
+ const statePath = (0, import_path2.join)(getConfigDir(), "state.json");
1631
+ if ((0, import_fs2.existsSync)(statePath)) return;
1632
+ const recentActivity = Array.isArray(raw.recentActivity) ? raw.recentActivity : [];
1633
+ const savedProviderSessions = Array.isArray(raw.savedProviderSessions) ? raw.savedProviderSessions : [];
1634
+ const legacySessionReads = isPlainObject(raw.recentSessionReads) ? raw.recentSessionReads : {};
1635
+ const sessionReads = isPlainObject(raw.sessionReads) ? raw.sessionReads : {};
1636
+ const sessionReadMarkers = isPlainObject(raw.sessionReadMarkers) ? raw.sessionReadMarkers : {};
1637
+ const hasData = recentActivity.length > 0 || savedProviderSessions.length > 0 || Object.keys(sessionReads).length > 0 || Object.keys(legacySessionReads).length > 0 || Object.keys(sessionReadMarkers).length > 0;
1638
+ if (!hasData) return;
1639
+ const mergedReads = Object.fromEntries(
1640
+ Object.entries({ ...legacySessionReads, ...sessionReads }).filter(([, v]) => typeof v === "number" && Number.isFinite(v))
1641
+ );
1642
+ const cleanedMarkers = Object.fromEntries(
1643
+ Object.entries(sessionReadMarkers).filter(([, v]) => typeof v === "string")
1644
+ );
1645
+ const state = {
1646
+ recentActivity,
1647
+ savedProviderSessions,
1648
+ sessionReads: mergedReads,
1649
+ sessionReadMarkers: cleanedMarkers
1650
+ };
1651
+ (0, import_fs2.writeFileSync)(statePath, JSON.stringify(state, null, 2), { encoding: "utf-8", mode: 384 });
1652
+ }
1653
+ function loadConfig() {
1654
+ const configPath = getConfigPath();
1655
+ if (!(0, import_fs2.existsSync)(configPath)) {
1656
+ const initialized = ensureMachineId({ ...DEFAULT_CONFIG });
1657
+ try {
1658
+ saveConfig(initialized.config);
1659
+ } catch {
1660
+ }
1661
+ return initialized.config;
1662
+ }
1663
+ try {
1664
+ const raw = (0, import_fs2.readFileSync)(configPath, "utf-8");
1665
+ const parsed = JSON.parse(raw);
1666
+ migrateStateToStateFile(parsed);
1667
+ const normalizedInput = normalizeConfig(parsed);
1668
+ const ensured = ensureMachineId(normalizedInput);
1669
+ const normalized = ensured.config;
1670
+ if (ensured.changed || JSON.stringify(parsed) !== JSON.stringify(normalized)) {
1671
+ try {
1672
+ saveConfig(normalized);
1673
+ } catch {
1674
+ }
1675
+ }
1676
+ return normalized;
1677
+ } catch {
1678
+ const initialized = ensureMachineId({ ...DEFAULT_CONFIG });
1679
+ return initialized.config;
1680
+ }
1681
+ }
1682
+ function saveConfig(config) {
1683
+ const configPath = getConfigPath();
1684
+ const dir = getConfigDir();
1685
+ const normalized = normalizeConfig(config);
1686
+ if (!(0, import_fs2.existsSync)(dir)) {
1687
+ (0, import_fs2.mkdirSync)(dir, { recursive: true, mode: 448 });
1688
+ }
1689
+ (0, import_fs2.writeFileSync)(configPath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
1690
+ try {
1691
+ (0, import_fs2.chmodSync)(configPath, 384);
1692
+ } catch {
1693
+ }
1694
+ }
1695
+ function updateConfig(updates) {
1696
+ const config = loadConfig();
1697
+ const updated = { ...config, ...updates };
1698
+ saveConfig(updated);
1699
+ return updated;
1700
+ }
1701
+ function markSetupComplete(ideId, extensions) {
1702
+ const ideIds = Array.isArray(ideId) ? ideId : [ideId];
1703
+ return updateConfig({
1704
+ selectedIde: ideIds[0],
1705
+ configuredIdes: ideIds,
1706
+ installedExtensions: extensions,
1707
+ setupCompleted: true,
1708
+ setupDate: (/* @__PURE__ */ new Date()).toISOString()
1709
+ });
1710
+ }
1711
+ function isSetupComplete() {
1712
+ const config = loadConfig();
1713
+ return config.setupCompleted;
1714
+ }
1715
+ function resetConfig() {
1716
+ saveConfig({ ...DEFAULT_CONFIG });
1717
+ }
1718
+ var import_os, import_path2, import_fs2, import_crypto, DEFAULT_CONFIG, MACHINE_ID_PREFIX;
1719
+ var init_config = __esm({
1720
+ "src/config/config.ts"() {
1721
+ "use strict";
1722
+ import_os = require("os");
1723
+ import_path2 = require("path");
1724
+ import_fs2 = require("fs");
1725
+ import_crypto = require("crypto");
1726
+ DEFAULT_CONFIG = {
1727
+ serverUrl: "https://api.adhf.dev",
1728
+ allowServerApiProxy: false,
1729
+ selectedIde: null,
1730
+ configuredIdes: [],
1731
+ installedExtensions: [],
1732
+ userEmail: null,
1733
+ userName: null,
1734
+ setupCompleted: false,
1735
+ setupDate: null,
1736
+ enabledIdes: [],
1737
+ workspaces: [],
1738
+ defaultWorkspaceId: null,
1739
+ machineNickname: null,
1740
+ machineId: void 0,
1741
+ machineSecret: null,
1742
+ registeredMachineId: void 0,
1743
+ providerSettings: {},
1744
+ machineProviders: {},
1745
+ ideSettings: {},
1746
+ providerSourceMode: "normal",
1747
+ updateChannel: "stable",
1748
+ terminalSizingMode: "measured"
1749
+ };
1750
+ MACHINE_ID_PREFIX = "mach_";
1751
+ }
1752
+ });
1753
+
1505
1754
  // src/git/git-worktree.ts
1506
1755
  var git_worktree_exports = {};
1507
1756
  __export(git_worktree_exports, {
@@ -1812,255 +2061,6 @@ var init_git_worktree = __esm({
1812
2061
  }
1813
2062
  });
1814
2063
 
1815
- // src/config/config.ts
1816
- var config_exports = {};
1817
- __export(config_exports, {
1818
- generateMachineId: () => generateMachineId,
1819
- getConfigDir: () => getConfigDir,
1820
- getDaemonDataDir: () => getDaemonDataDir,
1821
- isSetupComplete: () => isSetupComplete,
1822
- isStableMachineId: () => isStableMachineId,
1823
- loadConfig: () => loadConfig,
1824
- markSetupComplete: () => markSetupComplete,
1825
- resetConfig: () => resetConfig,
1826
- resolveProviderSourceMode: () => resolveProviderSourceMode,
1827
- saveConfig: () => saveConfig,
1828
- updateConfig: () => updateConfig
1829
- });
1830
- function resolveProviderSourceMode(providerSourceMode, legacyDisableUpstream) {
1831
- if (providerSourceMode === "normal" || providerSourceMode === "no-upstream") {
1832
- return providerSourceMode;
1833
- }
1834
- return legacyDisableUpstream === true ? "no-upstream" : "normal";
1835
- }
1836
- function isPlainObject(value) {
1837
- return !!value && typeof value === "object" && !Array.isArray(value);
1838
- }
1839
- function asStringArray(value) {
1840
- if (!Array.isArray(value)) return [];
1841
- return value.filter((item) => typeof item === "string");
1842
- }
1843
- function asNullableString(value) {
1844
- return typeof value === "string" ? value : null;
1845
- }
1846
- function asOptionalString(value) {
1847
- return typeof value === "string" && value.trim() ? value : void 0;
1848
- }
1849
- function asBoolean(value, fallback) {
1850
- return typeof value === "boolean" ? value : fallback;
1851
- }
1852
- function normalizeMachineProviders(value) {
1853
- if (!isPlainObject(value)) return {};
1854
- const result = {};
1855
- for (const [providerType, raw] of Object.entries(value)) {
1856
- if (!isPlainObject(raw)) continue;
1857
- const entry = {};
1858
- if (raw.enabled === true) entry.enabled = true;
1859
- if (typeof raw.executable === "string" && raw.executable.trim()) {
1860
- entry.executable = raw.executable.trim();
1861
- }
1862
- if (Array.isArray(raw.args)) {
1863
- entry.args = raw.args.filter((arg) => typeof arg === "string");
1864
- }
1865
- if (isPlainObject(raw.lastDetection)) {
1866
- entry.lastDetection = raw.lastDetection;
1867
- }
1868
- if (isPlainObject(raw.lastVerification)) {
1869
- entry.lastVerification = raw.lastVerification;
1870
- }
1871
- result[providerType] = entry;
1872
- }
1873
- return result;
1874
- }
1875
- function normalizeConfig(raw) {
1876
- const parsed = isPlainObject(raw) ? raw : {};
1877
- return {
1878
- serverUrl: typeof parsed.serverUrl === "string" && parsed.serverUrl.trim() ? parsed.serverUrl : DEFAULT_CONFIG.serverUrl,
1879
- allowServerApiProxy: asBoolean(parsed.allowServerApiProxy, DEFAULT_CONFIG.allowServerApiProxy ?? false),
1880
- selectedIde: asNullableString(parsed.selectedIde),
1881
- configuredIdes: asStringArray(parsed.configuredIdes),
1882
- installedExtensions: asStringArray(parsed.installedExtensions),
1883
- userEmail: asNullableString(parsed.userEmail),
1884
- userName: asNullableString(parsed.userName),
1885
- setupCompleted: asBoolean(parsed.setupCompleted, DEFAULT_CONFIG.setupCompleted),
1886
- setupDate: asNullableString(parsed.setupDate),
1887
- enabledIdes: asStringArray(parsed.enabledIdes),
1888
- workspaces: Array.isArray(parsed.workspaces) ? parsed.workspaces : [],
1889
- defaultWorkspaceId: asNullableString(parsed.defaultWorkspaceId) ?? asNullableString(parsed.activeWorkspaceId),
1890
- machineNickname: asNullableString(parsed.machineNickname),
1891
- machineId: asOptionalString(parsed.machineId),
1892
- machineSecret: parsed.machineSecret === null ? null : asOptionalString(parsed.machineSecret),
1893
- registeredMachineId: asOptionalString(parsed.registeredMachineId),
1894
- providerSettings: isPlainObject(parsed.providerSettings) ? parsed.providerSettings : {},
1895
- machineProviders: normalizeMachineProviders(parsed.machineProviders),
1896
- ideSettings: isPlainObject(parsed.ideSettings) ? parsed.ideSettings : {},
1897
- providerSourceMode: resolveProviderSourceMode(parsed.providerSourceMode, parsed.disableUpstream),
1898
- providerDir: asOptionalString(parsed.providerDir),
1899
- updateChannel: parsed.updateChannel === "preview" ? "preview" : "stable",
1900
- terminalSizingMode: parsed.terminalSizingMode === "fit" ? "fit" : "measured"
1901
- };
1902
- }
1903
- function generateMachineId() {
1904
- return `${MACHINE_ID_PREFIX}${(0, import_crypto.randomUUID)().replace(/-/g, "")}`;
1905
- }
1906
- function isStableMachineId(machineId) {
1907
- return typeof machineId === "string" && machineId.startsWith(MACHINE_ID_PREFIX);
1908
- }
1909
- function ensureMachineId(config) {
1910
- if (isStableMachineId(config.machineId)) {
1911
- return { config, changed: false };
1912
- }
1913
- return {
1914
- config: {
1915
- ...config,
1916
- machineId: generateMachineId()
1917
- },
1918
- changed: true
1919
- };
1920
- }
1921
- function getConfigDir() {
1922
- const override = process.env.ADHDEV_CONFIG_DIR;
1923
- const dir = override && override.trim() ? override.trim() : (0, import_path2.join)((0, import_os.homedir)(), ".adhdev");
1924
- if (!(0, import_fs2.existsSync)(dir)) {
1925
- (0, import_fs2.mkdirSync)(dir, { recursive: true });
1926
- }
1927
- return dir;
1928
- }
1929
- function getDaemonDataDir() {
1930
- const dir = (0, import_path2.join)(getConfigDir(), "daemon");
1931
- if (!(0, import_fs2.existsSync)(dir)) {
1932
- (0, import_fs2.mkdirSync)(dir, { recursive: true });
1933
- }
1934
- return dir;
1935
- }
1936
- function getConfigPath() {
1937
- return (0, import_path2.join)(getConfigDir(), "config.json");
1938
- }
1939
- function migrateStateToStateFile(raw) {
1940
- const statePath = (0, import_path2.join)(getConfigDir(), "state.json");
1941
- if ((0, import_fs2.existsSync)(statePath)) return;
1942
- const recentActivity = Array.isArray(raw.recentActivity) ? raw.recentActivity : [];
1943
- const savedProviderSessions = Array.isArray(raw.savedProviderSessions) ? raw.savedProviderSessions : [];
1944
- const legacySessionReads = isPlainObject(raw.recentSessionReads) ? raw.recentSessionReads : {};
1945
- const sessionReads = isPlainObject(raw.sessionReads) ? raw.sessionReads : {};
1946
- const sessionReadMarkers = isPlainObject(raw.sessionReadMarkers) ? raw.sessionReadMarkers : {};
1947
- const hasData = recentActivity.length > 0 || savedProviderSessions.length > 0 || Object.keys(sessionReads).length > 0 || Object.keys(legacySessionReads).length > 0 || Object.keys(sessionReadMarkers).length > 0;
1948
- if (!hasData) return;
1949
- const mergedReads = Object.fromEntries(
1950
- Object.entries({ ...legacySessionReads, ...sessionReads }).filter(([, v]) => typeof v === "number" && Number.isFinite(v))
1951
- );
1952
- const cleanedMarkers = Object.fromEntries(
1953
- Object.entries(sessionReadMarkers).filter(([, v]) => typeof v === "string")
1954
- );
1955
- const state = {
1956
- recentActivity,
1957
- savedProviderSessions,
1958
- sessionReads: mergedReads,
1959
- sessionReadMarkers: cleanedMarkers
1960
- };
1961
- (0, import_fs2.writeFileSync)(statePath, JSON.stringify(state, null, 2), { encoding: "utf-8", mode: 384 });
1962
- }
1963
- function loadConfig() {
1964
- const configPath = getConfigPath();
1965
- if (!(0, import_fs2.existsSync)(configPath)) {
1966
- const initialized = ensureMachineId({ ...DEFAULT_CONFIG });
1967
- try {
1968
- saveConfig(initialized.config);
1969
- } catch {
1970
- }
1971
- return initialized.config;
1972
- }
1973
- try {
1974
- const raw = (0, import_fs2.readFileSync)(configPath, "utf-8");
1975
- const parsed = JSON.parse(raw);
1976
- migrateStateToStateFile(parsed);
1977
- const normalizedInput = normalizeConfig(parsed);
1978
- const ensured = ensureMachineId(normalizedInput);
1979
- const normalized = ensured.config;
1980
- if (ensured.changed || JSON.stringify(parsed) !== JSON.stringify(normalized)) {
1981
- try {
1982
- saveConfig(normalized);
1983
- } catch {
1984
- }
1985
- }
1986
- return normalized;
1987
- } catch {
1988
- const initialized = ensureMachineId({ ...DEFAULT_CONFIG });
1989
- return initialized.config;
1990
- }
1991
- }
1992
- function saveConfig(config) {
1993
- const configPath = getConfigPath();
1994
- const dir = getConfigDir();
1995
- const normalized = normalizeConfig(config);
1996
- if (!(0, import_fs2.existsSync)(dir)) {
1997
- (0, import_fs2.mkdirSync)(dir, { recursive: true, mode: 448 });
1998
- }
1999
- (0, import_fs2.writeFileSync)(configPath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
2000
- try {
2001
- (0, import_fs2.chmodSync)(configPath, 384);
2002
- } catch {
2003
- }
2004
- }
2005
- function updateConfig(updates) {
2006
- const config = loadConfig();
2007
- const updated = { ...config, ...updates };
2008
- saveConfig(updated);
2009
- return updated;
2010
- }
2011
- function markSetupComplete(ideId, extensions) {
2012
- const ideIds = Array.isArray(ideId) ? ideId : [ideId];
2013
- return updateConfig({
2014
- selectedIde: ideIds[0],
2015
- configuredIdes: ideIds,
2016
- installedExtensions: extensions,
2017
- setupCompleted: true,
2018
- setupDate: (/* @__PURE__ */ new Date()).toISOString()
2019
- });
2020
- }
2021
- function isSetupComplete() {
2022
- const config = loadConfig();
2023
- return config.setupCompleted;
2024
- }
2025
- function resetConfig() {
2026
- saveConfig({ ...DEFAULT_CONFIG });
2027
- }
2028
- var import_os, import_path2, import_fs2, import_crypto, DEFAULT_CONFIG, MACHINE_ID_PREFIX;
2029
- var init_config = __esm({
2030
- "src/config/config.ts"() {
2031
- "use strict";
2032
- import_os = require("os");
2033
- import_path2 = require("path");
2034
- import_fs2 = require("fs");
2035
- import_crypto = require("crypto");
2036
- DEFAULT_CONFIG = {
2037
- serverUrl: "https://api.adhf.dev",
2038
- allowServerApiProxy: false,
2039
- selectedIde: null,
2040
- configuredIdes: [],
2041
- installedExtensions: [],
2042
- userEmail: null,
2043
- userName: null,
2044
- setupCompleted: false,
2045
- setupDate: null,
2046
- enabledIdes: [],
2047
- workspaces: [],
2048
- defaultWorkspaceId: null,
2049
- machineNickname: null,
2050
- machineId: void 0,
2051
- machineSecret: null,
2052
- registeredMachineId: void 0,
2053
- providerSettings: {},
2054
- machineProviders: {},
2055
- ideSettings: {},
2056
- providerSourceMode: "normal",
2057
- updateChannel: "stable",
2058
- terminalSizingMode: "measured"
2059
- };
2060
- MACHINE_ID_PREFIX = "mach_";
2061
- }
2062
- });
2063
-
2064
2064
  // src/config/workspaces.ts
2065
2065
  function expandPath(p) {
2066
2066
  const t = (p || "").trim();
@@ -3201,12 +3201,23 @@ function addNode(meshId, opts) {
3201
3201
  if (mesh.nodes.some((n) => n.workspace === opts.workspace)) {
3202
3202
  throw new Error("This workspace is already in the mesh");
3203
3203
  }
3204
+ const machineNickname = (() => {
3205
+ const explicit = typeof opts.machineNickname === "string" ? opts.machineNickname.trim() : "";
3206
+ if (explicit) return explicit;
3207
+ try {
3208
+ const local = loadConfig().machineNickname;
3209
+ return typeof local === "string" && local.trim() ? local.trim() : void 0;
3210
+ } catch {
3211
+ return void 0;
3212
+ }
3213
+ })();
3204
3214
  const node = {
3205
3215
  id: `node_${(0, import_crypto3.randomUUID)().replace(/-/g, "")}`,
3206
3216
  workspace: opts.workspace.trim(),
3207
3217
  repoRoot: opts.repoRoot,
3208
3218
  daemonId: opts.daemonId,
3209
3219
  machineId: opts.machineId,
3220
+ ...machineNickname ? { machineNickname } : {},
3210
3221
  capabilities: normalizeCapabilityTags(opts.capabilities),
3211
3222
  userOverrides: opts.userOverrides || {},
3212
3223
  policy: opts.policy || {},
@@ -3241,6 +3252,7 @@ function updateNode(meshId, nodeId, opts) {
3241
3252
  if (opts.userOverrides) node.userOverrides = { ...node.userOverrides, ...opts.userOverrides };
3242
3253
  if (opts.reportedPlatform && opts.reportedPlatform.trim()) node.reportedPlatform = opts.reportedPlatform.trim();
3243
3254
  if (opts.reportedArch && opts.reportedArch.trim()) node.reportedArch = opts.reportedArch.trim();
3255
+ if (opts.reportedMachineNickname && opts.reportedMachineNickname.trim()) node.machineNickname = opts.reportedMachineNickname.trim();
3244
3256
  if (opts.policy) node.policy = { ...node.policy, ...opts.policy };
3245
3257
  if (opts.worktreeBootstrap) node.worktreeBootstrap = opts.worktreeBootstrap;
3246
3258
  if (Object.prototype.hasOwnProperty.call(opts, "systemPrompt")) {
@@ -24946,6 +24958,7 @@ var path3 = __toESM(require("path"));
24946
24958
  init_git_diff();
24947
24959
  init_git_executor();
24948
24960
  init_git_status();
24961
+ init_config();
24949
24962
  var GIT_COMMAND_NAMES = /* @__PURE__ */ new Set([
24950
24963
  "git_status",
24951
24964
  "git_diff_summary",
@@ -25085,7 +25098,21 @@ async function handleGitCommand(command, args, services = defaultGitCommandServi
25085
25098
  if (submoduleIgnorePaths && submoduleIgnorePaths.length > 0) statusParams.submoduleIgnorePaths = submoduleIgnorePaths;
25086
25099
  const status = await runService(() => services.getStatus(statusParams));
25087
25100
  if ("success" in status) return status;
25088
- return { success: true, status, reporterPlatform: process.platform, reporterArch: process.arch };
25101
+ const reporterMachineNickname = (() => {
25102
+ try {
25103
+ const nick = loadConfig().machineNickname;
25104
+ return typeof nick === "string" && nick.trim() ? nick.trim() : void 0;
25105
+ } catch {
25106
+ return void 0;
25107
+ }
25108
+ })();
25109
+ return {
25110
+ success: true,
25111
+ status,
25112
+ reporterPlatform: process.platform,
25113
+ reporterArch: process.arch,
25114
+ ...reporterMachineNickname ? { reporterMachineNickname } : {}
25115
+ };
25089
25116
  }
25090
25117
  case "git_diff_summary": {
25091
25118
  if (!services.getDiffSummary) return serviceNotImplemented(command);
@@ -52427,6 +52454,10 @@ var meshStatusHandlers = {
52427
52454
  const sessionHostRecords = ctx.deps.sessionHostControl?.listSessions ? await ctx.deps.sessionHostControl.listSessions().catch(() => []) : [];
52428
52455
  const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
52429
52456
  const localMachineId = loadConfig().machineId || "";
52457
+ const localMachineNickname = (() => {
52458
+ const nick = loadConfig().machineNickname;
52459
+ return typeof nick === "string" && nick.trim() ? nick.trim() : "";
52460
+ })();
52430
52461
  const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
52431
52462
  const meshGitProbeCache = ctx.meshGitProbeCache;
52432
52463
  const directTruth = requireDirectPeerTruth ? await hydrateInlineMeshDirectTruth({
@@ -52507,6 +52538,9 @@ var meshStatusHandlers = {
52507
52538
  ) || Boolean(
52508
52539
  daemonId && (daemonIdsEquivalent(daemonId, localMachineId) || daemonIdsEquivalent(daemonId, ctx.deps.statusInstanceId))
52509
52540
  ) || Boolean(meshRecord?.inline && nodeIndex === 0) || sparseConfiguredCoordinatorNode;
52541
+ if (isSelfNode && localMachineNickname && !readStringValue(node.machineNickname, node.machine_nickname)) {
52542
+ node.machineNickname = localMachineNickname;
52543
+ }
52510
52544
  const machineIdentity = buildMeshNodeMachineIdentity(node, {
52511
52545
  localMachineId,
52512
52546
  localDaemonId: ctx.deps.statusInstanceId,
@@ -53395,7 +53429,7 @@ function buildLivePeerGitConnection(connection, timestamp = (/* @__PURE__ */ new
53395
53429
  }
53396
53430
  function recordInlineMeshDirectGitTruth(node, git, source) {
53397
53431
  if (!node || typeof node !== "object" || Array.isArray(node)) {
53398
- return { reporterPlatform: null, reporterArch: null };
53432
+ return { reporterPlatform: null, reporterArch: null, reporterMachineNickname: null };
53399
53433
  }
53400
53434
  const checkedAt = readNumberValue(git.lastCheckedAt) ?? Date.now();
53401
53435
  const updatedAt = new Date(checkedAt).toISOString();
@@ -53420,7 +53454,9 @@ function recordInlineMeshDirectGitTruth(node, git, source) {
53420
53454
  stampNodeReporterPlatform(node, reporterPlatform, reporterArch);
53421
53455
  if (reporterPlatform) node.reportedPlatform = reporterPlatform;
53422
53456
  if (reporterArch) node.reportedArch = reporterArch;
53423
- return { reporterPlatform, reporterArch };
53457
+ const reporterMachineNickname = readStringValue(git.reporterMachineNickname) ?? null;
53458
+ if (reporterMachineNickname) node.machineNickname = reporterMachineNickname;
53459
+ return { reporterPlatform, reporterArch, reporterMachineNickname };
53424
53460
  }
53425
53461
  function stampNodeReporterPlatform(node, platform10, arch2) {
53426
53462
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -53443,8 +53479,9 @@ function persistNodeReporterPlatform(meshSource, mesh, nodeId, reporter) {
53443
53479
  if (!meshId || !nodeId) return;
53444
53480
  const reportedPlatform = reporter.reporterPlatform ?? void 0;
53445
53481
  const reportedArch = reporter.reporterArch ?? void 0;
53446
- if (!reportedPlatform && !reportedArch) return;
53447
- void Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports)).then(({ updateNode: updateNode2 }) => updateNode2(meshId, nodeId, { reportedPlatform, reportedArch })).catch(() => {
53482
+ const reportedMachineNickname = reporter.reporterMachineNickname ?? void 0;
53483
+ if (!reportedPlatform && !reportedArch && !reportedMachineNickname) return;
53484
+ void Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports)).then(({ updateNode: updateNode2 }) => updateNode2(meshId, nodeId, { reportedPlatform, reportedArch, reportedMachineNickname })).catch(() => {
53448
53485
  });
53449
53486
  }
53450
53487
  function buildCachedInlineMeshGitStatus(node) {
@@ -54096,9 +54133,11 @@ async function probeRemoteMeshGitStatus(args) {
54096
54133
  if (!remoteGit || typeof remoteGit !== "object" || typeof remoteGit.isGitRepo !== "boolean") return null;
54097
54134
  const reporterPlatform = readStringValue(remoteResult?.reporterPlatform);
54098
54135
  const reporterArch = readStringValue(remoteResult?.reporterArch);
54136
+ const reporterMachineNickname = readStringValue(remoteResult?.reporterMachineNickname);
54099
54137
  const git = remoteGit;
54100
54138
  if (reporterPlatform) git.reporterPlatform = reporterPlatform;
54101
54139
  if (reporterArch) git.reporterArch = reporterArch;
54140
+ if (reporterMachineNickname) git.reporterMachineNickname = reporterMachineNickname;
54102
54141
  return git;
54103
54142
  }
54104
54143
  var MESH_DIRECT_PROBE_MAX_RETRIES = 2;