@pi-unipi/core 0.1.15 → 0.1.16

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/README.md CHANGED
@@ -1,17 +1,8 @@
1
1
  # @pi-unipi/core
2
2
 
3
- Shared utilities, event types, and constants for the [Unipi](https://github.com/Neuron-Mr-White/unipi) extension suite.
3
+ Shared infrastructure for every Unipi package. Provides constants, event types, and utility functions so packages can discover each other without tight coupling.
4
4
 
5
- ## Install
6
-
7
- ```bash
8
- pi install npm:@pi-unipi/core
9
- ```
10
-
11
- Or as part of the full suite:
12
- ```bash
13
- pi install npm:unipi
14
- ```
5
+ Other packages import from `@pi-unipi/core` to emit events, read module names, and use common file operations. Without it, each package would need its own event definitions and utilities.
15
6
 
16
7
  ## Usage
17
8
 
@@ -33,6 +24,7 @@ const safeName = sanitize("my/feature: branch");
33
24
  ## Exports
34
25
 
35
26
  ### Constants
27
+
36
28
  - `UNIPI_PREFIX` — Command prefix (`unipi:`)
37
29
  - `MODULES` — All module names
38
30
  - `WORKFLOW_COMMANDS` — Workflow command names
@@ -43,6 +35,7 @@ const safeName = sanitize("my/feature: branch");
43
35
  - `RALPH_COMPLETE_MARKER` — Loop completion marker
44
36
 
45
37
  ### Events
38
+
46
39
  - `UNIPI_EVENTS` — Event names
47
40
  - `UnipiModuleEvent` — Module ready/gone payload
48
41
  - `UnipiWorkflowEvent` — Workflow start/end payload
@@ -51,6 +44,7 @@ const safeName = sanitize("my/feature: branch");
51
44
  - `UnipiStatusRequestEvent` / `UnipiStatusResponseEvent` — Status payloads
52
45
 
53
46
  ### Utilities
47
+
54
48
  - `sanitize(name)` — Sanitize string for filenames
55
49
  - `ensureDir(path)` — Create parent directories
56
50
  - `tryDelete(path)` — Safe file deletion
@@ -69,6 +63,21 @@ const safeName = sanitize("my/feature: branch");
69
63
  - `isModuleAvailable(cwd, name)` — Check if npm module exists
70
64
  - `emitEvent(pi, name, payload)` — Safe event emission
71
65
 
66
+ ## How Packages Use Core
67
+
68
+ Every Unipi package depends on `@pi-unipi/core`. On load, each package:
69
+
70
+ 1. Imports `MODULES` to register its own name
71
+ 2. Imports `UNIPI_EVENTS` to subscribe to lifecycle events
72
+ 3. Calls `emitEvent(pi, UNIPI_EVENTS.MODULE_READY, ...)` to announce itself
73
+ 4. Uses utility functions for file I/O and path resolution
74
+
75
+ This creates a loose coupling — packages discover each other through events, not direct imports.
76
+
77
+ ## Configuration
78
+
79
+ Core has no configuration. It's a pure utility layer.
80
+
72
81
  ## License
73
82
 
74
83
  MIT
package/constants.ts CHANGED
@@ -319,6 +319,7 @@ export const INPUT_SHORTCUTS_COMMANDS = {
319
319
  export const FOOTER_COMMANDS = {
320
320
  FOOTER: "footer",
321
321
  FOOTER_SETTINGS: "footer-settings",
322
+ FOOTER_HELP: "footer-help",
322
323
  } as const;
323
324
 
324
325
  /** Compactor defaults */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/core",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Shared utilities, event types, and constants for Unipi extension suite",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/utils.ts CHANGED
@@ -141,6 +141,36 @@ export function getPackageVersion(packageDir: string): string {
141
141
  return pkg?.version ?? "0.0.0";
142
142
  }
143
143
 
144
+ /**
145
+ * Walk up from `startDir` to find a package.json with the given `name`.
146
+ * Returns the directory containing that package.json, or null if not found.
147
+ * Stops after `maxSteps` levels (default 10).
148
+ */
149
+ export function findPackageRoot(startDir: string, packageName: string, maxSteps = 10): string | null {
150
+ let dir = path.resolve(startDir);
151
+ for (let i = 0; i < maxSteps; i++) {
152
+ const pkgPath = path.join(dir, "package.json");
153
+ const pkg = readJson<{ name?: string }>(pkgPath);
154
+ if (pkg?.name === packageName) {
155
+ return dir;
156
+ }
157
+ const parent = path.dirname(dir);
158
+ if (parent === dir) break; // filesystem root
159
+ dir = parent;
160
+ }
161
+ return null;
162
+ }
163
+
164
+ /**
165
+ * Get the installed version of a named package by walking up from startDir.
166
+ * Returns "0.0.0" if the package cannot be found.
167
+ */
168
+ export function getInstalledPackageVersion(startDir: string, packageName: string): string {
169
+ const root = findPackageRoot(startDir, packageName);
170
+ if (!root) return "0.0.0";
171
+ return getPackageVersion(root);
172
+ }
173
+
144
174
  /**
145
175
  * Check if a module is available in node_modules.
146
176
  */