@andorra-labs/code 0.1.16 → 0.1.17

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 (188) hide show
  1. package/dist/src/acp-agent.d.ts +6 -0
  2. package/dist/src/acp-agent.js +15 -4
  3. package/dist/src/agent-execution.js +11 -8
  4. package/dist/src/agent-mcp-catalog.js +1 -0
  5. package/dist/src/agent-mcp.d.ts +3 -0
  6. package/dist/src/agent-mcp.js +33 -1
  7. package/dist/src/andorra/entry.d.ts +10 -0
  8. package/dist/src/andorra/entry.js +18 -4
  9. package/dist/src/andorra/hosted.d.ts +2 -1
  10. package/dist/src/andorra/hosted.js +2 -1
  11. package/dist/src/andorra/notices.d.ts +5 -0
  12. package/dist/src/andorra/notices.js +7 -0
  13. package/dist/src/andorra/state.d.ts +3 -2
  14. package/dist/src/andorra/state.js +4 -4
  15. package/dist/src/andorra/terminal.js +7 -2
  16. package/dist/src/anthropic-credentials.js +2 -0
  17. package/dist/src/app-server/error.d.ts +5 -0
  18. package/dist/src/app-server/error.js +7 -0
  19. package/dist/src/app-server/protocol.d.ts +19 -44
  20. package/dist/src/app-server/protocol.js +5 -1
  21. package/dist/src/app-server/workspace.d.ts +89 -0
  22. package/dist/src/app-server/workspace.js +457 -11
  23. package/dist/src/app-server.d.ts +358 -32
  24. package/dist/src/app-server.js +2429 -509
  25. package/dist/src/bridge/cloud.d.ts +27 -0
  26. package/dist/src/bridge/cloud.js +187 -0
  27. package/dist/src/bridge/command.d.ts +30 -0
  28. package/dist/src/bridge/command.js +347 -0
  29. package/dist/src/bridge/control.d.ts +68 -0
  30. package/dist/src/bridge/control.js +233 -0
  31. package/dist/src/bridge/engines.d.ts +90 -0
  32. package/dist/src/bridge/engines.js +601 -0
  33. package/dist/src/bridge/host-ops.d.ts +9 -0
  34. package/dist/src/bridge/host-ops.js +129 -0
  35. package/dist/src/bridge/host.d.ts +47 -0
  36. package/dist/src/bridge/host.js +540 -0
  37. package/dist/src/bridge/link.d.ts +38 -0
  38. package/dist/src/bridge/link.js +508 -0
  39. package/dist/src/bridge/login-link.d.ts +29 -0
  40. package/dist/src/bridge/login-link.js +54 -0
  41. package/dist/src/bridge/protocol.d.ts +136 -0
  42. package/dist/src/bridge/protocol.js +11 -0
  43. package/dist/src/bridge/store.d.ts +12 -0
  44. package/dist/src/bridge/store.js +61 -0
  45. package/dist/src/bridge/wording.d.ts +6 -0
  46. package/dist/src/bridge/wording.js +10 -0
  47. package/dist/src/browser-server.js +7 -1
  48. package/dist/src/browser-ui/tokens.css +1 -1
  49. package/dist/src/change-authors.d.ts +41 -0
  50. package/dist/src/change-authors.js +146 -0
  51. package/dist/src/cli.js +182 -32
  52. package/dist/src/coding-tools.js +15 -15
  53. package/dist/src/command-screens.d.ts +6 -0
  54. package/dist/src/command-screens.js +14 -11
  55. package/dist/src/commands.d.ts +14 -2
  56. package/dist/src/compaction-phrases.js +1 -1
  57. package/dist/src/completion.js +82 -5
  58. package/dist/src/config.d.ts +71 -3
  59. package/dist/src/config.js +202 -77
  60. package/dist/src/deadline.js +13 -1
  61. package/dist/src/decision/checks.js +1 -1
  62. package/dist/src/decision/requestPhrases.js +0 -1
  63. package/dist/src/default-graph.js +1 -1
  64. package/dist/src/file-diff.d.ts +4 -0
  65. package/dist/src/file-diff.js +2 -1
  66. package/dist/src/github-app/agent-writes.d.ts +102 -0
  67. package/dist/src/github-app/agent-writes.js +320 -0
  68. package/dist/src/github-app/client.d.ts +349 -0
  69. package/dist/src/github-app/client.js +810 -0
  70. package/dist/src/github-app/event-source.d.ts +208 -0
  71. package/dist/src/github-app/event-source.js +684 -0
  72. package/dist/src/github-app/metrics.d.ts +32 -0
  73. package/dist/src/github-app/metrics.js +49 -0
  74. package/dist/src/github-app/review-loop.d.ts +274 -0
  75. package/dist/src/github-app/review-loop.js +1177 -0
  76. package/dist/src/github-app/review-node.d.ts +81 -0
  77. package/dist/src/github-app/review-node.js +205 -0
  78. package/dist/src/github-app/review-post.d.ts +73 -0
  79. package/dist/src/github-app/review-post.js +139 -0
  80. package/dist/src/github-app/review-text.d.ts +107 -0
  81. package/dist/src/github-app/review-text.js +1133 -0
  82. package/dist/src/github-app/review-threads.d.ts +47 -0
  83. package/dist/src/github-app/review-threads.js +107 -0
  84. package/dist/src/github-app/reviewer.d.ts +121 -0
  85. package/dist/src/github-app/reviewer.js +598 -0
  86. package/dist/src/github-app/store.d.ts +59 -0
  87. package/dist/src/github-app/store.js +148 -0
  88. package/dist/src/github-app/triggers.d.ts +141 -0
  89. package/dist/src/github-app/triggers.js +441 -0
  90. package/dist/src/github-names.d.ts +8 -0
  91. package/dist/src/github-names.js +8 -0
  92. package/dist/src/glob-search.d.ts +61 -0
  93. package/dist/src/glob-search.js +180 -0
  94. package/dist/src/graph-health.js +6 -1
  95. package/dist/src/graph-manager-chat.js +1 -1
  96. package/dist/src/graph-preview.d.ts +46 -0
  97. package/dist/src/graph-preview.js +55 -0
  98. package/dist/src/graph-provider-portability.js +2 -1
  99. package/dist/src/graph-runner.js +64 -3
  100. package/dist/src/graph-server.js +3 -3
  101. package/dist/src/graph-sync.js +3 -3
  102. package/dist/src/graph-ui/app.js +91 -7
  103. package/dist/src/graph-ui/icons.js +2 -1
  104. package/dist/src/graph-ui/studio.js +15 -1
  105. package/dist/src/graph-ui/tokens.css +1 -1
  106. package/dist/src/graphs.d.ts +34 -1
  107. package/dist/src/graphs.js +158 -14
  108. package/dist/src/image-input.d.ts +16 -0
  109. package/dist/src/image-input.js +41 -0
  110. package/dist/src/membership.d.ts +10 -0
  111. package/dist/src/membership.js +19 -4
  112. package/dist/src/model-health-cache.js +1 -1
  113. package/dist/src/model-metadata.d.ts +6 -0
  114. package/dist/src/model-metadata.js +35 -15
  115. package/dist/src/model-relay/local.d.ts +116 -0
  116. package/dist/src/model-relay/local.js +468 -0
  117. package/dist/src/model-relay/remote.d.ts +129 -0
  118. package/dist/src/model-relay/remote.js +252 -0
  119. package/dist/src/model-relay/runs.d.ts +34 -0
  120. package/dist/src/model-relay/runs.js +146 -0
  121. package/dist/src/model-relay/wire.d.ts +5 -0
  122. package/dist/src/model-relay/wire.js +5 -0
  123. package/dist/src/project-registry.d.ts +21 -0
  124. package/dist/src/project-registry.js +74 -0
  125. package/dist/src/provider-import.d.ts +0 -12
  126. package/dist/src/provider-import.js +7 -195
  127. package/dist/src/providers.d.ts +23 -2
  128. package/dist/src/providers.js +25 -4
  129. package/dist/src/pull-request-logs.d.ts +12 -1
  130. package/dist/src/pull-request-logs.js +14 -3
  131. package/dist/src/pull-requests.d.ts +327 -7
  132. package/dist/src/pull-requests.js +429 -51
  133. package/dist/src/react-runtime.js +1 -1
  134. package/dist/src/remote/engine-pool.d.ts +88 -4
  135. package/dist/src/remote/engine-pool.js +366 -89
  136. package/dist/src/remote/roots.d.ts +19 -0
  137. package/dist/src/remote/roots.js +45 -7
  138. package/dist/src/remote/types.d.ts +0 -44
  139. package/dist/src/run-control.d.ts +7 -0
  140. package/dist/src/run-control.js +23 -0
  141. package/dist/src/run-records.d.ts +7 -2
  142. package/dist/src/run-records.js +71 -6
  143. package/dist/src/runtime.d.ts +5 -1
  144. package/dist/src/runtime.js +10 -2
  145. package/dist/src/session-changes.d.ts +35 -0
  146. package/dist/src/session-changes.js +194 -6
  147. package/dist/src/session-monitor.js +2 -1
  148. package/dist/src/session-reaper.d.ts +1 -1
  149. package/dist/src/session-reaper.js +6 -1
  150. package/dist/src/session-summary.d.ts +2 -1
  151. package/dist/src/session-summary.js +2 -1
  152. package/dist/src/sessions.d.ts +11 -1
  153. package/dist/src/sessions.js +17 -4
  154. package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
  155. package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
  156. package/dist/src/skills/bundled/provenance.json +2 -2
  157. package/dist/src/skills/runtime-skills.js +1 -1
  158. package/dist/src/telemetry/emitter.d.ts +15 -0
  159. package/dist/src/telemetry/emitter.js +35 -1
  160. package/dist/src/telemetry/schema.d.ts +25 -2
  161. package/dist/src/telemetry/schema.js +52 -4
  162. package/dist/src/telemetry/surface.d.ts +2 -1
  163. package/dist/src/telemetry/surface.js +4 -1
  164. package/dist/src/terminal-ui.d.ts +1 -0
  165. package/dist/src/terminal-ui.js +10 -3
  166. package/dist/src/test-edit-guard.d.ts +7 -0
  167. package/dist/src/test-edit-guard.js +49 -1
  168. package/dist/src/timers.d.ts +2 -0
  169. package/dist/src/tools.js +59 -9
  170. package/package.json +6 -1
  171. package/dist/src/remote/cert.d.ts +0 -11
  172. package/dist/src/remote/cert.js +0 -87
  173. package/dist/src/remote/client.d.ts +0 -119
  174. package/dist/src/remote/client.js +0 -544
  175. package/dist/src/remote/command.d.ts +0 -4
  176. package/dist/src/remote/command.js +0 -194
  177. package/dist/src/remote/errors.d.ts +0 -11
  178. package/dist/src/remote/errors.js +0 -14
  179. package/dist/src/remote/network.d.ts +0 -22
  180. package/dist/src/remote/network.js +0 -102
  181. package/dist/src/remote/pairing.d.ts +0 -63
  182. package/dist/src/remote/pairing.js +0 -299
  183. package/dist/src/remote/pem.d.ts +0 -2
  184. package/dist/src/remote/pem.js +0 -7
  185. package/dist/src/remote/serve.d.ts +0 -68
  186. package/dist/src/remote/serve.js +0 -244
  187. package/dist/src/remote/server.d.ts +0 -21
  188. package/dist/src/remote/server.js +0 -406
