@antst/dashi 0.1.0-alpha.14 → 0.1.0-alpha.16
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/lib/input.d.ts +7 -0
- package/lib/input.js +40 -0
- package/lib/renderer.js +1 -0
- package/lib/rewind.d.ts +6 -0
- package/lib/rewind.js +4 -0
- package/lib/session-runtime.js +4 -5
- package/lib/state.d.ts +3 -0
- package/lib/state.js +1 -0
- package/package.json +1 -1
package/lib/input.d.ts
CHANGED
|
@@ -3,8 +3,15 @@ import { type ComposerCursor, type UiAction, type ViewState } from './state.js';
|
|
|
3
3
|
export interface InputBindings {
|
|
4
4
|
readonly dispatch: (action: UiAction) => void;
|
|
5
5
|
readonly insertNewline?: () => void;
|
|
6
|
+
readonly insertText?: (text: string) => void;
|
|
6
7
|
readonly readComposerCursor?: () => ComposerCursor;
|
|
7
8
|
readonly readState: () => ViewState;
|
|
8
9
|
}
|
|
10
|
+
export declare function droppedPaths(data: string, cwd: string, inspect?: (path: string) => {
|
|
11
|
+
isDirectory(): boolean;
|
|
12
|
+
}): {
|
|
13
|
+
readonly images: readonly string[];
|
|
14
|
+
readonly text: string;
|
|
15
|
+
} | undefined;
|
|
9
16
|
export declare function caretOffset(text: string, cursor: ComposerCursor): number;
|
|
10
17
|
export declare function installInput(tui: TUI, bindings: InputBindings): () => void;
|
package/lib/input.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { formatFileMention } from '@deepseek-ai/dsh-file-reference/grammar';
|
|
1
4
|
import { isKeyRelease, matchesKey } from '@earendil-works/pi-tui';
|
|
5
|
+
import { isImagePath } from './image-input.js';
|
|
2
6
|
import { PAGE_CELLS } from './state.js';
|
|
7
|
+
export function droppedPaths(data, cwd, inspect = statSync) {
|
|
8
|
+
const [start, end] = ['\u001B[200~', '\u001B[201~'];
|
|
9
|
+
if (!data.startsWith(start) || !data.endsWith(end))
|
|
10
|
+
return undefined;
|
|
11
|
+
const token = /(?:[^\s'\\]+|'[^']*'|\\[\s\S])+/gu;
|
|
12
|
+
const source = data.slice(start.length, -end.length);
|
|
13
|
+
const chunks = source.match(token) ?? [];
|
|
14
|
+
if (chunks.length === 0 || source.replace(token, '').trim() !== '')
|
|
15
|
+
return undefined;
|
|
16
|
+
const paths = chunks.map(chunk => chunk.replace(/'([^']*)'|\\([\s\S])/gu, (_match, quoted, escaped) => quoted ?? escaped ?? ''));
|
|
17
|
+
try {
|
|
18
|
+
const entries = paths.map(value => {
|
|
19
|
+
const absolute = resolve(cwd, value);
|
|
20
|
+
const directory = inspect(absolute).isDirectory();
|
|
21
|
+
if (!directory && isImagePath(absolute))
|
|
22
|
+
return { absolute };
|
|
23
|
+
const local = relative(resolve(cwd), absolute);
|
|
24
|
+
const mention = formatFileMention({ kind: directory ? 'directory' : 'file', path: local !== '' && !isAbsolute(local) && local !== '..' && !local.startsWith(`..${sep}`) ? local : absolute }, false);
|
|
25
|
+
if (mention === undefined)
|
|
26
|
+
throw new Error('path cannot be mentioned');
|
|
27
|
+
return { absolute, mention };
|
|
28
|
+
});
|
|
29
|
+
const mentions = entries.flatMap(entry => entry.mention === undefined ? [] : [entry.mention]);
|
|
30
|
+
return { images: entries.flatMap(entry => entry.mention === undefined ? [entry.absolute] : []), text: mentions.length === 0 ? '' : `${mentions.join(' ')} ` };
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
3
36
|
export function caretOffset(text, cursor) {
|
|
4
37
|
const lines = text.split('\n');
|
|
5
38
|
let offset = 0;
|
|
@@ -16,6 +49,13 @@ export function installInput(tui, bindings) {
|
|
|
16
49
|
const customQuestion = question !== undefined && decision?.kind === 'question'
|
|
17
50
|
&& decision.cursor === question.options.length;
|
|
18
51
|
const completion = state.overlay?.kind === 'list' && state.overlay.purpose === 'completion';
|
|
52
|
+
const dropped = decision === undefined && state.overlay === undefined && state.search === undefined && droppedPaths(data, state.root?.cwd ?? state.cwd);
|
|
53
|
+
if (dropped) {
|
|
54
|
+
bindings.insertText?.(dropped.text);
|
|
55
|
+
for (const path of dropped.images)
|
|
56
|
+
bindings.dispatch({ type: 'attachment-path', path });
|
|
57
|
+
return { consume: true };
|
|
58
|
+
}
|
|
19
59
|
return customQuestion || state.search !== undefined || completion
|
|
20
60
|
|| decision === undefined && state.overlay === undefined ? undefined : { consume: true };
|
|
21
61
|
}
|
package/lib/renderer.js
CHANGED
|
@@ -461,6 +461,7 @@ export function createRenderer(options) {
|
|
|
461
461
|
: action);
|
|
462
462
|
},
|
|
463
463
|
insertNewline: () => { editor.insertTextAtCursor('\n'); },
|
|
464
|
+
insertText: text => { editor.insertTextAtCursor(text); },
|
|
464
465
|
readComposerCursor: () => editor.getCursor(),
|
|
465
466
|
});
|
|
466
467
|
return {
|
package/lib/rewind.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ModelSelection } from '@deepseek-ai/dsh-api-session-controller';
|
|
1
2
|
import type { SessionEvent } from '@deepseek-ai/dsh-session';
|
|
2
3
|
import type { Overlay, OverlayValue } from './state.js';
|
|
3
4
|
export interface RewindBoundary {
|
|
@@ -5,6 +6,11 @@ export interface RewindBoundary {
|
|
|
5
6
|
readonly label: string;
|
|
6
7
|
readonly prompt: string;
|
|
7
8
|
}
|
|
9
|
+
/** Return only a selection that DSH recorded for the source session. */
|
|
10
|
+
export declare function rewindModelSelection(projection: {
|
|
11
|
+
readonly lastUsed: ModelSelection | null;
|
|
12
|
+
readonly next: ModelSelection | null;
|
|
13
|
+
} | undefined): ModelSelection | undefined;
|
|
8
14
|
/** Return the text of a direct human message, excluding injected context. */
|
|
9
15
|
export declare function humanPrompt(event: SessionEvent): string | undefined;
|
|
10
16
|
/** Recover one composer input from DSH's durable log. */
|
package/lib/rewind.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/** Return only a selection that DSH recorded for the source session. */
|
|
2
|
+
export function rewindModelSelection(projection) {
|
|
3
|
+
return projection?.next ?? projection?.lastUsed ?? undefined;
|
|
4
|
+
}
|
|
1
5
|
/** Return the text of a direct human message, excluding injected context. */
|
|
2
6
|
export function humanPrompt(event) {
|
|
3
7
|
if (event.type !== 'user/message' || event.data.source.kind !== 'user')
|
package/lib/session-runtime.js
CHANGED
|
@@ -9,7 +9,7 @@ import { diffOverlay } from './diff-view.js';
|
|
|
9
9
|
import { eventsFromRecords } from './history-records.js';
|
|
10
10
|
import { admitDraftImages, encodeDraftImages, readDraftImages } from './image-input.js';
|
|
11
11
|
import { contextPercent, jobViews, subagentViews } from './presentation.js';
|
|
12
|
-
import { historyInput, historyInputs, humanPrompt, inheritedTurn, rewindActionOverlay, rewindOverlay, } from './rewind.js';
|
|
12
|
+
import { historyInput, historyInputs, humanPrompt, inheritedTurn, rewindActionOverlay, rewindOverlay, rewindModelSelection, } from './rewind.js';
|
|
13
13
|
import { createToolPresenter } from './tool-presentation.js';
|
|
14
14
|
import { quoteShellWord, runHumanShell } from './shell-command.js';
|
|
15
15
|
import { markdownTranscript } from './session-export.js';
|
|
@@ -449,13 +449,12 @@ export async function createSessionRuntime(ctx, options, tuiRoot, dispatch, deci
|
|
|
449
449
|
?? ctx.agentPresets.defaultId;
|
|
450
450
|
const modelProjection = ctx.sessionProjections.snapshot(bound.agent.session, ['modelSelection'])
|
|
451
451
|
.values.modelSelection;
|
|
452
|
-
const selection = modelProjection
|
|
452
|
+
const selection = rewindModelSelection(modelProjection);
|
|
453
453
|
const created = await ctx.sessionController.create({ cwd: bound.root.cwd, agentPreset });
|
|
454
454
|
let selectionFailure;
|
|
455
455
|
try {
|
|
456
|
-
if (selection
|
|
457
|
-
|
|
458
|
-
await ctx.sessionController.selectModel({ sessionId: created.sessionId, ...selection });
|
|
456
|
+
if (selection !== undefined)
|
|
457
|
+
await ctx.sessionController.selectModel({ sessionId: created.sessionId, ...selection });
|
|
459
458
|
}
|
|
460
459
|
catch (error) {
|
|
461
460
|
selectionFailure = error;
|
package/lib/state.d.ts
CHANGED
|
@@ -272,6 +272,9 @@ export type UiAction = {
|
|
|
272
272
|
readonly source?: string;
|
|
273
273
|
readonly text?: string;
|
|
274
274
|
readonly type: 'attachment-added';
|
|
275
|
+
} | {
|
|
276
|
+
readonly path: string;
|
|
277
|
+
readonly type: 'attachment-path';
|
|
275
278
|
} | {
|
|
276
279
|
readonly index: number;
|
|
277
280
|
readonly type: 'attachment-remove';
|
package/lib/state.js
CHANGED
|
@@ -114,6 +114,7 @@ export function reduce(state, action) {
|
|
|
114
114
|
...(replace ? { composer: action.text } : {}),
|
|
115
115
|
}, [...(replace ? [{ type: 'set-composer', text: action.text }] : []), ...redraw()]];
|
|
116
116
|
}
|
|
117
|
+
case 'attachment-path': return [state, [{ type: 'attach', path: action.path, source: state.composer, text: state.composer }]];
|
|
117
118
|
case 'attachment-remove': {
|
|
118
119
|
if (action.index < 0 || action.index >= state.attachments.length)
|
|
119
120
|
return [state, []];
|