Skip to content

Commit 3250179

Browse files
authored
Merge branch 'dev' into copilot/identify-key-areas-for-improvement
2 parents 7f10dfb + ec1fd82 commit 3250179

24 files changed

Lines changed: 652 additions & 54 deletions
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Copilot Setup Steps"
2+
3+
# Automatically run the setup steps when they are changed to allow for easy validation, and
4+
# allow manual testing through the repository's "Actions" tab
5+
on:
6+
workflow_dispatch:
7+
push:
8+
paths:
9+
- .github/workflows/copilot-setup-steps.yml
10+
pull_request:
11+
paths:
12+
- .github/workflows/copilot-setup-steps.yml
13+
14+
jobs:
15+
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
16+
copilot-setup-steps:
17+
runs-on: ubuntu-latest
18+
19+
# Set the permissions to the lowest permissions possible needed for your steps.
20+
# Copilot will be given its own token for its operations.
21+
permissions:
22+
# If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete.
23+
contents: read
24+
25+
# You can define any steps you want, and they will run before the agent starts.
26+
# If you do not check out your code, Copilot will do this for you.
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v5
30+
31+
- name: Setup Deno
32+
uses: denoland/setup-deno@v2
33+
with:
34+
deno-version: v2.x
35+
cache: true
36+
37+
- name: Cache dependencies
38+
run: deno install

.github/workflows/deno.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
deno-version: [1.43.3, "v1.x", "v2.x"]
15+
deno-version: ["v2.x"]
1616

1717
steps:
1818
- name: Git Checkout

