@adhdev/daemon-core 0.9.12 → 0.9.14
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/provider-cli-adapter.d.ts +3 -1
- package/dist/cli-adapters/pty-transport.d.ts +1 -1
- package/dist/commands/stream-commands.d.ts +1 -1
- package/dist/index.js +86 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -45
- package/dist/index.mjs.map +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.d.ts +3 -1
- package/src/cli-adapters/provider-cli-adapter.ts +65 -37
- package/src/cli-adapters/pty-transport.d.ts +1 -1
- package/src/cli-adapters/pty-transport.ts +1 -1
- package/src/cli-adapters/session-host-transport.ts +8 -7
- package/src/commands/router.ts +7 -1
- package/src/commands/stream-commands.d.ts +1 -1
- package/src/commands/stream-commands.ts +3 -3
- package/src/daemon/dev-cli-debug.ts +1 -1
- package/src/providers/cli-provider-instance.ts +1 -1
|
@@ -165,6 +165,8 @@ export declare class ProviderCliAdapter implements CliAdapter {
|
|
|
165
165
|
* Uses resolveAction script if available, otherwise falls back to standard text.
|
|
166
166
|
*/
|
|
167
167
|
resolveAction(data: any): Promise<void>;
|
|
168
|
+
private writeToPty;
|
|
169
|
+
private resetPendingSendState;
|
|
168
170
|
sendMessage(text: string): Promise<void>;
|
|
169
171
|
getPartialResponse(): string;
|
|
170
172
|
getRuntimeMetadata(): PtyRuntimeMetadata | null;
|
|
@@ -177,7 +179,7 @@ export declare class ProviderCliAdapter implements CliAdapter {
|
|
|
177
179
|
clearHistory(): void;
|
|
178
180
|
isProcessing(): boolean;
|
|
179
181
|
isReady(): boolean;
|
|
180
|
-
writeRaw(data: string): void
|
|
182
|
+
writeRaw(data: string): Promise<void>;
|
|
181
183
|
resolveModal(buttonIndex: number): void;
|
|
182
184
|
resize(cols: number, rows: number): void;
|
|
183
185
|
getDebugState(): Record<string, any>;
|
|
@@ -30,7 +30,7 @@ export interface PtyRuntimeTransport {
|
|
|
30
30
|
readonly pid: number;
|
|
31
31
|
readonly ready: Promise<void>;
|
|
32
32
|
readonly terminalQueriesHandled?: boolean;
|
|
33
|
-
write(data: string): void
|
|
33
|
+
write(data: string): void | Promise<void>;
|
|
34
34
|
resize(cols: number, rows: number): void;
|
|
35
35
|
kill(): void;
|
|
36
36
|
clearBuffer?(): void;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { CommandResult, CommandHelpers } from './handler.js';
|
|
6
6
|
export declare function handleSelectSession(h: CommandHelpers, args: any): Promise<CommandResult>;
|
|
7
7
|
export declare function handleOpenPanel(h: CommandHelpers, args: any): Promise<CommandResult>;
|
|
8
|
-
export declare function handlePtyInput(h: CommandHelpers, args: any): CommandResult
|
|
8
|
+
export declare function handlePtyInput(h: CommandHelpers, args: any): Promise<CommandResult>;
|
|
9
9
|
export declare function handlePtyResize(_h: CommandHelpers, args: any): CommandResult;
|
|
10
10
|
export declare function handleGetProviderSettings(h: CommandHelpers, args: any): CommandResult;
|
|
11
11
|
export declare function handleSetProviderSetting(h: CommandHelpers, args: any): Promise<CommandResult>;
|
package/dist/index.js
CHANGED
|
@@ -3396,6 +3396,29 @@ var init_provider_cli_adapter = __esm({
|
|
|
3396
3396
|
}
|
|
3397
3397
|
await this.sendMessage(promptText);
|
|
3398
3398
|
}
|
|
3399
|
+
async writeToPty(data) {
|
|
3400
|
+
if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
|
|
3401
|
+
await this.ptyProcess.write(data);
|
|
3402
|
+
}
|
|
3403
|
+
resetPendingSendState(reason) {
|
|
3404
|
+
this.isWaitingForResponse = false;
|
|
3405
|
+
this.responseBuffer = "";
|
|
3406
|
+
this.currentTurnScope = null;
|
|
3407
|
+
this.submitPendingUntil = 0;
|
|
3408
|
+
this.clearIdleFinishCandidate(reason);
|
|
3409
|
+
if (this.responseTimeout) {
|
|
3410
|
+
clearTimeout(this.responseTimeout);
|
|
3411
|
+
this.responseTimeout = null;
|
|
3412
|
+
}
|
|
3413
|
+
if (this.submitRetryTimer) {
|
|
3414
|
+
clearTimeout(this.submitRetryTimer);
|
|
3415
|
+
this.submitRetryTimer = null;
|
|
3416
|
+
}
|
|
3417
|
+
if (this.finishRetryTimer) {
|
|
3418
|
+
clearTimeout(this.finishRetryTimer);
|
|
3419
|
+
this.finishRetryTimer = null;
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3399
3422
|
async sendMessage(text) {
|
|
3400
3423
|
if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
|
|
3401
3424
|
const allowInputDuringGeneration = this.provider.allowInputDuringGeneration === true;
|
|
@@ -3490,19 +3513,29 @@ var init_provider_cli_adapter = __esm({
|
|
|
3490
3513
|
if (this.isWaitingForResponse) this.finishResponse();
|
|
3491
3514
|
}, this.timeouts.maxResponse);
|
|
3492
3515
|
};
|
|
3493
|
-
await new Promise((resolve12) => {
|
|
3516
|
+
await new Promise((resolve12, reject) => {
|
|
3494
3517
|
let resolved = false;
|
|
3495
3518
|
const resolveOnce = () => {
|
|
3496
3519
|
if (resolved) return;
|
|
3497
3520
|
resolved = true;
|
|
3498
3521
|
resolve12();
|
|
3499
3522
|
};
|
|
3523
|
+
const rejectOnce = (error) => {
|
|
3524
|
+
if (resolved) return;
|
|
3525
|
+
this.resetPendingSendState("send_write_failed");
|
|
3526
|
+
resolved = true;
|
|
3527
|
+
reject(error);
|
|
3528
|
+
};
|
|
3529
|
+
const writeRetryKey = (mode) => {
|
|
3530
|
+
void this.writeToPty(this.sendKey).catch((error) => {
|
|
3531
|
+
LOG.warn("CLI", `[${this.cliType}] ${mode} write failed: ${error?.message || error}`);
|
|
3532
|
+
});
|
|
3533
|
+
};
|
|
3500
3534
|
const submit = () => {
|
|
3501
3535
|
if (!this.ptyProcess) {
|
|
3502
3536
|
resolveOnce();
|
|
3503
3537
|
return;
|
|
3504
3538
|
}
|
|
3505
|
-
commitUserTurn();
|
|
3506
3539
|
this.submitPendingUntil = 0;
|
|
3507
3540
|
const screenText = this.terminalScreen.getText();
|
|
3508
3541
|
this.recordTrace("submit_write", {
|
|
@@ -3510,7 +3543,6 @@ var init_provider_cli_adapter = __esm({
|
|
|
3510
3543
|
sendKey: this.sendKey,
|
|
3511
3544
|
screenText: summarizeCliTraceText(screenText, 500)
|
|
3512
3545
|
});
|
|
3513
|
-
this.ptyProcess.write(this.sendKey);
|
|
3514
3546
|
const retrySubmitIfStuck = (attempt) => {
|
|
3515
3547
|
this.submitRetryTimer = null;
|
|
3516
3548
|
if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
|
|
@@ -3530,19 +3562,21 @@ var init_provider_cli_adapter = __esm({
|
|
|
3530
3562
|
sendKey: this.sendKey,
|
|
3531
3563
|
screenText: summarizeCliTraceText(screenText2, 500)
|
|
3532
3564
|
});
|
|
3533
|
-
|
|
3565
|
+
writeRetryKey("submit_retry");
|
|
3534
3566
|
if (attempt >= 3) {
|
|
3535
3567
|
this.submitRetryUsed = true;
|
|
3536
3568
|
return;
|
|
3537
3569
|
}
|
|
3538
3570
|
this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
|
|
3539
3571
|
};
|
|
3540
|
-
this.
|
|
3541
|
-
|
|
3542
|
-
|
|
3572
|
+
void this.writeToPty(this.sendKey).then(() => {
|
|
3573
|
+
commitUserTurn();
|
|
3574
|
+
this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
|
|
3575
|
+
startResponseTimeout();
|
|
3576
|
+
resolveOnce();
|
|
3577
|
+
}, rejectOnce);
|
|
3543
3578
|
};
|
|
3544
3579
|
if (this.submitStrategy === "immediate") {
|
|
3545
|
-
commitUserTurn();
|
|
3546
3580
|
this.submitPendingUntil = 0;
|
|
3547
3581
|
this.recordTrace("submit_write", {
|
|
3548
3582
|
mode: "immediate",
|
|
@@ -3550,37 +3584,38 @@ var init_provider_cli_adapter = __esm({
|
|
|
3550
3584
|
sendKey: this.sendKey,
|
|
3551
3585
|
screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
|
|
3552
3586
|
});
|
|
3553
|
-
this.
|
|
3554
|
-
|
|
3555
|
-
this.submitRetryTimer =
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3587
|
+
void this.writeToPty(text + this.sendKey).then(() => {
|
|
3588
|
+
commitUserTurn();
|
|
3589
|
+
this.submitRetryTimer = setTimeout(() => {
|
|
3590
|
+
this.submitRetryTimer = null;
|
|
3591
|
+
if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
|
|
3592
|
+
if (this.currentStatus === "waiting_approval") return;
|
|
3593
|
+
if (this.hasMeaningfulResponseBuffer(normalizedPromptSnippet)) return;
|
|
3594
|
+
const screenText = this.terminalScreen.getText();
|
|
3595
|
+
if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
|
|
3596
|
+
const liveApproval = this.runParseApproval(screenText) || this.runParseApproval(this.recentOutputBuffer);
|
|
3597
|
+
if (liveApproval) return;
|
|
3598
|
+
const liveStatus = this.runDetectStatus(screenText) || this.runDetectStatus(this.recentOutputBuffer);
|
|
3599
|
+
if (liveStatus === "generating" || liveStatus === "waiting_approval") return;
|
|
3600
|
+
LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
|
|
3601
|
+
this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
|
|
3602
|
+
this.recordTrace("submit_write", {
|
|
3603
|
+
mode: "immediate_retry",
|
|
3604
|
+
attempt: 1,
|
|
3605
|
+
sendKey: this.sendKey,
|
|
3606
|
+
screenText: summarizeCliTraceText(screenText, 500)
|
|
3607
|
+
});
|
|
3608
|
+
writeRetryKey("immediate_retry");
|
|
3609
|
+
this.submitRetryUsed = true;
|
|
3610
|
+
}, retryDelayMs);
|
|
3611
|
+
startResponseTimeout();
|
|
3612
|
+
resolveOnce();
|
|
3613
|
+
}, rejectOnce);
|
|
3578
3614
|
return;
|
|
3579
3615
|
}
|
|
3580
3616
|
if (submitDelayMs > 0) {
|
|
3581
3617
|
this.submitPendingUntil = Date.now() + submitDelayMs;
|
|
3582
3618
|
}
|
|
3583
|
-
this.ptyProcess.write(text);
|
|
3584
3619
|
this.recordTrace("submit_write", {
|
|
3585
3620
|
mode: "type_then_submit",
|
|
3586
3621
|
text: summarizeCliTraceText(text, 500),
|
|
@@ -3617,7 +3652,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
3617
3652
|
}
|
|
3618
3653
|
setTimeout(waitForEchoAndSubmit, 50);
|
|
3619
3654
|
};
|
|
3620
|
-
waitForEchoAndSubmit();
|
|
3655
|
+
void this.writeToPty(text).then(() => waitForEchoAndSubmit(), rejectOnce);
|
|
3621
3656
|
});
|
|
3622
3657
|
}
|
|
3623
3658
|
getPartialResponse() {
|
|
@@ -3772,12 +3807,12 @@ var init_provider_cli_adapter = __esm({
|
|
|
3772
3807
|
isReady() {
|
|
3773
3808
|
return this.ready;
|
|
3774
3809
|
}
|
|
3775
|
-
writeRaw(data) {
|
|
3810
|
+
async writeRaw(data) {
|
|
3776
3811
|
this.recordTrace("write_raw", {
|
|
3777
3812
|
keys: JSON.stringify(data),
|
|
3778
3813
|
length: data.length
|
|
3779
3814
|
});
|
|
3780
|
-
this.
|
|
3815
|
+
await this.writeToPty(data);
|
|
3781
3816
|
}
|
|
3782
3817
|
resolveModal(buttonIndex) {
|
|
3783
3818
|
let modal = this.activeModal || this.runParseApproval(this.recentOutputBuffer);
|
|
@@ -11779,14 +11814,14 @@ async function handleOpenPanel(h, args) {
|
|
|
11779
11814
|
success: revealState.visible || focusState.focused
|
|
11780
11815
|
};
|
|
11781
11816
|
}
|
|
11782
|
-
function handlePtyInput(h, args) {
|
|
11817
|
+
async function handlePtyInput(h, args) {
|
|
11783
11818
|
const { cliType, data, targetSessionId } = args || {};
|
|
11784
11819
|
if (!data) return { success: false, error: "data required" };
|
|
11785
11820
|
const adapter = h.getCliAdapter(targetSessionId || cliType);
|
|
11786
11821
|
if (!adapter || typeof adapter.writeRaw !== "function") {
|
|
11787
11822
|
return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
|
|
11788
11823
|
}
|
|
11789
|
-
adapter.writeRaw(data);
|
|
11824
|
+
await adapter.writeRaw(data);
|
|
11790
11825
|
return { success: true };
|
|
11791
11826
|
}
|
|
11792
11827
|
function handlePtyResize(_h, args) {
|
|
@@ -11963,7 +11998,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
11963
11998
|
if (cliCommand?.type === "send_message" && cliCommand.text) {
|
|
11964
11999
|
await adapter.sendMessage(cliCommand.text);
|
|
11965
12000
|
} else if (cliCommand?.type === "pty_write" && cliCommand.text && adapter.writeRaw) {
|
|
11966
|
-
adapter.writeRaw(cliCommand.text + "\r");
|
|
12001
|
+
await adapter.writeRaw(cliCommand.text + "\r");
|
|
11967
12002
|
}
|
|
11968
12003
|
applyProviderPatch(h, args, parsed.payload);
|
|
11969
12004
|
return {
|
|
@@ -13115,7 +13150,7 @@ var CliProviderInstance = class {
|
|
|
13115
13150
|
if (cliCommand?.type === "send_message" && cliCommand.text) {
|
|
13116
13151
|
await this.adapter.sendMessage(cliCommand.text);
|
|
13117
13152
|
} else if (cliCommand?.type === "pty_write" && cliCommand.text) {
|
|
13118
|
-
this.adapter.writeRaw(cliCommand.text + "\r");
|
|
13153
|
+
await this.adapter.writeRaw(cliCommand.text + "\r");
|
|
13119
13154
|
}
|
|
13120
13155
|
this.applyProviderResponse(parsed.payload, { phase: "immediate" });
|
|
13121
13156
|
}
|
|
@@ -18755,10 +18790,14 @@ var DaemonCommandRouter = class {
|
|
|
18755
18790
|
currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
|
|
18756
18791
|
} catch {
|
|
18757
18792
|
}
|
|
18758
|
-
|
|
18793
|
+
const runningVersion = typeof this.deps.statusVersion === "string" ? this.deps.statusVersion.trim().replace(/^v/, "") : null;
|
|
18794
|
+
if (currentInstalled === latest && runningVersion === latest) {
|
|
18759
18795
|
LOG.info("Upgrade", `Already on latest version v${latest}; skipping install`);
|
|
18760
18796
|
return { success: true, upgraded: false, alreadyLatest: true, version: latest };
|
|
18761
18797
|
}
|
|
18798
|
+
if (currentInstalled === latest && runningVersion && runningVersion !== latest) {
|
|
18799
|
+
LOG.info("Upgrade", `Installed package is v${latest}, but running daemon is v${runningVersion}; scheduling restart`);
|
|
18800
|
+
}
|
|
18762
18801
|
spawnDetachedDaemonUpgradeHelper({
|
|
18763
18802
|
packageName: pkgName,
|
|
18764
18803
|
targetVersion: latest,
|
|
@@ -22864,7 +22903,7 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
22864
22903
|
}
|
|
22865
22904
|
try {
|
|
22866
22905
|
if (typeof adapter.writeRaw === "function") {
|
|
22867
|
-
adapter.writeRaw(keys);
|
|
22906
|
+
await adapter.writeRaw(keys);
|
|
22868
22907
|
ctx.json(res, 200, { sent: true, type: target.type, instanceId: target.instanceId, keysLength: keys.length });
|
|
22869
22908
|
} else {
|
|
22870
22909
|
ctx.json(res, 400, { error: "writeRaw not available on this adapter" });
|
|
@@ -25791,7 +25830,7 @@ var SessionHostRuntimeTransport = class {
|
|
|
25791
25830
|
this.exitCallbacks.add(callback);
|
|
25792
25831
|
}
|
|
25793
25832
|
write(data) {
|
|
25794
|
-
this.enqueue(async () => {
|
|
25833
|
+
return this.enqueue(async () => {
|
|
25795
25834
|
let response = await this.client.request({
|
|
25796
25835
|
type: "send_input",
|
|
25797
25836
|
payload: {
|
|
@@ -26093,9 +26132,11 @@ var SessionHostRuntimeTransport = class {
|
|
|
26093
26132
|
};
|
|
26094
26133
|
}
|
|
26095
26134
|
enqueue(action) {
|
|
26096
|
-
|
|
26135
|
+
const operation = this.operationChain.then(() => this.ready).then(action);
|
|
26136
|
+
this.operationChain = operation.catch((error) => {
|
|
26097
26137
|
LOG.warn("CLI", `[session-host:${this.options.runtimeId}] ${error?.message || error}`);
|
|
26098
26138
|
});
|
|
26139
|
+
return operation;
|
|
26099
26140
|
}
|
|
26100
26141
|
async closeClient(destroy = false) {
|
|
26101
26142
|
if (this.closed) return;
|