deepclause-sdk 0.4.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.
Files changed (131) hide show
  1. package/README.md +134 -2
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +154 -28
  4. package/dist/agent.js.map +1 -1
  5. package/dist/cli/config.d.ts +150 -140
  6. package/dist/cli/config.d.ts.map +1 -1
  7. package/dist/cli/config.js +3 -0
  8. package/dist/cli/config.js.map +1 -1
  9. package/dist/cli/login.d.ts +2 -1
  10. package/dist/cli/login.d.ts.map +1 -1
  11. package/dist/cli/login.js +15 -2
  12. package/dist/cli/login.js.map +1 -1
  13. package/dist/cli/repl.d.ts +54 -1
  14. package/dist/cli/repl.d.ts.map +1 -1
  15. package/dist/cli/repl.js +437 -54
  16. package/dist/cli/repl.js.map +1 -1
  17. package/dist/cli/set-backend.d.ts +2 -2
  18. package/dist/cli/set-backend.d.ts.map +1 -1
  19. package/dist/cli/set-backend.js +54 -8
  20. package/dist/cli/set-backend.js.map +1 -1
  21. package/dist/cli/work.d.ts +16 -0
  22. package/dist/cli/work.d.ts.map +1 -0
  23. package/dist/cli/work.js +45 -0
  24. package/dist/cli/work.js.map +1 -0
  25. package/dist/index.d.ts +8 -6
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +4 -3
  28. package/dist/index.js.map +1 -1
  29. package/dist/prolog-src/deepclause_mi.pl +2426 -253
  30. package/dist/prolog-src/deepclause_strings.pl +36 -3
  31. package/dist/repl/agent.d.ts +5 -0
  32. package/dist/repl/agent.d.ts.map +1 -1
  33. package/dist/repl/agent.js +19 -7
  34. package/dist/repl/agent.js.map +1 -1
  35. package/dist/repl/auth.d.ts +6 -3
  36. package/dist/repl/auth.d.ts.map +1 -1
  37. package/dist/repl/auth.js +55 -5
  38. package/dist/repl/auth.js.map +1 -1
  39. package/dist/repl/backend.d.ts +24 -0
  40. package/dist/repl/backend.d.ts.map +1 -1
  41. package/dist/repl/backend.js +292 -12
  42. package/dist/repl/backend.js.map +1 -1
  43. package/dist/repl/compaction.d.ts +2 -0
  44. package/dist/repl/compaction.d.ts.map +1 -1
  45. package/dist/repl/compaction.js +9 -0
  46. package/dist/repl/compaction.js.map +1 -1
  47. package/dist/repl/event-history.d.ts +4 -0
  48. package/dist/repl/event-history.d.ts.map +1 -0
  49. package/dist/repl/event-history.js +33 -0
  50. package/dist/repl/event-history.js.map +1 -0
  51. package/dist/repl/harness-tools.d.ts +25 -18
  52. package/dist/repl/harness-tools.d.ts.map +1 -1
  53. package/dist/repl/harness-tools.js +103 -34
  54. package/dist/repl/harness-tools.js.map +1 -1
  55. package/dist/repl/history.d.ts +52 -2
  56. package/dist/repl/history.d.ts.map +1 -1
  57. package/dist/repl/history.js +113 -4
  58. package/dist/repl/history.js.map +1 -1
  59. package/dist/repl/index.d.ts +27 -5
  60. package/dist/repl/index.d.ts.map +1 -1
  61. package/dist/repl/index.js +27 -0
  62. package/dist/repl/index.js.map +1 -1
  63. package/dist/repl/reference.d.ts +31 -0
  64. package/dist/repl/reference.d.ts.map +1 -0
  65. package/dist/repl/reference.js +143 -0
  66. package/dist/repl/reference.js.map +1 -0
  67. package/dist/repl/render.d.ts +3 -1
  68. package/dist/repl/render.d.ts.map +1 -1
  69. package/dist/repl/render.js +7 -0
  70. package/dist/repl/render.js.map +1 -1
  71. package/dist/repl/session.d.ts +128 -23
  72. package/dist/repl/session.d.ts.map +1 -1
  73. package/dist/repl/session.js +895 -196
  74. package/dist/repl/session.js.map +1 -1
  75. package/dist/repl/tui/autocomplete.d.ts.map +1 -1
  76. package/dist/repl/tui/autocomplete.js +5 -1
  77. package/dist/repl/tui/autocomplete.js.map +1 -1
  78. package/dist/repl/tui/renderer.d.ts +2 -1
  79. package/dist/repl/tui/renderer.d.ts.map +1 -1
  80. package/dist/repl/tui/renderer.js +20 -3
  81. package/dist/repl/tui/renderer.js.map +1 -1
  82. package/dist/repl/tui/status-bar.d.ts +5 -2
  83. package/dist/repl/tui/status-bar.d.ts.map +1 -1
  84. package/dist/repl/tui/status-bar.js +8 -3
  85. package/dist/repl/tui/status-bar.js.map +1 -1
  86. package/dist/repl/tui/tool-pane.d.ts +1 -1
  87. package/dist/repl/tui/tool-pane.d.ts.map +1 -1
  88. package/dist/repl/tui/tool-pane.js +13 -7
  89. package/dist/repl/tui/tool-pane.js.map +1 -1
  90. package/dist/repl/tui/work-view.d.ts +10 -0
  91. package/dist/repl/tui/work-view.d.ts.map +1 -0
  92. package/dist/repl/tui/work-view.js +28 -0
  93. package/dist/repl/tui/work-view.js.map +1 -0
  94. package/dist/runner.d.ts.map +1 -1
  95. package/dist/runner.js +50 -19
  96. package/dist/runner.js.map +1 -1
  97. package/dist/runtime-identity.json +10 -0
  98. package/dist/system/assets/docs/AGENT_PROMPT.md +265 -3008
  99. package/dist/system/assets/docs/DML_AUTHORING.md +81 -299
  100. package/dist/system/assets/docs/DML_BASICS.md +93 -0
  101. package/dist/system/assets/docs/DML_DEBUGGING.md +73 -0
  102. package/dist/system/assets/docs/DML_FORMS.md +94 -728
  103. package/dist/system/assets/docs/DML_MEDIA.md +63 -0
  104. package/dist/system/assets/docs/DML_PROCESSES.md +100 -0
  105. package/dist/system/assets/docs/DML_PYTHON.md +74 -0
  106. package/dist/system/assets/docs/DML_REFERENCE.md +224 -1971
  107. package/dist/system/assets/docs/DML_SHELL.md +107 -0
  108. package/dist/system/assets/docs/DML_TASKS.md +112 -0
  109. package/dist/system/assets/docs/HARNESS_EXAMPLES.md +255 -179
  110. package/dist/system/assets/docs/HARNESS_PATTERNS.md +65 -538
  111. package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +186 -0
  112. package/dist/system/assets/docs/PROLOG_SNIPPETS.md +61 -154
  113. package/dist/system/assets/index.d.ts +1 -1
  114. package/dist/system/assets/index.d.ts.map +1 -1
  115. package/dist/system/assets/index.js +7 -0
  116. package/dist/system/assets/index.js.map +1 -1
  117. package/dist/system/environment.d.ts +1 -1
  118. package/dist/system/environment.d.ts.map +1 -1
  119. package/dist/system/environment.js +10 -6
  120. package/dist/system/environment.js.map +1 -1
  121. package/dist/system/runtime/shell-manager.d.ts +1 -1
  122. package/dist/system/runtime/shell-manager.d.ts.map +1 -1
  123. package/dist/types.d.ts +49 -2
  124. package/dist/types.d.ts.map +1 -1
  125. package/dist/work/index.d.ts +82 -0
  126. package/dist/work/index.d.ts.map +1 -0
  127. package/dist/work/index.js +232 -0
  128. package/dist/work/index.js.map +1 -0
  129. package/package.json +12 -3
  130. package/src/prolog-src/deepclause_mi.pl +2426 -253
  131. 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, resolveReplCompactionConfig, updateConfig } from './config.js';
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 { kind: 'login' };
291
+ return parseLoginArgs(arg);
195
292
  default:
