@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.
@@ -77,6 +77,8 @@ export declare class ProviderCliAdapter implements CliAdapter {
77
77
  private resizeSuppressUntil;
78
78
  private statusHistory;
79
79
  private cliScripts;
80
+ /** Per-session opaque state object created by cliScripts.createState(), reset on stop. */
81
+ private scriptState;
80
82
  private runtimeSettings;
81
83
  /** Full accumulated rendered PTY transcript for parser/readback use */
82
84
  private accumulatedBuffer;
@@ -63,17 +63,27 @@ export interface ParsedSession {
63
63
  coverage?: 'full' | 'tail' | 'current-turn';
64
64
  }
65
65
  export interface CliScripts {
66
- parseSession?: (input: CliScriptInput & {
66
+ /**
67
+ * Optional state factory. Called once per CLI session start (or script reload).
68
+ * The returned object is passed as the first argument to detectStatus, parseApproval,
69
+ * and parseSession on every invocation, allowing scripts to maintain per-session state
70
+ * (e.g. last-seen status, approval fingerprints, stability counters).
71
+ *
72
+ * Scripts that don't define createState() receive null as the state argument,
73
+ * making this change fully backward compatible.
74
+ */
75
+ createState?: () => unknown;
76
+ parseSession?: (state: unknown, input: CliScriptInput & {
67
77
  tail?: string;
68
78
  tailScreen?: CliScreenSnapshot;
69
79
  }) => ParsedSession | null;
70
- detectStatus?: (input: CliStatusInput) => string | null;
71
- parseApproval?: (input: CliApprovalInput) => {
80
+ detectStatus?: (state: unknown, input: CliStatusInput) => string | null;
81
+ parseApproval?: (state: unknown, input: CliApprovalInput) => {
72
82
  message: string;
73
83
  buttons: string[];
74
84
  } | null;
75
85
  resolveAction?: (data: any) => string;
76
- [name: string]: ((input: any) => any) | undefined;
86
+ [name: string]: ((state: unknown, input: any) => any) | ((data: any) => any) | (() => unknown) | undefined;
77
87
  }
78
88
  export interface CliScreenLine {
79
89
  index: number;
package/dist/index.js CHANGED
@@ -2699,6 +2699,8 @@ var init_provider_cli_adapter = __esm({
2699
2699
  statusHistory = [];
2700
2700
  // ─── CLI Scripts (script-based parsing) ───
2701
2701
  cliScripts;
2702
+ /** Per-session opaque state object created by cliScripts.createState(), reset on stop. */
2703
+ scriptState = null;
2702
2704
  runtimeSettings = {};
2703
2705
  /** Full accumulated rendered PTY transcript for parser/readback use */
2704
2706
  accumulatedBuffer = "";
@@ -2880,6 +2882,7 @@ ${lastSnapshot}`;
2880
2882
  this.cliScripts = scripts;
2881
2883
  this.parsedStatusCache = null;
2882
2884
  this.parseErrorMessage = null;
2885
+ this.scriptState = typeof scripts.createState === "function" ? scripts.createState() : null;
2883
2886
  const scriptNames = listCliScriptNames(scripts);
2884
2887
  LOG.info("CLI", `[${this.cliType}] CLI scripts injected: [${scriptNames.join(", ")}]`);
2885
2888
  }
@@ -2997,6 +3000,7 @@ ${lastSnapshot}`;
2997
3000
  this.ready = false;
2998
3001
  this.startupParseGate = false;
2999
3002
  this.spawnAt = 0;
3003
+ this.scriptState = null;
3000
3004
  this.onStatusChange?.();
3001
3005
  });
3002
3006
  this.spawnAt = Date.now();
@@ -3770,7 +3774,7 @@ ${lastSnapshot}`;
3770
3774
  scope: this.currentTurnScope,
3771
3775
  runtimeSettings: this.runtimeSettings
3772
3776
  });
3773
- const session = this.cliScripts.parseSession({ ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
3777
+ const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
3774
3778
  this.parseErrorMessage = null;
3775
3779
  return session && typeof session === "object" ? session : null;
3776
3780
  } catch (e) {
@@ -3784,7 +3788,7 @@ ${lastSnapshot}`;
3784
3788
  if (!this.cliScripts?.detectStatus) return null;
3785
3789
  try {
3786
3790
  const screenText = this.terminalScreen.getText();
3787
- const status = this.cliScripts.detectStatus({
3791
+ const status = this.cliScripts.detectStatus(this.scriptState, {
3788
3792
  tail: text.slice(-500),
3789
3793
  screenText,
3790
3794
  rawBuffer: this.accumulatedRawBuffer,
@@ -3803,7 +3807,7 @@ ${lastSnapshot}`;
3803
3807
  try {
3804
3808
  const screenText = this.terminalScreen.getText();
3805
3809
  const buffer = screenText || this.accumulatedBuffer;
3806
- return this.cliScripts.parseApproval({
3810
+ return this.cliScripts.parseApproval(this.scriptState, {
3807
3811
  buffer,
3808
3812
  screenText,
3809
3813
  rawBuffer: this.accumulatedRawBuffer,
@@ -3911,7 +3915,7 @@ ${lastSnapshot}`;
3911
3915
  scope: this.currentTurnScope,
3912
3916
  runtimeSettings: this.runtimeSettings
3913
3917
  });
3914
- return await Promise.resolve(fn({
3918
+ return await Promise.resolve(fn(this.scriptState, {
3915
3919
  ...input,
3916
3920
  args: args && typeof args === "object" ? { ...args } : {}
3917
3921
  }));