Skip to content

fix(amp): restore root plugin entry in install script - #488

Open
IceCodeNew wants to merge 2 commits into
nowledge-co:mainfrom
IceCodeNew:fix/amp-install-root-entry
Open

fix(amp): restore root plugin entry in install script#488
IceCodeNew wants to merge 2 commits into
nowledge-co:mainfrom
IceCodeNew:fix/amp-install-root-entry

Conversation

@IceCodeNew

@IceCodeNew IceCodeNew commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Problem

The install script hardened in 0c7ee11 added atomic staging/rollback but silently dropped the Amp-discoverable root plugin entry (plugins/nowledge-mem.ts). Amp only loads single-file plugins from a root .ts/.js entry inside the plugins directory (a root foo.ts masks a foo/ directory — see Amp Owner's Manual). With only the bundle dir installed, amp plugins list shows nothing and the plugin never loads.

The README (line 35) and the zh integration doc both correctly describe the root entry — the script regressed, not the docs. The same commit also removed the static-contract assertions for the entry, which is how it slipped past CI.

Root cause

Commit 0c7ee116 ("fix(amp): harden bootstrap and capture follow-up") rewrote install.sh with STAGING_DIR/BACKUP_*/restore_previous/install_staged, but the rewrite only copied the bundle dir and omitted the root entry that the prior merge had installed.

Fix

Restore the root entry inside the existing atomic flow (keeps all the proven rollback safety):

  • nowledge-mem-amp-plugin/scripts/install.sh
    • Add PLUGIN_ENTRY_DEST, stage entry.ts with export { default } from "./nowledge-mem/src/index.ts".
    • Extend restore_previous and install_staged to back up / move / restore the entry alongside the bundle and skill — any step failing restores all three (no partial update state).
    • Add pre-flight checks for the staged entry (exists + correct re-export).
    • Re-run is a safe atomic update of entry + bundle + skill. XDG_CONFIG_HOME support unchanged.
    • No uninstall/clean mode exists; none added (the script is install+update only, matching integrations.json).

Out of scope

  • The zh integration doc at mem.nowledge.co is external to this repo and already correct — no change needed.
  • No changes to bootstrap/sync/messages TS logic.

Summary by CodeRabbit

  • New Features

    • Amp plugin installation now creates a root plugin entry alongside the bundled plugin and skill.
    • Installation status and validation now account for the complete plugin layout.
  • Bug Fixes

    • Failed installations safely preserve the existing plugin, entry file, and skill.
    • Repeated installations remain stable without disrupting an existing setup.
  • Documentation

    • Updated troubleshooting guidance to reflect the current Amp plugin layout.

The hardened install.sh from 0c7ee11 added atomic staging/rollback but
dropped the Amp-discoverable root plugin entry (plugins/nowledge-mem.ts).
Amp only loads single-file plugins from a root .ts/.js entry inside the
plugins directory; a bare bundle dir is not discoverable, so
`amp plugins list` showed nothing after install. The README and the zh
integration docs both describe the root entry, so the script regressed.

Restore the entry inside the existing atomic flow:
- stage plugins/nowledge-mem.ts alongside the bundle and skill
- add it to restore_previous and install_staged so a failed step rolls
  back entry + bundle + skill together (no partial update state)
- add pre-flight checks for the staged entry
- re-run is a safe atomic update of all three

Tests:
- static contract test re-asserts PLUGIN_ENTRY_DEST/STAGED_ENTRY/BACKUP_ENTRY
  and the re-export line that 0c7ee11 removed
- new: first install creates entry+bundle+skill, entry target resolves
- new: re-run is idempotent (artifacts stable)
- new: pre-flight failure leaves a prior install untouched

README troubleshooting now points at the root entry file. The zh
integration doc already matches; no change there.
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e1a3557e-8e4c-40e0-878c-bf7f0e0de595

📥 Commits

Reviewing files that changed from the base of the PR and between 13733ab and 705c3e6.

📒 Files selected for processing (3)
  • nowledge-mem-amp-plugin/README.md
  • nowledge-mem-amp-plugin/scripts/install.sh
  • tests/plugin_e2e/test_key_plugins_e2e.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • nowledge-mem-amp-plugin/README.md
  • tests/plugin_e2e/test_key_plugins_e2e.py
  • nowledge-mem-amp-plugin/scripts/install.sh

📝 Walkthrough

Walkthrough

The Amp installer now creates a root nowledge-mem.ts entry that re-exports the bundled plugin. It stages and validates this entry, includes it in replacement and rollback, and adds end-to-end checks for installation, reinstalls, and failure recovery.

Changes

Amp plugin entry installation

Layer / File(s) Summary
Root entry contract and staging
nowledge-mem-amp-plugin/scripts/install.sh, nowledge-mem-amp-plugin/README.md, tests/plugin_e2e/test_key_plugins_e2e.py
The installer stages a root nowledge-mem.ts entry beside the bundle and skill. Validation checks its default re-export. Documentation and static tests use the updated layout.
Replacement and rollback
nowledge-mem-amp-plugin/scripts/install.sh, tests/plugin_e2e/test_key_plugins_e2e.py
Replacement backs up and installs the entry, bundle, and skill together. Rollback restores the previous installation when preflight or backup operations fail. End-to-end tests cover successful installation, idempotent reinstalls, and artifact preservation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Installer
  participant StagedSource
  participant AmpPlugins
  Installer->>StagedSource: Stage entry, bundle, and skill
  Installer->>StagedSource: Validate entry export and artifacts
  Installer->>AmpPlugins: Back up existing installation
  Installer->>AmpPlugins: Install staged artifacts
  Installer->>AmpPlugins: Restore backups on failure
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: restoring the root Amp plugin entry in the install script.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@IceCodeNew
IceCodeNew marked this pull request as ready for review August 9, 2026 12:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nowledge-mem-amp-plugin/README.md`:
- Line 136: Update the “Plugin not loading” troubleshooting instruction to use
the valid installer invocation from the community repository root: bash
nowledge-mem-amp-plugin/scripts/install.sh. Alternatively, explicitly instruct
users to change into nowledge-mem-amp-plugin before running
./scripts/install.sh.

In `@nowledge-mem-amp-plugin/scripts/install.sh`:
- Around line 46-53: The restore_previous function must not remove live
artifacts unless their backups were successfully created and replacements
occurred. Track backup and replacement success independently for the plugin
bundle, skill, and entry artifacts; conditionally remove only replaced
destinations and restore only valid backups. Add regression coverage that forces
each backup mv operation to fail and verifies the original artifacts remain
intact.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 679cf0b7-524d-49db-8a36-4cfa127e6ea1

📥 Commits

Reviewing files that changed from the base of the PR and between 0c7ee11 and 13733ab.

📒 Files selected for processing (3)
  • nowledge-mem-amp-plugin/README.md
  • nowledge-mem-amp-plugin/scripts/install.sh
  • tests/plugin_e2e/test_key_plugins_e2e.py

Comment thread nowledge-mem-amp-plugin/README.md Outdated
Comment thread nowledge-mem-amp-plugin/scripts/install.sh
CodeRabbit review of PR nowledge-co#488.

restore_previous removed PLUGIN_DEST/SKILL_DEST/PLUGIN_ENTRY_DEST
unconditionally, then restored only backups that existed. If a backup mv
failed (e.g. bundle backup at the entry-then-bundle step), the live
artifact was still in place (failed mv keeps its source), but
restore_previous deleted it and had no backup to restore from — the live
bundle/skill was destroyed.

Track each successful backup with a flag (ENTRY/BUNDLE/SKILL_BACKED_UP,
set to 1 only after the mv succeeds). restore_previous now removes only
destinations whose backup succeeded and restores only those backups, so
the rm and restore sets always match regardless of where the sequence
fails.

Also fix README troubleshooting: ./scripts/install.sh is not valid from
the repo root; use bash nowledge-mem-amp-plugin/scripts/install.sh
(matches Setup and integrations.json).

Tests:
- new test_amp_install_script_preserves_prior_install_when_backup_move_fails:
  chmod 0500 the live bundle dir so the bundle backup mv fails; assert
  prior entry+bundle+skill all intact afterwards
- existing amp tests still green

Verified: vitest 189 passed, shellcheck 0 findings, pytest -k amp 6 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant