@firstpick/pi-extension-cd 0.1.0 → 0.1.1

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/index.ts +2 -29
  2. package/package.json +4 -1
package/index.ts CHANGED
@@ -3,6 +3,7 @@ import * as os from "node:os";
3
3
  import * as path from "node:path";
4
4
  import { SessionManager, type ExtensionAPI, type ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
5
5
  import type { AutocompleteItem } from "@earendil-works/pi-tui";
6
+ import { expandTilde, formatUserPath as formatPath, getAgentDir, writeJsonFileAtomicSync } from "@firstpick/pi-utils";
6
7
 
7
8
  type CdHistoryEntry = {
8
9
  path: string;
@@ -47,11 +48,6 @@ const RESERVED_ALIAS_NAMES = new Set([
47
48
  "--status",
48
49
  ]);
49
50
 
50
- function getAgentDir(): string {
51
- const configured = process.env.PI_CODING_AGENT_DIR?.trim();
52
- return configured ? path.resolve(expandTilde(configured)) : path.join(os.homedir(), ".pi", "agent");
53
- }
54
-
55
51
  function getStorePath(): string {
56
52
  const configured = process.env.PI_CD_HISTORY_STORE_PATH?.trim();
57
53
  return configured ? path.resolve(expandTilde(configured)) : path.join(getAgentDir(), "state", "cd-history.json");
@@ -61,14 +57,6 @@ function emptyStore(): CdStore {
61
57
  return { version: STORE_VERSION, aliases: {}, history: [] };
62
58
  }
63
59
 
64
- function expandTilde(input: string): string {
65
- if (input === "~") return os.homedir();
66
- if (input.startsWith(`~${path.sep}`) || input.startsWith("~/")) {
67
- return path.join(os.homedir(), input.slice(2));
68
- }
69
- return input;
70
- }
71
-
72
60
  function canonicalPath(input: string, baseDir?: string): string {
73
61
  const expanded = expandTilde(input.trim());
74
62
  const resolved = path.resolve(baseDir ?? process.cwd(), expanded);
@@ -92,17 +80,6 @@ function normalizeDirectory(input: string, baseDir?: string): string | undefined
92
80
  return isDirectory(resolved) ? resolved : undefined;
93
81
  }
94
82
 
95
- function formatPath(input: string): string {
96
- const home = os.homedir();
97
- const resolvedHome = path.resolve(home);
98
- const resolved = path.resolve(input);
99
- if (resolved === resolvedHome) return "~";
100
- if (resolved.startsWith(`${resolvedHome}${path.sep}`)) {
101
- return `~/${path.relative(resolvedHome, resolved).split(path.sep).join("/")}`;
102
- }
103
- return resolved.split(path.sep).join(path.sep);
104
- }
105
-
106
83
  function formatAge(timestamp: number): string {
107
84
  const seconds = Math.max(0, Math.floor((Date.now() - timestamp) / 1000));
108
85
  if (seconds < 60) return "now";
@@ -157,11 +134,7 @@ function readStore(storePath: string): CdStore {
157
134
 
158
135
  function writeStore(storePath: string, store: CdStore): void {
159
136
  try {
160
- fs.mkdirSync(path.dirname(storePath), { recursive: true });
161
- const compacted = compactStore(store);
162
- const tempPath = `${storePath}.${process.pid}.${Date.now()}.tmp`;
163
- fs.writeFileSync(tempPath, `${JSON.stringify(compacted, null, 2)}\n`, "utf8");
164
- fs.renameSync(tempPath, storePath);
137
+ writeJsonFileAtomicSync(storePath, compactStore(store));
165
138
  } catch {
166
139
  // Directory changes should still work if persistence fails.
167
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firstpick/pi-extension-cd",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A Pi /cd command with ranked directory suggestions, persistent history, and aliases.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/Firstp1ck/npm-packages/tree/main/pi-extension-cd#readme",
@@ -22,6 +22,9 @@
22
22
  "./index.ts"
23
23
  ]
24
24
  },
25
+ "dependencies": {
26
+ "@firstpick/pi-utils": "^0.2.3"
27
+ },
25
28
  "peerDependencies": {
26
29
  "@earendil-works/pi-coding-agent": "*",
27
30
  "@earendil-works/pi-tui": "*"