deepclause-sdk 0.1.2 → 0.2.1

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 (122) hide show
  1. package/README.md +45 -6
  2. package/dist/cli/config.d.ts +2 -2
  3. package/dist/cli/repl.d.ts +55 -4
  4. package/dist/cli/repl.d.ts.map +1 -1
  5. package/dist/cli/repl.js +675 -52
  6. package/dist/cli/repl.js.map +1 -1
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +3 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/prolog-src/deepclause_mi.pl +516 -2
  12. package/dist/repl/backend.d.ts +9 -0
  13. package/dist/repl/backend.d.ts.map +1 -1
  14. package/dist/repl/backend.js +62 -5
  15. package/dist/repl/backend.js.map +1 -1
  16. package/dist/repl/harness-tools.d.ts +36 -0
  17. package/dist/repl/harness-tools.d.ts.map +1 -1
  18. package/dist/repl/harness-tools.js +173 -0
  19. package/dist/repl/harness-tools.js.map +1 -1
  20. package/dist/repl/history.d.ts +29 -0
  21. package/dist/repl/history.d.ts.map +1 -1
  22. package/dist/repl/history.js +71 -0
  23. package/dist/repl/history.js.map +1 -1
  24. package/dist/repl/index.d.ts +6 -0
  25. package/dist/repl/index.d.ts.map +1 -1
  26. package/dist/repl/index.js +9 -1
  27. package/dist/repl/index.js.map +1 -1
  28. package/dist/repl/picker.d.ts +3 -0
  29. package/dist/repl/picker.d.ts.map +1 -1
  30. package/dist/repl/picker.js +132 -0
  31. package/dist/repl/picker.js.map +1 -1
  32. package/dist/repl/process-backend.d.ts +31 -0
  33. package/dist/repl/process-backend.d.ts.map +1 -0
  34. package/dist/repl/process-backend.js +10 -0
  35. package/dist/repl/process-backend.js.map +1 -0
  36. package/dist/repl/process-executor.d.ts +67 -0
  37. package/dist/repl/process-executor.d.ts.map +1 -0
  38. package/dist/repl/process-executor.js +371 -0
  39. package/dist/repl/process-executor.js.map +1 -0
  40. package/dist/repl/process-worker.d.ts +10 -0
  41. package/dist/repl/process-worker.d.ts.map +1 -0
  42. package/dist/repl/process-worker.js +210 -0
  43. package/dist/repl/process-worker.js.map +1 -0
  44. package/dist/repl/processes.d.ts +282 -0
  45. package/dist/repl/processes.d.ts.map +1 -0
  46. package/dist/repl/processes.js +557 -0
  47. package/dist/repl/processes.js.map +1 -0
  48. package/dist/repl/render.d.ts +52 -2
  49. package/dist/repl/render.d.ts.map +1 -1
  50. package/dist/repl/render.js +52 -17
  51. package/dist/repl/render.js.map +1 -1
  52. package/dist/repl/session.d.ts +135 -3
  53. package/dist/repl/session.d.ts.map +1 -1
  54. package/dist/repl/session.js +413 -4
  55. package/dist/repl/session.js.map +1 -1
  56. package/dist/repl/status.d.ts +3 -1
  57. package/dist/repl/status.d.ts.map +1 -1
  58. package/dist/repl/status.js +4 -0
  59. package/dist/repl/status.js.map +1 -1
  60. package/dist/repl/tui/autocomplete.d.ts +19 -0
  61. package/dist/repl/tui/autocomplete.d.ts.map +1 -0
  62. package/dist/repl/tui/autocomplete.js +48 -0
  63. package/dist/repl/tui/autocomplete.js.map +1 -0
  64. package/dist/repl/tui/document.d.ts +51 -0
  65. package/dist/repl/tui/document.d.ts.map +1 -0
  66. package/dist/repl/tui/document.js +160 -0
  67. package/dist/repl/tui/document.js.map +1 -0
  68. package/dist/repl/tui/harness-view.d.ts +102 -0
  69. package/dist/repl/tui/harness-view.d.ts.map +1 -0
  70. package/dist/repl/tui/harness-view.js +323 -0
  71. package/dist/repl/tui/harness-view.js.map +1 -0
  72. package/dist/repl/tui/picker.d.ts +31 -0
  73. package/dist/repl/tui/picker.d.ts.map +1 -0
  74. package/dist/repl/tui/picker.js +43 -0
  75. package/dist/repl/tui/picker.js.map +1 -0
  76. package/dist/repl/tui/renderer.d.ts +98 -0
  77. package/dist/repl/tui/renderer.d.ts.map +1 -0
  78. package/dist/repl/tui/renderer.js +289 -0
  79. package/dist/repl/tui/renderer.js.map +1 -0
  80. package/dist/repl/tui/services-panel.d.ts +35 -0
  81. package/dist/repl/tui/services-panel.d.ts.map +1 -0
  82. package/dist/repl/tui/services-panel.js +108 -0
  83. package/dist/repl/tui/services-panel.js.map +1 -0
  84. package/dist/repl/tui/status-bar.d.ts +6 -2
  85. package/dist/repl/tui/status-bar.d.ts.map +1 -1
  86. package/dist/repl/tui/status-bar.js +82 -24
  87. package/dist/repl/tui/status-bar.js.map +1 -1
  88. package/dist/repl/tui/terminal.d.ts +28 -0
  89. package/dist/repl/tui/terminal.d.ts.map +1 -0
  90. package/dist/repl/tui/terminal.js +94 -0
  91. package/dist/repl/tui/terminal.js.map +1 -0
  92. package/dist/repl/tui/theme.d.ts +60 -0
  93. package/dist/repl/tui/theme.d.ts.map +1 -1
  94. package/dist/repl/tui/theme.js +142 -0
  95. package/dist/repl/tui/theme.js.map +1 -1
  96. package/dist/repl/tui/tool-pane.d.ts +68 -0
  97. package/dist/repl/tui/tool-pane.d.ts.map +1 -0
  98. package/dist/repl/tui/tool-pane.js +261 -0
  99. package/dist/repl/tui/tool-pane.js.map +1 -0
  100. package/dist/repl/tui/working-line.d.ts +23 -0
  101. package/dist/repl/tui/working-line.d.ts.map +1 -0
  102. package/dist/repl/tui/working-line.js +58 -0
  103. package/dist/repl/tui/working-line.js.map +1 -0
  104. package/dist/repl/worker-host.d.ts +80 -0
  105. package/dist/repl/worker-host.d.ts.map +1 -0
  106. package/dist/repl/worker-host.js +305 -0
  107. package/dist/repl/worker-host.js.map +1 -0
  108. package/dist/repl/worker-protocol.d.ts +123 -0
  109. package/dist/repl/worker-protocol.d.ts.map +1 -0
  110. package/dist/repl/worker-protocol.js +9 -0
  111. package/dist/repl/worker-protocol.js.map +1 -0
  112. package/dist/runner.d.ts +24 -0
  113. package/dist/runner.d.ts.map +1 -1
  114. package/dist/runner.js +47 -0
  115. package/dist/runner.js.map +1 -1
  116. package/dist/system/assets/docs/AGENT_PROMPT.md +193 -0
  117. package/dist/system/assets/docs/DML_AUTHORING.md +21 -0
  118. package/dist/system/assets/docs/DML_REFERENCE.md +145 -0
  119. package/dist/types.d.ts +7 -0
  120. package/dist/types.d.ts.map +1 -1
  121. package/package.json +2 -1
  122. package/src/prolog-src/deepclause_mi.pl +516 -2