196
293
  return { kind: 'unknown-command', name };
197
294
  }
@@ -401,10 +498,10 @@ const PROVIDER_ENV_KEYS = {
401
498
  export async function createReplRuntime(options) {
402
499
  const workspace = path.resolve(options.workspace ?? './');
403
500
  const config = await loadReplConfig(workspace);
404
- const replCompaction = resolveReplCompactionConfig(config);
501
+ const runtimePolicy = resolveWorkbenchPolicy(config);
405
502
  // One harness per name within a project: `--harness`, else the `-l` file's
406
503
  // name, else the configured default (`main`).
407
- const harnessName = normalizeHarnessName(options.harness)
504
+ let harnessName = normalizeHarnessName(options.harness)
408
505
  ?? (options.load?.length ? harnessNameFromFile(options.load[0]) : undefined)
409
506
  ?? normalizeHarnessName(config.repl.harness)
410
507
  ?? 'main';
@@ -576,7 +673,11 @@ export async function createReplRuntime(options) {
576
673
  imageBackend = undefined;
577
674
  }
578
675
  }
579
- const repl = await createHarnessRepl({
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',
580
681
  sessionId,
581
682
  resume,
582
683
  workspacePath: workspace,
@@ -584,9 +685,10 @@ export async function createReplRuntime(options) {
584
685
  provider: harnessProvider,
585
686
  temperature: options.temperature ?? config.temperatures.run,
586
687
  params: options.param ?? {},
587
- gasLimit: options.gasLimit,
588
- maxDepth: options.depth ?? config.repl.maxDepth,
589
- maxModelCalls: options.maxModelCalls ?? config.repl.maxModelCalls,
688
+ gasLimit: options.gasLimit ?? runtimePolicy.gasLimit,
689
+ maxDepth: options.depth ?? runtimePolicy.maxDepth,
690
+ maxModelCalls: options.maxModelCalls ?? runtimePolicy.maxModelCalls,
691
+ providerConcurrency: runtimePolicy.providerConcurrency,
590
692
  tools: toolset.tools,
591
693
  hostToolsCatalog: toolset.catalog,
592
694
  executionBackend: toolset.environment.kind,
@@ -604,18 +706,22 @@ export async function createReplRuntime(options) {
604
706
  : presentForm(repl, form);
605
707
  },
606
708
  history: historyOptions,
607
- harness: harnessName,
709
+ harness: resume && !options.harness ? undefined : harnessName,
608
710
  execution: options.execution,
609
711
  autoLoadHarness: !(options.load?.length),
610
- compaction: { settings: replCompaction, auto: replCompaction.auto },
712
+ compaction: runtimePolicy.compaction,
611
713
  contextWindow,
612
- onInput: buildCliOnInput(options),
613
- });
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';
614
720
  // Terminal images (agent `visualize` and `/viz`) are painted through the
615
721
  // renderer; the TUI installs an image sink later, which this follows.
616
722
  repl.session.setImageHandler((lines) => renderer.image(lines));
617
723
  let missingCredential;
618
- const statusTracker = new ReplStatusTracker({
724
+ let statusTracker = new ReplStatusTracker({
619
725
  model: {
620
726
  id: harnessModel,
621
727
  provider: String(harnessProvider),
@@ -635,10 +741,55 @@ export async function createReplRuntime(options) {
635
741
  }
636
742
  }
637
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
+ },
638
789
  repl,
639
790
  renderer,
640
791
  workspace,
641
- promptPrefix: config.repl.promptPrefix ?? 'dml> ',
792
+ promptPrefix: purpose === 'work' ? 'work> ' : config.repl.promptPrefix ?? 'dml> ',
642
793
  toolset,
643
794
  version: PACKAGE_VERSION,
644
795
  imageBackend,
@@ -659,12 +810,12 @@ export async function createReplRuntime(options) {
659
810
  statusSnapshot: () => statusTracker.snapshot(),
660
811
  observeEvent: (event) => statusTracker.observe(event),
661
812
  tuiMode: options.tui ?? config.repl.tui ?? 'auto',
662
- setOnInput: (handler) => repl.setOnInput(handler),
813
+ setOnInput: (handler) => { currentInput = handler; repl.setOnInput(handler); },
663
814
  missingCredential,
664
815
  };
665
816
  // Session-scoped subagents render their lifecycle and output through the
666
817
  // active renderer (the TUI swaps it in after this runtime is built).
667
- repl.session.setProcessEventSink((event) => {
818
+ const wireProcesses = (current) => current.session.setProcessEventSink((event) => {
668
819
  const label = `⚙ ${event.name}`;
669
820
  const sink = runtime.renderer;
670
821
  if (event.type === 'output' && event.content) {
@@ -678,6 +829,8 @@ export async function createReplRuntime(options) {
678
829
  sink.writeLine(`${label} ${event.state}${reason}`);
679
830
  }
680
831
  });
832
+ wireProcesses(repl);
833
+ runtime.renderer.setDetails?.(runtime.details ?? true);
681
834
  return runtime;
682
835
  }
683
836
  /** Package version, read once from package.json for the banner/`--version`. */
@@ -693,6 +846,17 @@ export const PACKAGE_VERSION = (() => {
693
846
  })();
694
847
  /** Startup banner for the interactive REPL (proposal §2.1). */
695
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
+ }
696
860
  const rich = runtime.renderer.mode === 'rich';
697
861
  const paint = (text, code) => (rich ? `\u001b[${code}m${text}\u001b[0m` : text);
698
862
  const dim = (text) => paint(text, '2');
@@ -756,9 +920,9 @@ async function resumeSuspendedContinuation(runtime) {
756
920
  if (!pending)
757
921
  return;
758
922
  runtime.renderer.writeLine(`resuming the suspended continuation: ${pending.continuation}`);
759
- await runtime.repl.session.clearSuspension?.();
760
923
  try {
761
- await runGoalWithRenderer(runtime.repl, pending.continuation, { renderer: runtime.renderer });
924
+ for await (const event of runtime.repl.resumeSuspension())
925
+ runtime.renderer.render(event);
762
926
  }
763
927
  catch (error) {
764
928
  runtime.renderer.writeLine(`could not resume ${pending.continuation}: ${String(error.message)}`);
@@ -778,7 +942,57 @@ async function renderResumedSession(runtime) {
778
942
  export async function dispatchReplInput(runtime, input, options = {}) {
779
943
  const { repl, renderer } = runtime;
780
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
+ }
781
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;
782
996
  case 'empty':
783
997
  case 'comment':
784
998
  return true;
@@ -826,16 +1040,23 @@ export async function dispatchReplInput(runtime, input, options = {}) {
826
1040
  print(`stopped ${input.target}`);
827
1041
  return true;
828
1042
  }
829
- case 'login':
830
- print("sign in from the terminal: deepclause login (or /login in the TUI)");
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}` : ''}`);
831
1051
  return true;
1052
+ }
832
1053
  case 'unknown-command':
833
1054
  print(`unknown command: /${input.name} — try /help.`);
834
1055
  return true;
835
1056
  case 'halt':
836
1057
  return false;
837
1058
  case 'help':
838
- print(helpText());
1059
+ print(helpText(runtime.mode));
839
1060
  return true;
840
1061
  case 'listing': {
841
1062
  const text = await repl.list(input.filter);
@@ -984,6 +1205,13 @@ export async function dispatchReplInput(runtime, input, options = {}) {
984
1205
  await runGoalWithRenderer(repl, input.goal, { first: options.first, renderer, signal: options.signal });
985
1206
  return true;
986
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
+ }
987
1215
  if (runtime.missingCredential) {
988
1216
  print(`ERROR: ${runtime.missingCredential}`);
989
1217
  return true;
@@ -997,8 +1225,21 @@ export async function dispatchReplInput(runtime, input, options = {}) {
997
1225
  return true;
998
1226
  }
999
1227
  }
1000
- 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');
1001
1240
  return [
1241
+ ' /mode [develop|work] [harness] switch conversation purpose',
1242
+ ' /workflows /workflow /details declared Work tasks and presentation',
1002
1243
  'DeepClause REPL — a living DML harness you author by talking to it.',
1003
1244
  '',
1004
1245
  ' Modes',
@@ -1023,7 +1264,7 @@ function helpText() {
1023
1264
  ' /compact [notes] compact the authoring memory',
1024
1265
  ' /export [file] save the harness (use .zip to bundle linked files)',
1025
1266
  ' /model [provider/id] show / set the model',
1026
- ' /login sign in to a provider (from the terminal or the TUI)',
1267
+ ' /login [provider] sign in; llama.cpp accepts --host, --port, --base-url',
1027
1268
  ' /freeze /unfreeze read-only lock',
1028
1269
  ' /params show session parameters',
1029
1270
  ' /trace /notrace toggle verbose logging',
@@ -1271,6 +1512,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1271
1512
  const working = new WorkingLine(tui);
1272
1513
  const renderer = new TuiRenderer({
1273
1514
  document,
1515
+ events: runtime.details ?? true,
1274
1516
  // The TUI draws through its own switch, but the status tracker must still see
1275
1517
  // every event (usage, model_call, …) or the footer loses its counters.
1276
1518
  onEvent: (event) => runtime.observeEvent(event),
@@ -1288,11 +1530,14 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1288
1530
  const statusBar = new StatusBarComponent({
1289
1531
  getSnapshot: () => runtime.statusSnapshot(),
1290
1532
  workspace: runtime.workspace,
1291
- sessionId: runtime.sessionId,
1292
- 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,
1293
1537
  backend: runtime.backend,
1294
1538
  isFrozen: () => runtime.repl.isFrozen(),
1295
1539
  isRunning: () => runState.running,
1540
+ canSteer: () => runState.steerable,
1296
1541
  processLabel: () => {
1297
1542
  const active = runtime.repl.session
1298
1543
  .processes()
@@ -1442,7 +1687,9 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1442
1687
  ? label
1443
1688
  : label === ' ;'
1444
1689
  ? 'Enter/; more · a all · . stop'
1445
- : null;
1690
+ : label === runtime.promptPrefix
1691
+ ? null
1692
+ : label;
1446
1693
  editor.setPrompt(hint);
1447
1694
  tui.setFocus(editor);
1448
1695
  }
@@ -1642,7 +1889,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1642
1889
  renderer.writeLine(`harness view ${harnessWidth} columns`);
1643
1890
  };
1644
1891
  const pickModel = async () => {
1645
- const catalog = runtime.modelResolver?.catalog() ?? [];
1892
+ const catalog = runtime.modelPickerCatalog ?? runtime.modelResolver?.catalog() ?? [];
1646
1893
  if (catalog.length === 0) {
1647
1894
  renderer.writeLine(`model: ${runtime.model} (no catalog to choose from; set one in config)`);
1648
1895
  return;
@@ -1650,7 +1897,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1650
1897
  const current = runtime.model.includes(':') ? runtime.model : undefined;
1651
1898
  const picked = await choose((done) => new ChoicePicker({
1652
1899
  title: 'Model',
1653
- hint: 'The default for this workspace (applies to the next session)',
1900
+ hint: 'The default for this workspace (applies on the next CLI start)',
1654
1901
  current,
1655
1902
  items: catalog.map((entry) => ({
1656
1903
  value: entry.model,
@@ -1668,7 +1915,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1668
1915
  renderer.writeLine(`default model set to ${picked} (takes effect on the next start)`);
1669
1916
  };
1670
1917
  /** `/login`: sign in to a provider from inside the TUI. */
1671
- const runLogin = async () => {
1918
+ const runLogin = async (input) => {
1672
1919
  let handle;
1673
1920
  try {
1674
1921
  handle = await openPiRuntime({});
@@ -1682,19 +1929,64 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1682
1929
  renderer.writeLine('no login providers available');
1683
1930
  return;
1684
1931
  }
1685
- const picked = await choose((done) => new ChoicePicker({
1686
- title: 'Sign in to a provider',
1687
- hint: 'Esc to cancel',
1688
- items: providers.map((provider) => ({
1689
- value: provider.id,
1690
- label: `${provider.name} (${provider.id})`,
1691
- description: provider.configured ? '✓ configured' : provider.authType,
1692
- })),
1693
- onSelect: (item) => done(item.value),
1694
- onCancel: () => done(),
1695
- }));
1696
- 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}`);
1697
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
+ }
1698
1990
  const interaction = {
1699
1991
  prompt: async (prompt) => {
1700
1992
  if (prompt.options && prompt.options.length > 0) {
@@ -1727,9 +2019,18 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1727
2019
  },
1728
2020
  };
1729
2021
  try {
1730
- await loginToProvider(handle, picked, { interaction });
2022
+ await loginToProvider(handle, picked, {
2023
+ interaction,
2024
+ baseUrl,
2025
+ host,
2026
+ port,
2027
+ });
1731
2028
  await persistSetting({ backend: { kind: 'pi' } }, 'login');
1732
- renderer.writeLine(`signed in to ${picked} (run /model to pick one of its models)`);
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)`);
1733
2034
  }
1734
2035
  catch (error) {
1735
2036
  renderer.writeLine(`login failed: ${error instanceof Error ? error.message : String(error)}`);
@@ -1754,6 +2055,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1754
2055
  },
1755
2056
  });
1756
2057
  harnessView.refresh();
2058
+ const workView = new WorkView(() => runtime.workSpec);
1757
2059
  let harnessVisible = options.harnessView ?? false;
1758
2060
  let servicesVisible = false;
1759
2061
  let servicesLogs = false;
@@ -1812,12 +2114,12 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1812
2114
  const columns = new HStack([
1813
2115
  { component: scroll, basis: 0, grow: 1, shrink: 1, minSize: 20 },
1814
2116
  {
1815
- component: harnessView,
2117
+ component: runtime.mode === 'work' ? workView : harnessView,
1816
2118
  basis: harnessWidth,
1817
2119
  grow: 0,
1818
2120
  shrink: 0,
1819
2121
  minSize: 20,
1820
- visible: (viewport) => harnessVisible && viewport.width >= 96,
2122
+ visible: (viewport) => (runtime.mode === 'work' || harnessVisible) && viewport.width >= 96,
1821
2123
  },
1822
2124
  ], { gap: 1 });
1823
2125
  tui.setLayoutRoot(new VStack([
@@ -1829,7 +2131,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1829
2131
  applyLayout();
1830
2132
  // A form opened by the running turn is shown in the dock and edited field by
1831
2133
  // field through the editor; the plain-TTY path uses the raw widget instead.
1832
- runtime.repl.session.setFormHandler(async (form) => {
2134
+ const presentTuiForm = async (form) => {
1833
2135
  const spec = form.spec;
1834
2136
  if (!spec)
1835
2137
  return;
@@ -1859,7 +2161,16 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1859
2161
  formView.setState(undefined);
1860
2162
  tui.requestRender();
1861
2163
  }
1862
- });
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
+ };
1863
2174
  tui.start();
1864
2175
  await printBanner(runtime, loaded);
1865
2176
  await renderResumedSession(runtime);
@@ -1879,9 +2190,44 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1879
2190
  if (line === null)
1880
2191
  break;
1881
2192
  }
1882
- const input = classifyReplInput(line);
2193
+ let input = classifyReplInput(line);
1883
2194
  if (input.kind === 'halt')
1884
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
+ }
1885
2231
  // The pickers are overlays over the transcript, so they need the TUI and are
1886
2232
  // handled here rather than in the command dispatcher the readline path shares.
1887
2233
  if (input.kind === 'model' && !input.model) {
@@ -1897,11 +2243,15 @@ export async function runTui(runtime, options, onExit, loaded = []) {
1897
2243
  continue;
1898
2244
  }
1899
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
+ }
1900
2250
  await handleHarnessCommand(input.width);
1901
2251
  continue;
1902
2252
  }
1903
2253
  if (input.kind === 'login') {
1904
- await runLogin();
2254
+ await runLogin(input);
1905
2255
  continue;
1906
2256
  }
1907
2257
  if (input.kind === 'ps' && (input.watch || input.logs)) {
@@ -1987,7 +2337,7 @@ export async function startRepl(options) {
1987
2337
  // saved, or when the harness has no predicates.
1988
2338
  let exitSaved = false;
1989
2339
  const saveHarnessOnExit = async () => {
1990
- if (exitSaved || options.exportPath || options.saveOnExit === false)
2340
+ if (runtime.mode === 'work' || exitSaved || options.exportPath || options.saveOnExit === false)
1991
2341
  return;
1992
2342
  exitSaved = true;
1993
2343
  try {
@@ -2010,6 +2360,25 @@ export async function startRepl(options) {
2010
2360
  if (options.load?.length) {
2011
2361
  await runtime.repl.session.finalizeHarnessBaseline();
2012
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
+ }
2013
2382
  // Freeze/lock only after all `-l` loads succeed (load before lock).
2014
2383
  if (options.locked) {
2015
2384
  await runtime.repl.lock();
@@ -2087,6 +2456,13 @@ export function registerReplCommand(program) {
2087
2456
  .option('-g, --goal <goal>', 'run one goal and exit (repeatable)', collect)
2088
2457
  .option('-l, --load <file>', 'load a DML file before starting (repeatable)', collect)
2089
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')
2090
2466
  .option('--harness <name>', 'harness to edit (a project can hold several; default main)')
2091
2467
  .option('--first', 'with a goal, print only the first solution')
2092
2468
  .option('--plain', 'no TUI formatting (auto when stdout is not a TTY)')
@@ -2142,6 +2518,9 @@ export function registerReplCommand(program) {
2142
2518
  .option('--no-color', 'disable ANSI color')
2143
2519
  .action(async (options) => {
2144
2520
  const exitCode = await startRepl({
2521
+ mode: options.mode,
2522
+ workflow: options.workflow,
2523
+ inputs: options.inputs,
2145
2524
  goal: options.goal,
2146
2525
  load: options.load,
2147
2526
  session: options.session,
@@ -2196,8 +2575,12 @@ export function normalizeHarnessName(name) {
2196
2575
  const trimmed = name?.trim();
2197
2576
  if (!trimmed)
2198
2577
  return undefined;
2199
- const slug = trimmed.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^-+|-+$/g, '');
2200
- return slug || undefined;
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;
2201
2584
  }
2202
2585
  /** Harness name implied by a `-l` file: its basename without the `.dml`/`.zip`. */
2203
2586
  function harnessNameFromFile(file) {