@@ -1,194 +0,0 @@
1
- import { realpath, stat } from 'node:fs/promises';
2
- import { basename, resolve } from 'node:path';
3
- import { configDirectory, loadConfig } from '../config.js';
4
- import { decodePairingCode } from './pairing.js';
5
- import { addRemoteShare, addRemoteWorkspace, clearRemoteInvitation, newWorkspaceId, removeRemoteShare, removeRemoteWorkspace, revokeRemoteDevice } from './pairing.js';
6
- import { ensureRemoteServe, remoteFingerprint, remoteHostingStatus, probeServeStatus } from './serve.js';
7
- import { ensureRemoteTlsIdentity } from './cert.js';
8
- import { redeemPairingPlan } from './client.js';
9
- import { RemoteOwnershipError } from './errors.js';
10
- export const REMOTE_USAGE = `Usage: andorra remote serve [--port N] [--insecure-http] [--rotate-cert]
11
- andorra remote status
12
- andorra remote code
13
- andorra remote devices | andorra remote revoke <device-id>
14
- andorra remote share <path> [--label name] | andorra remote unshare <share-id>
15
- andorra remote pair <pairing-code> [--name nickname]
16
- andorra remote workspaces | andorra remote unpair <workspace-id>
17
- andorra remote rotate-cert`;
18
- function message(error) { return error instanceof Error ? error.message : String(error); }
19
- async function waitForStop() {
20
- await new Promise(resolve => {
21
- const stop = () => { process.removeListener('SIGINT', stop); process.removeListener('SIGTERM', stop); resolve(); };
22
- process.once('SIGINT', stop);
23
- process.once('SIGTERM', stop);
24
- });
25
- }
26
- async function sharePath(value) {
27
- const candidate = resolve(value);
28
- const realPath = await realpath(candidate).catch(() => undefined);
29
- if (!realPath)
30
- throw new Error(`That folder does not exist: ${value}`);
31
- if (!(await stat(realPath)).isDirectory())
32
- throw new Error(`That path is not a folder: ${value}`);
33
- return realPath;
34
- }
35
- export async function runRemoteCommand(args, print, dependencies = {}) {
36
- const [command, ...rest] = args;
37
- const flag = (name) => {
38
- const index = rest.indexOf(name);
39
- return index >= 0 ? rest[index + 1] : undefined;
40
- };
41
- switch (command) {
42
- case 'serve': {
43
- const port = flag('--port');
44
- const handle = await ensureRemoteServe({
45
- owner: 'standalone',
46
- ...(port !== undefined ? { port: Number(port) } : {}),
47
- insecureHttp: rest.includes('--insecure-http'),
48
- rotateCert: rest.includes('--rotate-cert'),
49
- version: dependencies.version,
50
- });
51
- if (!handle.serving)
52
- throw new RemoteOwnershipError('The remote listener could not start.');
53
- try {
54
- const status = await remoteHostingStatus({ ensureServing: false });
55
- print(`Remote listener: ${handle.transport}://${status.hostname}:${handle.port} (${handle.owned ? 'this process' : 'adopted existing listener'})`);
56
- print(`Fingerprint: ${status.fingerprint}`);
57
- for (const line of status.code ? [`Pairing code: ${status.code}`] : [])
58
- print(line);
59
- if (handle.transport === 'http')
60
- print('WARNING: transport is http — folder names and contents travel unencrypted on the network.');
61
- print('Press Ctrl+C to stop serving.');
62
- await waitForStop();
63
- }
64
- finally {
65
- await handle.release().catch(() => undefined);
66
- }
67
- print('Stopped serving.');
68
- return 0;
69
- }
70
- case 'status': {
71
- const probed = await probeServeStatus();
72
- const config = await loadConfig();
73
- print(`Listener: ${probed ? `serving on ${probed.transport} port ${probed.port}` : 'not serving'}`);
74
- print(`Transport: ${config.remote?.hosting?.transport ?? 'https'}`);
75
- print(`Devices: ${(config.remote?.hosting?.devices ?? []).length}`);
76
- print(`Shares: ${(config.remote?.hosting?.shares ?? []).map(share => share.label ?? share.path).join(', ') || 'none'}`);
77
- print(`Paired workspaces: ${(config.remote?.workspaces ?? []).length}`);
78
- return 0;
79
- }
80
- case 'code': {
81
- const status = await remoteHostingStatus({ ensureServing: true, owner: 'standalone', version: dependencies.version });
82
- try {
83
- if (!status.code)
84
- throw new Error('No pairing code is available yet — the listener is still starting.');
85
- print(status.code);
86
- if (status.serve?.owned) {
87
- print('Keep this window open while pairing (Ctrl+C stops) — or leave serving to `andorra remote serve`.');
88
- await waitForStop();
89
- }
90
- }
91
- finally {
92
- await status.serve?.release().catch(() => undefined);
93
- }
94
- return 0;
95
- }
96
- case 'devices': {
97
- const config = await loadConfig();
98
- const devices = config.remote?.hosting?.devices ?? [];
99
- if (!devices.length)
100
- print('No paired devices.');
101
- for (const device of devices)
102
- print(`${device.id} ${device.label ?? 'unlabeled'} grant ${device.grant === 'full' ? 'full' : 'browse'} added ${device.addedAt}${device.lastSeenAt ? ` last seen ${device.lastSeenAt}` : ''}`);
103
- return 0;
104
- }
105
- case 'revoke': {
106
- const deviceId = rest[0];
107
- if (!deviceId)
108
- throw new Error('Usage: andorra remote revoke <device-id>');
109
- print(await revokeRemoteDevice(deviceId) ? `Revoked device ${deviceId}.` : `No device with id ${deviceId}.`);
110
- return 0;
111
- }
112
- case 'share': {
113
- const path = rest.find(entry => !entry.startsWith('--'));
114
- if (!path)
115
- throw new Error('Usage: andorra remote share <path> [--label name]');
116
- const share = await addRemoteShare(await sharePath(path), { label: flag('--label') });
117
- print(`Shared ${share.path} as ${share.label ?? basename(share.path)} (id ${share.id}).`);
118
- return 0;
119
- }
120
- case 'unshare': {
121
- const shareId = rest[0];
122
- if (!shareId)
123
- throw new Error('Usage: andorra remote unshare <share-id>');
124
- print(await removeRemoteShare(shareId) ? `Removed share ${shareId}.` : `No share with id ${shareId}.`);
125
- return 0;
126
- }
127
- case 'pair': {
128
- const code = rest.find(entry => !entry.startsWith('--'));
129
- if (!code)
130
- throw new Error('Usage: andorra remote pair <pairing-code> [--name nickname]');
131
- const local = await loadConfig();
132
- if ((local.remote?.workspaces ?? []).length >= 32) {
133
- throw new Error('This machine already pairs with the maximum number of workspaces. Unpair one, then pair again — the code has not been used.');
134
- }
135
- const decoded = decodePairingCode(code);
136
- const redeemed = await redeemPairingPlan({
137
- hosts: decoded.hosts,
138
- port: decoded.port,
139
- transport: decoded.transport,
140
- fingerprint: decoded.fp,
141
- invite: decoded.invite,
142
- name: decoded.n,
143
- }, { label: flag('--name') });
144
- const workspace = {
145
- id: newWorkspaceId(),
146
- nickname: (flag('--name') ?? redeemed.hostname ?? decoded.n).slice(0, 64),
147
- hosts: decoded.hosts,
148
- host: redeemed.host,
149
- port: decoded.port,
150
- transport: decoded.transport,
151
- fingerprint: decoded.fp,
152
- certPem: redeemed.certPem,
153
- token: redeemed.credential,
154
- hostname: redeemed.hostname,
155
- platform: redeemed.platform,
156
- version: redeemed.version,
157
- addedAt: new Date().toISOString(),
158
- };
159
- await addRemoteWorkspace(workspace).catch((error) => {
160
- throw new Error(`Paired with ${workspace.nickname}, but the workspace could not be saved locally (${error instanceof Error ? error.message : String(error)}). That machine now lists a device for this machine — revoke it there before pairing again.`);
161
- });
162
- print(`Paired with ${workspace.nickname} (id ${workspace.id}). Switch to it from the Workspace selector in the desktop.`);
163
- return 0;
164
- }
165
- case 'workspaces': {
166
- const config = await loadConfig();
167
- const workspaces = config.remote?.workspaces ?? [];
168
- if (!workspaces.length)
169
- print('No paired workspaces.');
170
- for (const workspace of workspaces)
171
- print(`${workspace.id} ${workspace.nickname} ${workspace.host ?? workspace.hosts[0]}:${workspace.port} (${workspace.transport})`);
172
- return 0;
173
- }
174
- case 'unpair': {
175
- const workspaceId = rest[0];
176
- if (!workspaceId)
177
- throw new Error('Usage: andorra remote unpair <workspace-id>');
178
- print(await removeRemoteWorkspace(workspaceId) ? `Unpaired workspace ${workspaceId}.` : `No workspace with id ${workspaceId}.`);
179
- return 0;
180
- }
181
- case 'rotate-cert': {
182
- await ensureRemoteTlsIdentity(`${configDirectory()}/remote-live/tls`, { rotate: true });
183
- await clearRemoteInvitation();
184
- const fingerprint = await remoteFingerprint();
185
- print(`Rotated the TLS identity. New fingerprint: ${fingerprint}`);
186
- print('Existing pairing codes and every peer\'s saved pairing are now invalid: generate new codes and re-pair each machine.');
187
- print('Restart any running listener (`andorra remote serve`) so it serves the new certificate.');
188
- return 0;
189
- }
190
- default:
191
- print(REMOTE_USAGE);
192
- return command === undefined ? 0 : 1;
193
- }
194
- }
@@ -1,11 +0,0 @@
1
- export type RemotePeerErrorKind = 'offline' | 'identity' | 'unauthorized' | 'network' | 'rejected';
2
- export declare class RemotePeerError extends Error {
3
- readonly kind: RemotePeerErrorKind;
4
- constructor(kind: RemotePeerErrorKind, message: string);
5
- }
6
- export declare class InviteRejectedError extends Error {
7
- constructor(message: string);
8
- }
9
- export declare class RemoteOwnershipError extends Error {
10
- constructor(message: string);
11
- }
@@ -1,14 +0,0 @@
1
- export class RemotePeerError extends Error {
2
- kind;
3
- constructor(kind, message) {
4
- super(message);
5
- this.kind = kind;
6
- this.name = 'RemotePeerError';
7
- }
8
- }
9
- export class InviteRejectedError extends Error {
10
- constructor(message) { super(message); this.name = 'InviteRejectedError'; }
11
- }
12
- export class RemoteOwnershipError extends Error {
13
- constructor(message) { super(message); this.name = 'RemoteOwnershipError'; }
14
- }
@@ -1,22 +0,0 @@
1
- import { networkInterfaces } from 'node:os';
2
- export declare function isTailscaleAddress(address: string): boolean;
3
- export declare function isPrivateAddress(address: string): boolean;
4
- export declare function isMagicDnsName(name: string): boolean;
5
- export declare function isAllowedPeerHost(host: string): boolean;
6
- export interface PeerAddress {
7
- address: string;
8
- family: 4 | 6;
9
- }
10
- export declare function resolvePeerAddresses(host: string, lookup?: (hostname: string, options: {
11
- all: true;
12
- verbatim: true;
13
- }) => Promise<PeerAddress[]>): Promise<PeerAddress[]>;
14
- export declare function resolvePeerAddress(host: string, lookup?: (hostname: string, options: {
15
- all: true;
16
- verbatim: true;
17
- }) => Promise<PeerAddress[]>): Promise<PeerAddress>;
18
- export interface HostDiscovery {
19
- tailscale?: () => Promise<string | undefined>;
20
- interfaces?: () => ReturnType<typeof networkInterfaces>;
21
- }
22
- export declare function advertiseHosts(discovery?: HostDiscovery): Promise<string[]>;
@@ -1,102 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import { networkInterfaces } from 'node:os';
3
- import { isIP } from 'node:net';
4
- import { promisify } from 'node:util';
5
- const execFileAsync = promisify(execFile);
6
- export function isTailscaleAddress(address) {
7
- if (isIP(address) !== 4)
8
- return false;
9
- const [first, second] = address.split('.').map(Number);
10
- return first === 100 && second >= 64 && second <= 127;
11
- }
12
- export function isPrivateAddress(address) {
13
- const value = address.replace(/^\[|\]$/g, '').toLowerCase();
14
- if (value === 'localhost' || value === '::1')
15
- return true;
16
- if (isTailscaleAddress(value))
17
- return true;
18
- if (isIP(value) === 4) {
19
- const [first, second] = value.split('.').map(Number);
20
- return first === 127 || first === 10 || (first === 172 && second >= 16 && second <= 31) || (first === 192 && second === 168);
21
- }
22
- return isIP(value) === 6 && (/^f[cd]/.test(value) || /^fe80/.test(value));
23
- }
24
- export function isMagicDnsName(name) {
25
- const value = name.toLowerCase();
26
- if (!value.endsWith('.ts.net') || value.includes('*'))
27
- return false;
28
- const label = '[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?';
29
- return new RegExp(`^(?:${label}\\.)+${label}$`).test(value);
30
- }
31
- export function isAllowedPeerHost(host) {
32
- const value = host.replace(/^\[|\]$/g, '');
33
- if (isIP(value))
34
- return isPrivateAddress(value);
35
- return isMagicDnsName(host);
36
- }
37
- export async function resolvePeerAddresses(host, lookup) {
38
- const value = host.replace(/^\[|\]$/g, '');
39
- if (isIP(value)) {
40
- if (!isPrivateAddress(value))
41
- throw new Error(`Refusing to contact ${host}: it is not a private or Tailscale address`);
42
- return [{ address: value, family: isIP(value) === 6 ? 6 : 4 }];
43
- }
44
- if (!isAllowedPeerHost(host))
45
- throw new Error(`Refusing to contact ${host}: peer hosts must be private addresses or Tailscale names`);
46
- const resolve = lookup ?? (async (hostname) => {
47
- const { promises } = await import('node:dns');
48
- return await promises.lookup(hostname, { all: true, verbatim: true });
49
- });
50
- const answers = await resolve(host, { all: true, verbatim: true });
51
- const list = Array.isArray(answers) ? answers : [answers];
52
- if (!list.length)
53
- throw new Error(`Could not resolve ${host}: no addresses returned`);
54
- for (const answer of list) {
55
- if (!isPrivateAddress(answer.address))
56
- throw new Error(`Refusing to contact ${host}: it resolved to the non-private address ${answer.address}`);
57
- }
58
- const seen = new Set();
59
- return [...list]
60
- .sort((left, right) => left.family === right.family ? 0 : left.family === 4 ? -1 : 1)
61
- .filter(answer => { if (seen.has(answer.address))
62
- return false; seen.add(answer.address); return true; });
63
- }
64
- export async function resolvePeerAddress(host, lookup) {
65
- return (await resolvePeerAddresses(host, lookup))[0];
66
- }
67
- async function tailscaleSelfName() {
68
- try {
69
- const { stdout } = await execFileAsync('tailscale', ['status', '--json'], { timeout: 4000, windowsHide: true, maxBuffer: 1 << 20 });
70
- const parsed = JSON.parse(stdout);
71
- const name = (parsed.Self?.DNSName ?? '').toLowerCase().replace(/\.$/, '');
72
- return isMagicDnsName(name) ? name : undefined;
73
- }
74
- catch {
75
- return undefined;
76
- }
77
- }
78
- export async function advertiseHosts(discovery = {}) {
79
- const discoverTailscale = discovery.tailscale ?? tailscaleSelfName;
80
- const hosts = [];
81
- try {
82
- const name = await discoverTailscale();
83
- if (name !== undefined && isAllowedPeerHost(name))
84
- hosts.push(name);
85
- }
86
- catch { }
87
- const interfaces = (discovery.interfaces ?? networkInterfaces)();
88
- for (const entries of Object.values(interfaces)) {
89
- for (const entry of entries ?? []) {
90
- if (entry.internal)
91
- continue;
92
- const address = entry.address.replace(/^\[|\]$/g, '');
93
- if (address.startsWith('::ffff:'))
94
- continue;
95
- if (/^fe80:/i.test(address))
96
- continue;
97
- if (isPrivateAddress(address) && !hosts.includes(address))
98
- hosts.push(address);
99
- }
100
- }
101
- return hosts.slice(0, 8);
102
- }
@@ -1,63 +0,0 @@
1
- import type { RemoteDevice, RemoteInvitation, RemoteShare, RemoteTransport, RemoteGrant, RemoteWorkspace } from './types.js';
2
- export declare const INVITE_TTL_MS: number;
3
- export interface PairingCode {
4
- v: 1;
5
- hosts: string[];
6
- port: number;
7
- invite: string;
8
- fp: string;
9
- transport: RemoteTransport;
10
- n: string;
11
- }
12
- export declare function encodePairingCode(code: PairingCode): string;
13
- export declare function decodePairingCode(value: string): PairingCode;
14
- export declare function invitationIsUsable(invitation: RemoteInvitation | null | undefined, now?: number): boolean;
15
- export declare function createRemoteInvitation(directory?: string, now?: number, grant?: RemoteGrant): Promise<RemoteInvitation>;
16
- export declare function clearRemoteInvitation(directory?: string): Promise<void>;
17
- export declare function redeemRemoteInvitation(invite: string, options?: {
18
- label?: string;
19
- directory?: string;
20
- now?: number;
21
- }): Promise<{
22
- deviceId: string;
23
- credential: string;
24
- grant: RemoteGrant;
25
- }>;
26
- export declare function revokeRemoteDevice(deviceId: string, directory?: string): Promise<boolean>;
27
- export declare function grantRemoteDevice(deviceId: string, directory?: string): Promise<RemoteDevice | null>;
28
- export declare function addRemoteShare(path: string, options?: {
29
- label?: string;
30
- directory?: string;
31
- }): Promise<RemoteShare>;
32
- export declare function removeRemoteShare(shareId: string, directory?: string): Promise<boolean>;
33
- export declare function persistRemotePort(port: number, directory?: string): Promise<void>;
34
- export declare function ensureRemoteInstallId(directory?: string): Promise<string>;
35
- export declare function setRemoteTransport(transport: RemoteTransport, directory?: string): Promise<void>;
36
- export declare function newWorkspaceId(): string;
37
- export declare function addRemoteWorkspace(workspace: RemoteWorkspace, directory?: string): Promise<void>;
38
- export declare function removeRemoteWorkspace(workspaceId: string, directory?: string): Promise<boolean>;
39
- export declare function updateRemoteWorkspace(workspaceId: string, changes: {
40
- nickname?: string;
41
- host?: string | null;
42
- }, directory?: string): Promise<RemoteWorkspace | undefined>;
43
- export declare function addProjectEntry(path: string, options?: {
44
- name?: string;
45
- directory?: string;
46
- }): Promise<void>;
47
- export declare function relinkProjectEntry(from: string, to: string, options?: {
48
- name?: string;
49
- directory?: string;
50
- }): Promise<boolean>;
51
- /**
52
- * The id `path` answers to, storing `candidate` when it has none yet and returning whichever id is actually on the entry.
53
- * Two tasks created at the same moment on a folder that has just been added would otherwise each store their own id, and
54
- * the loser keeps an identity the registry never accepted, splitting the project's browser profiles for good.
55
- */
56
- export declare function ensureProjectIdentity(path: string, candidate: string, directory?: string): Promise<string | undefined>;
57
- /**
58
- * Remembers the project id a folder answers to, so a task started after a rename or a
59
- * merge belongs to the same project as the tasks that were already there.
60
- * An id already on the entry wins: a second rename must not restart the project's identity.
61
- */
62
- export declare function rememberProjectIdentity(path: string, id: string, directory?: string): Promise<void>;
63
- export declare function removeProjectEntry(path: string, directory?: string): Promise<boolean>;