pi-skill-watch 0.0.0-stage → 0.1.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/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +64 -2
- package/extensions/skill-watch.ts +267 -0
- package/package.json +24 -4
- package/test/skill-watch.test.mjs +43 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-11-19
|
|
4
|
+
|
|
5
|
+
- Initial Pi extension package.
|
|
6
|
+
- Discover skills from standard user-level skill roots.
|
|
7
|
+
- Track GitHub sources from the Agent Skills lockfile and documented defaults.
|
|
8
|
+
- Report diffs without modifying installed files.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 笙歌落尽
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pi Skill Watch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Pi extension that checks installed skills against known GitHub upstreams and reports differences. **Checks never modify skill files.** Review the report, then decide whether and how to update a skill.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pi install npm:pi-skill-watch
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package is eligible for the Pi package gallery via the `pi-package` npm keyword.
|
|
12
|
+
|
|
13
|
+
## What it tracks
|
|
14
|
+
|
|
15
|
+
The extension recursively discovers `SKILL.md` directories in these user-level roots when present:
|
|
16
|
+
|
|
17
|
+
- `~/.pi/agent/skills`
|
|
18
|
+
- `~/.agents/skills`
|
|
19
|
+
- `~/.claude/skills`
|
|
20
|
+
- `~/.codex/skills`
|
|
21
|
+
|
|
22
|
+
For upstreams it reads `~/.agents/.skill-lock.json` entries whose source is GitHub. It also knows the official Anthropic `frontend-design`, `pdf`, `skill-creator` skills and `ppt-master`, which are commonly installed without a lockfile. Other skills without source metadata are reported as local-only; the extension will not guess their upstream.
|
|
23
|
+
|
|
24
|
+
You can add sources in `~/.pi/agent/skill-upstream-sources.json`:
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"my-skill": {
|
|
29
|
+
"repo": "owner/repository",
|
|
30
|
+
"skillPath": "skills/my-skill/SKILL.md",
|
|
31
|
+
"ref": "main"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`ref` is optional. When omitted, the repository's default branch is checked. A configured tag or commit stays pinned; the extension will not move it.
|
|
37
|
+
|
|
38
|
+
## Commands and notifications
|
|
39
|
+
|
|
40
|
+
- On Pi session start, check at most once per 24 hours.
|
|
41
|
+
- `/skill-updates` forces a fresh upstream check and shows differing file paths.
|
|
42
|
+
- First-run local differences are reported as a baseline difference, not as proof that a new update is available.
|
|
43
|
+
- Network/API failures are reported and do not prevent Pi from starting.
|
|
44
|
+
|
|
45
|
+
The cache is stored under `~/.pi/agent/pi-skill-watch/state.json`. No skill contents, absolute local paths, credentials, or lockfile data are written to the package or sent to the tracker service; checks only request public GitHub tree metadata.
|
|
46
|
+
|
|
47
|
+
## Privacy and safety
|
|
48
|
+
|
|
49
|
+
- No silent updates or file writes to installed skills.
|
|
50
|
+
- No third-party runtime dependencies.
|
|
51
|
+
- GitHub requests are read-only and rate-limited by the daily cache.
|
|
52
|
+
- Package-managed resources should continue to use Pi's package manager (`pi update --extensions`).
|
|
53
|
+
|
|
54
|
+
## Development
|
|
55
|
+
|
|
56
|
+
Requires Node.js 22.6+ (for built-in TypeScript stripping in tests).
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
npm test
|
|
60
|
+
npm pack --dry-run
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as os from "node:os";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
|
|
7
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
8
|
+
const HOME = os.homedir();
|
|
9
|
+
const STATE_PATH = path.join(HOME, ".pi", "agent", "pi-skill-watch", "state.json");
|
|
10
|
+
const LOCK_PATH = path.join(HOME, ".agents", ".skill-lock.json");
|
|
11
|
+
const SOURCES_PATH = path.join(HOME, ".pi", "agent", "skill-upstream-sources.json");
|
|
12
|
+
const SKILL_ROOTS = [".pi/agent/skills", ".agents/skills", ".claude/skills", ".codex/skills"].map((p) => path.join(HOME, p));
|
|
13
|
+
const SKIP_DIRS = new Set([".git", "node_modules", ".venv", "__pycache__", ".cache"]);
|
|
14
|
+
const DEFAULT_SOURCES: Record<string, Upstream> = {
|
|
15
|
+
"frontend-design": { repo: "anthropics/skills", skillPath: "skills/frontend-design/SKILL.md" },
|
|
16
|
+
pdf: { repo: "anthropics/skills", skillPath: "skills/pdf/SKILL.md" },
|
|
17
|
+
"skill-creator": { repo: "anthropics/skills", skillPath: "skills/skill-creator/SKILL.md" },
|
|
18
|
+
"ppt-master": { repo: "hugohe3/ppt-master", skillPath: "skills/ppt-master/SKILL.md" },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type Upstream = { repo: string; skillPath: string; ref?: string };
|
|
22
|
+
type LockEntry = { sourceType?: string; sourceUrl?: string; source?: string; skillPath?: string; ref?: string };
|
|
23
|
+
type Skill = { name: string; directory: string; source?: Upstream; pinned: boolean };
|
|
24
|
+
type Snapshot = { fingerprint: string; files: Record<string, string>; pending?: string[]; checkedAt: number };
|
|
25
|
+
type State = { checkedAt?: number; skills: Record<string, Snapshot> };
|
|
26
|
+
type CheckResult = { state: State; changed: string[]; localOnly: string[]; trackedCount: number; errors: string[]; skipped: boolean };
|
|
27
|
+
|
|
28
|
+
function parseRepo(value?: string): string | undefined {
|
|
29
|
+
if (!value) return undefined;
|
|
30
|
+
let candidate = value.trim();
|
|
31
|
+
if (candidate.startsWith("https://") || candidate.startsWith("http://")) {
|
|
32
|
+
try {
|
|
33
|
+
const url = new URL(candidate);
|
|
34
|
+
if (url.hostname.toLowerCase() !== "github.com") return undefined;
|
|
35
|
+
candidate = url.pathname.split("/").filter(Boolean).join("/");
|
|
36
|
+
} catch { return undefined; }
|
|
37
|
+
} else if (candidate.toLowerCase().startsWith("git@github.com:")) {
|
|
38
|
+
candidate = candidate.slice("git@github.com:".length);
|
|
39
|
+
}
|
|
40
|
+
if (candidate.toLowerCase().endsWith(".git")) candidate = candidate.slice(0, -4);
|
|
41
|
+
const parts = candidate.split("/");
|
|
42
|
+
return parts.length === 2 && parts.every(Boolean) ? candidate : undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function parseLockfile(text: string): Record<string, Upstream> {
|
|
46
|
+
const parsed = JSON.parse(text) as { skills?: Record<string, LockEntry> };
|
|
47
|
+
const result: Record<string, Upstream> = {};
|
|
48
|
+
for (const [name, entry] of Object.entries(parsed.skills ?? {})) {
|
|
49
|
+
if (entry.sourceType !== "github" || !entry.skillPath) continue;
|
|
50
|
+
const repo = parseRepo(entry.sourceUrl) ?? parseRepo(entry.source);
|
|
51
|
+
if (repo) result[name] = { repo, skillPath: entry.skillPath, ...(entry.ref ? { ref: entry.ref } : {}) };
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readJson<T>(file: string, fallback: T): T {
|
|
57
|
+
try { return JSON.parse(fs.readFileSync(file, "utf8")) as T; }
|
|
58
|
+
catch { return fallback; }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function skillName(skillFile: string, directory: string): string {
|
|
62
|
+
try {
|
|
63
|
+
const text = fs.readFileSync(skillFile, "utf8");
|
|
64
|
+
const frontmatter = text.match(/^---\s*\r?\n([\s\S]*?)\r?\n---/);
|
|
65
|
+
const match = frontmatter?.[1].match(/^name:\s*["']?([^\r\n"']+)/m);
|
|
66
|
+
if (match?.[1]) return match[1].trim();
|
|
67
|
+
} catch { /* use directory name */ }
|
|
68
|
+
return path.basename(directory);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function discoverSkills(roots: string[]): Skill[] {
|
|
72
|
+
const found = new Map<string, Skill>();
|
|
73
|
+
for (const root of roots) {
|
|
74
|
+
if (!fs.existsSync(root)) continue;
|
|
75
|
+
const walk = (directory: string) => {
|
|
76
|
+
let entries: fs.Dirent[];
|
|
77
|
+
try { entries = fs.readdirSync(directory, { withFileTypes: true }); }
|
|
78
|
+
catch { return; }
|
|
79
|
+
if (entries.some((entry) => entry.isFile() && entry.name.toLowerCase() === "skill.md")) {
|
|
80
|
+
const file = path.join(directory, entries.find((entry) => entry.isFile() && entry.name.toLowerCase() === "skill.md")!.name);
|
|
81
|
+
const name = skillName(file, directory);
|
|
82
|
+
const key = name.toLowerCase();
|
|
83
|
+
if (!found.has(key)) found.set(key, { name, directory, pinned: false });
|
|
84
|
+
}
|
|
85
|
+
for (const entry of entries) {
|
|
86
|
+
if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) walk(path.join(directory, entry.name));
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
walk(root);
|
|
90
|
+
}
|
|
91
|
+
return [...found.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function gitBlobHash(bytes: Buffer, relativePath: string): string {
|
|
95
|
+
const textExtensions = /\.(md|txt|json|ya?ml|toml|ini|py|js|mjs|cjs|ts|tsx|jsx|sh|ps1|html|css|xml|csv|svg)$/i;
|
|
96
|
+
const content = textExtensions.test(relativePath) ? Buffer.from(bytes.toString("utf8").replace(/\r\n/g, "\n"), "utf8") : bytes;
|
|
97
|
+
return createHash("sha1").update(Buffer.from(`blob ${content.length}\0`)).update(content).digest("hex");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function collectLocalFiles(root: string): Record<string, string> {
|
|
101
|
+
const result: Record<string, string> = {};
|
|
102
|
+
if (!fs.existsSync(root)) return result;
|
|
103
|
+
const walk = (directory: string, prefix = "") => {
|
|
104
|
+
let entries: fs.Dirent[];
|
|
105
|
+
try { entries = fs.readdirSync(directory, { withFileTypes: true }); }
|
|
106
|
+
catch { return; }
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
if (entry.isSymbolicLink()) continue;
|
|
109
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
110
|
+
const full = path.join(directory, entry.name);
|
|
111
|
+
if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) walk(full, relative);
|
|
112
|
+
else if (entry.isFile()) {
|
|
113
|
+
try { result[relative] = gitBlobHash(fs.readFileSync(full), relative); }
|
|
114
|
+
catch { /* unreadable files are excluded; the rest of the skill remains checkable */ }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
walk(root);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function diffFiles(local: Record<string, string>, remote: Record<string, string>): string[] {
|
|
123
|
+
return [...new Set([...Object.keys(local), ...Object.keys(remote)])]
|
|
124
|
+
.filter((file) => local[file] !== remote[file]).sort();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function fingerprint(files: Record<string, string>): string {
|
|
128
|
+
const canonical = Object.entries(files).sort(([a], [b]) => a.localeCompare(b)).map(([p, h]) => `${p}\0${h}`).join("\n");
|
|
129
|
+
return createHash("sha256").update(canonical).digest("hex");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function loadSources(): Record<string, Upstream> {
|
|
133
|
+
let locked: Record<string, Upstream> = {};
|
|
134
|
+
try { locked = parseLockfile(fs.readFileSync(LOCK_PATH, "utf8")); }
|
|
135
|
+
catch { /* lockfile is optional */ }
|
|
136
|
+
const custom = readJson<Record<string, Upstream>>(SOURCES_PATH, {});
|
|
137
|
+
return { ...DEFAULT_SOURCES, ...locked, ...custom };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function loadState(): State {
|
|
141
|
+
const state = readJson<State>(STATE_PATH, { skills: {} });
|
|
142
|
+
return state && typeof state.skills === "object" ? state : { skills: {} };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function saveState(state: State): void {
|
|
146
|
+
fs.mkdirSync(path.dirname(STATE_PATH), { recursive: true });
|
|
147
|
+
const temporary = `${STATE_PATH}.${process.pid}.tmp`;
|
|
148
|
+
fs.writeFileSync(temporary, `${JSON.stringify(state, null, 2)}\n`, "utf8");
|
|
149
|
+
fs.renameSync(temporary, STATE_PATH);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function repoDefaultBranch(repo: string): Promise<string> {
|
|
153
|
+
const response = await fetch(`https://api.github.com/repos/${repo}`, {
|
|
154
|
+
headers: { Accept: "application/vnd.github+json", "User-Agent": "pi-skill-watch" },
|
|
155
|
+
signal: AbortSignal.timeout(12_000),
|
|
156
|
+
});
|
|
157
|
+
if (!response.ok) throw new Error(`${repo}: GitHub HTTP ${response.status}`);
|
|
158
|
+
const body = await response.json() as { default_branch?: string };
|
|
159
|
+
if (!body.default_branch) throw new Error(`${repo}: missing default branch`);
|
|
160
|
+
return body.default_branch;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function getRepoTree(repo: string, ref: string): Promise<Record<string, string>> {
|
|
164
|
+
const response = await fetch(`https://api.github.com/repos/${repo}/git/trees/${encodeURIComponent(ref)}?recursive=1`, {
|
|
165
|
+
headers: { Accept: "application/vnd.github+json", "User-Agent": "pi-skill-watch" },
|
|
166
|
+
signal: AbortSignal.timeout(20_000),
|
|
167
|
+
});
|
|
168
|
+
if (!response.ok) throw new Error(`${repo}@${ref}: GitHub HTTP ${response.status}`);
|
|
169
|
+
const body = await response.json() as { truncated?: boolean; tree?: Array<{ path: string; type: string; sha: string }> };
|
|
170
|
+
if (body.truncated || !Array.isArray(body.tree)) throw new Error(`${repo}@${ref}: incomplete GitHub tree`);
|
|
171
|
+
return Object.fromEntries(body.tree.filter((item) => item.type === "blob").map((item) => [item.path, item.sha]));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function checkUpstreams(force: boolean): Promise<CheckResult> {
|
|
175
|
+
const state = loadState();
|
|
176
|
+
if (!force && state.checkedAt && Date.now() - state.checkedAt < DAY_MS) {
|
|
177
|
+
return { state, changed: [], localOnly: [], trackedCount: Object.keys(state.skills).length, errors: [], skipped: true };
|
|
178
|
+
}
|
|
179
|
+
const sources = loadSources();
|
|
180
|
+
const skills = discoverSkills(SKILL_ROOTS).map((skill) => {
|
|
181
|
+
const source = sources[skill.name];
|
|
182
|
+
return { ...skill, source, pinned: !!source?.ref };
|
|
183
|
+
});
|
|
184
|
+
const localOnly = skills.filter((skill) => !skill.source).map((skill) => skill.name);
|
|
185
|
+
const trackedSkills = skills.filter((skill) => skill.source);
|
|
186
|
+
const activeNames = new Set(trackedSkills.map((skill) => skill.name));
|
|
187
|
+
for (const name of Object.keys(state.skills)) if (!activeNames.has(name)) delete state.skills[name];
|
|
188
|
+
const treeCache = new Map<string, Promise<Record<string, string>>>();
|
|
189
|
+
const defaultCache = new Map<string, Promise<string>>();
|
|
190
|
+
const getTree = (source: Upstream) => {
|
|
191
|
+
const branchPromise = source.ref ? Promise.resolve(source.ref) : defaultCache.get(source.repo) ?? repoDefaultBranch(source.repo);
|
|
192
|
+
if (!source.ref && !defaultCache.has(source.repo)) defaultCache.set(source.repo, branchPromise);
|
|
193
|
+
const key = `${source.repo}@${source.ref ?? "HEAD"}`;
|
|
194
|
+
let promise = treeCache.get(key);
|
|
195
|
+
if (!promise) {
|
|
196
|
+
promise = branchPromise.then((branch) => getRepoTree(source.repo, branch));
|
|
197
|
+
treeCache.set(key, promise);
|
|
198
|
+
}
|
|
199
|
+
return promise;
|
|
200
|
+
};
|
|
201
|
+
const checks = await Promise.all(trackedSkills.map(async (skill) => {
|
|
202
|
+
const source = skill.source!;
|
|
203
|
+
try {
|
|
204
|
+
const tree = await getTree(source);
|
|
205
|
+
const directory = path.posix.dirname(source.skillPath);
|
|
206
|
+
const prefix = directory === "." ? "" : `${directory}/`;
|
|
207
|
+
const remote = Object.fromEntries(Object.entries(tree).filter(([p]) => p.startsWith(prefix)).map(([p, sha]) => [p.slice(prefix.length), sha]));
|
|
208
|
+
if (!Object.keys(remote).length) throw new Error(`${skill.name}: upstream skill path not found (${source.repo}/${source.skillPath})`);
|
|
209
|
+
const local = collectLocalFiles(skill.directory);
|
|
210
|
+
const fileDiff = diffFiles(local, remote);
|
|
211
|
+
const remoteFingerprint = fingerprint(remote);
|
|
212
|
+
const previous = state.skills[skill.name];
|
|
213
|
+
const upstreamChanged = !!previous && previous.fingerprint !== remoteFingerprint;
|
|
214
|
+
const firstDivergence = !previous && fileDiff.length > 0;
|
|
215
|
+
const pending = fileDiff.length ? fileDiff : undefined;
|
|
216
|
+
state.skills[skill.name] = { fingerprint: remoteFingerprint, files: remote, ...(pending ? { pending } : {}), checkedAt: Date.now() };
|
|
217
|
+
return { name: skill.name, changed: fileDiff.length > 0 && (upstreamChanged || firstDivergence), firstDivergence, upstreamChanged, error: undefined as string | undefined };
|
|
218
|
+
} catch (error) {
|
|
219
|
+
return { name: skill.name, changed: false, firstDivergence: false, upstreamChanged: false, error: error instanceof Error ? error.message : String(error) };
|
|
220
|
+
}
|
|
221
|
+
}));
|
|
222
|
+
if (checks.some((check) => !check.error)) { state.checkedAt = Date.now(); saveState(state); }
|
|
223
|
+
return {
|
|
224
|
+
state,
|
|
225
|
+
changed: checks.filter((check) => check.changed).map((check) => check.name),
|
|
226
|
+
localOnly,
|
|
227
|
+
trackedCount: trackedSkills.length,
|
|
228
|
+
errors: checks.flatMap((check) => check.error ? [check.error] : []),
|
|
229
|
+
skipped: false,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function makeReport(result: CheckResult): string {
|
|
234
|
+
const rows = ["Skill upstream report — checks only; installed files are never changed."];
|
|
235
|
+
const pending = Object.entries(result.state.skills).filter(([, value]) => value.pending);
|
|
236
|
+
if (pending.length) {
|
|
237
|
+
for (const [name, value] of pending) {
|
|
238
|
+
const skill = discoverSkills(SKILL_ROOTS).find((item) => item.name === name);
|
|
239
|
+
const pinned = skill && loadSources()[name]?.ref ? " (pinned ref)" : "";
|
|
240
|
+
rows.push(`• ${name}${pinned}: ${value.pending!.length} differing files — ${value.pending!.slice(0, 5).join(", ")}${value.pending!.length > 5 ? " …" : ""}`);
|
|
241
|
+
}
|
|
242
|
+
} else if (!result.errors.length) rows.push("All tracked skills match their configured upstream snapshots.");
|
|
243
|
+
rows.push(`Discovered ${result.trackedCount + result.localOnly.length} skills; ${result.trackedCount} have an upstream and ${result.localOnly.length} are local-only.`);
|
|
244
|
+
if (result.localOnly.length) rows.push(`Local-only: ${result.localOnly.slice(0, 15).join(", ")}${result.localOnly.length > 15 ? " …" : ""}`);
|
|
245
|
+
if (result.errors.length) rows.push(`Check errors: ${result.errors.join("; ")}`);
|
|
246
|
+
rows.push("Review differences before asking Pi to update a skill. No automatic updates are performed.");
|
|
247
|
+
return rows.join("\n");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export default function (pi: ExtensionAPI) {
|
|
251
|
+
pi.on("session_start", (_event, ctx) => {
|
|
252
|
+
if (!ctx.hasUI) return;
|
|
253
|
+
void checkUpstreams(false).then((result) => {
|
|
254
|
+
if (result.changed.length) ctx.ui.notify(`Skill upstream differences found: ${result.changed.join(", ")}. Run /skill-updates to review; nothing was overwritten.`, "warning");
|
|
255
|
+
else if (result.errors.length) ctx.ui.notify(`Skill upstream check incomplete: ${result.errors.join("; ")}`, "warning");
|
|
256
|
+
}).catch((error) => console.warn(`[pi-skill-watch] ${String(error)}`));
|
|
257
|
+
});
|
|
258
|
+
pi.registerCommand("skill-updates", {
|
|
259
|
+
description: "Check installed skills against known GitHub upstreams; report only",
|
|
260
|
+
handler: async (_args, ctx) => {
|
|
261
|
+
const result = await checkUpstreams(true);
|
|
262
|
+
const text = makeReport(result);
|
|
263
|
+
if (ctx.hasUI) ctx.ui.notify(text, result.errors.length ? "warning" : "info");
|
|
264
|
+
else console.log(text);
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-skill-watch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Find upstream changes for installed Pi and Agent Skills without silently overwriting local files.",
|
|
5
|
+
"author": "笙歌落尽",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"keywords": ["pi-package", "pi", "pi-extension", "agent-skills", "upstream-tracker"],
|
|
9
|
+
"files": [
|
|
10
|
+
"extensions/skill-watch.ts",
|
|
11
|
+
"test/",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"CHANGELOG.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node --experimental-strip-types --test"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
21
|
+
},
|
|
22
|
+
"pi": {
|
|
23
|
+
"extensions": ["./extensions/skill-watch.ts"],
|
|
24
|
+
"changelogPath": "./CHANGELOG.md"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import { collectLocalFiles, diffFiles, discoverSkills, gitBlobHash, parseLockfile } from "../extensions/skill-watch.ts";
|
|
7
|
+
|
|
8
|
+
test("parseLockfile keeps GitHub sources and pinned refs, ignores local skills", () => {
|
|
9
|
+
const entries = parseLockfile(JSON.stringify({ skills: {
|
|
10
|
+
alpha: { sourceType: "github", sourceUrl: "https://github.com/acme/skills.git", skillPath: "skills/alpha/SKILL.md", ref: "v1" },
|
|
11
|
+
beta: { sourceType: "github", source: "other/repo", skillPath: "beta/SKILL.md" },
|
|
12
|
+
local: { sourceType: "local", sourceUrl: "C:/private", skillPath: "local/SKILL.md" },
|
|
13
|
+
broken: { sourceType: "github", sourceUrl: "https://example.com/a/b", skillPath: "broken/SKILL.md" },
|
|
14
|
+
} }));
|
|
15
|
+
assert.deepEqual(entries, {
|
|
16
|
+
alpha: { repo: "acme/skills", skillPath: "skills/alpha/SKILL.md", ref: "v1" },
|
|
17
|
+
beta: { repo: "other/repo", skillPath: "beta/SKILL.md" },
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("discoverSkills recursively finds SKILL.md and uses its frontmatter name", (t) => {
|
|
22
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "pi-skill-discovery-"));
|
|
23
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
24
|
+
const folder = path.join(root, "nested", "folder-name");
|
|
25
|
+
mkdirSync(folder, { recursive: true });
|
|
26
|
+
writeFileSync(path.join(folder, "SKILL.md"), "---\nname: canonical-name\ndescription: test\n---\nbody\n");
|
|
27
|
+
mkdirSync(path.join(root, "node_modules", "ignored"), { recursive: true });
|
|
28
|
+
writeFileSync(path.join(root, "node_modules", "ignored", "SKILL.md"), "---\nname: should-ignore\n---\n");
|
|
29
|
+
assert.deepEqual(discoverSkills([root]).map(({ name }) => name), ["canonical-name"]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("local file hashes normalize CRLF to the GitHub text blob representation", (t) => {
|
|
33
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "pi-skill-hash-"));
|
|
34
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
35
|
+
writeFileSync(path.join(root, "SKILL.md"), "line one\r\nline two\r\n");
|
|
36
|
+
const files = collectLocalFiles(root);
|
|
37
|
+
assert.equal(files["SKILL.md"], gitBlobHash(Buffer.from("line one\nline two\n"), "SKILL.md"));
|
|
38
|
+
assert.equal(files["SKILL.md"], "e5c5c5583f49a34e86ce622b59363df99e09d4c6");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("diffFiles reports additions, deletions, and edits deterministically", () => {
|
|
42
|
+
assert.deepEqual(diffFiles({ a: "same", b: "old" }, { a: "same", c: "new" }), ["b", "c"]);
|
|
43
|
+
});
|