@firefunc-agent/runner 0.9.7 → 0.9.14
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/README.md +2 -0
- package/dist/activity.d.ts +1 -0
- package/dist/activity.js +1 -1
- package/dist/api-fallback.d.ts +9 -0
- package/dist/api-fallback.js +55 -0
- package/dist/api.d.ts +121 -0
- package/dist/api.js +147 -3
- package/dist/ask/index.d.ts +20 -0
- package/dist/ask/index.js +64 -0
- package/dist/ask-first.d.ts +8 -0
- package/dist/brief.d.ts +2 -0
- package/dist/brief.js +6 -0
- package/dist/build-info.json +2 -2
- package/dist/config.d.ts +2 -0
- package/dist/cut.d.ts +2 -1
- package/dist/cut.js +8 -4
- package/dist/daemon.js +14 -2
- package/dist/engines/claude.js +10 -4
- package/dist/git-auth.d.ts +1 -0
- package/dist/git-auth.js +9 -1
- package/dist/job.js +415 -38
- package/dist/keep-local.d.ts +1 -0
- package/dist/keep-local.js +3 -0
- package/dist/limit.d.ts +1 -0
- package/dist/limit.js +4 -1
- package/dist/locks.d.ts +3 -0
- package/dist/locks.js +46 -13
- package/dist/plan-phase/index.d.ts +11 -0
- package/dist/plan-phase/index.js +46 -0
- package/dist/pool.js +4 -2
- package/dist/pr-title.d.ts +5 -0
- package/dist/pr-title.js +18 -0
- package/dist/reference-files.d.ts +27 -0
- package/dist/reference-files.js +202 -0
- package/dist/run-attachments.d.ts +79 -0
- package/dist/run-attachments.js +276 -0
- package/dist/secret-scan.d.ts +1 -1
- package/dist/secret-scan.js +3 -0
- package/dist/secret-values.d.ts +17 -0
- package/dist/secret-values.js +81 -0
- package/dist/trail/chain.d.ts +12 -0
- package/dist/trail/chain.js +89 -0
- package/dist/trail/deltas.d.ts +34 -0
- package/dist/trail/deltas.js +206 -0
- package/dist/trail/index.d.ts +27 -0
- package/dist/trail/index.js +128 -0
- package/dist/trail/keys.d.ts +14 -0
- package/dist/trail/keys.js +61 -0
- package/dist/trail/recorder.d.ts +118 -0
- package/dist/trail/recorder.js +697 -0
- package/dist/trail/rules.d.ts +30 -0
- package/dist/trail/rules.js +158 -0
- package/dist/trail/stream.d.ts +41 -0
- package/dist/trail/stream.js +86 -0
- package/package.json +1 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync, } from 'node:fs';
|
|
4
|
+
import { isAbsolute, join, relative, sep } from 'node:path';
|
|
5
|
+
import { isNetworkError, withNetworkRetry } from './network.js';
|
|
6
|
+
export const ATTACH_FOLDER = '.firefunc/attach';
|
|
7
|
+
export const MAX_ATTACHMENTS = 12;
|
|
8
|
+
export const MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
|
|
9
|
+
export const MAX_ATTACHMENTS_TOTAL_BYTES = 60 * 1024 * 1024;
|
|
10
|
+
export const ATTACHMENT_TYPES = {
|
|
11
|
+
png: 'image/png',
|
|
12
|
+
jpg: 'image/jpeg',
|
|
13
|
+
jpeg: 'image/jpeg',
|
|
14
|
+
webp: 'image/webp',
|
|
15
|
+
gif: 'image/gif',
|
|
16
|
+
mp4: 'video/mp4',
|
|
17
|
+
};
|
|
18
|
+
const GITIGNORE = '# FireFunc: pictures a run attaches to its ticket, never committed\n*\n';
|
|
19
|
+
export const ATTACH_RULE = `- To show the founder what you built, save screenshots (png/jpg/webp) or one short screen recording (mp4) in \`${ATTACH_FOLDER}/\`; FireFunc attaches them to the ticket. Never capture a screen that shows a key, a token or a password.`;
|
|
20
|
+
export function attachLimitsOf(offer) {
|
|
21
|
+
const within = (v, cap) => typeof v === 'number' && Number.isFinite(v) && v > 0 ? Math.min(Math.floor(v), cap) : cap;
|
|
22
|
+
return {
|
|
23
|
+
maxFiles: within(offer.maxFiles, MAX_ATTACHMENTS),
|
|
24
|
+
maxFileBytes: within(offer.maxFileBytes, MAX_ATTACHMENT_BYTES),
|
|
25
|
+
maxTotalBytes: within(offer.maxTotalBytes, MAX_ATTACHMENTS_TOTAL_BYTES),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function git(cwd, args) {
|
|
29
|
+
try {
|
|
30
|
+
return execFileSync('git', ['-C', cwd, ...args], {
|
|
31
|
+
encoding: 'utf8',
|
|
32
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
33
|
+
}).trim();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function insideTop(top, real) {
|
|
40
|
+
const rel = relative(top, real);
|
|
41
|
+
if (!rel || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel))
|
|
42
|
+
return null;
|
|
43
|
+
return rel.split(sep).join('/');
|
|
44
|
+
}
|
|
45
|
+
function lstatExists(p) {
|
|
46
|
+
try {
|
|
47
|
+
lstatSync(p);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const NONE = { written: [], pathspecs: [], dir: null };
|
|
55
|
+
export function prepareAttachFolder(worktree, log) {
|
|
56
|
+
let top;
|
|
57
|
+
try {
|
|
58
|
+
top = realpathSync(worktree);
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
log(`no folder for pictures: ${e.message}`);
|
|
62
|
+
return NONE;
|
|
63
|
+
}
|
|
64
|
+
const outer = join(top, '.firefunc');
|
|
65
|
+
if (!lstatExists(outer)) {
|
|
66
|
+
try {
|
|
67
|
+
mkdirSync(outer);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
log(`no folder for pictures: ${e.message}`);
|
|
71
|
+
return NONE;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (!existsSync(outer)) {
|
|
75
|
+
log('no folder for pictures: .firefunc is a link to a place that does not exist in this checkout. ' +
|
|
76
|
+
'Fix: point it at a folder inside the repository, or remove the link.');
|
|
77
|
+
return NONE;
|
|
78
|
+
}
|
|
79
|
+
let outerReal;
|
|
80
|
+
try {
|
|
81
|
+
outerReal = realpathSync(outer);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
log(`no folder for pictures: ${e.message}`);
|
|
85
|
+
return NONE;
|
|
86
|
+
}
|
|
87
|
+
if (insideTop(top, outerReal) === null || !statSync(outerReal).isDirectory()) {
|
|
88
|
+
log(`no folder for pictures: .firefunc leads to ${outerReal}, which is not a folder inside this checkout. ` +
|
|
89
|
+
'Fix: make .firefunc a folder inside the repository.');
|
|
90
|
+
return NONE;
|
|
91
|
+
}
|
|
92
|
+
const dir = join(outerReal, 'attach');
|
|
93
|
+
const rel = insideTop(top, dir);
|
|
94
|
+
const gitTop = git(top, ['rev-parse', '--show-toplevel']);
|
|
95
|
+
let isRepo = false;
|
|
96
|
+
if (gitTop) {
|
|
97
|
+
try {
|
|
98
|
+
isRepo = realpathSync(gitTop) === top;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
isRepo = false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const ignoreCase = isRepo && git(top, ['config', '--bool', 'core.ignorecase']) === 'true';
|
|
105
|
+
const ours = () => ({
|
|
106
|
+
written: [rel],
|
|
107
|
+
pathspecs: [`:(exclude,literal${ignoreCase ? ',icase' : ''})${rel}`],
|
|
108
|
+
...(ignoreCase ? { ignoreCase } : {}),
|
|
109
|
+
dir,
|
|
110
|
+
});
|
|
111
|
+
if (lstatExists(dir)) {
|
|
112
|
+
let mine = false;
|
|
113
|
+
try {
|
|
114
|
+
mine =
|
|
115
|
+
lstatSync(dir).isDirectory() && readFileSync(join(dir, '.gitignore'), 'utf8') === GITIGNORE;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
mine = false;
|
|
119
|
+
}
|
|
120
|
+
if (mine)
|
|
121
|
+
return ours();
|
|
122
|
+
log(`no folder for pictures: ${rel} is already in the checkout, and FireFunc never writes into the ` +
|
|
123
|
+
`repository's own files. Fix: rename or remove ${rel} in the repository.`);
|
|
124
|
+
return NONE;
|
|
125
|
+
}
|
|
126
|
+
if (isRepo) {
|
|
127
|
+
const tracked = git(top, [
|
|
128
|
+
'ls-files',
|
|
129
|
+
'-z',
|
|
130
|
+
'--',
|
|
131
|
+
`:(literal${ignoreCase ? ',icase' : ''})${rel}`,
|
|
132
|
+
]);
|
|
133
|
+
if (tracked) {
|
|
134
|
+
log(`no folder for pictures: the repository tracks files under ${rel}. Fix: move them out of ${rel}.`);
|
|
135
|
+
return NONE;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
mkdirSync(dir);
|
|
140
|
+
writeFileSync(join(dir, '.gitignore'), GITIGNORE);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
log(`no folder for pictures: ${e.message}`);
|
|
144
|
+
return NONE;
|
|
145
|
+
}
|
|
146
|
+
return ours();
|
|
147
|
+
}
|
|
148
|
+
export function scanAttachFolder(dir, limits = attachLimitsOf({})) {
|
|
149
|
+
const files = [];
|
|
150
|
+
const skipped = [];
|
|
151
|
+
let names;
|
|
152
|
+
try {
|
|
153
|
+
names = readdirSync(dir).sort((a, b) => a.localeCompare(b));
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return { files, skipped };
|
|
157
|
+
}
|
|
158
|
+
let total = 0;
|
|
159
|
+
for (const name of names) {
|
|
160
|
+
if (name === '.gitignore')
|
|
161
|
+
continue;
|
|
162
|
+
const path = join(dir, name);
|
|
163
|
+
let st;
|
|
164
|
+
try {
|
|
165
|
+
st = lstatSync(path);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (!st.isFile()) {
|
|
171
|
+
skipped.push({
|
|
172
|
+
name,
|
|
173
|
+
why: st.isSymbolicLink() ? 'it is a link, not a file' : 'it is not a file',
|
|
174
|
+
});
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (name.length > 120 || /[\u0000-\u001f\u007f\\]/.test(name) || name.trim() !== name) {
|
|
178
|
+
skipped.push({ name, why: 'its name is not a plain file name' });
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const ext = /\.([A-Za-z0-9]+)$/.exec(name)?.[1]?.toLowerCase();
|
|
182
|
+
const contentType = ext ? ATTACHMENT_TYPES[ext] : undefined;
|
|
183
|
+
if (!contentType) {
|
|
184
|
+
skipped.push({ name, why: 'only .png, .jpg, .jpeg, .webp, .gif and .mp4 are attached' });
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (st.size === 0) {
|
|
188
|
+
skipped.push({ name, why: 'it is empty' });
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (st.size > limits.maxFileBytes) {
|
|
192
|
+
skipped.push({ name, why: `it is larger than ${limits.maxFileBytes} bytes` });
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (files.length >= limits.maxFiles) {
|
|
196
|
+
skipped.push({ name, why: `a run attaches at most ${limits.maxFiles} files` });
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (total + st.size > limits.maxTotalBytes) {
|
|
200
|
+
skipped.push({
|
|
201
|
+
name,
|
|
202
|
+
why: `a run attaches at most ${limits.maxTotalBytes} bytes in all`,
|
|
203
|
+
});
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
total += st.size;
|
|
207
|
+
files.push({ name, path, size: st.size, contentType });
|
|
208
|
+
}
|
|
209
|
+
return { files, skipped };
|
|
210
|
+
}
|
|
211
|
+
export async function uploadRunAttachments(opts) {
|
|
212
|
+
const { runId, api, log } = opts;
|
|
213
|
+
const fetcher = opts.fetcher ?? fetch;
|
|
214
|
+
const scan = scanAttachFolder(opts.dir, opts.limits);
|
|
215
|
+
const attached = [];
|
|
216
|
+
const skipped = [...scan.skipped];
|
|
217
|
+
for (const s of scan.skipped)
|
|
218
|
+
log(`picture ${s.name} not attached: ${s.why}`);
|
|
219
|
+
const retry = (label, fn) => withNetworkRetry(fn, {
|
|
220
|
+
label,
|
|
221
|
+
maxWaitMs: opts.maxWaitMs ?? 2 * 60_000,
|
|
222
|
+
probe: () => api.probe(),
|
|
223
|
+
log,
|
|
224
|
+
});
|
|
225
|
+
for (const f of scan.files) {
|
|
226
|
+
const skip = (why) => {
|
|
227
|
+
skipped.push({ name: f.name, why });
|
|
228
|
+
log(`picture ${f.name} not attached: ${why}`);
|
|
229
|
+
};
|
|
230
|
+
try {
|
|
231
|
+
const bytes = readFileSync(f.path);
|
|
232
|
+
if (bytes.byteLength !== f.size) {
|
|
233
|
+
skip('it changed while it was being read');
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
237
|
+
const offered = await retry(`offer of ${f.name}`, () => api.offerAttachment(runId, {
|
|
238
|
+
name: f.name,
|
|
239
|
+
size: f.size,
|
|
240
|
+
sha256,
|
|
241
|
+
contentType: f.contentType,
|
|
242
|
+
}));
|
|
243
|
+
if ('refused' in offered) {
|
|
244
|
+
skip(`${offered.refused.reason} Fix: ${offered.refused.fix}`);
|
|
245
|
+
if (offered.refused.status === 404 || offered.refused.status === 503)
|
|
246
|
+
break;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const put = await retry(`upload of ${f.name}`, () => fetcher(offered.upload.url, {
|
|
250
|
+
method: 'PUT',
|
|
251
|
+
headers: offered.upload.headers,
|
|
252
|
+
body: bytes,
|
|
253
|
+
}));
|
|
254
|
+
if (!put.ok) {
|
|
255
|
+
skip(`the upload answered ${put.status}`);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
const done = await retry(`check of ${f.name}`, () => api.completeAttachment(runId, offered.id));
|
|
259
|
+
if ('refused' in done) {
|
|
260
|
+
skip(`${done.refused.reason} Fix: ${done.refused.fix}`);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
attached.push(f.name);
|
|
264
|
+
}
|
|
265
|
+
catch (e) {
|
|
266
|
+
skip(isNetworkError(e)
|
|
267
|
+
? 'FireFunc could not be reached'
|
|
268
|
+
: `it could not be uploaded (${e.name})`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (attached.length) {
|
|
272
|
+
log(`uploaded ${attached.length} picture(s) for the ticket: ${attached.join(', ')}`);
|
|
273
|
+
}
|
|
274
|
+
return { attached, skipped };
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=run-attachments.js.map
|
package/dist/secret-scan.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type SecretKind = 'aws_access_key_id' | 'aws_secret_access_key' | 'github_token' | 'slack_token' | 'google_api_key' | 'stripe_secret_key' | 'private_key_block' | 'jwt' | 'generic_assignment';
|
|
1
|
+
export type SecretKind = 'aws_access_key_id' | 'aws_secret_access_key' | 'github_token' | 'slack_token' | 'google_api_key' | 'stripe_secret_key' | 'private_key_block' | 'jwt' | 'generic_assignment' | 'agent_secret';
|
|
2
2
|
export type SecretHit = {
|
|
3
3
|
path: string;
|
|
4
4
|
kind: SecretKind;
|
package/dist/secret-scan.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { devNull } from 'node:os';
|
|
2
|
+
import { heldSecretValues } from './secret-values.js';
|
|
2
3
|
export const SOFT_KINDS = new Set(['generic_assignment']);
|
|
3
4
|
export function refusesPush(hit) {
|
|
4
5
|
return !SOFT_KINDS.has(hit.kind);
|
|
@@ -36,6 +37,8 @@ export function secretKindsIn(line) {
|
|
|
36
37
|
break;
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
if (heldSecretValues().some((s) => line.includes(s.value)))
|
|
41
|
+
found.push('agent_secret');
|
|
39
42
|
return found;
|
|
40
43
|
}
|
|
41
44
|
function pathOf(header) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function registerSecretValues(runId: string, secrets: ReadonlyArray<{
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}>): void;
|
|
5
|
+
export declare function releaseSecretValues(runId: string): void;
|
|
6
|
+
export declare function heldSecretCount(): number;
|
|
7
|
+
export declare function blankSecrets(text: string): string;
|
|
8
|
+
export declare function blankSecretsDeep<T>(value: T): T;
|
|
9
|
+
export declare function heldSecretValues(): ReadonlyArray<{
|
|
10
|
+
name: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare function blankingApi<T extends {
|
|
14
|
+
event(runId: string, event: never, detail?: Record<string, unknown>): Promise<void>;
|
|
15
|
+
activity(runId: string, steps: never): Promise<void>;
|
|
16
|
+
result(runId: string, payload: never): Promise<void>;
|
|
17
|
+
}>(api: T): T;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const MIN_LENGTH = 8;
|
|
2
|
+
const byRun = new Map();
|
|
3
|
+
let held = [];
|
|
4
|
+
function rebuild() {
|
|
5
|
+
const all = [...byRun.values()].flat();
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
held = all
|
|
8
|
+
.filter((s) => s.value.length >= MIN_LENGTH && !seen.has(s.value) && seen.add(s.value))
|
|
9
|
+
.sort((a, b) => b.value.length - a.value.length);
|
|
10
|
+
}
|
|
11
|
+
export function registerSecretValues(runId, secrets) {
|
|
12
|
+
const kept = secrets.filter((s) => typeof s.value === 'string' && s.value.length >= MIN_LENGTH);
|
|
13
|
+
if (kept.length === 0)
|
|
14
|
+
return;
|
|
15
|
+
byRun.set(runId, [...(byRun.get(runId) ?? []), ...kept]);
|
|
16
|
+
rebuild();
|
|
17
|
+
}
|
|
18
|
+
export function releaseSecretValues(runId) {
|
|
19
|
+
if (byRun.delete(runId))
|
|
20
|
+
rebuild();
|
|
21
|
+
}
|
|
22
|
+
export function heldSecretCount() {
|
|
23
|
+
return held.length;
|
|
24
|
+
}
|
|
25
|
+
function formsOf(value) {
|
|
26
|
+
const forms = new Set([value]);
|
|
27
|
+
const json = JSON.stringify(value).slice(1, -1);
|
|
28
|
+
if (json !== value)
|
|
29
|
+
forms.add(json);
|
|
30
|
+
try {
|
|
31
|
+
const enc = encodeURIComponent(value);
|
|
32
|
+
if (enc !== value)
|
|
33
|
+
forms.add(enc);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
}
|
|
37
|
+
return [...forms];
|
|
38
|
+
}
|
|
39
|
+
export function blankSecrets(text) {
|
|
40
|
+
if (held.length === 0 || !text)
|
|
41
|
+
return text;
|
|
42
|
+
let out = text;
|
|
43
|
+
for (const s of held) {
|
|
44
|
+
for (const form of formsOf(s.value)) {
|
|
45
|
+
if (out.includes(form))
|
|
46
|
+
out = out.split(form).join(`[secret ${s.name}]`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
export function blankSecretsDeep(value) {
|
|
52
|
+
if (held.length === 0)
|
|
53
|
+
return value;
|
|
54
|
+
const walk = (v, depth) => {
|
|
55
|
+
if (typeof v === 'string')
|
|
56
|
+
return blankSecrets(v);
|
|
57
|
+
if (depth > 12 || v === null || typeof v !== 'object')
|
|
58
|
+
return v;
|
|
59
|
+
if (Array.isArray(v))
|
|
60
|
+
return v.map((x) => walk(x, depth + 1));
|
|
61
|
+
const out = {};
|
|
62
|
+
for (const [k, x] of Object.entries(v))
|
|
63
|
+
out[k] = walk(x, depth + 1);
|
|
64
|
+
return out;
|
|
65
|
+
};
|
|
66
|
+
return walk(value, 0);
|
|
67
|
+
}
|
|
68
|
+
export function heldSecretValues() {
|
|
69
|
+
return held;
|
|
70
|
+
}
|
|
71
|
+
export function blankingApi(api) {
|
|
72
|
+
const wrapped = Object.create(api);
|
|
73
|
+
const loose = api;
|
|
74
|
+
Object.assign(wrapped, {
|
|
75
|
+
event: (runId, event, detail) => loose.event.call(api, runId, event, blankSecretsDeep(detail)),
|
|
76
|
+
activity: (runId, steps) => loose.activity.call(api, runId, blankSecretsDeep(steps)),
|
|
77
|
+
result: (runId, payload) => loose.result.call(api, runId, blankSecretsDeep(payload)),
|
|
78
|
+
});
|
|
79
|
+
return wrapped;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=secret-values.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type KeyObject } from 'node:crypto';
|
|
2
|
+
export declare const TRAIL_SCHEMA_VERSION = 1;
|
|
3
|
+
export declare function canonicalJson(value: unknown): string;
|
|
4
|
+
export declare function sha256Hex(text: string | Uint8Array): string;
|
|
5
|
+
export declare function genesisHash(runId: string, source: 'machine' | 'firefunc'): string;
|
|
6
|
+
export declare function eventHashOf(ev: Record<string, unknown>): string;
|
|
7
|
+
export declare function merkleRoot(hashes: readonly string[]): string;
|
|
8
|
+
export declare function keyIdOf(publicKeyB64: string): string;
|
|
9
|
+
export declare function signText(privateKey: KeyObject, text: string): string;
|
|
10
|
+
export declare function digestText(d: Record<string, unknown>): string;
|
|
11
|
+
export declare function hmacHex(key: Buffer, bytes: Uint8Array | string): string;
|
|
12
|
+
export declare function ulid(nowMs: number, random?: Uint8Array): string;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createHash, createHmac, randomBytes, sign as edSign } from 'node:crypto';
|
|
2
|
+
export const TRAIL_SCHEMA_VERSION = 1;
|
|
3
|
+
const RECEIPT_FIELDS = new Set([
|
|
4
|
+
'event_hash',
|
|
5
|
+
'sig',
|
|
6
|
+
'key_id',
|
|
7
|
+
'received_at',
|
|
8
|
+
'clock_skew_ms',
|
|
9
|
+
'late',
|
|
10
|
+
'workspace_id',
|
|
11
|
+
'organization_id',
|
|
12
|
+
'project_id',
|
|
13
|
+
'altered_at_receipt',
|
|
14
|
+
]);
|
|
15
|
+
export function canonicalJson(value) {
|
|
16
|
+
if (value === null || typeof value !== 'object') {
|
|
17
|
+
if (typeof value === 'number' && !Number.isFinite(value))
|
|
18
|
+
return 'null';
|
|
19
|
+
return JSON.stringify(value) ?? 'null';
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
return `[${value.map((v) => (v === undefined ? 'null' : canonicalJson(v))).join(',')}]`;
|
|
23
|
+
}
|
|
24
|
+
const obj = value;
|
|
25
|
+
const keys = Object.keys(obj)
|
|
26
|
+
.filter((k) => obj[k] !== undefined)
|
|
27
|
+
.sort();
|
|
28
|
+
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`).join(',')}}`;
|
|
29
|
+
}
|
|
30
|
+
export function sha256Hex(text) {
|
|
31
|
+
return createHash('sha256').update(text).digest('hex');
|
|
32
|
+
}
|
|
33
|
+
export function genesisHash(runId, source) {
|
|
34
|
+
return sha256Hex(`firefunc-trail-v${TRAIL_SCHEMA_VERSION}:${runId}:${source}`);
|
|
35
|
+
}
|
|
36
|
+
export function eventHashOf(ev) {
|
|
37
|
+
const part = {};
|
|
38
|
+
for (const [k, v] of Object.entries(ev))
|
|
39
|
+
if (!RECEIPT_FIELDS.has(k) && v !== undefined)
|
|
40
|
+
part[k] = v;
|
|
41
|
+
return sha256Hex(`${String(part.prev_hash)}\n${canonicalJson(part)}`);
|
|
42
|
+
}
|
|
43
|
+
export function merkleRoot(hashes) {
|
|
44
|
+
if (hashes.length === 0)
|
|
45
|
+
return sha256Hex('');
|
|
46
|
+
let level = [...hashes];
|
|
47
|
+
while (level.length > 1) {
|
|
48
|
+
const next = [];
|
|
49
|
+
for (let i = 0; i < level.length; i += 2)
|
|
50
|
+
next.push(sha256Hex(level[i] + (level[i + 1] ?? level[i])));
|
|
51
|
+
level = next;
|
|
52
|
+
}
|
|
53
|
+
return level[0];
|
|
54
|
+
}
|
|
55
|
+
export function keyIdOf(publicKeyB64) {
|
|
56
|
+
return sha256Hex(Buffer.from(publicKeyB64, 'base64')).slice(0, 32);
|
|
57
|
+
}
|
|
58
|
+
export function signText(privateKey, text) {
|
|
59
|
+
return edSign(null, Buffer.from(text), privateKey).toString('base64');
|
|
60
|
+
}
|
|
61
|
+
export function digestText(d) {
|
|
62
|
+
const { sig: _s, key_id: _k, ...rest } = d;
|
|
63
|
+
return canonicalJson(rest);
|
|
64
|
+
}
|
|
65
|
+
export function hmacHex(key, bytes) {
|
|
66
|
+
return createHmac('sha256', key).update(bytes).digest('hex');
|
|
67
|
+
}
|
|
68
|
+
const CROCKFORD = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
69
|
+
export function ulid(nowMs, random = randomBytes(10)) {
|
|
70
|
+
let t = Math.max(0, Math.floor(nowMs));
|
|
71
|
+
let time = '';
|
|
72
|
+
for (let i = 0; i < 10; i++) {
|
|
73
|
+
time = CROCKFORD[t % 32] + time;
|
|
74
|
+
t = Math.floor(t / 32);
|
|
75
|
+
}
|
|
76
|
+
let bits = 0;
|
|
77
|
+
let acc = 0;
|
|
78
|
+
let rand = '';
|
|
79
|
+
for (let i = 0; i < 10 && rand.length < 16; i++) {
|
|
80
|
+
acc = (acc << 8) | (random[i] ?? 0);
|
|
81
|
+
bits += 8;
|
|
82
|
+
while (bits >= 5 && rand.length < 16) {
|
|
83
|
+
rand += CROCKFORD[(acc >> (bits - 5)) & 31];
|
|
84
|
+
bits -= 5;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return time + rand.padEnd(16, '0');
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ExecResult } from '../exec.js';
|
|
2
|
+
export type GitRun = (args: string[], opts: {
|
|
3
|
+
cwd: string;
|
|
4
|
+
input?: string;
|
|
5
|
+
}) => Promise<ExecResult>;
|
|
6
|
+
export type FileDelta = {
|
|
7
|
+
path: string;
|
|
8
|
+
created: boolean;
|
|
9
|
+
deleted: boolean;
|
|
10
|
+
isBinary: boolean;
|
|
11
|
+
linesAdded: number;
|
|
12
|
+
linesRemoved: number;
|
|
13
|
+
hunks: number;
|
|
14
|
+
hunkRanges: Array<[number, number, number, number]>;
|
|
15
|
+
hashBefore?: string;
|
|
16
|
+
hashAfter?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function countDiff(diff: string): Pick<FileDelta, 'isBinary' | 'linesAdded' | 'linesRemoved' | 'hunks' | 'hunkRanges'>;
|
|
19
|
+
export declare function statusPaths(out: string): string[];
|
|
20
|
+
export declare function createDeltaTracker(opts: {
|
|
21
|
+
worktree: () => string | null;
|
|
22
|
+
contentKey: Buffer;
|
|
23
|
+
forensic: boolean;
|
|
24
|
+
git?: GitRun;
|
|
25
|
+
maxFiles?: number;
|
|
26
|
+
}): {
|
|
27
|
+
prime: () => Promise<boolean>;
|
|
28
|
+
snapshot: () => Promise<{
|
|
29
|
+
deltas: FileDelta[];
|
|
30
|
+
truncated: number;
|
|
31
|
+
} | null>;
|
|
32
|
+
head: () => Promise<string | null>;
|
|
33
|
+
readonly usable: boolean | null;
|
|
34
|
+
};
|