@adhdev/daemon-core 0.9.82-rc.166 → 0.9.82-rc.168
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-adapters/raw-terminal-io.d.ts +37 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +234 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -16
- package/dist/index.mjs.map +1 -1
- package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +1 -0
- package/package.json +1 -1
- package/src/cli-adapters/raw-terminal-io.ts +252 -0
- package/src/index.ts +7 -0
- package/src/mesh/mesh-events.ts +19 -1
- package/src/providers/cli-provider-instance.ts +1 -1
- package/src/providers/provider-loader.ts +4 -4
- package/src/providers/sdk/v1/builders/cli/parse-approval.ts +7 -2
- package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +6 -0
package/dist/index.mjs
CHANGED
|
@@ -3694,6 +3694,20 @@ function hasDispatchAfterTerminal(meshId, sessionId, terminalId) {
|
|
|
3694
3694
|
}
|
|
3695
3695
|
return false;
|
|
3696
3696
|
}
|
|
3697
|
+
function hasUnterminalDirectDispatchLedgerEntry(meshId, sessionId) {
|
|
3698
|
+
const entries = readLedgerEntries(meshId, { tail: 200 });
|
|
3699
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
3700
|
+
const entry = entries[i];
|
|
3701
|
+
if (entry.sessionId !== sessionId) continue;
|
|
3702
|
+
if (entry.kind === "task_completed" || entry.kind === "task_failed" || entry.kind === "task_stalled") {
|
|
3703
|
+
return false;
|
|
3704
|
+
}
|
|
3705
|
+
if (entry.kind === "task_dispatched" && entry.payload?.source === "direct") {
|
|
3706
|
+
return true;
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3709
|
+
return false;
|
|
3710
|
+
}
|
|
3697
3711
|
function buildLongGeneratingCompletionReconciliation(args) {
|
|
3698
3712
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
3699
3713
|
const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
@@ -4561,7 +4575,7 @@ function setupMeshEventForwarding(components) {
|
|
|
4561
4575
|
if (coordinatorMeshId) {
|
|
4562
4576
|
try {
|
|
4563
4577
|
const activeDispatches = getActiveDirectDispatches(coordinatorMeshId);
|
|
4564
|
-
if (activeDispatches.some((d) => d.sessionId === instanceId)) {
|
|
4578
|
+
if (activeDispatches.some((d) => d.sessionId === instanceId) || hasUnterminalDirectDispatchLedgerEntry(coordinatorMeshId, instanceId)) {
|
|
4565
4579
|
meshIdFromDirectDispatch = coordinatorMeshId;
|
|
4566
4580
|
}
|
|
4567
4581
|
} catch {
|
|
@@ -6398,12 +6412,14 @@ function scopeLines(spec, lines, questionIndex) {
|
|
|
6398
6412
|
function extractButtons(spec, lines, windowStart, windowEnd) {
|
|
6399
6413
|
const buttonRe = compile3(spec.buttonPattern, spec.buttonFlags ?? "m");
|
|
6400
6414
|
const out = [];
|
|
6415
|
+
const labelGroup = Number.isInteger(spec.buttonLabelGroup) && (spec.buttonLabelGroup ?? 0) > 0 ? spec.buttonLabelGroup : 1;
|
|
6401
6416
|
let i = windowStart;
|
|
6402
6417
|
while (i < windowEnd) {
|
|
6403
6418
|
const line = lines[i];
|
|
6404
6419
|
const m = buttonRe.exec(line);
|
|
6405
|
-
|
|
6406
|
-
|
|
6420
|
+
const captured = m?.[labelGroup] ?? (labelGroup === 1 && m && m.length > 2 ? m[m.length - 1] : void 0);
|
|
6421
|
+
if (m && captured) {
|
|
6422
|
+
let label = captured.trim();
|
|
6407
6423
|
if (spec.continuationLines) {
|
|
6408
6424
|
let j = i + 1;
|
|
6409
6425
|
while (j < windowEnd) {
|
|
@@ -28100,7 +28116,7 @@ var CliProviderInstance = class {
|
|
|
28100
28116
|
};
|
|
28101
28117
|
}
|
|
28102
28118
|
getSessionModalState(sessionId) {
|
|
28103
|
-
const adapterStatus = this.adapter.getStatus({ allowParse:
|
|
28119
|
+
const adapterStatus = this.adapter.getStatus({ allowParse: true });
|
|
28104
28120
|
const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
|
|
28105
28121
|
const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
|
|
28106
28122
|
const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
|
|
@@ -31638,6 +31654,7 @@ function validateControl(control, errors) {
|
|
|
31638
31654
|
}
|
|
31639
31655
|
|
|
31640
31656
|
// src/providers/provider-loader.ts
|
|
31657
|
+
init_external_sources();
|
|
31641
31658
|
function registerProviderScriptRootSafely(root) {
|
|
31642
31659
|
if (!root || typeof root !== "string") return;
|
|
31643
31660
|
try {
|
|
@@ -31895,11 +31912,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
31895
31912
|
this.log(`Loaded ${externalCount} external providers (legacy unnamed source)`);
|
|
31896
31913
|
}
|
|
31897
31914
|
} else {
|
|
31898
|
-
const
|
|
31899
|
-
loadProvidersActive: loadProvidersActive2,
|
|
31900
|
-
resolveActiveSource: resolveActiveSource2
|
|
31901
|
-
} = (init_external_sources(), __toCommonJS(external_sources_exports));
|
|
31902
|
-
const activeFile = loadProvidersActive2();
|
|
31915
|
+
const activeFile = loadProvidersActive();
|
|
31903
31916
|
let totalLoaded = 0;
|
|
31904
31917
|
const ambiguousTypes = [];
|
|
31905
31918
|
for (const sourceEntry of rootEntries) {
|
|
@@ -31914,7 +31927,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
31914
31927
|
for (const [type] of this.providers) {
|
|
31915
31928
|
const prov = this.providers.get(type);
|
|
31916
31929
|
if (!prov) continue;
|
|
31917
|
-
const resolved =
|
|
31930
|
+
const resolved = resolveActiveSource(prov.category, type, activeFile);
|
|
31918
31931
|
if (resolved.candidates.length <= 1) continue;
|
|
31919
31932
|
if (resolved.ambiguous) {
|
|
31920
31933
|
ambiguousTypes.push({ type, chosen: resolved.source ?? "?", candidates: resolved.candidates });
|
|
@@ -39072,9 +39085,9 @@ var DaemonCommandRouter = class {
|
|
|
39072
39085
|
});
|
|
39073
39086
|
let node;
|
|
39074
39087
|
if (meshRecord.inline) {
|
|
39075
|
-
const { randomUUID:
|
|
39088
|
+
const { randomUUID: randomUUID11 } = await import("crypto");
|
|
39076
39089
|
node = {
|
|
39077
|
-
id: `node_${
|
|
39090
|
+
id: `node_${randomUUID11().replace(/-/g, "")}`,
|
|
39078
39091
|
workspace: result.worktreePath,
|
|
39079
39092
|
repoRoot: result.worktreePath,
|
|
39080
39093
|
daemonId: sourceNode.daemonId,
|
|
@@ -47430,6 +47443,203 @@ var SessionHostPtyTransportFactory = class {
|
|
|
47430
47443
|
}
|
|
47431
47444
|
};
|
|
47432
47445
|
|
|
47446
|
+
// src/cli-adapters/raw-terminal-io.ts
|
|
47447
|
+
import { randomUUID as randomUUID10 } from "crypto";
|
|
47448
|
+
import {
|
|
47449
|
+
SessionHostClient as SessionHostClient2
|
|
47450
|
+
} from "@adhdev/session-host-core";
|
|
47451
|
+
var BASE_KEY_SEQUENCES = {
|
|
47452
|
+
enter: "\r",
|
|
47453
|
+
escape: "\x1B",
|
|
47454
|
+
tab: " ",
|
|
47455
|
+
backspace: "\x7F",
|
|
47456
|
+
up: "\x1B[A",
|
|
47457
|
+
down: "\x1B[B",
|
|
47458
|
+
right: "\x1B[C",
|
|
47459
|
+
left: "\x1B[D",
|
|
47460
|
+
home: "\x1B[H",
|
|
47461
|
+
end: "\x1B[F",
|
|
47462
|
+
pageup: "\x1B[5~",
|
|
47463
|
+
pagedown: "\x1B[6~",
|
|
47464
|
+
space: " ",
|
|
47465
|
+
f1: "\x1BOP",
|
|
47466
|
+
f2: "\x1BOQ",
|
|
47467
|
+
f3: "\x1BOR",
|
|
47468
|
+
f4: "\x1BOS",
|
|
47469
|
+
f5: "\x1B[15~",
|
|
47470
|
+
f6: "\x1B[17~",
|
|
47471
|
+
f7: "\x1B[18~",
|
|
47472
|
+
f8: "\x1B[19~",
|
|
47473
|
+
f9: "\x1B[20~",
|
|
47474
|
+
f10: "\x1B[21~",
|
|
47475
|
+
f11: "\x1B[23~",
|
|
47476
|
+
f12: "\x1B[24~"
|
|
47477
|
+
};
|
|
47478
|
+
var SHIFTED_CSI_KEYS = {
|
|
47479
|
+
up: "\x1B[1;2A",
|
|
47480
|
+
down: "\x1B[1;2B",
|
|
47481
|
+
right: "\x1B[1;2C",
|
|
47482
|
+
left: "\x1B[1;2D",
|
|
47483
|
+
home: "\x1B[1;2H",
|
|
47484
|
+
end: "\x1B[1;2F",
|
|
47485
|
+
pageup: "\x1B[5;2~",
|
|
47486
|
+
pagedown: "\x1B[6;2~",
|
|
47487
|
+
f1: "\x1B[1;2P",
|
|
47488
|
+
f2: "\x1B[1;2Q",
|
|
47489
|
+
f3: "\x1B[1;2R",
|
|
47490
|
+
f4: "\x1B[1;2S",
|
|
47491
|
+
f5: "\x1B[15;2~",
|
|
47492
|
+
f6: "\x1B[17;2~",
|
|
47493
|
+
f7: "\x1B[18;2~",
|
|
47494
|
+
f8: "\x1B[19;2~",
|
|
47495
|
+
f9: "\x1B[20;2~",
|
|
47496
|
+
f10: "\x1B[21;2~",
|
|
47497
|
+
f11: "\x1B[23;2~",
|
|
47498
|
+
f12: "\x1B[24;2~"
|
|
47499
|
+
};
|
|
47500
|
+
function isLowercaseLetter(value) {
|
|
47501
|
+
return /^[a-z]$/.test(value);
|
|
47502
|
+
}
|
|
47503
|
+
function encodeControlLetter(letter) {
|
|
47504
|
+
return String.fromCharCode(letter.charCodeAt(0) - 96);
|
|
47505
|
+
}
|
|
47506
|
+
function encodeShiftedKey(key) {
|
|
47507
|
+
if (isLowercaseLetter(key)) return key.toUpperCase();
|
|
47508
|
+
if (key.startsWith("ctrl+") && isLowercaseLetter(key.slice(5))) {
|
|
47509
|
+
return encodeControlLetter(key.slice(5));
|
|
47510
|
+
}
|
|
47511
|
+
if (key.startsWith("alt+") && isLowercaseLetter(key.slice(4))) {
|
|
47512
|
+
return `\x1B${key.slice(4).toUpperCase()}`;
|
|
47513
|
+
}
|
|
47514
|
+
if (key === "tab") return "\x1B[Z";
|
|
47515
|
+
if (key in SHIFTED_CSI_KEYS) return SHIFTED_CSI_KEYS[key];
|
|
47516
|
+
if (key in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[key];
|
|
47517
|
+
throw new Error(`Unsupported named key: shift+${key}`);
|
|
47518
|
+
}
|
|
47519
|
+
function namedKeyToAnsi(key) {
|
|
47520
|
+
const normalized = String(key || "").trim().toLowerCase();
|
|
47521
|
+
if (normalized in BASE_KEY_SEQUENCES) return BASE_KEY_SEQUENCES[normalized];
|
|
47522
|
+
if (normalized.startsWith("ctrl+") && isLowercaseLetter(normalized.slice(5))) {
|
|
47523
|
+
return encodeControlLetter(normalized.slice(5));
|
|
47524
|
+
}
|
|
47525
|
+
if (normalized.startsWith("alt+") && isLowercaseLetter(normalized.slice(4))) {
|
|
47526
|
+
return `\x1B${normalized.slice(4)}`;
|
|
47527
|
+
}
|
|
47528
|
+
if (normalized.startsWith("shift+")) return encodeShiftedKey(normalized.slice(6));
|
|
47529
|
+
throw new Error(`Unsupported named key: ${key}`);
|
|
47530
|
+
}
|
|
47531
|
+
function namedKeysToAnsi(keys) {
|
|
47532
|
+
if (!Array.isArray(keys)) throw new Error("keys must be an array");
|
|
47533
|
+
return keys.map(namedKeyToAnsi).join("");
|
|
47534
|
+
}
|
|
47535
|
+
var RawTerminalAttachment = class _RawTerminalAttachment {
|
|
47536
|
+
constructor(sessionId, clientId, mode, client) {
|
|
47537
|
+
this.sessionId = sessionId;
|
|
47538
|
+
this.clientId = clientId;
|
|
47539
|
+
this.mode = mode;
|
|
47540
|
+
this.client = client;
|
|
47541
|
+
}
|
|
47542
|
+
closed = false;
|
|
47543
|
+
static async attach(options) {
|
|
47544
|
+
const sessionId = String(options.sessionId || "").trim();
|
|
47545
|
+
if (!sessionId) throw new Error("sessionId is required");
|
|
47546
|
+
const mode = options.mode || "read";
|
|
47547
|
+
const clientId = options.clientId || `raw-terminal-${process.pid}-${randomUUID10().slice(0, 8)}`;
|
|
47548
|
+
const client = options.client || new SessionHostClient2({ endpoint: options.endpoint });
|
|
47549
|
+
await client.connect();
|
|
47550
|
+
const attachResponse = await client.request({
|
|
47551
|
+
type: "attach_session",
|
|
47552
|
+
payload: {
|
|
47553
|
+
sessionId,
|
|
47554
|
+
clientId,
|
|
47555
|
+
clientType: "web",
|
|
47556
|
+
readOnly: mode === "read"
|
|
47557
|
+
}
|
|
47558
|
+
});
|
|
47559
|
+
if (!attachResponse.success) {
|
|
47560
|
+
await client.close().catch(() => {
|
|
47561
|
+
});
|
|
47562
|
+
throw new Error(attachResponse.error || `Failed to attach terminal session ${sessionId}`);
|
|
47563
|
+
}
|
|
47564
|
+
if (mode === "write") {
|
|
47565
|
+
const ownerResponse = await client.request({
|
|
47566
|
+
type: "acquire_write",
|
|
47567
|
+
payload: {
|
|
47568
|
+
sessionId,
|
|
47569
|
+
clientId,
|
|
47570
|
+
ownerType: "user",
|
|
47571
|
+
force: true
|
|
47572
|
+
}
|
|
47573
|
+
});
|
|
47574
|
+
if (!ownerResponse.success) {
|
|
47575
|
+
await client.request({
|
|
47576
|
+
type: "detach_session",
|
|
47577
|
+
payload: { sessionId, clientId }
|
|
47578
|
+
}).catch(() => ({ success: false }));
|
|
47579
|
+
await client.close().catch(() => {
|
|
47580
|
+
});
|
|
47581
|
+
throw new Error(ownerResponse.error || `Failed to acquire terminal session ${sessionId}`);
|
|
47582
|
+
}
|
|
47583
|
+
}
|
|
47584
|
+
return new _RawTerminalAttachment(sessionId, clientId, mode, client);
|
|
47585
|
+
}
|
|
47586
|
+
async readSnapshot() {
|
|
47587
|
+
const response = await this.client.request({
|
|
47588
|
+
type: "get_terminal_snapshot",
|
|
47589
|
+
payload: { sessionId: this.sessionId }
|
|
47590
|
+
});
|
|
47591
|
+
if (!response.success || !response.result) {
|
|
47592
|
+
throw new Error(response.error || `Terminal screen unavailable for ${this.sessionId}`);
|
|
47593
|
+
}
|
|
47594
|
+
return response.result;
|
|
47595
|
+
}
|
|
47596
|
+
async readScreenText() {
|
|
47597
|
+
return (await this.readSnapshot()).text;
|
|
47598
|
+
}
|
|
47599
|
+
async readState() {
|
|
47600
|
+
return (await this.readSnapshot()).state;
|
|
47601
|
+
}
|
|
47602
|
+
async writeInput(text) {
|
|
47603
|
+
if (this.mode !== "write") throw new Error("Raw terminal attachment is read-only");
|
|
47604
|
+
const response = await this.client.request({
|
|
47605
|
+
type: "send_input",
|
|
47606
|
+
payload: {
|
|
47607
|
+
sessionId: this.sessionId,
|
|
47608
|
+
clientId: this.clientId,
|
|
47609
|
+
data: text
|
|
47610
|
+
}
|
|
47611
|
+
});
|
|
47612
|
+
if (!response.success) throw new Error(response.error || `Failed to write terminal input to ${this.sessionId}`);
|
|
47613
|
+
}
|
|
47614
|
+
async writeKeys(keys) {
|
|
47615
|
+
await this.writeInput(namedKeysToAnsi(keys));
|
|
47616
|
+
}
|
|
47617
|
+
async close() {
|
|
47618
|
+
if (this.closed) return;
|
|
47619
|
+
this.closed = true;
|
|
47620
|
+
if (this.mode === "write") {
|
|
47621
|
+
await this.client.request({
|
|
47622
|
+
type: "release_write",
|
|
47623
|
+
payload: { sessionId: this.sessionId, clientId: this.clientId }
|
|
47624
|
+
}).catch(() => ({ success: false }));
|
|
47625
|
+
}
|
|
47626
|
+
await this.client.request({
|
|
47627
|
+
type: "detach_session",
|
|
47628
|
+
payload: { sessionId: this.sessionId, clientId: this.clientId }
|
|
47629
|
+
}).catch(() => ({ success: false }));
|
|
47630
|
+
await this.client.close().catch(() => {
|
|
47631
|
+
});
|
|
47632
|
+
}
|
|
47633
|
+
};
|
|
47634
|
+
async function withRawTerminalAttachment(options, operation) {
|
|
47635
|
+
const attachment = await RawTerminalAttachment.attach(options);
|
|
47636
|
+
try {
|
|
47637
|
+
return await operation(attachment);
|
|
47638
|
+
} finally {
|
|
47639
|
+
await attachment.close();
|
|
47640
|
+
}
|
|
47641
|
+
}
|
|
47642
|
+
|
|
47433
47643
|
// src/session-host/app-name.ts
|
|
47434
47644
|
var DEFAULT_SESSION_HOST_APP_NAME = "adhdev";
|
|
47435
47645
|
var DEFAULT_STANDALONE_SESSION_HOST_APP_NAME = "adhdev-standalone";
|
|
@@ -47463,7 +47673,7 @@ function resolveSessionHostAppName(options = {}) {
|
|
|
47463
47673
|
|
|
47464
47674
|
// src/session-host/runtime-support.ts
|
|
47465
47675
|
import {
|
|
47466
|
-
SessionHostClient as
|
|
47676
|
+
SessionHostClient as SessionHostClient3,
|
|
47467
47677
|
getDefaultSessionHostEndpoint
|
|
47468
47678
|
} from "@adhdev/session-host-core";
|
|
47469
47679
|
var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
|
|
@@ -47493,7 +47703,7 @@ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
|
|
|
47493
47703
|
}
|
|
47494
47704
|
}
|
|
47495
47705
|
async function canConnect(endpoint, requiredRequestTypes = []) {
|
|
47496
|
-
const client = new
|
|
47706
|
+
const client = new SessionHostClient3({ endpoint });
|
|
47497
47707
|
try {
|
|
47498
47708
|
await client.connect();
|
|
47499
47709
|
await assertRequiredRequestTypes(client, requiredRequestTypes);
|
|
@@ -47523,7 +47733,7 @@ async function ensureSessionHostReady(options) {
|
|
|
47523
47733
|
return endpoint;
|
|
47524
47734
|
}
|
|
47525
47735
|
async function listHostedCliRuntimes(endpoint) {
|
|
47526
|
-
const client = new
|
|
47736
|
+
const client = new SessionHostClient3({ endpoint });
|
|
47527
47737
|
try {
|
|
47528
47738
|
const response = await client.request({
|
|
47529
47739
|
type: "list_sessions",
|
|
@@ -48397,6 +48607,7 @@ export {
|
|
|
48397
48607
|
ProviderCliAdapter,
|
|
48398
48608
|
ProviderInstanceManager,
|
|
48399
48609
|
ProviderLoader,
|
|
48610
|
+
RawTerminalAttachment,
|
|
48400
48611
|
STANDALONE_CDP_SCAN_INTERVAL_MS,
|
|
48401
48612
|
SessionHostPtyTransportFactory,
|
|
48402
48613
|
SpecDriver,
|
|
@@ -48547,6 +48758,8 @@ export {
|
|
|
48547
48758
|
markSetupComplete,
|
|
48548
48759
|
markStaleDirectDispatches,
|
|
48549
48760
|
maybeRunDaemonUpgradeHelperFromEnv,
|
|
48761
|
+
namedKeyToAnsi,
|
|
48762
|
+
namedKeysToAnsi,
|
|
48550
48763
|
normalizeActiveChatData,
|
|
48551
48764
|
normalizeChatMessage,
|
|
48552
48765
|
normalizeChatMessageKind,
|
|
@@ -48627,6 +48840,7 @@ export {
|
|
|
48627
48840
|
validateCliProviderManifest,
|
|
48628
48841
|
validateMeshRefineConfig,
|
|
48629
48842
|
validateMeshTaskModeRequest,
|
|
48630
|
-
validateMeshWorktreeBootstrapConfig
|
|
48843
|
+
validateMeshWorktreeBootstrapConfig,
|
|
48844
|
+
withRawTerminalAttachment
|
|
48631
48845
|
};
|
|
48632
48846
|
//# sourceMappingURL=index.mjs.map
|