@adhdev/daemon-core 0.9.82-rc.136 → 0.9.82-rc.138

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.
Files changed (63) hide show
  1. package/dist/chat/source-machine.d.ts +166 -0
  2. package/dist/chat/source-resolver.d.ts +104 -0
  3. package/dist/cli-adapters/cli-script-runner.d.ts +45 -0
  4. package/dist/cli-adapters/cli-state-engine.d.ts +169 -0
  5. package/dist/cli-adapters/provider-cli-adapter.d.ts +72 -74
  6. package/dist/cli-adapters/provider-cli-parse.d.ts +1 -0
  7. package/dist/cli-adapters/provider-cli-shared.d.ts +5 -0
  8. package/dist/config/chat-history.d.ts +1 -0
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +3507 -2288
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +3515 -2301
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/mesh/beads-db.d.ts +54 -0
  15. package/dist/mesh/contracts.d.ts +164 -0
  16. package/dist/mesh/mesh-active-work.d.ts +7 -1
  17. package/dist/mesh/mesh-events.d.ts +10 -4
  18. package/dist/mesh/mesh-ledger.d.ts +21 -1
  19. package/dist/mesh/mesh-refine-status.d.ts +2 -3
  20. package/dist/mesh/mesh-work-queue.d.ts +17 -0
  21. package/dist/mesh/worktree-bootstrap-config.d.ts +2 -4
  22. package/dist/providers/contracts.d.ts +19 -0
  23. package/dist/providers/read-chat-contract.d.ts +29 -0
  24. package/dist/providers/transcript-v2.d.ts +176 -0
  25. package/dist/repo-mesh-types.d.ts +5 -0
  26. package/dist/shared-types.d.ts +7 -0
  27. package/dist/status/snapshot.d.ts +1 -0
  28. package/dist/types.d.ts +5 -0
  29. package/package.json +1 -1
  30. package/src/chat/source-machine.ts +534 -0
  31. package/src/chat/source-resolver.ts +0 -0
  32. package/src/chat/subscription-updates.ts +9 -0
  33. package/src/cli-adapters/cli-script-runner.ts +145 -0
  34. package/src/cli-adapters/cli-state-engine.ts +1054 -0
  35. package/src/cli-adapters/provider-cli-adapter.d.ts +0 -1
  36. package/src/cli-adapters/provider-cli-adapter.ts +413 -1399
  37. package/src/cli-adapters/provider-cli-parse.ts +3 -0
  38. package/src/cli-adapters/provider-cli-shared.ts +17 -1
  39. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +17 -1
  40. package/src/cli-adapters/terminal-backends/xterm-backend.ts +8 -1
  41. package/src/commands/chat-commands.ts +715 -368
  42. package/src/commands/router.ts +22 -2
  43. package/src/config/chat-history.ts +43 -16
  44. package/src/git/git-worktree.ts +8 -1
  45. package/src/index.ts +3 -2
  46. package/src/mesh/beads-db.ts +305 -2
  47. package/src/mesh/contracts.ts +329 -0
  48. package/src/mesh/coordinator-prompt.ts +12 -17
  49. package/src/mesh/mesh-active-work.ts +162 -59
  50. package/src/mesh/mesh-events.ts +198 -53
  51. package/src/mesh/mesh-ledger.ts +321 -105
  52. package/src/mesh/mesh-refine-status.ts +2 -3
  53. package/src/mesh/mesh-work-queue.ts +116 -120
  54. package/src/mesh/worktree-bootstrap-config.ts +17 -4
  55. package/src/providers/contracts.ts +19 -0
  56. package/src/providers/provider-loader.ts +21 -7
  57. package/src/providers/provider-schema.ts +12 -0
  58. package/src/providers/read-chat-contract.ts +74 -14
  59. package/src/providers/transcript-v2.ts +567 -0
  60. package/src/repo-mesh-types.ts +10 -0
  61. package/src/shared-types.ts +7 -0
  62. package/src/status/snapshot.ts +35 -11
  63. package/src/types.ts +5 -0
