Skip to main content

@flow-state-dev/workforce/codegen

Classes​

WorkforceCodeError​

Thrown when a walk finds anything it will not render.

Carries every problem rather than the first, because an author fixing a tree should see the whole list in one run. Nothing is rendered when this throws: a partial generation would leave a registry quietly short.

Extends​

  • Error

Constructors​

Constructor​
new WorkforceCodeError(problems): WorkforceCodeError;
Parameters​
problems​

string[]

Returns​

WorkforceCodeError

Overrides​

Error.constructor

Properties​

cause?​
cause?: unknown;
Inherited from​

Error.cause

message​
message: string;
Inherited from​

Error.message

name​
name: string;
Inherited from​

Error.name

problems​
readonly problems: string[];

Each refusal, in the order the walk met it.

stack?​
stack?: string;
Inherited from​

Error.stack

Interfaces​

CodeSlot​

One locked folder, and what a file in it becomes.

Every field is readonly, and each descriptor is frozen where it is declared. CODE_SLOTS is a published export, and dir is joined onto the workforce root to decide what the walk reads: a caller who could assign CODE_SLOTS[0].dir = "../outside" would send the walk out of the validated root and put ./../outside/... in the generated module. Freezing the array alone does not stop that — Object.freeze is shallow, and as const is a type-level assertion that does not survive the declared CodeSlot type.

Properties​

dir​
readonly dir: string;

Path under the workforce root, POSIX, relative. Owner-locked.

exportName​
readonly exportName: "workerFlows" | "blocks";

The map this slot's files are rendered onto. Public: an app imports it.

id​
readonly id: CodeSlotId;
label​
readonly label: SegmentLabel;

What a basename here names, for a refusal to say.


DiscoveredFile​

One file the walk found, and where it will be imported from.

Properties​

importPath​
importPath: string;

The specifier the generated module imports it by, e.g. ./flows/workers/researcher.

name​
name: string;

The basename without its extension — the name this file registers under.

path​
path: string;

Slash-separated path under the workforce root, e.g. flows/workers/researcher.ts. Orders the output.

slot​
slot: CodeSlotId;

DiscoveredPackageBlock​

One block a package carries.

Properties​

importPath​
importPath: string;

The specifier the generated module imports it by.

name​
name: string;

The basename without its extension: the tool's name.

package​
package: string;

The package's address — its folder's path under the workforce root, e.g. teams/support/packages/escalation.

path​
path: string;

Slash-separated path under the workforce root. Orders the output.


DiscoveredResourceModule​

One module the walk found, and where it will be imported from.

Properties​

atWorkerRoot​
atWorkerRoot: boolean;

Whether it sat in one worker's OWN resources/ folder, rather than the organisation's or a team's.

The one thing about a module's position the ref does not already carry, and the one thing anything downstream asks: such a module may be a resource and may not be a capability, because every worker on a flow shares that flow's capabilities and one installed from a single worker's folder would quietly change every other worker.

importPath​
importPath: string;

The specifier the generated module imports it by, e.g. ./teams/engineering/resources/research.

path​
path: string;

Slash-separated path under the workforce root, e.g. teams/engineering/resources/research.ts. Orders the output.

ref​
ref: string;

The ref it registers under — minted exactly as a document of that name in that folder would be.


DiscoveredWorkerBlock​

One block registered for one worker. A team-level file produces one of these per worker on the team.

Properties​

importPath​
importPath: string;

The specifier the generated module imports it by. One per FILE, however many workers share it.

level​
level: "team" | "worker";

Which level the file sits at. A worker's own shadows its team's of the same name.

name​
name: string;

The basename without its extension, which is the name the worker's tools: resolves.

path​
path: string;

Slash-separated path under the workforce root. Orders the output.

worker​
worker: string;

The worker it is registered for — <team>.<worker>, the worker id.


DiscoveryResult​

What one walk produced.

Properties​

files​
files: DiscoveredFile[];

Every file found in the two locked code folders, ordered by DiscoveredFile.path.

packageBlocks​
packageBlocks: DiscoveredPackageBlock[];

Every block a package's blocks/ folder carries, keyed by the package's address, ordered by path. Door D's half.

Registration against a PACKAGE, not a worker: which workers may call one is decided at the hire, from which workers hold the package.

resourceModules​
resourceModules: DiscoveredResourceModule[];

Every module found in a resources/ folder, ordered by path. Door B's half.

searched​
searched: string[];

Where it looked — the locked folders, then the resources/ and blocks/ slot patterns, so the command can say.

workerBlocks​
workerBlocks: DiscoveredWorkerBlock[];

Every block a team-tree blocks/ folder registers, per worker, ordered by path then worker. Door C's half.

