@dsh-ray/assistant-verifier 0.0.1-seed.0 → 0.2.1

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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +285 -1
  3. package/cordis.patch.yml +10 -0
  4. package/lib/config.d.ts +47 -0
  5. package/lib/config.d.ts.map +1 -0
  6. package/lib/config.js +82 -0
  7. package/lib/config.js.map +1 -0
  8. package/lib/creation-review-native.d.ts +30 -0
  9. package/lib/creation-review-native.d.ts.map +1 -0
  10. package/lib/creation-review-native.js +137 -0
  11. package/lib/creation-review-native.js.map +1 -0
  12. package/lib/creation-review-store.d.ts +108 -0
  13. package/lib/creation-review-store.d.ts.map +1 -0
  14. package/lib/creation-review-store.js +715 -0
  15. package/lib/creation-review-store.js.map +1 -0
  16. package/lib/creation-review.d.ts +317 -0
  17. package/lib/creation-review.d.ts.map +1 -0
  18. package/lib/creation-review.js +842 -0
  19. package/lib/creation-review.js.map +1 -0
  20. package/lib/drivers.d.ts +153 -0
  21. package/lib/drivers.d.ts.map +1 -0
  22. package/lib/drivers.js +825 -0
  23. package/lib/drivers.js.map +1 -0
  24. package/lib/host.d.ts +93 -0
  25. package/lib/host.d.ts.map +1 -0
  26. package/lib/host.js +2 -0
  27. package/lib/host.js.map +1 -0
  28. package/lib/index.d.ts +26 -0
  29. package/lib/index.d.ts.map +1 -0
  30. package/lib/index.js +18 -0
  31. package/lib/index.js.map +1 -0
  32. package/lib/linux-behavior-assets.d.ts +19 -0
  33. package/lib/linux-behavior-assets.d.ts.map +1 -0
  34. package/lib/linux-behavior-assets.js +89 -0
  35. package/lib/linux-behavior-assets.js.map +1 -0
  36. package/lib/linux-behavior-runner.d.ts +10 -0
  37. package/lib/linux-behavior-runner.d.ts.map +1 -0
  38. package/lib/linux-behavior-runner.js +69 -0
  39. package/lib/linux-behavior-runner.js.map +1 -0
  40. package/lib/linux-behavior-runtime.d.ts +67 -0
  41. package/lib/linux-behavior-runtime.d.ts.map +1 -0
  42. package/lib/linux-behavior-runtime.js +500 -0
  43. package/lib/linux-behavior-runtime.js.map +1 -0
  44. package/lib/memory-review-native.d.ts +50 -0
  45. package/lib/memory-review-native.d.ts.map +1 -0
  46. package/lib/memory-review-native.js +166 -0
  47. package/lib/memory-review-native.js.map +1 -0
  48. package/lib/memory-review.d.ts +50 -0
  49. package/lib/memory-review.d.ts.map +1 -0
  50. package/lib/memory-review.js +363 -0
  51. package/lib/memory-review.js.map +1 -0
  52. package/lib/native-behavior-artifact.d.ts +9 -0
  53. package/lib/native-behavior-artifact.d.ts.map +1 -0
  54. package/lib/native-behavior-artifact.js +144 -0
  55. package/lib/native-behavior-artifact.js.map +1 -0
  56. package/lib/native-behavior-worker.d.ts +3 -0
  57. package/lib/native-behavior-worker.d.ts.map +1 -0
  58. package/lib/native-behavior-worker.js +453 -0
  59. package/lib/native-behavior-worker.js.map +1 -0
  60. package/lib/plugin-behavior-config.d.ts +34 -0
  61. package/lib/plugin-behavior-config.d.ts.map +1 -0
  62. package/lib/plugin-behavior-config.js +170 -0
  63. package/lib/plugin-behavior-config.js.map +1 -0
  64. package/lib/plugin-behavior-runner.d.ts +57 -0
  65. package/lib/plugin-behavior-runner.d.ts.map +1 -0
  66. package/lib/plugin-behavior-runner.js +910 -0
  67. package/lib/plugin-behavior-runner.js.map +1 -0
  68. package/lib/review-authority-lineage.d.ts +109 -0
  69. package/lib/review-authority-lineage.d.ts.map +1 -0
  70. package/lib/review-authority-lineage.js +135 -0
  71. package/lib/review-authority-lineage.js.map +1 -0
  72. package/lib/review-maintenance.d.ts +20 -0
  73. package/lib/review-maintenance.d.ts.map +1 -0
  74. package/lib/review-maintenance.js +24 -0
  75. package/lib/review-maintenance.js.map +1 -0
  76. package/lib/revision-regression-review.d.ts +41 -0
  77. package/lib/revision-regression-review.d.ts.map +1 -0
  78. package/lib/revision-regression-review.js +379 -0
  79. package/lib/revision-regression-review.js.map +1 -0
  80. package/lib/revision-review.d.ts +242 -0
  81. package/lib/revision-review.d.ts.map +1 -0
  82. package/lib/revision-review.js +600 -0
  83. package/lib/revision-review.js.map +1 -0
  84. package/lib/service.d.ts +138 -0
  85. package/lib/service.d.ts.map +1 -0
  86. package/lib/service.js +878 -0
  87. package/lib/service.js.map +1 -0
  88. package/lib/source-review-git.d.ts +32 -0
  89. package/lib/source-review-git.d.ts.map +1 -0
  90. package/lib/source-review-git.js +241 -0
  91. package/lib/source-review-git.js.map +1 -0
  92. package/lib/source-review-native.d.ts +27 -0
  93. package/lib/source-review-native.d.ts.map +1 -0
  94. package/lib/source-review-native.js +149 -0
  95. package/lib/source-review-native.js.map +1 -0
  96. package/lib/source-review-store.d.ts +44 -0
  97. package/lib/source-review-store.d.ts.map +1 -0
  98. package/lib/source-review-store.js +212 -0
  99. package/lib/source-review-store.js.map +1 -0
  100. package/lib/source-review.d.ts +86 -0
  101. package/lib/source-review.d.ts.map +1 -0
  102. package/lib/source-review.js +255 -0
  103. package/lib/source-review.js.map +1 -0
  104. package/lib/store.d.ts +84 -0
  105. package/lib/store.d.ts.map +1 -0
  106. package/lib/store.js +386 -0
  107. package/lib/store.js.map +1 -0
  108. package/lib/version.d.ts +2 -0
  109. package/lib/version.d.ts.map +1 -0
  110. package/lib/version.js +2 -0
  111. package/lib/version.js.map +1 -0
  112. package/package.json +137 -4
  113. package/runtime/plugin-observer-launcher.c +246 -0
