Skip to content

feat(workspace): add lifecycle hooks for runtime prerequisites#430

Open
christso wants to merge 2 commits into
mainfrom
feat/workspace-lifecycle-scripts
Open

feat(workspace): add lifecycle hooks for runtime prerequisites#430
christso wants to merge 2 commits into
mainfrom
feat/workspace-lifecycle-scripts

Conversation

@christso

Copy link
Copy Markdown
Contributor

Summary

  • Add lifecycleHooks.preSync to workspace config, allowing declarative shell scripts to run before plugin sync
  • Scripts run in workspace root with ALLAGENTS_WORKSPACE and ALLAGENTS_CONFIG_DIR env vars
  • Required script failure aborts sync before filesystem mutation; optional scripts log warnings and continue
  • Dry-run shows what would run without executing

Motivation

Closes all-9qx. Plugins like the Codex plugin stack require runtime prerequisites (agent-tui, bd) that AllAgents cannot sync as agent artifacts. This escape hatch lets workspaces declare idempotent install/update scripts.

Changes

  • Schema: LifecycleScriptSchema and LifecycleHooksSchema in workspace-config.ts
  • Runner: src/core/lifecycle-scripts.ts - execute scripts in order, capture output, handle failures
  • Integration: syncWorkspace runs preSync hooks before plugin validation
  • CLI: lifecycle results shown in sync output, JSON mode support
  • Tests: 29 unit/integration tests (parsing, execution, dry-run, failure, ordering, env vars, full sync flow)
  • Docs: configuration reference section + examples/workspaces/lifecycle-hooks/

E2E Steps

# Build
bun run build

# Create temp workspace with lifecycle hooks
E2E_DIR=$(mktemp -d)
mkdir -p "$E2E_DIR/.allagents"
cat > "$E2E_DIR/.allagents/workspace.yaml" << 'YAML'
version: 2
repositories: []
plugins: []
clients: [claude]
lifecycleHooks:
  preSync:
    - name: first-hook
      script: 'echo "first-ran" > .allagents/e2e-first.txt'
    - name: second-hook
      script: 'echo "second-ran" > .allagents/e2e-second.txt'
YAML

# Dry-run: shows scripts, does NOT execute
cd "$E2E_DIR" && node /path/to/dist/index.js workspace sync --dry-run
# Expect: [dry-run] would run: first-hook / second-hook
# Verify: no e2e-first.txt or e2e-second.txt created

# Real sync: scripts run in order
cd "$E2E_DIR" && node /path/to/dist/index.js workspace sync
# Expect: first-hook (✓), second-hook (✓)
# Verify: cat .allagents/e2e-first.txt → "first-ran"
# Verify: cat .allagents/e2e-second.txt → "second-ran"

# Required failure: aborts sync
cat > "$E2E_DIR/.allagents/workspace.yaml" << 'YAML'
version: 2
repositories: []
plugins: []
clients: [claude]
lifecycleHooks:
  preSync:
    - name: failing-hook
      script: 'exit 42'
    - name: should-not-run
      script: 'echo "nope" > .allagents/e2e-not.txt'
YAML
cd "$E2E_DIR" && node /path/to/dist/index.js workspace sync
# Expect: failing-hook ✗ (exit 42), should-not-run NOT executed

# Optional failure: continues
cat > "$E2E_DIR/.allagents/workspace.yaml" << 'YAML'
version: 2
repositories: []
plugins: []
clients: [claude]
lifecycleHooks:
  preSync:
    - name: optional-fail
      script: 'exit 1'
      optional: true
    - name: continues-after
      script: 'echo "continued" > .allagents/e2e-continued.txt'
YAML
cd "$E2E_DIR" && node /path/to/dist/index.js workspace sync
# Expect: optional-fail ✗ (warning), continues-after ✓
# Verify: cat .allagents/e2e-continued.txt → "continued"

rm -rf "$E2E_DIR"

Notes

  • bun run test:integration is unavailable (no tests/integration/ directory on this branch)
  • Security model: scripts are arbitrary local commands; only the workspace owner can opt in; docs include a caution box
  • Idempotent pattern: example workspace shows storing version markers under .allagents/

Add a declarative lifecycleHooks.preSync mechanism that lets a workspace
run shell scripts before plugin artifacts are synced. This is an escape
hatch for runtime prerequisites (e.g., agent-tui, bd) that AllAgents
cannot sync as agent artifacts.

- Schema: LifecycleScriptSchema supports string shorthand and object form
  with name/optional fields
- Runner: execute scripts in order, stop on required failure, continue
  past optional failure, provide ALLAGENTS_WORKSPACE/ALLAGENTS_CONFIG_DIR
- Integration: run preSync hooks before plugin validation in syncWorkspace
- CLI: show script results in sync output, support dry-run and JSON mode
- Tests: 29 unit/integration tests covering parsing, execution, dry-run,
  failure, ordering, optional scripts, env vars, and full sync flow
- Docs: configuration reference section and example workspace
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploying allagents with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4c85aec
Status: ✅  Deploy successful!
Preview URL: https://451207f6.allagents.pages.dev
Branch Preview URL: https://feat-workspace-lifecycle-scr.allagents.pages.dev

View logs

…sed test imports

- Include lifecycleResults in syncWorkspace's early return when no clients
  are configured, so lifecycle hook output isn't silently dropped
- Remove unused chmod and mkdir imports from lifecycle-scripts test
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