@diegopetrucci/pi-claude-fast 0.1.2 → 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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.ts +17 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,7 +51,7 @@ Optional project config:
51
51
  .pi/claude-fast.json
52
52
  ```
53
53
 
54
- Project config overrides global config.
54
+ Project config overrides global config after Pi reports that the project is trusted.
55
55
 
56
56
  ```json
57
57
  {
package/index.ts CHANGED
@@ -6,6 +6,8 @@ import {
6
6
  type ExtensionContext,
7
7
  } from "@earendil-works/pi-coding-agent";
8
8
 
9
+ const CONFIG_DIR_NAME = ".pi";
10
+
9
11
  const EXTENSION_ID = "claude-fast";
10
12
  const PROVIDER_ID = "anthropic";
11
13
  const API_ID = "anthropic-messages";
@@ -35,6 +37,11 @@ type SessionState = {
35
37
  lastInjectedModel?: string;
36
38
  };
37
39
 
40
+ type ProjectConfigContext = {
41
+ cwd: string;
42
+ isProjectTrusted?: () => boolean;
43
+ };
44
+
38
45
  type RecursivePartial<T> = {
39
46
  [P in keyof T]?: T[P] extends object ? RecursivePartial<T[P]> : T[P];
40
47
  };
@@ -77,21 +84,25 @@ function mergeConfig(
77
84
  };
78
85
  }
79
86
 
87
+ function canReadProjectConfig(ctx: ProjectConfigContext): boolean {
88
+ return typeof ctx.isProjectTrusted === "function" && ctx.isProjectTrusted();
89
+ }
90
+
80
91
  function findProjectConfigPath(cwd: string): string {
81
92
  let current = cwd;
82
93
  while (true) {
83
- const candidate = join(current, ".pi", "claude-fast.json");
94
+ const candidate = join(current, CONFIG_DIR_NAME, "claude-fast.json");
84
95
  if (existsSync(candidate)) return candidate;
85
96
 
86
97
  const parent = dirname(current);
87
- if (parent === current) return join(cwd, ".pi", "claude-fast.json");
98
+ if (parent === current) return join(cwd, CONFIG_DIR_NAME, "claude-fast.json");
88
99
  current = parent;
89
100
  }
90
101
  }
91
102
 
92
- function loadConfig(cwd: string): ClaudeFastConfig {
103
+ function loadConfig(ctx: ProjectConfigContext): ClaudeFastConfig {
93
104
  const globalConfig = readConfigFile(join(getAgentDir(), "extensions", "claude-fast.json"));
94
- const projectConfig = readConfigFile(findProjectConfigPath(cwd));
105
+ const projectConfig = canReadProjectConfig(ctx) ? readConfigFile(findProjectConfigPath(ctx.cwd)) : {};
95
106
  return mergeConfig(mergeConfig(DEFAULT_CONFIG, globalConfig), projectConfig);
96
107
  }
97
108
 
@@ -235,7 +246,7 @@ export default function claudeFastExtension(pi: ExtensionAPI) {
235
246
  let state = states.get(ctx.sessionManager);
236
247
  if (!state) {
237
248
  state = {
238
- config: loadConfig(ctx.cwd),
249
+ config: loadConfig(ctx),
239
250
  override: "auto",
240
251
  };
241
252
  states.set(ctx.sessionManager, state);
@@ -245,7 +256,7 @@ export default function claudeFastExtension(pi: ExtensionAPI) {
245
256
 
246
257
  pi.on("session_start", (_event, ctx) => {
247
258
  const state: SessionState = {
248
- config: loadConfig(ctx.cwd),
259
+ config: loadConfig(ctx),
249
260
  override: "auto",
250
261
  };
251
262
  states.set(ctx.sessionManager, state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegopetrucci/pi-claude-fast",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A pi extension that enables Anthropic Claude Fast mode for supported Claude Opus models by injecting speed=fast.",
5
5
  "keywords": [
6
6
  "pi-package",