@@ -0,0 +1,44 @@
1
+ export declare class SourceReviewStoreError extends Error {
2
+ readonly code: 'invalid-input' | 'conflict' | 'corrupt';
3
+ constructor(code: 'invalid-input' | 'conflict' | 'corrupt', message: string);
4
+ }
5
+ type Model = {
6
+ provider: string;
7
+ model: string;
8
+ reasoningEffort?: string;
9
+ };
10
+ type Result = {
11
+ reason: string;
12
+ outputDigest: string;
13
+ };
14
+ interface ClaimInput {
15
+ operationId: string;
16
+ requestDigest: string;
17
+ authorityId: string;
18
+ authorityDigest: string;
19
+ maxReviews: number;
20
+ model: Model;
21
+ }
22
+ interface Claim {
23
+ state: 'claimed' | 'unknown' | 'approved' | 'rejected';
24
+ result?: Result;
25
+ }
26
+ /** Durable at-most-once model admission, independently bounded by an immutable grant. */
27
+ export declare class SourceReviewStore {
28
+ #private;
29
+ constructor(path: string);
30
+ close(): void;
31
+ /** Read the immutable grant without creating a row or admitting an operation. */
32
+ remaining(input: Pick<ClaimInput, 'authorityId' | 'authorityDigest' | 'maxReviews'>): number;
33
+ available(input: Pick<ClaimInput, 'authorityId' | 'authorityDigest' | 'maxReviews'> & {
34
+ operationId?: string;
35
+ }): boolean;
36
+ /** Exact receipt read: never creates a claim, consumes quota, or retries a model call. */
37
+ inspect(input: ClaimInput): Claim | undefined;
38
+ claim(input: ClaimInput): Claim;
39
+ finish(operationId: string, requestDigest: string, result: Result & {
40
+ status: 'approved' | 'rejected';
41
+ }): void;
42
+ }
43
+ export {};
44
+ //# sourceMappingURL=source-review-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-review-store.d.ts","sourceRoot":"","sources":["../src/source-review-store.ts"],"names":[],"mappings":"AAKA,qBAAa,sBAAuB,SAAQ,KAAK;IACnC,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,UAAU,GAAG,SAAS;gBAA9C,IAAI,EAAE,eAAe,GAAG,UAAU,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM;CACrF;AACD,KAAK,KAAK,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAC1E,KAAK,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAA;AAGtD,UAAU,UAAU;IAAG,WAAW,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE;AACnJ,UAAU,KAAK;IAAG,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;AAwB3F,yFAAyF;AACzF,qBAAa,iBAAiB;;gBAGhB,IAAI,EAAE,MAAM;IAsBxB,KAAK,IAAI,IAAI;IACb,iFAAiF;IACjF,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,aAAa,GAAG,iBAAiB,GAAG,YAAY,CAAC,GAAG,MAAM;IAiB5F,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,aAAa,GAAG,iBAAiB,GAAG,YAAY,CAAC,GAAG;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO;IAaxH,0FAA0F;IAC1F,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,GAAG,SAAS;IAgB7C,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK;IAqB/B,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAA;KAAE,GAAG,IAAI;CAa/G"}
@@ -0,0 +1,212 @@
1
+ import { closeSync, constants, lstatSync, mkdirSync, openSync, realpathSync } from 'node:fs';
2
+ import { dirname, isAbsolute, resolve } from 'node:path';
3
+ import { DatabaseSync } from 'node:sqlite';
4
+ import { acceptanceCanonicalJson } from '@dsh-ray/task-acceptance-contract';
5
+ export class SourceReviewStoreError extends Error {
6
+ code;
7
+ constructor(code, message) {
8
+ super(message);
9
+ this.code = code;
10
+ }
11
+ }
12
+ const D = /^[a-f0-9]{64}$/u, I = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,255}$/u;
13
+ function fail(code, message) { throw new SourceReviewStoreError(code, message); }
14
+ function id(value) { if (typeof value !== 'string' || !I.test(value))
15
+ fail('invalid-input', 'invalid review identity'); }
16
+ function digest(value) { if (typeof value !== 'string' || !D.test(value))
17
+ fail('invalid-input', 'invalid review digest'); }
18
+ function reason(value) {
19
+ if (typeof value !== 'string' || !value.trim() || value.includes('\0') || Buffer.byteLength(value) > 4096)
20
+ fail('invalid-input', 'invalid review reason');
21
+ }
22
+ function claimModel(input) {
23
+ id(input.operationId);
24
+ digest(input.requestDigest);
25
+ id(input.authorityId);
26
+ digest(input.authorityDigest);
27
+ if (!Number.isSafeInteger(input.maxReviews) || input.maxReviews < 1 || input.maxReviews > 10_000)
28
+ fail('invalid-input', 'invalid review quota');
29
+ id(input.model.provider);
30
+ if (typeof input.model.model !== 'string' || !input.model.model.trim() || input.model.model.includes('\0')
31
+ || !input.model.model.isWellFormed() || Buffer.byteLength(input.model.model) > 256)
32
+ fail('invalid-input', 'invalid review model');
33
+ if (input.model.reasoningEffort !== undefined)
34
+ id(input.model.reasoningEffort);
35
+ return acceptanceCanonicalJson({ provider: input.model.provider, model: input.model.model,
36
+ ...(input.model.reasoningEffort === undefined ? {} : { reasoningEffort: input.model.reasoningEffort }) });
37
+ }
38
+ function privateFile(path) {
39
+ const stat = lstatSync(path);
40
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || (stat.mode & 0o077) !== 0
41
+ || process.getuid && stat.uid !== process.getuid() || realpathSync(path) !== path)
42
+ fail('corrupt', 'review database must be private and canonical');
43
+ }
44
+ /** Durable at-most-once model admission, independently bounded by an immutable grant. */
45
+ export class SourceReviewStore {
46
+ #db;
47
+ #closed = false;
48
+ constructor(path) {
49
+ if (!isAbsolute(path) || resolve(path) !== path)
50
+ fail('invalid-input', 'invalid review database path');
51
+ const parent = dirname(path);
52
+ mkdirSync(parent, { recursive: true, mode: 0o700 });
53
+ const directory = lstatSync(parent);
54
+ if (!directory.isDirectory() || directory.isSymbolicLink() || (directory.mode & 0o077) !== 0
55
+ || process.getuid && directory.uid !== process.getuid() || realpathSync(parent) !== parent)
56
+ fail('corrupt', 'review database directory must be private and canonical');
57
+ try {
58
+ closeSync(openSync(path, constants.O_CREAT | constants.O_EXCL | constants.O_RDWR | constants.O_NOFOLLOW, 0o600));
59
+ }
60
+ catch (error) {
61
+ if (error.code !== 'EEXIST')
62
+ throw error;
63
+ }
64
+ privateFile(path);
65
+ for (const suffix of ['-wal', '-shm', '-journal']) {
66
+ try {
67
+ privateFile(path + suffix);
68
+ }
69
+ catch (error) {
70
+ if (error.code !== 'ENOENT')
71
+ throw error;
72
+ }
73
+ }
74
+ this.#db = new DatabaseSync(path);
75
+ try {
76
+ this.#db.exec(`PRAGMA busy_timeout=5000; PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL;
77
+ CREATE TABLE IF NOT EXISTS grants(authority TEXT PRIMARY KEY, digest TEXT NOT NULL, max INTEGER NOT NULL, used INTEGER NOT NULL);
78
+ CREATE TABLE IF NOT EXISTS reviews(operation TEXT PRIMARY KEY, request TEXT NOT NULL, authority TEXT NOT NULL,
79
+ model TEXT NOT NULL, state TEXT NOT NULL CHECK(state IN ('claimed','approved','rejected')), reason TEXT, output TEXT);`);
80
+ }
81
+ catch (error) {
82
+ this.#db.close();
83
+ throw error;
84
+ }
85
+ }
86
+ close() { if (!this.#closed) {
87
+ this.#closed = true;
88
+ this.#db.close();
89
+ } }
90
+ /** Read the immutable grant without creating a row or admitting an operation. */
91
+ remaining(input) {
92
+ id(input.authorityId);
93
+ digest(input.authorityDigest);
94
+ if (!Number.isSafeInteger(input.maxReviews) || input.maxReviews < 1 || input.maxReviews > 10_000)
95
+ fail('invalid-input', 'invalid review quota');
96
+ if (this.#closed)
97
+ fail('conflict', 'review database is closed');
98
+ const grant = this.#db.prepare('SELECT * FROM grants WHERE authority=?').get(input.authorityId);
99
+ const claims = this.#db.prepare('SELECT count(*) AS count FROM reviews WHERE authority=?')
100
+ .get(input.authorityId).count;
101
+ if (!grant) {
102
+ if (claims !== 0)
103
+ fail('corrupt', 'review claims have no grant');
104
+ return input.maxReviews;
105
+ }
106
+ if (!Number.isSafeInteger(grant.max) || grant.max < 1 || grant.max > 10_000
107
+ || !Number.isSafeInteger(grant.used) || grant.used < 0 || grant.used > grant.max
108
+ || grant.used !== claims)
109
+ fail('corrupt', 'invalid stored review quota');
110
+ if (grant.digest !== input.authorityDigest || grant.max !== input.maxReviews)
111
+ fail('conflict', 'authority grant differs');
112
+ return grant.max - grant.used;
113
+ }
114
+ available(input) {
115
+ if (this.#closed)
116
+ return false;
117
+ const grant = this.#db.prepare('SELECT * FROM grants WHERE authority=?').get(input.authorityId);
118
+ if (!grant)
119
+ return true;
120
+ if (grant.digest !== input.authorityDigest || grant.max !== input.maxReviews || !Number.isSafeInteger(grant.used)
121
+ || grant.used < 0 || grant.used > grant.max)
122
+ return false;
123
+ if (input.operationId !== undefined && this.#db.prepare('SELECT 1 FROM reviews WHERE operation=? AND authority=?').get(input.operationId, input.authorityId))
124
+ return true;
125
+ return grant.used < grant.max;
126
+ }
127
+ #transaction(callback) {
128
+ this.#db.exec('BEGIN IMMEDIATE');
129
+ try {
130
+ const result = callback();
131
+ this.#db.exec('COMMIT');
132
+ return result;
133
+ }
134
+ catch (error) {
135
+ this.#db.exec('ROLLBACK');
136
+ throw error;
137
+ }
138
+ }
139
+ /** Exact receipt read: never creates a claim, consumes quota, or retries a model call. */
140
+ inspect(input) {
141
+ const model = claimModel(input);
142
+ if (this.#closed)
143
+ fail('conflict', 'review database is closed');
144
+ const row = this.#db.prepare(`SELECT reviews.*, grants.digest AS grant_digest,
145
+ grants.max AS grant_max, grants.used AS grant_used
146
+ FROM reviews LEFT JOIN grants ON grants.authority=reviews.authority WHERE operation=?`)
147
+ .get(input.operationId);
148
+ if (!row)
149
+ return undefined;
150
+ if (row.request !== input.requestDigest || row.authority !== input.authorityId || row.model !== model
151
+ || row.grant_digest !== input.authorityDigest || row.grant_max !== input.maxReviews)
152
+ fail('conflict', 'review binding differs');
153
+ if (!Number.isSafeInteger(row.grant_used) || row.grant_used < 1 || row.grant_used > row.grant_max)
154
+ fail('corrupt', 'invalid stored review quota');
155
+ if (row.state === 'claimed')
156
+ return { state: 'unknown' };
157
+ if (row.state !== 'approved' && row.state !== 'rejected')
158
+ fail('corrupt', 'invalid stored review state');
159
+ reason(row.reason);
160
+ digest(row.output);
161
+ return { state: row.state, result: { reason: row.reason, outputDigest: row.output } };
162
+ }
163
+ claim(input) {
164
+ const model = claimModel(input);
165
+ return this.#transaction(() => {
166
+ const grant = this.#db.prepare('SELECT * FROM grants WHERE authority=?').get(input.authorityId);
167
+ if (grant && (grant.digest !== input.authorityDigest || grant.max !== input.maxReviews))
168
+ fail('conflict', 'authority grant differs');
169
+ if (grant && (!Number.isSafeInteger(grant.used) || grant.used < 0 || grant.used > grant.max))
170
+ fail('corrupt', 'invalid stored review quota');
171
+ const old = this.#db.prepare('SELECT * FROM reviews WHERE operation=?').get(input.operationId);
172
+ if (old) {
173
+ if (!grant || old.request !== input.requestDigest || old.authority !== input.authorityId || old.model !== model)
174
+ fail('conflict', 'review binding differs');
175
+ if (old.state === 'claimed')
176
+ return { state: 'unknown' };
177
+ if (old.state !== 'approved' && old.state !== 'rejected')
178
+ fail('corrupt', 'invalid stored review state');
179
+ reason(old.reason);
180
+ digest(old.output);
181
+ return { state: old.state, result: { reason: old.reason, outputDigest: old.output } };
182
+ }
183
+ if (grant && grant.used >= grant.max)
184
+ fail('conflict', 'review quota exhausted');
185
+ if (!grant)
186
+ this.#db.prepare('INSERT INTO grants VALUES(?,?,?,0)').run(input.authorityId, input.authorityDigest, input.maxReviews);
187
+ this.#db.prepare('UPDATE grants SET used=used+1 WHERE authority=?').run(input.authorityId);
188
+ this.#db.prepare("INSERT INTO reviews VALUES(?,?,?,?,'claimed',NULL,NULL)").run(input.operationId, input.requestDigest, input.authorityId, model);
189
+ return { state: 'claimed' };
190
+ });
191
+ }
192
+ finish(operationId, requestDigest, result) {
193
+ id(operationId);
194
+ digest(requestDigest);
195
+ reason(result.reason);
196
+ digest(result.outputDigest);
197
+ if (!['approved', 'rejected'].includes(result.status))
198
+ fail('invalid-input', 'invalid review result');
199
+ this.#transaction(() => {
200
+ const row = this.#db.prepare('SELECT * FROM reviews WHERE operation=?').get(operationId);
201
+ if (!row || row.request !== requestDigest)
202
+ fail('conflict', 'review differs');
203
+ if (row.state !== 'claimed') {
204
+ if (row.state !== result.status || row.reason !== result.reason || row.output !== result.outputDigest)
205
+ fail('conflict', 'result differs');
206
+ return;
207
+ }
208
+ this.#db.prepare('UPDATE reviews SET state=?,reason=?,output=? WHERE operation=?').run(result.status, result.reason, result.outputDigest, operationId);
209
+ });
210
+ }
211
+ }
212
+ //# sourceMappingURL=source-review-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-review-store.js","sourceRoot":"","sources":["../src/source-review-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC5F,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAA;AAE3E,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC1B;IAArB,YAAqB,IAA8C,EAAE,OAAe;QAAI,KAAK,CAAC,OAAO,CAAC,CAAA;QAAjF,SAAI,GAAJ,IAAI,CAA0C;IAAoC,CAAC;CACzG;AAOD,MAAM,CAAC,GAAG,iBAAiB,EAAE,CAAC,GAAG,uCAAuC,CAAA;AACxE,SAAS,IAAI,CAAC,IAAoC,EAAE,OAAe,IAAW,MAAM,IAAI,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA,CAAC,CAAC;AAC/H,SAAS,EAAE,CAAC,KAAc,IAAU,IAAI,OAAO,KAAK,KAAK,QAAQ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,CAAC,CAAA;gBACzI,OAAM;YACR,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,gEAAgE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAA;QACxJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,86 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { OwnerForegroundLearningTask } from '@dsh-ray/assistant-delivery';
3
+ export interface SourceReviewModelSelection {
4
+ provider: string;
5
+ model: string;
6
+ reasoningEffort?: string;
7
+ }
8
+ export type SourceReviewOwnerReceipt = OwnerForegroundLearningTask['owner'];
9
+ declare const ownerKeys: readonly ["authorityId", "authorityHash", "principalId", "principalRecordId", "principalVersion", "workspace", "agentPreset"];
10
+ export interface SourceReviewConfig {
11
+ authorityId: string;
12
+ expiresAt: number;
13
+ maxReviews: number;
14
+ repository: string;
15
+ git: {
16
+ path: string;
17
+ sha256: string;
18
+ };
19
+ decisionRoot: string;
20
+ plugins: readonly string[];
21
+ owner: Pick<SourceReviewOwnerReceipt, typeof ownerKeys[number]>;
22
+ reviewerPrincipal: string;
23
+ policy: string;
24
+ maxChangedFiles: number;
25
+ maxInputBytes: number;
26
+ maxOutputTokens: number;
27
+ timeoutMs: number;
28
+ model?: SourceReviewModelSelection;
29
+ }
30
+ export interface SourceReviewRequest {
31
+ protocol: 'dsh-source-review/v1';
32
+ operationId: string;
33
+ planId: string;
34
+ planDigest: string;
35
+ releaseId: string;
36
+ fence: number;
37
+ revision: number;
38
+ name: string;
39
+ baseCommit: string;
40
+ headCommit: string;
41
+ prId: string;
42
+ prEvidenceDigest: string;
43
+ checkedTreeDigest: string;
44
+ checkedPatchDigest: string;
45
+ scope: readonly string[];
46
+ source: {
47
+ owner: SourceReviewOwnerReceipt;
48
+ outcomeId: string;
49
+ sourceDigest: string;
50
+ objective: string;
51
+ modelSelection?: SourceReviewModelSelection;
52
+ };
53
+ }
54
+ export interface SourceReviewResult {
55
+ status: 'approved' | 'rejected' | 'unknown';
56
+ operationId: string;
57
+ requestDigest: string;
58
+ sessionId: string;
59
+ reason: string;
60
+ model: SourceReviewModelSelection;
61
+ outputDigest?: string;
62
+ }
63
+ export interface SourceReviewInput {
64
+ request: SourceReviewRequest;
65
+ signal?: AbortSignal;
66
+ withSourceFence<T>(callback: () => T): T;
67
+ }
68
+ export interface SourceReviewSelection {
69
+ decisionRoot: string;
70
+ owner: SourceReviewOwnerReceipt;
71
+ name: string;
72
+ modelSelection?: SourceReviewModelSelection;
73
+ operationId?: string;
74
+ }
75
+ export declare function validateSourceReviewConfig(value: SourceReviewConfig): SourceReviewConfig;
76
+ /** Lifetime belongs to the injected Fiber; close aborts and drains before DB close. */
77
+ export declare class SourceReviewRuntime {
78
+ #private;
79
+ private readonly ctx;
80
+ constructor(ctx: Context, config: SourceReviewConfig, databasePath: string);
81
+ available(input: SourceReviewSelection): boolean;
82
+ run(input: SourceReviewInput): Promise<SourceReviewResult>;
83
+ close(): Promise<void>;
84
+ }
85
+ export {};
86
+ //# sourceMappingURL=source-review.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-review.d.ts","sourceRoot":"","sources":["../src/source-review.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAA;AAK9E,MAAM,WAAW,0BAA0B;IAAG,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE;AACzG,MAAM,MAAM,wBAAwB,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAA;AAC3E,QAAA,MAAM,SAAS,+HAAgI,CAAA;AAC/I,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IA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AAE,0BAA0B,CAAA;KAAE,CAAA;CACrJ;AACD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;IACvF,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,0BAA0B,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAC5F;AACD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,mBAAmB,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;CAC7F;AACD,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,wBAAwB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;IACnE,cAAc,CAAC,EAAE,0BAA0B,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAClE;AAmCD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,kBAAkB,CAaxF;AAkDD,uFAAuF;AACvF,qBAAa,mBAAmB;;IAMlB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM;IAI3F,SAAS,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO;IAQhD,GAAG,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAmD1D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAMvB"}
@@ -0,0 +1,255 @@
1
+ import { closeSync, constants, fstatSync, fsyncSync, linkSync, lstatSync, openSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from 'node:fs';
2
+ import { isAbsolute, join, resolve } from 'node:path';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { acceptanceCanonicalJson, acceptanceDigest } from '@dsh-ray/task-acceptance-contract';
5
+ import { assertSourceReviewHead, inspectSourceReviewGit } from './source-review-git.js';
6
+ import { SourceReviewStore } from './source-review-store.js';
7
+ const ownerKeys = ['authorityId', 'authorityHash', 'principalId', 'principalRecordId', 'principalVersion', 'workspace', 'agentPreset'];
8
+ const idPattern = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,255}$/u;
9
+ const shaPattern = /^[a-f0-9]{64}$/u;
10
+ function exact(value, required, optional = []) {
11
+ if (!value || typeof value !== 'object' || Array.isArray(value)
12
+ || ![Object.prototype, null].includes(Object.getPrototypeOf(value))
13
+ || Reflect.ownKeys(value).some(key => typeof key !== 'string' || ![...required, ...optional].includes(key))
14
+ || required.some(key => !Object.hasOwn(value, key))
15
+ || Object.values(Object.getOwnPropertyDescriptors(value)).some(item => !item.enumerable || !('value' in item)))
16
+ throw new Error('source review invalid object');
17
+ }
18
+ function text(value, max) {
19
+ if (typeof value !== 'string' || !value.trim() || value.includes('\0') || Buffer.byteLength(value) > max)
20
+ throw new Error('source review invalid text');
21
+ }
22
+ function id(value) { text(value, 256); if (!idPattern.test(value))
23
+ throw new Error('source review invalid identity'); }
24
+ function integer(value, max = Number.MAX_SAFE_INTEGER, min = 1) {
25
+ if (!Number.isSafeInteger(value) || value < min || value > max)
26
+ throw new Error('source review invalid bound');
27
+ }
28
+ function path(value) {
29
+ text(value, 4096);
30
+ if (!isAbsolute(value) || value === '/' || resolve(value) !== value)
31
+ throw new Error('source review invalid path');
32
+ }
33
+ function sha(value) { if (typeof value !== 'string' || !shaPattern.test(value))
34
+ throw new Error('source review invalid digest'); }
35
+ function model(value) {
36
+ exact(value, ['provider', 'model'], ['reasoningEffort']);
37
+ id(value.provider);
38
+ id(value.model);
39
+ if (value.reasoningEffort !== undefined)
40
+ id(value.reasoningEffort);
41
+ }
42
+ function owner(value) {
43
+ for (const key of ['authorityId', 'principalId', 'principalRecordId', 'agentPreset'])
44
+ id(value[key]);
45
+ sha(value.authorityHash);
46
+ integer(value.principalVersion);
47
+ path(value.workspace);
48
+ }
49
+ function privateRoot(root) {
50
+ path(root);
51
+ const stat = lstatSync(root);
52
+ if (!stat.isDirectory() || stat.isSymbolicLink() || stat.mode & 0o077
53
+ || process.getuid && stat.uid !== process.getuid() || realpathSync(root) !== root)
54
+ throw new Error('source review decision directory must be private and canonical');
55
+ }
56
+ export function validateSourceReviewConfig(value) {
57
+ exact(value, ['authorityId', 'expiresAt', 'maxReviews', 'repository', 'git', 'decisionRoot', 'plugins', 'owner', 'reviewerPrincipal',
58
+ 'policy', 'maxChangedFiles', 'maxInputBytes', 'maxOutputTokens', 'timeoutMs'], ['model']);
59
+ id(value.authorityId);
60
+ integer(value.expiresAt);
61
+ integer(value.maxReviews, 10_000);
62
+ path(value.repository);
63
+ exact(value.git, ['path', 'sha256']);
64
+ path(value.git.path);
65
+ sha(value.git.sha256);
66
+ privateRoot(value.decisionRoot);
67
+ exact(value.owner, ownerKeys);
68
+ owner(value.owner);
69
+ id(value.reviewerPrincipal);
70
+ text(value.policy, 16_384);
71
+ integer(value.maxChangedFiles, 1000);
72
+ integer(value.maxInputBytes, 2_097_152, 4096);
73
+ integer(value.maxOutputTokens, 32_768);
74
+ integer(value.timeoutMs, 1_800_000, 1000);
75
+ if (!Array.isArray(value.plugins) || value.plugins.length === 0 || value.plugins.length > 64
76
+ || new Set(value.plugins).size !== value.plugins.length || value.plugins.some(name => !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u.test(name)))
77
+ throw new Error('source review invalid plugin scope');
78
+ if (value.model !== undefined)
79
+ model(value.model);
80
+ return structuredClone(value);
81
+ }
82
+ function validateRequest(value, config) {
83
+ exact(value, ['protocol', 'operationId', 'planId', 'planDigest', 'releaseId', 'fence', 'revision', 'name', 'baseCommit', 'headCommit',
84
+ 'prId', 'prEvidenceDigest', 'checkedTreeDigest', 'checkedPatchDigest', 'scope', 'source']);
85
+ if (value.protocol !== 'dsh-source-review/v1')
86
+ throw new Error('source review invalid protocol');
87
+ for (const key of ['operationId', 'planId', 'releaseId'])
88
+ id(value[key]);
89
+ if (typeof value.prId !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,159}$/u.test(value.prId))
90
+ throw new Error('source review invalid PR');
91
+ for (const key of ['planDigest', 'prEvidenceDigest', 'checkedTreeDigest', 'checkedPatchDigest'])
92
+ sha(value[key]);
93
+ integer(value.fence);
94
+ integer(value.revision);
95
+ for (const key of ['baseCommit', 'headCommit'])
96
+ if (!/^[a-f0-9]{40}$/u.test(value[key]))
97
+ throw new Error('source review invalid commit');
98
+ if (!config.plugins.includes(value.name) || !Array.isArray(value.scope) || value.scope.length !== 1 || value.scope[0] !== `plugins/${value.name}`)
99
+ throw new Error('source review outside grant scope');
100
+ exact(value.source, ['owner', 'outcomeId', 'sourceDigest', 'objective'], ['modelSelection']);
101
+ exact(value.source.owner, [...ownerKeys, 'receiptVersion', 'bindingVersion', 'generation']);
102
+ owner(value.source.owner);
103
+ if (value.source.owner.receiptVersion !== 2 || ownerKeys.some(key => value.source.owner[key] !== config.owner[key]))
104
+ throw new Error('source review owner changed');
105
+ integer(value.source.owner.bindingVersion);
106
+ integer(value.source.owner.generation);
107
+ id(value.source.outcomeId);
108
+ sha(value.source.sourceDigest);
109
+ text(value.source.objective, 65_536);
110
+ if (value.source.modelSelection !== undefined)
111
+ model(value.source.modelSelection);
112
+ }
113
+ /** Host-only immutable writer. The model never receives a filesystem capability. */
114
+ function writeDecision(config, request) {
115
+ privateRoot(config.decisionRoot);
116
+ const decision = { schemaVersion: 1, kind: 'dsh-local-review-decision', prId: request.prId,
117
+ baseCommit: request.baseCommit, headCommit: request.headCommit, prEvidenceDigest: request.prEvidenceDigest,
118
+ decision: 'approved', reviewerPrincipal: config.reviewerPrincipal };
119
+ const destination = join(config.decisionRoot, `${request.prId}.json`);
120
+ const verifyExisting = () => {
121
+ const stat = lstatSync(destination);
122
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || stat.mode & 0o077 || stat.size > 8192
123
+ || process.getuid && stat.uid !== process.getuid())
124
+ throw new Error('source review unsafe existing decision');
125
+ const fd = openSync(destination, constants.O_RDONLY | constants.O_NOFOLLOW);
126
+ try {
127
+ const opened = fstatSync(fd);
128
+ if (opened.ino !== stat.ino || opened.dev !== stat.dev)
129
+ throw new Error('source review decision replaced');
130
+ if (acceptanceCanonicalJson(JSON.parse(readFileSync(fd, 'utf8'))) !== acceptanceCanonicalJson(decision))
131
+ throw new Error('source review decision conflict');
132
+ }
133
+ finally {
134
+ closeSync(fd);
135
+ }
136
+ };
137
+ const temporary = join(config.decisionRoot, `.review-${randomUUID()}`);
138
+ const fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
139
+ try {
140
+ writeFileSync(fd, JSON.stringify(decision) + '\n');
141
+ fsyncSync(fd);
142
+ }
143
+ finally {
144
+ closeSync(fd);
145
+ }
146
+ try {
147
+ try {
148
+ linkSync(temporary, destination);
149
+ }
150
+ catch (error) {
151
+ if (error.code !== 'EEXIST')
152
+ throw error;
153
+ verifyExisting();
154
+ }
155
+ }
156
+ finally {
157
+ unlinkSync(temporary);
158
+ }
159
+ const directory = openSync(config.decisionRoot, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
160
+ try {
161
+ fsyncSync(directory);
162
+ }
163
+ finally {
164
+ closeSync(directory);
165
+ }
166
+ }
167
+ /** Lifetime belongs to the injected Fiber; close aborts and drains before DB close. */
168
+ export class SourceReviewRuntime {
169
+ ctx;
170
+ #config;
171
+ #store;
172
+ #controller = new AbortController();
173
+ #flights = new Set();
174
+ #closing;
175
+ constructor(ctx, config, databasePath) {
176
+ this.ctx = ctx;
177
+ this.#config = validateSourceReviewConfig(config);
178
+ this.#store = new SourceReviewStore(databasePath + '.source-reviews');
179
+ }
180
+ available(input) {
181
+ const config = this.#config;
182
+ return !this.#controller.signal.aborted && config.expiresAt > Date.now() && input.decisionRoot === config.decisionRoot
183
+ && input.owner.receiptVersion === 2 && ownerKeys.every(key => input.owner[key] === config.owner[key])
184
+ && config.plugins.includes(input.name) && (config.model !== undefined || input.modelSelection !== undefined)
185
+ && this.#store.available({ authorityId: config.authorityId, authorityDigest: acceptanceDigest(config), maxReviews: config.maxReviews,
186
+ ...(input.operationId === undefined ? {} : { operationId: input.operationId }) });
187
+ }
188
+ run(input) {
189
+ this.#controller.signal.throwIfAborted();
190
+ const operation = this.#run(input);
191
+ this.#flights.add(operation);
192
+ void operation.finally(() => this.#flights.delete(operation)).catch(() => { });
193
+ return operation;
194
+ }
195
+ async #run(input) {
196
+ const config = this.#config;
197
+ validateRequest(input.request, config);
198
+ const request = structuredClone(input.request), selected = structuredClone(config.model ?? request.source.modelSelection);
199
+ if (!selected)
200
+ throw new Error('source review requires a frozen task model or explicit fixed model');
201
+ const signal = AbortSignal.any([this.#controller.signal, AbortSignal.timeout(config.timeoutMs), ...(input.signal ? [input.signal] : [])]);
202
+ const assertLive = () => {
203
+ signal.throwIfAborted();
204
+ if (Date.now() >= config.expiresAt)
205
+ throw new Error('source review grant expired');
206
+ };
207
+ const assertCurrent = () => { assertLive(); input.withSourceFence(() => { }); };
208
+ assertCurrent();
209
+ const requestDigest = acceptanceDigest(request), authorityDigest = acceptanceDigest(config);
210
+ const gitRequest = { name: request.name, baseCommit: request.baseCommit, headCommit: request.headCommit, prId: request.prId,
211
+ scope: request.scope, checkedTreeDigest: request.checkedTreeDigest, checkedPatchDigest: request.checkedPatchDigest };
212
+ const gitConfig = { repository: config.repository, git: config.git, maxChangedFiles: config.maxChangedFiles, maxInputBytes: config.maxInputBytes };
213
+ // Git inspection completes before reserving a model call; no DB transaction crosses an await.
214
+ const context = await inspectSourceReviewGit(gitConfig, gitRequest, signal);
215
+ const claim = input.withSourceFence(() => {
216
+ assertLive();
217
+ assertSourceReviewHead(gitConfig, gitRequest);
218
+ return this.#store.claim({ operationId: request.operationId, requestDigest, authorityId: config.authorityId,
219
+ authorityDigest, maxReviews: config.maxReviews, model: selected });
220
+ });
221
+ const base = { operationId: request.operationId, requestDigest, model: selected, sessionId: `source-review-${requestDigest.slice(0, 40)}` };
222
+ if (claim.state === 'unknown')
223
+ return { ...base, status: 'unknown', reason: 'Previous review has no durable terminal result; model call will not be repeated.' };
224
+ if (claim.state === 'approved' || claim.state === 'rejected') {
225
+ if (claim.state === 'approved')
226
+ input.withSourceFence(() => { assertLive(); assertSourceReviewHead(gitConfig, gitRequest); writeDecision(config, request); });
227
+ return { ...base, status: claim.state, ...claim.result };
228
+ }
229
+ try {
230
+ const { runNativeSourceReview } = await import('./source-review-native.js');
231
+ assertCurrent();
232
+ const result = await runNativeSourceReview(this.ctx, { config, request, model: selected, ...context, signal, assertCurrent });
233
+ await inspectSourceReviewGit(gitConfig, gitRequest, signal);
234
+ input.withSourceFence(() => {
235
+ assertLive();
236
+ assertSourceReviewHead(gitConfig, gitRequest);
237
+ this.#store.finish(request.operationId, requestDigest, result);
238
+ if (result.status === 'approved')
239
+ writeDecision(config, request);
240
+ });
241
+ return { ...base, ...result };
242
+ }
243
+ catch {
244
+ return { ...base, status: 'unknown', reason: 'Review did not produce an admissible durable decision; inspect the Host review session before reconciliation.' };
245
+ }
246
+ }
247
+ close() {
248
+ return this.#closing ??= (async () => {
249
+ this.#controller.abort(new Error('source reviewer disposed'));
250
+ await Promise.allSettled(this.#flights);
251
+ this.#store.close();
252
+ })();
253
+ }
254
+ }
255
+ //# sourceMappingURL=source-review.js.map