@wonderwhy-er/desktop-commander 0.3.1-alpha.0 → 0.3.1-alpha.2

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 (76) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +1152 -1152
  3. package/dist/bootstrap.js +0 -0
  4. package/dist/command-manager.js +0 -0
  5. package/dist/config-field-definitions.js +0 -0
  6. package/dist/config-manager.d.ts +6 -0
  7. package/dist/config-manager.js +1 -1
  8. package/dist/config-recovery.js +0 -0
  9. package/dist/config.js +0 -0
  10. package/dist/custom-stdio.js +0 -0
  11. package/dist/data/onboarding-prompts.json +70 -70
  12. package/dist/error-handlers.js +0 -0
  13. package/dist/handlers/filesystem-handlers.js +2 -2
  14. package/dist/index.js +0 -0
  15. package/dist/npm-scripts/remote.js +34 -19
  16. package/dist/remote-device/diagnostics/device-log.d.ts +63 -0
  17. package/dist/remote-device/diagnostics/device-log.js +219 -0
  18. package/dist/remote-device/diagnostics/redact.d.ts +1 -0
  19. package/dist/remote-device/diagnostics/redact.js +76 -0
  20. package/dist/remote-device/diagnostics/report.d.ts +118 -0
  21. package/dist/remote-device/diagnostics/report.js +748 -0
  22. package/dist/remote-device/diagnostics/upload.d.ts +11 -0
  23. package/dist/remote-device/diagnostics/upload.js +59 -0
  24. package/dist/remote-device/scripts/blocking-offline-update.js +133 -133
  25. package/dist/search-manager.js +0 -0
  26. package/dist/server.js +610 -610
  27. package/dist/setup-claude-server.js +942 -942
  28. package/dist/terminal-manager.js +0 -0
  29. package/dist/tools/edit.js +2 -2
  30. package/dist/tools/fuzzySearch.js +9 -9
  31. package/dist/tools/improved-process-tools.js +10 -10
  32. package/dist/tools/pdf/extract-images.js +1 -1
  33. package/dist/tools/prompts.js +1 -1
  34. package/dist/track-installation.js +387 -387
  35. package/dist/types.js +0 -0
  36. package/dist/ui/config-editor/index.html +13 -13
  37. package/dist/ui/config-editor/src/app.js +30 -30
  38. package/dist/ui/config-editor/src/array-modal.js +32 -32
  39. package/dist/ui/config-editor/styles.css +586 -586
  40. package/dist/ui/file-preview/index.html +16 -16
  41. package/dist/ui/file-preview/src/app.js +8 -8
  42. package/dist/ui/file-preview/src/document-layout.js +31 -31
  43. package/dist/ui/file-preview/src/document-outline.js +8 -8
  44. package/dist/ui/file-preview/src/markdown/conflict-dialog.js +33 -33
  45. package/dist/ui/file-preview/src/markdown/controller.js +9 -9
  46. package/dist/ui/file-preview/src/markdown/editor.js +31 -31
  47. package/dist/ui/file-preview/styles.css +1630 -1630
  48. package/dist/uninstall-claude-server.js +745 -745
  49. package/dist/utils/files/binary.js +4 -4
  50. package/dist/utils/files/excel.js +3 -3
  51. package/dist/utils/lazy-package.d.ts +5 -3
  52. package/dist/utils/lazy-package.js +6 -4
  53. package/dist/utils/system-info.js +90 -90
  54. package/dist/utils/usageTracker.js +49 -49
  55. package/dist/version.d.ts +1 -1
  56. package/dist/version.js +1 -1
  57. package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -56
  58. package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -32
  59. package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -38
  60. package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -164
  61. package/package.json +29 -15
  62. package/vendor/telemetry-contract/README.md +56 -56
  63. package/vendor/telemetry-contract/package.json +32 -32
  64. package/vendor/telemetry-contract/transport.d.ts +38 -38
  65. package/vendor/telemetry-contract/transport.js +164 -164
  66. package/vendor/telemetry-contract/transport.test.js +39 -39
  67. package/dist/remote-device/broadcast-analytics.d.ts +0 -28
  68. package/dist/remote-device/broadcast-analytics.js +0 -41
  69. package/dist/remote-device/mqtt-enrollment.d.ts +0 -16
  70. package/dist/remote-device/mqtt-enrollment.js +0 -162
  71. package/dist/remote-device/mqtt-transport.d.ts +0 -44
  72. package/dist/remote-device/mqtt-transport.js +0 -197
  73. package/dist/remote-device/transport-analytics.d.ts +0 -29
  74. package/dist/remote-device/transport-analytics.js +0 -44
  75. package/dist/tools/search.d.ts +0 -32
  76. package/dist/tools/search.js +0 -202
