patchwork-os 1.2.0-beta.2.canary.786 → 1.2.0-beta.2.canary.787
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.
|
@@ -46,14 +46,35 @@ import type { Logger } from "./logger.js";
|
|
|
46
46
|
* tail-on-read offset tracking to maintain.
|
|
47
47
|
*/
|
|
48
48
|
/**
|
|
49
|
-
* Row-schema version stamped on every
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
49
|
+
* Row-schema version stamped on every event this build writes (ADR-0025).
|
|
50
|
+
* Bump only when a field's MEANING changes, never for an additive one: a
|
|
51
|
+
* reader skips a row from a version it does not know rather than guessing, so
|
|
52
|
+
* a gratuitous bump silently drops rows from every existing reader.
|
|
53
|
+
*
|
|
54
|
+
* 1 — a `request` row carries `correlationId` when it belonged to a run.
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* 2 (ADR-0027): every row — request, decision AND attribution — carries `iseq`
|
|
58
|
+
* and `prev`, stamped by `appendChained` from the file's tail under the lock.
|
|
59
|
+
* At `rv >= 2` their absence is a WRITER DEFECT. Rows at `rv 1` (and the
|
|
60
|
+
* decision/attribution rows written alongside them, which carried no `rv` at
|
|
61
|
+
* all) predate the chain and are never re-stamped; the `chain-start` marker
|
|
62
|
+
* commits to them as a block.
|
|
63
|
+
*/
|
|
64
|
+
export declare const APPROVAL_LOG_RV = 2;
|
|
65
|
+
/**
|
|
66
|
+
* ADR-0027 integrity fields, present on every row from `rv >= 2`. Written by
|
|
67
|
+
* the append primitive, never by a caller: `iseq` is the per-ledger integrity
|
|
68
|
+
* sequence read from the file's tail, `prev` the SHA-256 of the previous line's
|
|
69
|
+
* exact bytes. A position in the chain, not a fact about the approval — so the
|
|
70
|
+
* restore path returns them on the event and does NOT project them onto the
|
|
71
|
+
* live `PendingApproval`.
|
|
54
72
|
*/
|
|
55
|
-
export
|
|
56
|
-
|
|
73
|
+
export interface ChainedRowFields {
|
|
74
|
+
iseq?: number;
|
|
75
|
+
prev?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ApprovalRequestEvent extends ChainedRowFields {
|
|
57
78
|
kind: "request";
|
|
58
79
|
callId: string;
|
|
59
80
|
toolName: string;
|
|
@@ -89,11 +110,13 @@ export interface ApprovalRequestEvent {
|
|
|
89
110
|
*/
|
|
90
111
|
correlationId?: string;
|
|
91
112
|
}
|
|
92
|
-
export interface ApprovalDecisionEvent {
|
|
113
|
+
export interface ApprovalDecisionEvent extends ChainedRowFields {
|
|
93
114
|
kind: "decision";
|
|
94
115
|
callId: string;
|
|
95
116
|
decision: ApprovalDecision;
|
|
96
117
|
decidedAt: number;
|
|
118
|
+
/** Stamped from `rv >= 2`; a decision row at rv 1 carried no version. */
|
|
119
|
+
rv?: number;
|
|
97
120
|
}
|
|
98
121
|
/**
|
|
99
122
|
* Who decided. Written only on evidence: `approvalHttp` verifies the member's
|
|
@@ -101,12 +124,14 @@ export interface ApprovalDecisionEvent {
|
|
|
101
124
|
* Never written for a shared-secret (v1) session, an expired timer, or the
|
|
102
125
|
* phone path's single-use token — none of those name a person.
|
|
103
126
|
*/
|
|
104
|
-
export interface ApprovalAttributionEvent {
|
|
127
|
+
export interface ApprovalAttributionEvent extends ChainedRowFields {
|
|
105
128
|
kind: "attribution";
|
|
106
129
|
callId: string;
|
|
107
130
|
/** id + kind + display name AS IT WAS, never a roster reference. */
|
|
108
131
|
actor: ActorSnapshot;
|
|
109
132
|
attributedAt: number;
|
|
133
|
+
/** Stamped from `rv >= 2`; an attribution row at rv 1 carried no version. */
|
|
134
|
+
rv?: number;
|
|
110
135
|
}
|
|
111
136
|
export type ApprovalLogEvent = ApprovalRequestEvent | ApprovalDecisionEvent | ApprovalAttributionEvent;
|
|
112
137
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { appendChained } from "./ledgerChain.js";
|
|
4
4
|
import { patchworkHome } from "./patchworkHome.js";
|
|
5
5
|
/**
|
|
6
6
|
* Durable event log backing `ApprovalQueue` (ADR-0018: "persist the request,
|
|
@@ -47,13 +47,22 @@ import { patchworkHome } from "./patchworkHome.js";
|
|
|
47
47
|
* tail-on-read offset tracking to maintain.
|
|
48
48
|
*/
|
|
49
49
|
/**
|
|
50
|
-
* Row-schema version stamped on every
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
50
|
+
* Row-schema version stamped on every event this build writes (ADR-0025).
|
|
51
|
+
* Bump only when a field's MEANING changes, never for an additive one: a
|
|
52
|
+
* reader skips a row from a version it does not know rather than guessing, so
|
|
53
|
+
* a gratuitous bump silently drops rows from every existing reader.
|
|
54
|
+
*
|
|
55
|
+
* 1 — a `request` row carries `correlationId` when it belonged to a run.
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* 2 (ADR-0027): every row — request, decision AND attribution — carries `iseq`
|
|
59
|
+
* and `prev`, stamped by `appendChained` from the file's tail under the lock.
|
|
60
|
+
* At `rv >= 2` their absence is a WRITER DEFECT. Rows at `rv 1` (and the
|
|
61
|
+
* decision/attribution rows written alongside them, which carried no `rv` at
|
|
62
|
+
* all) predate the chain and are never re-stamped; the `chain-start` marker
|
|
63
|
+
* commits to them as a block.
|
|
55
64
|
*/
|
|
56
|
-
export const APPROVAL_LOG_RV =
|
|
65
|
+
export const APPROVAL_LOG_RV = 2;
|
|
57
66
|
/**
|
|
58
67
|
* The directory that holds `approval_log.jsonl`. Honors `PATCHWORK_HOME`, the
|
|
59
68
|
* same override every sibling durable log (`resolveOutcomeLogDir`,
|
|
@@ -127,6 +136,7 @@ export class ApprovalPersistence {
|
|
|
127
136
|
callId,
|
|
128
137
|
decision,
|
|
129
138
|
decidedAt,
|
|
139
|
+
rv: APPROVAL_LOG_RV,
|
|
130
140
|
};
|
|
131
141
|
this.append(event);
|
|
132
142
|
}
|
|
@@ -141,14 +151,21 @@ export class ApprovalPersistence {
|
|
|
141
151
|
callId,
|
|
142
152
|
actor,
|
|
143
153
|
attributedAt,
|
|
154
|
+
rv: APPROVAL_LOG_RV,
|
|
144
155
|
};
|
|
145
156
|
this.append(event);
|
|
146
157
|
}
|
|
147
158
|
append(event) {
|
|
148
159
|
try {
|
|
149
|
-
|
|
150
|
-
withFileLockSync
|
|
151
|
-
|
|
160
|
+
// ADR-0027: one locked, chained append. The primitive takes the same
|
|
161
|
+
// `${file}.lock` sentinel the old `withFileLockSync` wrapper did, so the
|
|
162
|
+
// wrapper is gone rather than nested (nesting it would wait on itself).
|
|
163
|
+
// No rotation: this is the governance ledger, and it does not shed rows
|
|
164
|
+
// (`approvalHttp` says why). Fail-soft contract unchanged — a failed
|
|
165
|
+
// append is counted in the `.write_failed` sidecar by the primitive and
|
|
166
|
+
// swallowed here after a warning, never surfaced to a live approval.
|
|
167
|
+
appendChained(this.file, event, {
|
|
168
|
+
mode: 0o600,
|
|
152
169
|
});
|
|
153
170
|
}
|
|
154
171
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvalPersistence.js","sourceRoot":"","sources":["../src/approvalPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"approvalPersistence.js","sourceRoot":"","sources":["../src/approvalPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH;;;;;;;GAOG;AACH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAA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KAAK,SAAS,EAAE,CAAC;gBAC7B,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACpC,CAAC;iBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACrC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC;YACD,uEAAuE;YACvE,oEAAoE;YACpE,gEAAgE;YAChE,uEAAuE;YACvE,sEAAsE;YACtE,uEAAuE;YACvE,+CAA+C;QACjD,CAAC;QACD,MAAM,UAAU,GAA2B,EAAE,CAAC;QAC9C,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,QAAQ,EAAE,CAAC;YACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "patchwork-os",
|
|
3
|
-
"version": "1.2.0-beta.2.canary.
|
|
3
|
+
"version": "1.2.0-beta.2.canary.787",
|
|
4
4
|
"description": "Your personal AI runtime, local-first. Patchwork OS gives any AI model a consistent set of tools, YAML recipes, a delegation policy with approval queue, and a durable trace memory — all on your machine, all under your policy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|