@desplega.ai/agent-swarm 1.165.0 → 1.166.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/dist/{acp-adapter-w6zws6me.js → acp-adapter-yzfxn8vj.js} +4 -4
- package/dist/{actions-jna0b3wm.js → actions-qz3m692w.js} +20 -24
- package/dist/{amp-adapter-0eve81pz.js → amp-adapter-j1xbmsqz.js} +4 -4
- package/dist/{app-75hm5cfa.js → app-43vrdmv8.js} +6 -7
- package/dist/{assistant-yzd51j33.js → assistant-ertffmka.js} +21 -25
- package/dist/{boot-reembed-z158xq32.js → boot-reembed-998jtpdg.js} +9 -12
- package/dist/{boot-reembed-2ex2mcsh.js → boot-reembed-s7k7c6v2.js} +10 -12
- package/dist/boot-scrub-sweep-nepsk4t1.js +211 -0
- package/dist/{boot-seeds-2bmnh18p.js → boot-seeds-vvzs1zhk.js} +8 -8
- package/dist/{claude-adapter-jbj1mycz.js → claude-adapter-2zvmekrp.js} +9 -11
- package/dist/{claude-managed-adapter-17ggz09t.js → claude-managed-adapter-s49wbk8t.js} +3 -3
- package/dist/{claude-managed-setup-ptm1nzm2.js → claude-managed-setup-cvhqq8qn.js} +4 -4
- package/dist/{claude-sdk-session-9re1g7r2.js → claude-sdk-session-kkbxtw5q.js} +2618 -2600
- package/dist/{cli-k6xx3pve.js → cli-0nhdwxd5.js} +4 -4
- package/dist/{cli-n9ehc28t.js → cli-0qjcsxgz.js} +4 -4
- package/dist/{cli-zn2v3t8v.js → cli-3ddybbbx.js} +1 -1
- package/dist/{cli-5anb0ev3.js → cli-3qn4r334.js} +71 -14
- package/dist/{cli-1kzfvd1z.js → cli-4r1sjfc4.js} +9 -5
- package/dist/{cli-ba66wyhy.js → cli-66zh26sp.js} +6 -6
- package/dist/{cli-9xb89xca.js → cli-68r1j4sg.js} +6 -6
- package/dist/{cli-xnzrzets.js → cli-8kgvmkak.js} +2 -2
- package/dist/{cli-28smfvbn.js → cli-8t229cmr.js} +5 -5
- package/dist/{cli-9866bd07.js → cli-aqcey741.js} +1 -1
- package/dist/{cli-90v942q1.js → cli-cpfmqz3n.js} +8 -8
- package/dist/{cli-50eg13rj.js → cli-df56tqdw.js} +459 -282
- package/dist/{cli-8gpbwy09.js → cli-dw2q9f7g.js} +5 -5
- package/dist/{cli-0n4fasz0.js → cli-ecknp7p1.js} +15 -15
- package/dist/{cli-xb3c6aat.js → cli-f2n17zhp.js} +1 -1
- package/dist/{cli-ftry7975.js → cli-feh3dkah.js} +1 -1
- package/dist/{cli-amwhs8h2.js → cli-fn697bnt.js} +2 -2
- package/dist/{cli-prt9emct.js → cli-gt8azyet.js} +3 -3
- package/dist/{cli-59jn5twa.js → cli-h3x613ze.js} +2 -2
- package/dist/{cli-mmzwwptd.js → cli-hf5s9pgf.js} +1 -1
- package/dist/cli-j2jbr8af.js +516 -0
- package/dist/{cli-wfajtmf7.js → cli-jhm6hzjn.js} +593 -10
- package/dist/{cli-xtgtyafv.js → cli-jvj6a0cv.js} +190 -439
- package/dist/{cli-hpryr6em.js → cli-mb75wpxf.js} +1 -1
- package/dist/{cli-420bdgw0.js → cli-mv2520nm.js} +1 -1
- package/dist/{cli-pjxnr1jn.js → cli-mwegs4af.js} +3 -3
- package/dist/{cli-5b2fjjzh.js → cli-p4ztb80h.js} +2 -2
- package/dist/{cli-e7t4snpa.js → cli-rggdq8wq.js} +4 -4
- package/dist/{cli-bdv39kgj.js → cli-rsy933yz.js} +5 -5
- package/dist/{cli-gh5yqzpe.js → cli-v2a8x45d.js} +2 -2
- package/dist/{cli-bns5c8k9.js → cli-vzc73wet.js} +43 -47
- package/dist/cli-wt7ccy4r.js +2654 -0
- package/dist/{cli-j0pdrmwg.js → cli-x7kpr72a.js} +3 -3
- package/dist/{cli-x7afk5wm.js → cli-xvc3q9br.js} +1 -1
- package/dist/{cli-9s3h836g.js → cli-xvdgasgy.js} +1 -1
- package/dist/{cli-zvckv750.js → cli-y59h2pk9.js} +2 -2
- package/dist/{cli-qdv8kgz7.js → cli-yshaazs1.js} +13884 -3241
- package/dist/{cli-nfygw434.js → cli-ysnyhws9.js} +2 -2
- package/dist/{cli-fw6vdcq5.js → cli-zp67qg5x.js} +34 -1
- package/dist/{cli-ma3zvh39.js → cli-zy7vwsne.js} +6066 -5829
- package/dist/cli.js +24 -20
- package/dist/{codex-adapter-3qnxshje.js → codex-adapter-dw1wxqt8.js} +7 -7
- package/dist/{codex-login-brkxhhdg.js → codex-login-terbdsqq.js} +2 -2
- package/dist/{codex-session-runner-612wnapp.js → codex-session-runner-3cgb8y1g.js} +7 -7
- package/dist/{commands-2ybfcxkj.js → commands-mhxam6z2.js} +6 -6
- package/dist/{cursor-adapter-p3jgdehv.js → cursor-adapter-2qda3st7.js} +3 -3
- package/dist/{db-f4ans0jj.js → db-sjks418k.js} +8 -6
- package/dist/{devin-adapter-dhzt01ff.js → devin-adapter-bffjj5n4.js} +2 -2
- package/dist/{dispatcher-pk182apd.js → dispatcher-1es759rn.js} +18 -22
- package/dist/{dsh-adapter-7twaeps1.js → dsh-adapter-bek4cyw9.js} +3 -3
- package/dist/{e2b-y8t3jzyz.js → e2b-nd50eccg.js} +1 -1
- package/dist/{event-bus-w7ac4n3c.js → event-bus-vnfthafg.js} +2 -2
- package/dist/{grok-adapter-yt9pab3k.js → grok-adapter-ar9cw9jg.js} +5 -5
- package/dist/{handlers-g2wnr4t9.js → handlers-1gkbhktr.js} +21 -25
- package/dist/{hook-f7jt9vnm.js → hook-ds2zxq9v.js} +14 -16
- package/dist/{hook-bbdpnkb4.js → hook-vxa3tcsy.js} +8 -10
- package/dist/{http-w40q4w94.js → http-3h21z9md.js} +247 -164
- package/dist/{index-056j5kzn.js → index-9b65j1m5.js} +8 -8
- package/dist/{index-9bfssf54.js → index-bn6cy8ps.js} +18 -22
- package/dist/{index-cj1r9q83.js → index-dkfxpkmm.js} +19 -23
- package/dist/{index-7n70jwbb.js → index-f8xnqrye.js} +19 -21
- package/dist/{index-fdk1t4d6.js → index-n0rxa4ca.js} +11962 -9900
- package/dist/{index-k8xc083e.js → index-n99fycq7.js} +18 -22
- package/dist/{keepalive-1tj10tf4.js → keepalive-3xspa9jw.js} +11 -8
- package/dist/{lead-st0bg7v4.js → lead-6qphc124.js} +34 -38
- package/dist/{maintenance-nz71zats.js → maintenance-0teem1bb.js} +7 -9
- package/dist/{node-f0ykebbv.js → node-9sg7ajby.js} +25 -7
- package/dist/{oauth-refresh-sweep-aefzwvvq.js → oauth-refresh-sweep-sh9q25xp.js} +10 -7
- package/dist/{onboard-kgpr9mbn.js → onboard-54qmnqxe.js} +2 -2
- package/dist/{opencode-adapter-0c8e70dk.js → opencode-adapter-wjfa2wvd.js} +2 -2
- package/dist/{otel-impl-x8zp4y5a.js → otel-impl-ycqzp2a1.js} +2 -2
- package/dist/{pi-mono-adapter-t280ah5c.js → pi-mono-adapter-e77e9zst.js} +4 -4
- package/dist/{pricing-refresh-9e0q7cwk.js → pricing-refresh-atnkngqs.js} +7 -7
- package/dist/{rbac-roles-kcp6zge2.js → rbac-roles-9pjphh9q.js} +6 -6
- package/dist/{rbac-roles-790j3ga8.js → rbac-roles-j78wdksm.js} +6 -6
- package/dist/{render-v2-tch4nefj.js → render-v2-pxjs49fx.js} +6 -7
- package/dist/{setup-rcm303ns.js → setup-ymej0xtx.js} +2 -2
- package/dist/{work-objects-ctg7t70w.js → work-objects-3nh4ymzb.js} +22 -26
- package/dist/{worker-5dp0xm55.js → worker-qa9fkz5s.js} +34 -38
- package/dist/{x-v3yw66zs.js → x-ma4gnfgy.js} +2 -2
- package/openapi.json +5 -2
- package/package.json +9 -5
- package/src/be/automation-preflight.ts +9 -4
- package/src/be/boot-scrub-sweep.ts +302 -0
- package/src/be/crypto/key-bootstrap.ts +1 -1
- package/src/be/db/approvals.ts +15 -1
- package/src/be/db/codex-oauth-device-flows.ts +40 -0
- package/src/be/db/config-secrets.ts +31 -0
- package/src/be/db/runtime.ts +4 -0
- package/src/be/db/script-runs.ts +15 -0
- package/src/be/db/tasks/write.ts +1 -1
- package/src/be/db-queries/mcp-oauth.ts +5 -0
- package/src/be/db-queries/oauth.ts +77 -0
- package/src/be/db.ts +162 -59
- package/src/be/events.ts +17 -1
- package/src/be/memory/index-content.ts +2 -2
- package/src/be/memory/providers/sqlite-store.ts +63 -11
- package/src/be/memory/types.ts +14 -0
- package/src/be/migrations/201_workflow_replay_columns.sql +10 -0
- package/src/be/migrations/202_codex_oauth_device_flows.sql +24 -0
- package/src/be/scripts/db.ts +28 -4
- package/src/be/scripts/source-secrets.ts +37 -0
- package/src/be/scrub-json.ts +32 -0
- package/src/be/sealed-json.ts +59 -0
- package/src/be/secret-registry.ts +131 -0
- package/src/be/workflow-replay.ts +77 -0
- package/src/http/codex-oauth-device.ts +8 -10
- package/src/http/db-query-bounded.ts +3 -0
- package/src/http/db-query-shared.ts +107 -15
- package/src/http/db-query.ts +10 -2
- package/src/http/index.ts +23 -6
- package/src/http/script-runs.ts +9 -1
- package/src/http/scripts.ts +15 -0
- package/src/http/workflows.ts +3 -2
- package/src/oauth/mcp-wrapper.ts +1 -1
- package/src/providers/acp-adapter.ts +25 -11
- package/src/providers/acp-target-catalog.ts +35 -1
- package/src/providers/acp-targets.ts +69 -3
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/script-workflows/supervisor.ts +11 -2
- package/src/scripts-runtime/eval-harness.ts +2 -12
- package/src/scripts-runtime/executors/quickjs-bundle.ts +152 -0
- package/src/scripts-runtime/executors/quickjs-prelude.ts +285 -0
- package/src/scripts-runtime/executors/quickjs-runner.ts +580 -0
- package/src/scripts-runtime/executors/quickjs-worker.ts +81 -0
- package/src/scripts-runtime/executors/quickjs.ts +196 -0
- package/src/scripts-runtime/executors/registry.ts +2 -0
- package/src/scripts-runtime/executors/sourcemap.ts +79 -0
- package/src/scripts-runtime/script-error-hints.ts +14 -0
- package/src/server.ts +3 -1
- package/src/tests/acp-adapter.test.ts +127 -2
- package/src/tests/boot-scrub-sweep.test.ts +390 -0
- package/src/tests/check-text-columns.test.ts +145 -0
- package/src/tests/claude-sdk-process.fixture.ts +13 -2
- package/src/tests/codex-oauth-device.test.ts +23 -37
- package/src/tests/db-query-denylist.test.ts +202 -0
- package/src/tests/db-task-read-contract.test.ts +1 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/entrypoint-acp-target-binary.test.ts +31 -1
- package/src/tests/events-scrub.test.ts +88 -0
- package/src/tests/fixtures/secret-corpus.ts +320 -0
- package/src/tests/script-connections.test.ts +5 -0
- package/src/tests/script-executor-conformance.test.ts +3 -0
- package/src/tests/script-executor-quickjs.test.ts +442 -0
- package/src/tests/script-executor-registry.test.ts +6 -1
- package/src/tests/script-runs-http.test.ts +88 -1
- package/src/tests/script-runs-scrub.test.ts +275 -0
- package/src/tests/scripts-http.test.ts +82 -1
- package/src/tests/scrubbed-text-12e.test.ts +289 -0
- package/src/tests/sealed-key-guard.test.ts +166 -0
- package/src/tests/secret-canary-sweep.test.ts +958 -0
- package/src/tests/secret-registry.test.ts +355 -0
- package/src/tests/secret-rules.test.ts +230 -0
- package/src/tests/secret-scrubber.test.ts +3 -2
- package/src/tests/workflow-replay.test.ts +518 -0
- package/src/tests/workflow-scrub.test.ts +242 -0
- package/src/tools/db-query.ts +1 -1
- package/src/tools/inject-learning.ts +1 -1
- package/src/tools/workflows/get-workflow-run.ts +3 -2
- package/src/types.ts +1 -1
- package/src/utils/secret-rules.generated.ts +2055 -0
- package/src/utils/secret-scrubber.ts +363 -29
- package/src/workflows/engine.ts +39 -4
- package/src/workflows/recovery.ts +10 -1
- package/src/workflows/resume.ts +62 -3
- package/src/workflows/retry-poller.ts +3 -0
- package/dist/boot-scrub-logs-246yn076.js +0 -99
- package/dist/cli-3a4m1aws.js +0 -572
- package/dist/cli-a87b04k8.js +0 -951
- package/dist/cli-cvk6yzw5.js +0 -40
- package/dist/cli-h1spv8v4.js +0 -427
- package/dist/cli-jqt9hrnz.js +0 -168
- package/dist/cli-yhmwmv0g.js +0 -9281
- package/src/be/boot-scrub-logs.ts +0 -132
package/dist/cli-cvk6yzw5.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildAgentFsLiveUrl,
|
|
3
|
-
buildCombFileUrl,
|
|
4
|
-
getAppUrl,
|
|
5
|
-
init_constants
|
|
6
|
-
} from "./cli-gd4favx9.js";
|
|
7
|
-
import {
|
|
8
|
-
__esm
|
|
9
|
-
} from "./cli-bc05qbss.js";
|
|
10
|
-
|
|
11
|
-
// src/utils/task-attachment-links.ts
|
|
12
|
-
function shellQuote(value) {
|
|
13
|
-
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
14
|
-
}
|
|
15
|
-
function taskAttachmentFetchCommand(taskId, attachmentId, name) {
|
|
16
|
-
const url = `$MCP_BASE_URL/api/fs/tasks/${taskId}/files/${attachmentId}/raw`;
|
|
17
|
-
const outPath = shellQuote(`/tmp/attachments/${attachmentId}/${name.replace(/\//g, "_")}`);
|
|
18
|
-
return `curl -s -H "Authorization: Bearer \${AGENT_SWARM_API_KEY:-$API_KEY}" -H "X-Agent-ID: $AGENT_ID" "${url}" --create-dirs -o ${outPath}`;
|
|
19
|
-
}
|
|
20
|
-
function taskAttachmentDisplayUrl(attachment, opts = {}) {
|
|
21
|
-
if (attachment.kind === "url")
|
|
22
|
-
return attachment.url ?? "";
|
|
23
|
-
if (attachment.kind === "page") {
|
|
24
|
-
return attachment.pageId ? `${getAppUrl()}/pages/${attachment.pageId}` : "page:";
|
|
25
|
-
}
|
|
26
|
-
if (attachment.providerId === "agent-fs" || attachment.kind === "agent-fs") {
|
|
27
|
-
const file = { path: attachment.path, orgId: attachment.orgId, driveId: attachment.driveId };
|
|
28
|
-
const combUrl = opts.comb === false ? null : buildCombFileUrl(file);
|
|
29
|
-
return combUrl ?? buildAgentFsLiveUrl(file) ?? `agent-fs:${attachment.path ?? ""}`;
|
|
30
|
-
}
|
|
31
|
-
if (attachment.providerId === "local-fs" || attachment.kind === "shared-fs") {
|
|
32
|
-
return `${getAppUrl()}/api/fs/tasks/${attachment.taskId}/files/${attachment.id}/raw`;
|
|
33
|
-
}
|
|
34
|
-
return attachment.path ?? attachment.providerKey ?? "";
|
|
35
|
-
}
|
|
36
|
-
var init_task_attachment_links = __esm(() => {
|
|
37
|
-
init_constants();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
export { taskAttachmentFetchCommand, taskAttachmentDisplayUrl, init_task_attachment_links };
|
package/dist/cli-h1spv8v4.js
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__esm
|
|
3
|
-
} from "./cli-bc05qbss.js";
|
|
4
|
-
|
|
5
|
-
// src/utils/secret-scrubber.ts
|
|
6
|
-
function normalizeKey(key) {
|
|
7
|
-
if (!/[a-z.-]/.test(key))
|
|
8
|
-
return key;
|
|
9
|
-
let out = key;
|
|
10
|
-
if (/[a-z]/.test(out) && /[A-Z]/.test(out)) {
|
|
11
|
-
out = out.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2");
|
|
12
|
-
}
|
|
13
|
-
return out.replace(/[.-]/g, "_").toUpperCase();
|
|
14
|
-
}
|
|
15
|
-
function escapedForms(value) {
|
|
16
|
-
const forms = new Set([value, value.replace(/[\\$"`]/g, "\\$&"), value.replaceAll("'", "'\\''")]);
|
|
17
|
-
for (const form of [...forms])
|
|
18
|
-
forms.add(JSON.stringify(form).slice(1, -1));
|
|
19
|
-
return [...forms];
|
|
20
|
-
}
|
|
21
|
-
function quoted(open, close, item, lineItem) {
|
|
22
|
-
return `${open}(?:(?:${lineItem})*${close}|(?:${item})*${close}${QUOTE_EOL}|(?:${lineItem})*)`;
|
|
23
|
-
}
|
|
24
|
-
function isSensitiveKeyPath(key) {
|
|
25
|
-
if (isSensitiveKey(key))
|
|
26
|
-
return true;
|
|
27
|
-
const dot = key.lastIndexOf(".");
|
|
28
|
-
return dot >= 0 && isSensitiveKey(key.slice(dot + 1));
|
|
29
|
-
}
|
|
30
|
-
function redactAssignment(match, key, value) {
|
|
31
|
-
if (!isSensitiveKeyPath(key))
|
|
32
|
-
return match;
|
|
33
|
-
let open = "";
|
|
34
|
-
let close = "";
|
|
35
|
-
for (const quote of ["\\\"", '"', "'"]) {
|
|
36
|
-
if (!value.startsWith(quote))
|
|
37
|
-
continue;
|
|
38
|
-
open = quote;
|
|
39
|
-
if (value.length >= quote.length * 2 && value.endsWith(quote))
|
|
40
|
-
close = quote;
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
const inner = value.slice(open.length, value.length - close.length);
|
|
44
|
-
if (inner === "" || /^\[REDACTED:[^\]]*\]$/.test(inner))
|
|
45
|
-
return match;
|
|
46
|
-
return `${key}=${open}[REDACTED:${key}]${close}`;
|
|
47
|
-
}
|
|
48
|
-
function isPlaceholderValue(value) {
|
|
49
|
-
return value === "" || value.includes("[REDACTED") || /^[$<*%{]/.test(value) || /^(?:null|none|nil|true|false|yes|no|undefined|~)$/i.test(value) || /^[+-]?\d+(?:\.\d+)?$/.test(value);
|
|
50
|
-
}
|
|
51
|
-
function looksLikeCode(value) {
|
|
52
|
-
return /[()[\]{};,]/.test(value) || /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(value) || /^[A-Za-z_]+$/.test(value) && value.length < 16;
|
|
53
|
-
}
|
|
54
|
-
function redactLineValue(match, lead, key, sep, value) {
|
|
55
|
-
if (!isSensitiveKeyPath(key))
|
|
56
|
-
return match;
|
|
57
|
-
const quote = /^(?:\\"|"|')/.exec(value)?.[0] ?? "";
|
|
58
|
-
const inner = quote ? value.slice(quote.length, -quote.length) : value;
|
|
59
|
-
if (isPlaceholderValue(inner) || !quote && looksLikeCode(inner))
|
|
60
|
-
return match;
|
|
61
|
-
return `${lead}${key}${sep}${quote}[REDACTED:${key}]${quote}`;
|
|
62
|
-
}
|
|
63
|
-
function jsonStringEnd(text, start, escaped) {
|
|
64
|
-
let innerEscape = false;
|
|
65
|
-
for (let i = start;i < text.length; i++) {
|
|
66
|
-
let ch = text[i];
|
|
67
|
-
if (ch === "\r" || ch === `
|
|
68
|
-
`)
|
|
69
|
-
return -(i + 1);
|
|
70
|
-
const at = i;
|
|
71
|
-
if (escaped) {
|
|
72
|
-
if (ch === '"')
|
|
73
|
-
return -(i + 1);
|
|
74
|
-
if (ch === "\\") {
|
|
75
|
-
ch = text[++i];
|
|
76
|
-
if (ch === undefined || ch === "\r" || ch === `
|
|
77
|
-
`)
|
|
78
|
-
return -(i + 1);
|
|
79
|
-
if (ch !== "\\" && ch !== '"')
|
|
80
|
-
ch = "x";
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (innerEscape)
|
|
84
|
-
innerEscape = false;
|
|
85
|
-
else if (ch === "\\")
|
|
86
|
-
innerEscape = true;
|
|
87
|
-
else if (ch === '"')
|
|
88
|
-
return at;
|
|
89
|
-
}
|
|
90
|
-
return -(text.length + 1);
|
|
91
|
-
}
|
|
92
|
-
function redactJsonValues(text, re, escaped) {
|
|
93
|
-
let out = "";
|
|
94
|
-
let last = 0;
|
|
95
|
-
re.lastIndex = 0;
|
|
96
|
-
for (let m = re.exec(text);m; m = re.exec(text)) {
|
|
97
|
-
const key = m[1] ?? "";
|
|
98
|
-
if (!isSensitiveKeyPath(key))
|
|
99
|
-
continue;
|
|
100
|
-
const valueStart = m.index + m[0].length;
|
|
101
|
-
const end = jsonStringEnd(text, valueStart, escaped);
|
|
102
|
-
if (end < 0) {
|
|
103
|
-
re.lastIndex = Math.max(re.lastIndex, -end - 2);
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
re.lastIndex = end + 1;
|
|
107
|
-
if (isPlaceholderValue(text.slice(valueStart, end)))
|
|
108
|
-
continue;
|
|
109
|
-
out += `${text.slice(last, valueStart)}[REDACTED:${key}]`;
|
|
110
|
-
last = end;
|
|
111
|
-
}
|
|
112
|
-
return last === 0 ? text : out + text.slice(last);
|
|
113
|
-
}
|
|
114
|
-
function redactHeader(match, name, sep, value) {
|
|
115
|
-
if (/^[A-Za-z_]+$/.test(value) && value.length < 16)
|
|
116
|
-
return match;
|
|
117
|
-
return `${name}${sep}[REDACTED:${name.toLowerCase().replace(/-/g, "_")}]`;
|
|
118
|
-
}
|
|
119
|
-
function scrubKeyContext(text) {
|
|
120
|
-
let out = text;
|
|
121
|
-
if (out.includes("PRIVATE KEY")) {
|
|
122
|
-
out = out.replace(PEM_RE, (match, begin, body, end) => body === PEM_MARKER ? match : `${begin}${PEM_MARKER}${end}`);
|
|
123
|
-
}
|
|
124
|
-
if (/authorization|x-api-key/i.test(out)) {
|
|
125
|
-
out = out.replace(AUTH_HEADER_RE, redactHeader).replace(API_KEY_HEADER_RE, redactHeader);
|
|
126
|
-
}
|
|
127
|
-
if (out.includes("--password")) {
|
|
128
|
-
out = out.replace(CURL_PASSWORD_RE, (match, flag, pw) => isPlaceholderValue(pw) ? match : `${flag}[REDACTED:curl_password]`);
|
|
129
|
-
}
|
|
130
|
-
if (/(?:^|\s)-(?:u|U|-user|-proxy-user)\b/.test(out)) {
|
|
131
|
-
out = out.replace(CURL_USER_RE, (match, prefix, user, pw) => isPlaceholderValue(pw) || pw === user ? match : `${prefix}[REDACTED:curl_password]`);
|
|
132
|
-
}
|
|
133
|
-
if (out.includes("://")) {
|
|
134
|
-
out = out.replace(URL_USERINFO_RE, (match, prefix, pw) => isPlaceholderValue(pw) ? match : `${prefix}[REDACTED:url_password]`);
|
|
135
|
-
}
|
|
136
|
-
if (out.includes('"')) {
|
|
137
|
-
out = redactJsonValues(out, JSON_KEY_RE, false);
|
|
138
|
-
if (out.includes("\\\""))
|
|
139
|
-
out = redactJsonValues(out, ESCAPED_JSON_KEY_RE, true);
|
|
140
|
-
}
|
|
141
|
-
if (out.includes(":"))
|
|
142
|
-
out = out.replace(YAML_KEY_RE, redactLineValue);
|
|
143
|
-
return out;
|
|
144
|
-
}
|
|
145
|
-
function snapshotEnv() {
|
|
146
|
-
const parts = [];
|
|
147
|
-
for (const key of Object.keys(process.env).sort()) {
|
|
148
|
-
if (!isSensitiveKey(key))
|
|
149
|
-
continue;
|
|
150
|
-
const v = process.env[key];
|
|
151
|
-
if (!v)
|
|
152
|
-
continue;
|
|
153
|
-
parts.push(`${key}=${v.length}`);
|
|
154
|
-
}
|
|
155
|
-
return parts.join("|");
|
|
156
|
-
}
|
|
157
|
-
function isSensitiveKey(key) {
|
|
158
|
-
const cached = sensitiveKeyVerdicts.get(key);
|
|
159
|
-
if (cached !== undefined)
|
|
160
|
-
return cached;
|
|
161
|
-
const verdict = computeIsSensitiveKey(key);
|
|
162
|
-
if (sensitiveKeyVerdicts.size >= MAX_KEY_VERDICTS)
|
|
163
|
-
sensitiveKeyVerdicts.clear();
|
|
164
|
-
sensitiveKeyVerdicts.set(key, verdict);
|
|
165
|
-
return verdict;
|
|
166
|
-
}
|
|
167
|
-
function computeIsSensitiveKey(key) {
|
|
168
|
-
const normalized = normalizeKey(key);
|
|
169
|
-
if (NON_SECRET_EXCEPTIONS.has(normalized))
|
|
170
|
-
return false;
|
|
171
|
-
if (SENSITIVE_KEY_EXACT.has(normalized))
|
|
172
|
-
return true;
|
|
173
|
-
if (registeredSensitiveKeys.has(key) || registeredSensitiveKeys.has(normalized))
|
|
174
|
-
return true;
|
|
175
|
-
for (const suffix of SENSITIVE_KEY_SUFFIXES) {
|
|
176
|
-
if (normalized.endsWith(suffix))
|
|
177
|
-
return true;
|
|
178
|
-
}
|
|
179
|
-
if (/^codex_oauth(_\d+)?$/.test(key))
|
|
180
|
-
return true;
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
function buildCache() {
|
|
184
|
-
const entries = [];
|
|
185
|
-
const seen = new Set;
|
|
186
|
-
for (const [key, rawValue] of Object.entries(process.env)) {
|
|
187
|
-
if (!rawValue)
|
|
188
|
-
continue;
|
|
189
|
-
if (!isSensitiveKey(key))
|
|
190
|
-
continue;
|
|
191
|
-
const candidates = rawValue.includes(",") ? [rawValue, ...rawValue.split(",").map((s) => s.trim())] : [rawValue];
|
|
192
|
-
for (const candidate of candidates) {
|
|
193
|
-
if (!candidate)
|
|
194
|
-
continue;
|
|
195
|
-
if (candidate.length < MIN_VALUE_LENGTH)
|
|
196
|
-
continue;
|
|
197
|
-
for (const form of escapedForms(candidate)) {
|
|
198
|
-
if (seen.has(form))
|
|
199
|
-
continue;
|
|
200
|
-
seen.add(form);
|
|
201
|
-
entries.push({ value: form, name: key });
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
entries.sort((a, b) => b.value.length - a.value.length);
|
|
206
|
-
return { entries, snapshotKey: snapshotEnv() };
|
|
207
|
-
}
|
|
208
|
-
function getCache() {
|
|
209
|
-
const current = snapshotEnv();
|
|
210
|
-
if (!cache || cache.snapshotKey !== current) {
|
|
211
|
-
cache = buildCache();
|
|
212
|
-
}
|
|
213
|
-
return cache;
|
|
214
|
-
}
|
|
215
|
-
function scrubSecrets(text) {
|
|
216
|
-
if (text == null)
|
|
217
|
-
return "";
|
|
218
|
-
if (text.length === 0)
|
|
219
|
-
return text;
|
|
220
|
-
let out = text;
|
|
221
|
-
const { entries } = getCache();
|
|
222
|
-
for (const { value, name } of entries) {
|
|
223
|
-
if (out.includes(value)) {
|
|
224
|
-
out = out.split(value).join(`[REDACTED:${name}]`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
for (const [value, name] of volatileSecrets) {
|
|
228
|
-
if (out.includes(value)) {
|
|
229
|
-
out = out.split(value).join(`[REDACTED:${name}]`);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
for (const { name, re } of TOKEN_REGEXES) {
|
|
233
|
-
out = out.replace(re, `[REDACTED:${name}]`);
|
|
234
|
-
}
|
|
235
|
-
out = out.replace(ASSIGNMENT_RE, redactAssignment);
|
|
236
|
-
if (out.includes("="))
|
|
237
|
-
out = out.replace(INI_ASSIGNMENT_RE, redactLineValue);
|
|
238
|
-
return scrubKeyContext(out);
|
|
239
|
-
}
|
|
240
|
-
function scrubObject(value, seen = new WeakSet) {
|
|
241
|
-
if (value === null || value === undefined)
|
|
242
|
-
return value;
|
|
243
|
-
if (typeof value === "string")
|
|
244
|
-
return scrubSecrets(value);
|
|
245
|
-
if (typeof value !== "object")
|
|
246
|
-
return value;
|
|
247
|
-
if (seen.has(value)) {
|
|
248
|
-
return "[Circular]";
|
|
249
|
-
}
|
|
250
|
-
seen.add(value);
|
|
251
|
-
if (Array.isArray(value)) {
|
|
252
|
-
return value.map((item) => scrubObject(item, seen));
|
|
253
|
-
}
|
|
254
|
-
const out = {};
|
|
255
|
-
for (const [key, child] of Object.entries(value)) {
|
|
256
|
-
out[key] = scrubObject(child, seen);
|
|
257
|
-
}
|
|
258
|
-
return out;
|
|
259
|
-
}
|
|
260
|
-
function refreshSecretScrubberCache() {
|
|
261
|
-
cache = null;
|
|
262
|
-
}
|
|
263
|
-
function registerVolatileSecret(value, name) {
|
|
264
|
-
if (value.length < MIN_VALUE_LENGTH)
|
|
265
|
-
return;
|
|
266
|
-
for (const form of escapedForms(value))
|
|
267
|
-
volatileSecrets.set(form, name);
|
|
268
|
-
}
|
|
269
|
-
function registerSensitiveKeyName(key) {
|
|
270
|
-
if (registeredSensitiveKeys.has(key))
|
|
271
|
-
return;
|
|
272
|
-
registeredSensitiveKeys.add(key);
|
|
273
|
-
sensitiveKeyVerdicts.clear();
|
|
274
|
-
cache = null;
|
|
275
|
-
}
|
|
276
|
-
var SENSITIVE_KEY_EXACT, SENSITIVE_KEY_SUFFIXES, NON_SECRET_EXCEPTIONS, MIN_VALUE_LENGTH = 12, QUOTE_EOL, JSON_DQ, RAW_DQ, SQ, BARE, ASSIGNMENT_RE, LINE_START, LINE_END, LINE_VALUE, INI_ASSIGNMENT_RE, YAML_KEY_RE, JSON_KEY, JSON_KEY_RE, ESCAPED_JSON_KEY_RE, TOKEN68, HEADER_SEP, AUTH_HEADER_RE, API_KEY_HEADER_RE, CURL_PASSWORD_RE, CURL_USER_RE, URL_USERINFO_RE, PEM_RE, PEM_MARKER = "[REDACTED:private_key]", TB, TOKEN_REGEXES, cache = null, volatileSecrets, registeredSensitiveKeys, sensitiveKeyVerdicts, MAX_KEY_VERDICTS = 4096;
|
|
277
|
-
var init_secret_scrubber = __esm(() => {
|
|
278
|
-
SENSITIVE_KEY_EXACT = new Set([
|
|
279
|
-
"API_KEY",
|
|
280
|
-
"SECRETS_ENCRYPTION_KEY",
|
|
281
|
-
"GITHUB_TOKEN",
|
|
282
|
-
"GITLAB_TOKEN",
|
|
283
|
-
"AZURE_DEVOPS_TOKEN",
|
|
284
|
-
"AZURE_DEVOPS_EXT_PAT",
|
|
285
|
-
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
286
|
-
"ANTHROPIC_API_KEY",
|
|
287
|
-
"OPENAI_API_KEY",
|
|
288
|
-
"OPENROUTER_API_KEY",
|
|
289
|
-
"SLACK_BOT_TOKEN",
|
|
290
|
-
"SLACK_SIGNING_SECRET",
|
|
291
|
-
"SLACK_CLIENT_SECRET",
|
|
292
|
-
"SLACK_USER_TOKEN",
|
|
293
|
-
"SLACK_APP_TOKEN",
|
|
294
|
-
"SENTRY_AUTH_TOKEN",
|
|
295
|
-
"VERCEL_TOKEN",
|
|
296
|
-
"RESEND_API_KEY",
|
|
297
|
-
"AGENTMAIL_API_KEY",
|
|
298
|
-
"API_AGENT_FS_API_KEY",
|
|
299
|
-
"AGENT_FS_API_KEY",
|
|
300
|
-
"BUSINESS_USE_API_KEY",
|
|
301
|
-
"QA_USE_API_KEY",
|
|
302
|
-
"DOCS_API_KEY",
|
|
303
|
-
"DOKPLOY_API_KEY",
|
|
304
|
-
"DEVTO_API_KEY",
|
|
305
|
-
"ELEVENLABS_API_KEY",
|
|
306
|
-
"ENGINY_API_KEY",
|
|
307
|
-
"OPENFORT_API_KEY",
|
|
308
|
-
"OPENFORT_TEST_SECRET_KEY",
|
|
309
|
-
"OPENFORT_TEST_WALLET_PRIVATE_KEY",
|
|
310
|
-
"OPENFORT_WALLET_SECRET",
|
|
311
|
-
"TURSO_API_TOKEN",
|
|
312
|
-
"TURSO_DB_TOKEN",
|
|
313
|
-
"TURSO_X_POSTS_DB_TOKEN",
|
|
314
|
-
"BROWSER_USE_API_KEY",
|
|
315
|
-
"PLAUSIBLE_API_KEY",
|
|
316
|
-
"IMGFLIP_PASSWORD",
|
|
317
|
-
"GSC_SERVICE_ACCOUNT_BASE64",
|
|
318
|
-
"LINEAR_API_KEY",
|
|
319
|
-
"LINEAR_OAUTH_CLIENT_SECRET",
|
|
320
|
-
"OTEL_EXPORTER_OTLP_HEADERS",
|
|
321
|
-
"SIGNOZ_INGESTION_KEY",
|
|
322
|
-
"SECRET",
|
|
323
|
-
"PASSWORD",
|
|
324
|
-
"PASSWD",
|
|
325
|
-
"TOKEN",
|
|
326
|
-
"PRIVATE_KEY",
|
|
327
|
-
"APIKEY",
|
|
328
|
-
"ACCESS_TOKEN",
|
|
329
|
-
"REFRESH_TOKEN",
|
|
330
|
-
"CLIENT_SECRET",
|
|
331
|
-
"AUTHORIZATION",
|
|
332
|
-
"CREDENTIALS"
|
|
333
|
-
]);
|
|
334
|
-
SENSITIVE_KEY_SUFFIXES = [
|
|
335
|
-
"_API_KEY",
|
|
336
|
-
"_TOKEN",
|
|
337
|
-
"_SECRET",
|
|
338
|
-
"_PASSWORD",
|
|
339
|
-
"_PASS",
|
|
340
|
-
"_PRIVATE_KEY",
|
|
341
|
-
"_ACCESS_KEY",
|
|
342
|
-
"_SECRET_KEY",
|
|
343
|
-
"_APIKEY",
|
|
344
|
-
"_AUTH_HEADER",
|
|
345
|
-
"_CREDENTIALS",
|
|
346
|
-
"_DSN",
|
|
347
|
-
"_DEPLOY_KEY"
|
|
348
|
-
];
|
|
349
|
-
NON_SECRET_EXCEPTIONS = new Set([
|
|
350
|
-
"MCP_BASE_URL",
|
|
351
|
-
"APP_URL",
|
|
352
|
-
"API_URL",
|
|
353
|
-
"TEMPLATE_REGISTRY_URL",
|
|
354
|
-
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
355
|
-
"PAGE_TOKEN",
|
|
356
|
-
"NEXT_PAGE_TOKEN",
|
|
357
|
-
"PREV_PAGE_TOKEN",
|
|
358
|
-
"NEXT_TOKEN",
|
|
359
|
-
"CONTINUATION_TOKEN",
|
|
360
|
-
"SYNC_TOKEN",
|
|
361
|
-
"NEXT_SYNC_TOKEN"
|
|
362
|
-
]);
|
|
363
|
-
QUOTE_EOL = String.raw`(?=$|[\r\n]|\\[rn]|")`;
|
|
364
|
-
JSON_DQ = quoted(String.raw`\\"(?!\$)`, String.raw`\\"`, String.raw`\\\\(?:\\\\|\\"|[^\\"])|\\[^\\"]|[^"\\]`, String.raw`\\\\(?:\\\\|\\"|[^\\"\r\n])|\\[^\\"nr\r\n]|[^"\\\r\n]`);
|
|
365
|
-
RAW_DQ = quoted(`"(?!\\$)`, `"`, String.raw`\\[\s\S]|[^"\\]`, String.raw`\\[^\r\n]|[^"\\\r\n]`);
|
|
366
|
-
SQ = quoted(`'`, `'`, String.raw`[^'\\]|'\\\\?''|\\[\s\S]`, String.raw`[^'\\\r\n]|'\\\\?''|\\[^nr\r\n]`);
|
|
367
|
-
BARE = String.raw`(?!\$)(?:\\[^nrtu"\s]|[^\s"'\\])+`;
|
|
368
|
-
ASSIGNMENT_RE = new RegExp(String.raw`(?:(?<=\\[nrt])|(?<![\w\\.]))([A-Za-z_][A-Za-z0-9_.]*)=(?!=)(${JSON_DQ}|${RAW_DQ}|${SQ}|${BARE})`, "g");
|
|
369
|
-
LINE_START = String.raw`(?:^|(?<=\\[nr]))`;
|
|
370
|
-
LINE_END = String.raw`(?=[ \t]*(?:$|\r|\\[nr]|"))`;
|
|
371
|
-
LINE_VALUE = String.raw`"[^"\\\r\n]*"|'[^'\\\r\n]*'|\\"[^"\\\r\n]*\\"|[^\s"'\\]+`;
|
|
372
|
-
INI_ASSIGNMENT_RE = new RegExp(String.raw`${LINE_START}([ \t]*)([A-Za-z_][\w.]*)([ \t]*=[ \t]*)(${LINE_VALUE})${LINE_END}`, "gm");
|
|
373
|
-
YAML_KEY_RE = new RegExp(String.raw`${LINE_START}([ \t]*(?:-[ \t]+)?)([A-Za-z_][\w.-]*)([ \t]*:[ \t]+)(${LINE_VALUE})${LINE_END}`, "gm");
|
|
374
|
-
JSON_KEY = String.raw`[A-Za-z_][\w.-]{0,63}`;
|
|
375
|
-
JSON_KEY_RE = new RegExp(String.raw`"(${JSON_KEY})"[ \t]*:[ \t]*"`, "g");
|
|
376
|
-
ESCAPED_JSON_KEY_RE = new RegExp(String.raw`\\"(${JSON_KEY})\\"[ \t]*:[ \t]*\\"`, "g");
|
|
377
|
-
TOKEN68 = String.raw`[A-Za-z0-9._~+/=-]{8,}(?![A-Za-z0-9._~+/=\[-])`;
|
|
378
|
-
HEADER_SEP = String.raw`\\?["']?[ \t]*:[ \t]*\\?["']?`;
|
|
379
|
-
AUTH_HEADER_RE = new RegExp(String.raw`(?<![\w-])((?:proxy-)?authorization)(${HEADER_SEP}(?:bearer|basic|token|bot)[ \t]+)(${TOKEN68})`, "gi");
|
|
380
|
-
API_KEY_HEADER_RE = new RegExp(String.raw`(?<![\w-])(x-api-key)(${HEADER_SEP})(${TOKEN68})`, "gi");
|
|
381
|
-
CURL_PASSWORD_RE = /(?<=^|[\s'"])(--password(?:[ \t]+|=)\\?["']?)([^\s"'\\]+)/g;
|
|
382
|
-
CURL_USER_RE = /(?<=^|[\s'"])((?:-u|-U|--user|--proxy-user)(?:[ \t]+|=)\\?["']?([^\s"'\\:@]+):)([^\s"'\\@]+)/g;
|
|
383
|
-
URL_USERINFO_RE = /(?<![a-z0-9+.-])([a-z][a-z0-9+.-]{0,31}:\/\/[^\s/:@?#"'\\]+:)([^\s/@?#"'\\]+)(?=@)/gi;
|
|
384
|
-
PEM_RE = /(-----BEGIN [A-Z0-9 ]{0,32}PRIVATE KEY(?: BLOCK)?-----)((?:(?!-----)[\s\S]){1,16384})(-----END [A-Z0-9 ]{0,32}PRIVATE KEY(?: BLOCK)?-----)/g;
|
|
385
|
-
TB = String.raw`(?:(?<=\\[nrtbfu0])|(?<!\w))`;
|
|
386
|
-
TOKEN_REGEXES = [
|
|
387
|
-
{ name: "github_pat", re: /github_pat_[A-Za-z0-9_]{20,}/g },
|
|
388
|
-
{ name: "github_token", re: new RegExp(String.raw`${TB}gh[pousr]_[A-Za-z0-9]{20,}\b`, "g") },
|
|
389
|
-
{ name: "acp_session_token", re: new RegExp(String.raw`${TB}aseph_[A-Za-z0-9]{20,}\b`, "g") },
|
|
390
|
-
{ name: "gitlab_pat", re: new RegExp(String.raw`${TB}glpat-[A-Za-z0-9_-]{20,}\b`, "g") },
|
|
391
|
-
{
|
|
392
|
-
name: "azure_devops_pat",
|
|
393
|
-
re: new RegExp(String.raw`${TB}[A-Za-z0-9]{76}AZDO[A-Za-z0-9]{4}\b`, "g")
|
|
394
|
-
},
|
|
395
|
-
{ name: "anthropic_key", re: new RegExp(String.raw`${TB}sk-ant-[A-Za-z0-9_-]{20,}\b`, "g") },
|
|
396
|
-
{ name: "openai_proj_key", re: new RegExp(String.raw`${TB}sk-proj-[A-Za-z0-9_-]{20,}\b`, "g") },
|
|
397
|
-
{
|
|
398
|
-
name: "openrouter_key",
|
|
399
|
-
re: new RegExp(String.raw`${TB}sk-or-(?:v1-)?[A-Za-z0-9_-]{20,}\b`, "g")
|
|
400
|
-
},
|
|
401
|
-
{ name: "sk_key", re: new RegExp(String.raw`${TB}sk-[A-Za-z0-9]{20,}\b`, "g") },
|
|
402
|
-
{ name: "slack_token", re: new RegExp(String.raw`${TB}xox[baprseo]-[A-Za-z0-9-]{10,}\b`, "g") },
|
|
403
|
-
{ name: "aws_access_key", re: new RegExp(String.raw`${TB}AKIA[0-9A-Z]{16}\b`, "g") },
|
|
404
|
-
{ name: "google_api_key", re: new RegExp(String.raw`${TB}AIza[A-Za-z0-9_-]{35}\b`, "g") },
|
|
405
|
-
{
|
|
406
|
-
name: "jwt",
|
|
407
|
-
re: new RegExp(String.raw`${TB}eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b`, "g")
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
name: "signoz_ingestion_key",
|
|
411
|
-
re: new RegExp(String.raw`${TB}signoz-ingestion-key=[A-Za-z0-9._~+/-]{20,}={0,2}\b`, "g")
|
|
412
|
-
},
|
|
413
|
-
{ name: "linear_oauth", re: new RegExp(String.raw`${TB}lin_oauth_[A-Za-z0-9_-]{10,}\b`, "g") },
|
|
414
|
-
{ name: "linear_api", re: new RegExp(String.raw`${TB}lin_api_[A-Za-z0-9_-]{10,}\b`, "g") },
|
|
415
|
-
{ name: "npm_token", re: new RegExp(String.raw`${TB}npm_[A-Za-z0-9_-]{20,}\b`, "g") },
|
|
416
|
-
{
|
|
417
|
-
name: "atlassian_token",
|
|
418
|
-
re: new RegExp(String.raw`${TB}ATATT[A-Za-z0-9_-]{20,}\b`, "g")
|
|
419
|
-
},
|
|
420
|
-
{ name: "mcp_token", re: new RegExp(String.raw`${TB}aswt_[A-Za-z0-9]{20,}\b`, "g") }
|
|
421
|
-
];
|
|
422
|
-
volatileSecrets = new Map;
|
|
423
|
-
registeredSensitiveKeys = new Set;
|
|
424
|
-
sensitiveKeyVerdicts = new Map;
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
export { isSensitiveKey, scrubSecrets, scrubObject, refreshSecretScrubberCache, registerVolatileSecret, registerSensitiveKeyName, init_secret_scrubber };
|
package/dist/cli-jqt9hrnz.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cosineSimilarity,
|
|
3
|
-
deserializeEmbedding,
|
|
4
|
-
getEmbeddingProvider,
|
|
5
|
-
init_embedding,
|
|
6
|
-
serializeEmbedding
|
|
7
|
-
} from "./cli-yhmwmv0g.js";
|
|
8
|
-
import {
|
|
9
|
-
getDbClient,
|
|
10
|
-
init_db
|
|
11
|
-
} from "./cli-qdv8kgz7.js";
|
|
12
|
-
import {
|
|
13
|
-
init_secret_scrubber,
|
|
14
|
-
scrubSecrets
|
|
15
|
-
} from "./cli-h1spv8v4.js";
|
|
16
|
-
|
|
17
|
-
// src/be/scripts/embeddings.ts
|
|
18
|
-
init_secret_scrubber();
|
|
19
|
-
init_db();
|
|
20
|
-
init_embedding();
|
|
21
|
-
var providerOverride = null;
|
|
22
|
-
function embeddingProvider() {
|
|
23
|
-
return providerOverride ?? getEmbeddingProvider();
|
|
24
|
-
}
|
|
25
|
-
function scriptEmbeddingText(script) {
|
|
26
|
-
return scrubSecrets([script.description, script.intent, script.signatureJson].join(`
|
|
27
|
-
`));
|
|
28
|
-
}
|
|
29
|
-
function rowToScript(row) {
|
|
30
|
-
return {
|
|
31
|
-
id: row.id,
|
|
32
|
-
name: row.name,
|
|
33
|
-
scope: row.scope,
|
|
34
|
-
scopeId: row.scopeId ?? null,
|
|
35
|
-
source: row.source,
|
|
36
|
-
description: row.description,
|
|
37
|
-
intent: row.intent,
|
|
38
|
-
signatureJson: row.signatureJson,
|
|
39
|
-
argsJsonSchema: row.argsJsonSchema ?? null,
|
|
40
|
-
contentHash: row.contentHash,
|
|
41
|
-
version: row.version,
|
|
42
|
-
isScratch: row.isScratch === 1,
|
|
43
|
-
typeChecked: row.typeChecked === 1,
|
|
44
|
-
fsMode: row.fsMode,
|
|
45
|
-
createdByAgentId: row.createdByAgentId ?? null,
|
|
46
|
-
createdAt: row.createdAt,
|
|
47
|
-
updatedAt: row.updatedAt
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
async function embedScript(script) {
|
|
51
|
-
const text = scriptEmbeddingText(script);
|
|
52
|
-
const provider = embeddingProvider();
|
|
53
|
-
const embedding = await provider.embed(text);
|
|
54
|
-
if (!embedding)
|
|
55
|
-
return;
|
|
56
|
-
if (embedding.length !== provider.dimensions) {
|
|
57
|
-
console.error(`[script-embed] dimension mismatch for "${script.name}": expected=${provider.dimensions} got=${embedding.length}, skipping`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
await getDbClient().run(`INSERT INTO script_embeddings (
|
|
61
|
-
scriptId, embedding, embeddingModel, embeddedText, embeddedAt
|
|
62
|
-
)
|
|
63
|
-
VALUES (?, ?, ?, ?, ?)
|
|
64
|
-
ON CONFLICT(scriptId) DO UPDATE SET
|
|
65
|
-
embedding = excluded.embedding,
|
|
66
|
-
embeddingModel = excluded.embeddingModel,
|
|
67
|
-
embeddedText = excluded.embeddedText,
|
|
68
|
-
embeddedAt = excluded.embeddedAt`, [script.id, serializeEmbedding(embedding), provider.name, text, new Date().toISOString()]);
|
|
69
|
-
}
|
|
70
|
-
async function candidateRows(scope, scopeId) {
|
|
71
|
-
const params = [];
|
|
72
|
-
let where = "s.isScratch = 0";
|
|
73
|
-
if (scope === "global") {
|
|
74
|
-
where += " AND s.scope = 'global' AND s.scopeId IS NULL";
|
|
75
|
-
} else if (scope === "agent") {
|
|
76
|
-
where += " AND s.scope = 'agent' AND s.scopeId = ?";
|
|
77
|
-
params.push(scopeId ?? "");
|
|
78
|
-
} else if (scopeId) {
|
|
79
|
-
where += " AND ((s.scope = 'agent' AND s.scopeId = ?) OR (s.scope = 'global' AND s.scopeId IS NULL))";
|
|
80
|
-
params.push(scopeId);
|
|
81
|
-
} else {
|
|
82
|
-
where += " AND s.scope = 'global' AND s.scopeId IS NULL";
|
|
83
|
-
}
|
|
84
|
-
return getDbClient().query(`SELECT
|
|
85
|
-
s.*,
|
|
86
|
-
e.scriptId,
|
|
87
|
-
e.embedding,
|
|
88
|
-
e.embeddingModel,
|
|
89
|
-
e.embeddedText,
|
|
90
|
-
e.embeddedAt
|
|
91
|
-
FROM script_embeddings e
|
|
92
|
-
JOIN scripts s ON s.id = e.scriptId
|
|
93
|
-
WHERE ${where}`, params);
|
|
94
|
-
}
|
|
95
|
-
async function scriptRows(scope, scopeId) {
|
|
96
|
-
const params = [];
|
|
97
|
-
let where = "isScratch = 0";
|
|
98
|
-
if (scope === "global") {
|
|
99
|
-
where += " AND scope = 'global' AND scopeId IS NULL";
|
|
100
|
-
} else if (scope === "agent") {
|
|
101
|
-
where += " AND scope = 'agent' AND scopeId = ?";
|
|
102
|
-
params.push(scopeId ?? "");
|
|
103
|
-
} else if (scopeId) {
|
|
104
|
-
where += " AND ((scope = 'agent' AND scopeId = ?) OR (scope = 'global' AND scopeId IS NULL))";
|
|
105
|
-
params.push(scopeId);
|
|
106
|
-
} else {
|
|
107
|
-
where += " AND scope = 'global' AND scopeId IS NULL";
|
|
108
|
-
}
|
|
109
|
-
return getDbClient().query(`SELECT *, NULL as scriptId, NULL as embedding, NULL as embeddingModel, NULL as embeddedText, NULL as embeddedAt FROM scripts WHERE ${where}`, params);
|
|
110
|
-
}
|
|
111
|
-
function nameMatchBonus(script, query) {
|
|
112
|
-
const trimmed = query.trim().toLowerCase();
|
|
113
|
-
if (!trimmed)
|
|
114
|
-
return 0;
|
|
115
|
-
return script.name.toLowerCase().includes(trimmed) ? 1 : 0;
|
|
116
|
-
}
|
|
117
|
-
async function lexicalFallback(args) {
|
|
118
|
-
const query = args.query.trim().toLowerCase();
|
|
119
|
-
return (await scriptRows(args.scope, args.scopeId)).map(rowToScript).filter((script) => {
|
|
120
|
-
if (!query)
|
|
121
|
-
return true;
|
|
122
|
-
return [script.name, script.description, script.intent].join(`
|
|
123
|
-
`).toLowerCase().includes(query);
|
|
124
|
-
}).map((script) => {
|
|
125
|
-
const bonus = nameMatchBonus(script, args.query);
|
|
126
|
-
return {
|
|
127
|
-
script,
|
|
128
|
-
score: bonus || 0.5,
|
|
129
|
-
semanticScore: 0,
|
|
130
|
-
nameMatchBonus: bonus
|
|
131
|
-
};
|
|
132
|
-
}).sort((a, b) => b.score - a.score).slice(0, args.limit ?? 10);
|
|
133
|
-
}
|
|
134
|
-
async function searchScripts(args) {
|
|
135
|
-
const provider = embeddingProvider();
|
|
136
|
-
const queryEmbedding = await provider.embed(args.query);
|
|
137
|
-
if (!queryEmbedding)
|
|
138
|
-
return lexicalFallback(args);
|
|
139
|
-
const candidates = await candidateRows(args.scope, args.scopeId);
|
|
140
|
-
if (candidates.length === 0)
|
|
141
|
-
return lexicalFallback(args);
|
|
142
|
-
const results = [];
|
|
143
|
-
for (const row of candidates) {
|
|
144
|
-
const stored = deserializeEmbedding(row.embedding);
|
|
145
|
-
if (stored.length !== queryEmbedding.length)
|
|
146
|
-
continue;
|
|
147
|
-
const script = rowToScript(row);
|
|
148
|
-
const semanticScore = cosineSimilarity(queryEmbedding, stored);
|
|
149
|
-
const bonus = nameMatchBonus(script, args.query);
|
|
150
|
-
results.push({
|
|
151
|
-
script,
|
|
152
|
-
score: 0.7 * semanticScore + 0.3 * bonus,
|
|
153
|
-
semanticScore,
|
|
154
|
-
nameMatchBonus: bonus
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
if (results.length === 0)
|
|
158
|
-
return lexicalFallback(args);
|
|
159
|
-
return results.sort((a, b) => b.score - a.score).slice(0, args.limit ?? 10);
|
|
160
|
-
}
|
|
161
|
-
async function reembedAllScripts() {
|
|
162
|
-
const rows = await getDbClient().query("SELECT *, NULL as scriptId, NULL as embedding, NULL as embeddingModel, NULL as embeddedText, NULL as embeddedAt FROM scripts WHERE isScratch = 0 ORDER BY updatedAt ASC");
|
|
163
|
-
for (const row of rows) {
|
|
164
|
-
await embedScript(rowToScript(row));
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export { embeddingProvider, embedScript, searchScripts, reembedAllScripts };
|