@nettee/beacon 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 +201 -0
- package/README.md +163 -0
- package/deploy/io.nettee.beacon.plist.example +32 -0
- package/dist/cli-app.js +71 -0
- package/dist/cli.js +21 -0
- package/dist/config/global.js +84 -0
- package/dist/config/profile.js +126 -0
- package/dist/config/registry.js +12 -0
- package/dist/config/secrets.js +68 -0
- package/dist/config/yaml.js +33 -0
- package/dist/doctor.js +29 -0
- package/dist/domain/types.js +18 -0
- package/dist/feishu/doctor.js +21 -0
- package/dist/feishu/gateway.js +129 -0
- package/dist/feishu/intake.js +67 -0
- package/dist/feishu/message-gateway.js +1 -0
- package/dist/feishu/message-pipeline.js +14 -0
- package/dist/feishu/reply-experiment.js +111 -0
- package/dist/feishu/trigger-input.js +46 -0
- package/dist/manual-trigger.js +59 -0
- package/dist/message/gateway.js +1 -0
- package/dist/outcome/doctor.js +29 -0
- package/dist/outcome/server.js +108 -0
- package/dist/outcome/submit.js +47 -0
- package/dist/run/create-pi-orchestrator.js +21 -0
- package/dist/run/orchestrator.js +269 -0
- package/dist/run/profile-runner.js +39 -0
- package/dist/run/queue.js +46 -0
- package/dist/runtime/pi-doctor.js +14 -0
- package/dist/runtime/pi-outcome-extension.js +53 -0
- package/dist/runtime/pi-rpc.js +247 -0
- package/dist/schedule/cron.js +48 -0
- package/dist/schedule/cursor-store.js +105 -0
- package/dist/schedule/loop.js +45 -0
- package/dist/schedule/reconciler.js +41 -0
- package/dist/service.js +97 -0
- package/dist/state/trigger-store.js +234 -0
- package/dist/version.js +9 -0
- package/examples/config.yaml +12 -0
- package/examples/profiles/example/profile.yaml +13 -0
- package/examples/profiles/example/prompt.md +1 -0
- package/examples/secrets.json.example +11 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Beacon
|
|
2
|
+
|
|
3
|
+
Beacon is a single-host service that turns Feishu messages and configured schedules into isolated Pi agent runs. Each accepted Trigger is durably claimed, produces exactly one explicit Final Outcome, and is delivered either as a quoted reply or to a configured Feishu `chat_id`.
|
|
4
|
+
|
|
5
|
+
This repository currently implements the Feishu + Pi MVP described by the
|
|
6
|
+
[Zest Dev Spec](https://github.com/nettee/beacon/blob/main/specs/change/20260913-beacon-feishu-pi-mvp/spec.md).
|
|
7
|
+
|
|
8
|
+
## Runtime requirements
|
|
9
|
+
|
|
10
|
+
- macOS with Node.js 22 or newer
|
|
11
|
+
- npm
|
|
12
|
+
- A Pi executable and Pi coding-agent directory
|
|
13
|
+
- One Feishu self-built application per Profile, configured for persistent-connection message events and the APIs needed to read/reply/react/create messages
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install --global @nettee/beacon@latest
|
|
19
|
+
beacon version
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Install an exact version when the deployment must be reproducible, including
|
|
23
|
+
when rolling back:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install --global @nettee/beacon@0.1.0
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Upgrade to the current stable release with the same `latest` command. Run
|
|
30
|
+
`beacon doctor` with the production configuration before restarting a running
|
|
31
|
+
service. Beacon does not manage launchd installation, restart, or rollback in
|
|
32
|
+
this release.
|
|
33
|
+
|
|
34
|
+
Beacon only accepts an absolute path for the global configuration:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
beacon doctor --config /Users/USERNAME/.beacon/config.yaml
|
|
38
|
+
beacon serve --config /Users/USERNAME/.beacon/config.yaml
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`doctor` validates every Profile and credential, obtains a Feishu tenant token, and runs a real Pi RPC smoke test. It does not create Beacon state records.
|
|
42
|
+
|
|
43
|
+
## Configuration
|
|
44
|
+
|
|
45
|
+
Copy the files under [`examples`](examples) into a private Beacon home and replace every placeholder. A minimal layout is:
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
~/.beacon/
|
|
49
|
+
├── config.yaml
|
|
50
|
+
├── secrets.json
|
|
51
|
+
└── profiles/
|
|
52
|
+
└── example/
|
|
53
|
+
├── profile.yaml
|
|
54
|
+
└── prompt.md
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Protect the home and secret file before running Beacon:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
chmod 700 /Users/USERNAME/.beacon
|
|
61
|
+
chmod 600 /Users/USERNAME/.beacon/secrets.json
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Configuration is strict: unknown YAML/JSON fields, YAML aliases or warnings, missing paths, duplicate Schedule IDs, invalid timezones/cron expressions, unsafe Prompt paths, permissive secret permissions, and missing Profile credentials all fail startup. Beacon validates all Profiles before opening a Feishu connection.
|
|
65
|
+
|
|
66
|
+
Each Schedule uses a five-field cron expression and an IANA timezone. Its `delivery.chat_id` may identify either a direct chat or a group chat; Beacon deliberately does not infer or fall back to another destination. A newly discovered Schedule starts at the current time. After sleep or restart, overdue occurrences are reconciled and coalesced to the most recent one.
|
|
67
|
+
|
|
68
|
+
## Commands
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
beacon serve --config <absolute-path>
|
|
72
|
+
beacon doctor --config <absolute-path>
|
|
73
|
+
beacon trigger --config <absolute-path> --profile <id> --input -
|
|
74
|
+
beacon version
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
An operator can run one Profile without Feishu delivery by piping input to `trigger`; the Final Outcome is printed to stdout:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
printf '%s\n' 'Summarize the workspace status.' | \
|
|
81
|
+
beacon trigger --config /Users/USERNAME/.beacon/config.yaml --profile example --input -
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## State and failure behavior
|
|
85
|
+
|
|
86
|
+
Per-Profile state lives below `profiles/<profile-id>/state/`. Trigger claims, normalized inputs, Run state, Final Outcomes, Delivery state, and Schedule cursors use durable JSON snapshots. Records do not expire, and Beacon has no automatic cleanup task. Manually deleting state also deletes its deduplication memory.
|
|
87
|
+
|
|
88
|
+
Duplicate Feishu events and duplicate Schedule occurrences do not start a second Run. Active Runs interrupted by restart fail rather than rerun. Pending Delivery can resume, while a Delivery interrupted after its external call began fails without resending. Run and Delivery success are recorded independently. Beacon does not automatically retry either one.
|
|
89
|
+
|
|
90
|
+
Secrets and ephemeral Run Capability tokens are excluded from persisted records and from the Pi environment except for the one Run-scoped Outcome capability.
|
|
91
|
+
|
|
92
|
+
## launchd
|
|
93
|
+
|
|
94
|
+
Edit [`deploy/io.nettee.beacon.plist.example`](deploy/io.nettee.beacon.plist.example) so every executable, config, working-directory, and log path is absolute. Create the log directory, copy the plist to `~/Library/LaunchAgents/io.nettee.beacon.plist`, then validate and load it:
|
|
95
|
+
|
|
96
|
+
Use `command -v beacon` after the global npm installation to find the absolute
|
|
97
|
+
CLI path for `ProgramArguments`. A Node version-manager upgrade can change that
|
|
98
|
+
path, so re-check it when changing the installed Node version.
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
plutil -lint /Users/USERNAME/Library/LaunchAgents/io.nettee.beacon.plist
|
|
102
|
+
launchctl bootstrap gui/$(id -u) /Users/USERNAME/Library/LaunchAgents/io.nettee.beacon.plist
|
|
103
|
+
launchctl print gui/$(id -u)/io.nettee.beacon
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The example uses a restrictive umask and asks launchd to restart only after abnormal exit. `SIGTERM` initiates an orderly shutdown: timers and Gateways stop, accepted intake work drains, and the local Outcome server closes.
|
|
107
|
+
|
|
108
|
+
## Development checks
|
|
109
|
+
|
|
110
|
+
Development requires pnpm 10.33.2. Install dependencies before running checks
|
|
111
|
+
from a source checkout:
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
pnpm install --frozen-lockfile
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
pnpm check
|
|
119
|
+
pnpm typecheck
|
|
120
|
+
pnpm test
|
|
121
|
+
pnpm test:package
|
|
122
|
+
pnpm e2e:message
|
|
123
|
+
pnpm build
|
|
124
|
+
plutil -lint deploy/io.nettee.beacon.plist.example
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`pnpm test:package` builds a production tarball, checks its allowlisted
|
|
128
|
+
contents, installs it under a temporary global npm prefix, and runs the
|
|
129
|
+
installed `beacon` binary without using the source tree.
|
|
130
|
+
|
|
131
|
+
`pnpm e2e:message` sends one synthetic Feishu direct message through an
|
|
132
|
+
in-memory Gateway, the production message pipeline, and a real Pi model. The
|
|
133
|
+
same in-memory Gateway captures the quoted reply without contacting Feishu. It defaults to
|
|
134
|
+
`openai-codex/gpt-5.3-codex-spark`; override the runtime with
|
|
135
|
+
`BEACON_E2E_MESSAGE_PROVIDER`, `BEACON_E2E_MESSAGE_MODEL`,
|
|
136
|
+
`BEACON_E2E_MESSAGE_PI_EXECUTABLE`, or
|
|
137
|
+
`BEACON_E2E_MESSAGE_PI_CODING_AGENT_DIRECTORY`.
|
|
138
|
+
|
|
139
|
+
## Publishing
|
|
140
|
+
|
|
141
|
+
Choose the next semantic version explicitly in `package.json` and
|
|
142
|
+
`pnpm-lock.yaml`, then submit the release candidate through the normal pull
|
|
143
|
+
request checks. After the initial package bootstrap, each push to `main` runs
|
|
144
|
+
the npm publish workflow. It verifies the source and packaged installation,
|
|
145
|
+
publishes a version that is not yet present, and explicitly skips a version
|
|
146
|
+
that already exists.
|
|
147
|
+
|
|
148
|
+
The first `@nettee/beacon` release is a one-time exception because npm requires
|
|
149
|
+
a package to exist before Trusted Publishing can be configured. After the
|
|
150
|
+
`0.1.0` pull request is merged:
|
|
151
|
+
|
|
152
|
+
1. Review `npm pack --dry-run --json`, then publish `0.1.0` interactively with
|
|
153
|
+
npm 2FA using `npm publish --access public`.
|
|
154
|
+
2. Configure `nettee/beacon` and `.github/workflows/publish-npm.yml` as the npm
|
|
155
|
+
Trusted Publisher with direct publish permission.
|
|
156
|
+
3. Set the GitHub repository variable `NPM_TRUSTED_PUBLISHING_ENABLED` to
|
|
157
|
+
`true`.
|
|
158
|
+
4. Install `@nettee/beacon@0.1.0` from the public registry in a clean temporary
|
|
159
|
+
prefix and verify `beacon version` before accepting the release.
|
|
160
|
+
|
|
161
|
+
The repository variable deliberately keeps publishing disabled during the
|
|
162
|
+
bootstrap merge. Subsequent versions publish from GitHub Actions with OIDC and
|
|
163
|
+
do not use a long-lived npm write token.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>Label</key>
|
|
6
|
+
<string>io.nettee.beacon</string>
|
|
7
|
+
<key>ProgramArguments</key>
|
|
8
|
+
<array>
|
|
9
|
+
<string>/usr/local/bin/beacon</string>
|
|
10
|
+
<string>serve</string>
|
|
11
|
+
<string>--config</string>
|
|
12
|
+
<string>/Users/USERNAME/.beacon/config.yaml</string>
|
|
13
|
+
</array>
|
|
14
|
+
<key>WorkingDirectory</key>
|
|
15
|
+
<string>/Users/USERNAME/.beacon</string>
|
|
16
|
+
<key>RunAtLoad</key>
|
|
17
|
+
<true/>
|
|
18
|
+
<key>KeepAlive</key>
|
|
19
|
+
<dict>
|
|
20
|
+
<key>SuccessfulExit</key>
|
|
21
|
+
<false/>
|
|
22
|
+
</dict>
|
|
23
|
+
<key>ThrottleInterval</key>
|
|
24
|
+
<integer>10</integer>
|
|
25
|
+
<key>Umask</key>
|
|
26
|
+
<integer>63</integer>
|
|
27
|
+
<key>StandardOutPath</key>
|
|
28
|
+
<string>/Users/USERNAME/.beacon/logs/service.stdout.log</string>
|
|
29
|
+
<key>StandardErrorPath</key>
|
|
30
|
+
<string>/Users/USERNAME/.beacon/logs/service.stderr.log</string>
|
|
31
|
+
</dict>
|
|
32
|
+
</plist>
|
package/dist/cli-app.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
function usage() {
|
|
3
|
+
throw new Error(`Usage:
|
|
4
|
+
beacon serve --config <absolute-path>
|
|
5
|
+
beacon doctor --config <absolute-path>
|
|
6
|
+
beacon trigger --config <absolute-path> --profile <id> --input -
|
|
7
|
+
beacon version`);
|
|
8
|
+
}
|
|
9
|
+
function configOnly(args) {
|
|
10
|
+
if (args.length !== 2 || args[0] !== "--config" || !args[1])
|
|
11
|
+
usage();
|
|
12
|
+
if (!isAbsolute(args[1]))
|
|
13
|
+
throw new Error("Config path must be absolute");
|
|
14
|
+
return args[1];
|
|
15
|
+
}
|
|
16
|
+
export function parseCli(args) {
|
|
17
|
+
const [command, ...rest] = args;
|
|
18
|
+
if (command === "version") {
|
|
19
|
+
if (rest.length !== 0)
|
|
20
|
+
usage();
|
|
21
|
+
return { command: "version" };
|
|
22
|
+
}
|
|
23
|
+
if (command === "serve" || command === "doctor") {
|
|
24
|
+
return { command, config: configOnly(rest) };
|
|
25
|
+
}
|
|
26
|
+
if (command === "trigger") {
|
|
27
|
+
if (rest.length !== 6)
|
|
28
|
+
usage();
|
|
29
|
+
const values = new Map();
|
|
30
|
+
for (let index = 0; index < rest.length; index += 2) {
|
|
31
|
+
const key = rest[index];
|
|
32
|
+
const value = rest[index + 1];
|
|
33
|
+
if (!key?.startsWith("--") || !value || values.has(key))
|
|
34
|
+
usage();
|
|
35
|
+
values.set(key, value);
|
|
36
|
+
}
|
|
37
|
+
const config = values.get("--config");
|
|
38
|
+
const profile = values.get("--profile");
|
|
39
|
+
if (!config ||
|
|
40
|
+
!profile ||
|
|
41
|
+
values.get("--input") !== "-" ||
|
|
42
|
+
values.size !== 3)
|
|
43
|
+
usage();
|
|
44
|
+
if (!isAbsolute(config))
|
|
45
|
+
throw new Error("Config path must be absolute");
|
|
46
|
+
return { command: "trigger", config, profile };
|
|
47
|
+
}
|
|
48
|
+
if (command === "outcome" && rest.length === 1 && rest[0] === "submit") {
|
|
49
|
+
return { command: "outcome-submit" };
|
|
50
|
+
}
|
|
51
|
+
return usage();
|
|
52
|
+
}
|
|
53
|
+
async function readStdin() {
|
|
54
|
+
process.stdin.setEncoding("utf8");
|
|
55
|
+
let value = "";
|
|
56
|
+
for await (const chunk of process.stdin)
|
|
57
|
+
value += chunk;
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
export async function runCli(command, dependencies) {
|
|
61
|
+
if (command.command === "serve")
|
|
62
|
+
return dependencies.serve(command.config);
|
|
63
|
+
if (command.command === "doctor")
|
|
64
|
+
return dependencies.doctor(command.config);
|
|
65
|
+
if (command.command === "trigger") {
|
|
66
|
+
return dependencies.trigger(command.config, command.profile, await readStdin());
|
|
67
|
+
}
|
|
68
|
+
if (command.command === "outcome-submit")
|
|
69
|
+
return dependencies.submitOutcome();
|
|
70
|
+
console.log(dependencies.version);
|
|
71
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseCli, runCli } from "./cli-app.js";
|
|
3
|
+
import { runDoctor } from "./doctor.js";
|
|
4
|
+
import { runManualTrigger } from "./manual-trigger.js";
|
|
5
|
+
import { submitOutcomeFromCli } from "./outcome/submit.js";
|
|
6
|
+
import { runBeacon } from "./service.js";
|
|
7
|
+
import { packageVersion } from "./version.js";
|
|
8
|
+
async function main() {
|
|
9
|
+
await runCli(parseCli(process.argv.slice(2)), {
|
|
10
|
+
serve: runBeacon,
|
|
11
|
+
doctor: runDoctor,
|
|
12
|
+
trigger: runManualTrigger,
|
|
13
|
+
submitOutcome: submitOutcomeFromCli,
|
|
14
|
+
version: packageVersion,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
main().catch((error) => {
|
|
18
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
+
console.error(`[beacon] fatal: ${message}`);
|
|
20
|
+
process.exitCode = 1;
|
|
21
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { access, realpath, stat } from "node:fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { parseStrictYaml } from "./yaml.js";
|
|
6
|
+
const positiveInteger = z.number().int().positive().safe();
|
|
7
|
+
const globalDocumentSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
version: z.literal(1),
|
|
10
|
+
profiles_directory: z.string().min(1),
|
|
11
|
+
pi: z
|
|
12
|
+
.object({
|
|
13
|
+
executable: z.string().min(1),
|
|
14
|
+
coding_agent_directory: z.string().min(1),
|
|
15
|
+
})
|
|
16
|
+
.strict(),
|
|
17
|
+
runs: z
|
|
18
|
+
.object({
|
|
19
|
+
max_concurrent: positiveInteger,
|
|
20
|
+
max_queued: z.number().int().nonnegative().safe(),
|
|
21
|
+
timeout_seconds: positiveInteger,
|
|
22
|
+
terminate_grace_seconds: positiveInteger,
|
|
23
|
+
})
|
|
24
|
+
.strict(),
|
|
25
|
+
scheduler: z
|
|
26
|
+
.object({ max_occurrences_per_reconciliation: positiveInteger })
|
|
27
|
+
.strict(),
|
|
28
|
+
})
|
|
29
|
+
.strict();
|
|
30
|
+
async function assertFile(path, executable = false) {
|
|
31
|
+
const canonical = await realpath(path).catch((error) => {
|
|
32
|
+
throw new Error(`Required file does not exist: ${path}`, { cause: error });
|
|
33
|
+
});
|
|
34
|
+
const metadata = await stat(canonical);
|
|
35
|
+
if (!metadata.isFile())
|
|
36
|
+
throw new Error(`Required path is not a file: ${path}`);
|
|
37
|
+
if (executable)
|
|
38
|
+
await access(canonical, constants.X_OK);
|
|
39
|
+
return canonical;
|
|
40
|
+
}
|
|
41
|
+
async function assertDirectory(path) {
|
|
42
|
+
const canonical = await realpath(path).catch((error) => {
|
|
43
|
+
throw new Error(`Required directory does not exist: ${path}`, {
|
|
44
|
+
cause: error,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
if (!(await stat(canonical)).isDirectory()) {
|
|
48
|
+
throw new Error(`Required path is not a directory: ${path}`);
|
|
49
|
+
}
|
|
50
|
+
return canonical;
|
|
51
|
+
}
|
|
52
|
+
export async function loadGlobalConfig(path) {
|
|
53
|
+
if (!isAbsolute(path))
|
|
54
|
+
throw new Error(`Global config path must be absolute: ${path}`);
|
|
55
|
+
const canonicalPath = await assertFile(path);
|
|
56
|
+
const document = globalDocumentSchema.parse(await parseStrictYaml(canonicalPath));
|
|
57
|
+
const homeDirectory = dirname(canonicalPath);
|
|
58
|
+
const resolveFromHome = (value) => isAbsolute(value) ? value : resolve(homeDirectory, value);
|
|
59
|
+
const profilesDirectory = await assertDirectory(resolveFromHome(document.profiles_directory));
|
|
60
|
+
if (!isAbsolute(document.pi.executable)) {
|
|
61
|
+
throw new Error("Pi executable path must be absolute");
|
|
62
|
+
}
|
|
63
|
+
if (!isAbsolute(document.pi.coding_agent_directory)) {
|
|
64
|
+
throw new Error("Pi coding agent directory must be absolute");
|
|
65
|
+
}
|
|
66
|
+
const executable = await assertFile(document.pi.executable, true);
|
|
67
|
+
const codingAgentDirectory = await assertDirectory(document.pi.coding_agent_directory);
|
|
68
|
+
return {
|
|
69
|
+
path: canonicalPath,
|
|
70
|
+
homeDirectory,
|
|
71
|
+
profilesDirectory,
|
|
72
|
+
secretsPath: resolve(homeDirectory, "secrets.json"),
|
|
73
|
+
pi: { executable, codingAgentDirectory },
|
|
74
|
+
runs: {
|
|
75
|
+
maxConcurrent: document.runs.max_concurrent,
|
|
76
|
+
maxQueued: document.runs.max_queued,
|
|
77
|
+
timeoutSeconds: document.runs.timeout_seconds,
|
|
78
|
+
terminateGraceSeconds: document.runs.terminate_grace_seconds,
|
|
79
|
+
},
|
|
80
|
+
scheduler: {
|
|
81
|
+
maxOccurrencesPerReconciliation: document.scheduler.max_occurrences_per_reconciliation,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|