lemma-agent 1.0.1 → 1.1.0
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 +29 -0
- package/dist/admin.js +15 -1
- package/dist/api-member.js +18 -5
- package/dist/app.js +44 -6
- package/dist/config.js +117 -0
- package/dist/credentials.js +11 -0
- package/dist/dispatch.js +37 -23
- package/dist/main.js +34 -1
- package/dist/proxy.js +858 -0
- package/dist/redact.js +179 -0
- package/dist/tools.js +2 -2
- package/package.json +3 -2
package/dist/redact.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
const PLACEHOLDER_PREFIX = "{{LEMMA_SECRET_";
|
|
3
|
+
const PLACEHOLDER_RE = /\{\{LEMMA_SECRET_[A-Z0-9_]+_[a-f0-9]{8}\}\}/g;
|
|
4
|
+
const MAX_PLACEHOLDER_TAIL = 80;
|
|
5
|
+
const DUMMY_VALUE_RE = /^(?:your[-_]|xxx+|example|changeme|placeholder|dummy|test[-_]key|<[^>]+>|\$\{[^}]+\})/i;
|
|
6
|
+
const BUILTIN_RULES = [
|
|
7
|
+
{ kind: "PRIVATE_KEY", regex: /-----BEGIN [A-Z0-9 ]+PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]+PRIVATE KEY-----/g },
|
|
8
|
+
{ kind: "ANTHROPIC_KEY", regex: /\bsk-ant-[A-Za-z0-9_-]{20,}\b/g },
|
|
9
|
+
{ kind: "OPENAI_KEY", regex: /\bsk-(?:proj-|svcacct-)?[A-Za-z0-9_-]{20,}\b/g },
|
|
10
|
+
{ kind: "GEMINI_KEY", regex: /\bAIza[0-9A-Za-z_-]{35,}\b/g },
|
|
11
|
+
{ kind: "GITHUB_TOKEN", regex: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{30,}\b|\bgithub_pat_[A-Za-z0-9_]{22,}\b/g },
|
|
12
|
+
{ kind: "AWS_KEY", regex: /\bAKIA[0-9A-Z]{16}\b/g },
|
|
13
|
+
{ kind: "URI_SECRET", regex: /((?:postgres(?:ql)?|mysql|mongodb(?:\+srv)?|redis|amqp):\/\/[^:\s/@"']+:)(?!\{\{LEMMA_SECRET_)([^@\s/"']{4,})(@)/g, group: 2 },
|
|
14
|
+
{
|
|
15
|
+
kind: "ENV_SECRET",
|
|
16
|
+
regex: /((?:^|[\r\n])[ \t]*(?:export[ \t]+)?[A-Z0-9_]*(?:API_KEY|SECRET|PASSWORD|PASSWD|PRIVATE_KEY|ACCESS_TOKEN|AUTH_TOKEN)[ \t]*[=:][ \t]*["']?)([A-Za-z0-9_./+=-]{8,})(["']?)/g,
|
|
17
|
+
group: 2,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
function escapeRegExp(s) {
|
|
21
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22
|
+
}
|
|
23
|
+
function compileCustomRule(pattern) {
|
|
24
|
+
if (pattern.prefix) {
|
|
25
|
+
const len = pattern.minLength ?? 8;
|
|
26
|
+
return {
|
|
27
|
+
kind: pattern.kind,
|
|
28
|
+
regex: new RegExp(`${escapeRegExp(pattern.prefix)}[A-Za-z0-9_-]{${len},}`, "g"),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
kind: pattern.kind,
|
|
33
|
+
regex: new RegExp(pattern.regex, pattern.regex.includes("(?") ? "g" : "g"),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export class Redactor {
|
|
37
|
+
secret;
|
|
38
|
+
allowlist;
|
|
39
|
+
exemptPrefixes;
|
|
40
|
+
rules;
|
|
41
|
+
vault = new Map();
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.secret = Buffer.isBuffer(options.hmacSecret)
|
|
44
|
+
? options.hmacSecret
|
|
45
|
+
: options.hmacSecret
|
|
46
|
+
? Buffer.from(options.hmacSecret, "utf8")
|
|
47
|
+
: randomBytes(32);
|
|
48
|
+
this.allowlist = new Set(options.allowlist ?? []);
|
|
49
|
+
this.exemptPrefixes = [PLACEHOLDER_PREFIX, "lemma-", ...(options.exemptPrefixes ?? [])];
|
|
50
|
+
this.rules = [...BUILTIN_RULES, ...(options.customPatterns ?? []).map(compileCustomRule)];
|
|
51
|
+
}
|
|
52
|
+
placeholderFor(kind, value) {
|
|
53
|
+
const digest = createHmac("sha256", this.secret).update(`${kind}:${value}`).digest("hex").slice(0, 8);
|
|
54
|
+
const placeholder = `${PLACEHOLDER_PREFIX}${kind}_${digest}}}`;
|
|
55
|
+
this.vault.set(placeholder, value);
|
|
56
|
+
return placeholder;
|
|
57
|
+
}
|
|
58
|
+
isExempt(value) {
|
|
59
|
+
if (!value || this.allowlist.has(value) || DUMMY_VALUE_RE.test(value))
|
|
60
|
+
return true;
|
|
61
|
+
return this.exemptPrefixes.some((p) => value.startsWith(p));
|
|
62
|
+
}
|
|
63
|
+
redactText(input, outMap) {
|
|
64
|
+
if (!input || input.length > 512_000)
|
|
65
|
+
return { text: input, count: 0 };
|
|
66
|
+
let text = input;
|
|
67
|
+
let count = 0;
|
|
68
|
+
for (const rule of this.rules) {
|
|
69
|
+
const re = new RegExp(rule.regex.source, rule.regex.flags.includes("g") ? rule.regex.flags : `${rule.regex.flags}g`);
|
|
70
|
+
text = text.replace(re, (...args) => {
|
|
71
|
+
const full = args[0];
|
|
72
|
+
if (rule.group !== undefined) {
|
|
73
|
+
const g1 = args[1] ?? "";
|
|
74
|
+
const target = args[rule.group] ?? "";
|
|
75
|
+
const g3 = args[rule.group + 1] ?? "";
|
|
76
|
+
if (!target || this.isExempt(target))
|
|
77
|
+
return full;
|
|
78
|
+
count++;
|
|
79
|
+
const ph = this.placeholderFor(rule.kind, target);
|
|
80
|
+
outMap?.set(ph, target);
|
|
81
|
+
return `${g1}${ph}${g3}`;
|
|
82
|
+
}
|
|
83
|
+
if (this.isExempt(full))
|
|
84
|
+
return full;
|
|
85
|
+
count++;
|
|
86
|
+
const ph = this.placeholderFor(rule.kind, full);
|
|
87
|
+
outMap?.set(ph, full);
|
|
88
|
+
return ph;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return { text, count };
|
|
92
|
+
}
|
|
93
|
+
redactJson(value, outMap) {
|
|
94
|
+
let total = 0;
|
|
95
|
+
const walk = (node, parentKey) => {
|
|
96
|
+
if (typeof node === "string") {
|
|
97
|
+
// 跳过图片/文件 base64 大块,避免无谓正则扫描
|
|
98
|
+
if (parentKey === "data" && node.length > 256 && /^[A-Za-z0-9+/=]+$/.test(node.slice(0, 128)))
|
|
99
|
+
return node;
|
|
100
|
+
const res = this.redactText(node, outMap);
|
|
101
|
+
total += res.count;
|
|
102
|
+
return res.text;
|
|
103
|
+
}
|
|
104
|
+
if (Array.isArray(node)) {
|
|
105
|
+
let changed = false;
|
|
106
|
+
const next = node.map((item) => {
|
|
107
|
+
const res = walk(item);
|
|
108
|
+
if (res !== item)
|
|
109
|
+
changed = true;
|
|
110
|
+
return res;
|
|
111
|
+
});
|
|
112
|
+
return changed ? next : node;
|
|
113
|
+
}
|
|
114
|
+
if (node && typeof node === "object") {
|
|
115
|
+
const obj = node;
|
|
116
|
+
let changed = false;
|
|
117
|
+
const next = {};
|
|
118
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
119
|
+
if (k === "mime_type" || k === "media_type") {
|
|
120
|
+
next[k] = v;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const res = walk(v, k);
|
|
124
|
+
if (res !== v)
|
|
125
|
+
changed = true;
|
|
126
|
+
next[k] = res;
|
|
127
|
+
}
|
|
128
|
+
return changed ? next : node;
|
|
129
|
+
}
|
|
130
|
+
return node;
|
|
131
|
+
};
|
|
132
|
+
return { value: walk(value), count: total };
|
|
133
|
+
}
|
|
134
|
+
restoreText(input, localMap) {
|
|
135
|
+
if (!input || !input.includes(PLACEHOLDER_PREFIX))
|
|
136
|
+
return input;
|
|
137
|
+
return input.replace(PLACEHOLDER_RE, (match) => localMap?.get(match) ?? this.vault.get(match) ?? match);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 跨 chunk 安全流式还原器:截留尾部可能未完整到达的 `{{LEMMA_SECRET_...` 片段,
|
|
142
|
+
* 避免 SSE 分片把单个占位符拆成两段而漏还原或破坏 JSON 结构。
|
|
143
|
+
*/
|
|
144
|
+
export class StreamUnredactor {
|
|
145
|
+
carry = "";
|
|
146
|
+
restore;
|
|
147
|
+
constructor(restoreFn) {
|
|
148
|
+
this.restore = restoreFn;
|
|
149
|
+
}
|
|
150
|
+
push(chunk) {
|
|
151
|
+
if (!chunk && !this.carry)
|
|
152
|
+
return "";
|
|
153
|
+
const combined = this.carry + chunk;
|
|
154
|
+
this.carry = "";
|
|
155
|
+
// 1. 先检查末尾是否有未闭合的 `{{LEMMA_SECRET_...`
|
|
156
|
+
const openIdx = combined.lastIndexOf(PLACEHOLDER_PREFIX);
|
|
157
|
+
if (openIdx >= 0 && combined.indexOf("}}", openIdx) < 0 && combined.length - openIdx <= MAX_PLACEHOLDER_TAIL && !/[\r\n]/.test(combined.slice(openIdx))) {
|
|
158
|
+
this.carry = combined.slice(openIdx);
|
|
159
|
+
return this.restore(combined.slice(0, openIdx));
|
|
160
|
+
}
|
|
161
|
+
// 2. 再检查末尾是否有被截断的前缀(如 `{` 或 `{{LEMMA_`)
|
|
162
|
+
const maxPrefixCheck = Math.min(PLACEHOLDER_PREFIX.length - 1, combined.length);
|
|
163
|
+
for (let len = maxPrefixCheck; len >= 1; len--) {
|
|
164
|
+
const tail = combined.slice(-len);
|
|
165
|
+
if (PLACEHOLDER_PREFIX.startsWith(tail)) {
|
|
166
|
+
this.carry = tail;
|
|
167
|
+
return this.restore(combined.slice(0, combined.length - len));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return this.restore(combined);
|
|
171
|
+
}
|
|
172
|
+
flush() {
|
|
173
|
+
if (!this.carry)
|
|
174
|
+
return "";
|
|
175
|
+
const out = this.restore(this.carry);
|
|
176
|
+
this.carry = "";
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
}
|
package/dist/tools.js
CHANGED
|
@@ -720,7 +720,7 @@ function createRequestApplyTool(config, changes, getConfirmApply) {
|
|
|
720
720
|
},
|
|
721
721
|
});
|
|
722
722
|
}
|
|
723
|
-
export function createLocalAgentsExtension(config, changes, project, hub, getConfirmApply) {
|
|
723
|
+
export function createLocalAgentsExtension(config, changes, project, hub, getConfirmApply, proxy) {
|
|
724
724
|
const agents = detectAgents(config);
|
|
725
725
|
// API 成员的工具扩展:只装给它们自己的子对话,总调度看不到
|
|
726
726
|
const memberTools = new Map();
|
|
@@ -729,7 +729,7 @@ export function createLocalAgentsExtension(config, changes, project, hub, getCon
|
|
|
729
729
|
if (a.available && api)
|
|
730
730
|
memberTools.set(a.kind, createMemberTools(a.kind, api, { workspace: config.agents[a.kind].workspace ?? "code", changes }));
|
|
731
731
|
}
|
|
732
|
-
const deps = { config, changes, project, hub, memberTools };
|
|
732
|
+
const deps = { config, changes, project, hub, memberTools, ...(proxy ? { proxy } : {}) };
|
|
733
733
|
const integrationHooks = {};
|
|
734
734
|
const integrations = createIntegrations(deps, integrationHooks);
|
|
735
735
|
deps.integrations = integrations;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lemma-agent",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Lemma: durable local multi-agent coding orchestration with isolated worktrees, blind review, and verified integration",
|
|
5
5
|
"bin": {
|
|
6
6
|
"lemma": "bin/lemma.mjs"
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"test:chaos-durable": "node --no-warnings test/chaos-durable.ts",
|
|
36
36
|
"test:cli-replay": "node --no-warnings test/cli-replay.ts",
|
|
37
37
|
"test:ux": "node --no-warnings test/ux-telemetry.ts",
|
|
38
|
+
"test:proxy": "node --no-warnings test/proxy.ts",
|
|
38
39
|
"test:ood": "node --no-warnings test/ood-benchmark.ts",
|
|
39
40
|
"test:projects": "node --no-warnings test/projects.ts",
|
|
40
41
|
"test:collaboration": "node --no-warnings test/integrations.ts && node --no-warnings test/task-workflow.ts && node --no-warnings test/task-workflow-api.ts && node --no-warnings test/task-workflow-code.ts && node --no-warnings test/task-recovery.ts && node --no-warnings test/context-handoff.ts && node --no-warnings test/collaboration-controls.ts && node --no-warnings test/mcp.ts && node --no-warnings test/collaboration-benchmark.ts && node --no-warnings test/fast-path.ts && node --no-warnings test/coding-benchmark-suite.ts && npm run test:security && npm run test:chaos-durable && npm run test:cli-replay && npm run test:ux && npm run test:ood",
|
|
@@ -44,7 +45,7 @@
|
|
|
44
45
|
"test:harness": "node --no-warnings test/sessions.ts && node --no-warnings test/repair.ts && node --no-warnings test/sessions-cli.ts",
|
|
45
46
|
"test:conversations": "node --no-warnings test/conversations-web.ts && node --no-warnings test/admin-rebind.ts && node --no-warnings test/web-controls.ts && node --no-warnings test/git-workbench.ts",
|
|
46
47
|
"test:terminal": "node --no-warnings test/terminal.ts && node --no-warnings test/terminal-state.ts && node --no-warnings test/model-selection.ts && npm run test:metrics && node --no-warnings test/terminal-cli.ts && node --no-warnings test/terminal-child-view.ts && node --no-warnings test/terminal-model-selection.ts",
|
|
47
|
-
"test": "npm run test:business && npm run test:collaboration && npm run test:settings && npm run test:custom-agents && npm run test:results && npm run test:dialogue && npm run test:projects && node --no-warnings test/smoke.ts && node --no-warnings test/crash.ts && node --no-warnings test/isolation.ts && node --no-warnings test/steer.ts && node --no-warnings test/board.ts && node --no-warnings test/jobs.ts && node --no-warnings test/api-member.ts && node --no-warnings test/lead.ts && node --no-warnings test/conventions.ts && node --no-warnings test/web.ts && npm run test:terminal && npm run test:harness && npm run test:conversations",
|
|
48
|
+
"test": "npm run test:business && npm run test:proxy && npm run test:collaboration && npm run test:settings && npm run test:custom-agents && npm run test:results && npm run test:dialogue && npm run test:projects && node --no-warnings test/smoke.ts && node --no-warnings test/crash.ts && node --no-warnings test/isolation.ts && node --no-warnings test/steer.ts && node --no-warnings test/board.ts && node --no-warnings test/jobs.ts && node --no-warnings test/api-member.ts && node --no-warnings test/lead.ts && node --no-warnings test/conventions.ts && node --no-warnings test/web.ts && npm run test:terminal && npm run test:harness && npm run test:conversations",
|
|
48
49
|
"test:business": "node --no-warnings test/business.ts && node --no-warnings test/settlement.ts",
|
|
49
50
|
"test:results": "node --no-warnings test/result-retrieval.ts",
|
|
50
51
|
"test:custom-agents": "node --no-warnings test/custom-agent-config.ts && node --no-warnings test/custom-agents.ts",
|