@ouro.bot/cli 0.1.0-alpha.1016 → 0.1.0-alpha.1019
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/changelog.json +14 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/auth/auth-flow.js +17 -12
- package/dist/heart/daemon/cli-defaults.js +19 -6
- package/dist/heart/daemon/provider-discovery.js +34 -0
- package/dist/heart/hatch/specialist-prompt.js +1 -0
- package/dist/heart/hatch/specialist-tools.js +39 -2
- package/dist/heart/optional-packages.js +9 -3
- package/dist/repertoire/bitwarden-native.js +2 -2
- package/dist/senses/cli/ouro-tui.js +2 -2
- package/dist/senses/cli/tui-store.js +11 -0
- package/dist/senses/cli.js +38 -9
- package/dist/senses/terminal-handoff.js +44 -0
- package/npm-shrinkwrap.json +298 -52
- package/package.json +7 -6
package/changelog.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1019",
|
|
6
|
+
"changes": [
|
|
7
|
+
"ouro hatch on a host with GH_TOKEN or GITHUB_TOKEN set: the github-copilot option it offers now looks up the account's Copilot endpoint first, so choosing it works instead of failing with 'no credentials configured'.",
|
|
8
|
+
"The hatchling vault unlock prompt during ouro hatch pauses the conversation view: the spinner stops, the prompt is visible, and what you type is hidden instead of being echoed into the chat input.",
|
|
9
|
+
"A failed complete_adoption no longer crashes ouro hatch with a JSON parse error: the guide explains the error and can retry, and quitting prints what went wrong."
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"version": "0.1.0-alpha.1021",
|
|
14
|
+
"changes": [
|
|
15
|
+
"A small host's install (npm config set omit optional) is now about 46 MB and 43 packages instead of 221 MB and 426: the bundled Bitwarden CLI and the terminal chat UI (ink, react) are optional packages too. Vault reads and writes are native, so bw is only fetched when a vault needs it, and without the chat UI ouro chats line by line. shell-quote, which the shell guardrails load, is now declared instead of arriving through ink, and a test keeps every runtime import declared. Native vault reads no longer need the access token to name the user (only writes do), and the edge benchmark's fake vault issues a real JWT, so it reads natively again."
|
|
16
|
+
]
|
|
17
|
+
},
|
|
4
18
|
{
|
|
5
19
|
"version": "0.1.0-alpha.1016",
|
|
6
20
|
"changes": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1019</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -39,6 +39,7 @@ exports.storeProviderCredentials = storeProviderCredentials;
|
|
|
39
39
|
exports.writeAgentModel = writeAgentModel;
|
|
40
40
|
exports.readAccountPoolSettings = readAccountPoolSettings;
|
|
41
41
|
exports.collectGithubCopilotPoolCredentials = collectGithubCopilotPoolCredentials;
|
|
42
|
+
exports.discoverGithubCopilotBaseUrl = discoverGithubCopilotBaseUrl;
|
|
42
43
|
exports.collectRuntimeAuthCredentials = collectRuntimeAuthCredentials;
|
|
43
44
|
exports.resolveHatchCredentials = resolveHatchCredentials;
|
|
44
45
|
exports.runRuntimeAuthFlow = runRuntimeAuthFlow;
|
|
@@ -331,6 +332,21 @@ async function collectGithubCopilotPoolCredentials(input, settings, deps) {
|
|
|
331
332
|
});
|
|
332
333
|
return credentials;
|
|
333
334
|
}
|
|
335
|
+
/** Ask GitHub which Copilot API endpoint serves this token's account (`endpoints.api`). */
|
|
336
|
+
async function discoverGithubCopilotBaseUrl(token, fetchImpl = fetch) {
|
|
337
|
+
const response = await fetchImpl("https://api.github.com/copilot_internal/user", {
|
|
338
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
339
|
+
});
|
|
340
|
+
if (!response.ok) {
|
|
341
|
+
throw new Error(`GitHub Copilot endpoint discovery failed (HTTP ${response.status}). Ensure your GitHub account has Copilot access.`);
|
|
342
|
+
}
|
|
343
|
+
const body = await response.json();
|
|
344
|
+
const baseUrl = body?.endpoints?.api;
|
|
345
|
+
if (!baseUrl) {
|
|
346
|
+
throw new Error("GitHub Copilot endpoint discovery returned no endpoints.api. Ensure your GitHub account has Copilot access.");
|
|
347
|
+
}
|
|
348
|
+
return baseUrl;
|
|
349
|
+
}
|
|
334
350
|
async function collectRuntimeAuthCredentials(input, deps) {
|
|
335
351
|
const spawnSync = deps.spawnSync ?? child_process_1.spawnSync;
|
|
336
352
|
const homeDir = deps.homeDir ?? os.homedir();
|
|
@@ -389,18 +405,7 @@ async function collectRuntimeAuthCredentials(input, deps) {
|
|
|
389
405
|
}
|
|
390
406
|
}
|
|
391
407
|
writeAuthProgress(input, "checking GitHub Copilot access...");
|
|
392
|
-
const
|
|
393
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
394
|
-
});
|
|
395
|
-
if (!response.ok) {
|
|
396
|
-
throw new Error(`GitHub Copilot endpoint discovery failed (HTTP ${response.status}). Ensure your GitHub account has Copilot access.`);
|
|
397
|
-
}
|
|
398
|
-
const body = await response.json();
|
|
399
|
-
const baseUrl = body?.endpoints?.api;
|
|
400
|
-
/* v8 ignore next -- defensive: valid response but missing endpoints field @preserve */
|
|
401
|
-
if (!baseUrl) {
|
|
402
|
-
throw new Error("GitHub Copilot endpoint discovery returned no endpoints.api. Ensure your GitHub account has Copilot access.");
|
|
403
|
-
}
|
|
408
|
+
const baseUrl = await discoverGithubCopilotBaseUrl(token);
|
|
404
409
|
return { githubToken: token, baseUrl };
|
|
405
410
|
}
|
|
406
411
|
if (input.provider === "openai-codex") {
|
|
@@ -591,7 +591,7 @@ async function defaultRunSerpentGuide() {
|
|
|
591
591
|
});
|
|
592
592
|
}
|
|
593
593
|
// Scan environment variables for API keys using the shared helper
|
|
594
|
-
const envCreds = (0, provider_discovery_1.scanEnvVarCredentials)(process.env);
|
|
594
|
+
const envCreds = await (0, provider_discovery_1.completeEnvDiscoveredCredentials)((0, provider_discovery_1.scanEnvVarCredentials)(process.env), (token) => (0, auth_flow_1.discoverGithubCopilotBaseUrl)(token));
|
|
595
595
|
const envDiscovered = [];
|
|
596
596
|
for (const cred of envCreds) {
|
|
597
597
|
// Enrich with default model and first matching env var name (for display)
|
|
@@ -716,13 +716,17 @@ async function defaultRunSerpentGuide() {
|
|
|
716
716
|
});
|
|
717
717
|
// Build specialist tools
|
|
718
718
|
const specialistTools = (0, specialist_tools_1.getSpecialistTools)();
|
|
719
|
+
let lastAdoptionError = null;
|
|
719
720
|
const specialistExecTool = (0, specialist_tools_1.createSpecialistExecTool)({
|
|
720
721
|
tempDir,
|
|
721
722
|
credentials: selectedCredentialPayload,
|
|
722
723
|
provider: providerRaw,
|
|
723
724
|
bundlesRoot,
|
|
724
725
|
animationWriter: (text) => process.stdout.write(text),
|
|
725
|
-
promptSecret:
|
|
726
|
+
promptSecret: async (question) => {
|
|
727
|
+
const { withTerminalHandedOff } = await Promise.resolve().then(() => __importStar(require("../../senses/terminal-handoff")));
|
|
728
|
+
return withTerminalHandedOff(() => defaultPromptSecret(question));
|
|
729
|
+
},
|
|
726
730
|
});
|
|
727
731
|
// Run the serpent guide session via runCliSession
|
|
728
732
|
const result = await runCliSession({
|
|
@@ -730,6 +734,12 @@ async function defaultRunSerpentGuide() {
|
|
|
730
734
|
tools: specialistTools,
|
|
731
735
|
execTool: specialistExecTool,
|
|
732
736
|
exitOnToolCall: "complete_adoption",
|
|
737
|
+
// A failed adoption goes back to the guide, which explains it and can retry.
|
|
738
|
+
exitOnToolResult: (toolResult) => {
|
|
739
|
+
const outcome = (0, specialist_tools_1.parseAdoptionResult)(toolResult);
|
|
740
|
+
lastAdoptionError = outcome.ok ? null : outcome.error;
|
|
741
|
+
return outcome.ok;
|
|
742
|
+
},
|
|
733
743
|
autoFirstTurn: true,
|
|
734
744
|
banner: false,
|
|
735
745
|
disableCommands: true,
|
|
@@ -740,10 +750,13 @@ async function defaultRunSerpentGuide() {
|
|
|
740
750
|
],
|
|
741
751
|
});
|
|
742
752
|
if (result.exitReason === "tool_exit" && result.toolResult) {
|
|
743
|
-
const
|
|
744
|
-
if (
|
|
745
|
-
return
|
|
746
|
-
|
|
753
|
+
const outcome = (0, specialist_tools_1.parseAdoptionResult)(result.toolResult);
|
|
754
|
+
if (outcome.ok)
|
|
755
|
+
return outcome.agentName;
|
|
756
|
+
lastAdoptionError = outcome.error;
|
|
757
|
+
}
|
|
758
|
+
if (lastAdoptionError) {
|
|
759
|
+
process.stdout.write(`\nhatch didn't finish: ${lastAdoptionError}\nfix that, then run \`ouro hatch\` again.\n`);
|
|
747
760
|
}
|
|
748
761
|
return null;
|
|
749
762
|
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.scanEnvVarCredentials = scanEnvVarCredentials;
|
|
11
|
+
exports.completeEnvDiscoveredCredentials = completeEnvDiscoveredCredentials;
|
|
11
12
|
exports.discoverInstalledAgentCredentials = discoverInstalledAgentCredentials;
|
|
12
13
|
exports.describeDiscoveredCredentialSource = describeDiscoveredCredentialSource;
|
|
13
14
|
exports.discoverWorkingProvider = discoverWorkingProvider;
|
|
@@ -40,6 +41,39 @@ function scanEnvVarCredentials(env) {
|
|
|
40
41
|
}
|
|
41
42
|
return results;
|
|
42
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Env-discovered GitHub Copilot credentials carry only a token; the runtime also needs the
|
|
46
|
+
* account's Copilot API endpoint. Fill it in the way `ouro auth` does, and drop the option
|
|
47
|
+
* when discovery fails, because offering it would only fail its ping.
|
|
48
|
+
*/
|
|
49
|
+
async function completeEnvDiscoveredCredentials(credentials, discoverCopilotBaseUrl) {
|
|
50
|
+
const completed = [];
|
|
51
|
+
for (const credential of credentials) {
|
|
52
|
+
const token = credential.credentials.githubToken;
|
|
53
|
+
if (credential.provider !== "github-copilot" || !token || credential.providerConfig.baseUrl) {
|
|
54
|
+
completed.push(credential);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const baseUrl = await discoverCopilotBaseUrl(token);
|
|
59
|
+
completed.push({
|
|
60
|
+
...credential,
|
|
61
|
+
credentials: { ...credential.credentials, baseUrl },
|
|
62
|
+
providerConfig: { ...credential.providerConfig, baseUrl },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
(0, runtime_1.emitNervesEvent)({
|
|
67
|
+
level: "warn",
|
|
68
|
+
component: "daemon",
|
|
69
|
+
event: "daemon.env_copilot_endpoint_discovery_failed",
|
|
70
|
+
message: "skipping env github-copilot credential: endpoint discovery failed",
|
|
71
|
+
meta: { reason: error instanceof Error ? error.message : String(error) },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return completed;
|
|
76
|
+
}
|
|
43
77
|
function stringifyProviderFields(fields) {
|
|
44
78
|
const result = {};
|
|
45
79
|
for (const [key, value] of Object.entries(fields)) {
|
|
@@ -95,6 +95,7 @@ function buildSpecialistSystemPrompt(soulText, identityText, existingBundles, co
|
|
|
95
95
|
"- `complete_adoption`: Finalize the bundle. Validates, asks the harness to collect and confirm the hatchling vault unlock secret through hidden terminal prompts, scaffolds structural dirs, moves to ~/AgentBundles/, writes secrets, plays hatch animation. I call this with `name` (PascalCase) and `handoff_message` (warm message for the human).",
|
|
96
96
|
"- The complete_adoption tool triggers hidden terminal prompts for the hatchling vault unlock secret. I must never ask the human to type the vault unlock secret into chat, and I must never include it in tool arguments.",
|
|
97
97
|
"- `settle`: End the conversation with a final message. I call this after complete_adoption succeeds.",
|
|
98
|
+
"- If complete_adoption returns `error: ...`, the hatch did not finish. I tell the human in plain words what went wrong and what they can do about it, without asking for any secret in chat. The bundle files are back in the temp directory, so once the problem is fixed I can call complete_adoption again.",
|
|
98
99
|
"",
|
|
99
100
|
"I must call `settle` when I am done to end the session cleanly.",
|
|
100
101
|
].join("\n"));
|
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.getSpecialistTools = getSpecialistTools;
|
|
37
|
+
exports.parseAdoptionResult = parseAdoptionResult;
|
|
37
38
|
exports.createSpecialistExecTool = createSpecialistExecTool;
|
|
38
39
|
const fs = __importStar(require("fs"));
|
|
39
40
|
const path = __importStar(require("path"));
|
|
@@ -209,9 +210,9 @@ async function execCompleteAdoption(args, deps) {
|
|
|
209
210
|
await (0, hatch_flow_1.storeHatchlingProviderCredentials)(name, deps.provider, deps.credentials);
|
|
210
211
|
}
|
|
211
212
|
catch (e) {
|
|
212
|
-
// Rollback:
|
|
213
|
+
// Rollback: put the files back in the temp directory so the guide can retry after a fix
|
|
213
214
|
try {
|
|
214
|
-
|
|
215
|
+
moveDir(targetBundle, deps.tempDir);
|
|
215
216
|
}
|
|
216
217
|
catch {
|
|
217
218
|
// Best effort cleanup
|
|
@@ -260,6 +261,42 @@ async function execCompleteAdoption(args, deps) {
|
|
|
260
261
|
});
|
|
261
262
|
return JSON.stringify({ success: true, agentName: name, bundlePath: targetBundle });
|
|
262
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Read a complete_adoption result. Success is JSON; failures are plain `error: ...` text,
|
|
266
|
+
* which must reach the human as a failed adoption rather than a JSON parse crash.
|
|
267
|
+
*/
|
|
268
|
+
function parseAdoptionResult(toolResult) {
|
|
269
|
+
let parsed = toolResult;
|
|
270
|
+
if (typeof toolResult === "string") {
|
|
271
|
+
try {
|
|
272
|
+
parsed = JSON.parse(toolResult);
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
const error = toolResult.trim().replace(/^error:\s*/i, "") || "complete_adoption returned nothing";
|
|
276
|
+
(0, runtime_1.emitNervesEvent)({
|
|
277
|
+
level: "warn",
|
|
278
|
+
component: "daemon",
|
|
279
|
+
event: "daemon.adoption_failed",
|
|
280
|
+
message: "complete_adoption reported a failure",
|
|
281
|
+
meta: { error },
|
|
282
|
+
});
|
|
283
|
+
return { ok: false, error };
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const record = (parsed && typeof parsed === "object" ? parsed : {});
|
|
287
|
+
if (record.success === true && typeof record.agentName === "string" && record.agentName) {
|
|
288
|
+
return { ok: true, agentName: record.agentName };
|
|
289
|
+
}
|
|
290
|
+
const error = typeof record.error === "string" && record.error ? record.error : "complete_adoption did not report success";
|
|
291
|
+
(0, runtime_1.emitNervesEvent)({
|
|
292
|
+
level: "warn",
|
|
293
|
+
component: "daemon",
|
|
294
|
+
event: "daemon.adoption_failed",
|
|
295
|
+
message: "complete_adoption reported a failure",
|
|
296
|
+
meta: { error },
|
|
297
|
+
});
|
|
298
|
+
return { ok: false, error };
|
|
299
|
+
}
|
|
263
300
|
/**
|
|
264
301
|
* Create a specialist tool executor with the given dependencies captured in closure.
|
|
265
302
|
*/
|
|
@@ -6,20 +6,26 @@ exports.importOptional = importOptional;
|
|
|
6
6
|
exports.describeStartupError = describeStartupError;
|
|
7
7
|
const runtime_1 = require("../nerves/runtime");
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* only the
|
|
9
|
+
* Packages listed in package.json optionalDependencies: the product SDKs, the terminal chat UI
|
|
10
|
+
* (ink and react; without them `ouro` chats line by line) and the bundled Bitwarden CLI (vault
|
|
11
|
+
* reads and writes are native; bw is only for vaults the native client does not support, and is
|
|
12
|
+
* then found on PATH or installed). npm installs them by default; a small host can leave them out
|
|
13
|
+
* with `npm install --omit=optional` (about 46 MB instead of 221 MB), and only the feature that
|
|
14
|
+
* needs one stops working.
|
|
12
15
|
*/
|
|
13
16
|
exports.OPTIONAL_PACKAGES = [
|
|
14
17
|
"@azure/identity",
|
|
15
18
|
"@azure/storage-blob",
|
|
19
|
+
"@bitwarden/cli",
|
|
16
20
|
"@microsoft/teams.api",
|
|
17
21
|
"@microsoft/teams.apps",
|
|
18
22
|
"@microsoft/teams.cards",
|
|
19
23
|
"@microsoft/teams.common",
|
|
20
24
|
"@microsoft/teams.dev",
|
|
21
25
|
"@microsoft/teams.graph",
|
|
26
|
+
"ink",
|
|
22
27
|
"mailparser",
|
|
28
|
+
"react",
|
|
23
29
|
"smtp-server",
|
|
24
30
|
"stripe",
|
|
25
31
|
];
|
|
@@ -276,6 +276,8 @@ class NativeVaultReader {
|
|
|
276
276
|
meta: { email: this.email, update: existingId !== undefined },
|
|
277
277
|
});
|
|
278
278
|
const answer = await this.withSession(async (session) => {
|
|
279
|
+
if (!session.userId)
|
|
280
|
+
throw new NativeVaultUnsupportedError("writes with an access token that names no user");
|
|
279
281
|
const itemKeyString = existing ? stringField(existing, "key") : undefined;
|
|
280
282
|
const key = itemKeyString ? decryptKey(itemKeyString, session.userKey, "item key") : session.userKey;
|
|
281
283
|
const login = field(existing, "login");
|
|
@@ -379,8 +381,6 @@ class NativeVaultReader {
|
|
|
379
381
|
const expiresIn = Number(field(token, "expires_in"));
|
|
380
382
|
const userKey = decryptKey(protectedKey, keys.stretched, "user key");
|
|
381
383
|
const userId = tokenUserId(accessToken);
|
|
382
|
-
if (!userId)
|
|
383
|
-
throw new NativeVaultUnsupportedError("an access token without a user id");
|
|
384
384
|
this.session = { accessToken, expiresAt: this.deps.now() + (Number.isFinite(expiresIn) && expiresIn > 0 ? expiresIn : 3600) * 1000, userKey, userId };
|
|
385
385
|
return this.session;
|
|
386
386
|
}
|
|
@@ -597,11 +597,11 @@ function InputArea({ onSubmit, onCtrlC, history, queuedInputs, onPopQueue, agent
|
|
|
597
597
|
})() }) })), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "─".repeat(termWidth()) }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsxs)(ink_1.Text, { dimColor: true, children: [" ", agentName, model ? ` · ${model}` : "", " \u00B7 /help"] }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexGrow: 1 }), tooltip ? (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: tooltip }) : (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "opt+enter for newline" })] })] }));
|
|
598
598
|
}
|
|
599
599
|
// ─── Main TUI Component ─────────────────────────────────────────────
|
|
600
|
-
function OuroTui({ agentName, model, completedMessages, inputHistory, queuedInputs, live, elapsedSeconds, contextPercent, onSubmit, onCtrlC, onPopQueue, cwd, resumeInfo, onImageMap, onHistoryAdd, }) {
|
|
600
|
+
function OuroTui({ agentName, model, completedMessages, inputHistory, queuedInputs, live, elapsedSeconds, contextPercent, onSubmit, onCtrlC, onPopQueue, cwd, resumeInfo, onImageMap, onHistoryAdd, paused, }) {
|
|
601
601
|
return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", children: [(0, jsx_runtime_1.jsx)(ink_1.Static, { items: [{ id: "__header__" }, ...completedMessages], children: (item, index) => {
|
|
602
602
|
if (index === 0) {
|
|
603
603
|
return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", marginBottom: 2, children: [(0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }), (0, jsx_runtime_1.jsx)(Header, { agentName: agentName, model: model, contextPercent: contextPercent, cwd: cwd, resumeInfo: resumeInfo }), (0, jsx_runtime_1.jsx)(ink_1.Text, { color: OURO.shadow, dimColor: true, children: " Ctrl-C twice to exit \u00b7 \u2191\u2193 history \u00b7 Esc clear \u00b7 opt+Enter newline" })] }, "header"));
|
|
604
604
|
}
|
|
605
605
|
return (0, jsx_runtime_1.jsx)(MessageBlock, { msg: item }, item.id);
|
|
606
|
-
} }), (live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }) : null, (0, jsx_runtime_1.jsx)(LiveArea, { live: live, elapsed: elapsedSeconds }), (live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { marginBottom: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }) : null, queuedInputs.length > 0 ? (0, jsx_runtime_1.jsx)(QueuedMessages, { items: queuedInputs }) : null, (0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }), (0, jsx_runtime_1.jsx)(InputArea, { onSubmit: onSubmit, onCtrlC: onCtrlC, history: inputHistory, queuedInputs: queuedInputs, onPopQueue: onPopQueue, agentName: agentName, model: model, onImageMap: onImageMap, onHistoryAdd: onHistoryAdd })] }));
|
|
606
|
+
} }), paused ? null : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }) : null, (0, jsx_runtime_1.jsx)(LiveArea, { live: live, elapsed: elapsedSeconds }), (live.loading || live.streamingText || live.activeTool) ? (0, jsx_runtime_1.jsx)(ink_1.Box, { marginBottom: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }) : null, queuedInputs.length > 0 ? (0, jsx_runtime_1.jsx)(QueuedMessages, { items: queuedInputs }) : null, (0, jsx_runtime_1.jsx)(ink_1.Box, { marginTop: 1, children: (0, jsx_runtime_1.jsx)(ink_1.Text, { children: "" }) }), (0, jsx_runtime_1.jsx)(InputArea, { onSubmit: onSubmit, onCtrlC: onCtrlC, history: inputHistory, queuedInputs: queuedInputs, onPopQueue: onPopQueue, agentName: agentName, model: model, onImageMap: onImageMap, onHistoryAdd: onHistoryAdd })] }))] }));
|
|
607
607
|
}
|
|
@@ -33,11 +33,14 @@ class TuiStore {
|
|
|
33
33
|
_headerShown = false;
|
|
34
34
|
_inputHistory = [];
|
|
35
35
|
_queuedInputs = [];
|
|
36
|
+
_paused = false;
|
|
36
37
|
get completedMessages() { return this._completed; }
|
|
37
38
|
get live() { return this._live; }
|
|
38
39
|
get headerShown() { return this._headerShown; }
|
|
39
40
|
get inputHistory() { return this._inputHistory; }
|
|
40
41
|
get queuedInputs() { return this._queuedInputs; }
|
|
42
|
+
/** True while a hidden terminal prompt has the terminal (no live area, no input box). */
|
|
43
|
+
get paused() { return this._paused; }
|
|
41
44
|
/** Elapsed seconds since spinner started — computed on demand, not stored */
|
|
42
45
|
getElapsed() {
|
|
43
46
|
if (this._live.loading && this._spinnerStart > 0) {
|
|
@@ -128,6 +131,14 @@ class TuiStore {
|
|
|
128
131
|
this._live = { ...this._live, loading: false, kickMessage: (0, format_1.formatKick)() };
|
|
129
132
|
this.notify();
|
|
130
133
|
}
|
|
134
|
+
pause() {
|
|
135
|
+
this._paused = true;
|
|
136
|
+
this.notify();
|
|
137
|
+
}
|
|
138
|
+
resume() {
|
|
139
|
+
this._paused = false;
|
|
140
|
+
this.notify();
|
|
141
|
+
}
|
|
131
142
|
suppressInput() {
|
|
132
143
|
this._live = { ...this._live, inputSuppressed: true };
|
|
133
144
|
this.notify();
|
package/dist/senses/cli.js
CHANGED
|
@@ -46,6 +46,7 @@ exports.addHistory = addHistory;
|
|
|
46
46
|
exports.renderMarkdown = renderMarkdown;
|
|
47
47
|
exports.createCliCallbacks = createCliCallbacks;
|
|
48
48
|
exports.createDebouncedLines = createDebouncedLines;
|
|
49
|
+
exports.createExitOnToolCallExecTool = createExitOnToolCallExecTool;
|
|
49
50
|
exports.runCliSession = runCliSession;
|
|
50
51
|
exports.main = main;
|
|
51
52
|
const readline = __importStar(require("readline"));
|
|
@@ -77,6 +78,7 @@ const cli_layout_1 = require("./cli-layout");
|
|
|
77
78
|
const image_paste_1 = require("./cli/image-paste");
|
|
78
79
|
const spinner_imperative_1 = require("./cli/spinner-imperative");
|
|
79
80
|
const tool_display_1 = require("./cli/tool-display");
|
|
81
|
+
const terminal_handoff_1 = require("./terminal-handoff");
|
|
80
82
|
var cli_layout_2 = require("./cli-layout");
|
|
81
83
|
Object.defineProperty(exports, "formatEchoedInputSummary", { enumerable: true, get: function () { return cli_layout_2.formatEchoedInputSummary; } });
|
|
82
84
|
Object.defineProperty(exports, "wrapCliText", { enumerable: true, get: function () { return cli_layout_2.wrapCliText; } });
|
|
@@ -511,6 +513,25 @@ class InputQueue {
|
|
|
511
513
|
}
|
|
512
514
|
}
|
|
513
515
|
exports.InputQueue = InputQueue;
|
|
516
|
+
/** Wrap execTool so a call to `toolName` ends the session, unless `shouldExit` rejects its result. */
|
|
517
|
+
function createExitOnToolCallExecTool(execTool, toolName, shouldExit, onExit) {
|
|
518
|
+
return async (name, args, ctx) => {
|
|
519
|
+
const result = await execTool(name, args, ctx);
|
|
520
|
+
if (name !== toolName)
|
|
521
|
+
return result;
|
|
522
|
+
if (shouldExit && !shouldExit(result)) {
|
|
523
|
+
(0, runtime_1.emitNervesEvent)({
|
|
524
|
+
component: "senses",
|
|
525
|
+
event: "senses.cli_exit_tool_declined",
|
|
526
|
+
message: "exit tool result did not end the session",
|
|
527
|
+
meta: { tool: name },
|
|
528
|
+
});
|
|
529
|
+
return result;
|
|
530
|
+
}
|
|
531
|
+
onExit(result);
|
|
532
|
+
return result;
|
|
533
|
+
};
|
|
534
|
+
}
|
|
514
535
|
async function runCliSession(options) {
|
|
515
536
|
/* v8 ignore start -- integration: runCliSession is interactive, tested via E2E @preserve */
|
|
516
537
|
const registry = (0, commands_1.createCommandRegistry)();
|
|
@@ -528,6 +549,7 @@ async function runCliSession(options) {
|
|
|
528
549
|
let cliCallbacks;
|
|
529
550
|
let tuiStore = null;
|
|
530
551
|
let inkRef = null;
|
|
552
|
+
let releaseTerminal = null;
|
|
531
553
|
const inputQueue = useTui ? new InputQueue() : null;
|
|
532
554
|
let rl = null;
|
|
533
555
|
if (useTui) {
|
|
@@ -623,6 +645,7 @@ async function runCliSession(options) {
|
|
|
623
645
|
onCtrlC: handleCtrlC,
|
|
624
646
|
onPopQueue: () => { const items = storeRef.popAllQueuedForEditing(); inputQueue.drainAll(); return items; },
|
|
625
647
|
headerShown: storeRef.headerShown,
|
|
648
|
+
paused: storeRef.paused,
|
|
626
649
|
cwd: process.cwd().replace(process.env.HOME ?? "", "~"),
|
|
627
650
|
resumeInfo,
|
|
628
651
|
onImageMap: (images) => { pendingImages = images; },
|
|
@@ -630,6 +653,15 @@ async function runCliSession(options) {
|
|
|
630
653
|
});
|
|
631
654
|
}
|
|
632
655
|
inkRef = ink.render(React.createElement(TuiRoot), { exitOnCtrlC: false, patchConsole: false });
|
|
656
|
+
releaseTerminal = (0, terminal_handoff_1.claimTerminal)({
|
|
657
|
+
suspend: async () => {
|
|
658
|
+
storeRef.pause();
|
|
659
|
+
// Ink throttles repaints to 32 ms and drops its stdin listener in an effect cleanup;
|
|
660
|
+
// let both land before the prompt starts reading keystrokes.
|
|
661
|
+
await new Promise((resolve) => setTimeout(resolve, 80));
|
|
662
|
+
},
|
|
663
|
+
resume: () => storeRef.resume(),
|
|
664
|
+
});
|
|
633
665
|
}
|
|
634
666
|
catch (err) {
|
|
635
667
|
// Ink failed to load (CJS compat, missing deps, etc.) — fall through to imperative
|
|
@@ -702,15 +734,11 @@ async function runCliSession(options) {
|
|
|
702
734
|
let exitToolFired = false;
|
|
703
735
|
const resolvedExecTool = options.execTool;
|
|
704
736
|
const wrappedExecTool = options.exitOnToolCall && resolvedExecTool
|
|
705
|
-
?
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
currentAbort?.abort();
|
|
711
|
-
}
|
|
712
|
-
return result;
|
|
713
|
-
}
|
|
737
|
+
? createExitOnToolCallExecTool(resolvedExecTool, options.exitOnToolCall, options.exitOnToolResult, (result) => {
|
|
738
|
+
exitToolResult = result;
|
|
739
|
+
exitToolFired = true;
|
|
740
|
+
currentAbort?.abort();
|
|
741
|
+
})
|
|
714
742
|
: resolvedExecTool;
|
|
715
743
|
// Resolve toolChoiceRequired: use explicit option if set, else fall back to toggle
|
|
716
744
|
const getEffectiveToolChoiceRequired = () => options.toolChoiceRequired !== undefined ? options.toolChoiceRequired : (0, commands_1.getToolChoiceRequired)();
|
|
@@ -900,6 +928,7 @@ async function runCliSession(options) {
|
|
|
900
928
|
}
|
|
901
929
|
finally {
|
|
902
930
|
rl?.close();
|
|
931
|
+
releaseTerminal?.();
|
|
903
932
|
if (inkRef) {
|
|
904
933
|
// Suppress React "state update on unmounted component" warnings during cleanup.
|
|
905
934
|
// Ink's useInput hook fires after unmount — this is harmless but noisy.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.claimTerminal = claimTerminal;
|
|
4
|
+
exports.withTerminalHandedOff = withTerminalHandedOff;
|
|
5
|
+
/**
|
|
6
|
+
* Lets a hidden terminal prompt (for example the hatchling vault unlock secret) borrow the
|
|
7
|
+
* terminal from a live full-screen session. While the prompt runs, the session's owner stops
|
|
8
|
+
* repainting and stops reading stdin, so the prompt is visible and keystrokes reach only it.
|
|
9
|
+
*/
|
|
10
|
+
const runtime_1 = require("../nerves/runtime");
|
|
11
|
+
let currentOwner = null;
|
|
12
|
+
/** Register the live session that owns the terminal. Returns a release function. */
|
|
13
|
+
function claimTerminal(owner) {
|
|
14
|
+
currentOwner = owner;
|
|
15
|
+
return () => {
|
|
16
|
+
if (currentOwner === owner)
|
|
17
|
+
currentOwner = null;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Run `prompt` with the terminal handed to it, then give the terminal back. */
|
|
21
|
+
async function withTerminalHandedOff(prompt) {
|
|
22
|
+
const owner = currentOwner;
|
|
23
|
+
if (!owner)
|
|
24
|
+
return prompt();
|
|
25
|
+
(0, runtime_1.emitNervesEvent)({
|
|
26
|
+
component: "senses",
|
|
27
|
+
event: "senses.terminal_handed_off",
|
|
28
|
+
message: "live session suspended for a terminal prompt",
|
|
29
|
+
meta: {},
|
|
30
|
+
});
|
|
31
|
+
await owner.suspend();
|
|
32
|
+
try {
|
|
33
|
+
return await prompt();
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
owner.resume();
|
|
37
|
+
(0, runtime_1.emitNervesEvent)({
|
|
38
|
+
component: "senses",
|
|
39
|
+
event: "senses.terminal_taken_back",
|
|
40
|
+
message: "live session resumed after a terminal prompt",
|
|
41
|
+
meta: {},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|