pi-atuin 0.1.1 → 0.1.3

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/history-store.ts CHANGED
@@ -25,6 +25,26 @@ export interface HistoryEntry {
25
25
 
26
26
  let writeQueue: Promise<void> = Promise.resolve();
27
27
 
28
+ // ponytail: in-memory dedup guard — input event may fire twice per entry.
29
+ // prevents duplicate writes to JSONL within 5s window.
30
+ const recentWrites = new Map<string, number>();
31
+ const WRITE_DEDUP_MS = 5_000;
32
+
33
+ export function isRecentWrite(text: string): boolean {
34
+ const last = recentWrites.get(text);
35
+ if (last && Date.now() - last < WRITE_DEDUP_MS) return true;
36
+ return false;
37
+ }
38
+
39
+ export function markRecentWrite(text: string): void {
40
+ recentWrites.set(text, Date.now());
41
+ // Cleanup entries older than WRITE_DEDUP_MS
42
+ const cutoff = Date.now() - WRITE_DEDUP_MS;
43
+ for (const [k, ts] of recentWrites) {
44
+ if (ts < cutoff) recentWrites.delete(k);
45
+ }
46
+ }
47
+
28
48
  // ---------------------------------------------------------------------------
29
49
  // JSONL persistence
30
50
  // ---------------------------------------------------------------------------
@@ -143,7 +163,7 @@ async function loadAllEntries(): Promise<HistoryEntry[]> {
143
163
  const key = entry.text.trim();
144
164
  const existing = seen.get(key);
145
165
  if (!existing || Math.abs(entry.timestamp - existing.timestamp) > 5000) {
146
- seen.set(`${key}-${entry.timestamp}`, entry);
166
+ seen.set(key, entry);
147
167
  }
148
168
  }
149
169
 
package/index.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
10
10
  import { CustomEditor } from "@earendil-works/pi-coding-agent";
11
11
  import { matchesKey, Key } from "@earendil-works/pi-tui";
12
- import { addEntry, invalidateCache, listRecent, writeToAtuin } from "./history-store.js";
12
+ import { addEntry, invalidateCache, listRecent, writeToAtuin, isRecentWrite, markRecentWrite } from "./history-store.js";
13
13
  import { HistorySearchComponent } from "./search-ui.js";
14
14
 
15
15
  export default function piAtuin(pi: ExtensionAPI) {
@@ -17,6 +17,9 @@ export default function piAtuin(pi: ExtensionAPI) {
17
17
  pi.on("input", async (event, ctx) => {
18
18
  if (event.source === "interactive" && event.text.trim()) {
19
19
  const text = event.text.trim();
20
+ // Guard against duplicate input events (pi may fire input twice)
21
+ if (isRecentWrite(text)) return { action: "continue" as const };
22
+ markRecentWrite(text);
20
23
  await addEntry(text, ctx.cwd);
21
24
  // Also write to atuin DB so shell atuin can search pi prompts
22
25
  writeToAtuin(text, ctx.cwd);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-atuin",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Atuin-style fuzzy history search for pi. Press ↑ for interactive history.",
5
5
  "license": "MIT",
6
6
  "author": "RealAlexandreAI",
@@ -18,7 +18,8 @@
18
18
  "pi": {
19
19
  "extensions": [
20
20
  "./index.ts"
21
- ]
21
+ ],
22
+ "image": "https://raw.githubusercontent.com/RealAlexandreAI/pi-atuin/master/screenshot.png"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "@earendil-works/pi-coding-agent": "*"