pm-lifecycle-hooks
Default-inert lifecycle hook exemplar for package authors.
安装
已安装 pm 时
pm install lifecycle-hooks --project使用 npm,无需安装 pm
npx -y @unbrained/pm-cli install lifecycle-hooks --project使用 Bun,无需安装 pm
bunx @unbrained/pm-cli install lifecycle-hooks --projectREADME
First-party package that demonstrates lifecycle hook registration through the public pm SDK.
This package is intentionally default-inert. Its afterCommand hook returns
without producing output, writing files, or changing command behavior. Package
authors can copy this shape when they need low-risk observation hooks.
Transition-aware packages can inspect afterCommand's optional affected
entries for item mutations. Each entry includes the item id, operation,
previous/current status, changed fields, and compact item metadata snapshots.
Copy this pattern when a package needs command-level notifications without parsing command results or reading item files:
api.hooks.afterCommand((event) => {
const transitions = event.affected?.filter(
(item) => item.previous_status !== item.status && item.status !== undefined,
);
if (!transitions?.length) {
return;
}
// Notify, enqueue, or cache based on item.id, item.previous_status,
// item.status, item.changed_fields, and item.current.
});
Use afterCommand for command-level context such as notifications. Use
onWrite when a package needs file-level sync or audit behavior.
Capabilities
hooks
Install
pm install lifecycle-hooks --project
Verify
pm package doctor --project --detail deep --json
pm contracts --runtime-only --availability-only --json
来自该扩展包在 GitHub 上的 README。 在 GitHub 上查看