agents-relay 1.0.75 → 1.0.76
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/feedback.js +234 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,6 +135,8 @@ events, durable-thread reuse, resume, or retry behavior.
|
|
|
135
135
|
|
|
136
136
|
Open the dashboard on localhost port 8787. The marker format is intentionally public and append-friendly; the CLI uses GitHubStore with the authenticated gh client in operational mode.
|
|
137
137
|
|
|
138
|
+
External product feedback uses the reusable `src/feedback.ts` contract. See [docs/feedback-intake.md](docs/feedback-intake.md) for the schema, attachment limits, privacy rules, materialization path, and provenance envelope for later Jobs/Tasks/PRs.
|
|
139
|
+
|
|
138
140
|
reconcile leases and launches ready tasks without waiting inside the runtime scheduler; the CLI waits only long enough for its launched workers to persist results. agents-relayd (or the equivalent npx agents-relay serve) is the watchdog/dashboard mode. Model-backed workers require --events nats; the event transport carries authoritative terminal worker events as well as wake/progress traffic. See [docs/service.md](docs/service.md). --file PATH is explicit local demo/test mode only.
|
|
139
141
|
|
|
140
142
|
`agents-relayd` without `--pr`/`--id` runs in workspace mode by default: it discovers nested Git repositories under `~/Workspace`, keeps only GitHub `origin` remotes, and aggregates their managed PR jobs into one dashboard and worker pool. Pass `--workspace PATH` to use another root. `--repo OWNER/REPO` remains the single-repository pool mode.
|
package/dist/feedback.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
|
+
export const FEEDBACK_MARKER = 'agents-relay:feedback:v1';
|
|
5
|
+
export const FEEDBACK_SCHEMA = 'agents-relay.feedback';
|
|
6
|
+
export const FEEDBACK_SCHEMA_VERSION = 1;
|
|
7
|
+
export const FEEDBACK_MAX_TEXT_LENGTH = 20_000;
|
|
8
|
+
export const FEEDBACK_MAX_ATTACHMENTS = 10;
|
|
9
|
+
export const FEEDBACK_MAX_ATTACHMENT_BYTES = 10 * 1024 * 1024;
|
|
10
|
+
export const FEEDBACK_IMAGE_TYPES = ['image/gif', 'image/jpeg', 'image/png', 'image/webp'];
|
|
11
|
+
export const DEFAULT_FEEDBACK_LIMITS = {
|
|
12
|
+
maxTextLength: 20_000,
|
|
13
|
+
maxAttachments: 5,
|
|
14
|
+
maxAttachmentBytes: 10 * 1024 * 1024,
|
|
15
|
+
allowedMediaTypes: ['image/png', 'image/jpeg', 'image/webp', 'image/gif'],
|
|
16
|
+
};
|
|
17
|
+
function effectiveLimits(limits = {}) {
|
|
18
|
+
return {
|
|
19
|
+
maxTextLength: limits.maxTextLength ?? DEFAULT_FEEDBACK_LIMITS.maxTextLength,
|
|
20
|
+
maxAttachments: limits.maxAttachments ?? DEFAULT_FEEDBACK_LIMITS.maxAttachments,
|
|
21
|
+
maxAttachmentBytes: limits.maxAttachmentBytes ?? DEFAULT_FEEDBACK_LIMITS.maxAttachmentBytes,
|
|
22
|
+
allowedMediaTypes: limits.allowedMediaTypes ?? DEFAULT_FEEDBACK_LIMITS.allowedMediaTypes,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function fail(message) { throw new Error(`Invalid feedback: ${message}`); }
|
|
26
|
+
function safeId(id) {
|
|
27
|
+
if (!/^[a-f0-9-]{36}$/i.test(id))
|
|
28
|
+
fail('feedback id is invalid');
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
function cleanFilename(filename) {
|
|
32
|
+
const cleaned = basename(filename).replace(/[^a-zA-Z0-9._-]/g, '_').slice(0, 120);
|
|
33
|
+
if (!cleaned || cleaned === '.' || cleaned === '..')
|
|
34
|
+
fail('attachment filename is invalid');
|
|
35
|
+
return cleaned;
|
|
36
|
+
}
|
|
37
|
+
function cleanOptional(value, field) {
|
|
38
|
+
if (value === undefined)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (value.length > 500)
|
|
41
|
+
fail(`${field} is too long`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function validateProvenance(input) {
|
|
45
|
+
if (!input.product.trim())
|
|
46
|
+
fail('provenance.product is required');
|
|
47
|
+
if (!input.submittedAt || Number.isNaN(Date.parse(input.submittedAt)))
|
|
48
|
+
fail('provenance.submittedAt must be an ISO timestamp');
|
|
49
|
+
if (input.contact && !input.contact.value.trim())
|
|
50
|
+
fail('contact value must not be empty');
|
|
51
|
+
// Only the explicitly documented fields are copied. Upload/browser/provider metadata is never persisted.
|
|
52
|
+
return {
|
|
53
|
+
source: input.source,
|
|
54
|
+
product: input.product.trim().slice(0, 200),
|
|
55
|
+
surface: cleanOptional(input.surface, 'surface'),
|
|
56
|
+
setupStep: cleanOptional(input.setupStep, 'setupStep'),
|
|
57
|
+
actorClass: input.actorClass,
|
|
58
|
+
version: cleanOptional(input.version, 'version'),
|
|
59
|
+
build: cleanOptional(input.build, 'build'),
|
|
60
|
+
submittedAt: new Date(input.submittedAt).toISOString(),
|
|
61
|
+
...(input.contact ? { contact: { channel: input.contact.channel, value: input.contact.value.trim().slice(0, 500) } } : {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function marker(label, value) {
|
|
65
|
+
return `<!-- ${label} ${JSON.stringify(value).replace(/>/g, '\\u003e')} -->`;
|
|
66
|
+
}
|
|
67
|
+
export function renderFeedbackMarker(record) {
|
|
68
|
+
const { userContent: _userContent, ...metadata } = record;
|
|
69
|
+
return marker(FEEDBACK_MARKER, metadata);
|
|
70
|
+
}
|
|
71
|
+
export function parseFeedbackMarker(value) {
|
|
72
|
+
const match = value.match(/<!--\s*agents-relay:feedback:v1\s+([\s\S]*?)\s*-->/);
|
|
73
|
+
if (!match)
|
|
74
|
+
return null;
|
|
75
|
+
try {
|
|
76
|
+
const parsed = JSON.parse(match[1]);
|
|
77
|
+
return parsed.schema === FEEDBACK_MARKER && parsed.schemaVersion === FEEDBACK_SCHEMA_VERSION ? parsed : null;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export class FileFeedbackStore {
|
|
84
|
+
root;
|
|
85
|
+
limits;
|
|
86
|
+
constructor(root, limits = {}) {
|
|
87
|
+
this.root = resolve(root);
|
|
88
|
+
this.limits = effectiveLimits(limits);
|
|
89
|
+
}
|
|
90
|
+
async submit(submission) {
|
|
91
|
+
const existing = submission.idempotencyKey ? await this.findByIdempotencyKey(submission.idempotencyKey) : null;
|
|
92
|
+
if (existing)
|
|
93
|
+
return { record: existing, recordRef: this.recordPath(existing.id) };
|
|
94
|
+
const text = submission.text.trim();
|
|
95
|
+
if (!text)
|
|
96
|
+
fail('text is required');
|
|
97
|
+
if (text.length > this.limits.maxTextLength)
|
|
98
|
+
fail(`text exceeds ${this.limits.maxTextLength} characters`);
|
|
99
|
+
const inputs = submission.attachments ?? [];
|
|
100
|
+
if (inputs.length > this.limits.maxAttachments)
|
|
101
|
+
fail(`at most ${this.limits.maxAttachments} attachments are allowed`);
|
|
102
|
+
const now = new Date().toISOString();
|
|
103
|
+
const id = randomUUID();
|
|
104
|
+
const attachmentDir = join(this.root, 'attachments', id);
|
|
105
|
+
const attachments = [];
|
|
106
|
+
await mkdir(attachmentDir, { recursive: true });
|
|
107
|
+
try {
|
|
108
|
+
for (const input of inputs) {
|
|
109
|
+
if (!this.limits.allowedMediaTypes.includes(input.mediaType.toLowerCase()))
|
|
110
|
+
fail(`unsupported attachment type: ${input.mediaType}`);
|
|
111
|
+
if (input.data.byteLength === 0 || input.data.byteLength > this.limits.maxAttachmentBytes)
|
|
112
|
+
fail(`attachment exceeds ${this.limits.maxAttachmentBytes} bytes`);
|
|
113
|
+
const attachmentId = randomUUID();
|
|
114
|
+
const filename = cleanFilename(input.filename);
|
|
115
|
+
const relative = join('attachments', id, `${attachmentId}-${filename}`);
|
|
116
|
+
await writeFile(join(this.root, relative), input.data, { flag: 'wx' });
|
|
117
|
+
attachments.push({ id: attachmentId, filename, mediaType: input.mediaType.toLowerCase(), sizeBytes: input.data.byteLength, sha256: createHash('sha256').update(input.data).digest('hex'), storageRef: relative, uploadedAt: now });
|
|
118
|
+
}
|
|
119
|
+
const record = {
|
|
120
|
+
schema: FEEDBACK_MARKER, schemaVersion: FEEDBACK_SCHEMA_VERSION, id,
|
|
121
|
+
...(submission.idempotencyKey ? { idempotencyKey: submission.idempotencyKey } : {}),
|
|
122
|
+
userContent: { text }, attachments, systemProvenance: validateProvenance(submission.provenance),
|
|
123
|
+
triage: { status: 'new', updatedAt: now }, downstream: [], createdAt: now,
|
|
124
|
+
};
|
|
125
|
+
await mkdir(join(this.root, 'records'), { recursive: true });
|
|
126
|
+
const recordRef = this.recordPath(id);
|
|
127
|
+
const temp = `${recordRef}.${randomUUID()}.tmp`;
|
|
128
|
+
await writeFile(temp, `${JSON.stringify(record, null, 2)}\n`, { encoding: 'utf8', flag: 'wx' });
|
|
129
|
+
await rename(temp, recordRef);
|
|
130
|
+
return { record, recordRef };
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
await this.removeAttachmentDirectory(attachmentDir);
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async read(id) {
|
|
138
|
+
const parsed = JSON.parse(await readFile(this.recordPath(safeId(id)), 'utf8'));
|
|
139
|
+
if (parsed.schema !== FEEDBACK_MARKER || parsed.schemaVersion !== FEEDBACK_SCHEMA_VERSION)
|
|
140
|
+
fail('record schema is unsupported');
|
|
141
|
+
return parsed;
|
|
142
|
+
}
|
|
143
|
+
recordPath(id) { return join(this.root, 'records', `${id}.json`); }
|
|
144
|
+
async findByIdempotencyKey(key) {
|
|
145
|
+
const directory = join(this.root, 'records');
|
|
146
|
+
let entries;
|
|
147
|
+
try {
|
|
148
|
+
entries = await readdir(directory);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
for (const entry of entries.filter(item => item.endsWith('.json'))) {
|
|
154
|
+
const record = JSON.parse(await readFile(join(directory, entry), 'utf8'));
|
|
155
|
+
if (record.idempotencyKey === key)
|
|
156
|
+
return record;
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
async removeAttachmentDirectory(path) {
|
|
161
|
+
try {
|
|
162
|
+
await rm(path, { recursive: true, force: true });
|
|
163
|
+
}
|
|
164
|
+
catch { /* best-effort cleanup; the record was not materialized */ }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export async function materializeFeedbackRecord(root, submission, limits) {
|
|
168
|
+
return new FileFeedbackStore(root, limits).submit(submission);
|
|
169
|
+
}
|
|
170
|
+
/** Redacts common bearer/API-key shapes before a product stores user text. */
|
|
171
|
+
export function redactSensitiveText(text) {
|
|
172
|
+
return text
|
|
173
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, 'Bearer [REDACTED]')
|
|
174
|
+
.replace(/\b(?:sk|pk)_[A-Za-z0-9_-]{12,}\b/g, '[REDACTED_KEY]')
|
|
175
|
+
.replace(/\b(?:api[_-]?key|token|secret)\s*[:=]\s*[^\s,;]+/gi, '$1=[REDACTED]');
|
|
176
|
+
}
|
|
177
|
+
export function createFeedbackRecord(submission, options = {}) {
|
|
178
|
+
if (typeof submission.text !== 'string' || submission.text.length === 0 || submission.text.length > FEEDBACK_MAX_TEXT_LENGTH)
|
|
179
|
+
fail(`text must contain 1-${FEEDBACK_MAX_TEXT_LENGTH} characters`);
|
|
180
|
+
const attachments = (submission.attachments ?? []).map((input, index) => {
|
|
181
|
+
if (!FEEDBACK_IMAGE_TYPES.includes(input.mimeType))
|
|
182
|
+
fail(`attachments[${index}] has an unsupported image format`);
|
|
183
|
+
if (!Number.isSafeInteger(input.sizeBytes) || input.sizeBytes <= 0 || input.sizeBytes > FEEDBACK_MAX_ATTACHMENT_BYTES)
|
|
184
|
+
fail(`attachments[${index}] exceeds the ${FEEDBACK_MAX_ATTACHMENT_BYTES} byte limit`);
|
|
185
|
+
if (!input.reference || input.reference.length > 2_000 || /[?#]/.test(input.reference) || /:\/\/[^/]*:[^@]+@/.test(input.reference))
|
|
186
|
+
fail('attachment reference must be a stable, credential-free reference');
|
|
187
|
+
return { ...input, id: `attachment-${index + 1}` };
|
|
188
|
+
});
|
|
189
|
+
if (attachments.length > FEEDBACK_MAX_ATTACHMENTS)
|
|
190
|
+
fail(`at most ${FEEDBACK_MAX_ATTACHMENTS} attachments are supported`);
|
|
191
|
+
const visibility = submission.visibility ?? 'private';
|
|
192
|
+
const sanitized = options.sanitize === true || submission.sanitized === true;
|
|
193
|
+
if (visibility === 'public' && !sanitized)
|
|
194
|
+
fail('public feedback must be explicitly sanitized');
|
|
195
|
+
const provenance = validateProvenance(submission.provenance);
|
|
196
|
+
return {
|
|
197
|
+
schema: FEEDBACK_SCHEMA, schemaVersion: FEEDBACK_SCHEMA_VERSION, id: options.id ?? `feedback-${randomUUID()}`,
|
|
198
|
+
userContent: { text: sanitized ? redactSensitiveText(submission.text) : submission.text }, attachments, provenance,
|
|
199
|
+
systemMetadata: { receivedAt: options.receivedAt ?? new Date().toISOString(), visibility, sanitized },
|
|
200
|
+
...(submission.contact ? { contact: submission.contact } : {}), triage: { status: 'new' }, downstream: { work: [] },
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
export function feedbackWorkProvenance(record) {
|
|
204
|
+
return { feedbackId: record.id, feedbackSchema: `${record.schema}/v${record.schemaVersion}`, feedbackReference: `feedback://${record.id}`, feedbackSubmittedAt: record.provenance.submittedAt };
|
|
205
|
+
}
|
|
206
|
+
export function feedbackFingerprint(record) {
|
|
207
|
+
return createHash('sha256').update(JSON.stringify({ text: record.userContent.text, attachments: record.attachments.map(item => item.sha256 ?? item.reference), provenance: record.provenance })).digest('hex');
|
|
208
|
+
}
|
|
209
|
+
export function renderFeedbackMarkdown(record) {
|
|
210
|
+
const markerBody = { schema: record.schema, schemaVersion: record.schemaVersion, id: record.id, provenance: record.provenance, attachmentIds: record.attachments.map(item => item.id), triage: record.triage, downstream: record.downstream };
|
|
211
|
+
const attachments = record.attachments.length === 0 ? '_None._' : record.attachments.map(item => `- ${item.id}: ${item.mimeType}, ${item.sizeBytes} bytes, ref \`${item.reference}\``).join('\n');
|
|
212
|
+
return `${marker(FEEDBACK_MARKER, markerBody)}\n# Feedback ${record.id}\n\n## User report\n\n${record.userContent.text}\n\n## Attachments\n\n${attachments}\n`;
|
|
213
|
+
}
|
|
214
|
+
export async function materializeFeedback(first, second, third) {
|
|
215
|
+
if (typeof first === 'string')
|
|
216
|
+
return materializeFeedbackRecord(first, second, third);
|
|
217
|
+
const path = second;
|
|
218
|
+
const format = third ?? 'json';
|
|
219
|
+
if (!path || path.includes('\0'))
|
|
220
|
+
throw new Error('Feedback materialization path is invalid');
|
|
221
|
+
await mkdir(resolve(path, '..'), { recursive: true });
|
|
222
|
+
const body = format === 'markdown' ? renderFeedbackMarkdown(first) : `${JSON.stringify(first, null, 2)}\n`;
|
|
223
|
+
await writeFile(path, body, { encoding: 'utf8', mode: 0o600 });
|
|
224
|
+
}
|
|
225
|
+
export async function readFeedbackAttachment(root, attachment) {
|
|
226
|
+
const path = resolve(root, attachment.storageRef);
|
|
227
|
+
const rootPath = resolve(root);
|
|
228
|
+
if (!path.startsWith(`${rootPath}/`))
|
|
229
|
+
fail('attachment reference escapes storage root');
|
|
230
|
+
const bytes = await readFile(path);
|
|
231
|
+
if (bytes.byteLength !== attachment.sizeBytes || createHash('sha256').update(bytes).digest('hex') !== attachment.sha256)
|
|
232
|
+
fail('attachment integrity check failed');
|
|
233
|
+
return bytes;
|
|
234
|
+
}
|