@flyingrobots/parley-emit 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/CHANGELOG.md +41 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +167 -2
- package/package.json +34 -4
- package/src/index.ts +8 -0
- package/src/inv.ts +72 -0
- package/src/location.ts +111 -0
- package/src/redact.ts +108 -0
- package/src/run.ts +304 -0
- package/src/schemas.ts +1408 -0
- package/src/tool.ts +328 -0
- package/src/ulid.ts +13 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This package is versioned
|
|
4
|
+
on its own; the spec and each message schema move separately (spec §4.4).
|
|
5
|
+
|
|
6
|
+
## [Unreleased]
|
|
7
|
+
|
|
8
|
+
## [0.1.0] — 2026-11-22
|
|
9
|
+
|
|
10
|
+
The schemas this version ships are the repository drafts at the commit recorded in
|
|
11
|
+
`src/schemas.ts`; no schema version is released by this package release (spec §4.5).
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `defineTool` and `main`: a tool declares its commands, effects, secrets, emitted types and
|
|
16
|
+
retention; `main` turns argv and a handler into a conforming run and returns the exit status.
|
|
17
|
+
- `Run`: `result`, `page`, `step`, `warning`, `error`, `input`, `finaliseInputs`, `end`; one
|
|
18
|
+
sequence across stdout, stderr and the receipt; sidecars over 65,536 bytes; redaction of declared
|
|
19
|
+
secrets with `redaction` events; `ParleyClosed` after `end`.
|
|
20
|
+
- Receipt location with repository hygiene and the state-directory fallback; retention by count;
|
|
21
|
+
`--dry-run`; `--schema` and `--help` as runs; `--human`; console capture; the top-level handler.
|
|
22
|
+
- `inv` as documented in the README; `ulid` run ids.
|
|
23
|
+
- The fourteen draft schemas at the pinned commit, with a test that they match the repository.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- After the review of the first candidate: declared secrets of every command count on every path,
|
|
28
|
+
the `end` record is scrubbed, the envelope and digests never are, and a run id or receipt path
|
|
29
|
+
that would carry a secret is never chosen; the `inv` preimage takes redacted input descriptors;
|
|
30
|
+
a throw before the bootstrap line is `startup.arguments_invalid`; the head is never a sidecar
|
|
31
|
+
and a bootstrap sink failure is reported after it; a sidecar failure keeps the receipt usable;
|
|
32
|
+
envelope keys from the tool are refused; `end(0)` after an error is refused; retention deletes
|
|
33
|
+
only completed bundles; every `console` function is captured; tree inputs skip `.parley` and
|
|
34
|
+
honour `exclude`; absolute input paths resolve; the ignore file is linked into place whole; the
|
|
35
|
+
state directory's retention is declared; console capture starts before the tool's resolvers run;
|
|
36
|
+
a failing renderer is one warning; a throw during discovery is an error line; an uncaught
|
|
37
|
+
throw's stack stays in the receipt; a failed `end` in `--human` mode names the receipt. From the
|
|
38
|
+
blind pass over the repaired head: the default descriptor sinks retry a full pipe and continue a
|
|
39
|
+
partial write; numbers, booleans and object keys are redacted; the longest secret is replaced
|
|
40
|
+
first, and the writer's own scalars and the public identity in writer-built records (tool, command and schema names and versions, discovery lines included) are never scrubbed; a secret in the
|
|
41
|
+
session is `startup.secret_in_identity`; a sidecar that cannot be written is kept inline.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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 2026 James Ross
|
|
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.
|
|
202
|
+
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,168 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @flyingrobots/parley-emit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A writer for the [Parley output protocol](../../spec/parley-v0.2.md). A tool conforms by
|
|
4
|
+
constructing a writer and emitting through it; the writer owns everything the protocol asks of a
|
|
5
|
+
program that is not the program's own result: the bootstrap line, the receipt and where it goes,
|
|
6
|
+
the single sequence across streams, `inv`, redaction, sidecars, retention, discovery, the
|
|
7
|
+
`--human` renderer, the top-level handler and the exit status.
|
|
8
|
+
|
|
9
|
+
Spec version `0.2.0`. Package version moves with this code; each message schema moves on its own
|
|
10
|
+
(spec §4.4). The schemas this package ships are the repository drafts at the commit recorded in
|
|
11
|
+
`src/schemas.ts`, byte-identical by test (spec §4.5).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Bun 1.2 or later. No runtime dependencies.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @flyingrobots/parley-emit
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## The smallest tool
|
|
22
|
+
|
|
23
|
+
`examples/count.ts`, abridged:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { defineTool, main } from "@flyingrobots/parley-emit";
|
|
27
|
+
|
|
28
|
+
const tool = defineTool({
|
|
29
|
+
name: "count", version: "0.1.0",
|
|
30
|
+
commands: {
|
|
31
|
+
files: {
|
|
32
|
+
intent: "Count the regular files directly under the working directory",
|
|
33
|
+
effects: { reads: ["<cwd>/*"], writes: [], network: false, idempotent: true },
|
|
34
|
+
secrets: [],
|
|
35
|
+
emits: [{ id: "count.result", version: "1.0.0", schema: COUNT }],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
retention: { count: 50 },
|
|
39
|
+
human: (line) => (line.event === "result" ? `${String(line.files)} file(s)` : null),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const status = await main(tool, ["count", ...process.argv.slice(2)], (run) => {
|
|
43
|
+
const names = regularFilesUnder(run.cwd);
|
|
44
|
+
run.step(`counted ${names.length} regular file(s)`, "only regular files count", { names });
|
|
45
|
+
run.result({ event: "result", files: names.length }, { id: "count.result", version: "1.0.0" });
|
|
46
|
+
});
|
|
47
|
+
process.exit(status);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Captured from `bun run examples/count.ts files` in a directory holding exactly two regular
|
|
51
|
+
files, with the streams redirected to files outside it, on 2026-11-22. stdout, three lines:
|
|
52
|
+
|
|
53
|
+
```jsonl
|
|
54
|
+
{"event":"run","t":1795352899887,"seq":0,"run":"01M81NYC9E28S33150VJB8ZP7E","tool":"count","v":"0.1.0","inv":"638c446f866624d00aed41b516d92549f87b0197871ae5db312b7edaa8051a16","paths":{"receipt":"/private/tmp/parley-emit-readme.Ra5U/work/.parley/receipts/01M81NYC9E28S33150VJB8ZP7E.jsonl"},"_schema":{"id":"parley.run.bootstrap","version":"1.1.1"}}
|
|
55
|
+
{"event":"result","t":1795352899890,"seq":3,"run":"01M81NYC9E28S33150VJB8ZP7E","files":2,"_schema":{"id":"count.result","version":"1.0.0"}}
|
|
56
|
+
{"event":"end","t":1795352899890,"seq":4,"run":"01M81NYC9E28S33150VJB8ZP7E","status":0,"receipt":"/private/tmp/parley-emit-readme.Ra5U/work/.parley/receipts/01M81NYC9E28S33150VJB8ZP7E.jsonl","redacted":false,"_schema":{"id":"parley.end","version":"1.0.0"}}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The receipt the bootstrap line names:
|
|
60
|
+
|
|
61
|
+
```jsonl
|
|
62
|
+
{"event":"receipt.head","t":1795352899887,"seq":1,"run":"01M81NYC9E28S33150VJB8ZP7E","tool":"count","v":"0.1.0","inv":"638c446f866624d00aed41b516d92549f87b0197871ae5db312b7edaa8051a16","argv":["count","files"],"resolved":{"command":"files","args":[]},"inputs":[],"effects":{"reads":["<cwd>/*"],"writes":[],"network":false,"idempotent":true,"bookkeeping":[{"op":"create","scope":"/private/tmp/parley-emit-readme.Ra5U/work/.parley/receipts/"},{"op":"create","scope":"/private/tmp/parley-emit-readme.Ra5U/work/.parley/.gitignore"},{"op":"delete","scope":"/private/tmp/parley-emit-readme.Ra5U/work/.parley/receipts/"},{"op":"create","scope":"/tmp/parley-emit-readme.Ra5U/state/parley/4b10e884505764fd/receipts/"},{"op":"delete","scope":"/tmp/parley-emit-readme.Ra5U/state/parley/4b10e884505764fd/receipts/"}]},"_schema":{"id":"parley.receipt.head","version":"2.0.0"}}
|
|
63
|
+
{"event":"receipt.step","t":1795352899890,"seq":2,"run":"01M81NYC9E28S33150VJB8ZP7E","decision":"counted 2 regular file(s)","because":"directories and special files are not files; only regular files count","detail":{"names":["b.txt","a.txt"]},"_schema":{"id":"parley.receipt.step","version":"1.0.0"}}
|
|
64
|
+
{"event":"result","t":1795352899890,"seq":3,"run":"01M81NYC9E28S33150VJB8ZP7E","files":2,"_schema":{"id":"count.result","version":"1.0.0"}}
|
|
65
|
+
{"event":"end","t":1795352899890,"seq":4,"run":"01M81NYC9E28S33150VJB8ZP7E","status":0,"receipt":"/private/tmp/parley-emit-readme.Ra5U/work/.parley/receipts/01M81NYC9E28S33150VJB8ZP7E.jsonl","redacted":false,"_schema":{"id":"parley.end","version":"1.0.0"}}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
stderr was empty. The exit status was 0. The repository doctor reports the three streams
|
|
69
|
+
conforming (`bun run doctor --stdout ... --stderr ... --receipt ...`).
|
|
70
|
+
|
|
71
|
+
## What the writer does for you
|
|
72
|
+
|
|
73
|
+
| Spec | Behaviour |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| §3.1 | Creates the receipt before announcing it; the bootstrap line is the first line on any stream, `seq: 0`, stdout only, before the handler runs |
|
|
76
|
+
| §5, §5.2 | `.parley/receipts/<run>.jsonl` under the initial working directory, after `.parley/.gitignore` holds a line `*` (created if absent, linked into place whole, never overwritten). The receipt goes to `$XDG_STATE_HOME/parley/<repo-hash>/receipts/` instead, with a `receipt.relocated` warning, when the ignore file is a user's without `*` or when the working-directory path would carry a declared secret value; an unwritable working directory falls back the same way, silently (the bootstrap line says where). No writable location is `startup.receipt_unwritable`; a state path that would also carry the secret is `startup.secret_in_path`; both exit 3 |
|
|
77
|
+
| §1.3 | One counter for the run; copies of one event share `seq`, `t` and `event`; a receipt copy may carry more (`receiptExtra`) |
|
|
78
|
+
| §2.2 | `inv` over tool, version, command, the redacted resolved interpretation and the bytes of every declared input (see below); on the bootstrap line and head when no inputs are declared, else in `receipt.inputs` before `end`; omitted when any input is unreadable. With no declared inputs it identifies the question only, not the state of the world |
|
|
79
|
+
| §5.3 | Declared flags, variables and sources of every command, whichever command runs: values replaced with `[redacted]` in `argv`, `resolved`, `inputs` and the payload of every later record, `end` included, before any copy leaves the process. Replacement is within strings, longest secret first; a number, boolean or bigint whose decimal form is a secret becomes `[redacted]` (a PIN parsed to a number is still the PIN); an object key carrying a secret is renamed. The head's `redacted` records where; a later surfacing is recorded by a `redaction` event; `end.redacted` aggregates. The envelope, the writer's digests and the public identity a writer-built record carries (the tool's name and version, a command's name, a schema's id and version, discovery lines included) are never scrubbed, and a writer-built scalar (`status`, `dry_run`, `network`) is never a secret: a run id or receipt path that would carry a secret is never chosen; a session that carries one is `startup.secret_in_identity`, exit 3; the tool's own name and version are public and printed as they are |
|
|
80
|
+
| §5 | A receipt record over 65,536 bytes becomes a sidecar `<run>/<seq>.json` with a `sidecar` event in its place; if the sidecar cannot be written the record is kept inline, so the bundle stays complete, and the failure is a `sink.sidecar_failed` error with status 4 |
|
|
81
|
+
| §5.1 | Retention by count per location, oldest completed bundles first (a receipt whose last line is `end`, or one without an `end` older than a day), recorded as a `receipt.step`; never a receipt still in flight; never on `--dry-run` |
|
|
82
|
+
| §4.1, §4.2 | `--schema` and `<command> --help` are runs that emit `command` and `schema` lines |
|
|
83
|
+
| §4.3 | `--dry-run` marks the bootstrap line and head and performs no retention deletion; the handler reads `run.dryRun` |
|
|
84
|
+
| §6, §3.2 | An uncaught throw in the handler, or while discovery is being emitted, becomes an `error` with code `uncaught.exception` whose stack goes to the receipt copy only; a reported error closes the run with status 2, and `end(0)` after one is refused. A throw from `resolved` or `inputs` before the bootstrap line is `startup.arguments_invalid`, exit 3, with the reserved receipt removed; a source resolver that throws means the source is not present; a throwing `human` renderer is reported once as a `human.renderer_failed` warning and the default rendering is used |
|
|
85
|
+
| §5.4, §3.3 | The default stdout and stderr sinks deliver whole lines: a partial write continues and a full pipe (EAGAIN on a descriptor the runtime left non-blocking) waits and retries, as a blocking write would. A sink failure before `end` is an `error` on the sinks still working and status 4; a failed bootstrap write is reported after the head, so the head stays the receipt's first line; after `end` nothing is written and the status alone carries a failure; emitting after `end` throws `ParleyClosed`. A record or `receiptExtra` carrying `t`, `seq`, `run` or `_schema` is a `TypeError` |
|
|
86
|
+
| §1.2 | Every function on `console`, called from the moment `main` starts until it returns, is captured into the run's receipt as a step; text captured before the receipt exists is held and written after the head. This contains libraries that log through `console`; it does not contain a library that writes to a file descriptor directly, or a timer that fires after `end` (see the exceptions below) |
|
|
87
|
+
| §1.1 | `--human` (alias `--humanize`) renders stdout and stderr through the tool's `human` function, falling back to one line per event; the bootstrap line and a successful `end` render as nothing, so `tool --human \| gh pr comment --body-file -` posts only the tool's prose, and a failed `end` names the receipt path; the receipt is unchanged |
|
|
88
|
+
|
|
89
|
+
## Arguments and flags
|
|
90
|
+
|
|
91
|
+
`main` takes `argv` as `[tool.name, ...process.argv.slice(2)]`: the first element names the tool
|
|
92
|
+
and is echoed in the head's `argv`. The command is the first positional argument that names one
|
|
93
|
+
of the tool's own commands; a tool with one command needs none. The writer's flags, `--human`,
|
|
94
|
+
`--humanize`, `--dry-run`, `--schema`, `--help` and `-h`, are recognised anywhere and removed
|
|
95
|
+
from the arguments the handler sees. `PARLEY_SESSION` in the environment, or the `session`
|
|
96
|
+
option, is carried as `session` on the bootstrap line and head; the writer never invents one.
|
|
97
|
+
|
|
98
|
+
## How this package derives `inv`
|
|
99
|
+
|
|
100
|
+
`inv` is SHA-256, hex, over the canonical JSON (keys sorted, no whitespace, UTF-8) of:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
{ tool, v, command, resolved, inputs: [{ path, role?, sha256 }] }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`resolved` is the interpretation after defaults, already redacted, so the fact that a declared
|
|
107
|
+
secret was supplied enters by name and its value never does (spec §2.2); the input descriptors in
|
|
108
|
+
the preimage are the redacted ones for the same reason, so a secret in an input path never enters
|
|
109
|
+
either. Each input's `sha256` is over its bytes; a `tree` input digests every regular file under
|
|
110
|
+
it in sorted path order as `path NUL digest LF`, skipping `.parley` directories and the paths in
|
|
111
|
+
its `exclude` list, so the relative names inside a tree are part of its identity and must not
|
|
112
|
+
carry a secret. The run id, receipt path, session and clock are not in the preimage.
|
|
113
|
+
|
|
114
|
+
What the tool supplies as `resolved` is in the preimage, so it must be order-normalised (sort
|
|
115
|
+
flags, resolve defaults) and free of volatile values: the working directory, the time, a process
|
|
116
|
+
id. The spec's own head example carries `cwd` in `resolved`; a tool that copies that will have an
|
|
117
|
+
`inv` that moves with the directory. With no declared inputs, `inv` covers the tool, version,
|
|
118
|
+
command and `resolved` only: it identifies the question, not the state of the world, and two runs
|
|
119
|
+
over different files will share it. A tool whose answer depends on content it does not declare as
|
|
120
|
+
an input should carry that content's address in `resolved`, as footprint carries the commit ids
|
|
121
|
+
of the range it compares. Two invocations differing only in a declared secret share an `inv`,
|
|
122
|
+
which is why a redacted receipt is never replayed (spec §2.3).
|
|
123
|
+
|
|
124
|
+
## Declared inputs
|
|
125
|
+
|
|
126
|
+
`main`'s `inputs` option maps the command's arguments to declared inputs,
|
|
127
|
+
`{ path, role?, exclude? }`; it may be async. A relative path is resolved against the initial
|
|
128
|
+
working directory; an absolute path stands, and enters the `inv` preimage as given, so prefer
|
|
129
|
+
relative paths and never a temporary one. Roles: a file (default), `tree` for a directory,
|
|
130
|
+
`stdin` for bytes the handler supplies with `run.input("-", bytes)`. An input the writer cannot
|
|
131
|
+
read is recorded with `error: input.unreadable`; a stdin input never supplied is `input.unread`.
|
|
132
|
+
Either omits `inv`.
|
|
133
|
+
|
|
134
|
+
A `tree` must not contain a credential source (spec §2.2: its bytes must not reach `inv` through
|
|
135
|
+
a directory digest). Name such files in `exclude`, as relative paths under the tree; if you cannot
|
|
136
|
+
name them, do not declare the tree. The writer's own `.parley` directory is always skipped, so the
|
|
137
|
+
working directory can be a tree without the receipts moving `inv` on every run.
|
|
138
|
+
|
|
139
|
+
## Retention
|
|
140
|
+
|
|
141
|
+
A tool states its policy as `retention: { count }` and the writer enforces it: when a location
|
|
142
|
+
holds more than `count` receipts, the oldest bundles beyond it are deleted, receipt and sidecar
|
|
143
|
+
directory together, and the deletion is recorded.
|
|
144
|
+
|
|
145
|
+
## What a receipt can contain
|
|
146
|
+
|
|
147
|
+
Everything the handler passes to `result`, `step`, `warning` and `error`, the raw and resolved
|
|
148
|
+
arguments, input paths and digests, captured console text, and copies of every result. Declared
|
|
149
|
+
secrets are replaced before writing; an undeclared secret is not, so declare it.
|
|
150
|
+
|
|
151
|
+
## Exceptions the protocol names
|
|
152
|
+
|
|
153
|
+
These are the places the writer's promises do not reach, named as spec §6 asks:
|
|
154
|
+
|
|
155
|
+
- A hard crash inside a native dependency or a signal kill ends the process without `end`; a
|
|
156
|
+
reader sees incomplete lifecycle evidence, which is what spec §3.3 says it is.
|
|
157
|
+
- A library that writes to file descriptor 1 or 2 directly, rather than through `console`, puts
|
|
158
|
+
its bytes on the stream. Spec §1.4 tells readers to quarantine such lines; the writer cannot
|
|
159
|
+
intercept them.
|
|
160
|
+
- A timer or callback that logs after `end` has nothing to be captured into; its text reaches the
|
|
161
|
+
stream, and the process should exit promptly after `main` returns.
|
|
162
|
+
- A source resolver runs before the bootstrap line and may have side effects of its own.
|
|
163
|
+
|
|
164
|
+
The writer uses synchronous writes so that on every other path the receipt is complete.
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
Apache-2.0.
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flyingrobots/parley-emit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A writer for the Parley output protocol: bootstrap, receipt, sequence, redaction, end, exit status.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"README.md",
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"NOTICE"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "bun test",
|
|
21
|
+
"sync-schemas": "bun run scripts/sync-schemas.ts"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/flyingrobots/parley.git",
|
|
26
|
+
"directory": "packages/parley-emit"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"registry": "https://registry.npmjs.org/"
|
|
31
|
+
},
|
|
32
|
+
"author": "James Ross",
|
|
33
|
+
"engines": {
|
|
34
|
+
"bun": ">=1.2"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { defineTool, main, type CommandSpec, type Effects, type EmittedType, type Handler, type InputDecl, type MainOptions, type ToolSpec } from "./tool.ts";
|
|
2
|
+
export { Run, ParleyClosed, SCHEMA_IDS, SIDECAR_THRESHOLD, type Diagnostic, type SchemaRef, type Sink } from "./run.ts";
|
|
3
|
+
export { REDACTED } from "./redact.ts";
|
|
4
|
+
export { SCHEMAS, SCHEMA_SOURCE } from "./schemas.ts";
|
|
5
|
+
export { ulid } from "./ulid.ts";
|
|
6
|
+
export { canonical, computeInv, digestTree, sha256, type InputDescriptor } from "./inv.ts";
|
|
7
|
+
export { chooseLocation, isLocationFailure, repoRoot, stateBase, bookkeepingFor } from "./location.ts";
|
|
8
|
+
export { carriesSecret, classifySecrets, collectSecretValues, redactArgv, scrub } from "./redact.ts";
|
package/src/inv.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// `inv` (spec §2.2): the identity of a question. This package's derivation, which the spec asks
|
|
2
|
+
// every supplier to document:
|
|
3
|
+
//
|
|
4
|
+
// inv = SHA-256 over the canonical JSON (keys sorted, no whitespace, UTF-8) of
|
|
5
|
+
// { tool, v, command, resolved, inputs: [{ path, role?, sha256 }] }
|
|
6
|
+
//
|
|
7
|
+
// `resolved` is the interpretation after defaults, with every declared secret already replaced by
|
|
8
|
+
// `[redacted]`, so the fact of supply enters by name and the value never does; the input
|
|
9
|
+
// descriptors in the preimage are the redacted ones for the same reason. Input digests are over
|
|
10
|
+
// bytes, never paths alone; a `tree` input digests its regular files in sorted path order,
|
|
11
|
+
// skipping every `.parley` directory and every path under the declaration's `exclude` list. The
|
|
12
|
+
// working directory, the run id, the receipt path, the session and the clock are not in the
|
|
13
|
+
// preimage. If any declared input could not be read, there is no `inv`.
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
15
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
16
|
+
import { join, resolve } from "node:path";
|
|
17
|
+
|
|
18
|
+
export function canonical(v: unknown): string {
|
|
19
|
+
if (Array.isArray(v)) return "[" + v.map(canonical).join(",") + "]";
|
|
20
|
+
if (v && typeof v === "object") {
|
|
21
|
+
const o = v as Record<string, unknown>;
|
|
22
|
+
return "{" + Object.keys(o).sort().filter((k) => o[k] !== undefined).map((k) => JSON.stringify(k) + ":" + canonical(o[k])).join(",") + "}";
|
|
23
|
+
}
|
|
24
|
+
return JSON.stringify(v) ?? "null";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function sha256(bytes: Uint8Array | string): string { return createHash("sha256").update(bytes).digest("hex"); }
|
|
28
|
+
|
|
29
|
+
export interface InputDecl { path: string; role?: string; /** Relative paths under a `tree` input to leave out of its digest, such as a credential file. */ exclude?: readonly string[] }
|
|
30
|
+
export interface InputDescriptor { path: string; role?: string; sha256?: string; error?: string }
|
|
31
|
+
|
|
32
|
+
export function computeInv(pre: { tool: string; v: string; command: string; resolved: unknown; inputs: InputDescriptor[] }): string | undefined {
|
|
33
|
+
if (pre.inputs.some((i) => i.sha256 === undefined)) return undefined;
|
|
34
|
+
return sha256(canonical({ tool: pre.tool, v: pre.v, command: pre.command, resolved: pre.resolved, inputs: pre.inputs.map((i) => ({ path: i.path, role: i.role, sha256: i.sha256 })) }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function excluded(rel: string, exclude: readonly string[]): boolean {
|
|
38
|
+
return exclude.some((e) => { const x = e.replace(/\/+$/, ""); return rel === x || rel.startsWith(x + "/"); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Digest of a directory: SHA-256 over `relative-path NUL file-digest LF` for every regular file, sorted by path, skipping `.parley` directories and excluded paths. */
|
|
42
|
+
export function digestTree(root: string, exclude: readonly string[] = []): string {
|
|
43
|
+
const files: string[] = [];
|
|
44
|
+
const walk = (dir: string, rel: string) => {
|
|
45
|
+
for (const name of readdirSync(dir).sort()) {
|
|
46
|
+
if (name === ".parley") continue;
|
|
47
|
+
const p = join(dir, name), r = rel ? `${rel}/${name}` : name;
|
|
48
|
+
if (excluded(r, exclude)) continue;
|
|
49
|
+
const st = statSync(p);
|
|
50
|
+
if (st.isDirectory()) walk(p, r); else if (st.isFile()) files.push(r);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
walk(root, "");
|
|
54
|
+
const h = createHash("sha256");
|
|
55
|
+
for (const r of files) h.update(r + "\0" + sha256(readFileSync(join(root, r))) + "\n");
|
|
56
|
+
return h.digest("hex");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Digest a declared input by role; an unreadable input yields an `error` code and no digest. A relative path is resolved against `cwd`; an absolute one stands. */
|
|
60
|
+
export function digestInput(cwd: string, input: InputDecl, supplied?: Uint8Array): InputDescriptor {
|
|
61
|
+
const base: InputDescriptor = { path: input.path, ...(input.role ? { role: input.role } : {}) };
|
|
62
|
+
try {
|
|
63
|
+
if (input.role === "stdin") return supplied ? { ...base, sha256: sha256(supplied) } : { ...base, error: "input.unread" };
|
|
64
|
+
if (supplied) return { ...base, sha256: sha256(supplied) };
|
|
65
|
+
const p = resolve(cwd, input.path);
|
|
66
|
+
const st = statSync(p);
|
|
67
|
+
if (st.isDirectory() || input.role === "tree") return { ...base, sha256: digestTree(p, input.exclude ?? []) };
|
|
68
|
+
return { ...base, sha256: sha256(readFileSync(p)) };
|
|
69
|
+
} catch {
|
|
70
|
+
return { ...base, error: "input.unreadable" };
|
|
71
|
+
}
|
|
72
|
+
}
|