adhdev 0.7.2 → 0.7.6
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.
- package/dist/cli/index.js +270 -38
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +268 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -2310,6 +2310,10 @@ var init_extension_provider_instance = __esm({
|
|
|
2310
2310
|
// meta
|
|
2311
2311
|
instanceId;
|
|
2312
2312
|
ideType = "";
|
|
2313
|
+
chatId = null;
|
|
2314
|
+
chatTitle = null;
|
|
2315
|
+
agentName = "";
|
|
2316
|
+
extensionId = "";
|
|
2313
2317
|
constructor(provider) {
|
|
2314
2318
|
this.type = provider.type;
|
|
2315
2319
|
this.provider = provider;
|
|
@@ -2336,8 +2340,8 @@ var init_extension_provider_instance = __esm({
|
|
|
2336
2340
|
category: "extension",
|
|
2337
2341
|
status: this.currentStatus,
|
|
2338
2342
|
activeChat: this.messages.length > 0 ? {
|
|
2339
|
-
id:
|
|
2340
|
-
title: this.provider.name,
|
|
2343
|
+
id: this.chatId || this.instanceId,
|
|
2344
|
+
title: this.chatTitle || this.agentName || this.provider.name,
|
|
2341
2345
|
status: this.currentStatus,
|
|
2342
2346
|
messages: this.messages,
|
|
2343
2347
|
activeModal: this.activeModal,
|
|
@@ -2359,6 +2363,10 @@ var init_extension_provider_instance = __esm({
|
|
|
2359
2363
|
if (data?.activeModal !== void 0) this.activeModal = data.activeModal;
|
|
2360
2364
|
if (data?.model) this.currentModel = data.model;
|
|
2361
2365
|
if (data?.mode) this.currentMode = data.mode;
|
|
2366
|
+
if (typeof data?.sessionId === "string" && data.sessionId.trim()) this.chatId = data.sessionId;
|
|
2367
|
+
if (typeof data?.title === "string" && data.title.trim()) this.chatTitle = data.title;
|
|
2368
|
+
if (typeof data?.agentName === "string" && data.agentName.trim()) this.agentName = data.agentName;
|
|
2369
|
+
if (typeof data?.extensionId === "string" && data.extensionId.trim()) this.extensionId = data.extensionId;
|
|
2362
2370
|
if (data?.status) {
|
|
2363
2371
|
const newStatus = data.status;
|
|
2364
2372
|
this.detectTransition(newStatus, data);
|
|
@@ -2378,11 +2386,6 @@ var init_extension_provider_instance = __esm({
|
|
|
2378
2386
|
return this.instanceId;
|
|
2379
2387
|
}
|
|
2380
2388
|
// ─── status transition detect ──────────────────────────────
|
|
2381
|
-
// NOTE: Extension transitions are TRACKED but NOT emitted as events.
|
|
2382
|
-
// The parent IdeProviderInstance already emits identical events
|
|
2383
|
-
// (generating_started, generating_completed, waiting_approval)
|
|
2384
|
-
// via its own detectAgentTransitions(). Emitting here would cause
|
|
2385
|
-
// duplicate toasts with slightly different content.
|
|
2386
2389
|
detectTransition(newStatus, data) {
|
|
2387
2390
|
const now = Date.now();
|
|
2388
2391
|
const agentStatus = newStatus === "streaming" || newStatus === "generating" ? "generating" : newStatus === "waiting_approval" ? "waiting_approval" : "idle";
|
|
@@ -2391,7 +2394,40 @@ var init_extension_provider_instance = __esm({
|
|
|
2391
2394
|
if (agentStatus !== this.lastAgentStatus) {
|
|
2392
2395
|
if (this.lastAgentStatus === "idle" && agentStatus === "generating") {
|
|
2393
2396
|
this.generatingStartedAt = now;
|
|
2397
|
+
this.pushEvent({
|
|
2398
|
+
event: "agent:generating_started",
|
|
2399
|
+
chatTitle: this.resolveChatTitle(data),
|
|
2400
|
+
timestamp: now,
|
|
2401
|
+
ideType: this.ideType || this.type,
|
|
2402
|
+
agentType: this.type,
|
|
2403
|
+
agentName: this.agentName || this.provider.name,
|
|
2404
|
+
extensionId: this.extensionId || this.type
|
|
2405
|
+
});
|
|
2406
|
+
} else if (agentStatus === "waiting_approval") {
|
|
2407
|
+
if (!this.generatingStartedAt) this.generatingStartedAt = now;
|
|
2408
|
+
this.pushEvent({
|
|
2409
|
+
event: "agent:waiting_approval",
|
|
2410
|
+
chatTitle: this.resolveChatTitle(data),
|
|
2411
|
+
timestamp: now,
|
|
2412
|
+
ideType: this.ideType || this.type,
|
|
2413
|
+
agentType: this.type,
|
|
2414
|
+
agentName: this.agentName || this.provider.name,
|
|
2415
|
+
extensionId: this.extensionId || this.type,
|
|
2416
|
+
modalMessage: data?.activeModal?.message,
|
|
2417
|
+
modalButtons: data?.activeModal?.buttons
|
|
2418
|
+
});
|
|
2394
2419
|
} else if (agentStatus === "idle" && (this.lastAgentStatus === "generating" || this.lastAgentStatus === "waiting_approval")) {
|
|
2420
|
+
const duration3 = this.generatingStartedAt ? Math.round((now - this.generatingStartedAt) / 1e3) : 0;
|
|
2421
|
+
this.pushEvent({
|
|
2422
|
+
event: "agent:generating_completed",
|
|
2423
|
+
chatTitle: this.resolveChatTitle(data),
|
|
2424
|
+
duration: duration3,
|
|
2425
|
+
timestamp: now,
|
|
2426
|
+
ideType: this.ideType || this.type,
|
|
2427
|
+
agentType: this.type,
|
|
2428
|
+
agentName: this.agentName || this.provider.name,
|
|
2429
|
+
extensionId: this.extensionId || this.type
|
|
2430
|
+
});
|
|
2395
2431
|
this.generatingStartedAt = 0;
|
|
2396
2432
|
}
|
|
2397
2433
|
this.lastAgentStatus = agentStatus;
|
|
@@ -2411,6 +2447,10 @@ var init_extension_provider_instance = __esm({
|
|
|
2411
2447
|
this.events = [];
|
|
2412
2448
|
return events;
|
|
2413
2449
|
}
|
|
2450
|
+
resolveChatTitle(data) {
|
|
2451
|
+
const title = typeof data?.title === "string" && data.title.trim() ? data.title.trim() : this.chatTitle;
|
|
2452
|
+
return title || this.agentName || this.provider.name;
|
|
2453
|
+
}
|
|
2414
2454
|
};
|
|
2415
2455
|
}
|
|
2416
2456
|
});
|
|
@@ -3169,7 +3209,7 @@ var init_scanner = __esm({
|
|
|
3169
3209
|
if (!manager) return;
|
|
3170
3210
|
registerExtensionProviders(this.ctx.providerLoader, manager, ide);
|
|
3171
3211
|
this.ctx.cdpManagers.set(ide, manager);
|
|
3172
|
-
LOG.info("
|
|
3212
|
+
LOG.info("IDE", `Attached: ${ide} (port ${port})`);
|
|
3173
3213
|
await setupIdeInstance(this.ctx, { ideType: ide, manager });
|
|
3174
3214
|
this.opts.onConnected?.(ide, ide, manager);
|
|
3175
3215
|
}
|
|
@@ -3202,7 +3242,7 @@ var init_scanner = __esm({
|
|
|
3202
3242
|
);
|
|
3203
3243
|
if (!manager) continue;
|
|
3204
3244
|
this.ctx.cdpManagers.set(managerKey, manager);
|
|
3205
|
-
LOG.info("
|
|
3245
|
+
LOG.info("IDE", `Attached window: ${managerKey} (port ${port}, page "${target.title}")`);
|
|
3206
3246
|
await setupIdeInstance(this.ctx, {
|
|
3207
3247
|
ideType: ide,
|
|
3208
3248
|
manager,
|
|
@@ -3256,9 +3296,9 @@ var init_initializer = __esm({
|
|
|
3256
3296
|
await this.connectIdePort(port, ide);
|
|
3257
3297
|
}
|
|
3258
3298
|
if (cdpManagers.size > 0) {
|
|
3259
|
-
LOG.info("
|
|
3299
|
+
LOG.info("IDE", `${cdpManagers.size} IDE window(s) attached: ${[...cdpManagers.entries()].map(([k, m]) => `${k}:${m.getPort()}`).join(", ")}`);
|
|
3260
3300
|
} else {
|
|
3261
|
-
LOG.warn("
|
|
3301
|
+
LOG.warn("IDE", `No IDE windows attached \u2014 tried: ${filtered.map((p) => `${p.ide}:${p.port}`).join(", ")}`);
|
|
3262
3302
|
}
|
|
3263
3303
|
}
|
|
3264
3304
|
// ─── Per-port connection (multi-window aware) ───
|
|
@@ -3284,7 +3324,7 @@ var init_initializer = __esm({
|
|
|
3284
3324
|
if (connected) {
|
|
3285
3325
|
registerExtensionProviders(providerLoader, manager, ide);
|
|
3286
3326
|
cdpManagers.set(ide, manager);
|
|
3287
|
-
LOG.info("
|
|
3327
|
+
LOG.info("IDE", `Attached: ${ide} (port ${port})`);
|
|
3288
3328
|
await this.config.onConnected?.(ide, manager, ide);
|
|
3289
3329
|
}
|
|
3290
3330
|
return;
|
|
@@ -3317,7 +3357,7 @@ var init_initializer = __esm({
|
|
|
3317
3357
|
if (connected) {
|
|
3318
3358
|
registerExtensionProviders(providerLoader, manager, ide);
|
|
3319
3359
|
cdpManagers.set(managerKey, manager);
|
|
3320
|
-
LOG.info("
|
|
3360
|
+
LOG.info("IDE", `Attached window: ${managerKey} (port ${port}${targets.length > 1 ? `, page "${target.title}"` : ""})`);
|
|
3321
3361
|
await this.config.onConnected?.(ide, manager, managerKey);
|
|
3322
3362
|
}
|
|
3323
3363
|
}
|
|
@@ -3346,7 +3386,7 @@ var init_initializer = __esm({
|
|
|
3346
3386
|
} catch {
|
|
3347
3387
|
}
|
|
3348
3388
|
this.config.cdpManagers.delete(key);
|
|
3349
|
-
LOG.info("
|
|
3389
|
+
LOG.info("IDE", `Detached window: ${key} (${reason})`);
|
|
3350
3390
|
await this.config.onDisconnected?.(ide, manager, key, reason);
|
|
3351
3391
|
}
|
|
3352
3392
|
}
|
|
@@ -4764,7 +4804,6 @@ function handleSetProviderSetting(h, args) {
|
|
|
4764
4804
|
}
|
|
4765
4805
|
async function handleExtensionScript(h, args, scriptName) {
|
|
4766
4806
|
const { agentType, ideType } = args || {};
|
|
4767
|
-
LOG.info("Command", `[ExtScript] ${scriptName} agentType=${agentType} ideType=${ideType} session=${h.currentSession?.sessionId || ""}`);
|
|
4768
4807
|
if (!agentType) return { success: false, error: "agentType is required" };
|
|
4769
4808
|
const loader = h.ctx.providerLoader;
|
|
4770
4809
|
if (!loader) return { success: false, error: "ProviderLoader not initialized" };
|
|
@@ -4990,7 +5029,75 @@ var init_workspace_commands = __esm({
|
|
|
4990
5029
|
});
|
|
4991
5030
|
|
|
4992
5031
|
// ../../oss/packages/daemon-core/src/commands/handler.ts
|
|
4993
|
-
|
|
5032
|
+
function logAtLevel(level, category, message) {
|
|
5033
|
+
switch (level) {
|
|
5034
|
+
case "debug":
|
|
5035
|
+
LOG.debug(category, message);
|
|
5036
|
+
return;
|
|
5037
|
+
case "warn":
|
|
5038
|
+
LOG.warn(category, message);
|
|
5039
|
+
return;
|
|
5040
|
+
case "error":
|
|
5041
|
+
LOG.error(category, message);
|
|
5042
|
+
return;
|
|
5043
|
+
default:
|
|
5044
|
+
LOG.info(category, message);
|
|
5045
|
+
}
|
|
5046
|
+
}
|
|
5047
|
+
function getCommandLogLevel(cmd) {
|
|
5048
|
+
return COMMAND_DEBUG_LEVELS.has(cmd) ? "debug" : "info";
|
|
5049
|
+
}
|
|
5050
|
+
function summarizeLogValue(value) {
|
|
5051
|
+
if (value === null) return "null";
|
|
5052
|
+
if (value === void 0) return "undefined";
|
|
5053
|
+
if (typeof value === "string") {
|
|
5054
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
5055
|
+
if (!normalized) return '""';
|
|
5056
|
+
if (normalized.length <= 80) return JSON.stringify(normalized);
|
|
5057
|
+
return `${JSON.stringify(normalized.slice(0, 80))}\u2026(${normalized.length} chars)`;
|
|
5058
|
+
}
|
|
5059
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
5060
|
+
if (Array.isArray(value)) return `[${value.length} items]`;
|
|
5061
|
+
if (typeof value === "object") return "{...}";
|
|
5062
|
+
return String(value);
|
|
5063
|
+
}
|
|
5064
|
+
function summarizeCommandArgs(args) {
|
|
5065
|
+
if (!args || typeof args !== "object") return "-";
|
|
5066
|
+
const preferredKeys = [
|
|
5067
|
+
"targetSessionId",
|
|
5068
|
+
"providerType",
|
|
5069
|
+
"agentType",
|
|
5070
|
+
"ideType",
|
|
5071
|
+
"model",
|
|
5072
|
+
"mode",
|
|
5073
|
+
"action",
|
|
5074
|
+
"button",
|
|
5075
|
+
"key",
|
|
5076
|
+
"force",
|
|
5077
|
+
"offset",
|
|
5078
|
+
"limit",
|
|
5079
|
+
"cols",
|
|
5080
|
+
"rows",
|
|
5081
|
+
"path",
|
|
5082
|
+
"command",
|
|
5083
|
+
"commandId",
|
|
5084
|
+
"workspace",
|
|
5085
|
+
"dir",
|
|
5086
|
+
"url",
|
|
5087
|
+
"text",
|
|
5088
|
+
"message",
|
|
5089
|
+
"data",
|
|
5090
|
+
"value"
|
|
5091
|
+
];
|
|
5092
|
+
const entries = [];
|
|
5093
|
+
for (const key of preferredKeys) {
|
|
5094
|
+
if (!(key in args) || args[key] === void 0) continue;
|
|
5095
|
+
const value = key === "text" || key === "message" ? `${String(args[key] || "").length} chars` : key === "data" ? `${String(args[key] || "").length} chars` : summarizeLogValue(args[key]);
|
|
5096
|
+
entries.push(`${key}=${value}`);
|
|
5097
|
+
}
|
|
5098
|
+
return entries.length ? entries.join(" ") : "{...}";
|
|
5099
|
+
}
|
|
5100
|
+
var COMMAND_DEBUG_LEVELS, DaemonCommandHandler;
|
|
4994
5101
|
var init_handler = __esm({
|
|
4995
5102
|
"../../oss/packages/daemon-core/src/commands/handler.ts"() {
|
|
4996
5103
|
"use strict";
|
|
@@ -5005,6 +5112,15 @@ var init_handler = __esm({
|
|
|
5005
5112
|
init_workspace_commands();
|
|
5006
5113
|
init_workspaces();
|
|
5007
5114
|
init_workspace_activity();
|
|
5115
|
+
COMMAND_DEBUG_LEVELS = /* @__PURE__ */ new Set([
|
|
5116
|
+
"pty_input",
|
|
5117
|
+
"pty_resize",
|
|
5118
|
+
"cdp_eval",
|
|
5119
|
+
"cdp_batch",
|
|
5120
|
+
"cdp_dom_query",
|
|
5121
|
+
"cdp_dom_dump",
|
|
5122
|
+
"cdp_dom_debug"
|
|
5123
|
+
]);
|
|
5008
5124
|
DaemonCommandHandler = class {
|
|
5009
5125
|
_ctx;
|
|
5010
5126
|
_agentStream = null;
|
|
@@ -5152,23 +5268,54 @@ var init_handler = __esm({
|
|
|
5152
5268
|
}
|
|
5153
5269
|
return void 0;
|
|
5154
5270
|
}
|
|
5271
|
+
logCommandStart(cmd, args) {
|
|
5272
|
+
const routeBits = [
|
|
5273
|
+
this._currentRoute.session?.sessionId ? `session=${this._currentRoute.session.sessionId}` : "",
|
|
5274
|
+
this._currentRoute.managerKey ? `manager=${this._currentRoute.managerKey}` : "",
|
|
5275
|
+
this._currentRoute.providerType ? `provider=${this._currentRoute.providerType}` : ""
|
|
5276
|
+
].filter(Boolean).join(" ");
|
|
5277
|
+
const summary = summarizeCommandArgs(args);
|
|
5278
|
+
logAtLevel(
|
|
5279
|
+
getCommandLogLevel(cmd),
|
|
5280
|
+
"Command",
|
|
5281
|
+
`[${cmd}] start${routeBits ? ` ${routeBits}` : ""} args=${summary}`
|
|
5282
|
+
);
|
|
5283
|
+
}
|
|
5284
|
+
logCommandEnd(cmd, result, startedAt) {
|
|
5285
|
+
const durationMs = Date.now() - startedAt;
|
|
5286
|
+
const parts = [`[${cmd}] end`, `success=${result.success}`, `duration=${durationMs}ms`];
|
|
5287
|
+
if (typeof result.error === "string" && result.error) {
|
|
5288
|
+
parts.push(`error=${JSON.stringify(result.error)}`);
|
|
5289
|
+
}
|
|
5290
|
+
const level = result.success ? getCommandLogLevel(cmd) : "warn";
|
|
5291
|
+
logAtLevel(level, "Command", parts.join(" "));
|
|
5292
|
+
}
|
|
5155
5293
|
setAgentStreamManager(manager) {
|
|
5156
5294
|
this._agentStream = manager;
|
|
5157
5295
|
}
|
|
5158
5296
|
// ─── Command Dispatcher ──────────────────────────
|
|
5159
5297
|
async handle(cmd, args) {
|
|
5160
5298
|
this._currentRoute = this.resolveRoute(args);
|
|
5299
|
+
const startedAt = Date.now();
|
|
5300
|
+
this.logCommandStart(cmd, args);
|
|
5301
|
+
let result;
|
|
5161
5302
|
if (!this._currentRoute.session && !this._currentRoute.managerKey && !this._currentRoute.providerType) {
|
|
5162
5303
|
const cdpCommands = ["send_chat", "read_chat", "list_chats", "new_chat", "switch_chat", "set_mode", "change_model", "set_thought_level", "resolve_action"];
|
|
5163
5304
|
if (cdpCommands.includes(cmd)) {
|
|
5164
|
-
|
|
5305
|
+
result = { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
|
|
5306
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
5307
|
+
return result;
|
|
5165
5308
|
}
|
|
5166
5309
|
}
|
|
5167
5310
|
try {
|
|
5168
|
-
|
|
5311
|
+
result = await this.dispatch(cmd, args);
|
|
5312
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
5313
|
+
return result;
|
|
5169
5314
|
} catch (e) {
|
|
5170
5315
|
LOG.error("Command", `[${cmd}] Unhandled error: ${e?.message || e}`);
|
|
5171
|
-
|
|
5316
|
+
result = { success: false, error: `Internal error: ${e?.message || "unknown"}` };
|
|
5317
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
5318
|
+
return result;
|
|
5172
5319
|
}
|
|
5173
5320
|
}
|
|
5174
5321
|
async dispatch(cmd, args) {
|
|
@@ -37898,7 +38045,13 @@ function forwardAgentStreamsToIdeInstance(instanceManager, ideType, streams) {
|
|
|
37898
38045
|
status: stream.status || "idle",
|
|
37899
38046
|
activeModal: stream.activeModal || null,
|
|
37900
38047
|
model: stream.model || void 0,
|
|
37901
|
-
mode: stream.mode || void 0
|
|
38048
|
+
mode: stream.mode || void 0,
|
|
38049
|
+
sessionId: stream.sessionId || stream.instanceId || void 0,
|
|
38050
|
+
title: stream.title || stream.agentName || void 0,
|
|
38051
|
+
agentType: stream.agentType || void 0,
|
|
38052
|
+
agentName: stream.agentName || void 0,
|
|
38053
|
+
extensionId: stream.extensionId || void 0,
|
|
38054
|
+
inputContent: stream.inputContent || ""
|
|
37902
38055
|
});
|
|
37903
38056
|
}
|
|
37904
38057
|
}
|
|
@@ -37971,14 +38124,13 @@ var init_provider_instance_manager = __esm({
|
|
|
37971
38124
|
try {
|
|
37972
38125
|
const state = instance.getState();
|
|
37973
38126
|
states.push(state);
|
|
37974
|
-
|
|
37975
|
-
|
|
37976
|
-
|
|
37977
|
-
|
|
37978
|
-
|
|
37979
|
-
|
|
37980
|
-
|
|
37981
|
-
providerCategory: state.category
|
|
38127
|
+
this.emitPendingEvents(instance.type, state);
|
|
38128
|
+
if (state.category === "ide") {
|
|
38129
|
+
for (const childState of state.extensions) {
|
|
38130
|
+
this.emitPendingEvents(childState.type, childState, {
|
|
38131
|
+
targetSessionId: childState.instanceId,
|
|
38132
|
+
workspaceName: state.workspace || void 0,
|
|
38133
|
+
parentSessionId: state.instanceId
|
|
37982
38134
|
});
|
|
37983
38135
|
}
|
|
37984
38136
|
}
|
|
@@ -38027,6 +38179,21 @@ var init_provider_instance_manager = __esm({
|
|
|
38027
38179
|
onEvent(listener) {
|
|
38028
38180
|
this.eventListeners.push(listener);
|
|
38029
38181
|
}
|
|
38182
|
+
emitPendingEvents(providerType, state, extra = {}) {
|
|
38183
|
+
for (const event of state.pendingEvents) {
|
|
38184
|
+
for (const listener of this.eventListeners) {
|
|
38185
|
+
listener({
|
|
38186
|
+
...event,
|
|
38187
|
+
providerType,
|
|
38188
|
+
instanceId: state.instanceId,
|
|
38189
|
+
targetSessionId: state.instanceId,
|
|
38190
|
+
providerCategory: state.category,
|
|
38191
|
+
workspaceName: state.workspace || void 0,
|
|
38192
|
+
...extra
|
|
38193
|
+
});
|
|
38194
|
+
}
|
|
38195
|
+
}
|
|
38196
|
+
}
|
|
38030
38197
|
/**
|
|
38031
38198
|
* Forward event to specific Instance
|
|
38032
38199
|
*/
|
|
@@ -41943,7 +42110,7 @@ async function initDaemonComponents(config2) {
|
|
|
41943
42110
|
const ideInstance = instanceManager.getInstance(instanceKey);
|
|
41944
42111
|
if (ideInstance) {
|
|
41945
42112
|
instanceManager.removeInstance(instanceKey);
|
|
41946
|
-
LOG.info("
|
|
42113
|
+
LOG.info("IDE", `Instance removed after detach: ${instanceKey}`);
|
|
41947
42114
|
}
|
|
41948
42115
|
if (ideInstance?.getInstanceId) {
|
|
41949
42116
|
agentStreamManager?.resetParentSession(ideInstance.getInstanceId());
|
|
@@ -42459,6 +42626,40 @@ var init_server_connection = __esm({
|
|
|
42459
42626
|
});
|
|
42460
42627
|
|
|
42461
42628
|
// src/daemon-p2p.ts
|
|
42629
|
+
function normalizeSharePermission(permission) {
|
|
42630
|
+
if (!permission) return void 0;
|
|
42631
|
+
if (permission === "view") return "remote_view";
|
|
42632
|
+
if (permission === "control") return "remote_control";
|
|
42633
|
+
if (permission === "full") return "remote_full";
|
|
42634
|
+
return permission;
|
|
42635
|
+
}
|
|
42636
|
+
function canPeerStartScreenshots(permission) {
|
|
42637
|
+
if (!permission) return true;
|
|
42638
|
+
return permission === "remote_view" || permission === "remote_control" || permission === "remote_full";
|
|
42639
|
+
}
|
|
42640
|
+
function canPeerSendMessages(permission) {
|
|
42641
|
+
if (!permission) return true;
|
|
42642
|
+
return permission === "chat_control" || permission === "remote_control" || permission === "remote_full";
|
|
42643
|
+
}
|
|
42644
|
+
function canPeerUseRemoteInput(permission) {
|
|
42645
|
+
if (!permission) return true;
|
|
42646
|
+
return permission === "remote_full";
|
|
42647
|
+
}
|
|
42648
|
+
function canPeerUsePrivilegedShareCommand(commandType, permission) {
|
|
42649
|
+
if (!permission) return true;
|
|
42650
|
+
switch (commandType) {
|
|
42651
|
+
case "read_chat":
|
|
42652
|
+
case "list_chats":
|
|
42653
|
+
return true;
|
|
42654
|
+
case "send_chat":
|
|
42655
|
+
case "new_chat":
|
|
42656
|
+
case "switch_chat":
|
|
42657
|
+
case "resolve_action":
|
|
42658
|
+
return canPeerSendMessages(permission);
|
|
42659
|
+
default:
|
|
42660
|
+
return false;
|
|
42661
|
+
}
|
|
42662
|
+
}
|
|
42462
42663
|
var fs11, path13, os16, import_node_module, esmRequire, logFile, log, logDebug, DaemonP2PSender;
|
|
42463
42664
|
var init_daemon_p2p = __esm({
|
|
42464
42665
|
"src/daemon-p2p.ts"() {
|
|
@@ -42671,7 +42872,7 @@ ${e?.stack || ""}`);
|
|
|
42671
42872
|
}
|
|
42672
42873
|
}
|
|
42673
42874
|
/** P2P connect Start */
|
|
42674
|
-
async initiateconnection(peerId) {
|
|
42875
|
+
async initiateconnection(peerId, sharePermission) {
|
|
42675
42876
|
if (!this.nodeDatachannel) {
|
|
42676
42877
|
log("Cannot initiate \u2014 node-datachannel not available");
|
|
42677
42878
|
return;
|
|
@@ -42764,6 +42965,7 @@ ${e?.stack || ""}`);
|
|
|
42764
42965
|
pc,
|
|
42765
42966
|
dataChannel: null,
|
|
42766
42967
|
state: "connecting",
|
|
42968
|
+
sharePermission: normalizeSharePermission(sharePermission),
|
|
42767
42969
|
screenshotActive: false,
|
|
42768
42970
|
connectedAt: Date.now(),
|
|
42769
42971
|
pendingCandidates: [],
|
|
@@ -42885,10 +43087,15 @@ ${e?.stack || ""}`);
|
|
|
42885
43087
|
}
|
|
42886
43088
|
if (parsed.type === "screenshot_start") {
|
|
42887
43089
|
const peer = this.peers.get(peerId);
|
|
43090
|
+
const permission = peer?.sharePermission;
|
|
42888
43091
|
if (!parsed.ideType) {
|
|
42889
43092
|
log(`screenshot_start: REJECTED \u2014 no ideType from peer ${peerId}`);
|
|
42890
43093
|
return;
|
|
42891
43094
|
}
|
|
43095
|
+
if (!canPeerStartScreenshots(permission)) {
|
|
43096
|
+
log(`screenshot_start: REJECTED \u2014 permission=${permission || "trusted"} peer=${peerId}`);
|
|
43097
|
+
return;
|
|
43098
|
+
}
|
|
42892
43099
|
if (peer) {
|
|
42893
43100
|
peer.screenshotActive = true;
|
|
42894
43101
|
peer.screenshotIdeType = parsed.ideType;
|
|
@@ -42917,23 +43124,27 @@ ${e?.stack || ""}`);
|
|
|
42917
43124
|
return;
|
|
42918
43125
|
}
|
|
42919
43126
|
if (parsed.type === "pty_input") {
|
|
43127
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
43128
|
+
if (permission) {
|
|
43129
|
+
log(`pty_input: REJECTED \u2014 permission=${permission} peer=${peerId}`);
|
|
43130
|
+
return;
|
|
43131
|
+
}
|
|
42920
43132
|
if (this.ptyInputHandler && parsed.data) {
|
|
42921
43133
|
this.ptyInputHandler(parsed.cliType || "", parsed.data);
|
|
42922
43134
|
}
|
|
42923
43135
|
return;
|
|
42924
43136
|
}
|
|
42925
43137
|
if (parsed.type === "pty_resize") {
|
|
43138
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
43139
|
+
if (permission) {
|
|
43140
|
+
log(`pty_resize: REJECTED \u2014 permission=${permission} peer=${peerId}`);
|
|
43141
|
+
return;
|
|
43142
|
+
}
|
|
42926
43143
|
if (this.ptyResizeHandler && parsed.cols && parsed.rows) {
|
|
42927
43144
|
this.ptyResizeHandler(parsed.cliType || "", parsed.cols, parsed.rows);
|
|
42928
43145
|
}
|
|
42929
43146
|
return;
|
|
42930
43147
|
}
|
|
42931
|
-
if (parsed.type === "chat_history") {
|
|
42932
|
-
const { agent, offset, limit, id, instanceId } = parsed;
|
|
42933
|
-
const result = readChatHistory(agent || "", offset || 0, limit || 30, instanceId);
|
|
42934
|
-
this.sendToPeer(peerId, { type: "chat_history_result", id, ...result, agent });
|
|
42935
|
-
return;
|
|
42936
|
-
}
|
|
42937
43148
|
this.handleFileRequest(peerId, parsed);
|
|
42938
43149
|
} catch (e) {
|
|
42939
43150
|
log(`Parse error from peer ${peerId}: ${e?.message}`);
|
|
@@ -43052,6 +43263,11 @@ ${e?.stack || ""}`);
|
|
|
43052
43263
|
// ─── P2P command/input/file handling ────────────────
|
|
43053
43264
|
async handleP2PCommand(peerId, msg) {
|
|
43054
43265
|
const { id, commandType, data } = msg;
|
|
43266
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
43267
|
+
if (!canPeerUsePrivilegedShareCommand(commandType, permission)) {
|
|
43268
|
+
this.sendToPeer(peerId, { type: "command_result", id, success: false, error: "Permission denied" });
|
|
43269
|
+
return;
|
|
43270
|
+
}
|
|
43055
43271
|
if (!this.commandHandler) {
|
|
43056
43272
|
this.sendToPeer(peerId, { type: "command_result", id, success: false, error: "No handler" });
|
|
43057
43273
|
return;
|
|
@@ -43065,6 +43281,11 @@ ${e?.stack || ""}`);
|
|
|
43065
43281
|
}
|
|
43066
43282
|
async handleInputEvent(peerId, msg) {
|
|
43067
43283
|
const { id, action, params, instanceId } = msg;
|
|
43284
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
43285
|
+
if (!canPeerUseRemoteInput(permission)) {
|
|
43286
|
+
this.sendToPeer(peerId, { id, type: "response", success: false, error: "Permission denied" });
|
|
43287
|
+
return;
|
|
43288
|
+
}
|
|
43068
43289
|
if (!this.inputHandler) {
|
|
43069
43290
|
this.sendToPeer(peerId, { id, type: "response", success: false, error: "No input handler" });
|
|
43070
43291
|
return;
|
|
@@ -43082,6 +43303,11 @@ ${e?.stack || ""}`);
|
|
|
43082
43303
|
}
|
|
43083
43304
|
}
|
|
43084
43305
|
async handleFileRequest(peerId, req) {
|
|
43306
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
43307
|
+
if (permission) {
|
|
43308
|
+
this.sendToPeer(peerId, { id: req.id, success: false, error: "Permission denied" });
|
|
43309
|
+
return;
|
|
43310
|
+
}
|
|
43085
43311
|
let response;
|
|
43086
43312
|
if (this.fileRequestHandler) {
|
|
43087
43313
|
try {
|
|
@@ -43107,7 +43333,7 @@ ${e?.stack || ""}`);
|
|
|
43107
43333
|
const peerId = payload?.peerId;
|
|
43108
43334
|
if (type === "p2p_ready") {
|
|
43109
43335
|
log(`p2p_ready from peer ${peerId}`);
|
|
43110
|
-
this.initiateconnection(peerId);
|
|
43336
|
+
this.initiateconnection(peerId, payload?.sharePermission);
|
|
43111
43337
|
return;
|
|
43112
43338
|
}
|
|
43113
43339
|
if (type === "p2p_answer") {
|
|
@@ -43120,6 +43346,9 @@ ${e?.stack || ""}`);
|
|
|
43120
43346
|
log(`p2p_answer for unknown peer ${peerId} \u2014 ignoring`);
|
|
43121
43347
|
return;
|
|
43122
43348
|
}
|
|
43349
|
+
if (payload?.sharePermission) {
|
|
43350
|
+
peer.sharePermission = normalizeSharePermission(payload.sharePermission);
|
|
43351
|
+
}
|
|
43123
43352
|
if (peer.remoteDescriptionSet) {
|
|
43124
43353
|
log(`p2p_answer ignored: already applied for peer ${peerId} (duplicate relay)`);
|
|
43125
43354
|
return;
|
|
@@ -43156,6 +43385,9 @@ ${e?.stack || ""}`);
|
|
|
43156
43385
|
}
|
|
43157
43386
|
const peer = this.peers.get(peerId);
|
|
43158
43387
|
if (peer?.pc && payload.candidate) {
|
|
43388
|
+
if (payload?.sharePermission) {
|
|
43389
|
+
peer.sharePermission = normalizeSharePermission(payload.sharePermission);
|
|
43390
|
+
}
|
|
43159
43391
|
log(`p2p_ice received from peer ${peerId}: ${String(payload.candidate).substring(0, 80)}`);
|
|
43160
43392
|
if (!peer.remoteDescriptionSet) {
|
|
43161
43393
|
peer.pendingCandidates.push({
|
|
@@ -43495,7 +43727,7 @@ var init_adhdev_daemon = __esm({
|
|
|
43495
43727
|
fs12 = __toESM(require("fs"));
|
|
43496
43728
|
path14 = __toESM(require("path"));
|
|
43497
43729
|
import_chalk2 = __toESM(require("chalk"));
|
|
43498
|
-
pkgVersion = "0.7.
|
|
43730
|
+
pkgVersion = "0.7.6";
|
|
43499
43731
|
if (pkgVersion === "unknown") {
|
|
43500
43732
|
try {
|
|
43501
43733
|
const possiblePaths = [
|