@kabmo-labs/kabmo 0.10.1 → 0.11.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/dist/client/index.html +1 -1
- package/dist/client/index.js +306 -306
- package/dist/client/static/js/index-bq6qeayr.css +1 -0
- package/dist/client/static/js/{index-135sdc46.js → index-nqvfpgm2.js} +649 -648
- package/package.json +1 -1
- package/src/client/components/common/code-surface/theme.ts +11 -5
- package/src/client/components/workspace/chat-timeline/chat-input/access-levels.ts +11 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/ApprovalBody.tsx +65 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Header.tsx +21 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/SelectBody.tsx +35 -19
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +145 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +32 -104
- package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/shortcuts.tsx +166 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +30 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +33 -27
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +51 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +6 -0
- package/src/client/components/workspace/diff-panel/folding.test.ts +252 -0
- package/src/client/components/workspace/diff-panel/folding.ts +134 -0
- package/src/client/components/workspace/diff-panel/merge.ts +5 -0
- package/src/client/components/workspace/git-panel/InitRepository.tsx +49 -0
- package/src/client/components/workspace/git-panel/commit-modal.test.ts +193 -0
- package/src/client/components/workspace/git-panel/index.test.ts +3 -125
- package/src/client/components/workspace/git-panel/index.tsx +7 -1
- package/src/client/components/workspace/git-panel/init-state.test.ts +145 -0
- package/src/client/data/samples/virtual-devices-session.ts +8 -2
- package/src/client/data/settings/omp-schema.json +25 -3
- package/src/client/hooks/chat/timeline/ask-frames.test.ts +33 -0
- package/src/client/hooks/chat/timeline/ask-frames.ts +9 -1
- package/src/server/lib/fs/git-actions-worktree.ts +25 -2
- package/src/server/lib/fs/git-actions.ts +3 -3
- package/src/server/lib/fs/git-status-read.test.ts +20 -0
- package/src/server/lib/fs/git-status-read.ts +43 -2
- package/src/server/lib/omp/session/messages.test.ts +21 -0
- package/src/server/routes/fs/git-action.test.ts +4 -0
- package/src/server/routes/fs/git-init-action.test.ts +125 -0
- package/src/shared/lib/chat/notice-row.test.ts +25 -0
- package/src/shared/lib/chat/notice-row.ts +22 -1
- package/src/shared/lib/chat/omp/approval-gate.test.ts +99 -0
- package/src/shared/lib/chat/omp/approval-gate.ts +129 -0
- package/src/shared/lib/omp/config/schema.test.ts +12 -0
- package/src/shared/lib/omp/session/job-progress.test.ts +76 -0
- package/src/shared/lib/omp/session/job-progress.ts +84 -0
- package/src/shared/lib/omp/session/mapper.ts +3 -6
- package/src/shared/lib/omp/session/messages-map.test.ts +15 -6
- package/src/shared/lib/omp/session/messages-map.ts +19 -1
- package/src/shared/lib/omp/session/proc.test.ts +23 -0
- package/src/shared/lib/omp/session/proc.ts +17 -0
- package/src/shared/lib/omp/session/wait.test.ts +22 -0
- package/src/shared/lib/omp/session/wait.ts +14 -0
- package/src/test-support/file-explorer.test-util.ts +1 -1
- package/dist/client/static/js/index-snd9wk6w.css +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kabmo-labs/kabmo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Web console and diagnostic workbench for AI coding agents — Elysia + Preact on Bun.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Wijanarko Putra Rajeb <wijanarko.rajeb@gmail.com>",
|
|
@@ -81,6 +81,12 @@ export function surfaceTheme(): Extension {
|
|
|
81
81
|
// The fold gutter, beside the line numbers. Its marker is a text glyph
|
|
82
82
|
// (`⌄` / `›`) inside a span, so the box needs a fixed width or the gutter
|
|
83
83
|
// shifts sideways as a block opens and closes.
|
|
84
|
+
//
|
|
85
|
+
// The colour reads `--editor-fg` FIRST: an explicit editor theme paints a
|
|
86
|
+
// surface of its own (`Dracula` over a light app palette), and the app's ink
|
|
87
|
+
// at 45% over that background is a glyph the reader cannot see — measured on
|
|
88
|
+
// the diff panel, which is the one Reader that can wear a dark editor theme
|
|
89
|
+
// inside a light console.
|
|
84
90
|
'.cm-foldGutter .cm-gutterElement': {
|
|
85
91
|
padding: '0 4px 0 2px',
|
|
86
92
|
minWidth: '1.1rem',
|
|
@@ -90,9 +96,9 @@ export function surfaceTheme(): Extension {
|
|
|
90
96
|
display: 'inline-block',
|
|
91
97
|
width: '100%',
|
|
92
98
|
cursor: 'pointer',
|
|
93
|
-
color: 'color-mix(in srgb, var(--theme-ink) 45%, transparent)',
|
|
99
|
+
color: 'color-mix(in srgb, var(--editor-fg, var(--theme-ink)) 45%, transparent)',
|
|
94
100
|
},
|
|
95
|
-
'.cm-foldGutter .cm-gutterElement span:hover': { color: 'var(--theme-ink)' },
|
|
101
|
+
'.cm-foldGutter .cm-gutterElement span:hover': { color: 'var(--editor-fg, var(--theme-ink))' },
|
|
96
102
|
// A folded range's own `…`. Two facts about this rule are load-bearing.
|
|
97
103
|
//
|
|
98
104
|
// 1. The declarations are LONGHAND. `border: 1px solid var(--x)` is a
|
|
@@ -105,11 +111,11 @@ export function surfaceTheme(): Extension {
|
|
|
105
111
|
// CM6 mounts our theme after the base one. Verified: our rule is emitted
|
|
106
112
|
// last and wins.
|
|
107
113
|
'.cm-foldPlaceholder': {
|
|
108
|
-
backgroundColor: 'color-mix(in srgb, var(--theme-ink) 7%, var(--theme-canvas))',
|
|
114
|
+
backgroundColor: 'color-mix(in srgb, var(--editor-fg, var(--theme-ink)) 7%, var(--editor-bg, var(--theme-canvas)))',
|
|
109
115
|
borderWidth: '1px',
|
|
110
116
|
borderStyle: 'solid',
|
|
111
|
-
borderColor: 'color-mix(in srgb, var(--theme-ink) 18%, transparent)',
|
|
112
|
-
color: 'color-mix(in srgb, var(--theme-ink) 55%, transparent)',
|
|
117
|
+
borderColor: 'color-mix(in srgb, var(--editor-fg, var(--theme-ink)) 18%, transparent)',
|
|
118
|
+
color: 'color-mix(in srgb, var(--editor-fg, var(--theme-ink)) 55%, transparent)',
|
|
113
119
|
borderRadius: '0.2em',
|
|
114
120
|
margin: '0 1px',
|
|
115
121
|
padding: '0 4px',
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Composer labels for omp's tool-approval modes (see ApprovalMode).
|
|
5
|
+
*
|
|
6
|
+
* The `yolo` copy is deliberately not "Everything runs without asking": omp
|
|
7
|
+
* 18.13.1 added `tools.restrictedFolders`, and a folder on that list asks in
|
|
8
|
+
* EVERY approval mode — `yolo` included — with no remembered grant and no
|
|
9
|
+
* session approval covering it. A mode picker that promised an unconditional
|
|
10
|
+
* bypass would be lying about the mode it names, and the user would meet the
|
|
11
|
+
* gate with no expectation of one.
|
|
12
|
+
*/
|
|
4
13
|
export const ACCESS_LEVEL_LABELS: Record<ApprovalMode, string> = {
|
|
5
14
|
'always-ask': 'Always ask',
|
|
6
15
|
write: 'Minimal',
|
|
@@ -10,5 +19,5 @@ export const ACCESS_LEVEL_LABELS: Record<ApprovalMode, string> = {
|
|
|
10
19
|
export const ACCESS_LEVEL_DESCRIPTIONS: Record<ApprovalMode, string> = {
|
|
11
20
|
'always-ask': 'Read-only tools run automatically; writes and shell commands ask first.',
|
|
12
21
|
write: 'Reads and edits run automatically; shell commands ask first.',
|
|
13
|
-
yolo: 'Everything runs without asking.',
|
|
22
|
+
yolo: 'Everything runs without asking — except a restricted folder, which always asks.',
|
|
14
23
|
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The body of omp's TOOL-APPROVAL gate: what is being approved, and why.
|
|
8
|
+
*
|
|
9
|
+
* Over RPC the gate is a `select` frame whose TITLE is omp's whole approval
|
|
10
|
+
* prompt, newline-separated (see `parseApprovalPrompt`). A title is a
|
|
11
|
+
* single-line field, and the dialog's header renders it with `truncate` — so
|
|
12
|
+
* the reason and the path were clipped out of the one element that could
|
|
13
|
+
* show them, and the gate read "Allow tool: read" over a command the user
|
|
14
|
+
* never saw. "Approve" without the thing being approved is not a decision.
|
|
15
|
+
*
|
|
16
|
+
* This body shows the prompt's parts, each in full:
|
|
17
|
+
*
|
|
18
|
+
* - the TOOL, as the header's own subject line;
|
|
19
|
+
* - the REASON omp wrote ("Restricted folder: /tmp/secrets" — omp's
|
|
20
|
+
* `tools.restrictedFolders` gate writes exactly that line);
|
|
21
|
+
* - the tool's own DETAIL rows (the path, the command), verbatim.
|
|
22
|
+
*
|
|
23
|
+
* A frame that is not an approval gate renders nothing here: the dialog's
|
|
24
|
+
* other bodies (a `confirm` banner, an extension's own message) own their
|
|
25
|
+
* own copy.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { AlertTriangle } from 'lucide-preact';
|
|
29
|
+
import { isApprovalGateFrame, parseApprovalPrompt } from '@/shared/lib/chat/omp/approval-gate';
|
|
30
|
+
|
|
31
|
+
interface ApprovalBodyProps {
|
|
32
|
+
/** The frame's title — omp's whole approval prompt. */
|
|
33
|
+
title?: string | null;
|
|
34
|
+
/** The frame's choices — a gate's are "Approve" / "Deny". */
|
|
35
|
+
options?: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function ApprovalBody({ title, options }: ApprovalBodyProps) {
|
|
39
|
+
const prompt = isApprovalGateFrame({ title, options }) ? parseApprovalPrompt(title) : null;
|
|
40
|
+
if (!prompt) return null;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="space-y-2">
|
|
44
|
+
{prompt.reason && (
|
|
45
|
+
<div className="flex items-start gap-2 rounded-xl border border-warning/25 bg-warning/8 px-3.5 py-2.5 text-[12px] leading-relaxed text-ink/80">
|
|
46
|
+
<AlertTriangle size={13} className="mt-0.5 shrink-0 text-warning" />
|
|
47
|
+
<span className="min-w-0 break-words">{prompt.reason}</span>
|
|
48
|
+
</div>
|
|
49
|
+
)}
|
|
50
|
+
|
|
51
|
+
{prompt.details.length > 0 && (
|
|
52
|
+
<div className="rounded-xl border border-ink/10 bg-canvas/40 px-3.5 py-2.5">
|
|
53
|
+
{prompt.details.map((detail, index) => (
|
|
54
|
+
<div
|
|
55
|
+
key={`${index}-${detail}`}
|
|
56
|
+
className="font-mono text-[11.5px] leading-relaxed text-ink/75 break-all"
|
|
57
|
+
>
|
|
58
|
+
{detail}
|
|
59
|
+
</div>
|
|
60
|
+
))}
|
|
61
|
+
</div>
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Header.tsx
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from 'preact/compat';
|
|
2
2
|
import { Sparkles, X } from 'lucide-preact';
|
|
3
|
+
import { isApprovalGateFrame, parseApprovalPrompt } from '@/shared/lib/chat/omp/approval-gate';
|
|
3
4
|
|
|
4
5
|
interface ExtensionDialogHeaderProps {
|
|
5
6
|
title?: string;
|
|
7
|
+
/** The frame's choices — a gate's are "Approve" / "Deny". */
|
|
8
|
+
options?: readonly string[];
|
|
6
9
|
methodLabel: string;
|
|
7
10
|
badge: string;
|
|
8
11
|
icon: ReactNode;
|
|
@@ -11,11 +14,27 @@ interface ExtensionDialogHeaderProps {
|
|
|
11
14
|
|
|
12
15
|
export function ExtensionDialogHeader({
|
|
13
16
|
title,
|
|
17
|
+
options,
|
|
14
18
|
methodLabel,
|
|
15
19
|
badge,
|
|
16
20
|
icon,
|
|
17
21
|
onCancel,
|
|
18
22
|
}: ExtensionDialogHeaderProps) {
|
|
23
|
+
// An approval gate's title is omp's WHOLE prompt, newline-separated
|
|
24
|
+
// ("Allow tool: read\nReason: …\nPath: …"). The header is one truncated
|
|
25
|
+
// line, so the raw title showed only "Allow tool: read" and clipped the
|
|
26
|
+
// rest away — and the body below then repeated it. The header names the
|
|
27
|
+
// TOOL, and the body carries the reason and the details.
|
|
28
|
+
//
|
|
29
|
+
// The gate is decided by the title AND the choice labels (see
|
|
30
|
+
// `isApprovalGateFrame`): a model-authored question can carry the same
|
|
31
|
+
// title, and that one is still a question.
|
|
32
|
+
const approval = isApprovalGateFrame({ title, options }) ? parseApprovalPrompt(title) : null;
|
|
33
|
+
const heading = approval ? `Allow ${approval.tool}` : title || methodLabel;
|
|
34
|
+
const subtitle = approval
|
|
35
|
+
? 'The agent wants to run this. Review it before you allow.'
|
|
36
|
+
: 'Autonomous agent inquiry requiring user confirmation';
|
|
37
|
+
|
|
19
38
|
return (
|
|
20
39
|
<div className="flex items-center justify-between border-b border-ink/8 bg-canvas/40 px-5 py-3.5">
|
|
21
40
|
<div className="flex items-center gap-3 min-w-0">
|
|
@@ -25,7 +44,7 @@ export function ExtensionDialogHeader({
|
|
|
25
44
|
<div className="min-w-0">
|
|
26
45
|
<div className="flex items-center gap-2">
|
|
27
46
|
<h3 className="truncate text-[14px] font-semibold tracking-tight text-ink">
|
|
28
|
-
{
|
|
47
|
+
{heading}
|
|
29
48
|
</h3>
|
|
30
49
|
<span className="flex items-center gap-1 rounded-full border border-ink/10 bg-paper px-2 py-0.5 font-mono text-[9px] font-medium tracking-wider text-ink/60 uppercase">
|
|
31
50
|
<Sparkles size={9} className="text-ink/40" />
|
|
@@ -33,7 +52,7 @@ export function ExtensionDialogHeader({
|
|
|
33
52
|
</span>
|
|
34
53
|
</div>
|
|
35
54
|
<p className="mt-0.5 text-[11px] text-ink/50">
|
|
36
|
-
|
|
55
|
+
{subtitle}
|
|
37
56
|
</p>
|
|
38
57
|
</div>
|
|
39
58
|
</div>
|
package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/SelectBody.tsx
CHANGED
|
@@ -10,6 +10,18 @@ interface ExtensionDialogSelectBodyProps {
|
|
|
10
10
|
customInputRef: RefObject<HTMLInputElement>;
|
|
11
11
|
onSelect: (option: string) => void;
|
|
12
12
|
onConfirmOption: (option: string) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Hide the free-text "Other" field.
|
|
15
|
+
*
|
|
16
|
+
* The field exists for an `ask` question, whose option list ends in
|
|
17
|
+
* "Other (type your own)" — a prompt to type an answer. omp's APPROVAL
|
|
18
|
+
* gate offers no such option: its choices are "Approve" and "Deny", and
|
|
19
|
+
* omp's own answer parser (`approvalAnswerForChoice`) treats ANY other
|
|
20
|
+
* string as a DENY. So a free-text field on a gate is a way to deny the
|
|
21
|
+
* call by typing near-miss text ("ok", "sure", "yep") and never to approve
|
|
22
|
+
* it — measured: "Approve" → allow, "yes please" → deny.
|
|
23
|
+
*/
|
|
24
|
+
hideCustomAnswer?: boolean;
|
|
13
25
|
}
|
|
14
26
|
|
|
15
27
|
export function ExtensionDialogSelectBody({
|
|
@@ -21,6 +33,7 @@ export function ExtensionDialogSelectBody({
|
|
|
21
33
|
customInputRef,
|
|
22
34
|
onSelect,
|
|
23
35
|
onConfirmOption,
|
|
36
|
+
hideCustomAnswer = false,
|
|
24
37
|
}: ExtensionDialogSelectBodyProps) {
|
|
25
38
|
return (
|
|
26
39
|
<div className="space-y-2">
|
|
@@ -86,25 +99,28 @@ export function ExtensionDialogSelectBody({
|
|
|
86
99
|
</div>
|
|
87
100
|
|
|
88
101
|
{/* Free-text answer for "Other"-style options: typing here wins over the
|
|
89
|
-
highlighted option, since the literal option text is not an answer.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
e.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
highlighted option, since the literal option text is not an answer.
|
|
103
|
+
An approval gate has no "Other" option, so it draws no field. */}
|
|
104
|
+
{!hideCustomAnswer && (
|
|
105
|
+
<div className="space-y-1.5 pt-1">
|
|
106
|
+
<div className="text-[11px] font-medium tracking-wider text-ink/50 uppercase">Other — type your own answer</div>
|
|
107
|
+
<input
|
|
108
|
+
ref={customInputRef}
|
|
109
|
+
type="text"
|
|
110
|
+
value={customValue}
|
|
111
|
+
placeholder="Type a custom answer and press Enter..."
|
|
112
|
+
onChange={(e) => onCustomChange(e.currentTarget.value)}
|
|
113
|
+
onKeyDown={(e) => {
|
|
114
|
+
if (e.key === 'Enter') {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
e.stopPropagation();
|
|
117
|
+
if (customValue.trim()) onConfirmOption(customValue.trim());
|
|
118
|
+
}
|
|
119
|
+
}}
|
|
120
|
+
className="w-full rounded-xl border border-ink/15 bg-paper px-4 py-3 text-[13.5px] text-ink placeholder:text-ink/35 outline-none transition-all focus:border-ink focus:ring-2 focus:ring-ink/15"
|
|
121
|
+
/>
|
|
122
|
+
</div>
|
|
123
|
+
)}
|
|
108
124
|
</div>
|
|
109
125
|
);
|
|
110
126
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What omp's TOOL-APPROVAL gate looks like on screen.
|
|
8
|
+
*
|
|
9
|
+
* The gate is a `select` frame whose title is omp's whole prompt,
|
|
10
|
+
* newline-separated. Two things about that shape are load-bearing and each
|
|
11
|
+
* was measured against omp 18.13.1:
|
|
12
|
+
*
|
|
13
|
+
* - The title is a ONE-LINE field, and the header rendered it with
|
|
14
|
+
* `truncate`, so the reason and the path were clipped out of the only
|
|
15
|
+
* element that could show them. The gate read "Allow tool: read" over a
|
|
16
|
+
* command the user never saw — and "Approve" without the thing being
|
|
17
|
+
* approved is not a decision.
|
|
18
|
+
* - omp's answer parser reads any answer that is not one of its choice
|
|
19
|
+
* labels as a DENY (measured: "Approve" allows, "yes please" denies), so
|
|
20
|
+
* the free-text "Other" field the `ask` question needs is, on a gate, a
|
|
21
|
+
* way to refuse the call by typing near-miss text.
|
|
22
|
+
*
|
|
23
|
+
* The frames below are omp's own, verbatim.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
27
|
+
import { Window } from 'happy-dom';
|
|
28
|
+
import { h, render } from 'preact';
|
|
29
|
+
import { act } from 'preact/test-utils';
|
|
30
|
+
import { ExtensionDialog } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog';
|
|
31
|
+
import type { ExtensionUiDialogRequest } from '@/shared/types/omp/agent';
|
|
32
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
33
|
+
|
|
34
|
+
/** omp's gate for a restricted-folder read. */
|
|
35
|
+
const RESTRICTED_READ: ExtensionUiDialogRequest = {
|
|
36
|
+
type: 'extension_ui_request',
|
|
37
|
+
id: 'g1',
|
|
38
|
+
method: 'select',
|
|
39
|
+
title: [
|
|
40
|
+
'Allow tool: read',
|
|
41
|
+
'Reason: Restricted folder: /tmp/livetest/secret',
|
|
42
|
+
'Path: /tmp/livetest/secret/creds.txt',
|
|
43
|
+
].join('\n'),
|
|
44
|
+
options: ['Approve', 'Deny'],
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** omp's gate for a bash call under `always-ask`. */
|
|
48
|
+
const BASH_GATE: ExtensionUiDialogRequest = {
|
|
49
|
+
type: 'extension_ui_request',
|
|
50
|
+
id: 'g2',
|
|
51
|
+
method: 'select',
|
|
52
|
+
title: ['Allow tool: bash', 'Command: ls -la /tmp/livetest'].join('\n'),
|
|
53
|
+
options: ['Approve', 'Deny'],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** An `ask` question's own dialog — the shape the free-text field serves. */
|
|
57
|
+
const QUESTION: ExtensionUiDialogRequest = {
|
|
58
|
+
type: 'extension_ui_request',
|
|
59
|
+
id: 'q1',
|
|
60
|
+
method: 'select',
|
|
61
|
+
title: 'Which language?',
|
|
62
|
+
options: ['Python', 'Other (type your own)'],
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let container: HTMLElement;
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
installDomGlobals(new Window());
|
|
69
|
+
container = document.createElement('div');
|
|
70
|
+
document.body.appendChild(container);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterEach(() => {
|
|
74
|
+
render(null, container);
|
|
75
|
+
container.remove();
|
|
76
|
+
restoreDomGlobals();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
afterAll(() => restoreDomGlobals());
|
|
80
|
+
|
|
81
|
+
/** Mount the dialog and return the text it draws. */
|
|
82
|
+
function draw(request: ExtensionUiDialogRequest): string {
|
|
83
|
+
render(h(ExtensionDialog, { request, onRespond: () => {} }), container);
|
|
84
|
+
return container.textContent ?? '';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe('omp\'s tool-approval gate', () => {
|
|
88
|
+
test('the reason and the path it approves are both on screen', () => {
|
|
89
|
+
const text = draw(RESTRICTED_READ);
|
|
90
|
+
|
|
91
|
+
expect(text).toContain('Restricted folder: /tmp/livetest/secret');
|
|
92
|
+
expect(text).toContain('/tmp/livetest/secret/creds.txt');
|
|
93
|
+
// The header names the TOOL, not the whole prompt.
|
|
94
|
+
expect(text).toContain('Allow read');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('the command it approves is on screen', () => {
|
|
98
|
+
const text = draw(BASH_GATE);
|
|
99
|
+
expect(text).toContain('ls -la /tmp/livetest');
|
|
100
|
+
expect(text).toContain('Allow bash');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('the free-text field is not offered on a gate', () => {
|
|
104
|
+
// omp reads any non-label answer as a DENY, so a free-text field here can
|
|
105
|
+
// only refuse the call.
|
|
106
|
+
const text = draw(RESTRICTED_READ);
|
|
107
|
+
expect(text).not.toContain('type your own answer');
|
|
108
|
+
expect(container.querySelector('input[type="text"]')).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('an ask question still offers its free-text field', () => {
|
|
112
|
+
// The gate's rule must not take the question's field away: a question's
|
|
113
|
+
// option list ends in "Other (type your own)" and needs the escape hatch.
|
|
114
|
+
const text = draw(QUESTION);
|
|
115
|
+
expect(text).toContain('type your own answer');
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('the gate\'s answer', () => {
|
|
120
|
+
test('a typed answer cannot answer a gate — it is always a deny', async () => {
|
|
121
|
+
const sent: unknown[] = [];
|
|
122
|
+
await act(async () => {
|
|
123
|
+
render(
|
|
124
|
+
h(ExtensionDialog, {
|
|
125
|
+
request: RESTRICTED_READ,
|
|
126
|
+
onRespond: (_request, response) => sent.push(response),
|
|
127
|
+
}),
|
|
128
|
+
container,
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// omp reads any non-label answer as a deny, so the dialog must not even
|
|
133
|
+
// offer a free-text field on a gate.
|
|
134
|
+
expect(container.querySelector('input[type="text"]')).toBeNull();
|
|
135
|
+
|
|
136
|
+
// The chosen option is what answers, verbatim — a label omp recognises.
|
|
137
|
+
const submit = [...container.querySelectorAll('button')]
|
|
138
|
+
.find((button) => button.textContent?.includes('Select Option'));
|
|
139
|
+
expect(submit).toBeDefined();
|
|
140
|
+
await act(async () => {
|
|
141
|
+
submit!.click();
|
|
142
|
+
});
|
|
143
|
+
expect(sent).toEqual([{ value: 'Approve' }]);
|
|
144
|
+
});
|
|
145
|
+
});
|
package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
3
|
-
import {
|
|
3
|
+
import { CheckCircle2 } from 'lucide-preact';
|
|
4
4
|
import type { ExtensionUiDialogRequest } from '@/client/hooks/chat/omp';
|
|
5
5
|
import { ExtensionDialogHeader } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Header';
|
|
6
6
|
import { ExtensionDialogSelectBody } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/SelectBody';
|
|
7
7
|
import { ExtensionDialogFooter } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Footer';
|
|
8
|
+
import { ApprovalBody } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/ApprovalBody';
|
|
9
|
+
import { dialogMethodMeta, useDialogShortcuts } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/shortcuts';
|
|
10
|
+
import { isApprovalGateFrame } from '@/shared/lib/chat/omp/approval-gate';
|
|
8
11
|
import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
|
|
9
12
|
|
|
10
13
|
export type ExtensionDialogResponse =
|
|
@@ -36,6 +39,11 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
|
|
|
36
39
|
|
|
37
40
|
const options = request.options ?? [];
|
|
38
41
|
const optionDetails = request.optionDetails ?? [];
|
|
42
|
+
// An approval gate is a `select` frame whose title is omp's approval prompt
|
|
43
|
+
// (see `isApprovalGateFrame`). It has no "Other" option, and omp's own
|
|
44
|
+
// answer parser treats any free-text answer as a DENY — so the free-text
|
|
45
|
+
// field is hidden for it rather than offered as a way to deny by typo.
|
|
46
|
+
const isApprovalGate = isApprovalGateFrame(request);
|
|
39
47
|
|
|
40
48
|
// Reset for a NEW dialog only. `request` is the identity to depend on —
|
|
41
49
|
// `options`/`optionDetails` above are derived arrays, re-created on every
|
|
@@ -78,7 +86,12 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
|
|
|
78
86
|
} else if (request.method === 'select') {
|
|
79
87
|
// A typed custom answer is the actual response — the "Other" option
|
|
80
88
|
// label itself is not. It wins over the highlighted option.
|
|
81
|
-
|
|
89
|
+
//
|
|
90
|
+
// An APPROVAL gate is the exception: omp's answer parser reads any
|
|
91
|
+
// string that is not one of its choice labels as a DENY (measured:
|
|
92
|
+
// "Approve" allows, "yes please" denies), so a custom answer there can
|
|
93
|
+
// only ever refuse. The gate answers with its chosen label.
|
|
94
|
+
if (customValue.trim() && !isApprovalGate) {
|
|
82
95
|
onRespond(request, { value: customValue.trim() });
|
|
83
96
|
} else if (selectedOption) {
|
|
84
97
|
onRespond(request, { value: selectedOption });
|
|
@@ -86,7 +99,7 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
|
|
|
86
99
|
} else {
|
|
87
100
|
onRespond(request, { value });
|
|
88
101
|
}
|
|
89
|
-
}, [onRespond, request, selectedOption, value, customValue]);
|
|
102
|
+
}, [onRespond, request, selectedOption, value, customValue, isApprovalGate]);
|
|
90
103
|
|
|
91
104
|
const handleConfirmOption = useCallback(
|
|
92
105
|
(option: string) => {
|
|
@@ -114,108 +127,18 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
|
|
|
114
127
|
[]
|
|
115
128
|
);
|
|
116
129
|
|
|
117
|
-
// Keyboard navigation & shortcuts
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (request.method === 'select' && options.length > 0) {
|
|
128
|
-
// Typing in the custom "Other" input must not trigger number/arrow/Enter
|
|
129
|
-
// shortcuts — those keys belong to the text field while focused.
|
|
130
|
-
const typingCustom = e.target instanceof HTMLInputElement && e.target === customInputRef.current;
|
|
131
|
-
if (typingCustom) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
130
|
+
// Keyboard navigation & shortcuts.
|
|
131
|
+
useDialogShortcuts({
|
|
132
|
+
method: request.method,
|
|
133
|
+
options,
|
|
134
|
+
selectedOption,
|
|
135
|
+
onSelectOption: setSelectedOption,
|
|
136
|
+
customInputRef,
|
|
137
|
+
onSubmit: submitValue,
|
|
138
|
+
onCancel: cancel,
|
|
139
|
+
});
|
|
134
140
|
|
|
135
|
-
|
|
136
|
-
if (!isNaN(num) && num >= 1 && num <= options.length) {
|
|
137
|
-
e.preventDefault();
|
|
138
|
-
setSelectedOption(options[num - 1]);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (e.key === 'ArrowDown') {
|
|
143
|
-
e.preventDefault();
|
|
144
|
-
const currentIdx = options.findIndex((o) => o === selectedOption);
|
|
145
|
-
const nextIdx = currentIdx < options.length - 1 ? currentIdx + 1 : 0;
|
|
146
|
-
setSelectedOption(options[nextIdx]);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (e.key === 'ArrowUp') {
|
|
150
|
-
e.preventDefault();
|
|
151
|
-
const currentIdx = options.findIndex((o) => o === selectedOption);
|
|
152
|
-
const prevIdx = currentIdx > 0 ? currentIdx - 1 : options.length - 1;
|
|
153
|
-
setSelectedOption(options[prevIdx]);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (e.key === 'Enter' && selectedOption) {
|
|
158
|
-
e.preventDefault();
|
|
159
|
-
submitValue();
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (request.method === 'confirm') {
|
|
165
|
-
if (e.key === 'Enter') {
|
|
166
|
-
e.preventDefault();
|
|
167
|
-
submitValue();
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (request.method === 'editor') {
|
|
173
|
-
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
|
|
174
|
-
e.preventDefault();
|
|
175
|
-
submitValue();
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
window.addEventListener('keydown', handleKeyDown);
|
|
182
|
-
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
183
|
-
}, [cancel, submitValue, request.method, options, selectedOption]);
|
|
184
|
-
|
|
185
|
-
const methodMeta = (() => {
|
|
186
|
-
switch (request.method) {
|
|
187
|
-
case 'select':
|
|
188
|
-
return {
|
|
189
|
-
icon: <ListFilter size={16} className="text-ink" />,
|
|
190
|
-
label: 'Decision Required',
|
|
191
|
-
badge: `${options.length} Choices`,
|
|
192
|
-
};
|
|
193
|
-
case 'confirm':
|
|
194
|
-
return {
|
|
195
|
-
icon: <AlertCircle size={16} className="text-ink" />,
|
|
196
|
-
label: 'Confirmation Required',
|
|
197
|
-
badge: 'Confirm Action',
|
|
198
|
-
};
|
|
199
|
-
case 'input':
|
|
200
|
-
return {
|
|
201
|
-
icon: <Terminal size={16} className="text-ink" />,
|
|
202
|
-
label: 'Prompt Input',
|
|
203
|
-
badge: 'Text Input',
|
|
204
|
-
};
|
|
205
|
-
case 'editor':
|
|
206
|
-
return {
|
|
207
|
-
icon: <FileText size={16} className="text-ink" />,
|
|
208
|
-
label: 'Buffer Editor',
|
|
209
|
-
badge: 'Multiline Buffer',
|
|
210
|
-
};
|
|
211
|
-
default:
|
|
212
|
-
return {
|
|
213
|
-
icon: <HelpCircle size={16} className="text-ink" />,
|
|
214
|
-
label: 'Agent Request',
|
|
215
|
-
badge: 'Input',
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
})();
|
|
141
|
+
const methodMeta = dialogMethodMeta(request.method, options.length);
|
|
219
142
|
|
|
220
143
|
return (
|
|
221
144
|
<div
|
|
@@ -241,6 +164,7 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
|
|
|
241
164
|
>
|
|
242
165
|
<ExtensionDialogHeader
|
|
243
166
|
title={request.title}
|
|
167
|
+
options={options}
|
|
244
168
|
methodLabel={methodMeta.label}
|
|
245
169
|
badge={methodMeta.badge}
|
|
246
170
|
icon={methodMeta.icon}
|
|
@@ -248,6 +172,9 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
|
|
|
248
172
|
/>
|
|
249
173
|
|
|
250
174
|
<div className="max-h-[65vh] overflow-y-auto px-6 py-5 space-y-4">
|
|
175
|
+
{/* The approval gate: what is being approved, and why. */}
|
|
176
|
+
<ApprovalBody title={request.title} options={options} />
|
|
177
|
+
|
|
251
178
|
{/* Prompt / Context Message with Markdown */}
|
|
252
179
|
{request.message && (
|
|
253
180
|
<div className="rounded-xl border border-ink/8 bg-canvas/40 p-4 text-[13px] leading-relaxed text-ink/85 select-text">
|
|
@@ -266,6 +193,7 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
|
|
|
266
193
|
customInputRef={customInputRef}
|
|
267
194
|
onSelect={handleSelectOption}
|
|
268
195
|
onConfirmOption={handleConfirmOption}
|
|
196
|
+
hideCustomAnswer={isApprovalGate}
|
|
269
197
|
/>
|
|
270
198
|
)}
|
|
271
199
|
|