apps/agent (docs/AGENT-1.0-PLAN.md §3-4, §10): listens on nothing; checks every job (pinned Hub key, server, time window, replays for 90 days, type per mode, strict arguments) before running crosscode with an argument array; opens the sealed config into a root-only file only for the job; redacts log lines; keeps unsent reports in an outbox; encrypts exports before upload; check-ports on the central server (read-only); self-update with automatic revert. One bundled dist/cli.js, a systemd unit and the install script that joins a server with a one-time token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
/**
|
|
* Log lines are filtered for anything that looks like a secret before they leave the server
|
|
* (AGENT-1.0-PLAN §4, rule 7). The crosscode script never prints .env values, but tools it runs
|
|
* (npm, Prisma, git) might print a URL with a password or a token in an error.
|
|
*/
|
|
|
|
const RULES: [RegExp, string][] = [
|
|
// user:password@ in any URL (postgresql://, https://).
|
|
[/([a-z][a-z0-9+.-]*:\/\/[^\s:/@]+:)[^\s@/]+@/gi, "$1***@"],
|
|
// KEY=value and KEY: value for keys that hold secrets.
|
|
[/\b([A-Z0-9_]*(SECRET|PASSWORD|PASSWD|TOKEN|API_KEY|PRIVATE_KEY|DSN|LICENCE_KEY|LICENSE_KEY)[A-Z0-9_]*)(\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)/g, "$1$3***"],
|
|
// Authorization headers and bearer tokens.
|
|
[/\b(authorization\s*:\s*)(bearer|basic)\s+\S+/gi, "$1$2 ***"],
|
|
[/\bbearer\s+[A-Za-z0-9._~+/=-]{16,}/gi, "Bearer ***"],
|
|
// PEM blocks.
|
|
[/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g, "[private key]"],
|
|
// Cross Code licence keys (CEH-7K2M-…).
|
|
[/\b(CEH|CCA|CCW|CCP)-[A-Z0-9]{4}(-[A-Z0-9]{4}){3}\b/g, "$1-****"],
|
|
// Long random-looking strings (hex or base64 of 32+ characters): likely keys or tokens.
|
|
[/\b[A-Fa-f0-9]{40,}\b/g, "***"],
|
|
[/\b[A-Za-z0-9+/_-]{48,}={0,2}/g, "***"],
|
|
];
|
|
|
|
export function redact(line: string): string {
|
|
let out = line;
|
|
for (const [re, to] of RULES) out = out.replace(re, to);
|
|
return out.length > 1000 ? `${out.slice(0, 997)}...` : out;
|
|
}
|
|
|
|
/** Keeps the last `max` lines of output, redacted, without holding all of it in memory. */
|
|
export class LogTail {
|
|
private lines: string[] = [];
|
|
private partial = "";
|
|
constructor(private max = 200) {}
|
|
push(chunk: string): void {
|
|
const parts = (this.partial + chunk).split(/\r?\n/);
|
|
this.partial = parts.pop() ?? "";
|
|
for (const p of parts) this.add(p);
|
|
}
|
|
private add(line: string): void {
|
|
this.lines.push(redact(line));
|
|
if (this.lines.length > this.max) this.lines.shift();
|
|
}
|
|
end(): string[] {
|
|
if (this.partial) {
|
|
this.add(this.partial);
|
|
this.partial = "";
|
|
}
|
|
return [...this.lines];
|
|
}
|
|
}
|