@@ -1,162 +0,0 @@
1
- import { createPrivateKey, generateKeyPair, X509Certificate } from 'node:crypto';
2
- import { mkdir, open, readFile } from 'node:fs/promises';
3
- import path from 'node:path';
4
- import { promisify } from 'node:util';
5
- import forge from 'node-forge';
6
- import { readMqttConfig } from './mqtt-transport.js';
7
- const generateRsaKeyPair = promisify(generateKeyPair);
8
- const ID = /^[A-Za-z0-9_-]{1,128}$/;
9
- // Leave network headroom above the backend's 20-second AWS setup deadline.
10
- const ENROLLMENT_TIMEOUT_MS = 30000;
11
- /** Read only existing credentials; a damaged file must never trigger silent key replacement. */
12
- async function readCache(file) {
13
- try {
14
- const value = JSON.parse(await readFile(file, 'utf8'));
15
- if (!value || typeof value !== 'object' || Array.isArray(value))
16
- throw new Error();
17
- return value;
18
- }
19
- catch (error) {
20
- if (error.code === 'ENOENT')
21
- return null;
22
- throw new Error('MQTT credential cache cannot be read; inspect the profile MQTT folder before restarting');
23
- }
24
- }
25
- /** Exclusive creation preserves the winner's private key if two processes use the same profile. */
26
- async function writePrivateCache(file, value) {
27
- try {
28
- const handle = await open(file, 'wx', 0o600);
29
- try {
30
- await handle.writeFile(JSON.stringify(value));
31
- }
32
- finally {
33
- await handle.close();
34
- }
35
- }
36
- catch {
37
- // Do not include filesystem/provider errors: startup errors also go to telemetry.
38
- throw new Error('MQTT credentials could not be saved; use one connector process per profile and check folder permissions');
39
- }
40
- }
41
- /** Validate issued/cached material before it can authenticate this device to the broker. */
42
- function validateCertificate(value, privateKey) {
43
- try {
44
- if (!value || typeof value.certificate_pem !== 'string' || value.certificate_pem.length > 16384 ||
45
- typeof value.certificate_id !== 'string' || !/^[a-fA-F0-9]{64}$/.test(value.certificate_id) ||
46
- typeof value.broker_url !== 'string')
47
- throw new Error();
48
- const broker = new URL(value.broker_url);
49
- if (broker.protocol !== 'mqtts:' || !broker.hostname || broker.username || broker.password ||
50
- broker.search || broker.hash || (broker.pathname && broker.pathname !== '/'))
51
- throw new Error();
52
- const certificate = new X509Certificate(value.certificate_pem);
53
- const now = Date.now();
54
- if (certificate.ca || !certificate.checkPrivateKey(createPrivateKey(privateKey)) ||
55
- !Number.isFinite(Date.parse(certificate.validFrom)) || !Number.isFinite(Date.parse(certificate.validTo)) ||
56
- Date.parse(certificate.validFrom) > now || Date.parse(certificate.validTo) <= now)
57
- throw new Error();
58
- }
59
- catch {
60
- throw new Error('MQTT certificate is invalid, expired, or does not match this device private key');
61
- }
62
- }
63
- /**
64
- * Enroll once using the existing authenticated session, or reuse this profile's credentials.
65
- * Only the CSR leaves the device. The backend owns authorization and AWS policy attachment.
66
- */
67
- export async function enrollMqttDevice(options, env = process.env) {
68
- const { serverUrl, profilePath, userId, deviceId, accessToken } = options;
69
- if (!ID.test(userId) || !ID.test(deviceId) || !accessToken) {
70
- throw new Error('MQTT enrollment requires an authenticated device');
71
- }
72
- let backend;
73
- try {
74
- backend = new URL(serverUrl);
75
- }
76
- catch {
77
- throw new Error('MQTT enrollment requires a valid MCP_SERVER_URL');
78
- }
79
- const localHttp = backend.protocol === 'http:' && env.MQTT_ALLOW_INSECURE_LOCAL === 'true' &&
80
- ['localhost', 'mcp.localhost', 'mcp.localhost.localdomain', '127.0.0.1', '[::1]'].includes(backend.hostname);
81
- if ((backend.protocol !== 'https:' && !localHttp) || backend.username || backend.password ||
82
- backend.search || backend.hash || (backend.pathname && backend.pathname !== '/')) {
83
- throw new Error('MQTT enrollment requires HTTPS; explicit local testing may use a loopback HTTP backend');
84
- }
85
- options.assertCurrent?.();
86
- const folder = `${path.resolve(profilePath)}.mqtt`;
87
- await mkdir(folder, { recursive: true, mode: 0o700 });
88
- const identityFile = path.join(folder, 'identity.json');
89
- const certificateFile = path.join(folder, 'certificate.json');
90
- let identity = await readCache(identityFile);
91
- let certificate = await readCache(certificateFile);
92
- if (!identity) {
93
- if (certificate)
94
- throw new Error('MQTT certificate exists without its device private key');
95
- // Node generates RSA asynchronously; forge only encodes and signs the CSR below.
96
- const keys = await generateRsaKeyPair('rsa', {
97
- modulusLength: 2048,
98
- privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
99
- publicKeyEncoding: { type: 'spki', format: 'pem' },
100
- });
101
- identity = {
102
- backend_origin: backend.origin,
103
- user_id: userId,
104
- device_id: deviceId,
105
- private_key: keys.privateKey,
106
- };
107
- options.assertCurrent?.();
108
- await writePrivateCache(identityFile, identity);
109
- }
110
- // A profile switched to another account/backend cannot reuse its previous AWS identity.
111
- if (identity.backend_origin !== backend.origin || identity.user_id !== userId ||
112
- identity.device_id !== deviceId || typeof identity.private_key !== 'string') {
113
- throw new Error('MQTT credentials belong to a different backend, user, or device; use a separate profile');
114
- }
115
- let privateKey;
116
- try {
117
- const key = createPrivateKey(identity.private_key);
118
- if (key.asymmetricKeyType !== 'rsa' || key.asymmetricKeyDetails?.modulusLength !== 2048)
119
- throw new Error();
120
- privateKey = forge.pki.privateKeyFromPem(identity.private_key);
121
- }
122
- catch {
123
- throw new Error('MQTT device private key is invalid; inspect the profile MQTT folder before restarting');
124
- }
125
- if (!certificate) {
126
- const csr = forge.pki.createCertificationRequest();
127
- csr.publicKey = forge.pki.setRsaPublicKey(privateKey.n, privateKey.e);
128
- csr.setSubject([{ name: 'commonName', value: `dc-device-${deviceId}` }]);
129
- csr.sign(privateKey, forge.md.sha256.create());
130
- options.assertCurrent?.();
131
- try {
132
- // One bounded request: redirects are forbidden so the bearer token cannot follow another origin.
133
- const response = await fetch(new URL('/device/mqtt/enroll', backend), {
134
- method: 'POST',
135
- headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
136
- body: JSON.stringify({ device_id: deviceId, csr: forge.pki.certificationRequestToPem(csr) }),
137
- redirect: 'error',
138
- signal: AbortSignal.timeout(ENROLLMENT_TIMEOUT_MS),
139
- });
140
- if (!response.ok) {
141
- throw new Error(`MQTT enrollment was refused (HTTP ${response.status}); check backend configuration and device access, then restart`);
142
- }
143
- certificate = await response.json();
144
- }
145
- catch (error) {
146
- if (error.message?.startsWith('MQTT enrollment was refused'))
147
- throw error;
148
- throw new Error('MQTT enrollment request failed or timed out; check connectivity and restart the connector');
149
- }
150
- validateCertificate(certificate, identity.private_key);
151
- options.assertCurrent?.();
152
- // ponytail: a lost AWS response can orphan a certificate; pilot cleanup is manual, with no retries or renewal worker.
153
- await writePrivateCache(certificateFile, certificate);
154
- }
155
- validateCertificate(certificate, identity.private_key);
156
- options.assertCurrent?.();
157
- // Pass credentials to this connection only; another profile in the process must not inherit them via env.
158
- return readMqttConfig({ ...env, MQTT_BROKER_URL: certificate.broker_url }, {
159
- cert: certificate.certificate_pem,
160
- key: identity.private_key,
161
- });
162
- }
@@ -1,44 +0,0 @@
1
- import { type IClientOptions } from 'mqtt';
2
- /** The server publishes identifiers only; RemoteChannel fetches the durable command row. */
3
- export interface MqttDoorbell {
4
- call_id: string;
5
- user_id: string;
6
- device_id: string;
7
- expires_at: string;
8
- }
9
- export interface MqttConfig {
10
- url: string;
11
- options: IClientOptions;
12
- }
13
- /**
14
- * Read opt-in connector settings for RemoteChannel registration/restoration.
15
- * Return null for legacy installs; only explicit loopback development may bypass mutual TLS.
16
- */
17
- export declare function readMqttConfig(env?: NodeJS.ProcessEnv, credentials?: {
18
- cert: string;
19
- key: string;
20
- }): MqttConfig | null;
21
- /** Match the server publisher's exact device topic without granting wildcard subscriptions. */
22
- export declare function mqttDoorbellTopic(userId: string, deviceId: string): string;
23
- /** A per-device subscription; payload validation precedes all database access. */
24
- export declare class MqttDoorbellReceiver {
25
- private readonly config;
26
- private readonly userId;
27
- private readonly deviceId;
28
- private readonly onDoorbell;
29
- private readonly onReady;
30
- private client;
31
- private stopped;
32
- private ready;
33
- private cancelStart;
34
- private readonly topic;
35
- /** Bind verified registration identity and RemoteChannel's delivery/readiness callbacks once. */
36
- constructor(config: MqttConfig, userId: string, deviceId: string, onDoorbell: (payload: MqttDoorbell) => Promise<void>, onReady: (ready: boolean) => Promise<void>);
37
- /**
38
- * Connect once and resolve after QoS 1 SUBACK plus the readiness callback.
39
- * MQTT.js owns socket reconnects; this receiver owns resubscription and admission.
40
- */
41
- start(): Promise<void>;
42
- /** Stop reconnects, reject pending startup and withdraw readiness on sign-out/shutdown. */
43
- stop(): Promise<void>;
44
- }
@@ -1,197 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { connect } from 'mqtt';
3
- // Ids become literal topic segments; reject separators and MQTT wildcards.
4
- const ID = /^[A-Za-z0-9_-]{1,128}$/;
5
- const CONNECT_TIMEOUT_MS = 10000;
6
- /**
7
- * Read opt-in connector settings for RemoteChannel registration/restoration.
8
- * Return null for legacy installs; only explicit loopback development may bypass mutual TLS.
9
- */
10
- export function readMqttConfig(env = process.env, credentials) {
11
- if (env.MQTT_TRANSPORT_ENABLED !== 'true')
12
- return null;
13
- let url;
14
- try {
15
- url = new URL(env.MQTT_BROKER_URL || '');
16
- }
17
- catch {
18
- throw new Error('MQTT_BROKER_URL must be a valid MQTT URL');
19
- }
20
- if (url.username || url.password || url.search || url.hash || (url.pathname && url.pathname !== '/')) {
21
- throw new Error('MQTT_BROKER_URL must not contain credentials, paths, or query parameters');
22
- }
23
- // MQTT 3.1.1 matches the local broker and AWS pilot. Clean sessions avoid broker
24
- // backlog replay; each reconnect below must obtain a fresh SUBACK before admission.
25
- const options = {
26
- protocolVersion: 4,
27
- clean: true,
28
- keepalive: 30,
29
- connectTimeout: CONNECT_TIMEOUT_MS,
30
- // Spread reconnects between connector processes after a shared network outage.
31
- reconnectPeriod: 1000 + Math.floor(Math.random() * 1500),
32
- resubscribe: false,
33
- queueQoSZero: false,
34
- };
35
- if (url.protocol === 'mqtt:') {
36
- if (env.MQTT_ALLOW_INSECURE_LOCAL !== 'true' ||
37
- !['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) {
38
- throw new Error('Plain MQTT requires MQTT_ALLOW_INSECURE_LOCAL=true and a loopback broker');
39
- }
40
- }
41
- else if (url.protocol === 'mqtts:') {
42
- if (!credentials && (!env.MQTT_CERT_FILE || !env.MQTT_KEY_FILE)) {
43
- throw new Error('TLS MQTT requires MQTT_CERT_FILE and MQTT_KEY_FILE');
44
- }
45
- try {
46
- // Enrollment supplies the locally held key directly; manual file configuration remains valid.
47
- options.cert = credentials?.cert ?? readFileSync(env.MQTT_CERT_FILE);
48
- options.key = credentials?.key ?? readFileSync(env.MQTT_KEY_FILE);
49
- if (env.MQTT_CA_FILE)
50
- options.ca = readFileSync(env.MQTT_CA_FILE);
51
- }
52
- catch {
53
- throw new Error('Unable to read MQTT TLS files');
54
- }
55
- options.rejectUnauthorized = true;
56
- }
57
- else {
58
- throw new Error('MQTT_BROKER_URL must use mqtts:// or explicit loopback mqtt://');
59
- }
60
- return { url: url.toString(), options };
61
- }
62
- /** Match the server publisher's exact device topic without granting wildcard subscriptions. */
63
- export function mqttDoorbellTopic(userId, deviceId) {
64
- if (!ID.test(userId) || !ID.test(deviceId))
65
- throw new Error('Invalid MQTT device identity');
66
- return `dc/mqtt/v1/users/${userId}/devices/${deviceId}/new_call`;
67
- }
68
- /** A per-device subscription; payload validation precedes all database access. */
69
- export class MqttDoorbellReceiver {
70
- /** Bind verified registration identity and RemoteChannel's delivery/readiness callbacks once. */
71
- constructor(config, userId, deviceId, onDoorbell, onReady) {
72
- this.config = config;
73
- this.userId = userId;
74
- this.deviceId = deviceId;
75
- this.onDoorbell = onDoorbell;
76
- this.onReady = onReady;
77
- this.client = null;
78
- this.stopped = false;
79
- this.ready = false;
80
- this.cancelStart = null;
81
- this.topic = mqttDoorbellTopic(userId, deviceId);
82
- }
83
- /**
84
- * Connect once and resolve after QoS 1 SUBACK plus the readiness callback.
85
- * MQTT.js owns socket reconnects; this receiver owns resubscription and admission.
86
- */
87
- async start() {
88
- if (this.client || this.stopped)
89
- throw new Error('MQTT receiver already started or stopped');
90
- // Log only the hostname: credentials and raw broker errors must stay out of logs.
91
- console.log('[MQTT] Connecting to broker:', new URL(this.config.url).hostname);
92
- const client = connect(this.config.url, {
93
- ...this.config.options,
94
- // Stable identity also lets an AWS policy restrict this certificate's Connect permission.
95
- clientId: `dc-device-${this.deviceId}`,
96
- });
97
- this.client = client;
98
- await new Promise((resolve, reject) => {
99
- let settled = false;
100
- // Startup has several competing exits; settle once and always cancel its timer.
101
- const finish = (error) => {
102
- if (settled)
103
- return;
104
- settled = true;
105
- clearTimeout(timer);
106
- this.cancelStart = null;
107
- if (error)
108
- reject(error);
109
- else
110
- resolve();
111
- };
112
- // A connected socket without a granted subscription must not hang device startup.
113
- const timer = setTimeout(() => {
114
- finish(new Error('MQTT connection/subscription timed out'));
115
- void this.stop().catch(() => { });
116
- }, this.config.options.connectTimeout ?? CONNECT_TIMEOUT_MS);
117
- this.cancelStart = () => finish(new Error('MQTT receiver stopped'));
118
- client.on('connect', () => {
119
- if (this.stopped)
120
- return;
121
- // Run after every connection: a TCP connection alone cannot receive commands.
122
- client.subscribe(this.topic, { qos: 1 }, (error, granted) => {
123
- if (this.stopped || !client.connected)
124
- return;
125
- if (error || granted?.length !== 1 || granted[0].topic !== this.topic || granted[0].qos !== 1) {
126
- finish(new Error('MQTT device subscription refused'));
127
- void this.stop().catch(() => { });
128
- return;
129
- }
130
- // Reject downgraded/foreign grants above, then let RemoteChannel persist capability.
131
- // Recheck after that await so a stop/close cannot resolve stale startup as ready.
132
- this.ready = true;
133
- void this.onReady(true).then(() => {
134
- if (!this.stopped && this.ready) {
135
- // Report usable command delivery only after the broker grants the subscription.
136
- console.log('[MQTT] Connected and subscribed; ready for tool calls');
137
- finish();
138
- }
139
- }).catch(() => {
140
- finish(new Error('MQTT readiness update failed'));
141
- void this.stop().catch(() => { });
142
- });
143
- });
144
- });
145
- // Withdraw local admission immediately; RemoteChannel serializes the durable flag update.
146
- client.on('close', () => {
147
- if (this.ready && !this.stopped) {
148
- console.warn('[MQTT] Disconnected; waiting for reconnection');
149
- }
150
- this.ready = false;
151
- void this.onReady(false).catch(() => { });
152
- });
153
- // MQTT.js reconnects after network faults. Never print TLS/broker errors,
154
- // which can include certificate paths or broker-provided sensitive text.
155
- client.on('error', () => { });
156
- // Treat broker input as untrusted before RemoteChannel performs any database read.
157
- // Reject retained backlog and oversized data before parsing, then enforce exact identity.
158
- client.on('message', (topic, bytes, packet) => {
159
- if (this.stopped || !this.ready || topic !== this.topic || packet.retain || bytes.length > 1024)
160
- return;
161
- let payload;
162
- try {
163
- payload = JSON.parse(bytes.toString('utf8'));
164
- }
165
- catch {
166
- return;
167
- }
168
- if (!payload || typeof payload !== 'object' || Object.keys(payload).length !== 4 ||
169
- typeof payload.call_id !== 'string' || !ID.test(payload.call_id) ||
170
- payload.user_id !== this.userId || payload.device_id !== this.deviceId ||
171
- typeof payload.expires_at !== 'string')
172
- return;
173
- // Canonical UTC and a live deadline reject malformed/stale notifications; the row's
174
- // independently stored deadline is checked again after RemoteChannel fetches it.
175
- const expires = Date.parse(payload.expires_at);
176
- if (!Number.isFinite(expires) || new Date(expires).toISOString() !== payload.expires_at ||
177
- expires <= Date.now())
178
- return;
179
- // EventEmitter cannot await handlers. RemoteChannel owns bounded admission and
180
- // observes execution; a rejected callback must not kill the MQTT event loop.
181
- void this.onDoorbell(payload).catch(() => { });
182
- });
183
- });
184
- }
185
- /** Stop reconnects, reject pending startup and withdraw readiness on sign-out/shutdown. */
186
- async stop() {
187
- if (this.stopped)
188
- return;
189
- this.stopped = true;
190
- this.ready = false;
191
- this.cancelStart?.();
192
- // Force socket closure: teardown must not wait for broker acknowledgements.
193
- this.client?.end(true);
194
- this.client = null;
195
- await this.onReady(false);
196
- }
197
- }
@@ -1,29 +0,0 @@
1
- type TransportObservation = {
2
- stage: 'received';
3
- payload: any;
4
- deviceId: string | null;
5
- userId: string | undefined;
6
- } | {
7
- stage: string;
8
- callId: string;
9
- deviceId: string | null | undefined;
10
- operation?: string;
11
- operationId?: string;
12
- };
13
- /** Record a device transport checkpoint without affecting command handling. */
14
- export declare function observeTransport(input: TransportObservation): {
15
- observation_id: `${string}-${string}-${string}-${string}-${string}`;
16
- source_process_id: `${string}-${string}-${string}-${string}-${string}`;
17
- schema_version: number;
18
- timestamp_utc: string;
19
- monotonic_ms: number;
20
- operation_id?: string | undefined;
21
- operation?: string | undefined;
22
- call_id: string;
23
- device_id: string;
24
- transport: string;
25
- stage: string;
26
- notification_id: string;
27
- attempt_number: number;
28
- } | null;
29
- export {};
@@ -1,44 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { capture } from '../utils/capture.js';
3
- const ID = /^[A-Za-z0-9_-]{1,128}$/;
4
- const PROCESS_ID = randomUUID();
5
- /** Record a device transport checkpoint without affecting command handling. */
6
- export function observeTransport(input) {
7
- try {
8
- const timestamp_utc = new Date().toISOString();
9
- const monotonic_ms = performance.now();
10
- const receipt = 'payload' in input;
11
- const callId = receipt ? input.payload?.call_id : input.callId;
12
- const deviceId = input.deviceId;
13
- if (typeof callId !== 'string' || !ID.test(callId) ||
14
- typeof deviceId !== 'string' || !ID.test(deviceId))
15
- return null;
16
- if (receipt && (input.payload.device_id !== deviceId || !input.userId ||
17
- (input.payload.user_id !== undefined && input.payload.user_id !== input.userId)))
18
- return null;
19
- const observationId = randomUUID();
20
- const operationId = receipt ? undefined : input.operationId ??
21
- (input.stage === 'operation_start' ? observationId : undefined);
22
- const event = {
23
- call_id: callId,
24
- device_id: deviceId,
25
- transport: 'broadcast',
26
- stage: input.stage,
27
- notification_id: `${callId}:broadcast:1`,
28
- attempt_number: 1,
29
- ...(!receipt && input.operation ? { operation: input.operation } : {}),
30
- ...(operationId ? { operation_id: operationId } : {}),
31
- observation_id: observationId,
32
- source_process_id: PROCESS_ID,
33
- schema_version: 1,
34
- timestamp_utc,
35
- monotonic_ms,
36
- };
37
- void capture(input.stage, event);
38
- return event;
39
- }
40
- catch {
41
- // Telemetry must never affect command handling.
42
- return null;
43
- }
44
- }
@@ -1,32 +0,0 @@
1
- export interface SearchResult {
2
- file: string;
3
- line: number;
4
- match: string;
5
- }
6
- export declare function searchCode(options: {
7
- rootPath: string;
8
- pattern: string;
9
- filePattern?: string;
10
- ignoreCase?: boolean;
11
- maxResults?: number;
12
- includeHidden?: boolean;
13
- contextLines?: number;
14
- }): Promise<SearchResult[]>;
15
- export declare function searchCodeFallback(options: {
16
- rootPath: string;
17
- pattern: string;
18
- filePattern?: string;
19
- ignoreCase?: boolean;
20
- maxResults?: number;
21
- excludeDirs?: string[];
22
- contextLines?: number;
23
- }): Promise<SearchResult[]>;
24
- export declare function searchTextInFiles(options: {
25
- rootPath: string;
26
- pattern: string;
27
- filePattern?: string;
28
- ignoreCase?: boolean;
29
- maxResults?: number;
30
- includeHidden?: boolean;
31
- contextLines?: number;
32
- }): Promise<SearchResult[]>;