@@ -0,0 +1,145 @@
1
+ /**
2
+ * CliScriptRunner — isolated execution of provider CLI scripts
3
+ *
4
+ * Responsible solely for invoking provider-supplied JavaScript functions
5
+ * (detectStatus, parseApproval, parseSession, etc.) and managing the
6
+ * per-session script state created by createState().
7
+ *
8
+ * The runner is stateless with respect to PTY / buffer content — all
9
+ * input data is passed explicitly by the caller so that the adapter can
10
+ * remain a pure transport layer without embedding parsing logic.
11
+ */
12
+
13
+ import { LOG } from '../logging/logger.js';
14
+ import {
15
+ listCliScriptNames,
16
+ type CliApprovalInput,
17
+ type CliScripts,
18
+ type CliScriptInput,
19
+ type CliScreenSnapshot,
20
+ type CliStatusInput,
21
+ type ParsedSession,
22
+ } from './provider-cli-shared.js';
23
+
24
+ export class CliScriptRunner {
25
+ private scripts: CliScripts = {};
26
+ private scriptState: unknown = null;
27
+ private _parseErrorMessage: string | null = null;
28
+ private readonly cliType: string;
29
+
30
+ constructor(cliType: string) {
31
+ this.cliType = cliType;
32
+ }
33
+
34
+ // ─── Script lifecycle ─────────────────────────────
35
+
36
+ setScripts(scripts: CliScripts): void {
37
+ this.scripts = scripts;
38
+ this._parseErrorMessage = null;
39
+ this.scriptState = typeof scripts.createState === 'function'
40
+ ? (scripts.createState() ?? null)
41
+ : null;
42
+ }
43
+
44
+ /** Reset per-session state — called when the PTY process exits. */
45
+ resetSessionState(): void {
46
+ this.scriptState = null;
47
+ }
48
+
49
+ // ─── Script access (for reflection and test patching) ────────────────────
50
+
51
+ /** Returns the live scripts object. Direct property assignment on this object
52
+ * patches individual scripts without replacing others (used in tests). */
53
+ get cliScripts(): CliScripts { return this.scripts; }
54
+
55
+ // ─── Capability checks ────────────────────────────
56
+
57
+ hasDetectStatus(): boolean {
58
+ return typeof this.scripts.detectStatus === 'function';
59
+ }
60
+
61
+ hasParseSession(): boolean {
62
+ return typeof this.scripts.parseSession === 'function';
63
+ }
64
+
65
+ getScriptNames(): string[] {
66
+ return listCliScriptNames(this.scripts);
67
+ }
68
+
69
+ // ─── Error state ──────────────────────────────────
70
+
71
+ get parseErrorMessage(): string | null {
72
+ return this._parseErrorMessage;
73
+ }
74
+
75
+ clearParseError(): void {
76
+ this._parseErrorMessage = null;
77
+ }
78
+
79
+ // ─── Script invocation ────────────────────────────
80
+
81
+ detectStatus(input: CliStatusInput): string | null {
82
+ if (!this.scripts.detectStatus) return null;
83
+ try {
84
+ return this.invoke<string | null>(this.scripts.detectStatus, input);
85
+ } catch (e: any) {
86
+ LOG.warn('CLI', `[${this.cliType}] detectStatus error: ${e?.message || e}`);
87
+ return null;
88
+ }
89
+ }
90
+
91
+ parseApproval(
92
+ input: CliApprovalInput,
93
+ ): { message: string; buttons: string[] } | null {
94
+ if (!this.scripts.parseApproval) return null;
95
+ try {
96
+ return this.invoke<{ message: string; buttons: string[] } | null>(
97
+ this.scripts.parseApproval,
98
+ input,
99
+ );
100
+ } catch (e: any) {
101
+ LOG.warn('CLI', `[${this.cliType}] parseApproval error: ${e?.message || e}`);
102
+ return null;
103
+ }
104
+ }
105
+
106
+ parseSession(
107
+ input: CliScriptInput & { tail?: string; tailScreen?: CliScreenSnapshot },
108
+ ): ParsedSession | null {
109
+ if (!this.scripts.parseSession) {
110
+ this._parseErrorMessage = `${this.cliType} parseSession unavailable`;
111
+ return null;
112
+ }
113
+ try {
114
+ const result = this.invoke<ParsedSession | null>(this.scripts.parseSession, input);
115
+ this._parseErrorMessage = null;
116
+ return result && typeof result === 'object' ? result : null;
117
+ } catch (e: any) {
118
+ this._parseErrorMessage = e?.message || String(e);
119
+ LOG.warn('CLI', `[${this.cliType}] parseSession error: ${this._parseErrorMessage}`);
120
+ return null;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Invoke an arbitrary named script (e.g. setModel, openModelPicker).
126
+ * Throws if the script is not available.
127
+ */
128
+ invokeByName(name: string, input: any): any {
129
+ const fn = this.scripts[name];
130
+ if (typeof fn !== 'function') {
131
+ throw new Error(`CLI script '${name}' not available`);
132
+ }
133
+ return this.invoke(fn, input);
134
+ }
135
+
136
+ // ─── Internal ─────────────────────────────────────
137
+
138
+ private invoke<T>(fn: Function, input: any): T {
139
+ const hasStateFactory = typeof this.scripts.createState === 'function';
140
+ const expectsState = hasStateFactory || this.scriptState !== null || fn.length >= 2;
141
+ return expectsState
142
+ ? (fn as (state: unknown, input: any) => T)(this.scriptState, input)
143
+ : (fn as (input: any) => T)(input);
144
+ }
145
+ }