cli-jaw 2.17.75 → 2.17.76
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/src/code-mode/manager.js +51 -7
- package/dist/src/code-mode/manager.js.map +1 -1
- package/dist/src/code-mode/normalize.js +3 -2
- package/dist/src/code-mode/normalize.js.map +1 -1
- package/dist/src/code-mode/session.js +10 -2
- package/dist/src/code-mode/session.js.map +1 -1
- package/dist/src/code-mode/store.js +265 -27
- package/dist/src/code-mode/store.js.map +1 -1
- package/dist/src/code-mode/wire.js +4 -1
- package/dist/src/code-mode/wire.js.map +1 -1
- package/dist/src/routes/code-native.js +56 -5
- package/dist/src/routes/code-native.js.map +1 -1
- package/dist/src/slack/blocks.js +22 -3
- package/dist/src/slack/blocks.js.map +1 -1
- package/dist/src/slack/bot.js +239 -26
- package/dist/src/slack/bot.js.map +1 -1
- package/dist/src/slack/events.js +99 -2
- package/dist/src/slack/events.js.map +1 -1
- package/dist/src/slack/identity.js +30 -0
- package/dist/src/slack/identity.js.map +1 -1
- package/dist/src/slack/ingress.js +5 -4
- package/dist/src/slack/ingress.js.map +1 -1
- package/package.json +1 -1
- package/public/dist/.vite/manifest.json +3 -3
- package/public/dist/assets/CodeCanvas-DLXPccm9.js +3 -0
- package/public/dist/assets/manager-CZcR8tfs.css +1 -0
- package/public/dist/assets/{manager-DIaOU2Vf.js → manager-HCkO4cai.js} +1 -1
- package/public/dist/manager/index.html +2 -2
- package/public/manager/src/code/CodeWorkbench.tsx +48 -4
- package/public/manager/src/code/ComposerFooter.tsx +21 -7
- package/public/manager/src/code/code-composer.css +1 -0
- package/public/manager/src/code/code-controller-draft-storage.ts +45 -6
- package/public/manager/src/code/code-controller-drafts.ts +14 -2
- package/public/manager/src/code/code-controller-runtime.ts +312 -17
- package/public/manager/src/code/code-controller-types.ts +43 -0
- package/public/manager/src/code/code-session-client.ts +22 -3
- package/public/manager/src/code/code-session-state.ts +1 -0
- package/public/manager/src/code/code-ulid.ts +19 -0
- package/public/manager/src/code/code-workbench.css +3 -0
- package/public/dist/assets/CodeCanvas-Ba7ROkA8.js +0 -3
- package/public/dist/assets/manager-DQjyj2aO.css +0 -1
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
<link rel="icon" type="image/png" href="/dist/assets/icon-192-CADbZUeU.png">
|
|
7
7
|
<title>Jaw Manager</title>
|
|
8
8
|
<script src="/manager/theme-boot.js"></script>
|
|
9
|
-
<script type="module" crossorigin src="/dist/assets/manager-
|
|
9
|
+
<script type="module" crossorigin src="/dist/assets/manager-HCkO4cai.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/dist/assets/settings-embedding-CUQ8Is3y.css">
|
|
11
11
|
<link rel="stylesheet" crossorigin href="/dist/assets/vendor-render-DSSkXCir.css">
|
|
12
|
-
<link rel="stylesheet" crossorigin href="/dist/assets/manager-
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/dist/assets/manager-CZcR8tfs.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="manager-root"></div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useRef, useState } from 'react';
|
|
2
|
-
import type { CodeControllerModel } from './code-controller-types';
|
|
2
|
+
import type { CodeControllerModel, CodeSettingsField, CodeSettingsValue } from './code-controller-types';
|
|
3
3
|
import { CodeComposer } from './CodeComposer';
|
|
4
4
|
import { ComposerFooter } from './ComposerFooter';
|
|
5
5
|
import { CodeDraftEmptyState } from './CodeDraftEmptyState';
|
|
@@ -11,6 +11,10 @@ import { CodeWorkspaceHeader } from './CodeWorkspaceHeader';
|
|
|
11
11
|
import { codeCanResume, codeCanRollback, codeCanStop, codeResendCopy, codeRollbackRows } from './code-types';
|
|
12
12
|
|
|
13
13
|
type Props = { controller: CodeControllerModel; endpointKey: string; onOpenLocalFile?: ((path: string) => void) | undefined };
|
|
14
|
+
const settingsLabels: Record<CodeSettingsField, string> = { model: 'Model', effort: 'Effort', permissionMode: 'Permission', thinking: 'Thinking' };
|
|
15
|
+
function settingsValue(value: CodeSettingsValue | undefined): string {
|
|
16
|
+
return value == null ? 'Default' : typeof value === 'boolean' ? (value ? 'On' : 'Off') : value;
|
|
17
|
+
}
|
|
14
18
|
export function CodeWorkbench({ controller: c, endpointKey, onOpenLocalFile }: Props) {
|
|
15
19
|
const sessionKey = `${endpointKey}:${c.selectedId ?? 'new'}`;
|
|
16
20
|
const [actionError, setActionError] = useState<{ key: string; message: string } | null>(null);
|
|
@@ -31,7 +35,7 @@ export function CodeWorkbench({ controller: c, endpointKey, onOpenLocalFile }: P
|
|
|
31
35
|
const provider = c.catalog?.providers.find(p => p.id === c.selection.provider);
|
|
32
36
|
const unknownSend = c.operation.kind === 'unknown-send';
|
|
33
37
|
// A streaming Claude turn takes one follow-up beside Stop; any other busy session offers Stop only.
|
|
34
|
-
const canSend = !c.steering && (c.followUp ? !c.followUpSent && !stopping && !c.pending && !archived && c.operation.kind === 'idle'
|
|
38
|
+
const canSend = c.settings === null && !c.steering && (c.followUp ? !c.followUpSent && !stopping && !c.pending && !archived && c.operation.kind === 'idle'
|
|
35
39
|
: !busy && !c.pending && !c.creationUnknown && !archived && c.operation.kind === 'idle' && !!provider?.available
|
|
36
40
|
&& !!c.selection.cwd.trim() && !!c.selection.model.trim()
|
|
37
41
|
// A suspended or recoverably failed session can be sent to: send attaches it first.
|
|
@@ -50,7 +54,7 @@ export function CodeWorkbench({ controller: c, endpointKey, onOpenLocalFile }: P
|
|
|
50
54
|
void action().catch(err => setActionError({ key: sessionKey, message: err instanceof Error ? err.message : String(err) }));
|
|
51
55
|
}
|
|
52
56
|
async function retry() {
|
|
53
|
-
if (!c.canRetrySameSend || retryGuard.current.has(sessionKey)) return;
|
|
57
|
+
if (c.settings !== null || !c.canRetrySameSend || retryGuard.current.has(sessionKey)) return;
|
|
54
58
|
retryGuard.current.add(sessionKey); setRetrying(sessionKey); setActionError(null);
|
|
55
59
|
try { await c.retrySameSend(); }
|
|
56
60
|
catch (err) { setActionError({ key: sessionKey, message: err instanceof Error ? err.message : String(err) }); }
|
|
@@ -82,7 +86,7 @@ export function CodeWorkbench({ controller: c, endpointKey, onOpenLocalFile }: P
|
|
|
82
86
|
? codeResendCopy(c.resendReason ?? undefined).detail
|
|
83
87
|
: 'Retry uses the original request. It may submit it if the server has not already accepted it.'}</p>
|
|
84
88
|
<pre className="code-retry-preview" aria-label="Original prompt">{c.retryText}</pre>
|
|
85
|
-
<button type="button" disabled={!c.canRetrySameSend || retrying === sessionKey} onClick={() => void retry()}>
|
|
89
|
+
<button type="button" disabled={c.settings !== null || !c.canRetrySameSend || retrying === sessionKey} onClick={() => void retry()}>
|
|
86
90
|
{retrying === sessionKey
|
|
87
91
|
? (c.resendRequired ? 'Sending as a new message…' : 'Retrying original send…')
|
|
88
92
|
: (c.resendRequired ? 'Send as a new message' : 'Retry same send')}</button>
|
|
@@ -110,6 +114,46 @@ export function CodeWorkbench({ controller: c, endpointKey, onOpenLocalFile }: P
|
|
|
110
114
|
onClick={() => c.setInput(failedInput)}>Restore submitted prompt</button>
|
|
111
115
|
<span>Restores text for editing without sending.</span>
|
|
112
116
|
</div>}
|
|
117
|
+
{c.settings && <section className="code-recovery-strip code-settings-strip" aria-label="Settings changes"
|
|
118
|
+
role={c.settings.state === 'unknown' || c.settings.state === 'rejected' || c.settings.state === 'conflict' ? 'alert' : 'status'}>
|
|
119
|
+
{c.settings.state === 'pending' && c.settings.waitingForSession && <p>Settings will apply when the session is confirmed</p>}
|
|
120
|
+
{(c.settings.state === 'sent' || (c.settings.state === 'pending' && !c.settings.waitingForSession && c.settings.busy)) && <p>Applying settings…</p>}
|
|
121
|
+
{/* A pending batch that stopped before sending (no checkpoint, no refresh, or a second
|
|
122
|
+
change elsewhere) waits for the reader; Send stays closed until it is applied or dropped. */}
|
|
123
|
+
{c.settings.state === 'pending' && !c.settings.waitingForSession && !c.settings.busy && <>
|
|
124
|
+
<p>These settings are not applied yet. Your messages wait until they are.</p>
|
|
125
|
+
<button type="button" onClick={() => perform(c.reapplySettings)}>Apply settings</button>
|
|
126
|
+
<button type="button" onClick={() => perform(c.discardSettings)}>Discard</button>
|
|
127
|
+
</>}
|
|
128
|
+
{c.settings.state === 'unknown' && <>
|
|
129
|
+
<p>The settings change may or may not have applied. It will never be resent automatically.</p>
|
|
130
|
+
{c.settings.expired && <p>The recorded outcome has expired.</p>}
|
|
131
|
+
<button type="button" disabled={c.settings.busy} onClick={() => perform(c.checkSettings)}>Check again</button>
|
|
132
|
+
<button type="button" disabled={c.settings.busy} onClick={() => perform(c.reapplySettings)}>Re-apply</button>
|
|
133
|
+
<button type="button" disabled={c.settings.busy} onClick={() => perform(c.discardSettings)}>Discard</button>
|
|
134
|
+
</>}
|
|
135
|
+
{c.settings.state === 'rejected' && <>
|
|
136
|
+
<p>{c.settings.error ?? 'The settings change was rejected.'}</p>
|
|
137
|
+
<button type="button" disabled={c.settings.busy} onClick={() => perform(c.reapplySettings)}>Re-apply</button>
|
|
138
|
+
<button type="button" disabled={c.settings.busy} onClick={() => perform(c.discardSettings)}>Discard</button>
|
|
139
|
+
</>}
|
|
140
|
+
{c.settings.state === 'conflict' && <>
|
|
141
|
+
<strong>Settings conflict</strong>
|
|
142
|
+
{c.settings.fields.filter(field => field.theirs !== undefined).map(field => <div className="code-settings-conflict" key={field.field}>
|
|
143
|
+
<p>{settingsLabels[field.field]}: yours {settingsValue(field.value)}, now {settingsValue(field.theirs)}</p>
|
|
144
|
+
<div role="group" aria-label={`${settingsLabels[field.field]} conflict`}>
|
|
145
|
+
<button type="button" disabled={c.settings!.busy} aria-pressed={field.resolution === 'mine'}
|
|
146
|
+
onClick={() => c.resolveSettingsConflict(field.field, 'mine')}>Keep mine</button>
|
|
147
|
+
<button type="button" disabled={c.settings!.busy} aria-pressed={field.resolution === 'theirs'}
|
|
148
|
+
onClick={() => c.resolveSettingsConflict(field.field, 'theirs')}>Take theirs</button>
|
|
149
|
+
</div>
|
|
150
|
+
</div>)}
|
|
151
|
+
<button type="button" disabled={c.settings.busy || c.settings.fields.some(field => field.theirs !== undefined && !field.resolution)}
|
|
152
|
+
onClick={() => perform(c.applyResolvedSettings)}>Apply</button>
|
|
153
|
+
<button type="button" disabled={c.settings.busy} onClick={() => perform(c.discardSettings)}>Discard</button>
|
|
154
|
+
</>}
|
|
155
|
+
{c.settings.error && c.settings.state !== 'rejected' && <p>{c.settings.error}</p>}
|
|
156
|
+
</section>}
|
|
113
157
|
<div className="code-composer-surface" aria-label="Code composer controls">
|
|
114
158
|
<CodeComposer key={`composer:${sessionKey}`} inputText={c.input} canSend={canSend} busy={busy} canStop={canStop} stopping={stopping}
|
|
115
159
|
pending={c.pending} followUp={c.followUp} followUpSent={c.followUpSent} steering={c.steering} readOnly={archived} autoFocus={c.selectedId === null} onInputChange={c.setInput} onSubmit={c.send} onStop={c.stop}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useId, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
|
-
import type { CodeControllerModel } from './code-controller-types';
|
|
3
|
+
import type { CodeControllerModel, CodeSettingsField } from './code-controller-types';
|
|
4
4
|
import type { CodeCreateSessionRequest } from '../../../../src/code-mode/wire';
|
|
5
5
|
import { CODE_POLICY_DETAILS, CODE_POLICY_LABELS, CODE_RUNTIME_LABELS } from './code-types';
|
|
6
6
|
import type { CodeNotice } from './code-toasts';
|
|
@@ -20,10 +20,10 @@ type MenuOption<T extends string> = {
|
|
|
20
20
|
* because a live Codex catalog can carry 28+ routed ids.
|
|
21
21
|
*/
|
|
22
22
|
export function CodeFooterMenu<T extends string>({ label, value, options, disabled, onChange, displayValue,
|
|
23
|
-
triggerContent, filterable, filterPlaceholder, className, title }: {
|
|
23
|
+
triggerContent, filterable, filterPlaceholder, className, title, marker }: {
|
|
24
24
|
label: string; value: T; options: MenuOption<T>[]; disabled: boolean; onChange(value: T): void;
|
|
25
25
|
displayValue?: string; triggerContent?: ReactNode; filterable?: boolean; filterPlaceholder?: string;
|
|
26
|
-
className?: string; title?: string;
|
|
26
|
+
className?: string; title?: string; marker?: 'Pending' | 'Not confirmed' | 'Conflict' | undefined;
|
|
27
27
|
}) {
|
|
28
28
|
const id = useId();
|
|
29
29
|
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
@@ -85,14 +85,15 @@ export function CodeFooterMenu<T extends string>({ label, value, options, disabl
|
|
|
85
85
|
event.preventDefault(); buttons[index]?.focus();
|
|
86
86
|
}
|
|
87
87
|
const shown = selected?.label ?? displayValue ?? (value || 'not selected');
|
|
88
|
-
const name = `${label}: ${shown}`;
|
|
88
|
+
const name = `${label}: ${shown}${marker ? `, ${marker}` : ''}`;
|
|
89
89
|
return <div className={`code-footer-menu${className ? ` ${className}` : ''}`}>
|
|
90
|
-
<button ref={triggerRef} type="button" className={`code-footer-menu-trigger${triggerContent ? ' is-icon' : ''}`}
|
|
90
|
+
<button ref={triggerRef} type="button" className={`code-footer-menu-trigger${triggerContent ? ' is-icon' : ''}${marker ? ` is-${marker === 'Not confirmed' ? 'unknown' : marker.toLowerCase()}` : ''}`}
|
|
91
91
|
aria-label={name} aria-haspopup="listbox" aria-expanded={Boolean(position)} aria-controls={position ? id : undefined}
|
|
92
92
|
disabled={disabled} title={title ?? selected?.detail ?? name} onClick={() => position ? close() : open()}
|
|
93
93
|
onKeyDown={event => { if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { event.preventDefault(); open(); } }}>
|
|
94
94
|
{triggerContent ?? <><span className="code-footer-label">{label}</span>
|
|
95
95
|
<strong>{selected?.label ?? displayValue ?? (value || 'Not selected')}</strong></>}
|
|
96
|
+
{marker && <span className="code-footer-pending-badge">{marker}</span>}
|
|
96
97
|
</button>
|
|
97
98
|
{position && createPortal(<div ref={menu} id={id} role="listbox" aria-label={label} className="code-footer-dropup code-footer-floating"
|
|
98
99
|
style={position} onKeyDown={navigate}>
|
|
@@ -125,7 +126,16 @@ export function ComposerFooter({ controller: c, onNotice }: {
|
|
|
125
126
|
// than the snapshot a session was created with; other runtimes keep their snapshot.
|
|
126
127
|
const permissionModes = (selection.provider === 'claude' ? provider?.capabilities : capabilities)?.permissionModes ?? [];
|
|
127
128
|
const locked = c.selectedId !== null;
|
|
128
|
-
const
|
|
129
|
+
const creationEditable = c.creationPending && (c.settings === null || c.settings.state === 'pending');
|
|
130
|
+
const disabled = (!creationEditable && (c.pending || c.busy || c.creationUnknown || c.operation.kind !== 'idle'
|
|
131
|
+
|| (locked && (!c.synced || c.session?.status !== 'idle' || c.session?.archivedAt !== null))))
|
|
132
|
+
|| (c.settings !== null && (!creationEditable || c.settings.busy));
|
|
133
|
+
function marker(field: CodeSettingsField) {
|
|
134
|
+
if (!c.settings?.fields.some(entry => entry.field === field)) return undefined;
|
|
135
|
+
if (c.settings.state === 'conflict') return 'Conflict' as const;
|
|
136
|
+
if (c.settings.state === 'unknown' || c.settings.state === 'rejected') return 'Not confirmed' as const;
|
|
137
|
+
return 'Pending' as const;
|
|
138
|
+
}
|
|
129
139
|
const [saving, setSaving] = useState(false);
|
|
130
140
|
const [error, setError] = useState<string | null>(null);
|
|
131
141
|
const guard = useRef(false);
|
|
@@ -171,7 +181,7 @@ export function ComposerFooter({ controller: c, onNotice }: {
|
|
|
171
181
|
return <>
|
|
172
182
|
<div className="code-composer-footer">
|
|
173
183
|
<CodeFooterMenu label="Runtime" value={selection.provider} className="code-footer-runtime"
|
|
174
|
-
disabled={locked ? !c.catalog : controlsDisabled || !c.catalog}
|
|
184
|
+
disabled={c.creationPending || (locked ? !c.catalog : controlsDisabled || !c.catalog)}
|
|
175
185
|
triggerContent={<ProviderGlyph provider={selection.provider} />}
|
|
176
186
|
title={CODE_RUNTIME_LABELS[selection.provider]}
|
|
177
187
|
options={(Object.keys(CODE_RUNTIME_LABELS) as Array<keyof typeof CODE_RUNTIME_LABELS>).map(id => {
|
|
@@ -185,21 +195,25 @@ export function ComposerFooter({ controller: c, onNotice }: {
|
|
|
185
195
|
else void change({ provider: value });
|
|
186
196
|
}} />
|
|
187
197
|
<CodeFooterMenu label="Permission" value={selection.permissionMode} displayValue={CODE_POLICY_LABELS[selection.permissionMode]}
|
|
198
|
+
marker={marker('permissionMode')}
|
|
188
199
|
disabled={controlsDisabled || !capabilities?.permissions}
|
|
189
200
|
options={permissionModes.map(value => ({ value, label: CODE_POLICY_LABELS[value], detail: CODE_POLICY_DETAILS[value] }))}
|
|
190
201
|
onChange={value => void change({ permissionMode: value })} />
|
|
191
202
|
<span className="code-composer-footer-spacer" aria-hidden="true" />
|
|
192
203
|
<ContextUsageMeter usage={c.session?.contextUsage} />
|
|
193
204
|
<CodeFooterMenu label="Model" value={selection.model} className="code-footer-model"
|
|
205
|
+
marker={marker('model')}
|
|
194
206
|
disabled={controlsDisabled || models.length === 0} filterable filterPlaceholder="Filter models…"
|
|
195
207
|
displayValue={selection.model || 'Select model'}
|
|
196
208
|
options={models.map(value => ({ value, label: value }))}
|
|
197
209
|
onChange={value => void change({ model: value })} />
|
|
198
210
|
{modelEfforts.length > 0 && <CodeFooterMenu label="Effort" value={selection.effort ?? ''}
|
|
211
|
+
marker={marker('effort')}
|
|
199
212
|
className="code-footer-effort" displayValue={selection.effort ?? 'Default'}
|
|
200
213
|
options={[{ value: '', label: 'Native default' }, ...modelEfforts.map(value => ({ value, label: value }))]}
|
|
201
214
|
disabled={controlsDisabled} onChange={value => void change({ effort: value || null })} />}
|
|
202
215
|
{selection.provider === 'claude' && <CodeFooterMenu label="Thinking" value={selection.thinking === false ? 'off' : 'on'}
|
|
216
|
+
marker={marker('thinking')}
|
|
203
217
|
className="code-footer-thinking"
|
|
204
218
|
options={[{ value: 'on', label: 'Thinking on', detail: 'Adaptive thinking with summaries' },
|
|
205
219
|
{ value: 'off', label: 'Thinking off', detail: 'Answer without extended thinking' }]}
|
|
@@ -151,6 +151,7 @@
|
|
|
151
151
|
}
|
|
152
152
|
.code-footer-menu-trigger:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
|
|
153
153
|
.code-footer-menu-trigger:disabled { cursor: not-allowed; opacity: 0.5; }
|
|
154
|
+
.code-footer-pending-badge { font-size: 10px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
|
|
154
155
|
.code-footer-menu-trigger strong {
|
|
155
156
|
min-width: 0;
|
|
156
157
|
overflow: hidden;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CodeCreateSessionRequest } from '../../../../src/code-mode/wire';
|
|
2
|
-
import type { CodeDraft, CodeDraftBook } from './code-controller-drafts';
|
|
2
|
+
import type { CodeDraft, CodeDraftBook, CodePendingSettings } from './code-controller-drafts';
|
|
3
3
|
import type { CodeResendReason } from './code-types';
|
|
4
4
|
|
|
5
5
|
const STORAGE_KEY = 'cli-jaw:code-drafts:v1';
|
|
@@ -22,6 +22,7 @@ export interface StoredCodeDraft {
|
|
|
22
22
|
selectionEdit: number;
|
|
23
23
|
creating: boolean;
|
|
24
24
|
creationKey?: string;
|
|
25
|
+
settings?: Omit<CodePendingSettings, 'op'> | null;
|
|
25
26
|
retry: { text: string; key: string; edit: number; resend?: boolean; resendReason?: CodeResendReason } | null;
|
|
26
27
|
stop: { turnId: string | null; operationId?: string; epoch: number } | null;
|
|
27
28
|
}
|
|
@@ -35,10 +36,42 @@ type StoredEnvelope = { version: number; endpoints: StoredCodeEndpoint[] };
|
|
|
35
36
|
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
36
37
|
const text = (value: unknown, limit: number): value is string => typeof value === 'string' && value.length <= limit;
|
|
37
38
|
const count = (value: unknown): value is number => typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
39
|
+
const mutationId = (value: unknown): boolean => value === null || (typeof value === 'string' && /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(value));
|
|
40
|
+
function parseSettings(value: unknown): Omit<CodePendingSettings, 'op'> | null | undefined {
|
|
41
|
+
if (value === undefined || value === null) return null;
|
|
42
|
+
if (!object(value) || !Array.isArray(value['fields']) || !value['fields'].length || value['fields'].length > 4
|
|
43
|
+
|| !['pending', 'sent', 'unknown', 'conflict', 'rejected'].includes(String(value['state']))
|
|
44
|
+
|| !mutationId(value['mutationId']) || !mutationId(value['watermark'])
|
|
45
|
+
|| !(value['expectedRevision'] === null || count(value['expectedRevision']))
|
|
46
|
+
|| typeof value['expired'] !== 'boolean' || typeof value['autoRetried'] !== 'boolean'
|
|
47
|
+
|| !(value['retryReady'] === undefined || typeof value['retryReady'] === 'boolean')
|
|
48
|
+
|| !(value['error'] === null || text(value['error'], 4096))) return undefined;
|
|
49
|
+
const fields: CodePendingSettings['fields'] = [];
|
|
50
|
+
for (const field of value['fields']) {
|
|
51
|
+
if (!object(field) || !['model', 'effort', 'permissionMode', 'thinking'].includes(String(field['field']))
|
|
52
|
+
|| fields.some(row => row.field === field['field'])) return undefined;
|
|
53
|
+
const valid = (item: unknown) => field['field'] === 'thinking' ? item === null || typeof item === 'boolean'
|
|
54
|
+
: item === null || text(item, field['field'] === 'model' ? 1024 : 80);
|
|
55
|
+
if (!valid(field['baseline']) || !valid(field['value'])) return undefined;
|
|
56
|
+
const conflict = field['conflict'];
|
|
57
|
+
if (conflict !== undefined && (!object(conflict) || !valid(conflict['theirs'])
|
|
58
|
+
|| !(conflict['resolution'] === undefined || conflict['resolution'] === 'mine' || conflict['resolution'] === 'theirs'))) return undefined;
|
|
59
|
+
fields.push({ field: field['field'] as CodePendingSettings['fields'][number]['field'], baseline: field['baseline'] as string | boolean | null,
|
|
60
|
+
value: field['value'] as string | boolean | null,
|
|
61
|
+
...(conflict === undefined ? {} : { conflict: { theirs: (conflict as Record<string, unknown>)['theirs'] as string | boolean | null,
|
|
62
|
+
...((conflict as Record<string, unknown>)['resolution'] ? { resolution: (conflict as Record<string, unknown>)['resolution'] as 'mine' | 'theirs' } : {}) } }) });
|
|
63
|
+
}
|
|
64
|
+
if (value['state'] !== 'pending' && value['mutationId'] === null && value['state'] !== 'conflict') return undefined;
|
|
65
|
+
return { fields, state: value['state'] as CodePendingSettings['state'], mutationId: value['mutationId'] as string | null,
|
|
66
|
+
expectedRevision: value['expectedRevision'] as number | null, watermark: value['watermark'] as string | null,
|
|
67
|
+
expired: value['expired'], autoRetried: value['autoRetried'], retryReady: value['retryReady'] === true, error: value['error'] as string | null };
|
|
68
|
+
}
|
|
38
69
|
|
|
39
70
|
function parseDraft(value: unknown): StoredCodeDraft | null {
|
|
40
71
|
if (!object(value) || !text(value['input'], MAX_TEXT_CHARS) || !count(value['edit'])
|
|
41
72
|
|| !count(value['selectionEdit']) || typeof value['creating'] !== 'boolean') return null;
|
|
73
|
+
const settings = parseSettings(value['settings']);
|
|
74
|
+
if (settings === undefined) return null;
|
|
42
75
|
const selection = value['selection'];
|
|
43
76
|
if (!object(selection) || !['codex-app', 'claude', 'cursor', 'grok'].includes(String(selection['provider']))
|
|
44
77
|
|| !text(selection['cwd'], 4096) || !text(selection['model'], 1024)
|
|
@@ -52,6 +85,7 @@ function parseDraft(value: unknown): StoredCodeDraft | null {
|
|
|
52
85
|
|| !text(retry['key'], 240) || !retry['key'] || !count(retry['edit']) || retry['edit'] > value['edit'])) return null;
|
|
53
86
|
if (stop !== null && (!object(stop) || !count(stop['epoch']) || !((text(stop['turnId'], 240) && !!stop['turnId'] && stop['operationId'] === undefined) || (stop['turnId'] === null && text(stop['operationId'], 240) && !!stop['operationId'])))) return null;
|
|
54
87
|
return {
|
|
88
|
+
settings,
|
|
55
89
|
...(typeof creationKey === 'string' ? { creationKey } : {}),
|
|
56
90
|
input: value['input'], edit: value['edit'], selectionEdit: value['selectionEdit'], creating: value['creating'],
|
|
57
91
|
selection: { provider: selection['provider'] as DraftSelection['provider'], cwd: selection['cwd'], model: selection['model'], effort: selection['effort'], permissionMode: selection['permissionMode'] as DraftSelection['permissionMode'],
|
|
@@ -131,6 +165,9 @@ function pack(draft: CodeDraft): StoredCodeDraft | null {
|
|
|
131
165
|
...(thinking === undefined ? {} : { thinking }) }, selectionEdit: draft.selectionEdit,
|
|
132
166
|
creating: draft.createUnknown || draft.operation.kind === 'creating',
|
|
133
167
|
...(draft.creationKey ? { creationKey: draft.creationKey } : {}),
|
|
168
|
+
settings: draft.settings ? { fields: draft.settings.fields, state: draft.settings.state, mutationId: draft.settings.mutationId,
|
|
169
|
+
expectedRevision: draft.settings.expectedRevision, watermark: draft.settings.watermark, expired: draft.settings.expired,
|
|
170
|
+
autoRetried: draft.settings.autoRetried, retryReady: draft.settings.retryReady, error: draft.settings.error } : null,
|
|
134
171
|
retry: draft.retry ? { text: draft.retry.text, key: draft.retry.key, edit: draft.retry.edit,
|
|
135
172
|
...(draft.retry.resend ? { resend: true } : {}),
|
|
136
173
|
...(draft.retry.resend && draft.retry.resendReason ? { resendReason: draft.retry.resendReason } : {}) } : null,
|
|
@@ -142,14 +179,14 @@ export function saveCodeDraftStorage(storage: Storage, endpoint: string, book: C
|
|
|
142
179
|
if (!fresh) { markIncomplete(storage, endpoint, true); return LIMIT_WARNING; }
|
|
143
180
|
const entry: StoredCodeEndpoint = { endpoint, selectedId: null, fresh, sessions: [] };
|
|
144
181
|
let limited = false;
|
|
145
|
-
const rows = [...book.sessions].sort(([a], [b]) => Number(b === book.selectedId) - Number(a === book.selectedId));
|
|
182
|
+
const rows = [...book.sessions].sort(([a, ad], [b, bd]) => Number(b === book.selectedId) - Number(a === book.selectedId) || Number(!!bd.settings) - Number(!!ad.settings));
|
|
146
183
|
for (const [id, draft] of rows) {
|
|
147
|
-
if (id !== book.selectedId && !draft.input && !draft.retry && !draft.stopTarget) continue;
|
|
184
|
+
if (id !== book.selectedId && !draft.input && !draft.retry && !draft.stopTarget && !draft.settings) continue;
|
|
148
185
|
const packed = pack(draft);
|
|
149
186
|
if (!packed) { markIncomplete(storage, endpoint, true); return LIMIT_WARNING; }
|
|
150
|
-
if (entry.sessions.length >= MAX_SESSIONS) { limited = true; continue; }
|
|
187
|
+
if (entry.sessions.length >= MAX_SESSIONS) { if (draft.settings) { markIncomplete(storage, endpoint, true); return LIMIT_WARNING; } limited = true; continue; }
|
|
151
188
|
const candidate = { ...entry, selectedId: id === book.selectedId ? id : entry.selectedId, sessions: [...entry.sessions, { id, draft: packed }] };
|
|
152
|
-
if (JSON.stringify(candidate).length > MAX_ENDPOINT_CHARS) { limited = true; continue; }
|
|
189
|
+
if (JSON.stringify(candidate).length > MAX_ENDPOINT_CHARS) { if (draft.settings) { markIncomplete(storage, endpoint, true); return LIMIT_WARNING; } limited = true; continue; }
|
|
153
190
|
entry.sessions = candidate.sessions; entry.selectedId = candidate.selectedId;
|
|
154
191
|
}
|
|
155
192
|
// Do not replace an older checkpoint with a partial version of the selected draft.
|
|
@@ -160,7 +197,9 @@ export function saveCodeDraftStorage(storage: Storage, endpoint: string, book: C
|
|
|
160
197
|
const endpoints = [...envelope.endpoints.filter(row => row.endpoint !== endpoint), entry];
|
|
161
198
|
let serialized = JSON.stringify({ version: VERSION, endpoints });
|
|
162
199
|
while (endpoints.length > MAX_ENDPOINTS || serialized.length > MAX_STORAGE_CHARS) {
|
|
163
|
-
const
|
|
200
|
+
const removable = endpoints.findIndex(row => row.endpoint !== endpoint && !row.fresh.settings && !row.sessions.some(session => session.draft.settings));
|
|
201
|
+
if (removable < 0) { markIncomplete(storage, endpoint, true); return LIMIT_WARNING; }
|
|
202
|
+
const [removed] = endpoints.splice(removable, 1);
|
|
164
203
|
if (removed) markIncomplete(storage, removed.endpoint, true);
|
|
165
204
|
serialized = JSON.stringify({ version: VERSION, endpoints });
|
|
166
205
|
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { CodeCreateSessionRequest, CodeModelCatalog, CodeSessionInfo } from '../../../../src/code-mode/wire';
|
|
2
|
-
import type { CodeControllerModel } from './code-controller-types';
|
|
2
|
+
import type { CodeControllerModel, CodeSettingsField, CodeSettingsState, CodeSettingsValue } from './code-controller-types';
|
|
3
3
|
import { browserCodeDraftStorage, loadCodeDraftStorage, saveCodeDraftStorage, type StoredCodeDraft } from './code-controller-draft-storage';
|
|
4
4
|
import { codeResendCopy, type CodeResendReason } from './code-types';
|
|
5
5
|
|
|
6
|
+
export interface CodePendingSettings {
|
|
7
|
+
fields: Array<{ field: CodeSettingsField; baseline: CodeSettingsValue; value: CodeSettingsValue; conflict?: { theirs: CodeSettingsValue; resolution?: 'mine' | 'theirs' } }>;
|
|
8
|
+
state: CodeSettingsState; mutationId: string | null; expectedRevision: number | null; watermark: string | null;
|
|
9
|
+
/**
|
|
10
|
+
* `autoRetried`: the one automatic retry has been dispatched. `retryReady`: a rebased automatic
|
|
11
|
+
* retry waits to be sent (so a reload resumes it as that retry). Both persist with the batch.
|
|
12
|
+
*/
|
|
13
|
+
expired: boolean; autoRetried: boolean; retryReady: boolean; error: string | null;
|
|
14
|
+
op: { token: number; kind: 'send' | 'lookup' | 'fence' | 'check' } | null;
|
|
15
|
+
}
|
|
6
16
|
export interface CodeDraft {
|
|
17
|
+
settings: CodePendingSettings | null;
|
|
7
18
|
input: string;
|
|
8
19
|
edit: number;
|
|
9
20
|
selection: CodeCreateSessionRequest;
|
|
@@ -62,7 +73,7 @@ export interface CodeDraftBook {
|
|
|
62
73
|
const memoryBooks = new Map<string, CodeDraftBook>();
|
|
63
74
|
const tabBooks = new WeakMap<Storage, Map<string, CodeDraftBook>>();
|
|
64
75
|
export function createCodeDraft(selection: CodeCreateSessionRequest): CodeDraft {
|
|
65
|
-
return { input: '', edit: 0, selection: { ...selection }, selectionEdit: 0,
|
|
76
|
+
return { input: '', edit: 0, selection: { ...selection }, selectionEdit: 0, settings: null,
|
|
66
77
|
operation: { kind: 'idle', error: null }, retry: null, createUnknown: false, creationKey: null, attachToken: 0, requiredSequence: 0,
|
|
67
78
|
restore: null, stopTarget: null, permissionOperations: {}, awaitingTurn: null, steer: null };
|
|
68
79
|
}
|
|
@@ -72,6 +83,7 @@ function restoreDraft(saved: StoredCodeDraft): CodeDraft {
|
|
|
72
83
|
draft.createUnknown = saved.creating;
|
|
73
84
|
draft.creationKey = saved.creationKey ?? null;
|
|
74
85
|
draft.retry = saved.retry;
|
|
86
|
+
draft.settings = saved.settings ? { ...saved.settings, state: saved.settings.state === 'sent' ? 'unknown' : saved.settings.state, op: null } : null;
|
|
75
87
|
if (saved.creating) draft.operation = { kind: 'creating', error: 'Creation was interrupted by reload. The original session may exist; no request has been retried.' };
|
|
76
88
|
if (saved.retry) draft.operation = { kind: 'unknown-send', error: saved.retry.resend
|
|
77
89
|
? codeResendCopy(saved.retry.resendReason).error
|