This package provides a Command Line Interface (CLI) for managing "workforce sessions" within a Goddard-compatible repository. It facilitates a multi-agent orchestration pattern where specific directories (packages) in a codebase are assigned dedicated autonomous AI agents. These agents communicate asynchronously via "inbox" files located in a .goddard/ directory within each package.
The system is designed for Workforce Lead Agents (per-package) and a Workforce Root Agent (repository-wide) to collaborate on complex tasks by appending requests and responses to JSONL files.
The CLI (goddard-workforce) is built using cmd-ts and @clack/prompts. It provides two primary commands:
init:- Scans the repository for packages (directories containing
package.json). - Prompts the user to select packages for workforce enablement.
- Creates a
.goddard/directory in each selected package containing emptyrequests.jsonlandresponses.jsonlfiles.
- Scans the repository for packages (directories containing
watch:- Resolves the repository root.
- Discovers all packages that have a
.goddard/directory. - Spawns a persistent
WorkforceSupervisor(from@goddard-ai/sdk) to manage the lifecycle of AI agents for those packages.
The core logic resides in @goddard-ai/sdk/node/workforce.ts, which manages state, file watching, and agent communication.
WorkforceSupervisor: Manages a collection ofWorkforcePackageRuntimeinstances.WorkforcePackageRuntime: Encapsulates the state for a single package, including:- An
AgentSessionconnected to the Goddard daemon. - A
chokidarwatcher monitoring the.goddard/directory. - A prompt queue for handling concurrent file updates.
- An
Each workforce-enabled package contains:
requests.jsonl: Inputs for the agent.responses.jsonl: Outputs/logs from the agent.processed-at.json: Tracks the byte offset and SHA-256 hash of the last processed line in the JSONL files.
- Discovery: Uses
git rev-parse --show-topleveland recursive directory walking to find packages containing a.goddarddirectory. - Session Initialization: For each package, it starts a persistent
piagent session via the Goddard daemon.- Root Agent: Assigned to the repository root. Instructed to own the project-wide view and route requests.
- Lead Agent: Assigned to sub-packages. Instructed to own only the code inside their specific directory.
- File Watching: Monitors the
.goddard/directory for appends. - Append Tracking:
- Reads
processed-at.jsonto find the previousoffset. - Verifies the
prefixHashto ensure file integrity. If the prefix hash doesn't match (e.g., the file was rewritten), it resets tracking. - Extracts only the newly appended lines.
- Reads
- Prompting: Formats the new JSONL records into a prompt and sends it to the agent session. If the agent is already busy, batches are queued and processed sequentially.
Stored in .goddard/processed-at.json.
{
"version": 1,
"files": {
"requests.jsonl": {
"offset": 1234,
"prefixHash": "sha256...",
"updatedAt": "ISO-TIMESTAMP"
}
}
}When activity is detected, the agent receives a prompt structured with:
- Header: Contextualizing the package name and relative path.
- Instruction: Explicit directives to process the newly appended JSONL records.
- Batches: Multiple batches of JSONL records wrapped in
jsonlblocks.
The system uses Buffer.byteLength and findLastCompleteOffset to ensure it only reads full lines from the JSONL files, maintaining integrity across multi-byte UTF-8 characters.
The drainPackageQueue function ensures that if new requests arrive while the agent is still processing a previous batch, they are queued and sent immediately after the current task finishes, preventing loss of intent during high-activity periods.
The workforce CLI requires a running Goddard daemon to manage the underlying AI sessions.
This project is licensed under the MIT License.