A REGISTRATION, not a grant: a worker's tools: is still what decides which of these it may call.


PackageBlockDiscovery​

What the package-block walk produced. Problems are handed back, as the other doors do.

Properties​

packageBlocks​
packageBlocks: DiscoveredPackageBlock[];

Every package block, ordered by path.

problems​
problems: string[];

Each refusal, in the order the walk met it.


WorkerBlockDiscovery​

What the worker-block walk produced. Problems are handed back rather than thrown — see the module header.

Properties​

problems​
problems: string[];

Each refusal, in the order the walk met it.

workerBlocks​
workerBlocks: DiscoveredWorkerBlock[];

Every registration, ordered by DiscoveredWorkerBlock.path then worker.

Type Aliases​

CodeSlotId​

type CodeSlotId = "worker" | "block";

Which locked folder a discovered file came from.

Variables​

BLOCKS_SLOT​

const BLOCKS_SLOT: "blocks" = "blocks";

The folder a block file sits in, at every level it may sit at.


CODE_SLOTS​

const CODE_SLOTS: readonly CodeSlot[];

The two locked folders, in the order their maps are rendered.

Owner-locked paths, not derived — a best-practice tree rather than a top-level folder per flow, and one convention covering flows and blocks together rather than a flows-only one the blocks half would later have to match.


GENERATED_FILE_NAME​

const GENERATED_FILE_NAME: "workforce.gen.ts" = "workforce.gen.ts";

The generated module's name, under the workforce root. Public: an author imports it.


PACKAGE_BLOCK_SLOT_PATTERNS​

const PACKAGE_BLOCK_SLOT_PATTERNS: readonly string[];

Where a package's blocks may sit, as the command reports it.


WORKER_BLOCK_SLOT_PATTERNS​

const WORKER_BLOCK_SLOT_PATTERNS: readonly string[];

The two places inside the team tree a blocks/ folder may sit, as the command reports them. workforce/blocks/ is the third place and belongs to the locked-folder walk, which reports it under its own name.

Patterns rather than the concrete folders walked, for the reason Door B's are: what an author wants to read back is where the convention looks.

Functions​

discoverPackageBlocks()​

function discoverPackageBlocks(root): Promise<PackageBlockDiscovery>;

Walk every package's blocks/ folder.

Structural refusals above a packages/ slot — a symlinked teams/, team or worker folder — are left to the doors that own those slots, which already report them; this walk simply does not go through them.

Parameters​

root​

string

Path to the app's workforce/ directory.

Returns​

Promise<PackageBlockDiscovery>

Every package block, ordered, and every refusal.

Throws​

If the root is symlinked, missing or unreadable.


discoverWorkerBlocks()​

function discoverWorkerBlocks(root): Promise<WorkerBlockDiscovery>;

Walk the team tree's blocks/ folders and return what they register, per worker.

The root is opened here rather than left to the caller, for the reason the walks beside it open it: a symlinked root would put the whole walk outside the configured tree.

Parameters​

root​

string

Path to the app's workforce/ directory.

Returns​

Promise<WorkerBlockDiscovery>

Every registration, ordered, and every refusal.

Throws​

If the root is symlinked, missing or unreadable.


discoverWorkforceCode()​

function discoverWorkforceCode(root): Promise<DiscoveryResult>;

Walk everything the convention reads under root — the two locked code folders, and every resources/ folder Door B's module walk covers — and return what they hold.

One level only, one file per entry — a directory inside a locked folder is refused by name rather than skipped, because a folder an author created and the tool ignored is the silence this convention exists to remove.

The root is opened here rather than left to the caller, so the no-follow promise belongs to this function and not to whoever happens to call it: a symlinked root would put the whole walk outside the configured tree, and a root that is not there would return empty maps for a path nobody configured.

Parameters​

root​

string

Path to the app's workforce/ directory.

Returns​

Promise<DiscoveryResult>

Every discovered file and resource module, ordered by path, plus where it looked.

Throws​

If the root is symlinked, missing or unreadable.

Throws​

If anything under it was refused; the message names all of them.


renderWorkforceCode()​

function renderWorkforceCode(
files,
modules,
workerBlocks?,
packageBlocks?
): string;

Render the module for a discovered tree.

Deterministic: the same list renders the same bytes, on any machine, in any directory order.

Parameters​

files​

DiscoveredFile[]

Every discovered code file, as discoverWorkforceCode ordered them.

modules​

DiscoveredResourceModule[]

Every discovered resource module, in the same order it returned them.

workerBlocks?​

DiscoveredWorkerBlock[]

Every per-worker block registration, in the same order it returned them.

packageBlocks?​

DiscoveredPackageBlock[]

Every package block, in the same order it returned them.

Returns​

string

The module's full text, newline-terminated.