Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 6, 2026

Add CLI flags to configure bun-worker settings

  • Explore and understand the current bun-worker implementation
  • Simplify the run() function to only accept setup function
  • Add CLI flag parsing support using cac library
  • Update README documentation
  • Add tests for CLI flag parsing
  • Build and test the changes
  • Address code review feedback
  • Remove package-lock.json (use bun.lock instead)
  • Simplify to essential CLI flags only
  • Extract CLI parsing to helper function
  • Rename flags to --database-path and --extension-path
  • Remove RunOptions interface entirely
  • Fix --help flag to exit gracefully

Summary

This PR adds CLI flag support to the bun-worker SDK using the cac library, providing a simple command-line interface for worker configuration.

Available CLI Flags

  • --concurrency, -c: Number of tasks to process concurrently (default: 10)
  • --database-path: SQLite database file path (overrides ABSURD_DATABASE_PATH environment variable)
  • --extension-path: Absurd-SQLite extension path (overrides ABSURD_DATABASE_EXTENSION_PATH environment variable)
  • --help, -h: Display help information

Implementation Details

  • Uses cac library for CLI parsing with proper help messages
  • Configuration exclusively through CLI flags and environment variables
  • Configuration priority: defaults → CLI flags
  • CLI parsing logic extracted to parseCliOptions() helper function for clean code organization
  • Simple, focused API with single parameter: run(setupFunction)
  • --help flag exits gracefully without requiring database configuration
  • All 77 tests passing
  • Security scan verification (CodeQL clean)

Usage

import run from "@absurd-sqlite/bun-worker";

await run((absurd) => {
  absurd.registerTask({ name: "hello" }, async (params) => {
    return { ok: true };
  });
});
# Run with custom concurrency
bun run worker.ts --concurrency 5

# Override database and extension paths
bun run worker.ts --database-path ./my.db --extension-path ./libabsurd.so

# Show help
bun run worker.ts --help

The implementation provides a focused CLI interface for essential options. All configuration is done via CLI flags or environment variables.

Original prompt

This section details on the original issue you should resolve

<issue_title>bun-worker should provide cli flags to configure the worker concurrency and other settings</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits January 6, 2026 07:40
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copilot AI changed the title [WIP] Add CLI flags to configure worker concurrency and settings Add CLI flags for bun-worker configuration Jan 6, 2026
Copilot AI requested a review from bcho January 6, 2026 07:52
@@ -0,0 +1,741 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

@copilot we use bun in this package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed package-lock.json and added it to .gitignore. The package now properly uses bun.lock for dependency management. (bcf13ef)

Copy link
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

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

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot

Hi! How can I help? Could you please provide more details about what you'd like me to address?

Copy link
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

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

@@ -0,0 +1,59 @@
# Bun Worker Sample

This sample demonstrates how to use the `@absurd-sqlite/bun-worker` SDK to create a worker that processes tasks.
Copy link
Member

Choose a reason for hiding this comment

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

remove this readme file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed samples/bun-worker/README.md (d77d116)

configureBunSqlite();

// The worker now supports CLI flags for configuration:
// --concurrency (-c): Number of concurrent tasks (default: 10)
Copy link
Member

Choose a reason for hiding this comment

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

expose only --concurrency flag for now. Add two more flags for specifying the extension path and database path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to expose only --concurrency, --database, and --extension flags (d77d116)

});
```

## CLI Flags
Copy link
Member

Choose a reason for hiding this comment

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

remove this part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the CLI Flags section from README (d77d116)

- Remove samples/bun-worker/README.md
- Use cac for CLI parsing with help messages
- Expose only --concurrency, --database, and --extension flags
- Remove extensive CLI documentation from SDK README
- Update error messages and tests

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copilot AI requested a review from bcho January 7, 2026 07:30
Copy link
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

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

});
```

## Programmatic Configuration
Copy link
Member

Choose a reason for hiding this comment

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

remove this part

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the Programmatic Configuration section from README (697101b)

* Whether to parse CLI flags for worker configuration.
* Defaults to true.
*/
parseCliFlags?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

remove this option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed parseCliFlags option from RunOptions (697101b)

): Promise<void> {
const parseFlags = options?.parseCliFlags !== false;

let dbPath = process.env.ABSURD_DATABASE_PATH;
Copy link
Member

Choose a reason for hiding this comment

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

extract the options parsing to a helper function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted CLI parsing to parseCliOptions() helper function (697101b)

.option("-c, --concurrency <number>", "Number of tasks to process concurrently", {
default: 10,
})
.option("-d, --database <path>", "SQLite database file path")
Copy link
Member

Choose a reason for hiding this comment

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

use --database-path and --extension-path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to --database-path and --extension-path (697101b)

- Remove parseCliFlags option from RunOptions
- Extract CLI parsing to parseCliOptions helper function
- Rename flags to --database-path and --extension-path
- Remove Programmatic Configuration section from README
- Update tests to remove parseCliFlags test case

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copilot AI requested a review from bcho January 7, 2026 07:48
/**
* Configuration options for the worker runtime.
*/
export interface RunOptions {
Copy link
Member

Choose a reason for hiding this comment

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

remove this options instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed RunOptions interface and the options parameter from run() function. Configuration is now only through CLI flags and environment variables. (715b562)

- Remove RunOptions interface and options parameter from run()
- Worker configuration now only through CLI flags and defaults
- Remove test for programmatic workerOptions configuration
- Simplifies API surface to focus on CLI-based configuration

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copilot AI requested a review from bcho January 7, 2026 08:08
Copy link
Member

@bcho bcho left a comment

Choose a reason for hiding this comment

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

bun run src/index.ts -- --help
bun-worker

Usage:
  $ bun-worker <command> [options]

Options:
  -c, --concurrency <number>  Number of tasks to process concurrently (default: 10)
  --database-path <path>      SQLite database file path
  --extension-path <path>     Absurd-SQLite extension path
  -h, --help                  Display this message
6084 | }
6085 | async function run(setupFunction) {
6086 |   const cliOptions = parseCliOptions();
6087 |   const dbPath = cliOptions.dbPath || process.env.ABSURD_DATABASE_PATH;
6088 |   const extensionPath = cliOptions.extensionPath || process.env.ABSURD_DATABASE_EXTENSION_PATH;
6089 |     throw new Error("Database path is required. Set ABSURD_DATABASE_PATH environment variable or use --database-path flag.");
                 ^

when -h is being used, no stacktrace should be dump

@bcho
Copy link
Member

bcho commented Jan 8, 2026

@copilot no i mean when using --help the program is failing, we should not do that

When --help is used, cac displays help and sets the help option.
Previously, the program would continue execution and fail with
"Database path is required" error. Now it exits gracefully with
exit code 0 after showing help.

Co-authored-by: bcho <1975118+bcho@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot no i mean when using --help the program is failing, we should not do that

Fixed. The --help flag now exits gracefully with code 0 after displaying help, without requiring database configuration. (6139d53)

@bcho bcho marked this pull request as ready for review January 8, 2026 05:34
@bcho bcho merged commit 4136e64 into main Jan 8, 2026
8 checks passed
@bcho bcho deleted the copilot/add-cli-flags-for-worker-concurrency branch January 8, 2026 05:37
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.

bun-worker should provide cli flags to configure the worker concurrency and other settings

2 participants