@@ -0,0 +1,261 @@
1
+ /**
2
+ * A tool-call pane for the fullscreen TUI.
3
+ *
4
+ * Modelled on Pi's tool panes, but built for our tools rather than Pi's tool
5
+ * model: `execute` (a goal and its bindings), `bash` (command, captured output,
6
+ * exit code, duration), `listing`, `visualize`, and the DML runtime's own tools.
7
+ *
8
+ * Collapsed by default — a tool call is usually a one-line event, and the detail
9
+ * is only wanted when something looks wrong. The last pane can be expanded with a
10
+ * keybinding (see `toggleLastPane` in the renderer).
11
+ */
12
+ import { Markdown, Text, TruncatedText, truncateToWidth, visibleWidth, wrapTextWithAnsi, } from '@earendil-works/pi-tui';
13
+ import { markdownTheme, tuiStyle } from './theme.js';
14
+ /** Lines of body shown while collapsed. */
15
+ const COLLAPSED_BODY_LINES = 4;
16
+ export class DmlToolPane {
17
+ toolName;
18
+ args;
19
+ state = 'running';
20
+ failure;
21
+ result;
22
+ expanded = false;
23
+ elapsedMs;
24
+ compact;
25
+ prefix;
26
+ cachedWidth;
27
+ cachedLines;
28
+ constructor(options) {
29
+ this.toolName = options.toolName;
30
+ this.args = options.args;
31
+ this.compact = options.compact ?? false;
32
+ this.prefix = options.prefix ?? '';
33
+ }
34
+ /** Re-indent the pane (a frame's depth is only known once its output arrives). */
35
+ setPrefix(prefix) {
36
+ if (prefix === this.prefix)
37
+ return;
38
+ this.prefix = prefix;
39
+ this.invalidateCache();
40
+ }
41
+ setArgs(args) {
42
+ this.args = args;
43
+ this.invalidateCache();
44
+ }
45
+ setResult(result, success, elapsedMs) {
46
+ this.result = result;
47
+ this.state = success ? 'ok' : 'failed';
48
+ this.elapsedMs = elapsedMs;
49
+ if (!success) {
50
+ this.failure = typeof result === 'string'
51
+ ? result
52
+ : String(result?.error ?? 'failed');
53
+ }
54
+ this.invalidateCache();
55
+ }
56
+ setExpanded(expanded) {
57
+ this.expanded = expanded;
58
+ this.invalidateCache();
59
+ }
60
+ toggle() {
61
+ this.setExpanded(!this.expanded);
62
+ }
63
+ get isExpanded() {
64
+ return this.expanded;
65
+ }
66
+ /** One-line summary for a bounded list, e.g. `bash — printf hello`. */
67
+ get summary() {
68
+ const first = this.bodyLines()[0] ?? '';
69
+ return first ? `${this.toolName} — ${first}` : this.toolName;
70
+ }
71
+ invalidateCache() {
72
+ this.cachedWidth = undefined;
73
+ this.cachedLines = undefined;
74
+ }
75
+ invalidate() {
76
+ this.invalidateCache();
77
+ }
78
+ /** The interesting argument, rendered as one short line. */
79
+ bodyLines() {
80
+ const { args, compact } = this;
81
+ const lines = [];
82
+ const command = typeof args.command === 'string' ? args.command : undefined;
83
+ const argv = Array.isArray(args.argv) ? args.argv.map(String) : undefined;
84
+ const goal = typeof args.goal === 'string' ? args.goal : undefined;
85
+ if (command)
86
+ lines.push(command);
87
+ else if (argv && argv.length > 0)
88
+ lines.push(argv.join(' '));
89
+ else if (goal) {
90
+ for (const line of goal.split('\n'))
91
+ lines.push(line.trim());
92
+ }
93
+ else {
94
+ const entries = Object.entries(args).filter(([, value]) => value !== undefined && value !== null);
95
+ if (entries.length > 0) {
96
+ lines.push(entries.map(([key, value]) => `${key}=${shortValue(value)}`).join(' '));
97
+ }
98
+ }
99
+ // A `execute` on its own is not interesting enough for a body.
100
+ if (compact && lines.length === 0)
101
+ return [];
102
+ return lines;
103
+ }
104
+ /** Result text, split into lines: stdout/stderr, bindings, or an error. */
105
+ resultLines() {
106
+ const out = [];
107
+ if (this.failure) {
108
+ out.push(this.failure);
109
+ }
110
+ const result = this.result;
111
+ if (result && typeof result === 'object') {
112
+ const stdout = typeof result.stdout === 'string' ? result.stdout : undefined;
113
+ const stderr = typeof result.stderr === 'string' ? result.stderr : undefined;
114
+ const output = typeof result.output === 'string' ? result.output : undefined;
115
+ const error = typeof result.error === 'string' ? result.error : undefined;
116
+ if (stdout && stdout.trim())
117
+ out.push(...stdout.trimEnd().split('\n'));
118
+ if (stderr && stderr.trim())
119
+ out.push(...stderr.trimEnd().split('\n'));
120
+ if (output && output.trim())
121
+ out.push(...output.trimEnd().split('\n'));
122
+ if (error && error !== this.failure)
123
+ out.push(error);
124
+ const bindings = Array.isArray(result.bindings) ? result.bindings : undefined;
125
+ if (bindings && bindings.length > 0) {
126
+ out.push(bindings
127
+ .map((binding) => {
128
+ const { name, value } = binding;
129
+ return `${String(name ?? '?')} = ${String(value ?? '')}`;
130
+ })
131
+ .join('\n'));
132
+ }
133
+ }
134
+ else if (typeof this.result === 'string' && this.result.trim()) {
135
+ out.push(...this.result.trimEnd().split('\n'));
136
+ }
137
+ return out;
138
+ }
139
+ render(width) {
140
+ if (this.cachedLines && this.cachedWidth === width)
141
+ return this.cachedLines;
142
+ const lines = this.renderLines(width);
143
+ this.cachedWidth = width;
144
+ this.cachedLines = lines;
145
+ return lines;
146
+ }
147
+ renderLines(width) {
148
+ /*
149
+ * The tree belongs to the frame (`framePrefix`), which already puts a `│` at
150
+ * this depth. The pane must therefore *indent* under that prefix rather than
151
+ * add a stem of its own, or a nested tool call shows two stems at different
152
+ * columns while the surrounding output shows one. This is also the shape the
153
+ * line renderer has always used for tool detail:
154
+ *
155
+ * run │ ⚙ bash
156
+ * run │ printf hello
157
+ */
158
+ const prefix = this.prefix;
159
+ const headerIndent = ' ';
160
+ const bodyIndent = ' ';
161
+ const gutter = `${prefix}${bodyIndent}`;
162
+ const gutterWidth = visibleWidth(prefix) + bodyIndent.length;
163
+ const contentWidth = Math.max(1, width - gutterWidth);
164
+ const glyph = this.state === 'ok' ? '✔' : this.state === 'failed' ? '✖' : '⚙';
165
+ const glyphStyled = this.state === 'failed'
166
+ ? tuiStyle.error(glyph)
167
+ : this.state === 'ok'
168
+ ? tuiStyle.success(glyph)
169
+ : tuiStyle.accent(glyph);
170
+ // Only offer the key when something is actually hidden: on a one-line call the
171
+ // hint is noise, and it made every pane look like it had more to show.
172
+ const body = this.bodyLines();
173
+ const result = this.resultLines();
174
+ const hidden = Math.max(0, body.length - COLLAPSED_BODY_LINES)
175
+ + Math.max(0, result.length - COLLAPSED_BODY_LINES);
176
+ const meta = [];
177
+ if (this.elapsedMs !== undefined)
178
+ meta.push(`${this.elapsedMs}ms`);
179
+ if (!this.expanded && hidden > 0)
180
+ meta.push('ctrl+o to expand');
181
+ const header = `${glyphStyled} ${tuiStyle.title(this.toolName)}${meta.length ? ` ${tuiStyle.dim(`· ${meta.join(' · ')}`)}` : ''}`;
182
+ const out = [truncateToWidth(`${prefix}${headerIndent}${header}`, width, '…')];
183
+ // Body: the call itself.
184
+ const bodyBudget = this.expanded ? body.length : Math.min(body.length, COLLAPSED_BODY_LINES);
185
+ for (const line of body.slice(0, bodyBudget)) {
186
+ for (const wrapped of this.wrap(line, contentWidth, body.length > 1 ? ' ' : '')) {
187
+ out.push(`${gutter}${truncateToWidth(wrapped, contentWidth, '…')}`);
188
+ }
189
+ }
190
+ // Result: markdown when expanded (a model answer or a report), bounded otherwise.
191
+ if (result.length > 0) {
192
+ const shown = this.expanded ? result : result.slice(0, COLLAPSED_BODY_LINES);
193
+ const omitted = result.length - shown.length;
194
+ if (this.expanded) {
195
+ const markdown = new Markdown(shown.join('\n'), 0, 0, markdownTheme());
196
+ for (const line of markdown.render(contentWidth)) {
197
+ out.push(line === '' ? '' : `${gutter}${line}`);
198
+ }
199
+ }
200
+ else {
201
+ for (const line of shown) {
202
+ const styled = this.state === 'failed' ? tuiStyle.error(line) : line;
203
+ for (const wrapped of this.wrap(styled, contentWidth, '')) {
204
+ out.push(`${gutter}${truncateToWidth(wrapped, contentWidth, '…')}`);
205
+ }
206
+ }
207
+ }
208
+ if (omitted > 0) {
209
+ out.push(`${gutter}${tuiStyle.dim(`… ${omitted} more line${omitted === 1 ? '' : 's'}`)}`);
210
+ }
211
+ }
212
+ // Every line must fit the viewport; a pane is a child of the transcript.
213
+ return out.map((line) => (visibleWidth(line) <= width ? line : truncateToWidth(line, width, '…')));
214
+ }
215
+ /** Wrap a styled string to `width`, prefixing continuation lines. */
216
+ wrap(text, width, continuationPrefix) {
217
+ if (visibleWidth(text) <= width)
218
+ return [text];
219
+ const wrapped = wrapTextWithAnsi(text, Math.max(1, width - visibleWidth(continuationPrefix)));
220
+ return wrapped.map((line, index) => (index === 0 ? line : `${continuationPrefix}${line}`));
221
+ }
222
+ }
223
+ /** Bound a value for a header line. Newlines collapse so the value stays one line. */
224
+ function shortValue(value) {
225
+ const raw = typeof value === 'string'
226
+ ? value
227
+ : (() => {
228
+ try {
229
+ return JSON.stringify(value);
230
+ }
231
+ catch {
232
+ return String(value);
233
+ }
234
+ })();
235
+ // A multi-line argument (a script's `content`, say) must not carry its newlines
236
+ // into the pane: the wrapper does not split on them, so the text after a newline
237
+ // rendered at column 0, outside the tree indentation.
238
+ const text = raw.replace(/\s*\n\s*/g, ' ⏎ ');
239
+ return text.length > 60 ? `${text.slice(0, 57)}…` : text;
240
+ }
241
+ /** A plain text block component, so callers can append text as a component. */
242
+ export class TextBlock {
243
+ text;
244
+ constructor(value, paddingX = 0) {
245
+ this.text = new Text(value, paddingX, 0);
246
+ }
247
+ setText(value) {
248
+ this.text.setText(value);
249
+ }
250
+ render(width) {
251
+ return this.text.render(width);
252
+ }
253
+ invalidate() {
254
+ this.text.invalidate();
255
+ }
256
+ }
257
+ /** A bounded single-line text component (for long binding values). */
258
+ export function truncated(value) {
259
+ return new TruncatedText(value, 0, 0);
260
+ }
261
+ //# sourceMappingURL=tool-pane.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-pane.js","sourceRoot":"","sources":["../../../src/repl/tui/tool-pane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,aAAa,EACb,eAAe,EACf,YAAY,EACZ,gBAAgB,GAEjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAA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AAW,EAAE,KAAK,CAAC,CAAC;IAC7C,OAAO,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3D,CAAC;AAED,+EAA+E;AAC/E,MAAM,OAAO,SAAS;IACH,IAAI,CAAO;IAE5B,YAAY,KAAa,EAAE,QAAQ,GAAG,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,CAAC,KAAa;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;IACzB,CAAC;CACF;AAED,sEAAsE;AACtE,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The working indicator, as a dock component.
3
+ *
4
+ * It used to be a `\r`-based line inside the transcript, which meant unrelated
5
+ * output could replace it and leave no sign that anything was happening — most
6
+ * visible with reasoning off and streaming quiet, where the transcript went
7
+ * silent until the first token. As a component in the dock it animates on its own
8
+ * and is only absent when nothing is running.
9
+ */
10
+ import { type Component, type TUI } from '@earendil-works/pi-tui';
11
+ export declare class WorkingLine implements Component {
12
+ private readonly loader;
13
+ private label;
14
+ constructor(tui: TUI);
15
+ /** Stop the animation (called on exit, so no timer outlives the UI). */
16
+ stop(): void;
17
+ /** Show the indicator with `label`, or hide it when `label` is null. */
18
+ set(label: string | null): void;
19
+ get isWorking(): boolean;
20
+ render(width: number): string[];
21
+ invalidate(): void;
22
+ }
23
+ //# sourceMappingURL=working-line.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"working-line.d.ts","sourceRoot":"","sources":["../../../src/repl/tui/working-line.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAU,KAAK,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAO1E,qBAAa,WAAY,YAAW,SAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,KAAK,CAAuB;gBAExB,GAAG,EAAE,GAAG;IAYpB,wEAAwE;IACxE,IAAI,IAAI,IAAI;IAKZ,wEAAwE;IACxE,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAW/B,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAM/B,UAAU,IAAI,IAAI;CAGnB"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The working indicator, as a dock component.
3
+ *
4
+ * It used to be a `\r`-based line inside the transcript, which meant unrelated
5
+ * output could replace it and leave no sign that anything was happening — most
6
+ * visible with reasoning off and streaming quiet, where the transcript went
7
+ * silent until the first token. As a component in the dock it animates on its own
8
+ * and is only absent when nothing is running.
9
+ */
10
+ import { Loader } from '@earendil-works/pi-tui';
11
+ import { tuiStyle } from './theme.js';
12
+ /** Frames for the indicator (a braille spinner, like the rest of the TUI). */
13
+ const FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
14
+ export class WorkingLine {
15
+ loader;
16
+ label = null;
17
+ constructor(tui) {
18
+ this.loader = new Loader(tui, tuiStyle.accent, tuiStyle.muted, '', {
19
+ frames: FRAMES,
20
+ intervalMs: 90,
21
+ });
22
+ // `Loader`'s constructor calls `setIndicator()`, which calls `start()`: it
23
+ // begins animating (and holding a timer) the moment it is constructed. Left
24
+ // alone that keeps the process alive after the TUI stops and re-renders while
25
+ // nothing is running, so park it until there is work to show.
26
+ this.loader.stop();
27
+ }
28
+ /** Stop the animation (called on exit, so no timer outlives the UI). */
29
+ stop() {
30
+ this.label = null;
31
+ this.loader.stop();
32
+ }
33
+ /** Show the indicator with `label`, or hide it when `label` is null. */
34
+ set(label) {
35
+ if (label === this.label)
36
+ return;
37
+ this.label = label;
38
+ if (label === null) {
39
+ this.loader.stop();
40
+ return;
41
+ }
42
+ this.loader.setMessage(label);
43
+ this.loader.start();
44
+ }
45
+ get isWorking() {
46
+ return this.label !== null;
47
+ }
48
+ render(width) {
49
+ // Nothing to show: no row at all, so the dock does not reserve a blank line.
50
+ if (this.label === null)
51
+ return [];
52
+ return this.loader.render(width);
53
+ }
54
+ invalidate() {
55
+ this.loader.invalidate();
56
+ }
57
+ }
58
+ //# sourceMappingURL=working-line.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"working-line.js","sourceRoot":"","sources":["../../../src/repl/tui/working-line.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,EAA4B,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,8EAA8E;AAC9E,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAElE,MAAM,OAAO,WAAW;IACL,MAAM,CAAS;IACxB,KAAK,GAAkB,IAAI,CAAC;IAEpC,YAAY,GAAQ;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE;YACjE,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,EAAE;SACf,CAAC,CAAC;QACH,2EAA2E;QAC3E,4EAA4E;QAC5E,8EAA8E;QAC9E,8DAA8D;QAC9D,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAED,wEAAwE;IACxE,IAAI;QACF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAED,wEAAwE;IACxE,GAAG,CAAC,KAAoB;QACtB,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK;YAAE,OAAO;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,6EAA6E;QAC7E,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI;YAAE,OAAO,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,UAAU;QACR,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;CACF"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The main-thread side of L2: a `ProcessBackend` that routes to a process worker.
3
+ *
4
+ * It keeps a synchronous cache of the worker's process table (refreshed by
5
+ * events and a short poll) so the status bar and `/ps` stay synchronous, and it
6
+ * services the worker's capability requests (`need`) through the session's
7
+ * `CapabilityBroker` — model, host tools, human input.
8
+ */
9
+ import type { ProcessRequestPayload, ProcessRequestResult } from '../runner.js';
10
+ import type { ProcessBackend } from './process-backend.js';
11
+ import type { DMLSession } from './session.js';
12
+ import { type ProcessEvent, type ProcessInfo, type Pid, type SpawnOptions } from './processes.js';
13
+ import type { WorkerInitData, WorkerToMain } from './worker-protocol.js';
14
+ /** The slice of `worker_threads.Worker` this host uses (injectable for tests). */
15
+ export interface WorkerLike {
16
+ postMessage(message: unknown): void;
17
+ on(event: 'message', handler: (message: WorkerToMain) => void): unknown;
18
+ on(event: 'error', handler: (error: Error) => void): unknown;
19
+ on(event: 'exit', handler: (code: number) => void): unknown;
20
+ terminate(): unknown;
21
+ }
22
+ export type WorkerFactory = (init: WorkerInitData) => WorkerLike;
23
+ export interface RemoteProcessHostOptions {
24
+ onEvent?: (event: ProcessEvent) => void;
25
+ workerFactory?: WorkerFactory;
26
+ refreshMs?: number;
27
+ }
28
+ export declare class RemoteProcessHost implements ProcessBackend {
29
+ private readonly session;
30
+ private readonly onEvent?;
31
+ private readonly workerFactory;
32
+ private readonly refreshMs;
33
+ private worker?;
34
+ private ready;
35
+ private readyPromise?;
36
+ private disposed;
37
+ private requestCounter;
38
+ private readonly pending;
39
+ private cache;
40
+ private nameIndex;
41
+ private refreshTimer?;
42
+ /** Every harness snapshot sent to the worker, keyed by version (for inspection). */
43
+ private readonly snapshotTexts;
44
+ private lastSnapshotVersion?;
45
+ constructor(session: DMLSession, options?: RemoteProcessHostOptions);
46
+ start(): Promise<void>;
47
+ private onReady?;
48
+ private onFatal?;
49
+ /**
50
+ * The harness update to attach to an outbound spawn/foreground request. The
51
+ * worker's children must run the code the user committed, not the module the
52
+ * worker happened to start with — otherwise a long-lived worker serves every
53
+ * later spawn from a stale snapshot.
54
+ */
55
+ private snapshotUpdate;
56
+ spawn(goal: string, options?: SpawnOptions): Promise<Pid>;
57
+ send(to: Pid | string, messageTerm: unknown): void;
58
+ stop(target: Pid | string, reason?: unknown): Promise<void>;
59
+ register(name: string, pid: Pid): void;
60
+ whereis(name: string): Pid | undefined;
61
+ info(pid: Pid): ProcessInfo | undefined;
62
+ processes(): ProcessInfo[];
63
+ callTerm(to: Pid | string, messageTerm: string, timeoutMs: number): Promise<string>;
64
+ foregroundHandle(request: ProcessRequestPayload, _signal?: AbortSignal): Promise<ProcessRequestResult>;
65
+ /**
66
+ * The harness source a process is running. The main keeps every snapshot it
67
+ * sent (keyed by version), so this stays synchronous and needs no worker hop.
68
+ */
69
+ codeOf(pid: Pid | string): string | undefined;
70
+ shutdown(): Promise<void>;
71
+ private handleMessage;
72
+ private serviceNeed;
73
+ private request;
74
+ private resolveRpc;
75
+ private refresh;
76
+ private rebuildNameIndex;
77
+ private post;
78
+ private failAll;
79
+ }
80
+ //# sourceMappingURL=worker-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-host.d.ts","sourceRoot":"","sources":["../../src/repl/worker-host.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAU,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1G,OAAO,KAAK,EAAgB,cAAc,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEvF,kFAAkF;AAClF,MAAM,WAAW,UAAU;IACzB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC;IACxE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,O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