deepclause-sdk 0.4.0 → 0.7.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 +191 -2
- package/dist/agent.d.ts +2 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +159 -28
- package/dist/agent.js.map +1 -1
- package/dist/cli/agent-inbox.d.ts +25 -0
- package/dist/cli/agent-inbox.d.ts.map +1 -0
- package/dist/cli/agent-inbox.js +46 -0
- package/dist/cli/agent-inbox.js.map +1 -0
- package/dist/cli/config.d.ts +166 -156
- 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/index.d.ts +1 -1
- package/dist/cli/index.js +7 -2
- package/dist/cli/index.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 +61 -1
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js +618 -67
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/run.d.ts +1 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +3 -1
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/serve.d.ts +3 -0
- package/dist/cli/serve.d.ts.map +1 -0
- package/dist/cli/serve.js +131 -0
- package/dist/cli/serve.js.map +1 -0
- 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 +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/judge/llm.d.ts.map +1 -1
- package/dist/judge/llm.js +9 -4
- package/dist/judge/llm.js.map +1 -1
- package/dist/judge/types.d.ts +10 -0
- package/dist/judge/types.d.ts.map +1 -1
- package/dist/judge/types.js.map +1 -1
- package/dist/prolog-src/deepclause_mi.pl +2791 -302
- package/dist/prolog-src/deepclause_strings.pl +36 -3
- package/dist/repl/agent-inbox.d.ts +73 -0
- package/dist/repl/agent-inbox.d.ts.map +1 -0
- package/dist/repl/agent-inbox.js +168 -0
- package/dist/repl/agent-inbox.js.map +1 -0
- package/dist/repl/agent.d.ts +19 -1
- package/dist/repl/agent.d.ts.map +1 -1
- package/dist/repl/agent.js +44 -13
- 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 +30 -0
- package/dist/repl/backend.d.ts.map +1 -1
- package/dist/repl/backend.js +309 -14
- 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 +36 -0
- package/dist/repl/event-history.js.map +1 -0
- package/dist/repl/harness-tools.d.ts +32 -18
- package/dist/repl/harness-tools.d.ts.map +1 -1
- package/dist/repl/harness-tools.js +127 -34
- package/dist/repl/harness-tools.js.map +1 -1
- package/dist/repl/history.d.ts +66 -5
- package/dist/repl/history.d.ts.map +1 -1
- package/dist/repl/history.js +174 -8
- package/dist/repl/history.js.map +1 -1
- package/dist/repl/index.d.ts +38 -5
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +32 -1
- package/dist/repl/index.js.map +1 -1
- package/dist/repl/process-backend.d.ts +1 -0
- package/dist/repl/process-backend.d.ts.map +1 -1
- package/dist/repl/process-executor.d.ts +4 -0
- package/dist/repl/process-executor.d.ts.map +1 -1
- package/dist/repl/process-executor.js +36 -1
- package/dist/repl/process-executor.js.map +1 -1
- package/dist/repl/process-worker.d.ts.map +1 -1
- package/dist/repl/process-worker.js +33 -8
- package/dist/repl/process-worker.js.map +1 -1
- package/dist/repl/processes.d.ts +14 -1
- package/dist/repl/processes.d.ts.map +1 -1
- package/dist/repl/processes.js +8 -2
- package/dist/repl/processes.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 +144 -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 +20 -0
- package/dist/repl/render.js.map +1 -1
- package/dist/repl/session.d.ts +199 -27
- package/dist/repl/session.d.ts.map +1 -1
- package/dist/repl/session.js +1471 -219
- package/dist/repl/session.js.map +1 -1
- package/dist/repl/toolset.d.ts +8 -0
- package/dist/repl/toolset.d.ts.map +1 -1
- package/dist/repl/toolset.js +53 -4
- package/dist/repl/toolset.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 +23 -4
- 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/repl/work-hooks.d.ts +29 -0
- package/dist/repl/work-hooks.d.ts.map +1 -0
- package/dist/repl/work-hooks.js +117 -0
- package/dist/repl/work-hooks.js.map +1 -0
- package/dist/repl/worker-host.d.ts +2 -0
- package/dist/repl/worker-host.d.ts.map +1 -1
- package/dist/repl/worker-host.js +48 -4
- package/dist/repl/worker-host.js.map +1 -1
- package/dist/repl/worker-protocol.d.ts +23 -2
- package/dist/repl/worker-protocol.d.ts.map +1 -1
- package/dist/repl/worker-protocol.js +1 -1
- package/dist/runner.d.ts +2 -2
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +69 -22
- package/dist/runner.js.map +1 -1
- package/dist/runtime-identity.json +10 -0
- package/dist/serve/agent-broadcast.d.ts +29 -0
- package/dist/serve/agent-broadcast.d.ts.map +1 -0
- package/dist/serve/agent-broadcast.js +28 -0
- package/dist/serve/agent-broadcast.js.map +1 -0
- package/dist/serve/agent-preferences.d.ts +16 -0
- package/dist/serve/agent-preferences.d.ts.map +1 -0
- package/dist/serve/agent-preferences.js +42 -0
- package/dist/serve/agent-preferences.js.map +1 -0
- package/dist/serve/api-docs.d.ts +61 -0
- package/dist/serve/api-docs.d.ts.map +1 -0
- package/dist/serve/api-docs.js +122 -0
- package/dist/serve/api-docs.js.map +1 -0
- package/dist/serve/backend.d.ts +12 -0
- package/dist/serve/backend.d.ts.map +1 -0
- package/dist/serve/backend.js +52 -0
- package/dist/serve/backend.js.map +1 -0
- package/dist/serve/capabilities.d.ts +6 -0
- package/dist/serve/capabilities.d.ts.map +1 -0
- package/dist/serve/capabilities.js +21 -0
- package/dist/serve/capabilities.js.map +1 -0
- package/dist/serve/example-agent.d.ts +5 -0
- package/dist/serve/example-agent.d.ts.map +1 -0
- package/dist/serve/example-agent.js +5 -0
- package/dist/serve/example-agent.js.map +1 -0
- package/dist/serve/files.d.ts +55 -0
- package/dist/serve/files.d.ts.map +1 -0
- package/dist/serve/files.js +249 -0
- package/dist/serve/files.js.map +1 -0
- package/dist/serve/harness.d.ts +3 -0
- package/dist/serve/harness.d.ts.map +1 -0
- package/dist/serve/harness.js +53 -0
- package/dist/serve/harness.js.map +1 -0
- package/dist/serve/previews.d.ts +40 -0
- package/dist/serve/previews.d.ts.map +1 -0
- package/dist/serve/previews.js +240 -0
- package/dist/serve/previews.js.map +1 -0
- package/dist/serve/protocol.d.ts +228 -0
- package/dist/serve/protocol.d.ts.map +1 -0
- package/dist/serve/protocol.js +2 -0
- package/dist/serve/protocol.js.map +1 -0
- package/dist/serve/schedules.d.ts +85 -0
- package/dist/serve/schedules.d.ts.map +1 -0
- package/dist/serve/schedules.js +249 -0
- package/dist/serve/schedules.js.map +1 -0
- package/dist/serve/server.d.ts +50 -0
- package/dist/serve/server.d.ts.map +1 -0
- package/dist/serve/server.js +1696 -0
- package/dist/serve/server.js.map +1 -0
- package/dist/serve/session-worker.d.ts +2 -0
- package/dist/serve/session-worker.d.ts.map +1 -0
- package/dist/serve/session-worker.js +291 -0
- package/dist/serve/session-worker.js.map +1 -0
- package/dist/serve/sessions.d.ts +178 -0
- package/dist/serve/sessions.d.ts.map +1 -0
- package/dist/serve/sessions.js +905 -0
- package/dist/serve/sessions.js.map +1 -0
- package/dist/serve/storage.d.ts +41 -0
- package/dist/serve/storage.d.ts.map +1 -0
- package/dist/serve/storage.js +211 -0
- package/dist/serve/storage.js.map +1 -0
- package/dist/serve/ui/api-docs.html +17 -0
- package/dist/serve/ui/api-docs.js +36 -0
- package/dist/serve/ui/app.js +958 -0
- package/dist/serve/ui/authoring.js +92 -0
- package/dist/serve/ui/deepclause-logo.png +0 -0
- package/dist/serve/ui/deepclause-mark.svg +1 -0
- package/dist/serve/ui/diff.js +16 -0
- package/dist/serve/ui/dompurify-LICENSE.txt +202 -0
- package/dist/serve/ui/features.css +15 -0
- package/dist/serve/ui/files.js +13 -0
- package/dist/serve/ui/ibm-plex-mono-latin.woff2 +0 -0
- package/dist/serve/ui/ibmplexmono-OFL.txt +93 -0
- package/dist/serve/ui/icons.js +30 -0
- package/dist/serve/ui/index.html +68 -0
- package/dist/serve/ui/manrope-OFL.txt +93 -0
- package/dist/serve/ui/manrope-latin.woff2 +0 -0
- package/dist/serve/ui/markdown.js +38 -0
- package/dist/serve/ui/marked-LICENSE.txt +44 -0
- package/dist/serve/ui/marked.js +88 -0
- package/dist/serve/ui/purify.js +2454 -0
- package/dist/serve/ui/style.css +249 -0
- package/dist/serve/ui/web-work.css +247 -0
- package/dist/serve/ui/web.css +1848 -0
- package/dist/serve/workflow-bundles.d.ts +8 -0
- package/dist/serve/workflow-bundles.d.ts.map +1 -0
- package/dist/serve/workflow-bundles.js +78 -0
- package/dist/serve/workflow-bundles.js.map +1 -0
- package/dist/serve/workflow-calls.d.ts +6 -0
- package/dist/serve/workflow-calls.d.ts.map +1 -0
- package/dist/serve/workflow-calls.js +13 -0
- package/dist/serve/workflow-calls.js.map +1 -0
- package/dist/serve/workflows.d.ts +93 -0
- package/dist/serve/workflows.d.ts.map +1 -0
- package/dist/serve/workflows.js +219 -0
- package/dist/serve/workflows.js.map +1 -0
- package/dist/system/assets/docs/AGENT_PROMPT.md +265 -3008
- package/dist/system/assets/docs/DML_AUTHORING.md +151 -291
- 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 +124 -0
- package/dist/system/assets/docs/DML_PYTHON.md +74 -0
- package/dist/system/assets/docs/DML_REFERENCE.md +353 -2012
- package/dist/system/assets/docs/DML_SHELL.md +249 -0
- package/dist/system/assets/docs/DML_TASKS.md +119 -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 +5 -1
- package/dist/system/environment.d.ts.map +1 -1
- package/dist/system/environment.js +20 -10
- package/dist/system/environment.js.map +1 -1
- package/dist/system/runtime/agentvm-manager.d.ts +12 -1
- package/dist/system/runtime/agentvm-manager.d.ts.map +1 -1
- package/dist/system/runtime/agentvm-manager.js +136 -20
- package/dist/system/runtime/agentvm-manager.js.map +1 -1
- package/dist/system/runtime/shell-manager.d.ts +4 -1
- package/dist/system/runtime/shell-manager.d.ts.map +1 -1
- package/dist/system/runtime/shell-manager.js +1 -1
- package/dist/system/runtime/shell-manager.js.map +1 -1
- package/dist/system/timezone.d.ts +20 -0
- package/dist/system/timezone.d.ts.map +1 -0
- package/dist/system/timezone.js +37 -0
- package/dist/system/timezone.js.map +1 -0
- package/dist/types.d.ts +85 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/work/index.d.ts +92 -0
- package/dist/work/index.d.ts.map +1 -0
- package/dist/work/index.js +297 -0
- package/dist/work/index.js.map +1 -0
- package/docs/DEEP_RESEARCH_EXAMPLE.md +127 -0
- package/docs/SERVE.md +664 -0
- package/docs/WORK_AGENT_HOOKS_PLAN.md +416 -0
- package/docs/WORK_AGENT_INBOX.md +140 -0
- package/docs/WORK_AGENT_INBOX_PLAN.md +91 -0
- package/docs/WORK_MODE.md +269 -0
- package/package.json +35 -4
- package/sdk-examples/deep-research.dml +144 -0
- package/sdk-examples/deep-research.py +502 -0
- package/sdk-examples/hooked-agent.dml +49 -0
- package/sdk-examples/subagent-inbox.dml +66 -0
- package/src/prolog-src/deepclause_mi.pl +2791 -302
- package/src/prolog-src/deepclause_strings.pl +36 -3
package/dist/cli/repl.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
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 { CliAgentInbox } from './agent-inbox.js';
|
|
13
|
+
import { resolveWorkbenchPolicy } from '../work/index.js';
|
|
10
14
|
import * as path from 'path';
|
|
11
15
|
import * as readline from 'readline';
|
|
12
16
|
import { fileURLToPath } from 'url';
|
|
@@ -21,6 +25,7 @@ import { ChoicePicker } from '../repl/tui/picker.js';
|
|
|
21
25
|
import { openPiRuntime } from '../repl/backend.js';
|
|
22
26
|
import { listLoginProviders, loginToProvider } from '../repl/auth.js';
|
|
23
27
|
import { HarnessView } from '../repl/tui/harness-view.js';
|
|
28
|
+
import { WorkView } from '../repl/tui/work-view.js';
|
|
24
29
|
import { TuiRenderer } from '../repl/tui/renderer.js';
|
|
25
30
|
import { WorkingLine } from '../repl/tui/working-line.js';
|
|
26
31
|
import { createReplAutocomplete } from '../repl/tui/autocomplete.js';
|
|
@@ -34,14 +39,14 @@ import { PromptEditor } from '../repl/tui/editor.js';
|
|
|
34
39
|
import { FormView } from '../repl/tui/form-view.js';
|
|
35
40
|
import { applyFormKey, initialState, rows } from '../repl/form-widget.js';
|
|
36
41
|
import { loadProjectContext } from '../repl/project-context.js';
|
|
37
|
-
import { createPiBackend, THINKING_LEVELS } from '../repl/backend.js';
|
|
42
|
+
import { LLAMA_PROVIDER_ID, createPiBackend, THINKING_LEVELS } from '../repl/backend.js';
|
|
38
43
|
import { createReplToolset } from '../repl/toolset.js';
|
|
39
44
|
import { takeStartupPrologMessages } from '../prolog/loader.js';
|
|
40
45
|
import { createPiImageBackend } from '../repl/imagegen.js';
|
|
41
|
-
import { EnvModelResolver, PiModelResolver } from '../repl/model-resolver.js';
|
|
46
|
+
import { EnvModelResolver, PiModelResolver, } from '../repl/model-resolver.js';
|
|
42
47
|
import { pickForm } from '../repl/form-widget.js';
|
|
43
48
|
import { parseModelId, resolveModelSlotConfig } from '../system/config/model-slots.js';
|
|
44
|
-
import { loadReplConfig,
|
|
49
|
+
import { loadReplConfig, updateConfig } from './config.js';
|
|
45
50
|
import { renderDiagramImage, resolveMedia, } from '../visualize/index.js';
|
|
46
51
|
const OUT_OF_BAND = new Set(['halt', 'help', 'reset', 'rollback', 'freeze', 'unfreeze', 'trace', 'notrace', 'params']);
|
|
47
52
|
const GRAPHICS_MODES = ['auto', 'kitty', 'iterm2', 'ascii', 'off'];
|
|
@@ -83,8 +88,83 @@ export function parseVizArgs(arg) {
|
|
|
83
88
|
}
|
|
84
89
|
/** Render a recorded turn as the line the user would retype (goals get `/goal`). */
|
|
85
90
|
export function formatTurnInput(turn) {
|
|
91
|
+
if (turn.workflow)
|
|
92
|
+
return `/workflow ${JSON.stringify(turn.workflow.name)} ${JSON.stringify(turn.workflow.inputs)}`;
|
|
86
93
|
return turn.mode === 'goal' ? `/goal ${turn.request}` : turn.request;
|
|
87
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Whether the TUI shows execution detail by default.
|
|
97
|
+
*
|
|
98
|
+
* Develop and Work both start with tool calls, task activity and reasoning
|
|
99
|
+
* visible. `--no-events` (and an explicit `/details off`) is the only opt-out;
|
|
100
|
+
* Work used to hide this by default, which made its assistant look inert next
|
|
101
|
+
* to Develop even though the runtime was emitting the same events.
|
|
102
|
+
*/
|
|
103
|
+
export function replDetailsDefault(events) {
|
|
104
|
+
return events !== false;
|
|
105
|
+
}
|
|
106
|
+
const LOGIN_USAGE = 'login (use /login [provider] [--host <host>] [--port <port>] [--base-url <url>])';
|
|
107
|
+
/**
|
|
108
|
+
* Parse `/login [provider] [--host host] [--port port] [--base-url url]`.
|
|
109
|
+
* A bare URL is accepted as `--base-url`, and a positional provider may be
|
|
110
|
+
* omitted when an endpoint flag implies llama.cpp.
|
|
111
|
+
*/
|
|
112
|
+
export function parseLoginArgs(arg) {
|
|
113
|
+
const tokens = arg.split(/\s+/).filter(Boolean);
|
|
114
|
+
let provider;
|
|
115
|
+
let baseUrl;
|
|
116
|
+
let host;
|
|
117
|
+
let port;
|
|
118
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
119
|
+
const token = tokens[index];
|
|
120
|
+
const equals = token.indexOf('=');
|
|
121
|
+
const flag = token.startsWith('--') ? (equals >= 0 ? token.slice(0, equals) : token) : '';
|
|
122
|
+
const inlineValue = equals >= 0 ? token.slice(equals + 1) : undefined;
|
|
123
|
+
const value = () => inlineValue ?? tokens[++index];
|
|
124
|
+
switch (flag) {
|
|
125
|
+
case '--base-url':
|
|
126
|
+
case '--url':
|
|
127
|
+
baseUrl = value();
|
|
128
|
+
if (!baseUrl)
|
|
129
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
130
|
+
break;
|
|
131
|
+
case '--host':
|
|
132
|
+
host = value();
|
|
133
|
+
if (!host)
|
|
134
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
135
|
+
break;
|
|
136
|
+
case '--port':
|
|
137
|
+
port = value();
|
|
138
|
+
if (!port)
|
|
139
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
140
|
+
break;
|
|
141
|
+
case '--provider':
|
|
142
|
+
provider = value();
|
|
143
|
+
if (!provider)
|
|
144
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
145
|
+
break;
|
|
146
|
+
case '':
|
|
147
|
+
if (token.startsWith('-')) {
|
|
148
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
149
|
+
}
|
|
150
|
+
if (/^https?:\/\//i.test(token)) {
|
|
151
|
+
if (baseUrl)
|
|
152
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
153
|
+
baseUrl = token;
|
|
154
|
+
}
|
|
155
|
+
else if (!provider) {
|
|
156
|
+
provider = token;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
return { kind: 'unknown-command', name: LOGIN_USAGE };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { kind: 'login', provider, baseUrl, host, port };
|
|
167
|
+
}
|
|
88
168
|
/**
|
|
89
169
|
* Slash commands are executed (or queued), never steered into a running model
|
|
90
170
|
* turn: `/send`, `/call`, `/ps`, `/stop` … address processes, not the model.
|
|
@@ -114,6 +194,24 @@ export function classifyReplInput(line) {
|
|
|
114
194
|
const name = (spaceIndex === -1 ? withoutSlash : withoutSlash.slice(0, spaceIndex)).toLowerCase();
|
|
115
195
|
const arg = (spaceIndex === -1 ? '' : withoutSlash.slice(spaceIndex)).trim();
|
|
116
196
|
switch (name) {
|
|
197
|
+
case 'mode': {
|
|
198
|
+
const [mode, harness, extra] = arg.split(/\s+/);
|
|
199
|
+
if (!arg)
|
|
200
|
+
return { kind: 'mode' };
|
|
201
|
+
return (mode === 'work' || mode === 'develop') && !extra ? { kind: 'mode', mode, harness } : { kind: 'unknown-command', name: 'mode (use /mode work|develop [harness])' };
|
|
202
|
+
}
|
|
203
|
+
case 'workflows': return { kind: 'workflows' };
|
|
204
|
+
case 'workflow': {
|
|
205
|
+
if (!arg)
|
|
206
|
+
return { kind: 'workflows' };
|
|
207
|
+
try {
|
|
208
|
+
return { kind: 'workflow', ...parseWorkflowCommand(arg) };
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return { kind: 'unknown-command', name: 'workflow (use /workflow "Name" {"Input":"value"})' };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
case 'details': return { kind: 'details', show: arg === 'on' ? true : arg === 'off' ? false : undefined };
|
|
117
215
|
case 'goal':
|
|
118
216
|
return arg ? { kind: 'goal', goal: arg } : { kind: 'unknown-command', name: 'goal (missing goal)' };
|
|
119
217
|
case 'listing':
|
|
@@ -191,7 +289,7 @@ export function classifyReplInput(line) {
|
|
|
191
289
|
case 'stop':
|
|
192
290
|
return arg ? { kind: 'stop', target: arg } : { kind: 'unknown-command', name: 'stop (usage: /stop <name>)' };
|
|
193
291
|
case 'login':
|
|
194
|
-
return
|
|
292
|
+
return parseLoginArgs(arg);
|
|
195
293
|
default:
|
|
196
294
|
return { kind: 'unknown-command', name };
|
|
197
295
|
}
|
|
@@ -399,12 +497,14 @@ const PROVIDER_ENV_KEYS = {
|
|
|
399
497
|
};
|
|
400
498
|
/** Build the harness + renderer from CLI options. */
|
|
401
499
|
export async function createReplRuntime(options) {
|
|
500
|
+
if (options.allowNetwork !== undefined && !options.sandbox)
|
|
501
|
+
throw new Error('--allow-network requires --sandbox');
|
|
402
502
|
const workspace = path.resolve(options.workspace ?? './');
|
|
403
503
|
const config = await loadReplConfig(workspace);
|
|
404
|
-
const
|
|
504
|
+
const runtimePolicy = resolveWorkbenchPolicy(config);
|
|
405
505
|
// One harness per name within a project: `--harness`, else the `-l` file's
|
|
406
506
|
// name, else the configured default (`main`).
|
|
407
|
-
|
|
507
|
+
let harnessName = normalizeHarnessName(options.harness)
|
|
408
508
|
?? (options.load?.length ? harnessNameFromFile(options.load[0]) : undefined)
|
|
409
509
|
?? normalizeHarnessName(config.repl.harness)
|
|
410
510
|
?? 'main';
|
|
@@ -433,7 +533,7 @@ export async function createReplRuntime(options) {
|
|
|
433
533
|
const toolset = await createReplToolset({
|
|
434
534
|
workspacePath: workspace,
|
|
435
535
|
sandbox: options.sandbox,
|
|
436
|
-
network: config.agentvm?.network ?? false,
|
|
536
|
+
network: options.allowNetwork ?? config.agentvm?.network ?? false,
|
|
437
537
|
hostConfig: config.shell,
|
|
438
538
|
toolNames,
|
|
439
539
|
// The runner already emits the tool_call start/completion events, so the
|
|
@@ -576,7 +676,13 @@ export async function createReplRuntime(options) {
|
|
|
576
676
|
imageBackend = undefined;
|
|
577
677
|
}
|
|
578
678
|
}
|
|
579
|
-
|
|
679
|
+
let currentInput = buildCliOnInput(options);
|
|
680
|
+
const agentInbox = new CliAgentInbox();
|
|
681
|
+
let inboxRenderer = () => renderer;
|
|
682
|
+
const replOptions = {
|
|
683
|
+
mode: options.mode ?? (options.workflow ? 'work' : undefined),
|
|
684
|
+
sessionKind: options.workflow ? 'workflow-run' : undefined,
|
|
685
|
+
origin: 'tui',
|
|
580
686
|
sessionId,
|
|
581
687
|
resume,
|
|
582
688
|
workspacePath: workspace,
|
|
@@ -584,9 +690,10 @@ export async function createReplRuntime(options) {
|
|
|
584
690
|
provider: harnessProvider,
|
|
585
691
|
temperature: options.temperature ?? config.temperatures.run,
|
|
586
692
|
params: options.param ?? {},
|
|
587
|
-
gasLimit: options.gasLimit,
|
|
588
|
-
maxDepth: options.depth ??
|
|
589
|
-
maxModelCalls: options.maxModelCalls ??
|
|
693
|
+
gasLimit: options.gasLimit ?? runtimePolicy.gasLimit,
|
|
694
|
+
maxDepth: options.depth ?? runtimePolicy.maxDepth,
|
|
695
|
+
maxModelCalls: options.maxModelCalls ?? runtimePolicy.maxModelCalls,
|
|
696
|
+
providerConcurrency: runtimePolicy.providerConcurrency,
|
|
590
697
|
tools: toolset.tools,
|
|
591
698
|
hostToolsCatalog: toolset.catalog,
|
|
592
699
|
executionBackend: toolset.environment.kind,
|
|
@@ -604,18 +711,30 @@ export async function createReplRuntime(options) {
|
|
|
604
711
|
: presentForm(repl, form);
|
|
605
712
|
},
|
|
606
713
|
history: historyOptions,
|
|
607
|
-
harness: harnessName,
|
|
714
|
+
harness: resume && !options.harness ? undefined : harnessName,
|
|
608
715
|
execution: options.execution,
|
|
609
716
|
autoLoadHarness: !(options.load?.length),
|
|
610
|
-
compaction:
|
|
717
|
+
compaction: runtimePolicy.compaction,
|
|
611
718
|
contextWindow,
|
|
612
|
-
onInput:
|
|
613
|
-
|
|
719
|
+
onInput: currentInput,
|
|
720
|
+
onAgentInboxReady: status => agentInbox.notify(status),
|
|
721
|
+
onAgentInboxEvent: event => {
|
|
722
|
+
if (event.agentInbox)
|
|
723
|
+
agentInbox.status(event.agentInbox);
|
|
724
|
+
// Status remains structured metadata in JSON mode; turn events are consumed
|
|
725
|
+
// by the idle loop, through whichever renderer is currently installed.
|
|
726
|
+
inboxRenderer().render(event);
|
|
727
|
+
},
|
|
728
|
+
};
|
|
729
|
+
let repl = await createHarnessRepl(replOptions);
|
|
730
|
+
const identity = await repl.sessionInfo();
|
|
731
|
+
harnessName = identity.harness ?? harnessName;
|
|
732
|
+
const purpose = identity.mode ?? 'develop';
|
|
614
733
|
// Terminal images (agent `visualize` and `/viz`) are painted through the
|
|
615
734
|
// renderer; the TUI installs an image sink later, which this follows.
|
|
616
735
|
repl.session.setImageHandler((lines) => renderer.image(lines));
|
|
617
736
|
let missingCredential;
|
|
618
|
-
|
|
737
|
+
let statusTracker = new ReplStatusTracker({
|
|
619
738
|
model: {
|
|
620
739
|
id: harnessModel,
|
|
621
740
|
provider: String(harnessProvider),
|
|
@@ -635,10 +754,56 @@ export async function createReplRuntime(options) {
|
|
|
635
754
|
}
|
|
636
755
|
}
|
|
637
756
|
const runtime = {
|
|
757
|
+
mode: purpose,
|
|
758
|
+
details: replDetailsDefault(options.events),
|
|
759
|
+
askInput: async (prompt, choices) => currentInput?.(prompt, choices),
|
|
760
|
+
harnesses: async () => {
|
|
761
|
+
try {
|
|
762
|
+
return (await readdir(path.resolve(workspace, config.repl.history.dir, 'harnesses'), { withFileTypes: true })).filter(entry => entry.isDirectory()).map(entry => entry.name).sort();
|
|
763
|
+
}
|
|
764
|
+
catch {
|
|
765
|
+
return [];
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
switchMode: async (mode, harness) => {
|
|
769
|
+
const target = normalizeHarnessName(harness) ?? runtime.harnessName;
|
|
770
|
+
const active = repl.session.processes().filter(process => ['running', 'runnable', 'waiting', 'input'].includes(process.state));
|
|
771
|
+
if (active.length)
|
|
772
|
+
throw new Error('Stop active services before switching conversations; they will not be silently disposed.');
|
|
773
|
+
let counterpart;
|
|
774
|
+
if (historyOptions && (mode !== runtime.mode || target !== runtime.harnessName)) {
|
|
775
|
+
const store = new HistoryStore(workspace, '__session_lookup__', historyOptions);
|
|
776
|
+
counterpart = (await store.sessionSummaries()).filter(row => row.mode === mode && row.harness === target && row.kind !== 'workflow-run').at(-1)?.id;
|
|
777
|
+
}
|
|
778
|
+
const next = await createHarnessRepl({ ...replOptions, mode, harness: target, sessionId: counterpart, resume: Boolean(counterpart), autoLoadHarness: true, onInput: currentInput });
|
|
779
|
+
const spec = mode === 'work' ? await next.workSpec() : undefined;
|
|
780
|
+
if (mode === 'work' && !spec?.shell) {
|
|
781
|
+
await next.dispose();
|
|
782
|
+
throw new Error(spec?.diagnostics.join('\n') || 'No Work shell defined.');
|
|
783
|
+
}
|
|
784
|
+
await repl.dispose();
|
|
785
|
+
repl = next;
|
|
786
|
+
agentInbox.reset();
|
|
787
|
+
runtime.repl = next;
|
|
788
|
+
runtime.mode = mode;
|
|
789
|
+
runtime.harnessName = target;
|
|
790
|
+
runtime.sessionId = next.session.getSessionId();
|
|
791
|
+
runtime.resumedSession = counterpart;
|
|
792
|
+
runtime.promptPrefix = mode === 'work' ? 'work> ' : config.repl.promptPrefix ?? 'dml> ';
|
|
793
|
+
runtime.workSpec = spec;
|
|
794
|
+
// Keep whatever the user chose with /details; the default is now the same
|
|
795
|
+
// for Develop and Work, so a mode switch no longer resets it.
|
|
796
|
+
runtime.renderer.setDetails?.(runtime.details ?? replDetailsDefault(options.events));
|
|
797
|
+
statusTracker = new ReplStatusTracker({ model: { id: harnessModel, provider: String(harnessProvider), reasoning, thinkingLevel }, contextWindow });
|
|
798
|
+
statusHolder.tracker = statusTracker;
|
|
799
|
+
wireProcesses(next);
|
|
800
|
+
next.session.setImageHandler(lines => runtime.renderer.image(lines));
|
|
801
|
+
runtime.onSessionChanged?.();
|
|
802
|
+
},
|
|
638
803
|
repl,
|
|
639
804
|
renderer,
|
|
640
805
|
workspace,
|
|
641
|
-
promptPrefix: config.repl.promptPrefix ?? 'dml> ',
|
|
806
|
+
promptPrefix: purpose === 'work' ? 'work> ' : config.repl.promptPrefix ?? 'dml> ',
|
|
642
807
|
toolset,
|
|
643
808
|
version: PACKAGE_VERSION,
|
|
644
809
|
imageBackend,
|
|
@@ -659,12 +824,14 @@ export async function createReplRuntime(options) {
|
|
|
659
824
|
statusSnapshot: () => statusTracker.snapshot(),
|
|
660
825
|
observeEvent: (event) => statusTracker.observe(event),
|
|
661
826
|
tuiMode: options.tui ?? config.repl.tui ?? 'auto',
|
|
662
|
-
setOnInput: (handler) => repl.setOnInput(handler),
|
|
827
|
+
setOnInput: (handler) => { currentInput = handler; repl.setOnInput(handler); },
|
|
663
828
|
missingCredential,
|
|
829
|
+
agentInbox,
|
|
664
830
|
};
|
|
831
|
+
inboxRenderer = () => runtime.renderer;
|
|
665
832
|
// Session-scoped subagents render their lifecycle and output through the
|
|
666
833
|
// active renderer (the TUI swaps it in after this runtime is built).
|
|
667
|
-
|
|
834
|
+
const wireProcesses = (current) => current.session.setProcessEventSink((event) => {
|
|
668
835
|
const label = `⚙ ${event.name}`;
|
|
669
836
|
const sink = runtime.renderer;
|
|
670
837
|
if (event.type === 'output' && event.content) {
|
|
@@ -678,6 +845,8 @@ export async function createReplRuntime(options) {
|
|
|
678
845
|
sink.writeLine(`${label} ${event.state}${reason}`);
|
|
679
846
|
}
|
|
680
847
|
});
|
|
848
|
+
wireProcesses(repl);
|
|
849
|
+
runtime.renderer.setDetails?.(runtime.details ?? true);
|
|
681
850
|
return runtime;
|
|
682
851
|
}
|
|
683
852
|
/** Package version, read once from package.json for the banner/`--version`. */
|
|
@@ -693,6 +862,17 @@ export const PACKAGE_VERSION = (() => {
|
|
|
693
862
|
})();
|
|
694
863
|
/** Startup banner for the interactive REPL (proposal §2.1). */
|
|
695
864
|
async function printBanner(runtime, loaded) {
|
|
865
|
+
if (runtime.mode === 'work') {
|
|
866
|
+
const spec = runtime.workSpec ?? await runtime.repl.workSpec();
|
|
867
|
+
runtime.workSpec = spec;
|
|
868
|
+
runtime.renderer.writeLine(`DeepClause · WORK · ${runtime.harnessName} · ${spec.shell?.kind ?? 'no shell'} · ${runtime.model}`);
|
|
869
|
+
if (spec.shell?.welcome)
|
|
870
|
+
runtime.renderer.writeLine(spec.shell.welcome);
|
|
871
|
+
for (const diagnostic of spec.diagnostics)
|
|
872
|
+
runtime.renderer.writeLine(diagnostic);
|
|
873
|
+
runtime.renderer.writeLine('/workflows — choose a task · /mode — switch conversation · /details — execution detail');
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
696
876
|
const rich = runtime.renderer.mode === 'rich';
|
|
697
877
|
const paint = (text, code) => (rich ? `\u001b[${code}m${text}\u001b[0m` : text);
|
|
698
878
|
const dim = (text) => paint(text, '2');
|
|
@@ -756,9 +936,9 @@ async function resumeSuspendedContinuation(runtime) {
|
|
|
756
936
|
if (!pending)
|
|
757
937
|
return;
|
|
758
938
|
runtime.renderer.writeLine(`resuming the suspended continuation: ${pending.continuation}`);
|
|
759
|
-
await runtime.repl.session.clearSuspension?.();
|
|
760
939
|
try {
|
|
761
|
-
await
|
|
940
|
+
for await (const event of runtime.repl.resumeSuspension())
|
|
941
|
+
runtime.renderer.render(event);
|
|
762
942
|
}
|
|
763
943
|
catch (error) {
|
|
764
944
|
runtime.renderer.writeLine(`could not resume ${pending.continuation}: ${String(error.message)}`);
|
|
@@ -778,7 +958,57 @@ async function renderResumedSession(runtime) {
|
|
|
778
958
|
export async function dispatchReplInput(runtime, input, options = {}) {
|
|
779
959
|
const { repl, renderer } = runtime;
|
|
780
960
|
const print = options.print ?? ((text) => renderer.writeLine(text));
|
|
961
|
+
if (runtime.mode === 'work' && ['goal', 'reset', 'rollback', 'spawn', 'send', 'call', 'freeze', 'unfreeze'].includes(input.kind)) {
|
|
962
|
+
print('This is a Develop operation. Use /mode develop to open a separate authoring conversation.');
|
|
963
|
+
return true;
|
|
964
|
+
}
|
|
781
965
|
switch (input.kind) {
|
|
966
|
+
case 'mode': {
|
|
967
|
+
if (!input.mode) {
|
|
968
|
+
print(`mode: ${runtime.mode ?? 'develop'}; use /mode work|develop [harness]`);
|
|
969
|
+
return true;
|
|
970
|
+
}
|
|
971
|
+
try {
|
|
972
|
+
await runtime.switchMode?.(input.mode, input.harness);
|
|
973
|
+
print(`${runtime.mode} · ${runtime.harnessName} · session ${runtime.sessionId}`);
|
|
974
|
+
if (runtime.workSpec?.shell?.welcome)
|
|
975
|
+
print(runtime.workSpec.shell.welcome);
|
|
976
|
+
await renderResumedSession(runtime);
|
|
977
|
+
}
|
|
978
|
+
catch (error) {
|
|
979
|
+
print(`ERROR: ${error.message}`);
|
|
980
|
+
}
|
|
981
|
+
return true;
|
|
982
|
+
}
|
|
983
|
+
case 'details':
|
|
984
|
+
runtime.details = input.show ?? !runtime.details;
|
|
985
|
+
renderer.setDetails?.(runtime.details);
|
|
986
|
+
print(`details ${runtime.details ? 'on' : 'off'}`);
|
|
987
|
+
return true;
|
|
988
|
+
case 'workflows': {
|
|
989
|
+
const spec = await repl.workSpec();
|
|
990
|
+
if (!spec.shell)
|
|
991
|
+
print(spec.diagnostics.join('\n'));
|
|
992
|
+
else {
|
|
993
|
+
for (const flow of spec.shell.workflows)
|
|
994
|
+
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'}`);
|
|
995
|
+
if (spec.shell.tools.length)
|
|
996
|
+
print(`Assistant tools (not directly runnable): ${spec.shell.tools.map(tool => tool.name).join(', ')}`);
|
|
997
|
+
}
|
|
998
|
+
return true;
|
|
999
|
+
}
|
|
1000
|
+
case 'workflow':
|
|
1001
|
+
if (runtime.mode !== 'work') {
|
|
1002
|
+
print('Use /mode work before starting a declared workflow.');
|
|
1003
|
+
return true;
|
|
1004
|
+
}
|
|
1005
|
+
try {
|
|
1006
|
+
await runDeclaredWorkflow({ repl, name: input.name, inputs: input.inputs, signal: options.signal, ask: runtime.askInput, render: event => renderer.render(event) });
|
|
1007
|
+
}
|
|
1008
|
+
catch (error) {
|
|
1009
|
+
print(`ERROR: ${error.message}`);
|
|
1010
|
+
}
|
|
1011
|
+
return true;
|
|
782
1012
|
case 'empty':
|
|
783
1013
|
case 'comment':
|
|
784
1014
|
return true;
|
|
@@ -826,16 +1056,23 @@ export async function dispatchReplInput(runtime, input, options = {}) {
|
|
|
826
1056
|
print(`stopped ${input.target}`);
|
|
827
1057
|
return true;
|
|
828
1058
|
}
|
|
829
|
-
case 'login':
|
|
830
|
-
|
|
1059
|
+
case 'login': {
|
|
1060
|
+
const flags = [
|
|
1061
|
+
input.provider ? `--provider ${input.provider}` : '',
|
|
1062
|
+
input.baseUrl ? `--base-url ${input.baseUrl}` : '',
|
|
1063
|
+
input.host ? `--host ${input.host}` : '',
|
|
1064
|
+
input.port ? `--port ${input.port}` : '',
|
|
1065
|
+
].filter(Boolean).join(' ');
|
|
1066
|
+
print(`sign in from the terminal: deepclause login${flags ? ` ${flags}` : ''}`);
|
|
831
1067
|
return true;
|
|
1068
|
+
}
|
|
832
1069
|
case 'unknown-command':
|
|
833
1070
|
print(`unknown command: /${input.name} — try /help.`);
|
|
834
1071
|
return true;
|
|
835
1072
|
case 'halt':
|
|
836
1073
|
return false;
|
|
837
1074
|
case 'help':
|
|
838
|
-
print(helpText());
|
|
1075
|
+
print(helpText(runtime.mode));
|
|
839
1076
|
return true;
|
|
840
1077
|
case 'listing': {
|
|
841
1078
|
const text = await repl.list(input.filter);
|
|
@@ -984,6 +1221,13 @@ export async function dispatchReplInput(runtime, input, options = {}) {
|
|
|
984
1221
|
await runGoalWithRenderer(repl, input.goal, { first: options.first, renderer, signal: options.signal });
|
|
985
1222
|
return true;
|
|
986
1223
|
case 'prompt': {
|
|
1224
|
+
if (runtime.mode === 'work') {
|
|
1225
|
+
const spec = await repl.workSpec();
|
|
1226
|
+
if (!spec.shell || spec.shell.kind === 'workflow') {
|
|
1227
|
+
print(spec.diagnostics.join('\n') || 'Choose a declared workflow with /workflows.');
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
987
1231
|
if (runtime.missingCredential) {
|
|
988
1232
|
print(`ERROR: ${runtime.missingCredential}`);
|
|
989
1233
|
return true;
|
|
@@ -997,8 +1241,21 @@ export async function dispatchReplInput(runtime, input, options = {}) {
|
|
|
997
1241
|
return true;
|
|
998
1242
|
}
|
|
999
1243
|
}
|
|
1000
|
-
function helpText() {
|
|
1244
|
+
function helpText(mode) {
|
|
1245
|
+
if (mode === 'work')
|
|
1246
|
+
return [
|
|
1247
|
+
'Work runs a declared harness; it does not author DML.',
|
|
1248
|
+
' /mode work|develop [harness] choose another conversation',
|
|
1249
|
+
' /workflows choose/list declared workflows',
|
|
1250
|
+
' /workflow "Name" {"Input":"value"} execute exactly that workflow',
|
|
1251
|
+
' /details [on|off] show technical events',
|
|
1252
|
+
' /model · /reasoning · /show-reasoning · /compact · /ps · /stop · /halt',
|
|
1253
|
+
'An agent shell accepts conversation. A workflow-only shell uses /workflow.',
|
|
1254
|
+
'Use /mode work <harness> again to refresh into a new snapshot.'
|
|
1255
|
+
].join('\n');
|
|
1001
1256
|
return [
|
|
1257
|
+
' /mode [develop|work] [harness] switch conversation purpose',
|
|
1258
|
+
' /workflows /workflow /details declared Work tasks and presentation',
|
|
1002
1259
|
'DeepClause REPL — a living DML harness you author by talking to it.',
|
|
1003
1260
|
'',
|
|
1004
1261
|
' Modes',
|
|
@@ -1023,7 +1280,7 @@ function helpText() {
|
|
|
1023
1280
|
' /compact [notes] compact the authoring memory',
|
|
1024
1281
|
' /export [file] save the harness (use .zip to bundle linked files)',
|
|
1025
1282
|
' /model [provider/id] show / set the model',
|
|
1026
|
-
' /login
|
|
1283
|
+
' /login [provider] sign in; llama.cpp accepts --host, --port, --base-url',
|
|
1027
1284
|
' /freeze /unfreeze read-only lock',
|
|
1028
1285
|
' /params show session parameters',
|
|
1029
1286
|
' /trace /notrace toggle verbose logging',
|
|
@@ -1054,6 +1311,19 @@ async function executeLoad(runtime, files) {
|
|
|
1054
1311
|
}
|
|
1055
1312
|
return 0;
|
|
1056
1313
|
}
|
|
1314
|
+
/** Present one serialized SDK delivery, including errors and usage, just like a
|
|
1315
|
+
* foreground turn. The SDK remains the sole owner of history/checkpoints. */
|
|
1316
|
+
async function renderAgentInbox(runtime, signal) {
|
|
1317
|
+
try {
|
|
1318
|
+
await runtime.agentInbox?.drain(runtime.repl, event => runtime.renderer.render(event), signal);
|
|
1319
|
+
}
|
|
1320
|
+
catch (error) {
|
|
1321
|
+
runtime.renderer.render({ type: 'error', content: `Background delivery failed: ${error instanceof Error ? error.message : String(error)}` });
|
|
1322
|
+
}
|
|
1323
|
+
finally {
|
|
1324
|
+
runtime.renderer.endTextBlock?.();
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1057
1327
|
/** Non-interactive mode: read classified inputs line by line until EOF. */
|
|
1058
1328
|
/**
|
|
1059
1329
|
* Ctrl-C exits, in every mode: this is the plain/readline path, where there is no
|
|
@@ -1078,13 +1348,33 @@ function installSigint(holder, rl, onExit) {
|
|
|
1078
1348
|
rl?.off('SIGINT', handler);
|
|
1079
1349
|
};
|
|
1080
1350
|
}
|
|
1081
|
-
async function runNonInteractive(runtime, options, onExit) {
|
|
1351
|
+
export async function runNonInteractive(runtime, options, onExit) {
|
|
1082
1352
|
let exitCode = 0;
|
|
1083
1353
|
const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
1084
1354
|
const holder = { turn: null };
|
|
1085
1355
|
const removeSigint = installSigint(holder, rl, onExit);
|
|
1086
1356
|
try {
|
|
1087
|
-
|
|
1357
|
+
const lines = rl[Symbol.asyncIterator]();
|
|
1358
|
+
let nextLine = lines.next();
|
|
1359
|
+
while (true) {
|
|
1360
|
+
const next = runtime.agentInbox
|
|
1361
|
+
? await runtime.agentInbox.waitForInput(nextLine)
|
|
1362
|
+
: { kind: 'input', value: await nextLine };
|
|
1363
|
+
if (next.kind === 'inbox') {
|
|
1364
|
+
const controller = new AbortController();
|
|
1365
|
+
holder.turn = controller;
|
|
1366
|
+
try {
|
|
1367
|
+
await renderAgentInbox(runtime, controller.signal);
|
|
1368
|
+
}
|
|
1369
|
+
finally {
|
|
1370
|
+
holder.turn = null;
|
|
1371
|
+
}
|
|
1372
|
+
continue; // Keep the same pending read: never lose a line during delivery.
|
|
1373
|
+
}
|
|
1374
|
+
if (next.value.done)
|
|
1375
|
+
break;
|
|
1376
|
+
const line = next.value.value;
|
|
1377
|
+
nextLine = lines.next();
|
|
1088
1378
|
const input = classifyReplInput(line);
|
|
1089
1379
|
if (input.kind === 'halt')
|
|
1090
1380
|
break;
|
|
@@ -1111,7 +1401,7 @@ async function runNonInteractive(runtime, options, onExit) {
|
|
|
1111
1401
|
return exitCode;
|
|
1112
1402
|
}
|
|
1113
1403
|
/** Interactive mode with the `dml>` prompt and a `;`/`.` pager for goals. */
|
|
1114
|
-
async function runInteractive(runtime, options, onExit) {
|
|
1404
|
+
export async function runInteractive(runtime, options, onExit) {
|
|
1115
1405
|
const { promptPrefix } = runtime;
|
|
1116
1406
|
const rl = readline.createInterface({
|
|
1117
1407
|
input: process.stdin,
|
|
@@ -1126,6 +1416,12 @@ async function runInteractive(runtime, options, onExit) {
|
|
|
1126
1416
|
rl.on('close', () => {
|
|
1127
1417
|
rlClosed = true;
|
|
1128
1418
|
});
|
|
1419
|
+
let cancelQuestion;
|
|
1420
|
+
let background = false;
|
|
1421
|
+
const queuedLines = [];
|
|
1422
|
+
// readline emits 'line' only when no question callback owns the input. Lines
|
|
1423
|
+
// entered during background work wait for the ordinary foreground dispatcher.
|
|
1424
|
+
rl.on('line', line => queuedLines.push(line));
|
|
1129
1425
|
const ask = (query) => new Promise((resolve) => {
|
|
1130
1426
|
// Calling question() on a closed interface throws; treat it as EOF.
|
|
1131
1427
|
if (rlClosed) {
|
|
@@ -1133,29 +1429,75 @@ async function runInteractive(runtime, options, onExit) {
|
|
|
1133
1429
|
return;
|
|
1134
1430
|
}
|
|
1135
1431
|
let settled = false;
|
|
1432
|
+
const controller = new AbortController();
|
|
1136
1433
|
const finish = (value) => {
|
|
1137
1434
|
if (settled)
|
|
1138
1435
|
return;
|
|
1139
1436
|
settled = true;
|
|
1437
|
+
cancelQuestion = undefined;
|
|
1140
1438
|
rl.off('close', onClose);
|
|
1141
1439
|
resolve(value);
|
|
1142
1440
|
};
|
|
1441
|
+
cancelQuestion = () => { controller.abort(); finish(null); };
|
|
1143
1442
|
const onClose = () => finish(null);
|
|
1144
1443
|
rl.once('close', onClose);
|
|
1145
|
-
rl.question(query, (answer) => finish(answer));
|
|
1444
|
+
rl.question(query, { signal: controller.signal }, (answer) => finish(answer));
|
|
1146
1445
|
});
|
|
1147
1446
|
runtime.setOnInput(async (prompt, choices) => {
|
|
1148
1447
|
const options = choices && choices.length > 0 ? ` (${choices.join('/')})` : '';
|
|
1448
|
+
const draft = background ? rl.line : undefined;
|
|
1449
|
+
if (draft !== undefined)
|
|
1450
|
+
rl.write(null, { ctrl: true, name: 'u' });
|
|
1149
1451
|
runtime.renderer.writeLine('');
|
|
1150
1452
|
runtime.renderer.writeLine(`? ${prompt}${options}`);
|
|
1151
|
-
|
|
1152
|
-
|
|
1453
|
+
try {
|
|
1454
|
+
const answer = await ask('> ');
|
|
1455
|
+
return answer === null ? undefined : answer;
|
|
1456
|
+
}
|
|
1457
|
+
finally {
|
|
1458
|
+
if (draft !== undefined && !rlClosed)
|
|
1459
|
+
rl.write(draft);
|
|
1460
|
+
}
|
|
1153
1461
|
});
|
|
1154
1462
|
const holder = { turn: null };
|
|
1155
1463
|
const removeSigint = installSigint(holder, rl, onExit);
|
|
1156
1464
|
try {
|
|
1157
1465
|
while (true) {
|
|
1158
|
-
|
|
1466
|
+
let line;
|
|
1467
|
+
if (queuedLines.length)
|
|
1468
|
+
line = queuedLines.shift();
|
|
1469
|
+
else {
|
|
1470
|
+
const next = runtime.agentInbox?.hasReady
|
|
1471
|
+
? { kind: 'inbox' }
|
|
1472
|
+
: runtime.agentInbox
|
|
1473
|
+
? await runtime.agentInbox.waitForInput(ask(promptPrefix))
|
|
1474
|
+
: { kind: 'input', value: await ask(promptPrefix) };
|
|
1475
|
+
if (next.kind === 'inbox') {
|
|
1476
|
+
const draft = rl.line;
|
|
1477
|
+
cancelQuestion?.();
|
|
1478
|
+
if (!rlClosed) {
|
|
1479
|
+
rl.write(null, { ctrl: true, name: 'u' });
|
|
1480
|
+
process.stdout.write('\n');
|
|
1481
|
+
}
|
|
1482
|
+
background = true;
|
|
1483
|
+
const controller = new AbortController();
|
|
1484
|
+
holder.turn = controller;
|
|
1485
|
+
try {
|
|
1486
|
+
// Keep the draft editable while output arrives; explicit input/2
|
|
1487
|
+
// temporarily borrows it through the handler above.
|
|
1488
|
+
if (!rlClosed)
|
|
1489
|
+
rl.write(draft);
|
|
1490
|
+
await renderAgentInbox(runtime, controller.signal);
|
|
1491
|
+
}
|
|
1492
|
+
finally {
|
|
1493
|
+
cancelQuestion?.();
|
|
1494
|
+
background = false;
|
|
1495
|
+
holder.turn = null;
|
|
1496
|
+
}
|
|
1497
|
+
continue;
|
|
1498
|
+
}
|
|
1499
|
+
line = next.value;
|
|
1500
|
+
}
|
|
1159
1501
|
if (line === null)
|
|
1160
1502
|
break;
|
|
1161
1503
|
const input = classifyReplInput(line);
|
|
@@ -1271,6 +1613,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1271
1613
|
const working = new WorkingLine(tui);
|
|
1272
1614
|
const renderer = new TuiRenderer({
|
|
1273
1615
|
document,
|
|
1616
|
+
events: runtime.details ?? true,
|
|
1274
1617
|
// The TUI draws through its own switch, but the status tracker must still see
|
|
1275
1618
|
// every event (usage, model_call, …) or the footer loses its counters.
|
|
1276
1619
|
onEvent: (event) => runtime.observeEvent(event),
|
|
@@ -1280,7 +1623,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1280
1623
|
},
|
|
1281
1624
|
});
|
|
1282
1625
|
runtime.renderer = renderer;
|
|
1283
|
-
const runState = { running: false, steerable: false, bufferable: false };
|
|
1626
|
+
const runState = { running: false, steerable: false, bufferable: false, background: false, queueable: false };
|
|
1284
1627
|
/** Slash commands typed during a turn/command, run when it finishes. */
|
|
1285
1628
|
const pendingCommands = [];
|
|
1286
1629
|
/** Lines typed during a goal query, consumed by the solution pager. */
|
|
@@ -1288,11 +1631,14 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1288
1631
|
const statusBar = new StatusBarComponent({
|
|
1289
1632
|
getSnapshot: () => runtime.statusSnapshot(),
|
|
1290
1633
|
workspace: runtime.workspace,
|
|
1291
|
-
sessionId: runtime.sessionId,
|
|
1292
|
-
harness: runtime.harnessName,
|
|
1634
|
+
sessionId: () => runtime.sessionId,
|
|
1635
|
+
harness: () => runtime.harnessName,
|
|
1636
|
+
mode: () => runtime.mode ?? 'develop',
|
|
1637
|
+
workVersion: () => runtime.mode === 'work' && runtime.workSpec ? `${runtime.workSpec.version !== undefined ? `v${runtime.workSpec.version} ` : ''}${runtime.workSpec.hash.slice(0, 6)}` : undefined,
|
|
1293
1638
|
backend: runtime.backend,
|
|
1294
1639
|
isFrozen: () => runtime.repl.isFrozen(),
|
|
1295
1640
|
isRunning: () => runState.running,
|
|
1641
|
+
canSteer: () => runState.steerable,
|
|
1296
1642
|
processLabel: () => {
|
|
1297
1643
|
const active = runtime.repl.session
|
|
1298
1644
|
.processes()
|
|
@@ -1389,6 +1735,14 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1389
1735
|
transcript.append(' (queued — runs when the current turn finishes)');
|
|
1390
1736
|
}
|
|
1391
1737
|
}
|
|
1738
|
+
else if (runState.background || runState.queueable) {
|
|
1739
|
+
// Hook-enabled agents cannot steer. Queue real human input behind their
|
|
1740
|
+
// foreground/background turn, never injecting a process-origin user turn.
|
|
1741
|
+
runtime.renderer.endTextBlock?.();
|
|
1742
|
+
transcript.append(text, 'user');
|
|
1743
|
+
pendingCommands.push(text);
|
|
1744
|
+
transcript.append(` (queued — runs when the ${runState.background ? 'background' : 'current'} turn finishes)`);
|
|
1745
|
+
}
|
|
1392
1746
|
else if (runState.steerable) {
|
|
1393
1747
|
runtime.renderer.endTextBlock?.();
|
|
1394
1748
|
transcript.append(text, 'steer');
|
|
@@ -1442,7 +1796,9 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1442
1796
|
? label
|
|
1443
1797
|
: label === ' ;'
|
|
1444
1798
|
? 'Enter/; more · a all · . stop'
|
|
1445
|
-
:
|
|
1799
|
+
: label === runtime.promptPrefix
|
|
1800
|
+
? null
|
|
1801
|
+
: label;
|
|
1446
1802
|
editor.setPrompt(hint);
|
|
1447
1803
|
tui.setFocus(editor);
|
|
1448
1804
|
}
|
|
@@ -1453,14 +1809,33 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1453
1809
|
// Route ask_user / input/2 through the editor prompt instead of the transcript.
|
|
1454
1810
|
runtime.setOnInput(async (prompt, choices) => {
|
|
1455
1811
|
const suffix = choices && choices.length > 0 ? ` (${choices.join('/')})` : '';
|
|
1456
|
-
|
|
1457
|
-
|
|
1812
|
+
// A background input request borrows the editor, not the user's unsent draft.
|
|
1813
|
+
const draft = runState.background ? editor?.getText() : undefined;
|
|
1814
|
+
if (draft !== undefined)
|
|
1815
|
+
editor?.setText('');
|
|
1816
|
+
try {
|
|
1817
|
+
const answer = await ask(`${prompt}${suffix}`, true);
|
|
1818
|
+
return answer === null ? undefined : answer;
|
|
1819
|
+
}
|
|
1820
|
+
finally {
|
|
1821
|
+
if (draft !== undefined)
|
|
1822
|
+
editor?.setText(draft);
|
|
1823
|
+
}
|
|
1458
1824
|
});
|
|
1825
|
+
const dismissInputPrompt = () => {
|
|
1826
|
+
if (!pendingIsInput)
|
|
1827
|
+
return;
|
|
1828
|
+
const resolve = pendingResolve;
|
|
1829
|
+
pendingResolve = null;
|
|
1830
|
+
pendingIsInput = false;
|
|
1831
|
+
resolve?.(null);
|
|
1832
|
+
};
|
|
1459
1833
|
/** Interrupt the running turn, if any. Returns whether there was one. */
|
|
1460
1834
|
const interruptTurn = () => {
|
|
1461
1835
|
if (!holder.turn)
|
|
1462
1836
|
return false;
|
|
1463
1837
|
holder.turn.abort(new Error('cancelled by user'));
|
|
1838
|
+
dismissInputPrompt();
|
|
1464
1839
|
// Close the streamed block and clear the dock spinner so an interrupted turn
|
|
1465
1840
|
// leaves no live line behind.
|
|
1466
1841
|
runtime.renderer.endTextBlock?.();
|
|
@@ -1642,7 +2017,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1642
2017
|
renderer.writeLine(`harness view ${harnessWidth} columns`);
|
|
1643
2018
|
};
|
|
1644
2019
|
const pickModel = async () => {
|
|
1645
|
-
const catalog = runtime.modelResolver?.catalog() ?? [];
|
|
2020
|
+
const catalog = runtime.modelPickerCatalog ?? runtime.modelResolver?.catalog() ?? [];
|
|
1646
2021
|
if (catalog.length === 0) {
|
|
1647
2022
|
renderer.writeLine(`model: ${runtime.model} (no catalog to choose from; set one in config)`);
|
|
1648
2023
|
return;
|
|
@@ -1650,7 +2025,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1650
2025
|
const current = runtime.model.includes(':') ? runtime.model : undefined;
|
|
1651
2026
|
const picked = await choose((done) => new ChoicePicker({
|
|
1652
2027
|
title: 'Model',
|
|
1653
|
-
hint: 'The default for this workspace (applies
|
|
2028
|
+
hint: 'The default for this workspace (applies on the next CLI start)',
|
|
1654
2029
|
current,
|
|
1655
2030
|
items: catalog.map((entry) => ({
|
|
1656
2031
|
value: entry.model,
|
|
@@ -1668,7 +2043,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1668
2043
|
renderer.writeLine(`default model set to ${picked} (takes effect on the next start)`);
|
|
1669
2044
|
};
|
|
1670
2045
|
/** `/login`: sign in to a provider from inside the TUI. */
|
|
1671
|
-
const runLogin = async () => {
|
|
2046
|
+
const runLogin = async (input) => {
|
|
1672
2047
|
let handle;
|
|
1673
2048
|
try {
|
|
1674
2049
|
handle = await openPiRuntime({});
|
|
@@ -1682,19 +2057,64 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1682
2057
|
renderer.writeLine('no login providers available');
|
|
1683
2058
|
return;
|
|
1684
2059
|
}
|
|
1685
|
-
const
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
description: provider.configured ? '✓ configured' : provider.authType,
|
|
1692
|
-
})),
|
|
1693
|
-
onSelect: (item) => done(item.value),
|
|
1694
|
-
onCancel: () => done(),
|
|
1695
|
-
}));
|
|
1696
|
-
if (!picked)
|
|
2060
|
+
const explicitEndpoint = input.baseUrl !== undefined
|
|
2061
|
+
|| input.host !== undefined
|
|
2062
|
+
|| input.port !== undefined;
|
|
2063
|
+
let picked = input.provider ?? (explicitEndpoint ? LLAMA_PROVIDER_ID : undefined);
|
|
2064
|
+
if (picked && !providers.some((provider) => provider.id === picked)) {
|
|
2065
|
+
renderer.writeLine(`unknown login provider: ${picked}`);
|
|
1697
2066
|
return;
|
|
2067
|
+
}
|
|
2068
|
+
if (!picked) {
|
|
2069
|
+
picked = await choose((done) => new ChoicePicker({
|
|
2070
|
+
title: 'Sign in to a provider',
|
|
2071
|
+
hint: 'Esc to cancel',
|
|
2072
|
+
items: providers.map((provider) => ({
|
|
2073
|
+
value: provider.id,
|
|
2074
|
+
label: `${provider.name} (${provider.id})`,
|
|
2075
|
+
description: provider.configured ? '✓ configured' : provider.authType,
|
|
2076
|
+
})),
|
|
2077
|
+
onSelect: (item) => done(item.value),
|
|
2078
|
+
onCancel: () => done(),
|
|
2079
|
+
}));
|
|
2080
|
+
if (!picked)
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
2083
|
+
// llama.cpp is the one provider whose endpoint is a local/remote server.
|
|
2084
|
+
// Collect it as a base URL, a host:port, or a bare host + port instead of
|
|
2085
|
+
// making the user type a full scheme in pi's generic URL prompt.
|
|
2086
|
+
let baseUrl = input.baseUrl;
|
|
2087
|
+
let host = input.host;
|
|
2088
|
+
let port = input.port;
|
|
2089
|
+
if (picked === LLAMA_PROVIDER_ID && !explicitEndpoint) {
|
|
2090
|
+
const envUrl = process.env.LLAMA_BASE_URL?.trim();
|
|
2091
|
+
const endpointAnswer = await ask(`llama.cpp host or base URL (${envUrl ?? '127.0.0.1'}) `);
|
|
2092
|
+
if (endpointAnswer === null)
|
|
2093
|
+
return;
|
|
2094
|
+
const endpoint = endpointAnswer.trim();
|
|
2095
|
+
if (endpoint && /^https?:\/\//i.test(endpoint)) {
|
|
2096
|
+
baseUrl = endpoint;
|
|
2097
|
+
}
|
|
2098
|
+
else if (!endpoint && envUrl) {
|
|
2099
|
+
baseUrl = envUrl;
|
|
2100
|
+
}
|
|
2101
|
+
else {
|
|
2102
|
+
host = endpoint || '127.0.0.1';
|
|
2103
|
+
let hasPort = false;
|
|
2104
|
+
try {
|
|
2105
|
+
hasPort = Boolean(new URL(`http://${host}`).port);
|
|
2106
|
+
}
|
|
2107
|
+
catch {
|
|
2108
|
+
// resolveLlamaServerUrl reports a precise error after the prompts.
|
|
2109
|
+
}
|
|
2110
|
+
if (!hasPort) {
|
|
2111
|
+
const portAnswer = await ask('llama.cpp port (8080) ');
|
|
2112
|
+
if (portAnswer === null)
|
|
2113
|
+
return;
|
|
2114
|
+
port = portAnswer.trim() || '8080';
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
1698
2118
|
const interaction = {
|
|
1699
2119
|
prompt: async (prompt) => {
|
|
1700
2120
|
if (prompt.options && prompt.options.length > 0) {
|
|
@@ -1727,9 +2147,18 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1727
2147
|
},
|
|
1728
2148
|
};
|
|
1729
2149
|
try {
|
|
1730
|
-
await loginToProvider(handle, picked, {
|
|
2150
|
+
await loginToProvider(handle, picked, {
|
|
2151
|
+
interaction,
|
|
2152
|
+
baseUrl,
|
|
2153
|
+
host,
|
|
2154
|
+
port,
|
|
2155
|
+
});
|
|
1731
2156
|
await persistSetting({ backend: { kind: 'pi' } }, 'login');
|
|
1732
|
-
|
|
2157
|
+
// The active backend's registry predates this login. Use the login
|
|
2158
|
+
// session's refreshed registry for /model so the new provider/models are
|
|
2159
|
+
// visible immediately (the choice still applies on the next start).
|
|
2160
|
+
runtime.modelPickerCatalog = new PiModelResolver(handle.registry).catalog();
|
|
2161
|
+
renderer.writeLine(`signed in to ${picked} (use /model <provider/id> to set the default for the next start)`);
|
|
1733
2162
|
}
|
|
1734
2163
|
catch (error) {
|
|
1735
2164
|
renderer.writeLine(`login failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -1754,6 +2183,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1754
2183
|
},
|
|
1755
2184
|
});
|
|
1756
2185
|
harnessView.refresh();
|
|
2186
|
+
const workView = new WorkView(() => runtime.workSpec);
|
|
1757
2187
|
let harnessVisible = options.harnessView ?? false;
|
|
1758
2188
|
let servicesVisible = false;
|
|
1759
2189
|
let servicesLogs = false;
|
|
@@ -1812,12 +2242,12 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1812
2242
|
const columns = new HStack([
|
|
1813
2243
|
{ component: scroll, basis: 0, grow: 1, shrink: 1, minSize: 20 },
|
|
1814
2244
|
{
|
|
1815
|
-
component: harnessView,
|
|
2245
|
+
component: runtime.mode === 'work' ? workView : harnessView,
|
|
1816
2246
|
basis: harnessWidth,
|
|
1817
2247
|
grow: 0,
|
|
1818
2248
|
shrink: 0,
|
|
1819
2249
|
minSize: 20,
|
|
1820
|
-
visible: (viewport) => harnessVisible && viewport.width >= 96,
|
|
2250
|
+
visible: (viewport) => (runtime.mode === 'work' || harnessVisible) && viewport.width >= 96,
|
|
1821
2251
|
},
|
|
1822
2252
|
], { gap: 1 });
|
|
1823
2253
|
tui.setLayoutRoot(new VStack([
|
|
@@ -1829,7 +2259,7 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1829
2259
|
applyLayout();
|
|
1830
2260
|
// A form opened by the running turn is shown in the dock and edited field by
|
|
1831
2261
|
// field through the editor; the plain-TTY path uses the raw widget instead.
|
|
1832
|
-
|
|
2262
|
+
const presentTuiForm = async (form) => {
|
|
1833
2263
|
const spec = form.spec;
|
|
1834
2264
|
if (!spec)
|
|
1835
2265
|
return;
|
|
@@ -1859,7 +2289,16 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1859
2289
|
formView.setState(undefined);
|
|
1860
2290
|
tui.requestRender();
|
|
1861
2291
|
}
|
|
1862
|
-
}
|
|
2292
|
+
};
|
|
2293
|
+
runtime.repl.session.setFormHandler(presentTuiForm);
|
|
2294
|
+
runtime.onSessionChanged = () => {
|
|
2295
|
+
runtime.repl.session.setFormHandler(presentTuiForm);
|
|
2296
|
+
runtime.repl.session.setImageHandler(lines => runtime.renderer.image(lines));
|
|
2297
|
+
harnessView.refresh();
|
|
2298
|
+
applyLayout();
|
|
2299
|
+
tui.invalidate();
|
|
2300
|
+
tui.requestRender();
|
|
2301
|
+
};
|
|
1863
2302
|
tui.start();
|
|
1864
2303
|
await printBanner(runtime, loaded);
|
|
1865
2304
|
await renderResumedSession(runtime);
|
|
@@ -1875,13 +2314,80 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1875
2314
|
tui.requestRender();
|
|
1876
2315
|
}
|
|
1877
2316
|
else {
|
|
1878
|
-
|
|
2317
|
+
// Only the idle main prompt is interruptible by an inbox wakeup. Pickers,
|
|
2318
|
+
// forms, tool approvals and foreground turns retain their normal owner.
|
|
2319
|
+
const next = runtime.agentInbox?.hasReady
|
|
2320
|
+
? { kind: 'inbox' }
|
|
2321
|
+
: runtime.agentInbox
|
|
2322
|
+
? await runtime.agentInbox.waitForInput(ask(runtime.promptPrefix))
|
|
2323
|
+
: { kind: 'input', value: await ask(runtime.promptPrefix) };
|
|
2324
|
+
if (next.kind === 'inbox') {
|
|
2325
|
+
// Detach the idle ask without submitting/clearing the editor's draft.
|
|
2326
|
+
pendingResolve = null;
|
|
2327
|
+
const controller = new AbortController();
|
|
2328
|
+
holder.turn = controller;
|
|
2329
|
+
runState.running = true;
|
|
2330
|
+
runState.background = true;
|
|
2331
|
+
runState.steerable = false;
|
|
2332
|
+
runState.bufferable = false;
|
|
2333
|
+
tui.requestRender();
|
|
2334
|
+
try {
|
|
2335
|
+
await renderAgentInbox(runtime, controller.signal);
|
|
2336
|
+
}
|
|
2337
|
+
finally {
|
|
2338
|
+
dismissInputPrompt();
|
|
2339
|
+
pendingResolve = null;
|
|
2340
|
+
holder.turn = null;
|
|
2341
|
+
runState.running = false;
|
|
2342
|
+
runState.background = false;
|
|
2343
|
+
editor?.setPrompt(null);
|
|
2344
|
+
working.set(null);
|
|
2345
|
+
tui.requestRender();
|
|
2346
|
+
}
|
|
2347
|
+
continue;
|
|
2348
|
+
}
|
|
2349
|
+
line = next.value;
|
|
1879
2350
|
if (line === null)
|
|
1880
2351
|
break;
|
|
1881
2352
|
}
|
|
1882
|
-
|
|
2353
|
+
let input = classifyReplInput(line);
|
|
1883
2354
|
if (input.kind === 'halt')
|
|
1884
2355
|
break;
|
|
2356
|
+
if (input.kind === 'mode' && !input.mode) {
|
|
2357
|
+
const mode = await choose(done => new ChoicePicker({ title: 'Conversation mode', items: [
|
|
2358
|
+
{ value: 'develop', label: 'Develop', description: 'Author and edit a harness' },
|
|
2359
|
+
{ value: 'work', label: 'Work', description: 'Use declared tools and workflows' },
|
|
2360
|
+
], onSelect: item => done(item.value), onCancel: () => done() }));
|
|
2361
|
+
if (!mode)
|
|
2362
|
+
continue;
|
|
2363
|
+
let harness;
|
|
2364
|
+
if (mode === 'work') {
|
|
2365
|
+
const names = await runtime.harnesses?.() ?? [];
|
|
2366
|
+
if (!names.length) {
|
|
2367
|
+
renderer.writeLine('No harnesses yet. Create one in Develop first.');
|
|
2368
|
+
continue;
|
|
2369
|
+
}
|
|
2370
|
+
harness = await choose(done => new ChoicePicker({ title: 'Work harness', current: runtime.harnessName,
|
|
2371
|
+
items: names.map(name => ({ value: name, label: name })), onSelect: item => done(item.value), onCancel: () => done() }));
|
|
2372
|
+
if (!harness)
|
|
2373
|
+
continue;
|
|
2374
|
+
}
|
|
2375
|
+
input = { kind: 'mode', mode: mode, harness };
|
|
2376
|
+
}
|
|
2377
|
+
if (input.kind === 'workflows' && runtime.mode === 'work') {
|
|
2378
|
+
const spec = await runtime.repl.workSpec();
|
|
2379
|
+
runtime.workSpec = spec;
|
|
2380
|
+
if (!spec.shell?.workflows.length) {
|
|
2381
|
+
renderer.writeLine(spec.diagnostics.join('\n') || 'No workflows; use the Work assistant.');
|
|
2382
|
+
continue;
|
|
2383
|
+
}
|
|
2384
|
+
const name = await choose(done => new ChoicePicker({ title: 'Workflows', items: spec.shell.workflows.map(flow => ({
|
|
2385
|
+
value: flow.name, label: flow.name, description: `${flow.inputs.length} inputs · ${flow.outputs.length} outputs`,
|
|
2386
|
+
})), onSelect: item => done(item.value), onCancel: () => done() }));
|
|
2387
|
+
if (!name)
|
|
2388
|
+
continue;
|
|
2389
|
+
input = { kind: 'workflow', name };
|
|
2390
|
+
}
|
|
1885
2391
|
// The pickers are overlays over the transcript, so they need the TUI and are
|
|
1886
2392
|
// handled here rather than in the command dispatcher the readline path shares.
|
|
1887
2393
|
if (input.kind === 'model' && !input.model) {
|
|
@@ -1897,11 +2403,15 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1897
2403
|
continue;
|
|
1898
2404
|
}
|
|
1899
2405
|
if (input.kind === 'harness') {
|
|
2406
|
+
if (runtime.mode === 'work') {
|
|
2407
|
+
renderer.writeLine('The source side view is in Develop; use /workflows here.');
|
|
2408
|
+
continue;
|
|
2409
|
+
}
|
|
1900
2410
|
await handleHarnessCommand(input.width);
|
|
1901
2411
|
continue;
|
|
1902
2412
|
}
|
|
1903
2413
|
if (input.kind === 'login') {
|
|
1904
|
-
await runLogin();
|
|
2414
|
+
await runLogin(input);
|
|
1905
2415
|
continue;
|
|
1906
2416
|
}
|
|
1907
2417
|
if (input.kind === 'ps' && (input.watch || input.logs)) {
|
|
@@ -1920,7 +2430,10 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1920
2430
|
const controller = new AbortController();
|
|
1921
2431
|
holder.turn = controller;
|
|
1922
2432
|
runState.running = true;
|
|
1923
|
-
|
|
2433
|
+
// Inbox-only shells also use the protected effective-context bridge.
|
|
2434
|
+
const shell = runtime.mode === 'work' ? runtime.workSpec?.shell : undefined;
|
|
2435
|
+
runState.steerable = input.kind === 'prompt' && !(shell?.hooks || shell?.inbox);
|
|
2436
|
+
runState.queueable = input.kind === 'prompt' && !runState.steerable;
|
|
1924
2437
|
runState.bufferable = input.kind === 'goal';
|
|
1925
2438
|
bufferedInput.length = 0;
|
|
1926
2439
|
tui.requestRender();
|
|
@@ -1941,6 +2454,8 @@ export async function runTui(runtime, options, onExit, loaded = []) {
|
|
|
1941
2454
|
finally {
|
|
1942
2455
|
holder.turn = null;
|
|
1943
2456
|
runState.running = false;
|
|
2457
|
+
runState.steerable = false;
|
|
2458
|
+
runState.queueable = false;
|
|
1944
2459
|
tui.requestRender();
|
|
1945
2460
|
}
|
|
1946
2461
|
}
|
|
@@ -1987,7 +2502,7 @@ export async function startRepl(options) {
|
|
|
1987
2502
|
// saved, or when the harness has no predicates.
|
|
1988
2503
|
let exitSaved = false;
|
|
1989
2504
|
const saveHarnessOnExit = async () => {
|
|
1990
|
-
if (exitSaved || options.exportPath || options.saveOnExit === false)
|
|
2505
|
+
if (runtime.mode === 'work' || exitSaved || options.exportPath || options.saveOnExit === false)
|
|
1991
2506
|
return;
|
|
1992
2507
|
exitSaved = true;
|
|
1993
2508
|
try {
|
|
@@ -2010,6 +2525,25 @@ export async function startRepl(options) {
|
|
|
2010
2525
|
if (options.load?.length) {
|
|
2011
2526
|
await runtime.repl.session.finalizeHarnessBaseline();
|
|
2012
2527
|
}
|
|
2528
|
+
if (runtime.mode === 'work')
|
|
2529
|
+
runtime.workSpec = await runtime.repl.workSpec();
|
|
2530
|
+
if (options.workflow) {
|
|
2531
|
+
const controller = new AbortController();
|
|
2532
|
+
const removeSigint = installSigint({ turn: controller });
|
|
2533
|
+
try {
|
|
2534
|
+
const inputs = options.inputs === undefined ? undefined : JSON.parse(options.inputs);
|
|
2535
|
+
const ok = await runDeclaredWorkflow({ repl: runtime.repl, name: options.workflow, inputs,
|
|
2536
|
+
signal: controller.signal, ask: runtime.askInput, render: event => runtime.renderer.render(event) });
|
|
2537
|
+
return ok ? 0 : 1;
|
|
2538
|
+
}
|
|
2539
|
+
catch (error) {
|
|
2540
|
+
runtime.renderer.writeErrorLine(`ERROR: ${error.message}`);
|
|
2541
|
+
return 1;
|
|
2542
|
+
}
|
|
2543
|
+
finally {
|
|
2544
|
+
removeSigint();
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2013
2547
|
// Freeze/lock only after all `-l` loads succeed (load before lock).
|
|
2014
2548
|
if (options.locked) {
|
|
2015
2549
|
await runtime.repl.lock();
|
|
@@ -2087,6 +2621,13 @@ export function registerReplCommand(program) {
|
|
|
2087
2621
|
.option('-g, --goal <goal>', 'run one goal and exit (repeatable)', collect)
|
|
2088
2622
|
.option('-l, --load <file>', 'load a DML file before starting (repeatable)', collect)
|
|
2089
2623
|
.option('--session <id>', 'resume a previous session by id (or "last")')
|
|
2624
|
+
.option('--mode <mode>', 'conversation purpose: develop (default) or work', (value) => {
|
|
2625
|
+
if (value !== 'develop' && value !== 'work')
|
|
2626
|
+
throw new Error('mode must be develop or work');
|
|
2627
|
+
return value;
|
|
2628
|
+
})
|
|
2629
|
+
.option('--workflow <name>', 'run exactly this declared Work workflow and exit')
|
|
2630
|
+
.option('--inputs <json>', 'workflow inputs as a JSON object')
|
|
2090
2631
|
.option('--harness <name>', 'harness to edit (a project can hold several; default main)')
|
|
2091
2632
|
.option('--first', 'with a goal, print only the first solution')
|
|
2092
2633
|
.option('--plain', 'no TUI formatting (auto when stdout is not a TTY)')
|
|
@@ -2113,6 +2654,8 @@ export function registerReplCommand(program) {
|
|
|
2113
2654
|
.option('--tools <list>', 'comma-separated capability host tools (default: bash)')
|
|
2114
2655
|
.option('--no-tools', 'register no capability host tools')
|
|
2115
2656
|
.option('--sandbox', 'run shell tools in AgentVM')
|
|
2657
|
+
.option('--allow-network', 'allow AgentVM outbound TCP/UDP networking')
|
|
2658
|
+
.option('--no-allow-network', 'disable AgentVM networking, overriding configuration')
|
|
2116
2659
|
.option('--require-sandbox', 'refuse to run unless the shell is sandboxed (bwrap/AgentVM/sandbox-exec)')
|
|
2117
2660
|
.option('--harness-view', 'open the live harness side view (experiment)')
|
|
2118
2661
|
.option('--execution <mode>', 'process execution mode: worker (L2, default) or inline (L1)', (value) => {
|
|
@@ -2142,6 +2685,9 @@ export function registerReplCommand(program) {
|
|
|
2142
2685
|
.option('--no-color', 'disable ANSI color')
|
|
2143
2686
|
.action(async (options) => {
|
|
2144
2687
|
const exitCode = await startRepl({
|
|
2688
|
+
mode: options.mode,
|
|
2689
|
+
workflow: options.workflow,
|
|
2690
|
+
inputs: options.inputs,
|
|
2145
2691
|
goal: options.goal,
|
|
2146
2692
|
load: options.load,
|
|
2147
2693
|
session: options.session,
|
|
@@ -2166,6 +2712,7 @@ export function registerReplCommand(program) {
|
|
|
2166
2712
|
tools: typeof options.tools === 'string' ? options.tools : undefined,
|
|
2167
2713
|
noTools: options.tools === false,
|
|
2168
2714
|
sandbox: options.sandbox,
|
|
2715
|
+
allowNetwork: options.allowNetwork,
|
|
2169
2716
|
requireSandbox: options.requireSandbox,
|
|
2170
2717
|
harnessView: options.harnessView,
|
|
2171
2718
|
execution: options.execution,
|
|
@@ -2196,8 +2743,12 @@ export function normalizeHarnessName(name) {
|
|
|
2196
2743
|
const trimmed = name?.trim();
|
|
2197
2744
|
if (!trimmed)
|
|
2198
2745
|
return undefined;
|
|
2199
|
-
|
|
2200
|
-
|
|
2746
|
+
let slug = trimmed.toLowerCase().replace(/[^a-z0-9_]+/g, '_').replace(/^_+|_+$/g, '');
|
|
2747
|
+
if (!slug)
|
|
2748
|
+
return undefined;
|
|
2749
|
+
if (!/^[a-z]/.test(slug))
|
|
2750
|
+
slug = `h_${slug}`;
|
|
2751
|
+
return slug;
|
|
2201
2752
|
}
|
|
2202
2753
|
/** Harness name implied by a `-l` file: its basename without the `.dml`/`.zip`. */
|
|
2203
2754
|
function harnessNameFromFile(file) {
|