deepclause-sdk 0.3.0 → 0.6.0
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/README.md +148 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +154 -28
- package/dist/agent.js.map +1 -1
- package/dist/cli/config.d.ts +150 -140
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +3 -0
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/login.d.ts +2 -1
- package/dist/cli/login.d.ts.map +1 -1
- package/dist/cli/login.js +15 -2
- package/dist/cli/login.js.map +1 -1
- package/dist/cli/repl.d.ts +54 -1
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js +467 -53
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +4 -0
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/set-backend.d.ts +2 -2
- package/dist/cli/set-backend.d.ts.map +1 -1
- package/dist/cli/set-backend.js +54 -8
- package/dist/cli/set-backend.js.map +1 -1
- package/dist/cli/work.d.ts +16 -0
- package/dist/cli/work.d.ts.map +1 -0
- package/dist/cli/work.js +45 -0
- package/dist/cli/work.js.map +1 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/prolog-src/deepclause_mi.pl +2596 -268
- package/dist/prolog-src/deepclause_strings.pl +36 -3
- package/dist/repl/agent.d.ts +12 -0
- package/dist/repl/agent.d.ts.map +1 -1
- package/dist/repl/agent.js +40 -16
- package/dist/repl/agent.js.map +1 -1
- package/dist/repl/auth.d.ts +6 -3
- package/dist/repl/auth.d.ts.map +1 -1
- package/dist/repl/auth.js +55 -5
- package/dist/repl/auth.js.map +1 -1
- package/dist/repl/backend.d.ts +24 -0
- package/dist/repl/backend.d.ts.map +1 -1
- package/dist/repl/backend.js +292 -12
- package/dist/repl/backend.js.map +1 -1
- package/dist/repl/compaction.d.ts +2 -0
- package/dist/repl/compaction.d.ts.map +1 -1
- package/dist/repl/compaction.js +9 -0
- package/dist/repl/compaction.js.map +1 -1
- package/dist/repl/event-history.d.ts +4 -0
- package/dist/repl/event-history.d.ts.map +1 -0
- package/dist/repl/event-history.js +33 -0
- package/dist/repl/event-history.js.map +1 -0
- package/dist/repl/harness-tools.d.ts +26 -18
- package/dist/repl/harness-tools.d.ts.map +1 -1
- package/dist/repl/harness-tools.js +103 -34
- package/dist/repl/harness-tools.js.map +1 -1
- package/dist/repl/history.d.ts +75 -3
- package/dist/repl/history.d.ts.map +1 -1
- package/dist/repl/history.js +155 -4
- package/dist/repl/history.js.map +1 -1
- package/dist/repl/index.d.ts +33 -5
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +30 -0
- package/dist/repl/index.js.map +1 -1
- package/dist/repl/reference.d.ts +31 -0
- package/dist/repl/reference.d.ts.map +1 -0
- package/dist/repl/reference.js +143 -0
- package/dist/repl/reference.js.map +1 -0
- package/dist/repl/render.d.ts +3 -1
- package/dist/repl/render.d.ts.map +1 -1
- package/dist/repl/render.js +17 -0
- package/dist/repl/render.js.map +1 -1
- package/dist/repl/session.d.ts +166 -23
- package/dist/repl/session.d.ts.map +1 -1
- package/dist/repl/session.js +980 -188
- package/dist/repl/session.js.map +1 -1
- package/dist/repl/tui/autocomplete.d.ts.map +1 -1
- package/dist/repl/tui/autocomplete.js +5 -1
- package/dist/repl/tui/autocomplete.js.map +1 -1
- package/dist/repl/tui/renderer.d.ts +2 -1
- package/dist/repl/tui/renderer.d.ts.map +1 -1
- package/dist/repl/tui/renderer.js +20 -3
- package/dist/repl/tui/renderer.js.map +1 -1
- package/dist/repl/tui/status-bar.d.ts +5 -2
- package/dist/repl/tui/status-bar.d.ts.map +1 -1
- package/dist/repl/tui/status-bar.js +8 -3
- package/dist/repl/tui/status-bar.js.map +1 -1
- package/dist/repl/tui/tool-pane.d.ts +1 -1
- package/dist/repl/tui/tool-pane.d.ts.map +1 -1
- package/dist/repl/tui/tool-pane.js +13 -7
- package/dist/repl/tui/tool-pane.js.map +1 -1
- package/dist/repl/tui/work-view.d.ts +10 -0
- package/dist/repl/tui/work-view.d.ts.map +1 -0
- package/dist/repl/tui/work-view.js +28 -0
- package/dist/repl/tui/work-view.js.map +1 -0
- package/dist/runner.d.ts +7 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +81 -23
- package/dist/runner.js.map +1 -1
- package/dist/runtime-identity.json +10 -0
- package/dist/system/assets/docs/AGENT_PROMPT.md +265 -2943
- package/dist/system/assets/docs/DML_AUTHORING.md +81 -295
- package/dist/system/assets/docs/DML_BASICS.md +93 -0
- package/dist/system/assets/docs/DML_DEBUGGING.md +73 -0
- package/dist/system/assets/docs/DML_FORMS.md +94 -728
- package/dist/system/assets/docs/DML_MEDIA.md +63 -0
- package/dist/system/assets/docs/DML_PROCESSES.md +100 -0
- package/dist/system/assets/docs/DML_PYTHON.md +74 -0
- package/dist/system/assets/docs/DML_REFERENCE.md +224 -1912
- package/dist/system/assets/docs/DML_SHELL.md +107 -0
- package/dist/system/assets/docs/DML_TASKS.md +112 -0
- package/dist/system/assets/docs/HARNESS_EXAMPLES.md +255 -179
- package/dist/system/assets/docs/HARNESS_PATTERNS.md +65 -538
- package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +186 -0
- package/dist/system/assets/docs/PROLOG_SNIPPETS.md +61 -154
- package/dist/system/assets/index.d.ts +1 -1
- package/dist/system/assets/index.d.ts.map +1 -1
- package/dist/system/assets/index.js +7 -0
- package/dist/system/assets/index.js.map +1 -1
- package/dist/system/environment.d.ts +1 -1
- package/dist/system/environment.d.ts.map +1 -1
- package/dist/system/environment.js +10 -6
- package/dist/system/environment.js.map +1 -1
- package/dist/system/runtime/shell-manager.d.ts +1 -1
- package/dist/system/runtime/shell-manager.d.ts.map +1 -1
- package/dist/types.d.ts +62 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/work/index.d.ts +82 -0
- package/dist/work/index.d.ts.map +1 -0
- package/dist/work/index.js +232 -0
- package/dist/work/index.js.map +1 -0
- package/package.json +12 -3
- package/src/prolog-src/deepclause_mi.pl +2596 -268
- package/src/prolog-src/deepclause_strings.pl +36 -3
package/dist/cli/repl.js
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* as whole-line keywords before the classifier.
|
|
8
8
|
*/
|
|
9
9
|
import { readFileSync } from 'fs';
|
|
10
|
+
import { readdir } from 'fs/promises';
|
|
11
|
+
import { parseWorkflowCommand, runDeclaredWorkflow } from './work.js';
|
|
12
|
+
import { resolveWorkbenchPolicy } from '../work/index.js';
|
|
10
13
|
import * as path from 'path';
|
|
11
14
|
import * as readline from 'readline';
|
|
12
15
|
import { fileURLToPath } from 'url';
|
|
@@ -21,6 +24,7 @@ import { ChoicePicker } from '../repl/tui/picker.js';
|
|
|
21
24
|
import { openPiRuntime } from '../repl/backend.js';
|
|
22
25
|
import { listLoginProviders, loginToProvider } from '../repl/auth.js';
|
|
23
26
|
import { HarnessView } from '../repl/tui/harness-view.js';
|
|
27
|
+
import { WorkView } from '../repl/tui/work-view.js';
|
|
24
28
|
import { TuiRenderer } from '../repl/tui/renderer.js';
|
|
25
29
|
import { WorkingLine } from '../repl/tui/working-line.js';
|
|
26
30
|
import { createReplAutocomplete } from '../repl/tui/autocomplete.js';
|
|
@@ -34,14 +38,14 @@ import { PromptEditor } from '../repl/tui/editor.js';
|
|
|
34
38
|
import { FormView } from '../repl/tui/form-view.js';
|
|
35
39
|
import { applyFormKey, initialState, rows } from '../repl/form-widget.js';
|
|
36
40
|
import { loadProjectContext } from '../repl/project-context.js';
|
|
37
|
-
import { createPiBackend, THINKING_LEVELS } from '../repl/backend.js';
|
|
41
|
+
import { LLAMA_PROVIDER_ID, createPiBackend, THINKING_LEVELS } from '../repl/backend.js';
|
|
38
42
|
import { createReplToolset } from '../repl/toolset.js';
|
|
39
43
|
import { takeStartupPrologMessages } from '../prolog/loader.js';
|
|
40
44
|
import { createPiImageBackend } from '../repl/imagegen.js';
|
|
41
|
-
import { EnvModelResolver, PiModelResolver } from '../repl/model-resolver.js';
|
|
45
|
+
import { EnvModelResolver, PiModelResolver, } from '../repl/model-resolver.js';
|
|
42
46
|
import { pickForm } from '../repl/form-widget.js';
|
|
43
47
|
import { parseModelId, resolveModelSlotConfig } from '../system/config/model-slots.js';
|
|
44
|
-
import { loadReplConfig,
|
|
48
|
+
import { loadReplConfig, updateConfig } from './config.js';
|
|
45
49
|
import { renderDiagramImage, resolveMedia, } from '../visualize/index.js';
|
|
46
50
|
const OUT_OF_BAND = new Set(['halt', 'help', 'reset', 'rollback', 'freeze', 'unfreeze', 'trace', 'notrace', 'params']);
|
|
47
51
|
const GRAPHICS_MODES = ['auto', 'kitty', 'iterm2', 'ascii', 'off'];
|
|
@@ -83,8 +87,83 @@ export function parseVizArgs(arg) {
|
|
|
83
87
|
}
|
|
84
88
|
/** Render a recorded turn as the line the user would retype (goals get `/goal`). */
|
|
85
89
|
export function formatTurnInput(turn) {
|
|
90
|
+
if (turn.workflow)
|
|
91
|
+
return `/workflow ${JSON.stringify(turn.workflow.name)} ${JSON.stringify(turn.workflow.inputs)}`;
|
|
86
92
|
return turn.mode === 'goal' ? `/goal ${turn.request}` : turn.request;
|
|
87
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Whether the TUI shows execution detail by default.
|
|
96
|
+
*
|
|
97
|
+
* Develop and Work both start with tool calls, task activity and reasoning
|
|
98
|
+
* visible. `--no-events` (and an explicit `/details off`) is the only opt-out;
|
|
99
|
+
* Work used to hide this by default, which made its assistant look inert next
|
|
100
|
+
* to Develop even though the runtime was emitting the same events.
|
|
101
|
+
*/
|
|
102
|
+
export function replDetailsDefault(events) {
|
|
103
|
+
return events !== false;
|
|
104
|
+
}
|
|
105
|
+
const LOGIN_USAGE = 'login (use /login [provider] [--host <host>] [--port <port>] [--base-url <url>])';
|
|
106
|
+
/**
|
|
107
|
+
* Parse `/login [provider] [--host host] [--port port] [--base-url url]`.
|
|
108
|
+
* A bare URL is accepted as `--base-url`, and a positional provider may be
|
|
109
|
+
* omitted when an endpoint flag implies llama.cpp.
|
|
110
|
+
*/
|
|
111
|
+
export function parseLoginArgs(arg) {
|
|
112
|
+
const tokens = arg.split(/\s+/).filter(Boolean);
|
|
113
|
+
let provider;
|
|
114
|
+
let baseUrl;
|
|
115
|
+
let host;
|
|
116
|
+
let port;
|
|
117
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
118
|
+
const token = tokens[index];
|
|
119
|
+
const equals = token.indexOf('=');
|
|
120
|
+
const flag = token.startsWith('--') ? (equals >= 0 ? token.slice(0, equals) : token) : '';
|
|
121
|
+
const inlineValue = equals >= 0 ? token.slice(equals + 1) : undefined;
|
|
122
|
+
const value = () => inlineValue ?? tokens[++index];
|
|
123
|
+
switch (flag) {
|
|
124
|
+
case '--base-url':
|
|
125
|
+
case '--url':
|
|
126
|
+
baseUrl = value();
|
|
127
|
+
if (!baseUrl)
|
|
128
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
129
|
+
break;
|
|
130
|
+
case '--host':
|
|
131
|
+
host = value();
|
|
132
|
+
if (!host)
|
|
133
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
134
|
+
break;
|
|
135
|
+
case '--port':
|
|
136
|
+
port = value();
|
|
137
|
+
if (!port)
|
|
138
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
139
|
+
break;
|
|
140
|
+
case '--provider':
|
|
141
|
+
provider = value();
|
|
142
|
+
if (!provider)
|
|
143
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
144
|
+
break;
|
|
145
|
+
case '':
|
|
146
|
+
if (token.startsWith('-')) {
|
|
147
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
148
|
+
}
|
|
149
|
+
if (/^https?:\/\//i.test(token)) {
|
|
150
|
+
if (baseUrl)
|
|
151
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
152
|
+
baseUrl = token;
|
|
153
|
+
}
|
|
154
|
+
else if (!provider) {
|
|
155
|
+
provider = token;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
default:
|
|
162
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { kind: 'login', provider, baseUrl, host, port };
|
|
166
|
+
}
|
|
88
167
|
/**
|
|
89
168
|
* Slash commands are executed (or queued), never steered into a running model
|
|
90
169
|
* turn: `/send`, `/call`, `/ps`, `/stop` … address processes, not the model.
|
|
@@ -114,6 +193,24 @@ export function classifyReplInput(line) {
|
|
|
114
193
|
const name = (spaceIndex === -1 ? withoutSlash : withoutSlash.slice(0, spaceIndex)).toLowerCase();
|
|
115
194
|
const arg = (spaceIndex === -1 ? '' : withoutSlash.slice(spaceIndex)).trim();
|
|
116
195
|
switch (name) {
|
|
196
|
+
case 'mode': {
|
|
197
|
+
const [mode, harness, extra] = arg.split(/\s+/);
|
|
198
|
+
if (!arg)
|
|
199
|
+
return { kind: 'mode' };
|
|
200
|
+
return (mode === 'work' || mode === 'develop') && !extra ? { kind: 'mode', mode, harness } : { kind: 'unknown-command', name: 'mode (use /mode work|develop [harness])' };
|
|
201
|
+
}
|
|
202
|
+
case 'workflows': return { kind: 'workflows' };
|
|
203
|
+
case 'workflow': {
|
|
204
|
+
if (!arg)
|
|
205
|
+
return { kind: 'workflows' };
|
|
206
|
+
try {
|
|
207
|
+
return { kind: 'workflow', ...parseWorkflowCommand(arg) };
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return { kind: 'unknown-command', name: 'workflow (use /workflow "Name" {"Input":"value"})' };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
case 'details': return { kind: 'details', show: arg === 'on' ? true : arg === 'off' ? false : undefined };
|
|
117
214
|
case 'goal':
|
|
118
215
|
return arg ? { kind: 'goal', goal: arg } : { kind: 'unknown-command', name: 'goal (missing goal)' };
|
|
119
216
|
case 'listing':
|
|
@@ -191,7 +288,7 @@ export function classifyReplInput(line) {
|
|
|
191
288
|
case 'stop':
|
|
192
289
|
return arg ? { kind: 'stop', target: arg } : { kind: 'unknown-command', name: 'stop (usage: /stop <name>)' };
|
|
193
290
|
case 'login':
|
|
194
|
-
return
|
|
291
|
+
return parseLoginArgs(arg);
|
|
195
292
|
default:
|
|
196
293
|
return { kind: 'unknown-command', name };
|
|
197
294
|
}
|
|
@@ -236,6 +333,9 @@ export async function runGoalWithRenderer(repl, goal, options) {
|
|
|
236
333
|
let hadError = false;
|
|
237
334
|
let printedAny = false;
|
|
238
335
|
let answered = false;
|
|
336
|
+
// A turn that suspended *succeeded* — it stopped at a safe point and the host
|
|
337
|
+
// recorded where to continue. Reporting `false.` would read as a failure.
|
|
338
|
+
let suspended = false;
|
|
239
339
|
for await (const event of repl.query(goal, { signal: options.signal })) {
|
|
240
340
|
if (event.type === 'solution') {
|
|
241
341
|
options.renderer.solution(event.solution?.bindings ?? []);
|
|
@@ -251,6 +351,10 @@ export async function runGoalWithRenderer(repl, goal, options) {
|
|
|
251
351
|
answered = true;
|
|
252
352
|
options.renderer.render(event);
|
|
253
353
|
}
|
|
354
|
+
else if (event.type === 'suspend') {
|
|
355
|
+
suspended = true;
|
|
356
|
+
options.renderer.render(event);
|
|
357
|
+
}
|
|
254
358
|
else if (event.type === 'finished') {
|
|
255
359
|
// Nothing to print for finished.
|
|
256
360
|
}
|
|
@@ -258,7 +362,7 @@ export async function runGoalWithRenderer(repl, goal, options) {
|
|
|
258
362
|
options.renderer.render(event);
|
|
259
363
|
}
|
|
260
364
|
}
|
|
261
|
-
if (!printedAny && !hadError) {
|
|
365
|
+
if (!printedAny && !hadError && !suspended) {
|
|
262
366
|
// A goal that committed with `answer/1` succeeded; one that produced neither
|
|
263
367
|
// a solution nor an answer simply failed. (`goalTerminator`/`noSolution`
|
|
264
368
|
// keep `--json` stdout pure, where a raw `false.` would corrupt the stream.)
|
|
@@ -394,10 +498,10 @@ const PROVIDER_ENV_KEYS = {
|
|
|
394
498
|
export async function createReplRuntime(options) {
|
|
395
499
|
const workspace = path.resolve(options.workspace ?? './');
|
|
396
500
|
const config = await loadReplConfig(workspace);
|
|
397
|
-
const
|
|
501
|
+
const runtimePolicy = resolveWorkbenchPolicy(config);
|
|
398
502
|
// One harness per name within a project: `--harness`, else the `-l` file's
|
|
399
503
|
// name, else the configured default (`main`).
|
|
400
|
-
|
|
504
|
+
let harnessName = normalizeHarnessName(options.harness)
|
|
401
505
|
?? (options.load?.length ? harnessNameFromFile(options.load[0]) : undefined)
|
|
402
506
|
?? normalizeHarnessName(config.repl.harness)
|
|
403
507
|
?? 'main';
|
|
@@ -569,7 +673,11 @@ export async function createReplRuntime(options) {
|
|
|
569
673
|
imageBackend = undefined;
|
|
570
674
|
}
|
|
571
675
|
}
|
|
572
|
-
|
|
676
|
+
let currentInput = buildCliOnInput(options);
|
|
677
|
+
const replOptions = {
|
|
678
|
+
mode: options.mode ?? (options.workflow ? 'work' : undefined),
|
|
679
|
+
sessionKind: options.workflow ? 'workflow-run' : undefined,
|
|
680
|
+
origin: 'tui',
|
|
573
681
|
sessionId,
|
|
574
682
|
resume,
|
|
575
683
|
workspacePath: workspace,
|
|
@@ -577,9 +685,10 @@ export async function createReplRuntime(options) {
|
|
|
577
685
|
provider: harnessProvider,
|
|
578
686
|
temperature: options.temperature ?? config.temperatures.run,
|
|
579
687
|
params: options.param ?? {},
|
|
580
|
-
gasLimit: options.gasLimit,
|
|
581
|
-
maxDepth: options.depth ??
|
|
582
|
-
maxModelCalls: options.maxModelCalls ??
|
|
688
|
+
gasLimit: options.gasLimit ?? runtimePolicy.gasLimit,
|
|
689
|
+
maxDepth: options.depth ?? runtimePolicy.maxDepth,
|
|
690
|
+
maxModelCalls: options.maxModelCalls ?? runtimePolicy.maxModelCalls,
|
|
691
|
+
providerConcurrency: runtimePolicy.providerConcurrency,
|
|
583
692
|
tools: toolset.tools,
|
|
584
693
|
hostToolsCatalog: toolset.catalog,
|
|
585
694
|
executionBackend: toolset.environment.kind,
|
|
@@ -597,18 +706,22 @@ export async function createReplRuntime(options) {
|
|
|
597
706
|
: presentForm(repl, form);
|
|
598
707
|
},
|
|
599
708
|
history: historyOptions,
|
|
600
|
-
harness: harnessName,
|
|
709
|
+
harness: resume && !options.harness ? undefined : harnessName,
|
|
601
710
|
execution: options.execution,
|
|
602
711
|
autoLoadHarness: !(options.load?.length),
|
|
603
|
-
compaction:
|
|
712
|
+
compaction: runtimePolicy.compaction,
|
|
604
713
|
contextWindow,
|
|
605
|
-
onInput:
|
|
606
|
-
}
|
|
714
|
+
onInput: currentInput,
|
|
715
|
+
};
|
|
716
|
+
let repl = await createHarnessRepl(replOptions);
|
|
717
|
+
const identity = await repl.sessionInfo();
|
|
718
|
+
harnessName = identity.harness ?? harnessName;
|
|
719
|
+
const purpose = identity.mode ?? 'develop';
|
|
607
720
|
// Terminal images (agent `visualize` and `/viz`) are painted through the
|
|
608
721
|
// renderer; the TUI installs an image sink later, which this follows.
|
|
609
722
|
repl.session.setImageHandler((lines) => renderer.image(lines));
|
|
610
723
|
let missingCredential;
|
|
611
|
-
|
|
724
|
+
let statusTracker = new ReplStatusTracker({
|
|
612
725
|
model: {
|
|
613
726
|
id: harnessModel,
|
|
614
727
|
provider: String(harnessProvider),
|
|
@@ -628,10 +741,55 @@ export async function createReplRuntime(options) {
|
|
|
628
741
|
}
|
|
629
742
|
}
|
|
630
743
|
const runtime = {
|
|
744
|
+
mode: purpose,
|
|
745
|
+
details: replDetailsDefault(options.events),
|
|
746
|
+
askInput: async (prompt, choices) => currentInput?.(prompt, choices),
|
|
747
|
+
harnesses: async () => {
|
|
748
|
+
try {
|
|
749
|
+
return (await readdir(path.resolve(workspace, config.repl.history.dir, 'harnesses'), { withFileTypes: true })).filter(entry => entry.isDirectory()).map(entry => entry.name).sort();
|
|
750
|
+
}
|
|
751
|
+
catch {
|
|
752
|
+
return [];
|
|
753
|
+
}
|
|
754
|
+
},
|
|
755
|
+
switchMode: async (mode, harness) => {
|
|
756
|
+
const target = normalizeHarnessName(harness) ?? runtime.harnessName;
|
|
757
|
+
const active = repl.session.processes().filter(process => ['running', 'runnable', 'waiting', 'input'].includes(process.state));
|
|
758
|
+
if (active.length)
|
|
759
|
+
throw new Error('Stop active services before switching conversations; they will not be silently disposed.');
|
|
760
|
+
let counterpart;
|
|
761
|
+
if (historyOptions && (mode !== runtime.mode || target !== runtime.harnessName)) {
|
|
762
|
+
const store = new HistoryStore(workspace, '__session_lookup__', historyOptions);
|
|
763
|
+
counterpart = (await store.sessionSummaries()).filter(row => row.mode === mode && row.harness === target && row.kind !== 'workflow-run').at(-1)?.id;
|
|
764
|
+
}
|
|
765
|
+
const next = await createHarnessRepl({ ...replOptions, mode, harness: target, sessionId: counterpart, resume: Boolean(counterpart), autoLoadHarness: true, onInput: currentInput });
|
|
766
|
+
const spec = mode === 'work' ? await next.workSpec() : undefined;
|
|
767
|
+
if (mode === 'work' && !spec?.shell) {
|
|
768
|
+
await next.dispose();
|
|
769
|
+
throw new Error(spec?.diagnostics.join('\n') || 'No Work shell defined.');
|
|
770
|
+
}
|
|
771
|
+
await repl.dispose();
|
|
772
|
+
repl = next;
|
|
773
|
+
runtime.repl = next;
|
|
774
|
+
runtime.mode = mode;
|
|
775
|
+
runtime.harnessName = target;
|
|
776
|
+
runtime.sessionId = next.session.getSessionId();
|
|
777
|
+
runtime.resumedSession = counterpart;
|
|
778
|
+
runtime.promptPrefix = mode === 'work' ? 'work> ' : config.repl.promptPrefix ?? 'dml> ';
|
|
779
|
+
runtime.workSpec = spec;
|
|
780
|
+
// Keep whatever the user chose with /details; the default is now the same
|
|
781
|
+
// for Develop and Work, so a mode switch no longer resets it.
|
|
782
|
+
runtime.renderer.setDetails?.(runtime.details ?? replDetailsDefault(options.events));
|
|
783
|
+
statusTracker = new ReplStatusTracker({ model: { id: harnessModel, provider: String(harnessProvider), reasoning, thinkingLevel }, contextWindow });
|
|
784
|
+
statusHolder.tracker = statusTracker;
|
|
785
|
+
wireProcesses(next);
|
|
786
|
+
next.session.setImageHandler(lines => runtime.renderer.image(lines));
|
|
787
|
+
runtime.onSessionChanged?.();
|
|
788
|
+
},
|
|
631
789
|
repl,
|
|
632
790
|
renderer,
|
|
633
791
|
workspace,
|
|
634
|
-
promptPrefix: config.repl.promptPrefix ?? 'dml> ',
|
|
792
|
+
promptPrefix: purpose === 'work' ? 'work> ' : config.repl.promptPrefix ?? 'dml> ',
|
|
635
793
|
toolset,
|
|
636
794
|
version: PACKAGE_VERSION,
|
|
637
795
|
imageBackend,
|
|
@@ -652,12 +810,12 @@ export async function createReplRuntime(options) {
|
|
|
652
810
|
statusSnapshot: () => statusTracker.snapshot(),
|
|
653
811
|
observeEvent: (event) => statusTracker.observe(event),
|
|
654
812
|
tuiMode: options.tui ?? config.repl.tui ?? 'auto',
|
|
655
|
-
setOnInput: (handler) => repl.setOnInput(handler),
|
|
813
|
+
setOnInput: (handler) => { currentInput = handler; repl.setOnInput(handler); },
|
|
656
814
|
missingCredential,
|
|
657
815
|
};
|
|
658
816
|
// Session-scoped subagents render their lifecycle and output through the
|
|
659
817
|
// active renderer (the TUI swaps it in after this runtime is built).
|
|
660
|
-
|
|
818
|
+
const wireProcesses = (current) => current.session.setProcessEventSink((event) => {
|
|
661
819
|
const label = `⚙ ${event.name}`;
|
|
662
820
|
const sink = runtime.renderer;
|
|
663
821
|
if (event.type === 'output' && event.content) {
|
|
@@ -671,6 +829,8 @@ export async function createReplRuntime(options) {
|
|
|
671
829
|
sink.writeLine(`${label} ${event.state}${reason}`);
|
|
672
830
|
}
|
|
673
831
|
});
|
|
832
|
+
wireProcesses(repl);
|
|
833
|
+
runtime.renderer.setDetails?.(runtime.details ?? true);
|
|
674
834
|
return runtime;
|
|
675
835
|
}
|
|
676
836
|
/** Package version, read once from package.json for the banner/`--version`. */
|
|
@@ -686,6 +846,17 @@ export const PACKAGE_VERSION = (() => {
|
|
|
686
846
|
})();
|
|
687
847
|
/** Startup banner for the interactive REPL (proposal §2.1). */
|
|
688
848
|
async function printBanner(runtime, loaded) {
|
|
849
|
+
if (runtime.mode === 'work') {
|
|
850
|
+
const spec = runtime.workSpec ?? await runtime.repl.workSpec();
|
|
851
|
+
runtime.workSpec = spec;
|
|
852
|
+
runtime.renderer.writeLine(`DeepClause · WORK · ${runtime.harnessName} · ${spec.shell?.kind ?? 'no shell'} · ${runtime.model}`);
|
|
853
|
+
if (spec.shell?.welcome)
|
|
854
|
+
runtime.renderer.writeLine(spec.shell.welcome);
|
|
855
|
+
for (const diagnostic of spec.diagnostics)
|
|
856
|
+
runtime.renderer.writeLine(diagnostic);
|
|
857
|
+
runtime.renderer.writeLine('/workflows — choose a task · /mode — switch conversation · /details — execution detail');
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
689
860
|
const rich = runtime.renderer.mode === 'rich';
|
|
690
861
|
const paint = (text, code) => (rich ? `\u001b[${code}m${text}\u001b[0m` : text);
|
|
691
862
|
const dim = (text) => paint(text, '2');
|
|
@@ -735,6 +906,28 @@ async function printBanner(runtime, loaded) {
|
|
|
735
906
|
* starting blank. Bounded, and skipped when the session was not resumed or
|
|
736
907
|
* tracing was off.
|
|
737
908
|
*/
|
|
909
|
+
/**
|
|
910
|
+
* Continue a session that was suspended with `suspend/1`.
|
|
911
|
+
*
|
|
912
|
+
* The turn stopped at a safe point and the host wrote the goal that resumes it
|
|
913
|
+
* (docs/DML_REPL_SUSPEND_RESUME.md). Resuming means running that goal once the
|
|
914
|
+
* harness and memory are restored — so `--session` picks the program up where it
|
|
915
|
+
* left off instead of dropping the user into a half-finished state. The record is
|
|
916
|
+
* cleared first: if the continuation suspends again it writes a fresh one.
|
|
917
|
+
*/
|
|
918
|
+
async function resumeSuspendedContinuation(runtime) {
|
|
919
|
+
const pending = runtime.repl.session.pendingSuspension?.();
|
|
920
|
+
if (!pending)
|
|
921
|
+
return;
|
|
922
|
+
runtime.renderer.writeLine(`resuming the suspended continuation: ${pending.continuation}`);
|
|
923
|
+
try {
|
|
924
|
+
for await (const event of runtime.repl.resumeSuspension())
|
|
925
|
+
runtime.renderer.render(event);
|
|
926
|
+
}
|
|
927
|
+
catch (error) {
|
|
928
|
+
runtime.renderer.writeLine(`could not resume ${pending.continuation}: ${String(error.message)}`);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
738
931
|
async function renderResumedSession(runtime) {
|
|
739
932
|
const events = await runtime.repl.resumedTranscript().catch(() => []);
|
|
740
933
|
if (events.length === 0)
|
|
@@ -749,7 +942,57 @@ async function renderResumedSession(runtime) {
|
|
|
749
942
|
export async function dispatchReplInput(runtime, input, options = {}) {
|
|
750
943
|
const { repl, renderer } = runtime;
|
|
751
944
|
const print = options.print ?? ((text) => renderer.writeLine(text));
|
|
945
|
+
if (runtime.mode === 'work' && ['goal', 'reset', 'rollback', 'spawn', 'send', 'call', 'freeze', 'unfreeze'].includes(input.kind)) {
|
|
946
|
+
print('This is a Develop operation. Use /mode develop to open a separate authoring conversation.');
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
752
949
|
switch (input.kind) {
|
|
950
|
+
case 'mode': {
|
|
951
|
+
if (!input.mode) {
|
|
952
|
+
print(`mode: ${runtime.mode ?? 'develop'}; use /mode work|develop [harness]`);
|
|
953
|
+
return true;
|
|
954
|
+
}
|
|
955
|
+
try {
|
|
956
|
+
await runtime.switchMode?.(input.mode, input.harness);
|
|
957
|
+
print(`${runtime.mode} · ${runtime.harnessName} · session ${runtime.sessionId}`);
|
|
958
|
+
if (runtime.workSpec?.shell?.welcome)
|
|
959
|
+
print(runtime.workSpec.shell.welcome);
|
|
960
|
+
await renderResumedSession(runtime);
|
|
961
|
+
}
|
|
962
|
+
catch (error) {
|
|
963
|
+
print(`ERROR: ${error.message}`);
|
|
964
|
+
}
|
|
965
|
+
return true;
|
|
966
|
+
}
|
|
967
|
+
case 'details':
|
|
968
|
+
runtime.details = input.show ?? !runtime.details;
|
|
969
|
+
renderer.setDetails?.(runtime.details);
|
|
970
|
+
print(`details ${runtime.details ? 'on' : 'off'}`);
|
|
971
|
+
return true;
|
|
972
|
+
case 'workflows': {
|
|
973
|
+
const spec = await repl.workSpec();
|
|
974
|
+
if (!spec.shell)
|
|
975
|
+
print(spec.diagnostics.join('\n'));
|
|
976
|
+
else {
|
|
977
|
+
for (const flow of spec.shell.workflows)
|
|
978
|
+
print(`${flow.name} — ${flow.inputs.map(arg => `${arg.name}: ${arg.type}`).join(', ') || 'no inputs'} → ${flow.outputs.map(arg => `${arg.name}: ${arg.type}`).join(', ') || 'no outputs'}`);
|
|
979
|
+
if (spec.shell.tools.length)
|
|
980
|
+
print(`Assistant tools (not directly runnable): ${spec.shell.tools.map(tool => tool.name).join(', ')}`);
|
|
981
|
+
}
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
case 'workflow':
|
|
985
|
+
if (runtime.mode !== 'work') {
|
|
986
|
+
print('Use /mode work before starting a declared workflow.');
|
|
987
|
+
return true;
|
|
988
|
+
}
|
|
989
|
+
try {
|
|
990
|
+
await runDeclaredWorkflow({ repl, name: input.name, inputs: input.inputs, signal: options.signal, ask: runtime.askInput, render: event => renderer.render(event) });
|
|
991
|
+
}
|
|
992
|
+
catch (error) {
|
|
993
|
+
print(`ERROR: ${error.message}`);
|
|
994
|
+
}
|
|
995
|
+
return true;
|
|
753
996
|
case 'empty':
|
|
754
997
|
case 'comment':
|
|
755
998
|
return true;
|
|
@@ -797,16 +1040,23 @@ export async function dispatchReplInput(runtime, input, options = {}) {
|
|
|
797
1040
|
print(`stopped ${input.target}`);
|
|
798
1041
|
return true;
|
|
799
1042
|
}
|
|
800
|
-
case 'login':
|
|
801
|
-
|
|
1043
|
+
case 'login': {
|
|
1044
|
+
const flags = [
|
|
1045
|
+
input.provider ? `--provider ${input.provider}` : '',
|
|
1046
|
+
input.baseUrl ? `--base-url ${input.baseUrl}` : '',
|
|
1047
|
+
input.host ? `--host ${input.host}` : '',
|
|
1048
|
+
input.port ? `--port ${input.port}` : '',
|
|
1049
|
+
].filter(Boolean).join(' ');
|
|
1050
|
+
print(`sign in from the terminal: deepclause login${flags ? ` ${flags}` : ''}`);
|
|
802
1051
|
return true;
|
|
1052
|
+
}
|
|
803
1053
|
case 'unknown-command':
|
|
804
1054
|
print(`unknown command: /${input.name} — try /help.`);
|
|
805
1055
|
return true;
|
|
806
1056
|
case 'halt':
|
|
807
1057
|
return false;
|
|
808
1058
|
case 'help':
|
|
809
|
-
print(helpText());
|
|
1059
|
+
print(helpText(runtime.mode));
|
|
810
1060
|
return true;
|
|
811
1061
|
case 'listing': {
|
|
812
1062
|
const text = await repl.list(input.filter);
|
|
@@ -955,6 +1205,13 @@ export async function dispatchReplInput(runtime, input, options = {}) {
|
|
|
955
1205
|
await runGoalWithRenderer(repl, input.goal, { first: options.first, renderer, signal: options.signal });
|
|
956
1206
|
return true;
|
|
957
1207
|
case 'prompt': {
|
|
1208
|
+
if (runtime.mode === 'work') {
|
|
1209
|
+
const spec = await repl.workSpec();
|
|
1210
|
+
if (!spec.shell || spec.shell.kind === 'workflow') {
|
|
1211
|
+
print(spec.diagnostics.join('\n') || 'Choose a declared workflow with /workflows.');
|
|
1212
|
+
return true;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
958
1215
|
if (runtime.missingCredential) {
|
|
959
1216
|
print(`ERROR: ${runtime.missingCredential}`);
|
|
960
1217
|
return true;
|
|
@@ -968,8 +1225,21 @@ export async function dispatchReplInput(runtime, input, options = {}) {
|
|
|
968
1225
|
return true;
|
|
969
1226
|
}
|
|
970
1227
|
}
|
|
971
|
-
function helpText() {
|
|
1228
|
+
function helpText(mode) {
|
|
1229
|
+
if (mode === 'work')
|
|
1230
|
+
return [
|
|
1231
|
+
'Work runs a declared harness; it does not author DML.',
|
|
1232
|
+
' /mode work|develop [harness] choose another conversation',
|
|
1233
|
+
' /workflows choose/list declared workflows',
|
|
1234
|
+
' /workflow "Name" {"Input":"value"} execute exactly that workflow',
|
|
1235
|
+
' /details [on|off] show technical events',
|
|
1236
|
+
' /model · /reasoning · /show-reasoning · /compact · /ps · /stop · /halt',
|
|
1237
|
+
'An agent shell accepts conversation. A workflow-only shell uses /workflow.',
|
|
1238
|
+
'Use /mode work <harness> again to refresh into a new snapshot.'
|
|
1239
|
+
].join('\n');
|
|
972
1240
|
return [
|
|
1241
|
+
' /mode [develop|work] [harness] switch conversation purpose',
|
|
1242
|
+
' /workflows /workflow /details declared Work tasks and presentation',
|
|
973
1243
|
'DeepClause REPL — a living DML harness you author by talking to it.',
|
|
974
1244
|
'',
|
|
975
1245
|
' Modes',
|
|
@@ -994,7 +1264,7 @@ function helpText() {
|
|
|
994
1264
|
' /compact [notes] compact the authoring memory',
|
|
995
1265
|
' /export [file] save the harness (use .zip to bundle linked files)',
|
|
996
1266
|
' /model [provider/id] show / set the model',
|
|
997
|
-
' /login
|
|
1267
|
+
' /login [provider] sign in; llama.cpp accepts --host, --port, --base-url',
|
|
998
1268
|
' /freeze /unfreeze read-only lock',
|
|
999
1269
|
' /params show session parameters',
|
|
1000
1270
|
' /trace /notrace toggle verbose logging',
|
|
@@ -1242,6 +1512,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1242
1512
|
const working = new WorkingLine(tui);
|
|
1243
1513
|
const renderer = new TuiRenderer({
|
|
1244
1514
|
document,
|
|
1515
|
+
events: runtime.details ?? true,
|
|
1245
1516
|
// The TUI draws through its own switch, but the status tracker must still see
|
|
1246
1517
|
// every event (usage, model_call, …) or the footer loses its counters.
|
|
1247
1518
|
onEvent: (event) => runtime.observeEvent(event),
|
|
@@ -1259,11 +1530,14 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1259
1530
|
const statusBar = new StatusBarComponent({
|
|
1260
1531
|
getSnapshot: () => runtime.statusSnapshot(),
|
|
1261
1532
|
workspace: runtime.workspace,
|
|
1262
|
-
sessionId: runtime.sessionId,
|
|
1263
|
-
harness: runtime.harnessName,
|
|
1533
|
+
sessionId: () => runtime.sessionId,
|
|
1534
|
+
harness: () => runtime.harnessName,
|
|
1535
|
+
mode: () => runtime.mode ?? 'develop',
|
|
1536
|
+
workVersion: () => runtime.mode === 'work' && runtime.workSpec ? `${runtime.workSpec.version !== undefined ? `v${runtime.workSpec.version} ` : ''}${runtime.workSpec.hash.slice(0, 6)}` : undefined,
|
|
1264
1537
|
backend: runtime.backend,
|
|
1265
1538
|
isFrozen: () => runtime.repl.isFrozen(),
|
|
1266
1539
|
isRunning: () => runState.running,
|
|
1540
|
+
canSteer: () => runState.steerable,
|
|
1267
1541
|
processLabel: () => {
|
|
1268
1542
|
const active = runtime.repl.session
|
|
1269
1543
|
.processes()
|
|
@@ -1413,7 +1687,9 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1413
1687
|
? label
|
|
1414
1688
|
: label === ' ;'
|
|
1415
1689
|
? 'Enter/; more · a all · . stop'
|
|
1416
|
-
:
|
|
1690
|
+
: label === runtime.promptPrefix
|
|
1691
|
+
? null
|
|
1692
|
+
: label;
|
|
1417
1693
|
editor.setPrompt(hint);
|
|
1418
1694
|
tui.setFocus(editor);
|
|
1419
1695
|
}
|
|
@@ -1613,7 +1889,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1613
1889
|
renderer.writeLine(`harness view ${harnessWidth} columns`);
|
|
1614
1890
|
};
|
|
1615
1891
|
const pickModel = async () => {
|
|
1616
|
-
const catalog = runtime.modelResolver?.catalog() ?? [];
|
|
1892
|
+
const catalog = runtime.modelPickerCatalog ?? runtime.modelResolver?.catalog() ?? [];
|
|
1617
1893
|
if (catalog.length === 0) {
|
|
1618
1894
|
renderer.writeLine(`model: ${runtime.model} (no catalog to choose from; set one in config)`);
|
|
1619
1895
|
return;
|
|
@@ -1621,7 +1897,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1621
1897
|
const current = runtime.model.includes(':') ? runtime.model : undefined;
|
|
1622
1898
|
const picked = await choose((done) => new ChoicePicker({
|
|
1623
1899
|
title: 'Model',
|
|
1624
|
-
hint: 'The default for this workspace (applies
|
|
1900
|
+
hint: 'The default for this workspace (applies on the next CLI start)',
|
|
1625
1901
|
current,
|
|
1626
1902
|
items: catalog.map((entry) => ({
|
|
1627
1903
|
value: entry.model,
|
|
@@ -1639,7 +1915,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1639
1915
|
renderer.writeLine(`default model set to ${picked} (takes effect on the next start)`);
|
|
1640
1916
|
};
|
|
1641
1917
|
/** `/login`: sign in to a provider from inside the TUI. */
|
|
1642
|
-
const runLogin = async () => {
|
|
1918
|
+
const runLogin = async (input) => {
|
|
1643
1919
|
let handle;
|
|
1644
1920
|
try {
|
|
1645
1921
|
handle = await openPiRuntime({});
|
|
@@ -1653,19 +1929,64 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1653
1929
|
renderer.writeLine('no login providers available');
|
|
1654
1930
|
return;
|
|
1655
1931
|
}
|
|
1656
|
-
const
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
description: provider.configured ? '✓ configured' : provider.authType,
|
|
1663
|
-
})),
|
|
1664
|
-
onSelect: (item) => done(item.value),
|
|
1665
|
-
onCancel: () => done(),
|
|
1666
|
-
}));
|
|
1667
|
-
if (!picked)
|
|
1932
|
+
const explicitEndpoint = input.baseUrl !== undefined
|
|
1933
|
+
|| input.host !== undefined
|
|
1934
|
+
|| input.port !== undefined;
|
|
1935
|
+
let picked = input.provider ?? (explicitEndpoint ? LLAMA_PROVIDER_ID : undefined);
|
|
1936
|
+
if (picked && !providers.some((provider) => provider.id === picked)) {
|
|
1937
|
+
renderer.writeLine(`unknown login provider: ${picked}`);
|
|
1668
1938
|
return;
|
|
1939
|
+
}
|
|
1940
|
+
if (!picked) {
|
|
1941
|
+
picked = await choose((done) => new ChoicePicker({
|
|
1942
|
+
title: 'Sign in to a provider',
|
|
1943
|
+
hint: 'Esc to cancel',
|
|
1944
|
+
items: providers.map((provider) => ({
|
|
1945
|
+
value: provider.id,
|
|
1946
|
+
label: `${provider.name} (${provider.id})`,
|
|
1947
|
+
description: provider.configured ? '✓ configured' : provider.authType,
|
|
1948
|
+
})),
|
|
1949
|
+
onSelect: (item) => done(item.value),
|
|
1950
|
+
onCancel: () => done(),
|
|
1951
|
+
}));
|
|
1952
|
+
if (!picked)
|
|
1953
|
+
return;
|
|
1954
|
+
}
|
|
1955
|
+
// llama.cpp is the one provider whose endpoint is a local/remote server.
|
|
1956
|
+
// Collect it as a base URL, a host:port, or a bare host + port instead of
|
|
1957
|
+
// making the user type a full scheme in pi's generic URL prompt.
|
|
1958
|
+
let baseUrl = input.baseUrl;
|
|
1959
|
+
let host = input.host;
|
|
1960
|
+
let port = input.port;
|
|
1961
|
+
if (picked === LLAMA_PROVIDER_ID && !explicitEndpoint) {
|
|
1962
|
+
const envUrl = process.env.LLAMA_BASE_URL?.trim();
|
|
1963
|
+
const endpointAnswer = await ask(`llama.cpp host or base URL (${envUrl ?? '127.0.0.1'}) `);
|
|
1964
|
+
if (endpointAnswer === null)
|
|
1965
|
+
return;
|
|
1966
|
+
const endpoint = endpointAnswer.trim();
|
|
1967
|
+
if (endpoint && /^https?:\/\//i.test(endpoint)) {
|
|
1968
|
+
baseUrl = endpoint;
|
|
1969
|
+
}
|
|
1970
|
+
else if (!endpoint && envUrl) {
|
|
1971
|
+
baseUrl = envUrl;
|
|
1972
|
+
}
|
|
1973
|
+
else {
|
|
1974
|
+
host = endpoint || '127.0.0.1';
|
|
1975
|
+
let hasPort = false;
|
|
1976
|
+
try {
|
|
1977
|
+
hasPort = Boolean(new URL(`http://${host}`).port);
|
|
1978
|
+
}
|
|
1979
|
+
catch {
|
|
1980
|
+
// resolveLlamaServerUrl reports a precise error after the prompts.
|
|
1981
|
+
}
|
|
1982
|
+
if (!hasPort) {
|
|
1983
|
+
const portAnswer = await ask('llama.cpp port (8080) ');
|
|
1984
|
+
if (portAnswer === null)
|
|
1985
|
+
return;
|
|
1986
|
+
port = portAnswer.trim() || '8080';
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1669
1990
|
const interaction = {
|
|
1670
1991
|
prompt: async (prompt) => {
|
|
1671
1992
|
if (prompt.options && prompt.options.length > 0) {
|
|
@@ -1698,9 +2019,18 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1698
2019
|
},
|
|
1699
2020
|
};
|
|
1700
2021
|
try {
|
|
1701
|
-
await loginToProvider(handle, picked, {
|
|
2022
|
+
await loginToProvider(handle, picked, {
|
|
2023
|
+
interaction,
|
|
2024
|
+
baseUrl,
|
|
2025
|
+
host,
|
|
2026
|
+
port,
|
|
2027
|
+
});
|
|
1702
2028
|
await persistSetting({ backend: { kind: 'pi' } }, 'login');
|
|
1703
|
-
|
|
2029
|
+
// The active backend's registry predates this login. Use the login
|
|
2030
|
+
// session's refreshed registry for /model so the new provider/models are
|
|
2031
|
+
// visible immediately (the choice still applies on the next start).
|
|
2032
|
+
runtime.modelPickerCatalog = new PiModelResolver(handle.registry).catalog();
|
|
2033
|
+
renderer.writeLine(`signed in to ${picked} (use /model <provider/id> to set the default for the next start)`);
|
|
1704
2034
|
}
|
|
1705
2035
|
catch (error) {
|
|
1706
2036
|
renderer.writeLine(`login failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -1725,6 +2055,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1725
2055
|
},
|
|
1726
2056
|
});
|
|
1727
2057
|
harnessView.refresh();
|
|
2058
|
+
const workView = new WorkView(() => runtime.workSpec);
|
|
1728
2059
|
let harnessVisible = options.harnessView ?? false;
|
|
1729
2060
|
let servicesVisible = false;
|
|
1730
2061
|
let servicesLogs = false;
|
|
@@ -1783,12 +2114,12 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1783
2114
|
const columns = new HStack([
|
|
1784
2115
|
{ component: scroll, basis: 0, grow: 1, shrink: 1, minSize: 20 },
|
|
1785
2116
|
{
|
|
1786
|
-
component: harnessView,
|
|
2117
|
+
component: runtime.mode === 'work' ? workView : harnessView,
|
|
1787
2118
|
basis: harnessWidth,
|
|
1788
2119
|
grow: 0,
|
|
1789
2120
|
shrink: 0,
|
|
1790
2121
|
minSize: 20,
|
|
1791
|
-
visible: (viewport) => harnessVisible && viewport.width >= 96,
|
|
2122
|
+
visible: (viewport) => (runtime.mode === 'work' || harnessVisible) && viewport.width >= 96,
|
|
1792
2123
|
},
|
|
1793
2124
|
], { gap: 1 });
|
|
1794
2125
|
tui.setLayoutRoot(new VStack([
|
|
@@ -1800,7 +2131,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1800
2131
|
applyLayout();
|
|
1801
2132
|
// A form opened by the running turn is shown in the dock and edited field by
|
|
1802
2133
|
// field through the editor; the plain-TTY path uses the raw widget instead.
|
|
1803
|
-
|
|
2134
|
+
const presentTuiForm = async (form) => {
|
|
1804
2135
|
const spec = form.spec;
|
|
1805
2136
|
if (!spec)
|
|
1806
2137
|
return;
|
|
@@ -1830,11 +2161,21 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1830
2161
|
formView.setState(undefined);
|
|
1831
2162
|
tui.requestRender();
|
|
1832
2163
|
}
|
|
1833
|
-
}
|
|
2164
|
+
};
|
|
2165
|
+
runtime.repl.session.setFormHandler(presentTuiForm);
|
|
2166
|
+
runtime.onSessionChanged = () => {
|
|
2167
|
+
runtime.repl.session.setFormHandler(presentTuiForm);
|
|
2168
|
+
runtime.repl.session.setImageHandler(lines => runtime.renderer.image(lines));
|
|
2169
|
+
harnessView.refresh();
|
|
2170
|
+
applyLayout();
|
|
2171
|
+
tui.invalidate();
|
|
2172
|
+
tui.requestRender();
|
|
2173
|
+
};
|
|
1834
2174
|
tui.start();
|
|
1835
2175
|
await printBanner(runtime, loaded);
|
|
1836
2176
|
await renderResumedSession(runtime);
|
|
1837
2177
|
tui.requestRender();
|
|
2178
|
+
await resumeSuspendedContinuation(runtime);
|
|
1838
2179
|
try {
|
|
1839
2180
|
while (true) {
|
|
1840
2181
|
// A slash command typed while a turn/command was running: run it now that
|
|
@@ -1849,9 +2190,44 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1849
2190
|
if (line === null)
|
|
1850
2191
|
break;
|
|
1851
2192
|
}
|
|
1852
|
-
|
|
2193
|
+
let input = classifyReplInput(line);
|
|
1853
2194
|
if (input.kind === 'halt')
|
|
1854
2195
|
break;
|
|
2196
|
+
if (input.kind === 'mode' && !input.mode) {
|
|
2197
|
+
const mode = await choose(done => new ChoicePicker({ title: 'Conversation mode', items: [
|
|
2198
|
+
{ value: 'develop', label: 'Develop', description: 'Author and edit a harness' },
|
|
2199
|
+
{ value: 'work', label: 'Work', description: 'Use declared tools and workflows' },
|
|
2200
|
+
], onSelect: item => done(item.value), onCancel: () => done() }));
|
|
2201
|
+
if (!mode)
|
|
2202
|
+
continue;
|
|
2203
|
+
let harness;
|
|
2204
|
+
if (mode === 'work') {
|
|
2205
|
+
const names = await runtime.harnesses?.() ?? [];
|
|
2206
|
+
if (!names.length) {
|
|
2207
|
+
renderer.writeLine('No harnesses yet. Create one in Develop first.');
|
|
2208
|
+
continue;
|
|
2209
|
+
}
|
|
2210
|
+
harness = await choose(done => new ChoicePicker({ title: 'Work harness', current: runtime.harnessName,
|
|
2211
|
+
items: names.map(name => ({ value: name, label: name })), onSelect: item => done(item.value), onCancel: () => done() }));
|
|
2212
|
+
if (!harness)
|
|
2213
|
+
continue;
|
|
2214
|
+
}
|
|
2215
|
+
input = { kind: 'mode', mode: mode, harness };
|
|
2216
|
+
}
|
|
2217
|
+
if (input.kind === 'workflows' && runtime.mode === 'work') {
|
|
2218
|
+
const spec = await runtime.repl.workSpec();
|
|
2219
|
+
runtime.workSpec = spec;
|
|
2220
|
+
if (!spec.shell?.workflows.length) {
|
|
2221
|
+
renderer.writeLine(spec.diagnostics.join('\n') || 'No workflows; use the Work assistant.');
|
|
2222
|
+
continue;
|
|
2223
|
+
}
|
|
2224
|
+
const name = await choose(done => new ChoicePicker({ title: 'Workflows', items: spec.shell.workflows.map(flow => ({
|
|
2225
|
+
value: flow.name, label: flow.name, description: `${flow.inputs.length} inputs · ${flow.outputs.length} outputs`,
|
|
2226
|
+
})), onSelect: item => done(item.value), onCancel: () => done() }));
|
|
2227
|
+
if (!name)
|
|
2228
|
+
continue;
|
|
2229
|
+
input = { kind: 'workflow', name };
|
|
2230
|
+
}
|
|
1855
2231
|
// The pickers are overlays over the transcript, so they need the TUI and are
|
|
1856
2232
|
// handled here rather than in the command dispatcher the readline path shares.
|
|
1857
2233
|
if (input.kind === 'model' && !input.model) {
|
|
@@ -1867,11 +2243,15 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1867
2243
|
continue;
|
|
1868
2244
|
}
|
|
1869
2245
|
if (input.kind === 'harness') {
|
|
2246
|
+
if (runtime.mode === 'work') {
|
|
2247
|
+
renderer.writeLine('The source side view is in Develop; use /workflows here.');
|
|
2248
|
+
continue;
|
|
2249
|
+
}
|
|
1870
2250
|
await handleHarnessCommand(input.width);
|
|
1871
2251
|
continue;
|
|
1872
2252
|
}
|
|
1873
2253
|
if (input.kind === 'login') {
|
|
1874
|
-
await runLogin();
|
|
2254
|
+
await runLogin(input);
|
|
1875
2255
|
continue;
|
|
1876
2256
|
}
|
|
1877
2257
|
if (input.kind === 'ps' && (input.watch || input.logs)) {
|
|
@@ -1957,7 +2337,7 @@ export async function startRepl(options) {
|
|
|
1957
2337
|
// saved, or when the harness has no predicates.
|
|
1958
2338
|
let exitSaved = false;
|
|
1959
2339
|
const saveHarnessOnExit = async () => {
|
|
1960
|
-
if (exitSaved || options.exportPath || options.saveOnExit === false)
|
|
2340
|
+
if (runtime.mode === 'work' || exitSaved || options.exportPath || options.saveOnExit === false)
|
|
1961
2341
|
return;
|
|
1962
2342
|
exitSaved = true;
|
|
1963
2343
|
try {
|
|
@@ -1980,6 +2360,25 @@ export async function startRepl(options) {
|
|
|
1980
2360
|
if (options.load?.length) {
|
|
1981
2361
|
await runtime.repl.session.finalizeHarnessBaseline();
|
|
1982
2362
|
}
|
|
2363
|
+
if (runtime.mode === 'work')
|
|
2364
|
+
runtime.workSpec = await runtime.repl.workSpec();
|
|
2365
|
+
if (options.workflow) {
|
|
2366
|
+
const controller = new AbortController();
|
|
2367
|
+
const removeSigint = installSigint({ turn: controller });
|
|
2368
|
+
try {
|
|
2369
|
+
const inputs = options.inputs === undefined ? undefined : JSON.parse(options.inputs);
|
|
2370
|
+
const ok = await runDeclaredWorkflow({ repl: runtime.repl, name: options.workflow, inputs,
|
|
2371
|
+
signal: controller.signal, ask: runtime.askInput, render: event => runtime.renderer.render(event) });
|
|
2372
|
+
return ok ? 0 : 1;
|
|
2373
|
+
}
|
|
2374
|
+
catch (error) {
|
|
2375
|
+
runtime.renderer.writeErrorLine(`ERROR: ${error.message}`);
|
|
2376
|
+
return 1;
|
|
2377
|
+
}
|
|
2378
|
+
finally {
|
|
2379
|
+
removeSigint();
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
1983
2382
|
// Freeze/lock only after all `-l` loads succeed (load before lock).
|
|
1984
2383
|
if (options.locked) {
|
|
1985
2384
|
await runtime.repl.lock();
|
|
@@ -2024,6 +2423,7 @@ export async function startRepl(options) {
|
|
|
2024
2423
|
}
|
|
2025
2424
|
await printBanner(runtime, options.load ?? []);
|
|
2026
2425
|
await renderResumedSession(runtime);
|
|
2426
|
+
await resumeSuspendedContinuation(runtime);
|
|
2027
2427
|
return await runInteractive(runtime, options, saveHarnessOnExit);
|
|
2028
2428
|
}
|
|
2029
2429
|
finally {
|
|
@@ -2056,6 +2456,13 @@ export function registerReplCommand(program) {
|
|
|
2056
2456
|
.option('-g, --goal <goal>', 'run one goal and exit (repeatable)', collect)
|
|
2057
2457
|
.option('-l, --load <file>', 'load a DML file before starting (repeatable)', collect)
|
|
2058
2458
|
.option('--session <id>', 'resume a previous session by id (or "last")')
|
|
2459
|
+
.option('--mode <mode>', 'conversation purpose: develop (default) or work', (value) => {
|
|
2460
|
+
if (value !== 'develop' && value !== 'work')
|
|
2461
|
+
throw new Error('mode must be develop or work');
|
|
2462
|
+
return value;
|
|
2463
|
+
})
|
|
2464
|
+
.option('--workflow <name>', 'run exactly this declared Work workflow and exit')
|
|
2465
|
+
.option('--inputs <json>', 'workflow inputs as a JSON object')
|
|
2059
2466
|
.option('--harness <name>', 'harness to edit (a project can hold several; default main)')
|
|
2060
2467
|
.option('--first', 'with a goal, print only the first solution')
|
|
2061
2468
|
.option('--plain', 'no TUI formatting (auto when stdout is not a TTY)')
|
|
@@ -2111,6 +2518,9 @@ export function registerReplCommand(program) {
|
|
|
2111
2518
|
.option('--no-color', 'disable ANSI color')
|
|
2112
2519
|
.action(async (options) => {
|
|
2113
2520
|
const exitCode = await startRepl({
|
|
2521
|
+
mode: options.mode,
|
|
2522
|
+
workflow: options.workflow,
|
|
2523
|
+
inputs: options.inputs,
|
|
2114
2524
|
goal: options.goal,
|
|
2115
2525
|
load: options.load,
|
|
2116
2526
|
session: options.session,
|
|
@@ -2165,8 +2575,12 @@ export function normalizeHarnessName(name) {
|
|
|
2165
2575
|
const trimmed = name?.trim();
|
|
2166
2576
|
if (!trimmed)
|
|
2167
2577
|
return undefined;
|
|
2168
|
-
|
|
2169
|
-
|
|
2578
|
+
let slug = trimmed.toLowerCase().replace(/[^a-z0-9_]+/g, '_').replace(/^_+|_+$/g, '');
|
|
2579
|
+
if (!slug)
|
|
2580
|
+
return undefined;
|
|
2581
|
+
if (!/^[a-z]/.test(slug))
|
|
2582
|
+
slug = `h_${slug}`;
|
|
2583
|
+
return slug;
|
|
2170
2584
|
}
|
|
2171
2585
|
/** Harness name implied by a `-l` file: its basename without the `.dml`/`.zip`. */
|
|
2172
2586
|
function harnessNameFromFile(file) {
|