@flyingrobots/parley-emit 0.1.0 → 0.2.4
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 +295 -0
- package/README.md +517 -15
- package/package.json +1 -1
- package/src/check.ts +198 -0
- package/src/history.ts +229 -0
- package/src/index.ts +7 -1
- package/src/location.ts +47 -4
- package/src/refusal.ts +54 -0
- package/src/run.ts +279 -15
- package/src/schemas.ts +635 -1
- package/src/tool.ts +160 -25
- package/src/transforms/declared.ts +49 -0
- package/src/transforms/secret-patterns.ts +84 -0
- package/src/transforms/secrets.ts +153 -0
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@ the single sequence across streams, `inv`, redaction, sidecars, retention, disco
|
|
|
7
7
|
`--human` renderer, the top-level handler and the exit status.
|
|
8
8
|
|
|
9
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
|
|
11
|
-
`src/schemas.ts`, byte-identical by test (spec §4.5).
|
|
10
|
+
(spec §4.4). The schemas this package ships are the versions released with spec `0.2.0`, copied from
|
|
11
|
+
`schemas/` at the commit recorded in `src/schemas.ts`, byte-identical by test (spec §4.5).
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
@@ -43,7 +43,7 @@ const status = await main(tool, ["count", ...process.argv.slice(2)], (run) => {
|
|
|
43
43
|
const names = regularFilesUnder(run.cwd);
|
|
44
44
|
run.step(`counted ${names.length} regular file(s)`, "only regular files count", { names });
|
|
45
45
|
run.result({ event: "result", files: names.length }, { id: "count.result", version: "1.0.0" });
|
|
46
|
-
});
|
|
46
|
+
}, { resolved: interpret }); // interpret throws on an argument, before the bootstrap line
|
|
47
47
|
process.exit(status);
|
|
48
48
|
```
|
|
49
49
|
|
|
@@ -73,27 +73,52 @@ conforming (`bun run doctor --stdout ... --stderr ... --receipt ...`).
|
|
|
73
73
|
| Spec | Behaviour |
|
|
74
74
|
| --- | --- |
|
|
75
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
|
|
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 with a negation that can re-include `receipts/`, such as `!receipts/` or `!*/`; a negation the writer cannot evaluate counts as one) 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
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
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 |
|
|
79
|
+
| §5.3 | Scrub widely, resolve narrowly (flyingrobots/parley#93): only the running command's credential sources are resolved and listed in `redacted.sources`, and another command's never are, while the declared flags and variables of every command, whichever command runs, are scrubbed and those present are named in `redacted.env`. Their values are 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, and the `code` of a diagnostic the writer itself raises, whose corruption would put an invalid line on the stream; a tool's own diagnostic is not writer-built and its `code` is scrubbed like anything else) are never scrubbed, and a writer-built scalar (`status`, `dry_run`, `network`) is never a secret. The schema document a `schema` line publishes is the tool's static declaration and is published as declared (flyingrobots/parley#111); every other discovery field is scrubbed: 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
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 |
|
|
81
|
+
| §5.1 | Retention by count of this tool's own receipts per location (another tool's are never counted), oldest completed bundles first (a receipt whose last line is `end`, or one without an `end` older than a day, judged at the decision; a receipt that moved before the unlink is spared; no lock, so a run silent for over a day that then appends while retention deletes its receipt loses it, flyingrobots/parley#112), 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. A command's error types default to `parley.error` and `parley.startup.failed`, since every command can produce a startup failure (flyingrobots/parley#92); a command that declares `errors` replaces the default and names both itself |
|
|
83
83
|
| §4.3 | `--dry-run` marks the bootstrap line and head and performs no retention deletion; the handler reads `run.dryRun` |
|
|
84
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
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
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
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
|
+
| §8 (informative) | An opt-in second sink: with `PARLEY_HISTORY` set or `$XDG_STATE_HOME/parley/history` present, every line of the receipt is also appended to a dated daily segment shared by every tool, repository and agent on the machine, named in `paths.history` and declared in `effects.bookkeeping`. Same bytes, so the same redaction; one whole line per write under `O_APPEND`; retention by whole segment; a stream that cannot be written is a warning and never an error, a sink failure or a different exit status. With a `history.transform` configured the stream copy is a projection of those bytes instead, opening with a `parley.history.transform` line that names it, with the envelope reattached and the body re-validated around the transform. With nothing configured, none of this happens (see below) |
|
|
88
89
|
|
|
89
90
|
## Arguments and flags
|
|
90
91
|
|
|
91
92
|
`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`.
|
|
93
|
-
|
|
94
|
-
`--humanize`, `--dry-run`, `--schema`, `--help` and `-h`, are
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
and is echoed in the head's `argv`.
|
|
94
|
+
|
|
95
|
+
The writer's own flags, `--human`, `--humanize`, `--dry-run`, `--schema`, `--help` and `-h`, are
|
|
96
|
+
recognised anywhere before the first `--` and set aside. **`--` ends the writer's flags**
|
|
97
|
+
(flyingrobots/parley#103): that first `--` is removed, and every argument after it reaches
|
|
98
|
+
`resolved`, `inputs` and the handler untouched, one with a writer flag's text or a second `--`
|
|
99
|
+
included. So a tool flag whose value is a writer flag's text goes after the `--`: `edit --note -h`
|
|
100
|
+
is `--help` for `edit`, while `edit -- --note -h` runs `edit` with `["--note", "-h"]`, `edit --`
|
|
101
|
+
gives the tool `[]`, and `edit -- a -- b` gives it `["a", "--", "b"]`. The writer cannot know which
|
|
102
|
+
of the tool's flags take a value, so it states this rule rather than guess. The Python writer
|
|
103
|
+
follows the same rule.
|
|
104
|
+
|
|
105
|
+
**The first argument that remains before any `--` is the command**, and only that one argument is
|
|
106
|
+
removed; nothing after `--` is ever the command, so `-- edit` in a tool with more than one command
|
|
107
|
+
is `startup.unknown_command`, exit 3. Every other argument reaches `resolved`, `inputs` and the handler in
|
|
108
|
+
order, a later one with a command's text included, so `edit --reason edit` gives the tool
|
|
109
|
+
`["--reason", "edit"]`. In a tool with more than one command, a first argument that names none is
|
|
110
|
+
`startup.unknown_command`, exit 3, even when a later argument names one: the writer cannot know
|
|
111
|
+
which of the tool's flags take a value, so it never looks past the first position. A tool with
|
|
112
|
+
one command may omit its name, and then nothing is removed. The Python writer follows the
|
|
113
|
+
same rule (flyingrobots/parley#101); the spec does not say how a command is selected.
|
|
114
|
+
|
|
115
|
+
`PARLEY_SESSION` in the environment, or the `session` option, is carried as `session` on the bootstrap line and head; the writer never invents one.
|
|
116
|
+
|
|
117
|
+
The bootstrap line is the boundary for a usage error (spec §3.2, flyingrobots/parley#91), and a
|
|
118
|
+
tool documents which side of it it checks on. A `resolved` or `inputs` callback runs before it:
|
|
119
|
+
one that throws makes a bad argument `startup.arguments_invalid`, exit 3, with no receipt, which
|
|
120
|
+
is the side the spec prefers and the one `examples/count.ts` takes. A handler that reports a bad
|
|
121
|
+
argument with `run.error` makes it a command error, exit 2, with a complete failed receipt.
|
|
97
122
|
|
|
98
123
|
## How this package derives `inv`
|
|
99
124
|
|
|
@@ -129,7 +154,11 @@ working directory; an absolute path stands, and enters the `inv` preimage as giv
|
|
|
129
154
|
relative paths and never a temporary one. Roles: a file (default), `tree` for a directory,
|
|
130
155
|
`stdin` for bytes the handler supplies with `run.input("-", bytes)`. An input the writer cannot
|
|
131
156
|
read is recorded with `error: input.unreadable`; a stdin input never supplied is `input.unread`.
|
|
132
|
-
Either omits `inv`.
|
|
157
|
+
Either omits `inv`. When the handler itself fails to read a declared input, it calls
|
|
158
|
+
`run.inputUnreadable(path)` (optionally with its own code), so the writer records the input as
|
|
159
|
+
unread instead of reading the path at finalisation and digesting bytes the program never saw
|
|
160
|
+
(spec §2.2, flyingrobots/parley#110). It throws for a path that is not a declared input, and
|
|
161
|
+
after the inputs are settled.
|
|
133
162
|
|
|
134
163
|
A `tree` must not contain a credential source (spec §2.2: its bytes must not reach `inv` through
|
|
135
164
|
a directory digest). Name such files in `exclude`, as relative paths under the tree; if you cannot
|
|
@@ -139,8 +168,10 @@ working directory can be a tree without the receipts moving `inv` on every run.
|
|
|
139
168
|
## Retention
|
|
140
169
|
|
|
141
170
|
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,
|
|
143
|
-
directory together, and the deletion is recorded.
|
|
171
|
+
holds more than `count` of **this tool's** receipts, the oldest bundles beyond it are deleted,
|
|
172
|
+
receipt and sidecar directory together, and the deletion is recorded. A receipt is this tool's
|
|
173
|
+
when its first line is a `receipt.head` naming it. Another tool's receipts, a reader's among
|
|
174
|
+
them, are never counted and never deleted, and a file with no readable head is left alone.
|
|
144
175
|
|
|
145
176
|
## What a receipt can contain
|
|
146
177
|
|
|
@@ -148,6 +179,473 @@ Everything the handler passes to `result`, `step`, `warning` and `error`, the ra
|
|
|
148
179
|
arguments, input paths and digests, captured console text, and copies of every result. Declared
|
|
149
180
|
secrets are replaced before writing; an undeclared secret is not, so declare it.
|
|
150
181
|
|
|
182
|
+
## The shared history stream
|
|
183
|
+
|
|
184
|
+
Spec §8, which is **informative**: a layer that consumes the format. The dependency runs one way.
|
|
185
|
+
Nobody needs this to use a conforming tool, and with no stream configured the writer behaves
|
|
186
|
+
exactly as it did before the stream existed — no extra path on the bootstrap line, no extra
|
|
187
|
+
bookkeeping, no file, no warning, no change to the exit status.
|
|
188
|
+
|
|
189
|
+
Turn it on in one of two ways:
|
|
190
|
+
|
|
191
|
+
| | |
|
|
192
|
+
| --- | --- |
|
|
193
|
+
| `PARLEY_HISTORY=/abs/dir` | That directory, created if absent, owner-only |
|
|
194
|
+
| `$XDG_STATE_HOME/parley/history` exists | Used when `PARLEY_HISTORY` is unset, so you opt in once with `mkdir -p` and never by surprise |
|
|
195
|
+
| `PARLEY_HISTORY=off` | Off, even when the state directory exists (`0`, `false`, `no`, `none` and empty do the same) |
|
|
196
|
+
| `PARLEY_HISTORY_DAYS=N` | How many daily segments to keep, today's included; the default is 14 |
|
|
197
|
+
|
|
198
|
+
What reaches it is configured in code, not by the environment: `MainOptions.history` takes a sink,
|
|
199
|
+
`null`, or `{ sink?, transform?, name? }`, and the transform is the subject of
|
|
200
|
+
[its own section below](#a-transform-on-the-stream-copy).
|
|
201
|
+
|
|
202
|
+
What the stream receives is **the bytes of the local receipt**, each line appended as the receipt
|
|
203
|
+
takes it: the head, every reasoning step, every `redaction` and `sidecar` event, every copy of a
|
|
204
|
+
result, error and warning, and `end`. The bootstrap line names the segment it is writing to
|
|
205
|
+
alongside the receipt, under the `paths.history` this package documents (§3.1 defines `receipt`
|
|
206
|
+
and lets a program add paths of its own), and the head declares the stream in
|
|
207
|
+
`effects.bookkeeping` as `create`, `append` and `delete` scopes.
|
|
208
|
+
|
|
209
|
+
Two tools, two repositories, two agents, one segment. Captured from `count` 0.1.0 in one
|
|
210
|
+
repository under `PARLEY_SESSION=ses_agent_one` and `greet` 0.3.1 in another under
|
|
211
|
+
`ses_agent_two`, sharing one `PARLEY_HISTORY`, on 2026-11-22. The repository doctor reports both
|
|
212
|
+
runs conforming. Their two `receipt.head` lines, as the segment holds them:
|
|
213
|
+
|
|
214
|
+
```jsonl
|
|
215
|
+
{"event":"receipt.head","t":1795386946090,"seq":1,"run":"01M82PDCH4QHRWVEWYJK07T512","tool":"count","v":"0.1.0","inv":"638c446f866624d00aed41b516d92549f87b0197871ae5db312b7edaa8051a16","session":"ses_agent_one","argv":["count","files"],"resolved":{"command":"files","args":[]},"inputs":[],"effects":{"reads":["<cwd>/*"],"writes":[],"network":false,"idempotent":true,"bookkeeping":[{"op":"create","scope":"/private/tmp/parley-history.SLUQ/repo-a/.parley/receipts/"},{"op":"create","scope":"/private/tmp/parley-history.SLUQ/repo-a/.parley/.gitignore"},{"op":"delete","scope":"/private/tmp/parley-history.SLUQ/repo-a/.parley/receipts/"},{"op":"create","scope":"/tmp/parley-history.SLUQ/state/parley/8a2e93acd522d682/receipts/"},{"op":"delete","scope":"/tmp/parley-history.SLUQ/state/parley/8a2e93acd522d682/receipts/"},{"op":"create","scope":"/tmp/parley-history.SLUQ/history/"},{"op":"append","scope":"/tmp/parley-history.SLUQ/history/2026-11-22.jsonl"},{"op":"delete","scope":"/tmp/parley-history.SLUQ/history/"}]},"_schema":{"id":"parley.receipt.head","version":"2.0.0"}}
|
|
216
|
+
{"event":"receipt.head","t":1795386946127,"seq":1,"run":"01M82PDCJ8A47H44PWS0XHGA6Q","tool":"greet","v":"0.3.1","inv":"af313858639aa04f3d587b63ac15db6066c7377a70e4539650a45ae4b8e12337","session":"ses_agent_two","argv":["greet","hello"],"resolved":{"command":"hello","args":[]},"inputs":[],"effects":{"reads":[],"writes":[],"network":false,"idempotent":true,"bookkeeping":[{"op":"create","scope":"/private/tmp/parley-history.SLUQ/repo-b/.parley/receipts/"},{"op":"create","scope":"/private/tmp/parley-history.SLUQ/repo-b/.parley/.gitignore"},{"op":"delete","scope":"/private/tmp/parley-history.SLUQ/repo-b/.parley/receipts/"},{"op":"create","scope":"/tmp/parley-history.SLUQ/state/parley/71a5d393d36afaa2/receipts/"},{"op":"delete","scope":"/tmp/parley-history.SLUQ/state/parley/71a5d393d36afaa2/receipts/"},{"op":"create","scope":"/tmp/parley-history.SLUQ/history/"},{"op":"append","scope":"/tmp/parley-history.SLUQ/history/2026-11-22.jsonl"},{"op":"delete","scope":"/tmp/parley-history.SLUQ/history/"}]},"_schema":{"id":"parley.receipt.head","version":"2.0.0"}}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The whole segment, eight lines, sorted by `t` and `seq` and abridged to the fields a timeline
|
|
220
|
+
reads:
|
|
221
|
+
|
|
222
|
+
```text
|
|
223
|
+
2026-11-22T22:35:46.090Z 01M82PDCH4… receipt.head count ses_agent_one
|
|
224
|
+
2026-11-22T22:35:46.090Z 01M82PDCH4… receipt.step counted 2 regular file(s)
|
|
225
|
+
2026-11-22T22:35:46.090Z 01M82PDCH4… result
|
|
226
|
+
2026-11-22T22:35:46.090Z 01M82PDCH4… end
|
|
227
|
+
2026-11-22T22:35:46.127Z 01M82PDCJ8… receipt.head greet ses_agent_two
|
|
228
|
+
2026-11-22T22:35:46.127Z 01M82PDCJ8… receipt.step greeted the caller
|
|
229
|
+
2026-11-22T22:35:46.127Z 01M82PDCJ8… result
|
|
230
|
+
2026-11-22T22:35:46.128Z 01M82PDCJ8… end
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Every line carries its own `run` (§1.3), so a line read out of the shared segment is attributable
|
|
234
|
+
without state, and `(run, seq)` finds the rest of its run.
|
|
235
|
+
|
|
236
|
+
### Appending under concurrent writers
|
|
237
|
+
|
|
238
|
+
The segment is opened `O_APPEND` and **one whole line goes out in one write**, which is what
|
|
239
|
+
orders this writer's line against every other writer's and keeps either from splitting the other.
|
|
240
|
+
A write that reports fewer bytes than the line is **abandoned rather than continued**: continuing
|
|
241
|
+
would let another process's append land inside this line, which is the failure mode worth
|
|
242
|
+
designing out. The stream is then dropped for the rest of the run and the failure is reported
|
|
243
|
+
once.
|
|
244
|
+
|
|
245
|
+
Two honest limits. The single-write guarantee is a property of local filesystems, not of POSIX:
|
|
246
|
+
put the stream on a local disk, not on NFS. And if a line is ever torn anyway, by a signal or a
|
|
247
|
+
full disk mid-write, it is one unparseable line in an otherwise fine file — a reader quarantines
|
|
248
|
+
it and reports it (§1.4) rather than losing the segment.
|
|
249
|
+
|
|
250
|
+
### Retention, by whole segments
|
|
251
|
+
|
|
252
|
+
The stream is one file per UTC day, `2026-11-22.jsonl`, and retention **deletes whole segments**:
|
|
253
|
+
it keeps `PARLEY_HISTORY_DAYS` of them, today's included, and unlinks the rest, recording the
|
|
254
|
+
deletion as a `receipt.step`. An append-only file with concurrent writers cannot be expired by
|
|
255
|
+
rewriting it, which is the whole reason the segments are dated; with `days` at least 1, today's
|
|
256
|
+
segment is never a candidate and the newest deletable one is already `days` days old, so no run
|
|
257
|
+
is holding it open. A dry run deletes nothing and says what it would have deleted.
|
|
258
|
+
|
|
259
|
+
`PARLEY_HISTORY_DAYS` is an integer from 1 to 36,500; anything else, including a window so wide
|
|
260
|
+
that its own start date stops being a date, falls back to 14, because a retention window is not
|
|
261
|
+
worth failing a run over. A run that crosses midnight keeps writing to the segment it opened.
|
|
262
|
+
|
|
263
|
+
### What the stream can contain, and why credentials cannot
|
|
264
|
+
|
|
265
|
+
**The stream is the receipt's bytes, so a credential cannot reach it unless it reached the receipt
|
|
266
|
+
first.** Every declared secret is replaced with `[redacted]` before any copy of a record leaves
|
|
267
|
+
the process (§5.3), and the sink is handed the same string the receipt was handed — not a
|
|
268
|
+
re-serialisation, not a second pass with its own idea of what a secret looks like. That is the
|
|
269
|
+
guarantee by construction, and the only one worth making: a stream whose bytes differed from the
|
|
270
|
+
receipt's would no longer be evidence of the same run.
|
|
271
|
+
|
|
272
|
+
What is left to protect is reach rather than content, because the same bytes now live longer and
|
|
273
|
+
in one place:
|
|
274
|
+
|
|
275
|
+
- The directory is created `0700` and segments `0600`, so another user on the machine cannot read
|
|
276
|
+
the timeline.
|
|
277
|
+
- A record stored as a sidecar reaches the stream as its `sidecar` event, never as its stored
|
|
278
|
+
bytes: the large payloads stay in the repository they came from.
|
|
279
|
+
- Nothing is sent anywhere. The stream is a local file; cross-machine sync is not part of it.
|
|
280
|
+
|
|
281
|
+
The stream's own path gets the rule the receipt's path gets: one that carries a declared secret
|
|
282
|
+
value is never chosen, because the bootstrap line prints it. The receipt has nowhere else to go
|
|
283
|
+
and fails startup; the stream is optional, so it yields — one `history.unavailable` warning and
|
|
284
|
+
the run carries on with no stream. The field name `history` is checked the same way, since a
|
|
285
|
+
secret that is a substring of it would rename the key the line prints.
|
|
286
|
+
|
|
287
|
+
The limit to be clear about: an **undeclared** secret is exactly as exposed in the stream as in
|
|
288
|
+
the receipt, for longer and across repositories. Declaring it is the fix, as it always was —
|
|
289
|
+
[`refuseSuspectedSecrets`](#refusing-a-line-that-looks-like-it-carries-a-credential) is the net
|
|
290
|
+
under it, and refuses a line that looks like it carries one rather than claiming to clean it.
|
|
291
|
+
|
|
292
|
+
### A broken stream never breaks a run
|
|
293
|
+
|
|
294
|
+
A path that cannot be opened is one `history.unavailable` warning; an append that fails is one
|
|
295
|
+
`history.write_failed` warning and the stream is dropped. Neither is an error, neither is a sink
|
|
296
|
+
failure, and neither changes the exit status: §8 is informative and opt-in, so the extra sink
|
|
297
|
+
cannot be the thing that fails the program. The receipt is the record; the stream is a
|
|
298
|
+
convenience.
|
|
299
|
+
|
|
300
|
+
### A transform on the stream copy
|
|
301
|
+
|
|
302
|
+
A sink is an observer with its own aperture. The receipt sink has the identity projection; the
|
|
303
|
+
shared timeline may need a narrower one, because a path, a hostname or a repository name that is
|
|
304
|
+
fine in a local receipt can be wrong on a stream other people and tools read. The transform is
|
|
305
|
+
that aperture, and it is configured **in code**:
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
const dropNames: HistoryTransform = (rec) => {
|
|
309
|
+
if (rec.event !== "receipt.step") return rec;
|
|
310
|
+
const { detail: _detail, ...rest } = rec;
|
|
311
|
+
return rest;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const status = await main(tool, ["count", ...process.argv.slice(2)], handler, {
|
|
315
|
+
history: { transform: dropNames, name: "drop-step-detail" },
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
It is handed the parsed record the receipt already holds — redacted, as §5.3 left it — and returns
|
|
320
|
+
a record to put on the stream or **nothing** to withhold the line. There is no environment
|
|
321
|
+
variable naming a module to execute, deliberately: a program that reads its own output policy out
|
|
322
|
+
of the environment can be made to run code by whoever sets it.
|
|
323
|
+
|
|
324
|
+
**The writer enforces the contract around it.** Nothing the transform does can put an invalid line
|
|
325
|
+
or a changed envelope on the shared timeline:
|
|
326
|
+
|
|
327
|
+
| Rule | Behaviour |
|
|
328
|
+
| --- | --- |
|
|
329
|
+
| The envelope is not the transform's | `event`, `t`, `seq`, `run` and `_schema` are taken off whatever it returns and the receipt line's are put back, so the two copies of one event agree on all five (§1.3). It may read them; it cannot change them |
|
|
330
|
+
| The body is re-validated | Against the schema for its **exact** advertised pair (§4.5): the schemas this package ships, plus the schema the tool declared on the emitted or error type (§4.2) |
|
|
331
|
+
| An unverifiable line is withheld | A pair this writer holds no schema document for, or one whose schema uses a construct the checker does not implement, is `history.transform_uncheckable`. An unchecked projection is never passed off as a checked one |
|
|
332
|
+
| Everything that goes wrong is a warning | A throw is `history.transform_failed`; a body that no longer validates is `history.transform_invalid`; a body that carries a declared secret value the writer had already replaced is `history.transform_unredacted`. Each names the withheld `seq`, goes to stderr and the receipt, and leaves the exit status exactly where it was (§6.1) |
|
|
333
|
+
|
|
334
|
+
**The stream copy says it is a projection.** Its first line for the run is a
|
|
335
|
+
`parley.history.transform` naming the transform and the SHA-256 of its source text as the runtime
|
|
336
|
+
renders it. Captured from the `count` example above with `dropNames` configured, on 2026-11-22:
|
|
337
|
+
|
|
338
|
+
```jsonl
|
|
339
|
+
{"event":"history.transform","t":1795390370293,"seq":1,"run":"01M82SNWFCYTA4NZ7K43TESPAT","name":"drop-step-detail","sha256":"3d6f8595191136c54884fe832e0fb0242116bf967441074e7c0cf577108319f3","_schema":{"id":"parley.history.transform","version":"1.0.0"}}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
The digest is honestly what it says: a digest of **source text as the runtime renders it**, not of
|
|
343
|
+
a build. Two transforms with different source differ; one function closing over different values
|
|
344
|
+
has the same source and the same digest, so name the configuration when that distinction matters.
|
|
345
|
+
|
|
346
|
+
That line reaches the stream and no other sink, so it takes a `seq` the receipt has no line at. The
|
|
347
|
+
receipt accounts for the gap rather than leaving it unexplained — the same run's receipt, whose
|
|
348
|
+
step at `seq 4` still carries the names the stream copy dropped:
|
|
349
|
+
|
|
350
|
+
```jsonl
|
|
351
|
+
{"event":"receipt.step","t":1795390370294,"seq":3,"run":"01M82SNWFCYTA4NZ7K43TESPAT","decision":"the shared stream's copy of this run is a projection by drop-step-detail","because":"a history transform is configured, so the stream copy is narrowed and says so: seq 1 is its parley.history.transform line, which reaches the stream alone and is why this receipt has no line at that seq. The transform's source digests to 3d6f8595191136c54884fe832e0fb0242116bf967441074e7c0cf577108319f3. The receipt is never projected (§8, informative)","_schema":{"id":"parley.receipt.step","version":"1.0.0"}}
|
|
352
|
+
{"event":"receipt.step","t":1795390370294,"seq":4,"run":"01M82SNWFCYTA4NZ7K43TESPAT","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"}}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Withholding leaves a `seq` gap on the stream and nowhere else. `bun run doctor --history
|
|
356
|
+
SEGMENT.jsonl` reads a segment and reports both, here for a `what-ran` transform that withholds
|
|
357
|
+
every `receipt.step`:
|
|
358
|
+
|
|
359
|
+
```text
|
|
360
|
+
PROJECTION 01M82SPNTW39HDZABES1HFYRAC what-ran 5dde666fc322… (history:1)
|
|
361
|
+
GAP 01M82SPNTW39HDZABES1HFYRAC seq 3 is not in this copy
|
|
362
|
+
GAP 01M82SPNTW39HDZABES1HFYRAC seq 4 is not in this copy
|
|
363
|
+
SEGMENT 4 line(s); 1 run(s), 1 projected, 2 gap(s), 0 without end, 0 unparseable
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
**With no transform configured none of this happens**: no opening line, no step, no projection and
|
|
367
|
+
no difference in any byte. A transform configured with no stream is equally inert.
|
|
368
|
+
|
|
369
|
+
#### Re-validating without a dependency
|
|
370
|
+
|
|
371
|
+
This package has no runtime dependencies, and re-validation needs a JSON Schema validator, so
|
|
372
|
+
`src/check.ts` is one — for a bounded subset. It implements the constructs the protocol's own
|
|
373
|
+
schemas use (`type`, `const`, `enum`, `required`, `properties`, `additionalProperties`, `items`,
|
|
374
|
+
the length, size and range bounds, `pattern`, the `json-pointer` format, `not`, `anyOf`, `allOf`,
|
|
375
|
+
`oneOf` and `if`/`then`/`else`) and **reports** a keyword it does not implement rather than
|
|
376
|
+
ignoring it, which is the difference between a bounded checker and a quiet one. The subset check
|
|
377
|
+
walks the whole schema document before any record is checked, because a keyword nested under a
|
|
378
|
+
property that record happens not to carry would otherwise go unnoticed and "we checked the parts
|
|
379
|
+
we understood" is the one claim this must not make. A test asserts
|
|
380
|
+
every schema this package ships is inside the subset, so a future draft reaching for `$ref` fails
|
|
381
|
+
there rather than silently going unchecked. A tool whose own type needs a construct outside the
|
|
382
|
+
subset will see its projected lines withheld as `history.transform_uncheckable`, which is the
|
|
383
|
+
fail-closed direction: better a gap you can see than a line nobody checked.
|
|
384
|
+
|
|
385
|
+
### A built-in: declaredProjection
|
|
386
|
+
|
|
387
|
+
The common reason to project the stream is a list the caller already knows: a username in a
|
|
388
|
+
path, a hostname, a private repository name — fine in a local receipt, wrong on a shared
|
|
389
|
+
timeline. Writing that scrub by hand risks getting longest-first replacement or key renaming
|
|
390
|
+
subtly wrong, so this package ships it (flyingrobots/parley#59):
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
import { declaredProjection } from "parley-emit";
|
|
394
|
+
|
|
395
|
+
await main(tool, argv, handler, {
|
|
396
|
+
history: { transform: declaredProjection(["db-prod-7"]) },
|
|
397
|
+
});
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
It applies the **same scrubber** the receipt's own redaction uses (§5.3) to the stream copy's
|
|
401
|
+
body alone: longest value first, so a value that contains another is replaced whole and leaves no
|
|
402
|
+
tail, and a key that carries a declared value is renamed. The envelope — `event`, `t`, `seq`,
|
|
403
|
+
`run`, `_schema` — is read off the record and put back untouched; it is never the scrub's to touch,
|
|
404
|
+
even when a declared value happens to equal one of those fields' own value (the literal event name
|
|
405
|
+
`"result"`, say).
|
|
406
|
+
|
|
407
|
+
**The writer's own identity scalars are exempt too, at any depth.** A record the receipt holds may
|
|
408
|
+
itself be writer-built (`receipt.head`, `end`), and fields like `tool`, `v`, `inv`, `sha256`,
|
|
409
|
+
`name`, `id`, `version` and `code` carry no pattern a validator would reject a corrupted value by
|
|
410
|
+
— they are plain strings. Without this, a declared value that happened to coincide with, say, the
|
|
411
|
+
tool's own name would silently rename `tool` on the stream's head, with nothing to catch it. This
|
|
412
|
+
is the same `DIGEST_KEYS` the receipt's own redaction of a writer-built record already exempts
|
|
413
|
+
(`src/run.ts`); `argv` is not one of them, so the same declared value legitimately still scrubs
|
|
414
|
+
there, since it is the tool's own caller-chosen data.
|
|
415
|
+
|
|
416
|
+
**An empty declared set configures no transform at all.** `declaredProjection([])` returns
|
|
417
|
+
`undefined` rather than an inert identity function, so `MainOptions.history.transform` is itself
|
|
418
|
+
`undefined`: the writer's own check never builds a projection for it, and the stream copy carries
|
|
419
|
+
no `parley.history.transform` opening line — the run that existed before the built-in did.
|
|
420
|
+
|
|
421
|
+
**The opening line never discloses what was declared.** The returned function is declared with a
|
|
422
|
+
literal name rather than built by string assembly, so its name on the stream is always the literal
|
|
423
|
+
`declaredProjection`, whatever was declared; and the SHA-256 digest the line also carries is of the
|
|
424
|
+
function's *source text*, which only ever closes over the declared values and never embeds them —
|
|
425
|
+
two different declared sets digest identically.
|
|
426
|
+
|
|
427
|
+
Captured from `count` 0.1.0 with `declaredProjection(["db-prod-7"])` configured, against a working
|
|
428
|
+
directory holding `readme.txt` and `db-prod-7-backup.txt`, on 2026-11-22. The receipt's step names
|
|
429
|
+
both files; the stream copy's does not, and the value is absent from the stream end to end:
|
|
430
|
+
|
|
431
|
+
```jsonl
|
|
432
|
+
{"event":"receipt.step","t":1795391463645,"seq":4,"run":"01M82TQ85WMZ7X3AA0R2DW3M7G","decision":"counted 2 regular file(s)","because":"a declared hostname in one of the names is fine in the receipt and wrong on the shared timeline","detail":{"names":["db-prod-7-backup.txt","readme.txt"]},"_schema":{"id":"parley.receipt.step","version":"1.0.0"}}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
```jsonl
|
|
436
|
+
{"event":"receipt.step","t":1795391463645,"seq":4,"run":"01M82TQ85WMZ7X3AA0R2DW3M7G","decision":"counted 2 regular file(s)","because":"a declared hostname in one of the names is fine in the receipt and wrong on the shared timeline","detail":{"names":["[redacted]-backup.txt","readme.txt"]},"_schema":{"id":"parley.receipt.step","version":"1.0.0"}}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Refusing a line that looks like it carries a credential
|
|
440
|
+
|
|
441
|
+
Declared redaction (§5.3) replaces what the program declared. It cannot catch a secret nobody
|
|
442
|
+
declared, and the stream is where that gap costs most: a receipt lives one run's lifetime, while a
|
|
443
|
+
segment lives for the retention window and is read by more observers than the run that wrote it.
|
|
444
|
+
|
|
445
|
+
`refuseSuspectedSecrets()` is a built-in transform that **withholds** any line whose body matches
|
|
446
|
+
one of a documented list of token shapes, and says so under its own code:
|
|
447
|
+
|
|
448
|
+
```ts
|
|
449
|
+
import { refuseSuspectedSecrets } from "@flyingrobots/parley-emit";
|
|
450
|
+
|
|
451
|
+
await main(tool, argv, handler, { history: { transform: refuseSuspectedSecrets() } });
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
**It refuses; it never rewrites.** A heuristic must not claim the certainty that rewriting implies,
|
|
455
|
+
and replacing the matched span would put a record on the stream that looks checked and differs from
|
|
456
|
+
the receipt's copy of the same event in a way nothing records. So a false positive costs **one
|
|
457
|
+
withheld stream line** and never a changed value in the receipt.
|
|
458
|
+
|
|
459
|
+
The shapes ship as data in `src/transforms/secret-patterns.ts` — a name, a regex source and one
|
|
460
|
+
line of rationale each — so reviewing what is refused is reading a table rather than reading code:
|
|
461
|
+
|
|
462
|
+
| Pattern | Regex source |
|
|
463
|
+
| --- | --- |
|
|
464
|
+
| `aws.access_key_id` | `\bAKIA[0-9A-Z]{16}\b` |
|
|
465
|
+
| `github.token` | `\bgh[opsur]_[A-Za-z0-9]{36}\b` |
|
|
466
|
+
| `github.fine_grained_pat` | `\bgithub_pat_[A-Za-z0-9]{22}_[A-Za-z0-9]{59}\b` |
|
|
467
|
+
| `slack.token` | `\bxox[abpr]-[0-9A-Za-z]{8,}(?:-[0-9A-Za-z]{8,}){0,3}\b` |
|
|
468
|
+
| `google.api_key` | `\bAIza[0-9A-Za-z_-]{35}(?![0-9A-Za-z_-])` |
|
|
469
|
+
| `pem.private_key` | `-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY-----` |
|
|
470
|
+
| `jwt` | `\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}(?![A-Za-z0-9_-])` |
|
|
471
|
+
| `http.bearer_token` | `\bBearer\s+[A-Za-z0-9._~+/=-]{20,}` |
|
|
472
|
+
| `npm.token` | `\bnpm_[A-Za-z0-9]{36}\b` |
|
|
473
|
+
| `stripe.live_key` | `\b(?:sk\|rk)_live_[0-9A-Za-z]{10,}\b` |
|
|
474
|
+
|
|
475
|
+
Every one is anchored and length-bounded, and every one is a prefix a vendor assigns and documents,
|
|
476
|
+
so a match is evidence about the string's provenance rather than about its entropy. There is
|
|
477
|
+
deliberately no "forty hex characters" entry: it would refuse every SHA-1. Each has a positive and
|
|
478
|
+
a negative sample in the suite, and the walk is over the shipped list, so a new entry without
|
|
479
|
+
samples fails a test. `SECRET_PATTERNS` is exported: pass
|
|
480
|
+
`refuseSuspectedSecrets([...SECRET_PATTERNS, ...mine])` to add to the list, a list of your own to
|
|
481
|
+
replace it, and `[]` for the identity.
|
|
482
|
+
|
|
483
|
+
**Captured from a real run** on 2026-11-22: a `release notes` tool that reads a token and forgot to
|
|
484
|
+
declare it, with the built-in configured and a planted GitHub-shaped token (`ghp_` and
|
|
485
|
+
`0123456789abcdefghij0123456789abcdef`, which is the right length and clearly nobody's). The
|
|
486
|
+
receipt carries the line, value and all, because the receipt is the record and nothing was
|
|
487
|
+
declared:
|
|
488
|
+
|
|
489
|
+
```jsonl
|
|
490
|
+
{"event":"receipt.step","t":1795392220912,"seq":4,"run":"01M82VEBQ5BGHTP5KTFMPKN8MQ","decision":"read the release token from the environment","because":"the token is not in the command's secrets list, which is the hole this refuses to widen","detail":{"token":"ghp_0123456789abcdefghij0123456789abcdef","repo":"flyingrobots/parley"},"_schema":{"id":"parley.receipt.step","version":"1.0.0"}}
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
The stream does not. stderr and the receipt carry one warning instead, naming the withheld `seq`,
|
|
494
|
+
the shape and the JSON Pointer — and never the matched text, which would put the suspect on stderr
|
|
495
|
+
and back on the stream through the warning's own copy:
|
|
496
|
+
|
|
497
|
+
```jsonl
|
|
498
|
+
{"event":"warning","t":1795392220912,"seq":5,"run":"01M82VEBQ5BGHTP5KTFMPKN8MQ","code":"history.suspected_secret","problem":"the body of seq 4 matches the github.token shape at /detail/token, so that line is not on the shared stream; the receipt is unaffected and still carries the value","remedy":"declare the value as a secret in the command's secrets list (spec §5.3) so it is replaced in the receipt too, or keep it out of the record; an unlisted shape passes, and a legitimate value that matches costs this one stream line","_schema":{"id":"parley.warning","version":"1.0.0"}}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
The run's exit status is 0: a withheld line is a warning and warnings never change it (§6.1). The
|
|
502
|
+
doctor reads the gap off the segment, from the same run:
|
|
503
|
+
|
|
504
|
+
```text
|
|
505
|
+
PROJECTION 01M82VEBQ5BGHTP5KTFMPKN8MQ refuseSuspectedSecrets 262e75ca7d76… (history:1)
|
|
506
|
+
GAP 01M82VEBQ5BGHTP5KTFMPKN8MQ seq 4 is not in this copy
|
|
507
|
+
SEGMENT 6 line(s); 1 run(s), 1 projected, 1 gap(s), 0 without end, 0 unparseable
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
**The limits, stated rather than implied.** This refuses what it recognises, and recognition is a
|
|
511
|
+
floor:
|
|
512
|
+
|
|
513
|
+
- **An unlisted shape passes.** A vendor's new prefix, an internal token format, a password: none
|
|
514
|
+
of them are here, and none of them are refused.
|
|
515
|
+
- **A token split across two string values passes.** The scan is per value and claims nothing about
|
|
516
|
+
what concatenating two of them would spell.
|
|
517
|
+
- **A token used as an object key passes.** Keys name fields; a value is what a program carries.
|
|
518
|
+
- **A legitimate value that matches is withheld.** A commit message quoting a key id, a fixture, a
|
|
519
|
+
test key with a live prefix: each costs one stream line. The receipt still has it.
|
|
520
|
+
- **The envelope is never scanned**, because `event`, `t`, `seq`, `run` and `_schema` are the
|
|
521
|
+
writer's and one unlucky run id would otherwise withhold every line of a run.
|
|
522
|
+
- **The head is not exempt, and it is the likeliest line to match.** It echoes `argv` and
|
|
523
|
+
`resolved` (§5), so an undeclared token on the command line withholds the whole head and the
|
|
524
|
+
stream copy of that run then has no head at all: no `tool`, no `v`, no `effects` for a reader of
|
|
525
|
+
the segment. The gap is reported like any other, the receipt is complete, and the status does not
|
|
526
|
+
move — but the honest reading of that copy is "a run happened and the stream cannot say what it
|
|
527
|
+
was".
|
|
528
|
+
|
|
529
|
+
The warning names a JSON Pointer, which is built from the record's own keys, and a key can be a
|
|
530
|
+
token too. When the pointer itself matches a shape the warning names the shape and not the
|
|
531
|
+
pointer: a line withheld for one suspected secret must not put a different one on the stream
|
|
532
|
+
through the warning that explains it.
|
|
533
|
+
|
|
534
|
+
Declaring the value as a secret (§5.3) is the real protection, and the warning's `remedy` says so.
|
|
535
|
+
This is the net under it.
|
|
536
|
+
|
|
537
|
+
**With `declaredProjection`.** The package ships no composition helper; composing two transforms
|
|
538
|
+
is the caller's function, and it is four lines — pass a refusal on untouched, hand a record to the
|
|
539
|
+
next:
|
|
540
|
+
|
|
541
|
+
```ts
|
|
542
|
+
const declared = declaredProjection(["db-prod-7"])!;
|
|
543
|
+
const suspect = refuseSuspectedSecrets();
|
|
544
|
+
const both: HistoryTransform = (rec) => {
|
|
545
|
+
const out = declared(rec);
|
|
546
|
+
return out && !isHistoryRefusal(out) ? suspect(out) : out;
|
|
547
|
+
};
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
**The writer's identity keys are scanned too.** `declaredProjection` skips `tool`, `v`, `inv`,
|
|
551
|
+
`sha256`, `name`, `id`, `version` and `code` (`DIGEST_KEYS`) because it *rewrites*, and rewriting
|
|
552
|
+
one of those would corrupt an identity nothing re-checks. This built-in never rewrites, so the
|
|
553
|
+
reason does not apply, and skipping them would only be a hole: a token in a tool's `name` would
|
|
554
|
+
pass. A hex digest matches no shape here, because every shape is a vendor prefix. The cost is a
|
|
555
|
+
withheld line if a tool names itself like a token, which is the right outcome.
|
|
556
|
+
|
|
557
|
+
#### A transform may refuse, not only withhold
|
|
558
|
+
|
|
559
|
+
flyingrobots/parley#57 gave a transform two answers: a record to project, or nothing to withhold
|
|
560
|
+
the line. Nothing is a gap with no reason attached, which is right for "the shared timeline does not
|
|
561
|
+
carry step detail" and wrong when the reason is the point. So there is a third:
|
|
562
|
+
|
|
563
|
+
```ts
|
|
564
|
+
import { refuse } from "@flyingrobots/parley-emit";
|
|
565
|
+
|
|
566
|
+
const offTimeline: HistoryTransform = (rec) =>
|
|
567
|
+
rec.event === "receipt.step" ? refuse("policy.off_timeline", `seq ${rec.seq} is not for the shared timeline`) : rec;
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
The writer withholds the line and raises one `warning` carrying that `code`, `problem` and
|
|
571
|
+
`remedy`, on stderr and in the receipt, leaving the exit status alone — the same treatment the four
|
|
572
|
+
`history.transform_*` codes get, under a code the transform chose. A refusal is a value rather than
|
|
573
|
+
a throw because a throw already means something in #57's contract (`history.transform_failed`: the
|
|
574
|
+
transform is broken), and because a value composes: a wrapping transform can read a refusal and
|
|
575
|
+
pass it on without an exception handler.
|
|
576
|
+
|
|
577
|
+
The code is the transform's; the namespace is still the writer's. A refusal whose `code` is not
|
|
578
|
+
spec §6's shape, or whose `problem` is empty, is `history.transform_failed` — the transform being
|
|
579
|
+
broken, like any other way of being broken. A refusal whose `code` carries a declared secret value
|
|
580
|
+
is `history.transform_unredacted`, because a diagnostic's `code` is the one string §5.3 does not
|
|
581
|
+
scrub, so a refusal cannot become the way a secret leaves. `refuse()` checks the first two at the
|
|
582
|
+
point the refusal is written.
|
|
583
|
+
|
|
584
|
+
#### Five decisions the owner may overrule
|
|
585
|
+
|
|
586
|
+
flyingrobots/parley#60 asked for a built-in and a pattern list; these are judgement calls rather
|
|
587
|
+
than consequences of the issue:
|
|
588
|
+
|
|
589
|
+
1. **A refusal is a return value, not a throw.** The issue allowed either. A value keeps "it threw"
|
|
590
|
+
meaning "it is broken" and composes without exception handlers. Overrule by mapping a typed
|
|
591
|
+
error in `Run`'s `projectOne` instead of `isHistoryRefusal`.
|
|
592
|
+
2. **The refusal's `problem` names the `seq`, and the writer does not append it.** The transform is
|
|
593
|
+
handed the record, so it has the `seq`; the writer never edits a sentence it did not write. The
|
|
594
|
+
cost is that a hand-written refusal can omit it. Overrule in `Run`'s `refused` in `src/run.ts`.
|
|
595
|
+
3. **Object keys are not scanned, only values.** A key names a field. The writer's own §5.3
|
|
596
|
+
scrubber does rename keys, because there the value was declared and the certainty is earned.
|
|
597
|
+
Overrule in `findSuspectedSecret`'s walk in `src/transforms/secrets.ts`.
|
|
598
|
+
4. **A caller's pattern list replaces the default rather than extending it**, so whoever passes one
|
|
599
|
+
is reviewing exactly what they refuse on. `[...SECRET_PATTERNS, ...mine]` is the extension, and
|
|
600
|
+
it is one line.
|
|
601
|
+
5. **The first match wins and the scan stops.** A refusal needs one reason, not an inventory, and
|
|
602
|
+
the line is withheld either way. Overrule by collecting every hit before refusing.
|
|
603
|
+
|
|
604
|
+
The list itself is the sixth: ten shapes, chosen for published prefixes and bounded lengths. Adding
|
|
605
|
+
one is a row and two samples; removing one is a row and two samples.
|
|
606
|
+
|
|
607
|
+
### Three more decisions the owner may overrule
|
|
608
|
+
|
|
609
|
+
flyingrobots/parley#57 left the shape of the enforcement to the implementation. These three are
|
|
610
|
+
judgement calls rather than consequences of the issue:
|
|
611
|
+
|
|
612
|
+
1. **A line the writer cannot re-validate is withheld, not passed through.** A tool-owned type
|
|
613
|
+
with no declared schema (§4.2 asks for one, and discovery already warns `schema.unavailable`
|
|
614
|
+
when it is missing) therefore does not reach a projected stream. The alternative is to pass it
|
|
615
|
+
through unchecked, which would make "nothing a projection does puts an invalid line on the
|
|
616
|
+
shared timeline" false. Overrule in `Run`'s `project` in `src/run.ts`: return `text` where it
|
|
617
|
+
now withholds.
|
|
618
|
+
2. **The receipt records the `seq` the opening line took, as a `receipt.step`.** The transform line
|
|
619
|
+
is stream-only, so without this the receipt has an unexplained gap at that `seq`. The cost is
|
|
620
|
+
one extra line and one extra `seq` in every projected run's receipt. Overrule by deleting
|
|
621
|
+
`noteProjection`'s `step` call.
|
|
622
|
+
3. **A transform may withhold `end`.** Nothing exempts the terminal event, so a copy on the stream
|
|
623
|
+
can end without one, and a reader sees incomplete lifecycle evidence for a run that in fact
|
|
624
|
+
completed — which is what §3.3 says that evidence means. The doctor's segment mode counts such
|
|
625
|
+
copies (`0 without end` above). Overrule by exempting `end` in `project`.
|
|
626
|
+
|
|
627
|
+
A fourth thing worth stating rather than deciding: the number of warnings is not the number of
|
|
628
|
+
withheld lines. A warning is itself a record, so it goes through the transform too, and a
|
|
629
|
+
transform that fails on a warning line withholds it **without warning again** — otherwise one
|
|
630
|
+
failure would generate another for ever. The stream's gaps, not the warning count, are the ground
|
|
631
|
+
truth for what a copy is missing.
|
|
632
|
+
|
|
633
|
+
### Two decisions the owner may overrule
|
|
634
|
+
|
|
635
|
+
flyingrobots/parley#3 left scope, expiry and redaction open and asked for a recommendation.
|
|
636
|
+
These are the recommendations, implemented:
|
|
637
|
+
|
|
638
|
+
1. **Scope and expiry: one stream per user per machine, as dated daily segments, keeping
|
|
639
|
+
`PARLEY_HISTORY_DAYS` of them (default 14).** Scope is the machine and the user because that is
|
|
640
|
+
what makes the timeline worth reading — every tool, repository, agent and session on the
|
|
641
|
+
machine in one place. Expiry is by age in whole files because an append-only file with
|
|
642
|
+
concurrent writers can be expired by unlinking and not by rewriting. Overrule by changing
|
|
643
|
+
`HISTORY_DEFAULT_DAYS` in `src/history.ts`, or `resolveHistory`'s state path for a different
|
|
644
|
+
scope; nothing else depends on either.
|
|
645
|
+
2. **Redaction: none of the stream's own, with owner-only permissions, no sidecar bodies and no
|
|
646
|
+
network instead.** The reasoning is the section above. Overrule by filtering in `Run`'s mirror
|
|
647
|
+
in `src/run.ts`, the single place the receipt's bytes are handed to the sink.
|
|
648
|
+
|
|
151
649
|
## Exceptions the protocol names
|
|
152
650
|
|
|
153
651
|
These are the places the writer's promises do not reach, named as spec §6 asks:
|
|
@@ -160,6 +658,10 @@ These are the places the writer's promises do not reach, named as spec §6 asks:
|
|
|
160
658
|
- A timer or callback that logs after `end` has nothing to be captured into; its text reaches the
|
|
161
659
|
stream, and the process should exit promptly after `main` returns.
|
|
162
660
|
- A source resolver runs before the bootstrap line and may have side effects of its own.
|
|
661
|
+
- A configured history transform is the tool's own code in the tool's own process. The writer
|
|
662
|
+
refuses what it returns when it is invalid, uncheckable or carries a declared secret, but it
|
|
663
|
+
cannot stop that code from writing elsewhere itself; the enforcement is over what reaches the
|
|
664
|
+
stream through the writer.
|
|
163
665
|
|
|
164
666
|
The writer uses synchronous writes so that on every other path the receipt is complete.
|
|
165
667
|
|
package/package.json
CHANGED