@aliou/pi-dev-kit 0.6.5 → 0.7.0

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
@@ -51,7 +51,7 @@ Returns the version of the currently running Pi instance.
51
51
 
52
52
  ### `pi_docs`
53
53
 
54
- Lists all Pi documentation files from the Pi installation: `README.md`, individual files in `docs/`, and the `examples/` directory path.
54
+ Lists Pi markdown documentation files from the Pi installation: `README.md`, `docs/`, and `examples/`.
55
55
 
56
56
  ### `pi_changelog`
57
57
 
@@ -59,4 +59,4 @@ Parses the Pi changelog and returns entries for a specific version (or the lates
59
59
 
60
60
  ## Compatibility
61
61
 
62
- Compatible with Pi 0.50.x and 0.51.0+. Tools that need the extension context use a runtime shim to handle the execute signature difference between versions.
62
+ Tested against Pi 0.74.0 and the `@earendil-works/*` Pi package namespace.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aliou/pi-dev-kit",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
@@ -17,7 +17,8 @@
17
17
  },
18
18
  "pi": {
19
19
  "extensions": [
20
- "./src/index.ts"
20
+ "./src/tools/index.ts",
21
+ "./src/commands/index.ts"
21
22
  ],
22
23
  "skills": [
23
24
  "./src/skills"
@@ -35,28 +36,28 @@
35
36
  "README.md"
36
37
  ],
37
38
  "dependencies": {
38
- "@aliou/pi-utils-ui": "^0.1.0"
39
+ "@aliou/pi-utils-ui": "^0.4.0"
39
40
  },
40
41
  "peerDependencies": {
41
- "@mariozechner/pi-coding-agent": "0.70.0",
42
- "@mariozechner/pi-tui": "0.70.0",
43
- "typebox": ">=1.1.24"
42
+ "@earendil-works/pi-coding-agent": "*",
43
+ "@earendil-works/pi-tui": "*",
44
+ "typebox": "*"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@biomejs/biome": "^2.3.13",
47
48
  "@changesets/cli": "^2.27.11",
48
- "@mariozechner/pi-coding-agent": "0.70.0",
49
- "@mariozechner/pi-tui": "0.70.0",
49
+ "@earendil-works/pi-coding-agent": "0.74.0",
50
+ "@earendil-works/pi-tui": "0.74.0",
50
51
  "typebox": "1.1.24",
51
52
  "@types/node": "^25.0.10",
52
53
  "husky": "^9.1.7",
53
54
  "typescript": "^5.9.3"
54
55
  },
55
56
  "peerDependenciesMeta": {
56
- "@mariozechner/pi-coding-agent": {
57
+ "@earendil-works/pi-coding-agent": {
57
58
  "optional": true
58
59
  },
59
- "@mariozechner/pi-tui": {
60
+ "@earendil-works/pi-tui": {
60
61
  "optional": true
61
62
  },
62
63
  "typebox": {
@@ -1,6 +1,10 @@
1
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { registerUpdateCommand } from "./update";
3
3
 
4
4
  export function registerCommands(pi: ExtensionAPI) {
5
5
  registerUpdateCommand(pi);
6
6
  }
7
+
8
+ export default function commandsExtension(pi: ExtensionAPI) {
9
+ registerCommands(pi);
10
+ }
@@ -1,102 +1,150 @@
1
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
- import { VERSION } from "@mariozechner/pi-coding-agent";
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import { VERSION } from "@earendil-works/pi-coding-agent";
3
3
 
4
- const NPM_REGISTRY_URL =
5
- "https://registry.npmjs.org/@mariozechner/pi-coding-agent/latest";
4
+ const NPM_REGISTRY_URLS = [
5
+ "https://registry.npmjs.org/@earendil-works/pi-coding-agent/latest",
6
+ "https://registry.npmjs.org/@mariozechner/pi-coding-agent/latest",
7
+ ] as const;
6
8
 
7
9
  async function fetchLatestVersion(): Promise<string | null> {
8
- try {
9
- const res = await fetch(NPM_REGISTRY_URL);
10
- if (!res.ok) return null;
11
- const data = (await res.json()) as { version?: string };
12
- return data.version ?? null;
13
- } catch {
14
- return null;
10
+ for (const url of NPM_REGISTRY_URLS) {
11
+ try {
12
+ const res = await fetch(url);
13
+ if (!res.ok) continue;
14
+ const data = (await res.json()) as { version?: string };
15
+ if (data.version) return data.version;
16
+ } catch {
17
+ // Try the next registry URL.
18
+ }
15
19
  }
20
+ return null;
16
21
  }
17
22
 
18
23
  const UPDATE_PROMPT = `# Update Pi Extensions
19
24
 
20
- Update this project's Pi extensions, themes, and components to the specified target Pi version.
21
-
22
- ## Steps
23
-
24
- ### 1. Detect Package Manager
25
-
26
- Use \`detect_package_manager\` to identify the package manager (npm, pnpm, yarn, bun). Use its install and run commands for all subsequent steps.
27
-
28
- ### 2. Version Check
29
-
30
- The target Pi version is provided above. Read \`./package.json\` to find the current Pi package versions. The relevant packages are any of:
31
- - \`@mariozechner/pi-ai\`
32
- - \`@mariozechner/pi-coding-agent\`
33
- - \`@mariozechner/pi-tui\`
34
- - \`@mariozechner/pi-agent-core\`
35
-
36
- Report the current version in package.json vs the target version. If versions match, stop here -- nothing to update.
37
-
38
- ### 3. Gather Documentation
39
-
40
- If there's a version mismatch:
41
- 1. Use \`pi_changelog\` to get changelog entries for versions between current and target
42
- 2. Use \`pi_docs\` to get paths to Pi documentation
43
- 3. Read the relevant docs, especially:
44
- - \`docs/extensions.md\` for extension API changes
45
- - Any migration guides or breaking changes noted in changelogs
46
-
47
- ### 4. Analyze Source
48
-
49
- Scan all source files that import from Pi packages:
50
- 1. Find all \`.ts\` and \`.tsx\` files that import from \`@mariozechner/pi-*\`
51
- 2. For each file, identify API usage that needs updating based on changelog/docs
52
- 3. Check overridden tools or tool wrappers for delegated \`tool.execute(...)\` calls; update forwarded parameter order and optional args
53
- 4. Note deprecated patterns or new recommended approaches
54
- 5. Look for custom utility functions that duplicate functionality now available in the Pi SDK -- if the SDK provides an equivalent, flag it for replacement
55
-
56
- ### 5. Create Update Plan
57
-
58
- Present a detailed plan:
59
- - Package version updates needed (in root and any sub-package.json files with peerDependencies)
60
- - For each affected file:
61
- - Specific API migrations required
62
- - Breaking changes and how to address them
63
- - New features from the changelog that could improve existing code
64
- - Custom utilities replaceable by SDK exports
65
-
66
- ### 6. User Confirmation
67
-
68
- Present the plan and ask for confirmation before proceeding. Wait for feedback. Iterate on the plan based on user input until agreement is reached.
69
-
70
- ### 7. Execute Updates
71
-
72
- Once confirmed:
73
- 1. Update Pi package versions in \`./package.json\` and any sub-package files (peerDependencies) to the exact target version. Use exact versions (e.g., \`0.51.0\`), not ranges.
74
- 2. Apply the planned code changes
75
- 3. Run the install command from step 1
76
- 4. Run typecheck (\`tsc --build\` or the project's typecheck script)
77
- 5. Run lint if the project has a lint script
78
- 6. Report results and any issues encountered
79
-
80
- ### 8. Commit Changes
81
-
82
- After successful verification:
83
- 1. Check \`git status\` to see all changed files
84
- 2. Stage only files changed by this update -- do not use \`git add .\`
85
- 3. Commit with message format: \`chore: update pi packages to X.Y.Z\`
86
- 4. Include a brief summary of breaking changes addressed in the commit body
87
-
88
- ## Fallback
89
-
90
- If the extension tools (\`pi_changelog\`, \`pi_docs\`, \`detect_package_manager\`) fail -- which can happen when the very update being applied changes the tool calling convention -- fall back to:
91
- - Changelog: read \`CHANGELOG.md\` from the Pi installation directory
92
- - Docs: read \`README.md\` and list \`docs/\` from the Pi installation directory
93
- - Package manager: check for lockfiles manually (\`pnpm-lock.yaml\`, \`yarn.lock\`, \`package-lock.json\`, \`bun.lockb\`)
94
-
95
- ## Important
96
-
97
- - Preserve existing functionality while updating to new APIs
98
- - Keep changes minimal and focused on API compatibility
99
- - If unsure about a migration, ask for clarification`;
25
+ Update this project's Pi extensions, themes, skills, prompt templates, and package metadata to the specified target Pi version.
26
+
27
+ ## Operating Rules
28
+
29
+ - Keep the update focused on Pi compatibility and current extension best practices.
30
+ - Read the relevant Pi docs before changing code. Follow linked docs when a page points to them.
31
+ - Present a concrete plan and wait for user confirmation before editing files.
32
+ - If a migration is ambiguous or changes public behavior, ask the user instead of guessing.
33
+ - Preserve existing extension behavior unless the target Pi version requires a change.
34
+
35
+ ## 1. Detect Package Manager
36
+
37
+ Use \`detect_package_manager\` to identify npm, pnpm, yarn, or bun. Use the detected install and run commands for every later step.
38
+
39
+ ## 2. Inspect Package State
40
+
41
+ Read \`./package.json\` and any sub-package \`package.json\` files. Find Pi core packages in all dependency sections, peer dependency metadata, pnpm overrides, imports, docs, and examples.
42
+
43
+ Current Pi core packages are:
44
+ - \`@earendil-works/pi-coding-agent\`
45
+ - \`@earendil-works/pi-agent-core\`
46
+ - \`@earendil-works/pi-ai\`
47
+ - \`@earendil-works/pi-tui\`
48
+ - \`typebox\`
49
+
50
+ Legacy packages under \`@mariozechner/*\` may still be present. Treat them as Pi core packages. Prefer \`@earendil-works/*\` when the target version exists on npm; if the new namespace is not published for the target version yet, keep the legacy namespace and report that decision.
51
+
52
+ For distributed Pi packages:
53
+ - Put imported Pi core packages in \`peerDependencies\` with \`"*"\` and mark each one \`optional: true\` in \`peerDependenciesMeta\`.
54
+ - Keep the same Pi core packages in \`devDependencies\` at the exact target version for local type checking.
55
+ - Keep \`typebox\` 1.x. Do not use \`@sinclair/typebox\` in new code.
56
+
57
+ Report current versions/namespaces vs target before planning code changes. If everything already matches and no code/docs best-practice updates are needed, stop.
58
+
59
+ ## 3. Gather Pi Documentation
60
+
61
+ If an update is needed:
62
+ 1. Use \`pi_changelog_versions\` and \`pi_changelog\` for every version between the current and target versions.
63
+ 2. Use \`pi_docs\` to locate installed Pi docs.
64
+ 3. Read relevant docs completely before editing, especially:
65
+ - \`docs/extensions.md\`
66
+ - \`docs/tui.md\` for components and renderers
67
+ - \`docs/packages.md\` for package metadata and peer dependency rules
68
+ - \`docs/custom-provider.md\` and \`docs/models.md\` for providers
69
+ - \`docs/rpc.md\` when UI or mode behavior is touched
70
+ - \`docs/skills.md\` when package skills are touched
71
+ 4. Read examples that match the changed area, not just the docs.
72
+
73
+ ## 4. Analyze Source and Docs
74
+
75
+ Scan all source, tests, README, skills, prompts, and examples for Pi usage.
76
+
77
+ For tools, verify:
78
+ - Standalone tool objects use \`defineTool({...})\` from Pi so \`execute\`, \`renderCall\`, and \`renderResult\` infer params from \`parameters\`. Do not pass explicit generic arguments to \`defineTool\` and avoid callback parameter annotations unless TypeScript needs help.
79
+ - Define \`type MyToolParams = Static<typeof parameters>\` for helper/action APIs, but prefer inference inside \`defineTool\` callbacks.
80
+ - Every tool has \`label\`. Add \`promptSnippet\` when the tool should appear in Available tools.
81
+ - Every \`promptGuidelines\` bullet names the exact tool, because Pi injects bullets flat into the global Guidelines section. Do not write "this tool".
82
+ - Execute signature is \`(toolCallId, params, signal, onUpdate, ctx)\`; signal comes before \`onUpdate\`.
83
+ - Use \`onUpdate?.(...)\` and forward \`signal\` to \`fetch\`, \`pi.exec\`, SDK clients, and long work.
84
+ - Use \`StringEnum\` from \`@earendil-works/pi-ai\`/legacy \`@mariozechner/pi-ai\` for string enums; avoid \`Type.Union([Type.Literal(...)])\` for model-facing enums.
85
+ - Use \`prepareArguments(args)\` only for backward-compatible schema shims before validation.
86
+ - Use \`executionMode: "sequential"\` for tools whose sibling calls mutate shared in-memory state or otherwise must not run concurrently.
87
+ - File-mutating tools normalize leading \`@\` in paths and wrap the full read-modify-write window in \`withFileMutationQueue()\`.
88
+ - Tools returning large output use \`truncateHead\` or \`truncateTail\`, tell the LLM what was truncated, and write full output to a temp file.
89
+ - Do not use Node \`child_process\` for normal commands; use \`pi.exec(command, args, { signal, cwd, timeout })\`.
90
+
91
+ For rendering and TUI, verify:
92
+ - \`renderCall\` and \`renderResult\` return Pi TUI \`Component\` objects, not raw strings.
93
+ - \`renderResult\` handles \`options.isPartial\` first with a stable tool-scoped message.
94
+ - Tool errors are detected via missing expected fields in \`details\` or the 4th render context \`context.isError\`.
95
+ - Use \`ToolCallHeader\`, \`ToolBody\`, and \`ToolFooter\` consistently. Omit empty footers.
96
+ - Use \`keyHint("app.tools.expand", "to expand")\` for expand hints.
97
+ - Use \`Container\`, \`Text\`, \`Markdown\`, \`SelectList\`, \`SettingsList\`, \`BorderedLoader\`, and \`DynamicBorder\` before writing custom UI.
98
+ - Custom components implement \`render(width): string[]\`, \`handleInput(data)\`, and \`invalidate()\`; use \`matchesKey\` and keep rendered lines within width.
99
+ - \`ctx.ui.custom()\` has RPC/print fallback and interactive close paths use explicit sentinels such as \`null\` or \`"closed"\`, not \`done(undefined)\`.
100
+
101
+ For extension APIs, verify:
102
+ - Hook return shapes match current Pi docs: \`input\` returns \`{ action: "continue" | "transform" | "handled", ... }\`; \`before_agent_start\` returns \`{ systemPrompt }\`; \`tool_result\` returns result patches.
103
+ - Session replacement uses \`withSession\` after \`ctx.newSession()\`, \`ctx.fork()\`, or \`ctx.switchSession()\`; do not reuse captured old \`pi\`, command \`ctx\`, or \`ctx.sessionManager\`.
104
+ - Reload command handlers treat \`await ctx.reload(); return;\` as terminal.
105
+ - Fire-and-forget UI methods do not need \`ctx.hasUI\`; dialog methods that gate behavior do.
106
+ - Providers use current \`pi.registerProvider(name, config)\`, \`name\`, \`authHeader\`, OAuth, per-model \`baseUrl\`, and \`thinkingLevelMap\` when relevant. Dynamic model discovery belongs in an async extension factory, not \`session_start\`.
107
+ - Use SDK helpers for Pi paths instead of \`homedir()\` when helpers exist.
108
+
109
+ For project structure and package docs, verify:
110
+ - Prefer one extension entry point per feature directory: \`src/tools/index.ts\`, \`src/commands/index.ts\`, \`src/hooks/index.ts\`, \`src/providers/index.ts\`.
111
+ - Avoid a root \`src/index.ts\` fan-out registrar for new code.
112
+ - Keep domain logic in Pi-free core modules and tools as thin wrappers.
113
+ - Config uses TypeScript raw/resolved interfaces with \`ConfigLoader<Raw, Resolved>\`, not TypeBox schemas.
114
+ - No \`.js\` suffixes in TypeScript imports.
115
+
116
+ ## 5. Create Update Plan
117
+
118
+ Present a detailed plan with:
119
+ - Package namespace/version changes and whether \`@earendil-works/*\` is available for the target.
120
+ - Files to change and why.
121
+ - API migrations required by changelogs/docs.
122
+ - Best-practice cleanups found in source, README, skills, prompts, and examples.
123
+ - Verification commands to run.
124
+
125
+ Ask for confirmation before editing.
126
+
127
+ ## 6. Execute After Confirmation
128
+
129
+ After the user confirms:
130
+ 1. Apply package metadata changes.
131
+ 2. Apply source/docs/skill/prompt changes.
132
+ 3. Run the detected install command.
133
+ 4. Run typecheck.
134
+ 5. Run lint if available.
135
+ 6. Report changed files, verification results, and any remaining risks.
136
+
137
+ ## 7. Commit Changes When Asked
138
+
139
+ Only commit if the user asks. If committing:
140
+ 1. Run \`git status\`.
141
+ 2. Stage only files changed for this update; never use \`git add .\`.
142
+ 3. Follow the repository's commit style, defaulting to \`chore: update pi packages to X.Y.Z\`.
143
+ 4. Include a short body listing breaking changes handled.
144
+
145
+ ## Fallbacks
146
+
147
+ If \`pi_changelog\`, \`pi_docs\`, or \`detect_package_manager\` fail, manually inspect the installed Pi package directory, its \`CHANGELOG.md\`, \`README.md\`, \`docs/\`, \`examples/\`, lockfiles, and \`package.json\`.`;
100
148
 
101
149
  export function registerUpdateCommand(pi: ExtensionAPI) {
102
150
  pi.registerCommand("extensions:update", {