@giladbarnea/pi-user-agents 0.0.14 → 0.0.15

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.
Files changed (2) hide show
  1. package/autocomplete.ts +11 -2
  2. package/package.json +1 -1
package/autocomplete.ts CHANGED
@@ -29,6 +29,7 @@ type CompletionTool = { name: string; description: string };
29
29
  type CompletionResourceCommand = ReturnType<ExtensionAPI["getCommands"]>[number];
30
30
  type ModelScopeSource = Pick<ExtensionContext["modelRegistry"], "getAvailable">;
31
31
  type AutocompleteRuntimeEditor = EditorComponent & {
32
+ cancelAutocomplete?: () => void;
32
33
  forceFileAutocomplete?: (explicitTab?: boolean) => void;
33
34
  getCursor?: () => { line: number; col: number };
34
35
  isShowingAutocomplete?: () => boolean;
@@ -449,15 +450,19 @@ function decorateAutocompleteEditor<T extends EditorComponent>(
449
450
  ): T {
450
451
  const runtimeEditor = editor as DecoratedEditor;
451
452
  if (runtimeEditor[DECORATED_EDITOR]) return editor;
453
+ const cancelAutocomplete = runtimeEditor.cancelAutocomplete;
454
+ if (typeof cancelAutocomplete !== "function")
455
+ throw new Error("pi-user-agents autocomplete requires editor.cancelAutocomplete()");
452
456
  const handleInput = editor.handleInput.bind(editor);
453
457
  editor.handleInput = (data) => {
454
458
  const getCursor = runtimeEditor.getCursor;
455
459
  if (typeof getCursor !== "function")
456
460
  throw new Error("pi-user-agents autocomplete requires editor.getCursor()");
457
461
  const beforeCursor = getCursor.call(editor);
462
+ const beforeText = editor.getText();
458
463
  const beforeExpectation =
459
464
  beforeCursor.line === 0
460
- ? analyzeAgentEditorInput(editor.getText(), beforeCursor.col)
465
+ ? analyzeAgentEditorInput(beforeText, beforeCursor.col)
461
466
  : undefined;
462
467
  const wasShowingAutocomplete = runtimeEditor.isShowingAutocomplete?.call(editor) ?? false;
463
468
  const printableCharacter =
@@ -466,8 +471,12 @@ function decorateAutocompleteEditor<T extends EditorComponent>(
466
471
  handleInput(data);
467
472
 
468
473
  const cursor = getCursor.call(editor);
474
+ const expectation =
475
+ cursor.line === 0 ? analyzeAgentEditorInput(editor.getText(), cursor.col) : undefined;
476
+ // Pi's word and line jumps do not refresh an open menu. Dismiss it before the next key.
477
+ if (wasShowingAutocomplete && beforeExpectation && !expectation && editor.getText() === beforeText)
478
+ cancelAutocomplete.call(editor);
469
479
  if (cursor.line !== 0) return;
470
- const expectation = analyzeAgentEditorInput(editor.getText(), cursor.col);
471
480
  const typedOptionDash = printableCharacter === "-" && expectation?.kind === "option";
472
481
  const completionAcceptance = isCompletionAcceptance(data);
473
482
  const typedEagerValueBoundary =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-user-agents",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Run, view, and control background Pi agents.",
5
5
  "keywords": [
6
6
  "pi-package",