@adhdev/daemon-core 0.9.77-rc.7 → 0.9.77-rc.8
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 +2 -0
- package/dist/cli-adapters/provider-cli-shared.d.ts +14 -4
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +10 -4
- package/src/cli-adapters/provider-cli-shared.ts +14 -4
package/package.json
CHANGED
|
@@ -195,6 +195,8 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
195
195
|
|
|
196
196
|
// ─── CLI Scripts (script-based parsing) ───
|
|
197
197
|
private cliScripts: CliScripts;
|
|
198
|
+
/** Per-session opaque state object created by cliScripts.createState(), reset on stop. */
|
|
199
|
+
private scriptState: unknown = null;
|
|
198
200
|
private runtimeSettings: Record<string, any> = {};
|
|
199
201
|
/** Full accumulated rendered PTY transcript for parser/readback use */
|
|
200
202
|
private accumulatedBuffer: string = '';
|
|
@@ -477,6 +479,9 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
477
479
|
this.cliScripts = scripts;
|
|
478
480
|
this.parsedStatusCache = null;
|
|
479
481
|
this.parseErrorMessage = null;
|
|
482
|
+
// Initialize per-session state: createState() is called once here and on script reload.
|
|
483
|
+
// The returned object lives until the PTY exits (scriptState = null on exit).
|
|
484
|
+
this.scriptState = typeof scripts.createState === 'function' ? scripts.createState() : null;
|
|
480
485
|
const scriptNames = listCliScriptNames(scripts);
|
|
481
486
|
LOG.info('CLI', `[${this.cliType}] CLI scripts injected: [${scriptNames.join(', ')}]`);
|
|
482
487
|
}
|
|
@@ -610,6 +615,7 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
610
615
|
this.ready = false;
|
|
611
616
|
this.startupParseGate = false;
|
|
612
617
|
this.spawnAt = 0;
|
|
618
|
+
this.scriptState = null;
|
|
613
619
|
this.onStatusChange?.();
|
|
614
620
|
});
|
|
615
621
|
|
|
@@ -1470,7 +1476,7 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
1470
1476
|
scope: this.currentTurnScope,
|
|
1471
1477
|
runtimeSettings: this.runtimeSettings,
|
|
1472
1478
|
});
|
|
1473
|
-
const session = this.cliScripts.parseSession({ ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
1479
|
+
const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
1474
1480
|
this.parseErrorMessage = null;
|
|
1475
1481
|
return session && typeof session === 'object' ? session : null;
|
|
1476
1482
|
} catch (e: any) {
|
|
@@ -1485,7 +1491,7 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
1485
1491
|
if (!this.cliScripts?.detectStatus) return null;
|
|
1486
1492
|
try {
|
|
1487
1493
|
const screenText = this.terminalScreen.getText();
|
|
1488
|
-
const status = this.cliScripts.detectStatus({
|
|
1494
|
+
const status = this.cliScripts.detectStatus(this.scriptState, {
|
|
1489
1495
|
tail: text.slice(-500),
|
|
1490
1496
|
screenText,
|
|
1491
1497
|
rawBuffer: this.accumulatedRawBuffer,
|
|
@@ -1505,7 +1511,7 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
1505
1511
|
try {
|
|
1506
1512
|
const screenText = this.terminalScreen.getText();
|
|
1507
1513
|
const buffer = screenText || this.accumulatedBuffer;
|
|
1508
|
-
return this.cliScripts.parseApproval({
|
|
1514
|
+
return this.cliScripts.parseApproval(this.scriptState, {
|
|
1509
1515
|
buffer,
|
|
1510
1516
|
screenText,
|
|
1511
1517
|
rawBuffer: this.accumulatedRawBuffer,
|
|
@@ -1640,7 +1646,7 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
1640
1646
|
scope: this.currentTurnScope,
|
|
1641
1647
|
runtimeSettings: this.runtimeSettings,
|
|
1642
1648
|
});
|
|
1643
|
-
return await Promise.resolve(fn({
|
|
1649
|
+
return await Promise.resolve(fn(this.scriptState, {
|
|
1644
1650
|
...input,
|
|
1645
1651
|
args: args && typeof args === 'object' ? { ...args } : {},
|
|
1646
1652
|
}));
|
|
@@ -48,11 +48,21 @@ export interface ParsedSession {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export interface CliScripts {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Optional state factory. Called once per CLI session start (or script reload).
|
|
53
|
+
* The returned object is passed as the first argument to detectStatus, parseApproval,
|
|
54
|
+
* and parseSession on every invocation, allowing scripts to maintain per-session state
|
|
55
|
+
* (e.g. last-seen status, approval fingerprints, stability counters).
|
|
56
|
+
*
|
|
57
|
+
* Scripts that don't define createState() receive null as the state argument,
|
|
58
|
+
* making this change fully backward compatible.
|
|
59
|
+
*/
|
|
60
|
+
createState?: () => unknown;
|
|
61
|
+
parseSession?: (state: unknown, input: CliScriptInput & { tail?: string; tailScreen?: CliScreenSnapshot }) => ParsedSession | null;
|
|
62
|
+
detectStatus?: (state: unknown, input: CliStatusInput) => string | null;
|
|
63
|
+
parseApproval?: (state: unknown, input: CliApprovalInput) => { message: string; buttons: string[] } | null;
|
|
54
64
|
resolveAction?: (data: any) => string;
|
|
55
|
-
[name: string]: ((input: any) => any) | undefined;
|
|
65
|
+
[name: string]: ((state: unknown, input: any) => any) | ((data: any) => any) | (() => unknown) | undefined;
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
export interface CliScreenLine {
|