AGENTS.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Agents Guide
2+
3+
This document provides an overview of the Pup repository structure, tools, and development workflow for AI agents and contributors.
4+
5+
## Repository Structure
6+
7+
```
8+
pup/
9+
├── lib/ # Core library code
10+
│ ├── cli/ # Command-line interface
11+
│ ├── common/ # Common utilities
12+
│ ├── core/ # Core process management logic
13+
│ ├── test/ # Test utilities
14+
│ ├── types/ # TypeScript type definitions
15+
│ └── workers/ # Worker scripts
16+
├── test/ # Test files
17+
│ ├── cli/ # CLI tests
18+
│ └── core/ # Core functionality tests
19+
├── docs/ # Documentation (Lume-based site)
20+
│ └── src/
21+
│ ├── examples/ # Usage examples
22+
│ ├── usage/ # Usage guides
23+
│ └── contributing/ # Contribution guides
24+
├── tools/ # Build and development tools
25+
├── pup.ts # Main entry point
26+
├── mod.ts # Library export
27+
└── deno.json # Deno configuration and tasks
28+
```
29+
30+
## Development Tools
31+
32+
Pup is built with Deno. Key commands are defined in `deno.json`:
33+
34+
### Formatting and Linting
35+
36+
```bash
37+
deno fmt # Format code
38+
deno fmt --check # Check formatting
39+
deno lint # Lint code
40+
```
41+
42+
### Testing
43+
44+
```bash
45+
deno test --allow-read --allow-write --allow-env --allow-net --allow-sys --allow-run --coverage=cov_profile
46+
```
47+
48+
### Build Tasks
49+
50+
```bash
51+
deno task check # Run format, lint, and tests
52+
deno task build-schema # Generate JSON schema
53+
deno task build-versions # Update version information
54+
deno task build # Complete build process
55+
```
56+
57+
## Pre-commit Checks
58+
59+
The project uses GitHub Actions for CI (`.github/workflows/deno.yaml`):
60+
61+
- Format checking (`deno fmt --check`)
62+
- Linting (`deno lint`)
63+
- Full test suite with coverage
64+
- Runs on: `main` and `dev` branches
65+
66+
Before submitting PRs, run `deno task check` locally to ensure all checks pass.
67+
68+
## Related Projects
69+
70+
Pup is part of an ecosystem of packages available on JSR:
71+
72+
### Core Dependencies
73+
74+
- **[@pup/api-definitions](https://github.com/hexagon/pup-api-definitions)** - API type definitions shared across the ecosystem
75+
- **[@pup/api-client](https://github.com/hexagon/pup-api-client)** - REST API client for CLI, plugins, and telemetry
76+
- **[@pup/telemetry](https://github.com/hexagon/pup-telemetry)** - Runtime-agnostic library for process telemetry and IPC
77+
- **[@pup/common](https://github.com/hexagon/pup-common)** - Common utilities shared across Pup packages
78+
- **[@pup/plugin](https://github.com/hexagon/pup-plugin)** - Base library for creating Pup plugins
79+
80+
### Official Plugins
81+
82+
- **[pup-plugin-web-interface](https://github.com/hexagon/pup-plugin-web-interface)** - Web-based UI for managing Pup
83+
84+
## Key Concepts
85+
86+
- **Process Management**: Core functionality in `lib/core/`
87+
- **Configuration**: Uses `pup.json` files (see `docs/src/examples/`)
88+
- **Service Management**: Cross-platform service installation (sysvinit, systemd, upstart, macOS, Windows)
89+
- **Telemetry & IPC**: Process monitoring and inter-process communication
90+
- **Plugins**: Extensible architecture for adding functionality
91+
92+
## Making Changes
93+
94+
1. Fork and create a branch from `dev`
95+
2. Make minimal, focused changes
96+
3. Add/update tests in `test/` directory
97+
4. Run `deno task check` to validate
98+
5. Update documentation if needed
99+
6. Submit PR against `dev` branch
100+
101+
## Documentation
102+
103+
Full documentation is available at [pup.56k.guru](https://pup.56k.guru), built from `docs/src/` using Lume.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _For detailed documentation, visit [pup.56k.guru](https://pup.56k.guru)._
1717
your own plugins to add additional features and integrations tailored to your needs.
1818
- **Process Telemetry and IPC:** Gain deeper insights into managed processes by gathering telemetry data, such as memory usage, from Deno client processes. Supports inter-process communication for
1919
connected processes to interact with each other.
20-
- **Rest API:** Control and monitor Pup from third party solutions using the build in Rest API.
20+
- **Rest API:** Control and monitor Pup from third party solutions using the built-in Rest API.
2121

2222
> **Note**: Programmatic usage, process telemetry, and IPC are currently available only when running Deno client processes.
2323
@@ -57,11 +57,11 @@ used below:
5757

5858
4. To make your instance run at boot, enable it using `pup enable-service`.
5959

60-
Will by default use the instance name for service name, which defaults to `pup`. You can override by passing `-n my-custom-name`.
60+
Will by default use the instance name for service name, which defaults to `pup`. You can override by passing `--name my-custom-name`.
6161

6262
5. To stream the logs from a running instance, use the command `pup monitor`. To show historic logs, use `pup logs`.
6363

64-
Will by default use the instance name for service name, which defaults to `pup`. You can override by passing `-n my-custom-name`.
64+
Will by default use the instance name for service name, which defaults to `pup`. You can override by passing `--name my-custom-name`.
6565

6666
For the full manual, see <https://pup.56k.guru>
6767

@@ -87,7 +87,7 @@ Full examples available at [/docs/src/examples](/docs/src/examples)
8787
- `canary`: The canary channel provides the most up-to-date and cutting-edge versions of Pup. It includes the latest changes and may not be as stable as the other channels. It is primarily intended
8888
for developers and early adopters who want to stay on the bleeding edge of Pup's development. Based on the current state of the `dev` repo of the github repository.
8989

90-
> **Note** Built-in plugins, such as splunk-hec and webinterace does not work with canary versions right now.
90+
> **Note** Built-in plugins, such as splunk-hec and webinterface do not work with canary versions right now.
9191
9292
Each channel serves different purposes, so choose the one that best fits your needs and requirements.
9393

application.meta.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
const Application = {
2323
name: "pup",
24-
version: "1.0.4",
24+
version: "1.0.5",
2525
url: "jsr:@pup/pup@$VERSION",
2626
description: "Powerful universal process manager, designed to keep your scripts, applications and services alive.",
2727
canary_url: "https://raw.githubusercontent.com/Hexagon/pup/refs/heads/dev/pup.ts",
28-
deno: "1.44.0", /* Minimum stable version of Deno required to run Pup (without --unstable-* flags) */
29-
deno_unstable: "1.44.0", /* Minimum version of Deno required to run Pup (with --unstable-* flags) */
28+
deno: "2.0.0", /* Minimum stable version of Deno required to run Pup (without --unstable-* flags) */
29+
deno_unstable: "2.0.0", /* Minimum version of Deno required to run Pup (with --unstable-* flags) */
3030
repository: "https://github.com/hexagon/pup",
3131
changelog: "https://hexagon.github.io/pup/changelog.html",
3232
permissions: [

deno.json

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pup/pup",
3-
"version": "1.0.4",
3+
"version": "1.0.5-dev.0",
44

55
"exports": {
66
".": "./pup.ts",
@@ -14,7 +14,7 @@
1414
},
1515

1616
"lint": {
17-
"exclude": ["cov_profile", "docs/_site"],
17+
"exclude": ["cov_profile", "docs/_site", "docs/src/examples/**", "tools/"],
1818
"rules": {
1919
"exclude": ["verbatim-module-syntax", "no-node-globals"]
2020
}
@@ -37,28 +37,29 @@
3737

3838
"imports": {
3939
"@cross/deepmerge": "jsr:@cross/deepmerge@~1.0.0",
40-
"@cross/env": "jsr:@cross/env@~1.0.2",
41-
"@cross/fs": "jsr:@cross/fs@~0.1.11",
42-
"@cross/jwt": "jsr:@cross/jwt@~0.5.0",
43-
"@cross/kv": "jsr:@cross/kv@~0.17.1",
44-
"@cross/runtime": "jsr:@cross/runtime@~1.1.0",
45-
"@cross/service": "jsr:@cross/service@^1.0.6",
46-
"@cross/test": "jsr:@cross/test@~0.0.9",
40+
"@cross/env": "jsr:@cross/env@~1.0.3",
41+
"@cross/fs": "jsr:@cross/fs@~0.1.13",
42+
"@cross/jwt": "jsr:@cross/jwt@~0.6.0",
43+
"@cross/kv": "jsr:@cross/kv@~0.17.4",
44+
"@cross/runtime": "jsr:@cross/runtime@~1.2.1",
45+
"@cross/service": "jsr:@cross/service@^1.0.7",
46+
"@cross/test": "jsr:@cross/test@~0.0.10",
4747
"@cross/utils": "jsr:@cross/utils@^0.16.0",
48-
"@hexagon/croner": "jsr:@hexagon/croner@~9.0.0",
49-
"@oak/oak": "jsr:@oak/oak@^17.0.0",
48+
"@hexagon/croner": "jsr:@hexagon/croner@~9.1.0",
49+
"@oak/oak": "jsr:@oak/oak@^17.1.6",
5050
"@pup/api-client": "jsr:@pup/api-client@~2.0.0",
5151
"@pup/api-definitions": "jsr:@pup/api-definitions@~2.0.0",
5252
"@pup/common": "jsr:@pup/common@~1.0.3",
5353
"@pup/plugin": "jsr:@pup/plugin@~1.0.1",
54-
"@std/assert": "jsr:@std/assert@~1.0.0",
55-
"@std/async": "jsr:@std/async@~1.0.0",
56-
"@std/encoding": "jsr:@std/encoding@~1.0.0",
57-
"@std/io": "jsr:@std/io@~0.224.0",
58-
"@std/path": "jsr:@std/path@~1.0.1",
59-
"@std/semver": "jsr:@std/semver@^1.0.3",
60-
"dax-sh": "npm:dax-sh@~0.42.0",
61-
"filesize": "npm:filesize@~10.1.1",
54+
"@std/assert": "jsr:@std/assert@~1.0.15",
55+
"@std/async": "jsr:@std/async@~1.0.15",
56+
"@std/encoding": "jsr:@std/encoding@~1.0.10",
57+
"@std/io": "jsr:@std/io@~0.225.2",
58+
"@std/path": "jsr:@std/path@~1.1.2",
59+
"@std/semver": "jsr:@std/semver@^1.0.6",
60+
"@std/streams": "jsr:@std/streams@~1.0.12",
61+
"dax-sh": "npm:dax-sh@~0.43.2",
62+
"filesize": "npm:filesize@~11.0.13",
6263
"json5": "npm:json5@~2.2.3",
6364
"timeago.js": "npm:timeago.js@~4.0.2",
6465
"zod": "npm:zod@~3.23.6",

docs/deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"serve": "deno task lume -s --port=8000"
66
},
77
"imports": {
8-
"lume/": "https://deno.land/x/lume@v1.19.1/",
9-
"lumocs/": "https://deno.land/x/lumocs@0.0.25/"
8+
"lume/": "https://deno.land/x/lume@v3.1.1/",
9+
"lumocs/": "https://deno.land/x/lumocs@0.2.0/"
1010
}
1111
}

docs/src/changelog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ nav_order: 13
99

1010
All notable changes to this project will be documented in this section.
1111

12+
## [Unreleased]
13+
14+
- feat(core): Add exponential backoff for process restarts via `restartBackoffMs` configuration option to prevent rapid restart loops
15+
1216
## [1.0.4] - 2024-11-19
1317

1418
- fix(core): Fix service auto start after install on Windows by upgrading dependency @cross/service
@@ -44,7 +48,7 @@ This release marks the initial stable release of Pup - a powerful universal proc
4448
your own plugins to add additional features and integrations tailored to your needs.
4549
- **Process Telemetry and IPC:** Gain deeper insights into managed processes by gathering telemetry data, such as memory usage, from Deno client processes. Supports inter-process communication for
4650
connected processes to interact with each other.
47-
- **Rest API:** Control and monitor Pup from third party solutions using the build in Rest API.
51+
- **Rest API:** Control and monitor Pup from third party solutions using the built-in Rest API.
4852

4953
_For detailed documentation, visit [pup.56k.guru](https://pup.56k.guru)._
5054

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Max Restarts and Exponential Backoff Example
2+
3+
This example demonstrates how to configure restart limits and exponential backoff for processes that may fail.
4+
5+
## Overview
6+
7+
The configuration shows two processes:
8+
9+
1. **max-3-times**: Uses a fixed restart delay of 3 seconds and allows up to 3 restarts
10+
2. **with-exponential-backoff**: Uses exponential backoff starting at 1 second and capping at 30 seconds, allowing up to 5 restarts
11+
12+
## How Exponential Backoff Works
13+
14+
When a process fails repeatedly, exponential backoff prevents rapid restart loops by increasing the delay between each restart attempt:
15+
16+
- **1st restart**: 1 second delay (restartDelayMs)
17+
- **2nd restart**: 2 seconds delay (1s × 2¹)
18+
- **3rd restart**: 4 seconds delay (1s × 2²)
19+
- **4th restart**: 8 seconds delay (1s × 2³)
20+
- **5th restart**: 16 seconds delay (1s × 2⁴)
21+
- **Further restarts**: 30 seconds delay (capped at restartBackoffMs)
22+
23+
This approach:
24+
25+
- Gives transient issues time to resolve
26+
- Prevents resource exhaustion from rapid restart loops
27+
- Allows more restart attempts while being system-friendly
28+
29+
## Running the Example
30+
31+
```bash
32+
pup run
33+
```
34+
35+
The `server.js` script exits immediately, so both processes will restart according to their configured policies until they reach their restart limits.
36+
37+
## Configuration
38+
39+
```jsonc
40+
{
41+
"processes": [
42+
{
43+
"id": "max-3-times",
44+
"cmd": "deno run server.js",
45+
"autostart": true,
46+
"restart": "always",
47+
"restartLimit": 3,
48+
"restartDelayMs": 3000
49+
},
50+
{
51+
"id": "with-exponential-backoff",
52+
"cmd": "deno run server.js",
53+
"autostart": true,
54+
"restart": "always",
55+
"restartLimit": 5,
56+
"restartDelayMs": 1000,
57+
"restartBackoffMs": 30000
58+
}
59+
]
60+
}
61+
```
62+
63+
## When to Use Exponential Backoff
64+
65+
Exponential backoff is particularly useful for:
66+
67+
- Services that may experience temporary network issues
68+
- Processes that depend on external resources (databases, APIs)
69+
- Applications that might fail during deployment or updates
70+
- Any process where rapid restart loops could cause problems
71+
72+
## Notes
73+
74+
- If `restartBackoffMs` is not set, the process will use a fixed `restartDelayMs` between all restarts
75+
- The backoff resets when the process exits successfully (status: FINISHED) or is manually stopped
76+
- Combined with `restartLimit`, exponential backoff provides robust process recovery while preventing runaway restart loops

docs/src/examples/max-restarts/pup.jsonc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
"restart": "always",
88
"restartLimit": 3,
99
"restartDelayMs": 3000
10+
},
11+
{
12+
"id": "with-exponential-backoff",
13+
"cmd": "deno run server.js",
14+
"autostart": true,
15+
"restart": "always",
16+
"restartLimit": 5,
17+
"restartDelayMs": 1000,
18+
"restartBackoffMs": 30000
1019
}
1120
]
1221
}

0 commit comments

Comments
 (0)