my-pi 0.1.87 → 0.1.89

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/dist/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Api, Model } from "@earendil-works/pi-ai";
2
1
  import { AgentSessionRuntime, CreateAgentSessionFromServicesOptions, ExtensionAPI, ExtensionFactory, ExtensionFactory as ExtensionFactory$1, InteractiveMode, InteractiveModeOptions, PrintModeOptions, runPrintMode, runRpcMode } from "@earendil-works/pi-coding-agent";
2
+ import { Api, Model } from "@earendil-works/pi-ai";
3
3
  //#region src/extensions/startup-screen/index.d.ts
4
4
  declare function startup_screen_extension(pi: ExtensionAPI): void;
5
5
  //#endregion
@@ -313,7 +313,7 @@ declare const BUILTIN_EXTENSION_REGISTRY: readonly [{
313
313
  type BuiltinExtensionKey = (typeof BUILTIN_EXTENSION_REGISTRY)[number]['key'];
314
314
  type BuiltinExtensionOptionName = (typeof BUILTIN_EXTENSION_REGISTRY)[number]['option_name'];
315
315
  //#endregion
316
- //#region src/api.d.ts
316
+ //#region src/api/options.d.ts
317
317
  type MyPiRuntimeMode = 'interactive' | 'print' | 'json' | 'rpc';
318
318
  type MyPiThinkingLevel = NonNullable<CreateAgentSessionFromServicesOptions['thinkingLevel']>;
319
319
  type BuiltinExtensionOptions = Partial<Record<BuiltinExtensionOptionName, boolean>>;
@@ -338,17 +338,25 @@ interface CreateMyPiOptions extends BuiltinExtensionOptions {
338
338
  append_system_prompt?: string;
339
339
  untrusted_repo?: boolean;
340
340
  }
341
+ //#endregion
342
+ //#region src/api/builtin-extensions.d.ts
341
343
  type BuiltinExtensionLoader = () => Promise<ExtensionFactory$1>;
344
+ declare function get_force_disabled_builtins(options: Pick<CreateMyPiOptions, 'runtime_mode'> & BuiltinExtensionOptions): Set<BuiltinExtensionKey>;
345
+ declare function get_externally_installed_builtin_extensions(agent_dir: string): Set<BuiltinExtensionKey>;
346
+ declare function create_lazy_builtin_extension_factory(key: BuiltinExtensionKey, load_extension: BuiltinExtensionLoader, force_disabled: ReadonlySet<BuiltinExtensionKey>): ExtensionFactory$1;
347
+ //#endregion
348
+ //#region src/api/env.d.ts
342
349
  declare function apply_untrusted_repo_defaults(env?: NodeJS.ProcessEnv): string[];
350
+ //#endregion
351
+ //#region src/api/models.d.ts
343
352
  interface ModelRegistryLike {
344
353
  getAll(): Model<Api>[];
345
354
  }
346
355
  declare function resolve_model_reference(model_reference: string | undefined, model_registry: ModelRegistryLike): Model<Api> | undefined;
347
356
  declare function resolve_effective_thinking_level(model: Model<Api> | undefined, thinking: MyPiThinkingLevel | undefined): MyPiThinkingLevel | undefined;
348
- declare function get_force_disabled_builtins(options: Pick<CreateMyPiOptions, 'runtime_mode'> & BuiltinExtensionOptions): Set<BuiltinExtensionKey>;
349
- declare function get_externally_installed_builtin_extensions(agent_dir: string): Set<BuiltinExtensionKey>;
350
- declare function create_lazy_builtin_extension_factory(key: BuiltinExtensionKey, load_extension: BuiltinExtensionLoader, force_disabled: ReadonlySet<BuiltinExtensionKey>): ExtensionFactory$1;
357
+ //#endregion
358
+ //#region src/api.d.ts
351
359
  declare function create_my_pi(options?: CreateMyPiOptions): Promise<import("@earendil-works/pi-coding-agent").AgentSessionRuntime>;
352
360
  //#endregion
353
- export { type AgentSessionRuntime, CreateMyPiOptions, type ExtensionFactory, InteractiveMode, type InteractiveModeOptions, MyPiRuntimeMode, MyPiThinkingLevel, type PrintModeOptions, apply_untrusted_repo_defaults, create_lazy_builtin_extension_factory, create_my_pi, get_externally_installed_builtin_extensions, get_force_disabled_builtins, resolve_effective_thinking_level, resolve_model_reference, runPrintMode, runRpcMode };
361
+ export { type AgentSessionRuntime, type CreateMyPiOptions, type ExtensionFactory, InteractiveMode, type InteractiveModeOptions, type MyPiRuntimeMode, type MyPiThinkingLevel, type PrintModeOptions, apply_untrusted_repo_defaults, create_lazy_builtin_extension_factory, create_my_pi, get_externally_installed_builtin_extensions, get_force_disabled_builtins, resolve_effective_thinking_level, resolve_model_reference, runPrintMode, runRpcMode };
354
362
  //# sourceMappingURL=api.d.ts.map
package/dist/api.js CHANGED
@@ -1,12 +1,12 @@
1
- import { n as BUILTIN_EXTENSION_REGISTRY, t as BUILTIN_EXTENSIONS } from "./builtin-registry-C7hkBDoD.js";
1
+ import { n as BUILTIN_EXTENSION_REGISTRY, t as BUILTIN_EXTENSIONS } from "./builtin-registry-DwcL3xlj.js";
2
2
  import { createRequire } from "node:module";
3
3
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
4
4
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
5
- import { clampThinkingLevel } from "@earendil-works/pi-ai";
6
5
  import { InteractiveMode, SessionManager, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, getAgentDir, runPrintMode, runRpcMode } from "@earendil-works/pi-coding-agent";
7
- import { apply_project_trust_untrusted_defaults } from "@spences10/pi-project-trust";
8
6
  import { get_settings_path, read_settings, write_settings } from "@spences10/pi-settings";
9
7
  import { homedir } from "node:os";
8
+ import { apply_project_trust_untrusted_defaults } from "@spences10/pi-project-trust";
9
+ import { clampThinkingLevel } from "@earendil-works/pi-ai";
10
10
  import { show_settings_modal } from "@spences10/pi-tui-modal";
11
11
  //#region src/settings/schema.ts
12
12
  const DEFAULT_SETTINGS = {
@@ -225,6 +225,168 @@ function find_builtin_extension(query) {
225
225
  ...extension.aliases
226
226
  ].some((value) => value.toLowerCase() === normalized));
227
227
  }
228
+ const PACKAGE_THEME_DIR = resolve(dirname(createRequire(import.meta.url).resolve("@spences10/pi-themes/package.json")), "themes");
229
+ function get_force_disabled_builtins(options) {
230
+ const force_disabled = /* @__PURE__ */ new Set();
231
+ for (const extension of BUILTIN_EXTENSION_REGISTRY) {
232
+ if (!(options[extension.option_name] ?? extension.default_enabled)) force_disabled.add(extension.key);
233
+ const disabled_in = "mode_constraints" in extension ? extension.mode_constraints.disabled_in : void 0;
234
+ if (options.runtime_mode && disabled_in?.includes(options.runtime_mode)) force_disabled.add(extension.key);
235
+ }
236
+ return force_disabled;
237
+ }
238
+ function is_agent_dir_package_installed(agent_dir, package_name) {
239
+ return existsSync(join(agent_dir, "npm", "node_modules", package_name));
240
+ }
241
+ function get_externally_installed_builtin_extensions(agent_dir) {
242
+ const installed = /* @__PURE__ */ new Set();
243
+ for (const extension of BUILTIN_EXTENSION_REGISTRY) {
244
+ const external_package_name = extension.external_package_name;
245
+ if (external_package_name && is_agent_dir_package_installed(agent_dir, external_package_name)) installed.add(extension.key);
246
+ }
247
+ return installed;
248
+ }
249
+ function warn_builtin_extension_unavailable(key, error) {
250
+ const reason = error instanceof Error ? error.message : String(error);
251
+ process.emitWarning(`Built-in extension "${key}" is unavailable and was skipped: ${reason}`, { code: "MY_PI_BUILTIN_EXTENSION_UNAVAILABLE" });
252
+ }
253
+ function create_lazy_builtin_extension_factory(key, load_extension, force_disabled) {
254
+ return async (pi) => {
255
+ if (!is_builtin_extension_active(load_builtin_extensions_config(), key, force_disabled)) return;
256
+ try {
257
+ await (await load_extension())(pi);
258
+ } catch (error) {
259
+ warn_builtin_extension_unavailable(key, error);
260
+ }
261
+ };
262
+ }
263
+ function create_lazy_telemetry_extension(options) {
264
+ return async (pi) => {
265
+ try {
266
+ const { create_telemetry_extension } = await import("@spences10/pi-telemetry");
267
+ await create_telemetry_extension(options)(pi);
268
+ } catch (error) {
269
+ warn_builtin_extension_unavailable("telemetry", error);
270
+ }
271
+ };
272
+ }
273
+ function create_extensions_override(managed_inline_paths) {
274
+ const managed_paths = new Set(managed_inline_paths);
275
+ return (base) => {
276
+ const managed = new Map(base.extensions.map((extension) => [extension.path, extension]));
277
+ const ordered_managed = managed_inline_paths.map((path) => managed.get(path)).filter((extension) => Boolean(extension));
278
+ const others = base.extensions.filter((extension) => !managed_paths.has(extension.path));
279
+ return {
280
+ ...base,
281
+ extensions: [...ordered_managed, ...others]
282
+ };
283
+ };
284
+ }
285
+ //#endregion
286
+ //#region src/api/env.ts
287
+ const PI_AGENT_DIR_ENV = "PI_CODING_AGENT_DIR";
288
+ const MY_PI_RUNTIME_MODE_ENV = "MY_PI_RUNTIME_MODE";
289
+ function snapshot_env(env, keys) {
290
+ return new Map(Array.from(keys, (key) => [key, env[key]]));
291
+ }
292
+ function restore_env(env, snapshot) {
293
+ for (const [key, value] of snapshot) if (value === void 0) delete env[key];
294
+ else env[key] = value;
295
+ }
296
+ function wrap_runtime_env_restore(runtime, restore) {
297
+ const dispose = runtime.dispose.bind(runtime);
298
+ let restored = false;
299
+ const restore_once = () => {
300
+ if (restored) return;
301
+ restored = true;
302
+ restore();
303
+ };
304
+ runtime.dispose = (async () => {
305
+ try {
306
+ await dispose();
307
+ } finally {
308
+ restore_once();
309
+ }
310
+ });
311
+ return runtime;
312
+ }
313
+ const UNTRUSTED_CHILD_ENV_DEFAULTS = {
314
+ MY_PI_CHILD_ENV_ALLOWLIST: "",
315
+ MY_PI_MCP_ENV_ALLOWLIST: "",
316
+ MY_PI_LSP_ENV_ALLOWLIST: "",
317
+ MY_PI_HOOKS_ENV_ALLOWLIST: "",
318
+ MY_PI_TEAM_MODE_ENV_ALLOWLIST: ""
319
+ };
320
+ function apply_untrusted_repo_defaults(env = process.env) {
321
+ const applied = apply_project_trust_untrusted_defaults(env);
322
+ for (const [key, value] of Object.entries(UNTRUSTED_CHILD_ENV_DEFAULTS)) {
323
+ if (env[key] !== void 0) continue;
324
+ env[key] = value;
325
+ applied.push(key);
326
+ }
327
+ return applied;
328
+ }
329
+ function is_resource_enabled(value) {
330
+ const normalized = value?.trim().toLowerCase();
331
+ if (!normalized) return true;
332
+ if ([
333
+ "0",
334
+ "false",
335
+ "no",
336
+ "skip",
337
+ "disable"
338
+ ].includes(normalized)) return false;
339
+ return true;
340
+ }
341
+ function resolve_agent_dir(cwd, agent_dir) {
342
+ return agent_dir ? resolve(cwd, agent_dir) : getAgentDir();
343
+ }
344
+ //#endregion
345
+ //#region src/api/models.ts
346
+ function resolve_model_reference(model_reference, model_registry) {
347
+ if (!model_reference) return void 0;
348
+ const models = model_registry.getAll();
349
+ const lower_reference = model_reference.toLowerCase();
350
+ const slash_index = model_reference.indexOf("/");
351
+ if (slash_index !== -1) {
352
+ const maybe_provider = model_reference.slice(0, slash_index);
353
+ const model_id = model_reference.slice(slash_index + 1);
354
+ const provider = models.find((model) => model.provider.toLowerCase() === maybe_provider.toLowerCase())?.provider;
355
+ if (provider) {
356
+ const provider_match = models.find((model) => model.provider === provider && model.id.toLowerCase() === model_id.toLowerCase());
357
+ if (provider_match) return provider_match;
358
+ }
359
+ }
360
+ return models.find((model) => {
361
+ const id = model.id.toLowerCase();
362
+ const full_id = `${model.provider}/${model.id}`.toLowerCase();
363
+ return id === lower_reference || full_id === lower_reference;
364
+ });
365
+ }
366
+ function resolve_effective_thinking_level(model, thinking) {
367
+ if (!thinking || !model) return thinking;
368
+ return clampThinkingLevel(model, thinking);
369
+ }
370
+ //#endregion
371
+ //#region src/api/session.ts
372
+ function resolve_session_file(cwd, session_dir, session_ref) {
373
+ if (!session_ref) return void 0;
374
+ const explicit_path = isAbsolute(session_ref) ? session_ref : resolve(cwd, session_ref);
375
+ if (existsSync(explicit_path)) return explicit_path;
376
+ if (session_ref.endsWith(".jsonl")) return explicit_path;
377
+ const dir = session_dir ? resolve(cwd, session_dir) : void 0;
378
+ if (!dir || !existsSync(dir)) return void 0;
379
+ const match = readdirSync(dir).filter((file) => file.endsWith(".jsonl") && (basename(file, ".jsonl").endsWith(session_ref) || file.includes(session_ref))).sort().at(-1);
380
+ return match ? join(dir, match) : void 0;
381
+ }
382
+ function create_session_manager(options) {
383
+ const resolved_session_dir = options.session_dir ? resolve(options.cwd, options.session_dir) : SessionManager.create(options.cwd).getSessionDir();
384
+ const session_ref = options.session ?? options.session_id;
385
+ const session_file = resolve_session_file(options.cwd, resolved_session_dir, session_ref);
386
+ const session_manager = session_file ? SessionManager.open(session_file, resolved_session_dir, options.cwd) : SessionManager.create(options.cwd, resolved_session_dir, options.session_id ? { id: options.session_id } : {});
387
+ if (options.startup_session_name && session_manager.getSessionName() !== options.startup_session_name) session_manager.appendSessionInfo(options.startup_session_name);
388
+ return session_manager;
389
+ }
228
390
  //#endregion
229
391
  //#region src/extensions/manager/index.ts
230
392
  const ENABLED = "● enabled";
@@ -401,162 +563,6 @@ function create_extensions_extension(options = {}) {
401
563
  create_extensions_extension();
402
564
  //#endregion
403
565
  //#region src/api.ts
404
- const PACKAGE_THEME_DIR = resolve(dirname(createRequire(import.meta.url).resolve("@spences10/pi-themes/package.json")), "themes");
405
- const PI_AGENT_DIR_ENV = "PI_CODING_AGENT_DIR";
406
- const MY_PI_RUNTIME_MODE_ENV = "MY_PI_RUNTIME_MODE";
407
- function snapshot_env(env, keys) {
408
- return new Map(Array.from(keys, (key) => [key, env[key]]));
409
- }
410
- function restore_env(env, snapshot) {
411
- for (const [key, value] of snapshot) if (value === void 0) delete env[key];
412
- else env[key] = value;
413
- }
414
- function wrap_runtime_env_restore(runtime, restore) {
415
- const dispose = runtime.dispose.bind(runtime);
416
- let restored = false;
417
- const restore_once = () => {
418
- if (restored) return;
419
- restored = true;
420
- restore();
421
- };
422
- runtime.dispose = (async () => {
423
- try {
424
- await dispose();
425
- } finally {
426
- restore_once();
427
- }
428
- });
429
- return runtime;
430
- }
431
- const UNTRUSTED_CHILD_ENV_DEFAULTS = {
432
- MY_PI_CHILD_ENV_ALLOWLIST: "",
433
- MY_PI_MCP_ENV_ALLOWLIST: "",
434
- MY_PI_LSP_ENV_ALLOWLIST: "",
435
- MY_PI_HOOKS_ENV_ALLOWLIST: "",
436
- MY_PI_TEAM_MODE_ENV_ALLOWLIST: ""
437
- };
438
- function apply_untrusted_repo_defaults(env = process.env) {
439
- const applied = apply_project_trust_untrusted_defaults(env);
440
- for (const [key, value] of Object.entries(UNTRUSTED_CHILD_ENV_DEFAULTS)) {
441
- if (env[key] !== void 0) continue;
442
- env[key] = value;
443
- applied.push(key);
444
- }
445
- return applied;
446
- }
447
- function is_resource_enabled(value) {
448
- const normalized = value?.trim().toLowerCase();
449
- if (!normalized) return true;
450
- if ([
451
- "0",
452
- "false",
453
- "no",
454
- "skip",
455
- "disable"
456
- ].includes(normalized)) return false;
457
- return true;
458
- }
459
- function resolve_agent_dir(cwd, agent_dir) {
460
- return agent_dir ? resolve(cwd, agent_dir) : getAgentDir();
461
- }
462
- function resolve_session_file(cwd, session_dir, session_ref) {
463
- if (!session_ref) return void 0;
464
- const explicit_path = isAbsolute(session_ref) ? session_ref : resolve(cwd, session_ref);
465
- if (existsSync(explicit_path)) return explicit_path;
466
- if (session_ref.endsWith(".jsonl")) return explicit_path;
467
- const dir = session_dir ? resolve(cwd, session_dir) : void 0;
468
- if (!dir || !existsSync(dir)) return void 0;
469
- const match = readdirSync(dir).filter((file) => file.endsWith(".jsonl") && (basename(file, ".jsonl").endsWith(session_ref) || file.includes(session_ref))).sort().at(-1);
470
- return match ? join(dir, match) : void 0;
471
- }
472
- function create_session_manager(options) {
473
- const resolved_session_dir = options.session_dir ? resolve(options.cwd, options.session_dir) : SessionManager.create(options.cwd).getSessionDir();
474
- const session_ref = options.session ?? options.session_id;
475
- const session_file = resolve_session_file(options.cwd, resolved_session_dir, session_ref);
476
- const session_manager = session_file ? SessionManager.open(session_file, resolved_session_dir, options.cwd) : SessionManager.create(options.cwd, resolved_session_dir, options.session_id ? { id: options.session_id } : {});
477
- if (options.startup_session_name && session_manager.getSessionName() !== options.startup_session_name) session_manager.appendSessionInfo(options.startup_session_name);
478
- return session_manager;
479
- }
480
- function resolve_model_reference(model_reference, model_registry) {
481
- if (!model_reference) return void 0;
482
- const models = model_registry.getAll();
483
- const lower_reference = model_reference.toLowerCase();
484
- const slash_index = model_reference.indexOf("/");
485
- if (slash_index !== -1) {
486
- const maybe_provider = model_reference.slice(0, slash_index);
487
- const model_id = model_reference.slice(slash_index + 1);
488
- const provider = models.find((model) => model.provider.toLowerCase() === maybe_provider.toLowerCase())?.provider;
489
- if (provider) {
490
- const provider_match = models.find((model) => model.provider === provider && model.id.toLowerCase() === model_id.toLowerCase());
491
- if (provider_match) return provider_match;
492
- }
493
- }
494
- return models.find((model) => {
495
- const id = model.id.toLowerCase();
496
- const full_id = `${model.provider}/${model.id}`.toLowerCase();
497
- return id === lower_reference || full_id === lower_reference;
498
- });
499
- }
500
- function resolve_effective_thinking_level(model, thinking) {
501
- if (!thinking || !model) return thinking;
502
- return clampThinkingLevel(model, thinking);
503
- }
504
- function get_force_disabled_builtins(options) {
505
- const force_disabled = /* @__PURE__ */ new Set();
506
- for (const extension of BUILTIN_EXTENSION_REGISTRY) {
507
- if (!(options[extension.option_name] ?? extension.default_enabled)) force_disabled.add(extension.key);
508
- const disabled_in = "mode_constraints" in extension ? extension.mode_constraints.disabled_in : void 0;
509
- if (options.runtime_mode && disabled_in?.includes(options.runtime_mode)) force_disabled.add(extension.key);
510
- }
511
- return force_disabled;
512
- }
513
- function is_agent_dir_package_installed(agent_dir, package_name) {
514
- return existsSync(join(agent_dir, "npm", "node_modules", package_name));
515
- }
516
- function get_externally_installed_builtin_extensions(agent_dir) {
517
- const installed = /* @__PURE__ */ new Set();
518
- for (const extension of BUILTIN_EXTENSION_REGISTRY) {
519
- const external_package_name = extension.external_package_name;
520
- if (external_package_name && is_agent_dir_package_installed(agent_dir, external_package_name)) installed.add(extension.key);
521
- }
522
- return installed;
523
- }
524
- function warn_builtin_extension_unavailable(key, error) {
525
- const reason = error instanceof Error ? error.message : String(error);
526
- process.emitWarning(`Built-in extension "${key}" is unavailable and was skipped: ${reason}`, { code: "MY_PI_BUILTIN_EXTENSION_UNAVAILABLE" });
527
- }
528
- function create_lazy_builtin_extension_factory(key, load_extension, force_disabled) {
529
- return async (pi) => {
530
- if (!is_builtin_extension_active(load_builtin_extensions_config(), key, force_disabled)) return;
531
- try {
532
- await (await load_extension())(pi);
533
- } catch (error) {
534
- warn_builtin_extension_unavailable(key, error);
535
- }
536
- };
537
- }
538
- function create_lazy_telemetry_extension(options) {
539
- return async (pi) => {
540
- try {
541
- const { create_telemetry_extension } = await import("@spences10/pi-telemetry");
542
- await create_telemetry_extension(options)(pi);
543
- } catch (error) {
544
- warn_builtin_extension_unavailable("telemetry", error);
545
- }
546
- };
547
- }
548
- function create_extensions_override(managed_inline_paths) {
549
- const managed_paths = new Set(managed_inline_paths);
550
- return (base) => {
551
- const managed = new Map(base.extensions.map((extension) => [extension.path, extension]));
552
- const ordered_managed = managed_inline_paths.map((path) => managed.get(path)).filter((extension) => Boolean(extension));
553
- const others = base.extensions.filter((extension) => !managed_paths.has(extension.path));
554
- return {
555
- ...base,
556
- extensions: [...ordered_managed, ...others]
557
- };
558
- };
559
- }
560
566
  async function create_my_pi(options = {}) {
561
567
  const { cwd = process.cwd(), agent_dir, extensions = [], extensionFactories: user_factories = [], runtime_mode = "interactive", telemetry, telemetry_db_path, model, thinking, selected_tools, excluded_tools, selected_skills, session, session_id, startup_session_name, session_dir, system_prompt, append_system_prompt, untrusted_repo = false } = options;
562
568
  const env_keys_to_restore = new Set([MY_PI_RUNTIME_MODE_ENV]);