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/index.js
CHANGED
|
@@ -2303,6 +2303,10 @@ var init_extension_provider_instance = __esm({
|
|
|
2303
2303
|
// meta
|
|
2304
2304
|
instanceId;
|
|
2305
2305
|
ideType = "";
|
|
2306
|
+
chatId = null;
|
|
2307
|
+
chatTitle = null;
|
|
2308
|
+
agentName = "";
|
|
2309
|
+
extensionId = "";
|
|
2306
2310
|
constructor(provider) {
|
|
2307
2311
|
this.type = provider.type;
|
|
2308
2312
|
this.provider = provider;
|
|
@@ -2329,8 +2333,8 @@ var init_extension_provider_instance = __esm({
|
|
|
2329
2333
|
category: "extension",
|
|
2330
2334
|
status: this.currentStatus,
|
|
2331
2335
|
activeChat: this.messages.length > 0 ? {
|
|
2332
|
-
id:
|
|
2333
|
-
title: this.provider.name,
|
|
2336
|
+
id: this.chatId || this.instanceId,
|
|
2337
|
+
title: this.chatTitle || this.agentName || this.provider.name,
|
|
2334
2338
|
status: this.currentStatus,
|
|
2335
2339
|
messages: this.messages,
|
|
2336
2340
|
activeModal: this.activeModal,
|
|
@@ -2352,6 +2356,10 @@ var init_extension_provider_instance = __esm({
|
|
|
2352
2356
|
if (data?.activeModal !== void 0) this.activeModal = data.activeModal;
|
|
2353
2357
|
if (data?.model) this.currentModel = data.model;
|
|
2354
2358
|
if (data?.mode) this.currentMode = data.mode;
|
|
2359
|
+
if (typeof data?.sessionId === "string" && data.sessionId.trim()) this.chatId = data.sessionId;
|
|
2360
|
+
if (typeof data?.title === "string" && data.title.trim()) this.chatTitle = data.title;
|
|
2361
|
+
if (typeof data?.agentName === "string" && data.agentName.trim()) this.agentName = data.agentName;
|
|
2362
|
+
if (typeof data?.extensionId === "string" && data.extensionId.trim()) this.extensionId = data.extensionId;
|
|
2355
2363
|
if (data?.status) {
|
|
2356
2364
|
const newStatus = data.status;
|
|
2357
2365
|
this.detectTransition(newStatus, data);
|
|
@@ -2371,11 +2379,6 @@ var init_extension_provider_instance = __esm({
|
|
|
2371
2379
|
return this.instanceId;
|
|
2372
2380
|
}
|
|
2373
2381
|
// ─── status transition detect ──────────────────────────────
|
|
2374
|
-
// NOTE: Extension transitions are TRACKED but NOT emitted as events.
|
|
2375
|
-
// The parent IdeProviderInstance already emits identical events
|
|
2376
|
-
// (generating_started, generating_completed, waiting_approval)
|
|
2377
|
-
// via its own detectAgentTransitions(). Emitting here would cause
|
|
2378
|
-
// duplicate toasts with slightly different content.
|
|
2379
2382
|
detectTransition(newStatus, data) {
|
|
2380
2383
|
const now = Date.now();
|
|
2381
2384
|
const agentStatus = newStatus === "streaming" || newStatus === "generating" ? "generating" : newStatus === "waiting_approval" ? "waiting_approval" : "idle";
|
|
@@ -2384,7 +2387,40 @@ var init_extension_provider_instance = __esm({
|
|
|
2384
2387
|
if (agentStatus !== this.lastAgentStatus) {
|
|
2385
2388
|
if (this.lastAgentStatus === "idle" && agentStatus === "generating") {
|
|
2386
2389
|
this.generatingStartedAt = now;
|
|
2390
|
+
this.pushEvent({
|
|
2391
|
+
event: "agent:generating_started",
|
|
2392
|
+
chatTitle: this.resolveChatTitle(data),
|
|
2393
|
+
timestamp: now,
|
|
2394
|
+
ideType: this.ideType || this.type,
|
|
2395
|
+
agentType: this.type,
|
|
2396
|
+
agentName: this.agentName || this.provider.name,
|
|
2397
|
+
extensionId: this.extensionId || this.type
|
|
2398
|
+
});
|
|
2399
|
+
} else if (agentStatus === "waiting_approval") {
|
|
2400
|
+
if (!this.generatingStartedAt) this.generatingStartedAt = now;
|
|
2401
|
+
this.pushEvent({
|
|
2402
|
+
event: "agent:waiting_approval",
|
|
2403
|
+
chatTitle: this.resolveChatTitle(data),
|
|
2404
|
+
timestamp: now,
|
|
2405
|
+
ideType: this.ideType || this.type,
|
|
2406
|
+
agentType: this.type,
|
|
2407
|
+
agentName: this.agentName || this.provider.name,
|
|
2408
|
+
extensionId: this.extensionId || this.type,
|
|
2409
|
+
modalMessage: data?.activeModal?.message,
|
|
2410
|
+
modalButtons: data?.activeModal?.buttons
|
|
2411
|
+
});
|
|
2387
2412
|
} else if (agentStatus === "idle" && (this.lastAgentStatus === "generating" || this.lastAgentStatus === "waiting_approval")) {
|
|
2413
|
+
const duration3 = this.generatingStartedAt ? Math.round((now - this.generatingStartedAt) / 1e3) : 0;
|
|
2414
|
+
this.pushEvent({
|
|
2415
|
+
event: "agent:generating_completed",
|
|
2416
|
+
chatTitle: this.resolveChatTitle(data),
|
|
2417
|
+
duration: duration3,
|
|
2418
|
+
timestamp: now,
|
|
2419
|
+
ideType: this.ideType || this.type,
|
|
2420
|
+
agentType: this.type,
|
|
2421
|
+
agentName: this.agentName || this.provider.name,
|
|
2422
|
+
extensionId: this.extensionId || this.type
|
|
2423
|
+
});
|
|
2388
2424
|
this.generatingStartedAt = 0;
|
|
2389
2425
|
}
|
|
2390
2426
|
this.lastAgentStatus = agentStatus;
|
|
@@ -2404,6 +2440,10 @@ var init_extension_provider_instance = __esm({
|
|
|
2404
2440
|
this.events = [];
|
|
2405
2441
|
return events;
|
|
2406
2442
|
}
|
|
2443
|
+
resolveChatTitle(data) {
|
|
2444
|
+
const title = typeof data?.title === "string" && data.title.trim() ? data.title.trim() : this.chatTitle;
|
|
2445
|
+
return title || this.agentName || this.provider.name;
|
|
2446
|
+
}
|
|
2407
2447
|
};
|
|
2408
2448
|
}
|
|
2409
2449
|
});
|
|
@@ -3096,9 +3136,9 @@ var init_initializer = __esm({
|
|
|
3096
3136
|
await this.connectIdePort(port, ide);
|
|
3097
3137
|
}
|
|
3098
3138
|
if (cdpManagers.size > 0) {
|
|
3099
|
-
LOG.info("
|
|
3139
|
+
LOG.info("IDE", `${cdpManagers.size} IDE window(s) attached: ${[...cdpManagers.entries()].map(([k, m]) => `${k}:${m.getPort()}`).join(", ")}`);
|
|
3100
3140
|
} else {
|
|
3101
|
-
LOG.warn("
|
|
3141
|
+
LOG.warn("IDE", `No IDE windows attached \u2014 tried: ${filtered.map((p) => `${p.ide}:${p.port}`).join(", ")}`);
|
|
3102
3142
|
}
|
|
3103
3143
|
}
|
|
3104
3144
|
// ─── Per-port connection (multi-window aware) ───
|
|
@@ -3124,7 +3164,7 @@ var init_initializer = __esm({
|
|
|
3124
3164
|
if (connected) {
|
|
3125
3165
|
registerExtensionProviders(providerLoader, manager, ide);
|
|
3126
3166
|
cdpManagers.set(ide, manager);
|
|
3127
|
-
LOG.info("
|
|
3167
|
+
LOG.info("IDE", `Attached: ${ide} (port ${port})`);
|
|
3128
3168
|
await this.config.onConnected?.(ide, manager, ide);
|
|
3129
3169
|
}
|
|
3130
3170
|
return;
|
|
@@ -3157,7 +3197,7 @@ var init_initializer = __esm({
|
|
|
3157
3197
|
if (connected) {
|
|
3158
3198
|
registerExtensionProviders(providerLoader, manager, ide);
|
|
3159
3199
|
cdpManagers.set(managerKey, manager);
|
|
3160
|
-
LOG.info("
|
|
3200
|
+
LOG.info("IDE", `Attached window: ${managerKey} (port ${port}${targets.length > 1 ? `, page "${target.title}"` : ""})`);
|
|
3161
3201
|
await this.config.onConnected?.(ide, manager, managerKey);
|
|
3162
3202
|
}
|
|
3163
3203
|
}
|
|
@@ -3186,7 +3226,7 @@ var init_initializer = __esm({
|
|
|
3186
3226
|
} catch {
|
|
3187
3227
|
}
|
|
3188
3228
|
this.config.cdpManagers.delete(key);
|
|
3189
|
-
LOG.info("
|
|
3229
|
+
LOG.info("IDE", `Detached window: ${key} (${reason})`);
|
|
3190
3230
|
await this.config.onDisconnected?.(ide, manager, key, reason);
|
|
3191
3231
|
}
|
|
3192
3232
|
}
|
|
@@ -4590,7 +4630,6 @@ function handleSetProviderSetting(h, args) {
|
|
|
4590
4630
|
}
|
|
4591
4631
|
async function handleExtensionScript(h, args, scriptName) {
|
|
4592
4632
|
const { agentType, ideType } = args || {};
|
|
4593
|
-
LOG.info("Command", `[ExtScript] ${scriptName} agentType=${agentType} ideType=${ideType} session=${h.currentSession?.sessionId || ""}`);
|
|
4594
4633
|
if (!agentType) return { success: false, error: "agentType is required" };
|
|
4595
4634
|
const loader = h.ctx.providerLoader;
|
|
4596
4635
|
if (!loader) return { success: false, error: "ProviderLoader not initialized" };
|
|
@@ -4816,7 +4855,75 @@ var init_workspace_commands = __esm({
|
|
|
4816
4855
|
});
|
|
4817
4856
|
|
|
4818
4857
|
// ../../oss/packages/daemon-core/src/commands/handler.ts
|
|
4819
|
-
|
|
4858
|
+
function logAtLevel(level, category, message) {
|
|
4859
|
+
switch (level) {
|
|
4860
|
+
case "debug":
|
|
4861
|
+
LOG.debug(category, message);
|
|
4862
|
+
return;
|
|
4863
|
+
case "warn":
|
|
4864
|
+
LOG.warn(category, message);
|
|
4865
|
+
return;
|
|
4866
|
+
case "error":
|
|
4867
|
+
LOG.error(category, message);
|
|
4868
|
+
return;
|
|
4869
|
+
default:
|
|
4870
|
+
LOG.info(category, message);
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
function getCommandLogLevel(cmd) {
|
|
4874
|
+
return COMMAND_DEBUG_LEVELS.has(cmd) ? "debug" : "info";
|
|
4875
|
+
}
|
|
4876
|
+
function summarizeLogValue(value) {
|
|
4877
|
+
if (value === null) return "null";
|
|
4878
|
+
if (value === void 0) return "undefined";
|
|
4879
|
+
if (typeof value === "string") {
|
|
4880
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
4881
|
+
if (!normalized) return '""';
|
|
4882
|
+
if (normalized.length <= 80) return JSON.stringify(normalized);
|
|
4883
|
+
return `${JSON.stringify(normalized.slice(0, 80))}\u2026(${normalized.length} chars)`;
|
|
4884
|
+
}
|
|
4885
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
4886
|
+
if (Array.isArray(value)) return `[${value.length} items]`;
|
|
4887
|
+
if (typeof value === "object") return "{...}";
|
|
4888
|
+
return String(value);
|
|
4889
|
+
}
|
|
4890
|
+
function summarizeCommandArgs(args) {
|
|
4891
|
+
if (!args || typeof args !== "object") return "-";
|
|
4892
|
+
const preferredKeys = [
|
|
4893
|
+
"targetSessionId",
|
|
4894
|
+
"providerType",
|
|
4895
|
+
"agentType",
|
|
4896
|
+
"ideType",
|
|
4897
|
+
"model",
|
|
4898
|
+
"mode",
|
|
4899
|
+
"action",
|
|
4900
|
+
"button",
|
|
4901
|
+
"key",
|
|
4902
|
+
"force",
|
|
4903
|
+
"offset",
|
|
4904
|
+
"limit",
|
|
4905
|
+
"cols",
|
|
4906
|
+
"rows",
|
|
4907
|
+
"path",
|
|
4908
|
+
"command",
|
|
4909
|
+
"commandId",
|
|
4910
|
+
"workspace",
|
|
4911
|
+
"dir",
|
|
4912
|
+
"url",
|
|
4913
|
+
"text",
|
|
4914
|
+
"message",
|
|
4915
|
+
"data",
|
|
4916
|
+
"value"
|
|
4917
|
+
];
|
|
4918
|
+
const entries = [];
|
|
4919
|
+
for (const key of preferredKeys) {
|
|
4920
|
+
if (!(key in args) || args[key] === void 0) continue;
|
|
4921
|
+
const value = key === "text" || key === "message" ? `${String(args[key] || "").length} chars` : key === "data" ? `${String(args[key] || "").length} chars` : summarizeLogValue(args[key]);
|
|
4922
|
+
entries.push(`${key}=${value}`);
|
|
4923
|
+
}
|
|
4924
|
+
return entries.length ? entries.join(" ") : "{...}";
|
|
4925
|
+
}
|
|
4926
|
+
var COMMAND_DEBUG_LEVELS, DaemonCommandHandler;
|
|
4820
4927
|
var init_handler = __esm({
|
|
4821
4928
|
"../../oss/packages/daemon-core/src/commands/handler.ts"() {
|
|
4822
4929
|
"use strict";
|
|
@@ -4831,6 +4938,15 @@ var init_handler = __esm({
|
|
|
4831
4938
|
init_workspace_commands();
|
|
4832
4939
|
init_workspaces();
|
|
4833
4940
|
init_workspace_activity();
|
|
4941
|
+
COMMAND_DEBUG_LEVELS = /* @__PURE__ */ new Set([
|
|
4942
|
+
"pty_input",
|
|
4943
|
+
"pty_resize",
|
|
4944
|
+
"cdp_eval",
|
|
4945
|
+
"cdp_batch",
|
|
4946
|
+
"cdp_dom_query",
|
|
4947
|
+
"cdp_dom_dump",
|
|
4948
|
+
"cdp_dom_debug"
|
|
4949
|
+
]);
|
|
4834
4950
|
DaemonCommandHandler = class {
|
|
4835
4951
|
_ctx;
|
|
4836
4952
|
_agentStream = null;
|
|
@@ -4978,23 +5094,54 @@ var init_handler = __esm({
|
|
|
4978
5094
|
}
|
|
4979
5095
|
return void 0;
|
|
4980
5096
|
}
|
|
5097
|
+
logCommandStart(cmd, args) {
|
|
5098
|
+
const routeBits = [
|
|
5099
|
+
this._currentRoute.session?.sessionId ? `session=${this._currentRoute.session.sessionId}` : "",
|
|
5100
|
+
this._currentRoute.managerKey ? `manager=${this._currentRoute.managerKey}` : "",
|
|
5101
|
+
this._currentRoute.providerType ? `provider=${this._currentRoute.providerType}` : ""
|
|
5102
|
+
].filter(Boolean).join(" ");
|
|
5103
|
+
const summary = summarizeCommandArgs(args);
|
|
5104
|
+
logAtLevel(
|
|
5105
|
+
getCommandLogLevel(cmd),
|
|
5106
|
+
"Command",
|
|
5107
|
+
`[${cmd}] start${routeBits ? ` ${routeBits}` : ""} args=${summary}`
|
|
5108
|
+
);
|
|
5109
|
+
}
|
|
5110
|
+
logCommandEnd(cmd, result, startedAt) {
|
|
5111
|
+
const durationMs = Date.now() - startedAt;
|
|
5112
|
+
const parts = [`[${cmd}] end`, `success=${result.success}`, `duration=${durationMs}ms`];
|
|
5113
|
+
if (typeof result.error === "string" && result.error) {
|
|
5114
|
+
parts.push(`error=${JSON.stringify(result.error)}`);
|
|
5115
|
+
}
|
|
5116
|
+
const level = result.success ? getCommandLogLevel(cmd) : "warn";
|
|
5117
|
+
logAtLevel(level, "Command", parts.join(" "));
|
|
5118
|
+
}
|
|
4981
5119
|
setAgentStreamManager(manager) {
|
|
4982
5120
|
this._agentStream = manager;
|
|
4983
5121
|
}
|
|
4984
5122
|
// ─── Command Dispatcher ──────────────────────────
|
|
4985
5123
|
async handle(cmd, args) {
|
|
4986
5124
|
this._currentRoute = this.resolveRoute(args);
|
|
5125
|
+
const startedAt = Date.now();
|
|
5126
|
+
this.logCommandStart(cmd, args);
|
|
5127
|
+
let result;
|
|
4987
5128
|
if (!this._currentRoute.session && !this._currentRoute.managerKey && !this._currentRoute.providerType) {
|
|
4988
5129
|
const cdpCommands = ["send_chat", "read_chat", "list_chats", "new_chat", "switch_chat", "set_mode", "change_model", "set_thought_level", "resolve_action"];
|
|
4989
5130
|
if (cdpCommands.includes(cmd)) {
|
|
4990
|
-
|
|
5131
|
+
result = { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
|
|
5132
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
5133
|
+
return result;
|
|
4991
5134
|
}
|
|
4992
5135
|
}
|
|
4993
5136
|
try {
|
|
4994
|
-
|
|
5137
|
+
result = await this.dispatch(cmd, args);
|
|
5138
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
5139
|
+
return result;
|
|
4995
5140
|
} catch (e) {
|
|
4996
5141
|
LOG.error("Command", `[${cmd}] Unhandled error: ${e?.message || e}`);
|
|
4997
|
-
|
|
5142
|
+
result = { success: false, error: `Internal error: ${e?.message || "unknown"}` };
|
|
5143
|
+
this.logCommandEnd(cmd, result, startedAt);
|
|
5144
|
+
return result;
|
|
4998
5145
|
}
|
|
4999
5146
|
}
|
|
5000
5147
|
async dispatch(cmd, args) {
|
|
@@ -37695,7 +37842,13 @@ function forwardAgentStreamsToIdeInstance(instanceManager, ideType, streams) {
|
|
|
37695
37842
|
status: stream.status || "idle",
|
|
37696
37843
|
activeModal: stream.activeModal || null,
|
|
37697
37844
|
model: stream.model || void 0,
|
|
37698
|
-
mode: stream.mode || void 0
|
|
37845
|
+
mode: stream.mode || void 0,
|
|
37846
|
+
sessionId: stream.sessionId || stream.instanceId || void 0,
|
|
37847
|
+
title: stream.title || stream.agentName || void 0,
|
|
37848
|
+
agentType: stream.agentType || void 0,
|
|
37849
|
+
agentName: stream.agentName || void 0,
|
|
37850
|
+
extensionId: stream.extensionId || void 0,
|
|
37851
|
+
inputContent: stream.inputContent || ""
|
|
37699
37852
|
});
|
|
37700
37853
|
}
|
|
37701
37854
|
}
|
|
@@ -37768,14 +37921,13 @@ var init_provider_instance_manager = __esm({
|
|
|
37768
37921
|
try {
|
|
37769
37922
|
const state = instance.getState();
|
|
37770
37923
|
states.push(state);
|
|
37771
|
-
|
|
37772
|
-
|
|
37773
|
-
|
|
37774
|
-
|
|
37775
|
-
|
|
37776
|
-
|
|
37777
|
-
|
|
37778
|
-
providerCategory: state.category
|
|
37924
|
+
this.emitPendingEvents(instance.type, state);
|
|
37925
|
+
if (state.category === "ide") {
|
|
37926
|
+
for (const childState of state.extensions) {
|
|
37927
|
+
this.emitPendingEvents(childState.type, childState, {
|
|
37928
|
+
targetSessionId: childState.instanceId,
|
|
37929
|
+
workspaceName: state.workspace || void 0,
|
|
37930
|
+
parentSessionId: state.instanceId
|
|
37779
37931
|
});
|
|
37780
37932
|
}
|
|
37781
37933
|
}
|
|
@@ -37824,6 +37976,21 @@ var init_provider_instance_manager = __esm({
|
|
|
37824
37976
|
onEvent(listener) {
|
|
37825
37977
|
this.eventListeners.push(listener);
|
|
37826
37978
|
}
|
|
37979
|
+
emitPendingEvents(providerType, state, extra = {}) {
|
|
37980
|
+
for (const event of state.pendingEvents) {
|
|
37981
|
+
for (const listener of this.eventListeners) {
|
|
37982
|
+
listener({
|
|
37983
|
+
...event,
|
|
37984
|
+
providerType,
|
|
37985
|
+
instanceId: state.instanceId,
|
|
37986
|
+
targetSessionId: state.instanceId,
|
|
37987
|
+
providerCategory: state.category,
|
|
37988
|
+
workspaceName: state.workspace || void 0,
|
|
37989
|
+
...extra
|
|
37990
|
+
});
|
|
37991
|
+
}
|
|
37992
|
+
}
|
|
37993
|
+
}
|
|
37827
37994
|
/**
|
|
37828
37995
|
* Forward event to specific Instance
|
|
37829
37996
|
*/
|
|
@@ -41562,7 +41729,7 @@ async function initDaemonComponents(config2) {
|
|
|
41562
41729
|
const ideInstance = instanceManager.getInstance(instanceKey);
|
|
41563
41730
|
if (ideInstance) {
|
|
41564
41731
|
instanceManager.removeInstance(instanceKey);
|
|
41565
|
-
LOG.info("
|
|
41732
|
+
LOG.info("IDE", `Instance removed after detach: ${instanceKey}`);
|
|
41566
41733
|
}
|
|
41567
41734
|
if (ideInstance?.getInstanceId) {
|
|
41568
41735
|
agentStreamManager?.resetParentSession(ideInstance.getInstanceId());
|
|
@@ -41997,6 +42164,40 @@ var init_server_connection = __esm({
|
|
|
41997
42164
|
});
|
|
41998
42165
|
|
|
41999
42166
|
// src/daemon-p2p.ts
|
|
42167
|
+
function normalizeSharePermission(permission) {
|
|
42168
|
+
if (!permission) return void 0;
|
|
42169
|
+
if (permission === "view") return "remote_view";
|
|
42170
|
+
if (permission === "control") return "remote_control";
|
|
42171
|
+
if (permission === "full") return "remote_full";
|
|
42172
|
+
return permission;
|
|
42173
|
+
}
|
|
42174
|
+
function canPeerStartScreenshots(permission) {
|
|
42175
|
+
if (!permission) return true;
|
|
42176
|
+
return permission === "remote_view" || permission === "remote_control" || permission === "remote_full";
|
|
42177
|
+
}
|
|
42178
|
+
function canPeerSendMessages(permission) {
|
|
42179
|
+
if (!permission) return true;
|
|
42180
|
+
return permission === "chat_control" || permission === "remote_control" || permission === "remote_full";
|
|
42181
|
+
}
|
|
42182
|
+
function canPeerUseRemoteInput(permission) {
|
|
42183
|
+
if (!permission) return true;
|
|
42184
|
+
return permission === "remote_full";
|
|
42185
|
+
}
|
|
42186
|
+
function canPeerUsePrivilegedShareCommand(commandType, permission) {
|
|
42187
|
+
if (!permission) return true;
|
|
42188
|
+
switch (commandType) {
|
|
42189
|
+
case "read_chat":
|
|
42190
|
+
case "list_chats":
|
|
42191
|
+
return true;
|
|
42192
|
+
case "send_chat":
|
|
42193
|
+
case "new_chat":
|
|
42194
|
+
case "switch_chat":
|
|
42195
|
+
case "resolve_action":
|
|
42196
|
+
return canPeerSendMessages(permission);
|
|
42197
|
+
default:
|
|
42198
|
+
return false;
|
|
42199
|
+
}
|
|
42200
|
+
}
|
|
42000
42201
|
var fs11, path13, os16, import_node_module, esmRequire, logFile, log, logDebug, DaemonP2PSender;
|
|
42001
42202
|
var init_daemon_p2p = __esm({
|
|
42002
42203
|
"src/daemon-p2p.ts"() {
|
|
@@ -42209,7 +42410,7 @@ ${e?.stack || ""}`);
|
|
|
42209
42410
|
}
|
|
42210
42411
|
}
|
|
42211
42412
|
/** P2P connect Start */
|
|
42212
|
-
async initiateconnection(peerId) {
|
|
42413
|
+
async initiateconnection(peerId, sharePermission) {
|
|
42213
42414
|
if (!this.nodeDatachannel) {
|
|
42214
42415
|
log("Cannot initiate \u2014 node-datachannel not available");
|
|
42215
42416
|
return;
|
|
@@ -42302,6 +42503,7 @@ ${e?.stack || ""}`);
|
|
|
42302
42503
|
pc,
|
|
42303
42504
|
dataChannel: null,
|
|
42304
42505
|
state: "connecting",
|
|
42506
|
+
sharePermission: normalizeSharePermission(sharePermission),
|
|
42305
42507
|
screenshotActive: false,
|
|
42306
42508
|
connectedAt: Date.now(),
|
|
42307
42509
|
pendingCandidates: [],
|
|
@@ -42423,10 +42625,15 @@ ${e?.stack || ""}`);
|
|
|
42423
42625
|
}
|
|
42424
42626
|
if (parsed.type === "screenshot_start") {
|
|
42425
42627
|
const peer = this.peers.get(peerId);
|
|
42628
|
+
const permission = peer?.sharePermission;
|
|
42426
42629
|
if (!parsed.ideType) {
|
|
42427
42630
|
log(`screenshot_start: REJECTED \u2014 no ideType from peer ${peerId}`);
|
|
42428
42631
|
return;
|
|
42429
42632
|
}
|
|
42633
|
+
if (!canPeerStartScreenshots(permission)) {
|
|
42634
|
+
log(`screenshot_start: REJECTED \u2014 permission=${permission || "trusted"} peer=${peerId}`);
|
|
42635
|
+
return;
|
|
42636
|
+
}
|
|
42430
42637
|
if (peer) {
|
|
42431
42638
|
peer.screenshotActive = true;
|
|
42432
42639
|
peer.screenshotIdeType = parsed.ideType;
|
|
@@ -42455,23 +42662,27 @@ ${e?.stack || ""}`);
|
|
|
42455
42662
|
return;
|
|
42456
42663
|
}
|
|
42457
42664
|
if (parsed.type === "pty_input") {
|
|
42665
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
42666
|
+
if (permission) {
|
|
42667
|
+
log(`pty_input: REJECTED \u2014 permission=${permission} peer=${peerId}`);
|
|
42668
|
+
return;
|
|
42669
|
+
}
|
|
42458
42670
|
if (this.ptyInputHandler && parsed.data) {
|
|
42459
42671
|
this.ptyInputHandler(parsed.cliType || "", parsed.data);
|
|
42460
42672
|
}
|
|
42461
42673
|
return;
|
|
42462
42674
|
}
|
|
42463
42675
|
if (parsed.type === "pty_resize") {
|
|
42676
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
42677
|
+
if (permission) {
|
|
42678
|
+
log(`pty_resize: REJECTED \u2014 permission=${permission} peer=${peerId}`);
|
|
42679
|
+
return;
|
|
42680
|
+
}
|
|
42464
42681
|
if (this.ptyResizeHandler && parsed.cols && parsed.rows) {
|
|
42465
42682
|
this.ptyResizeHandler(parsed.cliType || "", parsed.cols, parsed.rows);
|
|
42466
42683
|
}
|
|
42467
42684
|
return;
|
|
42468
42685
|
}
|
|
42469
|
-
if (parsed.type === "chat_history") {
|
|
42470
|
-
const { agent, offset, limit, id, instanceId } = parsed;
|
|
42471
|
-
const result = readChatHistory(agent || "", offset || 0, limit || 30, instanceId);
|
|
42472
|
-
this.sendToPeer(peerId, { type: "chat_history_result", id, ...result, agent });
|
|
42473
|
-
return;
|
|
42474
|
-
}
|
|
42475
42686
|
this.handleFileRequest(peerId, parsed);
|
|
42476
42687
|
} catch (e) {
|
|
42477
42688
|
log(`Parse error from peer ${peerId}: ${e?.message}`);
|
|
@@ -42590,6 +42801,11 @@ ${e?.stack || ""}`);
|
|
|
42590
42801
|
// ─── P2P command/input/file handling ────────────────
|
|
42591
42802
|
async handleP2PCommand(peerId, msg) {
|
|
42592
42803
|
const { id, commandType, data } = msg;
|
|
42804
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
42805
|
+
if (!canPeerUsePrivilegedShareCommand(commandType, permission)) {
|
|
42806
|
+
this.sendToPeer(peerId, { type: "command_result", id, success: false, error: "Permission denied" });
|
|
42807
|
+
return;
|
|
42808
|
+
}
|
|
42593
42809
|
if (!this.commandHandler) {
|
|
42594
42810
|
this.sendToPeer(peerId, { type: "command_result", id, success: false, error: "No handler" });
|
|
42595
42811
|
return;
|
|
@@ -42603,6 +42819,11 @@ ${e?.stack || ""}`);
|
|
|
42603
42819
|
}
|
|
42604
42820
|
async handleInputEvent(peerId, msg) {
|
|
42605
42821
|
const { id, action, params, instanceId } = msg;
|
|
42822
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
42823
|
+
if (!canPeerUseRemoteInput(permission)) {
|
|
42824
|
+
this.sendToPeer(peerId, { id, type: "response", success: false, error: "Permission denied" });
|
|
42825
|
+
return;
|
|
42826
|
+
}
|
|
42606
42827
|
if (!this.inputHandler) {
|
|
42607
42828
|
this.sendToPeer(peerId, { id, type: "response", success: false, error: "No input handler" });
|
|
42608
42829
|
return;
|
|
@@ -42620,6 +42841,11 @@ ${e?.stack || ""}`);
|
|
|
42620
42841
|
}
|
|
42621
42842
|
}
|
|
42622
42843
|
async handleFileRequest(peerId, req) {
|
|
42844
|
+
const permission = this.peers.get(peerId)?.sharePermission;
|
|
42845
|
+
if (permission) {
|
|
42846
|
+
this.sendToPeer(peerId, { id: req.id, success: false, error: "Permission denied" });
|
|
42847
|
+
return;
|
|
42848
|
+
}
|
|
42623
42849
|
let response;
|
|
42624
42850
|
if (this.fileRequestHandler) {
|
|
42625
42851
|
try {
|
|
@@ -42645,7 +42871,7 @@ ${e?.stack || ""}`);
|
|
|
42645
42871
|
const peerId = payload?.peerId;
|
|
42646
42872
|
if (type === "p2p_ready") {
|
|
42647
42873
|
log(`p2p_ready from peer ${peerId}`);
|
|
42648
|
-
this.initiateconnection(peerId);
|
|
42874
|
+
this.initiateconnection(peerId, payload?.sharePermission);
|
|
42649
42875
|
return;
|
|
42650
42876
|
}
|
|
42651
42877
|
if (type === "p2p_answer") {
|
|
@@ -42658,6 +42884,9 @@ ${e?.stack || ""}`);
|
|
|
42658
42884
|
log(`p2p_answer for unknown peer ${peerId} \u2014 ignoring`);
|
|
42659
42885
|
return;
|
|
42660
42886
|
}
|
|
42887
|
+
if (payload?.sharePermission) {
|
|
42888
|
+
peer.sharePermission = normalizeSharePermission(payload.sharePermission);
|
|
42889
|
+
}
|
|
42661
42890
|
if (peer.remoteDescriptionSet) {
|
|
42662
42891
|
log(`p2p_answer ignored: already applied for peer ${peerId} (duplicate relay)`);
|
|
42663
42892
|
return;
|
|
@@ -42694,6 +42923,9 @@ ${e?.stack || ""}`);
|
|
|
42694
42923
|
}
|
|
42695
42924
|
const peer = this.peers.get(peerId);
|
|
42696
42925
|
if (peer?.pc && payload.candidate) {
|
|
42926
|
+
if (payload?.sharePermission) {
|
|
42927
|
+
peer.sharePermission = normalizeSharePermission(payload.sharePermission);
|
|
42928
|
+
}
|
|
42697
42929
|
log(`p2p_ice received from peer ${peerId}: ${String(payload.candidate).substring(0, 80)}`);
|
|
42698
42930
|
if (!peer.remoteDescriptionSet) {
|
|
42699
42931
|
peer.pendingCandidates.push({
|
|
@@ -43033,7 +43265,7 @@ var init_adhdev_daemon = __esm({
|
|
|
43033
43265
|
fs12 = __toESM(require("fs"));
|
|
43034
43266
|
path14 = __toESM(require("path"));
|
|
43035
43267
|
import_chalk2 = __toESM(require("chalk"));
|
|
43036
|
-
pkgVersion = "0.7.
|
|
43268
|
+
pkgVersion = "0.7.6";
|
|
43037
43269
|
if (pkgVersion === "unknown") {
|
|
43038
43270
|
try {
|
|
43039
43271
|
const possiblePaths = [
|