@opensoftware/foreman 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +270 -2
- package/dist/adapters/factory.js +33 -0
- package/dist/adapters/factory.js.map +1 -0
- package/dist/adapters/gatekeeper.js +18 -0
- package/dist/adapters/gatekeeper.js.map +1 -0
- package/dist/adapters/harness.js +53 -0
- package/dist/adapters/harness.js.map +1 -0
- package/dist/adapters/nats.js +31 -0
- package/dist/adapters/nats.js.map +1 -0
- package/dist/adapters/sandbox.js +56 -0
- package/dist/adapters/sandbox.js.map +1 -0
- package/dist/cli.js +20 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/runs.js +68 -0
- package/dist/commands/runs.js.map +1 -0
- package/dist/commands/serve.js +110 -0
- package/dist/commands/serve.js.map +1 -0
- package/dist/domain/definition.js +45 -0
- package/dist/domain/definition.js.map +1 -0
- package/dist/domain/run.js +147 -0
- package/dist/domain/run.js.map +1 -0
- package/dist/domain/time.js +3 -0
- package/dist/domain/time.js.map +1 -0
- package/dist/workflows/activities.js +105 -0
- package/dist/workflows/activities.js.map +1 -0
- package/dist/workflows/run.js +53 -0
- package/dist/workflows/run.js.map +1 -0
- package/dist/workflows.bundle.js +12231 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,271 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
covers: [modules/foreman/src/**, modules/foreman/scripts/**]
|
|
3
|
+
---
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
# foreman
|
|
6
|
+
|
|
7
|
+
Run the factory's workflow for each work item: the stages of `factory.yaml` one after the other, each with its agent
|
|
8
|
+
through the harness port, with human gates, steering and cancel, on Temporal. A run survives a restart of the
|
|
9
|
+
foreman, and Temporal's UI shows its history. Decisions: [ADR 0067](../../docs/decisions/0067-foreman.md), on
|
|
10
|
+
[ADR 0004](../../docs/decisions/0004-temporal.md), and [ADR 0068](../../docs/decisions/0068-foreman-sandboxes.md) for
|
|
11
|
+
sandboxes.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
This quick start is scenario `SCN-FORE-001` and is tested on every change. You need the
|
|
16
|
+
[Temporal CLI](https://docs.temporal.io/cli) for a local Temporal server and Git. Save a factory of two stages:
|
|
17
|
+
|
|
18
|
+
```yaml factory.yaml
|
|
19
|
+
version: 1
|
|
20
|
+
factory: hello
|
|
21
|
+
providers:
|
|
22
|
+
harness:
|
|
23
|
+
acp: "^0"
|
|
24
|
+
agents:
|
|
25
|
+
plan:
|
|
26
|
+
harness: acp
|
|
27
|
+
model: routes/default
|
|
28
|
+
prompt: ./agents/plan.md
|
|
29
|
+
implement:
|
|
30
|
+
harness: acp
|
|
31
|
+
model: routes/default
|
|
32
|
+
prompt: ./agents/implement.md
|
|
33
|
+
workflow:
|
|
34
|
+
- stage: plan
|
|
35
|
+
- stage: implement
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```markdown agents/plan.md
|
|
39
|
+
Write a plan for the work item into plan.md.
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```markdown agents/implement.md
|
|
43
|
+
Implement plan.md.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Commit it, start Temporal, and serve the foreman with Claude Code behind the `acp` harness adapter:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
git init -q && git add -A && git commit -qm "the hello factory"
|
|
50
|
+
temporal server start-dev --headless &
|
|
51
|
+
export FOREMAN_API_TOKEN=dev-token
|
|
52
|
+
export FOREMAN_HARNESSES='{"acp": "npx -y @opensoftware/harness-acp run --allow read,edit -- npx -y @agentclientprotocol/claude-agent-acp"}'
|
|
53
|
+
npx @opensoftware/foreman serve
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Save a work item, as intake publishes it:
|
|
57
|
+
|
|
58
|
+
```json work.json
|
|
59
|
+
{
|
|
60
|
+
"id": "wi_5d1c1f0a9e7b3c2d4e6f",
|
|
61
|
+
"type": "idea",
|
|
62
|
+
"title": "Export reports as CSV",
|
|
63
|
+
"requester": { "kind": "person", "id": "slack:U0PERSON", "displayName": "Varun" },
|
|
64
|
+
"origin": { "source": "api" },
|
|
65
|
+
"dedupeKey": "idea:export-csv"
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Start a run and read it:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
curl -H "Authorization: Bearer dev-token" -H "content-type: application/json" \
|
|
73
|
+
--data @work.json http://localhost:8080/v1/runs
|
|
74
|
+
curl -H "Authorization: Bearer dev-token" http://localhost:8080/v1/runs/run_…
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The first call answers 201 with the run `run_…` in the state `running`. Once both agents ended their turns, the run is
|
|
78
|
+
`complete` and both stages are `succeeded`. Temporal's UI at http://localhost:8233 shows the workflow `run_…`.
|
|
79
|
+
|
|
80
|
+
## Sandboxes
|
|
81
|
+
|
|
82
|
+
The quick start runs both agents on your machine. Run an agent you do not trust with that machine in a sandbox: give
|
|
83
|
+
it `sandbox` in `factory.yaml`. This factory runs both stages on Docker, each in a fresh sandbox with 2 CPUs and 4 GiB,
|
|
84
|
+
that may reach only npm and Anthropic's API:
|
|
85
|
+
|
|
86
|
+
```yaml sandboxed/factory.yaml
|
|
87
|
+
version: 1
|
|
88
|
+
factory: hello
|
|
89
|
+
providers:
|
|
90
|
+
harness:
|
|
91
|
+
acp: "^0"
|
|
92
|
+
sandbox:
|
|
93
|
+
docker: "^0"
|
|
94
|
+
agents:
|
|
95
|
+
plan:
|
|
96
|
+
harness: acp
|
|
97
|
+
model: routes/default
|
|
98
|
+
prompt: ./agents/plan.md
|
|
99
|
+
secrets: [ref:file/anthropic-api-key]
|
|
100
|
+
sandbox:
|
|
101
|
+
template: node:24
|
|
102
|
+
cpu: 2
|
|
103
|
+
memory: 4Gi
|
|
104
|
+
egress: [registry.npmjs.org, api.anthropic.com]
|
|
105
|
+
implement:
|
|
106
|
+
harness: acp
|
|
107
|
+
model: routes/default
|
|
108
|
+
prompt: ./agents/implement.md
|
|
109
|
+
secrets: [ref:file/anthropic-api-key]
|
|
110
|
+
sandbox:
|
|
111
|
+
template: node:24
|
|
112
|
+
cpu: 2
|
|
113
|
+
memory: 4Gi
|
|
114
|
+
egress: [registry.npmjs.org, api.anthropic.com]
|
|
115
|
+
workflow:
|
|
116
|
+
- stage: plan
|
|
117
|
+
- stage: implement
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Put your Anthropic API key in the file `secrets/anthropic-api-key` and serve the foreman as in the quick start, with
|
|
121
|
+
`export OSF_SECRETS_DIR=$PWD/secrets` for the [docker sandbox adapter](../../adapters/sandbox/docker/README.md). Each
|
|
122
|
+
stage then goes like this:
|
|
123
|
+
|
|
124
|
+
1. The foreman creates a sandbox with the adapter that the factory names under `providers.sandbox` (`docker` when it
|
|
125
|
+
names none) from the agent's `sandbox`. The spec holds each secret as a reference under a variable,
|
|
126
|
+
`ref:file/anthropic-api-key` as `ANTHROPIC_API_KEY`, and `OTEL_RESOURCE_ATTRIBUTES` with the run. The sandbox gets
|
|
127
|
+
a placeholder; its egress proxy puts the key in on the way to `api.anthropic.com`
|
|
128
|
+
([sandbox port](../../ports/sandbox/README.md)). The foreman never reads a secret.
|
|
129
|
+
2. It copies the run's folder into the sandbox, below the sandbox's working folder, as `<run ID>`.
|
|
130
|
+
3. It runs the harness adapter's command line from `FOREMAN_HARNESSES` in the sandbox with the adapter's `exec`, and
|
|
131
|
+
speaks ACP to it. The template must hold that program; `node:24` holds `npx`.
|
|
132
|
+
4. When the turn ended, it copies the folder back into the run's folder, so the next stage finds the files.
|
|
133
|
+
5. It destroys the sandbox, also when the stage failed or was cancelled.
|
|
134
|
+
|
|
135
|
+
`FOREMAN_SANDBOXES` maps an adapter's name to its command line; an adapter it does not name runs
|
|
136
|
+
`npx -y @opensoftware/sandbox-<name>`. A factory names at most one sandbox adapter. An agent without `sandbox` runs on
|
|
137
|
+
the foreman's machine in the run's folder. A sandboxed agent reaches no MCP server yet.
|
|
138
|
+
|
|
139
|
+
## Commands
|
|
140
|
+
|
|
141
|
+
| Command | What it does |
|
|
142
|
+
| --- | --- |
|
|
143
|
+
| `foreman serve` | Serve the run API on `PORT` and run the workflow of `FOREMAN_FACTORY` on the Temporal server at `FOREMAN_TEMPORAL_ADDRESS`; with `FOREMAN_NATS_URL`, start a run for each `work.received@v1`. |
|
|
144
|
+
|
|
145
|
+
## API
|
|
146
|
+
|
|
147
|
+
| Route | What it does |
|
|
148
|
+
| --- | --- |
|
|
149
|
+
| `POST /v1/runs` | Start the run of a work item (the [work item](../../contracts/work-item/work-item.schema.json) format). 201 with the new run, 200 with the run the same work item started before, 400 with a problem that names the field. |
|
|
150
|
+
| `GET /v1/runs/{runId}` | The run: `state`, `factory`, `factoryVersion`, `startedAt`, `endedAt` and its `stages`. 404 for a run the server does not know. |
|
|
151
|
+
| `POST /v1/runs/{runId}/signals` | `{ "type": "steer", "message": "…" }` sends the message to the running stage's agent; `{ "type": "cancel" }` cancels the run. 202 with the run, 409 when the run ended. |
|
|
152
|
+
|
|
153
|
+
The OpenAPI of the routes is in [`contracts/openapi/openapi.json`](../../contracts/openapi/openapi.json); the
|
|
154
|
+
TypeScript type `paths` of `@opensoftware/contracts` types a client. Every route needs `Authorization: Bearer
|
|
155
|
+
<FOREMAN_API_TOKEN>`, else 401. Errors are `application/problem+json` with `title`, `status` and `detail`.
|
|
156
|
+
|
|
157
|
+
A run's ID is `run_` and 20 hex digits of the SHA-256 of the work item's ID, so a work item has one run. A run is
|
|
158
|
+
`running`, `blocked` (at a gate), `complete`, `failed` or `cancelled`. A stage is `pending`, `blocked`, `running`,
|
|
159
|
+
`succeeded`, `failed`, `rejected` (by its gate) or `cancelled`; it has its harness `sessionId` once it started and its
|
|
160
|
+
`gateId` once its gate was asked.
|
|
161
|
+
|
|
162
|
+
## How a run goes
|
|
163
|
+
|
|
164
|
+
- **The factory.** `foreman serve` checks `FOREMAN_FACTORY` against the
|
|
165
|
+
[factory definition](../../contracts/factory-definition/factory-definition.schema.json) when it starts, and that each
|
|
166
|
+
stage's agent is declared; a wrong file exits 2 with the path in the file. Each run reads the file again when it
|
|
167
|
+
starts and keeps that version until it ends. Its `factoryVersion` is the commit of the repository that holds the
|
|
168
|
+
file.
|
|
169
|
+
- **Stages.** The stages run in the order of `workflow`, each in the run's folder `OSF_DATA/runs/<run ID>`, or in a
|
|
170
|
+
sandbox when the stage's agent declares one ([Sandboxes](#sandboxes)). The foreman
|
|
171
|
+
starts the stage's harness adapter from `FOREMAN_HARNESSES`, speaks ACP to it, opens a session and sends one prompt:
|
|
172
|
+
the agent's prompt file, then the work item's ID, title and description. It allows the tool calls the adapter asks
|
|
173
|
+
about; limit them with the adapter's `--allow`. A turn that ends with `end_turn` succeeds the stage; any other end
|
|
174
|
+
fails or cancels it, ends the run, and leaves the later stages `pending`. The adapter gets
|
|
175
|
+
`OTEL_RESOURCE_ATTRIBUTES` with `osf.run.id`, `osf.work_item.id`, `osf.stage` and `osf.factory.version`.
|
|
176
|
+
- **Gates.** Before a stage with a `gate` starts, the foreman asks gatekeeper at `FOREMAN_GATEKEEPER_URL`
|
|
177
|
+
([gatekeeper](../gatekeeper/README.md#server)): the work item's ID, the stage, the summary `<title>: start the
|
|
178
|
+
stage <stage>`, the origin's link, and the gate's `policy` and `approvers` in `change`. The run is `blocked` until a
|
|
179
|
+
`gate.decided@v1` for that gate arrives on NATS. `approved` starts the stage; `rejected` or `expired` fails the run.
|
|
180
|
+
- **Signals.** A steering message reaches the running stage's agent within `FOREMAN_POLL_MS` as a prompt in its
|
|
181
|
+
session, which the harness port treats as steering. A cancel ends the agent's turn, or the wait at a gate, and the
|
|
182
|
+
run is `cancelled`.
|
|
183
|
+
- **Restarts.** The runs live in Temporal's history. A foreman that stops and starts again goes on with them; a stage
|
|
184
|
+
that ran when it stopped runs again, up to 3 times.
|
|
185
|
+
|
|
186
|
+
## Events
|
|
187
|
+
|
|
188
|
+
With `FOREMAN_NATS_URL`, the foreman starts a run for each [`work.received@v1`](../../contracts/events/work-received/work-received.schema.json)
|
|
189
|
+
on `osf.work.received.v1`, and hands each [`gate.decided@v1`](../../contracts/events/gate-decided/gate-decided.schema.json)
|
|
190
|
+
on `osf.gate.decided.v1` to the run of its work item. A run publishes
|
|
191
|
+
[`run.started@v1`](../../contracts/events/run-started/run-started.schema.json) on `osf.run.started.v1` when it starts and
|
|
192
|
+
[`run.completed@v1`](../../contracts/events/run-completed/run-completed.schema.json) on `osf.run.completed.v1` when it
|
|
193
|
+
ends, with the outcome `succeeded`, `failed` or `cancelled`. Their IDs are the run's ID with `.started` and
|
|
194
|
+
`.completed`. The subjects are core NATS: work published while no foreman listens is not started.
|
|
195
|
+
|
|
196
|
+
## Releases
|
|
197
|
+
|
|
198
|
+
release-please opens a release pull request from the Conventional Commits under `modules/foreman/`. Merging it creates
|
|
199
|
+
the tag `foreman-v<version>`. The workflow `.github/workflows/publish-foreman.yml` then builds the package and
|
|
200
|
+
publishes it to npm as `@opensoftware/foreman`. The first release is `0.1.0`; until `1.0.0`, a breaking change raises
|
|
201
|
+
the minor version. The one-time setup is the same as for contracts
|
|
202
|
+
([`contracts/README.md`](../../contracts/README.md#releases)).
|
|
203
|
+
|
|
204
|
+
## Configuration
|
|
205
|
+
|
|
206
|
+
<!-- generated by make docs from src/config.schema.json: do not edit -->
|
|
207
|
+
|
|
208
|
+
| Variable | Type | Default | Meaning |
|
|
209
|
+
| --- | --- | --- | --- |
|
|
210
|
+
| `PORT` | string | `"8080"` | serve: the port the HTTP server listens on. |
|
|
211
|
+
| `OSF_DATA` | string | `".foreman"` | serve: the folder of the runs' working folders, runs/<run ID>, and of the harness adapters' session records. |
|
|
212
|
+
| `OSF_NOW` | string | | The current time, like 2026-01-01T00:00:00Z, for the times of runs and stages. Default: the clock. |
|
|
213
|
+
| `FOREMAN_API_TOKEN` | string | | serve: the token that callers of /v1 send as Authorization: Bearer <token>. Required. |
|
|
214
|
+
| `FOREMAN_FACTORY` | string | `"factory.yaml"` | serve: the factory definition. Its folder must be in a Git repository: a run's factory version is its commit. |
|
|
215
|
+
| `FOREMAN_TEMPORAL_ADDRESS` | string | `"localhost:7233"` | serve: the gRPC address of the Temporal server. |
|
|
216
|
+
| `FOREMAN_TEMPORAL_NAMESPACE` | string | `"default"` | serve: the Temporal namespace of the runs. |
|
|
217
|
+
| `FOREMAN_TASK_QUEUE` | string | `"foreman"` | serve: the Temporal task queue of the runs' workflows and activities. |
|
|
218
|
+
| `FOREMAN_HARNESSES` | string | `"{}"` | serve: a JSON object from harness name to the command line of its adapter. A harness it does not name runs npx -y @opensoftware/harness-<name> run. |
|
|
219
|
+
| `FOREMAN_SANDBOXES` | string | `"{}"` | serve: a JSON object from sandbox adapter name to the command line of the adapter. An adapter it does not name runs npx -y @opensoftware/sandbox-<name>. The factory names its adapter under providers.sandbox, docker by default. |
|
|
220
|
+
| `FOREMAN_POLL_MS` | string | `"1000"` | serve: how often a running stage looks for steering messages and a cancel, in milliseconds. |
|
|
221
|
+
| `FOREMAN_GATEKEEPER_URL` | string | | serve: the URL of gatekeeper serve, which a stage with a gate asks for a decision. Required for a factory with gates. |
|
|
222
|
+
| `FOREMAN_GATEKEEPER_TOKEN` | string | | serve: gatekeeper's API token, GATEKEEPER_API_TOKEN. |
|
|
223
|
+
| `FOREMAN_NATS_URL` | string | | serve: the NATS server for work.received@v1 and gate.decided@v1 in, and run.started@v1 and run.completed@v1 out. Unset: no events. |
|
|
224
|
+
|
|
225
|
+
## Scenarios
|
|
226
|
+
|
|
227
|
+
<!-- generated by make docs from features/: do not edit -->
|
|
228
|
+
|
|
229
|
+
| ID | Status | Scenario |
|
|
230
|
+
| --- | --- | --- |
|
|
231
|
+
| SCN-FORE-001 | implemented | A program starts a run of the README's factory and it completes |
|
|
232
|
+
| SCN-FORE-002 | implemented | Each stage's agent gets its prompt and the work item |
|
|
233
|
+
| SCN-FORE-003 | implemented | The same work item again is the same run |
|
|
234
|
+
| SCN-FORE-004 | implemented | A stage whose turn ends with "refusal" fails the run |
|
|
235
|
+
| SCN-FORE-005 | implemented | A run the server does not know is 404 |
|
|
236
|
+
| SCN-FORE-006 | implemented | A call without the API token is refused |
|
|
237
|
+
| SCN-FORE-007 | implemented | A work item without a title is refused |
|
|
238
|
+
| SCN-FORE-008 | implemented | A run carries the commit of the factory definition |
|
|
239
|
+
| SCN-FORE-009 | implemented | A run keeps its factory version when the factory changes during the run |
|
|
240
|
+
| SCN-FORE-010 | implemented | A stage that names an unknown agent stops the server at the start |
|
|
241
|
+
| SCN-FORE-011 | implemented | The server needs an API token |
|
|
242
|
+
| SCN-FORE-012 | implemented | A stage with a gate asks gatekeeper and the run waits |
|
|
243
|
+
| SCN-FORE-013 | implemented | An approval of the gate starts the stage |
|
|
244
|
+
| SCN-FORE-014 | implemented | A rejection of the gate fails the run |
|
|
245
|
+
| SCN-FORE-015 | implemented | A decision for another gate does not start the stage |
|
|
246
|
+
| SCN-FORE-016 | implemented | A steering message reaches the running stage's agent |
|
|
247
|
+
| SCN-FORE-017 | implemented | A cancel ends the running stage's turn and the run |
|
|
248
|
+
| SCN-FORE-018 | implemented | A cancel ends a run that waits at a gate |
|
|
249
|
+
| SCN-FORE-019 | implemented | A signal to a run that ended is refused |
|
|
250
|
+
| SCN-FORE-020 | implemented | An unknown signal is refused |
|
|
251
|
+
| SCN-FORE-021 | implemented | A run goes on from its history after the foreman restarts |
|
|
252
|
+
| SCN-FORE-022 | implemented | A work item from intake starts a run |
|
|
253
|
+
| SCN-FORE-023 | implemented | A run that ends publishes its outcome and its factory version |
|
|
254
|
+
| SCN-FORE-024 | implemented | The foreman allows a tool call that the stage's agent asks about |
|
|
255
|
+
| SCN-FORE-025 | implemented | A stage whose harness does not start fails the run |
|
|
256
|
+
| SCN-FORE-026 | implemented | A factory outside a Git repository stops the server at the start |
|
|
257
|
+
| SCN-FORE-027 | implemented | An event without a valid work item starts no run |
|
|
258
|
+
| SCN-FORE-028 | implemented | A stage's harness session carries the run |
|
|
259
|
+
| SCN-FORE-029 | implemented | A run that fails publishes the outcome "failed" and the stage that failed |
|
|
260
|
+
| SCN-FORE-030 | implemented | A cancelled run publishes the outcome "cancelled" |
|
|
261
|
+
| SCN-FORE-031 | implemented | Two steering messages reach the agent once each, in order |
|
|
262
|
+
| SCN-FORE-032 | implemented | A stage whose agent declares a sandbox runs in a sandbox created from it |
|
|
263
|
+
| SCN-FORE-033 | implemented | The sandbox spec holds the agent's secret as a reference under its variable |
|
|
264
|
+
| SCN-FORE-034 | implemented | A stage's sandbox carries the run in its environment |
|
|
265
|
+
| SCN-FORE-035 | implemented | A file a stage writes in its sandbox reaches the run's folder and the next stage's sandbox |
|
|
266
|
+
| SCN-FORE-036 | implemented | Each stage's sandbox is destroyed when the stage ends |
|
|
267
|
+
| SCN-FORE-037 | implemented | A cancel destroys the sandbox of the running stage |
|
|
268
|
+
| SCN-FORE-038 | implemented | A sandbox the adapter cannot create fails the run |
|
|
269
|
+
| SCN-FORE-039 | implemented | The sandbox adapter is the one the factory names under "providers.sandbox" |
|
|
270
|
+
| SCN-FORE-040 | implemented | A factory that names two sandbox adapters stops the server at the start |
|
|
271
|
+
| SCN-FORE-041 | implemented | A stage whose agent declares no sandbox runs on the foreman's machine |
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Reads the factory (ADR 0067): factory.yaml, checked against the contract and for its stages' agents, the text of
|
|
2
|
+
// each agent's prompt, and the factory version, the commit of the folder that holds the file.
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { basename, dirname, resolve } from "node:path";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { UsageError } from "@opensoftware/cli";
|
|
8
|
+
import { validate } from "@opensoftware/contracts";
|
|
9
|
+
import { parse } from "yaml";
|
|
10
|
+
import { definitionOf, stageProblems } from "../domain/definition.js";
|
|
11
|
+
/** The factory at `path`; a file that cannot run is a usage error that names the file, the path in it and why. */
|
|
12
|
+
export async function readFactory(path) {
|
|
13
|
+
const file = resolve(path);
|
|
14
|
+
const name = basename(file);
|
|
15
|
+
const document = parse(readFileSync(file, "utf8"));
|
|
16
|
+
const contract = validate("factory-definition", document);
|
|
17
|
+
const problems = contract.length ? contract : stageProblems(document);
|
|
18
|
+
if (problems.length)
|
|
19
|
+
throw new UsageError(problems.map((problem) => `${name}: ${problem.path}: ${problem.message}`).join("\n"));
|
|
20
|
+
const folder = dirname(file);
|
|
21
|
+
const read = (prompt) => readFileSync(resolve(folder, prompt), "utf8");
|
|
22
|
+
return { definition: definitionOf(document, read), version: await commitOf(folder, name) };
|
|
23
|
+
}
|
|
24
|
+
async function commitOf(folder, name) {
|
|
25
|
+
try {
|
|
26
|
+
const { stdout } = await promisify(execFile)("git", ["rev-parse", "HEAD"], { cwd: folder });
|
|
27
|
+
return stdout.trim();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new UsageError(`${name}: commit it in a Git repository; a run's factory version is that commit`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/adapters/factory.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,8FAA8F;AAC9F,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC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CAAC,EAAE,MAAM,CAAC,CAAC;IAC/E,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,QAA6B,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;AAClH,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,MAAc,EAAE,IAAY;IAClD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;QAC5F,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,yEAAyE,CAAC,CAAC;IACzG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function gatekeeper(url, token) {
|
|
2
|
+
return {
|
|
3
|
+
async request(request) {
|
|
4
|
+
if (!url)
|
|
5
|
+
throw new Error("set FOREMAN_GATEKEEPER_URL: a stage has a gate");
|
|
6
|
+
const response = await fetch(new URL("/v1/gates", url), {
|
|
7
|
+
method: "POST",
|
|
8
|
+
headers: { "content-type": "application/json", ...(token ? { authorization: `Bearer ${token}` } : {}) },
|
|
9
|
+
body: JSON.stringify(request),
|
|
10
|
+
});
|
|
11
|
+
const body = await response.text();
|
|
12
|
+
if (!response.ok)
|
|
13
|
+
throw new Error(`gatekeeper answered ${response.status} to the gate request: ${body}`);
|
|
14
|
+
return JSON.parse(body);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=gatekeeper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gatekeeper.js","sourceRoot":"","sources":["../../src/adapters/gatekeeper.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,UAAU,CAAC,GAAuB,EAAE,KAAyB;IAC3E,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,OAAO;YACnB,IAAI,CAAC,GAAG;gBAAE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;YAC5E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE;gBACtD,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;gBACvG,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;aAC9B,CAAC,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,MAAM,yBAAyB,IAAI,EAAE,CAAC,CAAC;YACzG,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAa,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// A stage's agent through the harness port (ADR 0050, ADR 0067): the adapter runs as a program that speaks ACP on
|
|
2
|
+
// stdio, and the foreman is its client. One session per stage, in the run's folder, with one prompt; a prompt sent
|
|
3
|
+
// while the turn runs is a steering message. In a sandbox, the program is the sandbox adapter's exec (ADR 0068).
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { Readable, Writable } from "node:stream";
|
|
6
|
+
import { client, ndJsonStream, PROTOCOL_VERSION } from "@agentclientprotocol/sdk";
|
|
7
|
+
export async function startTurn(options) {
|
|
8
|
+
const [file, ...args] = options.command;
|
|
9
|
+
// The adapter's own messages go to the foreman's standard error.
|
|
10
|
+
const child = spawn(file, args, { cwd: options.cwd, env: options.env, stdio: ["pipe", "pipe", "inherit"] });
|
|
11
|
+
const exited = new Promise((resolve) => {
|
|
12
|
+
child.on("exit", () => resolve("exited"));
|
|
13
|
+
child.on("error", () => resolve("exited"));
|
|
14
|
+
});
|
|
15
|
+
const connection = client({ name: "opensoftware-foreman" })
|
|
16
|
+
// The adapter refuses tool kinds outside its --allow list itself; the foreman allows the rest (ADR 0067).
|
|
17
|
+
.onRequest("session/request_permission", ({ params }) => {
|
|
18
|
+
const allow = params.options.find((option) => option.kind.startsWith("allow"));
|
|
19
|
+
return { outcome: allow ? { outcome: "selected", optionId: allow.optionId } : { outcome: "cancelled" } };
|
|
20
|
+
})
|
|
21
|
+
.connect(ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout)));
|
|
22
|
+
const { agent } = connection;
|
|
23
|
+
const close = async () => {
|
|
24
|
+
connection.close();
|
|
25
|
+
child.stdin.end();
|
|
26
|
+
await Promise.race([exited, new Promise((resolve) => setTimeout(resolve, 1000))]);
|
|
27
|
+
child.kill();
|
|
28
|
+
};
|
|
29
|
+
try {
|
|
30
|
+
const handshake = (async () => {
|
|
31
|
+
await agent.request("initialize", { protocolVersion: PROTOCOL_VERSION, clientCapabilities: {} });
|
|
32
|
+
return agent.request("session/new", { cwd: options.folder, mcpServers: [] });
|
|
33
|
+
})();
|
|
34
|
+
const answer = await Promise.race([handshake, exited]);
|
|
35
|
+
if (typeof answer === "string")
|
|
36
|
+
throw new Error(`the harness ${options.command.join(" ")} exited`);
|
|
37
|
+
const { sessionId } = answer;
|
|
38
|
+
const send = (text) => agent.request("session/prompt", { sessionId, prompt: [{ type: "text", text }] });
|
|
39
|
+
const turn = send(options.prompt).then(({ stopReason }) => stopReason, () => "exited");
|
|
40
|
+
return {
|
|
41
|
+
sessionId,
|
|
42
|
+
done: Promise.race([turn, exited]),
|
|
43
|
+
steer: (text) => void send(text).catch(() => undefined),
|
|
44
|
+
cancel: () => void agent.notify("session/cancel", { sessionId }).catch(() => undefined),
|
|
45
|
+
close,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
await close();
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.js","sourceRoot":"","sources":["../../src/adapters/harness.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,mHAAmH;AACnH,iHAAiH;AACjH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAuBlF,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAoB;IAClD,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,OAAgC,CAAC;IACjE,iEAAiE;IACjE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IAC5G,MAAM,MAAM,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;QAC7C,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1C,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,MAAM,CAAC,EAAE,IAAI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AAC;QACd,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// NATS (ADR 0067): the foreman publishes run.started@v1 and run.completed@v1 and listens for work.received@v1 and
|
|
2
|
+
// gate.decided@v1 on core NATS subjects.
|
|
3
|
+
import { connect } from "@nats-io/transport-node";
|
|
4
|
+
export const SUBJECTS = {
|
|
5
|
+
workReceived: "osf.work.received.v1",
|
|
6
|
+
gateDecided: "osf.gate.decided.v1",
|
|
7
|
+
runStarted: "osf.run.started.v1",
|
|
8
|
+
runCompleted: "osf.run.completed.v1",
|
|
9
|
+
};
|
|
10
|
+
export async function openBus(url, warn) {
|
|
11
|
+
const connection = await connect({ servers: url });
|
|
12
|
+
return {
|
|
13
|
+
async publish(subject, event) {
|
|
14
|
+
connection.publish(subject, JSON.stringify(event));
|
|
15
|
+
await connection.flush();
|
|
16
|
+
},
|
|
17
|
+
subscribe(subject, handle) {
|
|
18
|
+
connection.subscribe(subject, {
|
|
19
|
+
callback: (_error, message) => {
|
|
20
|
+
Promise.resolve()
|
|
21
|
+
.then(() => handle(message.json()))
|
|
22
|
+
.catch((failure) => warn(`${subject}: ${failure.message}`));
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
async close() {
|
|
27
|
+
await connection.drain();
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=nats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nats.js","sourceRoot":"","sources":["../../src/adapters/nats.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,yCAAyC;AACzC,OAAO,EAAE,OAAO,EAAuB,MAAM,yBAAyB,CAAC;AAEvE,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,YAAY,EAAE,sBAAsB;IACpC,WAAW,EAAE,qBAAqB;IAClC,UAAU,EAAE,oBAAoB;IAChC,YAAY,EAAE,sBAAsB;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